static char*
aligned_address (char *mem, size_t size, size_t alignment)
{
- char *aligned = (char*)((gulong)(mem + (alignment - 1)) & ~(alignment - 1));
- g_assert (aligned >= mem && aligned + size <= mem + size + alignment && !((gulong)aligned & (alignment - 1)));
+ char *aligned = (char*)((size_t)(mem + (alignment - 1)) & ~(alignment - 1));
+ g_assert (aligned >= mem && aligned + size <= mem + size + alignment && !((size_t)aligned & (alignment - 1)));
return aligned;
}
mono_valloc (void *addr, size_t length, int flags)
{
void *ptr;
- int mflags = MEM_COMMIT;
+ int mflags = MEM_RESERVE|MEM_COMMIT;
int prot = prot_from_flags (flags);
/* translate the flags */
void*
mono_shared_area (void)
{
+ if (!malloced_shared_area)
+ malloced_shared_area = malloc_shared_area (0);
/* get the pid here */
- return malloc_shared_area (0);
+ return malloced_shared_area;
}
void
{
if (malloced_shared_area)
g_free (malloced_shared_area);
+ malloced_shared_area = NULL;
}
void*
mflags |= MAP_PRIVATE;
ptr = mmap (addr, length, prot, mflags, -1, 0);
- if (ptr == (void*)-1) {
+ if (ptr == MAP_FAILED) {
int fd = open ("/dev/zero", O_RDONLY);
if (fd != -1) {
ptr = mmap (addr, length, prot, mflags, fd, 0);
close (fd);
}
- if (ptr == (void*)-1)
+ if (ptr == MAP_FAILED)
return NULL;
}
return ptr;
mflags |= MAP_32BIT;
ptr = mmap (0, length, prot, mflags, fd, offset);
- if (ptr == (void*)-1)
+ if (ptr == MAP_FAILED)
return NULL;
*ret_handle = (void*)length;
return ptr;
*
* Returns: 0 on success.
*/
+#if defined(__native_client__)
+int
+mono_mprotect (void *addr, size_t length, int flags)
+{
+ int prot = prot_from_flags (flags);
+ void *new_addr;
+
+ if (flags & MONO_MMAP_DISCARD) memset (addr, 0, length);
+
+ new_addr = mmap(addr, length, prot, MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOUS, -1, 0);
+ if (new_addr == addr) return 0;
+ return -1;
+}
+#else
int
mono_mprotect (void *addr, size_t length, int flags)
{
}
return mprotect (addr, length, prot);
}
+#endif // __native_client__
#else
#if defined(HAVE_SHM_OPEN) && !defined (DISABLE_SHARED_PERFCOUNTERS)
+static int use_shared_area;
+
+static gboolean
+shared_area_disabled (void)
+{
+ if (!use_shared_area) {
+ if (g_getenv ("MONO_DISABLE_SHARED_AREA"))
+ use_shared_area = -1;
+ else
+ use_shared_area = 1;
+ }
+ return use_shared_area == -1;
+}
+
static int
mono_shared_area_instances_slow (void **array, int count, gboolean cleanup)
{
void *res;
SAreaHeader *header;
+ if (shared_area_disabled ()) {
+ if (!malloced_shared_area)
+ malloced_shared_area = malloc_shared_area (0);
+ /* get the pid here */
+ return malloced_shared_area;
+ }
+
/* perform cleanup of segments left over from dead processes */
mono_shared_area_instances_helper (NULL, 0, TRUE);
mono_shared_area_remove (void)
{
char buf [128];
+
+ if (shared_area_disabled ()) {
+ if (malloced_shared_area)
+ g_free (malloced_shared_area);
+ return;
+ }
+
g_snprintf (buf, sizeof (buf), "/mono.%d", getpid ());
shm_unlink (buf);
if (malloced_shared_area)
char buf [128];
void *res;
+ if (shared_area_disabled ())
+ return NULL;
+
g_snprintf (buf, sizeof (buf), "/mono.%d", GPOINTER_TO_INT (pid));
fd = shm_open (buf, O_RDONLY, S_IRUSR|S_IRGRP);
void*
mono_shared_area (void)
{
- return malloc_shared_area (getpid ());
+ if (!malloced_shared_area)
+ malloced_shared_area = malloc_shared_area (getpid ());
+ /* get the pid here */
+ return malloced_shared_area;
}
void