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/myprog12.c (Article 9) and /userland/myprog12.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 <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 myprog12.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(void)
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   int fd;                                         041   int fd;
042                                                   042 
043   fd = open("/dev/mem", O_RDWR);                  043   fd = open("/dev/mem", O_RDWR);
044   zoup = mmap(0, 4096, PROT_READ | PROT_WRITE,    044   zoup = mmap(0, 4096, PROT_READ | PROT_WRITE,
045               MAP_SHARED,                         045               MAP_SHARED,
046               fd, 0xb8000);                       046               fd, 0xb8000);
047   close(fd);                                      047   close(fd);
048                                                   048 
049   bochs_printf("mapped mem @%x\n", (unsigned)z    049   bochs_printf("mapped mem @%x\n", (unsigned)zoup);  
050   _sos_syscall1(4004, (unsigned)"Apres mmap vi    050   _sos_syscall1(4004, (unsigned)"Apres mmap video");
051                                                   051 
052   /* Do some forks to complicate things */        052   /* Do some forks to complicate things */
053   fork();                                         053   fork();
054   fork();                                         054   fork();
055                                                   055 
056   /* Write a string into it: it should be prin    056   /* Write a string into it: it should be printed on screen */
057   strzcpy(zoup + 80*5*2 + 10*2,                   057   strzcpy(zoup + 80*5*2 + 10*2,
058           "H e l l o   W o r l d   f r o m   S    058           "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 ",
059           250);                                   059           250);
060                                                   060 
061   /* Map the x86 text framebuffer into this pr    061   /* Map the x86 text framebuffer into this process address space in
062      PRIVATE mode */                              062      PRIVATE mode */
063   fd = open("/dev/mem", O_RDWR);                  063   fd = open("/dev/mem", O_RDWR);
064   zoup = mmap(0, 4096, PROT_READ | PROT_WRITE,    064   zoup = mmap(0, 4096, PROT_READ | PROT_WRITE,
065               0 /* Private */,                    065               0 /* Private */,
066               fd, 0xb8000);                       066               fd, 0xb8000);
067   close(fd);                                      067   close(fd);
068   bochs_printf("mapped mem @%x\n", (unsigned)z    068   bochs_printf("mapped mem @%x\n", (unsigned)zoup);  
069   _sos_syscall1(4004, (unsigned)"Apres mmap vi    069   _sos_syscall1(4004, (unsigned)"Apres mmap video");
070                                                   070 
071   /* Do some forks to complicate things */        071   /* Do some forks to complicate things */
072   fork();                                         072   fork();
073   fork();                                         073   fork();
074                                                   074 
075   /* Write a string into it: it should NOT be     075   /* Write a string into it: it should NOT be printed on screen since
076      the mapping is private */                    076      the mapping is private */
077   strzcpy(zoup + 80*5*2 + 10*2,                   077   strzcpy(zoup + 80*5*2 + 10*2,
078           "Y o u   c a n n o t   S e e   T h i    078           "Y o u   c a n n o t   S e e   T h i s ! ",
079           250);                                   079           250);
080                                                   080 
081   /* Test /dev/kmem */                            081   /* Test /dev/kmem */
082                                                   082 
083   /* remap some kernel pages in user space. We    083   /* remap some kernel pages in user space. We'd better map this in
084      "private" mode here, this way we can do w    084      "private" mode here, this way we can do whatever we like in this
085      area. If we'd mapped it read/write, this     085      area. If we'd mapped it read/write, this would overwrite kernel
086      data/code, causing a crash sooner or late    086      data/code, causing a crash sooner or later. */
087   fd = open("/dev/kmem", O_RDWR);                 087   fd = open("/dev/kmem", O_RDWR);
088   zoup = mmap(0, 100*4096, PROT_READ | PROT_WR    088   zoup = mmap(0, 100*4096, PROT_READ | PROT_WRITE,
089               0 /* private */,                    089               0 /* private */,
090               fd, 0x00201000);                    090               fd, 0x00201000);
091   close(fd);                                      091   close(fd);
092   bochs_printf("mapped kmem @%x\n", (unsigned)    092   bochs_printf("mapped kmem @%x\n", (unsigned)zoup);  
093   _sos_syscall1(4004, (unsigned)"Apres mmap ke    093   _sos_syscall1(4004, (unsigned)"Apres mmap kernel");
094                                                   094 
095   /* Do some forks to complicate things */        095   /* Do some forks to complicate things */
096   fork();                                         096   fork();
097   fork();                                         097   fork();
098                                                   098 
099   /* Overwriting our private "copy" of kernel     099   /* Overwriting our private "copy" of kernel */
100   memset(zoup, 0x0, 10*4096);                     100   memset(zoup, 0x0, 10*4096);
101   _sos_syscall1(4004, (unsigned)"Apres memset     101   _sos_syscall1(4004, (unsigned)"Apres memset kernel");
102                                                   102 
103   return 0;                                       103   return 0;
104 }                                                 104 }
                                                      

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