+
+/*
+ * Function: initAdjustor()
+ *
+ * Perform initialisation of adjustor thunk layer (if needed.)
+ */
+rtsBool
+initAdjustor(void)
+{
+#if defined(i386_TARGET_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 = stgMallocBytes(4, "initAdjustor");
+
+ 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 */
+
+ execPage(obscure_ccall_ret_code, pageExecuteRead);
+#endif
+ return rtsTrue;
+}