Skip to contentSkip to conversation

libdrm: Patch to compile on hurd.

PATCH In review Tobias Frost 3 participants 8 messages Apr 21, 2016 – Apr 24, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hallo,

attached is a patch that makes libdrm compile on hurd.

(Note: I intentionally said compile, as I have no way to see if it actually works there.)

The patch is created in a way to be neutral on all other archs; it is mostly about PATH_MAX, which does not exist on that arch.

Maybe you find the patch useful.

Thanks!

--

include/drm/drm.h +9 -0
@@ -42,10 +42,19 @@
 #include <asm/ioctl.h>
 typedef unsigned int drm_handle_t;
 
+#elif defined(__gnu_hurd__)
+#include <stdint.h>
+#include <mach/i386/ioccom.h>
+
 #else /* One of the BSDs */
 
 #include <sys/ioccom.h>
 #include <sys/types.h>
+
+#endif
+
+#if !defined(__linux__)
+
 typedef int8_t   __s8;
 typedef uint8_t  __u8;
 typedef int16_t  __s16;
xf86drm.h +4 -0
@@ -58,7 +58,11 @@
 
 #else /* One of the *BSDs */
 
+#if defined(__gnu_hurd__)
+#include <mach/i386/ioccom.h>
+#else
 #include <sys/ioccom.h>
+#endif
 #define DRM_IOCTL_NR(n)         ((n) & 0xff)
 #define DRM_IOC_VOID            IOC_VOID
 #define DRM_IOC_READ            IOC_OUT
xf86drm.c +24 -12
@@ -103,6 +103,16 @@
 
 #define memclear(s) memset(&s, 0, sizeof(s))
 
+/* for systems like hurd which does not have PATH_MAX.
+ Usage is only for string manipulation, so it is save to define it.
+ 1kB will be plenty space...*/
+#ifndef PATH_MAX
+#define MY_PATH_MAX (1024)
+#else
+#define MY_PATH_MAX PATH_MAX
+#endif
+
+
 static drmServerInfoPtr drm_server_info;
 
 void drmSetServerInfo(drmServerInfoPtr info)
