Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Initial Wine patch for Haiku (wine-6.23). Clang is required for build.
From a94d195b2ef1188052d0b950bc889b5eb0dfc3dc Mon Sep 17 00:00:00 2001
From: X512 <danger_mail@list.ru>
Date: Fri, 31 Dec 2021 08:17:23 +0900
Subject: Haiku: fix build and minimal operation
---
dlls/nsiproxy.sys/ndis.c | 10 ++++++++
dlls/ntdll/unix/file.c | 2 ++
dlls/ntdll/unix/loader.c | 4 +++
dlls/ntdll/unix/serial.c | 2 ++
dlls/ntdll/unix/server.c | 3 +++
dlls/ntdll/unix/signal_x86_64.c | 45 +++++++++++++++++++++++++++++++++
dlls/ntdll/unix/socket.c | 7 +++++
dlls/winex11.drv/bitblt.c | 1 +
dlls/ws2_32/unixlib.c | 6 +++++
server/change.c | 3 +++
server/fd.c | 3 +++
server/signal.c | 3 +++
server/sock.c | 8 ++++++
13 files changed, 97 insertions(+)
diff --git a/dlls/nsiproxy.sys/ndis.c b/dlls/nsiproxy.sys/ndis.c
index 3e37bce..ed8e206 100644
--- a/dlls/nsiproxy.sys/ndis.c
+++ b/dlls/nsiproxy.sys/ndis.c
@@ -264,6 +264,9 @@ static WCHAR *strdupAtoW( const char *str )
static struct if_entry *add_entry( DWORD index, char *name )
{
+#ifdef __HAIKU__
+ return NULL;
+#else
struct if_entry *entry;
int name_len = strlen( name );
@@ -292,6 +295,7 @@ static struct if_entry *add_entry( DWORD index, char *name )
list_add_tail( &if_list, &entry->entry );
return entry;
+#endif
}
static void update_if_table( void )
@@ -327,6 +331,7 @@ static void ifinfo_fill_dynamic( struct if_entry *entry, struct nsi_ndis_ifinfo_
fd = socket( PF_INET, SOCK_DGRAM, 0 );
if (fd == -1) return;
+#ifndef __HAIKU__
if (!ioctl( fd, SIOCGIFFLAGS, &req ))
{
if (req.ifr_flags & IFF_UP) data->oper_status = IfOperStatusUp;
@@ -335,6 +340,7 @@ static void ifinfo_fill_dynamic( struct if_entry *entry, struct nsi_ndis_ifinfo_
#endif
else data->oper_status = IfOperStatusDown;
} else data->oper_status = IfOperStatusUnknown;
+#endif
data->flags.unk = 0;
data->flags.not_media_conn = 0;
@@ -342,8 +348,12 @@ static void ifinfo_fill_dynamic( struct if_entry *entry, struct nsi_ndis_ifinfo_
data->media_conn_state = MediaConnectStateConnected;
data->unk = 0;
+#ifndef __HAIKU__
if (!ioctl( fd, SIOCGIFMTU, &req )) data->mtu = req.ifr_mtu;
else data->mtu = 0;
+#else
+ data->mtu = 0;
+#endif
close( fd );
diff --git a/dlls/ntdll/unix/file.c b/dlls/ntdll/unix/file.c
index 10d8f3d..43e2105 100644
--- a/dlls/ntdll/unix/file.c
+++ b/dlls/ntdll/unix/file.c
@@ -6529,6 +6529,7 @@ NTSTATUS WINAPI NtQueryVolumeInformationFile( HANDLE handle, IO_STATUS_BLOCK *io
}
if (!get_mountmgr_fs_info( handle, fd, &drive, sizeof(drive) )) fs_type = drive.fs_type;
+#ifndef __HAIKU__
else
{
struct statfs stfs;
@@ -6560,6 +6561,7 @@ NTSTATUS WINAPI NtQueryVolumeInformationFile( HANDLE handle, IO_STATUS_BLOCK *io
#endif
}
}
+#endif
switch (fs_type)
{
diff --git a/dlls/ntdll/unix/loader.c b/dlls/ntdll/unix/loader.c
index 82d099d..a1e4515 100644
--- a/dlls/ntdll/unix/loader.c
+++ b/dlls/ntdll/unix/loader.c
@@ -870,7 +870,11 @@ static NTSTATUS map_so_dll( const IMAGE_NT_HEADERS *nt_descr, HMODULE module )
+ sizeof(IMAGE_NT_HEADERS)
+ nb_sections * sizeof(IMAGE_SECTION_HEADER));
+#ifdef __HAIKU__
+ mprotect(addr, size, PROT_READ | PROT_WRITE);
+#else
if (anon_mmap_fixed( addr, size, PROT_READ | PROT_WRITE, 0 ) != addr) return STATUS_NO_MEMORY;
+#endif
dos = (IMAGE_DOS_HEADER *)addr;
nt = (IMAGE_NT_HEADERS *)((BYTE *)(dos + 1) + sizeof(builtin_signature));
diff --git a/dlls/ntdll/unix/serial.c b/dlls/ntdll/unix/serial.c
index 83244d0..6d1d27c 100644
--- a/dlls/ntdll/unix/serial.c
+++ b/dlls/ntdll/unix/serial.c
@@ -280,9 +280,11 @@ static NTSTATUS get_line_control(int fd, SERIAL_LINE_CONTROL* slc)
switch (port.c_cflag & CSIZE)
{
case CS5: slc->WordLength = 5; break;
+#ifndef __HAIKU__
case CS6: slc->WordLength = 6; break;
case CS7: slc->WordLength = 7; break;
case CS8: slc->WordLength = 8; break;
+#endif
default: ERR("unknown size %x\n", (UINT)(port.c_cflag & CSIZE));
}
diff --git a/dlls/ntdll/unix/server.c b/dlls/ntdll/unix/server.c
index 1dcd079..e6eb2c3 100644
--- a/dlls/ntdll/unix/server.c
+++ b/dlls/ntdll/unix/server.c
@@ -76,6 +76,9 @@
#define _POSIX_SPAWN_DISABLE_ASLR 0x0100
#endif
#endif
+#ifdef __HAIKU__
+#define SIGIO SIGPOLL
+#endif
#include "ntstatus.h"
#define WIN32_NO_STATUS
diff --git a/dlls/ntdll/unix/signal_x86_64.c b/dlls/ntdll/unix/signal_x86_64.c
index 9e9a96d..957f796 100644
--- a/dlls/ntdll/unix/signal_x86_64.c
+++ b/dlls/ntdll/unix/signal_x86_64.c
@@ -64,6 +64,11 @@
#ifdef __APPLE__
# include <mach/mach.h>
#endif
+#ifdef __HAIKU__
+# include <SupportDefs.h>
+extern status_t _kern_generic_syscall(const char *subsystem, uint32 function,
+ void *buffer, size_t bufferSize);
+#endif
#define NONAMELESSUNION
#define NONAMELESSSTRUCT
@@ -232,6 +237,34 @@ __ASM_GLOBAL_FUNC( alloc_fs_sel,
#define FPU_sig(context) ((XMM_SAVE_AREA32 *)&(context)->uc_mcontext->__fs.__fpu_fcw)
#define XState_sig(context) NULL
+#elif defined (__HAIKU__)
+
+#define RAX_sig(context) ((context)->uc_mcontext.rax)
+#define RBX_sig(context) ((context)->uc_mcontext.rbx)
+#define RCX_sig(context) ((context)->uc_mcontext.rcx)
+#define RDX_sig(context) ((context)->uc_mcontext.rdx)
+#define RSI_sig(context) ((context)->uc_mcontext.rsi)
+#define RDI_sig(context) ((context)->uc_mcontext.rdi)
+#define RBP_sig(context) ((context)->uc_mcontext.rbp)
+#define R8_sig(context) ((context)->uc_mcontext.r8)
+#define R9_sig(context) ((context)->uc_mcontext.r9)
+#define R10_sig(context) ((context)->uc_mcontext.r10)
+#define R11_sig(context) ((context)->uc_mcontext.r11)
+#define R12_sig(context) ((context)->uc_mcontext.r12)
+#define R13_sig(context) ((context)->uc_mcontext.r13)
+#define R14_sig(context) ((context)->uc_mcontext.r14)
+#define R15_sig(context) ((context)->uc_mcontext.r15)
+#define CS_sig(context) NULL
+#define FS_sig(context) NULL
+#define GS_sig(context) NULL
+#define EFL_sig(context) ((context)->uc_mcontext.rflags)
+#define RIP_sig(context) ((context)->uc_mcontext.rip)
+#define RSP_sig(context) ((context)->uc_mcontext.rsp)
+#define TRAP_sig(context) TRAP_x86_PAGEFLT
+#define ERROR_sig(context) 0
+#define FPU_sig(context) ((XMM_SAVE_AREA32 *)&(context)->uc_mcontext.fpu)
+#define XState_sig(context) NULL
+
#else
#error You must define the signal context functions for your platform
#endif
@@ -1511,10 +1544,12 @@ static inline void set_sigcontext( const CONTEXT *context, ucontext_t *sigcontex
R14_sig(sigcontext) = context->R14;
R15_sig(sigcontext) = context->R15;
RIP_sig(sigcontext) = context->Rip;
+#ifndef __HAIKU__
CS_sig(sigcontext) = context->SegCs;
FS_sig(sigcontext) = context->SegFs;
GS_sig(sigcontext) = context->SegGs;
EFL_sig(sigcontext) = context->EFlags;
+#endif
#ifdef DS_sig
DS_sig(sigcontext) = context->SegDs;
#endif
@@ -2171,7 +2206,9 @@ static void setup_raise_exception( ucontext_t *sigcontext, EXCEPTION_RECORD *rec
}
}
+#ifndef __HAIKU__
CS_sig(sigcontext) = cs64_sel;
+#endif
RIP_sig(sigcontext) = (ULONG_PTR)pKiUserExceptionDispatcher;
RSP_sig(sigcontext) = (ULONG_PTR)stack;
/* clear single-step, direction, and align check flag */
@@ -2550,6 +2587,12 @@ static void segv_handler( int signal, siginfo_t *siginfo, void *sigcontext )
EXCEPTION_RECORD rec = { 0 };
struct xcontext context;
ucontext_t *ucontext = sigcontext;
+ printf("segv_handler\n");
+ printf(" IP: %#" PRIx64 "\n", RIP_sig(ucontext));
+ printf(" SP: %#" PRIx64 "\n", RSP_sig(ucontext));
+ printf(" FP: %#" PRIx64 "\n", RBP_sig(ucontext));
+ printf(" address: %#" PRIx64 "\n", siginfo->si_addr);
+ _exit(1);
rec.ExceptionAddress = (void *)RIP_sig(ucontext);
save_context( &context, sigcontext );
@@ -2911,6 +2954,8 @@ void signal_init_thread( TEB *teb )
thread's gsbase. Have each thread record its gsbase pointer into its
TEB so alloc_tls_slot() can find it. */
teb->Reserved5[0] = amd64_thread_data()->pthread_teb;
+#elif defined (__HAIKU__)
+ _kern_generic_syscall("thread", /*THREAD_SET_GS_BASE*/ 1, teb, 0);
#else
# error Please define setting %gs for your architecture
#endif
diff --git a/dlls/ntdll/unix/socket.c b/dlls/ntdll/unix/socket.c
index 2e79b9b..335b9fa 100644
--- a/dlls/ntdll/unix/socket.c
+++ b/dlls/ntdll/unix/socket.c
@@ -168,7 +168,9 @@ static NTSTATUS sock_errno_to_status( int err )
case EDESTADDRREQ: return STATUS_INVALID_PARAMETER;
case EMSGSIZE: return STATUS_BUFFER_OVERFLOW;
case EPROTONOSUPPORT:
+#ifndef __HAIKU__
case ESOCKTNOSUPPORT:
+#endif
case EPFNOSUPPORT:
case EAFNOSUPPORT:
case EPROTOTYPE: return STATUS_NOT_SUPPORTED;
@@ -1450,11 +1452,16 @@ NTSTATUS sock_ioctl( HANDLE handle, HANDLE event, PIO_APC_ROUTINE apc, void *apc
}
else
{
+#ifdef __HAIKU__
+ status = sock_errno_to_status( -1 );
+ break;
+#else
if ((ret = ioctl( fd, SIOCATMARK, &value )) < 0)
{
status = sock_errno_to_status( errno );
break;
}
+#endif
/* windows is reversed with respect to unix */
*(int *)out_buffer = !value;
}
diff --git a/dlls/winex11.drv/bitblt.c b/dlls/winex11.drv/bitblt.c
index fad183b..fe47611 100644
--- a/dlls/winex11.drv/bitblt.c
+++ b/dlls/winex11.drv/bitblt.c
@@ -41,6 +41,7 @@
# include <sys/ipc.h>
# endif
#endif
+#undef HAVE_LIBXXSHM
#include "windef.h"
#include "winbase.h"
diff --git a/dlls/ws2_32/unixlib.c b/dlls/ws2_32/unixlib.c
index 67edf06..4b9274b 100644
--- a/dlls/ws2_32/unixlib.c
+++ b/dlls/ws2_32/unixlib.c
@@ -166,7 +166,9 @@ static const int ip_protocol_map[][2] =
MAP( IPPROTO_ICMP ),
MAP( IPPROTO_IGMP ),
MAP( IPPROTO_RAW ),
+#ifndef __HAIKU__
{WS_IPPROTO_IPV4, IPPROTO_IPIP},
+#endif
};
#undef MAP
@@ -338,7 +340,9 @@ static unsigned int errno_from_unix( int err )
case EPROTOTYPE: return WSAEPROTOTYPE;
case ENOPROTOOPT: return WSAENOPROTOOPT;
case EPROTONOSUPPORT: return WSAEPROTONOSUPPORT;
+#ifndef __HAIKU__
case ESOCKTNOSUPPORT: return WSAESOCKTNOSUPPORT;
+#endif
case EOPNOTSUPP: return WSAEOPNOTSUPP;
case EPFNOSUPPORT: return WSAEPFNOSUPPORT;
case EAFNOSUPPORT: return WSAEAFNOSUPPORT;
@@ -354,7 +358,9 @@ static unsigned int errno_from_unix( int err )
case EISCONN: return WSAEISCONN;
case ENOTCONN: return WSAENOTCONN;
case ESHUTDOWN: return WSAESHUTDOWN;
+#ifndef __HAIKU__
case ETOOMANYREFS: return WSAETOOMANYREFS;
+#endif
case ETIMEDOUT: return WSAETIMEDOUT;
case ECONNREFUSED: return WSAECONNREFUSED;
case ELOOP: return WSAELOOP;
diff --git a/server/change.c b/server/change.c
index a01d689..a26f7d3 100644
--- a/server/change.c
+++ b/server/change.c
@@ -36,6 +36,9 @@
#ifdef HAVE_SYS_INOTIFY_H
#include <sys/inotify.h>
#endif
+#ifdef __HAIKU__
+#define SIGIO SIGPOLL
+#endif
#include "ntstatus.h"
#define WIN32_NO_STATUS
diff --git a/server/fd.c b/server/fd.c
index c9a2118..1a0840f 100644
--- a/server/fd.c
+++ b/server/fd.c
@@ -88,6 +88,9 @@
#ifdef HAVE_SYS_SYSCALL_H
#include <sys/syscall.h>
#endif
+#ifdef __HAIKU__
+#undef ioctl
+#endif
#include "ntstatus.h"
#define WIN32_NO_STATUS
diff --git a/server/signal.c b/server/signal.c
index 19b76d4..05dafe1 100644
--- a/server/signal.c
+++ b/server/signal.c
@@ -28,6 +28,9 @@
#include <sys/resource.h>
#endif
#include <unistd.h>
+#ifdef __HAIKU__
+#define SIGIO SIGPOLL
+#endif
#include "file.h"
#include "object.h"
diff --git a/server/sock.c b/server/sock.c
index c9b7113..daeb937 100644
--- a/server/sock.c
+++ b/server/sock.c
@@ -1483,7 +1483,9 @@ static int get_unix_protocol( int protocol )
case WS_IPPROTO_ICMP: return IPPROTO_ICMP;
case WS_IPPROTO_IGMP: return IPPROTO_IGMP;
case WS_IPPROTO_IP: return IPPROTO_IP;
+#ifndef __HAIKU__
case WS_IPPROTO_IPV4: return IPPROTO_IPIP;
+#endif
case WS_IPPROTO_IPV6: return IPPROTO_IPV6;
case WS_IPPROTO_RAW: return IPPROTO_RAW;
case WS_IPPROTO_TCP: return IPPROTO_TCP;
@@ -1943,7 +1945,9 @@ static unsigned int sock_get_error( int err )
case EPROTOTYPE: return WSAEPROTOTYPE;
case ENOPROTOOPT: return WSAENOPROTOOPT;
case EPROTONOSUPPORT: return WSAEPROTONOSUPPORT;
+#ifndef __HAIKU__
case ESOCKTNOSUPPORT: return WSAESOCKTNOSUPPORT;
+#endif
case EOPNOTSUPP: return WSAEOPNOTSUPP;
case EPFNOSUPPORT: return WSAEPFNOSUPPORT;
case EAFNOSUPPORT: return WSAEAFNOSUPPORT;
@@ -1959,7 +1963,9 @@ static unsigned int sock_get_error( int err )
case EISCONN: return WSAEISCONN;
case ENOTCONN: return WSAENOTCONN;
case ESHUTDOWN: return WSAESHUTDOWN;
+#ifndef __HAIKU__
case ETOOMANYREFS: return WSAETOOMANYREFS;
+#endif
case ETIMEDOUT: return WSAETIMEDOUT;
case ECONNREFUSED: return WSAECONNREFUSED;
case ELOOP: return WSAELOOP;
@@ -2010,7 +2016,9 @@ static int sock_get_ntstatus( int err )
case EDESTADDRREQ: return STATUS_INVALID_PARAMETER;
case EMSGSIZE: return STATUS_BUFFER_OVERFLOW;
case EPROTONOSUPPORT:
+#ifndef __HAIKU__
case ESOCKTNOSUPPORT:
+#endif
case EPFNOSUPPORT:
case EAFNOSUPPORT:
case EPROTOTYPE: return STATUS_NOT_SUPPORTED;
--
2.30.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment