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