projects
/
mate.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
e77e74e
)
nativeMaschine: s/unsigned int/ptrdiff_t/g
author
Bernhard Urban
<lewurm@gmail.com>
Tue, 31 Jul 2012 20:22:28 +0000
(22:22 +0200)
committer
Bernhard Urban
<lewurm@gmail.com>
Tue, 31 Jul 2012 20:07:38 +0000
(22:07 +0200)
more portable
Mate/ClassPool.hs
patch
|
blob
|
history
Mate/GarbageAlloc.hs
patch
|
blob
|
history
Mate/MethodPool.hs
patch
|
blob
|
history
Mate/MethodPool.hs-boot
patch
|
blob
|
history
Mate/Strings.hs
patch
|
blob
|
history
Mate/X86CodeGen.hs
patch
|
blob
|
history
Mate/X86TrapHandling.hs
patch
|
blob
|
history
doc/TODO
patch
|
blob
|
history
ffi/trap.c
patch
|
blob
|
history
diff --git
a/Mate/ClassPool.hs
b/Mate/ClassPool.hs
index ad290542d7167c57b8a4a9b29efbd149d71d212b..58ba6c7a6080742870fbd352adeebf5bf24882cd 100644
(file)
--- a/
Mate/ClassPool.hs
+++ b/
Mate/ClassPool.hs
@@
-62,7
+62,7
@@
getClassFile path = do
ci <- getClassInfo path
return $ ciFile ci
ci <- getClassInfo path
return $ ciFile ci
-getStaticFieldOffset :: B.ByteString -> B.ByteString -> IO C
UInt
+getStaticFieldOffset :: B.ByteString -> B.ByteString -> IO C
Ptrdiff
getStaticFieldOffset path field = do
ci <- getClassInfo path
return $ fromIntegral $ ciStaticMap ci M.! field
getStaticFieldOffset path field = do
ci <- getClassInfo path
return $ fromIntegral $ ciStaticMap ci M.! field
@@
-92,7
+92,7
@@
getObjectSize path = do
-- one slot for "method-table-ptr"
return $ (1 + fsize) * 4
-- one slot for "method-table-ptr"
return $ (1 + fsize) * 4
-getStaticFieldAddr :: C
UInt -> IO CUInt
+getStaticFieldAddr :: C
Ptrdiff -> IO CPtrdiff
getStaticFieldAddr from = do
trapmap <- getTrapMap
let w32_from = fromIntegral from
getStaticFieldAddr from = do
trapmap <- getTrapMap
let w32_from = fromIntegral from
diff --git
a/Mate/GarbageAlloc.hs
b/Mate/GarbageAlloc.hs
index 1a272fbaedbbd02265d47a3a72785ab5b755cd8e..56bb8f17a80cde7cfa65808258fdecaa74a907be 100644
(file)
--- a/
Mate/GarbageAlloc.hs
+++ b/
Mate/GarbageAlloc.hs
@@
-24,8
+24,8
@@
mallocString size = do
printfStr "mallocString: %d\n" size
mallocBytes size
printfStr "mallocString: %d\n" size
mallocBytes size
-foreign export ccall mallocObject :: Int -> IO C
UInt
-mallocObject :: Int -> IO C
UInt
+foreign export ccall mallocObject :: Int -> IO C
Ptrdiff
+mallocObject :: Int -> IO C
Ptrdiff
mallocObject size = do
ptr <- mallocBytes size
printfStr "mallocObject: %d\n" size
mallocObject size = do
ptr <- mallocBytes size
printfStr "mallocObject: %d\n" size
diff --git
a/Mate/MethodPool.hs
b/Mate/MethodPool.hs
index 134428a6f539dde5c2057cf02a1123a7610627ea..23ff49b6439757bbb590e63a411ded2de631f7bd 100644
(file)
--- a/
Mate/MethodPool.hs
+++ b/
Mate/MethodPool.hs
@@
-35,7
+35,7
@@
foreign import ccall "dynamic"
code_void :: FunPtr (IO ()) -> IO ()
code_void :: FunPtr (IO ()) -> IO ()
-getMethodEntry :: C
UInt -> CUInt -> IO CUInt
+getMethodEntry :: C
Ptrdiff -> CPtrdiff -> IO CPtrdiff
getMethodEntry signal_from methodtable = do
mmap <- getMethodMap
tmap <- getTrapMap
getMethodEntry signal_from methodtable = do
mmap <- getMethodMap
tmap <- getTrapMap
diff --git
a/Mate/MethodPool.hs-boot
b/Mate/MethodPool.hs-boot
index 477e6ccfee90cd609da103c0010d10ee0d7da363..7efca9c6f1e0ac5c423caa8e1bf2531c71ecb9db 100644
(file)
--- a/
Mate/MethodPool.hs-boot
+++ b/
Mate/MethodPool.hs-boot
@@
-12,4
+12,4
@@
import Foreign.C.Types
addMethodRef :: Word32 -> MethodInfo -> [B.ByteString] -> IO ()
compileBB :: RawMethod -> MethodInfo -> IO Word32
executeFuncPtr :: Word32 -> IO ()
addMethodRef :: Word32 -> MethodInfo -> [B.ByteString] -> IO ()
compileBB :: RawMethod -> MethodInfo -> IO Word32
executeFuncPtr :: Word32 -> IO ()
-getMethodEntry :: C
UInt -> CUInt -> IO CUInt
+getMethodEntry :: C
Ptrdiff -> CPtrdiff -> IO CPtrdiff
diff --git
a/Mate/Strings.hs
b/Mate/Strings.hs
index 3ac7f995401e99c2fb0abda89062f3ea5bd6ebc6..f41f02265c91d31b4d4bb48e40001126248936ed 100644
(file)
--- a/
Mate/Strings.hs
+++ b/
Mate/Strings.hs
@@
-57,7
+57,7
@@
allocateJavaString str = do
fsize <- getObjectSize "java/lang/String"
printfStr "string: fsize: %d (should be 4 * 5)\n" fsize
tblptr <- mallocObject $ fromIntegral fsize
fsize <- getObjectSize "java/lang/String"
printfStr "string: fsize: %d (should be 4 * 5)\n" fsize
tblptr <- mallocObject $ fromIntegral fsize
- let ptr = intPtrToPtr (fromIntegral tblptr) :: Ptr C
UInt
+ let ptr = intPtrToPtr (fromIntegral tblptr) :: Ptr C
Ptrdiff
mtbl <- getMethodTable "java/lang/String"
poke ptr $ fromIntegral mtbl
mtbl <- getMethodTable "java/lang/String"
poke ptr $ fromIntegral mtbl
@@
-70,16
+70,16
@@
allocateJavaString str = do
copyBytes (plusPtr newstr 4) arr strlen
printfStr "new str ptr: (%s)@%d\n" (toString str) strlen
copyBytes (plusPtr newstr 4) arr strlen
printfStr "new str ptr: (%s)@%d\n" (toString str) strlen
- let newstr_length = castPtr newstr :: Ptr C
UInt
+ let newstr_length = castPtr newstr :: Ptr C
Ptrdiff
poke newstr_length $ fromIntegral strlen
-- set value pointer
poke newstr_length $ fromIntegral strlen
-- set value pointer
- poke (plusPtr ptr 4) (fromIntegral (ptrToIntPtr newstr) :: C
UInt
)
+ poke (plusPtr ptr 4) (fromIntegral (ptrToIntPtr newstr) :: C
Ptrdiff
)
-- set count field
-- set count field
- poke (plusPtr ptr 8) (fromIntegral strlen :: C
UInt
)
+ poke (plusPtr ptr 8) (fromIntegral strlen :: C
Ptrdiff
)
-- set hash code (TODO)
-- set hash code (TODO)
- poke (plusPtr ptr 12) (0 :: C
UInt
)
+ poke (plusPtr ptr 12) (0 :: C
Ptrdiff
)
-- set offset
-- set offset
- poke (plusPtr ptr 16) (0 :: C
UInt
)
+ poke (plusPtr ptr 16) (0 :: C
Ptrdiff
)
return $ fromIntegral tblptr
return $ fromIntegral tblptr
diff --git
a/Mate/X86CodeGen.hs
b/Mate/X86CodeGen.hs
index df39e5f858c7251057912d1167bfdc6c3a25922c..b2de573f619ad09672aec54e63b0ca6530e3f1f7 100644
(file)
--- a/
Mate/X86CodeGen.hs
+++ b/
Mate/X86CodeGen.hs
@@
-34,7
+34,7
@@
import Text.Printf
foreign import ccall "&mallocObject"
foreign import ccall "&mallocObject"
- mallocObjectAddr :: FunPtr (Int -> IO C
UInt
)
+ mallocObjectAddr :: FunPtr (Int -> IO C
Ptrdiff
)
type EntryPoint = Ptr Word8
type EntryPointOffset = Int
type EntryPoint = Ptr Word8
type EntryPointOffset = Int
diff --git
a/Mate/X86TrapHandling.hs
b/Mate/X86TrapHandling.hs
index 0e07cd5e29351e38c669e50530c0c241a6f66358..6ec0124f2c56e9ec347e982d37eeb3e6d6e8c648 100644
(file)
--- a/
Mate/X86TrapHandling.hs
+++ b/
Mate/X86TrapHandling.hs
@@
-25,7
+25,7
@@
data TrapType =
| VirtualMethodCall Bool
| InterfaceMethodCall Bool
| VirtualMethodCall Bool
| InterfaceMethodCall Bool
-getTrapType :: TrapMap -> C
UInt -> CUInt
-> TrapType
+getTrapType :: TrapMap -> C
Ptrdiff -> CPtrdiff
-> TrapType
getTrapType tmap signal_from from2 =
case M.lookup (fromIntegral signal_from) tmap of
(Just (StaticMethod _)) -> StaticMethodCall
getTrapType tmap signal_from from2 =
case M.lookup (fromIntegral signal_from) tmap of
(Just (StaticMethod _)) -> StaticMethodCall
@@
-38,8
+38,8
@@
getTrapType tmap signal_from from2 =
(Just _) -> error "getTrapType: abort #1 :-("
Nothing -> error $ "getTrapType: abort #2 :-(" ++ show signal_from ++ ", " ++ show from2 ++ ", " ++ show tmap
(Just _) -> error "getTrapType: abort #1 :-("
Nothing -> error $ "getTrapType: abort #2 :-(" ++ show signal_from ++ ", " ++ show from2 ++ ", " ++ show tmap
-foreign export ccall mateHandler :: C
UInt -> CUInt -> CUInt -> CUInt -> IO CUInt
-mateHandler :: C
UInt -> CUInt -> CUInt -> CUInt -> IO CUInt
+foreign export ccall mateHandler :: C
Ptrdiff -> CPtrdiff -> CPtrdiff -> CPtrdiff -> IO CPtrdiff
+mateHandler :: C
Ptrdiff -> CPtrdiff -> CPtrdiff -> CPtrdiff -> IO CPtrdiff
mateHandler eip eax ebx esp = do
callerAddr <- callerAddrFromStack esp
tmap <- getTrapMap
mateHandler eip eax ebx esp = do
callerAddr <- callerAddrFromStack esp
tmap <- getTrapMap
@@
-49,12
+49,12
@@
mateHandler eip eax ebx esp = do
VirtualMethodCall imm8 -> invokeHandler eax eax esp imm8
InterfaceMethodCall imm8 -> invokeHandler eax ebx esp imm8
VirtualMethodCall imm8 -> invokeHandler eax eax esp imm8
InterfaceMethodCall imm8 -> invokeHandler eax ebx esp imm8
-staticCallHandler :: C
UInt -> IO CUInt
+staticCallHandler :: C
Ptrdiff -> IO CPtrdiff
staticCallHandler eip = do
-- the actual insn to patch is displaced by two bytes
let insn_ptr = intPtrToPtr (fromIntegral (eip - 2)) :: Ptr CUChar
-- call offset is displaced by one byte
staticCallHandler eip = do
-- the actual insn to patch is displaced by two bytes
let insn_ptr = intPtrToPtr (fromIntegral (eip - 2)) :: Ptr CUChar
-- call offset is displaced by one byte
- let imm_ptr = intPtrToPtr (fromIntegral (eip - 1)) :: Ptr C
UInt
+ let imm_ptr = intPtrToPtr (fromIntegral (eip - 1)) :: Ptr C
Ptrdiff
-- in codegen we set the immediate to some magic value
-- in order to produce a SIGILL signal. we also do a safety
-- check here, if we're really the "owner" of this signal.
-- in codegen we set the immediate to some magic value
-- in order to produce a SIGILL signal. we also do a safety
-- check here, if we're really the "owner" of this signal.
@@
-71,10
+71,10
@@
staticCallHandler eip = do
return (eip - 2)
else error "staticCallHandler: something is wrong here. abort\n"
return (eip - 2)
else error "staticCallHandler: something is wrong here. abort\n"
-staticFieldHandler :: C
UInt -> IO CUInt
+staticFieldHandler :: C
Ptrdiff -> IO CPtrdiff
staticFieldHandler eip = do
-- patch the offset here, first two bytes are part of the insn (opcode + reg)
staticFieldHandler eip = do
-- patch the offset here, first two bytes are part of the insn (opcode + reg)
- let imm_ptr = intPtrToPtr (fromIntegral (eip + 2)) :: Ptr C
UInt
+ let imm_ptr = intPtrToPtr (fromIntegral (eip + 2)) :: Ptr C
Ptrdiff
checkMe <- peek imm_ptr
if checkMe == 0x00000000 then
do
checkMe <- peek imm_ptr
if checkMe == 0x00000000 then
do
@@
-82,7
+82,7
@@
staticFieldHandler eip = do
return eip
else error "staticFieldHandler: something is wrong here. abort.\n"
return eip
else error "staticFieldHandler: something is wrong here. abort.\n"
-invokeHandler :: C
UInt -> CUInt -> CUInt -> Bool -> IO CUInt
+invokeHandler :: C
Ptrdiff -> CPtrdiff -> CPtrdiff -> Bool -> IO CPtrdiff
invokeHandler method_table table2patch esp imm8 = do
-- table2patch: note, that can be a method-table or a interface-table
callerAddr <- callerAddrFromStack esp
invokeHandler method_table table2patch esp imm8 = do
-- table2patch: note, that can be a method-table or a interface-table
callerAddr <- callerAddrFromStack esp
@@
-93,18
+93,18
@@
invokeHandler method_table table2patch esp imm8 = do
return entryAddr
return entryAddr
-callerAddrFromStack :: C
UInt -> IO CUInt
+callerAddrFromStack :: C
Ptrdiff -> IO CPtrdiff
callerAddrFromStack = peek . intPtrToPtr . fromIntegral
callerAddrFromStack = peek . intPtrToPtr . fromIntegral
-offsetOfCallInsn8 :: C
UInt -> IO CUInt
+offsetOfCallInsn8 :: C
Ptrdiff -> IO CPtrdiff
offsetOfCallInsn8 esp = do
offsetOfCallInsn8 esp = do
- let ret_ptr = intPtrToPtr (fromIntegral esp) :: Ptr C
UInt
+ let ret_ptr = intPtrToPtr (fromIntegral esp) :: Ptr C
Ptrdiff
ret <- peek ret_ptr
retval <- peek (intPtrToPtr (fromIntegral (ret - 1)) :: Ptr CUChar)
return $ fromIntegral retval
ret <- peek ret_ptr
retval <- peek (intPtrToPtr (fromIntegral (ret - 1)) :: Ptr CUChar)
return $ fromIntegral retval
-offsetOfCallInsn32 :: C
UInt -> IO CUInt
+offsetOfCallInsn32 :: C
Ptrdiff -> IO CPtrdiff
offsetOfCallInsn32 esp = do
offsetOfCallInsn32 esp = do
- let ret_ptr = intPtrToPtr (fromIntegral esp) :: Ptr C
UInt
+ let ret_ptr = intPtrToPtr (fromIntegral esp) :: Ptr C
Ptrdiff
ret <- peek ret_ptr
peek (intPtrToPtr $ fromIntegral (ret - 4))
ret <- peek ret_ptr
peek (intPtrToPtr $ fromIntegral (ret - 4))
diff --git
a/doc/TODO
b/doc/TODO
index 52988bb2b4875e0330eb84c9029848fdbcb17fea..2e441d727a8e66133108344a7cc93f8a4240f151 100644
(file)
--- a/
doc/TODO
+++ b/
doc/TODO
@@
-57,9
+57,6
@@
(l) check different types (byte, long, ...)
(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
(l) floating point support
(h) better code generation
diff --git
a/ffi/trap.c
b/ffi/trap.c
index 1058004a1046afe6432f82fbceb9ab3b4194066a..301f2060ce47f5252bb4d2dfd73112efa069d9a7 100644
(file)
--- a/
ffi/trap.c
+++ b/
ffi/trap.c
@@
-1,5
+1,6
@@
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stddef.h>
#include "../debug.h"
#include "../debug.h"
@@
-21,7
+22,7
@@
#include <sys/ucontext.h>
#include <sys/ucontext.h>
-
unsigned int mateHandler(unsigned int, unsigned int, unsigned int, unsigned in
t);
+
ptrdiff_t mateHandler(ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_
t);
#ifdef DBG_TRAP
#define dprintf(args...) do { printf (args); } while (0);
#ifdef DBG_TRAP
#define dprintf(args...) do { printf (args); } while (0);
@@
-33,13
+34,13
@@
void chandler(int nSignal, siginfo_t *info, void *ctx)
{
mcontext_t *mctx = &((ucontext_t *) ctx)->uc_mcontext;
{
mcontext_t *mctx = &((ucontext_t *) ctx)->uc_mcontext;
-
unsigned int eip = (unsigned in
t) mctx->gregs[REG_EIP];
-
unsigned int eax = (unsigned in
t) mctx->gregs[REG_EAX];
-
unsigned int ebx = (unsigned in
t) mctx->gregs[REG_EBX];
-
unsigned int esp = (unsigned in
t) mctx->gregs[REG_ESP];
+
ptrdiff_t eip = (ptrdiff_
t) mctx->gregs[REG_EIP];
+
ptrdiff_t eax = (ptrdiff_
t) mctx->gregs[REG_EAX];
+
ptrdiff_t ebx = (ptrdiff_
t) mctx->gregs[REG_EBX];
+
ptrdiff_t esp = (ptrdiff_
t) mctx->gregs[REG_ESP];
dprintf("trap: type %d, eip 0x%08x, eax 0x%08x, ebx 0x%08x, "
"esp 0x%08x, *esp 0x%08x\n", nSignal, eip,
dprintf("trap: type %d, eip 0x%08x, eax 0x%08x, ebx 0x%08x, "
"esp 0x%08x, *esp 0x%08x\n", nSignal, eip,
- eax, ebx, esp, *(
unsigned in
t*) esp);
+ eax, ebx, esp, *(
ptrdiff_
t*) esp);
mctx->gregs[REG_EIP] = mateHandler(eip, eax, ebx, esp);
}
mctx->gregs[REG_EIP] = mateHandler(eip, eax, ebx, esp);
}