SimpleOS

LXR

Navigation



Site hébergé par : enix

The LXR Cross Referencer for SOS

source navigation ]
diff markup ]
identifier search ]
general search ]
 
 
Article:1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 6.5 ] [ 7 ] [ 7.5 ] [ 8 ] [ 9 ] [ 9.5 ]

001 /* Copyright (C) 2005 David Decotigny
002 
003    This program is free software; you can redistribute it and/or
004    modify it under the terms of the GNU General Public License
005    as published by the Free Software Foundation; either version 2
006    of the License, or (at your option) any later version.
007    
008    This program is distributed in the hope that it will be useful,
009    but WITHOUT ANY WARRANTY; without even the implied warranty of
010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
011    GNU General Public License for more details.
012    
013    You should have received a copy of the GNU General Public License
014    along with this program; if not, write to the Free Software
015    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
016    USA. 
017 */
018 
019 #include <crt.h>
020 #include <libc.h>
021 #include <stdarg.h>
022 #include <debug.h>
023 
024 /**
025  * @file myprog14.c
026  *
027  * uaccess tests. Demonstrate that a page fault in kernel during
028  * userspace access (with uaccess.c functions) is NEVER (or at least
029  * should not be) fatal:
030  *  - licit page faults are resolved as usual (COW, page_in, ...)
031  *  - illicit page faults are caught and the uaccess functions tolerate
032  *    and report it
033  *
034  * We use the temporary syscall 4012 (hexdump) to force the kernel to
035  * call user_memcpy and do some page faults.
036  */
037 
038 int main()
039 {
040   char * zoup;
041   int fd;
042 
043   fd = open("/dev/zero", O_RDWR);
044   zoup = mmap(0, 8192,
045               PROT_READ | PROT_WRITE,
046               MAP_SHARED,
047               fd, 34);
048   close(fd);
049 
050   bochs_printf("mapped @%x\n", (unsigned)zoup);
051 
052   /* Do some forks to complicate things */
053   fork();
054   fork();
055 
056   /* Force the first page of the mapping to be allocated */
057   *zoup = 'a';
058 
059   _sos_syscall2(4012, (unsigned)zoup, 16384);
060   /*
061    * all 3 cases are handled here:
062    *  - [zoup, zoup + 4kB[: no page fault at all (page already mapped)
063    *  - [zoup+4kB, zoup + 8kB[: page fault => /dev/zero page_in() called
064    *  - [zoup+8kB, ...[: page fault => illegal user address =>
065    *    user_memcpy reports that only 8kB out of the 16kB could be
066    *    hexdumped
067    */
068 
069   return 0;
070 }

source navigation ] diff markup ] identifier search ] general search ]