int sys_reboot( void ) { thread_id hThread; int i; write_kernel_config(); // Since we (hopefully) wont be killed by the signal we must close our files manually. for ( i = 0; i < 256; ++i ) { sys_close( i ); } printk( "Send TERM signals\n" ); for ( hThread = get_prev_thread( -1 ); -1 != hThread; hThread = get_prev_thread( hThread ) ) { if ( hThread > 1 ) { sys_kill( hThread, SIGTERM ); } } snooze( 2000000 ); printk( "Send KILL signals\n" ); for ( hThread = get_prev_thread( -1 ); -1 != hThread; hThread = get_prev_thread( hThread ) ) { if ( hThread > 1 ) { sys_kill( hThread, SIGKILL ); } } snooze( 1000000 ); printk( "Flush block cache()\n" ); flush_block_cache(); printk( "Shut down VFS\n" ); shutdown_vfs(); printk( "shut down block cache()\n" ); shutdown_block_cache(); shutdown_ap_processors(); printk( "Rebooting Pyro...\n" ); // Just to be sure :) snooze( 1000000 ); hard_reset(); printk( "It must be a sign!\n" ); return ( 0 ); }
void notify_rec(int *receivers) { printf("inside notify_rec..., argument receivers[0]=%d\n",receivers[0]); int i, status; for (i = 0; i < MAX_REQ_NOT; i++) { if (req_receivers[i].pid > 0) { printf("inside notify_rec... at least 1 pid (%d) requested notify\n", req_receivers[i].pid); status = array_search(receivers, MAX_PROCESSES, req_receivers[i].pid); if (status != FAIL) { printf("inside notify_rec... found receiver %d in array_search, executing kill\n",req_receivers[i].pid); int kill_status = sys_kill(req_receivers[i].proc_nr, req_receivers[i].signum); if ( kill_status < 0) { printf("Error %d: some proccess (%d) didn't receive the notification (%d)\n", kill_status, req_receivers[i].proc_nr, req_receivers[i].signum); } } } } }
static void sigchld_handler(int signal, siginfo_t *siginfo, void *data) { char *r; if (futex_get(&task_entries->start) == CR_STATE_RESTORE_SIGCHLD) { pr_debug("%ld: Collect a zombie with (pid %d, %d)\n", sys_getpid(), siginfo->si_pid, siginfo->si_pid); futex_dec_and_wake(&task_entries->nr_in_progress); futex_dec_and_wake(&zombies_inprogress); task_entries->nr_threads--; task_entries->nr_tasks--; mutex_unlock(&task_entries->zombie_lock); return; } if (siginfo->si_code & CLD_EXITED) r = " exited, status="; else if (siginfo->si_code & CLD_KILLED) r = " killed by signal "; else r = "disappeared with "; pr_info("Task %d %s %d\n", siginfo->si_pid, r, siginfo->si_status); futex_abort_and_wake(&task_entries->nr_in_progress); /* sa_restorer may be unmaped, so we can't go back to userspace*/ sys_kill(sys_getpid(), SIGSTOP); sys_exit_group(1); }
/*===========================================================================* * do_pending_pipe * *===========================================================================*/ static void do_pending_pipe(void) { int r, op; struct filp *f; tll_access_t locktype; f = fp->fp_filp[fp->fp_fd]; assert(f != NULL); locktype = (job_call_nr == VFS_READ) ? VNODE_READ : VNODE_WRITE; op = (job_call_nr == VFS_READ) ? READING : WRITING; lock_filp(f, locktype); r = rw_pipe(op, who_e, f, fp->fp_io_buffer, fp->fp_io_nbytes); if (r != SUSPEND) { /* Do we have results to report? */ /* Process is writing, but there is no reader. Send a SIGPIPE signal. * This should match the corresponding code in read_write(). */ if (r == EPIPE && op == WRITING) { if (!(f->filp_flags & O_NOSIGPIPE)) sys_kill(fp->fp_endpoint, SIGPIPE); } replycode(fp->fp_endpoint, r); } unlock_filp(f); }
/* * Reboot system call: for obvious reasons only root may call it, * and even root needs to set up some magic numbers in the registers * so that some mistake won't make this reboot the whole machine. * You can also set the meaning of the ctrl-alt-del-key here. * * reboot doesn't sync: do that yourself before calling this. */ asmlinkage int sys_reboot(int magic, int magic_too, int flag) { if (!suser()) return -EPERM; if (magic != 0xfee1dead || magic_too != 672274793) return -EINVAL; if (flag == 0x01234567) { #ifdef CONFIG_SCSI_GDTH gdth_halt(); #endif hard_reset_now(); } else if (flag == 0x89ABCDEF) C_A_D = 1; else if (!flag) C_A_D = 0; else if (flag == 0xCDEF0123) { #ifdef CONFIG_SCSI_GDTH gdth_halt(); #endif printk(KERN_EMERG "System halted\n"); sys_kill(-1, SIGKILL); #if defined(CONFIG_APM) && defined(CONFIG_APM_POWER_OFF) apm_power_off(); #endif do_exit(0); } else return -EINVAL; return (0); }
int kt_kernel_idle_task(void) { tm_thread_raise_flag(current_thread, THREAD_KERNEL); kthread_create(&kthread_pager, "[kpager]", 0, __KT_pager, 0); strncpy((char *)current_process->command, "[kernel]", 128); /* wait until init has successfully executed, and then remap. */ while(!(kernel_state_flags & KSF_HAVEEXECED)) { tm_schedule(); } printk(1, "[kernel]: remapping lower memory with protection flags...\n"); cpu_interrupt_set(0); for(addr_t addr = MEMMAP_KERNEL_START; addr < MEMMAP_KERNEL_END; addr += PAGE_SIZE) { mm_virtual_changeattr(addr, PAGE_PRESENT | PAGE_WRITE, PAGE_SIZE); } cpu_interrupt_set(1); /* Now enter the main idle loop, waiting to do periodic cleanup */ printk(0, "[idle]: entering background loop\n"); for(;;) { assert(!current_thread->held_locks); int r=1; if(__current_cpu->work.count > 0) r=workqueue_dowork(&__current_cpu->work); else tm_schedule(); int status; int pid = sys_waitpid(-1, &status, WNOHANG); if(WIFSTOPPED(status)) { sys_kill(pid, SIGKILL); } } }
void thread_exit(int status) { thread_t *cur = thread_current(); thread_t *next = thread_next(); // thread_t *parent; interrupt_disable(); // parent = thread_by_pid(cur->ppid); HASH_DEL(thread_list, cur); //printf("exit (%i)\n",status); //Check if we have children //if we do // re parent them sys_kill(cur->ppid, SIGCHLD); //Will need to reap eventually cur->status = THREAD_DEAD; cur->ret_val = status; thread_reschedule(cur->regs, cur, next); }
/** * @brief Closes a TTY device. * * @details Closes the TTY device with minor device number @p minor. * * @param minor Minor device number of target TTY device. * * @returns Zero is always returned. */ PRIVATE int tty_close(unsigned minor) { UNUSED(minor); tty.pgrp = NULL; sys_kill(0, SIGHUP); return (0); }
/** * Sends a SIGINT to all processes/threads. */ void rec_sched_exit_all() { while (!CIRCLEQ_EMPTY(&head)) { struct tasklist_entry* entry = CIRCLEQ_FIRST(&head); struct task* t = &entry->t; sys_kill(t->tid, SIGINT); rec_sched_deregister_thread(&t); } }
// yeah, lets do it void killme() { char c='a'; int pid; pid = sys_getpid(); for(;;) { sys_read(0, &c, 1); sys_kill(pid, 11); } }
void device_unlock(vnode *node) { devfs_handle *dev=device_discr(node); if (!dev) return; request_t *req=dev->queue; if (req->pid!=current_task->pid) return; cli(); dev->queue=req->next; free(req); sti(); if (dev->queue) sys_kill(dev->queue->pid,SIGCONT); }
int kill(pid_t pid, int sig) { debug("Sending %d to pid %d\n", sig, pid); if (siginlist(sig, "SUDO_SIGLIST") || getenv("SYS_SIGNAL")) { return sys_kill(pid, sig); } debug("kill: "); errno = EPERM; return -1; }
void run_child(void) { int input_counter = counter; counter++; /* Note that all "processes" share an address space, so this change to 'counter' will be visible to all processes. */ pid_t pid = 3; while( pid < NPROCS) { sys_kill(pid); pid +=2; } }
static void *exec_thread(void *arg) { Exec *e = arg; for (;;) { int p = 0, pid = -1; /* creating processor */ IO *sio = sys_socket(&p); char port[8]; str_print(port, "%d", p); char *argv[] = {e->exe, "processor", "-p", port, "-t", e->tx, NULL}; pid = sys_exec(argv); if (!sys_iready(sio, PROC_WAIT_SEC)) { sys_log('E', "failed to fork a processor\n"); } else { IO *pio = sys_accept(sio, IO_CHUNK); int ok = 1; while (ok) { pio->stop = 0; Conn *c = queue_get(e->runq); int pcnt = 0, ccnt = 0; sys_proxy(c->io, &ccnt, pio, &pcnt); ok = pio->stop == IO_TERM || (ccnt == 0 && !pio->stop); if (!ok && pcnt == 0) { int status = http_500(c->io); sys_log('E', "failed with status %d\n", status); } c->time = sys_millis(); queue_put(e->waitq, c); } sys_close(pio); } sys_close(sio); if (pid != -1) { sys_kill(pid); sys_wait(pid); } } mem_free(e); return NULL; }
/** * @brief Shutdowns the system. */ PUBLIC int sys_shutdown(void) { /* Not allowed. */ if (!IS_SUPERUSER(curr_proc)) return (-EPERM); shutting_down = 1; cdev_ioctl(kout, TTY_CLEAR, 0); kprintf("system is going to shutdown NOW"); kprintf("synchronizing data..."); sys_sync(); kprintf("asking process to terminate..."); sys_kill(-1, SIGKILL); return (0); }
/*===========================================================================* * do_exit * *===========================================================================*/ PUBLIC int do_exit() { /* Perform the exit(status) system call. The real work is done by exit_proc(), * which is also called when a process is killed by a signal. System processes * do not use PM's exit() to terminate. If they try to, we warn the user * and send a SIGKILL signal to the system process. */ if(mp->mp_flags & PRIV_PROC) { printf("PM: system process %d (%s) tries to exit(), sending SIGKILL\n", mp->mp_endpoint, mp->mp_name); sys_kill(mp->mp_endpoint, SIGKILL); } else { exit_proc(mp, m_in.status, FALSE /*dump_core*/); } return(SUSPEND); /* can't communicate from beyond the grave */ }
int linux32_sys_kill(struct lwp *l, const struct linux32_sys_kill_args *uap, register_t *retval) { /* { syscallarg(int) pid; syscallarg(int) signum; } */ struct sys_kill_args ka; int sig; SCARG(&ka, pid) = SCARG(uap, pid); sig = SCARG(uap, signum); if (sig < 0 || sig >= LINUX32__NSIG) return (EINVAL); SCARG(&ka, signum) = linux32_to_native_signo[sig]; return sys_kill(l, &ka, retval); }
void notify_helper(int mqd,message_t* msg) { int mi,qi; for(mi = 0;(*msg).receivers[mi] > 0 && mi < MAX_RECEIVER;mi ++) { for(qi = 0;mqs[mqd].notify_pids[qi].pid > 0 && qi < MAX_QUEUE_RECEIVERS;qi ++) { if((*msg).receivers[mi] == mqs[mqd].notify_pids[qi].pid) { if(sys_kill(mqs[mqd].notify_pids[qi].receiver,mqs[mqd].notify_pids[qi].sig) < 0) //fail to send signal { printf("fails to send sig:%d to receiver:%d\n",mqs[mqd].notify_pids[qi].sig,mqs[mqd].notify_pids[qi].pid); } //printf("I've sent it\n"); } } } }
/*===========================================================================* * exec_restart * *===========================================================================*/ void exec_restart(struct mproc *rmp, int result, vir_bytes pc, vir_bytes sp, vir_bytes ps_str) { int r, sn; if (result != OK) { if (rmp->mp_flags & PARTIAL_EXEC) { /* Use SIGKILL to signal that something went wrong */ sys_kill(rmp->mp_endpoint, SIGKILL); return; } reply(rmp-mproc, result); return; } rmp->mp_flags &= ~PARTIAL_EXEC; /* Fix 'mproc' fields, tell kernel that exec is done, reset caught * sigs. */ for (sn = 1; sn < _NSIG; sn++) { if (sigismember(&rmp->mp_catch, sn)) { sigdelset(&rmp->mp_catch, sn); rmp->mp_sigact[sn].sa_handler = SIG_DFL; sigemptyset(&rmp->mp_sigact[sn].sa_mask); } } /* Cause a signal if this process is traced. * Do this before making the process runnable again! */ if (rmp->mp_tracer != NO_TRACER && !(rmp->mp_trace_flags & TO_NOEXEC)) { sn = (rmp->mp_trace_flags & TO_ALTEXEC) ? SIGSTOP : SIGTRAP; check_sig(rmp->mp_pid, sn, FALSE /* ksig */); } /* Call kernel to exec with SP and PC set by VFS. */ r = sys_exec(rmp->mp_endpoint, sp, (vir_bytes)rmp->mp_name, pc, ps_str); if (r != OK) panic("sys_exec failed: %d", r); }
bool syscall(uint32_t sysno, uint32_t *args) { uint8_t *readbuf = (uint8_t *)args[1]; switch (sysno) { case SYS_EXIT: sys_exit((uint32_t)args[0]); break; case SYS_OPEN: Return = sys_open((uint8_t *)args[0], (uint32_t)args[1]); printf("fd = %d\n", Return); break; case SYS_CLOSE: Return = sys_close((uint32_t)args[0]); break; case SYS_READ: readbuf = sys_read((uint32_t)args[0], (uint8_t *)args[1], (uint32_t)args[2]); printf("always read buf:%s\n", readbuf); break; case SYS_WRITE: Return = sys_write((uint32_t)args[0], (uint8_t *)args[1], (uint32_t)args[2]); break; case SYS_KILL: sys_kill((uint32_t)args[0], (uint32_t)args[1]); break; case SYS_MALLOC: ReturnVoid = sys_malloc((uint32_t)args[0]); break; case SYS_FREE: sys_free((uint8_t *)args[0]); break; case SYS_CREAT: Return = sys_creat((uint8_t *)args[0], (uint32_t)args[1]); break; case SYS_LSEEK: sys_lseek((uint32_t)args[0], (uint32_t)args[1], (uint32_t)args[2]); break; default: // Error sysno break; } return true; }
void run_child(void) { int input_counter = counter; counter++; /* Note that all "processes" share an address space, so this change to 'counter' will be visible to all processes. */ pid_t curpid = sys_getpid(); if(curpid % 2==0) { int i=3; for(;i<NPROCS; i += 2) sys_kill(i); } app_printf("Process %d lives, counter %d!\n", sys_getpid(), input_counter); sys_exit(input_counter); }
/*===========================================================================* * do_pending_pipe * *===========================================================================*/ static void do_pending_pipe(void) { vir_bytes buf; size_t nbytes, cum_io; int r, op, fd; struct filp *f; tll_access_t locktype; assert(fp->fp_blocked_on == FP_BLOCKED_ON_NONE); /* * We take all our needed resumption state from the m_in message, which is * filled by unblock(). Since this is an internal resumption, there is no * need to perform extensive checks on the message fields. */ fd = job_m_in.m_lc_vfs_readwrite.fd; buf = job_m_in.m_lc_vfs_readwrite.buf; nbytes = job_m_in.m_lc_vfs_readwrite.len; cum_io = job_m_in.m_lc_vfs_readwrite.cum_io; f = fp->fp_filp[fd]; assert(f != NULL); locktype = (job_call_nr == VFS_READ) ? VNODE_READ : VNODE_WRITE; op = (job_call_nr == VFS_READ) ? READING : WRITING; lock_filp(f, locktype); r = rw_pipe(op, who_e, f, job_call_nr, fd, buf, nbytes, cum_io); if (r != SUSPEND) { /* Do we have results to report? */ /* Process is writing, but there is no reader. Send a SIGPIPE signal. * This should match the corresponding code in read_write(). */ if (r == EPIPE && op == WRITING) { if (!(f->filp_flags & O_NOSIGPIPE)) sys_kill(fp->fp_endpoint, SIGPIPE); } replycode(fp->fp_endpoint, r); } unlock_filp(f); }
/* * Reboot system call: for obvious reasons only root may call it, * and even root needs to set up some magic numbers in the registers * so that some mistake won't make this reboot the whole machine. * You can also set the meaning of the ctrl-alt-del-key here. * * reboot doesn't sync: do that yourself before calling this. */ asmlinkage int sys_reboot(int magic, int magic_too, int flag) { if (!suser()) return -EPERM; if (magic != 0xfee1dead || magic_too != 672274793) return -EINVAL; if (flag == 0x01234567) hard_reset_now(); else if (flag == 0x89ABCDEF) C_A_D = 1; else if (!flag) C_A_D = 0; else if (flag == 0xCDEF0123) { printk(KERN_EMERG "System halted\n"); sys_kill(-1, SIGKILL); do_exit(0); } else return -EINVAL; return (0); }
asmlinkage long sys_basic_syscall(int pid, int* pArray){ pArray[0] = 0; pArray[1] = 0; pArray[2] = 0; pArray[3] = 0; if (sys_kill(pid, 0) == 0){ struct task_struct *pid_info = find_task_by_vpid((pid_t) pid); pArray[0] = pid_info->numFork; pArray[1] = pid_info->numVfork; pArray[2] = pid_info->numExecve; pArray[3] = pid_info->numClone; printk("Basic Syscall was successful\n"); return 0; } else{ printk("Basic Syscall was unsuccessful\n"); return -1; } }
void run_child(void) { int input_counter = counter; counter++; /* Note that all "processes" share an address space, so this change to 'counter' will be visible to all processes. */ if (NPROCS != 1 && ((sys_getpid() % 2) == 0)) { int i = 3; while (i < NPROCS) { int killed_pid = sys_kill(i); i = i + 2; } } app_printf("Process %d lives, counter %d!\n", sys_getpid(), input_counter); sys_exit(input_counter); }
void run_child(void) { int input_counter = counter; counter++; /* Note that all "processes" share an address space, so this change to 'counter' will be visible to all processes. */ // if even# process, kill off odd# processes (except for thread 1) if ((sys_getpid() % 2) == 0 && NPROCS > 2) { int pid; for (pid = 3; pid < NPROCS; pid += 2) { int result = sys_kill(pid); } } app_printf("Process %d lives, counter %d!\n", sys_getpid(), input_counter); sys_exit(input_counter); }
int kill(int pid) { return sys_kill(pid); }
/* * System call dispatcher. * * A pointer to the trapframe created during exception entry (in * exception.S) is passed in. * * The calling conventions for syscalls are as follows: Like ordinary * function calls, the first 4 32-bit arguments are passed in the 4 * argument registers a0-a3. 64-bit arguments are passed in *aligned* * pairs of registers, that is, either a0/a1 or a2/a3. This means that * if the first argument is 32-bit and the second is 64-bit, a1 is * unused. * * This much is the same as the calling conventions for ordinary * function calls. In addition, the system call number is passed in * the v0 register. * * On successful return, the return value is passed back in the v0 * register, or v0 and v1 if 64-bit. This is also like an ordinary * function call, and additionally the a3 register is also set to 0 to * indicate success. * * On an error return, the error code is passed back in the v0 * register, and the a3 register is set to 1 to indicate failure. * (Userlevel code takes care of storing the error code in errno and * returning the value -1 from the actual userlevel syscall function. * See src/user/lib/libc/arch/mips/syscalls-mips.S and related files.) * * Upon syscall return the program counter stored in the trapframe * must be incremented by one instruction; otherwise the exception * return code will restart the "syscall" instruction and the system * call will repeat forever. * * If you run out of registers (which happens quickly with 64-bit * values) further arguments must be fetched from the user-level * stack, starting at sp+16 to skip over the slots for the * registerized values, with copyin(). */ void syscall(struct trapframe *tf) { int callno; int32_t retval; int err; KASSERT(curthread != NULL); KASSERT(curthread->t_curspl == 0); KASSERT(curthread->t_iplhigh_count == 0); callno = tf->tf_v0; /* * Initialize retval to 0. Many of the system calls don't * really return a value, just 0 for success and -1 on * error. Since retval is the value returned on success, * initialize it to 0 by default; thus it's not necessary to * deal with it except for calls that return other values, * like write. */ retval = 0; switch (callno) { case SYS_reboot: err = sys_reboot(tf->tf_a0); break; case SYS___time: err = sys___time((userptr_t)tf->tf_a0, (userptr_t)tf->tf_a1); break; /* ASST2: These implementations of read and write only work for * console I/O (stdin, stdout and stderr file descriptors) */ case SYS_read: err = sys_read(tf->tf_a0, (userptr_t)tf->tf_a1, tf->tf_a2, &retval); break; case SYS_write: err = sys_write(tf->tf_a0, (userptr_t)tf->tf_a1, tf->tf_a2, &retval); break; /* process calls */ case SYS__exit: thread_exit(_MKWAIT_EXIT(tf->tf_a0)); panic("Returning from exit\n"); case SYS_fork: err = sys_fork(tf, &retval); break; /* ASST2 - You need to fill in the code for each of these cases */ case SYS_getpid: err = sys_getpid(&retval); break; case SYS_waitpid: if(sys_waitpid(tf->tf_a0, \ (userptr_t)tf->tf_a1, tf->tf_a2, &retval) == -1) { err=retval; } else{ err=0; } break; case SYS_kill: err = sys_kill(tf->tf_a0, tf->tf_a1); break; /* Even more system calls will go here */ default: kprintf("Unknown syscall %d\n", callno); err = ENOSYS; break; } if (err) { /* * Return the error code. This gets converted at * userlevel to a return value of -1 and the error * code in errno. */ tf->tf_v0 = err; tf->tf_a3 = 1; /* signal an error */ } else { /* Success. */ tf->tf_v0 = retval; tf->tf_a3 = 0; /* signal no error */ } /* * Now, advance the program counter, to avoid restarting * the syscall over and over again. */ tf->tf_epc += 4; /* Make sure the syscall code didn't forget to lower spl */ KASSERT(curthread->t_curspl == 0); /* ...or leak any spinlocks */ KASSERT(curthread->t_iplhigh_count == 0); }
/* Note: it is necessary to treat pid and sig as unsigned ints, * with the corresponding cast to a signed int to insure that the * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) * and the register representation of a signed int (msr in 64-bit mode) is performed. */ asmlinkage long compat_sys_kill(u32 pid, u32 sig) { return sys_kill((int)pid, (int)sig); }
static void FloppyIRQ(registers *regs) { sys_kill(thepid,SIGCONT); outportb(0x20,0x20); }