From 7b998c4ad2db4ccf6163b33eea5956c8fa6c5745 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Wed, 16 Jan 2019 14:59:17 +0000 Subject: [PATCH] syscall_exec32: 32bit pieces for core dump (incomplete) Just to get us up and running --- Kernel/syscall_exec32.c | 67 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/Kernel/syscall_exec32.c b/Kernel/syscall_exec32.c index c6f99ae4..4de23282 100644 --- a/Kernel/syscall_exec32.c +++ b/Kernel/syscall_exec32.c @@ -376,3 +376,70 @@ char **wargs(char *ptr, struct s_argblk *argbuf, int *cnt) // ptr is in userspac return ((char **) argbase); } + + +/* TODO */ + +#ifdef CONFIG_LEVEL_2 + +/* + * Core dump + */ + +static struct coredump corehdr = { + 0xDEAD, + 0xC0DE, + 16, +}; + +uint8_t write_core_image(void) +{ + inoptr parent = NULLINODE; + inoptr ino; + + udata.u_error = 0; + + /* FIXME: need to think more about the case sp is lala */ + if (uput("core", (uint8_t *)udata.u_syscall_sp - 5, 5)) + return 0; + + ino = n_open((char *)udata.u_syscall_sp - 5, &parent); + if (ino) { + i_deref(parent); + return 0; + } + if (parent) { + i_lock(parent); + if ((ino = newfile(parent, "core")) != NULL) { + ino->c_node.i_mode = F_REG | 0400; + setftime(ino, A_TIME | M_TIME | C_TIME); + wr_inode(ino); + f_trunc(ino); + + /* FIXME: need to add some arch specific header bits, and + also pull stuff like the true sp and registers out of + the return stack properly */ + + corehdr.ch_base = MAPBASE; + corehdr.ch_break = udata.u_break; + corehdr.ch_sp = udata.u_syscall_sp; + corehdr.ch_top = PROGTOP; + udata.u_offset = 0; + udata.u_base = (uint8_t *)&corehdr; + udata.u_sysio = true; + udata.u_count = sizeof(corehdr); + writei(ino, 0); + udata.u_sysio = false; + udata.u_base = MAPBASE; + udata.u_count = udata.u_break - MAPBASE; + writei(ino, 0); + udata.u_base = udata.u_sp; + udata.u_count = PROGTOP - (uint16_t)udata.u_sp; + writei(ino, 0); + i_unlock_deref(ino); + return W_COREDUMP; + } + } + return 0; +} +#endif -- 2.34.1