summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author Pino Toscano <toscano.pino@tiscali.it>2025-06-09 10:35:50 +0200
committer GitHub <noreply@github.com>2025-06-09 10:35:50 +0200
commitde1d5774922bddb158ffa18481e0f90a05852a29 (patch)
tree30ee271955e7a68addcfe278caa0cf304aae3b9d
parentd91d9eb7539cf31ac1c5019b524e8c0263162dd5 (diff)
Various GNU/Hurd fixes (#13792)
* bx: Small platform detection/usage improvements * Use BX_PLATFORM_POSIX where needed The semaphone implementation already uses BX_PLATFORM_POSIX to include <pthread.h> on all the POSIX platforms; do the same also in other places for consistency. This is done also for <sched.h>, which is a POSIX API, and sched_yield() from it is already guarded by BX_PLATFORM_POSIX. * Drop support for GNU libc older than 2.12 glibc 2.12 was released on 2010, and at this point any supported Linux distro has that version or way greather than that. From bkaradzic/bx@b59b7debd32260750c2af71f62585d9b438b3b96 * bx: fix <pthread/pthread.h> include on Hurd <pthread/pthread.h> does not exist, the standard <pthread.h> does exist so switch to it. * osd/modules/file: use dirent::d_type on any GNU libc platform This BSD extension is provided by GNU libc, so enable its usage with that C library. * osd/modules/file: use <pty.h> on any GNU libc platform openpty() is implemented by GNU libc for all the OSes, so include <pty.h> when using that C library. * osd/modules/file: cast dirent::d_name to const char* before using it According to POSIX [1], the type of dirent::d_name is loosely defined as "char d_name[]", as array with an undefined size. In particular, few ways are seen in the wild: (a) "char d_name[size]", i.e. as proper array with a full size (b) "char d_name[1]"/"char d_name[0]", i.e. as C flexible arrays Regardless of its type, dirent::d_name is used as if it was a classic const char *, i.e. as pointer to a null-terminated string. util::string_format() uses C++ templates to collect all the arguments, and thus it will use the actual type of dirent::d_name. In case of (a) there is no issue, however for (b) the result is that only the first character is used. To ensure that dirent::d_name is fully used, explicitly cast it to const char * before passing it to util::string_format(), so the whole string is used. [1] https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/dirent.h.html
-rw-r--r--3rdparty/bx/src/mutex.cpp10
-rw-r--r--3rdparty/bx/src/os.cpp14
-rw-r--r--3rdparty/bx/src/thread.cpp15
-rw-r--r--src/osd/modules/file/posixdir.cpp4
-rw-r--r--src/osd/modules/file/posixptty.cpp2
5 files changed, 8 insertions, 37 deletions
diff --git a/3rdparty/bx/src/mutex.cpp b/3rdparty/bx/src/mutex.cpp
index 0ef8597a8aa..9e5845935b1 100644
--- a/3rdparty/bx/src/mutex.cpp
+++ b/3rdparty/bx/src/mutex.cpp
@@ -10,15 +10,7 @@
#if BX_CRT_NONE
# include <bx/cpu.h>
# include "crt0.h"
-#elif BX_PLATFORM_ANDROID \
- || BX_PLATFORM_BSD \
- || BX_PLATFORM_HAIKU \
- || BX_PLATFORM_LINUX \
- || BX_PLATFORM_IOS \
- || BX_PLATFORM_OSX \
- || BX_PLATFORM_PS4 \
- || BX_PLATFORM_RPI \
- || BX_PLATFORM_NX
+#elif BX_PLATFORM_POSIX
# include <pthread.h>
#elif BX_PLATFORM_WINDOWS \
|| BX_PLATFORM_WINRT \
diff --git a/3rdparty/bx/src/os.cpp b/3rdparty/bx/src/os.cpp
index 99394579b72..917b02e8c5a 100644
--- a/3rdparty/bx/src/os.cpp
+++ b/3rdparty/bx/src/os.cpp
@@ -19,17 +19,7 @@
# endif // WIN32_LEAN_AND_MEAN
# include <windows.h>
# include <psapi.h>
-#elif BX_PLATFORM_ANDROID \
- || BX_PLATFORM_BSD \
- || BX_PLATFORM_EMSCRIPTEN \
- || BX_PLATFORM_HAIKU \
- || BX_PLATFORM_HURD \
- || BX_PLATFORM_IOS \
- || BX_PLATFORM_LINUX \
- || BX_PLATFORM_NX \
- || BX_PLATFORM_OSX \
- || BX_PLATFORM_PS4 \
- || BX_PLATFORM_RPI
+#elif BX_PLATFORM_POSIX
# include <sched.h> // sched_yield
# if BX_PLATFORM_BSD \
|| BX_PLATFORM_HAIKU \
@@ -58,7 +48,7 @@
# include <mach/mach.h> // mach_task_basic_info
# elif BX_PLATFORM_HURD
# include <stdio.h> // fopen
-# include <pthread/pthread.h> // pthread_self
+# include <pthread.h> // pthread_self
# elif BX_PLATFORM_ANDROID
# include "debug.h" // getTid is not implemented...
# endif // BX_PLATFORM_ANDROID
diff --git a/3rdparty/bx/src/thread.cpp b/3rdparty/bx/src/thread.cpp
index f5e5f81bc21..162d4cafaf0 100644
--- a/3rdparty/bx/src/thread.cpp
+++ b/3rdparty/bx/src/thread.cpp
@@ -14,22 +14,11 @@
#if BX_CRT_NONE
# include "crt0.h"
-#elif BX_PLATFORM_ANDROID \
- || BX_PLATFORM_BSD \
- || BX_PLATFORM_HAIKU \
- || BX_PLATFORM_LINUX \
- || BX_PLATFORM_IOS \
- || BX_PLATFORM_OSX \
- || BX_PLATFORM_PS4 \
- || BX_PLATFORM_RPI \
- || BX_PLATFORM_NX
+#elif BX_PLATFORM_POSIX
# include <pthread.h>
# if BX_PLATFORM_BSD
# include <pthread_np.h>
# endif // BX_PLATFORM_BSD
-# if BX_PLATFORM_LINUX && (BX_CRT_GLIBC < 21200)
-# include <sys/prctl.h>
-# endif // BX_PLATFORM_
#elif BX_PLATFORM_WINDOWS \
|| BX_PLATFORM_WINRT \
|| BX_PLATFORM_XBOXONE \
@@ -250,7 +239,7 @@ namespace bx
#elif BX_PLATFORM_OSX \
|| BX_PLATFORM_IOS
pthread_setname_np(_name);
-#elif (BX_CRT_GLIBC >= 21200) && ! BX_PLATFORM_HURD
+#elif BX_CRT_GLIBC && ! BX_PLATFORM_HURD
pthread_setname_np(ti->m_handle, _name);
#elif BX_PLATFORM_LINUX
prctl(PR_SET_NAME,_name, 0, 0, 0);
diff --git a/src/osd/modules/file/posixdir.cpp b/src/osd/modules/file/posixdir.cpp
index 4c79c32a7d0..d4d78b342aa 100644
--- a/src/osd/modules/file/posixdir.cpp
+++ b/src/osd/modules/file/posixdir.cpp
@@ -81,7 +81,7 @@ using sdl_stat = struct stat64;
#define sdl_stat_fn stat64
#endif
-#if (defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__) || defined(__DragonFly__))
+#if (defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__) || defined(__DragonFly__) || defined(__GLIBC__))
#define HAS_DT_XXX 1
#else
#define HAS_DT_XXX 0
@@ -157,7 +157,7 @@ const osd::directory::entry *posix_directory::read()
m_entry.name = m_data->d_name;
sdl_stat st;
- bool stat_err(0 > sdl_stat_fn(util::string_format("%s%c%s", m_path, PATHSEPCH, m_data->d_name).c_str(), &st));
+ bool stat_err(0 > sdl_stat_fn(util::string_format("%s%c%s", m_path, PATHSEPCH, static_cast<const char *>(m_data->d_name)).c_str(), &st));
#if HAS_DT_XXX
switch (m_data->d_type)
diff --git a/src/osd/modules/file/posixptty.cpp b/src/osd/modules/file/posixptty.cpp
index 57ff069a2ce..56e65ec09eb 100644
--- a/src/osd/modules/file/posixptty.cpp
+++ b/src/osd/modules/file/posixptty.cpp
@@ -25,7 +25,7 @@
#elif defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
#include <termios.h>
#include <util.h>
-#elif defined(__linux__) || defined(__EMSCRIPTEN__)
+#elif defined(__linux__) || defined(__EMSCRIPTEN__) || defined(__GLIBC__)
#include <pty.h>
#elif defined(__HAIKU__)
#include <bsd/pty.h>