badsyscall.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <bio.h>
  4. #include <mach.h>
  5. #include <ureg.h>
  6. int handled = 0;
  7. int back = 0;
  8. int inhandler = 0;
  9. int badsys = 0;
  10. int verbose = 0;
  11. char *msg = "Writing from NxM program to stdout via linux write(2)\n";
  12. void
  13. handler(void *v, char *s)
  14. {
  15. char *f[7];
  16. u64int parm[7];
  17. struct Ureg* u = v;
  18. int i, n, nf;
  19. inhandler = 1;
  20. if (verbose)
  21. fprint(2, "handler: %p %s\n", v, s);
  22. handled++;
  23. if (strncmp(s, "sys: bad sys call", 17)==0 && badsys){
  24. badsys = 0;
  25. noted(NCONT);
  26. }
  27. if (strncmp(s, "linux:", 6))
  28. noted(NDFLT);
  29. s += 6;
  30. nf = tokenize(s, f, nelem(f));
  31. for(i = 0; i < nelem(parm); i++)
  32. parm[i] = strtoull(f[i], 0, 0);
  33. switch(parm[0]){
  34. case 22:
  35. u->ax = pipe((void*)(parm[1]));
  36. break;
  37. }
  38. inhandler = 0;
  39. noted(NCONT);
  40. }
  41. void
  42. main(int argc, char *argv[])
  43. {
  44. uvlong callbadsys(uvlong, ...);
  45. int fd[2];
  46. int ret;
  47. char data[4];
  48. if (notify(handler)){
  49. fprint(2, "%r\n");
  50. exits("notify fails");
  51. }
  52. fprint(2, "Notify passed\n");
  53. //callbadsys(0xc0FF);
  54. //fprint(2, "Handled %d\n", handled);
  55. /* try a good linux system call */
  56. ret = callbadsys((uvlong)1, (uvlong)1, msg, strlen(msg));
  57. fprint(2, "Write to stdout is %d, should be %d\n", ret, strlen(msg));
  58. /* try a emulated linux system call */
  59. fprint(2, "Call pipe\n");
  60. ret = callbadsys((uvlong)22, (uvlong)fd);
  61. fprint(2, "PIPE ret %d = fd [%d,%d]\n", ret, fd[0], fd[1]);
  62. ret = write(fd[0], "hi.", 3);
  63. fprint(2, "write to pipe is %d (should be 3)\n", ret);
  64. data[3] = 0;
  65. read(fd[1], data, 3);
  66. fprint(2, "read from pipe is %d (should be 3); data is :%s:\n", ret, data);
  67. /* now try a bad linux system call */
  68. badsys = 1;
  69. callbadsys(0x3FFF);
  70. fprint(2, "Handled %d\n", handled);
  71. back++;
  72. if (!handled)
  73. exits("badsyscall test fails");
  74. exits(nil);
  75. }