1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
/* Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
*/
/*
* SLIB.C -- Support routines for the shared library.
*/
extern unsigned vshlib_[];
extern char *((*environ)[]);
extern char *Malloc(), *Realloc(), *Free();
main()
{
/* Malloc etc. are produced by the MEDIT task - see mkshlib.csh. */
vlibinit_ (environ, Malloc, Realloc, Free);
/* Do something useful when S.e is called as a task. */
printf ("Sun/IRAF Shared Library, version %d, %d symbols\n",
vshlib_[0], vshlib_[5]);
printf ("base=%x, etext=%x, edata=%x, end=%x, size=%dKb\n",
vshlib_[1], vshlib_[2], vshlib_[3], vshlib_[4],
(vshlib_[4] - vshlib_[1]) / 1000);
}
/* Back link to selected procedures and global variables in the client so
* that the shared library code can call routines executing in the runtime
* context of the client image. (Not intended to be portable).
*/
#define I_malloc 0
#define I_realloc 1
#define I_free 2
#define I_len 3
#ifdef SOLARIS
#define I_dlopen 4
#define I_dlclose 5
#define I_dlsym 6
#define I_dlerror 7
#endif
typedef int (*PFI)();
static PFI fcn[I_len];
malloc (nb) { return (fcn[I_malloc](nb)); }
realloc (bp,nb) { return (fcn[I_realloc](bp,nb)); }
free (bp) { return (fcn[I_free](bp)); }
#ifdef SOLARIS
void *dlopen (const char *pathname, int mode)
{ return ((void *)fcn[I_dlopen] (pathname, mode)); }
int dlclose (void *handle)
{ return ((int)fcn[I_dlclose] (handle)); }
void *dlsym (void *handle, const char *name)
{ return ((void *)fcn[I_dlsym] (handle, name)); }
char *dlerror (void)
{ return ((char *)fcn[I_dlerror]()); }
vlibinit_ (u_environ, u_malloc, u_realloc, u_free,
u_dlopen, u_dlclose, u_dlsym, u_dlerror)
char *((*u_environ)[]);
PFI u_malloc, u_realloc, u_free;
PFI u_dlopen, u_dlclose, u_dlsym, u_dlerror;
{
environ = u_environ;
fcn[I_malloc] = u_malloc;
fcn[I_realloc] = u_realloc;
fcn[I_free] = u_free;
fcn[I_dlopen] = u_dlopen;
fcn[I_dlclose] = u_dlclose;
fcn[I_dlsym] = u_dlsym;
fcn[I_dlerror] = u_dlerror;
}
#else
vlibinit_ (u_environ, u_malloc, u_realloc, u_free)
char *((*u_environ)[]);
PFI u_malloc, u_realloc, u_free;
{
environ = u_environ;
fcn[I_malloc] = u_malloc;
fcn[I_realloc] = u_realloc;
fcn[I_free] = u_free;
}
#endif
|