22this code is no being maintained anymore
32 (0==stat(n,&stbuf)&&(stbuf.st_mode&S_IFMT)==S_IFREG&&0==access(n,X_OK))
34 (0==stat(n,&stbuf)&&(stbuf.st_mode&S_IFMT)==S_IFDIR&&0==access(n,W_OK))
37#define MAXSECTIONS 100
46#define N_TXTOFF(x) (sizeof(struct filehdr)+(x).f_opthdr+(x).f_nscns*sizeof(struct scnhdr))
54Yap_FindExecutable(
void)
56 register char *cp, *cp2;
60 cp = (
char *)getenv(
"PATH");
62 cp =
".:/usr/ucb:/bin:/usr/bin:/usr/local/bin";
63 if (*GLOBAL_argv[0] ==
'/') {
64 if (oktox(GLOBAL_argv[0])) {
65 strcpy(LOCAL_FileNameBuf, GLOBAL_argv[0]);
66 Yap_TrueFileName(LOCAL_FileNameBuf, GLOBAL_Executable, TRUE);
78 for (cp2 = LOCAL_FileNameBuf; (*cp) != 0 && (*cp) !=
':';)
81 strcpy(cp2, GLOBAL_argv[0]);
84 if (!oktox(LOCAL_FileNameBuf))
86 Yap_TrueFileName(LOCAL_FileNameBuf, GLOBAL_Executable, TRUE);
87 return GLOBAL_Executable;
90 strcpy(LOCAL_FileNameBuf, GLOBAL_argv[0]);
91 Yap_TrueFileName(LOCAL_FileNameBuf, GLOBAL_Executable, TRUE);
92 if (oktox(GLOBAL_Executable))
93 return GLOBAL_Executable;
95 Yap_Error(SYSTEM_ERROR_INTERNAL,MkAtomTerm(Yap_LookupAtom(GLOBAL_Executable)),
96 "cannot find file being executed");
102Yap_LoadForeignFile(
char *file,
int flags)
109Yap_CallForeignFile(
void *handle,
char *f)
115Yap_CloseForeignFile(
void *handle)
128 YapInitProc *init_proc)
130 char command[2*PATH_MAX];
135 char tmp_buff[32] =
"/tmp/YAP_TMP_XXXXXX";
139 struct aouthdr sysHeader;
140 struct filehdr fileHeader;
141 struct scnhdr sectionHeader[MAXSECTIONS];
143 unsigned long loadImageSize, firstloadImSz;
157 strcat(o_files,AtomName(tmp->name));
168 strcat(l_files,AtomName(tmp->name));
173 tfile = mktemp(tmp_buff);
176 if (strlen(o_files) + strlen(l_files) + strlen(proc_name) +
177 strlen(GLOBAL_Executable) > 2*PATH_MAX) {
178 strcpy(LOCAL_ErrorSay,
" too many parameters in load_foreign/3 ");
181 sprintf(command,
"/usr/bin/ld -N -A %s -o %s %s %s -lc",
183 tfile, o_files, l_files);
185 if (system(command) != 0) {
187 strcpy(LOCAL_ErrorSay,
" ld returned error status in load_foreign_files ");
191 if ((fildes = open(tfile, O_RDONLY)) < 0) {
192 strcpy(LOCAL_ErrorSay,
" unable to open temp file in load_foreign_files ");
197 read(fildes, (
char *) &fileHeader,
sizeof(fileHeader));
198 read(fildes, (
char *) &sysHeader,
sizeof(sysHeader));
200 for (i = 0; i < fileHeader.f_nscns; i++)
201 read(fildes, (
char *) §ionHeader[i],
202 sizeof(*sectionHeader));
206 loadImageSize = sysHeader.tsize + sysHeader.dsize + sysHeader.bsize;
209 loadImageSize += 4095 + 16;
215 firstloadImSz = loadImageSize;
217 if (!(FCodeBase = Yap_AllocCodeSpace((
int) loadImageSize))
219 || activate_code(ForeignCodeBase, u1)
222 strcpy(LOCAL_ErrorSay,
" unable to allocate space for external code ");
226 FCodeBase = (
char *) (Unsigned(FCodeBase + PAGESIZE - 1) & ~(PAGESIZE - 1));
233 sprintf(command,
"ld -x -A %s -T %lx -o %s -u %s %s %s -lc",
235 ((
unsigned long) (((
unsigned long) (ForeignCodeBase)) &
236 ((
unsigned long) (~Yap_HeapBase))
238 ), tfile, entry_point, o_files, l_files);
241 sprintf(command,
"ld -systype bsd43 -N -A %s -T %lx -o %s -u %s %s %s -lc",
243 (
unsigned long) ForeignCodeBase,
244 tfile, entry_point, o_files, l_files);
246 sprintf(command,
"ld -N -A %s -T %lx -o %s -e %s -u _%s %s -lc",
248 (
unsigned long) ForeignCodeBase,
249 tfile, entry_point, o_files, l_files);
253 if (system(command) != 0) {
255 strcpy(LOCAL_ErrorSay,
" ld returned error status in load_foreign_files ");
258 if ((fildes = open(tfile, O_RDONLY)) < 0) {
259 strcpy(LOCAL_ErrorSay,
" unable to open temp file in load_foreign_files ");
262 read(fildes, (
char *) &fileHeader,
sizeof(fileHeader));
263 read(fildes, (
char *) &sysHeader,
sizeof(sysHeader));
266 for (i = 0; i < fileHeader.f_nscns; i++)
267 read(fildes, (
char *) §ionHeader[i],
sizeof(*sectionHeader));
269 loadImageSize = sysHeader.tsize + sysHeader.dsize + sysHeader.bsize;
270 if (firstloadImSz < loadImageSize) {
271 strcpy(LOCAL_ErrorSay,
" miscalculation in load_foreign/3 ");
277 struct nlist func_info[2];
278#if defined(mips) || defined(I386)
279 char NAME1[128], NAME2[128];
280 func_info[0].n_name = NAME1;
281 func_info[1].n_name = NAME2;
283 sprintf(entry_fun,
"_%s", proc_name);
284 func_info[0].n_name = entry_fun;
285 func_info[1].n_name = NULL;
286 if (nlist(tfile, func_info) == -1) {
287 strcpy(LOCAL_ErrorSay,
" in nlist(3) ");
290 if (func_info[0].n_type == 0) {
291 strcpy(LOCAL_ErrorSay,
" in nlist(3) ");
294 *init_proc = (YapInitProc)(func_info[0].n_value);
298 lseek(fildes, (
long)(N_TXTOFF(header)), 0);
300 unsigned int u1 = header.a_text + header.a_data;
301 read(fildes, (
char *) FCodeBase, u1);
303 while (u1 < loadImageSize)
308 return LOAD_SUCCEEDED;
313 char *proc_name, YapInitProc *init_proc)
315 return LoadForeign(ofiles, libs, proc_name, init_proc);
319Yap_ShutdownLoadForeign(
void)
325 char *proc_name, YapInitProc *init_proc)
327 return(LoadForeign(ofiles,libs, proc_name, init_proc));
load_foreign_files/3 has works for the following configurations: