2
0

Generic.Modules.Mod 32 KB

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