The NZ Linux Resource

[WaiLUG] userspace and kernel space memory experiment

John john at lynch.org.nz
Wed Jan 4 21:39:41 NZDT 2006


----- Original Message ----- 
From: "Nic Bellamy" <nic at bellamy.co.nz>
To: "Wairarapa Linux User Group" <wailug at linux.net.nz>
Sent: Monday, January 02, 2006 10:39 AM
Subject: Re: [WaiLUG] userspace and kernel space memory experiment


> On Wed, 2005-12-28 at 21:13 +1300, John wrote:
>>Hi guys, I have been trying to figure out how the Linux Memory
>>management system works,
>>I tried to write a small C program that is in a sleep loop waking up
>>every 5 secs or so checking the value
>>of a variable (it first prints out is userspace virtual address of the
>>variable), I then wrote a module that tries
>>to alter that memory location from kernel space. I have been doing
>>this by traversing the pgd , pmd and pte arrays
>>and have come to the conclusion I have know Idea what I am doing :-)
>>and idea's on how this could be done ??
>
> Oddly, I didn't see the original message.
>
> A userspace virtual address is only unique when combined with the 
> processes page tables; ie. it's perfectly plausible (and common) for 
> multiple processes to be using the same virtual address space.
>
> To test this out, run multiple copies of your userspace program 
> simultaenously - you'll likely find they print out the same address in 
> each case.
>
> I have a copy of Understanding The Linux Kernel and also Liunx Device 
> Drivers here - they may be useful to you.

Solved this problem but I might take a rain check on the books as I am sure 
I am bound to
run into more trouble :-)

I managed to get this working (yes by traversing the process page tables) 
When
I email the list I was at the point where I had found the pte (page table 
entry) but had
not added the offset into it :-)

>
> One question though... uh... why do you want to do this?
I am working on  an embedded project where I need to supply the real memory 
address of a user space buffer to
a hardware register, so the hardware knows where to place it's processed 
data,
I guess this assumes the hardware does n't use the MMU , but I am real close 
to finding out :-)
So this is just me finding out if I could find the real memory address, 
turns out I can, not sure how safe
it is though.
>
> Cheers,
> Nic.
>
> -- 
> Nic Bellamy <nic at bellamy.co.nz>
> Bellamy Consulting -- Software & Security -- http://www.bellamy.co.nz/
> Phone: +64-6-377-4957   Fax: +64-6-377-0505   Mobile: +64-21-251-8954
>
> _______________________________________________
> WaiLUG mailing list
> WaiLUG at linux.net.nz
> http://www.linux.net.nz/cgi-bin/mailman/listinfo/wailug
> 




More information about the WaiLUG mailing list If you have any questions or comments about this page, email the Webmaster
Design Copyright © 1998-2005 Linux.net.nz