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