Win64.Objects.Mod 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464
  1. (* Aos, Copyright 2001, Pieter Muller, ETH Zurich; this module ported for the windows version, fof. *)
  2. MODULE Objects; (** AUTHOR "pjm, ejz, fof"; PURPOSE "Active object runtime support"; *)
  3. IMPORT SYSTEM, Trace, Kernel32, Machine, Modules, Heaps;
  4. CONST
  5. HandleExcp = TRUE; (* FALSE -> we asume that it is done correctly by Traps *)
  6. TraceVerbose = FALSE;
  7. StrongChecks = FALSE; defaultStackSize = 0;
  8. TraceOpenClose = FALSE;
  9. CONST
  10. (* Process flags *)
  11. Restart* = 0; (* Restart/Destroy process on exception *)
  12. PleaseHalt* = 10; (* Process requested to Halt itself soon *)
  13. Unbreakable* = 11;
  14. SelfTermination* = 12;
  15. Preempted* = 27; (* Has been preempted. *)
  16. Resistant* = 28; (* Can only be destroyed by itself *)
  17. PleaseStop* = 31; (* Process requested to Terminate or Halt itself soon *)
  18. InActive* = 26; (* needed to prevent processes to call finalizers while in await or lock or unlock, see Kernel.GC *)
  19. (** Process modes *)
  20. Unknown* = 0; Ready* = 1; (* for compatibility with native A2 *)
  21. Running* = 2; AwaitingLock* = 3; AwaitingCond* = 4; AwaitingEvent* = 5; Suspended* = 6; Terminated* = 7;
  22. (** Process priorities *)
  23. MinPriority = 0; (* only system idle processes run at this priority level *)
  24. Low* = 1; Normal* = 2; High* = 3; (* "user" priorities *)
  25. GCPriority* = 4; (* priority of garbage collector *)
  26. Realtime* = 5; (* reserved for interrupt handling and realtime apps, these processes are not allowed to allocate memory *)
  27. (* Process termination halt codes *)
  28. halt* = 2222;
  29. haltUnbreakable* = 2223;
  30. TYPE
  31. CpuCyclesArray* = ARRAY Machine.MaxCPU OF HUGEINT;
  32. ProtectedObject = POINTER TO RECORD END; (* protected object (10000) *)
  33. ProcessQueue = Heaps.ProcessQueue;
  34. Body = PROCEDURE (self: ProtectedObject);
  35. Condition = PROCEDURE (slink: ADDRESS): BOOLEAN;
  36. EventHandler* = PROCEDURE {DELEGATE};
  37. RealtimeEventHandler* = PROCEDURE {DELEGATE, REALTIME};
  38. Timer* = POINTER TO RECORD
  39. next, prev : Timer;
  40. trigger: LONGINT;
  41. handler: EventHandler
  42. END;
  43. RealtimeTimer* = POINTER TO RECORD
  44. next, prev: RealtimeTimer;
  45. trigger: LONGINT;
  46. handler: RealtimeEventHandler
  47. END;
  48. Clock = OBJECT
  49. VAR h: Timer;
  50. ticks: LONGINT;
  51. hevent: Kernel32.HANDLE;
  52. res: Kernel32.BOOL;
  53. mode: LONGINT;
  54. process: Process;
  55. PROCEDURE Wakeup;
  56. VAR res: Kernel32.BOOL;
  57. BEGIN {EXCLUSIVE}
  58. res := Kernel32.SetEvent(hevent)
  59. END Wakeup;
  60. PROCEDURE Finalize(ptr: ANY);
  61. VAR res: Kernel32.BOOL;
  62. BEGIN
  63. IF hevent # 0 THEN res := Kernel32.CloseHandle(hevent); hevent := 0 END
  64. END Finalize;
  65. PROCEDURE &Init*;
  66. VAR fn: Heaps.FinalizerNode;
  67. BEGIN
  68. hevent := Kernel32.CreateEvent(NIL, 0, 0, NIL);
  69. ASSERT(hevent # 0);
  70. NEW(fn); fn.finalizer := SELF.Finalize; Heaps.AddFinalizer(SELF, fn)
  71. END Init;
  72. BEGIN {ACTIVE, SAFE, PRIORITY(High)}
  73. process := CurrentProcess();
  74. mode := process.mode;
  75. LOOP
  76. Machine.Acquire(Machine.Objects);
  77. process.mode := mode;
  78. LOOP
  79. h := event.next; (* event: head of timer event queue *)
  80. ticks := Kernel32.GetTickCount();
  81. IF (h = event) OR (h.trigger - ticks > 0) THEN EXIT END;
  82. event.next := h.next; event.next.prev := event; (* unlink *)
  83. h.next := NIL; h.prev := NIL;
  84. Machine.Release(Machine.Objects);
  85. h.handler(); (* assume handler will return promptly *)
  86. Machine.Acquire(Machine.Objects)
  87. END;
  88. mode := process.mode;
  89. process.mode := AwaitingEvent;
  90. Machine.Release(Machine.Objects);
  91. IF h = event THEN (* sentinel head of timer event queue: wait forever until a new event has been entered in queue *)
  92. res := Kernel32.WaitForSingleObject(hevent, MAX(LONGINT));
  93. ELSE
  94. res := Kernel32.WaitForSingleObject(hevent, h.trigger - ticks);
  95. END;
  96. END
  97. END Clock;
  98. TYPE
  99. Win32Event = Kernel32.HANDLE;
  100. GCContext = RECORD
  101. nextPos: LONGINT; (* 0 to start with *)
  102. (*first,*) last: ARRAY 256 OF ADDRESS; (* first might be not required *)
  103. END;
  104. Process* = OBJECT(Heaps.ProcessLink)
  105. VAR
  106. rootedNext : Process; (* to prevent process to be GCed in WinAos *)
  107. obj-: ProtectedObject; (* associated active object *)
  108. state- {ALIGNED=16}: Kernel32.Context;
  109. (*
  110. sse: SSEState; (* fpu and sse state of preempted process (only valid if Preempted IN flag) *)
  111. sseAdr: LONGINT;
  112. *)
  113. condition-: Condition; (* awaited process' condition *)
  114. condFP-: ADDRESS; (* awaited process' condition's context *)
  115. mode-: LONGINT; (* process state *) (* only changed inside Objects lock ??? *)
  116. procID-: LONGINT; (* processor ID where running, exported for compatibilty , useless in WinAos *)
  117. waitingOn-: ProtectedObject; (* obj this process is waiting on (for lock or condition) *)
  118. id-: LONGINT; (* unique process ID for tracing *)
  119. flags*: SET; (* process flags *)
  120. priority-: LONGINT; (* process priority *)
  121. (*
  122. currPri: LONGINT;
  123. stack*: Machine.Stack; (** user-level stack of process *)
  124. *)
  125. stackBottom: ADDRESS;
  126. handle-: Kernel32.HANDLE; (* handle to corresponding Windows thread *)
  127. body: Body;
  128. event: Win32Event;
  129. restartPC-: ADDRESS; (** entry point of body, for SAFE exception recovery *)
  130. restartSP-: ADDRESS; (** stack level at start of body, for SAFE exception recovery *)
  131. (*
  132. perfCyc*: ARRAY Machine.MaxCPU OF HUGEINT;
  133. priInvCnt: LONGINT; (* counts the nummber of object locks hold that increased currPri of the process *)
  134. exp*: Machine.ExceptionState;
  135. oldReturnPC: LONGINT;
  136. *)
  137. lastThreadTimes: HUGEINT; (*ALEX 2005.12.12*)
  138. gcContext: GCContext;
  139. context: ANY; (* commands contect *)
  140. PROCEDURE FindRoots; (* override, called while GC, replaces Threads.CheckStacks *)
  141. VAR sp: ADDRESS; res: Kernel32.BOOL; pc, bp: ADDRESS;
  142. n,adr: ADDRESS; desc {UNTRACED}: Modules.ProcedureDescPointer; p {UNTRACED}: ANY; i: SIZE;
  143. a0,a1, obp, osb, osbp, opc, gbp: ADDRESS;
  144. O: ANY; ID: LONGINT;
  145. mod {UNTRACED}: Modules.Module;
  146. proc {UNTRACED}: Modules.ProcedureDescPointer;
  147. modName: ARRAY 128 OF CHAR;
  148. mode0,mode1: LONGINT;
  149. contextPos: LONGINT;
  150. BEGIN{UNCHECKED} (* avoid winapi call indirection *)
  151. O := obj; ID := id;
  152. IF (handle = 0) OR (mode = Terminated) OR (mode < Ready) (* procedure Wrapper not yet started *)
  153. OR (priority > High) (* stack of GC and realtime processes not traced *) THEN
  154. RETURN
  155. END;
  156. IF CurrentProcess() = SELF THEN
  157. sp := Machine.CurrentSP(); bp :=Machine.CurrentBP(); pc := Machine.CurrentPC();
  158. ELSE
  159. res := Kernel32.SuspendThread(handle); (* can suspend a suspended thread -- no problem at all *)
  160. state.ContextFlags := Kernel32.SetToDW(Kernel32.ContextControl + Kernel32.ContextInteger);
  161. res := Kernel32.GetThreadContext( handle, state );
  162. IF res = 0 THEN Trace.String("could not get thread context:"); Trace.Int(Kernel32.GetLastError(),1) END;
  163. sp := state.SP; bp := state.BP; pc := state.PC;
  164. mod := Modules.ThisModuleByAdr0(pc);
  165. IF mod # NIL THEN
  166. COPY(mod.name, modName);
  167. proc := Modules.FindProc(pc,mod.procTable);
  168. END;
  169. obp := bp; osb := stackBottom; opc := pc;
  170. osbp := state.BP;
  171. END;
  172. IF TraceProcessHook # NIL THEN
  173. TraceProcessHook(SELF,pc,bp,sp,stackBottom);
  174. END;
  175. contextPos := gcContext.nextPos;
  176. (* stack garbage collection *)
  177. IF Heaps.GCType= Heaps.HeuristicStackInspectionGC THEN
  178. Heaps.Candidate( state.RDI ); Heaps.Candidate( state.RSI );
  179. Heaps.Candidate( state.RBX ); Heaps.Candidate( state.RDX );
  180. Heaps.Candidate( state.RCX ); Heaps.Candidate( state.RAX );
  181. IF (stackBottom # 0) & (sp # 0) THEN
  182. Heaps.RegisterCandidates( sp, stackBottom - sp );
  183. END;
  184. ELSIF Heaps.GCType = Heaps.MetaDataForStackGC THEN
  185. IF TraceVerbose THEN
  186. Trace.String("GC, process id = "); Trace.Int(id,1); Trace.Ln;
  187. END;
  188. LOOP
  189. IF (bp = NIL) OR (bp >= stackBottom) THEN EXIT END;
  190. IF Machine.ValidHeapAddress(pc) THEN
  191. (* ok, valid stack frame from A2, we can trace this *)
  192. ELSE
  193. (* no, cannot trace this Windows stack frame, we have to check if we recorded when we exited A2 previously *)
  194. DEC(contextPos);
  195. IF (contextPos >= 0) THEN
  196. bp := gcContext.last[contextPos];
  197. ELSE
  198. EXIT;
  199. END;
  200. END;
  201. SYSTEM.GET(bp, n);
  202. IF ODD(n) THEN (* procedure descriptor at bp *)
  203. desc := SYSTEM.VAL(Modules.ProcedureDescPointer, n-1);
  204. IF desc # NIL THEN
  205. IF TraceVerbose THEN
  206. WriteType(desc); Trace.Ln;
  207. END;
  208. a0 := ADDRESSOF(desc.offsets);
  209. a1 := SYSTEM.VAL(ADDRESS, desc.offsets);
  210. ASSERT(a0+SIZEOF(ADDRESS)=a1,54321);
  211. FOR i := 0 TO LEN(desc.offsets)-1 DO
  212. adr := bp + desc.offsets[i]; (* pointer at offset *)
  213. SYSTEM.GET(adr, p); (* load pointer *)
  214. IF p # NIL THEN
  215. Heaps.Mark(p);
  216. END;
  217. END;
  218. END;
  219. SYSTEM.GET(bp + 2*SIZEOF(ADDRESS), pc);
  220. SYSTEM.GET(bp + SIZEOF(ADDRESS), bp);
  221. ELSE (* classical stack frame without procedure descriptor *)
  222. SYSTEM.GET(bp + SIZEOF(ADDRESS), pc);
  223. bp := n;
  224. END;
  225. END;
  226. (* ASSERT((bp = stackBottom) OR (bp=0) ,12345); can be violated when coming from windows *)
  227. END;
  228. IF (CurrentProcess() # SELF) (* & (mode # Suspended) *) THEN
  229. res := Kernel32.ResumeThread(handle);
  230. ASSERT(res # -1);
  231. END;
  232. END FindRoots;
  233. END Process;
  234. TYPE
  235. (* ExceptionHandler* = PROCEDURE( CONST exceptionPointers: Kernel32.ExceptionPointers): Kernel32.DWORD; *)
  236. ExceptionHandler* = PROCEDURE( VAR context: Kernel32.Context;
  237. VAR excpRec: Kernel32.ExceptionRecord;
  238. VAR handled: BOOLEAN);
  239. GCStatusExt = OBJECT(Heaps.GCStatus)
  240. (* called from Heaps.InvokeGC, i.e. this is a hidden upcall. However, it is necessary to take the Machine.Objects lock here since writing
  241. the set of variables here must not be interrupted, i.e. atomic writing of the set of variables is absolutely necessary. They system may hang
  242. if the lock is not taken. *)
  243. PROCEDURE SetgcOngoing(value: BOOLEAN);
  244. VAR p: Heaps.ProcessLink; cur, r: Process; res: Kernel32.BOOL; num: LONGINT; time: LONGINT;
  245. BEGIN (* serialize writers *)
  246. IF value THEN
  247. (* Low, Medium or High priority process calls this *)
  248. time := Kernel32.GetTickCount();
  249. Machine.Acquire(Machine.Objects);
  250. Machine.Acquire(Machine.Heaps); (* to protect agains concurrent LazySweep *)
  251. r := CurrentProcess();
  252. num := 0;
  253. p := ready.head;
  254. WHILE p # NIL DO
  255. cur := p(Process);
  256. IF ((cur.mode = Ready) OR (cur.mode = Running)) & (cur.priority <= High) & (cur # r) THEN
  257. res := Kernel32.SuspendThread(cur.handle);
  258. ASSERT(res >= 0);
  259. cur.mode := Suspended
  260. ELSE INC(num);
  261. END;
  262. p := p.next
  263. END;
  264. Heaps.CollectGarbage(Modules.root);
  265. p := ready.head;
  266. WHILE (p # NIL) DO
  267. cur := p(Process);
  268. (* only suspended and awaiting processes of ready queue are resumed *)
  269. IF cur.mode = Suspended THEN
  270. res := Kernel32.ResumeThread(cur.handle);
  271. ASSERT(res >= 0);
  272. cur.mode := Running
  273. END;
  274. p := p.next
  275. END;
  276. Machine.Release(Machine.Heaps);
  277. Machine.Release(Machine.Objects);
  278. time := Kernel32.GetTickCount()-time;
  279. IF Heaps.trace THEN Trace.String("GC Called -- duration "); Trace.Int(time,0); Trace.String(" ms."); Trace.Ln END;
  280. IF finalizerCaller # NIL THEN finalizerCaller.Activate() END;
  281. END;
  282. END SetgcOngoing;
  283. END GCStatusExt;
  284. FinalizedCollection* = OBJECT
  285. PROCEDURE RemoveAll*(obj: ANY); (** abstract *)
  286. BEGIN HALT(301) END RemoveAll;
  287. END FinalizedCollection;
  288. FinalizerNode* = POINTER TO RECORD (Heaps.FinalizerNode)
  289. c*: FinalizedCollection (* base type for collection containing object *)
  290. END;
  291. FinalizerCaller = OBJECT (* separate active object that calls finalizers *)
  292. VAR n: Heaps.FinalizerNode;
  293. event: Kernel32.HANDLE;
  294. process: Process;
  295. PROCEDURE &Init;
  296. BEGIN
  297. event := Kernel32.CreateEvent( NIL, Kernel32.False (* automatic *), Kernel32.False, NIL );
  298. ASSERT(event # 0);
  299. END Init;
  300. PROCEDURE Wait;
  301. VAR res: Kernel32.BOOL; mode: LONGINT;
  302. BEGIN
  303. mode := process.mode;
  304. process.mode := AwaitingEvent;
  305. res := Kernel32.WaitForSingleObject(event, Kernel32.Infinite);
  306. ASSERT(res = Kernel32.WaitObject0);
  307. process.mode := mode;
  308. END Wait;
  309. PROCEDURE Activate;
  310. VAR res: Kernel32.BOOL;
  311. BEGIN
  312. res := Kernel32.SetEvent(event);
  313. END Activate;
  314. BEGIN {ACTIVE, SAFE, PRIORITY(High)}
  315. process := CurrentProcess();
  316. LOOP
  317. Wait;
  318. LOOP
  319. n := Heaps.GetFinalizer();
  320. IF n = NIL THEN EXIT END;
  321. IF n IS FinalizerNode THEN
  322. n( FinalizerNode ).c.RemoveAll( n.objStrong ) (* remove it if it is not removed yet *)
  323. END;
  324. IF n.finalizer # NIL THEN
  325. n.finalizer( n.objStrong ) (* may acquire locks *)
  326. END
  327. END
  328. END;
  329. END FinalizerCaller;
  330. VAR
  331. awc-, awl-: LONGINT;
  332. oberonLoop*: ANY; (* Oberon Loop Process temporary workaround for Threads.oberonLoop *)
  333. break: ARRAY 16 OF CHAR;
  334. terminateProc: PROCEDURE;
  335. ready: ProcessQueue; (* contains running processes in this implementation *)
  336. numberOfProcessors: LONGINT; (* cached value of Machine.NumberOfProcessors() *)
  337. finalizerCaller: FinalizerCaller; (* active object for finalizer process, regarded as aprt of GC *)
  338. event: Timer; (* list of events *)
  339. clock: Clock;
  340. tlsIndex: LONGINT;
  341. nProcs: LONGINT;
  342. excplock: Kernel32.CriticalSection; exceptionhandler: ExceptionHandler;
  343. (* Set the current process' priority. *)
  344. PROCEDURE SetPriority*( priority: LONGINT );
  345. VAR r: Process; prio: LONGINT; res: Kernel32.BOOL;
  346. BEGIN
  347. ASSERT((priority >= Low) & (priority <= Realtime)); (* priority in bounds *)
  348. r := CurrentProcess(); r.priority := priority;
  349. CASE priority OF
  350. MinPriority:
  351. prio := Kernel32.ThreadPriorityIdle
  352. | Low:
  353. prio := Kernel32.ThreadPriorityBelowNormal
  354. | High:
  355. prio := Kernel32.ThreadPriorityAboveNormal
  356. | GCPriority, Realtime:
  357. prio := Kernel32.ThreadPriorityTimeCritical
  358. ELSE (* Normal *)
  359. prio := Kernel32.ThreadPriorityNormal
  360. END;
  361. res := Kernel32.SetThreadPriority( r.handle, prio );
  362. ASSERT(r.handle # 0);
  363. ASSERT(res # 0)
  364. END SetPriority;
  365. (** Return TRUE iff the specified protected object is locked exclusive to the current process. *)
  366. PROCEDURE LockedByCurrent*( obj: ANY ): BOOLEAN;
  367. VAR hdr {UNTRACED}: Heaps.ProtRecBlock; res: BOOLEAN;
  368. BEGIN
  369. SYSTEM.GET(SYSTEM.VAL(ADDRESS, obj) + Heaps.HeapBlockOffset, hdr);
  370. ASSERT(hdr IS Heaps.ProtRecBlock);
  371. Machine.Acquire(Machine.Objects);
  372. res := (hdr.lockedBy = ActiveObject());
  373. Machine.Release(Machine.Objects);
  374. RETURN res
  375. END LockedByCurrent;
  376. PROCEDURE Yield*;
  377. BEGIN
  378. Kernel32.Sleep(0)
  379. END Yield;
  380. (** Return current process. (DEPRECATED, use ActiveObject) *)
  381. PROCEDURE CurrentProcess*( ): Process;
  382. BEGIN{UNCHECKED} (* makes sure that Enter and Leave are not emitted *)
  383. RETURN SYSTEM.VAL(Process, Kernel32.TlsGetValue(tlsIndex));
  384. END CurrentProcess;
  385. PROCEDURE CurrentContext*(): ANY;
  386. VAR p: Process;
  387. BEGIN
  388. p := CurrentProcess();
  389. IF p # NIL THEN RETURN p.context
  390. ELSE RETURN NIL
  391. END;
  392. END CurrentContext;
  393. PROCEDURE SetContext*(context: ANY);
  394. VAR p: Process;
  395. BEGIN
  396. p := CurrentProcess();
  397. IF p # NIL THEN p.context := context END;
  398. END SetContext;
  399. (* Return stack bottom of process. For compatibility WinAos/UnixAos/NativeAos *)
  400. PROCEDURE GetStackBottom*(p: Process): ADDRESS;
  401. BEGIN
  402. RETURN p.stackBottom
  403. END GetStackBottom;
  404. (** Return the active object currently executing. *)
  405. PROCEDURE ActiveObject* (): ANY;
  406. VAR r: Process;
  407. BEGIN
  408. r := SYSTEM.VAL(Process, Kernel32.TlsGetValue(tlsIndex));
  409. RETURN r.obj
  410. END ActiveObject;
  411. (** Return the ID of the active currently executing process. *)
  412. PROCEDURE GetProcessID* (): LONGINT;
  413. VAR r: Process;
  414. BEGIN
  415. r := SYSTEM.VAL (Process, Kernel32.TlsGetValue( tlsIndex ));
  416. RETURN r.id
  417. END GetProcessID;
  418. (* Get a process from a queue (NIL if none). Caller must hold lock for specific queue. *)
  419. PROCEDURE Get(VAR queue: ProcessQueue; VAR new: Process);
  420. VAR t: Heaps.ProcessLink;
  421. BEGIN
  422. t := queue.head;
  423. IF t = NIL THEN (* zero elements in queue *)
  424. (* skip *)
  425. ELSIF t = queue.tail THEN (* one element in queue *)
  426. queue.head := NIL; queue.tail := NIL (* {(t.next = NIL) & (t.prev = NIL)} *)
  427. ELSE (* more than one element in queue *)
  428. queue.head := t.next; t.next := NIL; queue.head.prev := NIL
  429. END;
  430. ASSERT((t = NIL) OR (t.next = NIL ) & (t.prev = NIL)); (* temp strong check *)
  431. IF t = NIL THEN
  432. new := NIL
  433. ELSE
  434. ASSERT(t IS Process);
  435. new := t(Process)
  436. END
  437. END Get;
  438. (* Put a process in a queue. Caller must hold lock for specific queue. *)
  439. (* If t was running, be careful to protect Put and the subsequent SwitchTo with the ready lock. *)
  440. PROCEDURE Put(VAR queue: ProcessQueue; t: Process);
  441. BEGIN (* {t # NIL & t.next = NIL & t.prev = NIL} *)
  442. IF StrongChecks THEN
  443. ASSERT((t.next = NIL) & (t.prev = NIL))
  444. END;
  445. t.next := NIL; t.prev := NIL; (* ug *)
  446. IF queue.head = NIL THEN (* queue empty *)
  447. queue.head := t
  448. ELSE (* queue not empty *)
  449. queue.tail.next := t; t.prev := queue.tail
  450. END;
  451. queue.tail := t
  452. END Put;
  453. PROCEDURE {WINAPI} ExcpFrmHandler( CONST exceptionPointers: Kernel32.ExceptionPointers): Kernel32.DWORD ;
  454. VAR m: Modules.Module; eip, ebp, stack: ADDRESS; pc, handler, fp, sp: ADDRESS; handled: BOOLEAN; t: Process;
  455. BEGIN
  456. handled := FALSE;
  457. Kernel32.EnterCriticalSection( excplock );
  458. (*
  459. fof: commenting this resolved a problem with multiple traps that a are catched with FINALLY statements in Windows Vista
  460. in Windows XP not necessary if Kernel32.SetThreadContext is not used (better to return gracefully from this handler)
  461. SetCurrent(excpFrame);
  462. *)
  463. t := CurrentProcess();
  464. IF exceptionhandler = NIL THEN
  465. Trace.StringLn ( "Objects: No exception handler installed" );
  466. IF HandleExcp THEN
  467. Trace.String( "EXCEPTION " ); Trace.Address(exceptionPointers.exception.ExceptionCode);
  468. Trace.String( " at " ); Trace.Address(exceptionPointers.exception.ExceptionAddress);
  469. Trace.Ln(); Trace.String( "RAX " ); Trace.Address(exceptionPointers.context.RAX);
  470. Trace.String( " RBX " ); Trace.Address(exceptionPointers.context.RBX); Trace.Ln();
  471. Trace.String( "RCX " ); Trace.Address(exceptionPointers.context.RCX); Trace.String( " RDX " );
  472. Trace.Address(exceptionPointers.context.RDX); Trace.Ln(); Trace.String( "RDI " );
  473. Trace.Address(exceptionPointers.context.RDI); Trace.String( " RSI " );
  474. Trace.Address(exceptionPointers.context.RSI); Trace.Ln();
  475. Trace.String( "R8 " ); Trace.Address(exceptionPointers.context.R8);
  476. Trace.String( " R9 " ); Trace.Address(exceptionPointers.context.R9); Trace.Ln();
  477. Trace.String( "R10 " ); Trace.Address(exceptionPointers.context.R10);
  478. Trace.String( " R11 " ); Trace.Address(exceptionPointers.context.R11); Trace.Ln();
  479. Trace.String( "R12 " ); Trace.Address(exceptionPointers.context.R12);
  480. Trace.String( " R13 " ); Trace.Address(exceptionPointers.context.R13); Trace.Ln();
  481. Trace.String( "R14 " ); Trace.Address(exceptionPointers.context.R14);
  482. Trace.String( " R15 " ); Trace.Address(exceptionPointers.context.R15); Trace.Ln();
  483. Trace.Ln;
  484. Trace.String( "RBP " );
  485. Trace.Address(exceptionPointers.context.BP); Trace.String( " RSP " );
  486. Trace.Address(exceptionPointers.context.SP); Trace.Ln(); Trace.String( "PC " );
  487. Trace.Address(exceptionPointers.context.PC); Trace.Ln();
  488. Trace.Ln();
  489. eip := exceptionPointers.exception.ExceptionAddress; ebp := exceptionPointers.context.BP;
  490. IF eip = 0 THEN SYSTEM.GET( exceptionPointers.context.SP, eip ) END;
  491. stack := t.stackBottom;
  492. LOOP
  493. Trace.String( "at ebp= " ); Trace.Address(ebp); Trace.String( "H : " );
  494. m := Modules.ThisModuleByAdr( eip );
  495. IF m # NIL THEN
  496. Trace.String( m.name ); Trace.String( " " );
  497. Trace.Address(eip - SYSTEM.VAL( LONGINT, ADDRESSOF( m.code[0] ) ));
  498. ELSE Trace.String( "EIP " ); Trace.Address(eip)
  499. END;
  500. Trace.Ln();
  501. IF (ebp # 0) & (ebp < stack) THEN (* if ebp is 0 in first frame *)
  502. SYSTEM.GET( ebp + SIZEOF(ADDRESS), eip ); (* return addr from stack *)
  503. SYSTEM.GET( ebp, ebp ); (* follow dynamic link *)
  504. ELSE EXIT
  505. END
  506. END;
  507. Trace.Ln();
  508. (* finally and all that ...
  509. handled := FALSE; fp := exceptionPointers.context.BP; sp := exceptionPointers.context.SP;
  510. pc := exceptionPointers.context.PC; handler := Modules.GetExceptionHandler( pc );
  511. IF handler # -1 THEN (* Handler in the current PAF *)
  512. exceptionPointers.context.PC := handler; handled := TRUE;
  513. (*SetTrapVariable(pc, fp); SetLastExceptionState(exc)*)
  514. ELSE
  515. WHILE (fp # 0) & (handler = -1) DO
  516. SYSTEM.GET( fp + SIZEOF(ADDRESS), pc );
  517. pc := pc - 1; (* CALL instruction, machine dependant!!! *)
  518. handler := Modules.GetExceptionHandler( pc );
  519. sp := fp; (* Save the old framepointer into the stack pointer *)
  520. SYSTEM.GET( fp, fp ) (* Unwind PAF *)
  521. END;
  522. IF handler = -1 THEN handled := FALSE;
  523. ELSE
  524. TRACE("CHANGED HANDLER ADR ");
  525. exceptionPointers.context.PC := handler; exceptionPointers.context.BP := fp; exceptionPointers.context.SP := sp;
  526. (* SetTrapVariable(pc, fp); SetLastExceptionState(exc);*)
  527. handled := TRUE
  528. END
  529. END;
  530. *)
  531. ELSE Trace.StringLn ( "Warning: FINALLY statement cannot be treated !" );
  532. END
  533. ELSE exceptionhandler(exceptionPointers.context^, exceptionPointers.exception^,handled );
  534. END;
  535. IF ~handled THEN
  536. exceptionPointers.context.PC := (*TerminateProc*) t.restartPC ;
  537. exceptionPointers.context.SP := t.restartSP;
  538. exceptionPointers.context.BP := t.stackBottom;
  539. ELSIF TraceVerbose THEN Trace.StringLn ( "trying to jump to FINALLY pc..." );
  540. END;
  541. Kernel32.LeaveCriticalSection( excplock );
  542. IF TraceVerbose THEN
  543. Machine.Acquire (Machine.TraceOutput);
  544. Trace.String( "recover process; pc=" ); Trace.Address( exceptionPointers.context.PC );
  545. Trace.String( "; sp= " ); Trace.Address( exceptionPointers.context.SP); Trace.String( "; bp= " );
  546. Trace.Address( exceptionPointers.context.BP); Trace.Ln;
  547. Machine.Release (Machine.TraceOutput);
  548. END;
  549. RETURN Kernel32.ExceptionContinueExecution; (* sets thread context and continues where specified in context *)
  550. END ExcpFrmHandler;
  551. (*
  552. (* get the currently installed execption frame *)
  553. (* PROCEDURE -GetCur 64H, 8BH, 0DH, 0, 0, 0, 0; (* MOV ECX, FS:[0] *) *)
  554. (* Better *)
  555. PROCEDURE -GetCur;
  556. CODE {SYSTEM.AMD64}
  557. MOV RCX, [GS:0]
  558. ; DB 064H, 08BH, 00DH, 000H, 000H, 000H, 000H
  559. END GetCur;
  560. PROCEDURE GetCurrent( ): Kernel32.ExcpFrmPtr;
  561. VAR cur: Kernel32.ExcpFrmPtr;
  562. BEGIN
  563. GetCur;
  564. cur := SYSTEM.VAL(Kernel32.ExcpFrmPtr,Machine.GetRCX());
  565. TRACE(cur);
  566. (* RETURN ECX *)
  567. RETURN cur
  568. END GetCurrent;
  569. *)
  570. (*
  571. (* install a new exception frame *)
  572. (* PROCEDURE -SetCur 64H, 0A3H, 0, 0, 0, 0; (* MOV FS:[0], EAX *)*)
  573. (* Better *)
  574. PROCEDURE -SetCur;
  575. CODE {SYSTEM.AMD64}
  576. ; DB 064H, 0A3H, 000H, 000H, 000H, 000H
  577. MOV [GS:0], RAX
  578. END SetCur;
  579. PROCEDURE SetCurrent( cur: Kernel32.ExcpFrmPtr );
  580. BEGIN
  581. TRACE(cur);
  582. Machine.SetRAX(cur);
  583. (* EAX := cur *)
  584. CODE{SYSTEM.AMD64}
  585. MOV [GS:0], RAX
  586. END;
  587. TRACE(GetCurrent());
  588. (*SetCur*)
  589. END SetCurrent;
  590. *)
  591. PROCEDURE RemoveExcpFrm( VAR excpfrm: Kernel32.ExcpFrm );
  592. VAR this: Kernel32.ExcpFrmPtr;
  593. BEGIN
  594. (*
  595. this := GetCurrent();
  596. (* ASSERT ( this = ADDRESSOF( excpfrm ) ); *)
  597. IF this # ADDRESSOF( excpfrm ) THEN Trace.StringLn ( "RemoveExcpFrm: Problem with excpfrm pointer" );
  598. ELSE SetCurrent( excpfrm.link )
  599. END;
  600. *)
  601. (*
  602. Kernel32.RemoveVectoredExceptionHandler(ExcpFrmHandler);
  603. *)
  604. END RemoveExcpFrm;
  605. PROCEDURE InstallExcpFrm( VAR excpfrm: Kernel32.ExcpFrm );
  606. BEGIN
  607. Kernel32.AddVectoredContinueHandler(1, ExcpFrmHandler);
  608. (*
  609. excpfrm.link := GetCurrent(); excpfrm.handler := ExcpFrmHandler;
  610. SetCurrent( ADDRESSOF( excpfrm ) )
  611. *)
  612. END InstallExcpFrm;
  613. PROCEDURE InQueue( queue: ProcessQueue; t: Process ): BOOLEAN;
  614. VAR p: Heaps.ProcessLink;
  615. BEGIN
  616. p := queue.head;
  617. WHILE (p # NIL ) & (p # t) DO p := p.next; END;
  618. RETURN (p = t);
  619. END InQueue;
  620. (* Remove a process from a queue that contains it. Caller must hold lock for specific queue. *)
  621. (* Not intended for frequent use. *)
  622. (* does not check if queue contained t ! *)
  623. PROCEDURE Remove( VAR queue: ProcessQueue; t: Process );
  624. BEGIN
  625. IF StrongChecks THEN
  626. ASSERT(InQueue(queue, t));
  627. ASSERT(t # NIL);
  628. END;
  629. IF t.prev # NIL THEN t.prev.next := t.next END;
  630. IF t.next # NIL THEN t.next.prev := t.prev END;
  631. IF t = queue.head THEN queue.head := t.next END;
  632. IF t = queue.tail THEN queue.tail := t.prev END;
  633. ASSERT((queue.head = NIL) OR (queue.head.prev = NIL) & (queue.tail.next = NIL));
  634. t.prev := NIL; t.next := NIL
  635. END Remove;
  636. PROCEDURE WriteType(obj: ANY);
  637. VAR type: LONGINT;
  638. BEGIN
  639. IF obj = NIL THEN Trace.String(" > NIL");
  640. ELSE
  641. Trace.String(" > "); SYSTEM.GET(SYSTEM.VAL(LONGINT, obj) + Heaps.TypeDescOffset, type);
  642. Heaps.WriteType(type);
  643. END;
  644. END WriteType;
  645. PROCEDURE terminate( t: Process );
  646. VAR hdr {UNTRACED}: Heaps.ProtRecBlock; res: Kernel32.BOOL; shutdown: BOOLEAN;
  647. BEGIN
  648. IF t = NIL THEN RETURN END;
  649. (* see Objects.TerminateThis *)
  650. Machine.Acquire( Machine.Objects );
  651. IF TraceVerbose OR TraceOpenClose THEN
  652. Machine.Acquire (Machine.TraceOutput);
  653. Trace.String( "Terminating process " ); Trace.Int( t.id, 1 ); WriteType( t.obj ); Trace.Ln;
  654. Machine.Release (Machine.TraceOutput);
  655. END;
  656. IF (t.mode = Ready) OR (t.mode = Running) THEN Remove( ready, t );
  657. ELSIF t.mode = AwaitingLock THEN
  658. SYSTEM.GET(SYSTEM.VAL(ADDRESS, t.waitingOn) + Heaps.HeapBlockOffset, hdr);
  659. ASSERT(hdr IS Heaps.ProtRecBlock);
  660. Remove( hdr.awaitingLock, t ); Machine.Release( Machine.Objects );
  661. HALT( 97 )
  662. ELSIF t.mode = AwaitingCond THEN
  663. SYSTEM.GET(SYSTEM.VAL(ADDRESS, t.waitingOn) + Heaps.HeapBlockOffset, hdr);
  664. ASSERT(hdr IS Heaps.ProtRecBlock);
  665. Remove( hdr.awaitingCond, t ); Machine.Release( Machine.Objects );
  666. HALT( 98 )
  667. ELSE Machine.Release( Machine.Objects );
  668. HALT( 99 )
  669. END;
  670. t.mode := Terminated; (* a process can also be "terminated" if the queue containing it is garbage collected *)
  671. t.stackBottom := 0; t.state.SP := 0;
  672. t.restartPC := 0;
  673. IF t.event # 0 THEN res := Kernel32.CloseHandle( t.event ); t.event := 0 END;
  674. DEC( nProcs ); shutdown := (nProcs = 0);
  675. Machine.Release( Machine.Objects );
  676. IF shutdown THEN
  677. Trace.StringLn ( " Objects: shutdown" ); Modules.Shutdown( -1 );
  678. Kernel32.ExitProcess( 0 )
  679. END
  680. END terminate;
  681. PROCEDURE {WINAPI} Wrapper( lpParameter: ANY ): LONGINT;
  682. VAR t: Process; obj: ProtectedObject; res: Kernel32.BOOL; bp,sp: ADDRESS;
  683. excpfrm: Kernel32.ExcpFrm;
  684. BEGIN
  685. (* it may happen that the garbage collector runs right here and ignores this procedure.
  686. This is not a problem since lpParameter (being a reference to a process) is protected by the process lists *)
  687. Machine.Acquire(Machine.Objects);
  688. res := Kernel32.TlsSetValue(tlsIndex, SYSTEM.VAL(LONGINT, lpParameter));
  689. t := lpParameter(Process); obj := t.obj;
  690. ASSERT(res # 0);
  691. SetPriority(t.priority);
  692. bp := Machine.CurrentBP();
  693. sp := Machine.CurrentSP();
  694. t.restartSP := sp;
  695. t.stackBottom := bp;
  696. IF t.restartPC = SYSTEM.VAL(ADDRESS, terminateProc) THEN DEC(t.restartSP, SIZEOF(ADDRESS))
  697. ELSE DEC(t.restartSP, 2*SIZEOF(ADDRESS))
  698. END;
  699. IF TraceVerbose THEN
  700. Machine.Acquire(Machine.TraceOutput);
  701. Trace.String("New process; restartPC= "); Trace.Address(t.restartPC);
  702. Trace.String("; stackBottom= ");
  703. Trace.Address(t.stackBottom); Trace.Ln;
  704. Machine.Release(Machine.TraceOutput);
  705. END;
  706. t.mode := Running;
  707. (* now gc is enabled for this process stack *)
  708. Machine.Release(Machine.Objects);
  709. (* loop all processes that the GC did not see during process suspending because they were in the very moment being generated (just before the locked section) *)
  710. (*! should not be necessary any more as GC runs immediately and without scheduling decisions
  711. WHILE (gcActivity # NIL) & (gcActivity.process # NIL) & (gcActivity.process.mode = Running) DO END;
  712. *)
  713. t.body(obj);
  714. terminate(t);
  715. RemoveExcpFrm(excpfrm);
  716. RETURN 0
  717. END Wrapper;
  718. PROCEDURE FinalizeProcess(t: ANY);
  719. VAR p: Process; res: Kernel32.BOOL;
  720. BEGIN
  721. p := t(Process);
  722. IF TraceVerbose THEN
  723. Machine.Acquire (Machine.TraceOutput);
  724. Trace.String("Finalizing Process"); Trace.Int(p.id, 1);
  725. WriteType(p.obj); Trace.Ln;
  726. Machine.Release (Machine.TraceOutput);
  727. END;
  728. IF p.mode # Terminated THEN
  729. IF p.mode = AwaitingLock THEN DEC(awl);
  730. ELSIF p.mode = AwaitingCond THEN DEC(awc);
  731. END;
  732. (* no reference to the object any more *)
  733. Trace.String ("Closing unreferenced process"); (*Trace.Int(p.mode,20); Trace.Int( p.id, 20 ); *) Trace.Ln; (* Trace.Ln *)
  734. (* this usually happens, when an objects process waits on its own objtec and no reference exists any more. Then the object is discarded and
  735. consequently the process is unreferenced (except in the object). This cannot happen when there are still other references on the object.
  736. example:
  737. TYPE
  738. Object= OBJECT VAR active: BOOLEAN; BEGIN{ACTIVE} active := FALSE; AWAIT(active) END Object;
  739. VAR o: Object;
  740. BEGIN NEW(o);
  741. END;
  742. *)
  743. END;
  744. p.mode := Terminated; (* fof for GC problem *)
  745. IF p.handle # 0 THEN
  746. res := Kernel32.CloseHandle(p.handle); p.handle := 0
  747. END
  748. END FinalizeProcess;
  749. PROCEDURE TerminateProc;
  750. BEGIN
  751. terminate(CurrentProcess());
  752. Kernel32.ExitThread(0);
  753. Kernel32.Sleep(999999); (* wait until dependent threads terminated *)
  754. END TerminateProc;
  755. (* Allocate a new process associated with "obj". Must be outside lock region, because of potential GC. *)
  756. PROCEDURE NewProcess(body: Body; priority: LONGINT; flags: SET; obj: ProtectedObject; VAR new: Process);
  757. VAR t,r: Process; fn: Heaps.FinalizerNode;
  758. BEGIN
  759. NEW(t);
  760. t.gcContext.nextPos := 0;
  761. t.context := CurrentContext(); (* inherit context from parent process *)
  762. t.handle := 0;
  763. IF priority = 0 THEN (* no priority specified *)
  764. r := CurrentProcess();
  765. t.priority := r.priority (* inherit priority of creator *)
  766. ELSIF priority > 0 THEN (* positive priority specified *)
  767. t.priority := priority
  768. ELSE (* negative priority specified (only for Idle process) *)
  769. t.priority := MinPriority
  770. END;
  771. NEW(fn); (* implicit call Heaps.NewRec -> might invoke GC *)
  772. Machine.Acquire(Machine.Objects);
  773. t.next := NIL; t.prev := NIL; t.rootedNext := NIL;
  774. t.waitingOn := NIL; t.flags := flags; t.obj := obj; t.mode := Unknown;
  775. t.body := body; t.event := 0; fn.finalizer := FinalizeProcess;
  776. Heaps.AddFinalizer(t, fn);
  777. IF Restart IN flags THEN (* restart object body *)
  778. t.restartPC := SYSTEM.VAL(ADDRESS, body);
  779. ELSE (* terminate process *)
  780. t.restartPC := SYSTEM.VAL(ADDRESS, terminateProc);
  781. END;
  782. (* t.restartPC := SYSTEM.VAL(ADDRESS, terminateProc);*)
  783. t.handle := Kernel32.CreateThread(0, defaultStackSize, Wrapper, t, Kernel32.SetToDW({}), t.id);
  784. IF TraceVerbose OR TraceOpenClose THEN
  785. Machine.Acquire(Machine.TraceOutput);
  786. Trace.String("NewProcess: " ); Trace.Int(t.id, 1); WriteType(obj); Trace.Ln;
  787. Machine.Release(Machine.TraceOutput);
  788. END;
  789. ASSERT(t.handle # 0);
  790. new := t;
  791. END NewProcess;
  792. (* Create the process associated with an active object (kernel call). *)
  793. PROCEDURE CreateProcess*(body: Body; priority: LONGINT; flags: SET; obj: ProtectedObject);
  794. VAR t : Process; heapBlock {UNTRACED}: Heaps.HeapBlock;
  795. BEGIN
  796. ASSERT(priority >= 0, 1000); ASSERT(priority <=Realtime, 1001);
  797. SYSTEM.GET(SYSTEM.VAL(ADDRESS, obj) + Heaps.HeapBlockOffset, heapBlock);
  798. ASSERT(heapBlock IS Heaps.ProtRecBlock); (* protected object *)
  799. IF Restart IN flags THEN INCL(flags, Resistant) END; (* SAFE => Restart & Resistant *)
  800. NewProcess(body, priority, flags, obj, t); INC(nProcs); (* acquires Machine.Objects lock *)
  801. t.mode := Ready; Put(ready, t);
  802. Machine.Release(Machine.Objects);
  803. END CreateProcess;
  804. (* The procedure Lock, Unlock and Await do not use header locks since it turned out that the header locks sometimes were finalized
  805. too early. *)
  806. PROCEDURE Lock*(obj: ProtectedObject; exclusive: BOOLEAN );
  807. VAR hdr {UNTRACED}: Heaps.ProtRecBlock; r: Process; res: LONGINT;
  808. BEGIN (* {called from user level} *)
  809. SYSTEM.GET(SYSTEM.VAL(ADDRESS, obj) + Heaps.HeapBlockOffset, hdr);
  810. IF StrongChecks THEN
  811. ASSERT(hdr IS Heaps.ProtRecBlock); (* protected object *)
  812. ASSERT(exclusive) (* shared not implemented yet *)
  813. END;
  814. r := CurrentProcess();
  815. IF StrongChecks THEN
  816. ASSERT(hdr # NIL, 1001);
  817. ASSERT(r # NIL, 1002);
  818. END;
  819. Machine.Acquire(Machine.Objects);
  820. IF hdr.count = 0 THEN (* not locked *)
  821. hdr.count := -1; hdr.lockedBy := r;
  822. Machine.Release(Machine.Objects)
  823. ELSE (* already locked *)
  824. IF hdr.lockedBy = r THEN
  825. Machine.Release(Machine.Objects);
  826. HALT(2203) (* nested locks not allowed *)
  827. END;
  828. ASSERT(r.waitingOn = NIL); (* sanity check *)
  829. Remove(ready, r);
  830. IF r.event = 0 THEN
  831. r.event := Kernel32.CreateEvent( NIL, Kernel32.False (* auto *), Kernel32.False, NIL ); (* auto reset event with initial state = reset *)
  832. ASSERT ( r.event # 0, 1239 );
  833. END;
  834. r.waitingOn := obj; r.mode := AwaitingLock;
  835. Put(hdr.awaitingLock, r); INC(awl);
  836. Machine.Release(Machine.Objects);
  837. res := Kernel32.WaitForSingleObject(r.event, Kernel32.Infinite); (* block execution *)
  838. ASSERT(res = Kernel32.WaitObject0);
  839. IF StrongChecks THEN
  840. ASSERT(hdr.lockedBy = r); (* at this moment only this process can own the lock and only this process can release it*)
  841. END;
  842. END
  843. END Lock;
  844. (* Find the first true condition from the queue and remove it. Assume the object is currently locked. *)
  845. PROCEDURE FindCondition( VAR q: ProcessQueue ): Process;
  846. VAR first, cand: Process;
  847. BEGIN
  848. Get( q, first );
  849. IF first.condition( first.condFP ) THEN RETURN first END;
  850. Put( q, first );
  851. WHILE q.head # first DO
  852. Get( q, cand );
  853. IF cand.condition( cand.condFP ) THEN RETURN cand END;
  854. Put( q, cand )
  855. END;
  856. RETURN NIL
  857. END FindCondition;
  858. (* The procedure Lock, Unlock and Await do not use header locks since it turned out that the header locks sometimes were finalized
  859. too early. *)
  860. PROCEDURE Unlock*( obj: ProtectedObject; dummy: BOOLEAN );
  861. VAR hdr {UNTRACED}: Heaps.ProtRecBlock; t, c: Process; res: LONGINT;
  862. BEGIN
  863. SYSTEM.GET(SYSTEM.VAL(ADDRESS, obj) + Heaps.HeapBlockOffset, hdr);
  864. IF StrongChecks THEN
  865. ASSERT(hdr IS Heaps.ProtRecBlock) (* protected object *)
  866. END;
  867. ASSERT(hdr.count = -1); (* exclusive locked *)
  868. Machine.Acquire(Machine.Objects);
  869. IF hdr.awaitingCond.head # NIL THEN (* evaluate the waiting conditions *)
  870. (* we are holding the lock, so the queue can not change (to do: except in TerminateThis) *)
  871. c := FindCondition(hdr.awaitingCond); (* interrupts should be on during this call *)
  872. ELSE
  873. c := NIL
  874. END;
  875. IF c = NIL THEN (* no true condition found, check the lock queue *)
  876. Get(hdr.awaitingLock, t);
  877. IF t # NIL THEN
  878. hdr.lockedBy := t;
  879. t.waitingOn := NIL;
  880. ELSE
  881. hdr.lockedBy := NIL; hdr.count := 0
  882. END
  883. ELSE (* true condition found, transfer the lock *)
  884. c.waitingOn := NIL; hdr.lockedBy := c;
  885. t := NIL
  886. END;
  887. IF c # NIL THEN
  888. Put(ready, c); c.mode := Running; DEC(awc);
  889. res := Kernel32.SetEvent(c.event);
  890. ASSERT (res # 0, 1001);
  891. ELSIF t # NIL THEN
  892. Put(ready, t); t.mode := Running; DEC(awl);
  893. res := Kernel32.SetEvent(t.event);
  894. ASSERT (res # 0, 1002);
  895. END;
  896. Machine.Release( Machine.Objects )
  897. END Unlock;
  898. (* The procedure Lock, Unlock and Await do not use header locks since it turned out that the header locks sometimes were finalized
  899. too early. *)
  900. PROCEDURE Await*( cond: Condition; slink: LONGINT; obj: ProtectedObject; flags: SET );
  901. VAR hdr {UNTRACED}: Heaps.ProtRecBlock; r, c, t: Process; res: LONGINT;
  902. BEGIN
  903. IF 1 IN flags THEN (* compiler did not generate IF *)
  904. IF cond(slink) THEN
  905. RETURN (* condition already true *)
  906. END
  907. END;
  908. SYSTEM.GET(SYSTEM.VAL(ADDRESS, obj) + Heaps.HeapBlockOffset, hdr);
  909. IF StrongChecks THEN
  910. ASSERT(hdr IS Heaps.ProtRecBlock) (* protected object *)
  911. END;
  912. r := CurrentProcess();
  913. Machine.Acquire(Machine.Objects);
  914. IF hdr.lockedBy = r THEN (* current process holds exclusive lock *)
  915. IF StrongChecks THEN ASSERT(hdr.count = -1) END; (* exclusive locked *)
  916. IF hdr.awaitingCond.head # NIL THEN (* evaluate the waiting conditions *)
  917. (* we are holding the lock, so the queue can not change (to do: except in TerminateThis) *)
  918. c := FindCondition(hdr.awaitingCond) (* interrupts should be on during this call *)
  919. ELSE
  920. c := NIL
  921. END;
  922. IF c = NIL THEN
  923. Get(hdr.awaitingLock, t);
  924. IF t = NIL THEN (* none waiting - remove lock *)
  925. hdr.count := 0; hdr.lockedBy := NIL;
  926. ELSE (* transfer lock to first waiting process *)
  927. IF StrongChecks THEN ASSERT(t.mode = AwaitingLock) END;
  928. t.waitingOn := NIL;
  929. hdr.lockedBy := t;
  930. END;
  931. ELSE
  932. c.waitingOn := NIL; hdr.lockedBy := c;
  933. t := NIL;
  934. END;
  935. ELSE (* no lock, or some other process may hold the lock, but that's the user's indaba (may be monotonic condition) *)
  936. Machine.Release(Machine.Objects);
  937. HALT( 2204 ) (* await must be exclusive region *)
  938. END;
  939. r.condition := cond; r.condFP := slink;
  940. r.waitingOn := obj; r.mode := AwaitingCond;
  941. Remove(ready, r);
  942. IF r.event = 0 THEN
  943. r.event := Kernel32.CreateEvent( NIL, Kernel32.False (* auto *), Kernel32.False, NIL ); (* auto-reset event with initial state = reset *)
  944. ASSERT ( r.event # 0, 1239 );
  945. END;
  946. IF c # NIL THEN
  947. DEC(awc); Put(ready, c); c.mode := Running;
  948. res := Kernel32.SetEvent(c.event); (* restart execution *)
  949. ASSERT(res # 0, 1002);
  950. END;
  951. IF t # NIL THEN
  952. DEC(awl); Put(ready, t); t.mode := Running;
  953. res := Kernel32.SetEvent( t.event ); (* restart execution *)
  954. ASSERT(res # 0, 1003);
  955. END;
  956. Put(hdr.awaitingCond, r); INC(awc);
  957. Machine.Release(Machine.Objects);
  958. res := Kernel32.WaitForSingleObject(r.event, Kernel32.Infinite); (* block execution *)
  959. ASSERT(res = Kernel32.WaitObject0);
  960. IF StrongChecks THEN
  961. ASSERT(cond(slink));
  962. ASSERT(hdr.lockedBy = r) (* lock held again *)
  963. END
  964. END Await;
  965. PROCEDURE Break*( t: Process );
  966. CONST MaxTry = 50;
  967. VAR mod: Modules.Module; try: LONGINT; retBOOL: Kernel32.BOOL; (* Dan 09.11.05 *)
  968. PROCEDURE SafeForBreak( mod: Modules.Module ): BOOLEAN;
  969. BEGIN
  970. Trace.String( "Safe for break?: " );
  971. IF mod # NIL THEN
  972. Trace.StringLn ( mod.name );
  973. IF (mod.name = "Trace") OR (mod.name = "Machine") OR
  974. (mod.name = "Heaps") OR (mod.name = "Modules") OR
  975. (mod.name = "Objects") OR (mod.name = "Kernel") THEN
  976. Trace.StringLn ( " - no" ); RETURN FALSE
  977. ELSE Trace.StringLn ( " - yes" ); RETURN TRUE
  978. END
  979. ELSE Trace.StringLn ( "unknown module" ); RETURN FALSE
  980. END
  981. END SafeForBreak;
  982. BEGIN
  983. IF CurrentProcess() # t THEN
  984. Machine.Acquire( Machine.Objects );
  985. LOOP
  986. retBOOL := Kernel32.SuspendThread( t.handle );
  987. t.state.ContextFlags := SYSTEM.VAL(LONGINT, Kernel32.ContextControl);
  988. retBOOL := Kernel32.GetThreadContext( t.handle, t.state );
  989. mod := Modules.ThisModuleByAdr( t.state.PC ); Trace.String( "Objects Break at adr: " );
  990. Trace.Int( t.state.PC, 5 ); Trace.Ln;
  991. IF mod # NIL THEN
  992. Trace.String( "In module: " ); Trace.StringLn ( mod.name );
  993. END;
  994. IF ~SafeForBreak( mod ) (* we do not break Kernel modules *) THEN
  995. retBOOL := Kernel32.ResumeThread( t.handle ); INC( try );
  996. IF try > MaxTry THEN
  997. Trace.StringLn ( "Threads.Break: failed " );
  998. Machine.Release( Machine.Objects );
  999. RETURN
  1000. END
  1001. ELSE EXIT
  1002. END;
  1003. END;
  1004. (* push cont.Eip *) break[0] := 68X;
  1005. SYSTEM.MOVE( ADDRESSOF( t.state.PC ), ADDRESSOF( break[1] ), 4 );
  1006. (* push ebp *) break[5] := 055X;
  1007. (* mov ebp, esp *) break[6] := 08BX; break[7] := 0ECX;
  1008. (* push 13 *) break[8] := 06AX; break[9] := 0DX;
  1009. (* int 3 *) break[10] := 0CCX;
  1010. (* mov esp, ebp *) break[11] := 08BX; break[12] := 0E5X;
  1011. (* pop ebp *) break[13] := 05DX;
  1012. (* ret *) break[14] := 0C3X; t.state.PC := ADDRESSOF( break[0] );
  1013. retBOOL := Kernel32.SetThreadContext( t.handle, t.state );
  1014. retBOOL := Kernel32.ResumeThread( t.handle ); (* INC( Kernel.GClevel ); *)
  1015. Machine.Release( Machine.Objects );
  1016. ELSE HALT( 99 )
  1017. END;
  1018. END Break;
  1019. (* Attempt to terminate a specific process (mostly ignoring its locks). DEPRECATED *)
  1020. PROCEDURE TerminateThis*( t: Process; halt: BOOLEAN );
  1021. BEGIN
  1022. terminate(t);
  1023. END TerminateThis;
  1024. PROCEDURE Terminate*;
  1025. BEGIN
  1026. TerminateProc();
  1027. END Terminate;
  1028. TYPE KdHelp = RECORD
  1029. Thread: ADDRESS;
  1030. ThCallBackStack,ThCallBackStore,NextCallback,FramePointer: Kernel32.DWORD;
  1031. KiCallUserMode, KeUserCallbackDispatcher,SystemRangeStart,KiUserExceptionDispatcher,StackBase,StackLimit: ADDRESS;
  1032. Reserved: ARRAY 5 OF ADDRESS;
  1033. END;
  1034. (*
  1035. TYPE
  1036. ADDRESS64 = RECORD
  1037. offset: ADDRESS;
  1038. Segment: INTEGER;
  1039. AddressMode: INTEGER;
  1040. END;
  1041. TYPE StackFrame64 = RECORD
  1042. AddrPC, AddrReturn,AddrStack,AddrBSTore: ADDRESS64;
  1043. FuncTableEntry: ADDRESS;
  1044. Params: ARRAY 4 OF ADDRESS;
  1045. Far, Virtual: BOOLEAN;
  1046. Reserved: ARRAY 3 OF ADDRESS;
  1047. kdHelp: KdHelp;
  1048. END;
  1049. VAR StackWalk64: PROCEDURE {WINAPI} (MachineType: Kernel32.DWORD; hProcess: Kernel32.HANDLE;
  1050. hThread: Kernel32.HANDLE; VAR stackFrame: StackFrame64; VAR contextRecord: Kernel32.Context;
  1051. CONST ReadMemoryRoutine, FunctionTableAccessRoutine, GetModuleBaseRoutine,
  1052. TranslateAddress: ADDRESS): Kernel32.BOOL;
  1053. *)
  1054. PROCEDURE Init; (* can not use NEW *)
  1055. (*VAR lock: PROCEDURE(obj: ProtectedObject; exclusive: BOOLEAN);
  1056. unlock: PROCEDURE(obj: ProtectedObject; dummy: BOOLEAN);
  1057. await: PROCEDURE(cond: Condition; slink: LONGINT; obj: ProtectedObject; flags: SET);
  1058. create: PROCEDURE(body: Body; priority: LONGINT; flags: SET; obj: ProtectedObject);
  1059. *)
  1060. VAR t: Process; fn: Heaps.FinalizerNode; proc: Kernel32.HANDLE;
  1061. res: Kernel32.BOOL;
  1062. lib: Kernel32.HMODULE;
  1063. BEGIN
  1064. Kernel32.AddVectoredExceptionHandler(1, ExcpFrmHandler);
  1065. (* lib := Kernel32.LoadLibrary("DbgHelp.DLL");
  1066. Kernel32.GetProcAddress(lib, "StackWalk64",SYSTEM.VAL(ADDRESS,StackWalk64));
  1067. *)
  1068. Kernel32.InitializeCriticalSection(excplock);
  1069. numberOfProcessors := Machine.NumberOfProcessors();
  1070. (* lock := Lock; unlock := Unlock; await := Await; create := CreateProcess;*)
  1071. NEW(t); NEW(fn);
  1072. Machine.Acquire(Machine.Objects);
  1073. t.gcContext.nextPos := 0;
  1074. nProcs := 1;
  1075. t.next := NIL; t.prev := NIL;
  1076. t.waitingOn := NIL; t.flags := {}; t.obj := NIL;
  1077. t.mode := Unknown; t.body := NIL;
  1078. t.priority := Normal;
  1079. fn.finalizer := FinalizeProcess;
  1080. Heaps.AddFinalizer(t, fn);
  1081. t.handle := Kernel32.GetCurrentThread();
  1082. t.id := Kernel32.GetCurrentThreadId();
  1083. proc := Kernel32.GetCurrentProcess();
  1084. res := Kernel32.DuplicateHandle(proc, t.handle, proc, t.handle, Kernel32.SetToDW({}), 0, Kernel32.SetToDW({Kernel32.DuplicateSameAccess}));
  1085. ASSERT(res # 0);
  1086. res := Kernel32.TlsSetValue(tlsIndex, SYSTEM.VAL(LONGINT, t));
  1087. ASSERT(res # 0);
  1088. t.stackBottom := Machine.stackBottom;
  1089. t.mode := Running;
  1090. Put( ready, t );
  1091. ASSERT(t.handle # 0);
  1092. Machine.Release(Machine.Objects);
  1093. InitEventHandling; (* implicit call of NewProcess! *)
  1094. InitGCHandling; (* do. *)
  1095. Heaps.gcStatus := GCStatusFactory();
  1096. END Init;
  1097. (** Set (or reset) an event handler object's timeout value. *)
  1098. PROCEDURE SetTimeout*(t: Timer; h: EventHandler; ms: LONGINT );
  1099. VAR e: Timer; trigger: LONGINT;
  1100. BEGIN
  1101. ASSERT(Machine.Second= 1000); (* assume milliseconds for now *)
  1102. ASSERT((t # NIL) & (h # NIL));
  1103. ASSERT(ms >= 0);
  1104. Machine.Acquire(Machine.Objects);
  1105. trigger := Kernel32.GetTickCount() + ms; (* ignore overflow *)
  1106. IF t.next # NIL THEN (* cancel previous timeout *)
  1107. t.next.prev := t.prev; t.prev.next := t.next
  1108. END;
  1109. t.trigger := trigger; t.handler := h;
  1110. e := event.next; (* performance: linear search! *)
  1111. WHILE (e # event) & (e.trigger - trigger <= 0) DO e := e.next END;
  1112. t.prev := e.prev; e.prev := t; t.next := e; t.prev.next := t;
  1113. Machine.Release(Machine.Objects);
  1114. clock.Wakeup()
  1115. END SetTimeout;
  1116. (** Set (or reset) an event handler object's timeout value. Here ms is absolute *)
  1117. PROCEDURE SetTimeoutAt*(t: Timer; h: EventHandler; ms: LONGINT);
  1118. VAR e: Timer; trigger: LONGINT;
  1119. BEGIN
  1120. ASSERT(Machine.Second= 1000); (* assume milliseconds for now *)
  1121. ASSERT((t # NIL) & (h # NIL));
  1122. Machine.Acquire(Machine.Objects);
  1123. trigger := ms; (* ignore overflow *)
  1124. IF t.next # NIL THEN (* cancel previous timeout *)
  1125. t.next.prev := t.prev; t.prev.next := t.next
  1126. END;
  1127. t.trigger := trigger; t.handler := h;
  1128. e := event.next; (* performance: linear search! *)
  1129. WHILE (e # event) & (e.trigger - trigger <= 0) DO e := e.next END;
  1130. t.prev := e.prev; e.prev := t; t.next := e; t.prev.next := t;
  1131. Machine.Release(Machine.Objects);
  1132. clock.Wakeup()
  1133. END SetTimeoutAt;
  1134. (** Cancel an event handler object's timeout, if any. It is possible that the timer has expired, but not yet been scheduled to run. *)
  1135. PROCEDURE CancelTimeout*( t: Timer );
  1136. BEGIN
  1137. Machine.Acquire(Machine.Objects);
  1138. ASSERT (t # event );
  1139. IF t.next # NIL THEN
  1140. t.next.prev := t.prev;
  1141. IF t.prev#NIL THEN t.prev.next := t.next; END;
  1142. t.next := NIL;
  1143. t.prev := NIL
  1144. END;
  1145. Machine.Release(Machine.Objects);
  1146. END CancelTimeout;
  1147. PROCEDURE InitEventHandling;
  1148. BEGIN
  1149. NEW(event); event.next := event; event.prev := event; (* event: head of timer event queue, only a sentinel *)
  1150. NEW(clock);
  1151. END InitEventHandling;
  1152. PROCEDURE InitGCHandling;
  1153. BEGIN
  1154. NEW(finalizerCaller);
  1155. END InitGCHandling;
  1156. PROCEDURE GCStatusFactory(): Heaps.GCStatus;
  1157. VAR gcStatusExt : GCStatusExt;
  1158. BEGIN
  1159. ASSERT(Heaps.gcStatus = NIL);
  1160. NEW(gcStatusExt);
  1161. RETURN gcStatusExt
  1162. END GCStatusFactory;
  1163. PROCEDURE InstallExceptionHandler*( e: ExceptionHandler );
  1164. BEGIN
  1165. exceptionhandler := e;
  1166. END InstallExceptionHandler;
  1167. PROCEDURE UpdateProcessState*( p: Process );
  1168. VAR res: Kernel32.BOOL;
  1169. BEGIN
  1170. res := Kernel32.GetThreadContext( p.handle, p.state );
  1171. ASSERT (p.handle # 0);
  1172. END UpdateProcessState;
  1173. (*ALEX 2005.12.12 added for WMPerfMon needs*)
  1174. PROCEDURE NumReady*( ): LONGINT;
  1175. VAR n: LONGINT; p: Heaps.ProcessLink;
  1176. BEGIN
  1177. n := 0;
  1178. Machine.Acquire( Machine.Objects );
  1179. p := ready.head;
  1180. WHILE p # NIL DO INC( n ); p := p.next END;
  1181. Machine.Release( Machine.Objects );
  1182. RETURN n
  1183. END NumReady;
  1184. (** Return number of CPU cycles consumed by the specified process. If all is TRUE,
  1185. return the number of cycles since the process has been created. If FALSE, return the number of cycles
  1186. consumed since the last time asked. *)
  1187. PROCEDURE GetCpuCycles*(process : Process; VAR cpuCycles : CpuCyclesArray; all : BOOLEAN);
  1188. VAR res : Kernel32.BOOL; temp : HUGEINT;
  1189. BEGIN
  1190. ASSERT(process # NIL);
  1191. IF (Kernel32.QueryThreadCycleTime # NIL) THEN
  1192. res := Kernel32.QueryThreadCycleTime(process.handle, cpuCycles[0]);
  1193. ELSE
  1194. cpuCycles[0] := Machine.GetTimer(); res := Kernel32.True;
  1195. END;
  1196. IF ~all & (res = Kernel32.True) THEN
  1197. temp := process.lastThreadTimes;
  1198. process.lastThreadTimes := cpuCycles[0];
  1199. cpuCycles[0] := cpuCycles[0] - temp;
  1200. END;
  1201. END GetCpuCycles;
  1202. PROCEDURE CurrentProcessTime*(): HUGEINT;
  1203. VAR res: LONGINT; result: HUGEINT;
  1204. BEGIN
  1205. IF (Kernel32.QueryThreadCycleTime # NIL) THEN
  1206. res := Kernel32.QueryThreadCycleTime(CurrentProcess().handle, result);
  1207. ELSE (* fallback *)
  1208. result := Machine.GetTimer();
  1209. END;
  1210. RETURN result;
  1211. END CurrentProcessTime;
  1212. PROCEDURE TimerFrequency*(): HUGEINT;
  1213. BEGIN
  1214. RETURN 1000000000;
  1215. END TimerFrequency;
  1216. VAR GetProcedureName*: PROCEDURE (pc: ADDRESS; VAR n: ARRAY OF CHAR; VAR spc: ADDRESS);
  1217. PROCEDURE LeaveA2;
  1218. VAR cur: Process; ebp,n: ADDRESS;
  1219. BEGIN
  1220. CODE
  1221. PUSH RCX
  1222. PUSH RDX
  1223. PUSH R8
  1224. PUSH R9
  1225. END;
  1226. IF clock = NIL THEN
  1227. RETURN
  1228. END;
  1229. cur := CurrentProcess();
  1230. IF cur # NIL THEN
  1231. ebp := Machine.CurrentBP();
  1232. SYSTEM.GET(ebp, n);
  1233. IF ODD(n) THEN SYSTEM.GET(ebp + SIZEOF(ADDRESS), ebp) ELSE ebp := n END;
  1234. cur.gcContext.last[cur.gcContext.nextPos] := ebp;
  1235. INC(cur.gcContext.nextPos);
  1236. ASSERT(cur.gcContext.nextPos < 255);
  1237. IF cur.gcContext.nextPos > 255 THEN cur.gcContext.nextPos := 255 END;
  1238. (* IF (cur.gcContext.nextPos > 4) THEN cur.gcContext.nextPos := 2 END;*)
  1239. END;
  1240. CODE
  1241. POP R9
  1242. POP R8
  1243. POP RDX
  1244. POP RCX
  1245. END;
  1246. END LeaveA2;
  1247. PROCEDURE ReenterA2;
  1248. VAR cur: Process;
  1249. BEGIN
  1250. IF clock = NIL THEN RETURN END;
  1251. cur := CurrentProcess();
  1252. IF cur # NIL THEN
  1253. (* cur.gcContext.first[cur.gcContext.next] := NIL;*)
  1254. DEC(cur.gcContext.nextPos);
  1255. IF (cur.gcContext.nextPos <0 ) THEN cur.gcContext.nextPos := 0 END;
  1256. cur.gcContext.last[cur.gcContext.nextPos] := NIL; (* returned *)
  1257. END;
  1258. END ReenterA2;
  1259. VAR
  1260. TraceProcessHook*: PROCEDURE (prcoess: Process; pc, bp: ADDRESS; stacklow, stackhigh: ADDRESS);
  1261. BEGIN
  1262. TraceProcessHook := NIL;
  1263. exceptionhandler := NIL;
  1264. terminateProc := TerminateProc;
  1265. ready.head := NIL; ready.tail := NIL;
  1266. tlsIndex := Kernel32.TlsAlloc();
  1267. ASSERT ( tlsIndex # Kernel32.TLSOutOfIndexes );
  1268. Kernel32.SendToDebugger("Modules.root", ADDRESSOF(Modules.root));
  1269. Init;
  1270. END Objects.
  1271. (*
  1272. 24.03.1998 pjm Started
  1273. 06.05.1998 pjm CreateProcess init process, page fault handler
  1274. 06.08.1998 pjm Moved exception interrupt handling here for current process
  1275. 17.08.1998 pjm FindRoots method
  1276. 02.10.1998 pjm Idle process
  1277. 06.11.1998 pjm snapshot
  1278. 25.03.1999 pjm Scope removed
  1279. 28.05.1999 pjm EventHandler object
  1280. 01.06.1999 pjm Fixed InterruptProcess lock error
  1281. 16.06.1999 pjm Flat IRQ priority model to avoid GC deadlock
  1282. 23.06.1999 pjm Flat IRQ priority experiment failed, rather do STI in FieldIRQ to avoid GC deadlock
  1283. 29.06.1999 pjm Timeout in EventHandler object
  1284. 13.01.2000 pjm Overed (Interrupt Objects, Event Handlers, Process ID, Process state, Process mode, Process stack, Await)
  1285. 17.10.2000 pjm Priorities
  1286. 22.10.2003 mib SSE2 extension
  1287. 24.10.2003 phk Priority inversion / cycle counters
  1288. Stack invariant for GC:
  1289. o if process is running, the processor registers contain its state
  1290. o if process is not running, at least state.ESP is valid, and between stack.adr and stack.high (for GC)
  1291. o when releasing the Ready lock, make sure the process state is up to date
  1292. *)
  1293. SystemTools.ShowStacks ~
  1294. Heaps.SetMetaData
  1295. StaticLinker.Link --fileFormat=PE32 --fileName=A2GC.exe --extension=GofW --displacement=401000H Runtime Trace Kernel32 Machine Heaps Modules Objects Kernel KernelLog Streams Commands FIles WinFS Clock Dates Reals Strings Diagnostics BitSets StringPool ObjectFile GenericLinker Reflection GenericLoader BootConsole ~