Merge from subtype.
[cacao.git] / src / mm / memory.c
index b9af053d2d5ad1f66630480cca2bcc8cfe335ae0..0774aee016228547abfe7b8d919478d22a72dc4a 100644 (file)
@@ -1,7 +1,7 @@
 /* src/mm/memory.c - memory management
 
    Copyright (C) 1996-2005, 2006, 2007, 2008
-   CACAOVM - Verein zu Foerderung der freien virtuellen Machine CACAO
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
 
    This file is part of CACAO.
 
 #include "config.h"
 
 #include <assert.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
+#include <stdint.h>
 
 #if defined(__DARWIN__)
 /* If we compile with -ansi on darwin, <sys/types.h> is not
 
 #include "mm/memory.h"
 
-#include "native/native.h"
+#include "native/native.hpp"
 
-#include "threads/lock-common.h"
-#include "threads/threads-common.h"
+#include "threads/lock.hpp"
+#include "threads/thread.hpp"
 
 #include "toolbox/logging.h"
 
-#include "vm/exceptions.h"
 #include "vm/global.h"
-#include "vm/stringlocal.h"
-#include "vm/vm.h"
+#include "vm/string.hpp"
+#include "vm/vm.hpp"
 
-#include "vmcore/options.h"
+#include "vm/options.h"
+#include "vm/os.hpp"
 
 #if defined(ENABLE_STATISTICS)
-# include "vmcore/statistics.h"
+# include "vm/statistics.h"
 #endif
 
-#include "vmcore/system.h"
-
 
 /* memory_mprotect *************************************************************
 
@@ -74,9 +68,8 @@
 
 void memory_mprotect(void *addr, size_t len, int prot)
 {
-       if (system_mprotect(addr, len, prot) != 0)
-               vm_abort("memory_mprotect: system_mprotect failed: %s",
-                                strerror(errno));
+       if (os_mprotect(addr, len, prot) != 0)
+               vm_abort_errno("memory_mprotect: os_mprotect failed");
 }
 
 
@@ -93,7 +86,7 @@ void *memory_checked_alloc(size_t size)
 {
        /* always allocate memory zeroed out */
 
-       void *p = calloc(size, 1);
+       void *p = os_calloc(size, 1);
 
        if (p == NULL)
                vm_abort("memory_checked_alloc: calloc failed: out of memory");
@@ -102,7 +95,7 @@ void *memory_checked_alloc(size_t size)
 }
 
 
-void *mem_alloc(s4 size)
+void *mem_alloc(int32_t size)
 {
        void *m;
 
@@ -130,7 +123,7 @@ void *mem_alloc(s4 size)
 }
 
 
-void *mem_realloc(void *src, s4 len1, s4 len2)
+void *mem_realloc(void *src, int32_t len1, int32_t len2)
 {
        void *dst;
 
@@ -149,7 +142,7 @@ void *mem_realloc(void *src, s4 len1, s4 len2)
 
 #if defined(ENABLE_MEMCHECK)
        if (len2 < len1)
-               memset((u1*)dst + len2, MEMORY_CLEAR_BYTE, len1 - len2);
+               os_memset((u1*)dst + len2, MEMORY_CLEAR_BYTE, len1 - len2);
 #endif
 
        dst = realloc(src, len2);
@@ -159,14 +152,14 @@ void *mem_realloc(void *src, s4 len1, s4 len2)
 
 #if defined(ENABLE_MEMCHECK)
        if (len2 > len1)
-               memset((u1*)dst + len1, MEMORY_CLEAR_BYTE, len2 - len1);
+               os_memset((u1*)dst + len1, MEMORY_CLEAR_BYTE, len2 - len1);
 #endif
 
        return dst;
 }
 
 
-void mem_free(void *m, s4 size)
+void mem_free(void *m, int32_t size)
 {
        if (!m) {
                if (size == 0)
@@ -183,10 +176,10 @@ void mem_free(void *m, s4 size)
 
 #if defined(ENABLE_MEMCHECK)
        /* destroy the contents */
-       memset(m, MEMORY_CLEAR_BYTE, size);
+       os_memset(m, MEMORY_CLEAR_BYTE, size);
 #endif
 
-       free(m);
+       os_free(m);
 }
 
 
@@ -201,6 +194,10 @@ static void memory_thread(void)
 {
        int32_t seconds;
 
+       /* Prevent compiler warning. */
+
+       seconds = 1;
+
        /* If both arguments are specified, use the value of
           ProfileMemoryUsage. */