Re: sem_open really strange behavior

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a very good explanation. Now it is clear for me and my program is finally running ok.

Thanks to all.


On 22-06-2010 9:46, Cedric Roux wrote:
Sergio Sobarzo wrote:
Thanks a lot Andrew,

I read that paragraph thousand of times. However it is not an answer why it works if a line is commented or not. I cannot figure an acceptable explanation, that's why I thought it will be a gcc question.

It's because of the stack. Probably on your host (x86 I guess?)
arguments to functions are passed on the stack.
On your case you forget to pass two arguments, but sem_open
will read something from the stack anyway, most
certainly garbage. "Invalid argument" is documented in
the manpage I have here as
"EINVAL value was greater than SEM_VALUE_MAX".

Adding a local variable to a function modifies the layout and
content of the stack.
One time you will be lucky. The other one no. In any case,
you have a bug in your program.

Something like that. To fully understand try to trace your
program at the assembly level and see how the arguments are
smoked from the stack in sem_open (or read the sources of
the C library, you might get some clues too).

Hope that helps.
Cédric.



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux