summaryrefslogtreecommitdiff
path: root/emu/port/dynldc.c
blob: 2237f7ab59612e6dcfa430e686045a34b003c0a2 (plain)
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
#include	"dat.h"
#include	"fns.h"
#include	"error.h"
#include	<a.out.h>
#include	<dynld.h>

/*
 * channel-based kernel interface to dynld, for use by devdynld.c,
 * libinterp/dlm.c, and possibly others
 */

static long
readfc(void *a, void *buf, long nbytes)
{
	Chan *c = a;

	if(waserror())
		return -1;
	nbytes = devtab[c->type]->read(c, buf, nbytes, c->offset);
	poperror();
	return nbytes;
}

static vlong
seekfc(void *a, vlong off, int t)
{
	Chan *c = a;

	if(c->qid.type & QTDIR || off < 0)
		return -1;	/* won't happen */
	switch(t){
	case 0:
		lock(c);
		c->offset = off;
		unlock(c);
		break;
	case 1:
		lock(c);
		off += c->offset;
		c->offset = off;
		unlock(c);
		break;
	case 2:
		return -1;	/* not needed */
	}
	return off;
}

static void
errfc(char *s)
{
	kstrcpy(up->env->errstr, s, ERRMAX);
}

Dynobj*
kdynloadchan(Chan *c, Dynsym *tab, int ntab)
{
	return dynloadgen(c, readfc, seekfc, errfc, tab, ntab, 0);
}

int
kdynloadable(Chan *c)
{
	return dynloadable(c, readfc, seekfc);
}