mirror of
https://github.com/momo5502/hypervisor.git
synced 2025-07-01 08:41:55 +00:00
Progress
This commit is contained in:
@ -1,7 +1,14 @@
|
||||
string(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
|
||||
|
||||
file(GLOB driver_sources ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
|
||||
file(GLOB driver_headers ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp)
|
||||
|
||||
wdk_add_driver(driver
|
||||
driver_main.cpp
|
||||
thread.cpp
|
||||
new.cpp
|
||||
${driver_sources}
|
||||
${driver_header}
|
||||
)
|
||||
target_precompile_headers(driver
|
||||
PRIVATE std_include.hpp
|
||||
)
|
||||
|
||||
cmake_path(NATIVE_PATH PROJECT_SOURCE_DIR NORMALIZE WINDOWS_PROJECT_DIR)
|
||||
|
@ -258,11 +258,19 @@ void throw_test()
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void __cdecl __std_terminate()
|
||||
{
|
||||
KeBugCheckEx(DRIVER_VIOLATION, 14, 0, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
extern "C" NTSTATUS DriverEntry(const PDRIVER_OBJECT DriverObject, PUNICODE_STRING /*RegistryPath*/)
|
||||
{
|
||||
DriverObject->DriverUnload = unload;
|
||||
debug_log("Hello World\n");
|
||||
|
||||
delete(new int);
|
||||
|
||||
volatile long i = 0;
|
||||
|
||||
thread::dispatch_on_all_cores([&i]()
|
||||
|
55
src/driver/functional.hpp
Normal file
55
src/driver/functional.hpp
Normal file
@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
#include "unique_ptr.hpp"
|
||||
|
||||
namespace std
|
||||
{
|
||||
template <typename T>
|
||||
struct function;
|
||||
|
||||
template <typename Result, typename... Args>
|
||||
struct function<Result(Args ...)>
|
||||
{
|
||||
private:
|
||||
struct fn_interface
|
||||
{
|
||||
virtual ~fn_interface() = default;
|
||||
virtual Result operator()(Args ...) const = 0;
|
||||
};
|
||||
|
||||
template <typename F>
|
||||
struct fn_implementation : fn_interface
|
||||
{
|
||||
fn_implementation(F&& f) : f_(std::forward<F>(f))
|
||||
{
|
||||
}
|
||||
|
||||
Result operator()(Args ... a) const override
|
||||
{
|
||||
f_(std::forward<Args>(a)...);
|
||||
}
|
||||
|
||||
F f_;
|
||||
};
|
||||
|
||||
std::unique_ptr<fn_interface> fn{};
|
||||
|
||||
public:
|
||||
template <typename T>
|
||||
function(T&& t)
|
||||
: fn(new fn_implementation<T>(std::forward<T>(t)))
|
||||
{
|
||||
}
|
||||
|
||||
~function() = default;
|
||||
function(function<Result(Args ...)>&&) noexcept = default;
|
||||
function& operator=(function<Result(Args ...)>&&) noexcept = default;
|
||||
|
||||
function(const function<Result(Args ...)>&) = delete;
|
||||
function& operator=(const function<Result(Args ...)>&) = delete;
|
||||
|
||||
Result operator()(Args ... args) const
|
||||
{
|
||||
return (*fn)(std::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
#include "std_include.hpp"
|
||||
#include "new.hpp"
|
||||
#include "logging.hpp"
|
||||
|
||||
void* __cdecl operator new(const size_t size, const POOL_TYPE pool, const unsigned long tag)
|
||||
{
|
||||
|
@ -11,44 +11,3 @@ void __cdecl operator delete(void *ptr, size_t);
|
||||
void __cdecl operator delete(void *ptr);
|
||||
void __cdecl operator delete[](void *ptr, size_t);
|
||||
void __cdecl operator delete[](void *ptr);
|
||||
|
||||
// TEMPLATE CLASS remove_reference
|
||||
template<class _Ty>
|
||||
struct remove_reference
|
||||
{ // remove reference
|
||||
typedef _Ty type;
|
||||
};
|
||||
|
||||
template<class _Ty>
|
||||
struct remove_reference<_Ty&>
|
||||
{ // remove reference
|
||||
typedef _Ty type;
|
||||
};
|
||||
|
||||
template<class _Ty>
|
||||
struct remove_reference<_Ty&&>
|
||||
{ // remove rvalue reference
|
||||
typedef _Ty type;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
typename remove_reference<T>::type&& move(T&& arg)
|
||||
{
|
||||
return static_cast<typename remove_reference<T>::type&&>(arg);
|
||||
}
|
||||
|
||||
// TEMPLATE FUNCTION forward
|
||||
template<class _Ty> inline
|
||||
constexpr _Ty&& forward(
|
||||
typename remove_reference<_Ty>::type& _Arg)
|
||||
{ // forward an lvalue as either an lvalue or an rvalue
|
||||
return (static_cast<_Ty&&>(_Arg));
|
||||
}
|
||||
|
||||
template<class _Ty> inline
|
||||
constexpr _Ty&& forward(
|
||||
typename remove_reference<_Ty>::type&& _Arg)
|
||||
{ // forward an rvalue as an rvalue
|
||||
return (static_cast<_Ty&&>(_Arg));
|
||||
}
|
||||
|
||||
|
2
src/driver/sleep_callback.cpp
Normal file
2
src/driver/sleep_callback.cpp
Normal file
@ -0,0 +1,2 @@
|
||||
#include "std_include.hpp"
|
||||
#include "sleep_callback.hpp"
|
2
src/driver/sleep_callback.hpp
Normal file
2
src/driver/sleep_callback.hpp
Normal file
@ -0,0 +1,2 @@
|
||||
#pragma once
|
||||
#include "functional.hpp"
|
54
src/driver/type_traits.hpp
Normal file
54
src/driver/type_traits.hpp
Normal file
@ -0,0 +1,54 @@
|
||||
#pragma once
|
||||
|
||||
namespace std
|
||||
{
|
||||
// TEMPLATE CLASS remove_reference
|
||||
template <class _Ty>
|
||||
struct remove_reference
|
||||
{
|
||||
// remove reference
|
||||
typedef _Ty type;
|
||||
};
|
||||
|
||||
template <class _Ty>
|
||||
struct remove_reference<_Ty&>
|
||||
{
|
||||
// remove reference
|
||||
typedef _Ty type;
|
||||
};
|
||||
|
||||
template <class _Ty>
|
||||
struct remove_reference<_Ty&&>
|
||||
{
|
||||
// remove rvalue reference
|
||||
typedef _Ty type;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
typename remove_reference<T>::type&& move(T&& arg)
|
||||
{
|
||||
return static_cast<typename remove_reference<T>::type&&>(arg);
|
||||
}
|
||||
|
||||
template <class _Ty>
|
||||
using remove_reference_t = typename remove_reference<_Ty>::type;
|
||||
|
||||
// TEMPLATE FUNCTION forward
|
||||
template <class _Ty>
|
||||
inline
|
||||
constexpr _Ty&& forward(
|
||||
typename remove_reference<_Ty>::type& _Arg)
|
||||
{
|
||||
// forward an lvalue as either an lvalue or an rvalue
|
||||
return (static_cast<_Ty&&>(_Arg));
|
||||
}
|
||||
|
||||
template <class _Ty>
|
||||
inline
|
||||
constexpr _Ty&& forward(
|
||||
typename remove_reference<_Ty>::type&& _Arg)
|
||||
{
|
||||
// forward an rvalue as an rvalue
|
||||
return (static_cast<_Ty&&>(_Arg));
|
||||
}
|
||||
}
|
69
src/driver/unique_ptr.hpp
Normal file
69
src/driver/unique_ptr.hpp
Normal file
@ -0,0 +1,69 @@
|
||||
#pragma once
|
||||
#include "type_traits.hpp"
|
||||
|
||||
namespace std
|
||||
{
|
||||
template <typename T>
|
||||
class unique_ptr
|
||||
{
|
||||
unique_ptr() = default;
|
||||
|
||||
unique_ptr(T* pointer)
|
||||
: pointer_(pointer)
|
||||
{
|
||||
}
|
||||
|
||||
~unique_ptr()
|
||||
{
|
||||
if (this->pointer_)
|
||||
{
|
||||
delete this->pointer_;
|
||||
this->pointer_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
unique_ptr(unique_ptr<T>&& obj) noexcept
|
||||
: unique_ptr()
|
||||
{
|
||||
this->operator=(std::move(obj));
|
||||
}
|
||||
|
||||
unique_ptr& operator=(unique_ptr<T>&& obj) noexcept
|
||||
{
|
||||
if (this != &obj)
|
||||
{
|
||||
this->~unique_ptr();
|
||||
this->pointer_ = obj.pointer_;
|
||||
obj.pointer_ = nullptr;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
unique_ptr(const unique_ptr<T>& obj) = delete;
|
||||
unique_ptr& operator=(const unique_ptr<T>& obj) = delete;
|
||||
|
||||
T* operator->()
|
||||
{
|
||||
return this->pointer_;
|
||||
}
|
||||
|
||||
const T* operator->() const
|
||||
{
|
||||
return this->pointer_;
|
||||
}
|
||||
|
||||
T& operator*()
|
||||
{
|
||||
return *this->pointer_;
|
||||
}
|
||||
|
||||
const T& operator*() const
|
||||
{
|
||||
return *this->pointer_;
|
||||
}
|
||||
|
||||
private:
|
||||
T* pointer_{nullptr};
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user