Files
linux-kernel-module-cheat/userland/virt_to_phys_user.c
Ciro Santilli 六四事件 法轮功 26b890f42f Factor common userland and baremetal C functions
This allows add.c to run unmodified on both!

For that to work, use int main on baremetal, and pass the return value to
the final exit.
2018-11-15 20:07:47 +00:00

27 lines
698 B
C

/* https://github.com/cirosantilli/linux-kernel-module-cheat#userland-physical-address-experiments */
#define _XOPEN_SOURCE 700
#include <stdio.h> /* printf */
#include <stdlib.h> /* EXIT_SUCCESS, EXIT_FAILURE, strtoull */
#include "common_userland.h" /* virt_to_phys_user */
int main(int argc, char **argv)
{
pid_t pid;
uintptr_t vaddr, paddr = 0;
if (argc < 3) {
printf("Usage: %s pid vaddr\n", argv[0]);
return EXIT_FAILURE;
}
pid = strtoull(argv[1], NULL, 0);
vaddr = strtoull(argv[2], NULL, 0);
if (virt_to_phys_user(&paddr, pid, vaddr)) {
fprintf(stderr, "error: virt_to_phys_user\n");
return EXIT_FAILURE;
};
printf("0x%jx\n", (uintmax_t)paddr);
return EXIT_SUCCESS;
}