fpPS4/kernel/mm.txt
red-prig 57b2c9fa13 +
2022-10-02 00:46:07 +03:00

432 lines
9.7 KiB
Plaintext

int sceKernelMapDirectMemory
(void **virtualAddrDest,qword length,int protections,int flags,qword physicalAddr,
qword alignment)
{
int iVar1;
ulong in_stack_00000000;
pthread_once((pthread_once_t *)&_mem_init_ctl,_mem_init);
iVar1 = _sceKernelMapDirectMemory
(_direct_pool_id,virtualAddrDest,length,protections,flags,physicalAddr,alignment
,in_stack_00000000);
return iVar1;
}
int _sceKernelMapDirectMemory
(uint pool_id,void **virtualAddrDest,qword length,int protections,int flags,
qword physicalAddr,qword alignment,ulong param_8)
{
int last;
int *perror;
uint _flags;
dword *poffset;
void *adr;
qword align;
int ret1;
uint _len;
pthread_once((pthread_once_t *)&_mem_init_ctl,_mem_init);
ret1 = SCE_KERNEL_ERROR_EINVAL;
if (pool_id < 3) {
adr = *virtualAddrDest;
if ((((_direct_pool_id == 1) && ((APP_INFO[4] & 2) == 0)) &&
(((long)physicalAddr < 0x3000000000 || (0x301fffffff < physicalAddr)))) &&
(((flags & SCE_KERNEL_MAP_DMEM_COMPAT) == 0 && (0x24fffff < SDK_VERSION)))) {
ret1 = sceKernelMapDirectMemory2
(virtualAddrDest,length,-1,protections,flags,physicalAddr,alignment);
return ret1;
}
if (((((flags & 0xff9ffb6fU) == 0) && ((protections & 0xffffffc8U) == 0)) &&
(_len = (uint)length,
(((uint)adr | (uint)alignment | (uint)physicalAddr | _len) & 0x3fff) == 0)) &&
((~-alignment & alignment) == 0)) {
_flags = flags & 0xfffffbff;
if (((flags & MAP_FIXED) != 0) && (adr == (void *)0x0)) {
if (0x16fffff < SDK_VERSION) {
return SCE_KERNEL_ERROR_EINVAL;
}
_flags = flags & 0xfffffbef;
puts("[WARNING] map(addr=0, flags=MAP_FIXED)");
}
if (adr == (void *)0x0) {
if (param_8 >> 0x1e == 0x20) {
adr = (void *)0x880000000;
}
else {
adr = (void *)((ulong)((APP_INFO[4] & 2) == 0) << 0x21);
}
}
align = 0x4000;
if (0x4000 < alignment) {
align = alignment;
}
last = flsl(align);
if (last + -1 < 31) {
poffset = &DAT_01059578;
if (0x301fffffff < physicalAddr) {
poffset = DWORD_ARRAY_01059570 + (int)pool_id;
}
if ((long)physicalAddr < 0x3000000000) {
poffset = DWORD_ARRAY_01059570 + (int)pool_id;
}
adr = mmap(adr,length,protections,_flags | (last + -1) * 0x1000000 | MAP_SHARED,*poffset,physicalAddr);
if (adr == MAP_FAILED) {
perror = (int *)__error();
last = *perror;
ret1 = last + -0x7ffe0000;
if (last == 0) {
ret1 = last;
}
}
else {
*virtualAddrDest = adr;
ret1 = 0;
}
}
}
}
return ret1;
}
int sceKernelMapDirectMemory2
(void **virtualAddrDest,qword length,int memoryType,int protections,int flags,
qword physicalAddr,qword alignment)
{
int last;
void *adr;
int *perror;
int ret1;
qword align;
pthread_once((pthread_once_t *)&_mem_init_ctl,_mem_init);
ret1 = SCE_KERNEL_ERROR_EOPNOTSUPP;
if ((((_direct_pool_id == 1) && ((APP_INFO[4] & 2) == 0)) &&
(ret1 = SCE_KERNEL_ERROR_EINVAL, (flags & 0x1f000000U) == 0)) &&
(((alignment & 0x3fff) == 0 && ((~-alignment & alignment) == 0)))) {
align = 0x4000;
if (0x4000 < alignment) {
align = alignment;
}
last = flsl(align);
if (last + -1 < 31) {
adr = (void *)sys_mmap_dmem(*virtualAddrDest,length,memoryType,protections,
(last + -1) * 0x1000000 | flags,physicalAddr);
if (adr == MAP_FAILED) {
perror = (int *)__error();
last = *perror;
ret1 = last + -0x7ffe0000;
if (last == 0) {
ret1 = last;
}
}
else {
*virtualAddrDest = adr;
ret1 = 0;
}
}
}
return ret1;
}
int sceKernelMapFlexibleMemory(void **virtualAddrDest,qword length,int protections,int flags)
{
int iVar1;
undefined in_stack_00000000;
undefined7 in_stack_00000001;
iVar1 = _sceKernelMapFlexibleMemory
(virtualAddrDest,length,protections,flags,
CONCAT71(in_stack_00000001,in_stack_00000000));
return iVar1;
}
int _sceKernelMapFlexibleMemory
(void **virtualAddrDest,qword length,int protections,int flags,ulong param)
{
int *perror;
int ret1;
void *adr;
int err;
ret1 = SCE_KERNEL_ERROR_EINVAL;
if (((0x3fff < length) && ((length & 0x3fff) == 0)) &&
((flags & 0xffbfff6fU | protections & 0xffffffc8U) == 0)) {
adr = *virtualAddrDest;
if (((flags & MAP_FIXED) != 0) && (adr == (void *)0x0)) {
if (0x16fffff < SDK_VERSION) {
return SCE_KERNEL_ERROR_EINVAL;
}
flags = flags & 0xffffffef;
puts("[WARNING] map(addr=0, flags=MAP_FIXED)");
}
if (adr == (void *)0x0) {
if (param >> 0x1e == 0x20) {
adr = (void *)0x880000000;
}
else {
adr = (void *)((ulong)((APP_INFO[4] & 2) == 0) << 0x21);
}
}
adr = (void *)mmap(adr,length,protections,flags | MAP_ANON,-1,0);
if (adr == MAP_FAILED) {
perror = (int *)__error();
err = *perror;
ret1 = err + -0x7ffe0000;
if (err == 0) {
ret1 = err;
}
}
else {
*virtualAddrDest = adr;
ret1 = 0;
}
}
return ret1;
}
int sceKernelReserveVirtualRange(void **addr,size_t len,int flags,size_t alignment)
{
int last;
int *perror;
size_t align;
int ret1;
void *adr;
ret1 = SCE_KERNEL_ERROR_EINVAL;
if ((((flags & 0xffbfff6fU) == 0) &&
(adr = *addr, (((uint)adr | (uint)alignment | (uint)len) & 0x3fff) == 0)) &&
((~-alignment & alignment) == 0)) {
align = 0x4000;
if (0x4000 < alignment) {
align = alignment;
}
last = flsl(align);
if (last + -1 < 0x1f) {
if (((flags & MAP_FIXED) != 0) && (adr == (void *)0x0)) {
if (0x16fffff < SDK_VERSION) {
return SCE_KERNEL_ERROR_EINVAL;
}
flags = flags & 0xffffffef;
puts("[WARNING] map(addr=0, flags=MAP_FIXED)");
}
adr = (void *)mmap(adr,len,0,(last + -1) * 0x1000000 | flags | MAP_VOID | MAP_SHARED,-1,0);
if (adr == MAP_FAILED) {
perror = (int *)__error();
last = *perror;
ret1 = last + -0x7ffe0000;
if (last == 0) {
ret1 = last;
}
}
else {
*addr = adr;
ret1 = 0;
}
}
}
return ret1;
}
int sceKernelMprotect(void *addr,size_t len,int prot)
{
int ret1;
int *perror;
int err;
ret1 = mprotect(addr,len,prot);
if (ret1 < 0) {
perror = (int *)__error();
err = *perror;
ret1 = err + -0x7ffe0000;
if (err == 0) {
ret1 = err;
}
}
return ret1;
}
int sceKernelMsync(void *addr,size_t len,int flags)
{
int ret1;
int *perror;
int err;
ret1 = msync(addr,len,flags);
if (ret1 < 0) {
perror = (int *)__error();
err = *perror;
ret1 = err + -0x7ffe0000;
if (err == 0) {
ret1 = err;
}
}
return ret1;
}
int sceKernelMmap(void *addr,size_t len,int prot,int flags,int fd,size_t offset,void **res)
{
int iVar1;
int err;
void *adr;
int *perror;
adr = mmap(addr,len,prot,flags,fd,offset);
if (adr != MAP_FAILED) {
*res = adr;
return 0;
}
perror = (int *)__error();
iVar1 = *perror;
err = iVar1 + -0x7ffe0000;
if (iVar1 == 0) {
err = iVar1;
}
return err;
}
int sceKernelMunmap(void *addr,size_t len)
{
int ret1;
int *perror;
int err;
ret1 = munmap(addr,len);
if (ret1 < 0) {
perror = (int *)__error();
err = *perror;
ret1 = err + -0x7ffe0000;
if (err == 0) {
ret1 = err;
}
}
return ret1;
}
int sceKernelReleaseFlexibleMemory(void *addr,size_t len)
{
int ret2;
int ret1;
ret1 = SCE_KERNEL_ERROR_EINVAL;
if ((((uint)addr | (uint)len) & 0x3fff) == 0) {
ret2 = madvise(addr,len,MADV_FREE);
ret1 = SCE_KERNEL_ERROR_EINVAL;
if (ret2 != -1) {
ret1 = 0;
}
}
return ret1;
}
int sceKernelQueryMemoryProtection(void *addr,void **start,void **end,int *prot)
{
int ret1;
int *perror;
void *_start;
void *_end;
uint _prot;
long __guard;
int err;
__guard = __stack_chk_guard._0_8_;
ret1 = sys_query_memory_protection(addr,&_start);
if (ret1 == 0) {
if (start != (void **)0x0) {
*start = _start;
}
if (end != (void **)0x0) {
*end = _end;
}
ret1 = 0;
if (prot != (int *)0x0) {
*prot = _prot & 0x37;
}
}
else {
perror = (int *)__error();
err = *perror;
ret1 = err + -0x7ffe0000;
if (err == 0) {
ret1 = err;
}
}
if (__stack_chk_guard._0_8_ != __guard) {
/* WARNING: Subroutine does not return */
__stack_chk_fail();
}
return ret1;
}
int sceKernelVirtualQuery(void *addr,int flags,void *info,qword infoSize)
{
int ret1;
int err;
int *perror;
ret1 = sys_virtual_query();
err = 0;
if (ret1 == -1) {
perror = (int *)__error();
ret1 = *perror;
err = ret1 + -0x7ffe0000;
if (ret1 == 0) {
err = ret1;
}
}
return err;
}
int sceKernelMtypeprotect(void *addr,qword len,int type,int prot)
{
int ret1;
int err;
int *perror;
ret1 = sys_mtypeprotect();
err = 0;
if (ret1 == -1) {
perror = (int *)__error();
ret1 = *perror;
err = ret1 + -0x7ffe0000;
if (ret1 == 0) {
err = ret1;
}
}
return err;
}
int sceKernelSetVirtualRangeName(void *addr,qword len,char *name)
{
int ret1;
int err;
int *perror;
ret1 = sys_mname();
err = 0;
if (ret1 == -1) {
perror = (int *)__error();
ret1 = *perror;
err = ret1 + -0x7ffe0000;
if (ret1 == 0) {
err = ret1;
}
}
return err;
}