Skip to content

Commit

Permalink
add FUMO_DRIVER_DEBUG cmake flag
Browse files Browse the repository at this point in the history
  • Loading branch information
dumbasPL committed Jun 9, 2024
1 parent 068354d commit 6ee5530
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ endif()
set(CPM_SOURCE_CACHE "${CMAKE_SOURCE_DIR}/.cache/cpm")
include(cmake/CPM.cmake)

set(FUMO_DRIVER_DEBUG OFF CACHE BOOL "Enable driver debug logs/force reload")

add_subdirectory(src)
5 changes: 3 additions & 2 deletions src/driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ wdk_add_driver(fumo_drv WINVER 0x4A61 driver.c memory.c thread.c)
target_include_directories(fumo_drv PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../include)
set_target_properties(fumo_drv PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

# FIXME: add a cmake option to enable debug mode
target_compile_definitions(fumo_drv PRIVATE -DNO_FUMO_DRIVER_DEBUG)
if (FUMO_DRIVER_DEBUG)
target_compile_definitions(fumo_drv PRIVATE -DFUMO_DRIVER_DEBUG)
endif()
4 changes: 0 additions & 4 deletions src/driver/driver.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#pragma once
#include "imports.h"

#ifndef NO_FUMO_DRIVER_DEBUG
#define FUMO_DRIVER_DEBUG
#endif

#ifdef FUMO_DRIVER_DEBUG

// FUMO
Expand Down
6 changes: 5 additions & 1 deletion src/stage1/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ target_compile_features(stage1 PUBLIC c_std_17 cxx_std_20)
target_compile_definitions(stage1 PRIVATE UNICODE _UNICODE)
target_compile_options(stage1 PRIVATE /O1 /GS- /sdl- /guard:cf- /Zc:threadSafeInit-)
target_link_libraries(stage1 PUBLIC ntdll libKDU driver_interface lazy_importer)
set_target_properties(stage1 PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set_target_properties(stage1 PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})

if (FUMO_DRIVER_DEBUG)
target_compile_definitions(stage1 PRIVATE -DFUMO_DRIVER_DEBUG)
endif()
8 changes: 7 additions & 1 deletion src/stage1/stage1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
#include <filesystem>
#include <fstream>

#ifdef FUMO_DRIVER_DEBUG
#define FORCE_RELOAD_DRIVER true
#else
#define FORCE_RELOAD_DRIVER false
#endif

int stage1(PFUMO_EMBEDDED_DATA embedded_data) {
std::vector<BYTE> fumo_data;
std::wstring fumo_file_path;
Expand Down Expand Up @@ -68,7 +74,7 @@ int stage1(PFUMO_EMBEDDED_DATA embedded_data) {
if (!driver)
return fumo::error(ERR_STAGE1_FAILED_TO_OPEN_DRIVER, L"Failed to open driver");

auto error = init_driver(driver.get(), osv.dwBuildNumber);
auto error = init_driver(driver.get(), osv.dwBuildNumber, FORCE_RELOAD_DRIVER);
if (error != ERR_STAGE1_SUCCESS)
return error;

Expand Down

0 comments on commit 6ee5530

Please sign in to comment.