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


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;
034                                                   035 
                                                   >> 036   fd = open("/dev/zero", O_RDWR);
035   zoup = mmap((void*)4096, 8*1024*1024,           037   zoup = mmap((void*)4096, 8*1024*1024,
036               PROT_READ | PROT_WRITE,             038               PROT_READ | PROT_WRITE,
037               MAP_SHARED,                         039               MAP_SHARED,
038               "/dev/zero", 0x123456789012345UL !! 040               fd, 0x123456789012345ULL);
                                                   >> 041   close(fd);
                                                   >> 042 
039   bochs_printf("mapped @%x\n", (unsigned)zoup)    043   bochs_printf("mapped @%x\n", (unsigned)zoup);
040                                                   044 
041   switch (fork())                                 045   switch (fork())
042     {                                             046     {
043     case 0:                                       047     case 0:
044       bochs_printf("CHILD 1: %d %d\n", zoup[42    048       bochs_printf("CHILD 1: %d %d\n", zoup[42], zoup[43]);
045       for (i = 0 ; i < 1000000 ; i++)             049       for (i = 0 ; i < 1000000 ; i++)
046         zoup[43] = i / 19;                        050         zoup[43] = i / 19;
047       bochs_printf("CHILD 2: %d %d\n", zoup[42    051       bochs_printf("CHILD 2: %d %d\n", zoup[42], zoup[43]);
048       for (i = 0 ; i < 1000000 ; i++)             052       for (i = 0 ; i < 1000000 ; i++)
049         zoup[43] = i / 19;                        053         zoup[43] = i / 19;
050       bochs_printf("CHILD 3: %d %d\n", zoup[42    054       bochs_printf("CHILD 3: %d %d\n", zoup[42], zoup[43]);
051       break;                                      055       break;
052                                                   056 
053     default:                                      057     default:
054       bochs_printf("FATHER 1: %d %d\n", zoup[4    058       bochs_printf("FATHER 1: %d %d\n", zoup[42], zoup[43]);
055       for (i = 0 ; i < 1000000 ; i++)             059       for (i = 0 ; i < 1000000 ; i++)
056         zoup[42] = i / 17;                        060         zoup[42] = i / 17;
057       bochs_printf("FATHER 2: %d %d\n", zoup[4    061       bochs_printf("FATHER 2: %d %d\n", zoup[42], zoup[43]);
058       break;                                      062       break;
059     }                                             063     }
060                                                   064 
061   return 0;                                       065   return 0;
062 }                                                 066 }
                                                      

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