[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#909436: libdrm: FTBFS on hurd-i386



Source: libdrm
Version: 2.4.94-1
Severity: important
Tags: ftbfs, patch
User: debian-hurd@lists.debian.org
Usertags: hurd

Hello,

Currently libdrm FTBFS on GNU/Hurd due to a missing case in
include/drm/drm.h. Attached is a patch, hurd-port.diff, to fix this and
fixes for PATH_MAX issues in in xf86dri.c and include+defines for GNU
in xf86dri.h.

Additionally the patches debian_rules.diff and debian_control.diff adds
Hurd to the architecture list.

Thanks!
--- a/debian/control	2018-09-16 23:01:56.000000000 +0200
+++ b/debian/control	2018-09-16 23:03:11.000000000 +0200
@@ -13,7 +13,7 @@
  libudev-dev [linux-any],
  libpciaccess-dev,
  valgrind [amd64 armhf i386 mips mipsel powerpc s390x],
- libbsd-dev [kfreebsd-any],
+ libbsd-dev [kfreebsd-any hurd-any],
 Standards-Version: 4.1.4
 Section: libs
 Vcs-Git: https://salsa.debian.org/xorg-team/lib/libdrm
@@ -22,10 +22,10 @@
 
 Package: libdrm-dev
 Section: libdevel
-Architecture: linux-any kfreebsd-any
+Architecture: linux-any kfreebsd-any hurd-any
 Depends:
  libdrm2 (= ${binary:Version}),
- libdrm-intel1 (= ${binary:Version}) [amd64 i386 kfreebsd-amd64 kfreebsd-i386 x32],
+ libdrm-intel1 (= ${binary:Version}) [amd64 i386 kfreebsd-amd64 kfreebsd-i386 hurd-i386 x32],
  libdrm-radeon1 (= ${binary:Version}),
  libdrm-nouveau2 (= ${binary:Version}) [linux-any],
  libdrm-amdgpu1 (= ${binary:Version}),
@@ -46,7 +46,7 @@
  This package provides the development environment for libdrm.
 
 Package: libdrm2
-Architecture: linux-any kfreebsd-any
+Architecture: linux-any kfreebsd-any hurd-any
 Depends:
  libdrm-common (>= ${source:Version}),
  ${shlibs:Depends},
@@ -80,7 +80,7 @@
 Package: libdrm2-udeb
 Package-Type: udeb
 Section: debian-installer
-Architecture: linux-any kfreebsd-any
+Architecture: linux-any kfreebsd-any hurd-any
 Depends:
  ${shlibs:Depends},
  ${misc:Depends},
@@ -88,7 +88,7 @@
  This is a udeb, or a microdeb, for the debian-installer.
 
 Package: libdrm-intel1
-Architecture: amd64 i386 kfreebsd-amd64 kfreebsd-i386 x32
+Architecture: amd64 i386 kfreebsd-amd64 kfreebsd-i386 hurd-i386 x32
 Depends:
  ${shlibs:Depends},
  ${misc:Depends},
@@ -115,7 +115,7 @@
  OpenGL drivers.
 
 Package: libdrm-radeon1
-Architecture: linux-any kfreebsd-any
+Architecture: linux-any kfreebsd-any hurd-any
 Depends:
  ${shlibs:Depends},
  ${misc:Depends},
@@ -185,7 +185,7 @@
  OpenGL drivers.
 
 Package: libdrm-amdgpu1
-Architecture: linux-any kfreebsd-any
+Architecture: linux-any kfreebsd-any hurd-any
 Depends:
  ${shlibs:Depends},
  ${misc:Depends},
--- a/debian/rules	2018-08-31 15:01:29.000000000 +0200
+++ b/debian/rules	2018-09-01 00:16:08.000000000 +0200
@@ -33,7 +33,7 @@
 
 # Intel is only on x86:
 ifneq (,$(filter amd64 i386,$(DEB_HOST_ARCH_CPU)))
-ifneq (,$(filter linux kfreebsd,$(DEB_HOST_ARCH_OS)))
+ifneq (,$(filter linux kfreebsd hurd,$(DEB_HOST_ARCH_OS)))
 	INTEL = yes
 endif
 endif
Index: libdrm-2.4.94/include/drm/drm.h
===================================================================
--- libdrm-2.4.94.orig/include/drm/drm.h
+++ libdrm-2.4.94/include/drm/drm.h
@@ -57,6 +57,22 @@ typedef __uint64_t __u64;
 typedef size_t   __kernel_size_t;
 typedef unsigned long 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 <sys/ioccom.h>
Index: libdrm-2.4.94/xf86drm.h
===================================================================
--- libdrm-2.4.94.orig/xf86drm.h
+++ libdrm-2.4.94/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 <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>
Index: libdrm-2.4.94/xf86drm.c
===================================================================
--- libdrm-2.4.94.orig/xf86drm.c
+++ libdrm-2.4.94/xf86drm.c
@@ -2860,7 +2860,8 @@ static char *drmGetMinorNameForFD(int fd
     return NULL;
 #else
     struct stat sbuf;
-    char buf[PATH_MAX + 1];
+    char *buf = NULL;
+    int len = 0;
     const char *dev_name;
     unsigned int maj, min;
     int n, base;
@@ -2892,11 +2893,18 @@ static char *drmGetMinorNameForFD(int fd
     if (base < 0)
         return NULL;
 
-    n = snprintf(buf, sizeof(buf), dev_name, DRM_DIR_NAME, min - base);
-    if (n == -1 || n >= sizeof(buf))
+    len = snprintf(NULL, 0, dev_name, DRM_DIR_NAME, min - base);
+    if (len < 0)
         return NULL;
+    len++;
+    buf = malloc(len);
+    n = snprintf(buf, len, dev_name, DRM_DIR_NAME, min - base);
+    if (n == -1 || n >= len) {
+        free(buf);
+        return NULL;
+    }
 
-    return strdup(buf);
+    return buf;
 #endif
 }
 
@@ -3001,16 +3009,29 @@ static int drmParseSubsystemType(int maj
 static char *
 get_real_pci_path(int maj, int min, char *real_path)
 {
-    char path[PATH_MAX + 1], *term;
+    char *path = NULL, *term;
+    int len = 0, n;
 
-    snprintf(path, sizeof(path), "/sys/dev/char/%d:%d/device", maj, min);
-    if (!realpath(path, real_path))
+    len = snprintf(NULL, 0, "/sys/dev/char/%d:%d/device", maj, min);
+    if (len < 0)
+        return NULL;
+    len++;
+    path = malloc(len);
+    n = snprintf(path, len, "/sys/dev/char/%d:%d/device", maj, min);
+    if (n == -1 || n >= len) {
+        free(path);
         return NULL;
+    }
+    if (!realpath(path, real_path)) {
+        free(path);
+        return NULL;
+    }
 
     term = strrchr(real_path, '/');
     if (term && strncmp(term, "/virtio", 7) == 0)
         *term = 0;
 
+    free(path);
     return real_path;
 }
 
@@ -3710,17 +3731,30 @@ process_device(drmDevicePtr *device, con
                bool fetch_deviceinfo, uint32_t flags)
 {
     struct stat sbuf;
-    char node[PATH_MAX + 1];
+    char *node = NULL;
     int node_type, subsystem_type;
+    int len = 0, n, ret = 0;
     unsigned int maj, min;
 
     node_type = drmGetNodeType(d_name);
     if (node_type < 0)
         return -1;
 
-    snprintf(node, PATH_MAX, "%s/%s", DRM_DIR_NAME, d_name);
-    if (stat(node, &sbuf))
+    len = snprintf(NULL, 0, "%s/%s", DRM_DIR_NAME, d_name);
+    if (len < 0)
+      return -1;
+    len++;
+    node = malloc(len);
+    n = snprintf(node, len, "%s/%s", DRM_DIR_NAME, d_name);
+    if (n == -1 || n >= len) {
+        free(node);
         return -1;
+    }
+
+    if (stat(node, &sbuf)) {
+        free(node);
+        return -1;
+    }
 
     maj = major(sbuf.st_rdev);
     min = minor(sbuf.st_rdev);
@@ -3735,18 +3769,27 @@ process_device(drmDevicePtr *device, con
     switch (subsystem_type) {
     case DRM_BUS_PCI:
     case DRM_BUS_VIRTIO:
-        return drmProcessPciDevice(device, node, node_type, maj, min,
+        ret = drmProcessPciDevice(device, node, node_type, maj, min,
                                    fetch_deviceinfo, flags);
+	free(node);
+	return ret;
     case DRM_BUS_USB:
-        return drmProcessUsbDevice(device, node, node_type, maj, min,
+        ret = drmProcessUsbDevice(device, node, node_type, maj, min,
                                    fetch_deviceinfo, flags);
+	free(node);
+	return ret;
     case DRM_BUS_PLATFORM:
-        return drmProcessPlatformDevice(device, node, node_type, maj, min,
+        ret = drmProcessPlatformDevice(device, node, node_type, maj, min,
                                         fetch_deviceinfo, flags);
+	free(node);
+	return ret;
     case DRM_BUS_HOST1X:
-        return drmProcessHost1xDevice(device, node, node_type, maj, min,
+        ret = drmProcessHost1xDevice(device, node, node_type, maj, min,
                                       fetch_deviceinfo, flags);
+	free(node);
+	return ret;
     default:
+        free(node);
         return -1;
    }
 }
@@ -4080,10 +4123,10 @@ char *drmGetDeviceNameFromFd2(int fd)
     return strdup(path);
 #else
     struct stat      sbuf;
-    char             node[PATH_MAX + 1];
+    char            *node = NULL;
     const char      *dev_name;
     int              node_type;
-    int              maj, min, n, base;
+    int              maj, min, n, base, len = 0;
 
     if (fstat(fd, &sbuf))
         return NULL;
@@ -4116,11 +4159,16 @@ char *drmGetDeviceNameFromFd2(int fd)
     if (base < 0)
         return NULL;
 
-    n = snprintf(node, PATH_MAX, dev_name, DRM_DIR_NAME, min - base);
-    if (n == -1 || n >= PATH_MAX)
+    len = snprintf(NULL, 0, dev_name, DRM_DIR_NAME, min - base);
+    if (len < 0)
+      return NULL;
+    len++;
+    node = malloc(len);
+    n = snprintf(node, len, dev_name, DRM_DIR_NAME, min - base);
+    if (n == -1 || n >= len)
       return NULL;
 
-    return strdup(node);
+    return node;
 #endif
 }
 

Reply to: