FreeBSD patch

Seth Kingsley <[email protected]>
Newsgroups gmane.comp.emulators.winex.devel
Message-ID <[email protected]>
The attached patch allows current WineX CVS to compile on FreeBSD.  I
tested it with my GeForce2 MX using one of the NVIDIA demos.  The only
game I have right now is Need for Speed Hot Pursuit 2, and it complains
of a debugger being loaded.

You'll notice that there are duplicate patches for the FPU control-word
save/restore across several versions of DirectX.  If you guys would be
open to adding a local d3d_fpuctl.h with a few macros in it, it could be
used across all DirectX versions.

-- 
|| Seth Kingsley || [email protected] ||
|| http://www.meowfishies.com/ | Meow ^_^ ||
winex-030927.freebsd.patch (text/plain, 14.3 KB)
? make.out
? dlls/dxdiagn/Makefile
? dlls/dxdiagn/dxdiagn.spec.c
? dlls/mswsock/Makefile
? dlls/mswsock/mswsock.spec.c
? dlls/oleacc/Makefile
? dlls/oleacc/oleacc.spec.c
? dlls/quartz/make.out
Index: dlls/d3d8/d3d8_private.h
===================================================================
RCS file: /cvsroot/winex/wine/dlls/d3d8/d3d8_private.h,v
retrieving revision 1.78
diff -u -d -p -r1.78 d3d8_private.h
--- dlls/d3d8/d3d8_private.h	8 Jul 2003 03:01:26 -0000	1.78
+++ dlls/d3d8/d3d8_private.h	27 Sep 2003 22:28:08 -0000
@@ -4,7 +4,13 @@
 #define __WINE_D3D8_PRIVATE_H
 
 #ifdef DDRAW_SAVE_AND_RESTORE_FPU_HACK
+#ifdef linux
 #include <fpu_control.h>
+#elif defined(__FreeBSD__)
+#include <sys/types.h>
+
+typedef u_int16_t fpu_control_t;
+#endif /* linux */
 #endif
 
 #include "ddrawi.h"
Index: dlls/d3d8/draw.c
===================================================================
RCS file: /cvsroot/winex/wine/dlls/d3d8/draw.c,v
retrieving revision 1.39
diff -u -d -p -r1.39 draw.c
--- dlls/d3d8/draw.c	25 Jul 2003 21:44:53 -0000	1.39
+++ dlls/d3d8/draw.c	27 Sep 2003 22:28:10 -0000
@@ -20,7 +20,15 @@ DEFAULT_DEBUG_CHANNEL(ddraw);
    hack simply resets the FPU control state while in a scene.  By default we
    have it on, but we may want to consider this further later.  FIXME! */
 #ifdef DDRAW_SAVE_AND_RESTORE_FPU_HACK
-#  include <fpu_control.h>
+#  ifdef linux
+#      include <fpu_control.h>
+#  elif defined(__FreeBSD__)
+#      include <machine/npx.h>
+
+#      define _FPU_GETCW(cw) __asm__ ("fnstcw %0" : "=m" (*&cw))
+#      define _FPU_SETCW(cw) __asm__ ("fldcw %0" : : "m" (*&cw))
+#      define _FPU_DEFAULT  __INITIAL_NPXCW__
+#  endif /* linux */
    static const fpu_control_t fpu_default = _FPU_DEFAULT;
 
    /* Reset the FPU state to default while doing a scene */
Index: dlls/d3d9/d3d9_private.h
===================================================================
RCS file: /cvsroot/winex/wine/dlls/d3d9/d3d9_private.h,v
retrieving revision 1.4
diff -u -d -p -r1.4 d3d9_private.h
--- dlls/d3d9/d3d9_private.h	25 Sep 2003 21:56:58 -0000	1.4
+++ dlls/d3d9/d3d9_private.h	27 Sep 2003 22:28:12 -0000
@@ -4,7 +4,13 @@
 #define __WINE_D3D9_PRIVATE_H
 
 #ifdef DDRAW_SAVE_AND_RESTORE_FPU_HACK
+#ifdef linux
 #include <fpu_control.h>
