Make vm::var unmoveable

Fix bugs with discarding vm::make_var result
This commit is contained in:
Nekotekina 2018-09-03 15:09:09 +03:00
parent 8abe6489ed
commit 7bccdbf157
7 changed files with 65 additions and 61 deletions

View File

@ -80,7 +80,8 @@ error_code cellPhotoImport(u32 version, vm::cptr<char> dstHddPath, vm::ptr<CellP
sysutil_register_cb([=](ppu_thread& ppu) -> s32
{
vm::var<CellPhotoImportFileData> filedata;
filedata->data_sub = vm::var<CellPhotoImportFileDataSub>();
vm::var<CellPhotoImportFileDataSub> sub;
filedata->data_sub = sub;
funcFinish(ppu, CELL_OK, filedata, userdata);
return CELL_OK;
});
@ -95,7 +96,8 @@ error_code cellPhotoImport2(u32 version, vm::cptr<char> dstHddPath, vm::ptr<Cell
sysutil_register_cb([=](ppu_thread& ppu) -> s32
{
vm::var<CellPhotoImportFileData> filedata;
filedata->data_sub = vm::var<CellPhotoImportFileDataSub>();
vm::var<CellPhotoImportFileDataSub> sub;
filedata->data_sub = sub;
funcFinish(ppu, CELL_OK, filedata, userdata);
return CELL_OK;
});

View File

@ -309,7 +309,7 @@ error_code sceNpTrophyRegisterContext(ppu_thread& ppu, u32 context, u32 handle,
ctxt->tropusr.reset(tropusr);
// TODO: Callbacks
// From RE-ing a game's state machine, it seems the possible order is one of the following:
// From RE-ing a game's state machine, it seems the possible order is one of the following:
// * Install (Not installed) - Setup - Progress * ? - Finalize - Complete - Installed
// * Reinstall (Corrupted) - Setup - Progress * ? - Finalize - Complete - Installed
// * Update (Required update) - Setup - Progress * ? - Finalize - Complete - Installed
@ -533,8 +533,8 @@ error_code sceNpTrophyUnlockTrophy(u32 context, u32 handle, s32 trophyId, vm::pt
std::vector<uchar> trophyIconData;
trophyIconFile.read(trophyIconData, iconSize);
vm::ptr<SceNpTrophyDetails> details = vm::make_var(SceNpTrophyDetails());
vm::ptr<SceNpTrophyData> _ = vm::make_var(SceNpTrophyData());
vm::var<SceNpTrophyDetails> details({0});
vm::var<SceNpTrophyData> _({0});
s32 ret = sceNpTrophyGetTrophyInfo(context, handle, trophyId, details, _);
if (ret != CELL_OK)

View File

@ -12,14 +12,7 @@ extern vm::gvar<sys_lwmutex_t> g_ppu_prx_lwm;
// Convert the array of 32-bit pointers to 64-bit pointers using stack allocation
static auto convert_path_list(vm::cpptr<char> path_list, s32 count)
{
vm::var<vm::cptr<char, u64>[]> result(count);
for (s32 i = 0; i < count; i++)
{
result[i] = path_list[i];
}
return std::move(result);
return vm::var<vm::cptr<char, u64>[]>(count, path_list.get_ptr());
}
// Execute start or stop module function

View File

@ -188,7 +188,7 @@ error_code sys_spu_elf_get_information(u32 elf_img, vm::ptr<u32> entry, vm::ptr<
sysPrxForUser.warning("sys_spu_elf_get_information(elf_img=0x%x, entry=*0x%x, nseg=*0x%x)", elf_img, entry, nseg);
// Initialize ELF loader
vm::var<spu_elf_info> info(spu_elf_info{});
vm::var<spu_elf_info> info({0});
if (auto res = info->init(vm::cast(elf_img)))
{
@ -202,7 +202,7 @@ error_code sys_spu_elf_get_information(u32 elf_img, vm::ptr<u32> entry, vm::ptr<
}
// Load ELF header
vm::var<elf_ehdr<elf_be, u64>> ehdr(elf_ehdr<elf_be, u64>{});
vm::var<elf_ehdr<elf_be, u64>> ehdr({0});
if (info->ldr->get_ehdr(ehdr) || ehdr->e_machine != elf_machine::spu || !ehdr->e_phnum)
{
@ -234,7 +234,7 @@ error_code sys_spu_elf_get_segments(u32 elf_img, vm::ptr<sys_spu_segment> segmen
sysPrxForUser.warning("sys_spu_elf_get_segments(elf_img=0x%x, segments=*0x%x, nseg=0x%x)", elf_img, segments, nseg);
// Initialize ELF loader
vm::var<spu_elf_info> info(spu_elf_info{});
vm::var<spu_elf_info> info({0});
if (auto res = info->init(vm::cast(elf_img)))
{
@ -242,7 +242,7 @@ error_code sys_spu_elf_get_segments(u32 elf_img, vm::ptr<sys_spu_segment> segmen
}
// Load ELF header
vm::var<elf_ehdr<elf_be, u64>> ehdr(elf_ehdr<elf_be, u64>{});
vm::var<elf_ehdr<elf_be, u64>> ehdr({0});
if (info->ldr->get_ehdr(ehdr) || ehdr->e_machine != elf_machine::spu || !ehdr->e_phnum)
{
@ -281,7 +281,7 @@ error_code sys_spu_image_import(vm::ptr<sys_spu_image> img, u32 src, u32 type)
}
// Initialize ELF loader
vm::var<spu_elf_info> info(spu_elf_info{});
vm::var<spu_elf_info> info({0});
if (auto res = info->init(vm::cast(src)))
{
@ -295,7 +295,7 @@ error_code sys_spu_image_import(vm::ptr<sys_spu_image> img, u32 src, u32 type)
}
// Load ELF header
vm::var<elf_ehdr<elf_be, u64>> ehdr(elf_ehdr<elf_be, u64>{});
vm::var<elf_ehdr<elf_be, u64>> ehdr({0});
if (info->ldr->get_ehdr(ehdr) || ehdr->e_machine != elf_machine::spu || !ehdr->e_phnum)
{

View File

@ -426,7 +426,7 @@ error_code sys_mmapper_enable_page_fault_notification(u32 start_addr, u32 event_
}
}
vm::ptr<u32> port_id = vm::make_var<u32>(0);
vm::var<u32> port_id(0);
error_code res = sys_event_port_create(port_id, SYS_EVENT_PORT_LOCAL, SYS_MEMORY_PAGE_FAULT_EVENT_KEY);
sys_event_port_connect_local(port_id->value(), event_queue_id);

View File

@ -131,11 +131,12 @@ s32 sys_rsx_context_allocate(vm::ptr<u32> context_id, vm::ptr<u64> lpar_dma_cont
else
rsx::get_current_renderer()->main_mem_size = 0x10000000; //256MB
sys_event_queue_attribute_t attr;
attr.protocol = SYS_SYNC_PRIORITY;
attr.type = SYS_PPU_QUEUE;
auto queueId = vm::make_var<u32>(0);
sys_event_queue_create(queueId, vm::make_var(attr), 0, 0x20);
vm::var<sys_event_queue_attribute_t> attr;
attr->protocol = SYS_SYNC_PRIORITY;
attr->type = SYS_PPU_QUEUE;
attr->name_u64 = 0;
vm::var<u32> queueId(0);
sys_event_queue_create(queueId, attr, 0, 0x20);
driverInfo.handler_queue = queueId->value();
sys_event_port_create(queueId, SYS_EVENT_PORT_LOCAL, 0);

View File

@ -4,7 +4,7 @@
namespace vm
{
template<memory_location_t Location = vm::main>
template <memory_location_t Location = vm::main>
struct page_allocator
{
static inline vm::addr_t alloc(u32 size, u32 align)
@ -18,7 +18,7 @@ namespace vm
}
};
template<typename T>
template <typename T>
struct stack_allocator
{
static inline vm::addr_t alloc(u32 size, u32 align)
@ -32,38 +32,38 @@ namespace vm
}
};
// Variable general specialization
template<typename T, typename A>
// General variable base class
template <typename T, typename A>
class _var_base final : public _ptr_base<T, const u32>
{
using pointer = _ptr_base<T, const u32>;
public:
// Unmoveable object
_var_base(const _var_base&) = delete;
_var_base()
: pointer(A::alloc(SIZE_32(T), alignof(T)))
: pointer(A::alloc(SIZE_32(T), alignof(T)))
{
}
_var_base(const T& right)
: _var_base()
: _var_base()
{
std::memcpy(pointer::get_ptr(), &right, sizeof(T));
}
_var_base(_var_base&& right)
: pointer(right)
{
reinterpret_cast<u32&>(static_cast<pointer&>(right)) = 0;
}
~_var_base()
{
if (pointer::addr()) A::dealloc(pointer::addr(), SIZE_32(T));
if (pointer::addr())
{
A::dealloc(pointer::addr(), SIZE_32(T));
}
}
};
// Dynamic length array variable
template<typename T, typename A>
// Dynamic length array variable specialization
template <typename T, typename A>
class _var_base<T[], A> final : public _ptr_base<T, const u32>
{
using pointer = _ptr_base<T, const u32>;
@ -71,26 +71,33 @@ namespace vm
u32 m_size;
public:
// Unmoveable object
_var_base(const _var_base&) = delete;
_var_base(u32 count)
: pointer(A::alloc(SIZE_32(T) * count, alignof(T)))
, m_size(SIZE_32(T) * count)
: pointer(A::alloc(SIZE_32(T) * count, alignof(T)))
, m_size(SIZE_32(T) * count)
{
}
_var_base(_var_base&& right)
: pointer(right)
, m_size(right.m_size)
// Initialize via the iterator
template <typename I>
_var_base(u32 count, I&& it)
: _var_base(count)
{
reinterpret_cast<u32&>(static_cast<pointer&>(right)) = 0;
std::copy_n(std::forward<I>(it), count, pointer::get_ptr());
}
~_var_base()
{
if (pointer::addr()) A::dealloc(pointer::addr(), m_size);
if (pointer::addr())
{
A::dealloc(pointer::addr(), m_size);
}
}
// Remove operator ->
T* operator ->() const = delete;
T* operator->() const = delete;
u32 get_count() const
{
@ -109,36 +116,37 @@ namespace vm
};
// LE variable
template<typename T, typename A> using varl = _var_base<to_le_t<T>, A>;
template <typename T, typename A>
using varl = _var_base<to_le_t<T>, A>;
// BE variable
template<typename T, typename A> using varb = _var_base<to_be_t<T>, A>;
template <typename T, typename A>
using varb = _var_base<to_be_t<T>, A>;
inline namespace ps3_
{
// BE variable
template<typename T, typename A = stack_allocator<ppu_thread>> using var = varb<T, A>;
template <typename T, typename A = stack_allocator<ppu_thread>>
using var = varb<T, A>;
// Make BE variable initialized from value
template<typename T, typename A = stack_allocator<ppu_thread>>
inline auto make_var(const T& value)
template <typename T, typename A = stack_allocator<ppu_thread>>
[[nodiscard]] auto make_var(const T& value)
{
return varb<T, A>(value);
}
// Make char[] variable initialized from std::string
template<typename A = stack_allocator<ppu_thread>>
static auto make_str(const std::string& str)
template <typename A = stack_allocator<ppu_thread>>
[[nodiscard]] auto make_str(const std::string& str)
{
var<char[], A> var_(size32(str) + 1);
std::memcpy(var_.get_ptr(), str.c_str(), str.size() + 1);
return var_;
return _var_base<char[], A>(size32(str) + 1, str.c_str());
}
// Global HLE variable
template<typename T>
template <typename T>
struct gvar : ptr<T>
{
};
}
}
} // namespace ps3_
} // namespace vm