Add GNU/Hurd support

This commit is contained in:
Samuel Thibault 2023-09-24 16:17:12 +02:00 committed by Wim Taymans
parent f9559d2e83
commit 8b807ded35
8 changed files with 21 additions and 10 deletions

View file

@ -11,10 +11,11 @@
#define ARRAY_SIZE 63 #define ARRAY_SIZE 63
#define MAX_VALUE 0x10000 #define MAX_VALUE 0x10000
#if defined(__FreeBSD__) || defined(__MidnightBSD__) #if defined(__FreeBSD__) || defined(__MidnightBSD__) || defined (__GNU__)
#include <sys/param.h> #include <sys/param.h>
#if (__FreeBSD_version >= 1400000 && __FreeBSD_version < 1400043) \ #if (__FreeBSD_version >= 1400000 && __FreeBSD_version < 1400043) \
|| (__FreeBSD_version < 1300523) || defined(__MidnightBSD__) || (__FreeBSD_version < 1300523) || defined(__MidnightBSD__) \
|| defined (__GNU__)
static int sched_getcpu(void) { return -1; }; static int sched_getcpu(void) { return -1; };
#endif #endif
#endif #endif

View file

@ -143,7 +143,7 @@ static int get_exe_name(int pid, char *buf, size_t buf_size)
* (in the current namespace). * (in the current namespace).
*/ */
#if defined(__linux__) #if defined(__linux__) || defined(__GNU__)
spa_scnprintf(path, sizeof(path), "/proc/%u/exe", pid); spa_scnprintf(path, sizeof(path), "/proc/%u/exe", pid);
#elif defined(__FreeBSD__) || defined(__MidnightBSD__) #elif defined(__FreeBSD__) || defined(__MidnightBSD__)
spa_scnprintf(path, sizeof(path), "/proc/%u/file", pid); spa_scnprintf(path, sizeof(path), "/proc/%u/file", pid);

View file

@ -35,6 +35,9 @@
#if defined(__FreeBSD__) || defined(__MidnightBSD__) #if defined(__FreeBSD__) || defined(__MidnightBSD__)
#include <sys/thr.h> #include <sys/thr.h>
#endif #endif
#if defined(__GNU__)
#include <mach.h>
#endif
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include <pthread.h> #include <pthread.h>
@ -221,6 +224,9 @@ static pid_t _gettid(void)
long pid; long pid;
thr_self(&pid); thr_self(&pid);
return (pid_t)pid; return (pid_t)pid;
#elif defined(__GNU__)
mach_port_t thread = mach_thread_self();
return (pid_t)thread;
#else #else
#error "No gettid impl" #error "No gettid impl"
#endif #endif

View file

@ -18,7 +18,7 @@
#ifdef HAVE_PWD_H #ifdef HAVE_PWD_H
#include <pwd.h> #include <pwd.h>
#endif #endif
#if defined(__FreeBSD__) || defined(__MidnightBSD__) #if defined(__FreeBSD__) || defined(__MidnightBSD__) || defined(__GNU__)
#ifndef O_PATH #ifndef O_PATH
#define O_PATH 0 #define O_PATH 0
#endif #endif

View file

@ -25,7 +25,8 @@
PW_LOG_TOPIC_EXTERN(log_mem); PW_LOG_TOPIC_EXTERN(log_mem);
#define PW_LOG_TOPIC_DEFAULT log_mem #define PW_LOG_TOPIC_DEFAULT log_mem
#if !defined(__FreeBSD__) && !defined(__MidnightBSD__) && !defined(HAVE_MEMFD_CREATE) #if !defined(__FreeBSD__) && !defined(__MidnightBSD__) && !defined(__GNU__) \
&& !defined(HAVE_MEMFD_CREATE)
/* /*
* No glibc wrappers exist for memfd_create(2), so provide our own. * No glibc wrappers exist for memfd_create(2), so provide our own.
* *
@ -42,7 +43,7 @@ static inline int memfd_create(const char *name, unsigned int flags)
#define HAVE_MEMFD_CREATE 1 #define HAVE_MEMFD_CREATE 1
#endif #endif
#if defined(__FreeBSD__) || defined(__MidnightBSD__) #if defined(__FreeBSD__) || defined(__MidnightBSD__) || defined(__GNU__)
#define MAP_LOCKED 0 #define MAP_LOCKED 0
#endif #endif

View file

@ -7,7 +7,7 @@
#include <unistd.h> #include <unistd.h>
#include <limits.h> #include <limits.h>
#include <stdio.h> #include <stdio.h>
#if !defined(__FreeBSD__) && !defined(__MidnightBSD__) #if !defined(__FreeBSD__) && !defined(__MidnightBSD__) && !defined(__GNU__)
#include <sys/prctl.h> #include <sys/prctl.h>
#endif #endif
#include <pwd.h> #include <pwd.h>
@ -720,7 +720,7 @@ static void init_prgname(void)
static char name[PATH_MAX]; static char name[PATH_MAX];
spa_memzero(name, sizeof(name)); spa_memzero(name, sizeof(name));
#if defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__MidnightBSD_kernel__) #if defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__MidnightBSD_kernel__) || defined(__GNU__)
{ {
if (readlink("/proc/self/exe", name, sizeof(name)-1) > 0) { if (readlink("/proc/self/exe", name, sizeof(name)-1) > 0) {
prgname = strrchr(name, '/') + 1; prgname = strrchr(name, '/') + 1;
@ -738,7 +738,7 @@ static void init_prgname(void)
} }
} }
#endif #endif
#if !defined(__FreeBSD__) && !defined(__MidnightBSD__) #if !defined(__FreeBSD__) && !defined(__MidnightBSD__) && !defined(__GNU__)
{ {
if (prctl(PR_GET_NAME, (unsigned long) name, 0, 0, 0) == 0) { if (prctl(PR_GET_NAME, (unsigned long) name, 0, 0, 0) == 0) {
prgname = name; prgname = name;

View file

@ -22,7 +22,7 @@ extern "C" {
#include <spa/utils/result.h> #include <spa/utils/result.h>
#include <spa/utils/type-info.h> #include <spa/utils/type-info.h>
#if defined(__FreeBSD__) || defined(__MidnightBSD__) #if defined(__FreeBSD__) || defined(__MidnightBSD__) || defined(__GNU__)
struct ucred { struct ucred {
}; };
#endif #endif

View file

@ -53,6 +53,9 @@ int pthread_setname_np(pthread_t thread, const char *name)
} }
#endif #endif
#endif #endif
#if defined(__GNU__)
int pthread_setname_np(pthread_t thread, const char *name) { return 0; }
#endif
static struct spa_thread *impl_create(void *object, static struct spa_thread *impl_create(void *object,
const struct spa_dict *props, const struct spa_dict *props,