Nt.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #include <windows.h>
  2. #include <lib9.h>
  3. #define Windows (1<<2) /* hack - can't include cc.h because of clashes */
  4. #define Chunk (1*1024*1024)
  5. void*
  6. mysbrk(ulong size)
  7. {
  8. void *v;
  9. static int chunk;
  10. static uchar *brk;
  11. if(chunk < size) {
  12. chunk = Chunk;
  13. if(chunk < size)
  14. chunk = Chunk + size;
  15. brk = VirtualAlloc(NULL, chunk, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
  16. if(brk == 0)
  17. return (void*)-1;
  18. }
  19. v = brk;
  20. chunk -= size;
  21. brk += size;
  22. return v;
  23. }
  24. int
  25. mycreat(char *n, int p)
  26. {
  27. return create(n, 1, p);
  28. }
  29. int
  30. mywait(int *s)
  31. {
  32. fprint(2, "mywait called\n");
  33. abort();
  34. return 0;
  35. }
  36. int
  37. mydup(int f1, int f2)
  38. {
  39. fprint(2, "mydup called\n");
  40. abort();
  41. return 0;
  42. }
  43. int
  44. mypipe(int *fd)
  45. {
  46. fprint(2, "mypipe called\n");
  47. abort();
  48. return 0;
  49. }
  50. int
  51. systemtype(int sys)
  52. {
  53. return sys&Windows;
  54. }
  55. int
  56. pathchar(void)
  57. {
  58. return '/';
  59. }
  60. char*
  61. mygetwd(char *path, int len)
  62. {
  63. return getcwd(path, len);
  64. }
  65. int
  66. myexec(char *path, char *argv[])
  67. {
  68. fprint(2, "myexec called\n");
  69. abort();
  70. return 0;
  71. }
  72. int
  73. myfork(void)
  74. {
  75. fprint(2, "myfork called\n");
  76. abort();
  77. return 0;
  78. }
  79. /*
  80. * fake mallocs
  81. */
  82. void*
  83. malloc(uint n)
  84. {
  85. return mysbrk(n);
  86. }
  87. void*
  88. calloc(uint m, uint n)
  89. {
  90. return mysbrk(m*n);
  91. }
  92. void*
  93. realloc(void *p, uint n)
  94. {
  95. void *new;
  96. new = malloc(n);
  97. if(new && p)
  98. memmove(new, p, n);
  99. return new;
  100. }
  101. void
  102. free(void *p)
  103. {
  104. }
  105. int
  106. myaccess(char *f)
  107. {
  108. int fd;
  109. fd = open(f, OREAD);
  110. if(fd < 0)
  111. return -1;
  112. close(fd);
  113. return 0;
  114. }