+#elif defined(__FreeBSD__)
+#include <sys/types.h>
+
+typedef u_int16_t fpu_control_t;
+#endif /* linux */
 #endif
 
 #include "ddrawi.h"
Index: dlls/d3d9/draw.c
===================================================================
RCS file: /cvsroot/winex/wine/dlls/d3d9/draw.c,v
retrieving revision 1.4
diff -u -d -p -r1.4 draw.c
--- dlls/d3d9/draw.c	25 Sep 2003 16:09:26 -0000	1.4
+++ dlls/d3d9/draw.c	27 Sep 2003 22:28:13 -0000
@@ -22,7 +22,15 @@ DEFAULT_DEBUG_CHANNEL(ddraw);
    hack simply resets the FPU control state while in a scene.  By default we
    have it on, but we may want to consider this further later.  FIXME! */
 #ifdef DDRAW_SAVE_AND_RESTORE_FPU_HACK
-#  include <fpu_control.h>
+#  ifdef linux
+#      include <fpu_control.h>
+#  elif defined(__FreeBSD__)
+#      include <machine/npx.h>
+
+#      define _FPU_GETCW(cw) __asm__ ("fnstcw %0" : "=m" (*&cw))
+#      define _FPU_SETCW(cw) __asm__ ("fldcw %0" : : "m" (*&cw))
+#      define _FPU_DEFAULT  __INITIAL_NPXCW__
+#  endif /* linux */
    static const fpu_control_t fpu_default = _FPU_DEFAULT;
 
    /* Reset the FPU state to default while doing a scene */
Index: dlls/ddraw/d3d_private.h
===================================================================
RCS file: /cvsroot/winex/wine/dlls/ddraw/d3d_private.h,v
retrieving revision 1.47
diff -u -d -p -r1.47 d3d_private.h
--- dlls/ddraw/d3d_private.h	31 May 2003 07:45:52 -0000	1.47
+++ dlls/ddraw/d3d_private.h	27 Sep 2003 22:28:14 -0000
@@ -11,7 +11,13 @@
 /* THIS FILE MUST NOT CONTAIN X11 or MESA DEFINES */
 
 #ifdef DDRAW_SAVE_AND_RESTORE_FPU_HACK
+#ifdef linux
 #include <fpu_control.h>
+#elif defined(__FreeBSD__)
+#include <sys/types.h>
+
+typedef u_int16_t fpu_control_t;
+#endif /* linux */
 #endif
 
 #include "d3d.h"
Index: dlls/ddraw/d3ddevice/main.c
===================================================================
RCS file: /cvsroot/winex/wine/dlls/ddraw/d3ddevice/main.c,v
retrieving revision 1.23
diff -u -d -p -r1.23 main.c
--- dlls/ddraw/d3ddevice/main.c	28 Jul 2003 16:50:15 -0000	1.23
+++ dlls/ddraw/d3ddevice/main.c	27 Sep 2003 22:28:21 -0000
@@ -32,7 +32,15 @@ DEFAULT_DEBUG_CHANNEL(ddraw);
    hack simply resets the FPU control state while in a scene.  By default we
    have it on, but we may want to consider this further later.  FIXME! */
 #ifdef DDRAW_SAVE_AND_RESTORE_FPU_HACK
-#  include <fpu_control.h>
+#  ifdef linux
+#      include <fpu_control.h>
+#  elif defined(__FreeBSD__)
+#      include <machine/npx.h>
+
+#      define _FPU_GETCW(cw) __asm__ ("fnstcw %0" : "=m" (*&cw))
+#      define _FPU_SETCW(cw) __asm__ ("fldcw %0" : : "m" (*&cw))
+#      define _FPU_DEFAULT  __INITIAL_NPXCW__
+#  endif /* linux */
    static const fpu_control_t fpu_default = _FPU_DEFAULT;
 
    /* Reset the FPU state to default while doing a scene */
