prog.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <thread.h>
  12. #include <sunrpc.h>
  13. SunStatus
  14. sunCallPack(SunProg *prog, uint8_t *a, uint8_t *ea, uint8_t **pa,
  15. SunCall *c)
  16. {
  17. uint8_t *x;
  18. int (*pack)(uint8_t*, uint8_t*, uint8_t**, SunCall*);
  19. if(pa == nil)
  20. pa = &x;
  21. if(c->type < 0 || c->type >= prog->nproc || (pack=prog->proc[c->type].pack) == nil)
  22. return SunProcUnavail;
  23. if((*pack)(a, ea, pa, c) < 0)
  24. return SunGarbageArgs;
  25. return SunSuccess;
  26. }
  27. SunStatus
  28. sunCallUnpack(SunProg *prog, uint8_t *a, uint8_t *ea, uint8_t **pa,
  29. SunCall *c)
  30. {
  31. uint8_t *x;
  32. int (*unpack)(uint8_t*, uint8_t*, uint8_t**, SunCall*);
  33. if(pa == nil)
  34. pa = &x;
  35. if(c->type < 0 || c->type >= prog->nproc || (unpack=prog->proc[c->type].unpack) == nil)
  36. return SunProcUnavail;
  37. if((*unpack)(a, ea, pa, c) < 0){
  38. fprint(2, "in: %.*H unpack failed\n", (int)(ea-a), a);
  39. return SunGarbageArgs;
  40. }
  41. return SunSuccess;
  42. }
  43. SunStatus
  44. sunCallUnpackAlloc(SunProg *prog, SunCallType type, uint8_t *a, uint8_t *ea,
  45. uint8_t **pa, SunCall **pc)
  46. {
  47. uint8_t *x;
  48. uint size;
  49. int (*unpack)(uint8_t*, uint8_t*, uint8_t**, SunCall*);
  50. SunCall *c;
  51. if(pa == nil)
  52. pa = &x;
  53. if(type < 0 || type >= prog->nproc || (unpack=prog->proc[type].unpack) == nil)
  54. return SunProcUnavail;
  55. size = prog->proc[type].sizeoftype;
  56. if(size == 0)
  57. return SunProcUnavail;
  58. c = mallocz(size, 1);
  59. if(c == nil)
  60. return SunSystemErr;
  61. c->type = type;
  62. if((*unpack)(a, ea, pa, c) < 0){
  63. fprint(2, "in: %.*H unpack failed\n", (int)(ea-a), a);
  64. free(c);
  65. return SunGarbageArgs;
  66. }
  67. *pc = c;
  68. return SunSuccess;
  69. }
  70. uint
  71. sunCallSize(SunProg *prog, SunCall *c)
  72. {
  73. uint (*size)(SunCall*);
  74. if(c->type < 0 || c->type >= prog->nproc || (size=prog->proc[c->type].size) == nil)
  75. return ~0;
  76. return (*size)(c);
  77. }