Merge pull request #638 from maxton/master

Update kernel convention for xboxkrnl_io.cc
This commit is contained in:
Justin Moore 2016-12-02 11:15:04 -06:00 committed by GitHub
commit af8e231ce6
1 changed files with 51 additions and 100 deletions

View File

@ -25,61 +25,33 @@ namespace kernel {
namespace xboxkrnl {
// http://msdn.microsoft.com/en-us/library/windows/hardware/ff540287.aspx
class X_FILE_FS_VOLUME_INFORMATION {
public:
struct X_FILE_FS_VOLUME_INFORMATION {
// FILE_FS_VOLUME_INFORMATION
uint64_t creation_time;
uint32_t serial_number;
uint32_t label_length;
uint32_t supports_objects;
xe::be<uint64_t> creation_time;
xe::be<uint32_t> serial_number;
xe::be<uint32_t> label_length;
xe::be<uint32_t> supports_objects;
char label[1];
void Write(uint8_t* base, uint32_t p) {
uint8_t* dst = base + p;
xe::store_and_swap<uint64_t>(dst + 0, this->creation_time);
xe::store_and_swap<uint32_t>(dst + 8, this->serial_number);
xe::store_and_swap<uint32_t>(dst + 12, this->label_length);
xe::store_and_swap<uint32_t>(dst + 16, this->supports_objects);
memcpy(dst + 20, this->label, this->label_length);
}
};
static_assert_size(X_FILE_FS_VOLUME_INFORMATION, 24);
// https://msdn.microsoft.com/en-us/library/windows/hardware/ff540282.aspx
class X_FILE_FS_SIZE_INFORMATION {
public:
struct X_FILE_FS_SIZE_INFORMATION {
// FILE_FS_SIZE_INFORMATION
uint64_t total_allocation_units;
uint64_t available_allocation_units;
uint32_t sectors_per_allocation_unit;
uint32_t bytes_per_sector;
void Write(uint8_t* base, uint32_t p) {
uint8_t* dst = base + p;
xe::store_and_swap<uint64_t>(dst + 0, this->total_allocation_units);
xe::store_and_swap<uint64_t>(dst + 8, this->available_allocation_units);
xe::store_and_swap<uint32_t>(dst + 16, this->sectors_per_allocation_unit);
xe::store_and_swap<uint32_t>(dst + 20, this->bytes_per_sector);
}
xe::be<uint64_t> total_allocation_units;
xe::be<uint64_t> available_allocation_units;
xe::be<uint32_t> sectors_per_allocation_unit;
xe::be<uint32_t> bytes_per_sector;
};
static_assert_size(X_FILE_FS_SIZE_INFORMATION, 24);
// http://msdn.microsoft.com/en-us/library/windows/hardware/ff540251(v=vs.85).aspx
class X_FILE_FS_ATTRIBUTE_INFORMATION {
public:
struct X_FILE_FS_ATTRIBUTE_INFORMATION {
// FILE_FS_ATTRIBUTE_INFORMATION
uint32_t attributes;
int32_t maximum_component_name_length;
uint32_t fs_name_length;
xe::be<uint32_t> attributes;
xe::be<int32_t> maximum_component_name_length;
xe::be<uint32_t> fs_name_length;
char fs_name[1];
void Write(uint8_t* base, uint32_t p) {
uint8_t* dst = base + p;
xe::store_and_swap<uint32_t>(dst + 0, this->attributes);
xe::store_and_swap<uint32_t>(dst + 4, this->maximum_component_name_length);
xe::store_and_swap<uint32_t>(dst + 8, this->fs_name_length);
memcpy(dst + 12, this->fs_name, this->fs_name_length);
}
};
static_assert_size(X_FILE_FS_ATTRIBUTE_INFORMATION, 16);
@ -612,59 +584,51 @@ dword_result_t NtQueryFullAttributesFile(
}
DECLARE_XBOXKRNL_EXPORT(NtQueryFullAttributesFile, ExportTag::kImplemented);
SHIM_CALL NtQueryVolumeInformationFile_shim(PPCContext* ppc_context,
KernelState* kernel_state) {
uint32_t file_handle = SHIM_GET_ARG_32(0);
uint32_t io_status_block_ptr = SHIM_GET_ARG_32(1);
uint32_t fs_info_ptr = SHIM_GET_ARG_32(2);
uint32_t length = SHIM_GET_ARG_32(3);
uint32_t fs_info_class = SHIM_GET_ARG_32(4);
XELOGD("NtQueryVolumeInformationFile(%.8X, %.8X, %.8X, %.8X, %.8X)",
file_handle, io_status_block_ptr, fs_info_ptr, length, fs_info_class);
dword_result_t NtQueryVolumeInformationFile(
dword_t file_handle, pointer_t<X_IO_STATUS_BLOCK> io_status_block_ptr,
lpvoid_t fs_info_ptr, dword_t length, dword_t fs_info_class) {
X_STATUS result = X_STATUS_SUCCESS;
uint32_t info = 0;
// Grab file.
auto file = kernel_state->object_table()->LookupObject<XFile>(file_handle);
auto file = kernel_state()->object_table()->LookupObject<XFile>(file_handle);
if (file) {
switch (fs_info_class) {
case 1: { // FileFsVolumeInformation
// TODO(gibbed): actual value
std::string name = "test";
X_FILE_FS_VOLUME_INFORMATION volume_info = {0};
volume_info.creation_time = 0;
volume_info.serial_number = 12345678;
volume_info.supports_objects = 0;
volume_info.label_length = uint32_t(name.size());
std::memcpy(volume_info.label, name.data(), name.size());
volume_info.Write(SHIM_MEM_BASE, fs_info_ptr);
X_FILE_FS_VOLUME_INFORMATION* volume_info =
fs_info_ptr.as<X_FILE_FS_VOLUME_INFORMATION*>();
volume_info->creation_time = 0;
volume_info->serial_number = 12345678;
volume_info->supports_objects = 0;
volume_info->label_length = uint32_t(name.size());
std::memcpy(volume_info->label, name.data(), name.size());
info = length;
break;
}
case 3: { // FileFsSizeInformation
X_FILE_FS_SIZE_INFORMATION fs_size_info = {0};
fs_size_info.total_allocation_units =
X_FILE_FS_SIZE_INFORMATION* fs_size_info =
fs_info_ptr.as<X_FILE_FS_SIZE_INFORMATION*>();
fs_size_info->total_allocation_units =
file->device()->total_allocation_units();
fs_size_info.available_allocation_units =
fs_size_info->available_allocation_units =
file->device()->available_allocation_units();
fs_size_info.sectors_per_allocation_unit =
fs_size_info->sectors_per_allocation_unit =
file->device()->sectors_per_allocation_unit();
fs_size_info.bytes_per_sector = file->device()->bytes_per_sector();
fs_size_info.Write(SHIM_MEM_BASE, fs_info_ptr);
fs_size_info->bytes_per_sector = file->device()->bytes_per_sector();
info = length;
break;
}
case 5: { // FileFsAttributeInformation
// TODO(gibbed): actual value
std::string name = "test";
X_FILE_FS_ATTRIBUTE_INFORMATION fs_attribute_info = {0};
fs_attribute_info.attributes = 0;
fs_attribute_info.maximum_component_name_length = 255;
fs_attribute_info.fs_name_length = uint32_t(name.size());
std::memcpy(fs_attribute_info.fs_name, name.data(), name.size());
fs_attribute_info.Write(SHIM_MEM_BASE, fs_info_ptr);
X_FILE_FS_ATTRIBUTE_INFORMATION* fs_attribute_info =
fs_info_ptr.as<X_FILE_FS_ATTRIBUTE_INFORMATION*>();
fs_attribute_info->attributes = 0;
fs_attribute_info->maximum_component_name_length = 255;
fs_attribute_info->fs_name_length = uint32_t(name.size());
std::memcpy(fs_attribute_info->fs_name, name.data(), name.size());
info = length;
break;
}
@ -687,12 +651,13 @@ SHIM_CALL NtQueryVolumeInformationFile_shim(PPCContext* ppc_context,
info = 0;
}
if (io_status_block_ptr) {
SHIM_SET_MEM_32(io_status_block_ptr, result); // Status
SHIM_SET_MEM_32(io_status_block_ptr + 4, info); // Information
io_status_block_ptr->status = result;
io_status_block_ptr->information = info;
}
SHIM_SET_RETURN_32(result);
return result;
}
DECLARE_XBOXKRNL_EXPORT(NtQueryVolumeInformationFile, ExportTag::kStub);
dword_result_t NtQueryDirectoryFile(
dword_t file_handle, dword_t event_handle, function_t apc_routine,
@ -734,45 +699,31 @@ dword_result_t NtQueryDirectoryFile(
}
DECLARE_XBOXKRNL_EXPORT(NtQueryDirectoryFile, ExportTag::kImplemented);
SHIM_CALL NtFlushBuffersFile_shim(PPCContext* ppc_context,
KernelState* kernel_state) {
uint32_t file_handle = SHIM_GET_ARG_32(0);
uint32_t io_status_block_ptr = SHIM_GET_ARG_32(1);
XELOGD("NtFlushBuffersFile(%.8X, %.8X)", file_handle, io_status_block_ptr);
dword_result_t NtFlushBuffersFile(
dword_t file_handle, pointer_t<X_IO_STATUS_BLOCK> io_status_block_ptr) {
auto result = X_STATUS_SUCCESS;
if (io_status_block_ptr) {
SHIM_SET_MEM_32(io_status_block_ptr, result); // Status
SHIM_SET_MEM_32(io_status_block_ptr + 4, 0); // Information
io_status_block_ptr->status = result;
io_status_block_ptr->information = 0;
}
SHIM_SET_RETURN_32(result);
return result;
}
DECLARE_XBOXKRNL_EXPORT(NtFlushBuffersFile, ExportTag::kStub);
dword_result_t FscGetCacheElementCount(dword_t r3) { return 0; }
DECLARE_XBOXKRNL_EXPORT(FscGetCacheElementCount, ExportTag::kStub);
SHIM_CALL FscSetCacheElementCount_shim(PPCContext* ppc_context,
KernelState* kernel_state) {
uint32_t unk_0 = SHIM_GET_ARG_32(0);
uint32_t unk_1 = SHIM_GET_ARG_32(1);
dword_result_t FscSetCacheElementCount(dword_t unk_0, dword_t unk_1) {
// unk_0 = 0
// unk_1 looks like a count? in what units? 256 is a common value
XELOGD("FscSetCacheElementCount(%.8X, %.8X)", unk_0, unk_1);
SHIM_SET_RETURN_32(X_STATUS_SUCCESS);
return X_STATUS_SUCCESS;
}
DECLARE_XBOXKRNL_EXPORT(FscSetCacheElementCount, ExportTag::kStub);
void RegisterIoExports(xe::cpu::ExportResolver* export_resolver,
KernelState* kernel_state) {
SHIM_SET_MAPPING("xboxkrnl.exe", NtQueryVolumeInformationFile, state);
SHIM_SET_MAPPING("xboxkrnl.exe", NtFlushBuffersFile, state);
SHIM_SET_MAPPING("xboxkrnl.exe", FscSetCacheElementCount, state);
}
KernelState* kernel_state) {}
} // namespace xboxkrnl
} // namespace kernel