[Glibc-bsd-commits] r4616 - in trunk/glibc-ports/kfreebsd/i386: . fbtl i686/fbtl

Petr Salinger ps-guest at alioth.debian.org
Mon Jul 8 12:47:34 UTC 2013


Author: ps-guest
Date: 2013-06-26 20:27:11 +0000 (Wed, 26 Jun 2013)
New Revision: 4616

Added:
   trunk/glibc-ports/kfreebsd/i386/fbtl/exit-thread.S
   trunk/glibc-ports/kfreebsd/i386/fbtl/pt-vfork.c
   trunk/glibc-ports/kfreebsd/i386/fbtl/sysdep-cancel.h
   trunk/glibc-ports/kfreebsd/i386/fbtl/tls.h
   trunk/glibc-ports/kfreebsd/i386/i686/fbtl/tls.h
Modified:
   trunk/glibc-ports/kfreebsd/i386/syscalls-internal.h
Log:
add i386 bits


Added: trunk/glibc-ports/kfreebsd/i386/fbtl/exit-thread.S
===================================================================
--- trunk/glibc-ports/kfreebsd/i386/fbtl/exit-thread.S	                        (rev 0)
+++ trunk/glibc-ports/kfreebsd/i386/fbtl/exit-thread.S	2013-06-26 20:27:11 UTC (rev 4616)
@@ -0,0 +1,32 @@
+/* Copyright (C) 1991,92,97,99,2002 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library 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.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sysdep.h>
+	.text
+ENTRY (__exit_thread)
+        mov %gs:0, %edx
+	mov 4(%ebp), %ecx	/* we will need it later, 
+                                %ecx is saved by kernel */
+        add $TID,  %edx		/* should be KTID, but
+                                they are at the same place anyway */
+        mov %edx, 4(%ebp)
+        DO_CALL (thr_exit, 1)
+	mov %ecx, 4(%ebp)	/* use saved value */
+        DO_CALL (exit, 1)
+        /* Shouldn't get here.  */
+        hlt
+END   (__exit_thread)

Added: trunk/glibc-ports/kfreebsd/i386/fbtl/pt-vfork.c
===================================================================
--- trunk/glibc-ports/kfreebsd/i386/fbtl/pt-vfork.c	                        (rev 0)
+++ trunk/glibc-ports/kfreebsd/i386/fbtl/pt-vfork.c	2013-06-26 20:27:11 UTC (rev 4616)
@@ -0,0 +1 @@
+#warning TODO

