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/myprog11.c (Article 9) and /userland/myprog11.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 <stdarg.h>                               021 #include <stdarg.h>
022 #include <debug.h>                                022 #include <debug.h>
023                                                   023 
024                                                   024 
025 /**                                               025 /**
026  * @file myprog11.c                               026  * @file myprog11.c
027  *                                                027  *
028  * mresize tests                                  028  * mresize tests
029  *                                                029  *
030  * We use the temporary syscall 4004 to dump t    030  * We use the temporary syscall 4004 to dump the list of VRs in the
031  * thread's address space                         031  * thread's address space
032  */                                               032  */
033                                                   033 
034                                                   034 
035 int main()                                     !! 035 int main(void)
036 {                                                 036 {
037   void * moved;                                   037   void * moved;
038   char * zoup;                                    038   char * zoup;
039   int fd;                                         039   int fd;
040                                                   040 
041   fd = open("/dev/zero", O_RDWR);                 041   fd = open("/dev/zero", O_RDWR);
042   zoup = mmap((void*)4096, 8*1024*1024,           042   zoup = mmap((void*)4096, 8*1024*1024,
043               PROT_READ | PROT_WRITE,             043               PROT_READ | PROT_WRITE,
044               MAP_SHARED,                         044               MAP_SHARED,
045               fd, 34);                            045               fd, 34);
046   close(fd);                                      046   close(fd);
047                                                   047 
048   bochs_printf("mapped @%x\n", (unsigned)zoup)    048   bochs_printf("mapped @%x\n", (unsigned)zoup);
049                                                   049 
050   /* Do some forks to complicate things */        050   /* Do some forks to complicate things */
051   fork();                                         051   fork();
052   fork();                                         052   fork();
053                                                   053 
054   /* First, split the region in slices using a    054   /* First, split the region in slices using a sequence of
055      mprotects */                                 055      mprotects */
056   _sos_syscall1(4004, (unsigned)"Initial");       056   _sos_syscall1(4004, (unsigned)"Initial");
057   mprotect(zoup, 10*4096, PROT_READ);             057   mprotect(zoup, 10*4096, PROT_READ);
058   zoup += 10*4096;                                058   zoup += 10*4096;
059   _sos_syscall1(4004, (unsigned)"After mprotec    059   _sos_syscall1(4004, (unsigned)"After mprotect Low");
060                                                   060 
061   mprotect(zoup-4096, 2*4096, PROT_READ);         061   mprotect(zoup-4096, 2*4096, PROT_READ);
062   zoup += 4096;                                   062   zoup += 4096;
063   _sos_syscall1(4004, (unsigned)"After mprotec    063   _sos_syscall1(4004, (unsigned)"After mprotect Before Low");
064                                                   064 
065   mprotect(zoup-4096, 4096, PROT_READ);           065   mprotect(zoup-4096, 4096, PROT_READ);
066   _sos_syscall1(4004, (unsigned)"After mprotec    066   _sos_syscall1(4004, (unsigned)"After mprotect Before low (bis)");
067                                                   067 
068   mprotect(zoup + 1024*1024, 4096, PROT_READ);    068   mprotect(zoup + 1024*1024, 4096, PROT_READ);
069   _sos_syscall1(4004, (unsigned)"After mprotec    069   _sos_syscall1(4004, (unsigned)"After mprotect Middle");
070                                                   070 
071   mprotect(zoup + 1024*1024, 4096, PROT_READ);    071   mprotect(zoup + 1024*1024, 4096, PROT_READ);
072   _sos_syscall1(4004, (unsigned)"After mprotec    072   _sos_syscall1(4004, (unsigned)"After mprotect Middle (bis)");
073                                                   073 
074   mprotect(zoup + 8*1024*1024 - 11*4096 - 4096    074   mprotect(zoup + 8*1024*1024 - 11*4096 - 4096, 4096, PROT_READ);
075   _sos_syscall1(4004, (unsigned)"After mprotec    075   _sos_syscall1(4004, (unsigned)"After mprotect High");
076                                                   076 
077   mprotect(zoup + 8*1024*1024 - 11*4096 - 2*40    077   mprotect(zoup + 8*1024*1024 - 11*4096 - 2*4096, 3*4096, PROT_READ);
078   _sos_syscall1(4004, (unsigned)"After mprotec    078   _sos_syscall1(4004, (unsigned)"After mprotect Past High");
079                                                   079 
080   mprotect((void*)0x40000000, 0x10000000, PROT    080   mprotect((void*)0x40000000, 0x10000000, PROT_READ);
081   _sos_syscall1(4004, (unsigned)"After mprotec    081   _sos_syscall1(4004, (unsigned)"After mprotect Complete VR");
082                                                   082 
083   mprotect((void*)0x40000000, 0x10000000, PROT    083   mprotect((void*)0x40000000, 0x10000000, PROT_READ);
084   _sos_syscall1(4004, (unsigned)"After mprotec    084   _sos_syscall1(4004, (unsigned)"After mprotect Complete VR (bis)");
085                                                   085 
086   /* Now try to resize one of the VR */           086   /* Now try to resize one of the VR */
087   moved = zoup + 8*1024*1024 - 11*4096 - 10*40    087   moved = zoup + 8*1024*1024 - 11*4096 - 10*4096;
088   _sos_mresize(zoup + 8*1024*1024 - 11*4096 -     088   _sos_mresize(zoup + 8*1024*1024 - 11*4096 - 2*4096, 3*4096,
089                & moved, 40*4096, 0);              089                & moved, 40*4096, 0);
090   _sos_syscall1(4004, (unsigned)"After mremap     090   _sos_syscall1(4004, (unsigned)"After mremap (not allowed)");
091   bochs_printf("moved=%x\n", (unsigned)moved);    091   bochs_printf("moved=%x\n", (unsigned)moved);
092                                                   092 
093   _sos_mresize(zoup + 8*1024*1024 - 11*4096 -     093   _sos_mresize(zoup + 8*1024*1024 - 11*4096 - 2*4096, 4096,
094                & moved, 40*4096, 0);              094                & moved, 40*4096, 0);
095   _sos_syscall1(4004, (unsigned)"After mremap     095   _sos_syscall1(4004, (unsigned)"After mremap (not allowed - bis)");
096   bochs_printf("moved=%x\n", (unsigned)moved);    096   bochs_printf("moved=%x\n", (unsigned)moved);
097                                                   097 
098   _sos_mresize(zoup + 8*1024*1024 - 11*4096 -     098   _sos_mresize(zoup + 8*1024*1024 - 11*4096 - 2*4096, 4096,
099                & moved, 40*4096, MREMAP_MAYMOV    099                & moved, 40*4096, MREMAP_MAYMOVE);
100   _sos_syscall1(4004, (unsigned)"After mremap     100   _sos_syscall1(4004, (unsigned)"After mremap (DO move)");
101   bochs_printf("moved=%x\n", (unsigned)moved);    101   bochs_printf("moved=%x\n", (unsigned)moved);
102                                                   102 
103   _sos_mresize(moved, 4096,                       103   _sos_mresize(moved, 4096,
104                & moved, 100*4096, MREMAP_MAYMO    104                & moved, 100*4096, MREMAP_MAYMOVE);
105   _sos_syscall1(4004, (unsigned)"After mremap     105   _sos_syscall1(4004, (unsigned)"After mremap (DO move)");
106   bochs_printf("moved=%x\n", (unsigned)moved);    106   bochs_printf("moved=%x\n", (unsigned)moved);
107                                                   107 
108   return 0;                                       108   return 0;
109 }                                                 109 }
                                                      

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