-#if defined(__native_client_codegen__) && defined(__native_client__)
-/* End of text segment, set by linker.
- * Dynamic text starts on the next allocated page.
- */
-extern char etext[];
-char *next_dynamic_code_addr = NULL;
-
-/*
- * This routine gets the next available bundle aligned
- * pointer in the dynamic code section. It does not check
- * for the section end, this error will be caught in the
- * service runtime.
- */
-void*
-allocate_code(intptr_t increment)
-{
- char *addr;
- if (increment < 0) return NULL;
- increment = increment & kNaClBundleMask ? (increment & ~kNaClBundleMask) + kNaClBundleSize : increment;
- addr = next_dynamic_code_addr;
- next_dynamic_code_addr += increment;
- return addr;
-}
-
-int
-nacl_is_code_address (void *target)
-{
- return (char *)target < next_dynamic_code_addr;
-}
-
-/* Fill code buffer with arch-specific NOPs. */
-void
-mono_nacl_fill_code_buffer (guint8 *data, int size);
-
-#ifndef USE_JUMP_TABLES
-const int kMaxPatchDepth = 32;
-__thread unsigned char **patch_source_base = NULL;
-__thread unsigned char **patch_dest_base = NULL;
-__thread int *patch_alloc_size = NULL;
-__thread int patch_current_depth = -1;
-__thread int allow_target_modification = 1;
-
-static void
-nacl_jit_check_init ()
-{
- if (patch_source_base == NULL) {
- patch_source_base = g_malloc (kMaxPatchDepth * sizeof(unsigned char *));
- patch_dest_base = g_malloc (kMaxPatchDepth * sizeof(unsigned char *));
- patch_alloc_size = g_malloc (kMaxPatchDepth * sizeof(int));
- }
-}
-#endif
-
-void
-nacl_allow_target_modification (int val)
-{
-#ifndef USE_JUMP_TABLES
- allow_target_modification = val;
-#endif /* USE_JUMP_TABLES */
-}
-
-/* Given a patch target, modify the target such that patching will work when
- * the code is copied to the data section.
- */
-void*
-nacl_modify_patch_target (unsigned char *target)
-{
- /*
- * There's no need in patch tricks for jumptables,
- * as we always patch same jumptable.
- */
-#ifndef USE_JUMP_TABLES
- /* This seems like a bit of an ugly way to do this but the advantage
- * is we don't have to worry about all the conditions in
- * mono_resolve_patch_target, and it can be used by all the bare uses
- * of <arch>_patch.
- */
- unsigned char *sb;
- unsigned char *db;
-
- if (!allow_target_modification) return target;
-
- nacl_jit_check_init ();
- sb = patch_source_base[patch_current_depth];
- db = patch_dest_base[patch_current_depth];
-
- if (target >= sb && (target < sb + patch_alloc_size[patch_current_depth])) {
- /* Do nothing. target is in the section being generated.
- * no need to modify, the disp will be the same either way.
- */
- } else {
- int target_offset = target - db;
- target = sb + target_offset;
- }
-#endif
- return target;
-}
-
-void*
-nacl_inverse_modify_patch_target (unsigned char *target)
-{
- /*
- * There's no need in patch tricks for jumptables,
- * as we always patch same jumptable.
- */
-#ifndef USE_JUMP_TABLES
- unsigned char *sb;
- unsigned char *db;
- int target_offset;
-
- if (!allow_target_modification) return target;
-
- nacl_jit_check_init ();
- sb = patch_source_base[patch_current_depth];
- db = patch_dest_base[patch_current_depth];
-
- target_offset = target - sb;
- target = db + target_offset;
-#endif
- return target;
-}
-
-
-#endif /* __native_client_codegen && __native_client__ */
-