2
0
Эх сурвалжийг харах

Patched an issue with the GC: modules were - for a very short moment - not protected when being returned from the Generic loader.
Reason is that dynamically loaded modules, although forming a valid heap block, are not immediately reachable from a sweep because they are embedded into an array. The solution is now to publish a module before returning it from the loader.

git-svn-id: https://svn.inf.ethz.ch/svn/lecturers/a2/trunk@6686 8c9fc860-2736-0410-a75d-ab315db34111

felixf 9 жил өмнө
parent
commit
31c9394a57

+ 3 - 2
source/Generic.Modules.Mod

@@ -174,8 +174,8 @@ TYPE
 
 	END Module;
 
-	LoaderProc* = PROCEDURE (CONST name, fileName: ARRAY OF CHAR; VAR res: LONGINT;
-			VAR msg: ARRAY OF CHAR): Module;	(** load an object file *)
+		
+	LoaderProc* = PROCEDURE (CONST name, fileName: ARRAY OF CHAR; VAR res: LONGINT; VAR msg: ARRAY OF CHAR): Module;	(** load an object file *)
 
 VAR
 	extension-: ARRAY MaxObjFormats, 8 OF CHAR;
@@ -299,6 +299,7 @@ END PublishThis;
 PROCEDURE Initialize*(VAR module: Module);
 VAR new: BOOLEAN;
 BEGIN
+	IF (module = NIL) THEN RETURN END;
 	Publish (module, new);
 	IF new THEN
 		IF module.body # NIL THEN

+ 12 - 1
source/GenericLoader.Mod

@@ -588,7 +588,7 @@ VAR
 		END
 	END SelectionSort;
 	
-	PROCEDURE LoadObj*(CONST name, fileName: ARRAY OF CHAR;  VAR res: LONGINT;  VAR msg: ARRAY OF CHAR): Modules.Module;
+	PROCEDURE LoadObj*(CONST name, fileName: ARRAY OF CHAR;  VAR res: LONGINT; VAR msg: ARRAY OF CHAR): Modules.Module;
 	TYPE Body=PROCEDURE;
 	VAR
 		file: Files.File; reader: Files.Reader; linker: Linker;
@@ -624,14 +624,25 @@ VAR
 				module.staticTypeDescs := testTypeDescs; (* trick to identify new object file loaded modules *)
 				module.data := arrangement.data.bytes;
 				module.code := arrangement.code.bytes;
+
 				module.firstProc := arrangement.code.firstAddress;
 				module.sb := arrangement.data.firstAddress;
 				module.body := SYSTEM.VAL(Body, arrangement.bodyAddress);
+				
 				(*
 				SortProcTable(module);
 				SelectionSort(module.exTable);
 				*)
 
+				(*
+					careful: when GC uses a heuristic for pointer detection on the stack, it will not
+					trace the module because the module is not reachable as a heap block in a sweep
+					Therefore the code and data array has to be secured in addition.
+					Here this is made sure to enter the module in the data structure before returning it. 
+				*) 
+				Modules.Initialize(module);
+
+
 			ELSE module := NIL; res := LinkerError; stringWriter.Update; stringWriter.Get(msg);
 
 			END;