Skip to content

Commit

Permalink
Fix the BUG that functions in intrin.h cannot be used even if it is i… (
Browse files Browse the repository at this point in the history
#33)

* Fix the BUG that functions in intrin.h cannot be used even if it is introduced

* add demonstrate
  • Loading branch information
Oxygen1a1 authored Aug 13, 2024
1 parent c941028 commit 79a45e7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions cmake/FindWdk.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ set(WDK_COMPILE_FLAGS
"/kernel" # create kernel mode binary
"/FIwarning.h" # disable warnings in WDK headers
"/FI${WDK_ADDITIONAL_FLAGS_FILE}" # include file to disable RTC
"/Oi" # enable intrinsic functions so that you can use functions like _disable or _enable
)

set(WDK_COMPILE_DEFINITIONS "WINNT=1")
Expand Down
3 changes: 2 additions & 1 deletion samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ add_subdirectory(MinifilterCppDriver)
add_subdirectory(WdmCppDriver)
add_subdirectory(WdmCppLib)
add_subdirectory(WdmDriver)
add_subdirectory(WdmLib)
add_subdirectory(WdmLib)
add_subdirectory(WdmIntrinsicFunctions)
4 changes: 4 additions & 0 deletions samples/WdmIntrinsicFunctions/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
wdk_add_driver(WdmIntrinsicFunctions
Main.cpp
)
target_link_libraries(WdmIntrinsicFunctions WdmCppLib)
25 changes: 25 additions & 0 deletions samples/WdmIntrinsicFunctions/Main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <wdm.h>
#include <intrin.h>

DRIVER_UNLOAD driverUnload;
VOID driverUnload(_In_ PDRIVER_OBJECT driverObject)
{
UNREFERENCED_PARAMETER(driverObject);

DbgPrint("Driver unloaded\n");
}

EXTERN_C NTSTATUS DriverEntry(_In_ PDRIVER_OBJECT driverObject, _In_ PUNICODE_STRING registryPath)
{
UNREFERENCED_PARAMETER(registryPath);

DbgPrint("Driver loaded\n");

_disable(); //use intrinsic function
ULONG64 cr3 = __readcr3(); //use intrinsic function
_enable(); //use intrinsic function

DbgPrint("CR3: %p\n", cr3);
driverObject->DriverUnload = driverUnload;
return STATUS_SUCCESS;
}

0 comments on commit 79a45e7

Please sign in to comment.