dynld.c 736 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "dat.h"
  2. #include "fns.h"
  3. #include "error.h"
  4. #include <a.out.h>
  5. #include <dynld.h>
  6. /*
  7. * kernel interface to dynld, for use by devdynld.c,
  8. * libinterp/dlm.c, and possibly others
  9. */
  10. typedef struct Fd Fd;
  11. struct Fd {
  12. int fd;
  13. };
  14. static long
  15. readfd(void *a, void *buf, long nbytes)
  16. {
  17. return kread(((Fd*)a)->fd, buf, nbytes);
  18. }
  19. static vlong
  20. seekfd(void *a, vlong off, int t)
  21. {
  22. return kseek(((Fd*)a)->fd, off, t);
  23. }
  24. static void
  25. errfd(char *s)
  26. {
  27. kstrcpy(up->env->errstr, s, ERRMAX);
  28. }
  29. Dynobj*
  30. kdynloadfd(int fd, Dynsym *tab, int ntab)
  31. {
  32. Dynobj *o;
  33. Fd f;
  34. f.fd = fd;
  35. return dynloadgen(&f, readfd, seekfd, errfd, tab, ntab, 0);
  36. }
  37. int
  38. kdynloadable(int fd)
  39. {
  40. Fd f;
  41. f.fd = fd;
  42. return dynloadable(&f, readfd, seekfd);
  43. }