mem.c (1128B)
1 #include <stdlib.h> 2 3 #include "vx32.h" 4 5 int vxmem_resize(vxmem *mem, size_t newsize) 6 { 7 if(mem->resize == 0) 8 abort(); 9 return mem->resize(mem, newsize); 10 } 11 12 int vxmem_read(vxmem *mem, void *data, uint32_t addr, uint32_t len) 13 { 14 if(mem->read == 0) 15 abort(); 16 return mem->read(mem, data, addr, len); 17 } 18 19 int vxmem_write(vxmem *mem, const void *data, uint32_t addr, uint32_t len) 20 { 21 if(mem->write == 0) 22 abort(); 23 return mem->write(mem, data, addr, len); 24 } 25 26 vxmmap *vxmem_map(vxmem *mem, uint32_t flags) 27 { 28 if(mem->map == 0) 29 abort(); 30 return mem->map(mem, flags); 31 } 32 33 void vxmem_unmap(vxmem *mem, vxmmap *m) 34 { 35 if(mem->unmap == 0) 36 abort(); 37 mem->unmap(mem, m); 38 } 39 40 int vxmem_checkperm(vxmem *mem, uint32_t addr, uint32_t len, 41 uint32_t perm, uint32_t *out_faultva) 42 { 43 if(mem->checkperm == 0) 44 abort(); 45 return mem->checkperm(mem, addr, len, perm, out_faultva); 46 } 47 48 int vxmem_setperm(vxmem *mem, uint32_t addr, uint32_t len, uint32_t perm) 49 { 50 if(mem->setperm == 0) 51 abort(); 52 return mem->setperm(mem, addr, len, perm); 53 } 54 55 void vxmem_free(vxmem *mem) 56 { 57 if(mem == 0) 58 return; 59 if(mem->free == 0) 60 abort(); 61 mem->free(mem); 62 } 63