Skip to contentSkip to conversation

eal/windows: fix memory management macros usage

PATCH Applied Gregory Etelson 5 participants 9 messages Nov 14, 2023 – Nov 22, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 eal/windows: fix memory management macros usage

Windows compilation with cross-mingw on Fedora 39 failed because MEM_REPLACE_PLACEHOLDER and MEM_RESERVE_PLACEHOLDER were already defined in the compiler environment:

eal_memory.c:77: error: "MEM_REPLACE_PLACEHOLDER" redefined /usr/x86_64-w64-mingw32/sys-root/mingw/include/winnt.h:5710: note:
this is the location of the previous definition

eal_memory.c:78: error: "MEM_RESERVE_PLACEHOLDER" redefined /usr/x86_64-w64-mingw32/sys-root/mingw/include/winnt.h:5715: note:
this is the location of the previous definition

The patch masks MEM_REPLACE_PLACEHOLDER and MEM_RESERVE_PLACEHOLDER macros if they were pre-defined by compiler.

The patch also masks MEM_COALESCE_PLACEHOLDERS and MEM_PRESERVE_PLACEHOLDER to prevent similar errors.

Fixes 2a5d547a4a9b ("eal/windows: implement basic memory management")
---
 lib/eal/windows/eal_memory.c | 8 ++++++++
 1 file changed, 8 insertions(+)
lib/eal/windows/eal_memory.c +8 -0
index 215d768e2c..31410a41fd 100644
@@ -72,10 +72,18 @@ static VirtualAlloc2_type VirtualAlloc2_ptr;
 
 #ifdef RTE_TOOLCHAIN_GCC
 
+#ifndef MEM_COALESCE_PLACEHOLDERS
 #define MEM_COALESCE_PLACEHOLDERS 0x00000001
+#endif
+#ifndef MEM_PRESERVE_PLACEHOLDER
 #define MEM_PRESERVE_PLACEHOLDER  0x00000002
+#endif
+#ifndef MEM_REPLACE_PLACEHOLDER
 #define MEM_REPLACE_PLACEHOLDER   0x00004000
+#endif
+#ifndef MEM_RESERVE_PLACEHOLDER
 #define MEM_RESERVE_PLACEHOLDER   0x00040000
+#endif
 
 int
 eal_mem_win32api_init(void)
Signature · 1 line
2.39.2
Acked-by on v1 1/1
#1 lore raw
Quoted 15 lines · Gregory Etelson

Windows compilation with cross-mingw on Fedora 39 failed because MEM_REPLACE_PLACEHOLDER and MEM_RESERVE_PLACEHOLDER were already defined in the compiler environment:

eal_memory.c:77: error: "MEM_REPLACE_PLACEHOLDER" redefined /usr/x86_64-w64-mingw32/sys-root/mingw/include/winnt.h:5710: note:
this is the location of the previous definition

eal_memory.c:78: error: "MEM_RESERVE_PLACEHOLDER" redefined /usr/x86_64-w64-mingw32/sys-root/mingw/include/winnt.h:5715: note:
this is the location of the previous definition

The patch masks MEM_REPLACE_PLACEHOLDER and MEM_RESERVE_PLACEHOLDER macros if they were pre-defined by compiler.

Quoted 8 lines

The patch also masks MEM_COALESCE_PLACEHOLDERS and MEM_PRESERVE_PLACEHOLDER to prevent similar errors.

Fixes 2a5d547a4a9b ("eal/windows: implement basic memory management")

---

since we are duplicating something that comes from something else that has been duplicated out of windows WDK here it might be a reasonable safety check to verify that our duplicated values match our expectations?

#ifndef MEM_COALESCE_PLACEHOLDERS
#define MEM_COALESCE_PLACEHOLDERS 0x00000001
#else
static_assert(MEM_COALESCE_PLACEHOLDERS == 0x00000001, "...") #endif

either way, this is straight forward.

#2 lore raw

Hello Tyler,

Quoted 5 lines

since we are duplicating something that comes from something else that has been duplicated out of windows WDK here it might be a reasonable safety check to verify that our duplicated values match our expectations?

