mirror of https://github.com/red-prig/fpPS4.git
This commit is contained in:
parent
0ea0d4b529
commit
dbc6a80e39
|
@ -188,26 +188,40 @@ var
|
||||||
FShift :QWORD;
|
FShift :QWORD;
|
||||||
FOffset:Pointer;
|
FOffset:Pointer;
|
||||||
FSize :QWORD;
|
FSize :QWORD;
|
||||||
|
ASize :QWORD;
|
||||||
err :Integer;
|
err :Integer;
|
||||||
begin
|
begin
|
||||||
Result:=nil;
|
Result:=nil;
|
||||||
|
|
||||||
FOffset:=AlignDw(Offset,GRANULAR_PAGE_SIZE);
|
FOffset:=AlignDw(Offset,GRANULAR_PAGE_SIZE);
|
||||||
FShift :=Offset-FOffset;
|
FShift :=Offset-FOffset;
|
||||||
FSize :=AlignUp(FShift+Size,GRANULAR_PAGE_SIZE);
|
FSize :=FShift+Size;
|
||||||
|
ASize :=AlignUp(FSize,GRANULAR_PAGE_SIZE);
|
||||||
|
|
||||||
case btype of
|
case btype of
|
||||||
BT_PRIV,
|
BT_PRIV,
|
||||||
BT_GPUM:
|
BT_GPUM:
|
||||||
begin
|
begin
|
||||||
err:=_VirtualReserve(Pointer(FOffset),FSize,prot);
|
err:=_VirtualReserve(Pointer(FOffset),ASize,prot);
|
||||||
if (err<>0) then Exit;
|
if (err<>0) then
|
||||||
|
begin
|
||||||
|
Writeln(StdErr,'_VirtualReserve(',HexStr(FOffset),',',HexStr(ASize,16),'):',err);
|
||||||
|
Exit;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
BT_FMAP:
|
BT_FMAP:
|
||||||
begin
|
begin
|
||||||
if (offst<FShift) then Exit;
|
if (offst<FShift) then
|
||||||
|
begin
|
||||||
|
Writeln(StdErr,'offst<FShift:',offst,'<',FShift);
|
||||||
|
Exit;
|
||||||
|
end;
|
||||||
err:=_VirtualMmap(Pointer(FOffset),FSize,prot,fd,offst-FShift);
|
err:=_VirtualMmap(Pointer(FOffset),FSize,prot,fd,offst-FShift);
|
||||||
if (err<>0) then Exit;
|
if (err<>0) then
|
||||||
|
begin
|
||||||
|
Writeln(StdErr,'_VirtualMmap(',HexStr(FOffset),',',HexStr(ASize,16),'):',err);
|
||||||
|
Exit;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
else
|
else
|
||||||
Exit;
|
Exit;
|
||||||
|
@ -218,7 +232,7 @@ begin
|
||||||
|
|
||||||
Result^.F.btype :=btype;
|
Result^.F.btype :=btype;
|
||||||
Result^.Offset :=FOffset;
|
Result^.Offset :=FOffset;
|
||||||
Result^.Size :=FSize;
|
Result^.Size :=ASize;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -261,6 +275,11 @@ begin
|
||||||
if (a>b) then Result:=a else Result:=b;
|
if (a>b) then Result:=a else Result:=b;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function Min(a,b:QWORD):QWORD; inline;
|
||||||
|
begin
|
||||||
|
if (a<b) then Result:=a else Result:=b;
|
||||||
|
end;
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
Function TVirtualAdrBlock.GetOffset:Pointer; inline;
|
Function TVirtualAdrBlock.GetOffset:Pointer; inline;
|
||||||
|
@ -646,7 +665,7 @@ begin
|
||||||
key:=It.Item^;
|
key:=It.Item^;
|
||||||
if (key.F.mapped=0) then
|
if (key.F.mapped=0) then
|
||||||
begin
|
begin
|
||||||
Offset:=System.Align(Max(key.Offset,ss),Align);
|
Offset:=AlignUp(Max(key.Offset,ss),Align);
|
||||||
if (Offset+Size)<=(key.Offset+key.Size) then
|
if (Offset+Size)<=(key.Offset+key.Size) then
|
||||||
begin
|
begin
|
||||||
|
|
||||||
|
@ -656,12 +675,12 @@ begin
|
||||||
if ((_qflag and (MAP_FIXED or MAP_VOID))<>0) then //commit or reserved
|
if ((_qflag and (MAP_FIXED or MAP_VOID))<>0) then //commit or reserved
|
||||||
begin
|
begin
|
||||||
_mmap_sys(_qaddr,_qsize);
|
_mmap_sys(_qaddr,_qsize);
|
||||||
ss:=Offset;
|
ss:=(Offset+Size);
|
||||||
Goto _start;
|
Goto _start;
|
||||||
end else
|
end else
|
||||||
if (_qsize<Size) then //not fit
|
if (_qsize<Size) then //not fit
|
||||||
begin
|
begin
|
||||||
ss:=Offset;
|
ss:=(Offset+Size);
|
||||||
Goto _start;
|
Goto _start;
|
||||||
end;
|
end;
|
||||||
end else
|
end else
|
||||||
|
@ -944,7 +963,7 @@ var
|
||||||
|
|
||||||
function _mapped:Boolean; inline;
|
function _mapped:Boolean; inline;
|
||||||
begin
|
begin
|
||||||
Result:=((flags and MAP_SHARED)<>0) and (fd>0);
|
Result:=((flags and MAP_ANON)=0) and (fd>0);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
@ -990,6 +1009,7 @@ var
|
||||||
key:TVirtualAdrNode;
|
key:TVirtualAdrNode;
|
||||||
start:Pointer;
|
start:Pointer;
|
||||||
FEndN,FEndO:Pointer;
|
FEndN,FEndO:Pointer;
|
||||||
|
ASize:QWORD;
|
||||||
FSize:QWORD;
|
FSize:QWORD;
|
||||||
err:Integer;
|
err:Integer;
|
||||||
btype:Byte;
|
btype:Byte;
|
||||||
|
@ -1011,17 +1031,17 @@ var
|
||||||
|
|
||||||
function _direct:Byte; inline;
|
function _direct:Byte; inline;
|
||||||
begin
|
begin
|
||||||
Result:=Byte(((flags and MAP_SHARED)<>0) and (fd=0));
|
Result:=Byte(((flags and MAP_ANON)=0) and (fd=0));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function _mapped:Byte; inline;
|
function _mapped:Byte; inline;
|
||||||
begin
|
begin
|
||||||
Result:=Byte(((flags and MAP_SHARED)<>0) and (fd>0));
|
Result:=Byte(((flags and MAP_ANON)=0) and (fd>0));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function _addres:Boolean; inline;
|
function _addres:Boolean; inline;
|
||||||
begin
|
begin
|
||||||
Result:=((flags and MAP_SHARED)<>0);
|
Result:=((flags and MAP_ANON)=0);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function _fetch:Boolean;
|
function _fetch:Boolean;
|
||||||
|
@ -1030,16 +1050,16 @@ var
|
||||||
|
|
||||||
if _FetchNode_m(M_LE or C_LE,Offset,key) then
|
if _FetchNode_m(M_LE or C_LE,Offset,key) then
|
||||||
begin
|
begin
|
||||||
FEndN:=Offset+Size;
|
FEndN:=Offset+ASize;
|
||||||
FEndO:=key.Offset+key.Size;
|
FEndO:=key.Offset+key.Size;
|
||||||
|
|
||||||
_Devide(Offset,Size,key);
|
_Devide(Offset,ASize,key);
|
||||||
|
|
||||||
Result:=True;
|
Result:=True;
|
||||||
end else
|
end else
|
||||||
if _FetchNode_m(M_BE or C_BE,(Offset+Size),key) then
|
if _FetchNode_m(M_BE or C_BE,(Offset+ASize),key) then
|
||||||
begin
|
begin
|
||||||
FEndN:=Offset+Size;
|
FEndN:=Offset+ASize;
|
||||||
FEndO:=key.Offset+key.Size;
|
FEndO:=key.Offset+key.Size;
|
||||||
|
|
||||||
_Devide(key.Offset,FEndN-key.Offset,key);
|
_Devide(key.Offset,FEndN-key.Offset,key);
|
||||||
|
@ -1069,6 +1089,8 @@ var
|
||||||
|
|
||||||
addr :=ia(_addres,addr,FSize);
|
addr :=ia(_addres,addr,FSize);
|
||||||
Offset:=Offset+FSize;
|
Offset:=Offset+FSize;
|
||||||
|
|
||||||
|
ASize :=ASize -FSize;
|
||||||
Size :=Size -FSize;
|
Size :=Size -FSize;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -1102,6 +1124,8 @@ var
|
||||||
|
|
||||||
addr :=ia(_addres,addr,FSize);
|
addr :=ia(_addres,addr,FSize);
|
||||||
Offset:=Offset+FSize;
|
Offset:=Offset+FSize;
|
||||||
|
|
||||||
|
ASize :=ASize -FSize;
|
||||||
Size :=Size -FSize;
|
Size :=Size -FSize;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -1110,6 +1134,10 @@ begin
|
||||||
if (Size=0) then Exit(EINVAL);
|
if (Size=0) then Exit(EINVAL);
|
||||||
if (Offset>Fhi) then Exit(EINVAL);
|
if (Offset>Fhi) then Exit(EINVAL);
|
||||||
|
|
||||||
|
if (Align<PHYSICAL_PAGE_SIZE) then Align:=PHYSICAL_PAGE_SIZE;
|
||||||
|
|
||||||
|
ASize:=AlignUp(Size,PHYSICAL_PAGE_SIZE);
|
||||||
|
|
||||||
if _fixed then
|
if _fixed then
|
||||||
begin
|
begin
|
||||||
if (Offset<Flo) then Exit(EINVAL);
|
if (Offset<Flo) then Exit(EINVAL);
|
||||||
|
@ -1117,7 +1145,12 @@ begin
|
||||||
begin
|
begin
|
||||||
Offset:=Max(Offset,Flo);
|
Offset:=Max(Offset,Flo);
|
||||||
|
|
||||||
Result:=_FindFreeOffset(Offset,Size,Align,Offset);
|
if (_mapped<>0) or (Size>=GRANULAR_PAGE_SIZE) then
|
||||||
|
begin
|
||||||
|
if (Align<GRANULAR_PAGE_SIZE) then Align:=GRANULAR_PAGE_SIZE;
|
||||||
|
end;
|
||||||
|
|
||||||
|
Result:=_FindFreeOffset(Offset,ASize,Align,Offset);
|
||||||
if (Result<>0) then Exit;
|
if (Result<>0) then Exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -1152,7 +1185,19 @@ begin
|
||||||
begin
|
begin
|
||||||
if (key.block=nil) then
|
if (key.block=nil) then
|
||||||
begin
|
begin
|
||||||
key.block:=NewAdrBlock(key.Offset,key.Size,prot,btype,fd,addr);
|
if (key.Offset>Offset) then
|
||||||
|
begin
|
||||||
|
FSize:=key.Offset-Offset;
|
||||||
|
FSize:=Min(Size-FSize,key.Size);
|
||||||
|
|
||||||
|
key.block:=NewAdrBlock(key.Offset,FSize,prot,btype,fd,addr);
|
||||||
|
end else
|
||||||
|
begin
|
||||||
|
FSize:=Offset-key.Offset;
|
||||||
|
FSize:=Min(Size+FSize,key.Size);
|
||||||
|
|
||||||
|
key.block:=NewAdrBlock(key.Offset,FSize,prot,btype,fd,addr);
|
||||||
|
end;
|
||||||
|
|
||||||
if (key.block=nil) then
|
if (key.block=nil) then
|
||||||
begin
|
begin
|
||||||
|
|
|
@ -723,36 +723,32 @@ begin
|
||||||
|
|
||||||
if (flags and MAP_VOID)<>0 then //reserved
|
if (flags and MAP_VOID)<>0 then //reserved
|
||||||
begin
|
begin
|
||||||
flags:=flags and (not MAP_SHARED);
|
Result:=VirtualManager.mmap(addr,len,align,prot,flags,-1,0,res);
|
||||||
Result:=VirtualManager.mmap(addr,len,align,prot,flags,fd,offset,res);
|
|
||||||
end else
|
end else
|
||||||
if (flags and MAP_ANON)<>0 then //flex
|
if (flags and MAP_ANON)<>0 then //flex
|
||||||
begin
|
begin
|
||||||
Result:=VirtualManager.mmap(addr,len,align,prot,flags,fd,offset,res);
|
Result:=VirtualManager.mmap(addr,len,align,prot,flags,-1,0,res);
|
||||||
end else
|
end else
|
||||||
if (flags and MAP_SHARED)<>0 then
|
if (fd>=0) then
|
||||||
begin
|
begin
|
||||||
if (fd>=0) then
|
if (fd=0) then //direct (psevdo dmem fd=0)
|
||||||
begin
|
begin
|
||||||
if (fd=0) then //direct (psevdo dmem fd=0)
|
Result:=DirectManager.CheckedMMap(offset,len);
|
||||||
|
|
||||||
|
if (Result=0) then
|
||||||
begin
|
begin
|
||||||
Result:=DirectManager.CheckedMMap(offset,len);
|
|
||||||
|
Result:=VirtualManager.mmap(addr,len,align,prot,flags,fd,offset,res);
|
||||||
|
|
||||||
if (Result=0) then
|
if (Result=0) then
|
||||||
begin
|
begin
|
||||||
|
Result:=DirectManager.mmap_addr(offset,len,addr);
|
||||||
Result:=VirtualManager.mmap(addr,len,align,prot,flags,fd,offset,res);
|
|
||||||
|
|
||||||
if (Result=0) then
|
|
||||||
begin
|
|
||||||
Result:=DirectManager.mmap_addr(offset,len,addr);
|
|
||||||
end;
|
|
||||||
|
|
||||||
end;
|
end;
|
||||||
end else
|
|
||||||
begin //map file
|
|
||||||
Result:=VirtualManager.mmap(addr,len,align,prot,flags,fd,offset,res);
|
|
||||||
end;
|
end;
|
||||||
|
end else
|
||||||
|
begin //map file
|
||||||
|
Result:=VirtualManager.mmap(addr,len,align,prot,flags,fd,offset,res);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -802,7 +798,6 @@ begin
|
||||||
|
|
||||||
if (Result=0) then
|
if (Result=0) then
|
||||||
begin
|
begin
|
||||||
flags:=flags or MAP_SHARED;
|
|
||||||
Result:=VirtualManager.mmap(addr,length,alignment,prots,flags,0,physicalAddr,res);
|
Result:=VirtualManager.mmap(addr,length,alignment,prots,flags,0,physicalAddr,res);
|
||||||
|
|
||||||
if (Result=0) then
|
if (Result=0) then
|
||||||
|
|
|
@ -437,16 +437,28 @@ begin
|
||||||
|
|
||||||
sys_crt_init;
|
sys_crt_init;
|
||||||
|
|
||||||
|
//StackTop - Max
|
||||||
|
//StackBottom - Min
|
||||||
|
|
||||||
StackLength:=data^.Attr.stacksize_attr;
|
StackLength:=data^.Attr.stacksize_attr;
|
||||||
StackBottom:=Sptr-StackLength;
|
Assert(StackLength<>0);
|
||||||
|
|
||||||
|
StackBottom:=StackTop-StackLength;
|
||||||
|
|
||||||
|
Writeln('StackTop :',HexStr(StackTop));
|
||||||
|
Writeln('Sptr :',HexStr(Sptr));
|
||||||
|
|
||||||
|
Writeln('StackBottom:',HexStr(StackBottom));
|
||||||
|
Writeln('StackLength:',HexStr(StackLength,16));
|
||||||
|
|
||||||
ReadBarrier;
|
ReadBarrier;
|
||||||
if (data<>nil) and (data^.entry<>nil) then
|
if (data<>nil) and (data^.entry<>nil) then
|
||||||
begin
|
begin
|
||||||
if (data^.Attr.stackaddr_attr=nil) then
|
//if (data^.Attr.stackaddr_attr=nil) then
|
||||||
begin
|
//begin
|
||||||
data^.Attr.stackaddr_attr:=StackBottom;
|
data^.Attr.stackaddr_attr:=StackBottom;
|
||||||
end;
|
data^.Attr.stacksize_attr:=StackLength;
|
||||||
|
//end;
|
||||||
|
|
||||||
writeln('BeginThread:',data^.name,':',HexStr(data^.entry));
|
writeln('BeginThread:',data^.name,':',HexStr(data^.entry));
|
||||||
tcb_thread:=data;
|
tcb_thread:=data;
|
||||||
|
|
|
@ -223,6 +223,7 @@ Var
|
||||||
dwFileOffsetLow,dwFileOffsetHigh,protect,desiredAccess,dwMaxSizeLow,dwMaxSizeHigh:DWORD;
|
dwFileOffsetLow,dwFileOffsetHigh,protect,desiredAccess,dwMaxSizeLow,dwMaxSizeHigh:DWORD;
|
||||||
maxSize:size_t;
|
maxSize:size_t;
|
||||||
begin
|
begin
|
||||||
|
Result:=0;
|
||||||
if (Addr=nil) then Exit(-1);
|
if (Addr=nil) then Exit(-1);
|
||||||
|
|
||||||
h:=_get_osfhandle(fd);
|
h:=_get_osfhandle(fd);
|
||||||
|
|
Loading…
Reference in New Issue