Kaynağa Gözat

* several small patches (most FreeBSD/x86_64) merged

git-svn-id: branches/fixes_2_2@7392 -
marco 18 yıl önce
ebeveyn
işleme
9781307345

+ 2 - 0
.gitattributes

@@ -4422,6 +4422,7 @@ rtl/freebsd/unxsockh.inc svneol=native#text/plain
 rtl/freebsd/unxsysc.inc svneol=native#text/plain
 rtl/freebsd/x86_64/bsyscall.inc svneol=native#text/plain
 rtl/freebsd/x86_64/prt0.as -text
+rtl/freebsd/x86_64/sighnd.inc svneol=native#text/plain
 rtl/gba/Makefile svneol=native#text/plain
 rtl/gba/Makefile.fpc svneol=native#text/plain
 rtl/gba/classes.pp svneol=native#text/plain
@@ -6263,6 +6264,7 @@ tests/test/cg/obj/darwin/powerpc/tcext5.o -text
 tests/test/cg/obj/freebsd/i386/ctest.o -text
 tests/test/cg/obj/freebsd/i386/tcext3.o -text
 tests/test/cg/obj/freebsd/i386/tcext4.o -text
+tests/test/cg/obj/freebsd/i386/tcext5.o -text
 tests/test/cg/obj/go32v2/i386/ctest.o -text
 tests/test/cg/obj/go32v2/i386/tcext3.o -text
 tests/test/cg/obj/go32v2/i386/tcext4.o -text

+ 9 - 7
compiler/systems/i_bsd.pas

@@ -99,10 +99,12 @@ unit i_bsd;
             system       : system_x86_64_freebsd;
             name         : 'FreeBSD for x86-64';
             shortname    : 'FreeBSD';
-            flags        : [tf_needs_symbol_size,tf_pic_uses_got,tf_files_case_sensitive,tf_use_function_relative_addresses{,tf_smartlink_sections}];
+            flags        : [tf_needs_symbol_size,tf_needs_dwarf_cfi,{Linux: tf_library_needs_pic,}tf_needs_symbol_type,
+                            tf_files_case_sensitive,tf_use_function_relative_addresses
+                                {	tf_pic_uses_got,tf_smartlink_sections}];
             cpu          : cpu_x86_64;
             unit_env     : 'BSDUNITS';
-            extradefines : 'UNIX;HASUNIX';
+            extradefines : 'UNIX;HASUNIX;BSD';
             exeext       : '';
             defext       : '.def';
             scriptext    : '.sh';
@@ -124,13 +126,13 @@ unit i_bsd;
             Cprefix      : '';
             newline      : #10;
             dirsep       : '/';
-            assem        : as_gas;
+            assem        : as_x86_64_elf64;
             assemextern  : as_gas;
             link         : nil;
             linkextern   : nil;
             ar           : ar_gnu_ar;
             res          : res_none;
-            dbg          : dbg_stabs;
+            dbg          : dbg_dwarf2;            //dbg_stabs;
             script       : script_unix;
             endian       : endian_little;
             alignment    :
@@ -141,11 +143,11 @@ unit i_bsd;
                 constalignmin   : 0;
                 constalignmax   : 8;
                 varalignmin     : 0;
-                varalignmax     : 8;
+                varalignmax     : 16;
                 localalignmin   : 4;
-                localalignmax   : 8;
+                localalignmax   : 16;
                 recordalignmin  : 0;
-                recordalignmax  : 8;
+                recordalignmax  : 16;
                 maxCrecordalign : 8
               );
             first_parm_offset : 16;

+ 2 - 2
rtl/bsd/bunxsysc.inc

