The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: xenon on August 23, 2005, 08:49:24 AM

Title: Manipulate page tables in Windows application
Post by: xenon on August 23, 2005, 08:49:24 AM
I'm coding a Windows application program. Can I get access to the pages tables?
Here is what i'm trying to do:
I want a modulo buffer.
8192 bytes of buffer.
When the offset pointer overshoots >=8192, it will wrap back and access from the beginning of the buffer.
(The offset pointer will always be < 12*1024)

I just need to reserved 3 pages of contiguous memory space, with the 3rd page map back to the same place as 1st page.
Title: Re: Manipulate page tables in Windows application
Post by: Tedd on August 23, 2005, 09:19:43 AM
You can get pages of memory with VirtualAlloc, but this doesn't give you the option of remapping them to wherever you like.
I don't think that would/should be allowed :bdg
Title: Re: Manipulate page tables in Windows application
Post by: QvasiModo on August 23, 2005, 03:36:16 PM
I think you'd have to code a driver to do that. Usermode apps can't access the page tables directly, for stability and security reasons.
Title: Re: Manipulate page tables in Windows application
Post by: hutch-- on August 25, 2005, 12:30:23 PM
xenon,

Is there any reason why you don't write a simple wrap around to go back to the start of the buffer ?
Title: Re: Manipulate page tables in Windows application
Post by: xenon on July 27, 2006, 11:35:53 AM
Sorry for missing for a long time.

It was just a random thought of playing with page tables. I was thinking of saving some clock cycles on a simple wrap around. The experimental program is supposed to be a Mersenne number factoring program. The buffer is a sieve that each bit represent a candidate factor. Then thousands of small prime numbers are run through one by one to clear many bits in the sieve, eliminating the need to test those factors (because those factors are divisible by that small prime). Anyway, I don't think I can explain why is there a need for the wrap around. That time I was experimenting to get it run faster, but now, I've put it aside. Thanks for your help.
Title: Re: Manipulate page tables in Windows application
Post by: drizz on July 27, 2006, 12:15:31 PM
if you set 3rd page as PAGE_GUARD (or PAGE_NO_ACCESS), and you set up an exception handler,
maybe that will work for you?.. (adjusting CONTEXT to start of first page).
but performance will suffer..
Title: Re: Manipulate page tables in Windows application
Post by: mnemonic on July 27, 2006, 12:48:40 PM
Maybe I'm missing something essentially, but anyway, here is my idea.

If you have your pointer in e.g. EAX, you could try
and EAX, 00000000000000000001111111111111b
after each iteration.
That way your pointer will always stay between 0 and 8191.
If you have some register spare you can even put that constant in there and speed things up. That way it should be even faster than some "page fault wraparound" by the OS.

Regards