diff options
author | des <des@FreeBSD.org> | 2002-10-29 09:43:00 +0000 |
---|---|---|
committer | des <des@FreeBSD.org> | 2002-10-29 09:43:00 +0000 |
commit | 099d1a58f7bc088a9f71af6d32542ca3949468a3 (patch) | |
tree | 49cef8938d7beb10016662d15546fa090865073d /crypto/openssh/monitor_mm.c | |
parent | 1ba793a7c09e24d920de3983a3223770cb37ebff (diff) | |
download | FreeBSD-src-099d1a58f7bc088a9f71af6d32542ca3949468a3.zip FreeBSD-src-099d1a58f7bc088a9f71af6d32542ca3949468a3.tar.gz |
Vendor import of OpenSSH-portable 3.5p1.
Diffstat (limited to 'crypto/openssh/monitor_mm.c')
-rw-r--r-- | crypto/openssh/monitor_mm.c | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/crypto/openssh/monitor_mm.c b/crypto/openssh/monitor_mm.c index c363036..b4a6e40 100644 --- a/crypto/openssh/monitor_mm.c +++ b/crypto/openssh/monitor_mm.c @@ -24,12 +24,13 @@ */ #include "includes.h" -RCSID("$OpenBSD: monitor_mm.c,v 1.6 2002/06/04 23:05:49 markus Exp $"); +RCSID("$OpenBSD: monitor_mm.c,v 1.8 2002/08/02 14:43:15 millert Exp $"); #ifdef HAVE_SYS_MMAN_H #include <sys/mman.h> #endif +#include "openbsd-compat/xmmap.h" #include "ssh.h" #include "xmalloc.h" #include "log.h" @@ -38,7 +39,14 @@ RCSID("$OpenBSD: monitor_mm.c,v 1.6 2002/06/04 23:05:49 markus Exp $"); static int mm_compare(struct mm_share *a, struct mm_share *b) { - return ((char *)a->address - (char *)b->address); + long diff = (char *)a->address - (char *)b->address; + + if (diff == 0) + return (0); + else if (diff < 0) + return (-1); + else + return (1); } RB_GENERATE(mmtree, mm_share, next, mm_compare) @@ -84,15 +92,9 @@ mm_create(struct mm_master *mmalloc, size_t size) */ mm->mmalloc = mmalloc; -#ifdef HAVE_MMAP_ANON_SHARED - address = mmap(NULL, size, PROT_WRITE|PROT_READ, MAP_ANON|MAP_SHARED, - -1, 0); + address = xmmap(size); if (address == MAP_FAILED) fatal("mmap(%lu): %s", (u_long)size, strerror(errno)); -#else - fatal("%s: UsePrivilegeSeparation=yes and Compression=yes not supported", - __func__); -#endif mm->address = address; mm->size = size; @@ -130,7 +132,7 @@ mm_destroy(struct mm_master *mm) mm_freelist(mm->mmalloc, &mm->rb_free); mm_freelist(mm->mmalloc, &mm->rb_allocated); -#ifdef HAVE_MMAP_ANON_SHARED +#ifdef HAVE_MMAP if (munmap(mm->address, mm->size) == -1) fatal("munmap(%p, %lu): %s", mm->address, (u_long)mm->size, strerror(errno)); @@ -165,8 +167,10 @@ mm_malloc(struct mm_master *mm, size_t size) if (size == 0) fatal("mm_malloc: try to allocate 0 space"); + if (size > SIZE_T_MAX - MM_MINSIZE + 1) + fatal("mm_malloc: size too big"); - size = ((size + MM_MINSIZE - 1) / MM_MINSIZE) * MM_MINSIZE; + size = ((size + (MM_MINSIZE - 1)) / MM_MINSIZE) * MM_MINSIZE; RB_FOREACH(mms, mmtree, &mm->rb_free) { if (mms->size >= size) |