From 7dacbebee2562397ba34427e62413cbb4d2013ba Mon Sep 17 00:00:00 2001 From: Svante Signell Date: Mon, 8 Dec 2025 22:24:29 +0100 Subject: [PATCH] Add support for GNU/Hurd --- include/drm/drm.h | 15 +++++++++++++++ xf86drm.c | 32 ++++++++++++++++---------------- xf86drm.h | 10 ++++++++++ 3 files changed, 41 insertions(+), 16 deletions(-) diff --git a/include/drm/drm.h b/include/drm/drm.h index 3ddff73d..456af3a5 100644 --- a/include/drm/drm.h +++ b/include/drm/drm.h @@ -41,6 +41,21 @@ #include typedef unsigned int drm_handle_t; +#elif defined(__GNU__) +#include +#include +#include +typedef __int8_t __s8; +typedef __uint8_t __u8; +typedef __int16_t __s16; +typedef __uint16_t __u16; +typedef __int32_t __s32; +typedef __uint32_t __u32; +typedef __int64_t __s64; +typedef __uint64_t __u64; +typedef size_t __kernel_size_t; +typedef unsigned int drm_handle_t; + #else /* One of the BSDs */ #include diff --git a/xf86drm.c b/xf86drm.c index d4bfec8a..a60aca65 100644 --- a/xf86drm.c +++ b/xf86drm.c @@ -101,7 +101,7 @@ #define DRM_MAJOR 226 /* Linux */ #endif -#if defined(__OpenBSD__) || defined(__DragonFly__) +#if defined(__OpenBSD__) || defined(__DragonFly__) || defined(__GNU__) struct drm_pciinfo { uint16_t domain; uint8_t bus; @@ -3495,7 +3495,7 @@ static char *drmGetMinorNameForFD(int fd, int type) return strdup(name); #else struct stat sbuf; - char buf[PATH_MAX + 1]; + char *buf = NULL; const char *dev_name = drmGetDeviceName(type); unsigned int maj, min; int n; @@ -3512,11 +3512,12 @@ static char *drmGetMinorNameForFD(int fd, int type) if (!dev_name) return NULL; - n = snprintf(buf, sizeof(buf), dev_name, DRM_DIR_NAME, min); - if (n == -1 || n >= sizeof(buf)) + n = asprintf(&buf, dev_name, DRM_DIR_NAME, min); + if (n < 0) return NULL; - return strdup(buf); + return buf; + #endif } @@ -3636,7 +3637,7 @@ static int drmParseSubsystemType(int maj, int min) return DRM_BUS_VIRTIO; } return subsystem_type; -#elif defined(__OpenBSD__) || defined(__DragonFly__) || defined(__FreeBSD__) +#elif defined(__OpenBSD__) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__GNU__) return DRM_BUS_PCI; #else #warning "Missing implementation of drmParseSubsystemType" @@ -3744,7 +3745,7 @@ static int drmParsePciBusInfo(int maj, int min, drmPciBusInfoPtr info) info->func = func; return 0; -#elif defined(__OpenBSD__) || defined(__DragonFly__) +#elif defined(__OpenBSD__) || defined(__DragonFly__) || defined(__GNU__) struct drm_pciinfo pinfo; int fd, type; @@ -3915,7 +3916,7 @@ static int drmParsePciDeviceInfo(int maj, int min, return parse_config_sysfs_file(maj, min, device); return 0; -#elif defined(__OpenBSD__) || defined(__DragonFly__) +#elif defined(__OpenBSD__) || defined(__DragonFly__) || defined(__GNU__) struct drm_pciinfo pinfo; int fd, type; @@ -4524,7 +4525,7 @@ process_device(drmDevicePtr *device, const char *d_name, bool fetch_deviceinfo, uint32_t flags) { struct stat sbuf; - char node[PATH_MAX + 1]; + char *node = NULL; int node_type, subsystem_type, written; unsigned int maj, min; const int max_node_length = ALIGN(drmGetMaxNodeName(), sizeof(void *)); @@ -4532,8 +4533,7 @@ process_device(drmDevicePtr *device, const char *d_name, node_type = drmGetNodeType(d_name); if (node_type < 0) return -1; - - written = snprintf(node, PATH_MAX, "%s/%s", DRM_DIR_NAME, d_name); + written = asprintf(&node, "%s/%s", DRM_DIR_NAME, d_name); if (written < 0) return -1; @@ -4940,7 +4940,7 @@ drm_public char *drmGetDeviceNameFromFd2(int fd) return drmGetDeviceNameFromFd(fd); #else struct stat sbuf; - char node[PATH_MAX + 1]; + char *node = NULL; const char *dev_name; int node_type; int maj, min, n; @@ -4962,11 +4962,11 @@ drm_public char *drmGetDeviceNameFromFd2(int fd) if (!dev_name) return NULL; - n = snprintf(node, PATH_MAX, dev_name, DRM_DIR_NAME, min); - if (n == -1 || n >= PATH_MAX) - return NULL; + n = asprintf(&node, dev_name, DRM_DIR_NAME, min); + if (n < 0) + return NULL; - return strdup(node); + return node; #endif } diff --git a/xf86drm.h b/xf86drm.h index b45337a4..59ef2c5c 100644 --- a/xf86drm.h +++ b/xf86drm.h @@ -56,6 +56,16 @@ extern "C" { #define DRM_IOC_READWRITE _IOC_READ|_IOC_WRITE #define DRM_IOC(dir, group, nr, size) _IOC(dir, group, nr, size) +#elif defined(__GNU__) +#include +#include +#define DRM_IOCTL_NR(n) ((n) & 0xff) +#define DRM_IOC_VOID IOC_VOID +#define DRM_IOC_READ IOC_OUT +#define DRM_IOC_WRITE IOC_IN +#define DRM_IOC_READWRITE IOC_INOUT +#define DRM_IOC(dir, group, nr, size) _IOC(dir, group, nr, size) + #else /* One of the *BSDs */ #include