i.e. get rid of dirty FFI hacks.
thanks to simonmar:
http://stackoverflow.com/questions/
10967598/get-the-address-of-a-function-without-ffi#comment14326263_10967598
#endif
-foreign import ccall "dynamic"
- code_int :: FunPtr (CInt -> CInt -> IO CInt) -> CInt -> CInt -> IO CInt
-
-foreign import ccall "getMallocObjectAddr"
- getMallocObjectAddr :: CUInt
+foreign import ccall "&mallocObject"
+ mallocObjectAddr :: FunPtr (Int -> IO CUInt)
type EntryPoint = Ptr Word8
type EntryPointOffset = Int
callMalloc :: CodeGen e s ()
callMalloc = do
- calladdr <- getCurrentOffset
- let w32_calladdr = 5 + calladdr
- let malloaddr = fromIntegral getMallocObjectAddr :: Word32
- call (malloaddr - w32_calladdr)
+ call mallocObjectAddr
add esp (4 :: Word32)
push eax
(l) check different types (byte, long, ...)
+(l) get rid of CUInt where appropriate
+ -> CPtrdiff and CSize (ptrdiff_t and size_t) is more portable
+
(l) floating point support
(h) better code generation
#include <sys/ucontext.h>
-unsigned int mallocObject(int);
unsigned int mateHandler(unsigned int, unsigned int, unsigned int, unsigned int);
#ifdef DBG_TRAP
#define dprintf(args...)
#endif
-void mainresult(unsigned int a)
-{
- dprintf("mainresult: 0x%08x\n", a);
-}
-
void chandler(int nSignal, siginfo_t *info, void *ctx)
{
mcontext_t *mctx = &((ucontext_t *) ctx)->uc_mcontext;
segvaction.sa_flags = SA_SIGINFO | SA_RESTART | SA_NODEFER;
sigaction(SIGSEGV, &segvaction, NULL);
}
-
-unsigned int getaddr(void)
-{
- return (unsigned int) mainresult;
-}
-
-unsigned int getMallocObjectAddr(void)
-{
- return (unsigned int) mallocObject;
-}