2014-06-23 19:40:40 +02:00
|
|
|
#include "stdafx.h"
|
|
|
|
|
#include "Emu/Memory/Memory.h"
|
|
|
|
|
#include "Emu/System.h"
|
2015-03-06 23:58:42 +01:00
|
|
|
#include "Emu/IdManager.h"
|
2014-06-23 19:40:40 +02:00
|
|
|
#include "Emu/SysCalls/SysCalls.h"
|
2014-08-23 16:51:51 +02:00
|
|
|
|
2014-08-26 01:55:37 +02:00
|
|
|
#include "Emu/FS/VFS.h"
|
2014-07-11 13:59:13 +02:00
|
|
|
#include "Emu/FS/vfsFile.h"
|
2014-08-19 12:14:26 +02:00
|
|
|
#include "Crypto/unself.h"
|
2014-06-25 00:38:34 +02:00
|
|
|
#include "sys_prx.h"
|
2014-06-23 19:40:40 +02:00
|
|
|
|
|
|
|
|
SysCallBase sys_prx("sys_prx");
|
|
|
|
|
|
2014-09-04 19:32:20 +02:00
|
|
|
s32 sys_prx_load_module(vm::ptr<const char> path, u64 flags, vm::ptr<sys_prx_load_module_option_t> pOpt)
|
2014-06-23 19:40:40 +02:00
|
|
|
{
|
2014-09-04 19:32:20 +02:00
|
|
|
sys_prx.Todo("sys_prx_load_module(path=\"%s\", flags=0x%llx, pOpt=0x%x)", path.get_ptr(), flags, pOpt.addr());
|
2014-06-23 19:40:40 +02:00
|
|
|
|
2014-09-04 19:32:20 +02:00
|
|
|
std::string _path = path.get_ptr();
|
2014-08-19 12:14:26 +02:00
|
|
|
// Check if the file is SPRX
|
|
|
|
|
std::string local_path;
|
2014-09-04 19:32:20 +02:00
|
|
|
Emu.GetVFS().GetDevice(_path, local_path);
|
2014-08-19 12:14:26 +02:00
|
|
|
if (IsSelf(local_path)) {
|
|
|
|
|
if (!DecryptSelf(local_path+".prx", local_path)) {
|
|
|
|
|
return CELL_PRX_ERROR_ILLEGAL_LIBRARY;
|
|
|
|
|
}
|
2014-09-04 19:32:20 +02:00
|
|
|
_path += ".prx";
|
2014-08-19 12:14:26 +02:00
|
|
|
}
|
|
|
|
|
|
2014-09-04 19:32:20 +02:00
|
|
|
vfsFile f(_path);
|
2014-06-23 19:40:40 +02:00
|
|
|
if (!f.IsOpened()) {
|
|
|
|
|
return CELL_PRX_ERROR_UNKNOWN_MODULE;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-19 12:14:26 +02:00
|
|
|
// Create the PRX object and return its id
|
2015-05-28 21:13:35 +02:00
|
|
|
std::shared_ptr<lv2_prx_t> prx = std::make_shared<lv2_prx_t>();
|
2014-08-30 22:41:01 +02:00
|
|
|
prx->size = (u32)f.GetSize();
|
|
|
|
|
prx->address = (u32)Memory.Alloc(prx->size, 4);
|
2014-11-19 15:16:30 +01:00
|
|
|
prx->path = (const char*)path;
|
2014-08-19 12:14:26 +02:00
|
|
|
|
2014-06-23 19:40:40 +02:00
|
|
|
// Load the PRX into memory
|
2014-11-19 15:16:30 +01:00
|
|
|
f.Read(vm::get_ptr(prx->address), prx->size);
|
2014-06-23 19:40:40 +02:00
|
|
|
|
2015-05-28 21:13:35 +02:00
|
|
|
return Emu.GetIdManager().add(std::move(prx));
|
2014-06-23 19:40:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 sys_prx_load_module_on_memcontainer()
|
|
|
|
|
{
|
2014-07-21 16:42:43 +02:00
|
|
|
sys_prx.Todo("sys_prx_load_module_on_memcontainer()");
|
2014-06-23 19:40:40 +02:00
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 sys_prx_load_module_by_fd()
|
|
|
|
|
{
|
2014-07-21 16:42:43 +02:00
|
|
|
sys_prx.Todo("sys_prx_load_module_by_fd()");
|
2014-06-23 19:40:40 +02:00
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 sys_prx_load_module_on_memcontainer_by_fd()
|
|
|
|
|
{
|
2014-07-21 16:42:43 +02:00
|
|
|
sys_prx.Todo("sys_prx_load_module_on_memcontainer_by_fd()");
|
2014-06-23 19:40:40 +02:00
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-11 19:20:01 +02:00
|
|
|
s32 sys_prx_start_module(s32 id, u32 args, u32 argp_addr, vm::ptr<u32> modres, u64 flags, vm::ptr<sys_prx_start_module_option_t> pOpt)
|
2014-06-23 19:40:40 +02:00
|
|
|
{
|
2015-04-14 04:00:31 +02:00
|
|
|
sys_prx.Todo("sys_prx_start_module(id=0x%x, args=%d, argp_addr=0x%x, modres_addr=0x%x, flags=0x%llx, pOpt=0x%x)",
|
2014-09-02 03:05:13 +02:00
|
|
|
id, args, argp_addr, modres.addr(), flags, pOpt.addr());
|
2014-06-23 19:40:40 +02:00
|
|
|
|
2015-05-27 05:11:59 +02:00
|
|
|
const auto prx = Emu.GetIdManager().get<lv2_prx_t>(id);
|
2015-04-14 04:00:31 +02:00
|
|
|
|
|
|
|
|
if (!prx)
|
|
|
|
|
{
|
2014-06-23 19:40:40 +02:00
|
|
|
return CELL_ESRCH;
|
2015-04-14 04:00:31 +02:00
|
|
|
}
|
2014-06-23 19:40:40 +02:00
|
|
|
|
|
|
|
|
if (prx->isStarted)
|
|
|
|
|
return CELL_PRX_ERROR_ALREADY_STARTED;
|
|
|
|
|
|
|
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-11 19:20:01 +02:00
|
|
|
s32 sys_prx_stop_module(s32 id, u32 args, u32 argp_addr, vm::ptr<u32> modres, u64 flags, vm::ptr<sys_prx_stop_module_option_t> pOpt)
|
2014-06-23 19:40:40 +02:00
|
|
|
{
|
2015-04-14 04:00:31 +02:00
|
|
|
sys_prx.Todo("sys_prx_stop_module(id=0x%x, args=%d, argp_addr=0x%x, modres_addr=0x%x, flags=0x%llx, pOpt=0x%x)",
|
2014-09-02 03:05:13 +02:00
|
|
|
id, args, argp_addr, modres.addr(), flags, pOpt.addr());
|
2014-06-23 19:40:40 +02:00
|
|
|
|
2015-05-27 05:11:59 +02:00
|
|
|
const auto prx = Emu.GetIdManager().get<lv2_prx_t>(id);
|
2015-04-14 04:00:31 +02:00
|
|
|
|
|
|
|
|
if (!prx)
|
|
|
|
|
{
|
2014-06-23 19:40:40 +02:00
|
|
|
return CELL_ESRCH;
|
2015-04-14 04:00:31 +02:00
|
|
|
}
|
2014-06-23 19:40:40 +02:00
|
|
|
|
|
|
|
|
if (!prx->isStarted)
|
|
|
|
|
return CELL_PRX_ERROR_ALREADY_STOPPED;
|
|
|
|
|
|
|
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-02 03:05:13 +02:00
|
|
|
s32 sys_prx_unload_module(s32 id, u64 flags, vm::ptr<sys_prx_unload_module_option_t> pOpt)
|
2014-06-23 19:40:40 +02:00
|
|
|
{
|
2015-04-14 04:00:31 +02:00
|
|
|
sys_prx.Todo("sys_prx_unload_module(id=0x%x, flags=0x%llx, pOpt=0x%x)", id, flags, pOpt.addr());
|
2014-06-23 19:40:40 +02:00
|
|
|
|
|
|
|
|
// Get the PRX, free the used memory and delete the object and its ID
|
2015-05-27 05:11:59 +02:00
|
|
|
const auto prx = Emu.GetIdManager().get<lv2_prx_t>(id);
|
2015-04-14 04:00:31 +02:00
|
|
|
|
|
|
|
|
if (!prx)
|
|
|
|
|
{
|
2014-06-23 19:40:40 +02:00
|
|
|
return CELL_ESRCH;
|
2015-04-14 04:00:31 +02:00
|
|
|
}
|
|
|
|
|
|
2014-06-23 19:40:40 +02:00
|
|
|
Memory.Free(prx->address);
|
2015-05-27 05:11:59 +02:00
|
|
|
Emu.GetIdManager().remove<lv2_prx_t>(id);
|
2014-06-23 19:40:40 +02:00
|
|
|
|
|
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 sys_prx_get_module_list()
|
|
|
|
|
{
|
2014-07-21 16:42:43 +02:00
|
|
|
sys_prx.Todo("sys_prx_get_module_list()");
|
2014-06-23 19:40:40 +02:00
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 sys_prx_get_my_module_id()
|
|
|
|
|
{
|
2014-07-21 16:42:43 +02:00
|
|
|
sys_prx.Todo("sys_prx_get_my_module_id()");
|
2014-06-23 19:40:40 +02:00
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 sys_prx_get_module_id_by_address()
|
|
|
|
|
{
|
2014-07-21 16:42:43 +02:00
|
|
|
sys_prx.Todo("sys_prx_get_module_id_by_address()");
|
2014-06-23 19:40:40 +02:00
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 sys_prx_get_module_id_by_name()
|
|
|
|
|
{
|
2014-07-21 16:42:43 +02:00
|
|
|
sys_prx.Todo("sys_prx_get_module_id_by_name()");
|
2015-02-19 12:18:28 +01:00
|
|
|
return CELL_PRX_ERROR_UNKNOWN_MODULE;
|
2014-06-23 19:40:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 sys_prx_get_module_info()
|
|
|
|
|
{
|
2014-07-21 16:42:43 +02:00
|
|
|
sys_prx.Todo("sys_prx_get_module_info()");
|
2014-06-23 19:40:40 +02:00
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 sys_prx_register_library(u32 lib_addr)
|
|
|
|
|
{
|
2014-07-21 16:42:43 +02:00
|
|
|
sys_prx.Todo("sys_prx_register_library(lib_addr=0x%x)", lib_addr);
|
2014-06-23 19:40:40 +02:00
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 sys_prx_unregister_library()
|
|
|
|
|
{
|
2014-07-21 16:42:43 +02:00
|
|
|
sys_prx.Todo("sys_prx_unregister_library()");
|
2014-06-23 19:40:40 +02:00
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 sys_prx_get_ppu_guid()
|
|
|
|
|
{
|
2014-07-21 16:42:43 +02:00
|
|
|
sys_prx.Todo("sys_prx_get_ppu_guid()");
|
2014-06-23 19:40:40 +02:00
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 sys_prx_register_module()
|
|
|
|
|
{
|
2014-07-21 16:42:43 +02:00
|
|
|
sys_prx.Todo("sys_prx_register_module()");
|
2014-06-23 19:40:40 +02:00
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 sys_prx_query_module()
|
|
|
|
|
{
|
2014-07-21 16:42:43 +02:00
|
|
|
sys_prx.Todo("sys_prx_query_module()");
|
2014-06-23 19:40:40 +02:00
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 sys_prx_link_library()
|
|
|
|
|
{
|
2014-07-21 16:42:43 +02:00
|
|
|
sys_prx.Todo("sys_prx_link_library()");
|
2014-06-23 19:40:40 +02:00
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 sys_prx_unlink_library()
|
|
|
|
|
{
|
2014-07-21 16:42:43 +02:00
|
|
|
sys_prx.Todo("sys_prx_unlink_library()");
|
2014-06-23 19:40:40 +02:00
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 sys_prx_query_library()
|
|
|
|
|
{
|
2014-07-21 16:42:43 +02:00
|
|
|
sys_prx.Todo("sys_prx_query_library()");
|
2014-06-23 19:40:40 +02:00
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 sys_prx_start()
|
|
|
|
|
{
|
2014-07-21 16:42:43 +02:00
|
|
|
sys_prx.Todo("sys_prx_start()");
|
2014-06-23 19:40:40 +02:00
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 sys_prx_stop()
|
|
|
|
|
{
|
2014-07-21 16:42:43 +02:00
|
|
|
sys_prx.Todo("sys_prx_stop()");
|
2014-06-23 19:40:40 +02:00
|
|
|
return CELL_OK;
|
|
|
|
|
}
|