Merge branch 'master' into d3d12

This commit is contained in:
Triang3l
2019-07-30 07:59:38 +03:00
32 changed files with 334 additions and 121 deletions

View File

@@ -16,6 +16,7 @@
#include "xenia/kernel/xevent.h"
#include "xenia/kernel/xfile.h"
#include "xenia/kernel/xiocompletion.h"
#include "xenia/kernel/xsymboliclink.h"
#include "xenia/kernel/xthread.h"
#include "xenia/vfs/device.h"
#include "xenia/xbox.h"
@@ -717,6 +718,64 @@ dword_result_t NtFlushBuffersFile(
}
DECLARE_XBOXKRNL_EXPORT1(NtFlushBuffersFile, kFileSystem, kStub);
// https://docs.microsoft.com/en-us/windows/win32/devnotes/ntopensymboliclinkobject
dword_result_t NtOpenSymbolicLinkObject(
lpdword_t handle_out, pointer_t<X_OBJECT_ATTRIBUTES> object_attrs) {
if (!object_attrs) {
return X_STATUS_INVALID_PARAMETER;
}
assert_not_null(handle_out);
assert_true(object_attrs->attributes == 64); // case insensitive
auto object_name =
kernel_memory()->TranslateVirtual<X_ANSI_STRING*>(object_attrs->name_ptr);
std::string target_path =
object_name->to_string(kernel_memory()->virtual_membase());
if (object_attrs->root_directory != 0) {
assert_always();
}
auto pos = target_path.find("\\??\\");
if (pos != target_path.npos && pos == 0) {
target_path = target_path.substr(4); // Strip the full qualifier
}
std::string link_path;
if (!kernel_state()->file_system()->FindSymbolicLink(target_path,
link_path)) {
return X_STATUS_NO_SUCH_FILE;
}
object_ref<XSymbolicLink> symlink(new XSymbolicLink(kernel_state()));
symlink->Initialize(target_path, link_path);
*handle_out = symlink->handle();
return X_STATUS_SUCCESS;
}
DECLARE_XBOXKRNL_EXPORT1(NtOpenSymbolicLinkObject, kFileSystem, kImplemented);
// https://docs.microsoft.com/en-us/windows/win32/devnotes/ntquerysymboliclinkobject
dword_result_t NtQuerySymbolicLinkObject(dword_t handle,
pointer_t<X_ANSI_STRING> target) {
auto symlink =
kernel_state()->object_table()->LookupObject<XSymbolicLink>(handle);
if (!symlink) {
return X_STATUS_NO_SUCH_FILE;
}
auto length = std::min(static_cast<size_t>(target->maximum_length),
symlink->target().size());
if (length > 0) {
auto target_buf = kernel_memory()->TranslateVirtual(target->pointer);
std::memcpy(target_buf, symlink->target().c_str(), length);
}
target->length = static_cast<uint16_t>(length);
return X_STATUS_SUCCESS;
}
DECLARE_XBOXKRNL_EXPORT1(NtQuerySymbolicLinkObject, kFileSystem, kImplemented);
dword_result_t FscGetCacheElementCount(dword_t r3) { return 0; }
DECLARE_XBOXKRNL_EXPORT1(FscGetCacheElementCount, kFileSystem, kStub);

View File

@@ -543,6 +543,12 @@ dword_result_t ExAllocatePoolTypeWithTag(dword_t size, dword_t tag,
}
DECLARE_XBOXKRNL_EXPORT1(ExAllocatePoolTypeWithTag, kMemory, kImplemented);
dword_result_t ExAllocatePool(dword_t size) {
const uint32_t none = 0x656E6F4E; // 'None'
return ExAllocatePoolTypeWithTag(size, none, 0);
}
DECLARE_XBOXKRNL_EXPORT1(ExAllocatePool, kMemory, kImplemented);
void ExFreePool(lpvoid_t base_address) {
kernel_state()->memory()->SystemHeapFree(base_address);
}

View File

@@ -312,6 +312,30 @@ dword_result_t RtlUnicodeToMultiByteN(pointer_t<uint8_t> destination_ptr,
DECLARE_XBOXKRNL_EXPORT3(RtlUnicodeToMultiByteN, kNone, kImplemented,
kHighFrequency, kSketchy);
// https://undocumented.ntinternals.net/UserMode/Undocumented%20Functions/Executable%20Images/RtlImageNtHeader.html
pointer_result_t RtlImageNtHeader(lpvoid_t module) {
if (!module) {
return 0;
}
// Little-endian! no swapping!
auto dos_header = module.as<const uint8_t*>();
auto dos_magic = *reinterpret_cast<const uint16_t*>(&dos_header[0x00]);
if (dos_magic != 0x5A4D) { // 'MZ'
return 0;
}
auto dos_lfanew = *reinterpret_cast<const int32_t*>(&dos_header[0x3C]);
auto nt_header = &dos_header[dos_lfanew];
auto nt_magic = *reinterpret_cast<const uint32_t*>(&nt_header[0x00]);
if (nt_magic != 0x4550) { // 'PE'
return 0;
}
return static_cast<uint32_t>(nt_header - kernel_memory()->virtual_membase());
}
DECLARE_XBOXKRNL_EXPORT1(RtlImageNtHeader, kNone, kImplemented);
pointer_result_t RtlImageXexHeaderField(pointer_t<xex2_header> xex_header,
dword_t field_dword) {
uint32_t field_value = 0;