mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-11-26 13:52:21 +00:00
loader: remove more unused ro functionality
This commit is contained in:
parent
cb74bc6bb8
commit
bfd04cfe92
2 changed files with 0 additions and 167 deletions
|
@ -27,15 +27,6 @@ Result MapUtils::LocateSpaceForMap(u64 *out, u64 out_size) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
Result MapUtils::MapCodeMemoryForProcess(Handle process_h, bool is_64_bit_address_space, u64 base_address, u64 size, u64 *out_code_memory_address) {
|
||||
if (kernelAbove200()) {
|
||||
return MapCodeMemoryForProcessModern(process_h, base_address, size, out_code_memory_address);
|
||||
} else {
|
||||
return MapCodeMemoryForProcessDeprecated(process_h, is_64_bit_address_space, base_address, size, out_code_memory_address);
|
||||
}
|
||||
}
|
||||
|
||||
Result MapUtils::LocateSpaceForMapModern(u64 *out, u64 out_size) {
|
||||
MemoryInfo mem_info = {};
|
||||
AddressSpaceInfo address_space = {};
|
||||
|
@ -126,70 +117,6 @@ Result MapUtils::LocateSpaceForMapDeprecated(u64 *out, u64 out_size) {
|
|||
return rc;
|
||||
}
|
||||
|
||||
Result MapUtils::MapCodeMemoryForProcessModern(Handle process_h, u64 base_address, u64 size, u64 *out_code_memory_address) {
|
||||
AddressSpaceInfo address_space = {};
|
||||
Result rc;
|
||||
|
||||
if (R_FAILED((rc = GetAddressSpaceInfo(&address_space, process_h)))) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (size > address_space.addspace_size) {
|
||||
return ResultLoaderInsufficientAddressSpace;
|
||||
}
|
||||
|
||||
u64 try_address;
|
||||
for (unsigned int i = 0; i < 0x200; i++) {
|
||||
while (true) {
|
||||
try_address = address_space.addspace_base + (StratosphereRandomUtils::GetRandomU64((u64)(address_space.addspace_size - size) >> 12) << 12);
|
||||
if (address_space.heap_size && (address_space.heap_base <= try_address + size - 1 && try_address <= address_space.heap_end - 1)) {
|
||||
continue;
|
||||
}
|
||||
if (address_space.map_size && (address_space.map_base <= try_address + size - 1 && try_address <= address_space.map_end - 1)) {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
rc = svcMapProcessCodeMemory(process_h, try_address, base_address, size);
|
||||
if (rc != ResultKernelInvalidMemoryState) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
*out_code_memory_address = try_address;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
Result MapUtils::MapCodeMemoryForProcessDeprecated(Handle process_h, bool is_64_bit_address_space, u64 base_address, u64 size, u64 *out_code_memory_address) {
|
||||
Result rc;
|
||||
u64 addspace_base, addspace_size;
|
||||
if (is_64_bit_address_space) {
|
||||
addspace_base = 0x8000000ULL;
|
||||
addspace_size = 0x78000000ULL;
|
||||
} else {
|
||||
addspace_base = 0x200000ULL;
|
||||
addspace_size = 0x3FE0000ULL;
|
||||
}
|
||||
|
||||
if (size > addspace_size) {
|
||||
return ResultLoaderInsufficientAddressSpace;
|
||||
}
|
||||
|
||||
u64 try_address;
|
||||
for (unsigned int i = 0; i < 0x200; i++) {
|
||||
try_address = addspace_base + (StratosphereRandomUtils::GetRandomU64((u64)(addspace_size - size) >> 12) << 12);
|
||||
rc = svcMapProcessCodeMemory(process_h, try_address, base_address, size);
|
||||
if (rc != ResultKernelInvalidMemoryState) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
*out_code_memory_address = try_address;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
Result MapUtils::GetAddressSpaceInfo(AddressSpaceInfo *out, Handle process_h) {
|
||||
Result rc;
|
||||
if (R_FAILED((rc = svcGetInfo(&out->heap_base, 4, process_h, 0)))) {
|
||||
|
|
|
@ -35,11 +35,6 @@ class MapUtils {
|
|||
static Result LocateSpaceForMapDeprecated(u64 *out, u64 out_size);
|
||||
static Result LocateSpaceForMapModern(u64 *out, u64 out_size);
|
||||
static Result LocateSpaceForMap(u64 *out, u64 out_size);
|
||||
|
||||
|
||||
static Result MapCodeMemoryForProcessDeprecated(Handle process_h, bool is_64_bit_address_space, u64 base_address, u64 size, u64 *out_code_memory_address);
|
||||
static Result MapCodeMemoryForProcessModern(Handle process_h, u64 base_address, u64 size, u64 *out_code_memory_address);
|
||||
static Result MapCodeMemoryForProcess(Handle process_h, bool is_64_bit_address_space, u64 base_address, u64 size, u64 *out_code_memory_address);
|
||||
};
|
||||
|
||||
class AutoCloseMap {
|
||||
|
@ -84,92 +79,3 @@ class AutoCloseMap {
|
|||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct MappedCodeMemory {
|
||||
Handle process_handle;
|
||||
u64 base_address;
|
||||
u64 size;
|
||||
u64 code_memory_address;
|
||||
void *mapped_address;
|
||||
|
||||
bool IsActive() {
|
||||
return this->code_memory_address != 0;
|
||||
}
|
||||
|
||||
bool IsMapped() {
|
||||
return this->mapped_address != NULL;
|
||||
}
|
||||
|
||||
/* Utility functions. */
|
||||
Result Open(Handle process_h, bool is_64_bit_address_space, u64 address, u64 size) {
|
||||
Result rc;
|
||||
if (this->IsActive()) {
|
||||
return ResultLoaderInternalError;
|
||||
}
|
||||
|
||||
this->process_handle = process_h;
|
||||
this->base_address = address;
|
||||
this->size = size;
|
||||
|
||||
if (R_FAILED((rc = MapUtils::MapCodeMemoryForProcess(this->process_handle, is_64_bit_address_space, this->base_address, this->size, &this->code_memory_address)))) {
|
||||
Close();
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
Result OpenAtAddress(Handle process_h, u64 address, u64 size, u64 target_code_memory_address) {
|
||||
Result rc;
|
||||
if (this->IsActive()) {
|
||||
return ResultLoaderInternalError;
|
||||
}
|
||||
this->process_handle = process_h;
|
||||
this->base_address = address;
|
||||
this->size = size;
|
||||
|
||||
if (R_SUCCEEDED((rc = svcMapProcessCodeMemory(this->process_handle, target_code_memory_address, this->base_address, this->size)))) {
|
||||
this->code_memory_address = target_code_memory_address;
|
||||
} else {
|
||||
Close();
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
Result Map() {
|
||||
Result rc;
|
||||
u64 try_address;
|
||||
if (this->IsMapped()) {
|
||||
return ResultLoaderInternalError;
|
||||
}
|
||||
if (R_FAILED(rc = MapUtils::LocateSpaceForMap(&try_address, size))) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (R_FAILED((rc = svcMapProcessMemory((void *)try_address, this->process_handle, this->code_memory_address, size)))) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
this->mapped_address = (void *)try_address;
|
||||
return rc;
|
||||
}
|
||||
|
||||
Result Unmap() {
|
||||
Result rc = ResultSuccess;
|
||||
if (this->IsMapped()) {
|
||||
if (R_FAILED((rc = svcUnmapProcessMemory(this->mapped_address, this->process_handle, this->code_memory_address, this->size)))) {
|
||||
/* TODO: panic(). */
|
||||
}
|
||||
}
|
||||
this->mapped_address = NULL;
|
||||
return rc;
|
||||
}
|
||||
|
||||
void Close() {
|
||||
Unmap();
|
||||
if (this->IsActive()) {
|
||||
if (R_FAILED(svcUnmapProcessCodeMemory(this->process_handle, this->code_memory_address, this->base_address, this->size))) {
|
||||
/* TODO: panic(). */
|
||||
}
|
||||
}
|
||||
*this = {};
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue