This commit is contained in:
red-prig 2022-10-03 23:06:13 +03:00
parent 23271ab913
commit b5804ad25e
7 changed files with 122 additions and 27 deletions

View File

@ -460,17 +460,25 @@ begin
if next then
begin
It:=FAllcSet.find_be(key);
repeat
if (It.Item=nil) then Exit(EACCES);
key:=It.Item^;
if (not key.IsFree) then Break;
It.Next;
until false;
end else
begin
It:=FAllcSet.find(key);
if (It.Item=nil) then Exit(EINVAL);
key:=It.Item^;
if key.IsFree then Exit(EACCES);
end;
if (It.Item=nil) then Exit(EACCES);
key:=It.Item^;
if key.IsFree then Exit(EACCES);
ROut:=key;
end;

View File

@ -1613,17 +1613,25 @@ begin
if next then
begin
It:=FAllcSet.find_be(key);
repeat
if (It.Item=nil) then Exit(EACCES);
key:=It.Item^;
if (not key.IsFree) then Break;
It.Next;
until false;
end else
begin
It:=FAllcSet.find(key);
if (It.Item=nil) then Exit(EINVAL);
key:=It.Item^;
if key.IsFree then Exit(EACCES);
end;
if (It.Item=nil) then Exit(EINVAL);
key:=It.Item^;
if key.IsFree then Exit(EACCES);
ROut:=key;
end;

View File

@ -425,7 +425,7 @@ begin
ch:=psCondWaitHelper(arg);
_c:=ch^.c;
System.EnterCriticalSection(_c^.waiters_count_lock_);
SwEnterCriticalSection(_c^.waiters_count_lock_);
n:=_c^.waiters_count_unblock_;
if (n<>0) then

View File

@ -271,6 +271,10 @@ begin
end;
end;
var
dev_random_nm:array[0..1] of PChar=('/dev/random','/dev/urandom');
dev_random_fd:Integer=-1;
function ps4_sceKernelOpen(path:PChar;flags,mode:Integer):Integer; SysV_ABI_CDecl;
const
WR_RDWR=SCE_KERNEL_O_WRONLY or SCE_KERNEL_O_RDWR;
@ -302,6 +306,32 @@ begin
Exit(_set_sce_errno(SCE_KERNEL_ERROR_ENOENT));
end;
if (CompareChar0(path^,dev_random_nm[0]^,Length(dev_random_nm[0]))=0) or
(CompareChar0(path^,dev_random_nm[1]^,Length(dev_random_nm[1]))=0) then
begin
if (dev_random_fd<>-1) then
begin
Exit(dev_random_fd);
end else
begin
_sig_lock;
h:=_get_osfhandle(0);
Result:=_open_osfhandle(h,flags and O_OFS);
_sig_unlock;
if (Result=-1) then
begin
Exit(_set_sce_errno(SCE_KERNEL_ERROR_EMFILE));
end else
begin
dev_random_fd:=Result;
end;
end;
Exit;
end;
_sig_lock;
rp:=_parse_filename(path);
_sig_unlock;
@ -365,6 +395,8 @@ function ps4_sceKernelLseek(fd:Integer;offset:Int64;whence:Integer):Int64; SysV_
var
h:THandle;
begin
if (dev_random_fd<>-1) and (dev_random_fd=fd) then Exit(SCE_KERNEL_ERROR_EINVAL);
_sig_lock;
h:=_get_osfhandle(fd);
_sig_unlock;
@ -392,6 +424,8 @@ var
h:THandle;
N:DWORD;
begin
if (dev_random_fd<>-1) and (dev_random_fd=fd) then Exit(SCE_KERNEL_ERROR_EINVAL);
_sig_lock;
h:=_get_osfhandle(fd);
_sig_unlock;
@ -416,11 +450,29 @@ begin
_sig_unlock;
end;
const
BCRYPT_USE_SYSTEM_PREFERRED_RNG=2;
function BCryptGenRandom(hAlgorithm:Pointer;
pbBuffer:PByte;
cbBuffer:DWORD;
dwFlags:DWORD):DWORD; stdcall; external 'Bcrypt';
function ps4_sceKernelRead(fd:Integer;buf:Pointer;nbytes:Int64):Int64; SysV_ABI_CDecl;
var
h:THandle;
N:DWORD;
begin
if (buf=nil) then Exit(_set_sce_errno(SCE_KERNEL_ERROR_EFAULT));
if (nbytes<0) or (nbytes>High(Integer)) then Exit(_set_sce_errno(SCE_KERNEL_ERROR_EINVAL));
if (dev_random_fd<>-1) and (dev_random_fd=fd) then
begin
BCryptGenRandom(nil,buf,nbytes,BCRYPT_USE_SYSTEM_PREFERRED_RNG);
Result:=nbytes;
Exit(_set_sce_errno(0));
end;
_sig_lock;
h:=_get_osfhandle(fd);
_sig_unlock;
@ -430,9 +482,6 @@ begin
Exit(_set_sce_errno(SCE_KERNEL_ERROR_EBADF));
end;
if (buf=nil) then Exit(_set_sce_errno(SCE_KERNEL_ERROR_EFAULT));
if (nbytes<0) or (nbytes>High(Integer)) then Exit(_set_sce_errno(SCE_KERNEL_ERROR_EINVAL));
N:=0;
_sig_lock;
if ReadFile(h,buf^,nbytes,N,nil) then
@ -454,6 +503,13 @@ begin
if (buf=nil) then Exit(_set_sce_errno(SCE_KERNEL_ERROR_EFAULT));
if (nbytes<0) or (nbytes>High(Integer)) or (offset<0) then Exit(_set_sce_errno(SCE_KERNEL_ERROR_EINVAL));
if (dev_random_fd<>-1) and (dev_random_fd=fd) then
begin
BCryptGenRandom(nil,buf,nbytes,BCRYPT_USE_SYSTEM_PREFERRED_RNG);
Result:=nbytes;
Exit(_set_sce_errno(0));
end;
_sig_lock;
h:=_get_osfhandle(fd);
_sig_unlock;
@ -726,6 +782,13 @@ begin
if (data=nil) then Exit(_set_errno(EFAULT));
if (size>High(Integer)) then Exit(_set_errno(EINVAL));
if (dev_random_fd<>-1) and (dev_random_fd=fd) then
begin
BCryptGenRandom(nil,data,size,BCRYPT_USE_SYSTEM_PREFERRED_RNG);
Result:=size;
Exit(_set_errno(0));
end;
_sig_lock;
h:=_get_osfhandle(fd);
_sig_unlock;

View File

@ -41,6 +41,17 @@ uses
sys_pthread,
sys_signal;
type
pSceKernelUuid=^SceKernelUuid;
SceKernelUuid=TGuid;
function ps4_sceKernelUuidCreate(outUuid:pSceKernelUuid):Integer; SysV_ABI_CDecl;
begin
if (outUuid=nil) then Exit(SCE_KERNEL_ERROR_EINVAL);
CreateGUID(outUuid^);
Result:=0;
end;
function ps4___error:Pointer; SysV_ABI_CDecl;
begin
Result:=_error;
@ -759,6 +770,8 @@ begin
lib^.set_proc($3AEDE22F569BBE78,@ps4_stack_chk_fail);
lib^.set_proc($91BC385071D2632D,@ps4_pthread_cxa_finalize);
lib^.set_proc($5E3A28B22C3E5CF2,@ps4_sceKernelUuidCreate);
//signal
lib^.set_proc($38C0D128A019F08E,@ps4_sceKernelDebugRaiseException);
@ -1091,8 +1104,10 @@ begin
lib^.set_proc($C2E0ABA081A3B768,@ps4_open);
lib^.set_proc($6D8FCF3BA261CE14,@ps4_close);
lib^.set_proc($171559A81000EE4B,@ps4_write);
lib^.set_proc($0D1B81B76A6F2029,@ps4_read);
lib^.set_proc($171559A81000EE4B,@ps4_write); //_write
lib^.set_proc($14DE2068F9AE155F,@ps4_write); //write
lib^.set_proc($0D1B81B76A6F2029,@ps4_read); //_read
lib^.set_proc($02A062A02DAF1772,@ps4_read); //read
lib^.set_proc($795F70003DAB8880,@ps4_sceKernelStat);
lib^.set_proc($13A6A8DF8C0FC3E5,@ps4_stat);

View File

@ -80,6 +80,7 @@ type
isPooledMemory :0..1;
isCommitted :0..1;
end;
align:array[0..6] of Byte;
name:array[0..SCE_KERNEL_VIRTUAL_RANGE_NAME_SIZE-1] of AnsiChar;
end;
@ -486,7 +487,7 @@ begin
rwlock_unlock(MMLock);
_sig_unlock;
if (Result<>0) then
if (Result=0) then
begin
info^:=Default(SceKernelDirectMemoryQueryInfo);
info^.start:=ROut.Offset;
@ -521,7 +522,7 @@ begin
rwlock_unlock(MMLock);
_sig_unlock;
if (Result<>0) then
if (Result=0) then
begin
memoryTypeOut ^:=ROut.F.mtype;
regionStartOut^:=ROut.Offset;
@ -818,7 +819,7 @@ function __munmap(addr:Pointer;len:size_t):Integer;
begin
Result:=VirtualManager.Release(addr,len);
if (Result<>0) then
if (Result=0) then
begin
NamedManager.Mname(addr,len,nil);
end;
@ -848,7 +849,7 @@ begin
Result:=VirtualManager.Release(addr,len);
if (Result<>0) then
if (Result=0) then
begin
NamedManager.Mname(addr,len,nil);
end;
@ -923,7 +924,7 @@ begin
rwlock_unlock(MMLock);
_sig_unlock;
if (Result<>0) then
if (Result=0) then
begin
if (pStart<>nil) then
begin
@ -968,12 +969,12 @@ begin
Result:=VirtualManager.Query(addr,(flags=SCE_KERNEL_VQ_FIND_NEXT),VOut);
if (Result<>0) and (VOut.F.direct=1) then
if (Result=0) and (VOut.F.direct=1) then
begin
Result:=DirectManager.QueryMType(VOut.addr,DOut);
end;
if (Result<>0) then
if (Result=0) then
begin
NamedManager.Query(addr,@name);
end;
@ -981,7 +982,7 @@ begin
rwlock_unlock(MMLock);
_sig_unlock;
if (Result<>0) then
if (Result=0) then
begin
Committed:=(VOut.F.Free=0) and (VOut.F.reserv=0);
info^:=Default(SceKernelVirtualQueryInfo);

View File

@ -2630,7 +2630,7 @@ begin
Pointer(P):=Pointer(mMap.pAddr+dtInit);
Writeln('module_start');
Writeln('module_start:',pFileName);
Result:=P(argc,argp,param);
end;