Cywin Support
Cywin allows for source-level portability of POSIX program on Windows. As such, it must emulate the POSIX semantics on top of the Win32 API, providing for a good test case of any Win32 implementation. This task is tracked as Bug #443.
Like any such emulation, this is likely to push the Win32 API to its limits. It will not be easy to get the entire Cygwin suite running on top of Wine, but we do have the Cygwin sources which may help us understand more readily what the problems are.
For Wine, the upside would be a very good test suite, and a much solid implementation of the fundamental Win32 APIs.
Probably the most fundamental and at the same time difficult to emulate POSIX call is fork(2). Cygwin must jump through a lot of hoops to do so on top of Win32 (see fork.cc).
As a result, a good start would be to get a simple program compiled under Cygwin that uses fork() to run under Wine.
The program (fork.c) is rather simple:
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <errno.h>
4 #include <unistd.h>
5 #include <sys/types.h>
6 #include <sys/wait.h>
7
8 main()
9 {
10 pid_t pid;
11 int rv;
12
13 pid=fork();
14
15 if (pid < 0) {
16 perror("fork"); /* something went wrong */
17 exit(1); /* parent exits */
18 }
19
20 if (pid == 0) {
21 printf(" CHILD: My PID is %d\n", getpid());
22 printf(" CHILD: My parent's PID is %d\n", getppid());
23 printf(" CHILD: Enter my exit status (make it small): ");
24 scanf(" %d", &rv);
25 printf(" CHILD: You have entered exit status: %d\n", rv);
26 exit(rv);
27 } else {
28 printf("PARENT: My PID is %d\n", getpid());
29 printf("PARENT: My child's PID is %d\n", pid);
30 printf("PARENT: I'm now waiting for my child to exit()...\n");
31 wait(&rv);
32 printf("PARENT: My child's exit status is: %d\n", WEXITSTATUS(rv));
33 }
34 }
35 ~
To compile and run under Cygwin, you simply do:
$ gcc -o fork.exe fork.c $ ./fork.exe PARENT: My PID is 284 PARENT: My child's PID is 1620 PARENT: I'm now waiting for my child to exit()... CHILD: My PID is 1620 CHILD: My parent's PID is 284 CHILD: Enter my exit status (make it small): 12 CHILD: You have entered exit status: 12 PARENT: My child's exit status is: 12
When run under Wine however, you currently get:
[dimi@dimi cygwin]$ wine fork.exe
34 [main] ? (8) cygheap_user::init: GetTokenInformation (TokenUser), Win32 error 5
fixme:advapi:ImpersonateLoggedOnUser ((nil)):stub returning FALSE
fixme:advapi:ImpersonateLoggedOnUser ((nil)):stub returning FALSE
4930 [main] ? (8) _dll_crt0: internal error: couldn't determine location of thread function on stack. Expect signal problems.
fixme:advapi:ImpersonateLoggedOnUser ((nil)):stub returning FALSE
fixme:advapi:ImpersonateLoggedOnUser ((nil)):stub returning FALSE
fixme:ntdll:NtQueryObject Unsupported information class 1
fixme:ntdll:NtQueryObject Unsupported information class 1
fixme:advapi:ImpersonateLoggedOnUser ((nil)):stub returning FALSE
1664845 [main] fork 12 _dll_crt0: internal error: couldn't determine location of thread function on stack. Expect signal problems.
fixme:advapi:ImpersonateLoggedOnUser ((nil)):stub returning FALSE
fixme:advapi:ImpersonateLoggedOnUser ((nil)):stub returning FALSE
fixme:advapi:ImpersonateLoggedOnUser ((nil)):stub returning FALSE
fixme:ntdll:NtQueryVolumeInformationFile 0x8: volume info not supported
err:seh:raise_exception Exception frame is not in stack limits => unable to dispatch exception.
1675967 [main] fork 8 _cygtls::handle_exceptions: Exception: STATUS_ACCESS_VIOLATION
1678416 [main] fork 8 open_stackdumpfile: Dumping stack trace to fork.exe.stackdump
Segmentation fault
Please note that to run it under Wine, I had to copy fork.exe, as well as /bin/cygwin1.dll from the Cygwin install to the Wine environment.
