Restore parent process after DOS 2.x child termination
authorRobert Pengelly <robertapengelly@hotmail.com>
Sun, 18 Oct 2026 16:15:09 +0000 (17:15 +0100)
committerRobert Pengelly <robertapengelly@hotmail.com>
Sun, 18 Oct 2026 16:15:09 +0000 (17:15 +0100)
interrupts.c

index dd06b14a14b301f5658ca4c8d5b42a83d8bed88f..209e9eedec4f65bea5d62f0c104b121062e0956f 100644 (file)
@@ -159,6 +159,32 @@ static void dos_terminate_process (CPU8086 *cpu) {
         
         }
         
+        /* DOS 2.x can create children through AH=55h without EXEC. */
+        if (caller_psp == cpu->psp_seg) {
+        
+            uint16_t parent_psp = mem_read16 (cpu->mem, cpu->mem_size, psp_base + 0x16);
+            uint16_t saved_sp = mem_read16 (cpu->mem, cpu->mem_size, psp_base + 0x2E);
+            uint16_t saved_ss = mem_read16 (cpu->mem, cpu->mem_size, psp_base + 0x30);
+            
+            if (parent_psp != 0 && parent_psp != cpu->psp_seg && saved_ss != 0 && return_cs != DOS_IVT_STUB_SEG && (return_cs != 0 || return_ip != 0)) {
+            
+                dos_close_process_handles (cpu);
+                dos_exec_release_memory (cpu);
+                
+                cpu->psp_seg = parent_psp;
+                cpu->ss = saved_ss;
+                
+                cpu->regs[REG_SP] = saved_sp;
+                
+                cpu->cs = return_cs;
+                cpu->ip = return_ip;
+                
+                return;
+            
+            }
+        
+        }
+        
         cpu->halted = 1;
         return;
     
@@ -6884,8 +6910,10 @@ static void int_21 (CPU8086 *cpu) {
             }
             
             for (i = 0; i < 12; i++) {
+            
                 mem_write8 (cpu->mem, cpu->mem_size, destination + 0x0A + i,
                     mem_read8 (cpu->mem, cpu->mem_size, (uint32_t) (0x22 * 4) + i));
+            
             }
             
             mem_write16 (cpu->mem, cpu->mem_size, destination + 0x16, parent_psp);