Click here to Skip to main content
15,611,704 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
i was reading a page that told:

"My microbenchmark begins by allocating one memory page, then creates two virtual address aliases pointing to it"

First Question. i want to know how can i create two virtual address that pointing to same memory page in linux with c?

again on that page he told that:

"One of the virtual pages (which we’ll call the “setup” pointer) is set to allow access from user mode. The second virtual page (“test” pointer) is set to varying permissions, then used to perform a load."

Second Question. can we change permission bit of a virtual address in virtual page table of our programe? as he did with second pointer.

Third Question. if it is possible, we can do this in both Kernel Mode and User Mode?

What I have tried:

I have read some articles about virtual memory management in linux and i can figure out virtual memory table, but i do not have any idea about that how can implement a code to do that.
Updated 30-Oct-19 22:08pm

You should ask the person who wrote those statements. We have no idea what the context of those claims may be.
Share this answer
Richard is totally right. We can't know what these statements mean without context.

However, I would offer some input. I may be totally wrong, but if I am, take that as an indication that you are not providing sufficient information to answer these questions:

1. Since you're specifically referring to doing things on Linux, I assume you're working on that OS - we'll need that info later. I have no idea how to answer your question because I don't understand what this is about: you can't allocate a memory page from a C/C++ program running under Linux. Either this is Linux kernel functionality (i. e. part of the OS), or it is not about a memory page in the sense of memory managed by the Linux OS.

2. Most certainly not! Memory management, Virtual memory pages, and access right are system level functions that you normally shouldn't touch at all. They are in place to prevent programs from accidentaly (or intentionally) interfering with other programs. If the system would allow you doing that, I'd consider it a severe bug.

3. Ok, now you let the cat out of the bag: 'Kernel Mode' means you're looking at the lowest level operating system functions! This means your reference to Linux was either misleading, or you intend to write/change/add Linux Kernel functionality. If that's the case, you should go to the appropriate Linux boards. This is way to advanced and specialized to get much useful input from here.

If that is not what you wanted, you should tell us what your actual goal is instead of posting questions out of context.

P.S.: I have no knowledge about writing Linux Kernel code, but I do know that at the lowest level it's all pure C code, not C++. If that's your topic, you should change the tags to C and Linux, this is clearly not a C++ question.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900