FBSD: Use ucontext for FreeBSD 10+ on amd64
[openafs.git] / src / lwp / process.c
index b5537f8..9540571 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2000, International Business Machines Corporation and others.
  * All Rights Reserved.
- * 
+ *
  * This software has been released under the terms of the IBM Public
  * License.  For details, see the LICENSE file in the top-level source
  * directory or online at http://www.openafs.org/dl/license10.html
 #include <afsconfig.h>
 #include <afs/param.h>
 
-RCSID
-    ("$Header$");
+#include <roken.h>
 
-#include <stdio.h>
 #include <assert.h>
+
 #include "lwp.h"
-#ifdef HAVE_STDLIB_H
-#include <stdlib.h>
-#endif
 
-#if defined(AFS_OSF_ENV) || defined(AFS_S390_LINUX20_ENV)
+#if defined(AFS_S390_LINUX20_ENV)
 extern int PRE_Block;          /* used in lwp.c and process.s */
 #else
 extern char PRE_Block;         /* used in lwp.c and process.s */
@@ -30,23 +26,27 @@ extern char PRE_Block;              /* used in lwp.c and process.s */
 
 #if defined(USE_UCONTEXT) && defined(HAVE_UCONTEXT_H)
 
+# if defined(AFS_LINUX20_ENV) || defined(AFS_XBSD_ENV)
+#  define AFS_UCONTEXT_NOSTACK
+# endif
+
 afs_int32
-savecontext(char (*ep) (), struct lwp_context *savearea, char *newsp)
+savecontext(void (*ep) (void), struct lwp_context *savearea, char *newsp)
 {
-#if defined(AFS_LINUX20_ENV)
+# ifdef AFS_UCONTEXT_NOSTACK
     /* getcontext does not export stack info */
     int stackvar;
-#endif
+# endif
 
     PRE_Block = 1;
 
     savearea->state = 0;
     getcontext(&savearea->ucontext);
-#if defined(AFS_LINUX20_ENV)
-    savearea->topstack = &stackvar;
-#else
+# ifdef AFS_UCONTEXT_NOSTACK
+    savearea->topstack = (char *)&stackvar;
+# else
     savearea->topstack = savearea->ucontext.uc_stack.ss_sp;
-#endif
+# endif
     switch (savearea->state) {
     case 0:
        if (newsp) {
@@ -69,8 +69,7 @@ savecontext(char (*ep) (), struct lwp_context *savearea, char *newsp)
 }
 
 void
-returnto(savearea)
-     struct lwp_context *savearea;
+returnto(struct lwp_context *savearea)
 {
     PRE_Block = 0;
 
@@ -130,7 +129,7 @@ Need offset to SP in jmp_buf for this platform.
 typedef __uint64_t jmp_buf_type;
 #endif
 #else
-#if defined(AFS_ALPHA_LINUX20_ENV) || defined(AFS_PPC64_LINUX20_ENV) 
+#if defined(AFS_ALPHA_LINUX20_ENV) || defined(AFS_PPC64_LINUX20_ENV)
 typedef long jmp_buf_type;
 #else
 typedef int jmp_buf_type;
@@ -138,7 +137,7 @@ typedef int jmp_buf_type;
 #endif /*SGI*/
 
     static jmp_buf jmp_tmp;
-static char (*EP) ();
+static void (*EP) (void);
 static int rc;
 static jmp_buf_type *jmpBuffer;
 
@@ -152,13 +151,13 @@ static jmp_buf_type *jmpBuffer;
 #if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 3)
 
 #if defined(AFS_SPARC64_LINUX24_ENV) || defined(AFS_SPARC_LINUX24_ENV)
-/* technically we should use POINTER_GUARD 
+/* technically we should use POINTER_GUARD
  * ( == offsetof (tcbhead_t, pointer_guard) )
  * instead of 0x18
  */
 #undef ptr_mangle
 static int ptr_mangle(int p)
-{   
+{
     register char *tls_ptr __asm__("%g7");
     return p ^ *(int*)(tls_ptr + 0x18);
 }
@@ -172,10 +171,7 @@ static int ptr_mangle(int p)
 
 
 afs_int32
-savecontext(ep, savearea, sp)
-     char (*ep) ();
-     struct lwp_context *savearea;
-     char *sp;
+savecontext(void (*ep)(void), struct lwp_context *savearea, char *sp)
 {
     int code;
 
@@ -233,7 +229,7 @@ savecontext(ep, savearea, sp)
     return 0;
 }
 
-afs_int32
+void
 returnto(struct lwp_context * savearea)
 {
 #if    defined(DEBUG)
@@ -249,7 +245,7 @@ returnto(struct lwp_context * savearea)
 #endif
     PRE_Block = 0;
     longjmp(savearea->setjmp_buffer, 2);
-    return 0;
+    return;
 }
 
 #endif