From: simonmar Date: Thu, 10 Mar 2005 14:47:33 +0000 (+0000) Subject: [project @ 2005-03-10 14:47:33 by simonmar] X-Git-Tag: Initial_conversion_from_CVS_complete~922 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=59765e871b2ab6f5bf898c09533d1fac7996181a;p=ghc-hetmet.git [project @ 2005-03-10 14:47:33 by simonmar] x86: For some reason the code for obscure_ccall_ret_code was allocated dynamically and specified using literal bytes rather than inline assembly. Change it to use inline assembly. --- diff --git a/ghc/rts/Adjustor.c b/ghc/rts/Adjustor.c index 59119bf..afb9ac0 100644 --- a/ghc/rts/Adjustor.c +++ b/ghc/rts/Adjustor.c @@ -95,7 +95,30 @@ mallocBytesRWX(int len) } #if defined(i386_HOST_ARCH) -static unsigned char *obscure_ccall_ret_code; +/* + Now here's something obscure for you: + + When generating an adjustor thunk that uses the C calling + convention, we have to make sure that the thunk kicks off + the process of jumping into Haskell with a tail jump. Why? + Because as a result of jumping in into Haskell we may end + up freeing the very adjustor thunk we came from using + freeHaskellFunctionPtr(). Hence, we better not return to + the adjustor code on our way out, since it could by then + point to junk. + + The fix is readily at hand, just include the opcodes + for the C stack fixup code that we need to perform when + returning in some static piece of memory and arrange + to return to it before tail jumping from the adjustor thunk. +*/ +__asm__ ( + ".globl obscure_ccall_ret_code\n" + "obscure_ccall_ret_code:\n\t" + "addl $0x4, %esp\n\t" + "ret" + ); +extern void obscure_ccall_ret_code(void); #endif #if defined(alpha_HOST_ARCH) @@ -906,30 +929,4 @@ freeHaskellFunctionPtr(void* ptr) void initAdjustor(void) { -#if defined(i386_HOST_ARCH) - /* Now here's something obscure for you: - - When generating an adjustor thunk that uses the C calling - convention, we have to make sure that the thunk kicks off - the process of jumping into Haskell with a tail jump. Why? - Because as a result of jumping in into Haskell we may end - up freeing the very adjustor thunk we came from using - freeHaskellFunctionPtr(). Hence, we better not return to - the adjustor code on our way out, since it could by then - point to junk. - - The fix is readily at hand, just include the opcodes - for the C stack fixup code that we need to perform when - returning in some static piece of memory and arrange - to return to it before tail jumping from the adjustor thunk. - */ - - obscure_ccall_ret_code = mallocBytesRWX(4); - - obscure_ccall_ret_code[0x00] = (unsigned char)0x83; /* addl $0x4, %esp */ - obscure_ccall_ret_code[0x01] = (unsigned char)0xc4; - obscure_ccall_ret_code[0x02] = (unsigned char)0x04; - - obscure_ccall_ret_code[0x03] = (unsigned char)0xc3; /* ret */ -#endif }