diff options
Diffstat (limited to 'monitor_mm.c')
-rw-r--r-- | monitor_mm.c | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/monitor_mm.c b/monitor_mm.c index c363036e6..b4a6e40c9 100644 --- a/monitor_mm.c +++ b/monitor_mm.c | |||
@@ -24,12 +24,13 @@ | |||
24 | */ | 24 | */ |
25 | 25 | ||
26 | #include "includes.h" | 26 | #include "includes.h" |
27 | RCSID("$OpenBSD: monitor_mm.c,v 1.6 2002/06/04 23:05:49 markus Exp $"); | 27 | RCSID("$OpenBSD: monitor_mm.c,v 1.8 2002/08/02 14:43:15 millert Exp $"); |
28 | 28 | ||
29 | #ifdef HAVE_SYS_MMAN_H | 29 | #ifdef HAVE_SYS_MMAN_H |
30 | #include <sys/mman.h> | 30 | #include <sys/mman.h> |
31 | #endif | 31 | #endif |
32 | 32 | ||
33 | #include "openbsd-compat/xmmap.h" | ||
33 | #include "ssh.h" | 34 | #include "ssh.h" |
34 | #include "xmalloc.h" | 35 | #include "xmalloc.h" |
35 | #include "log.h" | 36 | #include "log.h" |
@@ -38,7 +39,14 @@ RCSID("$OpenBSD: monitor_mm.c,v 1.6 2002/06/04 23:05:49 markus Exp $"); | |||
38 | static int | 39 | static int |
39 | mm_compare(struct mm_share *a, struct mm_share *b) | 40 | mm_compare(struct mm_share *a, struct mm_share *b) |
40 | { | 41 | { |
41 | return ((char *)a->address - (char *)b->address); | 42 | long diff = (char *)a->address - (char *)b->address; |
43 | |||
44 | if (diff == 0) | ||
45 | return (0); | ||
46 | else if (diff < 0) | ||
47 | return (-1); | ||
48 | else | ||
49 | return (1); | ||
42 | } | 50 | } |
43 | 51 | ||
44 | RB_GENERATE(mmtree, mm_share, next, mm_compare) | 52 | RB_GENERATE(mmtree, mm_share, next, mm_compare) |
@@ -84,15 +92,9 @@ mm_create(struct mm_master *mmalloc, size_t size) | |||
84 | */ | 92 | */ |
85 | mm->mmalloc = mmalloc; | 93 | mm->mmalloc = mmalloc; |
86 | 94 | ||
87 | #ifdef HAVE_MMAP_ANON_SHARED | 95 | address = xmmap(size); |
88 | address = mmap(NULL, size, PROT_WRITE|PROT_READ, MAP_ANON|MAP_SHARED, | ||
89 | -1, 0); | ||
90 | if (address == MAP_FAILED) | 96 | if (address == MAP_FAILED) |
91 | fatal("mmap(%lu): %s", (u_long)size, strerror(errno)); | 97 | fatal("mmap(%lu): %s", (u_long)size, strerror(errno)); |
92 | #else | ||
93 | fatal("%s: UsePrivilegeSeparation=yes and Compression=yes not supported", | ||
94 | __func__); | ||
95 | #endif | ||
96 | 98 | ||
97 | mm->address = address; | 99 | mm->address = address; |
98 | mm->size = size; | 100 | mm->size = size; |
@@ -130,7 +132,7 @@ mm_destroy(struct mm_master *mm) | |||
130 | mm_freelist(mm->mmalloc, &mm->rb_free); | 132 | mm_freelist(mm->mmalloc, &mm->rb_free); |
131 | mm_freelist(mm->mmalloc, &mm->rb_allocated); | 133 | mm_freelist(mm->mmalloc, &mm->rb_allocated); |
132 | 134 | ||
133 | #ifdef HAVE_MMAP_ANON_SHARED | 135 | #ifdef HAVE_MMAP |
134 | if (munmap(mm->address, mm->size) == -1) | 136 | if (munmap(mm->address, mm->size) == -1) |
135 | fatal("munmap(%p, %lu): %s", mm->address, (u_long)mm->size, | 137 | fatal("munmap(%p, %lu): %s", mm->address, (u_long)mm->size, |
136 | strerror(errno)); | 138 | strerror(errno)); |
@@ -165,8 +167,10 @@ mm_malloc(struct mm_master *mm, size_t size) | |||
165 | 167 | ||
166 | if (size == 0) | 168 | if (size == 0) |
167 | fatal("mm_malloc: try to allocate 0 space"); | 169 | fatal("mm_malloc: try to allocate 0 space"); |
170 | if (size > SIZE_T_MAX - MM_MINSIZE + 1) | ||
171 | fatal("mm_malloc: size too big"); | ||
168 | 172 | ||
169 | size = ((size + MM_MINSIZE - 1) / MM_MINSIZE) * MM_MINSIZE; | 173 | size = ((size + (MM_MINSIZE - 1)) / MM_MINSIZE) * MM_MINSIZE; |
170 | 174 | ||
171 | RB_FOREACH(mms, mmtree, &mm->rb_free) { | 175 | RB_FOREACH(mms, mmtree, &mm->rb_free) { |
172 | if (mms->size >= size) | 176 | if (mms->size >= size) |