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 ]

Diff markup

Differences between /userland/myprog14.c (Article 7.5) and /userland/myprog14.c (Article 9.5)


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

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