NEURON
dll.cpp
Go to the documentation of this file.
1 #include <../../nrnconf.h>
2 #if defined(CYGWIN)
3 #define nrnCYGWIN
4 #endif
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <errno.h>
9 #include <setjmp.h>
10 #include <math.h>
11 #include <io.h>
12 #include <assert.h>
13 
14 #define __attribute__(arg) /**/
15 #include "coff.h"
16 #undef CYGWIN
17 #define CYGWIN 1
18 
19 #if defined(__MWERKS__)|| defined(_MSC_VER)
20 #undef SYMESZ
21 #define SYMESZ 18
22 #undef RELSZ
23 #define RELSZ 10
24 #endif
25 
26 #include "limits.h"
27 #include "dll.h"
28 
29 #if defined(nrnCYGWIN)
30 extern "C" {
31 extern FILE __files[]; // declared in mswinprt.c. FILE* __files does not work here.
32 int _flsbuf(unsigned i, FILE* f) {
33  printf("\n_flsbuf i=%d\n", i);
34  return i;
35 }
36 }
37 #endif
38 
39 char* dllstrdup(const char* s) {
40  char* p = new char[strlen(s) + 1];
41  strcpy(p, s);
42  return p;
43 }
44 
45 #if defined(__MWERKS__) && !defined(_MSC_VER)
46 extern "C" {
47 #if __MWERKS__ >= 7
48 FILE __files[]; // would be from file_struc.h except for RC_INVOKED
49 #endif
50 
51 extern int flsbuf(unsigned, FILE*);
52 int _flsbuf(unsigned i, FILE* f) {
53  printf("\n_flsbuf i=%d\n", i);
54  return i;
55 }
56 
57 }
58 #endif
59 
60 #define PRINT 0
61 #define PRDEBUG printf(
62 
63 //#define PRDEBUGFILE "c:/temp.tmp"
64 #if defined(PRDEBUGFILE)
65 #undef PRDEBUG
66 #define PRDEBUG fprintf(prdebug_,
67 static FILE* prdebug_;
68 #endif
69 
70 typedef void (*CDTOR)();
71 
72 struct Symtab {
74  static Symtab *symtabs;
75  char **name;
76  void **value;
77  int num;
78  int max;
79  Symtab();
80  ~Symtab();
81  void add(char *name, void *value);
82  void *get(char *name);
83  static void *lookup(char *name);
84 };
85 
86 struct dll_s {
88  char *loadpath;
89  int valid;
90  static dll_s *top;
93  char *bytes;
94  char *dtor_section;
98 };
99 
100 dll_s *dll_s::top = 0;
101 
103 
105 {
106  next = symtabs;
107  prev = 0;
108  symtabs = this;
109  num = 0;
110  max = 10;
111  name = (char **)malloc(max*sizeof(char *));
112  value = (void **)malloc(max*sizeof(void *));
113 }
114 
116 {
117  int i;
118  for (i=0; i<num; i++)
119  free(name[i]);
120  free(name);
121  free(value);
122  if (next)
123  next->prev = prev;
124  if (prev)
125  prev->next = next;
126  else
127  symtabs = next;
128 }
129 
130 void Symtab::add(char *Pname, void *Pvalue)
131 {
132  if (num >= max)
133  {
134  max += 10;
135  name = (char **)realloc(name, max * sizeof(char *));
136  value = (void **)realloc(value, max * sizeof(void *));
137  }
138  name[num] = dllstrdup(Pname);
139  value[num] = Pvalue;
140  num++;
141 }
142 
143 void *Symtab::get(char *Pname)
144 {
145  int i;
146  for (i=0; i<num; i++)
147  if (strcmp(Pname, name[i]) == 0)
148  return value[i];
149  return 0;
150 }
151 
152 void *Symtab::lookup(char *Pname)
153 {
154  Symtab *s;
155  for (s=symtabs; s; s=s->next)
156  {
157  void *v = s->get(Pname);
158  if (v)
159  {
160  return v;
161  }
162  }
163  return 0;
164 }
165 
166 static struct {
167  int val;
168  char *name;
169 } flags[] = {
170  F_RELFLG, "REL",
171  F_EXEC, "EXEC",
172  F_LNNO, "LNNO",
173  F_LSYMS, "LSYMS",
174  0, 0
175 };
176 
177 static struct {
178  int val;
179  char *name;
180 } sflags[] = {
181  STYP_TEXT, "text",
182  STYP_DATA, "data",
183  STYP_BSS, "bss",
184  0, 0
185 };
186 
187 static char *dll_argv0 = 0;
188 static Symtab *local_symtab = 0;
189 static Symtab *common_symtab = 0;
190 
191 static void dll_exitfunc(void)
192 {
193  while (dll_s::top)
194  dll_unload((struct DLL *)dll_s::top);
195 }
196 
197 void dll_register(char *Psymbol, void *Paddress)
198 {
199  if (local_symtab == 0)
200  local_symtab = new Symtab;
201  if (common_symtab == 0)
202  common_symtab = new Symtab;
203  local_symtab->add(Psymbol, Paddress);
204  local_symtab->get(Psymbol);
205 }
206 
207 // following works around the c++ overloading of math functions
208 // eg. want sin(double) not sin(float)
209 static void dll_registerdf1(char* Psymbol, double(*Paddress)(double)) {
210  dll_register(Psymbol, (void*)Paddress);
211 }
212 
213 static void dll_registerdf2(char* Psymbol, double(*Paddress)(double, double)) {
214  dll_register(Psymbol, (void*)Paddress);
215 }
216 
217 #define MKDLL(a,b) extern void b();
218 #define DFMKDLL(a,b) extern double b();
219 #define DFMKDLL1(a,b) /**/
220 #define DFMKDLL2(a,b) /**/
221 #define DMKDLL(a,b) extern double b;
222 #define IMKDLL(a,b) extern int b;
223 #define MKDLLdec(a,b) /**/
224 #define MKDLLvpf(a,b) extern void* b();
225 #define MKDLLvp(a,b) extern void* b;
226 #define MKDLLif(a,b) extern int b();
227 extern "C" {
228 #include "nrnmath.h"
229 #include "nrnmech.h"
230 #if OCMATRIX
231 #include "ocmatdll.h"
232 #endif
233 }
234 #undef MKDLL
235 #undef DFMKDLL
236 #undef DFMKDLL1
237 #undef DFMKDLL2
238 #undef DMKDLL
239 #undef IMKDLL
240 #undef MKDLLdec
241 #undef MKDLLvpf
242 #undef MKDLLvp
243 #undef MKDLLif
244 
245 void dll_init(char *argv0)
246 {
247  // this was causing an unhandled exception on
248  // exit on one machine. I don't believe, but
249  // am not certain, that it is any longer necessary
250  //atexit(dll_exitfunc);
251  if (dll_argv0)
252  free(dll_argv0);
253  else
254  {
255  dll_register("_dll_load", (void*)dll_load);
256  dll_register("_dll_unload", (void*)dll_unload);
257  dll_register("_dll_lookup", (void*)dll_lookup);
258 #define MKDLL(a,b) dll_register(a, (void*)b);
259 #define DFMKDLL(a,b) dll_register(a, (void*)b);
260 #define DFMKDLL1(a,b) dll_registerdf1(a, b);
261 #define DFMKDLL2(a,b) dll_registerdf2(a, b);
262 #define DMKDLL(a,b) dll_register(a, (void*)(&b));
263 #define IMKDLL(a,b) DMKDLL(a,b)
264 #define MKDLLdec(a,b) MKDLL(a, b)
265 #define MKDLLvpf(a,b) MKDLL(a,b)
266 #define MKDLLif(a,b) MKDLL(a,b)
267 #define MKDLLvp(a,b) DMKDLL(a,b)
268 
269 #include "nrnmath.h"
270 #include "nrnmech.h"
271 #if OCMATRIX
272 #include "ocmatdll.h"
273 #endif
274 #undef MKDLL
275 #undef DFMKDLL
276 #undef DMKDLL
277 #undef IMKDLL
278 #undef MKDLLdec
279 #undef MKDLLvpf
280 #undef MKDLLif
281  }
282  dll_argv0 = dllstrdup(argv0);
283 }
284 
285 char *find_file(char *fn)
286 {
287 #if 0
288  char *bp, *ep, *pp;
289  static char buf[PATH_MAX];
290  if (strpbrk(fn, ":\\/"))
291  return fn;
292 
293 // printf("find: try `%s'\n", fn);
294  if (access(fn,0) == 0)
295  return fn;
296 
297  if (dll_argv0)
298  {
299  strcpy(buf, dll_argv0);
300  ep = buf;
301  for (bp=buf; *bp; bp++)
302  if (strchr(":\\/", *bp))
303  ep = bp+1;
304  strcpy(ep, fn);
305 // printf("find: try `%s'\n", buf);
306  if (access(buf, 0) == 0)
307  return buf;
308  }
309 
310  bp = getenv("PATH");
311  while (*bp)
312  {
313  pp = buf;
314  while (*bp && *bp != ';')
315  *pp++ = *bp++;
316  *pp++ = '/';
317  strcpy(pp, fn);
318 // printf("find: try `%s'\n", buf);
319  if (access(buf, 0) == 0)
320  return buf;
321  if (*bp == 0)
322  break;
323  bp++;
324  }
325 // printf("find: default `%s'\n", fn);
326 #endif
327  return fn;
328 }
329 
330 struct DLL *dll_load(char *filename)
331 {
332 #if defined(PRDEBUGFILE)
333 prdebug_ = fopen(PRDEBUGFILE, "wb");
334 #endif
335  if (dll_argv0 == 0)
336  dll_init("");
337 
338  dll_s *dll;
339  for (dll=dll_s::top; dll; dll=dll->next)
340  if (strcmp(dll->loadpath, filename) == 0)
341  {
342  dll->load_count ++;
343  return (DLL *)dll;
344  }
345  DLL* d = dll_force_load(filename);
346 #if defined(PRDEBUGFILE)
347 fclose(prdebug_);
348 #endif
349  return d;
350 }
351 
352 struct DLL *dll_force_load(char *filename)
353 {
354  int i, s;
355  int error = 0;
356  int max_bytes = 0;
357  dll_s *dll;
358 
359  char *loadpath = find_file(filename);
360 
361 #if PRINT
362  PRDEBUG "load: `%s'\n", loadpath);
363 #endif
364  FILE *file = fopen(loadpath, "rb");
365  if (file == 0)
366  {
367  printf("Error: unable to load %s\n", filename);
368  perror("The error was");
369  return 0;
370  }
371 
372  dll = new dll_s;
373  dll->valid = 0;
374  dll->loadpath = dllstrdup(filename);
375  dll->num_sections = 0;
376  dll->next = dll_s::top;
377  if (dll->next)
378  dll->next->prev = dll;
379  dll_s::top = dll;
380  dll->prev = 0;
381  dll->load_count = 1;
382  dll->dtor_count = 0;
383  dll->uninit_func = 0;
384  CDTOR init_func = 0;
385 
386  FILHDR filhdr;
387  fread(&filhdr, 1, FILHSZ, file);
388 #if PRINT
389  PRDEBUG "file: %s, magic=%#x\n", filename, filhdr.f_magic);
390 #endif
391  if (filhdr.f_magic != 0x14c)
392  {
393  fprintf(stderr, "Not a COFF file\n");
394  return 0;
395  }
396 #if PRINT
397  PRDEBUG "nscns=%d, nsyms=%d, symptr=%#x\n", filhdr.f_nscns, filhdr.f_nsyms,
398  filhdr.f_symptr);
399  PRDEBUG "flags: ");
400  for (i=0; flags[i].val; i++)
401  if (filhdr.f_flags & flags[i].val)
402  PRDEBUG " %s", flags[i].name);
403  PRDEBUG "\n");
404 #endif
405 
406  if (filhdr.f_opthdr)
407  fseek(file, filhdr.f_opthdr, 1);
408 
409  SCNHDR *section;
410  section = new SCNHDR[filhdr.f_nscns];
411  dll->num_sections = filhdr.f_nscns;
412 #if defined(__MWERKS__) || defined(nrnCYGWIN)
413  for (i=0; i < filhdr.f_nscns; ++i) {
414  fread(section+i, 1, SCNHSZ, file);
415 #if PRINT == 2
416  PRDEBUG "%8s paddr %x vaddr %x size %x scnptr %x relptr %x lnnoptr %x nreloc %x nlnno %x flags %x\n",
417  section[i].s_name, section[i].s_paddr, section[i].s_vaddr, section[i].s_size,
418  section[i].s_scnptr, section[i].s_relptr, section[i].s_lnnoptr,
419  section[i].s_nreloc, section[i].s_nlnno, section[i].s_flags);
420 #endif
421  }
422 #else
423  fread(section, sizeof(SCNHDR), filhdr.f_nscns, file);
424 #endif
425  max_bytes = 0;
426  for (s=0; s<filhdr.f_nscns; s++) {
427 #if CYGWIN
428  if (max_bytes < section[s].s_vaddr + section[s].s_size + section[s].s_paddr)
429  max_bytes = section[s].s_vaddr + section[s].s_size + section[s].s_paddr;
430 #else
431  if (max_bytes < section[s].s_vaddr + section[s].s_size)
432  max_bytes = section[s].s_vaddr + section[s].s_size;
433 #endif
434  }
435 
436  dll->bytes = new char[max_bytes];
437  // there was a problem with the hoc_scdoub and hoc_vdoub terminator 0's not
438  // being set to 0 in all cases. Perhaps cygwin has changed its section zeroing
439  // policy and s_size is back in favor at s_paddr expense. Anyway, the
440  // following at least starts us out with a zero array and the segmentation
441  // violation seen occasionally with NEURONMainMenu/File/WorkingDir
442  // no longer occurs. See the next #if CYGWIN for my earlier hack which
443  // may be obsolete.
444  for (i=0; i < max_bytes; ++i) {dll->bytes[i] = 0;}
445 
446  for (s=0; s<filhdr.f_nscns; s++)
447  {
448  if (section[s].s_scnptr)
449  {
450 #if PRINT
451  PRDEBUG "section %d from file at 0x%x size 0x%x\n",
452  s, dll->bytes + section[s].s_vaddr, section[s].s_size);
453 #endif
454  if (section[s].s_size)
455  {
456  fseek(file, section[s].s_scnptr, 0);
457  fread(dll->bytes+section[s].s_vaddr, 1, section[s].s_size, file);
458  }
459  }
460  else
461  {
462 #if CYGWIN
463 #if PRINT
464  PRDEBUG "section %d zeroed 0x%x bytes at 0x%x\n", s, section[s].s_paddr, dll->bytes+section[s].s_vaddr);
465  PRDEBUG "if not CYGWIN then we would\n");
466  PRDEBUG "section %d zeroed %d bytes at 0x%x\n", s, section[s].s_size, dll->bytes+section[s].s_vaddr);
467 #endif
468  if (section[s].s_paddr)
469  memset(dll->bytes+section[s].s_vaddr, 0, section[s].s_paddr);
470  }
471 #else
472 #if PRINT
473  PRDEBUG "section %d zeroed %d bytes at 0x%x\n", s, section[s].s_size, dll->bytes+section[s].s_vaddr);
474 #endif
475  if (section[s].s_size)
476  memset(dll->bytes+section[s].s_vaddr, 0, section[s].s_size);
477  }
478 #endif
479  }
480 
481  SYMENT *syment = new SYMENT[filhdr.f_nsyms];
482  unsigned long *symaddr = new unsigned long [filhdr.f_nsyms];
483  fseek(file, filhdr.f_symptr, 0);
484  //printf("SYMESZ=%d\n", SYMESZ);
485 #if defined(__MWERKS__) || defined(nrnCYGWIN)
486  for (i=0; i < filhdr.f_nsyms; ++i) {
487  fread(syment+i, 1, SYMESZ, file);
488  }
489 #else
490  fread(syment, filhdr.f_nsyms, SYMESZ, file);
491 #endif
492  unsigned long strsize = 4;
493  fread(&strsize, 1, sizeof(unsigned long), file);
494  //printf("strsize=%ld\n", strsize);
495  char *strings = new char[strsize];
496  strings[0] = 0;
497  if (strsize > 4)
498  fread(strings+4, strsize-4, 1, file);
499 
500  for (i=0; i<filhdr.f_nsyms; i++)
501  {
502  char snameb[9], *sname, *scname;
503 #if PRINT
504  PRDEBUG "[0x%08x] ", syment[i].e_value);
505 #endif
506  if (syment[i].e.e.e_zeroes)
507  {
508  sprintf(snameb, "%.8s", syment[i].e.e_name);
509  sname = snameb;
510  }
511  else
512  sname = strings + syment[i].e.e.e_offset;
513 
514  if (syment[i].e_scnum > 0)
515  {
516  symaddr[i] = syment[i].e_value + (long)(dll->bytes);
517 #if CYGWIN
518  symaddr[i] += section[syment[i].e_scnum-1].s_vaddr;
519 #endif
520  if (syment[i].e_sclass == 2)
521  dll->symtab.add(sname, (void *)symaddr[i]);
522  if (strcmp(sname, "_dll_unloadfunc") == 0)
523  dll->uninit_func = (CDTOR)symaddr[i];
524  if (strcmp(sname, "_dll_loadfunc") == 0)
525  init_func = (CDTOR)symaddr[i];
526  }
527  else if (syment[i].e_scnum == N_UNDEF)
528  {
529  if (syment[i].e_value)
530  {
531  void *stv = common_symtab->get(sname);
532  if (stv)
533  symaddr[i] = (long)stv;
534  else
535  {
536  stv = calloc(syment[i].e_value,1);
537  common_symtab->add(sname, stv);
538  symaddr[i] = (long)stv;
539  }
540  }
541  else
542  {
543  symaddr[i] = (long)Symtab::lookup(sname);
544  if (symaddr[i] == 0)
545  {
546  fprintf(stderr, "Undefined symbol %s referenced from %s\n",
547  sname, filename);
548  error = 1;
549  }
550  }
551  }
552 
553 #if PRINT
554  if (syment[i].e_scnum >= 1)
555  scname = section[syment[i].e_scnum-1].s_name;
556  else
557  scname = "N/A";
558  PRDEBUG "[%2d] 0x%08x %2d %-8.8s %04x %02x %d %s\n", i,
559  symaddr[i],
560  syment[i].e_scnum,
561  scname,
562  syment[i].e_type,
563  syment[i].e_sclass,
564  syment[i].e_numaux,
565  sname);
566  for (int a=0; a<syment[i].e_numaux; a++)
567  {
568  i++;
569 #if 0
570  unsigned char *ap = (unsigned char *)(syment+i);
571  printf("\033[0m");
572  for (int b=0; b<SYMESZ; b++)
573  printf(" %02x\033[32m%c\033[37m", ap[b], ap[b]>' '?ap[b]:' ');
574  printf("\033[1m\n");
575 #endif
576  }
577 #else
578  i += syment[i].e_numaux;
579 #endif
580  }
581 
582  for (s=0; s<filhdr.f_nscns; s++)
583  {
584 #if PRINT
585  PRDEBUG "\nS[%d] `%-8s' pa=%#x va=%#x s=%#x ptr=%#x\n",
586  s, section[s].s_name, section[s].s_paddr,section[s].s_vaddr,
587  section[s].s_size, section[s].s_scnptr);
588  PRDEBUG " rel=%#x nrel=%#x flags: ",
589  section[s].s_relptr, section[s].s_nreloc);
590  for (i=0; sflags[i].val; i++)
591  if (section[s].s_flags & sflags[i].val)
592  PRDEBUG " %s", sflags[i].name);
593  PRDEBUG "\n");
594 #endif
595 
596  if (section[s].s_nreloc)
597  {
598  fseek(file, section[s].s_relptr, 0);
599 //printf("RELSZ=%d\n", RELSZ);
600  RELOC *r = new RELOC[section[s].s_nreloc];
601 #if defined(__MWERKS__) || defined(nrnCYGWIN)
602  for (i=0; i < section[s].s_nreloc; ++i) {
603  fread(r+i, 1, RELSZ, file);
604  }
605 #else
606  fread(r, RELSZ, section[s].s_nreloc, file);
607 #endif
608  for (i=0; i<section[s].s_nreloc; i++)
609  {
610  long *ptr = (long *)(dll->bytes + r[i].r_vaddr);
611  long old_value = *ptr;
612 #if PRINT
613  PRDEBUG " [%02d] 0x%08x(0x%08x) %2d 0x%04x 0%02o (was 0x%08x",
614  i, r[i].r_vaddr, ptr, r[i].r_symndx, r[i].r_type, r[i].r_type, old_value);
615 #endif
616  switch (r[i].r_type)
617  {
618  case 0x06:
619 #if !CYGWIN
620  old_value -= syment[r[i].r_symndx].e_value;
621 #endif
622  old_value += symaddr[r[i].r_symndx];
623  break;
624  case 0x14:
625  if (syment[r[i].r_symndx].e_scnum == 0 || 1)
626  {
627 #if !CYGWIN // old coff format from gcc2.7.2 days
628  old_value -= (long)(dll->bytes);
629 #else // new pe-coff format from gcc2.95.2
630  old_value = -(long)ptr - 4;
631 #endif
632  old_value += symaddr[r[i].r_symndx];
633  }
634  break;
635  default:
636  fprintf(stderr, "Error: unexpected relocation type %#x\n",
637  r[i].r_type);
638  error = 1;
639  }
640  *ptr = old_value;
641 #if PRINT
642  PRDEBUG ", now 0x%08x)\n", old_value);
643  if (r[i].r_type == 0x14) {
644  PRDEBUG "pc(0x%08x) + 4 + offset(0x%08x) = external address(0x%08x)\n", (long)ptr, (long)*ptr,
645  (long)*ptr+(long)ptr+4);
646  PRDEBUG "index %2d address 0x%08x\n", r[i].r_symndx, symaddr[r[i].r_symndx]);
647  }
648  if (r[i].r_type == 0x06) {
649  PRDEBUG "e_value=0x%08x\n", syment[r[i].r_symndx].e_value);
650  }
651 #endif
652  }
653  delete [] r;
654  }
655  }
656  for (s=0; s<filhdr.f_nscns; s++)
657  {
658  if (strcmp(section[s].s_name, ".ctor") == 0)
659  {
660  for (i=0; i<section[s].s_size/4; i++)
661  {
662  CDTOR f;
663  void **fv = (void **)(dll->bytes+section[s].s_vaddr);
664  f = (CDTOR)(fv[i]);
665  f();
666  }
667  }
668  if (strcmp(section[s].s_name, ".dtor") == 0)
669  {
670  dll->dtor_section = dll->bytes + section[s].s_vaddr;
671  dll->dtor_count = section[s].s_size/4;
672  }
673  }
674  if (init_func)
675  init_func();
676 
677  dll->valid = 1;
678  fclose(file);
679  delete [] syment;
680  delete [] symaddr;
681  delete [] strings;
682  delete [] section;
683 
684  #if (PRINT == 2)
685  for (i=0; i < max_bytes; ++i) {
686  if ((long)(dll->bytes + i)%8 == 0) {
687  PRDEBUG "\n%08x ", (long)(dll->bytes + i));
688  }
689  PRDEBUG " %02x", dll->bytes[i]&0xff);
690  }
691  PRDEBUG "\n");
692  PRDEBUG "printf=%08x *printf=%02x\n", (long)printf, *((char*)printf)&0xff);
693  #endif
694 
695  if (error)
696  return 0;
697  return (struct DLL *)dll;
698 }
699 
700 void dll_unload(struct DLL *Pdll)
701 {
702  int i, s;
703  CDTOR f;
704  if (Pdll == 0)
705  return;
706  dll_s *dll = (dll_s *)Pdll;
707  if (--dll->load_count)
708  return;
709 // printf("unload: `%s'\n", dll->loadpath);
710  if (dll->valid)
711  {
712  if (dll->uninit_func)
713  dll->uninit_func();
714  for (i=0; i<dll->dtor_count; i++)
715  {
716  void **fv = (void **)(dll->dtor_section);
717  f = (CDTOR)(fv[i]);
718  f();
719  }
720  }
721  if (dll->next)
722  dll->next->prev = dll->prev;
723  if (dll->prev)
724  dll->prev->next = dll->next;
725  else
726  dll_s::top = dll->next;
727  if (dll->bytes)
728  delete dll->bytes;
729  dll->valid = 0;
730  delete dll;
731 }
732 
733 void *dll_lookup(struct DLL *Pdll, char *name)
734 {
735  dll_s *dll = (dll_s *)Pdll;
736  return dll->symtab.get(name);
737 }
struct DLL * dll_load(char *filename)
Definition: dll.cpp:330
char * find_file(char *fn)
Definition: dll.cpp:285
dll_s * prev
Definition: dll.cpp:87
#define N_UNDEF
Definition: coff.h:218
void dll_init(char *argv0)
Definition: dll.cpp:245
#define F_EXEC
Definition: coff.h:25
#define PRDEBUG
Definition: dll.cpp:61
static Symtab * common_symtab
Definition: dll.cpp:189
#define RELSZ
Definition: coff.h:307
Symtab symtab
Definition: dll.cpp:96
static void dll_registerdf1(char *Psymbol, double(*Paddress)(double))
Definition: dll.cpp:209
#define STYP_TEXT
Definition: coff.h:108
~Symtab()
Definition: dll.cpp:115
int dtor_count
Definition: dll.cpp:95
static Symtab * symtabs
Definition: dll.cpp:74
void
int num_sections
Definition: dll.cpp:92
size_t p
#define F_LSYMS
Definition: coff.h:27
#define v
Definition: md1redef.h:4
#define SYMESZ
Definition: coff.h:206
sprintf(buf," if (secondorder) {\ " int _i;\" " for(_i=0;_i< %d;++_i) {\" " _p[_slist%d[_i]]+=dt *_p[_dlist%d[_i]];\" " }}\", numeqn, listnum, listnum)
int max
Definition: dll.cpp:78
#define e
Definition: passive0.cpp:24
char ** name
Definition: dll.cpp:75
static Symtab * local_symtab
Definition: dll.cpp:188
long
Definition: netcvode.cpp:4792
#define FILHDR
Definition: coff.h:36
char * bytes
Definition: dll.cpp:93
#define SCNHDR
Definition: coff.h:92
#define SCNHSZ
Definition: coff.h:94
#define F_LNNO
Definition: coff.h:26
_CONST char * s
Definition: system.cpp:74
Definition: dll.cpp:72
static struct @33 sflags[]
int val
Definition: dll.cpp:167
#define printf
Definition: mwprefix.h:26
Symtab()
Definition: dll.cpp:104
char * getenv(const char *s)
Definition: macprt.cpp:67
#define SYMENT
Definition: coff.h:204
static void dll_registerdf2(char *Psymbol, double(*Paddress)(double, double))
Definition: dll.cpp:213
fprintf(stderr, "Don't know the location of params at %p\, pp)
Definition: dll.cpp:86
#define RELOC
Definition: coff.h:305
void * dll_lookup(struct DLL *Pdll, char *name)
Definition: dll.cpp:733
#define F_RELFLG
Definition: coff.h:24
Symtab * prev
Definition: dll.cpp:73
void add(char *name, void *value)
Definition: dll.cpp:130
#define STYP_DATA
Definition: coff.h:109
int num
Definition: dll.cpp:77
void ** value
Definition: dll.cpp:76
static dll_s * top
Definition: dll.cpp:90
int valid
Definition: dll.cpp:89
static void dll_exitfunc(void)
Definition: dll.cpp:191
CDTOR uninit_func
Definition: dll.cpp:97
void * get(char *name)
Definition: dll.cpp:143
struct DLL * dll_force_load(char *filename)
Definition: dll.cpp:352
#define FILHSZ
Definition: coff.h:38
dll_s * next
Definition: dll.cpp:87
static char * dll_argv0
Definition: dll.cpp:187
#define i
Definition: md1redef.h:12
char * loadpath
Definition: dll.cpp:88
void(* CDTOR)()
Definition: dll.cpp:70
static void * lookup(char *name)
Definition: dll.cpp:152
#define error(err_num, fn_name)
Definition: err.h:73
char buf[512]
Definition: init.cpp:13
static struct @32 flags[]
char * dllstrdup(const char *s)
Definition: dll.cpp:39
char * dtor_section
Definition: dll.cpp:94
Symtab * next
Definition: dll.cpp:73
#define PATH_MAX
Definition: limits.h:64
FILE * fopen()
void dll_unload(struct DLL *Pdll)
Definition: dll.cpp:700
#define STYP_BSS
Definition: coff.h:110
void dll_register(char *Psymbol, void *Paddress)
Definition: dll.cpp:197
int load_count
Definition: dll.cpp:91