From 91b8d48f52116530da8e0a2bdb1c086210170e00 Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Wed, 7 Feb 2024 23:17:55 +0100 Subject: [PATCH] userspace: mmap test read and write --- userspace/main_user.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/userspace/main_user.c b/userspace/main_user.c index cfdc52c..9502c75 100644 --- a/userspace/main_user.c +++ b/userspace/main_user.c @@ -56,11 +56,13 @@ int func_alloc() return 0; } -int func_mmap() -{ +int func_mmap() { - char *path ="/dev/zero"; - mmap(0, 4096, 0, 0, path); + char *path = "/dev/zero"; + void *mapAddr = mmap((void *)4096, 4096, PROT_READ | PROT_WRITE, 0, path); + printf("Zero mmaped at %p\n", mapAddr); + int data = *(int *)mapAddr; + *(int *)mapAddr = data; return 0; }