summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Marlow <marlowsd@gmail.com>2008-12-02 12:07:35 +0000
committerSimon Marlow <marlowsd@gmail.com>2008-12-02 12:07:35 +0000
commit164be7854f6de07bb4bc15f60af727ddb562cde7 (patch)
tree1a731627a6d78e425098f27082aa428fead2cd25
parentc0378a2774a400e2992bc57a7ec580df3f142b29 (diff)
downloadhaskell-164be7854f6de07bb4bc15f60af727ddb562cde7.tar.gz
Fix more problems caused by padding in the Capability structure
Fixes crashes on Windows and Sparc
-rw-r--r--includes/Regs.h2
-rw-r--r--includes/Stg.h4
-rw-r--r--rts/Capability.h4
-rw-r--r--rts/Interpreter.c2
4 files changed, 7 insertions, 5 deletions
diff --git a/includes/Regs.h b/includes/Regs.h
index 49366ed342..45f9149af5 100644
--- a/includes/Regs.h
+++ b/includes/Regs.h
@@ -398,7 +398,7 @@ GLOBAL_REG_DECL(bdescr *,HpAlloc,REG_HpAlloc)
-------------------------------------------------------------------------- */
-#define FunReg ((StgFunTable *)((void *)BaseReg - sizeof(StgFunTable)))
+#define FunReg ((StgFunTable *)((void *)BaseReg - FIELD_OFFSET(struct PartCapability_, r)))
#define stg_EAGER_BLACKHOLE_info (FunReg->stgEagerBlackholeInfo)
#define stg_gc_enter_1 (FunReg->stgGCEnter1)
diff --git a/includes/Stg.h b/includes/Stg.h
index 7ac6b1a864..394c987f07 100644
--- a/includes/Stg.h
+++ b/includes/Stg.h
@@ -74,6 +74,10 @@
#define BITS_PER_BYTE 8
#define BITS_IN(x) (BITS_PER_BYTE * sizeof(x))
+/* Compute offsets of struct fields
+ */
+#define FIELD_OFFSET(s_type, field) ((StgWord)&(((s_type*)0)->field))
+
/*
* 'Portable' inlining:
* INLINE_HEADER is for inline functions in header files (macros)
diff --git a/rts/Capability.h b/rts/Capability.h
index b6f6440cb8..ba0695c8ee 100644
--- a/rts/Capability.h
+++ b/rts/Capability.h
@@ -143,12 +143,10 @@ struct Capability_ {
// Converts a *StgRegTable into a *Capability.
//
-#define OFFSET(s_type, field) ((size_t)&(((s_type*)0)->field))
-
INLINE_HEADER Capability *
regTableToCapability (StgRegTable *reg)
{
- return (Capability *)((void *)((unsigned char*)reg - OFFSET(Capability,r)));
+ return (Capability *)((void *)((unsigned char*)reg - FIELD_OFFSET(Capability,r)));
}
// Initialise the available capabilities.
diff --git a/rts/Interpreter.c b/rts/Interpreter.c
index 4324f7f44a..1b2d7303ed 100644
--- a/rts/Interpreter.c
+++ b/rts/Interpreter.c
@@ -1422,7 +1422,7 @@ run_BCO:
ffi_call(cif, fn, ret, argptrs);
// And restart the thread again, popping the RET_DYN frame.
- cap = (Capability *)((void *)((unsigned char*)resumeThread(tok) - sizeof(StgFunTable)));
+ cap = (Capability *)((void *)((unsigned char*)resumeThread(tok) - FIELD_OFFSET(Capability,r)));
LOAD_STACK_POINTERS;
// Re-load the pointer to the BCO from the RET_DYN frame,