Introduce sys_getregs call, and let vfs use it

This commit is contained in:
David van Moolenbroek 2011-11-22 02:07:33 +01:00
parent c30f014a89
commit 1e1db53986
4 changed files with 21 additions and 11 deletions

View file

@ -461,6 +461,7 @@
# define GET_AOUTHEADER 22 /* get a.out headers from the boot image */ # define GET_AOUTHEADER 22 /* get a.out headers from the boot image */
#endif #endif
# define GET_CPUINFO 23 /* get information about cpus */ # 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_ENDPT m7_i4 /* calling process (may only be SELF) */
#define I_VAL_PTR m7_p1 /* virtual address at caller */ #define I_VAL_PTR m7_p1 /* virtual address at caller */
#define I_VAL_LEN m7_i1 /* max length of value */ #define I_VAL_LEN m7_i1 /* max length of value */

View file

@ -199,6 +199,7 @@ _PROTOTYPE(int sys_umap_remote, (endpoint_t proc_ep, endpoint_t grantee,
#if !defined(__ELF__) #if !defined(__ELF__)
#define sys_getaoutheader(dst,nr) sys_getinfo(GET_AOUTHEADER, dst, 0,0,nr) #define sys_getaoutheader(dst,nr) sys_getinfo(GET_AOUTHEADER, dst, 0,0,nr)
#endif #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, _PROTOTYPE(int sys_getinfo, (int request, void *val_ptr, int val_len,
void *val_ptr2, int val_len2) ); void *val_ptr2, int val_len2) );
_PROTOTYPE(int sys_whoami, (endpoint_t *ep, char *name, int namelen, _PROTOTYPE(int sys_whoami, (endpoint_t *ep, char *name, int namelen,

View file

@ -44,6 +44,7 @@ PUBLIC int do_getinfo(struct proc * caller, message * m_ptr)
vir_bytes src_vir; vir_bytes src_vir;
int nr_e, nr, r; int nr_e, nr, r;
int wipe_rnd_bin = -1; int wipe_rnd_bin = -1;
struct proc *p;
#if !defined(__ELF__) #if !defined(__ELF__)
struct exec e_hdr; struct exec e_hdr;
#endif #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)); src_vir = (vir_bytes) priv_addr(nr_to_id(nr));
break; 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: { case GET_WHOAMI: {
int len; int len;
/* GET_WHOAMI uses m3 and only uses the message contents for info. */ /* GET_WHOAMI uses m3 and only uses the message contents for info. */

View file

@ -7,12 +7,6 @@
#include <machine/elf.h> #include <machine/elf.h>
#include "param.h" #include "param.h"
#include <machine/archtypes.h>
#include "../../kernel/const.h"
#include "../../kernel/config.h"
#include "../../kernel/type.h"
#include "../../kernel/proc.h"
/* Include ELF headers */ /* Include ELF headers */
#include <sys/elf_core.h> #include <sys/elf_core.h>
#include <sys/procfs.h> #include <sys/procfs.h>
@ -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_elf_header, (Elf32_Ehdr elf_header) );
FORWARD _PROTOTYPE( void dump_notes, (Elf32_Nhdr nhdrs[], int csig, FORWARD _PROTOTYPE( void dump_notes, (Elf32_Nhdr nhdrs[], int csig,
char *exe_name) ); char *exe_name) );
FORWARD _PROTOTYPE( void dump_program_headers, (Elf_Phdr phdrs[],
int phnum) );
FORWARD _PROTOTYPE( void dump_segments, (Elf32_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; minix_elfcore_info_t mei;
int mei_len = sizeof(minix_elfcore_info_t); int mei_len = sizeof(minix_elfcore_info_t);
int gregs_len = sizeof(gregset_t); int gregs_len = sizeof(gregset_t);
struct proc p; struct stackframe_s regs;
char proc_name[PROC_NAME_LEN]; char proc_name[PROC_NAME_LEN];
/* Get process's name */ /* Get process's name */
if (sys_datacopy(PM_PROC_NR, (vir_bytes) exe_name, if (sys_datacopy(PM_PROC_NR, (vir_bytes) exe_name,
VFS_PROC_NR, (vir_bytes) proc_name, PROC_NAME_LEN) != OK) 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 */ /* Dump first note entry */
mei.mei_version = MINIX_ELFCORE_VERSION; 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((char *)&mei, mei_len);
write_buf(pad, PAD_LEN(mei_len) - mei_len); write_buf(pad, PAD_LEN(mei_len) - mei_len);
/* XXX: Other way to read registries ? */
/* Get registers */ /* Get registers */
if (sys_getproc(&p, fp->fp_endpoint) != OK) if (sys_getregs(&regs, fp->fp_endpoint) != OK)
printf("VFS: Could not read registers\n"); 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 */ /* Dump second note entry - the general registers */
write_buf((char *)&nhdrs[1], sizeof(Elf_Nhdr)); write_buf((char *)&nhdrs[1], sizeof(Elf_Nhdr));
write_buf(note_name, nhdrs[1].n_namesz); write_buf(note_name, nhdrs[1].n_namesz);
write_buf(pad, PAD_LEN(nhdrs[1].n_namesz) - 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 *)&regs, gregs_len);
write_buf(pad, PAD_LEN(gregs_len) - gregs_len); write_buf(pad, PAD_LEN(gregs_len) - gregs_len);
} }