Skip to content

Commit

Permalink
Refactor - Part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
RatinCN committed Sep 12, 2024
1 parent 80a1e7b commit 2dab418
Show file tree
Hide file tree
Showing 36 changed files with 1,323 additions and 231 deletions.
63 changes: 63 additions & 0 deletions Source/Include/KNSoft/NDK/Extension/Extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,66 @@
} varName

#pragma endregion

#pragma region MSVC and WinSDK

#if _WIN64
#define IS_WIN64 TRUE
#else
#define IS_WIN64 FALSE
#endif

/* Patch C_ASSERT to avoid confusion amount static_assert, _Static_assert, _STATIC_ASSERT and C_ASSERT */

#undef C_ASSERT
#define C_ASSERT(expr) static_assert((expr), #expr)

#define __A2U8(quote) u8##quote
#define _A2U8(quote) __A2U8(quote)

#define __A2W(quote) L##quote
#define _A2W(quote) __A2W(quote)

#if _WIN64
#define MSVC_VARDNAME(x) x
#define MSVC_INCLUDE_VAR(x) __pragma(comment(linker, "/include:"#x))
#else
#define MSVC_VARDNAME(x) _##x
#define MSVC_INCLUDE_VAR(x) __pragma(comment(linker, "/include:_"#x))
#endif

/*
* Initializer support
* See also:
* https://devblogs.microsoft.com/cppblog/new-compiler-warnings-for-dynamic-initialization/
* https://learn.microsoft.com/en-us/cpp/c-runtime-library/crt-initialization
*
* ** FIXME: Not support C++ yet **
*/

#ifndef __cplusplus

// Section 'section-name' is reserved for C++ dynamic initialization.
#pragma warning(error: 5247 5248)

typedef int(__cdecl* _PIFV)(void);

#pragma section(".CRT$XINDK", long, read)

#define MSVC_INITIALIZER(x)\
int __cdecl x(void);\
__declspec(allocate(".CRT$XINDK")) _PIFV _KNSoft_NDK_Initializer_User_##x = &x;\
MSVC_INCLUDE_VAR(_KNSoft_NDK_Initializer_User_##x)\
int __cdecl x(void)

#endif

#pragma endregion

#pragma region MSBuild

#define MSB_LIB_PATH(LibName) (MSB_PLATFORMTARGET"/"MSB_CONFIGURATION"/"##LibName)

/* Other MSB_* are defined in Directory.Build.props */

#pragma endregion
70 changes: 0 additions & 70 deletions Source/Include/KNSoft/NDK/Extension/MSToolChain.h

This file was deleted.

2 changes: 1 addition & 1 deletion Source/Include/KNSoft/NDK/NDK.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include <Windows.h>
#include "Win32/Def/WinUser.h"
#include "Win32/Def/CommCtrl.h"

/* APIs */

Expand All @@ -31,5 +32,4 @@

#ifndef _KNSOFT_NDK_NO_EXTENSION
#include "Extension/Extension.h"
#include "Extension/MSToolChain.h"
#endif
109 changes: 108 additions & 1 deletion Source/Include/KNSoft/NDK/NT/Bcd.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ typedef VOID(NTAPI* BCD_MESSAGE_CALLBACK)(
_In_ PWSTR Message
);

/**
* Sets the logging level and callback routine for BCD messages.
*
* @param BcdLoggingLevel The logging level to set.
* @param BcdMessageCallbackRoutine The callback routine for BCD messages.
* @return NTSTATUS Successful or errant status.
*/
NTSYSAPI
NTSTATUS
NTAPI
Expand All @@ -102,34 +109,62 @@ BcdSetLogging(
_In_ BCD_MESSAGE_CALLBACK BcdMessageCallbackRoutine
);

/**
* Initializes the BCD synchronization mutant.
*/
NTSYSAPI
VOID
NTAPI
BcdInitializeBcdSyncMutant(
VOID
);

/**
* Retrieves the file name for the BCD.
*
* @param BcdSystemStorePath The pointer to receive the system store path.
* @return NTSTATUS Successful or errant status.
*/
NTSYSAPI
NTSTATUS
NTAPI
BcdGetSystemStorePath(
_Out_ PWSTR* BcdSystemStorePath // RtlFreeHeap(RtlProcessHeap(), 0, BcdSystemStorePath);
);

/**
* Sets the device for the system BCD store.
*
* @param SystemPartition The system partition to set.
* @return NTSTATUS Successful or errant status.
*/
NTSYSAPI
NTSTATUS
NTAPI
BcdSetSystemStoreDevice(
_In_ UNICODE_STRING SystemPartition
);

/**
* Opens the BCD system store.
*
* @param BcdStoreHandle The handle to receive the system store.
* @return NTSTATUS Successful or errant status.
*/
NTSYSAPI
NTSTATUS
NTAPI
BcdOpenSystemStore(
_Out_ PHANDLE BcdStoreHandle
);

/**
* Opens a BCD store from a file.
*
* @param BcdFilePath The file path of the BCD store.
* @param BcdStoreHandle The handle to receive the BCD store.
* @return NTSTATUS Successful or errant status.
*/
NTSYSAPI
NTSTATUS
NTAPI
Expand All @@ -138,6 +173,13 @@ BcdOpenStoreFromFile(
_Out_ PHANDLE BcdStoreHandle
);

/**
* Creates a BCD store.
*
* @param BcdFilePath The file path to create the BCD store.
* @param BcdStoreHandle The handle to receive the BCD store.
* @return NTSTATUS Successful or errant status.
*/
NTSYSAPI
NTSTATUS
NTAPI
Expand All @@ -146,14 +188,28 @@ BcdCreateStore(
_Out_ PHANDLE BcdStoreHandle
);

/**
* Exports the BCD store to a file.
*
* @param BcdFilePath The file path to export the BCD store.
* @return NTSTATUS Successful or errant status.
*/
NTSYSAPI
NTSTATUS
NTAPI
BcdExportStore(
_In_ UNICODE_STRING BcdFilePath
);

#if (PHNT_VERSION > PHNT_WIN11)
#if (NTDDI_VERSION > NTDDI_WIN11_ZN)
/**
* Exports the BCD store to a file with additional flags.
*
* @param BcdStoreHandle The handle to the BCD store.
* @param Flags The flags for exporting the store.
* @param BcdFilePath The file path to export the BCD store.
* @return NTSTATUS Successful or errant status.
*/
NTSYSAPI
NTSTATUS
NTAPI
Expand All @@ -164,6 +220,12 @@ BcdExportStoreEx(
);
#endif

/**
* Imports a BCD store from a file.
*
* @param BcdFilePath The file path to import the BCD store.
* @return NTSTATUS Successful or errant status.
*/
NTSYSAPI
NTSTATUS
NTAPI
Expand All @@ -177,6 +239,13 @@ typedef enum _BCD_IMPORT_FLAGS
BCD_IMPORT_DELETE_FIRMWARE_OBJECTS
} BCD_IMPORT_FLAGS;

