Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Work #67

Merged
merged 18 commits into from
Apr 8, 2024
Merged

Work #67

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions core/fileManager/types/type_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ std::pair<Handle_t, int32_t> open(std::filesystem::path path, filesystem::SceOpe
switch (mode.mode) {
case filesystem::SceOpenMode::RDONLY: {
access = GENERIC_READ;
if (mode.shlock) shareMode = FILE_SHARE_READ;
if (!mode.exlock) shareMode = FILE_SHARE_READ;
} break;
case filesystem::SceOpenMode::WRONLY: {
access = GENERIC_WRITE;
if (mode.shlock) shareMode = FILE_SHARE_WRITE;
if (!mode.exlock) shareMode = FILE_SHARE_WRITE;
} break;
case filesystem::SceOpenMode::RDWR: {
access = GENERIC_READ | GENERIC_WRITE;
if (mode.shlock) shareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
if (!mode.exlock) shareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
} break;
}
// -
Expand Down
4 changes: 2 additions & 2 deletions core/imports/exports/runtimeExport.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct CxaDestructor {
void* destructor_object;
};

#pragma pack(1)
#pragma pack(push, 1)

struct alignas(32) EntryParams {
int argc = 0;
Expand Down Expand Up @@ -65,7 +65,7 @@ struct SceKernelModuleInfoEx {
uint32_t ref_count;
};

#pragma pack()
#pragma pack(pop)

class IRuntimeExport {
CLASS_NO_COPY(IRuntimeExport);
Expand Down
3 changes: 2 additions & 1 deletion core/kernel/eventflag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ int KernelEventFlag::wait(uint64_t bits, WaitMode wait_mode, ClearMode clear_mod
if (m_status == Status::Canceled) {
return getErr(ErrCode::_ECANCELED);
} else if (m_status == Status::Deleted) {
return getErr(ErrCode::_EACCES);
return getErr(ErrCode::_EINTR);
}
// -

Expand All @@ -169,6 +169,7 @@ int deleteEventFlag(IKernelEventFlag_t ef) {
if (ef == nullptr) {
return getErr(ErrCode::_ESRCH);
}

LOG_INFO(L"Deleted ptr:0x%08llx", (uint64_t)ef);
delete ef;
return Ok;
Expand Down
27 changes: 13 additions & 14 deletions core/kernel/eventqueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,24 +79,23 @@ int KernelEqueue::waitForEvents(KernelEvent_t ev, int num, SceKernelUseconds con

boost::unique_lock lock(m_mutex_cond);

int ret = 0;
if (micros != nullptr && *micros > 0) {
using namespace std::chrono_literals;

if (m_cond_var.wait_for(lock, boost::chrono::microseconds(*(decltype(micros))micros), [&] {
ret = getTriggeredEvents(ev, num);
return (ret > 0) | m_closed;
}) == 0) {
// LOG_TRACE(L"waitForEvents timeout");
auto hasEvents = [&] {
for (auto& ev: m_events) {
if (ev.triggered) {
return true;
}
}
return false;
};

if (micros != nullptr && *micros > 0) {
m_cond_var.wait_for(lock, boost::chrono::microseconds(*(decltype(micros))micros), [&] { return hasEvents() | m_closed; });
} else {
m_cond_var.wait(lock, [&] {
ret = getTriggeredEvents(ev, num);
return (ret > 0) | m_closed;
});
m_cond_var.wait(lock, [&] { return hasEvents() | m_closed; });
}

// LOG_TRACE(L"<-waitForEvents: ident:0x%08llx ret:%d", ev->ident, ret);
return ret;
return getTriggeredEvents(ev, num);
}

int KernelEqueue::getTriggeredEvents(KernelEvent_t eventList, int num) {
Expand Down
7 changes: 5 additions & 2 deletions core/kernel/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,11 @@ int rename(const char* from, const char* to) {
if (!mapped2) {
return getErr(ErrCode::_EACCES);
}

std::filesystem::rename(*mapped1, *mapped2);
try {
std::filesystem::rename(*mapped1, *mapped2);
} catch (...) {
return getErr(ErrCode::_ENFILE);
}
return Ok;
}

Expand Down
22 changes: 16 additions & 6 deletions core/kernel/semaphore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,22 @@ int Semaphore::wait_internal(int needCount, uint32_t* pMicros, boost::unique_loc

m_countThreads++;
if (pMicros != nullptr) {
if (!condVar->wait_for(lock, boost::chrono::microseconds(micros),
[this, condVar, needCount] { return m_state != Status::Set || (m_condQueue.front() == condVar && m_count >= needCount); })) {
LOG_WARN(L"<- KernelSema(%llu) name:%S waitCount:%llu timeout", m_id, m_name.c_str(), waitCount);
*pMicros = 0;
m_countThreads--;
return getErr(ErrCode::_ETIMEDOUT);
if (*pMicros == 0) {
if (m_count < needCount) {
*pMicros = 0;
m_countThreads--;
m_condState.notify_all();
return getErr(ErrCode::_ETIMEDOUT);
}
} else {
if (!condVar->wait_for(lock, boost::chrono::microseconds(micros),
[this, condVar, needCount] { return m_state != Status::Set || (m_condQueue.front() == condVar && m_count >= needCount); })) {
LOG_WARN(L"<- KernelSema(%llu) name:%S waitCount:%llu timeout", m_id, m_name.c_str(), waitCount);
*pMicros = 0;
m_countThreads--;
m_condState.notify_all();
return getErr(ErrCode::_ETIMEDOUT);
}
}
} else {
condVar->wait(lock, [this, condVar, needCount] { return m_state != Status::Set || (m_condQueue.front() == condVar && m_count >= needCount); });
Expand Down
14 changes: 14 additions & 0 deletions core/videoout/vulkan/vulkanSetup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,20 @@ VulkanObj* initVulkan(SDL_Window* window, VkSurfaceKHR& surface, bool enableVali
VK_API_VERSION_MINOR(g_PhysicalDeviceProperties.apiVersion), VK_API_VERSION_PATCH(g_PhysicalDeviceProperties.apiVersion));
printf("%s\n", text.data());
LOG_INFO(L"%S", text.data());

// Debug infos
VkPhysicalDeviceMemoryProperties memProperties;
vkGetPhysicalDeviceMemoryProperties(obj->deviceInfo.physicalDevice, &memProperties);

for (uint32_t i = 0; i < memProperties.memoryTypeCount; i++) {
LOG_DEBUG(L"%u| Memory Type: index:%u flags:%S", i, memProperties.memoryTypes[i].heapIndex,
string_VkMemoryPropertyFlags(memProperties.memoryTypes[i].propertyFlags).data());
}
for (uint32_t i = 0; i < memProperties.memoryHeapCount; i++) {
LOG_DEBUG(L"%u| Memory Heap: size:%u flags:%S", i, memProperties.memoryHeaps[i].size,
string_VkMemoryHeapFlags(memProperties.memoryHeaps[i].flags).data());
}
// -
}

obj->deviceInfo.device = createDevice(obj->deviceInfo.physicalDevice, surface, extensions, queues, enableValidation);
Expand Down
2 changes: 2 additions & 0 deletions modules/libSceLibcInternal/mspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

LOG_DEFINE_MODULE(mspace);

// todo use vmaVirtualAllocate for this!

namespace {
struct MSpaceData {
boost::simple_segregated_storage<std::size_t> storage;
Expand Down
7 changes: 4 additions & 3 deletions modules/libScePad/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ EXPORT SYSV_ABI int scePadOpen(int32_t userId, PadPortType type, int32_t index,
// - already open

auto lockSDL2 = accessVideoOut().getSDLLock();
for (uint32_t n = 0; n < MAX_CONTROLLERS_COUNT; ++n) {
for (int n = 0; n < MAX_CONTROLLERS_COUNT; ++n) {
if (pData->controller[n].userId >= 0) continue;
auto& pController = pData->controller[n].padPtr;

Expand All @@ -79,7 +79,7 @@ EXPORT SYSV_ABI int scePadOpen(int32_t userId, PadPortType type, int32_t index,
default: LOG_CRIT(L"Unimplemented controller type!"); return Err::FATAL;
}

LOG_INFO(L"-> Pad[%llu]: userId:%d name:%S guid:%S", n, userId, pController->getName(), pController->getGUID());
LOG_INFO(L"-> Pad[%d]: userId:%d name:%S guid:%S", n, userId, pController->getName(), pController->getGUID());
return n;
}

Expand Down Expand Up @@ -151,7 +151,8 @@ EXPORT SYSV_ABI int scePadSetMotionSensorState(int32_t handle, bool bEnable) {
auto& pController = pData->controller[handle].padPtr;
if (!pController) return Err::INVALID_HANDLE;

return pController->setMotion(bEnable) ? Ok : Err::FATAL;
pController->setMotion(bEnable);
return Ok;
}

EXPORT SYSV_ABI int scePadSetTiltCorrectionState(int32_t handle, bool bEnable) {
Expand Down
12 changes: 8 additions & 4 deletions modules/libScePad/interfaces/ixip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ bool XIPController::reconnect() {
::strcpy_s(m_guid, "1337deadbeef00000000000000000000");
m_xRumblePossible = caps.Vibration.wLeftMotorSpeed > 0 || caps.Vibration.wRightMotorSpeed > 0;
if (caps.Flags & XINPUT_CAPS_NO_NAVIGATION) {
LOG_WARN(L"Your gamepad lacks menu navigation buttons, you may not be able to reach some parts of game menus!");
LOG_ERR(L"Your gamepad lacks menu navigation buttons, you may not be able to reach some parts of game menus!");
}
++m_connectCount;
m_state = ControllerState::Connected;
m_xUserId = n;
return true;
}
Expand Down Expand Up @@ -131,8 +133,10 @@ bool XIPController::readPadData(ScePadData& data) {
XINPUT_STATE xstate;
if (xip_getStateFunc(m_xUserId, &xstate) != ERROR_SUCCESS) {
m_state = ControllerState::Disconnected;
data = ScePadData {};
return false;
if (!reconnect()) {
data = ScePadData {};
return false;
}
}

auto xGamepad = &xstate.Gamepad;
Expand Down Expand Up @@ -189,7 +193,7 @@ bool XIPController::readPadData(ScePadData& data) {

},

.connected = true,
.connected = m_state == ControllerState::Connected,
.timestamp = accessTimer().getTicks(),
.connectedCount = m_connectCount,
.deviceUniqueDataLen = 0,
Expand Down
5 changes: 2 additions & 3 deletions modules/libSceSaveData/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,7 @@ EXPORT SYSV_ABI int32_t sceSaveDataSyncSaveDataMemory(const SceSaveDataMemorySyn
}

EXPORT SYSV_ABI int32_t sceSaveDataSetupSaveDataMemory2(const SceSaveDataMemorySetup2* setupParam, SceSaveDataMemorySetupResult* result) {
if (setupParam == nullptr || setupParam->memorySize == 0 || setupParam->option != SceSaveDataMemoryOption::SET_PARAM) return getErr(ErrCode::_EINVAL);

if (setupParam == nullptr || setupParam->memorySize == 0 || setupParam->option.bits.SET_PARAM == 0) return getErr(ErrCode::_EINVAL);
auto filename = std::format("SLOT{}_UID{}.dat", setupParam->slotId, setupParam->userId);

filesystem::SceOpen oflags {.mode = filesystem::SceOpenMode::WRONLY, .create = 1, .excl = 1};
Expand Down Expand Up @@ -267,7 +266,7 @@ EXPORT SYSV_ABI int32_t sceSaveDataSetupSaveDataMemory2(const SceSaveDataMemoryS

EXPORT SYSV_ABI int32_t sceSaveDataSetupSaveDataMemory(const SceUserServiceUserId userId, size_t memorySize, const SceSaveDataParam* param) {
const SceSaveDataMemorySetup2 ssdms2 {
.option = SceSaveDataMemoryOption::SET_PARAM,
.option = SceSaveDataMemoryOption {.bits = {.SET_PARAM = 1}},
.userId = userId,
.memorySize = memorySize,
.iconMemorySize = 0,
Expand Down
11 changes: 9 additions & 2 deletions modules/libSceSaveData/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,19 @@ enum class SceSaveDataSortKey : uint32_t { DIRNAME = 0, USER_PARAM = 1, BLOCKS =

enum class SceSaveDataSortOrder : uint32_t { ASCENT = 0, DESCENT = 1 };

enum class SceSaveDataMemoryOption : uint32_t { NONE = 0x00000000, SET_PARAM = 0x00000001, DOUBLE_BUFFER = 0x00000010 };

enum class SceSaveDataMemorySyncOption : uint32_t { NONE = 0x00000000, BLOCKING = 0x00000001 << 0 };

enum class SceSaveDataEventType : uint32_t { INVALID = 0, UMOUNT_BACKUP_END = 1, BACKUP_END = 2, SAVE_DATA_MEMORY_SYNC_END = 3 };

union SceSaveDataMemoryOption {
struct {
uint32_t SET_PARAM : 1;
uint32_t DOUBLE_BUFFER : 1;
} bits;

uint32_t bitfield;
};

/*
* Structures
*/
Expand Down
22 changes: 2 additions & 20 deletions modules/libkernel/eventflag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,8 @@ EXPORT SYSV_ABI int sceKernelCreateEventFlag(IKernelEventFlag_t* ef, const char*
return getErr(ErrCode::_EINVAL);
}

bool single = true;
bool fifo = true;

switch (attr) {
case 0x10:
case 0x11:
single = true;
fifo = true;
break;
case 0x20:
case 0x21:
single = false;
fifo = true;
break;
case 0x22:
single = false;
fifo = false;
break;
default: LOG_CRIT(L"unknown attr: %u", attr);
}
bool const single = (attr & 0x30) == 0x10;
bool fifo = (attr & 0x03) == 0x1;

std::string _name;
if (name != nullptr) _name = std::string(name);
Expand Down
Loading
Loading