-/* $OpenBSD: monitor_mm.c,v 1.18 2013/11/08 00:39:15 djm Exp $ */
+/* $OpenBSD: monitor_mm.c,v 1.19 2014/01/04 17:50:55 tedu Exp $ */
/*
* Copyright 2002 Niels Provos <provos@citi.umich.edu>
* All rights reserved.
#include <errno.h>
#include <stdarg.h>
+#include <stddef.h>
#include <stdlib.h>
#include <string.h>
static int
mm_compare(struct mm_share *a, struct mm_share *b)
{
- long diff = (char *)a->address - (char *)b->address;
+ ptrdiff_t diff = (char *)a->address - (char *)b->address;
if (diff == 0)
return (0);
tmp2 = RB_INSERT(mmtree, head, tmp);
if (tmp2 != NULL)
- fatal("mm_make_entry(%p): double address %p->%p(%lu)",
- mm, tmp2, address, (u_long)size);
+ fatal("mm_make_entry(%p): double address %p->%p(%zu)",
+ mm, tmp2, address, size);
return (tmp);
}
mm->mmalloc = mmalloc;
address = mmap(NULL, size, PROT_WRITE|PROT_READ, MAP_ANON|MAP_SHARED,
- -1, (off_t)0);
+ -1, 0);
if (address == MAP_FAILED)
- fatal("mmap(%lu): %s", (u_long)size, strerror(errno));
+ fatal("mmap(%zu): %s", size, strerror(errno));
mm->address = address;
mm->size = size;
mm_freelist(mm->mmalloc, &mm->rb_allocated);
if (munmap(mm->address, mm->size) == -1)
- fatal("munmap(%p, %lu): %s", mm->address, (u_long)mm->size,
+ fatal("munmap(%p, %zu): %s", mm->address, mm->size,
strerror(errno));
if (mm->mmalloc == NULL)
free(mm);
address = mm_malloc(mm, size);
if (address == NULL)
- fatal("%s: mm_malloc(%lu)", __func__, (u_long)size);
+ fatal("%s: mm_malloc(%zu)", __func__, size);
memset(address, 0, size);
return (address);
}
/* Does not change order in RB tree */
mms->size -= size;
- mms->address = (u_char *)mms->address + size;
+ mms->address = (char *)mms->address + size;
if (mms->size == 0) {
RB_REMOVE(mmtree, &mm->rb_free, mms);
/* Check if range does not overlap */
if (prev != NULL && MM_ADDRESS_END(prev) > address)
- fatal("mm_free: memory corruption: %p(%lu) > %p",
- prev->address, (u_long)prev->size, address);
+ fatal("mm_free: memory corruption: %p(%zu) > %p",
+ prev->address, prev->size, address);
/* See if we can merge backwards */
if (prev != NULL && MM_ADDRESS_END(prev) == address) {
return;
if (MM_ADDRESS_END(prev) > mms->address)
- fatal("mm_free: memory corruption: %p < %p(%lu)",
- mms->address, prev->address, (u_long)prev->size);
+ fatal("mm_free: memory corruption: %p < %p(%zu)",
+ mms->address, prev->address, prev->size);
if (MM_ADDRESS_END(prev) != mms->address)
return;
void
mm_memvalid(struct mm_master *mm, void *address, size_t size)
{
- void *end = (u_char *)address + size;
+ void *end = (char *)address + size;
if (address < mm->address)
fatal("mm_memvalid: address too small: %p", address);
if (end < address)
fatal("mm_memvalid: end < address: %p < %p", end, address);
- if (end > (void *)((u_char *)mm->address + mm->size))
+ if (end > MM_ADDRESS_END(mm))
fatal("mm_memvalid: address too large: %p", address);
}
-/* $OpenBSD: xmalloc.c,v 1.28 2013/05/17 00:13:14 djm Exp $ */
+/* $OpenBSD: xmalloc.c,v 1.29 2014/01/04 17:50:55 tedu Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
fatal("xmalloc: zero size");
ptr = malloc(size);
if (ptr == NULL)
- fatal("xmalloc: out of memory (allocating %lu bytes)", (u_long) size);
+ fatal("xmalloc: out of memory (allocating %zu bytes)", size);
return ptr;
}
fatal("xcalloc: nmemb * size > SIZE_T_MAX");
ptr = calloc(nmemb, size);
if (ptr == NULL)
- fatal("xcalloc: out of memory (allocating %lu bytes)",
- (u_long)(size * nmemb));
+ fatal("xcalloc: out of memory (allocating %zu bytes)",
+ size * nmemb);
return ptr;
}
else
new_ptr = realloc(ptr, new_size);
if (new_ptr == NULL)
- fatal("xrealloc: out of memory (new_size %lu bytes)",
- (u_long) new_size);
+ fatal("xrealloc: out of memory (new_size %zu bytes)",
+ new_size);
return new_ptr;
}