Page Fault question

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
Anthony M.

Page Fault question

Post by Anthony M. »

Hi, i was working on my kernel's ata driver, and when doing an open()
call on the ata driver, a pointer to a file struct is taken as an
argument, and within that struct is an int containin the device number
to be looked up. well, when the open() function tries to access
file->device it causes a page fault (interrupt 14. this is correct,
right?). i don't understand why. and what is the proper way of handling
a page fault?

code is similar to this.

Code: Select all

typedef struct _file_t
{
   unsigned int device;
   ...
} file_t;

------------

file_t file;
file.device = 1;

ata_open(&file);

------------
int ata_open(file_t *file)
{
     k_printf("%s called\n", __FUNCTION__); // this prints fine

     // page fault here from dereference of file to get device number.
     k_printf("%s: getting device info for device %d\n", __FUNCTION__,
file->device);

     ...

}
any help or insight in this would be greatly appreciated. thanks.
Anthony Lineberry
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Page Fault question

Post by Pype.Clicker »

Anthony M. wrote:
i don't understand why. and what is the proper way of handling
a page fault?
Probably the pointer "file" is not valid. Since you apparently have the structure automatically allocated on the stack, this is indeed surprising. Looking at CR2 value and compare that to register contents and disassembling output might give you further enlightenment on the causes.

The proper way of handling a PF may differ depending on the context. E.g. a page fault can mean you try to access an invalid area (report and terminate), or that you're accessing a "virtual region" (allocate a new page and return), or that you're accessing a swapped-out region (swap in and return).
Post Reply