winelib shared memory problem

Open forum for end-user questions about Wine. Before asking questions, check out the Wiki as a first step.
Forum Rules
Locked
AleXoundOS
Newbie
Newbie
Posts: 2
Joined: Fri Feb 03, 2012 7:29 pm

winelib shared memory problem

Post by AleXoundOS »

Hi

I have two programs:
  • The first is a windows binary compiled in Visual C++ which acts like a Server.
    The second program is a Client, which I compile from sources.
Both are written in C++.
Server and client communicate using two IPC mechanisms: named pipe and shared memory. shared memory consists of a structure, e.g.:

Code: Select all

struct GameData
Using mingw compiler Client compiles well. Then I launch Server and Client using wine and they connect using both IPC mechanisms properly.

Compiling using winelib also works. But when winelib compiled Client tries to connect with the Server and read shared memory, it fails to read anything properly from the shared memory. I found that it is only able to read one element of the structure properly which appears to be the first element in the shared memory. named pipe connection works without any problems.

After some googling I found that using different compilers may lead to differences in ABI (Application Binary Interface). So I apologized that different compilers can store information using structures differently.
If it is the reason of the problem, then why mingw compiled program matches the Visual C++ ABI and winelib not?
I also tried different -fabi-version=n options for wineg++. But the issue remained. (May be I needed to use this option in conjunction with some other options to get effect?)

Is there a way to solve the problem? Or is there a way to write the structures code in the Server in a way that can be understandable by other compilers? I can ask the author of the Server to rewrite some code, but if it will not require big changes in the code. Compiling the Server using winelib seems to be too complex task, it uses lots of things that are not friendly to gcc.

May be it is not related to ABI?

My aim is to compile Client using winelib, so being able to use linux calls from Client program.

My specs:
wine-1.4-rc2
gcc 4.6.2
mingw32-gcc 4.6.2
Arch Linux x86_64
I'm using glibc library for winelib.
AleXoundOS
Newbie
Newbie
Posts: 2
Joined: Fri Feb 03, 2012 7:29 pm

winelib shared memory problem

Post by AleXoundOS »

I have solved the problem with faulty read/write of structure, which was created by Server. This article helped me a lot in understanding the problem.
Since the Server was compiled in VC++ under windows, it uses different way of storing binary data or being more exact "Data Structure Alignment" than gcc on Linux. As I figured out two main issues that can arise when using structures in different systems are "data alignment" and "data structure padding", which must match on both sides.
Apparently in my case "data structure padding" has matched between VC++ on Windows and wineg++ on Linux. So I haven't added any "#pragma pack(n)" lines into the code.
But "data alignment" was different. Unexpectedly the exact solution was found in wikipedia that came with "-malign-double" option to gcc compiler. By default on Windows "double" and "long double" types are 8-byte aligned and on Linux 4-byte aligned. This option instructs the gcc compiler to use 8-byte alignment for these types.
Locked