[NTOS]: Implement MmDeleteTeb, VADs are now deleted/freed on thread exit as well...
[reactos.git] / reactos / ntoskrnl / ps / amd64 / psctx.c
1 /*
2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: ntoskrnl/ps/amd64/pxctx.c
5 * PURPOSE: Process Manager: Set/Get Context for i386
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7 * Timo Kreuzer (timo.kreuzer@reactos.org)
8 */
9
10 /* INCLUDES *******************************************************************/
11
12 #include <ntoskrnl.h>
13 #define NDEBUG
14 #include <debug.h>
15
16 /* FUNCTIONS ******************************************************************/
17
18 VOID
19 NTAPI
20 PspGetContext(IN PKTRAP_FRAME TrapFrame,
21 IN PVOID NonVolatileContext,
22 IN OUT PCONTEXT Context)
23 {
24 PAGED_CODE();
25
26 /* Convert the trap frame to a context */
27 KeTrapFrameToContext(TrapFrame, NULL, Context);
28 }
29
30 VOID
31 NTAPI
32 PspSetContext(OUT PKTRAP_FRAME TrapFrame,
33 OUT PVOID NonVolatileContext,
34 IN PCONTEXT Context,
35 IN KPROCESSOR_MODE Mode)
36 {
37 PAGED_CODE();
38
39 /* Convert the context to a trap frame structure */
40 KeContextToTrapFrame(Context, NULL, TrapFrame, Context->ContextFlags, Mode);
41 }
42
43 VOID
44 NTAPI
45 PspGetOrSetContextKernelRoutine(IN PKAPC Apc,
46 IN OUT PKNORMAL_ROUTINE* NormalRoutine,
47 IN OUT PVOID* NormalContext,
48 IN OUT PVOID* SystemArgument1,
49 IN OUT PVOID* SystemArgument2)
50 {
51 PGET_SET_CTX_CONTEXT GetSetContext;
52 PKEVENT Event;
53 PCONTEXT Context;
54 PKTHREAD Thread;
55 KPROCESSOR_MODE Mode;
56 PKTRAP_FRAME TrapFrame = NULL;
57 PAGED_CODE();
58
59 /* Get the Context Structure */
60 GetSetContext = CONTAINING_RECORD(Apc, GET_SET_CTX_CONTEXT, Apc);
61 Context = &GetSetContext->Context;
62 Event = &GetSetContext->Event;
63 Mode = GetSetContext->Mode;
64 Thread = Apc->SystemArgument2;
65
66 /* If this is a kernel-mode request, grab the saved trap frame */
67 if (Mode == KernelMode) TrapFrame = Thread->TrapFrame;
68
69 /* If we don't have one, grab it from the stack */
70 if (!TrapFrame)
71 {
72 DPRINT1("FIXME!!!!\n");
73 /* Trap frame is right under our initial stack */
74 // TrapFrame = (PKTRAP_FRAME)((ULONG_PTR)Thread->InitialStack -
75 // ROUND_UP(sizeof(KTRAP_FRAME), KTRAP_FRAME_ALIGN) -
76 // sizeof(FX_SAVE_AREA));
77 }
78
79 /* Check if it's a set or get */
80 if (Apc->SystemArgument1)
81 {
82 /* Get the Context */
83 PspSetContext(TrapFrame, NULL, Context, Mode);
84 }
85 else
86 {
87 /* Set the Context */
88 PspGetContext(TrapFrame, NULL, Context);
89 }
90
91 /* Notify the Native API that we are done */
92 KeSetEvent(Event, IO_NO_INCREMENT, FALSE);
93 }
94
95 /* EOF */