NULL pointer or objptr should not pass the validity check.
吴佳森 <[email protected]> Thu, 9 May 2013 17:27:48 +0800
| Newsgroups | gmane.comp.lang.ml.mlton.devel |
|---|---|
| Message-ID | <CAKCzkEpe9TUpxYZ-P5kvJJ45RFfYC5Z_yZNDWbYk3rACNuuyjg@mail.gmail.com> |
When I was porting the MLton, I met two segment faults. And after careful
inspection on the trace, I made following changes to runtime/gc/objptr.c
and runtime/gc/pointer.c.
The changes are about deciding whether the given pointer or objptr is
valid. The original code only check the last few bits must be zero, and
hence NULL pointer is also considered valid. I don't think NULL pointer
should pass the check hence made the changes.
I am not sure if I'm correct on the judgement because I guess if may also
be some problem elsewhere that introduce the NULL pointer to GC.
Could someone please have a check on it? I would appreciate any feed back
for it. Thank you very much.
[jason@jason-vm mlton]$ git diff runtime/gc/objptr.c
diff --git a/runtime/gc/objptr.c b/runtime/gc/objptr.c
index 37f98ed..d26ca91 100644
--- a/runtime/gc/objptr.c
+++ b/runtime/gc/objptr.c
@@ -9,7 +9,7 @@
bool isObjptr (objptr p) {
unsigned int shift = GC_MODEL_MINALIGN_SHIFT - GC_MODEL_OBJPTR_SHIFT;
objptr mask = ~((~((objptr)0)) << shift);
- return (0 == (p & mask));
+ return (0 != p && 0 == (p & mask));
}
pointer objptrToPointer (objptr O, pointer B) {
[jason@jason-vm mlton]$ git diff runtime/gc/pointer.c
diff --git a/runtime/gc/pointer.c b/runtime/gc/pointer.c
index 33248fb..3f66400 100644
--- a/runtime/gc/pointer.c
+++ b/runtime/gc/pointer.c
@@ -9,5 +9,5 @@
/* isPointer returns true if p looks like a pointer. */
bool isPointer (pointer p) {
uintptr_t mask = ~((~((uintptr_t)0)) << GC_MODEL_MINALIGN_SHIFT);
- return (0 == ((uintptr_t)p & mask));
+ return (0 != p && 0 == ((uintptr_t)p & mask));
}
------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and
their applications. This 200-page book is written by three acclaimed
leaders in the field. The early access version is available now.
Download your free book today! http://p.sf.net/sfu/neotech_d2d_may
_______________________________________________
MLton-devel mailing list
[email protected]; [email protected]
https://lists.sourceforge.net/lists/listinfo/mlton-devel