Index: dlls/ntdll/cdrom.c
===================================================================
RCS file: /cvsroot/winex/wine/dlls/ntdll/cdrom.c,v
retrieving revision 1.7
diff -u -d -p -r1.7 cdrom.c
--- dlls/ntdll/cdrom.c	7 Sep 2003 04:59:50 -0000	1.7
+++ dlls/ntdll/cdrom.c	27 Sep 2003 22:28:26 -0000
@@ -294,7 +294,9 @@ static DWORD CDROM_GetStatusCode(int io)
     switch (errno)
     {
     case EIO:
+#ifdef linux
     case ENOMEDIUM:
+#endif /* linux */
 	    return STATUS_NO_MEDIA_IN_DEVICE;
     case EPERM:
 	    return STATUS_ACCESS_DENIED;
Index: dlls/ntdll/signal_i386.c
===================================================================
RCS file: /cvsroot/winex/wine/dlls/ntdll/signal_i386.c,v
retrieving revision 1.15
diff -u -d -p -r1.15 signal_i386.c
--- dlls/ntdll/signal_i386.c	25 Jul 2003 21:45:06 -0000	1.15
+++ dlls/ntdll/signal_i386.c	27 Sep 2003 22:28:29 -0000
@@ -100,30 +100,6 @@ static inline int wine_sigaction( int si
 }
 #endif
 
-#ifdef HAVE_SIGALTSTACK
-static int wine_sigaltstack( const struct sigaltstack *new,
-                             struct sigaltstack *old )
-{
-    int ret;
-
-    ret = sigaltstack(new, old);
-    if (ret >= 0) return 0;
-
-#ifdef linux
-/* direct syscall for sigaltstack: glibc 2.0 just has an ENOSYS stub. */
-    __asm__ __volatile__( "pushl %%ebx\n\t"
-                          "movl %2,%%ebx\n\t"
-                          "int $0x80\n\t"
-                          "popl %%ebx"
-                          : "=a" (ret)
-                          : "0" (SYS_sigaltstack), "r" (new), "c" (old) );
-    if (ret >= 0) return 0;
-    errno = -ret;
-#endif
-    return -1;
-}
-#endif
-
 #define VM86_EAX 0 /* the %eax value while vm86_enter is executing */
 
 int vm86_enter( void **vm86_ptr );
@@ -163,6 +139,30 @@ __ASM_GLOBAL_FUNC(vm86_enter,
 
 #endif  /* linux */
 
+#ifdef HAVE_SIGALTSTACK
+static int wine_sigaltstack( const struct sigaltstack *new,
+                             struct sigaltstack *old )
+{
+    int ret;
+
+    ret = sigaltstack(new, old);
+    if (ret >= 0) return 0;
+
+#ifdef linux
+/* direct syscall for sigaltstack: glibc 2.0 just has an ENOSYS stub. */
+    __asm__ __volatile__( "pushl %%ebx\n\t"
+                          "movl %2,%%ebx\n\t"
+                          "int $0x80\n\t"
+                          "popl %%ebx"
+                          : "=a" (ret)
+                          : "0" (SYS_sigaltstack), "r" (new), "c" (old) );
+    if (ret >= 0) return 0;
+    errno = -ret;
+#endif
+    return -1;
+}
+#endif
+
 #ifdef BSDI
 
 #define EAX_sig(context)     ((context)->tf_eax)
@@ -816,6 +816,47 @@ static void do_fpe( CONTEXT *context, in
     EXC_RtlRaiseException( &rec, context );
 }
 
+#if defined(USE_PTHREADS)
+static void raise_signal_if_unexpected_thread( int sig, int sig_to_raise )
+{
+# if defined(__i386__)
+    if ( __get_fs() == 0 || NtCurrentTeb()->unix_tid != wine_gettid() )
+# else
+    if ( NtCurrentTeb()->unix_tid != wine_gettid() )
+# endif
+    {
+        fprintf( stderr, "tid %d received signal %d. Raising signal %d\n",
+                   wine_gettid(), sig, sig_to_raise );
+        raise(sig_to_raise);
+    }
+}
+#else
+#  define raise_signal_if_unexpected_thread(a,b)
+#endif /* USE_PTHREADS */
+
+/**********************************************************************
+ *		usr1_handler
+ *
+ * Handler for SIGUSR1.
+ * The window driver (x11drv) use it for interthread signaling.
+ */
+static void (*usr1_callback)(CONTEXT*);
+
+static HANDLER_DEF(usr1_handler)
+{
+    raise_signal_if_unexpected_thread( SIGUSR1, SIGQUIT );
+
+#if 0
+    CONTEXT context;
+
+    save_context( &context, HANDLER_CONTEXT );
+    if (usr1_callback) usr1_callback( &context );
+    restore_context( &context, HANDLER_CONTEXT );
+#else
+    if (usr1_callback) usr1_callback( NULL );
+#endif
+}
+
 
 #ifdef __HAVE_VM86
 /**********************************************************************
@@ -876,47 +917,6 @@ static void set_vm86_pend( CONTEXT *cont
             restore_vm86_context( &vcontext, vm86 );
         }
     }
-}
-
-#if defined(USE_PTHREADS)
-static void raise_signal_if_unexpected_thread( int sig, int sig_to_raise )
-{
-# if defined(__i386__)
-    if ( __get_fs() == 0 || NtCurrentTeb()->unix_tid != wine_gettid() )
-# else
-    if ( NtCurrentTeb()->unix_tid != wine_gettid() )
-# endif
-    {
-        fprintf( stderr, "tid %d received signal %d. Raising signal %d\n",
-                   wine_gettid(), sig, sig_to_raise );
-        raise(sig_to_raise);
-    }
-}
-#else
-#  define raise_signal_if_unexpected_thread(a,b)
-#endif /* USE_PTHREADS */
-
-/**********************************************************************
- *		usr1_handler
- *
- * Handler for SIGUSR1.
- * The window driver (x11drv) use it for interthread signaling.
- */
-static void (*usr1_callback)(CONTEXT*);
-
-static HANDLER_DEF(usr1_handler)
-{
-    raise_signal_if_unexpected_thread( SIGUSR1, SIGQUIT );
-
-#if 0
-    CONTEXT context;
-
-    save_context( &context, HANDLER_CONTEXT );
-    if (usr1_callback) usr1_callback( &context );
-    restore_context( &context, HANDLER_CONTEXT );
-#else
-    if (usr1_callback) usr1_callback( NULL );
-#endif
 }
 
 
Index: dlls/quartz/ffmpeg/libavcodec/mem.c
===================================================================
RCS file: /cvsroot/winex/wine/dlls/quartz/ffmpeg/libavcodec/mem.c,v
retrieving revision 1.1.1.2
diff -u -d -p -r1.1.1.2 mem.c
--- dlls/quartz/ffmpeg/libavcodec/mem.c	3 May 2003 00:19:08 -0000	1.1.1.2
+++ dlls/quartz/ffmpeg/libavcodec/mem.c	27 Sep 2003 22:28:30 -0000
@@ -33,6 +33,8 @@
 #include <malloc.h>
 #endif
 
+#include <stdlib.h>
+
 /* you can redefine av_malloc and av_free in your project to use your
    memory allocator. You do not need to suppress this file because the
    linker will do it automatically */
Index: dlls/quartz/ffmpeg/libavformat/avio.h
===================================================================
RCS file: /cvsroot/winex/wine/dlls/quartz/ffmpeg/libavformat/avio.h,v
retrieving revision 1.2
diff -u -d -p -r1.2 avio.h
--- dlls/quartz/ffmpeg/libavformat/avio.h	3 May 2003 00:29:53 -0000	1.2
+++ dlls/quartz/ffmpeg/libavformat/avio.h	27 Sep 2003 22:28:31 -0000
@@ -64,7 +64,7 @@ typedef struct {
     int (*read_packet)(void *opaque, uint8_t *buf, int buf_size);
     void (*write_packet)(void *opaque, uint8_t *buf, int buf_size);
     int (*seek)(void *opaque, offset_t offset, int whence);
-    int (*get_buffer)(void *opaque, UINT8 *buf, offset_t pos, int buf_size);
+    int (*get_buffer)(void *opaque, uint8_t *buf, offset_t pos, int buf_size);
     offset_t pos; /* position in the file of the current buffer */
     int must_flush; /* true if the next seek should flush */
     int eof_reached; /* true if eof reached */
Index: dlls/wininet/http.c
===================================================================
RCS file: /cvsroot/winex/wine/dlls/wininet/http.c,v
retrieving revision 1.6
diff -u -d -p -r1.6 http.c
--- dlls/wininet/http.c	2 Aug 2003 02:04:50 -0000	1.6
+++ dlls/wininet/http.c	27 Sep 2003 22:28:37 -0000
@@ -26,6 +26,10 @@
 
 #include "config.h"
 
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif /* HAVE_SYS_SOCKET_H */
+
 #include <stdio.h>
 #include <stdlib.h>
 #ifdef HAVE_UNISTD_H
Index: include/wine/server_protocol.h
===================================================================
RCS file: /cvsroot/winex/wine/include/wine/server_protocol.h,v
retrieving revision 1.19
diff -u -d -p -r1.19 server_protocol.h
--- include/wine/server_protocol.h	7 Sep 2003 05:12:47 -0000	1.19
+++ include/wine/server_protocol.h	27 Sep 2003 22:28:45 -0000
@@ -8,6 +8,12 @@
 #ifndef __WINE_WINE_SERVER_PROTOCOL_H
 #define __WINE_WINE_SERVER_PROTOCOL_H
 
+#include "config.h"
+
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif /* HAVE_SYS_TYPES_H */
+
 #include <stdlib.h>
 #include <time.h>
 #include "winbase.h"
Index: library/ldt.c
===================================================================
RCS file: /cvsroot/winex/wine/library/ldt.c,v
retrieving revision 1.4
diff -u -d -p -r1.4 ldt.c
--- library/ldt.c	26 Jun 2003 19:22:50 -0000	1.4
+++ library/ldt.c	27 Sep 2003 22:28:45 -0000
@@ -18,16 +18,10 @@
 
 #ifdef __i386__
 
-#ifdef linux
-
 #ifdef HAVE_SYS_SYSCALL_H
 # include <sys/syscall.h>
 #endif
 
-#if !defined( SYS_set_thread_area ) /* linux only */
-# define SYS_set_thread_area 243
-#endif
-
 struct modify_ldt_s
 {
     unsigned int  entry_number;
@@ -42,6 +36,12 @@ struct modify_ldt_s
     unsigned int  __wine_unused : 25; /* This field doesn't exist in modify_ldt_t */
 };
 
+#ifdef linux
+
+#if !defined( SYS_set_thread_area ) /* linux only */
+# define SYS_set_thread_area 243
+#endif
+
 static inline int modify_ldt( int func, struct modify_ldt_s *ptr,
                                   unsigned long count )
 {
@@ -218,7 +218,6 @@ int wine_ldt_set_entry( unsigned short s
     return ret;
 }
 
-static int tried_already = 0;
 static unsigned short thread_area_selector = 0;
 static const LDT_ENTRY null_entry;  /* all-zeros, used to clear LDT entries */
 
@@ -226,6 +225,8 @@ static const LDT_ENTRY null_entry;  /* a
 unsigned short wine_ldt_alloc_os_supported_thread_area_selector( void )
 {
 #if defined( __linux__ )
+  static int tried_already = 0;
+
   if( !tried_already )
   {
     struct modify_ldt_s ldt_info;
@@ -265,10 +266,12 @@ void wine_ldt_os_set_thread_area_for_thr
 
     wine_ldt_initialize_modify_ldt_struct( &ldt_info, sel>>3, &fs_entry );
     
+#if defined( __linux__ )
     if( set_thread_area( &ldt_info ) < 0 )
     {
       perror( "set_thread_area" );
     }
+#endif /* __linux__ */
   }
 }
signature.asc (application/pgp-signature, 187 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (FreeBSD)

iD8DBQE/dhDtD1AymFxBOwgRAu+aAJ4jHYT8KYISV+3w69670BigA4H3gACfQdDV
AhpqbHTYsBs7J3x8Ea3Pt68=
=/8rg
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.