Subj : crash in JS_NewContext To : netscape.public.mozilla.jseng From : Weiyang Zhou Date : Tue Sep 06 2005 09:21 pm Hi, We are porting SpiderMonkey to an embedded system running on a RISC 32bit microprocessor. We did our initial development on Windows XP with Pentium 4 processor. Everything works fine. Then we moved to the target device enviroment. My startup code looks like this: rt = JS_NewRuntime(64L * 1024L * 1024L); if (!rt) return 1; cx = JS_NewContext(rt, gStackChunkSize); if (!cx) return 1; ........ But it always crashes inside JS_NewContext. I traced into it and found it happened when calling js_CompareStrings. The call stack is like this: js_CompareStrings js_compare_atom_keys JS_HashTableRawLookup js_AtomizeString js_Atomize js_InitPinnedAtoms js_InitAtomState js_NewContext Wherein js_InitPinnedAtoms it is on the line of FROB(nullAtom, js_null_str); The strange thing is if I added the following debug code in js_Atomize like this: ..... str = ALIGN(buf, JSString); { char buffer[256]; sprintf(buffer, "%x %x %d %d %d\n", buf, str, ALIGNMENT(JSString), sizeof(JSString), (jsuword)(buf) % ALIGNMENT(JSString)); printf("%s", buffer); } ...... Then it won't crash during the initialization. You can see the debug code doesn't do anything significant except it uses the stack. But it still crashes when I start using JS_CompileScript. With the above debug statements, I saw a difference between Windows and the target device. In Windows, (jsuword)(buf) % ALIGNMENT(JSString) is 0, but on the target device, (jsuword)(buf) % ALIGNMENT(JSString) is 4. Will this make the two macros in jsatom.c fail? ALIGNMENT(JSString) and sizeof(JSString) are both 8 in the two enviroment. #define ALIGNMENT(t) JS_MAX(JSVAL_ALIGN, sizeof(t)) #define ALIGN(b,t) ((t*) &(b)[ALIGNMENT(t) - (jsuword)(b) % ALIGNMENT(t)]) Also, can anyone explain the purpose of the ALIGN macro? Any help will be appreciated. Thanks a lot. .