summaryrefslogtreecommitdiff
path: root/lib9/sbrk-posix.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib9/sbrk-posix.c')
-rw-r--r--lib9/sbrk-posix.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/lib9/sbrk-posix.c b/lib9/sbrk-posix.c
new file mode 100644
index 00000000..c21cd2ff
--- /dev/null
+++ b/lib9/sbrk-posix.c
@@ -0,0 +1,48 @@
+#ifdef __APPLE_CC__ /* look for a better way */
+#include "lib9.h"
+#undef _POSIX_C_SOURCE
+#undef getwd
+
+#include <unistd.h>
+#include <pthread.h>
+#include <time.h>
+#include <termios.h>
+#include <signal.h>
+#include <pwd.h>
+#include <sys/resource.h>
+#include <sys/time.h>
+
+#include <sys/socket.h>
+#include <sched.h>
+#include <errno.h>
+#include <sys/ucontext.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <mach/mach_init.h>
+
+#include <mach/task.h>
+
+#include <mach/vm_map.h>
+
+
+__typeof__(sbrk(0))
+sbrk(int size)
+{
+ void *brk;
+ kern_return_t err;
+
+ err = vm_allocate( (vm_map_t) mach_task_self(),
+ (vm_address_t *)&brk,
+ size,
+ VM_FLAGS_ANYWHERE);
+ if (err != KERN_SUCCESS)
+ brk = (void*)-1;
+
+ return brk;
+}
+#else
+/* dummy function for everyone else, in case its ar complains about empty files */
+void __fakesbrk(void){}
+#endif