Minimum amount of pages

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Minimum amount of pages

Post by Candy »

I've had a discussion with a professor of mine about this

Technically speaking, what is the absolute minimum of pages (possibly hand-crafted) that must be loaded before the first instruction can be executed (you can pick the instruction yourself) ? This working on a 2-level paging structure such as x86.

His answer was 3, since his idea was, page directory, page table & page with code.

My idea is that you can put a single page directory entry on the same physical page as a page table entry, and still have enough place left over for at least 1 opcode. My best idea on x86 came to 5 bytes, namely 0x03 0x00 0x00 0x00 0xFC (with eip set to 0x04, and this page loaded to physical 0x0)

Is my answer valid?
Tim

Re:Minimum amount of pages

Post by Tim »

Potentially lots of pages -- think about the instruction's opcodes. It depends what the instruction is. What if the first instruction is an INT?

If we only consider 'normal' instructions, then think about loading a dword that crosses a page boundary, with the instruction itself crossing a page boundary. Then you've got 2 pages for the source, 2 pages for the instruction itself, page directory and page table -- giving 6.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Minimum amount of pages

Post by Candy »

Those things only came into point with the maximum number of pages (think about the cases where you load from an dword at 0xFFFFFE, write to a dword at 0x2FFFFFE, using a 4-byte instruction starting at 0x4FFFFFE, thus forcing you to also load 6 pages of page table, and of course the page directory page, coming to a total of 13.

The question we argued about was the one that represented the minimum amount of pages that could be referenced. You could pick the instruction yourself (as to get the page count down). Still, the argument is about if you can or can not put the page directory part on the same page as the page table, which I also abuse for the instruction. (0xFC == cld btw) If you are trying to get the lowest number possible, is it unreasonable to think about these parts in a theoretical question?
beyond infinity lazy

Re:Minimum amount of pages

Post by beyond infinity lazy »

theoretical questions...

I have never been good friend with theory for it often makes one walking blindfold throu' hell and then wondering 'huh, I've burnt my feet?'

Anyway, even if it is feasible to do a paging trick like the one you have proposed ... what would be the witz of it? I canna imagine this a useful thing when you wanna do multiprocessing with more than one pagedirectory in play.

but I'd propose you write a piece of code to demosntrate it - and to show proof of your hypothesis. maybe a little falsification would do something good?

stay safe
Post Reply