Winelib Seg Fault - functions resolve to address zero

Questions about Wine on Linux
Locked
milesdavis
Newbie
Newbie
Posts: 1
Joined: Mon Aug 14, 2017 4:25 pm

Winelib Seg Fault - functions resolve to address zero

Post by milesdavis »

I am porting a visual c++ application from windows to ubuntu using winelib. At run time, I am getting segmentation faults when certain functions are called. In each case, the GDB backtrace for the core dump shows that the last stack frame was calling function 0x00000000. This has occured on various unrelated calls to memset, strcpy, inet_addr, and SHGetFolderPath. I have confirmed that the arguments being passed to these functions are not null. In fact, replacing memset with std:fill, or replacing strcpy with a for loop manually copying bytes removes the error. This leads me to believe that there's nothing wrong with the underlying char buffers. Then I discovered that the calls to memset and strcpy would succeed if -mno-cygwin was removed from the makefile (thus the calls are resolved to libc instead of wine's msvcrt). Similarly, I was able to get past the inet_addr error by wrapping it with a call to the linux arpa/inet.h definition instead of the wine windows.h definition. That said, when I created a standalone test program that called wine's inet_addr, no error occured. The error is only reproducible in my larger program.

As SHGetFolderPath does not have a linux equivalent, I haven't been able to get past this error as easily. Does anyone have any idea what could be amiss here?

I have reproduced this using wine 1.8 and a clean install of wine 2.0.2

Relevant code:
#define SUCCEEDED(hr) (((HRESULT)(hr)) >= 0) // putting this here so SUCCEEDED is definitely defined
void classname::functionname(CHAR* prefixpath)
{
TCHAR lpPath[MAX_USER_NAME_LEN] = {NULL};

cout << (void*)SHGetFolderPath << endl;
cout << (void*)SHGetFolderPathA << endl;
cout << CSIDL_COMMON_APPDATA << endl;
cout << lpPath << endl;

if (SUCCEEDED(SHGetFolderPath(0, CSIDL_COMMON_APPDATA, NULL, 0, lpPath)))

Output:
> wine nameofprogram.exe.so

Code: Select all

0x7defb820
0x7defb820
35

Segmentation fault (core dumped)
Backtrace:
>gdb wine /tmp/nameofcore

Code: Select all

GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from wine...Reading symbols from /usr/lib/debug/.build-id/04/7f2ad86868be8f73f32ac6f05512a4d07ce88f.debug...done.
done.

warning: core file may not match specified executable file.
[New LWP 15385]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by 'nameofprogram.exe.so
        '.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00000000 in ?? () 
> (gdb) bt
#0 0x00000000 in ?? ()
#1 0x7ab84308 in nameofclass::nameoffunction (this=0xff8521e1,
prefixpath=0xff85099c "") at nameoffile:1678
...
> (gdb) frame 1

Code: Select all

#1  0x7ab84308 in nameofclass::nameoffunction (this=0xff8521e1, 
    prefixpath=0xff85099c "") at nameoffile:1678
1678	    if (SUCCEEDED(SHGetFolderPath(0, CSIDL_COMMON_APPDATA, NULL, 0, lpPath)))
Thanks for your help
Locked