2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
25 * Unix compatibility for sbrk system call.
28 * 09-Mar-90 Gregg Kellogg (gk) at NeXT.
29 * include <kern/mach_interface.h> instead of <kern/mach.h>
31 * 14-Feb-89 Avadis Tevanian (avie) at NeXT.
32 * Total rewrite using a fixed area of VM from break region.
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 */
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
;
51 if (sbrk_needs_init
) {
52 sbrk_needs_init
= FALSE
;
54 * Allocate a big region to simulate break region.
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
)
63 return((caddr_t
)sbrk_curbrk
);
65 sbrk_region_size
-= size
;
66 if (sbrk_region_size
< 0)
68 return((caddr_t
)(sbrk_curbrk
- size
));