[HACK] Re: Who understands this code?

Greg Schafer gschafer at zip.com.au
Sat Mar 15 15:24:21 PST 2003


On Sat, Mar 15, 2003 at 05:54:41PM -0500, Donald Smith wrote:
> //okay put this after the char *x,...
> 
> int i;
> 
> //then before the if (y != x + pg):
> 
> for (i = 0; i < 8; i++) /* limit to 8 tries */
>   {
>     if (y != x + pg)
>       {
>         x = y;
>         y = anonmap(pg);
>         if (y == (char *)MAP_FAILED)
>           perror_exit ("test 3 mmap 3", 15);
>       }
>     else
>         break; /* got one */
>   }
> 
> // this code is untested! don't even know if it compiles. I think break 
> is the correct instruction to use.

Thanks Don. It compiles and even appears to do the right thing! I just tried
ld.so.cache sizes of 3102, 6151 & 29741 and it seemed to do the right thing
on all accounts.

The straces are attached for your perusal.

Greg
-------------- next part --------------
execve("./ct-mmap.bad", ["./ct-mmap.bad"], [/* 8 vars */]) = 0
uname({sys="Linux", node="tigers-lfs", ...}) = 0
brk(0)                                  = 0x8049f84
open("/etc/ld.so.preload", O_RDONLY)    = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY)      = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=3102, ...}) = 0
mmap2(NULL, 3102, PROT_READ, MAP_PRIVATE, 3, 0) = 0x40014000
close(3)                                = 0
open("/lib/libc.so.6", O_RDONLY)        = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\340[\1"..., 1024) = 1024
fstat64(3, {st_mode=S_IFREG|0755, st_size=1263608, ...}) = 0
mmap2(NULL, 1254820, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) = 0x40015000
mprotect(0x40140000, 30116, PROT_NONE)  = 0
mmap2(0x40140000, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3, 0x12a) = 0x40140000
mmap2(0x40145000, 9636, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x40145000
close(3)                                = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40148000
munmap(0x40014000, 3102)                = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40014000
munmap(0x40014000, 4096)                = 0
mmap2(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40149000
rt_sigaction(SIGSEGV, {0x80485b3, [SEGV], SA_RESTART|0x4000000}, {SIG_DFL}, 8) = 0
munmap(0x4014a000, 4096)                = 0
--- SIGSEGV (Segmentation fault) ---
rt_sigprocmask(SIG_UNBLOCK, [SEGV], NULL, 8) = 0
munmap(0x40149000, 4096)                = 0
mmap2(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40149000
rt_sigaction(SIGSEGV, {0x80485b3, [SEGV], SA_RESTART|0x4000000}, {0x80485b3, [SEGV], SA_RESTART|0x4000000}, 8) = 0
munmap(0x40149000, 4096)                = 0
--- SIGSEGV (Segmentation fault) ---
rt_sigprocmask(SIG_UNBLOCK, [SEGV], NULL, 8) = 0
munmap(0x4014a000, 4096)                = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40014000
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40149000
write(2, "test 3 nonconsecutive pages - 40"..., 49) = 49
semget(16, 0, 0)                        = -1 ENOSYS (Function not implemented)
_exit(16)                               = ?
-------------- next part --------------
execve("./ct-mmap.good", ["./ct-mmap.good"], [/* 8 vars */]) = 0
uname({sys="Linux", node="tigers-lfs", ...}) = 0
brk(0)                                  = 0x8049fc4
open("/etc/ld.so.preload", O_RDONLY)    = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY)      = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=3102, ...}) = 0
mmap2(NULL, 3102, PROT_READ, MAP_PRIVATE, 3, 0) = 0x40014000
close(3)                                = 0
open("/lib/libc.so.6", O_RDONLY)        = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\340[\1"..., 1024) = 1024
fstat64(3, {st_mode=S_IFREG|0755, st_size=1263608, ...}) = 0
mmap2(NULL, 1254820, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) = 0x40015000
mprotect(0x40140000, 30116, PROT_NONE)  = 0
mmap2(0x40140000, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3, 0x12a) = 0x40140000
mmap2(0x40145000, 9636, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x40145000
close(3)                                = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40148000
munmap(0x40014000, 3102)                = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40014000
munmap(0x40014000, 4096)                = 0
mmap2(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40149000
rt_sigaction(SIGSEGV, {0x80485b3, [SEGV], SA_RESTART|0x4000000}, {SIG_DFL}, 8) = 0
munmap(0x4014a000, 4096)                = 0
--- SIGSEGV (Segmentation fault) ---
rt_sigprocmask(SIG_UNBLOCK, [SEGV], NULL, 8) = 0
munmap(0x40149000, 4096)                = 0
mmap2(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40149000
rt_sigaction(SIGSEGV, {0x80485b3, [SEGV], SA_RESTART|0x4000000}, {0x80485b3, [SEGV], SA_RESTART|0x4000000}, 8) = 0
munmap(0x40149000, 4096)                = 0
--- SIGSEGV (Segmentation fault) ---
rt_sigprocmask(SIG_UNBLOCK, [SEGV], NULL, 8) = 0
munmap(0x4014a000, 4096)                = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40014000
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40149000
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x4014a000
rt_sigaction(SIGSEGV, {0x80485b3, [SEGV], SA_RESTART|0x4000000}, {0x80485b3, [SEGV], SA_RESTART|0x4000000}, 8) = 0
munmap(0x40149000, 8192)                = 0
--- SIGSEGV (Segmentation fault) ---
rt_sigprocmask(SIG_UNBLOCK, [SEGV], NULL, 8) = 0
rt_sigaction(SIGSEGV, {0x80485b3, [SEGV], SA_RESTART|0x4000000}, {0x80485b3, [SEGV], SA_RESTART|0x4000000}, 8) = 0
--- SIGSEGV (Segmentation fault) ---
rt_sigprocmask(SIG_UNBLOCK, [SEGV], NULL, 8) = 0
semget(IPC_PRIVATE, 0, 0)               = -1 ENOSYS (Function not implemented)
_exit(0)                                = ?


More information about the lfs-dev mailing list