Win64.Objects.Mod 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474
  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. (* starting address of user stack for current thread, called stack top in TIB.H *)
  454. PROCEDURE -StackBottom*( ): ADDRESS;
  455. CODE {SYSTEM.i386}
  456. DB 064H
  457. DB 08BH
  458. DB 005H
  459. DB 004H
  460. DB 000H
  461. DB 000H
  462. DB 000H
  463. END StackBottom;
  464. PROCEDURE {WINAPI} ExcpFrmHandler( CONST exceptionPointers: Kernel32.ExceptionPointers): Kernel32.DWORD ;
  465. VAR m: Modules.Module; eip, ebp, stack: ADDRESS; pc, handler, fp, sp: ADDRESS; handled: BOOLEAN; t: Process;
  466. BEGIN
  467. handled := FALSE;
  468. Kernel32.EnterCriticalSection( excplock );
  469. (*
  470. fof: commenting this resolved a problem with multiple traps that a are catched with FINALLY statements in Windows Vista
  471. in Windows XP not necessary if Kernel32.SetThreadContext is not used (better to return gracefully from this handler)
  472. SetCurrent(excpFrame);
  473. *)
  474. t := CurrentProcess();
  475. IF exceptionhandler = NIL THEN
  476. Trace.StringLn ( "Objects: No exception handler installed" );
  477. IF HandleExcp THEN
  478. Trace.String( "EXCEPTION " ); Trace.Address(exceptionPointers.exception.ExceptionCode);
  479. Trace.String( " at " ); Trace.Address(exceptionPointers.exception.ExceptionAddress);
  480. Trace.Ln(); Trace.String( "RAX " ); Trace.Address(exceptionPointers.context.RAX);
  481. Trace.String( " RBX " ); Trace.Address(exceptionPointers.context.RBX); Trace.Ln();
  482. Trace.String( "RCX " ); Trace.Address(exceptionPointers.context.RCX); Trace.String( " RDX " );
  483. Trace.Address(exceptionPointers.context.RDX); Trace.Ln(); Trace.String( "RDI " );
  484. Trace.Address(exceptionPointers.context.RDI); Trace.String( " RSI " );
  485. Trace.Address(exceptionPointers.context.RSI); Trace.Ln();
  486. Trace.String( "R8 " ); Trace.Address(exceptionPointers.context.R8);
  487. Trace.String( " R9 " ); Trace.Address(exceptionPointers.context.R9); Trace.Ln();
  488. Trace.String( "R10 " ); Trace.Address(exceptionPointers.context.R10);
  489. Trace.String( " R11 " ); Trace.Address(exceptionPointers.context.R11); Trace.Ln();
  490. Trace.String( "R12 " ); Trace.Address(exceptionPointers.context.R12);
  491. Trace.String( " R13 " ); Trace.Address(exceptionPointers.context.R13); Trace.Ln();
  492. Trace.String( "R14 " ); Trace.Address(exceptionPointers.context.R14);
  493. Trace.String( " R15 " ); Trace.Address(exceptionPointers.context.R15); Trace.Ln();
  494. Trace.Ln;
  495. Trace.String( "RBP " );
  496. Trace.Address(exceptionPointers.context.BP); Trace.String( " RSP " );
  497. Trace.Address(exceptionPointers.context.SP); Trace.Ln(); Trace.String( "PC " );
  498. Trace.Address(exceptionPointers.context.PC); Trace.Ln();
  499. Trace.Ln();
  500. eip := exceptionPointers.exception.ExceptionAddress; ebp := exceptionPointers.context.BP;
  501. IF eip = 0 THEN SYSTEM.GET( exceptionPointers.context.SP, eip ) END;
  502. stack := StackBottom();
  503. LOOP
  504. Trace.String( "at ebp= " ); Trace.Address(ebp); Trace.String( "H : " );
  505. m := Modules.ThisModuleByAdr( eip );
  506. IF m # NIL THEN
  507. Trace.String( m.name ); Trace.String( " " );
  508. Trace.Address(eip - SYSTEM.VAL( LONGINT, ADDRESSOF( m.code[0] ) ));
  509. ELSE Trace.String( "EIP " ); Trace.Address(eip)
  510. END;
  511. Trace.Ln();
  512. IF (ebp # 0) & (ebp < stack) THEN (* if ebp is 0 in first frame *)
  513. SYSTEM.GET( ebp + SIZEOF(ADDRESS), eip ); (* return addr from stack *)
  514. SYSTEM.GET( ebp, ebp ); (* follow dynamic link *)
  515. ELSE EXIT
  516. END
  517. END;
  518. Trace.Ln();
  519. (* finally and all that ...
  520. handled := FALSE; fp := exceptionPointers.context.BP; sp := exceptionPointers.context.SP;
  521. pc := exceptionPointers.context.PC; handler := Modules.GetExceptionHandler( pc );
  522. IF handler # -1 THEN (* Handler in the current PAF *)
  523. exceptionPointers.context.PC := handler; handled := TRUE;
  524. (*SetTrapVariable(pc, fp); SetLastExceptionState(exc)*)
  525. ELSE
  526. WHILE (fp # 0) & (handler = -1) DO
  527. SYSTEM.GET( fp + SIZEOF(ADDRESS), pc );
  528. pc := pc - 1; (* CALL instruction, machine dependant!!! *)
  529. handler := Modules.GetExceptionHandler( pc );
  530. sp := fp; (* Save the old framepointer into the stack pointer *)
  531. SYSTEM.GET( fp, fp ) (* Unwind PAF *)
  532. END;
  533. IF handler = -1 THEN handled := FALSE;
  534. ELSE
  535. TRACE("CHANGED HANDLER ADR ");
  536. exceptionPointers.context.PC := handler; exceptionPointers.context.BP := fp; exceptionPointers.context.SP := sp;
  537. (* SetTrapVariable(pc, fp); SetLastExceptionState(exc);*)
  538. handled := TRUE
  539. END
  540. END;
  541. *)
  542. ELSE Trace.StringLn ( "Warning: FINALLY statement cannot be treated !" );
  543. END
  544. ELSE exceptionhandler(exceptionPointers.context^, exceptionPointers.exception^,handled );
  545. END;
  546. IF ~handled THEN
  547. exceptionPointers.context.PC := (*TerminateProc*) t.restartPC ;
  548. exceptionPointers.context.SP := t.restartSP;
  549. exceptionPointers.context.BP := t.stackBottom;
  550. ELSIF TraceVerbose THEN Trace.StringLn ( "trying to jump to FINALLY pc..." );
  551. END;
  552. Kernel32.LeaveCriticalSection( excplock );
  553. IF TraceVerbose THEN
  554. Machine.Acquire (Machine.TraceOutput);
  555. Trace.String( "recover process; pc=" ); Trace.Address( exceptionPointers.context.PC );
  556. Trace.String( "; sp= " ); Trace.Address( exceptionPointers.context.SP); Trace.String( "; bp= " );
  557. Trace.Address( exceptionPointers.context.BP); Trace.Ln;
  558. Machine.Release (Machine.TraceOutput);
  559. END;
  560. RETURN Kernel32.ExceptionContinueExecution; (* sets thread context and continues where specified in context *)
  561. END ExcpFrmHandler;
  562. (*
  563. (* get the currently installed execption frame *)
  564. (* PROCEDURE -GetCur 64H, 8BH, 0DH, 0, 0, 0, 0; (* MOV ECX, FS:[0] *) *)
  565. (* Better *)
  566. PROCEDURE -GetCur;
  567. CODE {SYSTEM.AMD64}
  568. MOV RCX, [GS:0]
  569. ; DB 064H, 08BH, 00DH, 000H, 000H, 000H, 000H
  570. END GetCur;
  571. PROCEDURE GetCurrent( ): Kernel32.ExcpFrmPtr;
  572. VAR cur: Kernel32.ExcpFrmPtr;
  573. BEGIN
  574. GetCur;
  575. cur := SYSTEM.VAL(Kernel32.ExcpFrmPtr,Machine.GetRCX());
  576. TRACE(cur);
  577. (* RETURN ECX *)
  578. RETURN cur
  579. END GetCurrent;
  580. *)
  581. (*
  582. (* install a new exception frame *)
  583. (* PROCEDURE -SetCur 64H, 0A3H, 0, 0, 0, 0; (* MOV FS:[0], EAX *)*)
  584. (* Better *)
  585. PROCEDURE -SetCur;
  586. CODE {SYSTEM.AMD64}
  587. ; DB 064H, 0A3H, 000H, 000H, 000H, 000H
  588. MOV [GS:0], RAX
  589. END SetCur;
  590. PROCEDURE SetCurrent( cur: Kernel32.ExcpFrmPtr );
  591. BEGIN
  592. TRACE(cur);
  593. Machine.SetRAX(cur);
  594. (* EAX := cur *)
  595. CODE{SYSTEM.AMD64}
  596. MOV [GS:0], RAX
  597. END;
  598. TRACE(GetCurrent());
  599. (*SetCur*)
  600. END SetCurrent;
  601. *)
  602. PROCEDURE RemoveExcpFrm( VAR excpfrm: Kernel32.ExcpFrm );
  603. VAR this: Kernel32.ExcpFrmPtr;
  604. BEGIN
  605. (*
  606. this := GetCurrent();
  607. (* ASSERT ( this = ADDRESSOF( excpfrm ) ); *)
  608. IF this # ADDRESSOF( excpfrm ) THEN Trace.StringLn ( "RemoveExcpFrm: Problem with excpfrm pointer" );
  609. ELSE SetCurrent( excpfrm.link )
  610. END;
  611. *)
  612. (*
  613. Kernel32.RemoveVectoredExceptionHandler(ExcpFrmHandler);
  614. *)
  615. END RemoveExcpFrm;
  616. PROCEDURE InstallExcpFrm( VAR excpfrm: Kernel32.ExcpFrm );
  617. BEGIN
  618. Kernel32.AddVectoredContinueHandler(1, ExcpFrmHandler);
  619. (*
  620. excpfrm.link := GetCurrent(); excpfrm.handler := ExcpFrmHandler;
  621. SetCurrent( ADDRESSOF( excpfrm ) )
  622. *)
  623. END InstallExcpFrm;
  624. PROCEDURE InQueue( queue: ProcessQueue; t: Process ): BOOLEAN;
  625. VAR p: Heaps.ProcessLink;
  626. BEGIN
  627. p := queue.head;
  628. WHILE (p # NIL ) & (p # t) DO p := p.next; END;
  629. RETURN (p = t);
  630. END InQueue;
  631. (* Remove a process from a queue that contains it. Caller must hold lock for specific queue. *)
  632. (* Not intended for frequent use. *)
  633. (* does not check if queue contained t ! *)
  634. PROCEDURE Remove( VAR queue: ProcessQueue; t: Process );
  635. BEGIN
  636. IF StrongChecks THEN
  637. ASSERT(InQueue(queue, t));
  638. ASSERT(t # NIL);
  639. END;
  640. IF t.prev # NIL THEN t.prev.next := t.next END;
  641. IF t.next # NIL THEN t.next.prev := t.prev END;
  642. IF t = queue.head THEN queue.head := t.next END;
  643. IF t = queue.tail THEN queue.tail := t.prev END;
  644. ASSERT((queue.head = NIL) OR (queue.head.prev = NIL) & (queue.tail.next = NIL));
  645. t.prev := NIL; t.next := NIL
  646. END Remove;
  647. PROCEDURE WriteType(obj: ANY);
  648. VAR type: LONGINT;
  649. BEGIN
  650. IF obj = NIL THEN Trace.String(" > NIL");
  651. ELSE
  652. Trace.String(" > "); SYSTEM.GET(SYSTEM.VAL(LONGINT, obj) + Heaps.TypeDescOffset, type);
  653. Heaps.WriteType(type);
  654. END;
  655. END WriteType;
  656. PROCEDURE terminate( t: Process );
  657. VAR hdr {UNTRACED}: Heaps.ProtRecBlock; res: Kernel32.BOOL; shutdown: BOOLEAN;
  658. BEGIN
  659. IF t = NIL THEN RETURN END;
  660. (* see Objects.TerminateThis *)
  661. Machine.Acquire( Machine.Objects );
  662. IF TraceVerbose OR TraceOpenClose THEN
  663. Machine.Acquire (Machine.TraceOutput);
  664. Trace.String( "Terminating process " ); Trace.Int( t.id, 1 ); WriteType( t.obj ); Trace.Ln;
  665. Machine.Release (Machine.TraceOutput);
  666. END;
  667. IF (t.mode = Ready) OR (t.mode = Running) THEN Remove( ready, t );
  668. ELSIF t.mode = AwaitingLock THEN
  669. SYSTEM.GET(SYSTEM.VAL(ADDRESS, t.waitingOn) + Heaps.HeapBlockOffset, hdr);
  670. ASSERT(hdr IS Heaps.ProtRecBlock);
  671. Remove( hdr.awaitingLock, t ); Machine.Release( Machine.Objects );
  672. HALT( 97 )
  673. ELSIF t.mode = AwaitingCond THEN
  674. SYSTEM.GET(SYSTEM.VAL(ADDRESS, t.waitingOn) + Heaps.HeapBlockOffset, hdr);
  675. ASSERT(hdr IS Heaps.ProtRecBlock);
  676. Remove( hdr.awaitingCond, t ); Machine.Release( Machine.Objects );
  677. HALT( 98 )
  678. ELSE Machine.Release( Machine.Objects );
  679. HALT( 99 )
  680. END;
  681. t.mode := Terminated; (* a process can also be "terminated" if the queue containing it is garbage collected *)
  682. t.stackBottom := 0; t.state.SP := 0;
  683. t.restartPC := 0;
  684. IF t.event # 0 THEN res := Kernel32.CloseHandle( t.event ); t.event := 0 END;
  685. DEC( nProcs ); shutdown := (nProcs = 0);
  686. Machine.Release( Machine.Objects );
  687. IF shutdown THEN
  688. Trace.StringLn ( " Objects: shutdown" ); Modules.Shutdown( -1 );
  689. Kernel32.ExitProcess( 0 )
  690. END
  691. END terminate;
  692. PROCEDURE {WINAPI} Wrapper( lpParameter: ANY ): LONGINT;
  693. VAR t: Process; obj: ProtectedObject; res: Kernel32.BOOL; bp,sp: ADDRESS;
  694. excpfrm: Kernel32.ExcpFrm;
  695. BEGIN
  696. (* it may happen that the garbage collector runs right here and ignores this procedure.
  697. This is not a problem since lpParameter (being a reference to a process) is protected by the process lists *)
  698. Machine.Acquire(Machine.Objects);
  699. res := Kernel32.TlsSetValue(tlsIndex, SYSTEM.VAL(LONGINT, lpParameter));
  700. t := lpParameter(Process); obj := t.obj;
  701. ASSERT(res # 0);
  702. SetPriority(t.priority);
  703. bp := Machine.CurrentBP();
  704. sp := Machine.CurrentSP();
  705. t.restartSP := sp;
  706. t.stackBottom := bp;
  707. IF t.restartPC = SYSTEM.VAL(ADDRESS, terminateProc) THEN DEC(t.restartSP, SIZEOF(ADDRESS))
  708. ELSE DEC(t.restartSP, 2*SIZEOF(ADDRESS))
  709. END;
  710. IF TraceVerbose THEN
  711. Machine.Acquire(Machine.TraceOutput);
  712. Trace.String("New process; restartPC= "); Trace.Address(t.restartPC);
  713. Trace.String("; stackBottom= ");
  714. Trace.Address(t.stackBottom); Trace.Ln;
  715. Machine.Release(Machine.TraceOutput);
  716. END;
  717. t.mode := Running;
  718. (* now gc is enabled for this process stack *)
  719. Machine.Release(Machine.Objects);
  720. (* 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) *)
  721. (*! should not be necessary any more as GC runs immediately and without scheduling decisions
  722. WHILE (gcActivity # NIL) & (gcActivity.process # NIL) & (gcActivity.process.mode = Running) DO END;
  723. *)
  724. t.body(obj);
  725. terminate(t);
  726. RemoveExcpFrm(excpfrm);
  727. RETURN 0
  728. END Wrapper;
  729. PROCEDURE FinalizeProcess(t: ANY);
  730. VAR p: Process; res: Kernel32.BOOL;
  731. BEGIN
  732. p := t(Process);
  733. IF TraceVerbose THEN
  734. Machine.Acquire (Machine.TraceOutput);
  735. Trace.String("Finalizing Process"); Trace.Int(p.id, 1);
  736. WriteType(p.obj); Trace.Ln;
  737. Machine.Release (Machine.TraceOutput);
  738. END;
  739. IF p.mode # Terminated THEN
  740. IF p.mode = AwaitingLock THEN DEC(awl);
  741. ELSIF p.mode = AwaitingCond THEN DEC(awc);
  742. END;
  743. (* no reference to the object any more *)
  744. Trace.String ("Closing unreferenced process"); (*Trace.Int(p.mode,20); Trace.Int( p.id, 20 ); *) Trace.Ln; (* Trace.Ln *)
  745. (* this usually happens, when an objects process waits on its own objtec and no reference exists any more. Then the object is discarded and
  746. consequently the process is unreferenced (except in the object). This cannot happen when there are still other references on the object.
  747. example:
  748. TYPE
  749. Object= OBJECT VAR active: BOOLEAN; BEGIN{ACTIVE} active := FALSE; AWAIT(active) END Object;
  750. VAR o: Object;
  751. BEGIN NEW(o);
  752. END;
  753. *)
  754. END;
  755. p.mode := Terminated; (* fof for GC problem *)
  756. IF p.handle # 0 THEN
  757. res := Kernel32.CloseHandle(p.handle); p.handle := 0
  758. END
  759. END FinalizeProcess;
  760. PROCEDURE TerminateProc;
  761. BEGIN
  762. terminate(CurrentProcess());
  763. Kernel32.ExitThread(0);
  764. Kernel32.Sleep(999999); (* wait until dependent threads terminated *)
  765. END TerminateProc;
  766. (* Allocate a new process associated with "obj". Must be outside lock region, because of potential GC. *)
  767. PROCEDURE NewProcess(body: Body; priority: LONGINT; flags: SET; obj: ProtectedObject; VAR new: Process);
  768. VAR t,r: Process; fn: Heaps.FinalizerNode;
  769. BEGIN
  770. NEW(t);
  771. t.gcContext.nextPos := 0;
  772. t.context := CurrentContext(); (* inherit context from parent process *)
  773. t.handle := 0;
  774. IF priority = 0 THEN (* no priority specified *)
  775. r := CurrentProcess();
  776. t.priority := r.priority (* inherit priority of creator *)
  777. ELSIF priority > 0 THEN (* positive priority specified *)
  778. t.priority := priority
  779. ELSE (* negative priority specified (only for Idle process) *)
  780. t.priority := MinPriority
  781. END;
  782. NEW(fn); (* implicit call Heaps.NewRec -> might invoke GC *)
  783. Machine.Acquire(Machine.Objects);
  784. t.next := NIL; t.prev := NIL; t.rootedNext := NIL;
  785. t.waitingOn := NIL; t.flags := flags; t.obj := obj; t.mode := Unknown;
  786. t.body := body; t.event := 0; fn.finalizer := FinalizeProcess;
  787. Heaps.AddFinalizer(t, fn);
  788. IF Restart IN flags THEN (* restart object body *)
  789. t.restartPC := SYSTEM.VAL(ADDRESS, body);
  790. ELSE (* terminate process *)
  791. t.restartPC := SYSTEM.VAL(ADDRESS, terminateProc);
  792. END;
  793. (* t.restartPC := SYSTEM.VAL(ADDRESS, terminateProc);*)
  794. t.handle := Kernel32.CreateThread(0, defaultStackSize, Wrapper, t, Kernel32.SetToDW({}), t.id);
  795. IF TraceVerbose OR TraceOpenClose THEN
  796. Machine.Acquire(Machine.TraceOutput);
  797. Trace.String("NewProcess: " ); Trace.Int(t.id, 1); WriteType(obj); Trace.Ln;
  798. Machine.Release(Machine.TraceOutput);
  799. END;
  800. ASSERT(t.handle # 0);
  801. new := t;
  802. END NewProcess;
  803. (* Create the process associated with an active object (kernel call). *)
  804. PROCEDURE CreateProcess*(body: Body; priority: LONGINT; flags: SET; obj: ProtectedObject);
  805. VAR t : Process; heapBlock {UNTRACED}: Heaps.HeapBlock;
  806. BEGIN
  807. ASSERT(priority >= 0, 1000); ASSERT(priority <=Realtime, 1001);
  808. SYSTEM.GET(SYSTEM.VAL(ADDRESS, obj) + Heaps.HeapBlockOffset, heapBlock);
  809. ASSERT(heapBlock IS Heaps.ProtRecBlock); (* protected object *)
  810. IF Restart IN flags THEN INCL(flags, Resistant) END; (* SAFE => Restart & Resistant *)
  811. NewProcess(body, priority, flags, obj, t); INC(nProcs); (* acquires Machine.Objects lock *)
  812. t.mode := Ready; Put(ready, t);
  813. Machine.Release(Machine.Objects);
  814. END CreateProcess;
  815. (* The procedure Lock, Unlock and Await do not use header locks since it turned out that the header locks sometimes were finalized
  816. too early. *)
  817. PROCEDURE Lock*(obj: ProtectedObject; exclusive: BOOLEAN );
  818. VAR hdr {UNTRACED}: Heaps.ProtRecBlock; r: Process; res: LONGINT;
  819. BEGIN (* {called from user level} *)
  820. SYSTEM.GET(SYSTEM.VAL(ADDRESS, obj) + Heaps.HeapBlockOffset, hdr);
  821. IF StrongChecks THEN
  822. ASSERT(hdr IS Heaps.ProtRecBlock); (* protected object *)
  823. ASSERT(exclusive) (* shared not implemented yet *)
  824. END;
  825. r := CurrentProcess();
  826. IF StrongChecks THEN
  827. ASSERT(hdr # NIL, 1001);
  828. ASSERT(r # NIL, 1002);
  829. END;
  830. Machine.Acquire(Machine.Objects);
  831. IF hdr.count = 0 THEN (* not locked *)
  832. hdr.count := -1; hdr.lockedBy := r;
  833. Machine.Release(Machine.Objects)
  834. ELSE (* already locked *)
  835. IF hdr.lockedBy = r THEN
  836. Machine.Release(Machine.Objects);
  837. HALT(2203) (* nested locks not allowed *)
  838. END;
  839. ASSERT(r.waitingOn = NIL); (* sanity check *)
  840. Remove(ready, r);
  841. IF r.event = 0 THEN
  842. r.event := Kernel32.CreateEvent( NIL, Kernel32.False (* auto *), Kernel32.False, NIL ); (* auto reset event with initial state = reset *)
  843. ASSERT ( r.event # 0, 1239 );
  844. END;
  845. r.waitingOn := obj; r.mode := AwaitingLock;
  846. Put(hdr.awaitingLock, r); INC(awl);
  847. Machine.Release(Machine.Objects);
  848. res := Kernel32.WaitForSingleObject(r.event, Kernel32.Infinite); (* block execution *)
  849. ASSERT(res = Kernel32.WaitObject0);
  850. IF StrongChecks THEN
  851. ASSERT(hdr.lockedBy = r); (* at this moment only this process can own the lock and only this process can release it*)
  852. END;
  853. END
  854. END Lock;
  855. (* Find the first true condition from the queue and remove it. Assume the object is currently locked. *)
  856. PROCEDURE FindCondition( VAR q: ProcessQueue ): Process;
  857. VAR first, cand: Process;
  858. BEGIN
  859. Get( q, first );
  860. IF first.condition( first.condFP ) THEN RETURN first END;
  861. Put( q, first );
  862. WHILE q.head # first DO
  863. Get( q, cand );
  864. IF cand.condition( cand.condFP ) THEN RETURN cand END;
  865. Put( q, cand )
  866. END;
  867. RETURN NIL
  868. END FindCondition;
  869. (* The procedure Lock, Unlock and Await do not use header locks since it turned out that the header locks sometimes were finalized
  870. too early. *)
  871. PROCEDURE Unlock*( obj: ProtectedObject; dummy: BOOLEAN );
  872. VAR hdr {UNTRACED}: Heaps.ProtRecBlock; t, c: Process; res: LONGINT;
  873. BEGIN
  874. SYSTEM.GET(SYSTEM.VAL(ADDRESS, obj) + Heaps.HeapBlockOffset, hdr);
  875. IF StrongChecks THEN
  876. ASSERT(hdr IS Heaps.ProtRecBlock) (* protected object *)
  877. END;
  878. ASSERT(hdr.count = -1); (* exclusive locked *)
  879. Machine.Acquire(Machine.Objects);
  880. IF hdr.awaitingCond.head # NIL THEN (* evaluate the waiting conditions *)
  881. (* we are holding the lock, so the queue can not change (to do: except in TerminateThis) *)
  882. c := FindCondition(hdr.awaitingCond); (* interrupts should be on during this call *)
  883. ELSE
  884. c := NIL
  885. END;
  886. IF c = NIL THEN (* no true condition found, check the lock queue *)
  887. Get(hdr.awaitingLock, t);
  888. IF t # NIL THEN
  889. hdr.lockedBy := t;
  890. t.waitingOn := NIL;
  891. ELSE
  892. hdr.lockedBy := NIL; hdr.count := 0
  893. END
  894. ELSE (* true condition found, transfer the lock *)
  895. c.waitingOn := NIL; hdr.lockedBy := c;
  896. t := NIL
  897. END;
  898. IF c # NIL THEN
  899. Put(ready, c); c.mode := Running; DEC(awc);
  900. res := Kernel32.SetEvent(c.event);
  901. ASSERT (res # 0, 1001);
  902. ELSIF t # NIL THEN
  903. Put(ready, t); t.mode := Running; DEC(awl);
  904. res := Kernel32.SetEvent(t.event);
  905. ASSERT (res # 0, 1002);
  906. END;
  907. Machine.Release( Machine.Objects )
  908. END Unlock;
  909. (* The procedure Lock, Unlock and Await do not use header locks since it turned out that the header locks sometimes were finalized
  910. too early. *)
  911. PROCEDURE Await*( cond: Condition; slink: LONGINT; obj: ProtectedObject; flags: SET );
  912. VAR hdr {UNTRACED}: Heaps.ProtRecBlock; r, c, t: Process; res: LONGINT;
  913. BEGIN
  914. IF 1 IN flags THEN (* compiler did not generate IF *)
  915. IF cond(slink) THEN
  916. RETURN (* condition already true *)
  917. END
  918. END;
  919. SYSTEM.GET(SYSTEM.VAL(ADDRESS, obj) + Heaps.HeapBlockOffset, hdr);
  920. IF StrongChecks THEN
  921. ASSERT(hdr IS Heaps.ProtRecBlock) (* protected object *)
  922. END;
  923. r := CurrentProcess();
  924. Machine.Acquire(Machine.Objects);
  925. IF hdr.lockedBy = r THEN (* current process holds exclusive lock *)
  926. IF StrongChecks THEN ASSERT(hdr.count = -1) END; (* exclusive locked *)
  927. IF hdr.awaitingCond.head # NIL THEN (* evaluate the waiting conditions *)
  928. (* we are holding the lock, so the queue can not change (to do: except in TerminateThis) *)
  929. c := FindCondition(hdr.awaitingCond) (* interrupts should be on during this call *)
  930. ELSE
  931. c := NIL
  932. END;
  933. IF c = NIL THEN
  934. Get(hdr.awaitingLock, t);
  935. IF t = NIL THEN (* none waiting - remove lock *)
  936. hdr.count := 0; hdr.lockedBy := NIL;
  937. ELSE (* transfer lock to first waiting process *)
  938. IF StrongChecks THEN ASSERT(t.mode = AwaitingLock) END;
  939. t.waitingOn := NIL;
  940. hdr.lockedBy := t;
  941. END;
  942. ELSE
  943. c.waitingOn := NIL; hdr.lockedBy := c;
  944. t := NIL;
  945. END;
  946. ELSE (* no lock, or some other process may hold the lock, but that's the user's indaba (may be monotonic condition) *)
  947. Machine.Release(Machine.Objects);
  948. HALT( 2204 ) (* await must be exclusive region *)
  949. END;
  950. r.condition := cond; r.condFP := slink;
  951. r.waitingOn := obj; r.mode := AwaitingCond;
  952. Remove(ready, r);
  953. IF r.event = 0 THEN
  954. r.event := Kernel32.CreateEvent( NIL, Kernel32.False (* auto *), Kernel32.False, NIL ); (* auto-reset event with initial state = reset *)
  955. ASSERT ( r.event # 0, 1239 );
  956. END;
  957. IF c # NIL THEN
  958. DEC(awc); Put(ready, c); c.mode := Running;
  959. res := Kernel32.SetEvent(c.event); (* restart execution *)
  960. ASSERT(res # 0, 1002);
  961. END;
  962. IF t # NIL THEN
  963. DEC(awl); Put(ready, t); t.mode := Running;
  964. res := Kernel32.SetEvent( t.event ); (* restart execution *)
  965. ASSERT(res # 0, 1003);
  966. END;
  967. Put(hdr.awaitingCond, r); INC(awc);
  968. Machine.Release(Machine.Objects);
  969. res := Kernel32.WaitForSingleObject(r.event, Kernel32.Infinite); (* block execution *)
  970. ASSERT(res = Kernel32.WaitObject0);
  971. IF StrongChecks THEN
  972. ASSERT(cond(slink));
  973. ASSERT(hdr.lockedBy = r) (* lock held again *)
  974. END
  975. END Await;
  976. PROCEDURE Break*( t: Process );
  977. CONST MaxTry = 50;
  978. VAR mod: Modules.Module; try: LONGINT; retBOOL: Kernel32.BOOL; (* Dan 09.11.05 *)
  979. PROCEDURE SafeForBreak( mod: Modules.Module ): BOOLEAN;
  980. BEGIN
  981. Trace.String( "Safe for break?: " );
  982. IF mod # NIL THEN
  983. Trace.StringLn ( mod.name );
  984. IF (mod.name = "Trace") OR (mod.name = "Machine") OR
  985. (mod.name = "Heaps") OR (mod.name = "Modules") OR
  986. (mod.name = "Objects") OR (mod.name = "Kernel") THEN
  987. Trace.StringLn ( " - no" ); RETURN FALSE
  988. ELSE Trace.StringLn ( " - yes" ); RETURN TRUE
  989. END
  990. ELSE Trace.StringLn ( "unknown module" ); RETURN FALSE
  991. END
  992. END SafeForBreak;
  993. BEGIN
  994. IF CurrentProcess() # t THEN
  995. Machine.Acquire( Machine.Objects );
  996. LOOP
  997. retBOOL := Kernel32.SuspendThread( t.handle );
  998. t.state.ContextFlags := SYSTEM.VAL(LONGINT, Kernel32.ContextControl);
  999. retBOOL := Kernel32.GetThreadContext( t.handle, t.state );
  1000. mod := Modules.ThisModuleByAdr( t.state.PC ); Trace.String( "Objects Break at adr: " );
  1001. Trace.Int( t.state.PC, 5 ); Trace.Ln;
  1002. IF mod # NIL THEN
  1003. Trace.String( "In module: " ); Trace.StringLn ( mod.name );
  1004. END;
  1005. IF ~SafeForBreak( mod ) (* we do not break Kernel modules *) THEN
  1006. retBOOL := Kernel32.ResumeThread( t.handle ); INC( try );
  1007. IF try > MaxTry THEN
  1008. Trace.StringLn ( "Threads.Break: failed " );
  1009. Machine.Release( Machine.Objects );
  1010. RETURN
  1011. END
  1012. ELSE EXIT
  1013. END;
  1014. END;
  1015. (* push cont.Eip *) break[0] := 68X;
  1016. SYSTEM.MOVE( ADDRESSOF( t.state.PC ), ADDRESSOF( break[1] ), 4 );
  1017. (* push ebp *) break[5] := 055X;
  1018. (* mov ebp, esp *) break[6] := 08BX; break[7] := 0ECX;
  1019. (* push 13 *) break[8] := 06AX; break[9] := 0DX;
  1020. (* int 3 *) break[10] := 0CCX;
  1021. (* mov esp, ebp *) break[11] := 08BX; break[12] := 0E5X;
  1022. (* pop ebp *) break[13] := 05DX;
  1023. (* ret *) break[14] := 0C3X; t.state.PC := ADDRESSOF( break[0] );
  1024. retBOOL := Kernel32.SetThreadContext( t.handle, t.state );
  1025. retBOOL := Kernel32.ResumeThread( t.handle ); (* INC( Kernel.GClevel ); *)
  1026. Machine.Release( Machine.Objects );
  1027. ELSE HALT( 99 )
  1028. END;
  1029. END Break;
  1030. (* Attempt to terminate a specific process (mostly ignoring its locks). DEPRECATED *)
  1031. PROCEDURE TerminateThis*( t: Process; halt: BOOLEAN );
  1032. BEGIN
  1033. terminate(t);
  1034. END TerminateThis;
  1035. PROCEDURE Terminate*;
  1036. BEGIN
  1037. TerminateProc();
  1038. END Terminate;
  1039. TYPE KdHelp = RECORD
  1040. Thread: ADDRESS;
  1041. ThCallBackStack,ThCallBackStore,NextCallback,FramePointer: Kernel32.DWORD;
  1042. KiCallUserMode, KeUserCallbackDispatcher,SystemRangeStart,KiUserExceptionDispatcher,StackBase,StackLimit: ADDRESS;
  1043. Reserved: ARRAY 5 OF ADDRESS;
  1044. END;
  1045. (*
  1046. TYPE
  1047. ADDRESS64 = RECORD
  1048. offset: ADDRESS;
  1049. Segment: INTEGER;
  1050. AddressMode: INTEGER;
  1051. END;
  1052. TYPE StackFrame64 = RECORD
  1053. AddrPC, AddrReturn,AddrStack,AddrBSTore: ADDRESS64;
  1054. FuncTableEntry: ADDRESS;
  1055. Params: ARRAY 4 OF ADDRESS;
  1056. Far, Virtual: BOOLEAN;
  1057. Reserved: ARRAY 3 OF ADDRESS;
  1058. kdHelp: KdHelp;
  1059. END;
  1060. VAR StackWalk64: PROCEDURE {WINAPI} (MachineType: Kernel32.DWORD; hProcess: Kernel32.HANDLE;
  1061. hThread: Kernel32.HANDLE; VAR stackFrame: StackFrame64; VAR contextRecord: Kernel32.Context;
  1062. CONST ReadMemoryRoutine, FunctionTableAccessRoutine, GetModuleBaseRoutine,
  1063. TranslateAddress: ADDRESS): Kernel32.BOOL;
  1064. *)
  1065. PROCEDURE Init; (* can not use NEW *)
  1066. (*VAR lock: PROCEDURE(obj: ProtectedObject; exclusive: BOOLEAN);
  1067. unlock: PROCEDURE(obj: ProtectedObject; dummy: BOOLEAN);
  1068. await: PROCEDURE(cond: Condition; slink: LONGINT; obj: ProtectedObject; flags: SET);
  1069. create: PROCEDURE(body: Body; priority: LONGINT; flags: SET; obj: ProtectedObject);
  1070. *)
  1071. VAR t: Process; fn: Heaps.FinalizerNode; proc: Kernel32.HANDLE;
  1072. res: Kernel32.BOOL;
  1073. lib: Kernel32.HMODULE;
  1074. BEGIN
  1075. Kernel32.AddVectoredExceptionHandler(1, ExcpFrmHandler);
  1076. (* lib := Kernel32.LoadLibrary("DbgHelp.DLL");
  1077. Kernel32.GetProcAddress(lib, "StackWalk64",SYSTEM.VAL(ADDRESS,StackWalk64));
  1078. *)
  1079. Kernel32.InitializeCriticalSection(excplock);
  1080. numberOfProcessors := Machine.NumberOfProcessors();
  1081. (* lock := Lock; unlock := Unlock; await := Await; create := CreateProcess;*)
  1082. NEW(t); NEW(fn);
  1083. Machine.Acquire(Machine.Objects);
  1084. t.gcContext.nextPos := 0;
  1085. nProcs := 1;
  1086. t.next := NIL; t.prev := NIL;
  1087. t.waitingOn := NIL; t.flags := {}; t.obj := NIL;
  1088. t.mode := Unknown; t.body := NIL;
  1089. t.priority := Normal;
  1090. fn.finalizer := FinalizeProcess;
  1091. Heaps.AddFinalizer(t, fn);
  1092. t.handle := Kernel32.GetCurrentThread();
  1093. t.id := Kernel32.GetCurrentThreadId();
  1094. proc := Kernel32.GetCurrentProcess();
  1095. res := Kernel32.DuplicateHandle(proc, t.handle, proc, t.handle, Kernel32.SetToDW({}), 0, Kernel32.SetToDW({Kernel32.DuplicateSameAccess}));
  1096. ASSERT(res # 0);
  1097. res := Kernel32.TlsSetValue(tlsIndex, SYSTEM.VAL(LONGINT, t));
  1098. ASSERT(res # 0);
  1099. t.stackBottom := StackBottom(); t.mode := Running;
  1100. Put( ready, t );
  1101. ASSERT(t.handle # 0);
  1102. Machine.Release(Machine.Objects);
  1103. InitEventHandling; (* implicit call of NewProcess! *)
  1104. InitGCHandling; (* do. *)
  1105. Heaps.gcStatus := GCStatusFactory();
  1106. END Init;
  1107. (** Set (or reset) an event handler object's timeout value. *)
  1108. PROCEDURE SetTimeout*(t: Timer; h: EventHandler; ms: LONGINT );
  1109. VAR e: Timer; trigger: LONGINT;
  1110. BEGIN
  1111. ASSERT(Machine.Second= 1000); (* assume milliseconds for now *)
  1112. ASSERT((t # NIL) & (h # NIL));
  1113. ASSERT(ms >= 0);
  1114. Machine.Acquire(Machine.Objects);
  1115. trigger := Kernel32.GetTickCount() + ms; (* ignore overflow *)
  1116. IF t.next # NIL THEN (* cancel previous timeout *)
  1117. t.next.prev := t.prev; t.prev.next := t.next
  1118. END;
  1119. t.trigger := trigger; t.handler := h;
  1120. e := event.next; (* performance: linear search! *)
  1121. WHILE (e # event) & (e.trigger - trigger <= 0) DO e := e.next END;
  1122. t.prev := e.prev; e.prev := t; t.next := e; t.prev.next := t;
  1123. Machine.Release(Machine.Objects);
  1124. clock.Wakeup()
  1125. END SetTimeout;
  1126. (** Set (or reset) an event handler object's timeout value. Here ms is absolute *)
  1127. PROCEDURE SetTimeoutAt*(t: Timer; h: EventHandler; ms: LONGINT);
  1128. VAR e: Timer; trigger: LONGINT;
  1129. BEGIN
  1130. ASSERT(Machine.Second= 1000); (* assume milliseconds for now *)
  1131. ASSERT((t # NIL) & (h # NIL));
  1132. Machine.Acquire(Machine.Objects);
  1133. trigger := ms; (* ignore overflow *)
  1134. IF t.next # NIL THEN (* cancel previous timeout *)
  1135. t.next.prev := t.prev; t.prev.next := t.next
  1136. END;
  1137. t.trigger := trigger; t.handler := h;
  1138. e := event.next; (* performance: linear search! *)
  1139. WHILE (e # event) & (e.trigger - trigger <= 0) DO e := e.next END;
  1140. t.prev := e.prev; e.prev := t; t.next := e; t.prev.next := t;
  1141. Machine.Release(Machine.Objects);
  1142. clock.Wakeup()
  1143. END SetTimeoutAt;
  1144. (** Cancel an event handler object's timeout, if any. It is possible that the timer has expired, but not yet been scheduled to run. *)
  1145. PROCEDURE CancelTimeout*( t: Timer );
  1146. BEGIN
  1147. Machine.Acquire(Machine.Objects);
  1148. ASSERT (t # event );
  1149. IF t.next # NIL THEN
  1150. t.next.prev := t.prev;
  1151. IF t.prev#NIL THEN t.prev.next := t.next; END;
  1152. t.next := NIL;
  1153. t.prev := NIL
  1154. END;
  1155. Machine.Release(Machine.Objects);
  1156. END CancelTimeout;
  1157. PROCEDURE InitEventHandling;
  1158. BEGIN
  1159. NEW(event); event.next := event; event.prev := event; (* event: head of timer event queue, only a sentinel *)
  1160. NEW(clock);
  1161. END InitEventHandling;
  1162. PROCEDURE InitGCHandling;
  1163. BEGIN
  1164. NEW(finalizerCaller);
  1165. END InitGCHandling;
  1166. PROCEDURE GCStatusFactory(): Heaps.GCStatus;
  1167. VAR gcStatusExt : GCStatusExt;
  1168. BEGIN
  1169. ASSERT(Heaps.gcStatus = NIL);
  1170. NEW(gcStatusExt);
  1171. RETURN gcStatusExt
  1172. END GCStatusFactory;
  1173. PROCEDURE InstallExceptionHandler*( e: ExceptionHandler );
  1174. BEGIN
  1175. exceptionhandler := e;
  1176. END InstallExceptionHandler;
  1177. PROCEDURE UpdateProcessState*( p: Process );
  1178. VAR res: Kernel32.BOOL;
  1179. BEGIN
  1180. res := Kernel32.GetThreadContext( p.handle, p.state );
  1181. ASSERT (p.handle # 0);
  1182. END UpdateProcessState;
  1183. (*ALEX 2005.12.12 added for WMPerfMon needs*)
  1184. PROCEDURE NumReady*( ): LONGINT;
  1185. VAR n: LONGINT; p: Heaps.ProcessLink;
  1186. BEGIN
  1187. n := 0;
  1188. Machine.Acquire( Machine.Objects );
  1189. p := ready.head;
  1190. WHILE p # NIL DO INC( n ); p := p.next END;
  1191. Machine.Release( Machine.Objects );
  1192. RETURN n
  1193. END NumReady;
  1194. (** Return number of CPU cycles consumed by the specified process. If all is TRUE,
  1195. return the number of cycles since the process has been created. If FALSE, return the number of cycles
  1196. consumed since the last time asked. *)
  1197. PROCEDURE GetCpuCycles*(process : Process; VAR cpuCycles : CpuCyclesArray; all : BOOLEAN);
  1198. VAR res : Kernel32.BOOL; temp : HUGEINT;
  1199. BEGIN
  1200. ASSERT(process # NIL);
  1201. IF (Kernel32.QueryThreadCycleTime # NIL) THEN
  1202. res := Kernel32.QueryThreadCycleTime(process.handle, cpuCycles[0]);
  1203. ELSE
  1204. cpuCycles[0] := Machine.GetTimer(); res := Kernel32.True;
  1205. END;
  1206. IF ~all & (res = Kernel32.True) THEN
  1207. temp := process.lastThreadTimes;
  1208. process.lastThreadTimes := cpuCycles[0];
  1209. cpuCycles[0] := cpuCycles[0] - temp;
  1210. END;
  1211. END GetCpuCycles;
  1212. PROCEDURE CurrentProcessTime*(): HUGEINT;
  1213. VAR res: LONGINT; result: HUGEINT;
  1214. BEGIN
  1215. IF (Kernel32.QueryThreadCycleTime # NIL) THEN
  1216. res := Kernel32.QueryThreadCycleTime(CurrentProcess().handle, result);
  1217. ELSE (* fallback *)
  1218. result := Machine.GetTimer();
  1219. END;
  1220. RETURN result;
  1221. END CurrentProcessTime;
  1222. PROCEDURE TimerFrequency*(): HUGEINT;
  1223. BEGIN
  1224. RETURN 1000000000;
  1225. END TimerFrequency;
  1226. VAR GetProcedureName*: PROCEDURE (pc: ADDRESS; VAR n: ARRAY OF CHAR; VAR spc: ADDRESS);
  1227. PROCEDURE LeaveA2;
  1228. VAR cur: Process; ebp,n: ADDRESS;
  1229. BEGIN
  1230. CODE
  1231. PUSH RCX
  1232. PUSH RDX
  1233. PUSH R8
  1234. PUSH R9
  1235. END;
  1236. IF clock = NIL THEN
  1237. RETURN
  1238. END;
  1239. cur := CurrentProcess();
  1240. IF cur # NIL THEN
  1241. ebp := Machine.CurrentBP();
  1242. SYSTEM.GET(ebp, n);
  1243. IF ODD(n) THEN SYSTEM.GET(ebp + SIZEOF(ADDRESS), ebp) ELSE ebp := n END;
  1244. cur.gcContext.last[cur.gcContext.nextPos] := ebp;
  1245. INC(cur.gcContext.nextPos);
  1246. ASSERT(cur.gcContext.nextPos < 255);
  1247. IF cur.gcContext.nextPos > 255 THEN cur.gcContext.nextPos := 255 END;
  1248. (* IF (cur.gcContext.nextPos > 4) THEN cur.gcContext.nextPos := 2 END;*)
  1249. END;
  1250. CODE
  1251. POP R9
  1252. POP R8
  1253. POP RDX
  1254. POP RCX
  1255. END;
  1256. END LeaveA2;
  1257. PROCEDURE ReenterA2;
  1258. VAR cur: Process;
  1259. BEGIN
  1260. IF clock = NIL THEN RETURN END;
  1261. cur := CurrentProcess();
  1262. IF cur # NIL THEN
  1263. (* cur.gcContext.first[cur.gcContext.next] := NIL;*)
  1264. DEC(cur.gcContext.nextPos);
  1265. IF (cur.gcContext.nextPos <0 ) THEN cur.gcContext.nextPos := 0 END;
  1266. cur.gcContext.last[cur.gcContext.nextPos] := NIL; (* returned *)
  1267. END;
  1268. END ReenterA2;
  1269. VAR
  1270. TraceProcessHook*: PROCEDURE (prcoess: Process; pc, bp: ADDRESS; stacklow, stackhigh: ADDRESS);
  1271. BEGIN
  1272. TraceProcessHook := NIL;
  1273. exceptionhandler := NIL;
  1274. terminateProc := TerminateProc;
  1275. ready.head := NIL; ready.tail := NIL;
  1276. tlsIndex := Kernel32.TlsAlloc();
  1277. ASSERT ( tlsIndex # Kernel32.TLSOutOfIndexes );
  1278. Kernel32.SendToDebugger("Modules.root", ADDRESSOF(Modules.root));
  1279. Init;
  1280. END Objects.
  1281. (*
  1282. 24.03.1998 pjm Started
  1283. 06.05.1998 pjm CreateProcess init process, page fault handler
  1284. 06.08.1998 pjm Moved exception interrupt handling here for current process
  1285. 17.08.1998 pjm FindRoots method
  1286. 02.10.1998 pjm Idle process
  1287. 06.11.1998 pjm snapshot
  1288. 25.03.1999 pjm Scope removed
  1289. 28.05.1999 pjm EventHandler object
  1290. 01.06.1999 pjm Fixed InterruptProcess lock error
  1291. 16.06.1999 pjm Flat IRQ priority model to avoid GC deadlock
  1292. 23.06.1999 pjm Flat IRQ priority experiment failed, rather do STI in FieldIRQ to avoid GC deadlock
  1293. 29.06.1999 pjm Timeout in EventHandler object
  1294. 13.01.2000 pjm Overed (Interrupt Objects, Event Handlers, Process ID, Process state, Process mode, Process stack, Await)
  1295. 17.10.2000 pjm Priorities
  1296. 22.10.2003 mib SSE2 extension
  1297. 24.10.2003 phk Priority inversion / cycle counters
  1298. Stack invariant for GC:
  1299. o if process is running, the processor registers contain its state
  1300. o if process is not running, at least state.ESP is valid, and between stack.adr and stack.high (for GC)
  1301. o when releasing the Ready lock, make sure the process state is up to date
  1302. *)
  1303. SystemTools.ShowStacks ~
  1304. Heaps.SetMetaData
  1305. 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 ~