Author: aandrejevic
Date: Sat May 2 02:59:21 2015
New Revision: 67507
URL:
http://svn.reactos.org/svn/reactos?rev=67507&view=rev
Log:
[NTVDM]
Implement INT 27h (Terminate and Stay Resident).
Keep track of the last entry SS:SP in the INT 21h handler.
Restore the stack in DosTerminateProcess.
The number of bytes to keep resident applies only to the block which holds the PSP,
other blocks are not freed.
Modified:
trunk/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/dos.c
trunk/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/process.c
Modified: trunk/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/dos.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/mvdm/ntvdm/dos/…
==============================================================================
--- trunk/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/dos.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/dos.c [iso-8859-1] Sat May 2
02:59:21 2015
@@ -177,6 +177,10 @@
INT Return;
(*InDos)++;
+
+ /* Save the value of SS:SP on entry in the PSP */
+ SEGMENT_TO_PSP(CurrentPsp)->LastStack =
+ MAKELONG(getSP() + (STACK_FLAGS + 1) * 2, getSS());
/* Check the value in the AH register */
switch (getAH())
@@ -1817,6 +1821,11 @@
Stack[STACK_FLAGS] |= EMULATOR_FLAG_CF;
}
+VOID WINAPI DosInt27h(LPWORD Stack)
+{
+ DosTerminateProcess(getCS(), 0, (getDX() + 0x0F) >> 4);
+}
+
VOID WINAPI DosFastConOut(LPWORD Stack)
{
/*
@@ -2002,6 +2011,7 @@
// RegisterDosInt32(0x22, DosInt22h ); // Termination
RegisterDosInt32(0x23, DosBreakInterrupt); // Ctrl-C / Ctrl-Break
// RegisterDosInt32(0x24, DosInt24h ); // Critical Error
+ RegisterDosInt32(0x27, DosInt27h ); // Terminate and Stay Resident
RegisterDosInt32(0x29, DosFastConOut ); // DOS 2+ Fast Console Output
RegisterDosInt32(0x2F, DosInt2Fh );
Modified: trunk/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/process.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/mvdm/ntvdm/dos/…
==============================================================================
--- trunk/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/process.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/process.c [iso-8859-1] Sat May 2
02:59:21 2015
@@ -780,23 +780,20 @@
/* Check if this block was allocated by the process */
if (CurrentMcb->OwnerPsp == Psp)
{
- if (KeepResident == 0)
+ if (KeepResident)
+ {
+ /* Check if this is the PSP block and we should reduce its size */
+ if (McbSegment == Psp && KeepResident < CurrentMcb->Size)
+ {
+ /* Reduce the size of the block */
+ DosResizeMemory(McbSegment + 1, KeepResident, NULL);
+ break;
+ }
+ }
+ else
{
/* Free this entire block */
DosFreeMemory(McbSegment + 1);
- }
- else if (KeepResident < CurrentMcb->Size)
- {
- /* Reduce the size of the block */
- DosResizeMemory(McbSegment + 1, KeepResident, NULL);
-
- /* No further paragraphs need to stay resident */
- KeepResident = 0;
- }
- else
- {
- /* Just reduce the amount of paragraphs we need to keep resident */
- KeepResident -= CurrentMcb->Size;
}
}
@@ -849,6 +846,10 @@
/* Save the return code - Normal termination */
DosErrorLevel = MAKEWORD(ReturnCode, 0x00);
+ /* Restore the old stack */
+ setSS(HIWORD(SEGMENT_TO_PSP(CurrentPsp)->LastStack));
+ setSP(LOWORD(SEGMENT_TO_PSP(CurrentPsp)->LastStack));
+
/* Return control to the parent process */
CpuExecute(HIWORD(PspBlock->TerminateAddress),
LOWORD(PspBlock->TerminateAddress));