Skip to content

Commit b383284

Browse files
committed
Add ntl::Irql.
Add ntl::spin_lock. Add ntl::resource.
1 parent 0efe0af commit b383284

File tree

10 files changed

+819
-10
lines changed

10 files changed

+819
-10
lines changed

README.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,25 @@ Provides features to support a better development environment in the kernel.
161161
* ntl::rpc::client [(tested)](./test/app/src/main.cpp#L4) [(tested)](./test/common/rpc.hpp)
162162
* I did not have enough time to implement the data serialization part myself, so I referred to the contents of the project below. thank you! :-)
163163
* [Eyal Z/zpp serializer](https://github.com/eyalz800/serializer)
164+
* ntl::irql
165+
* Class for KIRQL
166+
* Classes
167+
* ntl::irql [(tested)](./test/driver/src/ntl.cpp#L46)
168+
* Functions
169+
* ntl::raise_irql [(tested)](./test/driver/src/ntl.cpp#L49)
170+
* raise_irql_to_dpc_level [(tested)](./test/driver/src/ntl.cpp#L62)
171+
* raise_irql_to_synch_level [(tested)](./test/driver/src/ntl.cpp#L71)
172+
* ntl::spin_lock
173+
* Class for KSPIN_LOCK
174+
* Classes
175+
* ntl::spin_lock [(tested)](./test/driver/src/ntl.cpp#L80)
176+
* ntl::unique_lock [(tested)](./test/driver/src/ntl.cpp#L99)
177+
* ntl::resource
178+
* Class for ERESOURCE
179+
* Classes
180+
* ntl::resource [(tested)](./test/driver/src/ntl.cpp#L117)
181+
* ntl::unique_lock [(tested)](./test/driver/src/ntl.cpp#L156)
182+
* ntl::shared_lock [(tested)](./test/driver/src/ntl.cpp#L179)
164183

165184
## Requirements
166185

@@ -187,7 +206,7 @@ Provides features to support a better development environment in the kernel.
187206
* 14.26.28801
188207
* 14.29.30133
189208
* 14.31.31103
190-
* Windows Kit (SDK, WDK)
209+
* Windows Kits (SDK, WDK)
191210
* 10.0.17763.0
192211
* 10.0.18362.0
193212
* 10.0.22000.0
@@ -281,7 +300,7 @@ If the SDK and WDK versions are different, builds are more likely to fail. **If
281300
include(cmake/CPM.cmake)
282301
283302
set(CRTSYS_NTL_MAIN ON) # use ntl::main
284-
CPMAddPackage("gh:ntoskrnl7/[email protected].8")
303+
CPMAddPackage("gh:ntoskrnl7/[email protected].9")
285304
include(${crtsys_SOURCE_DIR}/cmake/CrtSys.cmake)
286305
287306
# add driver

docs/ko-kr.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ crtsys의 장점은 아래와 같습니다.
147147
* [x] Create device [(tested)](../test/driver/src/main.cpp#L44)
148148
* ntl::device
149149
* DEVICE_OBJECT에 대한 클래스
150-
* Features
150+
* 기능
151151
* [x] Device Extension [(tested)](../test/driver/src/main.cpp#L33)
152152
* [ ] IRP_MJ_CREATE
153153
* [ ] IRP_MJ_CLOSE
@@ -161,6 +161,25 @@ crtsys의 장점은 아래와 같습니다.
161161
* ntl::rpc::client [(tested)](../test/app/src/main.cpp#L4) [(tested)](../test/common/rpc.hpp)
162162
* 데이터 직렬화 부분을 직접 구현하기에는 시간이 부족하여 아래 프로젝트 내용을 참고했습니다. 감사합니다! :-)
163163
* [Eyal Z/zpp serializer](https://github.com/eyalz800/serializer)
164+
* ntl::irql
165+
* KIRQL에 대한 클래스
166+
* 클래스
167+
* ntl::irql [(tested)](../test/driver/src/ntl.cpp#L46)
168+
* 함수
169+
* ntl::raise_irql [(tested)](../test/driver/src/ntl.cpp#L49)
170+
* raise_irql_to_dpc_level [(tested)](../test/driver/src/ntl.cpp#L62)
171+
* raise_irql_to_synch_level [(tested)](../test/driver/src/ntl.cpp#L71)
172+
* ntl::spin_lock
173+
* KSPIN_LOCK에 대한 클래스
174+
* 클래스
175+
* ntl::spin_lock [(tested)](../test/driver/src/ntl.cpp#L80)
176+
* ntl::unique_lock [(tested)](../test/driver/src/ntl.cpp#L99)
177+
* ntl::resource
178+
* ERESOURCE에 대한 클래스
179+
* 클래스
180+
* ntl::resource [(tested)](../test/driver/src/ntl.cpp#L117)
181+
* ntl::unique_lock [(tested)](../test/driver/src/ntl.cpp#L156)
182+
* ntl::shared_lock [(tested)](../test/driver/src/ntl.cpp#L179)
164183

165184
## Requirements
166185

@@ -187,7 +206,7 @@ crtsys의 장점은 아래와 같습니다.
187206
* 14.26.28801
188207
* 14.29.30133
189208
* 14.31.31103
190-
* Windows Kit (SDK, WDK)
209+
* Windows Kits (SDK, WDK)
191210
* 10.0.17763.0
192211
* 10.0.18362.0
193212
* 10.0.22000.0
@@ -281,7 +300,7 @@ SDK와 WDK의 버전이 다르면 빌드가 실패할 가능성이 높으므로
281300
include(cmake/CPM.cmake)
282301
283302
set(CRTSYS_NTL_MAIN ON) # use ntl::main
284-
CPMAddPackage("gh:ntoskrnl7/[email protected].8")
303+
CPMAddPackage("gh:ntoskrnl7/[email protected].9")
285304
include(${crtsys_SOURCE_DIR}/cmake/CrtSys.cmake)
286305
287306
# add driver

include/.internal/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ Environment:
2626

2727
#define CRTSYS_VERSION_MAJOR 0
2828
#define CRTSYS_VERSION_MINOR 1
29-
#define CRTSYS_VERSION_PATCH 8
29+
#define CRTSYS_VERSION_PATCH 9
3030

3131
#endif // _CRTSYS_VERSION_

include/ntl/irql

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/**
2+
* @file irql
3+
* @author jungkwang.lee ([email protected])
4+
* @brief KIRQL Helper features.
5+
*
6+
* @copyright Copyright (c) 2022 NT Template Library Authoers.
7+
*
8+
*/
9+
10+
#ifndef _NTDDK_
11+
#include <wdm.h>
12+
#endif
13+
14+
namespace ntl {
15+
enum irql : KIRQL {
16+
passive = PASSIVE_LEVEL,
17+
low = passive,
18+
apc = APC_LEVEL,
19+
dispatch = DISPATCH_LEVEL,
20+
dpc = dispatch,
21+
#if defined(_X86_) || defined(_AMD64_)
22+
cmci = CMCI_LEVEL,
23+
#endif
24+
clock = CLOCK_LEVEL,
25+
ipi = IPI_LEVEL,
26+
drs = DRS_LEVEL,
27+
power = POWER_LEVEL,
28+
profile = PROFILE_LEVEL,
29+
#if defined(_X86_)
30+
clock1 = CLOCK1_LEVEL,
31+
clock2 = CLOCK2_LEVEL,
32+
#endif
33+
high = HIGH_LEVEL
34+
};
35+
36+
struct to_dpc_level_t {
37+
explicit to_dpc_level_t() = default;
38+
};
39+
40+
struct to_synch_level_t {
41+
explicit to_synch_level_t() = default;
42+
};
43+
44+
_INLINE_VAR constexpr to_dpc_level_t to_dpc_level{};
45+
_INLINE_VAR constexpr to_synch_level_t to_synch_level{};
46+
47+
class raised_irql {
48+
public:
49+
raised_irql(to_dpc_level_t) : old_irql_(KeRaiseIrqlToDpcLevel()) {}
50+
raised_irql(to_synch_level_t) : old_irql_(KeRaiseIrqlToSynchLevel()) {}
51+
raised_irql(irql irql) { KeRaiseIrql(static_cast<KIRQL>(irql), &old_irql_); }
52+
53+
~raised_irql() { KeLowerIrql(old_irql_); }
54+
55+
raised_irql(const raised_irql &) = delete;
56+
raised_irql &operator=(const raised_irql &) = delete;
57+
58+
irql old() const { return static_cast<irql>(old_irql_); }
59+
60+
private:
61+
KIRQL old_irql_;
62+
};
63+
64+
raised_irql raise_irql(KIRQL irql) {
65+
return raised_irql{static_cast<ntl::irql>(irql)};
66+
}
67+
68+
raised_irql raise_irql_to_dpc_level() { return raised_irql{to_dpc_level}; }
69+
70+
raised_irql raise_irql_to_synch_level() { return raised_irql{to_synch_level}; }
71+
72+
ntl::irql current_irql() { return static_cast<ntl::irql>(KeGetCurrentIrql()); }
73+
} // namespace ntl

0 commit comments

Comments
 (0)