This commit is contained in:
red-prig 2022-10-04 20:27:29 +03:00
parent 864bc3fc64
commit c9403e82f7
6 changed files with 111 additions and 57 deletions

View File

@ -215,10 +215,6 @@ uses
sys_signal,
sys_time;
function _open_osfhandle(h:THandle;flags:Integer):Integer; cdecl; external 'msvcrt';
function _get_osfhandle(fd:Integer):THandle; cdecl; external 'msvcrt';
function _close(fd:Integer):Integer; cdecl; external 'msvcrt';
Function get_DesiredAccess(flags:Integer):DWORD;
begin
Result:=0;
@ -575,20 +571,6 @@ begin
Result:=_set_errno(sce2px(ps4_sceKernelStat(path,stat)));
end;
function SwGetFileAttributes(Const lpFileName:RawByteString;lpFileInformation:LPVOID):DWORD;
var
wp:WideString;
begin
Result:=0;
_sig_lock;
wp:=UTF8Decode(lpFileName);
if not GetFileAttributesExW(PWideChar(wp),GetFileExInfoStandard,lpFileInformation) then
begin
Result:=GetLastError;
end;
_sig_unlock;
end;
function ps4_sceKernelStat(path:PChar;stat:PSceKernelStat):Integer; SysV_ABI_CDecl;
var
rp:RawByteString;
@ -648,24 +630,6 @@ begin
Result:=_set_errno(sce2px(ps4_sceKernelFstat(fd,stat)));
end;
function SwGetFileType(hFile:HANDLE):DWORD;
begin
_sig_lock;
Result:=GetFileType(hFile);
_sig_unlock;
end;
function SwGetFileInformationByHandle(hFile:HANDLE;lpFileInformation:LPBY_HANDLE_FILE_INFORMATION):DWORD;
begin
Result:=0;
_sig_lock;
if not GetFileInformationByHandle(hFile,lpFileInformation) then
begin
Result:=GetLastError;
end;
_sig_unlock;
end;
function ps4_sceKernelFstat(fd:Integer;stat:PSceKernelStat):Integer; SysV_ABI_CDecl;
var
h:THandle;
@ -815,17 +779,6 @@ begin
_sig_unlock;
end;
Function SwCreateDir(Const NewDir:RawByteString):DWORD;
begin
Result:=0;
_sig_lock;
if not CreateDir(NewDir) then
begin
Result:=GetLastError;
end;
_sig_unlock;
end;
function ps4_sceKernelMkdir(path:PChar;mode:Integer):Integer; SysV_ABI_CDecl;
var
fn:RawByteString;

View File

@ -973,6 +973,8 @@ begin
lib^.set_proc($DE483BAD3D0D408B,@ps4_scePthreadExit);
lib^.set_proc($149AD3E4BB940405,@ps4_pthread_exit);
lib^.set_proc($959CC5792C4F974F,@ps4_pthread_setcancelstate);
lib^.set_proc($128B51F1ADC049FE,@ps4_pthread_self);
lib^.set_proc($688F8E782CFCC6B4,@ps4_scePthreadSelf);

View File

@ -53,6 +53,8 @@ function ps4_pthread_equal(t1,t2:pthread):Integer; SysV_ABI_CDecl;
procedure ps4_scePthreadExit(value_ptr:Pointer); SysV_ABI_CDecl;
procedure ps4_pthread_exit(value_ptr:Pointer); SysV_ABI_CDecl;
function ps4_pthread_setcancelstate(state:Integer;oldstate:PInteger):Integer; SysV_ABI_CDecl;
function ps4_pthread_self():pthread; SysV_ABI_CDecl;
function ps4_scePthreadSelf():pthread; SysV_ABI_CDecl;
@ -717,6 +719,19 @@ begin
ps4_scePthreadExit(value_ptr);
end;
function ps4_pthread_setcancelstate(state:Integer;oldstate:PInteger):Integer; SysV_ABI_CDecl;
begin
Result:=0;
Case state of
PTHREAD_CANCEL_DISABLE:Writeln('PTHREAD_CANCEL_DISABLE');
PTHREAD_CANCEL_ENABLE :Writeln('PTHREAD_CANCEL_ENABLE');
else
Exit(EINVAL);
end;
end;
function ps4_pthread_self():pthread; SysV_ABI_CDecl;
begin
Result:=tcb_thread;

View File

