[XenAccess-devel] [PATCH] Configurable offsets
Status: Beta
Brought to you by:
bdpayne
From: <hi...@cc...> - 2007-08-21 18:25:55
|
This patch adds configurable offsets to xenaccess. See the previous message for a longer description. Signed-off-by: Hajime Inoue <hi...@cc...> Index: xa_private.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- xa_private.h=09(revision 65) +++ xa_private.h=09(working copy) @@ -46,22 +46,27 @@ /* offset to each of these fields from the beginning of the struct assuming that CONFIG_SCHEDSTATS is not defined and CONFIG_KEYS - is defined in the guest's kernel (this is the default in xen) */ -#define XALINUX_TASKS_OFFSET 24 * 4 /* task_struct->tasks */ -#define XALINUX_MM_OFFSET 30 * 4 /* task_struct->mm */ -#define XALINUX_PID_OFFSET 39 * 4 /* task_struct->pid */ -#define XALINUX_NAME_OFFSET 108 * 4 /* task_struct->comm */ -#define XALINUX_PGD_OFFSET 9 * 4 /* mm_struct->pgd */ -#define XALINUX_ADDR_OFFSET 32 * 4 /* mm_struct->start_code */ + is defined in the guest's kernel (this is the default in xen) + + These are defined in the OS specific memory files */ + +extern int xalinux_tasks_offset; /* task_struct->tasks */ +extern int xalinux_mm_offset; /* task_struct->mm */ +extern int xalinux_pid_offset; /* task_struct->pid */ +extern int xalinux_name_offset; /* task_struct->name */ +extern int xalinux_pgd_offset; /* mm_struct->pgd */ +extern int xalinux_addr_offset; /* mm_struct->start_code */ + /* offsets for Windows fields */ -#define XAWIN_TASKS_OFFSET 0x88 /* EPROCESS->ActiveProcessLinks */ -#define XAWIN_PDBASE_OFFSET 0x18 /* EPROCESS->Pcb->DirectoryTableBase = */ -#define XAWIN_PID_OFFSET 0x84 /* EPROCESS->UniqueProcessId */ -#define XAWIN_PEB_OFFSET 0x1b0 /* EPROCESS->Peb */ -#define XAWIN_IBA_OFFSET 0x8 /* EPROCESS->Peb->ImageBaseAddress */ -#define XAWIN_PH_OFFSET 0x18 /* EPROCESS->Peb->ProcessHeap */ +extern int xawin_tasks_offset; /* EPROCESS->ActiveProcessLinks */ +extern int xawin_pdbase_offset; /* EPROCESS->Pcb->DirectoryTableBase */ +extern int xawin_pid_offset; /* EPROCESS->UniqueProcessId */ +extern int xawin_peb_offset; /* EPROCESS->Peb */ +extern int xawin_iba_offset; /* EPROCESS->Peb->ImageBaseAddress */ +extern int xawin_ph_offset; /* EPROCESS->Peb->ProcessHeap */ + /*------------------------------ * Utility function from xa_util */ Index: xa_core.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- xa_core.c=09(revision 65) +++ xa_core.c=09(working copy) @@ -91,6 +91,48 @@ printf("WARNING: Unknown or undefined OS type, assuming Linux.\n")= ; instance->os_type =3D XA_OS_LINUX; } + + /* Copy config info based on OS type */ + if(instance->os_type =3D=3D XA_OS_LINUX) + { +=09 xa_dbprint("--reading in linux offsets from config file.\n"); + if(entry->offsets.linux_offsets.tasks) + xalinux_tasks_offset =3D entry->offsets.linux_offsets.tasks; + + if(entry->offsets.linux_offsets.mm) + xalinux_mm_offset =3D entry->offsets.linux_offsets.mm; + + if(entry->offsets.linux_offsets.pid) + xalinux_pid_offset =3D entry->offsets.linux_offsets.pid; + + if(entry->offsets.linux_offsets.name) + xalinux_name_offset =3D entry->offsets.linux_offsets.name; + + if(entry->offsets.linux_offsets.addr) + xalinux_addr_offset =3D entry->offsets.linux_offsets.addr; + } + else /* This must be windows (see code above) */ + { +=09 xa_dbprint("--reading in windows offsets from config file.\n"); + if(entry->offsets.windows_offsets.tasks) + xawin_tasks_offset =3D entry->offsets.windows_offsets.tasks; + + if(entry->offsets.windows_offsets.pdbase) + xawin_pdbase_offset =3D entry->offsets.windows_offsets.pdbase; + + if(entry->offsets.windows_offsets.pid) + xawin_pid_offset =3D entry->offsets.windows_offsets.pid; + + if(entry->offsets.windows_offsets.peb) + xawin_peb_offset =3D entry->offsets.windows_offsets.peb; + + if(entry->offsets.windows_offsets.iba) + xawin_iba_offset =3D entry->offsets.windows_offsets.iba; + + if(entry->offsets.windows_offsets.ph) + xawin_ph_offset =3D entry->offsets.windows_offsets.ph; + } + #ifdef XA_DEBUG xa_dbprint("--got ostype from config (%s).\n", entry->ostype); if (instance->os_type =3D=3D XA_OS_LINUX){ @@ -247,7 +289,7 @@ goto error_exit; } instance->init_task =3D - *((uint32_t*)(memory + local_offset + XALINUX_TASKS_OFFSET)); + *((uint32_t*)(memory + local_offset + xalinux_tasks_offset)); munmap(memory, instance->page_size); } @@ -287,7 +329,7 @@ /* get address start of process list */ instance->init_task =3D - *((uint32_t*)(memory + local_offset + XAWIN_TASKS_OFFSET)); + *((uint32_t*)(memory + local_offset + xawin_tasks_offset)); munmap(memory, instance->page_size); } Index: windows_memory.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- windows_memory.c=09(revision 65) +++ windows_memory.c=09(working copy) @@ -35,6 +35,15 @@ #include <sys/mman.h> #include "xa_private.h" +/* Globals */ +int xawin_tasks_offset =3D 0x88; +int xawin_pdbase_offset =3D 0x18; +int xawin_pid_offset =3D 0x84; +int xawin_peb_offset =3D 0x1b0; +int xawin_iba_offset =3D 0x8; +int xawin_ph_offset =3D 0x18; + + /* finds the EPROCESS struct for a given pid */ unsigned char *windows_get_EPROCESS ( xa_instance_t *instance, int pid, uint32_t *offset) @@ -61,7 +70,7 @@ } memcpy(&task_pid, - memory + *offset + XAWIN_PID_OFFSET - XAWIN_TASKS_OFFSET, + memory + *offset + xawin_pid_offset - xawin_tasks_offset, 4 ); @@ -92,7 +101,7 @@ /* now follow the pointer to the memory descriptor and grab the pgd value */ - pgd =3D =20 *((uint32_t*)(memory+offset+XAWIN_PDBASE_OFFSET-XAWIN_TASKS_OFFSET)); + pgd =3D =20 *((uint32_t*)(memory+offset+xawin_pdbase_offset-xawin_tasks_offset)); pgd +=3D instance->page_offset; munmap(memory, instance->page_size); Index: config/config_parser.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- config/config_parser.h=09(revision 65) +++ config/config_parser.h=09(working copy) @@ -32,10 +32,28 @@ #define CONFIG_STR_LENGTH 1024 -typedef struct xa_config_entry{ +typedef struct xa_config_entry { char domain_name[CONFIG_STR_LENGTH]; char sysmap[CONFIG_STR_LENGTH]; char ostype[CONFIG_STR_LENGTH]; + union { + struct linux_offsets { + int tasks; + int mm; + int pid; + int name; + int pgd; + int addr; + } linux_offsets; + struct windows_offsets { + int tasks; + int pdbase; + int pid; + int peb; + int iba; + int ph; + } windows_offsets; + } offsets; } xa_config_entry_t; void xa_parse_config(char *td); Index: config/lexicon.l =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- config/lexicon.l=09(revision 65) +++ config/lexicon.l=09(working copy) @@ -35,9 +35,22 @@ %} %% +linux_tasks return LINUX_TASKS; +linux_mm return LINUX_MM; +linux_pid return LINUX_PID; +linux_name return LINUX_NAME; +linux_pgd return LINUX_PGD; +linux_addr return LINUX_ADDR; +win_tasks return WIN_TASKS; +win_pdbase return WIN_PDBASE; +win_pid return WIN_PID; +win_peb return WIN_PEB; +win_iba return WIN_IBA; +win_ph return WIN_PH; sysmap return SYSMAPTOK; ostype return OSTYPETOK; -[a-zA-Z0-9.-]+ yylval.str =3D strdup(yytext); return WORD; +0x[0-9a-fA-F]|[1-9][0-9]+ yylval.str =3D strdup(yytext); return NUM; +[a-zA-Z][a-zA-Z0-9.-]+ yylval.str =3D strdup(yytext); return WORD; [a-zA-Z0-9\/.-]+ yylval.str =3D strdup(yytext); return FILENAME; \" return QUOTE; \{ return OBRACE; Index: config/grammar.y =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- config/grammar.y=09(revision 65) +++ config/grammar.y=09(working copy) @@ -33,6 +33,7 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> +#include <errno.h> #include "config_parser.h" xa_config_entry_t entry; @@ -53,10 +54,13 @@ void entry_done () { if (strncmp(tmp_entry.domain_name, target_domain, =20 CONFIG_STR_LENGTH) =3D=3D 0){ + entry =3D tmp_entry; +/* memcpy(entry.domain_name, tmp_entry.domain_name, CONFIG_STR_LENGTH= ); memcpy(entry.sysmap, tmp_entry.sysmap, CONFIG_STR_LENGTH); - memcpy(entry.ostype, tmp_entry.ostype, CONFIG_STR_LENGTH); - /* copy over other values here as they are added */ + memcpy(entry.ostype, tmp_entry.ostype, CONFIG_STR_LENGTH) + entry.offsets =3D tmp_entry.offsets; +*/ } } @@ -78,6 +82,19 @@ char *str; } +%token<str> NUM +%token LINUX_TASKS +%token LINUX_MM +%token LINUX_PID +%token LINUX_NAME +%token LINUX_PGD +%token LINUX_ADDR +%token WIN_TASKS +%token WIN_PDBASE +%token WIN_PID +%token WIN_PEB +%token WIN_IBA +%token WIN_PH %token SYSMAPTOK %token OSTYPETOK %token<str> WORD @@ -113,8 +130,128 @@ sysmap_assignment | ostype_assignment + | + linux_tasks_assignment + | + linux_mm_assignment + | + linux_pid_assignment + | + linux_name_assignment + | + linux_pgd_assignment + | + linux_addr_assignment + | + win_tasks_assignment + | + win_pdbase_assignment + | + win_pid_assignment + | + win_peb_assignment + | + win_iba_assignment + | + win_ph_assignment ; +linux_tasks_assignment: + LINUX_TASKS EQUALS NUM + { + int tmp =3D strtol($3, NULL, 0); + tmp_entry.offsets.linux_offsets.tasks =3D tmp; + } + ; + +linux_mm_assignment: + LINUX_MM EQUALS NUM + { + int tmp =3D strtol($3, NULL, 0); + tmp_entry.offsets.linux_offsets.mm =3D tmp; + } + ; + +linux_pid_assignment: + LINUX_PID EQUALS NUM + { + int tmp =3D strtol($3, NULL, 0); + tmp_entry.offsets.linux_offsets.pid =3D tmp; + } + ; + +linux_name_assignment: + LINUX_NAME EQUALS NUM + { + int tmp =3D strtol($3, NULL, 0); + tmp_entry.offsets.linux_offsets.name =3D tmp; + } + ; + +linux_pgd_assignment: + LINUX_PGD EQUALS NUM + { + int tmp =3D strtol($3, NULL, 0); + tmp_entry.offsets.linux_offsets.pgd =3D tmp; + } + ; + +linux_addr_assignment: + LINUX_ADDR EQUALS NUM + { + int tmp =3D strtol($3, NULL, 0); + tmp_entry.offsets.linux_offsets.addr =3D tmp; + } + ; + +win_tasks_assignment: + WIN_TASKS EQUALS NUM + { + int tmp =3D strtol($3, NULL, 0); + tmp_entry.offsets.windows_offsets.tasks =3D tmp; + } + ; + +win_pdbase_assignment: + WIN_PDBASE EQUALS NUM + { + int tmp =3D strtol($3, NULL, 0); + tmp_entry.offsets.windows_offsets.pdbase =3D tmp; + } + ; + +win_pid_assignment: + WIN_PID EQUALS NUM + { + int tmp =3D strtol($3, NULL, 0); + tmp_entry.offsets.windows_offsets.pid =3D tmp; + } + ; + +win_peb_assignment: + WIN_PEB EQUALS NUM + { + int tmp =3D strtol($3, NULL, 0); + tmp_entry.offsets.windows_offsets.peb =3D tmp; + } + ; + +win_iba_assignment: + WIN_IBA EQUALS NUM + { + int tmp =3D strtol($3, NULL, 0); + tmp_entry.offsets.windows_offsets.iba =3D tmp; + } + ; + +win_ph_assignment: + WIN_PH EQUALS NUM + { + int tmp =3D strtol($3, NULL, 0); + tmp_entry.offsets.windows_offsets.ph =3D tmp; + } + ; + sysmap_assignment: SYSMAPTOK EQUALS QUOTE FILENAME QUOTE { Index: linux_memory.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- linux_memory.c=09(revision 65) +++ linux_memory.c=09(working copy) @@ -34,6 +34,15 @@ #include <sys/mman.h> #include "xa_private.h" + +/* Globals */ +int xalinux_tasks_offset =3D 0x60; +int xalinux_mm_offset =3D 0x78; +int xalinux_pid_offset =3D 0x9c; +int xalinux_name_offset =3D 0x1b0; +int xalinux_pgd_offset =3D 0x24; +int xalinux_addr_offset =3D 0x80; + /* finds the task struct for a given pid */ unsigned char *linux_get_taskstruct ( xa_instance_t *instance, int pid, uint32_t *offset) @@ -60,7 +69,7 @@ } memcpy(&task_pid, - memory + *offset + XALINUX_PID_OFFSET - XALINUX_TASKS_OFFSET= , + memory + *offset + xalinux_pid_offset - xalinux_tasks_offset= , 4 ); @@ -91,15 +100,15 @@ /* now follow the pointer to the memory descriptor and grab the pgd value */ - memcpy(&ptr, memory + offset + XALINUX_MM_OFFSET - =20 XALINUX_TASKS_OFFSET, 4); + memcpy(&ptr, memory + offset + xalinux_mm_offset - =20 xalinux_tasks_offset, 4); munmap(memory, instance->page_size); memory =3D xa_access_virtual_address(instance, ptr, &offset); if (NULL =3D=3D memory){ printf("ERROR: failed to follow mm pointer"); goto error_exit; } - /* memcpy(&pgd, memory + offset + XALINUX_PGD_OFFSET, 4); */ - pgd =3D *((uint32_t*)(memory + offset + XALINUX_PGD_OFFSET)); + /* memcpy(&pgd, memory + offset + xalinux_pgd_offset, 4); */ + pgd =3D *((uint32_t*)(memory + offset + xalinux_pgd_offset)); error_exit: if (memory) munmap(memory, instance->page_size); @@ -142,7 +151,7 @@ } /* copy the information out of the memory descriptor */ - memcpy(&ptr, memory + offset + XALINUX_MM_OFFSET - =20 XALINUX_TASKS_OFFSET, 4); + memcpy(&ptr, memory + offset + xalinux_mm_offset - =20 xalinux_tasks_offset, 4); munmap(memory, instance->page_size); memory =3D xa_access_virtual_address(instance, ptr, &offset); if (NULL =3D=3D memory){ @@ -151,7 +160,7 @@ } memcpy( taskaddr, - memory + offset + XALINUX_ADDR_OFFSET, + memory + offset + xalinux_addr_offset, sizeof(xa_linux_taskaddr_t) ); |