idm::last_id cleanup

This commit is contained in:
Nekotekina 2017-02-04 18:09:02 +03:00
parent e3e4decabf
commit fe26db4d36
5 changed files with 16 additions and 39 deletions

View File

@ -22,8 +22,6 @@ struct trophy_context_t
static const u32 id_step = 1;
static const u32 id_count = 1023;
const u32 id = idm::last_id();
std::string trp_name;
fs::file trp_stream;
std::unique_ptr<TROPUSRLoader> tropusr;
@ -34,8 +32,6 @@ struct trophy_handle_t
static const u32 id_base = 1;
static const u32 id_step = 1;
static const u32 id_count = 1023;
const u32 id = idm::last_id();
};
// Functions
@ -125,7 +121,7 @@ s32 sceNpTrophyCreateContext(vm::ptr<u32> context, vm::cptr<SceNpCommunicationId
// set trophy context parameters (could be passed to constructor through make_ptr call)
ctxt->trp_name = std::move(name);
ctxt->trp_stream = std::move(stream);
*context = ctxt->id;
*context = idm::last_id();
return CELL_OK;
}

View File

@ -4,6 +4,7 @@
#include <mutex>
#include "Emu/VFS.h"
#include "Emu/IdManager.h"
#include "Utilities/StrUtil.h"
namespace vm { using namespace ps3; }
@ -143,17 +144,14 @@ error_code sys_fs_open(vm::cptr<char> path, s32 flags, vm::ptr<u32> fd, s32 mode
return CELL_ENOENT;
}
const auto _file = idm::make_ptr<lv2_fs_object, lv2_file>(path.get_ptr(), std::move(file), mode, flags);
if (!_file)
if (const u32 id = idm::make<lv2_fs_object, lv2_file>(path.get_ptr(), std::move(file), mode, flags))
{
// out of file descriptors
return CELL_EMFILE;
*fd = id;
return CELL_OK;
}
*fd = _file->id;
return CELL_OK;
// Out of file descriptors
return CELL_EMFILE;
}
error_code sys_fs_read(u32 fd, vm::ptr<void> buf, u64 nbytes, vm::ptr<u64> nread)
@ -245,18 +243,14 @@ error_code sys_fs_opendir(vm::cptr<char> path, vm::ptr<u32> fd)
return CELL_ENOENT;
}
const auto _dir = idm::make_ptr<lv2_fs_object, lv2_dir>(path.get_ptr(), std::move(dir));
if (!_dir)
if (const u32 id = idm::make<lv2_fs_object, lv2_dir>(path.get_ptr(), std::move(dir)))
{
// out of file descriptors
return CELL_EMFILE;
*fd = id;
return CELL_OK;
}
*fd = _dir->id;
sys_fs.notice("sys_fs_opendir(%s) -> lv2_fs_id %d", path, _dir->id);
return CELL_OK;
// Out of file descriptors
return CELL_EMFILE;
}
error_code sys_fs_readdir(u32 fd, vm::ptr<CellFsDirent> dir, vm::ptr<u64> nread)

View File

@ -2,7 +2,6 @@
#include "Emu/Memory/Memory.h"
#include "Emu/Cell/ErrorCodes.h"
#include "Emu/IdManager.h"
// Open Flags
enum : s32
@ -102,14 +101,11 @@ struct lv2_fs_object
static const u32 id_step = 1;
static const u32 id_count = 255 - id_base;
const u32 id;
// Mount Point
const std::add_pointer_t<lv2_fs_mount_point> mp;
lv2_fs_object(lv2_fs_mount_point* mp)
: mp(mp)
, id(idm::last_id())
{
}
@ -185,7 +181,8 @@ struct lv2_file_op_rw : lv2_file_op
CHECK_SIZE(lv2_file_op_rw, 0x38);
// SysCalls
// Syscalls
error_code sys_fs_test(u32 arg1, u32 arg2, vm::ps3::ptr<u32> arg3, u32 arg4, vm::ps3::ptr<char> arg5, u32 arg6);
error_code sys_fs_open(vm::ps3::cptr<char> path, s32 flags, vm::ps3::ptr<u32> fd, s32 mode, vm::ps3::cptr<void> arg, u64 size);
error_code sys_fs_read(u32 fd, vm::ps3::ptr<void> buf, u64 nbytes, vm::ps3::ptr<u64> nread);

View File

@ -32,7 +32,7 @@ s32 prx_load_module(std::string path, u64 flags, vm::ptr<sys_prx_load_module_opt
return CELL_PRX_ERROR_ILLEGAL_LIBRARY;
}
return prx->id;
return idm::last_id();
}
s32 sys_prx_load_module(vm::cptr<char> path, u64 flags, vm::ptr<sys_prx_load_module_option_t> pOpt)
@ -124,7 +124,7 @@ s32 sys_prx_unload_module(s32 id, u64 flags, vm::ptr<sys_prx_unload_module_optio
sys_prx.warning("sys_prx_unload_module(id=0x%x, flags=0x%llx, pOpt=*0x%x)", id, flags, pOpt);
// Get the PRX, free the used memory and delete the object and its ID
const auto prx = idm::get<lv2_obj, lv2_prx>(id);
const auto prx = idm::withdraw<lv2_obj, lv2_prx>(id);
if (!prx)
{
@ -134,7 +134,6 @@ s32 sys_prx_unload_module(s32 id, u64 flags, vm::ptr<sys_prx_unload_module_optio
//Memory.Free(prx->address);
//s32 result = prx->exit ? prx->exit() : CELL_OK;
idm::remove<lv2_obj, lv2_prx>(id);
return CELL_OK;
}
@ -231,8 +230,3 @@ s32 sys_prx_stop()
sys_prx.todo("sys_prx_stop()");
return CELL_OK;
}
lv2_prx::lv2_prx()
: id(idm::last_id())
{
}

View File

@ -77,8 +77,6 @@ struct lv2_prx final : lv2_obj
{
static const u32 id_base = 0x23000000;
const u32 id;
bool is_started = false;
std::unordered_map<u32, u32> specials;
@ -87,8 +85,6 @@ struct lv2_prx final : lv2_obj
vm::ps3::ptr<s32(int argc, vm::ps3::ptr<void> argv)> start = vm::null;
vm::ps3::ptr<s32(int argc, vm::ps3::ptr<void> argv)> stop = vm::null;
vm::ps3::ptr<s32()> exit = vm::null;
lv2_prx();
};
// SysCalls