Working on switching to std::string.

This commit is contained in:
Ben Vanik
2014-08-16 02:30:23 -07:00
parent 01f0b14250
commit a4dfc23abc
34 changed files with 211 additions and 250 deletions

View File

@@ -15,6 +15,4 @@ using namespace xe::kernel::fs;
Device::Device(const std::string& path) : path_(path) {}
Device::~Device() {}
const char* Device::path() const { return path_.c_str(); }
Device::~Device() = default;

View File

@@ -26,7 +26,7 @@ class Device {
Device(const std::string& path);
virtual ~Device();
const char* path() const;
const std::string& path() const { return path_; }
virtual Entry* ResolvePath(const char* path) = 0;

View File

@@ -29,15 +29,15 @@ DiscImageFile::DiscImageFile(
DiscImageFile::~DiscImageFile() {
}
const char* DiscImageFile::path(void) const {
const std::string& DiscImageFile::path() const {
return entry_->path();
}
const char* DiscImageFile::absolute_path(void) const {
const std::string& DiscImageFile::absolute_path() const {
return entry_->absolute_path();
}
const char* DiscImageFile::name(void) const {
const std::string& DiscImageFile::name() const {
return entry_->name();
}

View File

@@ -15,43 +15,39 @@
#include <xenia/kernel/objects/xfile.h>
namespace xe {
namespace kernel {
namespace fs {
class DiscImageEntry;
class DiscImageFile : public XFile {
public:
public:
DiscImageFile(KernelState* kernel_state, uint32_t desired_access,
DiscImageEntry* entry);
virtual ~DiscImageFile();
~DiscImageFile() override;
virtual const char* path(void) const;
virtual const char* absolute_path(void) const;
virtual const char* name(void) const;
const std::string& path() const override;
const std::string& absolute_path() const override;
const std::string& name() const override;
virtual X_STATUS QueryInfo(XFileInfo* out_info);
virtual X_STATUS QueryDirectory(XDirectoryInfo* out_info,
size_t length, const char* file_name, bool restart);
virtual X_STATUS QueryVolume(XVolumeInfo* out_info, size_t length);
virtual X_STATUS QueryFileSystemAttributes(XFileSystemAttributeInfo* out_info, size_t length);
X_STATUS QueryInfo(XFileInfo* out_info) override;
X_STATUS QueryDirectory(XDirectoryInfo* out_info, size_t length,
const char* file_name, bool restart) override;
X_STATUS QueryVolume(XVolumeInfo* out_info, size_t length) override;
X_STATUS QueryFileSystemAttributes(XFileSystemAttributeInfo* out_info,
size_t length) override;
protected:
virtual X_STATUS ReadSync(
void* buffer, size_t buffer_length, size_t byte_offset,
size_t* out_bytes_read);
protected:
X_STATUS ReadSync(void* buffer, size_t buffer_length, size_t byte_offset,
size_t* out_bytes_read) override;
private:
private:
DiscImageEntry* entry_;
};
} // namespace fs
} // namespace kernel
} // namespace xe
#endif // XENIA_KERNEL_FS_DEVICES_DISC_IMAGE_FILE_H_

View File

@@ -29,15 +29,15 @@ HostPathFile::~HostPathFile() {
CloseHandle(file_handle_);
}
const char* HostPathFile::path(void) const {
const std::string& HostPathFile::path() const {
return entry_->path();
}
const char* HostPathFile::absolute_path(void) const {
const std::string& HostPathFile::absolute_path() const {
return entry_->absolute_path();
}
const char* HostPathFile::name(void) const {
const std::string& HostPathFile::name() const {
return entry_->name();
}

View File

@@ -10,49 +10,47 @@
#ifndef XENIA_KERNEL_FS_DEVICES_HOST_PATH_FILE_H_
#define XENIA_KERNEL_FS_DEVICES_HOST_PATH_FILE_H_
#include <string>
#include <xenia/common.h>
#include <xenia/core.h>
#include <xenia/kernel/objects/xfile.h>
namespace xe {
namespace kernel {
namespace fs {
class HostPathEntry;
class HostPathFile : public XFile {
public:
public:
HostPathFile(KernelState* kernel_state, uint32_t desired_access,
HostPathEntry* entry, HANDLE file_handle);
virtual ~HostPathFile();
~HostPathFile() override;
virtual const char* path(void) const;
virtual const char* absolute_path(void) const;
virtual const char* name(void) const;
const std::string& path() const override;
const std::string& absolute_path() const override;
const std::string& name() const override;
virtual X_STATUS QueryInfo(XFileInfo* out_info);
virtual X_STATUS QueryDirectory(XDirectoryInfo* out_info,
size_t length, const char* file_name, bool restart);
virtual X_STATUS QueryVolume(XVolumeInfo* out_info, size_t length);
virtual X_STATUS QueryFileSystemAttributes(XFileSystemAttributeInfo* out_info, size_t length);
X_STATUS QueryInfo(XFileInfo* out_info) override;
X_STATUS QueryDirectory(XDirectoryInfo* out_info, size_t length,
const char* file_name, bool restart) override;
X_STATUS QueryVolume(XVolumeInfo* out_info, size_t length) override;
X_STATUS QueryFileSystemAttributes(XFileSystemAttributeInfo* out_info,
size_t length) override;
protected:
virtual X_STATUS ReadSync(
void* buffer, size_t buffer_length, size_t byte_offset,
size_t* out_bytes_read);
protected:
X_STATUS ReadSync(void* buffer, size_t buffer_length, size_t byte_offset,
size_t* out_bytes_read) override;
private:
private:
HostPathEntry* entry_;
HANDLE file_handle_;
HANDLE file_handle_;
};
} // namespace fs
} // namespace kernel
} // namespace xe
#endif // XENIA_KERNEL_FS_DEVICES_HOST_PATH_FILE_H_

View File

@@ -29,15 +29,15 @@ STFSContainerFile::STFSContainerFile(
STFSContainerFile::~STFSContainerFile() {
}
const char* STFSContainerFile::path(void) const {
const std::string& STFSContainerFile::path() const {
return entry_->path();
}
const char* STFSContainerFile::absolute_path(void) const {
const std::string& STFSContainerFile::absolute_path() const {
return entry_->absolute_path();
}
const char* STFSContainerFile::name(void) const {
const std::string& STFSContainerFile::name() const {
return entry_->name();
}

View File

@@ -15,43 +15,39 @@
#include <xenia/kernel/objects/xfile.h>
namespace xe {
namespace kernel {
namespace fs {
class STFSContainerEntry;
class STFSContainerFile : public XFile {
public:
public:
STFSContainerFile(KernelState* kernel_state, uint32_t desired_access,
STFSContainerEntry* entry);
virtual ~STFSContainerFile();
~STFSContainerFile() override;
virtual const char* path(void) const;
virtual const char* absolute_path(void) const;
virtual const char* name(void) const;
const std::string& path() const override;
const std::string& absolute_path() const override;
const std::string& name() const override;
virtual X_STATUS QueryInfo(XFileInfo* out_info);
virtual X_STATUS QueryDirectory(XDirectoryInfo* out_info,
size_t length, const char* file_name, bool restart);
virtual X_STATUS QueryVolume(XVolumeInfo* out_info, size_t length);
virtual X_STATUS QueryFileSystemAttributes(XFileSystemAttributeInfo* out_info, size_t length);
X_STATUS QueryInfo(XFileInfo* out_info) override;
X_STATUS QueryDirectory(XDirectoryInfo* out_info, size_t length,
const char* file_name, bool restart) override;
X_STATUS QueryVolume(XVolumeInfo* out_info, size_t length) override;
X_STATUS QueryFileSystemAttributes(XFileSystemAttributeInfo* out_info,
size_t length) override;
protected:
virtual X_STATUS ReadSync(
void* buffer, size_t buffer_length, size_t byte_offset,
size_t* out_bytes_read);
protected:
X_STATUS ReadSync(void* buffer, size_t buffer_length, size_t byte_offset,
size_t* out_bytes_read) override;
private:
private:
STFSContainerEntry* entry_;
};
} // namespace fs
} // namespace kernel
} // namespace xe
#endif // XENIA_KERNEL_FS_DEVICES_STFS_CONTAINER_FILE_H_

View File

@@ -14,28 +14,17 @@ using namespace xe;
using namespace xe::kernel;
using namespace xe::kernel::fs;
MemoryMapping::MemoryMapping(uint8_t* address, size_t length)
: address_(address), length_(length) {}
MemoryMapping::MemoryMapping(uint8_t* address, size_t length) :
address_(address), length_(length) {
}
MemoryMapping::~MemoryMapping() {}
MemoryMapping::~MemoryMapping() {
}
Entry::Entry(Type type, Device* device, const char* path) :
type_(type),
device_(device) {
Entry::Entry(Type type, Device* device, const std::string& path)
: type_(type), device_(device), path_(path) {
assert_not_null(device);
path_ = xestrdupa(path);
// TODO(benvanik): *shudder*
absolute_path_ = xestrdupa((std::string(device->path()) + std::string(path)).c_str());
absolute_path_ = device->path() + path;
// TODO(benvanik): last index of \, unless \ at end, then before that
name_ = NULL;
name_ = "";
}
Entry::~Entry() {
xe_free(name_);
xe_free(path_);
xe_free(absolute_path_);
}
Entry::~Entry() = default;

View File

@@ -10,6 +10,8 @@
#ifndef XENIA_KERNEL_FS_ENTRY_H_
#define XENIA_KERNEL_FS_ENTRY_H_
#include <string>
#include <xenia/common.h>
#include <xenia/core.h>
@@ -52,14 +54,14 @@ public:
kTypeDirectory,
};
Entry(Type type, Device* device, const char* path);
Entry(Type type, Device* device, const std::string& path);
virtual ~Entry();
Type type() const { return type_; }
Device* device() const { return device_; }
const char* path() const { return path_; }
const char* absolute_path() const { return absolute_path_; }
const char* name() const { return name_; }
const std::string& path() const { return path_; }
const std::string& absolute_path() const { return absolute_path_; }
const std::string& name() const { return name_; }
virtual X_STATUS QueryInfo(XFileInfo* out_info) = 0;
virtual X_STATUS QueryDirectory(XDirectoryInfo* out_info,
@@ -79,9 +81,9 @@ public:
private:
Type type_;
Device* device_;
char* path_;
char* absolute_path_;
char* name_;
std::string path_;
std::string absolute_path_;
std::string name_;
};

View File

@@ -9,6 +9,7 @@
#include <xenia/kernel/fs/filesystem.h>
#include <poly/string.h>
#include <xenia/kernel/fs/devices/disc_image_device.h>
#include <xenia/kernel/fs/devices/host_path_device.h>
#include <xenia/kernel/fs/devices/stfs_container_device.h>
@@ -129,24 +130,22 @@ int FileSystem::RegisterSTFSContainerDevice(
return RegisterDevice(path, device);
}
int FileSystem::CreateSymbolicLink(const char* path, const char* target) {
symlinks_.insert(std::pair<const char*, const char*>(
xestrdupa(path),
xestrdupa(target)));
int FileSystem::CreateSymbolicLink(const std::string& path,
const std::string& target) {
symlinks_.insert({path, target});
return 0;
}
int FileSystem::DeleteSymbolicLink(const char* path) {
std::unordered_map<std::string, std::string>::iterator it =
symlinks_.find(std::string(path));
if (it != symlinks_.end()) {
symlinks_.erase(it);
return 0;
int FileSystem::DeleteSymbolicLink(const std::string& path) {
auto& it = symlinks_.find(path);
if (it == symlinks_.end()) {
return 1;
}
return 1;
symlinks_.erase(it);
return 0;
}
Entry* FileSystem::ResolvePath(const char* path) {
Entry* FileSystem::ResolvePath(const std::string& path) {
// Strip off prefix and pass to device.
// e.g., d:\some\PATH.foo -> some\PATH.foo
// Support both symlinks and device specifiers, like:
@@ -158,33 +157,24 @@ Entry* FileSystem::ResolvePath(const char* path) {
// Resolve symlinks.
// TODO(benvanik): more robust symlink handling - right now we assume simple
// drive path -> device mappings with nothing nested.
char full_path[poly::max_path];
XEIGNORE(xestrcpya(full_path, XECOUNT(full_path), path));
for (std::unordered_map<std::string, std::string>::iterator it =
symlinks_.begin(); it != symlinks_.end(); ++it) {
if (xestrcasestra(path, it->first.c_str()) == path) {
// Found symlink, fixup.
const char* after_path = path + it->first.size();
XEIGNORE(xesnprintfa(full_path, XECOUNT(full_path), "%s%s",
it->second.c_str(), after_path));
std::string full_path = path;
for (const auto& it : symlinks_) {
if (poly::find_first_of_case(path, it.first) == 0) {
// Found symlink, fixup by replacing the prefix.
full_path = it.second + full_path.substr(it.first.size());
break;
}
}
// Scan all devices.
for (std::vector<Device*>::iterator it = devices_.begin();
it != devices_.end(); ++it) {
Device* device = *it;
if (xestrcasestra(full_path, device->path()) == full_path) {
// Found!
// Trim the device prefix off and pass down.
char device_path[poly::max_path];
XEIGNORE(xestrcpya(device_path, XECOUNT(device_path),
full_path + xestrlena(device->path())));
return device->ResolvePath(device_path);
for (auto& device : devices_) {
if (poly::find_first_of_case(full_path, device->path()) == 0) {
// Found! Trim the device prefix off and pass down.
auto device_path = full_path.substr(device->path().size());
return device->ResolvePath(device_path.c_str());
}
}
XELOGE("ResolvePath(%s) failed - no root found", path);
XELOGE("ResolvePath(%s) failed - no root found", path.c_str());
return NULL;
}

View File

@@ -47,10 +47,10 @@ class FileSystem {
int RegisterSTFSContainerDevice(const std::string& path,
const std::wstring& local_path);
int CreateSymbolicLink(const char* path, const char* target);
int DeleteSymbolicLink(const char* path);
int CreateSymbolicLink(const std::string& path, const std::string& target);
int DeleteSymbolicLink(const std::string& path);
Entry* ResolvePath(const char* path);
Entry* ResolvePath(const std::string& path);
private:
std::vector<Device*> devices_;

View File

@@ -40,7 +40,7 @@ GDFXEntry* GDFXEntry::GetChild(const char* name) {
for (std::vector<GDFXEntry*>::iterator it = children.begin();
it != children.end(); ++it) {
GDFXEntry* entry = *it;
if (xestrcasecmpa(entry->name.c_str(), name) == 0) {
if (strcasecmp(entry->name.c_str(), name) == 0) {
return entry;
}
}

View File

@@ -108,7 +108,7 @@ STFSEntry* STFSEntry::GetChild(const char* name) {
// TODO(benvanik): a faster search
for (auto it = children.begin(); it != children.end(); ++it) {
STFSEntry* entry = *it;
if (xestrcasecmpa(entry->name.c_str(), name) == 0) {
if (strcasecmp(entry->name.c_str(), name) == 0) {
return entry;
}
}

View File

@@ -80,15 +80,15 @@ XModule* KernelState::GetModule(const char* name) {
// NULL name = self.
// TODO(benvanik): lookup module from caller address.
return GetExecutableModule();
} else if (xestrcasecmpa(name, "xam.xex") == 0) {
} else if (strcasecmp(name, "xam.xex") == 0) {
auto module = emulator_->xam();
module->Retain();
return module;
} else if (xestrcasecmpa(name, "xboxkrnl.exe") == 0) {
} else if (strcasecmp(name, "xboxkrnl.exe") == 0) {
auto module = emulator_->xboxkrnl();
module->Retain();
return module;
} else if (xestrcasecmpa(name, "kernel32.dll") == 0) {
} else if (strcasecmp(name, "kernel32.dll") == 0) {
// Some games request this, for some reason. wtf.
return NULL;
} else {

View File

@@ -127,18 +127,19 @@ class XFile : public XObject {
public:
virtual ~XFile();
virtual const char* path(void) const = 0;
virtual const char* absolute_path(void) const = 0;
virtual const char* name(void) const = 0;
virtual const std::string& path() const = 0;
virtual const std::string& absolute_path() const = 0;
virtual const std::string& name() const = 0;
size_t position() const { return position_; }
void set_position(size_t value) { position_ = value; }
virtual X_STATUS QueryInfo(XFileInfo* out_info) = 0;
virtual X_STATUS QueryDirectory(XDirectoryInfo* out_info,
size_t length, const char* file_name, bool restart) = 0;
virtual X_STATUS QueryDirectory(XDirectoryInfo* out_info, size_t length,
const char* file_name, bool restart) = 0;
virtual X_STATUS QueryVolume(XVolumeInfo* out_info, size_t length) = 0;
virtual X_STATUS QueryFileSystemAttributes(XFileSystemAttributeInfo* out_info, size_t length) = 0;
virtual X_STATUS QueryFileSystemAttributes(XFileSystemAttributeInfo* out_info,
size_t length) = 0;
X_STATUS Read(void* buffer, size_t buffer_length, size_t byte_offset,
size_t* out_bytes_read);

View File

@@ -42,7 +42,6 @@ XThread::XThread(KernelState* kernel_state,
thread_state_address_(0),
thread_state_(0),
event_(NULL),
name_(0),
irql_(0) {
creation_params_.stack_size = stack_size;
creation_params_.xapi_thread_startup = xapi_thread_startup;
@@ -95,9 +94,6 @@ XThread::~XThread() {
if (thread_state_address_) {
kernel_state()->memory()->HeapFree(thread_state_address_, 0);
}
if (name_) {
xe_free(name_);
}
if (thread_handle_) {
// TODO(benvanik): platform kill
@@ -149,35 +145,9 @@ void XThread::set_last_error(uint32_t error_code) {
poly::store_and_swap<uint32_t>(p + 0x160, error_code);
}
void XThread::set_name(const char* name) {
if (name == name_) {
return;
}
if (name_) {
xe_free(name_);
}
name_ = xestrdupa(name);
#if XE_PLATFORM_WIN32
// Do the nasty set for us.
#pragma pack(push, 8)
typedef struct tagTHREADNAME_INFO {
DWORD dwType; // must be 0x1000
LPCSTR szName; // pointer to name (in user addr space)
DWORD dwThreadID; // thread ID (-1=caller thread)
DWORD dwFlags; // reserved for future use, must be zero
} THREADNAME_INFO;
#pragma pack(pop)
THREADNAME_INFO info;
info.dwType = 0x1000;
info.szName = name_;
info.dwThreadID = ::GetThreadId(thread_handle_);
info.dwFlags = 0;
__try {
RaiseException(0x406D1388, 0, sizeof(info) / sizeof(ULONG_PTR), (ULONG_PTR*)&info);
} __except(EXCEPTION_CONTINUE_EXECUTION) {
}
#endif // WIN32
void XThread::set_name(const std::string& name) {
name_ = name;
poly::threading::set_name(thread_handle_, name);
}
X_STATUS XThread::Create() {
@@ -287,7 +257,7 @@ X_STATUS XThread::Exit(int exit_code) {
static uint32_t __stdcall XThreadStartCallbackWin32(void* param) {
XThread* thread = reinterpret_cast<XThread*>(param);
xe::Profiler::ThreadEnter(thread->name());
xe::Profiler::ThreadEnter(thread->name().c_str());
current_thread_tls = thread;
thread->Execute();
current_thread_tls = nullptr;

View File

@@ -12,6 +12,7 @@
#include <atomic>
#include <mutex>
#include <string>
#include <xenia/kernel/xobject.h>
@@ -44,8 +45,8 @@ public:
uint32_t thread_id();
uint32_t last_error();
void set_last_error(uint32_t error_code);
const char* name() const { return name_; }
void set_name(const char* name);
const std::string& name() const { return name_; }
void set_name(const std::string& name);
X_STATUS Create();
X_STATUS Exit(int exit_code);
@@ -96,7 +97,7 @@ private:
uint32_t thread_state_address_;
cpu::XenonThreadState* thread_state_;
char* name_;
std::string name_;
std::atomic<uint32_t> irql_;
std::mutex apc_lock_;

View File

@@ -139,7 +139,7 @@ X_STATUS XUserModule::GetSection(
auto header = xe_xex2_get_header(xex_);
for (size_t n = 0; n < header->resource_info_count; n++) {
auto& res = header->resource_infos[n];
if (xestrcmpa(name, res.name) == 0) {
if (strcmp(name, res.name) == 0) {
// Found!
*out_section_data = res.address;
*out_section_size = res.size;

View File

@@ -902,7 +902,7 @@ int xe_xex2_load_pe(xe_xex2_ref xex) {
const PESection* xe_xex2_get_pe_section(xe_xex2_ref xex, const char* name) {
for (std::vector<PESection*>::iterator it = xex->sections->begin();
it != xex->sections->end(); ++it) {
if (!xestrcmpa((*it)->name, name)) {
if (!strcmp((*it)->name, name)) {
return *it;
}
}