[Mono-list] [PATCH] Hack tramp-x86.c to work with exec-shield[-nx] for 2.6.7

Omar Kilani omar@tinysofa.org
Fri, 25 Jun 2004 16:41:07 +1000


This is a multi-part message in MIME format.
--------------090905070700060601090101
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Hello,

mono/mini/tramp-x86.c interacts badly with Ingo Molnar's 
exec-shield[-nx] patches for 2.6.7 (as found at 
http://people.redhat.com/mingo/exec-shield/)

The attached patch hacks around this issue, and makes mono run... at least.

Thanks to lupus for instructions on how to fix this.

Regards,
Omar Kilani

--------------090905070700060601090101
Content-Type: text/plain;
 name="mono-0.96-exec-shield-hack.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="mono-0.96-exec-shield-hack.patch"

diff -urN mono-0.96/mono/mini/tramp-x86.c mono-0.96.exec-shield-hack/mono/mini/tramp-x86.c
--- mono-0.96/mono/mini/tramp-x86.c	2004-05-20 03:25:35.000000000 +1000
+++ mono-0.96.exec-shield-hack/mono/mini/tramp-x86.c	2004-06-25 00:26:48.384066160 +1000
@@ -15,6 +15,7 @@
 #include <mono/metadata/tabledefs.h>
 #include <mono/arch/x86/x86-codegen.h>
 #include <mono/metadata/mono-debug-debugger.h>
+#include <mono/utils/mono-codeman.h>
 
 #ifdef HAVE_VALGRIND_MEMCHECK_H
 #include <valgrind/memcheck.h>
@@ -23,6 +24,14 @@
 #include "mini.h"
 #include "mini-x86.h"
 
+static MonoCodeManager *mono_code_man = NULL;
+
+void *mono_code_man_alloc(int size) {
+	if (!mono_code_man)
+		 mono_code_man = mono_code_manager_new(); 
+	return mono_code_manager_reserve(mono_code_man, size);
+}
+
 typedef enum {
 	MONO_TRAMPOLINE_GENERIC,
 	MONO_TRAMPOLINE_JUMP,
@@ -56,7 +65,7 @@
 	if (!m->signature->ret->byref && MONO_TYPE_ISSTRUCT (m->signature->ret))
 		this_pos = 8;
 	    
-	start = code = g_malloc (16);
+	start = code = mono_code_man_alloc (16);
 
 	x86_alu_membase_imm (code, X86_ADD, X86_ESP, this_pos, sizeof (MonoObject));
 	x86_jump_code (code, addr);
@@ -267,7 +276,7 @@
 		break;
 	}
 
-	code = buf = g_malloc (256);
+	code = buf = mono_code_man_alloc (256);
 	/* save caller save regs because we need to do a call */ 
 	x86_push_reg (buf, X86_EDX);
 	x86_push_reg (buf, X86_EAX);
@@ -374,7 +383,7 @@
 	
 	tramp = create_trampoline_code (MONO_TRAMPOLINE_JUMP);
 
-	code = buf = g_malloc (TRAMPOLINE_SIZE);
+	code = buf = mono_code_man_alloc (TRAMPOLINE_SIZE);
 	x86_push_imm (buf, method);
 	x86_jump_code (buf, tramp);
 	g_assert ((buf - code) <= TRAMPOLINE_SIZE);
@@ -417,7 +426,7 @@
 
 	tramp = create_trampoline_code (MONO_TRAMPOLINE_GENERIC);
 
-	code = buf = g_malloc (TRAMPOLINE_SIZE);
+	code = buf = mono_code_man_alloc (TRAMPOLINE_SIZE);
 	x86_push_imm (buf, method);
 	x86_jump_code (buf, tramp);
 	g_assert ((buf - code) <= TRAMPOLINE_SIZE);
@@ -448,7 +457,7 @@
 
 	tramp = create_trampoline_code (MONO_TRAMPOLINE_CLASS_INIT);
 
-	code = buf = g_malloc (TRAMPOLINE_SIZE);
+	code = buf = mono_code_man_alloc (TRAMPOLINE_SIZE);
 	x86_push_imm (buf, vtable);
 	x86_jump_code (buf, tramp);
 	g_assert ((buf - code) <= TRAMPOLINE_SIZE);
@@ -466,7 +475,8 @@
 {
 	guint8 *ptr, *buf;
 
-	ptr = buf = g_malloc0 (16);
+	ptr = buf = mono_code_man_alloc (16);
+	memset(ptr, 0, 16);
 	x86_breakpoint (buf);
 	if (notification_address)
 		*notification_address = buf;

--------------090905070700060601090101--