From e2e2c7e3946b93e8c2fddc0248de6861dc4aff6d Mon Sep 17 00:00:00 2001 From: Anarchos Date: Thu, 11 Apr 2024 05:14:46 +0200 Subject: [PATCH] Haiku OS port (#485) * Haiku OS port * haiku with X11 backend * haiku has stpncpy * Haiku is not Linux. * X not stable enough on Haiku * Haiku : settimeofday is a no-op * Haiku : no need to define settimeofday at all (pointed by nbriggs) --------- Signed-off-by: Anarchos --- bin/makefile-haiku.x86_64-sdl | 19 +++++++++++++++++++ bin/osversion | 1 + inc/maiko/platform.h | 6 ++++++ src/inet.c | 29 +++++++++++++++++++++++++---- src/initsout.c | 4 ++-- src/ldeboot.c | 1 + src/timer.c | 16 ++++++++++++++-- src/tty.c | 4 ++++ src/unixfork.c | 2 ++ src/uraid.c | 2 ++ src/uutils.c | 5 ++++- 11 files changed, 80 insertions(+), 9 deletions(-) create mode 100644 bin/makefile-haiku.x86_64-sdl diff --git a/bin/makefile-haiku.x86_64-sdl b/bin/makefile-haiku.x86_64-sdl new file mode 100644 index 0000000..1e68a87 --- /dev/null +++ b/bin/makefile-haiku.x86_64-sdl @@ -0,0 +1,19 @@ +# Options for Haiku, Intel x86_64 and SDL + +CC = gcc -m64 $(GCC_CFLAGS) +# CC = clang -m64 $(CLANG_CFLAGS) + +XFILES = $(OBJECTDIR)sdl.o + +XFLAGS = -DSDL + +# OPTFLAGS is normally -O2. +OPTFLAGS = -O2 -g3 +DFLAGS = $(XFLAGS) -DRELEASE=351 + +LDFLAGS = -lSDL2 -lnetwork +LDELDFLAGS = -lnetwork -lbsd + +OBJECTDIR = ../$(RELEASENAME)/ + +default : ../$(OSARCHNAME)/lde ../$(OSARCHNAME)/ldesdl diff --git a/bin/osversion b/bin/osversion index 19f6eae..80bf6bd 100755 --- a/bin/osversion +++ b/bin/osversion @@ -12,6 +12,7 @@ case "$os" in *-*-openbsd*) echo openbsd ;; *-*-freebsd*) echo freebsd ;; *-*-cygwin*) echo cygwin ;; + *-*-haiku*) echo haiku ;; esac ### Don't leave the variable set. unset os diff --git a/inc/maiko/platform.h b/inc/maiko/platform.h index a69b21f..725db07 100644 --- a/inc/maiko/platform.h +++ b/inc/maiko/platform.h @@ -166,6 +166,12 @@ # define MAIKO_ARCH_DETECTED 1 #endif +#ifdef __HAIKU__ +# define MAIKO_OS_HAIKU 1 +# define MAIKO_OS_NAME "Haiku" +# define MAIKO_OS_UNIX_LIKE 1 +# define MAIKO_OS_DETECTED 1 +#endif /* Modern GNU C, Clang, Sun Studio provide __BYTE_ORDER__ * Older GNU C (ca. 4.0.1) provides __BIG_ENDIAN__/__LITTLE_ENDIAN__ */ diff --git a/src/inet.c b/src/inet.c index 0231d3a..ecdbab6 100644 --- a/src/inet.c +++ b/src/inet.c @@ -107,8 +107,14 @@ LispPTR subr_TCP_ops(int op, LispPTR nameConn, LispPTR proto, LispPTR length, Li addr_class = LispNumToCInt(nameConn); protocol = LispNumToCInt(proto); result = socket(addr_class, protocol, 0); +#ifndef MAIKO_OS_HAIKU fcntl(result, F_SETFL, fcntl(result, F_GETFL, 0) | O_ASYNC | O_NONBLOCK); +#else + fcntl(result, F_SETFL, fcntl(result, F_GETFL, 0) | O_NONBLOCK); +#endif +#ifdef F_SETOWN fcntl(result, F_SETOWN, getpid()); +#endif return (GetSmallp(result)); case TCPconnect: /* args: hostname or (fixp)address, socket# */ @@ -131,7 +137,9 @@ LispPTR subr_TCP_ops(int op, LispPTR nameConn, LispPTR proto, LispPTR length, Li return (NIL); } fcntl(result, F_SETFL, fcntl(result, F_GETFL, 0) | O_NONBLOCK); +#ifdef F_SETOWN fcntl(result, F_SETOWN, getpid()); +#endif return (GetSmallp(result)); @@ -197,13 +205,20 @@ LispPTR subr_TCP_ops(int op, LispPTR nameConn, LispPTR proto, LispPTR length, Li sigset_t signals; sigemptyset(&signals); +#ifndef MAIKO_OS_HAIKU sigaddset(&signals, SIGIO); - +#endif sigprocmask(SIG_BLOCK, &signals, NULL); +#ifndef MAIKO_OS_HAIKU fcntl(result, F_SETFL, fcntl(result, F_GETFL, 0) | O_ASYNC | O_NONBLOCK); - fcntl(result, F_SETOWN, getpid()); +#else + fcntl(result, F_SETFL, fcntl(result, F_GETFL, 0) | O_NONBLOCK); +#endif +#ifdef F_SETOWN + fcntl(result, F_SETOWN, getpid()); +#endif if (listen(result, 5) == -1) { perror("TCP Listen"); close(result); @@ -225,8 +240,9 @@ LispPTR subr_TCP_ops(int op, LispPTR nameConn, LispPTR proto, LispPTR length, Li return (NIL); } fcntl(result, F_SETFL, fcntl(result, F_GETFL, 0) | O_NONBLOCK); +#ifdef F_SETOWN fcntl(result, F_SETOWN, getpid()); - +#endif return (GetSmallp(result)); case INETpeername: /* socket#, buffer for name string */ @@ -259,9 +275,14 @@ LispPTR subr_TCP_ops(int op, LispPTR nameConn, LispPTR proto, LispPTR length, Li close(result); return (NIL); } +#ifndef MAIKO_OS_HAIKU fcntl(result, F_SETFL, fcntl(result, F_GETFL, 0) | O_ASYNC | O_NONBLOCK); +#else + fcntl(result, F_SETFL, fcntl(result, F_GETFL, 0) | O_NONBLOCK); +#endif +#ifdef F_SETOWN fcntl(result, F_SETOWN, getpid()); - +#endif FD_SET(result, &LispIOFds); /* so we get interrupts */ FD_SET(result, &LispReadFds); DBPRINT(("LispIOFds = %p\n", (void *)&LispIOFds)); diff --git a/src/initsout.c b/src/initsout.c index dc70e7a..ff4a678 100644 --- a/src/initsout.c +++ b/src/initsout.c @@ -140,9 +140,9 @@ void init_ifpage(unsigned sysout_size) { #endif /* BIGVM */ /* unfortunately, Lisp only looks at a 16 bit serial number */ -#ifndef DOS +#if !defined(DOS) && !defined(MAIKO_OS_HAIKU) InterfacePage->serialnumber = 0xffff & gethostid(); -#endif /* DOS */ +#endif /* DOS MAIKO_OS_HAIKU */ /* get user name and stuff into vmem; this is the VMEM buffer; This is a BCPL string -- it starts with a length count. C strings diff --git a/src/ldeboot.c b/src/ldeboot.c index 6e18927..88708e5 100644 --- a/src/ldeboot.c +++ b/src/ldeboot.c @@ -201,6 +201,7 @@ int main(int argc, char *argv[]) { } else { /* copy up to and including the final "/" in the path */ dirsepp = stpncpy(filetorunpath, argv[0], dirsepp + 1 - argv[0]); + /* dirsepp now points to the trailing null in the copy */ strncpy(dirsepp, filetorun, PATH_MAX - (dirsepp - filetorunpath)); argv[0] = filetorunpath; diff --git a/src/timer.c b/src/timer.c index ef91303..fed42f7 100644 --- a/src/timer.c +++ b/src/timer.c @@ -47,6 +47,10 @@ unsigned long tick_count = 0; /* approx 18 ticks per sec */ #include #endif /* DOS */ +#ifdef MAIKO_OS_HAIKU +#include +#endif + #if defined(USE_DLPI) #include extern int ether_fd; @@ -301,6 +305,8 @@ void subr_settime(LispPTR args[]) dosday.year = uxtime.tm_year; dosday.dayofweek = uxtime.tm_wday; _dos_setdate(&dosday); +#elif defined(MAIKO_OS_HAIKU) + (void)args[0]; #elif defined(MAIKO_OS_EMSCRIPTEN) (void)args[0]; #else @@ -556,17 +562,19 @@ static void int_io_service(int sig) /************************************************************************/ static void int_io_init(void) { -#ifndef DOS +#if !defined(DOS) || !defined(MAIKO_OS_HAIKU) struct sigaction io_action; io_action.sa_handler = int_io_service; sigemptyset(&io_action.sa_mask); io_action.sa_flags = 0; +#ifndef MAIKO_OS_HAIKU if (sigaction(SIGIO, &io_action, NULL) == -1) { perror("sigaction: SIGIO"); } else { DBPRINT(("I/O interrupts enabled\n")); } +#endif #if defined(USE_DLPI) DBPRINT(("INIT ETHER: Doing I_SETSIG.\n")); @@ -578,7 +586,7 @@ static void int_io_init(void) { return; } #endif /* USE_DLPI */ -#endif /* DOS */ +#endif /* DOS MAIKO_OS_HAIKU */ } /************************************************************************/ @@ -600,7 +608,9 @@ void int_block(void) { sigset_t signals; sigemptyset(&signals); sigaddset(&signals, SIGVTALRM); +#ifndef MAIKO_OS_HAIKU sigaddset(&signals, SIGIO); +#endif sigaddset(&signals, SIGALRM); sigaddset(&signals, SIGXFSZ); #ifdef FLTINT @@ -628,7 +638,9 @@ void int_unblock(void) { sigset_t signals; sigemptyset(&signals); sigaddset(&signals, SIGVTALRM); +#ifndef MAIKO_OS_HAIKU sigaddset(&signals, SIGIO); +#endif sigaddset(&signals, SIGALRM); sigaddset(&signals, SIGXFSZ); #ifdef FLTINT diff --git a/src/tty.c b/src/tty.c index f00643f..e628cfd 100644 --- a/src/tty.c +++ b/src/tty.c @@ -51,7 +51,11 @@ void tty_open(void) if (TTY_Fd < 0) { if ((TTY_Fd = open(TTY_Dev, O_RDWR)) >= 0) { tcgetattr(TTY_Fd, &options); +#ifndef MAIKO_OS_HAIKU options.c_iflag &= ~(IMAXBEL|IXOFF|INPCK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON|IGNPAR); +#else + options.c_iflag &= ~(IXOFF|INPCK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON|IGNPAR); +#endif options.c_iflag |= IGNBRK; options.c_oflag &= ~OPOST; options.c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL|ICANON|ISIG|IEXTEN|NOFLSH|TOSTOP); diff --git a/src/unixfork.c b/src/unixfork.c index 366495f..767f2a3 100644 --- a/src/unixfork.c +++ b/src/unixfork.c @@ -219,7 +219,9 @@ int fork_Unix(void) { /* interrupts need to be blocked here so subprocess won't see them */ sigemptyset(&signals); sigaddset(&signals, SIGVTALRM); +#ifndef MAIKO_OS_HAIKU sigaddset(&signals, SIGIO); +#endif sigaddset(&signals, SIGALRM); sigaddset(&signals, SIGXFSZ); sigaddset(&signals, SIGFPE); diff --git a/src/uraid.c b/src/uraid.c index df9ecab..3b311b8 100644 --- a/src/uraid.c +++ b/src/uraid.c @@ -864,7 +864,9 @@ int device_before_raid(void) { #ifdef XWINDOW /* So X events still get recognized. */ sigemptyset(&signals); +#ifndef MAIKO_OS_HAIKU sigaddset(&signals, SIGIO); +#endif sigprocmask(SIG_UNBLOCK, &signals, NULL); #endif diff --git a/src/uutils.c b/src/uutils.c index 77fe046..e011229 100644 --- a/src/uutils.c +++ b/src/uutils.c @@ -231,10 +231,13 @@ LispPTR unix_getparm(LispPTR *args) { struct passwd *pwd; if ((pwd = getpwuid(getuid())) == NULL) return NIL; envvalue = pwd->pw_gecos; - } else if (strcmp(envname, "HOSTID") == 0) { + } +#ifndef MAIKO_OS_HAIKU + else if (strcmp(envname, "HOSTID") == 0) { snprintf(result, sizeof(result), "%lx", gethostid()); envvalue = result; } +#endif /* MAIKO_OS_HAIKU */ #endif /* DOS */ else return NIL;