@ -86,6 +86,9 @@ function _VirtualQuery (addr:Pointer;paddr:PPointer;psize:Pptruint;pprots,pfla
implementation
uses
sys_kernel;
const
FILE_MAP_EXECUTE=$0020;
@ -208,20 +211,21 @@ begin
end;
end;
function _get_osfhandle(fd:Integer):THandle; cdecl; external 'msvcrt';
function MapViewOfFileEx(hFileMappingObject:HANDLE;
dwDesiredAccess:DWORD;
dwFileOffsetHigh:DWORD;
dwFileOffsetLow:DWORD;
dwNumberOfBytesToMap:SIZE_T;
lpBaseAddress:LPVOID):LPVOID; stdcall; external 'kernel32' name 'MapViewOfFileEx';
function _VirtualMmap(Addr:Pointer;len:size_t;prot,fd:Integer;offst:size_t):Integer;
Var
fm,h:THandle;
dwFileOffsetLow,dwFileOffsetHigh,protect,desiredAccess,dwMaxSizeLow,dwMaxSizeHigh:DWORD;
dwFileOffsetLow,
dwFileOffsetHigh,
protect,
desiredAccess,
dwMaxSizeLow,
dwMaxSizeHigh:DWORD;
fileSize:size_t;
maxSize:size_t;
info:BY_HANDLE_FILE_INFORMATION;
begin
Result:=0;
if (Addr=nil) then Exit(-1);
@ -232,8 +236,20 @@ begin
Exit(GetLastError);
end;
info:=Default(BY_HANDLE_FILE_INFORMATION);
Result:=SwGetFileInformationByHandle(h,@info);
if (Result<>0) then Exit;
fileSize:=info.nFileSizeLow or (QWORD(info.nFileSizeHigh) shl 32);
maxSize:=offst+len;
if (maxSize>fileSize) then
begin
maxSize:=fileSize;
len:=maxSize-offst;
end;
dwFileOffsetLow :=DWORD(offst and $FFFFFFFF);
dwFileOffsetHigh:=DWORD(offst shr 32);
dwMaxSizeLow :=DWORD(maxSize and $FFFFFFFF);

View File

@ -5,6 +5,7 @@ unit sys_kernel;
interface
Uses
SysUtils,
Windows;
{$I sce_errno.inc}
@ -45,11 +46,28 @@ function SwWaitForSingleObject(
function SwWaitFor(Handle:THandle;pTimeout:PQWORD):Integer; //pTimeout in ns
function SwGetFileAttributes(Const lpFileName:RawByteString;lpFileInformation:LPVOID):DWORD;
function SwGetFileType(hFile:HANDLE):DWORD;
function SwGetFileInformationByHandle(hFile:HANDLE;lpFileInformation:LPBY_HANDLE_FILE_INFORMATION):DWORD;
Function SwCreateDir(Const NewDir:RawByteString):DWORD;
Function safe_move(const src;var dst;count:QWORD):QWORD;
procedure safe_move_ptr(const src;var dst);
function safe_test(var src:DWORD;value:DWORD):Boolean;
function safe_str(P:PChar):shortstring;
function _open_osfhandle(h:THandle;flags:Integer):Integer; cdecl; external 'msvcrt';
function _get_osfhandle(fd:Integer):THandle; cdecl; external 'msvcrt';
function _close(fd:Integer):Integer; cdecl; external 'msvcrt';
function MapViewOfFileEx(hFileMappingObject:HANDLE;
dwDesiredAccess:DWORD;
dwFileOffsetHigh:DWORD;
dwFileOffsetLow:DWORD;
dwNumberOfBytesToMap:SIZE_T;
lpBaseAddress:LPVOID):LPVOID; stdcall; external 'kernel32' name 'MapViewOfFileEx';
implementation
uses
@ -250,6 +268,49 @@ begin
end;
function SwGetFileAttributes(Const lpFileName:RawByteString;lpFileInformation:LPVOID):DWORD;
var
wp:WideString;
begin
Result:=0;
_sig_lock;
wp:=UTF8Decode(lpFileName);
if not GetFileAttributesExW(PWideChar(wp),GetFileExInfoStandard,lpFileInformation) then
begin
Result:=GetLastError;
end;
_sig_unlock;
end;
function SwGetFileType(hFile:HANDLE):DWORD;
begin
_sig_lock;
Result:=GetFileType(hFile);
_sig_unlock;
end;
function SwGetFileInformationByHandle(hFile:HANDLE;lpFileInformation:LPBY_HANDLE_FILE_INFORMATION):DWORD;
begin
Result:=0;
_sig_lock;
if not GetFileInformationByHandle(hFile,lpFileInformation) then
begin
Result:=GetLastError;
end;
_sig_unlock;
end;
Function SwCreateDir(Const NewDir:RawByteString):DWORD;
begin
Result:=0;
_sig_lock;
if not CreateDir(NewDir) then
begin
Result:=GetLastError;
end;
_sig_unlock;
end;
Function safe_move(const src;var dst;count:QWORD):QWORD;
begin
_sig_lock;

View File

@ -19,6 +19,13 @@ const
PTHREAD_CREATE_DETACHED=PTHREAD_DETACHED;
PTHREAD_CREATE_JOINABLE=0;
PTHREAD_CANCEL_ENABLE =0;
PTHREAD_CANCEL_DISABLE =1;
PTHREAD_CANCEL_DEFERRED =0;
PTHREAD_CANCEL_ASYNCHRONOUS=2;
PTHREAD_CANCELED =Pointer(1);
SCE_PTHREAD_DESTRUCTOR_ITERATIONS =4;
SCE_PTHREAD_KEYS_MAX =256;
SCE_PTHREAD_STACK_MIN =PTHREAD_STACK_MIN;