/**
* Imports a BCD store from a file with additional flags.
*
* @param BcdFilePath The file path to import the BCD store.
* @param BcdImportFlags The flags for importing the store.
* @return NTSTATUS Successful or errant status.
*/
NTSYSAPI
NTSTATUS
NTAPI
Expand All @@ -185,6 +254,13 @@ BcdImportStoreWithFlags(
_In_ BCD_IMPORT_FLAGS BcdImportFlags
);

/**
* Deletes object references in the BCD store.
*
* @param BcdStoreHandle The handle to the BCD store.
* @param Identifier The identifier of the object to delete references for.
* @return NTSTATUS Successful or errant status.
*/
NTSYSAPI
NTSTATUS
NTAPI
Expand All @@ -193,6 +269,11 @@ BcdDeleteObjectReferences(
_In_ PGUID Identifier
);

/**
* Deletes the system store for BCD.
*
* @return NTSTATUS Successful or errant status.
*/
NTSYSAPI
NTSTATUS
NTAPI
Expand All @@ -207,6 +288,14 @@ typedef enum _BCD_OPEN_FLAGS
BCD_OPEN_SYNC_FIRMWARE_ENTRIES
} BCD_OPEN_FLAGS;

/**
* Opens a BCD store with additional flags.
*
* @param BcdFilePath The file path of the BCD store.
* @param BcdOpenFlags The flags for opening the store.
* @param BcdStoreHandle The handle to receive the BCD store.
* @return NTSTATUS Successful or errant status.
*/
NTSYSAPI
NTSTATUS
NTAPI
Expand All @@ -216,20 +305,38 @@ BcdOpenStore(
_Out_ PHANDLE BcdStoreHandle
);

/**
* Closes a BCD store.
*
* @param BcdStoreHandle The handle to the BCD store.
* @return NTSTATUS Successful or errant status.
*/
NTSYSAPI
NTSTATUS
NTAPI
BcdCloseStore(
_In_ HANDLE BcdStoreHandle
);

/**
* Flushes a BCD store.
*
* @param BcdStoreHandle The handle to the BCD store.
* @return NTSTATUS Successful or errant status.
*/
NTSYSAPI
NTSTATUS
NTAPI
BcdFlushStore(
_In_ HANDLE BcdStoreHandle
);

/**
* Forcibly unloads a BCD store.
*
* @param BcdStoreHandle The handle to the BCD store.
* @return NTSTATUS Successful or errant status.
*/
NTSYSAPI
NTSTATUS
NTAPI
Expand Down
Loading

0 comments on commit 2dab418

Please sign in to comment.