001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019 #include <crt.h>
020 #include <libc.h>
021 #include <stdarg.h>
022 #include <debug.h>
023
024
025
026
027
028
029
030
031
032
033 int main(void)
034 {
035 char * zoup;
036 int fd;
037
038 fd = open("/dev/zero", O_RDWR);
039 zoup = mmap((void*)4096, 8*1024*1024,
040 PROT_READ | PROT_WRITE,
041 MAP_SHARED,
042 fd, 34);
043 close(fd);
044
045 bochs_printf("mapped @%x\n", (unsigned)zoup);
046
047
048 fork();
049 fork();
050
051 _sos_syscall1(4004, (unsigned)"Initial");
052 mprotect(zoup, 10*4096, PROT_READ);
053 zoup += 10*4096;
054 _sos_syscall1(4004, (unsigned)"After mprotect Low");
055
056 mprotect(zoup-4096, 2*4096, PROT_READ);
057 zoup += 4096;
058 _sos_syscall1(4004, (unsigned)"After mprotect Before Low");
059
060 mprotect(zoup-4096, 4096, PROT_READ);
061 _sos_syscall1(4004, (unsigned)"After mprotect Before low (bis)");
062
063 mprotect(zoup + 1024*1024, 4096, PROT_READ);
064 _sos_syscall1(4004, (unsigned)"After mprotect Middle");
065
066 mprotect(zoup + 1024*1024, 4096, PROT_READ);
067 _sos_syscall1(4004, (unsigned)"After mprotect Middle (bis)");
068
069 mprotect(zoup + 8*1024*1024 - 11*4096 - 4096, 4096, PROT_READ);
070 _sos_syscall1(4004, (unsigned)"After mprotect High");
071
072 mprotect(zoup + 8*1024*1024 - 11*4096 - 2*4096, 3*4096, PROT_READ);
073 _sos_syscall1(4004, (unsigned)"After mprotect Past High");
074
075 mprotect((void*)0x40000000, 0x10000000, PROT_READ);
076 _sos_syscall1(4004, (unsigned)"After mprotect Complete VR");
077
078 mprotect((void*)0x40000000, 0x10000000, PROT_READ);
079 _sos_syscall1(4004, (unsigned)"After mprotect Complete VR (bis)");
080
081 return 0;
082 }