Memory paging and interruptions

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
MagicalTux
Posts: 22
Joined: Mon Dec 04, 2006 5:34 pm

Memory paging and interruptions

Post by MagicalTux »

Well,... I was wondering if it's possible for an application to have no pages to the kernel, but still be able to make a syscall.

For example the application calls :

int $0x80

This calls linux-compatible interruption.

Now I don't want to page the interruption handler to the application. It seems that cr0 and cr3 aren't altered when int is called, so I was wondering if it's possible for the system to jump to a non-mapped area upon receiving an interrupt. Obviously no, but still... I wonder if it's really impossible.

Any clue about that is welcome :)
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

Provided you have a valid ESP0/SS0, it can be done:

- application calls INT xxx
- processor loads ESP and SS from the TSS, CS and EIP from the IDT and jumps to that location.
- Processor generates a pagefault as the code does not exists
- Pagefault handler pages in the interrupt handler
- Pagefault handler resumes execution
- The interrupt is restarted and the syscall is executed

Alternatively, you can force a GPF on the INT call, check which int is called and act accordingly.

In either case, read the manuals for more info.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Otter
Member
Member
Posts: 75
Joined: Sun Dec 31, 2006 11:56 am
Location: Germany

Post by Otter »

Now I don't want to page the interruption handler to the application
You should do that. Your application does not need write access to this page, but what's the problem if it sees this handler in memory ? If you want to change from user to kernel mode you can use Task Gates, but it's slow and needs a lot of extra work.
MagicalTux
Posts: 22
Joined: Mon Dec 04, 2006 5:34 pm

Post by MagicalTux »

Ok, so I'll just have to have a readonly page somewhere in process memory to handle interrupts, which will just switch to kernel pages and give control back to kernel.

Thanks a lot :)
Post Reply