1. read_pfn.c 완성
1. 코드
#include <sys/fcntl.h>
#include <sys/types.h>
#include <sys/user.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
unsigned long read_pfn(void* ptr)
{
static int fd = -1;
unsigned long vpn = (unsigned long) ptr >> 12;
unsigned long data;
fd = open("/proc/self/pagemap", O_RDONLY);
pread(fd, &data, sizeof(data), vpn * sizeof(data));
if(data & 1UL << 63)
return data & ((1UL << 55) - 1);
return 0;
}
2. 실행 결과
linux-source-5.15.0 설치 문제

2. MAP_SHARED, MAP_PRIVATE 동작 확인