Skip to content

Add support for Windows Drivers#757

Merged
redboltz merged 1 commit intomsgpack:masterfrom
wbenny:master
Jan 20, 2019
Merged

Add support for Windows Drivers#757
redboltz merged 1 commit intomsgpack:masterfrom
wbenny:master

Conversation

@wbenny
Copy link
Copy Markdown
Contributor

@wbenny wbenny commented Jan 17, 2019

This commit enables msgpack to be compiled as a part of Windows Driver. MSVC automatically creates macro _KERNEL_MODE when source code is compiled with /kernel switch (this compiler switch is turned on when driver is compiled).

Changes:

  • msgpack_object_print and msgpack_object_bin_print are disabled, because there is no printf in kernel mode
  • msgpack_object_print and msgpack_object_bin_print are moved so they are together (so that one #if !defined(...) can wrap them)
  • Return value is explicitly casted from size_t to int to disable compiler warning
  • Warning 4204 is disabled when compiling with MSVC
  • _msgpack_atomic_counter_header is set to <ntddk.h> if _KERNEL_MODE is defined (it contains prototypes for InterlockedIncrement and InterlockedDecrement)
  • TRUE and FALSE macros are disabled if _KERNEL_MODE is defined (they are defined unconditionally in <ntddk.h>)
  • assert is redefined to NT_ASSERT (assert specific to Windows Drivers)
  • _NO_CRT_STDIO_INLINE is unconditionally defined (it makes _snprintf symbol to be imported from ntoskrnl.exe)
  • snprintf is redefined to _snprintf (because ntoskrnl.exe does not export snprintf, only _snprintf, but they have same behavior)

NOTE: After these changes, linker still complains that symbols malloc, realloc and free can't be found. The cleanest solution would be to provide interface for setting custom allocators. Nonetheless, simply creating custom version of these functions resolves that problem too.

@redboltz
Copy link
Copy Markdown
Contributor

@wbenny , thank you for sending the PR.
It looks good to me.

@redboltz redboltz merged commit aec88c0 into msgpack:master Jan 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants