prog.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <thread.h>
  4. #include <sunrpc.h>
  5. SunStatus
  6. sunCallPack(SunProg *prog, uchar *a, uchar *ea, uchar **pa, SunCall *c)
  7. {
  8. uchar *x;
  9. int (*pack)(uchar*, uchar*, uchar**, SunCall*);
  10. if(pa == nil)
  11. pa = &x;
  12. if(c->type < 0 || c->type >= prog->nproc || (pack=prog->proc[c->type].pack) == nil)
  13. return SunProcUnavail;
  14. if((*pack)(a, ea, pa, c) < 0)
  15. return SunGarbageArgs;
  16. return SunSuccess;
  17. }
  18. SunStatus
  19. sunCallUnpack(SunProg *prog, uchar *a, uchar *ea, uchar **pa, SunCall *c)
  20. {
  21. uchar *x;
  22. int (*unpack)(uchar*, uchar*, uchar**, SunCall*);
  23. if(pa == nil)
  24. pa = &x;
  25. if(c->type < 0 || c->type >= prog->nproc || (unpack=prog->proc[c->type].unpack) == nil)
  26. return SunProcUnavail;
  27. if((*unpack)(a, ea, pa, c) < 0){
  28. fprint(2, "in: %.*H unpack failed\n", (int)(ea-a), a);
  29. return SunGarbageArgs;
  30. }
  31. return SunSuccess;
  32. }
  33. SunStatus
  34. sunCallUnpackAlloc(SunProg *prog, SunCallType type, uchar *a, uchar *ea, uchar **pa, SunCall **pc)
  35. {
  36. uchar *x;
  37. uint size;
  38. int (*unpack)(uchar*, uchar*, uchar**, SunCall*);
  39. SunCall *c;
  40. if(pa == nil)
  41. pa = &x;
  42. if(type < 0 || type >= prog->nproc || (unpack=prog->proc[type].unpack) == nil)
  43. return SunProcUnavail;
  44. size = prog->proc[type].sizeoftype;
  45. if(size == 0)
  46. return SunProcUnavail;
  47. c = mallocz(size, 1);
  48. if(c == nil)
  49. return SunSystemErr;
  50. c->type = type;
  51. if((*unpack)(a, ea, pa, c) < 0){
  52. fprint(2, "in: %.*H unpack failed\n", (int)(ea-a), a);
  53. free(c);
  54. return SunGarbageArgs;
  55. }
  56. *pc = c;
  57. return SunSuccess;
  58. }
  59. uint
  60. sunCallSize(SunProg *prog, SunCall *c)
  61. {
  62. uint (*size)(SunCall*);
  63. if(c->type < 0 || c->type >= prog->nproc || (size=prog->proc[c->type].size) == nil)
  64. return ~0;
  65. return (*size)(c);
  66. }