#include
#include
#include
#include
#include
#define MB (1UL << 20) #define GB (1UL << 30) #define TB (1UL << 40) #define SYSFS_PATH "/sys/kernel/mm/page_walker/address" int main() FILE *sys; size_t mmap_len = GB * 256; unsigned long phys_addr; p = mmap(0, mmap_len, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0); if (p == MAP_FAILED) { fprintf(stderr, "mmap failed %d\n", errno); printf("allocated %lu MiB at %p\n", mmap_len >> 20, p);
sys = fopen(SYSFS_PATH, “rw”);
if (!sys) {
fprintf(stderr, “could not open file %d\n”, errno);
fprintf(sys, “%lx”, mmap);
fscanf(sys, “%lx”, &phys_addr);
printf(“Physical address %lx\n”, phys_addr);
sleep(3600);