Skip to content

Commit

Permalink
Merge pull request #13038 from sum2012/sysclib_minor
Browse files Browse the repository at this point in the history
Add sysclib_strncmp,sysclib_memmove
  • Loading branch information
hrydgard authored Jun 21, 2020
2 parents 72da3e1 + d691627 commit 282dfb1
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions Core/HLE/sceKernelInterrupt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -754,13 +754,34 @@ static u32 sysclib_memset(u32 destAddr, int data, int size) {

static int sysclib_strstr(u32 s1, u32 s2) {
ERROR_LOG(SCEKERNEL, "Untested sysclib_strstr(%08x, %08x)", s1, s2);
std::string str1 = Memory::GetCharPointer(s1);
std::string str2 = Memory::GetCharPointer(s2);
size_t index = str1.find(str2);
if (index == str1.npos) {
return 0;
if (Memory::IsValidAddress(s1) && Memory::IsValidAddress(s2)) {
std::string str1 = Memory::GetCharPointer(s1);
std::string str2 = Memory::GetCharPointer(s2);
size_t index = str1.find(str2);
if (index == str1.npos) {
return 0;
}
return s1 + (uint32_t)index;
}
return 0;
}

static int sysclib_strncmp(u32 s1, u32 s2, u32 size) {
ERROR_LOG(SCEKERNEL, "Untested sysclib_strncmp(%08x, %08x, x)", s1, s2, size);
if (Memory::IsValidAddress(s1) && Memory::IsValidAddress(s2)) {
const char * str1 = Memory::GetCharPointer(s1);
const char * str2 = Memory::GetCharPointer(s2);
return strncmp(str1, str2, size);
}
return s1 + (uint32_t)index;
return 0;
}

static u32 sysclib_memmove(u32 dst, u32 src, u32 size) {
ERROR_LOG(SCEKERNEL, "Untested sysclib_memmove(%08x, %08x, x)", dst, src, size);
if (Memory::IsValidRange(dst, size) && Memory::IsValidRange(src, size)) {
memmove(Memory::GetPointer(dst), Memory::GetPointer(src), size);
}
return 0;
}

const HLEFunction SysclibForKernel[] =
Expand All @@ -774,6 +795,8 @@ const HLEFunction SysclibForKernel[] =
{0x7661E728, &WrapI_UU<sysclib_sprintf>, "sprintf", 'i', "xx", HLE_KERNEL_SYSCALL },
{0x10F3BB61, &WrapU_UII<sysclib_memset>, "memset", 'x', "xii", HLE_KERNEL_SYSCALL },
{0x0D188658, &WrapI_UU<sysclib_strstr>, "strstr", 'i', "xx", HLE_KERNEL_SYSCALL },
{0x7AB35214, &WrapI_UUU<sysclib_strncmp>, "strncmp", 'i', "xxx", HLE_KERNEL_SYSCALL },
{0xA48D2592, &WrapU_UUU<sysclib_memmove>, "memmove", 'x', "xxx", HLE_KERNEL_SYSCALL },
};

void Register_Kernel_Library()
Expand Down

0 comments on commit 282dfb1

Please sign in to comment.