diff --git a/so3/arch/arm32/Makefile b/so3/arch/arm32/Makefile index 37b6356f6..a8d2bdbfe 100644 --- a/so3/arch/arm32/Makefile +++ b/so3/arch/arm32/Makefile @@ -2,7 +2,7 @@ obj-y += head.o obj-y += setup.o exception.o context.o fault.o obj-y += cache_v7_asm.o cache_v7.o cache-cp15.o -obj-y += thread.o ptrace.o +obj-y += thread.o obj-y += vfp.o obj-y += backtrace.o backtrace_asm.o obj-y += smccc-call.o diff --git a/so3/arch/arm32/context.S b/so3/arch/arm32/context.S index 0234098bd..d49488436 100644 --- a/so3/arch/arm32/context.S +++ b/so3/arch/arm32/context.S @@ -47,7 +47,6 @@ #ifdef CONFIG_MMU -.extern __check_ptrace_traceme .extern pre_launch_proc #endif diff --git a/so3/arch/arm32/exception.S b/so3/arch/arm32/exception.S index 0c44feced..37feef58a 100644 --- a/so3/arch/arm32/exception.S +++ b/so3/arch/arm32/exception.S @@ -47,7 +47,6 @@ .extern __data_abort .extern __undefined_instruction -.extern __check_ptrace_syscall .extern sig_check .extern __stack_alignment_fault @@ -221,13 +220,6 @@ __after_push_sp_usr: @ Restore r0-r2 ldmia sp, {r0-r2} -#ifdef CONFIG_MMU - @ Give a chance to a ptrace tracer to monitor us (before the syscall) - stmfd sp!, {r0-r4} - bl __check_ptrace_syscall - ldmfd sp!, {r0-r4} -#endif - mov r0, sp cpsie i @ Re-enable interrupts @@ -243,14 +235,6 @@ __after_push_sp_usr: add sp, sp, #SVC_STACK_FRAME_SIZE __no_sigreturn: - -#ifdef CONFIG_MMU - @ Give a chance to a ptrace tracer to monitor us (after the syscall) - stmfd sp!, {r0-r4} - bl __check_ptrace_syscall - ldmfd sp!, {r0-r4} -#endif - __ret_from_fork: @ Store the return value on the stack frame diff --git a/so3/arch/arm32/ptrace.c b/so3/arch/arm32/ptrace.c deleted file mode 100644 index b9a32d743..000000000 --- a/so3/arch/arm32/ptrace.c +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (C) 2014-2022 Daniel Rossier - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#include -#include -#include - -/* - * Can be used for debugging purposes. - * - */ -void __dump_regs(void *regs) -{ - unsigned long *cpuregs = (unsigned long *) regs; - - printk("r4: %x ", *cpuregs); - printk("r5: %x ", *(cpuregs + 1)); - printk("r6: %x ", *(cpuregs + 2)); - printk("r7: %x ", *(cpuregs + 3)); - printk("r8: %x ", *(cpuregs + 4)); - printk("r9: %x ", *(cpuregs + 5)); - printk("r10: %x ", *(cpuregs + 6)); - printk("fp: %x ", *(cpuregs + 7)); - printk("ip: %x ", *(cpuregs + 8)); - printk("sp: %x ", *(cpuregs + 9)); - printk("lr: %x ", *(cpuregs + 10)); - printk("pc: %x ", *(cpuregs + 11)); - printk("psr: %x ", *(cpuregs + 12)); - printk("\n"); -} - -/** - * Update the CPU registers of the TCB belonging - * to the current thread. - */ -void update_cpu_regs(void) -{ - register uint32_t __r0 asm("r0"); - register uint32_t __r1 asm("r1"); - register uint32_t __r2 asm("r2"); - register uint32_t __r3 asm("r3"); - register uint32_t __r4 asm("r4"); - register uint32_t __r5 asm("r5"); - register uint32_t __r6 asm("r6"); - register uint32_t __r7 asm("r7"); - register uint32_t __r8 asm("r8"); - register uint32_t __r9 asm("r9"); - register uint32_t __r10 asm("r10"); - register uint32_t __r11 asm("r11"); - register uint32_t __r12 asm("r12"); - register uint32_t __r13 asm("r13"); - register uint32_t __r14 asm("r14"); - - /* Keep the values permanent */ - uint32_t r0 = __r0; - uint32_t r1 = __r1; - uint32_t r2 = __r2; - uint32_t r3 = __r3; - uint32_t r4 = __r4; - uint32_t r5 = __r5; - uint32_t r6 = __r6; - uint32_t r7 = __r7; - uint32_t r8 = __r8; - uint32_t r9 = __r9; - uint32_t r10 = __r10; - uint32_t r11 = __r11; - uint32_t r12 = __r12; - uint32_t r13 = __r13; - uint32_t r14 = __r14; - - /* Finally update the tcb structure */ - tcb_t *tcb = current(); - - tcb->cpu_regs.r0 = r0; - tcb->cpu_regs.r1 = r1; - tcb->cpu_regs.r2 = r2; - tcb->cpu_regs.r3 = r3; - tcb->cpu_regs.r4 = r4; - tcb->cpu_regs.r5 = r5; - tcb->cpu_regs.r6 = r6; - tcb->cpu_regs.r7 = r7; - tcb->cpu_regs.r8 = r8; - tcb->cpu_regs.r9 = r9; - tcb->cpu_regs.r10 = r10; - tcb->cpu_regs.fp = r11; - tcb->cpu_regs.ip = r12; - tcb->cpu_regs.sp = r13; - tcb->cpu_regs.lr = r14; -} - -void retrieve_cpu_regs(struct user *uregs, pcb_t *pcb) -{ - uregs->regs.uregs[0] = pcb->main_thread->cpu_regs.r0; - uregs->regs.uregs[1] = pcb->main_thread->cpu_regs.r1; - uregs->regs.uregs[2] = pcb->main_thread->cpu_regs.r2; - uregs->regs.uregs[3] = pcb->main_thread->cpu_regs.r3; - uregs->regs.uregs[4] = pcb->main_thread->cpu_regs.r4; - uregs->regs.uregs[5] = pcb->main_thread->cpu_regs.r5; - uregs->regs.uregs[6] = pcb->main_thread->cpu_regs.r6; - uregs->regs.uregs[7] = pcb->main_thread->cpu_regs.r7; - uregs->regs.uregs[8] = pcb->main_thread->cpu_regs.r8; - uregs->regs.uregs[9] = pcb->main_thread->cpu_regs.r9; - uregs->regs.uregs[10] = pcb->main_thread->cpu_regs.r10; - uregs->regs.uregs[11] = pcb->main_thread->cpu_regs.fp; - uregs->regs.uregs[12] = pcb->main_thread->cpu_regs.ip; - uregs->regs.uregs[13] = pcb->main_thread->cpu_regs.sp; - uregs->regs.uregs[14] = pcb->main_thread->cpu_regs.lr; -} diff --git a/so3/arch/arm64/Makefile b/so3/arch/arm64/Makefile index e7159d159..ad63cc0cd 100644 --- a/so3/arch/arm64/Makefile +++ b/so3/arch/arm64/Makefile @@ -5,7 +5,7 @@ endif obj-y += head.o exception.o traps.o -obj-y += fault.o backtrace.o +obj-y += fault.o backtrace.o obj-y += backtrace.o backtrace_asm.o obj-y += cache_v8.o cache.o context.o obj-y += semihosting.o semicall.o @@ -14,7 +14,7 @@ obj-$(CONFIG_AVZ) += domain.o mmio.o obj-y += smccc-call.o -obj-y += thread.o ptrace.o +obj-y += thread.o obj-$(CONFIG_MMU) += mmu.o @@ -23,4 +23,4 @@ obj-$(CONFIG_ARM64VT) += #smmu.o obj-y += lib/ obj-y += $(TARGET)/ - + diff --git a/so3/arch/arm64/context.S b/so3/arch/arm64/context.S index 30e6d8850..05f34506c 100644 --- a/so3/arch/arm64/context.S +++ b/so3/arch/arm64/context.S @@ -43,8 +43,6 @@ .global __enable_vfp -.extern __check_ptrace_traceme - #ifdef CONFIG_AVZ // Switch from a domain to another diff --git a/so3/arch/arm64/exception.S b/so3/arch/arm64/exception.S index a1d6a0c58..b47e9f8e4 100644 --- a/so3/arch/arm64/exception.S +++ b/so3/arch/arm64/exception.S @@ -42,7 +42,6 @@ .extern current_thread .extern __sync_serror .extern do_exit -.extern __check_ptrace_syscall .extern sig_check .global __vectors @@ -610,17 +609,6 @@ ret_from_fork: str xzr, [sp, #OFFSET_X0] b __ret_from_fork - -#if 0 -#ifdef CONFIG_MMU - // Give a chance to a ptrace tracer to monitor us (after the syscall) - stmfd sp!, {r0-r4} - bl __check_ptrace_syscall - ldmfd sp!, {r0-r4} -#endif -#endif - - #if !defined(CONFIG_AVZ) && defined(CONFIG_SOO) .align 5 diff --git a/so3/arch/arm64/ptrace.c b/so3/arch/arm64/ptrace.c deleted file mode 100644 index d513b000a..000000000 --- a/so3/arch/arm64/ptrace.c +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2014-2022 Daniel Rossier - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#include -#include -#include - -/* - * Can be used for debugging purposes. - * - */ -void __dump_regs(void *regs) -{ - unsigned long *cpuregs = (unsigned long *) regs; - int i; - - printk("---------- CPU regs ----------\n"); - - for (i = 0; i <= 30; i++) - printk("x%d = %x\n", i, *(cpuregs + i)); - - printk("\n"); -} - -/** - * Update the CPU registers of the TCB belonging - * to the current thread. - */ -void update_cpu_regs(void) -{ -} - -void retrieve_cpu_regs(struct user *uregs, pcb_t *pcb) -{ -} diff --git a/so3/avz/kernel/injector.c b/so3/avz/kernel/injector.c index 7693b8135..ffd5207b6 100644 --- a/so3/avz/kernel/injector.c +++ b/so3/avz/kernel/injector.c @@ -21,7 +21,6 @@ #include #include #include -#include #include #include diff --git a/so3/include/process.h b/so3/include/process.h index ec94efe26..7c845a234 100644 --- a/so3/include/process.h +++ b/so3/include/process.h @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include @@ -81,11 +80,6 @@ typedef struct { page_t *page; } page_list_t; -typedef struct { - bool tracee; - enum __ptrace_request req_in_progress; -} ptrace_info_t; - struct pcb { int pid; char name[PROC_NAME_LEN]; @@ -150,9 +144,6 @@ struct pcb { /* Bitmap of the signals set for this process */ sigset_t sigset_map; - /* The process might be under a ptrace activity, and hence becoming a tracer (parent) or tracee (child) */ - enum __ptrace_request ptrace_pending_req; - /* Mutex lock to be used in conjunction with the user space (very temporary) */ mutex_t *lock; }; diff --git a/so3/include/ptrace.h b/so3/include/ptrace.h deleted file mode 100644 index b77dfa09d..000000000 --- a/so3/include/ptrace.h +++ /dev/null @@ -1,221 +0,0 @@ -/* - * Copyright (C) 2014-2019 Daniel Rossier - * Copyright (C) 2017-2018 Xavier Ruppen - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifndef _SYS_PTRACE_H -#define _SYS_PTRACE_H - -#include -#include - -/* Type of the REQUEST argument to `ptrace.' */ -enum __ptrace_request { - /* Indicate that the process making this request should be traced. - All signals received by this process can be intercepted by its - parent, and its parent can use the other `ptrace' requests. */ - PTRACE_TRACEME = 0, -#define PT_TRACE_ME PTRACE_TRACEME - - /* Return the word in the process's text space at address ADDR. */ - PTRACE_PEEKTEXT = 1, -#define PT_READ_I PTRACE_PEEKTEXT - - /* Return the word in the process's data space at address ADDR. */ - PTRACE_PEEKDATA = 2, -#define PT_READ_D PTRACE_PEEKDATA - - /* Return the word in the process's user area at offset ADDR. */ - PTRACE_PEEKUSER = 3, -#define PT_READ_U PTRACE_PEEKUSER - - /* Write the word DATA into the process's text space at address ADDR. */ - PTRACE_POKETEXT = 4, -#define PT_WRITE_I PTRACE_POKETEXT - - /* Write the word DATA into the process's data space at address ADDR. */ - PTRACE_POKEDATA = 5, -#define PT_WRITE_D PTRACE_POKEDATA - - /* Write the word DATA into the process's user area at offset ADDR. */ - PTRACE_POKEUSER = 6, -#define PT_WRITE_U PTRACE_POKEUSER - - /* Continue the process. */ - PTRACE_CONT = 7, -#define PT_CONTINUE PTRACE_CONT - - /* Kill the process. */ - PTRACE_KILL = 8, -#define PT_KILL PTRACE_KILL - - /* Single step the process. */ - PTRACE_SINGLESTEP = 9, -#define PT_STEP PTRACE_SINGLESTEP - - /* Get all general purpose registers used by a processes. */ - PTRACE_GETREGS = 12, -#define PT_GETREGS PTRACE_GETREGS - - /* Set all general purpose registers used by a processes. */ - PTRACE_SETREGS = 13, -#define PT_SETREGS PTRACE_SETREGS - - /* Get all floating point registers used by a processes. */ - PTRACE_GETFPREGS = 14, -#define PT_GETFPREGS PTRACE_GETFPREGS - - /* Set all floating point registers used by a processes. */ - PTRACE_SETFPREGS = 15, -#define PT_SETFPREGS PTRACE_SETFPREGS - - /* Attach to a process that is already running. */ - PTRACE_ATTACH = 16, -#define PT_ATTACH PTRACE_ATTACH - - /* Detach from a process attached to with PTRACE_ATTACH. */ - PTRACE_DETACH = 17, -#define PT_DETACH PTRACE_DETACH - - /* Get all extended floating point registers used by a processes. */ - PTRACE_GETFPXREGS = 18, -#define PT_GETFPXREGS PTRACE_GETFPXREGS - - /* Set all extended floating point registers used by a processes. */ - PTRACE_SETFPXREGS = 19, -#define PT_SETFPXREGS PTRACE_SETFPXREGS - - /* Continue and stop at the next entry to or return from syscall. */ - PTRACE_SYSCALL = 24, -#define PT_SYSCALL PTRACE_SYSCALL - - /* Get a TLS entry in the GDT. */ - PTRACE_GET_THREAD_AREA = 25, -#define PT_GET_THREAD_AREA PTRACE_GET_THREAD_AREA - - /* Change a TLS entry in the GDT. */ - PTRACE_SET_THREAD_AREA = 26, -#define PT_SET_THREAD_AREA PTRACE_SET_THREAD_AREA - - /* Continue and stop at the next syscall, it will not be executed. */ - PTRACE_SYSEMU = 31, -#define PT_SYSEMU PTRACE_SYSEMU - - /* Single step the process, the next syscall will not be executed. */ - PTRACE_SYSEMU_SINGLESTEP = 32, -#define PT_SYSEMU_SINGLESTEP PTRACE_SYSEMU_SINGLESTEP - - /* Execute process until next taken branch. */ - PTRACE_SINGLEBLOCK = 33, -#define PT_STEPBLOCK PTRACE_SINGLEBLOCK - - /* Set ptrace filter options. */ - PTRACE_SETOPTIONS = 0x4200, -#define PT_SETOPTIONS PTRACE_SETOPTIONS - - /* Get last ptrace message. */ - PTRACE_GETEVENTMSG = 0x4201, -#define PT_GETEVENTMSG PTRACE_GETEVENTMSG - - /* Get siginfo for process. */ - PTRACE_GETSIGINFO = 0x4202, -#define PT_GETSIGINFO PTRACE_GETSIGINFO - - /* Set new siginfo for process. */ - PTRACE_SETSIGINFO = 0x4203, -#define PT_SETSIGINFO PTRACE_SETSIGINFO - - /* Get register content. */ - PTRACE_GETREGSET = 0x4204, -#define PTRACE_GETREGSET PTRACE_GETREGSET - - /* Set register content. */ - PTRACE_SETREGSET = 0x4205, -#define PTRACE_SETREGSET PTRACE_SETREGSET - - /* Like PTRACE_ATTACH, but do not force tracee to trap and do not affect - signal or group stop state. */ - PTRACE_SEIZE = 0x4206, -#define PTRACE_SEIZE PTRACE_SEIZE - - /* Trap seized tracee. */ - PTRACE_INTERRUPT = 0x4207, -#define PTRACE_INTERRUPT PTRACE_INTERRUPT - - /* Wait for next group event. */ - PTRACE_LISTEN = 0x4208, -#define PTRACE_LISTEN PTRACE_LISTEN - - /* Retrieve siginfo_t structures without removing signals from a queue. */ - PTRACE_PEEKSIGINFO = 0x4209, -#define PTRACE_PEEKSIGINFO PTRACE_PEEKSIGINFO - - /* Get the mask of blocked signals. */ - PTRACE_GETSIGMASK = 0x420a, -#define PTRACE_GETSIGMASK PTRACE_GETSIGMASK - - /* Change the mask of blocked signals. */ - PTRACE_SETSIGMASK = 0x420b, -#define PTRACE_SETSIGMASK PTRACE_SETSIGMASK - - /* Get seccomp BPF filters. */ - PTRACE_SECCOMP_GET_FILTER = 0x420c, -#define PTRACE_SECCOMP_GET_FILTER PTRACE_SECCOMP_GET_FILTER - - /* Specific to SO3 to indicate that no ptrace request is pending. */ - PTRACE_NO_REQUEST = 0xffff -}; - -#define PTRACE_O_TRACESYSGOOD 0x00000001 -#define PTRACE_O_TRACEFORK 0x00000002 -#define PTRACE_O_TRACEVFORK 0x00000004 -#define PTRACE_O_TRACECLONE 0x00000008 -#define PTRACE_O_TRACEEXEC 0x00000010 -#define PTRACE_O_TRACEVFORKDONE 0x00000020 -#define PTRACE_O_TRACEEXIT 0x00000040 -#define PTRACE_O_TRACESECCOMP 0x00000080 -#define PTRACE_O_EXITKILL 0x00100000 -#define PTRACE_O_SUSPEND_SECCOMP 0x00200000 -#define PTRACE_O_MASK 0x003000ff - -#define PTRACE_EVENT_FORK 1 -#define PTRACE_EVENT_VFORK 2 -#define PTRACE_EVENT_CLONE 3 -#define PTRACE_EVENT_EXEC 4 -#define PTRACE_EVENT_VFORK_DONE 5 -#define PTRACE_EVENT_EXIT 6 -#define PTRACE_EVENT_SECCOMP 7 - -#define PTRACE_PEEKSIGINFO_SHARED 1 - -struct ptrace_peeksiginfo_args { - uint64_t off; - uint32_t flags; - int32_t nr; -}; - -SYSCALL_DECLARE(ptrace, enum __ptrace_request request, int pid, void *addr, void *data); - -struct pcb; -struct user; - -void update_cpu_regs(void); -void retrieve_cpu_regs(struct user *uregs, struct pcb *pcb); - -void __dump_regs(void *regs); - -#endif diff --git a/so3/kernel/Makefile b/so3/kernel/Makefile index 71f68a103..fee71be7c 100644 --- a/so3/kernel/Makefile +++ b/so3/kernel/Makefile @@ -12,7 +12,7 @@ obj-y += main.o \ spinlock.o \ syscalls.o \ softirq.o \ - timer.o + timer.o obj-$(CONFIG_CPU_PSCI) += psci_smp.o obj-$(CONFIG_CPU_SPIN_TABLE) += spin_table.o @@ -23,7 +23,7 @@ obj-y += bitmap.o obj-y += softirq.o obj-y += spinlock.o -obj-$(CONFIG_MMU) += process.o ptrace.o +obj-$(CONFIG_MMU) += process.o EXTRA_CFLAGS += -I$(srctree)/include/net diff --git a/so3/kernel/process.c b/so3/kernel/process.c index b1d2706d9..0caa26cf0 100644 --- a/so3/kernel/process.c +++ b/so3/kernel/process.c @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include @@ -184,9 +183,6 @@ pcb_t *new_process(void) pcb->next_anon_start = USER_ANONYMOUS_VADDR; - /* Reset the ptrace request indicator */ - pcb->ptrace_pending_req = PTRACE_NO_REQUEST; - /* The spinlock inside the mutex must aligned in aarch64 */ pcb->lock = memalign(N_MUTEX * sizeof(mutex_t), 8); @@ -1022,69 +1018,27 @@ SYSCALL_DEFINE4(wait4, int, pid, uint32_t *, wstatus, uint32_t, options, void *, if (child->state != PROC_STATE_ZOMBIE) return 0; - /* Must the child be resumed after being stopped due to a ptrace request - * ? */ - if ((child->ptrace_pending_req != PTRACE_NO_REQUEST) && (child->ptrace_pending_req != PTRACE_TRACEME)) { - /* Resume the child process being stopped previously. */ - - child->state = PROC_STATE_READY; - ready(child->main_thread); - } - if (child->state != PROC_STATE_WAITING) /* Wait on the main_thread of this process */ thread_join(child->main_thread); - /* Before joining, we need to check the state of child because it could - * have been finished before this call. */ - if ((child->state == PROC_STATE_ZOMBIE) && (child->ptrace_pending_req == PTRACE_NO_REQUEST)) { - /* Free the page tables used for this process */ - reset_root_pgtable(child->pgtable, true); - - /* Get the exit code left in the PCB by the child */ - if (wstatus) { - *wstatus = ~0x7f; /* !WTERMSIG -> WIFEXITED true */ - *wstatus = ((char) child->exit_status) << 8; - } - - /* - * SO3 approach consists in avoiding having orphan process. - * The process will be removed from the system definitively only - * if it has no children. - */ - if (!find_proc_by_parent(child)) - remove_proc(child); - - } else { - if (child->ptrace_pending_req != PTRACE_NO_REQUEST) { - /* In this case, the child has been stopped in the - * context of the ptrace syscall */ - - /* Reset the ptrace request */ - child->ptrace_pending_req = PTRACE_NO_REQUEST; - - if (wstatus) { - *wstatus = 0x17f; /* WIFSTOPPED true */ - *wstatus |= ((char) child->exit_status) << 8; - } - } else { - /* Free the page tables used for this process */ - reset_root_pgtable(child->pgtable, true); + /* Free the page tables used for this process */ + reset_root_pgtable(child->pgtable, true); - /* Get the exit code left in the PCB by the child */ - if (wstatus) { - *wstatus = ~0x7f; /* !WTERMSIG -> WIFEXITED true */ - *wstatus |= ((char) child->exit_status) << 8; - } - - /* Finally remove the process from the system - * definitively as long as there is no children from - * there */ - if (!find_proc_by_parent(child)) - remove_proc(child); - } + /* Get the exit code left in the PCB by the child */ + if (wstatus) { + *wstatus = ~0x7f; /* !WTERMSIG -> WIFEXITED true */ + *wstatus |= ((char) child->exit_status) << 8; } + /* + * SO3 approach consists in avoiding having orphan process. + * The process will be removed from the system definitively only + * if it has no children. + */ + if (!find_proc_by_parent(child)) + remove_proc(child); + local_irq_restore(flags); return pid; diff --git a/so3/kernel/ptrace.c b/so3/kernel/ptrace.c deleted file mode 100644 index 3a30ef729..000000000 --- a/so3/kernel/ptrace.c +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (C) 2014-2019 Daniel Rossier - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#include -#include -#include -#include - -/* - * Stop the execution of the process, i.e. its main_thread and all other threads - * (used by a ptrace activity for example). - */ -void ptrace_process_stop(void) -{ - /* Wake up the tracer... */ - /* It may be the case that the parent did not have time to wait for us and is still in ready */ - if (current()->pcb->parent->main_thread->state != THREAD_STATE_READY) - ready(current()->pcb->parent->main_thread); - - /* The process is in waiting state */ - /* ... and wait on the tracer */ - - current()->pcb->state = PROC_STATE_WAITING; /* No further threads of this process may be running */ - - waiting(); -} - -void __check_ptrace_traceme(void) -{ - tcb_t *tcb = current(); - - /* Check if the process is a tracee and if this thread is the main thread, - * therefore we need to be stopped until the tracer executes waitpid() - */ - - if ((tcb->pcb != NULL) && (tcb == tcb->pcb->main_thread) && (tcb->pcb->ptrace_pending_req == PTRACE_TRACEME)) - ptrace_process_stop(); -} - -void __check_ptrace_syscall(void) -{ - /* Update the CPU regs of the TCB belonging to the current thread */ - update_cpu_regs(); - - if (current()->pcb->ptrace_pending_req == PTRACE_SYSCALL) - ptrace_process_stop(); -} - -/* - * Implementation of ptrace syscall - */ -SYSCALL_DEFINE4(ptrace, enum __ptrace_request, request, int, pid, void *, addr, void *, data) -{ - pcb_t *pcb; - - switch (request) { - case PTRACE_TRACEME: - /* pid not used here */ - current()->pcb->ptrace_pending_req = request; - break; - - case PTRACE_SYSCALL: - pcb = find_proc_by_pid(pid); - - /* To set a ptrace request within a child, it must be first waiting, being stopped some where - * by a previous ptrace request (the initial is typically PTRACE_TRACEME). - * Otherwise, the request is ignored. - */ - if (!pcb) { - return -ESRCH; - } - - if (pcb->state == PROC_STATE_WAITING) - pcb->ptrace_pending_req = request; - break; - - case PTRACE_GETREGS: - if (!data) { - return -EFAULT; - } - - pcb = find_proc_by_pid(pid); - - if (!pcb) { - return -ESRCH; - } - - retrieve_cpu_regs((struct user *) data, pcb); - break; - - default: - printk("%s: request %d not yet implemented\n.", __func__, request); - } - - return 0; -} diff --git a/so3/kernel/thread.c b/so3/kernel/thread.c index 86efae402..07f84fbc3 100644 --- a/so3/kernel/thread.c +++ b/so3/kernel/thread.c @@ -544,34 +544,28 @@ int thread_join(tcb_t *tcb) } } - /* Check if the child is a tracee (and therefore we have a tracer on it) */ - if ((tcb != NULL) && (tcb->pcb->ptrace_pending_req != PTRACE_NO_REQUEST)) { - exit_status = 0; + /* The joined thread *must* be in zombie */ + ASSERT(tcb->state == THREAD_STATE_ZOMBIE); - } else { - /* The joined thread *must* be in zombie */ - ASSERT(tcb->state == THREAD_STATE_ZOMBIE); - - if (is_main_thread) - exit_status = tcb->pcb->exit_status; - else - exit_status = tcb->exit_status; + if (is_main_thread) + exit_status = tcb->pcb->exit_status; + else + exit_status = tcb->exit_status; - /* - * Now, if we are the last which is woken up, we can proceed with the tcb removal. - * If the join is done on a main_thread, it means the waiting parent is doing the join, and - * we can then clean the tcb (remember that the main_thread does not appear in the list - * of threads of the PCB; only created threads are in it. - */ + /* + * Now, if we are the last which is woken up, we can proceed with the tcb removal. + * If the join is done on a main_thread, it means the waiting parent is doing the join, and + * we can then clean the tcb (remember that the main_thread does not appear in the list + * of threads of the PCB; only created threads are in it. + */ - if (list_empty(&tcb->joinQueue)) { - if (is_main_thread) { - clean_thread(tcb); - tcb->pcb->main_thread = NULL; - } else - /* Remove the tcb from the list of threads owned by this process */ - remove_tcb_from_pcb(tcb); - } + if (list_empty(&tcb->joinQueue)) { + if (is_main_thread) { + clean_thread(tcb); + tcb->pcb->main_thread = NULL; + } else + /* Remove the tcb from the list of threads owned by this process */ + remove_tcb_from_pcb(tcb); } local_irq_restore(flags); diff --git a/so3/syscall.tbl b/so3/syscall.tbl index 97c9611bd..996b9ab1c 100644 --- a/so3/syscall.tbl +++ b/so3/syscall.tbl @@ -51,7 +51,6 @@ clone MMU exit MMU exit_group MMU wait4 MMU -ptrace MMU gettimeofday MMU gettimeofday_time32 MMU clock_gettime MMU