Bug 24020 – LUID is defined incorrectly in core.sys.windows.winnt

Status
NEW
Severity
normal
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2023-06-28T04:18:58Z
Last change time
2024-12-07T13:42:50Z
Assigned to
No Owner
Creator
bold.bell6556
Moved to GitHub: dmd#17464 →

Comments

Comment #0 by bold.bell6556 — 2023-06-28T04:18:58Z
The LUID struct is defined in the Windows headers as: typedef struct _LUID { DWORD LowPart; LONG HighPart; } LUID, *PLUID; However in druntime\import\core\sys\windows\winnt.d it is defined as: union LARGE_INTEGER { struct { uint LowPart; int HighPart; } long QuadPart; } alias LARGE_INTEGER LUID; This is a problem because these have different padding when used as a struct field. This can be seen when attempting to use the display config APIs. The header for queries is defined as: typedef struct DISPLAYCONFIG_DEVICE_INFO_HEADER { DISPLAYCONFIG_DEVICE_INFO_TYPE type; UINT32 size; LUID adapterId; UINT32 id; } DISPLAYCONFIG_DEVICE_INFO_HEADER; If we check the size of this structure in C, we get a result of 20 bytes. If we bring this over to D, using the definition of LUID from core.sys.windows.winnt, we get a result of 24 bytes. (The offsets of all fields are identical between both C and D). I confirmed that this is not a D compiler issue by switching LUID for LARGE_INTEGER in the C definition. After that change, the struct size increased to 24 bytes. I then altered the D code to use the correct definition for LUID and the size of the header struct decreased to the expected size of 20 bytes.
Comment #1 by robert.schadek — 2024-12-07T13:42:50Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17464 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB