sbrk-posix.c 948 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #ifdef __APPLE_CC__ /* look for a better way */
  2. #include "lib9.h"
  3. #undef _POSIX_C_SOURCE
  4. #undef getwd
  5. #include <unistd.h>
  6. #include <pthread.h>
  7. #include <time.h>
  8. #include <termios.h>
  9. #include <signal.h>
  10. #include <pwd.h>
  11. #include <sys/resource.h>
  12. #include <sys/time.h>
  13. #include <sys/socket.h>
  14. #include <sched.h>
  15. #include <errno.h>
  16. #include <sys/ucontext.h>
  17. #include <sys/types.h>
  18. #include <sys/stat.h>
  19. #include <mach/mach_init.h>
  20. #include <mach/task.h>
  21. #include <mach/vm_map.h>
  22. __typeof__(sbrk(0))
  23. sbrk(int size)
  24. {
  25. void *brk;
  26. kern_return_t err;
  27. err = vm_allocate( (vm_map_t) mach_task_self(),
  28. (vm_address_t *)&brk,
  29. size,
  30. VM_FLAGS_ANYWHERE);
  31. if (err != KERN_SUCCESS)
  32. brk = (void*)-1;
  33. return brk;
  34. }
  35. #else
  36. /* dummy function for everyone else, in case its ar complains about empty files */
  37. void __fakesbrk(void){}
  38. #endif