Generic.Modules.Mod 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046
  1. MODULE Modules; (** AUTHOR "pjm"; PURPOSE "Modules and types"; *)
  2. IMPORT SYSTEM, Trace, Machine, Heaps, Runtime;
  3. CONST
  4. Ok* = 0;
  5. AddressSize = SIZEOF (ADDRESS); (* architecture dependent size of addresses in bytes *)
  6. MaxTags* = 16; (* in type descriptor *)
  7. (** type descriptor field offsets relative to root (middle) *)
  8. Tag0Ofs* = -AddressSize * 2; (** first tag *)
  9. Mth0Ofs* = Tag0Ofs - AddressSize*MaxTags; (** first method *)
  10. Ptr0Ofs* = AddressSize; (** first pointer offset *)
  11. MaxObjFormats = 5; (* maximum number of object file formats installed *)
  12. (** flags in TypeDesc, RoundUp(log2(MaxTags)) low bits reserved for extLevel *)
  13. ProtTypeBit* = Heaps.ProtTypeBit;
  14. None* = 0; PowerDown* = 1; Reboot* = 2;
  15. ClearCode = TRUE;
  16. InitTableLen = 1024;
  17. InitPtrTableLen = 2048;
  18. DefaultContext* = "A2";
  19. NoLoader=3400;
  20. TraceBoot=TRUE;
  21. TYPE
  22. (* definitions for object-model loader support *)
  23. Name* = ARRAY 32 OF CHAR;
  24. DynamicName* = POINTER {UNSAFE} TO ARRAY 256 OF CHAR;
  25. Command* = RECORD
  26. (* Fields exported for initialization by loader/linker only! Consider read-only! *)
  27. name*: Name; (* name of the procedure *)
  28. argTdAdr*, retTdAdr* : ADDRESS; (* address of type descriptors of argument and return type, 0 if no type *)
  29. entryAdr* : ADDRESS; (* entry address of procedure *)
  30. END;
  31. ExportDesc* = RECORD
  32. fp*: LONGINT;
  33. name* {UNTRACED}: DynamicName;
  34. adr*: ADDRESS;
  35. exports*: LONGINT;
  36. dsc* {UNTRACED}: ExportArray
  37. END;
  38. ExportArray* = POINTER {UNSAFE} TO ARRAY OF ExportDesc;
  39. Bytes* = POINTER TO ARRAY OF CHAR;
  40. TerminationHandler* = PROCEDURE;
  41. EntryType*=RECORD
  42. class*: CHAR;
  43. subclass*: CHAR;
  44. (* size in bits *)
  45. size*: INTEGER;
  46. type*: ADDRESS; (* type descriptor or additional information *)
  47. END;
  48. FieldEntry* = RECORD
  49. name*: DynamicName;
  50. offset*: SIZE; (* offset of this type *)
  51. type*: EntryType;
  52. flags*: SET;
  53. END;
  54. FieldEntries*= POINTER TO ARRAY OF FieldEntry;
  55. ProcedureEntries*=POINTER TO ARRAY OF ProcedureEntry;
  56. ProcedureEntry*=RECORD
  57. name*: DynamicName;
  58. address*: ADDRESS;
  59. size*: SIZE;
  60. parameters*: FieldEntries;
  61. variables*: FieldEntries;
  62. procedures*: ProcedureEntries;
  63. returnType*: EntryType;
  64. END;
  65. TypeDesc* = POINTER TO RECORD
  66. descSize: LONGINT;
  67. sentinel: LONGINT; (* = MPO-4 *)
  68. tag*: ADDRESS; (* pointer to static type descriptor, only used by linker and loader *)
  69. flags*: SET;
  70. mod*: Module; (* hint only, because module may have been freed (at Heaps.ModOfs) *)
  71. name*: Name;
  72. fields*: FieldEntries;
  73. procedures*: ProcedureEntries;
  74. END;
  75. ExceptionTableEntry* = RECORD
  76. pcFrom*: ADDRESS;
  77. pcTo*: ADDRESS;
  78. pcHandler*: ADDRESS;
  79. END;
  80. ExceptionTable* = POINTER TO ARRAY OF ExceptionTableEntry;
  81. ProcTableEntry* = RECORD
  82. pcFrom*, pcLimit*, pcStatementBegin*, pcStatementEnd*: ADDRESS;
  83. noPtr*: LONGINT;
  84. END;
  85. ProcTable* = POINTER TO ARRAY OF ProcTableEntry;
  86. PtrTable* = POINTER TO ARRAY OF ADDRESS;
  87. ProcOffsetEntry* = RECORD
  88. data*: ProcTableEntry; (* code offsets of procedures *)
  89. startIndex*: LONGINT; (* index into global ptrOffsets table *)
  90. END;
  91. ProcOffsetTable* = POINTER TO ARRAY OF ProcOffsetEntry;
  92. Module* = OBJECT (Heaps.RootObject) (* cf. Linker0 & Heaps.WriteType *)
  93. VAR
  94. next*: Module; (** once a module is published, all fields are read-only *)
  95. name*: Name;
  96. init, published: BOOLEAN;
  97. refcnt*: LONGINT; (* counts loaded modules that import this module *)
  98. sb*: ADDRESS; (* reference address between constants and local variables *)
  99. entry*: POINTER TO ARRAY OF ADDRESS;
  100. command*: POINTER TO ARRAY OF Command;
  101. ptrAdr*: POINTER TO ARRAY OF ADDRESS; (* traced explicitly in FindRoots *)
  102. typeInfo*: POINTER TO ARRAY OF TypeDesc;
  103. module*: POINTER TO ARRAY OF Module; (* imported modules: for reference counting *)
  104. procTable*: ProcTable; (* information inserted by loader, removed after use in Publish *)
  105. ptrTable*: PtrTable; (* information inserted by loader, removed after use in Publish *)
  106. data*, code*, staticTypeDescs* (* ug *), refs*: Bytes;
  107. export*: ExportDesc;
  108. term*: TerminationHandler;
  109. exTable*: ExceptionTable;
  110. noProcs*: LONGINT; (* used for removing proc offsets when unloading module *)
  111. firstProc*: ADDRESS; (* procedure with lowest PC in module, also used for unloading *)
  112. maxPtrs*: LONGINT;
  113. crc*: LONGINT;
  114. body*: PROCEDURE;
  115. PROCEDURE FindRoots; (* override *)
  116. VAR i: LONGINT; ptr: ANY; (* moduleName: Name; *) false: BOOLEAN;
  117. BEGIN
  118. false := FALSE; IF false THEN BEGIN{EXCLUSIVE} END END; (* trick to make a module a protected record ... *)
  119. IF published THEN (* mark global pointers *)
  120. (* moduleName := name; *)
  121. FOR i := 0 TO LEN(ptrAdr) - 1 DO
  122. SYSTEM.GET (ptrAdr[i], ptr);
  123. IF ptr # NIL THEN Heaps.Mark(ptr) END
  124. END;
  125. Heaps.AddRootObject(next);
  126. (* all other fields are being traversed by Mark of the Garbage Collector *)
  127. END;
  128. END FindRoots;
  129. END Module;
  130. LoaderProc* = PROCEDURE (CONST name, fileName: ARRAY OF CHAR; VAR res: LONGINT;
  131. VAR msg: ARRAY OF CHAR): Module; (** load an object file *)
  132. VAR
  133. extension-: ARRAY MaxObjFormats, 8 OF CHAR;
  134. loader: ARRAY MaxObjFormats OF LoaderProc;
  135. numLoaders: LONGINT;
  136. kernelProc*: ARRAY 11 OF ADDRESS; (** kernel call addresses for loader *)
  137. freeRoot*: Module; (** list of freed modules (temporary) *)
  138. (* the following two variables are initialized by Linker *)
  139. root-: Module; (** list of modules (read-only) *)
  140. initBlock: ANY; (* placeholder - anchor for module init code (initialized by linker) *)
  141. procOffsets-: ProcOffsetTable; (* global table containing procedure code offsets and pointer offsets, sorted in ascending order of procedure code offsets *)
  142. numProcs: LONGINT; (* number of entries in procOffsets *)
  143. ptrOffsets-: PtrTable;
  144. numPtrs: LONGINT;
  145. shutdown*: LONGINT; (** None, Reboot, PowerDown *)
  146. trace: BOOLEAN;
  147. register: RECORD
  148. first, last: Module;
  149. END;
  150. (** Register a module loader. *)
  151. PROCEDURE AddLoader*(CONST ext: ARRAY OF CHAR; proc: LoaderProc);
  152. BEGIN
  153. Machine.Acquire(Machine.Modules);
  154. ASSERT(numLoaders < MaxObjFormats);
  155. loader[numLoaders] := proc;
  156. COPY(ext, extension[numLoaders]);
  157. ASSERT(ext = extension[numLoaders]); (* no overflow *)
  158. INC(numLoaders);
  159. Machine.Release(Machine.Modules)
  160. END AddLoader;
  161. (** Remove a module loader. *)
  162. PROCEDURE RemoveLoader*(CONST ext: ARRAY OF CHAR; proc: LoaderProc);
  163. VAR i, j: LONGINT;
  164. BEGIN
  165. Machine.Acquire(Machine.Modules);
  166. i := 0;
  167. WHILE (i # numLoaders) & ((loader[i] # proc) OR (extension[i] # ext)) DO INC(i) END;
  168. IF i # numLoaders THEN
  169. FOR j := i TO numLoaders - 2 DO
  170. loader[j] := loader[j + 1]; extension[j] := extension[j + 1];
  171. END;
  172. loader[numLoaders - 1] := NIL; extension[numLoaders - 1] := "";
  173. DEC(numLoaders)
  174. END;
  175. Machine.Release(Machine.Modules)
  176. END RemoveLoader;
  177. (** Append string from to to, truncating on overflow. *)
  178. PROCEDURE Append*(CONST from: ARRAY OF CHAR; VAR to: ARRAY OF CHAR);
  179. VAR i, j, m: LONGINT;
  180. BEGIN
  181. j := 0; WHILE to[j] # 0X DO INC(j) END;
  182. m := LEN(to)-1;
  183. i := 0; WHILE (from[i] # 0X) & (j # m) DO to[j] := from[i]; INC(i); INC(j) END;
  184. to[j] := 0X
  185. END Append;
  186. (** Add a module to the pool of accessible modules, or return named module. *)
  187. PROCEDURE Publish*(VAR m: Module; VAR new: BOOLEAN);
  188. VAR n: Module; i: LONGINT; a: ANY;
  189. BEGIN
  190. (*
  191. ASSERT((m.code # NIL) & (LEN(m.code^) > 0));
  192. *)
  193. Machine.Acquire(Machine.Modules);
  194. n := root; WHILE (n # NIL) & (n.name # m.name) DO n := n.next END;
  195. IF n # NIL THEN (* module with same name exists, return it and ignore new m *)
  196. m := n; new := FALSE
  197. ELSE
  198. IF TraceBoot THEN
  199. Machine.Acquire(Machine.TraceOutput);
  200. Trace.String("publish "); Trace.String(m.name);
  201. (*
  202. a := m;
  203. IF a IS Heaps.RootObject THEN Trace.String(" IS RootObj") END;
  204. IF a IS Module THEN Trace.String(" IS Module"); END;
  205. *)
  206. Trace.Ln;
  207. Machine.Release(Machine.TraceOutput);
  208. END;
  209. m.published := TRUE;
  210. m.next := root; root := m;
  211. m.refcnt := 0;
  212. (*! reactivate: does not work with statically linked image
  213. SortProcTable(m);
  214. InsertProcOffsets(m.procTable, m.ptrTable, m.maxPtrs);
  215. (*! yes: used, cf. ThisModuleByAdr *)
  216. m.procTable := NIL; m.ptrTable := NIL; (* not used any more as entered in global variable *)
  217. *)
  218. IF m.module # NIL THEN
  219. FOR i := 0 TO LEN(m.module)-1 DO INC(m.module[i].refcnt) END;
  220. END;
  221. new := TRUE;
  222. END;
  223. Machine.Release(Machine.Modules)
  224. END Publish;
  225. (*
  226. (* runtime call for new compiler -- called by body of loaded module *)
  227. PROCEDURE PublishThis*(m: Module): BOOLEAN;
  228. VAR new: BOOLEAN; i:LONGINT; module: Module;
  229. BEGIN
  230. IF m = SELF THEN
  231. RETURN Runtime.InsertModule(SYSTEM.VAL(ADDRESS,m))
  232. END;
  233. Publish(m,new);
  234. RETURN new
  235. END PublishThis;
  236. *)
  237. PROCEDURE Initialize*(VAR module: Module);
  238. VAR new: BOOLEAN;
  239. BEGIN
  240. Publish (module, new);
  241. IF new THEN
  242. IF module.body # NIL THEN
  243. Machine.FlushDCacheRange(ADDRESSOF(module.code[0]), LEN(module.code));
  244. module.body
  245. END;
  246. module.init := TRUE;
  247. END;
  248. END Initialize;
  249. VAR callagain: BOOLEAN;
  250. PROCEDURE Initialize0*(module: Module);
  251. VAR new: BOOLEAN;
  252. BEGIN
  253. (*TRACE(module.name);*)
  254. (* module MUST have been removed from register list and must not have been initialized yet *)
  255. ASSERT(module.next = NIL);
  256. Publish (module, new);
  257. callagain := FALSE;
  258. IF new THEN
  259. IF module.name = "Objects" THEN
  260. callagain := TRUE;
  261. module.init := TRUE;
  262. END;
  263. (*
  264. Trace.Memory(SYSTEM.VAL(ADDRESS, module), 256);
  265. TRACE(module, module.name, module.body);
  266. TRACE(module);
  267. TRACE(ADDRESS OF module.next);
  268. TRACE(ADDRESS OF module.name);
  269. TRACE(ADDRESS OF module.init);
  270. TRACE(ADDRESS OF module.published);
  271. TRACE(ADDRESS OF module.body);
  272. TRACE(ADDRESS OF module.refcnt);
  273. TRACE(ADDRESS OF module.sb);
  274. TRACE(ADDRESS OF module.entry);
  275. TRACE(ADDRESS OF module.command);
  276. TRACE(ADDRESS OF module.ptrAdr);
  277. TRACE(ADDRESS OF module.typeInfo);
  278. TRACE(ADDRESS OF module.module);
  279. TRACE(ADDRESS OF module.procTable);
  280. TRACE(ADDRESS OF module.ptrTable);
  281. TRACE(ADDRESS OF module.data);
  282. TRACE(ADDRESS OF module.code);
  283. TRACE(ADDRESS OF module.staticTypeDescs);
  284. TRACE(ADDRESS OF module.refs);
  285. TRACE(ADDRESS OF module.export);
  286. TRACE(ADDRESS OF module.term);
  287. TRACE(ADDRESS OF module.exTable);
  288. TRACE(ADDRESS OF module.noProcs);
  289. TRACE(ADDRESS OF module.firstProc);
  290. TRACE(ADDRESS OF module.maxPtrs);
  291. TRACE(ADDRESS OF module.crc);
  292. TRACE(ADDRESS OF module.body);
  293. *)
  294. IF module.body # NIL THEN module.body END;
  295. IF callagain THEN
  296. PublishRegisteredModules (* does not return on intel architecture. Returns on ARM but looses procedure stack frame: we are not allowed to refer to local variables after this *)
  297. ELSE
  298. module.init := TRUE;
  299. END;
  300. END;
  301. END Initialize0;
  302. (** Return the named module or NIL if it is not loaded yet. *)
  303. PROCEDURE ModuleByName*(CONST name: ARRAY OF CHAR): Module;
  304. VAR m: Module;
  305. BEGIN
  306. Machine.Acquire(Machine.Modules);
  307. m := root; WHILE (m # NIL) & (m.name # name) DO m := m.next END;
  308. Machine.Release(Machine.Modules);
  309. RETURN m
  310. END ModuleByName;
  311. (* Generate a module file name. *)
  312. PROCEDURE GetFileName(CONST name, extension: ARRAY OF CHAR; VAR fileName: ARRAY OF CHAR);
  313. VAR i, j: LONGINT;
  314. BEGIN
  315. i := 0; WHILE name[i] # 0X DO fileName[i] := name[i]; INC(i) END;
  316. j := 0; WHILE extension[j] # 0X DO fileName[i] := extension[j]; INC(i); INC(j) END;
  317. fileName[i] := 0X
  318. END GetFileName;
  319. PROCEDURE SortProcTable(m: Module);
  320. VAR i, j, min : LONGINT;
  321. PROCEDURE Max(a,b: LONGINT): LONGINT;
  322. BEGIN
  323. IF a > b THEN RETURN a ELSE RETURN b END;
  324. END Max;
  325. PROCEDURE SwapProcTableEntries(p, q : LONGINT);
  326. VAR procentry : ProcTableEntry;
  327. k, i, basep, baseq: LONGINT; ptr: SIZE;
  328. BEGIN
  329. k := Max(m.procTable[p].noPtr, m.procTable[q].noPtr);
  330. IF k > 0 THEN (* swap entries in ptrTable first *)
  331. basep := p * m.maxPtrs; baseq := q * m.maxPtrs;
  332. FOR i := 0 TO k - 1 DO
  333. ptr := m.ptrTable[basep + i];
  334. m.ptrTable[basep + i] := m.ptrTable[baseq + i];
  335. m.ptrTable[baseq + i] := ptr
  336. END
  337. END;
  338. procentry := m.procTable[p];
  339. m.procTable[p] := m.procTable[q];
  340. m.procTable[q] := procentry
  341. END SwapProcTableEntries;
  342. PROCEDURE NormalizePointerArray;
  343. VAR ptrTable: PtrTable; i,j,k: LONGINT;
  344. BEGIN
  345. NEW(ptrTable, m.maxPtrs*m.noProcs);
  346. k := 0;
  347. FOR i := 0 TO LEN(m.procTable)-1 DO
  348. FOR j := 0 TO m.procTable[i].noPtr-1 DO
  349. ptrTable[i*m.maxPtrs+j] := m.ptrTable[k];
  350. INC(k);
  351. END;
  352. END;
  353. m.ptrTable := ptrTable;
  354. END NormalizePointerArray;
  355. BEGIN
  356. NormalizePointerArray;
  357. FOR i := 0 TO m.noProcs - 2 DO
  358. min := i;
  359. FOR j := i + 1 TO m.noProcs - 1 DO
  360. IF m.procTable[j].pcFrom < m.procTable[min].pcFrom THEN min:= j END
  361. END;
  362. IF min # i THEN SwapProcTableEntries(i, min) END
  363. END
  364. END SortProcTable;
  365. PROCEDURE SelectionSort(exTable: ExceptionTable);
  366. VAR
  367. p, q, min: LONGINT;
  368. entry: ExceptionTableEntry;
  369. BEGIN
  370. FOR p := 0 TO LEN(exTable) - 2 DO
  371. min := p;
  372. FOR q := p + 1 TO LEN(exTable) - 1 DO
  373. IF exTable[min].pcFrom > exTable[q].pcFrom THEN min := q END;
  374. entry := exTable[min]; exTable[min] := exTable[p]; exTable[p] := entry;
  375. END
  376. END
  377. END SelectionSort;
  378. (** Load the module if it is not already loaded. *) (* Algorithm J. Templ, ETHZ, 1994 *)
  379. PROCEDURE ThisModule*(CONST name: ARRAY OF CHAR; VAR res: LONGINT; VAR msg: ARRAY OF CHAR): Module;
  380. TYPE Body = PROCEDURE;
  381. VAR m, p: Module; fileName: ARRAY 64 OF CHAR; body: Body; new: BOOLEAN; i: LONGINT;
  382. BEGIN
  383. res := Ok; msg[0] := 0X; m := ModuleByName(name);
  384. IF m = NIL THEN
  385. IF trace THEN
  386. Machine.Acquire (Machine.TraceOutput);
  387. Trace.String(">"); Trace.StringLn (name);
  388. Machine.Release (Machine.TraceOutput);
  389. END;
  390. IF numLoaders = 0 THEN
  391. res := NoLoader; m := NIL;
  392. ELSE
  393. i:= 0;
  394. REPEAT
  395. GetFileName(name, extension[i], fileName);
  396. m := loader[i](name, fileName, res, msg);
  397. INC(i);
  398. UNTIL (m # NIL) OR (i=numLoaders);
  399. END;
  400. IF trace THEN
  401. Machine.Acquire (Machine.TraceOutput);
  402. Trace.String("?"); Trace.StringLn (name);
  403. Machine.Release (Machine.TraceOutput);
  404. END;
  405. p := m;
  406. IF (m # NIL) & ~m.published THEN (* no race on m.published, as update is done below in Publish *)
  407. Initialize(m);
  408. END;
  409. IF trace THEN
  410. Machine.Acquire (Machine.TraceOutput);
  411. IF m = NIL THEN
  412. Trace.String("could not load "); Trace.StringLn(name)
  413. ELSIF ~m.published THEN
  414. Trace.String("not published "); Trace.StringLn(name)
  415. ELSE
  416. Trace.String("<"); Trace.StringLn (name);
  417. END;
  418. Machine.Release (Machine.TraceOutput);
  419. END;
  420. END;
  421. RETURN m
  422. END ThisModule;
  423. (** Return the module that contains code address pc or NIL if not found. Can also return freed modules. Non-blocking version for reflection *)
  424. PROCEDURE ThisModuleByAdr0*(pc: ADDRESS): Module;
  425. VAR m: Module; cbase, dbase: ADDRESS; i: LONGINT; found: BOOLEAN; list: LONGINT;
  426. BEGIN
  427. list := 0; found := FALSE;
  428. REPEAT
  429. CASE list OF
  430. 0: m := root
  431. |1: m := freeRoot
  432. END;
  433. WHILE (m # NIL) & ~found DO
  434. IF m.procTable # NIL THEN
  435. i := 0;
  436. WHILE ~found & (i<LEN(m.procTable)) DO
  437. IF (m.procTable[i].pcFrom <= pc) & (pc <m.procTable[i].pcLimit) THEN
  438. found := TRUE;
  439. END;
  440. INC(i);
  441. END;
  442. END;
  443. IF ~found THEN
  444. m := m.next;
  445. END;
  446. END;
  447. INC(list)
  448. UNTIL found OR (list=2);
  449. RETURN m
  450. END ThisModuleByAdr0;
  451. (** Return the module that contains code address pc or NIL if not found. Can also return freed modules. *)
  452. PROCEDURE ThisModuleByAdr*(pc: ADDRESS): Module;
  453. VAR m: Module; cbase, dbase: ADDRESS; i: LONGINT; found: BOOLEAN; list: LONGINT;
  454. BEGIN
  455. Machine.Acquire(Machine.Modules);
  456. m := ThisModuleByAdr0(pc);
  457. Machine.Release(Machine.Modules);
  458. RETURN m
  459. END ThisModuleByAdr;
  460. CONST ModuleInitTimeout = HUGEINT(3000000000); (* Timeout for waiting until a module get initialized, 3 seconds for 1 GHz CPU *)
  461. (* Retrieve a procedure given a module name, the procedure name and some type information (kernel call) *)
  462. PROCEDURE GetProcedure*(CONST moduleName, procedureName : ARRAY OF CHAR; argTdAdr, retTdAdr : ADDRESS; VAR entryAdr : ADDRESS);
  463. VAR module : Module; ignoreMsg : ARRAY 32 OF CHAR; i, res : LONGINT; t: HUGEINT;
  464. BEGIN
  465. module := ThisModule(moduleName, res, ignoreMsg);
  466. IF (res = Ok) THEN
  467. (*!
  468. module body must have been called (see note at the end of this module);
  469. return NIL if the module does not get initialized within the specified timeout
  470. *)
  471. IF ~module.init THEN
  472. t := Machine.GetTimer();
  473. WHILE ~module.init & (Machine.GetTimer() - t < ModuleInitTimeout) DO END;
  474. IF ~module.init THEN (* timeout has expired *)
  475. RETURN;
  476. END;
  477. END;
  478. Machine.Acquire(Machine.Modules);
  479. i := 0; entryAdr := Heaps.NilVal;
  480. WHILE (entryAdr = Heaps.NilVal) & (i # LEN(module.command^)) DO
  481. IF (module.command[i].name = procedureName) & (module.command[i].argTdAdr = argTdAdr) & (module.command[i].retTdAdr = retTdAdr) THEN
  482. entryAdr := module.command[i].entryAdr;
  483. END;
  484. INC(i)
  485. END;
  486. Machine.Release(Machine.Modules);
  487. END;
  488. END GetProcedure;
  489. (** Return the named type *)
  490. PROCEDURE ThisType*(m: Module; CONST name: ARRAY OF CHAR): TypeDesc;
  491. VAR i: LONGINT; type: TypeDesc;
  492. BEGIN
  493. Machine.Acquire(Machine.Modules);
  494. i := 0;
  495. WHILE (i < LEN(m.typeInfo)) & (m.typeInfo[i].name # name) DO INC(i) END;
  496. IF i = LEN(m.typeInfo) THEN
  497. type := NIL
  498. ELSE
  499. type := m.typeInfo[i]
  500. END;
  501. Machine.Release(Machine.Modules);
  502. RETURN type
  503. END ThisType;
  504. PROCEDURE ThisTypeByAdr*(adr: ADDRESS; VAR m: Module; VAR t: TypeDesc);
  505. BEGIN
  506. IF adr # 0 THEN
  507. Machine.Acquire(Machine.Modules);
  508. SYSTEM.GET (adr + Heaps.TypeDescOffset, adr);
  509. t := SYSTEM.VAL(TypeDesc, adr);
  510. m := t.mod;
  511. Machine.Release(Machine.Modules)
  512. ELSE
  513. m := NIL; t := NIL
  514. END
  515. END ThisTypeByAdr;
  516. (** create a new object given its type descriptor *)
  517. PROCEDURE NewObj*(t : TypeDesc; isRealtime: BOOLEAN) : ANY;
  518. VAR x : ANY;
  519. BEGIN
  520. Heaps.NewRec(x, SYSTEM.VAL (ADDRESS, t.tag), isRealtime);
  521. RETURN x;
  522. END NewObj;
  523. (** return the type descriptor of an object *)
  524. PROCEDURE TypeOf*(obj : ANY): TypeDesc;
  525. VAR
  526. m : Module;
  527. t : TypeDesc;
  528. adr : ADDRESS;
  529. BEGIN
  530. SYSTEM.GET(SYSTEM.VAL(ADDRESS, obj) + Heaps.TypeDescOffset, adr);
  531. ThisTypeByAdr(adr, m, t);
  532. RETURN t;
  533. END TypeOf;
  534. PROCEDURE FindPos(key: ADDRESS; VAR pos: LONGINT): BOOLEAN;
  535. VAR l, r, x: LONGINT; isHit: BOOLEAN;
  536. BEGIN
  537. IF numProcs > 0 THEN
  538. l := 0; r := numProcs - 1;
  539. REPEAT
  540. x := (l + r) DIV 2;
  541. IF key < procOffsets[x].data.pcFrom THEN r := x - 1 ELSE l := x + 1 END;
  542. isHit := ((procOffsets[x].data.pcFrom <= key) & (key < procOffsets[x].data.pcLimit));
  543. UNTIL isHit OR (l > r);
  544. IF isHit THEN
  545. pos := x;
  546. RETURN TRUE
  547. END;
  548. END;
  549. RETURN FALSE
  550. END FindPos;
  551. (** searches for the given pc in the global ProcKeyTable, if found it returns the corresponding data element *)
  552. PROCEDURE FindProc*(pc: ADDRESS; VAR data: ProcTableEntry; VAR index: LONGINT; VAR success: BOOLEAN);
  553. VAR x: LONGINT;
  554. BEGIN
  555. success := FindPos(pc, x);
  556. IF success THEN
  557. data := procOffsets[x].data;
  558. index := procOffsets[x].startIndex
  559. END
  560. END FindProc;
  561. PROCEDURE FindInsertionPos(VAR entry: ProcTableEntry; VAR pos: LONGINT): BOOLEAN;
  562. VAR l, r, x: LONGINT; success, isHit: BOOLEAN;
  563. BEGIN
  564. pos := -1;
  565. success := FALSE;
  566. IF numProcs = 0 THEN (* empty table *)
  567. pos := 0; success := TRUE
  568. ELSE
  569. l := 0; r := numProcs - 1;
  570. REPEAT
  571. x := (l + r) DIV 2;
  572. IF entry.pcLimit < procOffsets[x].data.pcFrom THEN r := x - 1 ELSE l := x + 1 END;
  573. isHit := ((x = 0) OR (procOffsets[x - 1].data.pcLimit <= entry.pcFrom)) & (entry.pcLimit <= procOffsets[x].data.pcFrom);
  574. UNTIL isHit OR (l > r);
  575. IF isHit THEN
  576. pos := x; success := TRUE
  577. ELSE
  578. IF (x = numProcs - 1) & (procOffsets[x].data.pcLimit <= entry.pcFrom) THEN
  579. pos := x + 1; success := TRUE
  580. END
  581. END
  582. END;
  583. RETURN success
  584. END FindInsertionPos;
  585. PROCEDURE NumTotalPtrs(procTable: ProcTable): LONGINT;
  586. VAR i, num: LONGINT;
  587. BEGIN
  588. num := 0;
  589. IF procTable # NIL THEN
  590. FOR i := 0 TO LEN(procTable) - 1 DO
  591. num := num + procTable[i].noPtr
  592. END;
  593. END;
  594. RETURN num
  595. END NumTotalPtrs;
  596. (* insert the procedure code offsets and pointer offsets of a single module into the global table *)
  597. PROCEDURE InsertProcOffsets(procTable: ProcTable; ptrTable: PtrTable; maxPtr: LONGINT);
  598. VAR success: BOOLEAN; i, j, pos, poslast, newLen, num,numberPointer: LONGINT;
  599. temp: ADDRESS;
  600. newProcOffsets: ProcOffsetTable; newPtrOffsets: PtrTable;
  601. ptrOfsLen,procOfsLen: LONGINT;
  602. BEGIN
  603. (* this procedure is called by procedure Publish only and is protected by the Machine.Modules lock *)
  604. IF procTable=NIL THEN RETURN END;
  605. IF ptrTable=NIL THEN RETURN END;
  606. IF LEN(procTable) > 0 THEN
  607. IF procOffsets = NIL THEN procOfsLen := 0 ELSE procOfsLen := LEN(procOffsets) END;
  608. IF numProcs + LEN(procTable) > procOfsLen THEN
  609. newLen := procOfsLen + InitTableLen;
  610. WHILE numProcs + LEN(procTable) > newLen DO newLen := newLen + InitTableLen END;
  611. NEW(newProcOffsets, newLen);
  612. FOR i := 0 TO numProcs - 1 DO
  613. newProcOffsets[i] := procOffsets[i]
  614. END;
  615. procOffsets := newProcOffsets
  616. END;
  617. num := NumTotalPtrs(procTable);
  618. IF ptrOffsets = NIL THEN ptrOfsLen := 0 ELSE ptrOfsLen := LEN(ptrOffsets) END;
  619. IF numPtrs + num > ptrOfsLen THEN
  620. newLen := ptrOfsLen + InitPtrTableLen;
  621. WHILE numPtrs + num > newLen DO newLen := newLen + InitPtrTableLen END;
  622. NEW(newPtrOffsets, newLen);
  623. FOR i := 0 TO numPtrs - 1 DO
  624. newPtrOffsets[i] := ptrOffsets[i]
  625. END;
  626. ptrOffsets := newPtrOffsets
  627. END;
  628. success := FindInsertionPos(procTable[0], pos); success := success & FindInsertionPos(procTable[LEN(procTable) - 1], poslast);
  629. IF (~success) OR (pos # poslast) THEN Machine.Release(Machine.Modules); HALT(2001) END;
  630. FOR i := numProcs - 1 TO pos BY -1 DO procOffsets[i + LEN(procTable)] := procOffsets[i] END;
  631. numberPointer := 0;
  632. FOR i := 0 TO LEN(procTable) - 1 DO
  633. procOffsets[pos + i].data := procTable[i];
  634. procOffsets[pos + i].startIndex := numPtrs; (* this field is never accessed in case of procTable[i].noPtr = 0, so we may as well put numPtrs in there *)
  635. FOR j := 0 TO procTable[i].noPtr - 1 DO
  636. (*
  637. temp := ptrTable[numberPointer]; INC(numberPointer);
  638. *)
  639. temp := ptrTable[i * maxPtr + j];
  640. ptrOffsets[numPtrs + j] := temp;
  641. END;
  642. numPtrs := numPtrs + procTable[i].noPtr;
  643. END;
  644. numProcs := numProcs + LEN(procTable);
  645. END
  646. END InsertProcOffsets;
  647. (** deletes a sequence of entries given in procTable from the global procOffsets table - the table remains sorted,
  648. this procedure is called within AosLocks.AosModules, so no lock is taken here. *)
  649. PROCEDURE DeleteProcOffsets(firstProcPC: ADDRESS; noProcsInMod: LONGINT);
  650. VAR pos, i, noPtrsInMod, oldIndex: LONGINT; success: BOOLEAN;
  651. BEGIN
  652. IF noProcsInMod > 0 THEN
  653. success := FindPos(firstProcPC, pos);
  654. IF success THEN
  655. (* delete entries in ptrOffsets first *)
  656. noPtrsInMod := 0;
  657. FOR i := pos TO pos + noProcsInMod - 1 DO
  658. noPtrsInMod := noPtrsInMod + procOffsets[i].data.noPtr
  659. END;
  660. oldIndex := procOffsets[pos].startIndex;
  661. FOR i := procOffsets[pos].startIndex + noPtrsInMod TO numPtrs - 1 DO
  662. ptrOffsets[i - noPtrsInMod] := ptrOffsets[i]
  663. END;
  664. numPtrs := numPtrs - noPtrsInMod;
  665. (* delete entries in procOffsets *)
  666. FOR i := pos + noProcsInMod TO numProcs - 1 DO
  667. procOffsets[i - noProcsInMod] := procOffsets[i]
  668. END;
  669. numProcs := numProcs - noProcsInMod;
  670. (* adjust startIndex of procOffsets entries greater than those that have been deleted *)
  671. FOR i := 0 TO numProcs - 1 DO
  672. IF procOffsets[i].startIndex > oldIndex THEN
  673. procOffsets[i].startIndex := procOffsets[i].startIndex - noPtrsInMod
  674. END
  675. END;
  676. ELSE
  677. Trace.String("corrupt global procOffsets table"); Trace.Ln;
  678. Machine.Release(Machine.Modules);
  679. HALT(2000)
  680. END
  681. END
  682. END DeleteProcOffsets;
  683. (** Install procedure to execute when module is freed or shut down. The handler can distinguish the two cases by checking Modules.shutdown. If it is None, the module is being freed, otherwise the system is being shut down or rebooted. Only one handler may be installed per module. The last handler installed is active. *)
  684. PROCEDURE InstallTermHandler*(h: TerminationHandler);
  685. VAR m: Module;
  686. BEGIN
  687. m := ThisModuleByAdr(SYSTEM.VAL (ADDRESS, h));
  688. IF m # NIL THEN
  689. m.term := h (* overwrite existing handler, if any *)
  690. END
  691. END InstallTermHandler;
  692. (** Free a module. The module's termination handler, if any, is called first. Then all objects that have finalizers in this module are finalized (even if they are still reachable). Then the module's data and code are invalidated. *)
  693. PROCEDURE FreeModule*(CONST name: ARRAY OF CHAR; VAR res: LONGINT; VAR msg: ARRAY OF CHAR);
  694. VAR p, m: Module; term: TerminationHandler; i: LONGINT;
  695. BEGIN
  696. m := ModuleByName(name);
  697. IF (m # NIL) & (m.refcnt = 0) THEN (* will be freed below *)
  698. IF m.term # NIL THEN (* call termination handler *)
  699. term := m.term; m.term := NIL; term (* may trap *)
  700. END;
  701. Heaps.CleanupModuleFinalizers(ADDRESSOF(m.code[0]), LEN(m.code), m.name)
  702. END;
  703. res := Ok; msg[0] := 0X;
  704. Machine.Acquire(Machine.Modules);
  705. Trace.String("Acquired Machine.Modules x"); Trace.Ln;
  706. p := NIL; m := root;
  707. WHILE (m # NIL) & (m.name # name) DO p := m; m := m.next END;
  708. Trace.String("Acquired Machine.Modules y"); Trace.Ln;
  709. IF m # NIL THEN
  710. Trace.String("found module"); Trace.Ln;
  711. IF m.refcnt = 0 THEN (* free the module *)
  712. FOR i := 0 TO LEN(m.module)-1 DO DEC(m.module[i].refcnt) END;
  713. m.init := FALSE; (* disallow ThisCommand *)
  714. Append("?", m.name);
  715. (* move module to free list *)
  716. IF p = NIL THEN root := root.next ELSE p.next := m.next END;
  717. m.next := freeRoot; freeRoot := m;
  718. (* clear global pointers and code *)
  719. IF m.ptrAdr # NIL THEN
  720. Trace.String("ptradr del"); Trace.Ln;
  721. FOR i := 0 TO LEN(m.ptrAdr)-1 DO SYSTEM.PUT (m.ptrAdr[i], NIL) END;
  722. END;
  723. IF ClearCode & (m.code # NIL) THEN
  724. Trace.String("clear code"); Trace.Ln;
  725. FOR i := 0 TO LEN(m.code)-1 DO m.code[i] := 0CCX END
  726. END;
  727. Trace.String("clear code f"); Trace.Ln;
  728. (* remove references to module data *)
  729. m.published := FALSE;
  730. m.entry := NIL; m.command := NIL; m.ptrAdr := NIL;
  731. (* do not clear m.type or m.module, as old heap block tags might reference type descs indirectly. *) (* m.staticTypeDescs, m.typeInfo ??? *)
  732. (* do not clear m.data or m.code, as they are used in ThisModuleByAdr (for debugging). *)
  733. (* do not clear m.refs, as they are used in Traps (for debugging). *)
  734. m.export.dsc := NIL; m.exTable := NIL;
  735. (*Trace.String("delete proc offsets"); Trace.Ln;
  736. DeleteProcOffsets(m.firstProc, m.noProcs);
  737. *)
  738. ELSE
  739. res := 1901; (* can not free module in use *)
  740. COPY(name, msg); Append(" reference count not zero", msg)
  741. END
  742. ELSE
  743. res := 1902; (* module not found *)
  744. COPY(name, msg); Append(" not found", msg)
  745. END;
  746. Machine.Release(Machine.Modules)
  747. END FreeModule;
  748. (** Shut down all modules by calling their termination handlers and then call Machine.Shutdown. *)
  749. PROCEDURE Shutdown*(code: LONGINT);
  750. VAR m: Module; term: TerminationHandler;
  751. BEGIN
  752. IF code # None THEN
  753. LOOP
  754. Machine.Acquire(Machine.Modules);
  755. m := root; WHILE (m # NIL) & (m.term = NIL) DO m := m.next END;
  756. IF m # NIL THEN term := m.term; m.term := NIL END;
  757. Machine.Release(Machine.Modules);
  758. IF m = NIL THEN EXIT END;
  759. IF trace THEN
  760. Machine.Acquire (Machine.TraceOutput);
  761. Trace.String("TermHandler "); Trace.StringLn (m.name);
  762. Machine.Release (Machine.TraceOutput);
  763. END;
  764. term (* if this causes exception or hangs, another shutdown call will retry *)
  765. END;
  766. (* clean up finalizers *)
  767. m := root;
  768. WHILE m # NIL DO
  769. IF LEN(m.code)>0 THEN
  770. Heaps.CleanupModuleFinalizers(ADDRESSOF(m.code[0]), LEN(m.code), m.name)
  771. END;
  772. m := m.next
  773. END;
  774. IF trace THEN
  775. Machine.Acquire (Machine.TraceOutput);
  776. Trace.StringLn ("Modules.Shutdown finished");
  777. Machine.Release (Machine.TraceOutput);
  778. END;
  779. Machine.Shutdown(code = Reboot) (* does not return *)
  780. END
  781. END Shutdown;
  782. (* Is this PC handled in the corresponding module. deep = scan the whole stack. *)
  783. PROCEDURE IsExceptionHandled*(VAR pc, fp: ADDRESS; deep: BOOLEAN): BOOLEAN;
  784. VAR
  785. handler: ADDRESS;
  786. BEGIN
  787. IF deep THEN
  788. handler := GetExceptionHandler(pc);
  789. IF handler # -1 THEN (* Handler in the current PAF *)
  790. RETURN TRUE
  791. ELSE
  792. WHILE (fp # 0) & (handler = -1) DO
  793. SYSTEM.GET (fp + 4, pc);
  794. pc := pc - 1; (* CALL instruction, machine dependant!!! *)
  795. handler := GetExceptionHandler(pc);
  796. SYSTEM.GET (fp, fp) (* Unwind PAF *)
  797. END;
  798. IF handler = -1 THEN RETURN FALSE ELSE pc := handler; RETURN TRUE END
  799. END
  800. ELSE
  801. RETURN GetExceptionHandler(pc) # -1
  802. END
  803. END IsExceptionHandled;
  804. (* Is this PC handled in the corresponding module. If the PC is handled the PC of the
  805. handler is return else -1 is return. There is no problem concurrently accessing this
  806. procedure, there is only reading work. *)
  807. PROCEDURE GetExceptionHandler*(pc: ADDRESS): ADDRESS;
  808. VAR
  809. m: Module;
  810. PROCEDURE BinSearch(exTable: ExceptionTable; key: ADDRESS): ADDRESS;
  811. VAR
  812. x, l, r: LONGINT;
  813. BEGIN
  814. l := 0; r:=LEN(exTable) - 1;
  815. REPEAT
  816. x := (l + r) DIV 2;
  817. IF key < exTable[x].pcFrom THEN r := x - 1 ELSE l := x + 1 END;
  818. UNTIL ((key >= exTable[x].pcFrom) & (key < exTable[x].pcTo) ) OR (l > r);
  819. IF (key >= exTable[x].pcFrom) & (key < exTable[x].pcTo) THEN
  820. RETURN exTable[x].pcHandler;
  821. ELSE
  822. RETURN -1;
  823. END
  824. END BinSearch;
  825. BEGIN
  826. m := ThisModuleByAdr(pc);
  827. IF (m # NIL) & (m.exTable # NIL) & (LEN(m.exTable) > 0) THEN
  828. RETURN BinSearch(m.exTable, pc);
  829. END;
  830. RETURN -1;
  831. END GetExceptionHandler;
  832. (** fof: to make custom solutions to the race process, described below, possible. This is not a solution to the generic problem !! *)
  833. PROCEDURE Initialized*(m: Module): BOOLEAN;
  834. BEGIN
  835. RETURN m.init;
  836. END Initialized;
  837. (** Return the specified kernel procedure address. *)
  838. PROCEDURE GetKernelProc*(num: LONGINT): ADDRESS;
  839. VAR adr: ADDRESS;
  840. BEGIN
  841. adr := kernelProc[253-num];
  842. ASSERT(adr # 0);
  843. RETURN adr
  844. END GetKernelProc;
  845. PROCEDURE Register- (module {UNTRACED}: Module);
  846. BEGIN {UNCOOPERATIVE, UNCHECKED}
  847. (*TRACE(module.name);*)
  848. IF register.first = NIL THEN
  849. register.first := module;
  850. ELSE
  851. register.last.next := module;
  852. END;
  853. register.last := module;
  854. END Register;
  855. PROCEDURE PublishRegisteredModules;
  856. VAR m {UNTRACED}, prev {UNTRACED}, cur {UNTRACED}: Module; module, import: SIZE;
  857. BEGIN
  858. WHILE register.first # NIL DO
  859. m := register.first;
  860. register.first := m.next;
  861. m.next := NIL;
  862. IF m.module # NIL THEN
  863. FOR import := 0 TO LEN (m.module) - 1 DO
  864. IF ~m.module[import].published THEN
  865. ASSERT(register.first # NIL);
  866. prev := NIL;
  867. cur := register.first;
  868. WHILE (cur # NIL) & (cur # m.module[import]) DO
  869. prev := cur;
  870. cur := cur.next
  871. END;
  872. (*ASSERT(cur = m.module[import]);*)
  873. ASSERT(cur = m.module[import]);
  874. IF prev = NIL THEN
  875. register.first := cur.next
  876. ELSE
  877. prev.next := cur.next;
  878. END;
  879. cur.next := NIL;
  880. Initialize0 (m.module[import]);
  881. END
  882. END;
  883. END;
  884. Initialize0 (m);
  885. END;
  886. END PublishRegisteredModules;
  887. (* procedure that will be called last in a linked kernel *)
  888. PROCEDURE {FINAL, NOPAF} Main;
  889. BEGIN
  890. (*Machine.Init;*)
  891. Trace.String("publish registered modules"); Trace.Ln;
  892. PublishRegisteredModules;
  893. END Main;
  894. PROCEDURE Init;
  895. VAR
  896. newArr: PROCEDURE (VAR p: ANY; elemTag: ADDRESS; numElems, numDims: SIZE; isRealtime: BOOLEAN);
  897. newSys: PROCEDURE (VAR p: ANY; size: SIZE; isRealtime: BOOLEAN);
  898. newRec: PROCEDURE (VAR p: ANY; tag: ADDRESS; isRealtime: BOOLEAN);
  899. getProcedure: PROCEDURE(CONST m, p : ARRAY OF CHAR; argTdAdr, retTdAdr : ADDRESS; VAR entryAdr : ADDRESS);
  900. s: ARRAY 4 OF CHAR;
  901. module: Module; new: BOOLEAN; i: LONGINT;
  902. BEGIN
  903. (* root and initBlock are initialized by the linker *)
  904. shutdown := None;
  905. newArr := Heaps.NewArr;
  906. newSys := Heaps.NewSys;
  907. newRec := Heaps.NewRec;
  908. getProcedure := GetProcedure;
  909. kernelProc[0] := SYSTEM.VAL (ADDRESS, newRec); (* 253 *)
  910. kernelProc[1] := SYSTEM.VAL (ADDRESS, newSys); (* 252 *)
  911. kernelProc[2] := SYSTEM.VAL (ADDRESS, newArr); (* 251 *)
  912. kernelProc[3] := 0; (* 250 *)
  913. kernelProc[4] := 0; (* 249 *)
  914. kernelProc[5] := 0; (* 248 *)
  915. kernelProc[6] := 0; (* 247 *)
  916. kernelProc[7] := 0; (* 246 *)
  917. kernelProc[8] := 0; (* 245 *)
  918. kernelProc[9] := 0; (* 244 *)
  919. kernelProc[10] := SYSTEM.VAL(ADDRESS, getProcedure); (* 243 *)
  920. numLoaders := 0;
  921. freeRoot := NIL;
  922. Machine.GetConfig("TraceModules", s);
  923. trace := (s[0] = "1");
  924. (*
  925. FOR i := 0 TO Runtime.modules-1 DO
  926. module := SYSTEM.VAL(Module,Runtime.kernelModule[i]);
  927. IF TraceBoot THEN
  928. Trace.String("publishing module ");
  929. Trace.String(module.name); Trace.Ln;
  930. END;
  931. Publish(module,new);
  932. ASSERT(new,112233);
  933. END;
  934. *)
  935. (*
  936. module := SYSTEM.VAL(Module,SELF);
  937. Publish(module,new);
  938. *)
  939. END Init;
  940. BEGIN
  941. Init;
  942. END Modules.
  943. (*
  944. 19.03.1998 pjm Started
  945. 06.10.1998 pjm FreeModule
  946. Note:
  947. o GetProcedure race: process A calls ThisModule, the module is published, but before its body has finished executing, process B calls GetProcedure, causing the assert (m.init) to fail. Process B should perhaps wait in this case until the body has executed, or GetProcedure should return NIL (but that will just move the race to the user).
  948. *)