You also can do this in windows :

#include <windows.h>
#include <stdio.h>

void sysfatal(char * reason)
{
   printf("'%s' failed with error %d\n", reason, GetLastError());
   ExitProcess(0);
}

PUCHAR    Page;

int filter(unsigned int code, struct _EXCEPTION_POINTERS *ep)
{
   if (code == EXCEPTION_ACCESS_VIOLATION) {
if(ep->ExceptionRecord->ExceptionInformation[1] == (DWORD_PTR) Page){
           Page = VirtualAlloc(Page, 4096, MEM_COMMIT, PAGE_READWRITE);
           if(Page == 0)
               sysfatal("VirtualAlloc: commit");
           return EXCEPTION_CONTINUE_EXECUTION;
       }
       return EXCEPTION_EXECUTE_HANDLER;
   }
   return EXCEPTION_CONTINUE_SEARCH;
}

int main(int argc, char ** argv)
{
   // Reserve
   Page = VirtualAlloc(0, 4096, MEM_RESERVE, PAGE_READWRITE);
   if(Page == 0)
       sysfatal("VirtualAlloc: reserve");
   __try{
       // Touch
       *Page = 0;
       puts("touched.");
   }
   __except(filter(GetExceptionCode(), GetExceptionInformation()))
   {
       puts("in except");
   }
   return 0;
}


Philippe Anel a écrit :
l4 (http://en.wikipedia.org/wiki/L4_microkernel_family) has such api ... but it is only a kernel.

Paul Lalonde a écrit :
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I have an application I'm building which requires OS support to allow a user-space function to fill a page on page-faults. Ideally, I could reserve a chunk of address space but not back it with memory, and then on fault my handler would serve out data from some small cache of user-managed physical pages.

My google-fu has been weak in finding such a system-level API in any OS. Has this got a name I should be searching on? I can't believe no-one has implemented user-level page replacement.

Thanks,
   Paul

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (Darwin)

iD8DBQFHMKM4pJeHo/Fbu1wRAgezAKCSDVI812jisKkliXjpsWTMU3AlogCcDkOl
liIiMj9Y/2xwHx1iFKjSZ8w=
=CAPO
-----END PGP SIGNATURE-----






Reply via email to