1*433d6423SLionel Sambuc #include <sys/cdefs.h>
2*433d6423SLionel Sambuc #include "namespace.h"
3*433d6423SLionel Sambuc #include <lib.h>
4*433d6423SLionel Sambuc
5*433d6423SLionel Sambuc #include <string.h>
6*433d6423SLionel Sambuc #include <unistd.h>
7*433d6423SLionel Sambuc
8*433d6423SLionel Sambuc #ifdef __weak_alias
9*433d6423SLionel Sambuc __weak_alias(brk, _brk)
10*433d6423SLionel Sambuc #endif
11*433d6423SLionel Sambuc
12*433d6423SLionel Sambuc extern char *_brksize;
13*433d6423SLionel Sambuc
14*433d6423SLionel Sambuc /* Both OSF/1 and SYSVR4 man pages specify that brk(2) returns int.
15*433d6423SLionel Sambuc * However, BSD4.3 specifies that brk() returns char*. POSIX omits
16*433d6423SLionel Sambuc * brk() on the grounds that it imposes a memory model on an architecture.
17*433d6423SLionel Sambuc * On the other hand, they are so crucial to correct operation of so many
18*433d6423SLionel Sambuc * parts of the system, that we have chosen to hide the name brk using _brk,
19*433d6423SLionel Sambuc * as with system calls. In this way, if a user inadvertently defines a
20*433d6423SLionel Sambuc * procedure brk, MINIX may continue to work because the true call is _brk.
21*433d6423SLionel Sambuc */
brk(addr)22*433d6423SLionel Sambuc int brk(addr)
23*433d6423SLionel Sambuc void *addr;
24*433d6423SLionel Sambuc {
25*433d6423SLionel Sambuc message m;
26*433d6423SLionel Sambuc
27*433d6423SLionel Sambuc if (addr != _brksize) {
28*433d6423SLionel Sambuc memset(&m, 0, sizeof(m));
29*433d6423SLionel Sambuc m.m_lc_vm_brk.addr = addr;
30*433d6423SLionel Sambuc if (_syscall(VM_PROC_NR, VM_BRK, &m) < 0) return(-1);
31*433d6423SLionel Sambuc _brksize = addr;
32*433d6423SLionel Sambuc }
33*433d6423SLionel Sambuc return(0);
34*433d6423SLionel Sambuc }
35*433d6423SLionel Sambuc
36