public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* 64 bit Cywgin 2.5.2 on Wine: python fails with sem_init: Invalid argument
@ 2016-07-04  2:46 Qian Hong
  2016-07-04  9:52 ` Corinna Vinschen
  0 siblings, 1 reply; 2+ messages in thread
From: Qian Hong @ 2016-07-04  2:46 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 2820 bytes --]

Hi folks,

When compiling 64 bit Cygwin on Wine, I found a python{2,3} failure
when building documentation [1]:

xmlto --skip-validation --with-dblatex pdf -o cygwin-ug-net/ -m
/drone/src/github.com/cygwin/cygwin/winsup/doc/fo.xsl
/drone/src/github.com/cygwin/cygwin/winsup/doc/cygwin-ug-net.xml
sem_init: Invalid argument
Traceback (most recent call last):
  File "/usr/bin/dblatex", line 10, in <module>
    from dbtexmf.dblatex import dblatex
  File "/usr/lib/python2.7/site-packages/dbtexmf/dblatex/dblatex.py",
line 8, in <module>
    from dbtexmf.core.dbtex import DbTex, DbTexCommand
  File "/usr/lib/python2.7/site-packages/dbtexmf/core/dbtex.py", line
11, in <module>
    import urllib
  File "/usr/lib/python2.7/urllib.py", line 26, in <module>
    import socket
  File "/usr/lib/python2.7/socket.py", line 67, in <module>
    from _ssl import SSLError as sslerror
ImportError: cannot import name SSLError
make[3]: [Makefile:104: cygwin-ug-net/cygwin-ug-net.pdf] Error 1 (ignored)


According to my previous experience this happens with previous version
of Cygwin 64 bit on Wine, but works fine on Windows, and works fine on
32 bit Cygwin on Wine. I can't test latest git HEAD Cygwin version due
to another known failure.

I tried to track down the problem, and I found during the call of
sem_init(sem, pshared=0, value=1), in some case pshared and value were
unexpectedly changed to large integers after
verifyable_object_isvalid().

I tried to reproduce with a simplified test case, and got the below
code which behaviors wrong but not exactly in the same way:

#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <semaphore.h>
#include <pthread.h>


int
main(int argc, char *argv[])
{
    sem_t *p_sem = malloc(sizeof(sem_t));

    memset(p_sem, 0xcc, sizeof(sem_t)); /* trigger exception handling
code in Cygwin sem_init()-->verifyable_object_isvalid() */
    sem_init(p_sem, 0, 1);

    return 0;
}

Compiled using Cygwin gcc -pthread, The above code works fine on
Cygwin on Windows and 32 bit Cygwin on Wine, but causes a stack
overflow on 64 bit Cygwin on Wine. Unfortunately it does not fail
exatly in the same way to Cygiwn python, but at least it brings some
interesting question.

I think it is a Wine bug which does not handle exception correctly,
and I'm trying to track down deeper. At the time could anyone provide
some hint which piece of Cygwin code could I learn to write a pure
Win32 test case emulating the above example?

I also attached +seh log comparing 64 bit Cygwin and 32 bit Cygwin on
Wine, which show the stackoverflow on 64 bit but handles fine on 32
bit, hopefully that helps. I created a Wine bug on [2].

Thank you!


[1] https://tea-ci.org/cygwin/cygwin/4
[2] https://bugs.wine-staging.com/show_bug.cgi?id=691

-- 
Regards,
Qian Hong

-
http://www.winehq.org

[-- Attachment #2: sem_init.wine.seh.64.txt --]
[-- Type: text/plain, Size: 1992 bytes --]

00ec:trace:seh:raise_exception code=c0000005 flags=0 addr=0x180154e5e ip=180154e5e tid=00ec
00ec:trace:seh:raise_exception  rax=cccccccccccccccc rbx=0000000600010590 rcx=0000000600010590 rdx=00000000df0df04c
00ec:trace:seh:raise_exception  rsi=0000000000000001 rdi=0000000000000000 rbp=00000000ffffcc10 rsp=00000000ffffcb10
00ec:trace:seh:raise_exception   r8=0000000000000000  r9=0000000000000000 r10=00000000ffffcb40 r11=0000000100401130
00ec:trace:seh:raise_exception  r12=0000000000001000 r13=000000007b47ead0 r14=00007fffff7e8000 r15=00007fffffffc3f8
00ec:trace:seh:RtlVirtualUnwind type 1 rip 180154e5e rsp ffffcb10
00ec:trace:seh:dump_unwind_info **** func 114dc0-114eaa
00ec:trace:seh:dump_unwind_info unwind info at 0x1802cd50c flags 1 prolog 0x4 bytes function 0x180154dc0-0x180154eaa
00ec:trace:seh:dump_unwind_info     0x4: subq $0x58,%rsp
00ec:trace:seh:dump_unwind_info     handler 0x180071c30 data at 0x1802cd518
00ec:trace:seh:call_handler calling handler 0x180071c30 (rec=0xffffc9e0, frame=0xffffcb10 context=0xffffbab0, dispatch=0xffffb980)
00ec:Call ntdll.RtlUnwindEx(ffffcb10,180154e91,ffffc9e0,00000000,ffffbab0,ffffb9d0) ret=180071c5f
00ec:trace:seh:RtlUnwindEx code=c0000005 flags=2 end_frame=0xffffcb10 target_ip=0x180154e91 rip=000000007bc9d3ba
00ec:trace:seh:RtlUnwindEx  rax=000000000033fe80 rbx=000000000033fe80 rcx=00000000ffffbab0 rdx=0000000000000000
00ec:trace:seh:RtlUnwindEx  rsi=00000000ffffbab0 rdi=00000000ffffb250 rbp=00000000ffffbab0 rsp=00000000ffffb0b0
00ec:trace:seh:RtlUnwindEx   r8=00000000ffffc9e0  r9=0000000000000000 r10=00007ffff77bafe0 r11=00007ffff75856f0
00ec:trace:seh:RtlUnwindEx  r12=00000000ffffb250 r13=00000000ffffc9e0 r14=0000000180154e91 r15=00000000ffffb980
00ec:err:seh:setup_exception stack overflow 7472 bytes in thread 00ec eip 000000007bc99c63 esp 00000000ffff88d0 stack 0xffe00000-0xffffa000-0x100000000
00ec:warn:seh:abort_thread exit frame outside of stack limits in thread 00ec frame 0x33ff80 stack 0xffffa000-0x100000000


[-- Attachment #3: sem_init.wine.seh.32.txt --]
[-- Type: text/plain, Size: 498 bytes --]

00ca:trace:seh:raise_exception code=c0000005 flags=0 addr=0x61124db9 ip=61124db9 tid=00ca
00ca:trace:seh:raise_exception  info[0]=00000000
00ca:trace:seh:raise_exception  info[1]=ccccccd0
00ca:trace:seh:raise_exception  eax=cccccccc ebx=20010348 ecx=00000000 edx=6122aa90 esi=61320fe7 edi=0061ca04
00ca:trace:seh:raise_exception  ebp=0061ca08 esp=0061c9d0 cs=0023 ds=002b es=002b fs=0063 gs=006b flags=00010286
00ca:trace:seh:call_stack_handlers calling handler at 0x61031aa0 code=c0000005 flags=0

[-- Attachment #4: Type: text/plain, Size: 218 bytes --]

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: 64 bit Cywgin 2.5.2 on Wine: python fails with sem_init: Invalid argument
  2016-07-04  2:46 64 bit Cywgin 2.5.2 on Wine: python fails with sem_init: Invalid argument Qian Hong
@ 2016-07-04  9:52 ` Corinna Vinschen
  0 siblings, 0 replies; 2+ messages in thread