@@ -2835,14 +2845,15 @@
 static int drmParseSubsystemType(int maj, int min)
 {
 #ifdef __linux__
-    char path[PATH_MAX + 1];
-    char link[PATH_MAX + 1] = "";
+
+    char path[MY_PATH_MAX + 1];
+    char link[MY_PATH_MAX + 1] = "";
     char *name;
 
-    snprintf(path, PATH_MAX, "/sys/dev/char/%d:%d/device/subsystem",
+    snprintf(path, MY_PATH_MAX, "/sys/dev/char/%d:%d/device/subsystem",
              maj, min);
 
-    if (readlink(path, link, PATH_MAX) < 0)
+    if (readlink(path, link, MY_PATH_MAX) < 0)
         return -errno;
 
     name = strrchr(link, '/');
@@ -2857,18 +2868,19 @@
 #warning "Missing implementation of drmParseSubsystemType"
     return -EINVAL;
 #endif
+
 }
 
 static int drmParsePciBusInfo(int maj, int min, drmPciBusInfoPtr info)
 {
 #ifdef __linux__
-    char path[PATH_MAX + 1];
+    char path[MY_PATH_MAX + 1];
     char data[128 + 1];
     char *str;
     int domain, bus, dev, func;
     int fd, ret;
 
-    snprintf(path, PATH_MAX, "/sys/dev/char/%d:%d/device/uevent", maj, min);
+    snprintf(path, MY_PATH_MAX, "/sys/dev/char/%d:%d/device/uevent", maj, min);
     fd = open(path, O_RDONLY);
     if (fd < 0)
         return -errno;
@@ -2949,11 +2961,11 @@
                                  drmPciDeviceInfoPtr device)
 {
 #ifdef __linux__
-    char path[PATH_MAX + 1];
+    char path[MY_PATH_MAX + 1];
     unsigned char config[64];
     int fd, ret;
 
-    snprintf(path, PATH_MAX, "/sys/class/drm/%s/device/config", d_name);
+    snprintf(path, MY_PATH_MAX, "/sys/class/drm/%s/device/config", d_name);
     fd = open(path, O_RDONLY);
     if (fd < 0)
         return -errno;
@@ -3082,7 +3094,7 @@
     DIR *sysdir;
     struct dirent *dent;
     struct stat sbuf;
-    char node[PATH_MAX + 1];
+    char node[MY_PATH_MAX + 1];
     int node_type, subsystem_type;
     int maj, min;
     int ret, i, node_count;
@@ -3118,7 +3130,7 @@
         if (node_type < 0)
             continue;
 
-        snprintf(node, PATH_MAX, "%s/%s", DRM_DIR_NAME, dent->d_name);
+        snprintf(node, MY_PATH_MAX, "%s/%s", DRM_DIR_NAME, dent->d_name);
         if (stat(node, &sbuf))
             continue;
 
@@ -3198,7 +3210,7 @@
     DIR *sysdir;
     struct dirent *dent;
     struct stat sbuf;
-    char node[PATH_MAX + 1];
+    char node[MY_PATH_MAX + 1];
     int node_type, subsystem_type;
     int maj, min;
     int ret, i, node_count, device_count;
@@ -3220,7 +3232,7 @@
         if (node_type < 0)
             continue;
 
-        snprintf(node, PATH_MAX, "%s/%s", DRM_DIR_NAME, dent->d_name);
+        snprintf(node, MY_PATH_MAX, "%s/%s", DRM_DIR_NAME, dent->d_name);
         if (stat(node, &sbuf))
             continue;
 

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#1 lore raw

Hi Tobias,

Quoted 4 lines · Tobias Frost

Hallo,

attached is a patch that makes libdrm compile on hurd.

Thanks for the patch.

Quoted 3 lines

(Note: I intentionally said compile, as I have no way to see if it actually works there.)

Step one is actually making it build and step two involves testing it ;-) I've CC'ed Gary Wong, a gnu developer who has sent patches about mesa in the past.

Quoted 5 lines

The patch is created in a way to be neutral on all other archs; it is mostly about PATH_MAX, which does not exist on that arch.

Maybe you find the patch useful.

Sure do, just a few suggestions.

Can you please split out the include/drm/* change to a separate patch and base it against the kernel UAPI headers.

On the PATH_MAX front, please drop the whitespace change, and define PATH_MAX at top level, rather than using MY_PATH_MAX throughout the code.

Please CC me on the updated patches and please send them via git send-email.

Thanks
Emil
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#2 lore raw

Hi Emil,

Am Donnerstag, den 21.04.2016, 13:33 +0100 schrieb Emil Velikov:

Quoted 19 lines

Hi Tobias,

Quoted 4 lines · Tobias Frost

Hallo,

attached is a patch that makes libdrm compile on hurd.

Thanks for the patch.

Quoted 3 lines

(Note: I intentionally said compile, as I have no way to see if it actually works there.)

Step one is actually making it build and step two involves testing it ;-) I've CC'ed Gary Wong, a gnu developer who has sent patches about mesa in the past.

Quoted 3 lines

The patch is created in a way to be neutral on all other archs; it is mostly about PATH_MAX, which does not exist on that arch.

Quoted 6 lines
Quoted 2 lines

Maybe you find the patch useful.

Sure do, just a few suggestions.

Can you please split out the include/drm/* change to a separate patch and base it against the kernel UAPI headers.

I might need more instructions about this.. I'm unsure which repository I should use as base...

Quoted 6 lines

On the PATH_MAX front, please drop the whitespace change, and define PATH_MAX at top level, rather than using MY_PATH_MAX throughout the code.

Please CC me on the updated patches and please send them via git send-email.

On the way...
(the include/drm/* stuff is against trunk of the git repo, in the hope that this is what you need -- see above)

Quoted 2 lines

Thanks
Emil

--
tobi
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#3 lore raw

PATCH 1/1 Workaround for systems that does not have PATH_MAX, like hurd.

In reply to Tobias Frost

It is safe to define it here, as the code is only using it for string manipulation and not for syscalls that might make different assumptions.

---
 xf86drm.c | 7 +++++++
 xf86drm.h | 4 ++++
 2 files changed, 11 insertions(+)
xf86drm.c +7 -0
index 45aa5fc..4dac7a4 100644
@@ -103,6 +103,13 @@
 
 #define memclear(s) memset(&s, 0, sizeof(s))
 
+/* for systems like hurd, which does not have PATH_MAX.
+ Usage is only for string manipulation, so it is save to define it.
+ 1kB will be plenty space.*/
+#ifndef PATH_MAX
+#define PATH_MAX (1024)
+#endif
+
 static drmServerInfoPtr drm_server_info;
 
 void drmSetServerInfo(drmServerInfoPtr info)
xf86drm.h +4 -0
index 481d882..1d45f02 100644
@@ -58,7 +58,11 @@ extern "C" {
 
 #else /* One of the *BSDs */
 
+#if defined(__GNU__)
+#include <mach/i386/ioccom.h>
+#else
 #include <sys/ioccom.h>
+#endif
 #define DRM_IOCTL_NR(n)         ((n) & 0xff)
 #define DRM_IOC_VOID            IOC_VOID
 #define DRM_IOC_READ            IOC_OUT
Signature · 6 lines
2.8.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#4 lore raw

Re: [PATCH] Workaround for systems that does not have PATH_MAX, like hurd.

Hi Tobias,

A couple of suggestions I missed the first time around.

Quoted 12 lines · Tobias Frost

It is safe to define it here, as the code is only using it for string manipulation and not for syscalls that might make different assumptions.

---
 xf86drm.c | 7 +++++++
 xf86drm.h | 4 ++++
 2 files changed, 11 insertions(+)
xf86drm.c +0 -0
index 45aa5fc..4dac7a4 100644

xf86drm.c line 110

Quoted 8 lines
xf86drm.c +5 -0
@@ -103,6 +103,13 @@
 
 #define memclear(s) memset(&s, 0, sizeof(s))
 
+/* for systems like hurd, which does not have PATH_MAX.
+ Usage is only for string manipulation, so it is save to define it.
+ 1kB will be plenty space.*/
+#ifndef PATH_MAX
+#define PATH_MAX (1024)

The brackets do not seem necessary.

Quoted 10 lines
xf86drm.c +2 -0
+#endif
+
 static drmServerInfoPtr drm_server_info;
 
 void drmSetServerInfo(drmServerInfoPtr info)
xf86drm.h +0 -0
index 481d882..1d45f02 100644

xf86drm.h extern "C" { · line 62

Quoted 5 lines
xf86drm.h +2 -0
@@ -58,7 +58,11 @@ extern "C" {
 
 #else /* One of the *BSDs */
 
+#if defined(__GNU__)
+#include <mach/i386/ioccom.h>

The porting guidelines [1] does mention that ioctl.h is available (although in the context of _IOT/_IOTS), so I'm wondering how come the IOC_* symbols are not in there. Is there any documentation that says that which header should be used ?

With the "i386" in the path, the above does look rather hacky. And looking at the current code - can you please move the "one of the BSDs" include at the top (before the extern C guard). The GNU one should also be there.

Thanks
Emil
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#6 lore raw

PATCH 1/1 On hurd other includes are required to compile.

As both BSD and Hurd needs also the typedefs, so making sure that they are become declared when not compiling for linux.

---
 include/drm/drm.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
include/drm/drm.h +5 -1
index b4ebaa9..e77146f 100644
@@ -42,10 +42,14 @@
 #include <asm/ioctl.h>
 typedef unsigned int drm_handle_t;
 
+#elif defined(__GNU__) /* this is hurd */
+#include <stdint.h>
+#include <mach/i386/ioccom.h>
 #else /* One of the BSDs */
-
 #include <sys/ioccom.h>
 #include <sys/types.h>
+#endif
+#if !defined(__linux__)
 typedef int8_t   __s8;
 typedef uint8_t  __u8;
 typedef int16_t  __s16;
Signature · 6 lines
2.8.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#7 lore raw

Re: [PATCH] On hurd other includes are required to compile.

Hi Tobias,

Quoted 13 lines · Tobias Frost

As both BSD and Hurd needs also the typedefs, so making sure that they are become declared when not compiling for linux.

---
 include/drm/drm.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
include/drm/drm.h +0 -0
index b4ebaa9..e77146f 100644
@@ -42,10 +42,14 @@
 #include <asm/ioctl.h>
 typedef unsigned int drm_handle_t;

include/drm/drm.h line 52

Quoted 10 lines
include/drm/drm.h +5 -1
 
+#elif defined(__GNU__) /* this is hurd */
+#include <stdint.h>
+#include <mach/i386/ioccom.h>
 #else /* One of the BSDs */
-
 #include <sys/ioccom.h>
 #include <sys/types.h>
+#endif
+#if !defined(__linux__)

The patch should be based against the linux kernel. Namely

https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/uapi/drm/drm.h

I would kindly ask that you familiarise yourself with the SubmittingPatches document [1] if you haven't already But before anything, can we hear please on the "using i386 in the include feels hacky" topic mentioned in the other patch.

Thanks
Emil

[1] https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/SubmittingPatches
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel