21 |
|
|
22 |
|
|
23 |
#include <string.h> |
#include <string.h> |
24 |
|
#include <stdlib.h> |
25 |
#include <dlfcn.h> |
#include <dlfcn.h> |
26 |
|
#include <sys/param.h> |
27 |
|
#include <time.h> |
28 |
#ifdef HAVE_AOUT |
#ifdef HAVE_AOUT |
29 |
#include HAVE_AOUT |
#include HAVE_AOUT |
30 |
#endif |
#endif |
32 |
#include <elf.h> |
#include <elf.h> |
33 |
#endif |
#endif |
34 |
|
|
35 |
|
#include "ptable.h" |
36 |
|
|
37 |
/* cc -DVOL=volatile -G 0 -c foo.c ; ld -shared foo.o -o jim.o ; cat foo.data >> jim.o */ |
/* cc -DVOL=volatile -G 0 -c foo.c ; ld -shared foo.o -o jim.o ; cat foo.data >> jim.o */ |
38 |
int did_a_dynamic_load; |
int did_a_dynamic_load; |
39 |
|
|
43 |
} ; |
} ; |
44 |
static struct name_list *loaded_files; |
static struct name_list *loaded_files; |
45 |
|
|
46 |
|
void |
47 |
get_init_name(faslfile,init_fun) |
get_init_name(faslfile,init_fun) |
48 |
object faslfile; |
object faslfile; |
49 |
char *init_fun; |
char *init_fun; |
50 |
{ |
{ |
51 |
object path = coerce_to_pathname(faslfile); |
object path = coerce_to_pathname(faslfile); |
52 |
char *p; |
char *p; |
|
int n; |
|
53 |
strcpy(init_fun,"init_"); |
strcpy(init_fun,"init_"); |
54 |
coerce_to_filename(path->pn.pn_name,init_fun+5); |
coerce_to_filename(path->pn.pn_name,init_fun+5); |
55 |
p = init_fun +5; |
p = init_fun +5; |
58 |
p++;} |
p++;} |
59 |
} |
} |
60 |
|
|
61 |
|
int |
62 |
fasload(faslfile) |
fasload(faslfile) |
63 |
object faslfile; |
object faslfile; |
64 |
{ void *dlp ; |
{ void *dlp ; |
65 |
int (*fptr)(); |
int (*fptr)(); |
66 |
char buf[200]; |
char buf[200]; |
67 |
static count=0; |
static int count=0; |
68 |
object memory; |
object memory; |
69 |
object data; |
object data; |
70 |
char filename[MAXPATHLEN]; |
char filename[MAXPATHLEN]; |
84 |
strcpy(nl->name,buf); |
strcpy(nl->name,buf); |
85 |
} |
} |
86 |
faslstream = open_stream(faslfile, smm_input, Cnil, sKerror); |
faslstream = open_stream(faslfile, smm_input, Cnil, sKerror); |
87 |
#define MAKE_SHARED_LIB |
/* #define MAKE_SHARED_LIB */ |
88 |
|
#undef MAKE_SHARED_LIB |
89 |
#ifdef MAKE_SHARED_LIB |
#ifdef MAKE_SHARED_LIB |
90 |
{ struct filehdr fhdr; |
{ struct filehdr fhdr; |
91 |
fread(&fhdr,1,sizeof(fhdr),faslstream->sm.sm_fp); |
fread(&fhdr,1,sizeof(fhdr),faslstream->sm.sm_fp); |
98 |
} |
} |
99 |
} |
} |
100 |
#endif |
#endif |
101 |
|
{ |
102 |
|
char com[600]; |
103 |
|
snprintf(com,sizeof(com),"ld -shared %s -o %s",filename,buf); |
104 |
|
system(com); |
105 |
|
} |
106 |
|
|
107 |
dlp = dlopen(buf,RTLD_NOW); |
dlp = dlopen(buf,RTLD_NOW); |
108 |
if (dlp ==0) |
if (dlp ==0) { |
109 |
|
fputs(dlerror(),stderr); |
110 |
FEerror("Cant open for dynamic link ~a",1,make_simple_string(faslfile)); |
FEerror("Cant open for dynamic link ~a",1,make_simple_string(faslfile)); |
111 |
|
} |
112 |
|
|
113 |
fptr = (int (*)())dlsym(dlp, "init_code"); |
fptr = (int (*)())dlsym(dlp, "init_code"); |
114 |
if (fptr == 0) |
if (fptr == 0) |
126 |
memory->cfd.cfd_start = NULL; |
memory->cfd.cfd_start = NULL; |
127 |
memory->cfd.cfd_size = 0; |
memory->cfd.cfd_size = 0; |
128 |
if(symbol_value(sLAload_verboseA)!=Cnil) |
if(symbol_value(sLAload_verboseA)!=Cnil) |
129 |
printf(" start address (dynamic) 0x%x ",fptr); |
printf(" start address (dynamic) %p ",fptr); |
130 |
call_init(0,memory,data,fptr); |
call_init(0,memory,data,fptr); |
131 |
unlink(buf); |
unlink(buf); |
132 |
did_a_dynamic_load = 1; |
did_a_dynamic_load = 1; |
133 |
return memory->cfd.cfd_size; |
return memory->cfd.cfd_size; |
134 |
} |
} |
135 |
|
|
136 |
unlink_loaded_files() |
void |
137 |
|
unlink_loaded_files(void) |
138 |
{ while(loaded_files) |
{ while(loaded_files) |
139 |
{ unlink(loaded_files->name); |
{ unlink(loaded_files->name); |
140 |
loaded_files= loaded_files->next; |
loaded_files= loaded_files->next; |
141 |
} |
} |
142 |
} |
} |
143 |
|
|
144 |
|
#include "sfasli.c" |