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/myprog7.c (Article 9) and /userland/myprog7.c (Article 7.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 <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 static unsigned rien[16384];                      023 static unsigned rien[16384];
024                                                   024 
025                                                   025 
026 /**                                               026 /**
027  * @file myprog7.c                                027  * @file myprog7.c
028  * Tests forks and make sure that private mapp    028  * Tests forks and make sure that private mappings (eg the '.data'
029  * section of the program object file) are rea    029  * section of the program object file) are really private
030  */                                               030  */
031                                                   031 
032                                                   032 
033 static void assign(unsigned * addr, const unsi    033 static void assign(unsigned * addr, const unsigned val)
034 {                                                 034 {
035   bochs_printf("[0x%x]=0x%x <- 0x%x\n", (unsig    035   bochs_printf("[0x%x]=0x%x <- 0x%x\n", (unsigned)addr, *addr, val);
036   *addr = val;                                    036   *addr = val;
037   bochs_printf(" ===> 0x%x\n", *addr);            037   bochs_printf(" ===> 0x%x\n", *addr);
038 }                                                 038 }
039                                                   039 
040                                                   040 
041 int main()                                        041 int main()
042 {                                                 042 {
043   int i, level;                                   043   int i, level;
044                                                   044   
045   bochs_printf("myprog7: Hello\n");               045   bochs_printf("myprog7: Hello\n");
046                                                   046 
047   assign(& rien[0], 0x42);                        047   assign(& rien[0], 0x42);
048   assign(& rien[1000], 0x42);                     048   assign(& rien[1000], 0x42);
049                                                   049 
050   level = 0;                                      050   level = 0;
051   for (i = 0 ; i < 10 ; i++)                      051   for (i = 0 ; i < 10 ; i++)
052     {                                             052     {
053       pid_t fork_status;                          053       pid_t fork_status;
054                                                   054 
055       fork_status = fork();                       055       fork_status = fork();
056       if (fork_status == 0)                       056       if (fork_status == 0)
057         {                                         057         {
058           level ++;                               058           level ++;
059           bochs_printf("myprog7: I am the chil    059           bochs_printf("myprog7: I am the child %d %d\n", level, i);
060                                                   060 
061           assign(& rien[0], 0x0f<<24 | (level     061           assign(& rien[0], 0x0f<<24 | (level << 8) | i);
062           assign(& rien[1000], 0x0a<<24 | (lev    062           assign(& rien[1000], 0x0a<<24 | (level << 8) | i);
063                                                   063 
064           if ((i % 2) == 0)                       064           if ((i % 2) == 0)
065             {                                     065             {
066               char strprog[20];                   066               char strprog[20];
067               snprintf(strprog, sizeof(strprog    067               snprintf(strprog, sizeof(strprog), "myprog%d", i/2 + 1);
068               exec(strprog);                      068               exec(strprog);
069             }                                     069             } 
070         }                                         070         }
071       else if (fork_status > 0)                   071       else if (fork_status > 0)
072         {                                         072         {
073           bochs_printf("myprog7: I am the fath    073           bochs_printf("myprog7: I am the father %d %d\n", level, i);
074                                                   074 
075           assign(& rien[0], 0x8f<<24 | (level     075           assign(& rien[0], 0x8f<<24 | (level << 8) | i);
076           assign(& rien[1000], 0x8a<<24 | (lev    076           assign(& rien[1000], 0x8a<<24 | (level << 8) | i);
077         }                                         077         }
078       else                                        078       else
079         bochs_printf("myprog7: fork error %d !    079         bochs_printf("myprog7: fork error %d !\n", fork_status);
080     }                                             080     }
081                                                   081 
082   bochs_printf("myprog7: The end %d %d\n", lev    082   bochs_printf("myprog7: The end %d %d\n", level, i);
083   assign(& rien[0], 0xff<<24 | (level << 8) |     083   assign(& rien[0], 0xff<<24 | (level << 8) | i);
084   assign(& rien[1000], 0xfa<<24 | (level << 8)    084   assign(& rien[1000], 0xfa<<24 | (level << 8) | i);
085                                                   085 
086   return 0;                                       086   return 0;
087 }                                                 087 }
                                                      

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