From: Corinna Vinschen @ 2016-07-04  9:52 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 3710 bytes --]

Hi Qian,

On Jul  4 10:45, Qian Hong wrote:
> Hi folks,
> 
> When compiling 64 bit Cygwin on Wine, I found a python{2,3} failure
> when building documentation [1]:
> 
> xmlto --skip-validation --with-dblatex pdf -o cygwin-ug-net/ -m
> /drone/src/github.com/cygwin/cygwin/winsup/doc/fo.xsl
> /drone/src/github.com/cygwin/cygwin/winsup/doc/cygwin-ug-net.xml
> sem_init: Invalid argument

What is python calling sem_init for here?!?  That means you need to
start cygserver just to build the Cygwin docs natively.  Oh well.

> [...]
> According to my previous experience this happens with previous version
> of Cygwin 64 bit on Wine, but works fine on Windows, and works fine on
> 32 bit Cygwin on Wine. I can't test latest git HEAD Cygwin version due
> to another known failure.

Yeah, Vista++ compatiblity...

> I tried to track down the problem, and I found during the call of
> sem_init(sem, pshared=0, value=1), in some case pshared and value were
> unexpectedly changed to large integers after
> verifyable_object_isvalid().
> 
> I tried to reproduce with a simplified test case, and got the below
> code which behaviors wrong but not exactly in the same way:
> 
> #include <unistd.h>
> #include <stdlib.h>
> #include <string.h>
> #include <semaphore.h>
> #include <pthread.h>
> 
> 
> int
> main(int argc, char *argv[])
> {
>     sem_t *p_sem = malloc(sizeof(sem_t));
> 
>     memset(p_sem, 0xcc, sizeof(sem_t)); /* trigger exception handling
> code in Cygwin sem_init()-->verifyable_object_isvalid() */

This is perfectly valid.  The verifyable_object_isvalid code performs
an access check which results in an exception for invalid objects,
but which is catched by the surrounding __try/__except code.

>     sem_init(p_sem, 0, 1);
> 
>     return 0;
> }
> 
> Compiled using Cygwin gcc -pthread, The above code works fine on
> Cygwin on Windows and 32 bit Cygwin on Wine, but causes a stack
> overflow on 64 bit Cygwin on Wine. Unfortunately it does not fail
> exatly in the same way to Cygiwn python, but at least it brings some
> interesting question.

