On Sun, 2013-05-05 at 18:20 +0400, Anton Kozlov wrote:

> 
> So, the question is, what mechanism can be used to make bare version
> act     like libc one? I've tried to do STACK_REGISTER, but it brought
> no success. 
Increase the size of the stack. If you put 0x10000 instead of 0x1000,
then both versions are working (with or without libc).

>From what I understood debugging with GDB+vgdb, the difference of
behaviour is due to the different way the char stack[STACK_SZ];
is mapped, and the value of the stack ptr when SIGCHLD is received.
It looks like the char stack array is partially located in a "file" rw
mapping, and partially in a "anon" mapping.
When the signal is received, if the sigframe will overlap with the
part of stack in the file mapping, then Valgrind will believe it
has to grow the stack. With the libc version, the sigframe can be
fully in the anon segment, not with the "bare" version.
(I think the sigframe is about 1800 bytes).

(I was amazed to see that one single array can be mapped in two
different segments). But the below seems to indicate that quite
clearly:

bare
**3740** stack: id=1, begin=0x80493A0, end=0x804A3A0
--3740:0:aspacem    1:      0004000000-0008047fff     64m
--3740:0:aspacem    2: file 0008048000-0008048fff    4096 r-xT- d=0xfd00 
i=705272  o=0       (1)
--3740:0:aspacem    3: file 0008049000-0008049fff    4096 rw--- d=0xfd00 
i=705272  o=0       (1)
--3740:0:aspacem    4: anon 000804a000-000804afff    4096 rw---                 
                
--3740:0:aspacem    5: anon 000804b000-000804bfff    4096 rwx--
--3740:0:aspacem    6: RSVN 000804c000-000884afff 8384512 ----- SmLower
(gdb) p $sp /// when SIGCHLD rcvd
$1 = (void *) 0x804a368 <stack+4040>

with libc:
**3721** stack: id=1, begin=0x8049860, end=0x804A860
--3721:0:aspacem   18:      0004028000-0008047fff     64m
--3721:0:aspacem   19: file 0008048000-0008048fff    4096 r-xT- d=0xfd00 
i=705463  o=0       (1)
--3721:0:aspacem   20: file 0008049000-0008049fff    4096 rw--- d=0xfd00 
i=705463  o=0       (1)
--3721:0:aspacem   21: anon 000804a000-000804afff    4096 rw---                 
                
--3721:0:aspacem   22: anon 000804b000-000804bfff    4096 rwx--
--3721:0:aspacem   23: RSVN 000804c000-000884afff 8384512 ----- SmLower
--3721:0:aspacem   24:      000884b000-0037ffffff    759m
(gdb) p $sp /// when SIGCHLD rcvd
$1 = (void *) 0x804a854 <stack+4084>

If you slightly extend the stack needed with the libc version, then you get the
same behaviour:
==3894== Can't extend stack to 0x8049fa0 during signal delivery for thread 1:
==3894==   no stack segment
(I have introduced a function
void bpause()
{
  char truc[400];
  pause();
}

and calls bpause instead of pause in main.

Philippe



------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite
It's a free troubleshooting tool designed for production
Get down to code-level detail for bottlenecks, with <2% overhead.
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap2
_______________________________________________
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users

Reply via email to