MEM_COALESCE_PLACEHOLDERS, MEM_PRESERVE_PLACEHOLDER, MEM_REPLACE_PLACEHOLDER and MEM_RESERVE_PLACEHOLDER are defined in Win32 API.

DPDK has no expectations about these values. DPDK needs them as parameters to the VirtualX function calls. It looks like the macros were added to EAL because they were missing in mingw.

Once compiler environment was fixed, the proper order was restored.

Regards,
Gregory

Quoted 12 lines

#ifndef MEM_COALESCE_PLACEHOLDERS
#define MEM_COALESCE_PLACEHOLDERS 0x00000001
#else
static_assert(MEM_COALESCE_PLACEHOLDERS == 0x00000001, "...") #endif

either way, this is straight forward.

#3 lore raw
Quoted 12 lines · Gregory

Hello Tyler,

Quoted 5 lines

since we are duplicating something that comes from something else that has been duplicated out of windows WDK here it might be a reasonable safety check to verify that our duplicated values match our expectations?

MEM_COALESCE_PLACEHOLDERS, MEM_PRESERVE_PLACEHOLDER, MEM_REPLACE_PLACEHOLDER and MEM_RESERVE_PLACEHOLDER are defined in Win32 API.

Quoted 6 lines

DPDK has no expectations about these values. DPDK needs them as parameters to the VirtualX function calls.
It looks like the macros were added to EAL because they were missing in mingw.

Once compiler environment was fixed, the proper order was restored.

yes, there is a lag between when names appear in the actual WDK and when mingw takes a the snapshot of the headers. so long as the copy they take is only from released WDK versions that align with an OS we shouldn't expect the values to change but if the duplicated names in dpdk were based upon an insider (preview version of SDK) value that later got changed there could be a misalignment. unlikely but possible.

Quoted 17 lines

Regards,
Gregory

Quoted 12 lines

#ifndef MEM_COALESCE_PLACEHOLDERS
#define MEM_COALESCE_PLACEHOLDERS 0x00000001
#else
static_assert(MEM_COALESCE_PLACEHOLDERS == 0x00000001, "...") #endif

either way, this is straight forward.

#4 lore raw

Hello Tyler,

Quoted 15 lines
Quoted 15 lines
Quoted 5 lines

since we are duplicating something that comes from something else that has been duplicated out of windows WDK here it might be a reasonable safety check to verify that our duplicated values match our expectations?

MEM_COALESCE_PLACEHOLDERS, MEM_PRESERVE_PLACEHOLDER, MEM_REPLACE_PLACEHOLDER and MEM_RESERVE_PLACEHOLDER are defined in Win32 API.

DPDK has no expectations about these values. DPDK needs them as parameters to the VirtualX function calls.
It looks like the macros were added to EAL because they were missing in mingw.

Quoted 9 lines
Quoted 1 line

Once compiler environment was fixed, the proper order was restored.

yes, there is a lag between when names appear in the actual WDK and when mingw takes a the snapshot of the headers. so long as the copy they take is only from released WDK versions that align with an OS we shouldn't expect the values to change but if the duplicated names in dpdk were based upon an insider (preview version of SDK) value that later got changed there could be a misalignment. unlikely but possible.

DPDK matrix works with official OS compiler versions.
Such compilers will not provide bad API.
As for non-official compilers or releases, they come without any warranty.

Regards,
Gregory

#5 lore raw
In reply to Tyler Retzlaff

2023-11-14 10:22 (UTC-0800), Tyler Retzlaff:

Quoted 18 lines · Gregory
Quoted 17 lines

Hello Tyler,

Quoted 5 lines

since we are duplicating something that comes from something else that has been duplicated out of windows WDK here it might be a reasonable safety check to verify that our duplicated values match our expectations?

MEM_COALESCE_PLACEHOLDERS, MEM_PRESERVE_PLACEHOLDER, MEM_REPLACE_PLACEHOLDER and MEM_RESERVE_PLACEHOLDER are defined in Win32 API.

DPDK has no expectations about these values. DPDK needs them as parameters to the VirtualX function calls.
It looks like the macros were added to EAL because they were missing in mingw.

Quoted 8 lines
Quoted 1 line

Once compiler environment was fixed, the proper order was restored.

