From: David van Moolenbroek Date: Tue, 22 Nov 2011 01:07:33 +0000 (+0100) Subject: Introduce sys_getregs call, and let vfs use it X-Git-Tag: v3.2.0~232 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/invmod.png?a=commitdiff_plain;h=1e1db539862f0013e4fb374dc844e76e775b4a1f;p=minix.git Introduce sys_getregs call, and let vfs use it --- diff --git a/common/include/minix/com.h b/common/include/minix/com.h index 01a9094da..dad34cf16 100644 --- a/common/include/minix/com.h +++ b/common/include/minix/com.h @@ -461,6 +461,7 @@ # define GET_AOUTHEADER 22 /* get a.out headers from the boot image */ #endif # define GET_CPUINFO 23 /* get information about cpus */ +# define GET_REGS 24 /* get general process registers */ #define I_ENDPT m7_i4 /* calling process (may only be SELF) */ #define I_VAL_PTR m7_p1 /* virtual address at caller */ #define I_VAL_LEN m7_i1 /* max length of value */ diff --git a/common/include/minix/syslib.h b/common/include/minix/syslib.h index c899a51ac..22483fe3f 100644 --- a/common/include/minix/syslib.h +++ b/common/include/minix/syslib.h @@ -199,6 +199,7 @@ _PROTOTYPE(int sys_umap_remote, (endpoint_t proc_ep, endpoint_t grantee, #if !defined(__ELF__) #define sys_getaoutheader(dst,nr) sys_getinfo(GET_AOUTHEADER, dst, 0,0,nr) #endif +#define sys_getregs(dst,nr) sys_getinfo(GET_REGS, dst, 0,0, nr) _PROTOTYPE(int sys_getinfo, (int request, void *val_ptr, int val_len, void *val_ptr2, int val_len2) ); _PROTOTYPE(int sys_whoami, (endpoint_t *ep, char *name, int namelen, diff --git a/kernel/system/do_getinfo.c b/kernel/system/do_getinfo.c index 08887303b..98c0748c7 100644 --- a/kernel/system/do_getinfo.c +++ b/kernel/system/do_getinfo.c @@ -44,6 +44,7 @@ PUBLIC int do_getinfo(struct proc * caller, message * m_ptr) vir_bytes src_vir; int nr_e, nr, r; int wipe_rnd_bin = -1; + struct proc *p; #if !defined(__ELF__) struct exec e_hdr; #endif @@ -112,6 +113,15 @@ PUBLIC int do_getinfo(struct proc * caller, message * m_ptr) src_vir = (vir_bytes) priv_addr(nr_to_id(nr)); break; } + case GET_REGS: { + nr_e = (m_ptr->I_VAL_LEN2_E == SELF) ? + caller->p_endpoint : m_ptr->I_VAL_LEN2_E; + if(!isokendpt(nr_e, &nr)) return EINVAL; /* validate request */ + p = proc_addr(nr); + length = sizeof(p->p_reg); + src_vir = (vir_bytes) &p->p_reg; + break; + } case GET_WHOAMI: { int len; /* GET_WHOAMI uses m3 and only uses the message contents for info. */ diff --git a/servers/vfs/elf_core_dump.c b/servers/vfs/elf_core_dump.c index 8f3489f7f..570ba43aa 100644 --- a/servers/vfs/elf_core_dump.c +++ b/servers/vfs/elf_core_dump.c @@ -7,12 +7,6 @@ #include #include "param.h" -#include -#include "../../kernel/const.h" -#include "../../kernel/config.h" -#include "../../kernel/type.h" -#include "../../kernel/proc.h" - /* Include ELF headers */ #include #include @@ -29,6 +23,8 @@ FORWARD _PROTOTYPE( void adjust_offsets, (Elf32_Phdr phdrs[], int phnum) ); FORWARD _PROTOTYPE( void dump_elf_header, (Elf32_Ehdr elf_header) ); FORWARD _PROTOTYPE( void dump_notes, (Elf32_Nhdr nhdrs[], int csig, char *exe_name) ); +FORWARD _PROTOTYPE( void dump_program_headers, (Elf_Phdr phdrs[], + int phnum) ); FORWARD _PROTOTYPE( void dump_segments, (Elf32_Phdr phdrs[], int phnum) ); /*===========================================================================* @@ -236,13 +232,13 @@ PRIVATE void dump_notes(Elf_Nhdr nhdrs[], int csig, char *exe_name) minix_elfcore_info_t mei; int mei_len = sizeof(minix_elfcore_info_t); int gregs_len = sizeof(gregset_t); - struct proc p; + struct stackframe_s regs; char proc_name[PROC_NAME_LEN]; /* Get process's name */ if (sys_datacopy(PM_PROC_NR, (vir_bytes) exe_name, VFS_PROC_NR, (vir_bytes) proc_name, PROC_NAME_LEN) != OK) - printf("VFS: Cannot get porcess's name\n"); + printf("VFS: Cannot get process's name\n"); /* Dump first note entry */ mei.mei_version = MINIX_ELFCORE_VERSION; @@ -257,16 +253,18 @@ PRIVATE void dump_notes(Elf_Nhdr nhdrs[], int csig, char *exe_name) write_buf((char *)&mei, mei_len); write_buf(pad, PAD_LEN(mei_len) - mei_len); - /* XXX: Other way to read registries ? */ /* Get registers */ - if (sys_getproc(&p, fp->fp_endpoint) != OK) + if (sys_getregs(®s, fp->fp_endpoint) != OK) printf("VFS: Could not read registers\n"); + if (sizeof(regs) != gregs_len) + printf("VFS: Wrong core register structure size\n"); + /* Dump second note entry - the general registers */ write_buf((char *)&nhdrs[1], sizeof(Elf_Nhdr)); write_buf(note_name, nhdrs[1].n_namesz); write_buf(pad, PAD_LEN(nhdrs[1].n_namesz) - nhdrs[1].n_namesz); - write_buf((char *)&(p.p_reg), gregs_len); + write_buf((char *)®s, gregs_len); write_buf(pad, PAD_LEN(gregs_len) - gregs_len); }