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/myprog8.c (Article 9) and /userland/myprog8.c (Article 8)


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 <libc.h>                                 019 #include <libc.h>
020 #include <stdarg.h>                               020 #include <stdarg.h>
021 #include <debug.h>                                021 #include <debug.h>
022                                                   022 
023                                                   023 
024 /**                                               024 /**
025  * @file myprog8.c                                025  * @file myprog8.c
026  * Make sure that shared mappings (here: anony    026  * Make sure that shared mappings (here: anonymous shared mapping) are
027  * really shared between father and child         027  * really shared between father and child
028  */                                               028  */
029                                                   029 
030 int main()                                        030 int main()
031 {                                                 031 {
032   int i;                                          032   int i;
033   char *zoup;                                     033   char *zoup;
034   int fd;                                      << 
035                                                << 
036   fd = open("/dev/zero", O_RDWR);              << 
037   zoup = mmap((void*)4096, 8*1024*1024,        << 
038               PROT_READ | PROT_WRITE,          << 
039               MAP_SHARED,                      << 
040               fd, 0x123456789012345ULL);       << 
041   close(fd);                                   << 
042                                                   034 
                                                   >> 035   zoup = fakemmap((void*)4096, 8*1024*1024,
                                                   >> 036                   PROT_READ | PROT_WRITE,
                                                   >> 037                   MAP_SHARED,
                                                   >> 038                   "/dev/zero", 0x123456789012345ULL);
043   bochs_printf("mapped @%x\n", (unsigned)zoup)    039   bochs_printf("mapped @%x\n", (unsigned)zoup);
044                                                   040 
045   switch (fork())                                 041   switch (fork())
046     {                                             042     {
047     case 0:                                       043     case 0:
048       bochs_printf("CHILD 1: %d %d\n", zoup[42    044       bochs_printf("CHILD 1: %d %d\n", zoup[42], zoup[43]);
049       for (i = 0 ; i < 1000000 ; i++)             045       for (i = 0 ; i < 1000000 ; i++)
050         zoup[43] = i / 19;                        046         zoup[43] = i / 19;
051       bochs_printf("CHILD 2: %d %d\n", zoup[42    047       bochs_printf("CHILD 2: %d %d\n", zoup[42], zoup[43]);
052       for (i = 0 ; i < 1000000 ; i++)             048       for (i = 0 ; i < 1000000 ; i++)
053         zoup[43] = i / 19;                        049         zoup[43] = i / 19;
054       bochs_printf("CHILD 3: %d %d\n", zoup[42    050       bochs_printf("CHILD 3: %d %d\n", zoup[42], zoup[43]);
055       break;                                      051       break;
056                                                   052 
057     default:                                      053     default:
058       bochs_printf("FATHER 1: %d %d\n", zoup[4    054       bochs_printf("FATHER 1: %d %d\n", zoup[42], zoup[43]);
059       for (i = 0 ; i < 1000000 ; i++)             055       for (i = 0 ; i < 1000000 ; i++)
060         zoup[42] = i / 17;                        056         zoup[42] = i / 17;
061       bochs_printf("FATHER 2: %d %d\n", zoup[4    057       bochs_printf("FATHER 2: %d %d\n", zoup[42], zoup[43]);
062       break;                                      058       break;
063     }                                             059     }
064                                                   060 
065   return 0;                                       061   return 0;
066 }                                                 062 }
                                                      

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