Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
include pwn.hpp -> include pwn (#22)
- Loading branch information
Showing
19 changed files
with
153 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,68 @@ | ||
#pragma once | ||
|
||
#include "Common.hpp" | ||
#include "Error.hpp" | ||
#include "Handle.hpp" | ||
|
||
|
||
namespace pwn::Job | ||
{ | ||
|
||
// todo: | ||
// limit_cpufreq_for_job | ||
// assign_job_to_core | ||
|
||
class Job | ||
{ | ||
public: | ||
Job(_In_ LPCWSTR name = nullptr) : m_Name(name), m_Valid {false} | ||
{ | ||
HANDLE hJob = ::CreateJobObjectW(nullptr, name); | ||
if ( !hJob && ::GetLastError() == ERROR_ALREADY_EXISTS ) | ||
{ | ||
hJob = ::OpenJobObjectW(JOB_OBJECT_ALL_ACCESS, FALSE, name); | ||
} | ||
|
||
if ( !hJob ) | ||
throw std::exception("cannot create job"); | ||
|
||
m_hJob = UniqueHandle {hJob}; | ||
|
||
m_Valid = true; | ||
} | ||
|
||
bool | ||
IsValid() const | ||
{ | ||
return m_Valid; | ||
} | ||
|
||
|
||
private: | ||
auto | ||
AddProcess(u32 ProcessId) -> Result<bool>; | ||
|
||
bool m_Valid {false}; | ||
std::wstring m_Name {}; | ||
UniqueHandle m_hJob {}; | ||
std::vector<UniqueHandle> m_Handles {}; | ||
}; | ||
} // namespace Job | ||
#pragma once | ||
|
||
#include "Common.hpp" | ||
#include "Error.hpp" | ||
#include "Handle.hpp" | ||
|
||
|
||
namespace pwn::Job | ||
{ | ||
|
||
// todo: | ||
// limit_cpufreq_for_job | ||
// assign_job_to_core | ||
|
||
class Job | ||
{ | ||
public: | ||
Job(_In_ LPCWSTR name = nullptr) : m_Name(name), m_Valid {false} | ||
{ | ||
HANDLE hJob = ::CreateJobObjectW(nullptr, name); | ||
if ( !hJob && ::GetLastError() == ERROR_ALREADY_EXISTS ) | ||
{ | ||
hJob = ::OpenJobObjectW(JOB_OBJECT_ALL_ACCESS, FALSE, name); | ||
} | ||
|
||
if ( !hJob ) | ||
throw std::exception("cannot create job"); | ||
|
||
m_hJob = UniqueHandle {hJob}; | ||
|
||
m_Valid = true; | ||
} | ||
|
||
bool | ||
IsValid() const | ||
{ | ||
return m_Valid; | ||
} | ||
|
||
auto | ||
AddProcess(u32 ProcessId) -> Result<bool>; | ||
|
||
/// | ||
///@brief Simple C++ friendly wrapper for `AddProcess` | ||
/// | ||
///@param ProcessId | ||
///@return Job& | ||
///@throws `runtime_error` if adding process to the job failed | ||
/// | ||
Job& | ||
operator+=(u32 ProcessId) | ||
{ | ||
if ( Success(AddProcess(ProcessId)) ) | ||
{ | ||
return *this; | ||
} | ||
|
||
throw std::runtime_error("Error adding process to job"); | ||
} | ||
|
||
|
||
private: | ||
bool m_Valid {false}; | ||
std::wstring m_Name {}; | ||
UniqueHandle m_hJob {}; | ||
std::vector<UniqueHandle> m_Handles {}; | ||
}; | ||
} // namespace pwn::Job |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#include <pwn.hpp> | ||
#include <pwn> | ||
using namespace pwn; | ||
|
||
int | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/// @brief | ||
/// | ||
|
||
#include <pwn.hpp> | ||
#include <pwn> | ||
using namespace pwn; | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#include <pwn.hpp> | ||
#include <pwn> | ||
using namespace pwn; | ||
|
||
int | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#include <pwn.hpp> | ||
#include <pwn> | ||
using namespace pwn; | ||
|
||
auto | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#include "pwn.hpp" | ||
#include "pwn" | ||
|
||
|
||
static __attribute__((constructor)) void | ||
|
Oops, something went wrong.