#include "mono-codeman.h"
#include "mono-mmap.h"
+#include "mono-counters.h"
#include "dlmalloc.h"
#include <mono/metadata/class-internals.h>
#include <mono/metadata/profiler-private.h>
#if defined(__native_client_codegen__) && defined(__native_client__)
#include <malloc.h>
-#include <sys/nacl_syscalls.h>
+#include <nacl/nacl_dyncode.h>
#endif
+static uintptr_t code_memory_used = 0;
+
/*
* AMD64 processors maintain icache coherency only for pages which are
* marked executable. Also, windows DEP requires us to obtain executable memory from
CodeChunk *current;
CodeChunk *full;
#if defined(__native_client_codegen__) && defined(__native_client__)
- MonoGHashTable *hash;
+ GHashTable *hash;
#endif
};
if (next_dynamic_code_addr == NULL) {
const guint kPageMask = 0xFFFF; /* 64K pages */
next_dynamic_code_addr = (uintptr_t)(etext + kPageMask) & ~kPageMask;
+#if defined (__GLIBC__)
+ /* TODO: For now, just jump 64MB ahead to avoid dynamic libraries. */
+ next_dynamic_code_addr += (uintptr_t)0x4000000;
+#else
/* Workaround bug in service runtime, unable to allocate */
/* from the first page in the dynamic code section. */
- /* TODO: remove */
next_dynamic_code_addr += (uintptr_t)0x10000;
+#endif
}
- cman->hash = mono_g_hash_table_new (NULL, NULL);
- /* Keep the hash table from being collected */
- mono_gc_register_root (&cman->hash, sizeof (void*), NULL);
+ cman->hash = g_hash_table_new (NULL, NULL);
if (patch_source_base == NULL) {
patch_source_base = g_malloc (kMaxPatchDepth * sizeof(unsigned char *));
patch_dest_base = g_malloc (kMaxPatchDepth * sizeof(unsigned char *));
} else if (dead->flags == CODE_FLAG_MALLOC) {
dlfree (dead->data);
}
+ code_memory_used -= dead->size;
free (dead);
}
}
chunk->bsize = bsize;
mono_profiler_code_chunk_new((gpointer) chunk->data, chunk->size);
+ code_memory_used += chunk_size;
+ mono_runtime_resource_check_limit (MONO_RESOURCE_JIT_CODE, code_memory_used);
/*printf ("code chunk at: %p\n", ptr);*/
return chunk;
}
/* Allocate code space from the service runtime */
code_ptr = allocate_code (size);
/* Insert pointer to code space in hash, keyed by buffer ptr */
- mono_g_hash_table_insert (cman->hash, temp_ptr, code_ptr);
+ g_hash_table_insert (cman->hash, temp_ptr, code_ptr);
nacl_jit_check_init ();
unsigned char *code;
int status;
g_assert (newsize <= size);
- code = mono_g_hash_table_lookup (cman->hash, data);
+ code = g_hash_table_lookup (cman->hash, data);
g_assert (code != NULL);
/* Pad space after code with HLTs */
/* TODO: this is x86/amd64 specific */
}
status = nacl_dyncode_create (code, data, newsize);
if (status != 0) {
+ unsigned char *codep;
+ fprintf(stderr, "Error creating Native Client dynamic code section attempted to be\n"
+ "emitted at %p (hex dissasembly of code follows):\n", code);
+ for (codep = data; codep < data + newsize; codep++)
+ fprintf(stderr, "%02x ", *codep);
+ fprintf(stderr, "\n");
g_assert_not_reached ();
}
- mono_g_hash_table_remove (cman->hash, data);
+ g_hash_table_remove (cman->hash, data);
g_assert (data == patch_source_base[patch_current_depth]);
g_assert (code == patch_dest_base[patch_current_depth]);
patch_current_depth--;
void *
nacl_code_manager_get_code_dest (MonoCodeManager *cman, void *data)
{
- return mono_g_hash_table_lookup (cman->hash, data);
+ return g_hash_table_lookup (cman->hash, data);
}
#endif