diff options
author | Toni Uhlig <matzeton@googlemail.com> | 2023-06-28 12:58:24 +0200 |
---|---|---|
committer | Toni Uhlig <matzeton@googlemail.com> | 2023-06-28 13:23:10 +0200 |
commit | f72851a80c90960822c5498b717fac738a92971b (patch) | |
tree | e94c6dcb7480e3895cd3cb2d2463a9688967a55c | |
parent | 77b71807249233c5289e106ef753515a33c93f1f (diff) |
example3 supports BUILD_NATIVE
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
-rw-r--r-- | .circleci/config.yml | 7 | ||||
-rw-r--r-- | .github/workflows/build.yml | 5 | ||||
-rw-r--r-- | .gitlab-ci.yml | 2 | ||||
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | examples/Makefile | 54 | ||||
-rw-r--r-- | examples/dpp-example-cplusplus-EASTL.cpp | 85 |
7 files changed, 124 insertions, 35 deletions
diff --git a/.circleci/config.yml b/.circleci/config.yml index 1cd7097..b157754 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -13,7 +13,7 @@ jobs: apt-get install -y -qq \ coreutils wget tar gzip bzip2 patch cmake make binutils gcc g++ autoconf automake flex bison texinfo \ git subversion curl xz-utils osslsigncode \ - binutils-mingw-w64-x86-64 gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64 mingw-w64-x86-64-dev + binutils-mingw-w64-x86-64 gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64 mingw-w64-x86-64-dev libboost-dev - run: | make deps \ WERROR=1 JOBS=4 Q= \ @@ -38,7 +38,10 @@ jobs: -r _install/dpp-example-cplusplus-EASTL.bat -a \ -r _install/dpp-example.sys -a \ -r _install/dpp-example-cplusplus.sys -a \ - -r _install/dpp-example-cplusplus-EASTL.sys + -r _install/dpp-example-cplusplus-EASTL.sys -a \ + -r _install/dpp-example-cplusplus-EASTL.run + - run: | + ./_install/dpp-example-cplusplus-EASTL.run - run: | wget 'https://github.com/utoni/mingw-w64-build-ng/releases/download/v1.0/mingw-w64-toolchain.tbz2' -O ./mingw-w64-toolchain.tbz2 - run: | diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e112b49..5dcea60 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -40,7 +40,7 @@ jobs: if: startsWith(matrix.os, 'ubuntu') run: | sudo apt-get update - sudo apt-get install autoconf automake cmake libtool pkg-config gettext flex bison + sudo apt-get install autoconf automake bison build-essential cmake flex libtool pkg-config gettext libboost-dev sudo apt-get install ${{ matrix.compiler }} lcov osslsigncode - name: Print Help run: | @@ -56,6 +56,9 @@ jobs: make examples-install DESTDIR=$(realpath _install) ls -alh _install test -r _install/codesign-ca-cert.crt -a -r _install/dpp-example.bat -a -r _install/dpp-example-cplusplus.bat -a -r _install/dpp-example-cplusplus-EASTL.bat -a -r _install/dpp-example.sys -a -r _install/dpp-example-cplusplus.sys -a -r _install/dpp-example-cplusplus-EASTL.sys + - name: Test + run: | + ./_install/dpp-example-cplusplus-EASTL.run - name: Cleanup run: | make deps-clean diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9eb6389..8eaa871 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -19,7 +19,7 @@ before_script: - > apt-get install -y -qq \ coreutils wget tar gzip bzip2 patch cmake make binutils gcc g++ autoconf automake flex bison texinfo \ - git subversion curl xz-utils osslsigncode + git subversion curl xz-utils osslsigncode libboost-dev makedeps: script: @@ -20,12 +20,15 @@ export SIGNTOOL_PREFIX examples: $(MAKE) -C examples DPP_ROOT=$(realpath $(DPP_ROOT)) all + $(MAKE) -C examples DPP_ROOT=$(realpath $(DPP_ROOT)) BUILD_NATIVE=1 all examples-clean: $(MAKE) -C examples DPP_ROOT=$(realpath $(DPP_ROOT)) clean + $(MAKE) -C examples DPP_ROOT=$(realpath $(DPP_ROOT)) BUILD_NATIVE=1 clean examples-install: $(MAKE) -C examples DPP_ROOT=$(realpath $(DPP_ROOT)) install + $(MAKE) -C examples DPP_ROOT=$(realpath $(DPP_ROOT)) BUILD_NATIVE=1 install deps: $(MAKE) -C $(DPP_ROOT) -f Makefile.deps \ @@ -20,6 +20,9 @@ Instead either use Zeranoe's build script with `make -C [path-to-this-repo] -f M 2. `examples/dpp-template-cplusplus`: same, but written in C++, including a very complex class and some MT 3. `examples/dpp-template-cplusplus-EASTL`: C++ example w/ (EA)STL integration, basicially everything usable except for SEH and assertions. +`examples/dpp-template-cplusplus-EASTL` supports `BUILD_NATIVE`! +You can build and run it on your native Linux either with the other examples e.g. `make examples`, build only native executables `make -C examples DPP_ROOT="$(realpath .)" BUILD_NATIVE=1` in the top-level directory or directly build it from the examples directory with `make DPP_ROOT="$(realpath ..)" BUILD_NATIVE=1`. + ## Build and Test Build all examples with a Mingw64 toolchain using Zeranoe's build script: diff --git a/examples/Makefile b/examples/Makefile index d260b22..abf8f2a 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -2,34 +2,42 @@ ifndef DPP_ROOT $(error DPP_ROOT is undefined, use `make DPP_ROOT=$(realpath ..)`) endif +ifndef BUILD_NATIVE include $(DPP_ROOT)/Makefile.inc +OPP_SUFFIX := kopp +EXE_SUFFIX := sys +else +include $(DPP_ROOT)/Makefile.native.inc +CFLAGS += -DBUILD_USERMODE=1 +OPP_SUFFIX := uopp +EXE_SUFFIX := run +endif 1_DRIVER_NAME = dpp-example 1_OBJECTS = $(1_DRIVER_NAME).o -1_TARGET = $(1_DRIVER_NAME).sys +1_TARGET = $(1_DRIVER_NAME).$(EXE_SUFFIX) 2_DRIVER_NAME = dpp-example-cplusplus -2_OBJECTS = $(2_DRIVER_NAME).opp -2_TARGET = $(2_DRIVER_NAME).sys +2_OBJECTS = $(2_DRIVER_NAME).$(OPP_SUFFIX) +2_TARGET = $(2_DRIVER_NAME).$(EXE_SUFFIX) 3_DRIVER_NAME = dpp-example-cplusplus-EASTL -3_OBJECTS = $(3_DRIVER_NAME).opp -3_TARGET = $(3_DRIVER_NAME).sys - -ifdef BUILD_NATIVE -$(error There is nothing the build as native executable here..) -endif +3_OBJECTS = $(3_DRIVER_NAME).$(OPP_SUFFIX) +3_TARGET = $(3_DRIVER_NAME).$(EXE_SUFFIX) +ifndef BUILD_NATIVE all: $(1_TARGET) $(2_TARGET) $(3_TARGET) - -include $(DPP_ROOT)/Makefile.inc +else +all: $(3_TARGET) +endif %.o: %.c $(call BUILD_C_OBJECT,$<,$@) -%.opp: %.cpp +%.$(OPP_SUFFIX): %.cpp $(call BUILD_CPP_OBJECT,$<,$@) +ifndef BUILD_NATIVE # simple C driver $(1_TARGET): $(1_OBJECTS) $(call LINK_C_KERNEL_TARGET,$(1_OBJECTS),$@) @@ -49,6 +57,28 @@ install: all $(INSTALL) $(1_DRIVER_NAME).bat $(DESTDIR) $(INSTALL) $(2_DRIVER_NAME).bat $(DESTDIR) $(INSTALL) $(3_DRIVER_NAME).bat $(DESTDIR) +else +$(1_TARGET): + $(error Target $(1_TARGET) does not support BUILD_NATIVE) + +# C++ driver w/ MT +$(2_TARGET): + $(error Target $(2_TARGET) does not support BUILD_NATIVE) + +# C++ driver w/ EASTL +$(3_TARGET): $(3_OBJECTS) + $(call LINK_CPP_USER_TARGET,$(3_OBJECTS),$@) + +install: all + $(call INSTALL_EXEC,$(3_TARGET)) +endif + +$(1_DRIVER_NAME): $(1_TARGET) + @echo 'Target compiled/linked: $(1_TARGET)' +$(2_DRIVER_NAME): $(2_TARGET) + @echo 'Target compiled/linked: $(2_TARGET)' +$(3_DRIVER_NAME): $(3_TARGET) + @echo 'Target compiled/linked: $(3_TARGET)' clean: rm -f $(1_OBJECTS) $(1_TARGET) $(1_TARGET).map diff --git a/examples/dpp-example-cplusplus-EASTL.cpp b/examples/dpp-example-cplusplus-EASTL.cpp index b57815d..a92d4ed 100644 --- a/examples/dpp-example-cplusplus-EASTL.cpp +++ b/examples/dpp-example-cplusplus-EASTL.cpp @@ -1,3 +1,4 @@ +#ifndef BUILD_USERMODE #include <ntddk.h> #include <cstdint> @@ -15,55 +16,89 @@ #include <EASTL/unordered_set.h> #include <EASTL/vector.h> +using namespace eastl; +#else +#include <cstdint> +#include <cstdio> + +#include <algorithm> +#include <functional> +#include <map> +#include <memory> +#include <set> +#include <string> +#include <unordered_map> +#include <unordered_set> +#include <vector> + +#include <boost/scoped_ptr.hpp> + +#define DbgPrint printf + +using namespace std; +using boost::scoped_ptr; + +typedef struct +{ +} DRIVER_OBJECT; +typedef DRIVER_OBJECT * PDRIVER_OBJECT; +typedef struct +{ +} UNICODE_STRING; +typedef UNICODE_STRING * PUNICODE_STRING; +typedef int NTSTATUS; +#endif + // C&P from: https://raw.githubusercontent.com/sidyhe/dxx/ed06aba3b91fe8e101d08c33c26ba73db96acef0/README.md void stl_test() { - eastl::make_unique<DRIVER_OBJECT>(); - eastl::make_shared<UNICODE_STRING>(); - eastl::scoped_ptr<double> dptr(new double(3.6)); + make_unique<DRIVER_OBJECT>(); + make_shared<UNICODE_STRING>(); + scoped_ptr<double> dptr(new double(3.6)); - eastl::set<int> set_test; + set<int> set_test; set_test.insert(1); set_test.insert(3); set_test.insert(5); set_test.erase(1); - eastl::map<int, int> map_test; + map<int, int> map_test; map_test[0] = 1; map_test[10] = 11; map_test[20] = 12; map_test.erase(11); - eastl::vector<int> vec_test; + vector<int> vec_test; vec_test.push_back(2); vec_test.push_back(3); vec_test.push_back(1); - eastl::stable_sort(vec_test.begin(), vec_test.end(), eastl::less<int>()); + stable_sort(vec_test.begin(), vec_test.end(), less<int>()); for (auto e : vec_test) { DbgPrint("%d\n", e); } - eastl::string s; + string s; s = "This a string"; s.append(" "); s.append("any"); DbgPrint("%s\n", s.c_str()); - eastl::wstring ws; + wstring ws; ws = L"wide string"; ws.clear(); - eastl::unordered_set<float> us_test; + unordered_set<float> us_test; us_test.insert(333); - eastl::unordered_map<double, eastl::string> um_test; - um_test.insert(eastl::make_pair(6.6, "9.9")); + unordered_map<double, string> um_test; + um_test.insert(make_pair(6.6, "9.9")); } void more_stl_test() { - eastl::hash_map<int, eastl::string> hm; +#ifndef BUILD_USERMODE + hash_map<int, string> hm; hm[0] = "test1"; hm[10] = "test2"; @@ -72,22 +107,23 @@ void more_stl_test() { DbgPrint("%s\n", s.second.c_str()); } +#endif - eastl::uniform_int_distribution<std::uint32_t> uid(1, UINT32_MAX); + uniform_int_distribution<std::uint32_t> uid(1, UINT32_MAX); DbgPrint("PRNG: %u\n", uid); auto lambda = [] { DbgPrint("Hello lambda!\n"); }; - eastl::function<void(void)> fn = lambda; + function<void(void)> fn = lambda; fn(); auto lambda2 = [](int n) { DbgPrint("Hello lambda2, %u!\n", n); return n; }; - eastl::function<int(int)> fn2 = lambda2; + function<int(int)> fn2 = lambda2; fn2(1337); - eastl::vector<std::uint32_t> fill_me; + vector<std::uint32_t> fill_me; for (auto i = UINT16_MAX; i > 0; --i) { fill_me.push_back(i); @@ -97,7 +133,7 @@ void more_stl_test() extern "C" { - +#ifndef BUILD_USERMODE DRIVER_INITIALIZE DriverEntry; DRIVER_UNLOAD DriverUnload; @@ -114,10 +150,21 @@ extern "C" return STATUS_SUCCESS; } - VOID DriverUnload(PDRIVER_OBJECT DriverObject) + void DriverUnload(PDRIVER_OBJECT DriverObject) { (void)DriverObject; DbgPrint("%s\n", "Bye ring0!"); } +#else + int main() + { + DbgPrint("%s\n", "Hello user!"); + + stl_test(); + more_stl_test(); + + return 0; + } +#endif } |