[fpc-devel] OO rewrite - technical questions
Daniël Mantione
daniel.mantione at freepascal.org
Mon Jul 19 18:50:21 CEST 2010
Op Mon, 19 Jul 2010, schreef Sven Barth:
> Hi!
>
>> Yes, though I am still puzzled how it works on x86_64; it seems regvars
>> there are also accessed using fs, but x86_64 prevents you from writing
>> to segment registers.
>
> As mentioned here http://en.wikipedia.org/wiki/X86_64#Windows in the 10th
> point Windows uses the GS segment register to store pointers to the TEB (see
> http://en.wikipedia.org/wiki/Thread_Environment_Block ) of the current
> running thread (x86 uses FS). So they should still be writable as the TEB is
> written to by the Win32 subsystem (of which a part runs in usermode) as part
> of its bookkeeping and maybe also by user applications to implement the 64
> bit equivalent of SEH.
Well, the following works on i386 but doesn't on x86_64, even though
modify_ldt succeeds:
program ldt_test;
{$asmmode intel}
uses baseunix,linux;
var p:pointer;
ud:user_desc;
begin
p:=pointer(fpmmap(nil,4096,3,MAP_PRIVATE+MAP_ANONYMOUS,-1,0));
ud.entry_number:=1;
pointer(ud.base_addr):=p;
ud.limit:=4096;
ud.flags:=UD_SEG_32BIT or UD_CONTENTS_DATA or UD_USEABLE;
modify_ldt(1, at ud,sizeof(ud));
asm
mov ax,15
mov fs,ax
mov fs:[0].dword,29
end;
writeln(Pcardinal(p)^);
end.
If you know how to make it work, I keep myself recommended :)
Daniël
More information about the fpc-devel
mailing list