-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser.c
More file actions
33 lines (25 loc) · 888 Bytes
/
Copy pathuser.c
File metadata and controls
33 lines (25 loc) · 888 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <stdio.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <unistd.h>
#include "mem_ioctl.h"
#define PAGE_SIZE 4096
int main() {
// 1. 커널 모듈이 생성한 proc 파일 열기
int fd = open("/proc/malloc_monitor", O_RDWR);
/* User space memory allocation */
char *ptr = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); // Allocate new memory space
printf("user CMD_MALLOC\n");
ioctl(fd, CMD_MALLOC, ptr); // Send signal to kernel module
printf("user CMD_ACCESS\n");
/* User space memory access */
ptr[0] = 'A'; // Memory write
ioctl(fd, CMD_ACCESS, ptr); // Send signal to kernel module
printf("user CMD_KMALLOC\n");
/* Kerel space memory allocation */
ioctl(fd, CMD_KMALLOC); // Send signal to kernel module
close(fd);
return 0;
}