]> andersk Git - openssh.git/blobdiff - monitor_mm.c
- (djm) [platform.h] Add missing prototype for
[openssh.git] / monitor_mm.c
index f72a180ea80a46f78d01c711a95a4506d7c9fa5c..faf9f3dcb4f6e9eadd14732c5d77e36c37a6fd18 100644 (file)
@@ -1,3 +1,4 @@
+/* $OpenBSD: monitor_mm.c,v 1.16 2009/06/22 05:39:28 dtucker Exp $ */
 /*
  * Copyright 2002 Niels Provos <provos@citi.umich.edu>
  * All rights reserved.
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: monitor_mm.c,v 1.7 2002/06/28 01:49:31 millert Exp $");
 
+#include <sys/types.h>
 #ifdef HAVE_SYS_MMAN_H
 #include <sys/mman.h>
 #endif
+#include <sys/param.h>
+#include "openbsd-compat/sys-tree.h"
+
+#include <errno.h>
+#include <stdarg.h>
+#include <string.h>
 
-#include "ssh.h"
 #include "xmalloc.h"
+#include "ssh.h"
 #include "log.h"
 #include "monitor_mm.h"
 
@@ -91,15 +98,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);
-       if (address == MAP_FAILED)
+       address = xmmap(size);
+       if (address == (void *)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;
@@ -137,7 +138,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));
@@ -172,8 +173,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)
This page took 0.091367 seconds and 4 git commands to generate.