Added: trunk/glibc-ports/kfreebsd/i386/fbtl/sysdep-cancel.h
===================================================================
--- trunk/glibc-ports/kfreebsd/i386/fbtl/sysdep-cancel.h	                        (rev 0)
+++ trunk/glibc-ports/kfreebsd/i386/fbtl/sysdep-cancel.h	2013-06-26 20:27:11 UTC (rev 4616)
@@ -0,0 +1,108 @@
+/* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Jakub Jelinek <jakub at redhat.com>, 2002.
+   Modification for FreeBSD by Petr Salinger, 2005.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library 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.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <sysdep.h>
+#include <tls.h>
+#ifndef __ASSEMBLER__
+# include <fbtl/pthreadP.h>
+#endif
+
+#if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
+
+# undef PSEUDO
+# define PSEUDO(name, syscall_name, args)				      \
+  .text;								      \
+  ENTRY (name)								      \
+    cmpl $0, %gs:MULTIPLE_THREADS_OFFSET;				      \
+    jne L(pseudo_cancel);						      \
+  .type __##syscall_name##_nocancel, at function;				      \
+  .globl __##syscall_name##_nocancel;					      \
+  __##syscall_name##_nocancel:						      \
+    DO_CALL (syscall_name, args);					      \
+    jb SYSCALL_ERROR_LABEL;						      \
+    ret;								      \
+  .size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel;	      \
+  L(pseudo_cancel):							      \
+    CENABLE								      \
+    movl %eax, %ecx;							      \
+    movl $SYS_ify (syscall_name), %eax;					      \
+    int $0x80;								      \
+    PUSHRESULT;							      	      \
+    movl %ecx, %eax; 							      \
+    CDISABLE;							 	      \
+    POPRESULT;							      	      \
+    jb SYSCALL_ERROR_LABEL;						      \
+  L(pseudo_end):
+
+/*
+  on FreeBSD some syscalls return result in pair edx+eax,
+  therefore proper way would be
+
+# define PUSHRESULT	pushl %edx; pushl %eax; pushfl
+# define POPRESULT	popfl; popl %eax; popl %edx
+
+  for FreeBSD 5.4 affected syscalls are
+
+	lseek()
+	fork()
+	vfork()
+	rfork()
+	pipe()
+
+   none of them is cancelable, therefore
+*/
+
+# define PUSHRESULT	pushl %eax; cfi_adjust_cfa_offset (4);  pushfl;    cfi_adjust_cfa_offset (4)
+# define POPRESULT	popfl;      cfi_adjust_cfa_offset (-4); popl %eax; cfi_adjust_cfa_offset (-4)
+
+# ifdef IS_IN_libpthread
+#  define CENABLE	call __pthread_enable_asynccancel;
+#  define CDISABLE	call __pthread_disable_asynccancel
+# elif !defined NOT_IN_libc
+#  define CENABLE	call __libc_enable_asynccancel;
+#  define CDISABLE	call __libc_disable_asynccancel
+# elif defined IS_IN_librt
+#  define CENABLE	call __librt_enable_asynccancel;
+#  define CDISABLE	call __librt_disable_asynccancel
+# else
+#  error Unsupported library
+# endif
+
+
+# ifndef __ASSEMBLER__
+#  define SINGLE_THREAD_P \
+  __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
+				   header.multiple_threads) == 0, 1)
+# else
+#  define SINGLE_THREAD_P cmpl $0, %gs:MULTIPLE_THREADS_OFFSET
+# endif
+
+#elif !defined __ASSEMBLER__
+
+# define SINGLE_THREAD_P (1)
+# define NO_CANCELLATION 1
+
+#endif
+
+#ifndef __ASSEMBLER__
+# define RTLD_SINGLE_THREAD_P \
+  __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
+				   header.multiple_threads) == 0, 1)
+#endif

Added: trunk/glibc-ports/kfreebsd/i386/fbtl/tls.h
===================================================================
--- trunk/glibc-ports/kfreebsd/i386/fbtl/tls.h	                        (rev 0)
+++ trunk/glibc-ports/kfreebsd/i386/fbtl/tls.h	2013-06-26 20:27:11 UTC (rev 4616)
@@ -0,0 +1,97 @@
+/* Definition for thread-local data handling.  fbtl/i386 version.
+   Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library 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.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#ifndef _FREEBSD_TLS_H
+#define _FREEBSD_TLS_H
+
+#include <fbtl/sysdeps/i386/tls.h>
+
+# ifndef __ASSEMBLER__
+
+#undef TLS_INIT_TP
+#undef TLS_SETUP_GS_SEGMENT
+#undef TLS_GET_GS
+#undef TLS_SET_GS       
+#undef __NR_set_thread_area
+
+#include <sysarch.h>
+#include <sys/syscall.h>
+
+
+/* Code to initially initialize the thread pointer.  This might need
+   special attention since 'errno' is not yet available and if the
+   operation can cause a failure 'errno' must not be touched. */
+
+#  define TLS_DO_SET_GSBASE(descr)		\
+({                                      	\
+  long base = (long) descr;             	\
+  int result;                           	\
+  asm volatile (                        	\
+                "pushl %3\n\t"          	\
+                "pushl %2\n\t"          	\
+                "pushl %1\n\t"       		\
+                "int $0x80\n\t"         	\
+                "popl %3\n\t"        		\
+                "popl %3\n\t"        		\
+                "popl %3\n\t"        		\
+                : "=a" (result)         	\
+                : "0" (SYS_sysarch),     	\
+                  "i" (I386_SET_GSBASE),       	\
+                  "d" (&base)			\
+                : "memory", "cc" );    		\
+  result;                                       \
+})
+
+#   define TLS_SETUP_GS_SEGMENT(descr, secondcall)                            \
+  (TLS_DO_SET_GSBASE(descr)                                                   \
+   ? "set_thread_area failed when setting up thread-local storage\n" : NULL)
+
+/*   The value of this macro is null if successful, or an error string.  */
+
+#  define TLS_INIT_TP(descr, secondcall)				      \
+  ({									      \
+    void *_descr = (descr);						      \
+    tcbhead_t *head = _descr;						      \
+									      \
+    head->tcb = _descr;							      \
+    /* For now the thread descriptor is at the same address.  */	      \
+    head->self = _descr;						      \
+									      \
+    INIT_SYSINFO;							      \
+    TLS_SETUP_GS_SEGMENT (_descr, secondcall);				      \
+  })
+
+#if 0
+/* in Linux one; */
+/* Magic for libthread_db to know how to do THREAD_SELF.  */
+# define DB_THREAD_SELF \
+  REGISTER_THREAD_AREA (32, offsetof (struct user_regs_struct, xgs), 3) \
+  REGISTER_THREAD_AREA (64, 26 * 8, 3) /* x86-64's user_regs_struct->gs */
+#else
+/* # warning proper variant needed */
+# undef DB_THREAD_SELF_INCLUDE
+# undef DB_THREAD_SELF
+# define DB_THREAD_SELF \
+  REGISTER_THREAD_AREA (32, 12, 3)  /* offsetof (struct user_regs_struct, xgs) */ \
+  REGISTER_THREAD_AREA (64, 26 * 8, 3) /* x86-64's user_regs_struct->gs */
+#endif
+
+#endif /* __ASSEMBLER__ */
+
+#endif	/* tls.h */