Stack overflow sounds weird.  The execption handling in Cygwin isn't
perfect, but an exception in verifyable_object_isvalid should not screw
up the stack.

> I think it is a Wine bug which does not handle exception correctly,
> and I'm trying to track down deeper. At the time could anyone provide
> some hint which piece of Cygwin code could I learn to write a pure
> Win32 test case emulating the above example?

Have a look at verifyable_object_isvalid in general, plus how the
exception handling in Cygwin on 64 bit works.  I'd suggest to take
a look into the implementation of the __try/__except macros in cygtls.h
and the exception::myfault handler in exceptions.cc.

> I also attached +seh log comparing 64 bit Cygwin and 32 bit Cygwin on
> Wine, which show the stackoverflow on 64 bit but handles fine on 32
> bit, hopefully that helps. I created a Wine bug on [2].

Puh, I admit that it doesn't help me much.  As a rough guess I'd say
that the unwinder failed to unwind correctly for some reason, but I also
freely admit that my knowledge on 64 bit unwinding is not exactly
complete.  I wouldn't exclude the possibility of a bug in Cygwin here.

May I point out http://www.nynaeve.net/?p=113, which is the last part
of a series on 64 bit exception handling and which has pointers to all
previous parts of the series.  It helped me much to get 64bit exception
handling in Cygwin going.


HTH,
Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-07-04  9:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-04  2:46 64 bit Cywgin 2.5.2 on Wine: python fails with sem_init: Invalid argument Qian Hong
2016-07-04  9:52 ` Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).