@@ -538,7 +538,7 @@ function Fppread(fd: cint; buf: pchar; nbytes : size_t; offset:Toff): ssize_t; [
 begin
   
  	{$ifdef CPU64}
-	    Fppread:=do_syscall(syscall_nr_pread,Fd,TSysParam(buf),nbytes,TSysParam(OffSet});
+	    Fppread:=do_syscall(syscall_nr_pread,Fd,TSysParam(buf),nbytes,TSysParam(OffSet));
 	{$else}
            Fppread:=do_syscall(syscall_nr_pread,Fd,TSysParam(buf),nbytes,
            {$ifdef 64bitfs}
@@ -556,7 +556,7 @@ function Fppwrite(fd: cint;buf:pchar; nbytes : size_t; offset:Toff): ssize_t; [p
 
 begin
  	{$ifdef CPU64}
-           Fppwrite:=do_syscall(syscall_nr_pwrite,Fd,TSysParam(buf),nbytes,TSysParam(OffSet});
+           Fppwrite:=do_syscall(syscall_nr_pwrite,Fd,TSysParam(buf),nbytes,TSysParam(OffSet));
 	{$else}
            Fppwrite:=do_syscall(syscall_nr_pwrite,Fd,TSysParam(buf),nbytes,
 	  // ,0  = possible alignment here.

+ 16 - 3
rtl/bsd/ossysc.inc

@@ -71,23 +71,36 @@ FreeBSD: same implementation as NetBSD.
 }
 
 begin
-  Fplseek:=do_syscall(syscall_nr___syscall,syscall_nr_lseek,0,TSysParam(fd),0,lo(Offset),{0} hi(offset),Whence);
+  {$ifdef CPU64}
+    Fplseek:=do_syscall(syscall_nr___syscall,syscall_nr_lseek,TSysParam(fd),0,Offset,whence);
+  {$else}
+    Fplseek:=do_syscall(syscall_nr___syscall,syscall_nr_lseek,0,TSysParam(fd),0,lo(Offset),{0} hi(offset),Whence);
+  {$endif}
 end;
 
 function Fpftruncate(fd : cint; flength : off_t): cint; [public, alias : 'FPC_SYSC_FTRUNCATE'];
 
 begin
- Fpftruncate:=Do_syscall(syscall_nr___syscall,syscall_nr_ftruncate,0,fd,0,lo(flength),hi(flength));
+ {$ifdef CPU64}
+   Fpftruncate:=Do_syscall(syscall_nr___syscall,syscall_nr_ftruncate, fd  ,0   ,flength);
+ {$else}
+   Fpftruncate:=Do_syscall(syscall_nr___syscall,syscall_nr_ftruncate,0,fd,0,lo(flength),hi(flength));
+ {$endif}
+
 end;
 
 
 Function Fpmmap(start:pointer;len:size_t;prot:cint;flags:cint;fd:cint;offst:off_t):pointer; [public, alias:  'FPC_SYSC_MMAP'];
 
 begin
-  Fpmmap:=pointer(longint(do_syscall(syscall_nr_mmap,TSysParam(Start),Len,Prot,Flags,fd,
+ {$ifdef CPU64}
+  Fpmmap:=pointer(ptruint(do__syscall(TSysParam(syscall_nr_mmap),TSysParam(Start),TSysParam(Len),TSysParam(Prot),TSysParam(Flags),TSysParam(fd),TSysParam(offst),0,0)));
+{$else}
+  Fpmmap:=pointer(ptruint(do_syscall(syscall_nr_mmap,TSysParam(Start),Len,Prot,Flags,fd,
         {$ifdef FPC_BIG_ENDIAN}    hi(offst),lo(offst){$endif}
         {$ifdef FPC_LITTLE_ENDIAN} lo(offst),hi(offst){$endif},0
         )));
+{$endif}
 end;
 
 {$endif}

+ 2 - 0
rtl/bsd/ostypes.inc

@@ -291,7 +291,9 @@ Type
  
 CONST
  { Constansts for MMAP }
+{$ifdef FPC_IS_SYSTEM}
   MAP_PRIVATE   =2;
+{$endif}
   MAP_ANONYMOUS =$1000;
 
     {*************************************************************************}

+ 139 - 100
rtl/bsd/x86_64/syscall.inc

@@ -24,111 +24,133 @@
 
 {$ASMMODE GAS}
 
-function do_sysCall(sysnr:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL0'];
+function fpsysCall(sysnr:TSysParam):TSysResult; assembler;[public,alias:'FPC_DOSYS0'];
 
 asm
   movq sysnr, %rax        { Syscall number -> rax.  }
   syscall                 { Do the system call. }
   jge .LSyscOK            { branch to exit if ok, errorhandler otherwise}
-  movq  %rax,%rcx
-  movq  FPC_THREADVAR_RELOCATE,%rax
+ movq  %rax,%rdx
+{$ifdef FPC_PIC}
+  movq  fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
+  movq  (%rax),%rax
+  movq  Errno@GOTPCREL(%rip),%r11
+{$else FPC_PIC}
+  movq  fpc_threadvar_relocate_proc,%rax
+  leaq  Errno,%r11
+{$endif FPC_PIC}
   testq %rax,%rax
   jne   .LThread
-  movq  %rcx,Errno+8
+  movl  %edx,8(%r11)
   jmp   .LNoThread
 .LThread:
-  pushq %rcx
-  pushq Errno
+  pushq %rdx
+  movq  (%r11),%rdi
   call  *%rax
-  popq  %rcx
-  movq  %rcx,(%rax)
+  popq  %rdx
+  movl  %edx,(%rax)
 .LNoThread:
   movq  $-1,%rax
-  movq  rax,%rdx
 .LSyscOK:
 end;
 
-function do_sysCall(sysnr,param1 : TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL1'];
+function fpsysCall(sysnr,param1 : TSysParam):TSysResult; assembler;[public,alias:'FPC_DOSYS1'];
 
 asm
   movq sysnr, %rax        { Syscall number -> rax.  }
   movq param1, %rdi         { shift arg1 - arg1. }
   syscall                 { Do the system call. }
   jge .LSyscOK            { branch to exit if ok, errorhandler otherwise}
-  movq  %rax,%rcx
-  movq  FPC_THREADVAR_RELOCATE,%rax
+ movq  %rax,%rdx
+{$ifdef FPC_PIC}
+  movq  fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
+  movq  (%rax),%rax
+  movq  Errno@GOTPCREL(%rip),%r11
+{$else FPC_PIC}
+  movq  fpc_threadvar_relocate_proc,%rax
+  leaq  Errno,%r11
+{$endif FPC_PIC}
   testq %rax,%rax
   jne   .LThread
-  movq  %rcx,Errno+8
+  movl  %edx,8(%r11)
   jmp   .LNoThread
 .LThread:
-  pushq %rcx
-  pushq Errno
+  pushq %rdx
+  movq  (%r11),%rdi
   call  *%rax
-  popq  %rcx
-  movq  %rcx,(%rax)
+  popq  %rdx
+  movl  %edx,(%rax)
 .LNoThread:
   movq  $-1,%rax
-  movq  rax,%rdx
 .LSyscOK:
 end;
 
-function do_sysCall(sysnr,param1,param2 : TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL2'];
+function fpsysCall(sysnr,param1,param2 : TSysParam):TSysResult; assembler;[public,alias:'FPC_DOSYS2'];
 
 asm
   movq sysnr, %rax        { Syscall number -> rax.  }
   movq param1, %rdi         { shift arg1 - arg2. }
   movq param2, %rsi
-  mov %rcx,%r10
   syscall                 { Do the system call. }
   jge .LSyscOK            { branch to exit if ok, errorhandler otherwise}
-  movq  %rax,%rcx
-  movq  FPC_THREADVAR_RELOCATE,%rax
+ movq  %rax,%rdx
+{$ifdef FPC_PIC}
+  movq  fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
+  movq  (%rax),%rax
+  movq  Errno@GOTPCREL(%rip),%r11
+{$else FPC_PIC}
+  movq  fpc_threadvar_relocate_proc,%rax
+  leaq  Errno,%r11
+{$endif FPC_PIC}
   testq %rax,%rax
   jne   .LThread
-  movq  %rcx,Errno+8
+  movl  %edx,8(%r11)
   jmp   .LNoThread
 .LThread:
-  pushq %rcx
-  pushq Errno
+  pushq %rdx
+  movq  (%r11),%rdi
   call  *%rax
-  popq  %rcx
-  movq  %rcx,(%rax)
+  popq  %rdx
+  movl  %edx,(%rax)
 .LNoThread:
   movq  $-1,%rax
-  movq  rax,%rdx
 .LSyscOK:
 end;
 
-function do_sysCall(sysnr,param1,param2,param3:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL3'];
+function fpsysCall(sysnr,param1,param2,param3:TSysParam):TSysResult; assembler;[public,alias:'FPC_DOSYS3'];
 
 asm
   movq sysnr, %rax        { Syscall number -> rax.  }
   movq param1, %rdi         { shift arg1 - arg3. }
   movq param2, %rsi
   movq param3, %rdx
-  mov %rcx,%r10
   syscall                 { Do the system call. }
   jge .LSyscOK            { branch to exit if ok, errorhandler otherwise}
-  movq  %rax,%rcx
-  movq  FPC_THREADVAR_RELOCATE,%rax
+ movq  %rax,%rdx
+{$ifdef FPC_PIC}
+  movq  fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
+  movq  (%rax),%rax
+  movq  Errno@GOTPCREL(%rip),%r11
+{$else FPC_PIC}
+  movq  fpc_threadvar_relocate_proc,%rax
+  leaq  Errno,%r11
+{$endif FPC_PIC}
   testq %rax,%rax
   jne   .LThread
-  movq  %rcx,Errno+8
+  movl  %edx,8(%r11)
   jmp   .LNoThread
 .LThread:
-  pushq %rcx
-  pushq Errno
+  pushq %rdx
+  movq  (%r11),%rdi
   call  *%rax
-  popq  %rcx
-  movq  %rcx,(%rax)
+  popq  %rdx
+  movl  %edx,(%rax)
 .LNoThread:
   movq  $-1,%rax
-  movq  rax,%rdx
 .LSyscOK:
 end;
 
-function do_sysCall(sysnr,param1,param2,param3,param4:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL4'];
+function fpsysCall(sysnr,param1,param2,param3,param4:TSysParam):TSysResult; assembler;[public,alias:'FPC_DOSYS4'];
 
 asm
   movq sysnr, %rax        { Syscall number -> rax.  }
@@ -136,28 +158,33 @@ asm
   movq param2, %rsi
   movq param3, %rdx
   movq param4, %r10
-  mov %rcx,%r10
   syscall                 { Do the system call. }
   jge .LSyscOK            { branch to exit if ok, errorhandler otherwise}
-  movq  %rax,%rcx
-  movq  FPC_THREADVAR_RELOCATE,%rax
+ movq  %rax,%rdx
+{$ifdef FPC_PIC}
+  movq  fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
+  movq  (%rax),%rax
+  movq  Errno@GOTPCREL(%rip),%r11
+{$else FPC_PIC}
+  movq  fpc_threadvar_relocate_proc,%rax
+  leaq  Errno,%r11
+{$endif FPC_PIC}
   testq %rax,%rax
   jne   .LThread
-  movq  %rcx,Errno+8
+  movl  %edx,8(%r11)
   jmp   .LNoThread
 .LThread:
-  pushq %rcx
-  pushq Errno
+  pushq %rdx
+  movq  (%r11),%rdi
   call  *%rax
-  popq  %rcx
-  movq  %rcx,(%rax)
+  popq  %rdx
+  movl  %edx,(%rax)
 .LNoThread:
   movq  $-1,%rax
-  movq  rax,%rdx
 .LSyscOK:
 end;
 
-function do_sysCall(sysnr,param1,param2,param3,param4,param5 : TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL5'];
+function fpsysCall(sysnr,param1,param2,param3,param4,param5 : TSysParam):TSysResult; assembler;[public,alias:'FPC_DOSYS5'];
 
 asm
   movq sysnr, %rax        { Syscall number -> rax.  }
@@ -166,29 +193,34 @@ asm
   movq param3, %rdx
   movq param4, %r10
   movq param5, %r8
-  mov %rcx,%r10
   syscall                 { Do the system call. }
   jge .LSyscOK            { branch to exit if ok, errorhandler otherwise}
-  movq  %rax,%rcx
-  movq  FPC_THREADVAR_RELOCATE,%rax
+ movq  %rax,%rdx
+{$ifdef FPC_PIC}
+  movq  fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
+  movq  (%rax),%rax
+  movq  Errno@GOTPCREL(%rip),%r11
+{$else FPC_PIC}
+  movq  fpc_threadvar_relocate_proc,%rax
+  leaq  Errno,%r11
+{$endif FPC_PIC}
   testq %rax,%rax
   jne   .LThread
-  movq  %rcx,Errno+8
+  movl  %edx,8(%r11)
   jmp   .LNoThread
 .LThread:
-  pushq %rcx
-  pushq Errno
+  pushq %rdx
+  movq  (%r11),%rdi
   call  *%rax
-  popq  %rcx
-  movq  %rcx,(%rax)
+  popq  %rdx
+  movl  %edx,(%rax)
 .LNoThread:
   movq  $-1,%rax
-  movq  rax,%rdx
 .LSyscOK:
 end;
 
 
-function do_sysCall(sysnr,param1,param2,param3,param4,param5,param6 : TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL6'];
+function fpsysCall(sysnr,param1,param2,param3,param4,param5,param6 : TSysParam):TSysResult; assembler;[public,alias:'FPC_DOSYS6'];
 
 asm
   movq sysnr, %rax        { Syscall number -> rax.  }
@@ -198,61 +230,68 @@ asm
   movq param4, %r10
   movq param5, %r8
   movq param6, %r9
-  mov %rcx,%r10
   syscall                 { Do the system call. }
   jge .LSyscOK            { branch to exit if ok, errorhandler otherwise}
-  movq  %rax,%rcx
-  movq  FPC_THREADVAR_RELOCATE,%rax
+
+ movq  %rax,%rdx
+{$ifdef FPC_PIC}
+  movq  fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
+  movq  (%rax),%rax
+  movq  Errno@GOTPCREL(%rip),%r11
+{$else FPC_PIC}
+  movq  fpc_threadvar_relocate_proc,%rax
+  leaq  Errno,%r11
+{$endif FPC_PIC}
   testq %rax,%rax
   jne   .LThread
-  movq  %rcx,Errno+8
+  movl  %edx,8(%r11)
   jmp   .LNoThread
 .LThread:
-  pushq %rcx
-  pushq Errno
+  pushq %rdx
+  movq  (%r11),%rdi
   call  *%rax
-  popq  %rcx
-  movq  %rcx,(%rax)
+  popq  %rdx
+  movl  %edx,(%rax)
 .LNoThread:
   movq  $-1,%rax
-  movq  rax,%rdx
 .LSyscOK:
-end;
 
-procedure actualsyscall; assembler; {inline requires a dummy push IIRC}
-    asm
-     syscall
-     jge .LSyscOK            { branch to exit if ok, errorhandler otherwise}
-     movq  %rax,%rcx
-     movq  FPC_THREADVAR_RELOCATE,%rax
-     testq %rax,%rax
-     jne   .LThread
-     movq  %rcx,Errno+8
-     jmp   .LNoThread
-   .LThread:
-     pushq %rcx
-     pushq Errno
-     call  *%rax
-     popq  %rcx
-     movq  %rcx,(%rax)
-   .LNoThread:
-     movq  $-1,%rax
-     movq  rax,%rdx
-   .LSyscOK:
 end;
-
-function do__sysCall(sysnr,param1,param2,param3,param4,param5,param6,param7,Param8:TSysParam):TSysResult; oldfpccall; external name 'FPC_DOSYS8';
-// Hmm, we have to do something different :)
+//                    edi   esi   edx 	 ecx    r8      r9   stack
+function fp_sysCall(sysnr,param1,param2,param3,param4,param5,param6 : TSysParam):TSysResult; assembler;[public,alias:'FPC__DOSYS'];
 
 asm
-  movq param8,%rax
-  push %rax
-  movq param7,%rax
-  push %rax
-  movq $syscall_nr__syscall,  %rax
-  mov %rcx,%r10
-  call actualsyscall
-  add $16,%rsp
+  sub    $0x18,%rsp
+  movq   param6,%rax	// from caller stack to mine.	
+  movq   %rax,0x8(%rsp)
+  movl   $0, 0(%rsp)    // dummy or caller frame because ?
+  mov    $0xc6,%rax	// __syscall
+  mov    %rcx,%r10
+  syscall                 { Do the system call. }
+  jge .LSyscOK            { branch to exit if ok, errorhandler otherwise}
+  movq  %rax,%rdx
+{$ifdef FPC_PIC}
+  movq  fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
+  movq  (%rax),%rax
+  movq  Errno@GOTPCREL(%rip),%r11
+{$else FPC_PIC}
+  movq  fpc_threadvar_relocate_proc,%rax
+  leaq  Errno,%r11
+{$endif FPC_PIC}
+  testq %rax,%rax
+  jne   .LThread
+  movl  %edx,8(%r11)
+  jmp   .LNoThread
+.LThread:
+  pushq %rdx
+  movq  (%r11),%rdi
+  call  *%rax
+  popq  %rdx
+  movl  %edx,(%rax)
+.LNoThread:
+  movq  $-1,%rax
+.LSyscOK:
+  add    $0x18,%rsp
 end;
 
 

+ 2 - 1
rtl/bsd/x86_64/syscallh.inc

@@ -39,8 +39,9 @@ function do_sysCall(sysnr,param1,param2,param3:TSysParam):TSysResult;oldfpccall;
 function do_sysCall(sysnr,param1,param2,param3,param4:TSysParam):TSysResult;oldfpccall; external name 'FPC_DOSYS4';
 function do_sysCall(sysnr,param1,param2,param3,param4,param5:TSysParam):TSysResult; oldfpccall;  external name 'FPC_DOSYS5';
 function do_sysCall(sysnr,param1,param2,param3,param4,param5,param6:TSysParam):int64;oldfpccall;  external name 'FPC_DOSYS6';
+//function do_sysCall(sysnr,param1,param2,param3,param4,param5,param6,param7:TSysParam):int64;oldfpccall;  external name 'FPC_DOSYS7';
 
 // special
-function do__sysCall(sysnr,param1,param2,param3,param4,param5,param6,param7,Param8:TSysParam):TSysResult; oldfpccall;  external name 'FPC_DOSYS8';
+function do__sysCall(sysnr,param1,param2,param3,param4,param5,param6,param7,Param8:TSysParam):TSysResult; oldfpccall;  external name 'FPC__DOSYS';
 {$endif}
 

+ 13 - 0
rtl/freebsd/freebsd.pas

@@ -185,6 +185,19 @@ Type
   function kse_release(timeout: PTimeSpec): cInt; extdecl;
   function kse_switchin(tmbx: PKseThrMailBox; flags: cInt): cInt; extdecl;
 
+Const
+ MAP_FILE         = $0000;  { map from file (default) }
+ MAP_ANON         = $1000;  { allocated from memory, swap space }
+   
+ MAP_RENAME       = $0020; { Sun: rename private pages to file }
+ MAP_NORESERVE    = $0040; { Sun: don't reserve needed swap area }
+ //  MAP_INHERIT      = $0080; { region is retained after exec. not anymore in 5.x? }
+ //  MAP_NOEXTEND     = $0100; { for MAP_FILE, don't change file size. not anymore in 5.x? }
+ MAP_HASSEMAPHORE = $0200; { region may contain semaphores }
+ MAP_STACK        = $0400; { region grows down, like a stack }
+ MAP_NOSYNC       = $0800; { page to but do not sync underlying file}
+ MAP_NOCORE       = $20000;{ dont include these pages in a coredump}
+
 implementation
 
 Uses

+ 54 - 0
rtl/freebsd/x86_64/sighnd.inc

@@ -0,0 +1,54 @@
+{
+   This file is part of the Free Pascal run time library.
+   (c) 2000-2003 by Marco van de Voort
+   member of the Free Pascal development team.
+
+   See the file COPYING.FPC, included in this distribution,
+   for details about the copyright.
+
+   Signalhandler for FreeBSD/i386
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY;without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+}
+
+procedure SignalToRunerror(Sig: cint; info : psiginfo;  SigContext:PSigContext); cdecl;
+
+var
+  res : word;
+
+begin
+  res:=0;
+  case sig of
+    SIGFPE :
+          begin
+            Case Info^.si_code Of
+                FPE_INTDIV : Res:=200;  {integer divide fault. Div0?}
+                FPE_FLTOVF : Res:=205;  {Overflow trap}
+                FPE_FLTUND : Res:=206;  {Stack over/underflow}
+                FPE_FLTRES : Res:=216;  {Device not available}
+                FPE_FLTINV : Res:=216;  {Invalid floating point operation}
+               Else
+                Res:=208; {coprocessor error}
+                End;
+             sysResetFPU;
+          End;
+    SIGILL,
+    SIGBUS,
+    SIGSEGV :
+        res:=216;
+  end;
+  {$ifdef FPC_USE_SIGPROCMASK}
+   reenable_signal(sig);
+  {$endif }
+{ give runtime error at the position where the signal was raised }
+  if res<>0 then
+   begin
+{$ifdef cpui386}
+  HandleErrorAddrFrame(res,Pointer(SigContext^.sc_eip),pointer(SigContext^.sc_ebp));
+{$else}
+     HandleError(res);
+{$endif}
+   end;
+end;

+ 6 - 2
rtl/linux/linux.pp

@@ -160,10 +160,14 @@ const
   KD_TEXT0        = 2;    {obsolete}
   KD_TEXT1        = 3;    {obsolete}
 
-
+  MAP_GROWSDOWN  = $100;       { stack-like segment }
+  MAP_DENYWRITE  = $800;       { ETXTBSY }
+  MAP_EXECUTABLE = $1000;      { mark it as an executable }
+  MAP_LOCKED     = $2000;      { pages are locked }
+  MAP_NORESERVE  = $4000;      { don't check for reservations }
 
 type
-  TCloneFunc=function(args:pointer):longint;cdecl;
+  TCloneFunc = function(args:pointer):longint;cdecl;
 
   EPoll_Data = record
     case integer of

+ 2 - 0
rtl/linux/ostypes.inc

@@ -236,7 +236,9 @@ CONST
   S_IFSOCK= 49152; { socket }
 
   { Constansts for MMAP }
+ {$IFDEF FPC_IS_SYSTEM}
   MAP_PRIVATE   =2;
+ {$ENDIF}
   MAP_ANONYMOUS =$20;
 
 

+ 2 - 0
rtl/solaris/ostypes.inc

@@ -210,7 +210,9 @@ Const
 
 Const
  { Constansts for MMAP }
+ {$ifdef FPC_IS_SYSTEM}
   MAP_PRIVATE   =2;
+ {$endif}
   MAP_ANONYMOUS =$100;
 
 type

+ 19 - 0
rtl/unix/baseunix.pp

@@ -47,6 +47,25 @@ Uses UnixType;
 
 {$i genfunch.inc}
 
+{ Fairly portable constants. I'm not going to waste time to duplicate and alias
+them anywhere}
+
+Const
+  MAP_FAILED    = pointer(-1);  { mmap() has failed }
+  MAP_SHARED    =  $1;          { Share changes }
+  MAP_PRIVATE   =  $2;          { Changes are private }
+  MAP_TYPE      =  $f;          { Mask for type of mapping }
+  MAP_FIXED     = $10;          { Interpret addr exactly }
+
+// MAP_ANON(YMOUS) is OS dependant but used in the RTL and in ostypes.inc
+// Under BSD without -YMOUS, so alias it:
+  MAP_ANON	= MAP_ANONYMOUS;
+
+  PROT_READ     =  $1;          { page can be read }
+  PROT_WRITE    =  $2;          { page can be written }
+  PROT_EXEC     =  $4;          { page can be executed }
+  PROT_NONE     =  $0;          { page can not be accessed }
+
 implementation
 
 {$ifdef hassysctl}

+ 65 - 103
rtl/unix/unix.pp

@@ -22,47 +22,47 @@ Uses BaseUnix,UnixType;
 {$endif}
 
 {$i aliasptp.inc}
+{$i unxconst.inc} { Get Types and Constants only exported in this unit }
 
-{ Get Types and Constants only exported in this unit }
-{$i unxconst.inc}
-
-// We init to zero to be able to put timezone stuff under IFDEF, and still
-// keep the code working.
-// We can't do this hear, since unixutil functions access this.
-
-// var
-//  Tzseconds : Longint = 0;
-
-
-{********************
-      File
-********************}
+{**  File handling **}
 
 Const
   P_IN  = 1;                    // pipes (?)
   P_OUT = 2;
 
-Const
   LOCK_SH = 1;                  // flock constants ?
   LOCK_EX = 2;
   LOCK_UN = 8;
   LOCK_NB = 4;
 
+// The portable MAP_* and PROT_ constants are exported from unit Unix for compability.
+  PROT_READ  = baseunix.PROT_READ;             { page can be read }
+  PROT_WRITE = baseunix.PROT_WRITE;             { page can be written }
+  PROT_EXEC  = baseunix.PROT_EXEC;             { page can be executed }
+  PROT_NONE  = baseunix.PROT_NONE;             { page can not be accessed }
+
+  MAP_FAILED    = baseunix.MAP_FAILED;	      { mmap() failed }
+  MAP_SHARED    = baseunix.MAP_SHARED;        { Share changes }
+  MAP_PRIVATE   = baseunix.MAP_PRIVATE;       { Changes are private }
+  MAP_TYPE      = baseunix.MAP_TYPE;          { Mask for type of mapping }
+  MAP_FIXED     = baseunix.MAP_FIXED;         { Interpret addr exactly }
+
+{ Flags to `msync'.  There is non msync() call in this unit? }
+  MS_ASYNC        = 1;               { Sync memory asynchronously.  }
+  MS_SYNC         = 4;               { Synchronous memory sync.  }
+  MS_INVALIDATE   = 2;               { Invalidate the caches.  }
+
 Type
   Tpipe = baseunix.tfildes;     // compability.
 
-{******************************************************************************
-                            Procedure/Functions
-******************************************************************************}
-
-{**************************
-     Time/Date Handling
-***************************}
+{** Time/Date Handling **}
 
 var
   tzdaylight : boolean;
   tzname     : array[boolean] of pchar;
 
+{************     Procedure/Functions     ************}
+
 {$IFNDEF DONT_READ_TIMEZONE}  // allows to disable linking in and trying for platforms
                        // it doesn't (yet) work for.
 
@@ -73,19 +73,14 @@ procedure ReadTimezoneFile(fn:string);
 function  GetTimezoneFile:string;
 {$ENDIF}
 
-{**************************
-     Process Handling
-***************************}
-
-//
-// These are much better, in nearly all ways.
-//
+{**  Process Handling  **}
 
 function FpExecLE (Const PathName:AnsiString;const S:Array Of AnsiString;MyEnv:ppchar):cint;
-function FpExecL(Const PathName:AnsiString;const S:Array Of AnsiString):cint;
-function FpExecLP(Const PathName:AnsiString;const S:Array Of AnsiString):cint;
-function FpExecV(Const PathName:AnsiString;args:ppchar):cint;
-function FpExecVP(Const PathName:AnsiString;args:ppchar):cint;
+function FpExecL  (Const PathName:AnsiString;const S:Array Of AnsiString):cint;
+function FpExecLP (Const PathName:AnsiString;const S:Array Of AnsiString):cint;
+function FpExecLPE(Const PathName:AnsiString;const S:Array Of AnsiString;env:ppchar):cint;
+function FpExecV  (Const PathName:AnsiString;args:ppchar):cint;
+function FpExecVP (Const PathName:AnsiString;args:ppchar):cint;
 function FpExecVPE(Const PathName:AnsiString;args,env:ppchar):cint;
 
 Function Shell   (const Command:String):cint;     deprecated;
@@ -94,101 +89,49 @@ Function fpSystem(const Command:string):cint;
 Function fpSystem(const Command:AnsiString):cint;
 
 Function WaitProcess (Pid:cint):cint; 
-{ like WaitPid(PID,@result,0) Handling of Signal interrupts (errno=EINTR), returning the Exitcode of Process (>=0) or -Status if terminated}
 
 Function WIFSTOPPED (Status: Integer): Boolean;
 Function W_EXITCODE (ReturnCode, Signal: Integer): Integer;
 Function W_STOPCODE (Signal: Integer): Integer;
 
-{**************************
-     File Handling
-***************************}
+{**      File Handling     **}
 
 {$ifndef FPC_USE_LIBC} // defined using cdecl for libc.
-Function  fsync (fd : cint) : cint;
+// some of these are formally listed as deprecated, but specially statfs will remain for a while, no rush.
+Function  fsync (fd : cint) : cint; deprecated;	
 Function  fpFlock   (fd,mode : cint)   : cint ;
-Function  fStatFS (Fd: cint;Var Info:tstatfs):cint;
-Function  StatFS  (Path:pchar;Var Info:tstatfs):cint;
+Function  fStatFS (Fd: cint;Var Info:tstatfs):cint; deprecated;
+Function  StatFS  (Path:pchar;Var Info:tstatfs):cint; deprecated;
 {$endif}
 
+Function  fpfStatFS (Fd: cint; Info:pstatfs):cint;
+Function  fpStatFS  (Path:pchar; Info:pstatfs):cint;
+Function  fpfsync (fd : cint) : cint;
+
 Function  fpFlock   (var T : text;mode : cint) : cint;
 Function  fpFlock   (var F : File;mode : cint) : cint;
 
 Function  SelectText (var T:Text;TimeOut :PTimeVal):cint; deprecated;
 Function  SelectText (var T:Text;TimeOut :cint):cint; deprecated;
 
-{**************************
-   Directory Handling
-***************************}
+{**  Directory Handling  **}
 
 procedure SeekDir(p:pdir;loc:clong);
 function  TellDir(p:pdir):TOff;
 
-{**************************
-    Pipe/Fifo/Stream
-***************************}
+{**     Pipe/Fifo/Stream     **}
 
 Function AssignPipe  (var pipe_in,pipe_out:cint):cint;
 Function AssignPipe  (var pipe_in,pipe_out:text):cint;
 Function AssignPipe  (var pipe_in,pipe_out:file):cint;
-//Function PClose      (Var F:text) : cint;
-//Function PClose      (Var F:file) : cint;
 Function POpen       (var F:text;const Prog:Ansistring;rw:char):cint;
 Function POpen       (var F:file;const Prog:Ansistring;rw:char):cint;
 Function AssignStream(Var StreamIn,Streamout:text;Const Prog:ansiString;const args : array of ansistring) : cint;
 Function AssignStream(Var StreamIn,Streamout,streamerr:text;Const Prog:ansiString;const args : array of ansistring) : cint;
-
-Function  GetDomainName:String;
+Function  GetDomainName:String; deprecated; // because linux only.
 Function  GetHostName:String;
 
-
-{**************************
-     Memory functions
-***************************}
-
-const
-  PROT_READ  = $1;             { page can be read }
-  PROT_WRITE = $2;             { page can be written }
-  PROT_EXEC  = $4;             { page can be executed }
-  PROT_NONE  = $0;             { page can not be accessed }
-
-  MAP_FAILED    = pointer(-1); { mmap() has failed }
-  MAP_SHARED    = $1;          { Share changes }
-//  MAP_PRIVATE   = $2;          { Changes are private }
-  MAP_TYPE      = $f;          { Mask for type of mapping }
-  MAP_FIXED     = $10;         { Interpret addr exactly }
-//  MAP_ANONYMOUS = $20;         { don't use a file }
-
-{ Flags to `msync'.  }
-  MS_ASYNC        = 1;               { Sync memory asynchronously.  }
-  MS_SYNC         = 4;               { Synchronous memory sync.  }
-  MS_INVALIDATE   = 2;               { Invalidate the caches.  }
-
-{$ifdef Linux}
-  MAP_GROWSDOWN  = $100;       { stack-like segment }
-  MAP_DENYWRITE  = $800;       { ETXTBSY }
-  MAP_EXECUTABLE = $1000;      { mark it as an executable }
-  MAP_LOCKED     = $2000;      { pages are locked }
-  MAP_NORESERVE  = $4000;      { don't check for reservations }
-{$else}
-  {$ifdef FreeBSD}
-  // FreeBSD defines MAP_COPY=MAP_PRIVATE=$2;
-  MAP_FILE         = $0000;  { map from file (default) }
-  MAP_ANON         = $1000;  { allocated from memory, swap space }
-
-  MAP_RENAME       = $0020; { Sun: rename private pages to file }
-  MAP_NORESERVE    = $0040; { Sun: don't reserve needed swap area }
-  MAP_INHERIT      = $0080; { region is retained after exec }
-  MAP_NOEXTEND     = $0100; { for MAP_FILE, don't change file size }
-  MAP_HASSEMAPHORE = $0200; { region may contain semaphores }
-  MAP_STACK        = $0400; { region grows down, like a stack }
-  MAP_NOSYNC       = $0800; { page to but do not sync underlying file}
-  MAP_NOCORE       = $20000;{ dont include these pages in a coredump}
-  {$endif}
-{$endif}
-{**************************
-    Utility functions
-***************************}
+{** Utility functions  **}
 
 Type
         TFSearchOption  = (NoCurrentDirectory,
@@ -198,7 +141,7 @@ Type
 Function  FSearch  (const path:AnsiString;dirlist:Ansistring;CurrentDirStrategy:TFSearchOption):AnsiString;
 Function  FSearch  (const path:AnsiString;dirlist:AnsiString):AnsiString;
 
-procedure SigRaise (sig:integer);
+procedure SigRaise (sig:integer); deprecated;
 
 {$ifdef FPC_USE_LIBC}
   const clib = 'c';
@@ -355,6 +298,7 @@ Begin
   FpExecLE:=intFPExecl(PathName,s,MyEnv,false);
 End;
 
+
 function FpExecL(Const PathName:AnsiString;const S:Array Of AnsiString):cint;
 
 Begin
@@ -367,6 +311,12 @@ Begin
   FpExecLP:=intFPExecl(PathName,S,EnvP,True);
 End;
 
+function FpExecLPE(Const PathName:AnsiString;const S:Array Of AnsiString;env:ppchar):cint;
+
+Begin
+  FpExecLPE:=intFPExecl(PathName,S,Env,True);
+End;
+
 function FpExecV(Const PathName:AnsiString;args:ppchar):cint;
 
 Begin
@@ -1288,7 +1238,6 @@ begin
   fpKill(fpGetPid,Sig);
 end;
 
-
 {******************************************************************************
                              Utility calls
 ******************************************************************************}
@@ -1357,9 +1306,22 @@ Begin
  FSearch:=FSearch(path,dirlist,CurrentDirectoryFirst);
 End;
 
-{--------------------------------
-      Stat.Mode Macro's
---------------------------------}
+Function  fpfStatFS (Fd: cint; Info:pstatfs):cint;
+begin
+  fpfstatfs:=fstatfs(fd,info^);
+end;
+
+Function  fpStatFS  (Path:pchar; Info:pstatfs):cint;
+
+begin
+  fpstatfs:=statfs(Path,info^);
+end;
+
+Function  fpfsync (fd : cint) : cint;
+
+begin
+  fpfsync:=fsync(fd);
+end;
 
 Initialization
 {$IFNDEF DONT_READ_TIMEZONE}

BIN
tests/test/cg/obj/freebsd/i386/tcext5.o