yes, there is a lag between when names appear in the actual WDK and when mingw takes a the snapshot of the headers. so long as the copy they take is only from released WDK versions that align with an OS we shouldn't expect the values to change but if the duplicated names in dpdk were based upon an insider (preview version of SDK) value that later got changed there could be a misalignment. unlikely but possible.

I think we should trust the toolchain unless there is an known bug, i.e. the patch is good as-is.

Acked-by on v1 1/1
#6 lore raw
In reply to Gregory Etelson

2023-11-14 19:05 (UTC+0200), Gregory Etelson:

Quoted 15 lines

Windows compilation with cross-mingw on Fedora 39 failed because MEM_REPLACE_PLACEHOLDER and MEM_RESERVE_PLACEHOLDER were already defined in the compiler environment:

eal_memory.c:77: error: "MEM_REPLACE_PLACEHOLDER" redefined /usr/x86_64-w64-mingw32/sys-root/mingw/include/winnt.h:5710: note:
this is the location of the previous definition

eal_memory.c:78: error: "MEM_RESERVE_PLACEHOLDER" redefined /usr/x86_64-w64-mingw32/sys-root/mingw/include/winnt.h:5715: note:
this is the location of the previous definition

The patch masks MEM_REPLACE_PLACEHOLDER and MEM_RESERVE_PLACEHOLDER macros if they were pre-defined by compiler.

Quoted 7 lines

The patch also masks MEM_COALESCE_PLACEHOLDERS and MEM_PRESERVE_PLACEHOLDER to prevent similar errors.

Fixes 2a5d547a4a9b ("eal/windows: implement basic memory management")
#7 lore raw

14/11/2023 20:19, Dmitry Kozlyuk:

Quoted 19 lines

2023-11-14 19:05 (UTC+0200), Gregory Etelson:

Quoted 18 lines

Windows compilation with cross-mingw on Fedora 39 failed because MEM_REPLACE_PLACEHOLDER and MEM_RESERVE_PLACEHOLDER were already defined in the compiler environment:

eal_memory.c:77: error: "MEM_REPLACE_PLACEHOLDER" redefined /usr/x86_64-w64-mingw32/sys-root/mingw/include/winnt.h:5710: note:
this is the location of the previous definition

eal_memory.c:78: error: "MEM_RESERVE_PLACEHOLDER" redefined /usr/x86_64-w64-mingw32/sys-root/mingw/include/winnt.h:5715: note:
this is the location of the previous definition

The patch masks MEM_REPLACE_PLACEHOLDER and MEM_RESERVE_PLACEHOLDER macros if they were pre-defined by compiler.

The patch also masks MEM_COALESCE_PLACEHOLDERS and MEM_PRESERVE_PLACEHOLDER to prevent similar errors.

Quoted 6 lines
Quoted 4 lines
Fixes 2a5d547a4a9b ("eal/windows: implement basic memory management")
Acked-by Tyler Retzlaff Acked-by Dmitry Kozlyuk Acked-by Thomas Monjalon on v1 1/1 Applied
#8 lore raw
In reply to Gregory Etelson
Quoted 16 lines · Gregory Etelson

Windows compilation with cross-mingw on Fedora 39 failed because MEM_REPLACE_PLACEHOLDER and MEM_RESERVE_PLACEHOLDER were already defined in the compiler environment:

eal_memory.c:77: error: "MEM_REPLACE_PLACEHOLDER" redefined /usr/x86_64-w64-mingw32/sys-root/mingw/include/winnt.h:5710: note:
this is the location of the previous definition

eal_memory.c:78: error: "MEM_RESERVE_PLACEHOLDER" redefined /usr/x86_64-w64-mingw32/sys-root/mingw/include/winnt.h:5715: note:
this is the location of the previous definition

The patch masks MEM_REPLACE_PLACEHOLDER and MEM_RESERVE_PLACEHOLDER macros if they were pre-defined by compiler.

Quoted 7 lines

The patch also masks MEM_COALESCE_PLACEHOLDERS and MEM_PRESERVE_PLACEHOLDER to prevent similar errors.

Fixes 2a5d547a4a9b ("eal/windows: implement basic memory management")

For the record, the same issue has been reported with Ubuntu 23.10.

Applied, thanks.

Signature · 1 line
David Marchand