Add support for GNU/Hurd

This commit is contained in:
Svante Signell 2025-12-08 22:24:29 +01:00
parent b71953a199
commit 7dacbebee2
3 changed files with 41 additions and 16 deletions

View file

@ -41,6 +41,21 @@
#include <asm/ioctl.h>
typedef unsigned int drm_handle_t;
#elif defined(__GNU__)
#include <sys/types.h>
#include <sys/ioctl.h>
#include <mach/i386/ioccom.h>
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 <stdint.h>

View file

@ -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
}

View file

@ -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 <mach/port.h>
#include <hurd/ioctl.h>
#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 <sys/ioccom.h>