@@ -171,6 +171,10 @@ static void patchCn1Globals(Path srcRoot) throws IOException {
171171 content = content .replace ("#ifdef __OBJC__\n " , "#ifdef __OBJC__\n @class NSString;\n " );
172172 Files .write (cn1Globals , content .getBytes (StandardCharsets .UTF_8 ));
173173 }
174+ if (!content .contains ("#include <string.h>" )) {
175+ content = content .replace ("#include <stdlib.h>\n " , "#include <stdlib.h>\n #include <string.h>\n " );
176+ Files .write (cn1Globals , content .getBytes (StandardCharsets .UTF_8 ));
177+ }
174178 }
175179
176180 static void writeRuntimeStubs (Path srcRoot ) throws IOException {
@@ -187,11 +191,12 @@ static void writeRuntimeStubs(Path srcRoot) throws IOException {
187191 "\n " +
188192 "static void initThreadState() {\n " +
189193 " memset(&globalThreadData, 0, sizeof(globalThreadData));\n " +
190- " globalThreadData.threadObjectStack = calloc(64, sizeof(struct elementStruct));\n " +
191- " globalThreadData.pendingHeapAllocations = calloc(64, sizeof(void*));\n " +
192- " globalThreadData.callStackClass = calloc(64, sizeof(int));\n " +
193- " globalThreadData.callStackLine = calloc(64, sizeof(int));\n " +
194- " globalThreadData.callStackMethod = calloc(64, sizeof(int));\n " +
194+ " globalThreadData.blocks = calloc(CN1_MAX_STACK_CALL_DEPTH, sizeof(struct TryBlock));\n " +
195+ " globalThreadData.threadObjectStack = calloc(CN1_MAX_OBJECT_STACK_DEPTH, sizeof(struct elementStruct));\n " +
196+ " globalThreadData.pendingHeapAllocations = calloc(CN1_MAX_OBJECT_STACK_DEPTH, sizeof(void*));\n " +
197+ " globalThreadData.callStackClass = calloc(CN1_MAX_STACK_CALL_DEPTH, sizeof(int));\n " +
198+ " globalThreadData.callStackLine = calloc(CN1_MAX_STACK_CALL_DEPTH, sizeof(int));\n " +
199+ " globalThreadData.callStackMethod = calloc(CN1_MAX_STACK_CALL_DEPTH, sizeof(int));\n " +
195200 "}\n " +
196201 "\n " +
197202 "struct ThreadLocalData* getThreadLocalData() {\n " +
@@ -237,6 +242,22 @@ static void writeRuntimeStubs(Path srcRoot) throws IOException {
237242 "\n " +
238243 "void monitorExit(CODENAME_ONE_THREAD_STATE, JAVA_OBJECT obj) { (void)obj; }\n " +
239244 "\n " +
245+ "struct elementStruct* pop(struct elementStruct** sp) {\n " +
246+ " (*sp)--;\n " +
247+ " return *sp;\n " +
248+ "}\n " +
249+ "\n " +
250+ "void popMany(CODENAME_ONE_THREAD_STATE, int count, struct elementStruct** sp) {\n " +
251+ " while (count-- > 0) {\n " +
252+ " (*sp)--;\n " +
253+ " }\n " +
254+ "}\n " +
255+ "\n " +
256+ "void throwException(CODENAME_ONE_THREAD_STATE, JAVA_OBJECT obj) {\n " +
257+ " (void)obj;\n " +
258+ " exit(1);\n " +
259+ "}\n " +
260+ "\n " +
240261 "struct clazz class__java_lang_Class = {0};\n " +
241262 "int currentGcMarkValue = 1;\n " ;
242263
0 commit comments