Unverified Commit 6e998c8c authored by PhoeniX's avatar PhoeniX

Ranged random support

parent b1ad924d
......@@ -10,4 +10,8 @@ class RAND {
static uint64_t _get64();
public:
template<typename T> static inline T get() { return static_cast<T>(_get64()); }
template<typename T> static inline T get(T max) { return get(0, max); }
template<typename T> static inline T get(T min, T max) {
return min + (get<T>() % (max - min));
}
};
......@@ -102,7 +102,7 @@ void Pagetable::init() {
EFI::getImageHandle(), &EFI::GUID_LoadedImageProtocol,
reinterpret_cast<void**>(&loaded_image));
uintptr_t ptbase = 0x600000 + (RAND::get<uintptr_t>() & 0x3FFF000);
uintptr_t ptbase = RAND::get<uintptr_t>(0x800, 0x10000) << 12;
pagetable = static_cast<PTE*>(efiAllocatePage(ptbase, ST));
efiMapPage(pagetable, nullptr, ST, 0);
......@@ -135,7 +135,7 @@ void Pagetable::init() {
static const size_t pdpe_num = 64;
static const size_t ptsz = (3 + pdpe_num) * 0x1000;
uintptr_t ptbase = 0x600000 - ptsz + ((RAND::get<uintptr_t>() & 0x3FFF) << 12);
uintptr_t ptbase = RAND::get<uintptr_t>(0x800, 0x8000 - (3 + pdpe_num)) << 12;
PTE *newpt = reinterpret_cast<PTE*>(ptbase);
Memory::fill(newpt, 0, ptsz);
......
......@@ -12,8 +12,8 @@ Process::Process() {
id = size_t(-1);
pagetable = nullptr;
entry = 0;
_aslrCode = ((RAND::get<uintptr_t>() << 12) & 0x7FFFFFFF000) | 0x40000000000;
_aslrStack = ((RAND::get<uintptr_t>() << 12) & 0x7FFFFFFF000) | 0x80000000000;
_aslrCode = RAND::get<uintptr_t>(0x80000000llu, 0x100000000llu) << 12;
_aslrStack = RAND::get<uintptr_t>(0x40000000llu, 0x80000000llu) << 12;
}
Process::~Process() {
if (pagetable != nullptr) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment