xenaccess.h

Go to the documentation of this file.
00001 /*
00002  * The libxa library provides access to resources in domU machines.
00003  * 
00004  * Copyright (C) 2005 - 2007  Bryan D. Payne (bryan@thepaynes.cc)
00005  * 
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  * 
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  * 
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00019  * 02110-1301, USA.
00020  *
00021  * --------------------
00022  * This file contains the public function definitions for the libxa
00023  * library.
00024  *
00025  * File: xenaccess.h
00026  *
00027  * Author(s): Bryan D. Payne (bryan@thepaynes.cc)
00028  */
00029 
00036 #ifndef LIB_XEN_ACCESS_H
00037 #define LIB_XEN_ACCESS_H
00038 
00039 #ifdef HAVE_CONFIG_H
00040 #include <config.h>
00041 #endif /* HAVE_CONFIG_H */
00042 
00043 #ifdef ENABLE_XEN
00044 #include <xenctrl.h>
00045 #endif /* ENABLE_XEN */
00046 #include <stddef.h>
00047 #include <stdint.h>
00048 #include <time.h>
00049 #include <stdio.h>
00050 #include <sys/mman.h>
00051 #include <errno.h>
00052 
00053 /* uncomment this to enable debug output */
00054 #define XA_DEBUG
00055 
00059 #define XA_MODE_XEN 0
00060 
00064 #define XA_MODE_FILE 1
00065 
00070 #define XA_FILETYPE_DD 0
00071 
00075 #define XA_SUCCESS 0
00076 
00079 #define XA_FAILURE -1
00080 
00088 #define XA_FAILHARD 0
00089 
00097 #define XA_FAILSOFT 1
00098 
00102 #define XA_OS_LINUX 0
00103 
00107 #define XA_OS_WINDOWS 1
00108 
00113 #define XA_XENVER_UNKNOWN 0
00114 
00118 #define XA_XENVER_3_0_4 1
00119 
00123 #define XA_XENVER_3_1_0 3
00124 
00128 #define XA_XENVER_3_1_1 4
00129 
00133 #define XA_XENVER_3_1_2 5
00134 
00138 #define XA_XENVER_3_1_3 6
00139 
00143 #define XA_XENVER_3_1_4 7
00144 
00148 #define XA_XENVER_3_2_0 8
00149 
00153 #define XA_XENVER_3_2_1 9
00154 
00158 #define XA_XENVER_3_2_2 10
00159 
00163 #define XA_XENVER_3_3_0 11
00164 
00165 struct xa_cache_entry{
00166     time_t last_used;
00167     char *symbol_name;
00168     uint32_t virt_address;
00169     uint32_t mach_address;
00170     int pid;
00171     struct xa_cache_entry *next;
00172     struct xa_cache_entry *prev;
00173 };
00174 typedef struct xa_cache_entry* xa_cache_entry_t;
00175 
00176 struct xa_pid_cache_entry{
00177     time_t last_used;
00178     int pid;
00179     uint32_t pgd;
00180     struct xa_pid_cache_entry *next;
00181     struct xa_pid_cache_entry *prev;
00182 };
00183 typedef struct xa_pid_cache_entry* xa_pid_cache_entry_t;
00184 
00193 typedef struct xa_instance{
00194     uint32_t mode;          
00195     uint32_t error_mode;    
00196     char *sysmap;           
00197     char *image_type;       
00198     uint32_t page_offset;   
00199     uint32_t page_shift;    
00200     uint32_t page_size;     
00201     uint32_t kpgd;          
00202     uint32_t init_task;     
00203     int os_type;            
00204     int hvm;                
00205     int pae;                
00206     int pse;                
00207     uint32_t cr3;           
00208     xa_cache_entry_t cache_head;         
00209     xa_cache_entry_t cache_tail;         
00210     int current_cache_size;              
00211     xa_pid_cache_entry_t pid_cache_head; 
00212     xa_pid_cache_entry_t pid_cache_tail; 
00213     int current_pid_cache_size;          
00214     union{
00215         struct linux_instance{
00216             int tasks_offset;    
00217             int mm_offset;       
00218             int pid_offset;      
00219             int pgd_offset;      
00220             int addr_offset;     
00221         } linux_instance;
00222         struct windows_instance{
00223             uint32_t ntoskrnl;   
00224             int tasks_offset;    
00225             int pdbase_offset;   
00226             int pid_offset;      
00227             int peb_offset;      
00228             int iba_offset;      
00229             int ph_offset;       
00230         } windows_instance;
00231     } os;
00232     union{
00233 #ifdef ENABLE_XEN
00234         struct xen{
00235             int xc_handle;       
00236             uint32_t domain_id;  
00237             int xen_version;     
00238             xc_dominfo_t info;   
00239             uint32_t size;       
00240             unsigned long *live_pfn_to_mfn_table;
00241             unsigned long nr_pfns;
00242         } xen;
00243 #endif
00244         struct file{
00245             FILE *fhandle;       
00246             uint32_t size;       
00247         } file;
00248     } m;
00249 } xa_instance_t;
00250 
00260 typedef struct xa_linux_taskaddr{
00261     unsigned long start_code;  
00262     unsigned long end_code;    
00263     unsigned long start_data;  
00264     unsigned long end_data;    
00265     unsigned long start_brk;   
00266     unsigned long brk;         
00267     unsigned long start_stack; 
00268     unsigned long arg_stack;   
00269     unsigned long arg_end;     
00270     unsigned long env_start;   
00271     unsigned long env_end;     
00272 } xa_linux_taskaddr_t;
00273 
00282 typedef struct xa_windows_peb{
00283     uint32_t ImageBaseAddress; 
00284     uint32_t ProcessHeap;      
00285 } xa_windows_peb_t;
00286 
00287 /*--------------------------------------------------------
00288  * Initialization and Destruction functions from xa_core.c
00289  */
00290 
00307 int xa_init_vm_name_strict (char *domain_name, xa_instance_t *instance);
00308 
00326 int xa_init_vm_name_lax (char *domain_name, xa_instance_t *instance);
00327 
00345 int xa_init_vm_id_strict (uint32_t domain_id, xa_instance_t *instance);
00346 
00365 int xa_init_vm_id_lax (uint32_t domain_id, xa_instance_t *instance);
00366 
00384 int xa_init_file_strict
00385     (char *filename, char *image_type, xa_instance_t *instance);
00386 
00405 int xa_init_file_lax
00406     (char *filename, char *image_type, xa_instance_t *instance);
00407 
00414 int xa_destroy (xa_instance_t *instance);
00415 
00416 /*-----------------------------------------
00417  * Memory access functions from xa_memory.c
00418  */
00419 
00431 void *xa_access_pa (
00432         xa_instance_t *instance, uint32_t phys_address,
00433         uint32_t *offset, int prot);
00434 
00446 void *xa_access_ma (
00447         xa_instance_t *instance, uint32_t mach_address,
00448         uint32_t *offset, int prot);
00449 
00462 void *xa_access_kernel_sym (
00463         xa_instance_t *instance, char *symbol, uint32_t *offset, int prot);
00464 
00476 void *xa_access_kernel_va (
00477         xa_instance_t *instance, uint32_t virt_address,
00478         uint32_t *offset, int prot);
00479 
00492 void *xa_access_kernel_va_range (
00493     xa_instance_t* instance, uint32_t virt_address,
00494     uint32_t size, uint32_t* offset, int prot);
00495 
00511 void *xa_access_user_va (
00512         xa_instance_t *instance, uint32_t virt_address,
00513         uint32_t *offset, int pid, int prot);
00514 
00532 void *xa_access_user_va_range (
00533     xa_instance_t* instance, uint32_t virt_address,
00534     uint32_t size, uint32_t* offset, int pid, int prot);
00535 
00544 uint32_t xa_translate_kv2p(xa_instance_t *instance, uint32_t virt_address);
00545 
00546 /*---------------------------------------
00547  * Memory access functions from xa_util.c
00548  */
00549 
00558 int xa_read_long_sym (xa_instance_t *instance, char *sym, uint32_t *value);
00559 
00568 int xa_read_long_long_sym (xa_instance_t *instance, char *sym, uint64_t *value);
00569 
00579 int xa_read_long_virt (
00580         xa_instance_t *instance, uint32_t vaddr, int pid, uint32_t *value);
00581 
00591 int xa_read_long_long_virt (
00592         xa_instance_t *instance, uint32_t vaddr, int pid, uint64_t *value);
00593 
00602 int xa_read_long_phys (
00603         xa_instance_t *instance, uint32_t paddr, uint32_t *value);
00604 
00613 int xa_read_long_long_phys (
00614         xa_instance_t *instance, uint32_t paddr, uint64_t *value);
00615 
00624 int xa_read_long_mach (
00625         xa_instance_t *instance, uint32_t maddr, uint32_t *value);
00626 
00635 int xa_read_long_long_mach (
00636         xa_instance_t *instance, uint32_t maddr, uint64_t *value);
00637 
00646 int xa_symbol_to_address (xa_instance_t *instance, char *sym, uint32_t *vaddr);
00647 
00648 /*-----------------------------
00649  * Linux-specific functionality
00650  */
00651 
00661 int xa_linux_get_taskaddr (
00662         xa_instance_t *instance, int pid, xa_linux_taskaddr_t *taskaddr);
00663 
00664 /*-----------------------------
00665  * Windows-specific functionality
00666  */
00667 
00677 int xa_windows_get_peb (
00678         xa_instance_t *instance, int pid, xa_windows_peb_t *peb);
00679 
00680 
01186 #endif /* LIB_XEN_ACCESS_H */

Generated on Thu Dec 18 13:28:46 2008 for XenAccess by  doxygen 1.4.7