xref: /inferno-os/os/port/dynld.c (revision 7ef44d652ae9e5e1f5b3465d73684e4a54de73c0)
1 #include "u.h"
2 #include "../port/lib.h"
3 #include "../port/error.h"
4 #include "mem.h"
5 #include	"dat.h"
6 #include	"fns.h"
7 #include	<a.out.h>
8 #include	<dynld.h>
9 #include	<kernel.h>
10 
11 /*
12  * kernel interface to dynld, for use by devdynld.c,
13  * libinterp/dlm.c, and possibly others
14  */
15 
16 typedef struct Fd Fd;
17 struct Fd {
18 	int	fd;
19 };
20 
21 static long
22 readfd(void *a, void *buf, long nbytes)
23 {
24 	return kread(((Fd*)a)->fd, buf, nbytes);
25 }
26 
27 static vlong
28 seekfd(void *a, vlong off, int t)
29 {
30 	return kseek(((Fd*)a)->fd, off, t);
31 }
32 
33 static void
34 errfd(char *s)
35 {
36 	kstrcpy(up->env->errstr, s, ERRMAX);
37 }
38 
39 Dynobj*
40 kdynloadfd(int fd, Dynsym *tab, int ntab)
41 {
42 	Fd f;
43 
44 	f.fd = fd;
45 	return dynloadgen(&f, readfd, seekfd, errfd, tab, ntab, 0);
46 }
47 
48 int
49 kdynloadable(int fd)
50 {
51 	Fd f;
52 
53 	f.fd = fd;
54 	return dynloadable(&f, readfd, seekfd);
55 }
56 
57 /* auxiliary routines for dynamic loading of C modules */
58 
59 Dynobj*
60 dynld(int fd)
61 {
62 	Fd f;
63 
64 	f.fd = fd;
65 	return dynloadgen(&f, readfd, seekfd, errfd, _exporttab, dyntabsize(_exporttab), 0);
66 }
67 
68 int
69 dynldable(int fd)
70 {
71 	Fd f;
72 
73 	f.fd = fd;
74 	return dynloadable(&f, readfd, seekfd);
75 }
76