]> git.saurik.com Git - apple/libc.git/blob - mach/sbrk.c
Libc-262.tar.gz
[apple/libc.git] / mach / sbrk.c
1 /*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 * File: sbrk.c
24 *
25 * Unix compatibility for sbrk system call.
26 *
27 * HISTORY
28 * 09-Mar-90 Gregg Kellogg (gk) at NeXT.
29 * include <kern/mach_interface.h> instead of <kern/mach.h>
30 *
31 * 14-Feb-89 Avadis Tevanian (avie) at NeXT.
32 * Total rewrite using a fixed area of VM from break region.
33 */
34
35 #include <mach/mach.h> /* for vm_allocate, vm_offset_t */
36 #include <mach/vm_statistics.h>
37 #include <sys/types.h> /* for caddr_t */
38
39 static int sbrk_needs_init = TRUE;
40 static vm_size_t sbrk_region_size = 4*1024*1024; /* Well, what should it be? */
41 static vm_address_t sbrk_curbrk;
42
43 caddr_t sbrk(size)
44 int size;
45 {
46 vm_offset_t addr;
47 kern_return_t ret;
48 caddr_t ocurbrk;
49 extern int end;
50
51 if (sbrk_needs_init) {
52 sbrk_needs_init = FALSE;
53 /*
54 * Allocate a big region to simulate break region.
55 */
56 ret = vm_allocate(mach_task_self(), &sbrk_curbrk, sbrk_region_size,
57 VM_MAKE_TAG(VM_MEMORY_SBRK)|TRUE);
58 if (ret != KERN_SUCCESS)
59 return((caddr_t)-1);
60 }
61
62 if (size <= 0)
63 return((caddr_t)sbrk_curbrk);
64 sbrk_curbrk += size;
65 sbrk_region_size -= size;
66 if (sbrk_region_size < 0)
67 return((caddr_t)-1);
68 return((caddr_t)(sbrk_curbrk - size));
69 }
70
71 caddr_t brk(x)
72 caddr_t x;
73 {
74 return((caddr_t)-1);
75 }
76