📄 signals.c
字号:
** check signals settings , change eip to signal handler
*/
static int do_signal(int signal)
{
DWORD address;
DWORD mask;
#ifdef CONFIG_KDEB
if (!opt_kdeb)
#endif
/* if debugger: switch first */
if ((npz->p_flags & PF_DEBUG) && signal != SIGKILL && signal != SIGCLD) {
npz->wait_return = (signal << 8) | 127;
npz->p_flags |= PF_WAIT_WAIT;
npz->p_status = PS_STOP;
npz->pptr->p_status = PS_RUN; /* run debugger */
switch_context(npz->pptr);
npz->p_status = PS_RUN; /* continue child */
npz->wait_return = 0;
if (signal == SIGTRAP) {
mask = ~ SIGMASK(signal);
npz->sig_raised &= mask;
npz->sig_blocked &= mask;
return 0;
}
}
address = npz->sigaction[SIGSA(signal)].sa_handler;
if (opt_printall)
printf("do_signal %d handler %lX\n", signal, address);
mask = SIGMASK(signal);
npz->sig_raised &= ~mask; /* clear sig_raised */
if (address == 1L) /* ignore sig */
return 0;
if (address == 0L) {
/* emx ignores SIGCLD, SIGCHLD, SIGUSR */
if (sigdfl[SIGSA(signal)].action == SIGDFL_IGNORE)
return 0;
else if (sigdfl[SIGSA(signal)].action == SIGDFL_CORE) {
if (!opt_nocore)
write_core_file(npz);
}
printf("\nProcess terminated by %s\n", sigdfl[SIGSA(signal)].text);
do_exit4c(signal);
return 1;
}
/* ok, do user handler */
if (npz->sigaction[SIGSA(signal)].sa_flags & SA_SYSV)
npz->sigaction[SIGSA(signal)].sa_handler = 0L;
else
npz->sig_blocked |= mask; /* set blocked */
setup_frame(address, npz->sig_blocked, signal);
/* BSD block others */
npz->sig_blocked |= npz->sigaction[SIGSA(signal)].sa_mask;
return 1;
}
long sys_signal(int signum, long handler)
{
long old_handler;
if (signum < 1 || signum >= MAX_SIGNALS || signum == SIGKILL)
return -1;
old_handler = npz->sigaction[SIGSA(signum)].sa_handler;
if (handler == SIG_ACK) {
npz->sig_blocked &= ~ SIGMASK(signum);
return old_handler;
}
else if (handler != SIG_DFL && handler != SIG_IGN)
if (verify_illegal(npz, handler, 4))
return -1;
npz->sigaction[SIGSA(signum)].sa_handler = handler;
npz->sigaction[SIGSA(signum)].sa_flags = 0;
npz->sigaction[SIGSA(signum)].sa_mask = 0;
if ((npz->uflags & 3) == 1) /* system V */
npz->sigaction[SIGSA(signum)].sa_flags = SA_SYSV;
else if ((npz->uflags & 3) == 2) /* BSD */
npz->sigaction[SIGSA(signum)].sa_flags = 0;
else /* old EMX */
npz->sigaction[SIGSA(signum)].sa_flags = SA_ACK;
return old_handler;
}
char *exceptext[] =
{
"division by zero",
"debug",
"NMI",
"breakpoint",
"overflow",
"bound check",
"invalid opcode",
"copro not availble",
"double fault",
"copro exception",
"invalid TSS",
"segment not present",
"stack fault",
"general protection",
"page fault",
"reserved",
"copro error",
"alignment error"
};
/*
** this function is called after hardware exceptions
*/
/* regs after exceptions */
REG386 regf;
EXCEPTION_10 reg_info;
void myexcep13(void)
{ /* C exception handler */
int signal;
#ifdef CONFIG_KDEB
if (opt_kdeb && (WORD) regf.cs == code16sel && regf.faultno == 1) {
memcpy(&(RSX_PROCESS.regs), ®f, sizeof(REG386));
return KDEB_debug_handler();
}
#endif
if (opt_printall)
printf("Exception %d\n", (WORD) regf.faultno);
/* test if we have a error in kernel, abort rsx */
/* future versions will just terminate the running process */
if ((WORD) regf.cs == code16sel || (WORD) regf.ds == data16sel) {
printf("Kernel fault at %X %lX\n", (WORD) regf.cs, regf.eip);
printf("EAX=%08lX EBX=%08lX ECX=%08lX EDX=%08lX\n"
"EBP=%08lX ESP=%08lX ESI=%08lX EDI=%08lX\n"
"CS=%04X DS=%04X ES=%04X SS=%04X\n",
regf.eax, regf.ebx, regf.ecx, regf.edx,
regf.ebp, regf.esp, regf.esi, regf.edi,
(WORD) regf.cs, (WORD) regf.ds, (WORD) regf.es, (WORD) regf.ss);
if (dpmi10) {
printf("cr2 = %lX\n", reg_info.cr2);
printf("pte = %lX\n", reg_info.pte);
}
printf("User Registers:\n");
npz->regs.faultno = regf.faultno;
print_exception_exit();
}
/* user fault, copy saved regs to process table */
memcpy(&(npz->regs), ®f, sizeof(REG386));
signal = exception2signal(FAULTNO);
if (signal != SIGTRAP) {
printf("process %d get hardware fault %d (%s) at %lX\n",
npz->pid, FAULTNO, exceptext[FAULTNO], EIP);
if (opt_printall) {
print_regs_exception();
if (dpmi10) {
printf("cr2 = %lX\n", reg_info.cr2);
printf("offset = %lX\n", reg_info.cr2 - npz->memaddress);
printf("pte = %lX\n", reg_info.pte);
}
}
}
send_signal(npz, signal);
/* then, check_signal() is called (see excep32.asm) */
}
static void print_regs_exception(void)
{
printf("selector=%lX errbits: %X\n"
"cs:eip=%04X:%08lX eflags=%08lX\n"
"eax=%08lX ebx=%08lX ecx=%08lX edx=%08lX\n"
"ebp=%08lX esp=%08lX esi=%08lX edi=%08lX\n"
"cs=%04X ds=%04X es=%04X ss=%04X fs=%04X gs=%04X\n",
ERR & ~7L, (WORD) ERR & 7,
CS, EIP, EFLAGS,
EAX, EBX, ECX, EDX,
EBP, ESP, ESI, EDI,
CS, DS, ES, SS, FS, GS);
}
static void print_exception_exit()
{
printf("PROTECTION FAULT %d :\n", FAULTNO);
print_regs_exception();
shut_down(3);
}
/*
** DPMI 1.0 support, damand paging
**
** only called, if start32.c sets page_fault() function
*/
/*
** commit page, if legal address
** page in text, data
** return 1, if real page-fault
*/
static unsigned char pagein_buffer[4096];
int swapper(void)
{
DWORD offset;
NEWPROCESS *proc;
WORD page = 1 + 8; /* commit & read/write */
int handle;
if ((WORD) reg_info.cs == code16sel) {
/* copy in kernel, find current process */
for (proc = &FIRST_PROCESS; proc <= &LAST_PROCESS; proc++) {
if (!proc->code32sel)
continue;
if ((reg_info.cr2 > proc->memaddress) &&
(reg_info.cr2 < proc->memaddress + proc->membytes))
break;
}
if (proc > &LAST_PROCESS) {
if (opt_printall) {
puts("swapper: cannot find process");
printf("pagefault in %04X\n", (WORD) reg_info.cs);
printf("cr2 %08lX\n", reg_info.cr2);
printf("pte %X err %X\n", (WORD) reg_info.pte, (WORD) reg_info.error_code);
}
return 1;
}
} else
proc = npz;
offset = (reg_info.cr2 - proc->memaddress) & ~0xFFFL;
#if 0
if (opt_printall) {
printf("process %d : pagefault in %04X\n", proc->pid, (WORD) reg_info.cs);
printf("cr2 %08lX, pageoffset %08lX\n", reg_info.cr2, offset);
printf("pte %X err %X\n", (WORD) reg_info.pte, (WORD) reg_info.error_code);
printf("memaddress = %lX handle = %lX\n", proc->memaddress, proc->memhandle);
}
#endif
if (proc->pid == 0)
return 1;
handle = (int) proc->filehandle;
/* text */
if (offset >= proc->text_start && offset < proc->text_end) {
if ((WORD) reg_info.cs != code16sel && (reg_info.error_code & 2))
return 1;
if (ModifyPageAttributes(proc->memhandle, offset, 1, &page))
return 1; /* better:readonly */
if (handle == 0) /* forked process */
return 0;
rm_lseek(handle, proc->text_off + (offset - proc->text_start), SEEK_SET);
if (rm_read(handle, pagein_buffer, 4096) != 4096)
return 1;
cpy16_32(proc->data32sel, offset, pagein_buffer, 4096L);
page = 1;
if (ModifyPageAttributes(proc->memhandle, offset, 1, &page))
return 1;
return 0;
} else
/* bss */ if (offset >= proc->bss_start && offset < proc->bss_end) {
if (ModifyPageAttributes(proc->memhandle, offset, 1, &page))
return 1;
if (handle == 0) /* forked process */
return 0;
bzero32(proc->data32sel, offset, 4096L);
return 0;
} else
/* data */ if (offset >= proc->data_start && offset < proc->data_end) {
if (ModifyPageAttributes(proc->memhandle, offset, 1, &page))
return 1;
if (handle == 0) /* forked process */
return 0;
rm_lseek(handle, proc->data_off + (offset - proc->data_start), SEEK_SET);
if (rm_read(handle, pagein_buffer, 4096) != 4096)
return 1;
cpy16_32(proc->data32sel, offset, pagein_buffer, 4096L);
return 0;
} else
/* heap */ if (offset >= proc->init_brk && offset < proc->brk_value) {
if (ModifyPageAttributes(proc->memhandle, offset, 1, &page))
return 1;
if (handle == 0) /* forked process */
return 0;
if (proc->p_flags & PF_DJGPP_FILE)
bzero32(proc->data32sel, offset, 4096L);
return 0;
} else
/* stack */ if (offset >= proc->brk_value && offset <= proc->membytes) {
if (ModifyPageAttributes(proc->memhandle, offset, 1, &page))
return 1;
return 0;
} else
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -