summaryrefslogtreecommitdiff
path: root/emu/port/dynldc.c
diff options
context:
space:
mode:
authorCharles.Forsyth <devnull@localhost>2009-03-25 15:55:14 +0000
committerCharles.Forsyth <devnull@localhost>2009-03-25 15:55:14 +0000
commitdfd1934d5e1ddbeb326f77fc0e52307c801a1a3e (patch)
treef1e8b23278caae95e01d88b00421d6c3642357ef /emu/port/dynldc.c
parent78dfdcbd59dc8f36975e7695933e3f753957474c (diff)
x20090325-1554
Diffstat (limited to 'emu/port/dynldc.c')
-rw-r--r--emu/port/dynldc.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/emu/port/dynldc.c b/emu/port/dynldc.c
new file mode 100644
index 00000000..2237f7ab
--- /dev/null
+++ b/emu/port/dynldc.c
@@ -0,0 +1,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);
+}