|
[ source navigation ] [ diff markup ] [ identifier search ] [ general search ] |
|||
|
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() 039 { 039 { 040 char * zoup; 040 char * zoup; 041 041 042 zoup = mmap(0, 8192, !! 042 zoup = fakemmap(0, 8192, 043 PROT_READ | PROT_WRITE, !! 043 PROT_READ | PROT_WRITE, 044 MAP_SHARED, !! 044 MAP_SHARED, 045 "/dev/zero", 34); !! 045 "/dev/zero", 34); 046 bochs_printf("mapped @%x\n", (unsigned)zoup) 046 bochs_printf("mapped @%x\n", (unsigned)zoup); 047 047 048 /* Do some forks to complicate things */ 048 /* Do some forks to complicate things */ 049 fork(); 049 fork(); 050 fork(); 050 fork(); 051 051 052 /* Force the first page of the mapping to be 052 /* Force the first page of the mapping to be allocated */ 053 *zoup = 'a'; 053 *zoup = 'a'; 054 054 055 _sos_syscall2(4012, (unsigned)zoup, 16384); 055 _sos_syscall2(4012, (unsigned)zoup, 16384); 056 /* 056 /* 057 * all 3 cases are handled here: 057 * all 3 cases are handled here: 058 * - [zoup, zoup + 4kB[: no page fault at a 058 * - [zoup, zoup + 4kB[: no page fault at all (page already mapped) 059 * - [zoup+4kB, zoup + 8kB[: page fault => 059 * - [zoup+4kB, zoup + 8kB[: page fault => /dev/zero page_in() called 060 * - [zoup+8kB, ...[: page fault => illegal 060 * - [zoup+8kB, ...[: page fault => illegal user address => 061 * user_memcpy reports that only 8kB out 061 * user_memcpy reports that only 8kB out of the 16kB could be 062 * hexdumped 062 * hexdumped 063 */ 063 */ 064 064 065 return 0; 065 return 0; 066 } 066 }
[ source navigation ] | [ diff markup ] | [ identifier search ] | [ general search ] |