test: psctx386.c Source File

Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

# psctx386.c

Go to the documentation of this file.

    00001 /*++
    00002
    00003 Copyright (c) 1989  Microsoft Corporation
    00004
    00005 Module Name:
    00006
    00007     psctx.c
    00008
    00009 Abstract:
    00010
    00011     This procedure implements Get/Set Context Thread
    00012
    00013 Author:
    00014
    00015     Mark Lucovsky (markl) 25-May-1989
    00016
    00017 Notes:
    00018
    00019     There IS NO NonVolatileContext stored outside of the trap
    00020     frame on a 386, with the exception of floating point.  Hence,
    00021     the NonVolatileContextPointers argument to Get/SetContext is
    00022     always NULL on the 386.
    00023
    00024 Revision History:
    00025
    00026      8-Jan-90   bryanwi
    00027
    00028         Port to 386
    00029
    00030 --*/
    00031
    00032 #include "psp.h"
    00033
    00034 #define PSPALIGN_DOWN(address,amt) ((ULONG)(address) & ~(( amt ) - 1))
    00035
    00036 #define PSPALIGN_UP(address,amt) (PSPALIGN_DOWN( (address + (amt) - 1), (amt) ))
    00037
    00038 #ifdef ALLOC_PRAGMA
    00039 #pragma alloc_text(PAGE,PspGetContext )
    00040 #pragma alloc_text(PAGE,PspGetSetContextSpecialApc )
    00041 #pragma alloc_text(PAGE,PspSetContext)
    00042 #endif
    00043
    00044
    00045 VOID
    00046 PspGetContext(
    00047     IN PKTRAP_FRAME TrapFrame,
    00048     IN PKNONVOLATILE_CONTEXT_POINTERS NonVolatileContext,
    00049     IN OUT PCONTEXT Context
    00050     )
    00051
    00052 /*++
    00053
    00054 Routine Description:
    00055
    00056     This function moves the contents of the specified trap and NonVolatile
    00057     context into the specified context record. It's primary user will
    00058     be NtGetContextThread.
    00059
    00060     N.B. - NonVolatileContext is IGNORED on the 386.
    00061
    00062 Arguments:
    00063
    00064     TrapFrame - Supplies the contents of a trap frame that should be
    00065                 restored copied into the proper location in the context
    00066                 record.
    00067
    00068     Context - Returns the threads current context.
    00069
    00070 Return Value:
    00071
    00072     None.
    00073
    00074 --*/
    00075
    00076 {
    00077     UNREFERENCED_PARAMETER( NonVolatileContext );
    00078
    00079     PAGED_CODE();
    00080
    00081     ASSERT(((TrapFrame->SegCs & MODE_MASK) != KernelMode) ||
    00082            (TrapFrame->EFlags & EFLAGS_V86_MASK));
    00083
    00084     KeContextFromKframes(TrapFrame, NULL, Context);
    00085 }
    00086
    00087 VOID
    00088 PspSetContext(
    00089     OUT PKTRAP_FRAME TrapFrame,
    00090     OUT PKNONVOLATILE_CONTEXT_POINTERS NonVolatileContext,
    00091     IN PCONTEXT Context,
    00092     KPROCESSOR_MODE Mode
    00093     )
    00094
    00095 /*++
    00096
    00097 Routine Description:
    00098
    00099     This function moves the contents of the specified context record
    00100     into the specified trap frame, and modifies the thread's non volatile
    00101     context by storing through the thread's nonvolatile context pointers.
    00102
    00103     N.B. - NonVolatileContext is IGNORED on the 386.
    00104
    00105 Arguments:
    00106
    00107     TrapFrame - Returns selected pieces of the context record.
    00108
    00109     Context - Supplies a context record to be copied in the trap and
    00110               nonvolatile context.
    00111
    00112     Mode - Supplies the mode to be used when sanitizing the psr, epsr and fsr
    00113
    00114 Return Value:
    00115
    00116     None.
    00117
    00118 --*/
    00119
    00120 {
    00121     UNREFERENCED_PARAMETER( NonVolatileContext );
    00122     ASSERT(((TrapFrame->SegCs & MODE_MASK) != KernelMode) ||
    00123            (TrapFrame->EFlags & EFLAGS_V86_MASK));
    00124
    00125     PAGED_CODE();
    00126
    00127     KeContextToKframes(TrapFrame, NULL, Context, Context->ContextFlags, Mode);
    00128 }
    00129
    00130 VOID
    00131 PspGetSetContextSpecialApc(
    00132     IN PKAPC Apc,
    00133     IN PKNORMAL_ROUTINE *NormalRoutine,
    00134     IN PVOID *NormalContext,
    00135     IN PVOID *SystemArgument1,
    00136     IN PVOID *SystemArgument2
    00137     )
    00138
    00139 /*++
    00140
    00141 Routine Description:
    00142
    00143     This function either captures the usermode state of the current
    00144     thread, or sets the usermode state of the current thread. The
    00145     operation type is determined by the value of SystemArgument1. A
    00146     NULL value is used for get context, and a non-NULL value is used
    00147     for set context.
    00148
    00149 Arguments:
    00150
    00151     Apc - Supplies a pointer to the APC control object that caused entry
    00152           into this routine.
    00153
    00154     NormalRoutine - Supplies a pointer to a pointer to the normal routine
    00155         function that was specifed when the APC was initialized.
    00156
    00157     NormalContext - Supplies a pointer to a pointer to an arbitrary data
    00158         structure that was specified when the APC was initialized.
    00159
    00160     SystemArgument1, SystemArgument2 - Supplies a set of two pointer to two
    00161         arguments that contain untyped data.
    00162
    00163 Return Value:
    00164
    00165     None.
    00166
    00167 --*/
    00168
    00169 {
    00170     PGETSETCONTEXT Ctx;
    00171     PKTRAP_FRAME TrapFrame;
    00172     PETHREAD Thread;
    00173
    00174     PAGED_CODE();
    00175
    00176     UNREFERENCED_PARAMETER( NormalRoutine );
    00177     UNREFERENCED_PARAMETER( NormalContext );
    00178     UNREFERENCED_PARAMETER( SystemArgument1 );
    00179     UNREFERENCED_PARAMETER( SystemArgument2 );
    00180
    00181     Ctx = CONTAINING_RECORD(Apc,GETSETCONTEXT,Apc);
    00182     Thread = Apc->SystemArgument2;
    00183
    00184     TrapFrame = (PKTRAP_FRAME)((PUCHAR)Thread->Tcb.InitialStack -
    00185                 PSPALIGN_UP(sizeof(KTRAP_FRAME),KTRAP_FRAME_ALIGN) -
    00186                 sizeof(FX_SAVE_AREA));
    00187
    00188     if ( Apc->SystemArgument1 ) {
    00189
    00190         //
    00191         // Set Context
    00192         //
    00193
    00194         PspSetContext(TrapFrame,NULL,&Ctx->Context,Ctx->Mode);
    00195
    00196     } else {
    00197
    00198         //
    00199         // Get Context
    00200         //
    00201
    00202         PspGetContext(TrapFrame,NULL,&Ctx->Context);
    00203     }
    00204
    00205     KeSetEvent(&Ctx->OperationComplete,0,FALSE);
    00206
    00207 }