-/* Copyright (C) 2012-2013
- Free Software Foundation
+/* Copyright (C) 2012-2020 Free Software Foundation, Inc.
This file is part of GCC.
#include <stdlib.h>
#include <unistd.h>
+#if defined (__CYGWIN__) || defined (__MINGW32__)
+#include <windows.h>
+#else
#include <sys/mman.h>
+#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
static size_t current_chunk_size VTV_PROTECTED_VAR = 0;
static int malloc_initialized VTV_PROTECTED_VAR = 0;
+#if defined (__CYGWIN__) || defined (__MINGW32__)
+//sysconf(_SC_PAGE_SIZE) port
+long sysconf_SC_PAGE_SIZE()
+{
+ SYSTEM_INFO si;
+ GetSystemInfo(&si);
+ long pageSize = (long)si.dwPageSize;
+ return pageSize;
+ //return 4096; // standard usermode 32bit pagesize in bytes // FIXME
+}
+#endif
+
/* The function goes through and counts all the pages we have allocated
so far. It returns the page count. */
}
#ifdef VTV_DEBUG
- VTV_malloc_dump_stats ();
+ __vtv_malloc_dump_stats ();
#endif
}
VTV_DEBUG_ASSERT ((size & (VTV_PAGE_SIZE - 1)) == 0);
void *allocated;
+#if defined (__CYGWIN__) || defined (__MINGW32__)
+ if ((allocated = VirtualAlloc(NULL, size, MEM_RESERVE|MEM_COMMIT,
+ PAGE_READWRITE)) == 0)
+#else
if ((allocated = mmap (NULL, size, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)) == 0)
+#endif
VTV_error ();
VTV_DEBUG_ASSERT (((unsigned long) allocated & (VTV_PAGE_SIZE - 1)) == 0);
}
static void
-obstack_chunk_free (size_t)
+obstack_chunk_free (void *)
{
/* Do nothing. For our purposes there should be very little
de-allocation. */
if (malloc_initialized)
return;
+#if defined (__CYGWIN__) || defined (__MINGW32__)
+ if (VTV_PAGE_SIZE != sysconf_SC_PAGE_SIZE())
+#else
if (VTV_PAGE_SIZE != sysconf (_SC_PAGE_SIZE))
+#endif
VTV_error ();
- obstack_chunk_size (&vtv_obstack) = VTV_PAGE_SIZE;
- obstack_alignment_mask (&vtv_obstack) = sizeof (long) - 1;
/* We guarantee that the obstack alloc failed handler will never be
called because in case the allocation of the chunk fails, it will
never return */
obstack_alloc_failed_handler = NULL;
- obstack_init (&vtv_obstack);
+ obstack_specify_allocation (&vtv_obstack, VTV_PAGE_SIZE, sizeof (long),
+ obstack_chunk_alloc, obstack_chunk_free);
malloc_initialized = 1;
}