|
[ 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 <string.h> 021 #include <string.h> 022 #include <stdarg.h> 022 #include <stdarg.h> 023 #include <debug.h> 023 #include <debug.h> 024 024 025 025 026 /** 026 /** 027 * @file myprog12.c !! 027 * @file myprog10.c 028 * 028 * 029 * /dev/mem & /dev/kmem tests 029 * /dev/mem & /dev/kmem tests 030 */ 030 */ 031 031 032 032 033 int main() 033 int main() 034 { 034 { 035 char *zoup; 035 char *zoup; 036 036 037 /* Test /dev/mem */ 037 /* Test /dev/mem */ 038 038 039 /* Map the x86 text framebuffer into this pr 039 /* Map the x86 text framebuffer into this process address space in 040 shared mode */ 040 shared mode */ 041 zoup = fakemmap(0, 4096, PROT_READ | PROT_WR !! 041 zoup = mmap(0, 4096, PROT_READ | PROT_WRITE, 042 MAP_SHARED, !! 042 MAP_SHARED, 043 "/dev/mem", 0xb8000); !! 043 "/dev/mem", 0xb8000); 044 bochs_printf("mapped mem @%x\n", (unsigned)z 044 bochs_printf("mapped mem @%x\n", (unsigned)zoup); 045 _sos_syscall1(4004, (unsigned)"Apres mmap vi 045 _sos_syscall1(4004, (unsigned)"Apres mmap video"); 046 046 047 /* Do some forks to complicate things */ 047 /* Do some forks to complicate things */ 048 fork(); 048 fork(); 049 fork(); 049 fork(); 050 050 051 /* Write a string into it: it should be prin 051 /* Write a string into it: it should be printed on screen */ 052 strzcpy(zoup + 80*5*2 + 10*2, 052 strzcpy(zoup + 80*5*2 + 10*2, 053 "H e l l o W o r l d f r o m S 053 "H e l l o W o r l d f r o m S O S i n U s e r M o d e ", 054 250); 054 250); 055 055 056 /* Map the x86 text framebuffer into this pr 056 /* Map the x86 text framebuffer into this process address space in 057 PRIVATE mode */ 057 PRIVATE mode */ 058 zoup = fakemmap(0, 4096, PROT_READ | PROT_WR !! 058 zoup = mmap(0, 4096, PROT_READ | PROT_WRITE, 059 0 /* Private */, !! 059 0 /* Private */, 060 "/dev/mem", 0xb8000); !! 060 "/dev/mem", 0xb8000); 061 bochs_printf("mapped mem @%x\n", (unsigned)z 061 bochs_printf("mapped mem @%x\n", (unsigned)zoup); 062 _sos_syscall1(4004, (unsigned)"Apres mmap vi 062 _sos_syscall1(4004, (unsigned)"Apres mmap video"); 063 063 064 /* Do some forks to complicate things */ 064 /* Do some forks to complicate things */ 065 fork(); 065 fork(); 066 fork(); 066 fork(); 067 067 068 /* Write a string into it: it should NOT be 068 /* Write a string into it: it should NOT be printed on screen since 069 the mapping is private */ 069 the mapping is private */ 070 strzcpy(zoup + 80*5*2 + 10*2, 070 strzcpy(zoup + 80*5*2 + 10*2, 071 "Y o u c a n n o t S e e T h i 071 "Y o u c a n n o t S e e T h i s ! ", 072 250); 072 250); 073 073 074 /* Test /dev/kmem */ 074 /* Test /dev/kmem */ 075 075 076 /* remap some kernel pages in user space. We 076 /* remap some kernel pages in user space. We'd better map this in 077 "private" mode here, this way we can do w 077 "private" mode here, this way we can do whatever we like in this 078 area. If we'd mapped it read/write, this 078 area. If we'd mapped it read/write, this would overwrite kernel 079 data/code, causing a crash sooner or late 079 data/code, causing a crash sooner or later. */ 080 zoup = fakemmap(0, 100*4096, PROT_READ | PRO !! 080 zoup = mmap(0, 100*4096, PROT_READ | PROT_WRITE, 081 0 /* private */, !! 081 0 /* private */, 082 "/dev/kmem", 0x00201000); !! 082 "/dev/kmem", 0x00201000); 083 bochs_printf("mapped kmem @%x\n", (unsigned) 083 bochs_printf("mapped kmem @%x\n", (unsigned)zoup); 084 _sos_syscall1(4004, (unsigned)"Apres mmap ke 084 _sos_syscall1(4004, (unsigned)"Apres mmap kernel"); 085 085 086 /* Do some forks to complicate things */ 086 /* Do some forks to complicate things */ 087 fork(); 087 fork(); 088 fork(); 088 fork(); 089 089 090 /* Overwriting our private "copy" of kernel 090 /* Overwriting our private "copy" of kernel */ 091 memset(zoup, 0x0, 10*4096); 091 memset(zoup, 0x0, 10*4096); 092 _sos_syscall1(4004, (unsigned)"Apres memset 092 _sos_syscall1(4004, (unsigned)"Apres memset kernel"); 093 093 094 return 0; 094 return 0; 095 } 095 }
[ source navigation ] | [ diff markup ] | [ identifier search ] | [ general search ] |