Skip to content

Commit

Permalink
xglobals,xprecompiled: Avoid <ntdef.h>
Browse files Browse the repository at this point in the history
In Microsoft Windows SDK there are duplicate definitions which cause compiler
errors when built with clang-cl. `RTL_CONSTANT_STRING` is necessary so we
define our own.

(cherry picked from commit a273c6e)
Signed-off-by: LIU Hao <lh_mouse@126.com>
  • Loading branch information
lhmouse committed Oct 29, 2024
1 parent 4f6be37 commit 5ec6373
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion mcfgthread/xglobals.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ __MCF_gthread_initialize_globals(void)

/* Generate the unique name for this process. */
static WCHAR gnbuffer[] = L"Local\\__MCF_crt_xglobals_*?pid???_#?cookie????????";
UNICODE_STRING gname = RTL_CONSTANT_STRING(gnbuffer);
UNICODE_STRING gname = __MCF_NT_STRING_INIT(gnbuffer);
__MCF_ASSERT(gnbuffer[25] == L'*');
ULONG pid = GetCurrentProcessId();
do_encode_numeric_field(gnbuffer + 25, 8, pid, L"0123456789ABCDEF");
Expand Down
9 changes: 8 additions & 1 deletion mcfgthread/xglobals.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <winnt.h>
#include <winternl.h>
#include <winerror.h>
#include <ntdef.h>
#include <sysinfoapi.h>
#include <profileapi.h>
#include <realtimeapiset.h>
Expand Down Expand Up @@ -73,6 +72,14 @@ NTSYSAPI ULONG NTAPI RtlNtStatusToDosErrorNoTeb(NTSTATUS status) __MCF_FN_CONST;
* the `.bss` section. */
#define __MCF_BAD_PTR ((void*) -127)

/* Define a macro that is identical to `RTL_CONSTANT_STRING()` as we are not
* willing to include <ntdef.h> here. */
#define __MCF_NT_STRING_INIT(s) \
{ .Length = sizeof(s) - sizeof(*(s)), \
.MaximumLength = sizeof(s), \
.Buffer = (void*) ((s) + __MCF_STATIC_ASSERT_0( \
!__builtin_types_compatible_p(__typeof__(1+&*(s)), __typeof__(s)))) }

/* Define macros and types for lazy binding.
* If a symbol cannot be found during startup, it is set to a null pointer. */
#define __MCF_G_LAZY_FIELD(name) decltype_##name* __f_##name
Expand Down
1 change: 0 additions & 1 deletion mcfgthread/xprecompiled.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <winnt.h>
#include <winternl.h>
#include <winerror.h>
#include <ntdef.h>
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
Expand Down

0 comments on commit 5ec6373

Please sign in to comment.