Skip to content

Instantly share code, notes, and snippets.

@vasi
Last active August 17, 2025 04:35
Show Gist options
  • Select an option

  • Save vasi/94173f68b4caa93100a9b192086b02cc to your computer and use it in GitHub Desktop.

Select an option

Save vasi/94173f68b4caa93100a9b192086b02cc to your computer and use it in GitHub Desktop.
#include <sys/mman.h>
#include <fcntl.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
// Run: sudo ./test /sys/bus/pci/devices/*:00:10.0/resource2
char *file = argv[1];
fprintf(stderr, "file = %s\n", file);
int fd = open(file, O_RDWR | O_CLOEXEC);
fprintf(stderr, "fd = %d\n", fd);
void *addr = mmap(NULL, 0x4000, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
fprintf(stderr, "addr = %p\n", addr);
perror("error");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment