void do_irq (context_t context) { int flags; hw_save_flags_and_cli (flags); #if 1 irq_nesting_counter ++; if (hw_irq_ctrl [context.irqnr].ack) hw_ack_irq (context.irqnr); #endif if (irq_handler_table [context.irqnr]) (*irq_handler_table [context.irqnr]) (&context); else default_irq_handler (&context); #if 1 if (hw_irq_ctrl [context.irqnr].end) hw_end_irq (context.irqnr); irq_nesting_counter --; #endif hw_restore_flags (flags); if (irq_nesting_counter == SCHED_PENDING) { scheduling (); } do_signals(); }
static void drcomd_daemon(struct drcom_handle *h) { int s; int r; s = init_daemon_socket(); if(s < 0) exit(-1); if(setup_sig_handlers()<0){ logerr("sig handlers not setup, exit.\n"); exit(1); } loginfo("drcomd %s started.\n", DRCOM_VERSION); while (1) { int maxfd; fd_set readfds; FD_ZERO(&readfds); FD_SET(s, &readfds); FD_SET(sigusr1_pipe[READ_END], &readfds); maxfd = s; if(maxfd < sigusr1_pipe[READ_END]) maxfd = sigusr1_pipe[READ_END]; unblock_sigusr1(); r = select(maxfd+1, &readfds, NULL,NULL, NULL); if(r<0){ if(errno != EINTR) logerr("signal caught\n"); continue; } if(FD_ISSET(sigusr1_pipe[READ_END], &readfds)){ char buf[256]; int *sig = (int*)buf; read(sigusr1_pipe[READ_END], &buf, sizeof(buf)); do_signals(h, *sig); } if(!FD_ISSET(s, &readfds)) continue; block_sigusr1(); do_one_client(s, h); } /* FIXME: * drcom_clean_up(); * drcom_destroy_handle(); * close_daemon_socket(); */ }
static int do_spawn(struct spawn *sp, const char *command) { int status = -1; pid_t pid; if (!do_signals(sp->signals, sp->num_signals, SST_PRE)) return status; pid = fork(); if (pid < 0) { G_warning(_("Unable to create a new process")); undo_signals(sp->signals, sp->num_signals, SST_PRE); return status; } if (pid == 0) { if (!undo_signals(sp->signals, sp->num_signals, SST_PRE)) _exit(127); if (!do_signals(sp->signals, sp->num_signals, SST_CHILD)) _exit(127); if (sp->directory) if (chdir(sp->directory) < 0) { G_warning(_("Unable to change directory to %s"), sp->directory); _exit(127); } do_redirects(sp->redirects, sp->num_redirects); do_bindings(sp->bindings, sp->num_bindings); execvp(command, (char **)sp->args); G_warning(_("Unable to execute command")); _exit(127); } do_signals(sp->signals, sp->num_signals, SST_POST); if (sp->background) status = (int)pid; else { pid_t n; do n = waitpid(pid, &status, 0); while (n == (pid_t) - 1 && errno == EINTR); if (n != pid) status = -1; else { if (WIFEXITED(status)) status = WEXITSTATUS(status); else if (WIFSIGNALED(status)) status = WTERMSIG(status); else status = -0x100; } } undo_signals(sp->signals, sp->num_signals, SST_POST); undo_signals(sp->signals, sp->num_signals, SST_PRE); return status; }
int main(int argc, char **argv) { int x = 0; char *args[10]; setuid(2); signal(SIGCHLD, sigchld); do_signals(); x += getpid(); x += getppid(); x += getuid(); x += getgid(); x += setsid(); x += seteuid(); x += setegid(); lseek(0, 0, -1); kill(0, 0); signal(99, 0); signal(SIGINT, int_handler); signal(SIGSEGV, segv_handler); // *(int *) 0 = 0; pipe(0); munmap(0, 0); mincore(0, 0); shmget(0); shmat(0); line = __LINE__; poll(-1, 0, 0); signal(SIGSEGV, SIG_IGN); // ppoll(-1, -1, -1, 0); signal(SIGSEGV, SIG_DFL); sched_yield(); readv(-1, 0, 0, 0); writev(-1, 0, 0, 0); msync(0, 0, 0); fsync(-1); fdatasync(-1); semget(0, 0, 0); semctl(0, 0, 0); uselib(NULL); pivot_root(0, 0); personality(-1); setfsuid(-1); flock(-1, 0); shmdt(0, 0, 0); times(0); mremap(0, 0, 0, 0, 0); madvise(0, 0, 0); fchown(-1, 0, 0); lchown(0, 0, 0); setreuid(); setregid(); link("/nonexistant", "/also-nonexistant"); do_slow(); symlink("/nothing", "/"); rename("/", "/"); mkdir("/junk/stuff////0", 0777); geteuid(); getsid(); getpgid(); getresuid(); getresgid(); getpgid(); ptrace(-1, 0, 0, 0); semop(0, 0, 0); capget(0, 0); line = __LINE__; gettimeofday(0, 0); settimeofday(0, 0); dup(-1); dup2(-1, -1); shmctl(0, 0, 0, 0); execve("/bin/nothing", "/bin/nothing", 0); alarm(9999); bind(0, 0, 0); socket(0, 0, 0); accept(0, 0, 0); listen(0); shutdown(0); getsockname(0, 0, 0); getpeername(0, 0, 0); truncate(0, 0); ftruncate(0, 0); line = __LINE__; if (vfork() == 0) exit(0); line = __LINE__; x = opendir("/", 0, 0); line = __LINE__; readdir(x, 0, 0); line = __LINE__; closedir(x); line = __LINE__; chroot("/"); line = __LINE__; sigaction(0, 0, 0); line = __LINE__; sigprocmask(0, 0, 0); x += open("/nothing", 0); x += chdir("/nothing"); x += mknod("/nothing/nothing", 0); x += ioctl(); execve("/nothing", NULL, NULL); line = __LINE__; x += close(-2); line = __LINE__; if (fork() == 0) exit(0); line = __LINE__; clone(clone_func, 0, 0, 0); line = __LINE__; brk(0); sbrk(0); line = __LINE__; mmap(0, 0, 0, 0, 0); line = __LINE__; uname(0); line = __LINE__; getcwd(0, 0); line = __LINE__; iopl(3); ioperm(0, 0, 0); mount(0, 0, 0, 0, 0); umount(0, 0); umount(0, 0, 0); swapon(0, 0); swapoff(0); sethostname(0); line = __LINE__; time(NULL); unlink("/nothing"); line = __LINE__; rmdir("/nothing"); chmod(0, 0); line = __LINE__; # if defined(__i386) || defined(__amd64) modify_ldt(0); # endif stat("/doing-nice", 0); nice(0); args[0] = "/bin/df"; args[1] = "-l"; args[2] = NULL; close(1); open("/dev/null", O_WRONLY); /***********************************************/ /* Some syscalls arent available direct */ /* from libc, so get them here. We mostly */ /* care about the ones which have caused */ /* implementation difficulty and kernel */ /* crashes - eventually we can be complete. */ /***********************************************/ line = __LINE__; open("/system-dependent-syscalls-follow", 0); line = __LINE__; if (fork() == 0) exit(0); {int status; while (wait(&status) >= 0) ; } sigaltstack(0, 0); /*vm86(0, 0);*/ /***********************************************/ /* Some syscalls arent directly accessible, */ /* e.g. legacy. */ /***********************************************/ #if defined(__x86_64__) trace(__LINE__, "x64 syscalls"); syscall(174, 0, 0, 0); // create_module syscall(176, 0, 0, 0); // delete_module syscall(178, 0, 0, 0); // query_module #else trace(__LINE__, "x32 syscalls"); syscall(0, 0, 0, 0); // restart_syscall syscall(34, 0, 0, 0); // nice syscall(59, 0, 0, 0); // oldolduname syscall(109, 0, 0, 0); // olduname if (fork() == 0) syscall(1, 0, 0, 0); // exit #endif line = __LINE__; execve("/bin/df", args, NULL); fprintf(stderr, "Error: should not get here -- %s\n", strerror(errno)); exit(1); }