upd with strerror

This commit is contained in:
Ole Algoritme
2023-02-28 11:30:50 +01:00
parent 6ecc32ac2c
commit 14c65888e4

12
gddr6.c
View File

@@ -8,6 +8,12 @@
#include <sys/mman.h> #include <sys/mman.h>
#include <pci/pci.h> #include <pci/pci.h>
#define PRINT_ERROR \
do { \
fprintf(stderr, "Error at line %d, file %s (%d) [%s]\n", \
__LINE__, __FILE__, errno, strerror(errno)); exit(1); \
} while(0)
struct device struct device
{ {
uint32_t bar0; uint32_t bar0;
@@ -77,10 +83,8 @@ int main(int argc, char **argv)
base_offset = offset & ~(sysconf(_SC_PAGE_SIZE)-1); base_offset = offset & ~(sysconf(_SC_PAGE_SIZE)-1);
map_base = mmap(0, map_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, base_offset); map_base = mmap(0, map_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, base_offset);
if (!map_base) { if(map_base == (void *) -1)
printf("Can't map memory. Are you r00t?\n"); PRINT_ERROR;
exit(-1);
}
virt_addr = map_base + offset - base_offset; virt_addr = map_base + offset - base_offset;
read_result = *((uint32_t *) virt_addr); read_result = *((uint32_t *) virt_addr);