Added: trunk/glibc-ports/kfreebsd/i386/i686/fbtl/tls.h
===================================================================
--- trunk/glibc-ports/kfreebsd/i386/i686/fbtl/tls.h	                        (rev 0)
+++ trunk/glibc-ports/kfreebsd/i386/i686/fbtl/tls.h	2013-06-26 20:27:11 UTC (rev 4616)
@@ -0,0 +1,2 @@
+/* no special TLS_GET_GS and TLS_SET_GS, as we do not define them at all */
+#include <sysdeps/unix/bsd/bsd4.4/kfreebsd/i386/fbtl/tls.h>

Modified: trunk/glibc-ports/kfreebsd/i386/syscalls-internal.h
===================================================================
--- trunk/glibc-ports/kfreebsd/i386/syscalls-internal.h	2013-06-26 20:26:16 UTC (rev 4615)
+++ trunk/glibc-ports/kfreebsd/i386/syscalls-internal.h	2013-06-26 20:27:11 UTC (rev 4616)
@@ -60,6 +60,32 @@
   result;                                       \
 })
 
+#define INTERNAL_SYSCALL_write(name, err, nr, fd, buf, cnt) \
+(void)({                                        \
+  register long int _a1 = (long int) (fd);	\
+  register long int _a2 = (long int) (buf);	\
+  register long int _a3 = (long int) (cnt);	\
+  register long int result;			\
+  register long int _trash;			\
+  asm volatile (                                \
+                "pushl %5\n\t"                  \
+                "pushl %4\n\t"                  \
+                "pushl %3\n\t"                  \
+                "pushl %2\n\t"                  \
+                "int $0x80\n\t"                 \
+                "addl $16,%%esp\n\t"		\
+                : "=a" (result),		\
+                  "=d" (_trash)                 \
+                : "0" ((long int) SYS_##name),	\
+                  "ri" (_a1),			\
+                  "ri" (_a2),			\
+                  "ri" (_a3)			\
+              /*   may be even "g" constraint could be used */ \
+              /*   but we have to worry about esp register and esp based address */ \
+                : "memory", "cc" );             \
+  result;                                       \
+})
+
 #define INTERNAL_SYSCALL_writev(name, err, nr, fd, iov, cnt) \
 (void)({                                        \
   register long int _a1 = (long int) (fd);	\
@@ -85,4 +111,5 @@
                 : "memory", "cc" );             \
   result;                                       \
 })
+
 #endif




More information about the Glibc-bsd-commits mailing list