Shrinking alloy memory interface so that alloy-sandbox doesn't need xe.

This commit is contained in:
Ben Vanik
2014-08-19 21:02:15 -07:00
parent 76d524b655
commit 48a0e5c601
23 changed files with 230 additions and 192 deletions

View File

@@ -152,7 +152,7 @@ X_STATUS XThread::Create() {
// So, at offset 0x100 we have a 4b pointer to offset 200, then have the
// structure.
thread_state_address_ =
(uint32_t)memory()->HeapAlloc(0, 2048, alloy::MEMORY_FLAG_ZERO);
(uint32_t)memory()->HeapAlloc(0, 2048, MEMORY_FLAG_ZERO);
if (!thread_state_address_) {
XELOGW("Unable to allocate thread state block");
return X_STATUS_NO_MEMORY;
@@ -167,13 +167,12 @@ X_STATUS XThread::Create() {
// This is used by interrupts/APCs/etc so we can round-trip pointers through.
scratch_size_ = 4 * 16;
scratch_address_ =
(uint32_t)memory()->HeapAlloc(0, scratch_size_, alloy::MEMORY_FLAG_ZERO);
(uint32_t)memory()->HeapAlloc(0, scratch_size_, MEMORY_FLAG_ZERO);
// Allocate TLS block.
const xe_xex2_header_t* header = module->xex_header();
uint32_t tls_size = header->tls_info.slot_count * header->tls_info.data_size;
tls_address_ =
(uint32_t)memory()->HeapAlloc(0, tls_size, alloy::MEMORY_FLAG_ZERO);
tls_address_ = (uint32_t)memory()->HeapAlloc(0, tls_size, MEMORY_FLAG_ZERO);
if (!tls_address_) {
XELOGW("Unable to allocate thread local storage block");
module->Release();

View File

@@ -21,14 +21,14 @@
#include <third_party/mspack/mspack.h>
#include <third_party/pe/pe_image.h>
using namespace alloy;
// using namespace alloy;
DEFINE_bool(xex_dev_key, false, "Use the devkit key.");
typedef struct xe_xex2 {
xe_ref_t ref;
Memory *memory;
xe::Memory *memory;
xe_xex2_header_t header;
@@ -44,13 +44,13 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
xe_xex2_header_t *header);
int xe_xex2_decrypt_key(xe_xex2_header_t *header);
int xe_xex2_read_image(xe_xex2_ref xex, const uint8_t *xex_addr,
const size_t xex_length, Memory *memory);
const size_t xex_length, xe::Memory *memory);
int xe_xex2_load_pe(xe_xex2_ref xex);
int xe_xex2_find_import_infos(xe_xex2_ref xex,
const xe_xex2_import_library_t *library);
xe_xex2_ref xe_xex2_load(Memory *memory, const void *addr, const size_t length,
xe_xex2_options_t options) {
xe_xex2_ref xe_xex2_load(xe::Memory *memory, const void *addr,
const size_t length, xe_xex2_options_t options) {
xe_xex2_ref xex = (xe_xex2_ref)xe_calloc(sizeof(xe_xex2));
xe_ref_init((xe_ref)xex);
@@ -542,12 +542,13 @@ void xe_xex2_decrypt_buffer(const uint8_t *session_key,
int xe_xex2_read_image_uncompressed(const xe_xex2_header_t *header,
const uint8_t *xex_addr,
const size_t xex_length, Memory *memory) {
const size_t xex_length,
xe::Memory *memory) {
// Allocate in-place the XEX memory.
const size_t exe_length = xex_length - header->exe_offset;
size_t uncompressed_size = exe_length;
uint32_t alloc_result = (uint32_t)memory->HeapAlloc(
header->exe_address, uncompressed_size, MEMORY_FLAG_ZERO);
header->exe_address, uncompressed_size, xe::MEMORY_FLAG_ZERO);
if (!alloc_result) {
XELOGE("Unable to allocate XEX memory at %.8X-%.8X.", header->exe_address,
uncompressed_size);
@@ -575,7 +576,7 @@ int xe_xex2_read_image_uncompressed(const xe_xex2_header_t *header,
int xe_xex2_read_image_basic_compressed(const xe_xex2_header_t *header,
const uint8_t *xex_addr,
const size_t xex_length,
Memory *memory) {
xe::Memory *memory) {
const size_t exe_length = xex_length - header->exe_offset;
const uint8_t *source_buffer = (const uint8_t *)xex_addr + header->exe_offset;
const uint8_t *p = source_buffer;
@@ -592,7 +593,7 @@ int xe_xex2_read_image_basic_compressed(const xe_xex2_header_t *header,
// Allocate in-place the XEX memory.
uint32_t alloc_result = (uint32_t)memory->HeapAlloc(
header->exe_address, uncompressed_size, MEMORY_FLAG_ZERO);
header->exe_address, uncompressed_size, xe::MEMORY_FLAG_ZERO);
if (!alloc_result) {
XELOGE("Unable to allocate XEX memory at %.8X-%.8X.", header->exe_address,
uncompressed_size);
@@ -645,7 +646,7 @@ XECLEANUP:
int xe_xex2_read_image_compressed(const xe_xex2_header_t *header,
const uint8_t *xex_addr,
const size_t xex_length, Memory *memory) {
const size_t xex_length, xe::Memory *memory) {
const size_t exe_length = xex_length - header->exe_offset;
const uint8_t *exe_buffer = (const uint8_t *)xex_addr + header->exe_offset;
@@ -726,7 +727,7 @@ int xe_xex2_read_image_compressed(const xe_xex2_header_t *header,
// Allocate in-place the XEX memory.
uint32_t alloc_result = (uint32_t)memory->HeapAlloc(
header->exe_address, uncompressed_size, MEMORY_FLAG_ZERO);
header->exe_address, uncompressed_size, xe::MEMORY_FLAG_ZERO);
if (!alloc_result) {
XELOGE("Unable to allocate XEX memory at %.8X-%.8X.", header->exe_address,
uncompressed_size);
@@ -778,7 +779,7 @@ XECLEANUP:
}
int xe_xex2_read_image(xe_xex2_ref xex, const uint8_t *xex_addr,
const size_t xex_length, Memory *memory) {
const size_t xex_length, xe::Memory *memory) {
const xe_xex2_header_t *header = &xex->header;
switch (header->file_format_info.compression_type) {
case XEX_COMPRESSION_NONE:

View File

@@ -158,7 +158,7 @@ SHIM_CALL NtQueryVirtualMemory_shim(PPCContext* ppc_state, KernelState* state) {
XELOGD("NtQueryVirtualMemory(%.8X, %.8X)", base_address,
memory_basic_information_ptr);
alloy::AllocationInfo mem_info;
AllocationInfo mem_info;
size_t result = state->memory()->QueryInformation(base_address, &mem_info);
if (!result) {
SHIM_SET_RETURN_32(X_STATUS_INVALID_PARAMETER);
@@ -250,7 +250,7 @@ SHIM_CALL MmAllocatePhysicalMemoryEx_shim(PPCContext* ppc_state,
assert_true(max_addr_range == 0xFFFFFFFF);
// Allocate.
uint32_t flags = alloy::MEMORY_FLAG_PHYSICAL;
uint32_t flags = MEMORY_FLAG_PHYSICAL;
uint32_t base_address = (uint32_t)state->memory()->HeapAlloc(
0, adjusted_size, flags, adjusted_alignment);
if (!base_address) {
@@ -410,7 +410,7 @@ SHIM_CALL ExAllocatePoolTypeWithTag_shim(PPCContext* ppc_state,
}
uint32_t addr = (uint32_t)state->memory()->HeapAlloc(
0, adjusted_size, alloy::MEMORY_FLAG_ZERO, alignment);
0, adjusted_size, MEMORY_FLAG_ZERO, alignment);
SHIM_SET_RETURN_32(addr);
}