Commit | Line | Data |
---|---|---|
36c8bb59 JH |
1 | /* |
2 | * Copyright (c) 1993 Paul Kranenburg | |
3 | * All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms, with or without | |
6 | * modification, are permitted provided that the following conditions | |
7 | * are met: | |
8 | * 1. Redistributions of source code must retain the above copyright | |
9 | * notice, this list of conditions and the following disclaimer. | |
10 | * 2. Redistributions in binary form must reproduce the above copyright | |
11 | * notice, this list of conditions and the following disclaimer in the | |
12 | * documentation and/or other materials provided with the distribution. | |
13 | * 3. All advertising materials mentioning features or use of this software | |
14 | * must display the following acknowledgement: | |
15 | * This product includes software developed by Paul Kranenburg. | |
16 | * 4. The name of the author may not be used to endorse or promote products | |
17 | * derived from this software withough specific prior written permission | |
18 | * | |
19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |
23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 | * | |
30 | * $Id$ | |
31 | */ | |
32 | ||
33 | #include <machine/vmparam.h> | |
34 | #include <sys/param.h> | |
35 | #include <stdio.h> | |
36 | #include <stdlib.h> | |
37 | #include <sys/types.h> | |
38 | #include <sys/stat.h> | |
39 | #include <sys/file.h> | |
40 | #include <sys/time.h> | |
41 | #include <sys/resource.h> | |
42 | #include <sys/mman.h> | |
43 | #ifndef BSD | |
44 | #define MAP_COPY MAP_PRIVATE | |
45 | #define MAP_FILE 0 | |
46 | #define MAP_ANON 0 | |
47 | #endif | |
48 | #include <fcntl.h> | |
49 | #include <a.out.h> | |
50 | #include <stab.h> | |
51 | #include <string.h> | |
52 | #if __STDC__ | |
53 | #include <stdarg.h> | |
54 | #else | |
55 | #include <varargs.h> | |
56 | #endif | |
57 | ||
58 | #include "ld.h" | |
59 | ||
60 | #ifndef BSD /* Need do better than this */ | |
61 | #define NEED_DEV_ZERO 1 | |
62 | #endif | |
63 | ||
64 | caddr_t | |
65 | sbrk(incr) | |
66 | int incr; | |
67 | { | |
68 | int fd = -1; | |
69 | caddr_t curbrk; | |
70 | ||
71 | /* Round-up increment to page size */ | |
72 | incr = ((incr + PAGSIZ - 1) & ~(PAGSIZ - 1)); | |
73 | ||
74 | #if DEBUG | |
75 | xprintf("sbrk: incr = %#x\n", incr); | |
76 | #endif | |
77 | ||
78 | #ifdef NEED_DEV_ZERO | |
79 | fd = open("/dev/zero", O_RDWR, 0); | |
80 | if (fd == -1) | |
81 | perror("/dev/zero"); | |
82 | #endif | |
83 | ||
84 | if ((curbrk = mmap(0, incr, | |
85 | PROT_READ|PROT_WRITE, | |
86 | MAP_ANON|MAP_COPY, fd, 0)) == (caddr_t)-1) { | |
87 | xprintf("Cannot map anonymous memory"); | |
88 | _exit(1); | |
89 | } | |
90 | ||
91 | #ifdef DEBUG | |
92 | xprintf("sbrk: curbrk = %#x\n", curbrk); | |
93 | #endif | |
94 | ||
95 | #ifdef NEED_DEV_ZERO | |
96 | close(fd); | |
97 | #endif | |
98 | ||
99 | return(curbrk); | |
100 | } | |
101 |