This is the mail archive of the
mailing list for the Cygwin project.
Re: sem_init() fails (when used in a certain way)
On Mar 30 01:35, Christopher Faylor wrote:
> On Tue, Mar 29, 2011 at 11:38:32PM +0200, Corinna Vinschen wrote:
> >On Mar 29 13:24, Christopher Faylor wrote:
> >> I think we should put a
> >> myfault efault;
> >> if (efault.faulted ())
> >> ...
> >> in place of the is_good_object() test and sprinkle those throughout the
> >> other sem_* functions, if they're not already there.
> >You can't just replace all is_good_object tests with myfault handlers,
> >afaics. The only case where the is_good_object test doesn't make sense
> >for the reason outlined in Jon's mail are the init methods of the
> >various object types. In all other methods the is_good_object test is
> >still necessary to check the object pointer and to generate the EINVAL
> >error code reliably. So the myfault handler could (and probably
> >should) be added to these methods while keeping the is_good_object
> The reason I mentioned putting them in the functions rather than an init
> function is to catch any subsequent problems with dereferencing invalid
> pointers. If you put a handler in the init function then it is only
> valid for the life of the init function. I wasn't suggesting replacing
> all of the is_good_object tests, though, just the one that Jon
Thanks for clarifying. We just have to keep in mind to return EINVAL
rather than EFAULT.
Btw., glibc does not test the validity of the semaphore at all. If you
give an invalid sem pointer to the sem functions, it just crashes:
$ cat > sem.c <<EOF
int ret = sem_wait ((sem_t *) NULL);
printf ("%d\n", errno);
$ gcc -g -o sem sem.c -lpthread
Segmentation fault (core dumped)
I assume the glibc code is trimmed for speed in the first place. If
you're using an invalid semaphore you get what you deserve.
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Project Co-Leader cygwin AT cygwin DOT com