Explorar el Código

mq: add x32-specific implementations to work around mismatched kernel ABI

the kernel mq_attr structure has 8 64-bit longs instead of 8 32-bit
longs.

it's not clear that this is the nicest way to implement the fix, but
the concept (translation) is right, and the details can be changed
later if desired.
Rich Felker hace 2 meses
padre
commit
d36e5bf83b
Se han modificado 2 ficheros con 36 adiciones y 0 borrados
  1. 22 0
      src/mq/x32/mq_open.c
  2. 14 0
      src/mq/x32/mq_setattr.c

+ 22 - 0
src/mq/x32/mq_open.c

@@ -0,0 +1,22 @@
+#include <mqueue.h>
+#include <fcntl.h>
+#include <stdarg.h>
+#include "syscall.h"
+
+mqd_t mq_open(const char *name, int flags, ...)
+{
+	mode_t mode = 0;
+	struct mq_attr *attr = 0;
+	long long attrbuf[8];
+	if (*name == '/') name++;
+	if (flags & O_CREAT) {
+		va_list ap;
+		va_start(ap, flags);
+		mode = va_arg(ap, mode_t);
+		attr = va_arg(ap, struct mq_attr *);
+		if (attr) for (int i=0; i<8; i++)
+			attrbuf[i] = *(long *)((char *)attr + i*sizeof(long));
+		va_end(ap);
+	}
+	return syscall(SYS_mq_open, name, flags, mode, attr?attrbuf:0);
+}

+ 14 - 0
src/mq/x32/mq_setattr.c

@@ -0,0 +1,14 @@
+#include <mqueue.h>
+#include "syscall.h"
+
+int mq_setattr(mqd_t mqd, const struct mq_attr *restrict new, struct mq_attr *restrict old)
+{
+	long long attr[8];
+	if (new) for (int i=0; i<8; i++)
+		attr[i] = *(long *)((char *)new + i*sizeof(long));
+	int ret = __syscall(SYS_mq_getsetattr, mqd, new?attr:0, old?attr:0);
+	if (ret < 0) return __syscall_ret(ret);
+	if (old) for (int i=0; i<8; i++)
+		*(long *)((char *)old + i*sizeof(long)) = attr[i];
+	return 0;
+}