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