diff mbox series

[2/5] include: Add declaration of struct ipc64_perm

Message ID 5a10d33509ac73c26b233ab72c579f44386d0a55.1590057824.git.viresh.kumar@linaro.org
State Superseded
Headers show
Series syscalls: Add tests to verify the _time_high fields | expand

Commit Message

Viresh Kumar May 21, 2020, 10:47 a.m. UTC
This adds declaration of struct ipc64_perm, which will be used by
following patches.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 configure.ac     |  1 +
 include/ipcbuf.h | 45 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+)
 create mode 100644 include/ipcbuf.h

Comments

Arnd Bergmann May 21, 2020, 1:11 p.m. UTC | #1
On Thu, May 21, 2020 at 12:47 PM Viresh Kumar <viresh.kumar@linaro.org> wrote:
>
> This adds declaration of struct ipc64_perm, which will be used by
> following patches.
>
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>

Like the other structures, there are multiple definitions in the kernel:

$ git grep ^struct.ipc64_perm
arch/parisc/include/uapi/asm/ipcbuf.h:struct ipc64_perm
arch/powerpc/include/uapi/asm/ipcbuf.h:struct ipc64_perm
arch/s390/include/uapi/asm/ipcbuf.h:struct ipc64_perm
arch/sparc/include/uapi/asm/ipcbuf.h:struct ipc64_perm
arch/xtensa/include/uapi/asm/ipcbuf.h:struct ipc64_perm
include/uapi/asm-generic/ipcbuf.h:struct ipc64_perm

Any reason you can't just #include <asm/ipcbuf.h> to get the
kernel's definition for the correct architecture?

        Arnd
Viresh Kumar May 22, 2020, 7:10 a.m. UTC | #2
On 21-05-20, 15:11, Arnd Bergmann wrote:
> On Thu, May 21, 2020 at 12:47 PM Viresh Kumar <viresh.kumar@linaro.org> wrote:
> >
> > This adds declaration of struct ipc64_perm, which will be used by
> > following patches.
> >
> > Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
> 
> Like the other structures, there are multiple definitions in the kernel:
> 
> $ git grep ^struct.ipc64_perm

I searched with a { at the end :)

> arch/parisc/include/uapi/asm/ipcbuf.h:struct ipc64_perm
> arch/powerpc/include/uapi/asm/ipcbuf.h:struct ipc64_perm
> arch/s390/include/uapi/asm/ipcbuf.h:struct ipc64_perm
> arch/sparc/include/uapi/asm/ipcbuf.h:struct ipc64_perm
> arch/xtensa/include/uapi/asm/ipcbuf.h:struct ipc64_perm
> include/uapi/asm-generic/ipcbuf.h:struct ipc64_perm
> 
> Any reason you can't just #include <asm/ipcbuf.h> to get the
> kernel's definition for the correct architecture?

Because the libc header may not have the definitions, and so we need
to define our own.
Petr Vorel June 16, 2020, 6:56 p.m. UTC | #3
Hi,

> --- /dev/null
> +++ b/include/ipcbuf.h
...
> +#include <linux/posix_types.h>
> +
> +#ifndef HAVE_IPC64_PERM
...

> +struct ipc64_perm {
> +	__kernel_key_t		key;
> +	__kernel_uid32_t	uid;
> +	__kernel_gid32_t	gid;
> +	__kernel_uid32_t	cuid;
> +	__kernel_gid32_t	cgid;
> +	__kernel_mode_t		mode;
> +				/* pad if mode_t is u16: */
> +	unsigned char		__pad1[4 - sizeof(__kernel_mode_t)];
> +	unsigned short		seq;
> +	unsigned short		__pad2;
> +	__kernel_ulong_t	__unused1;
> +	__kernel_ulong_t	__unused2;

Since this commit we depend on kernel headers from v3.4-rc1
- __kernel_ulong_t was defined in afead38d011a ("posix_types: Introduce
__kernel_[u]long_t").

I'll send a RFC patch, because not sure, whether we should still support these
old versions, or just drop the oldest distro from Travis and declare kernel v3.4
dependency. BTW current glibc requires v3.2.

Kind regards,
Petr
diff mbox series

Patch

diff --git a/configure.ac b/configure.ac
index 1d3ea58d0082..eaf33dd60350 100644
--- a/configure.ac
+++ b/configure.ac
@@ -150,6 +150,7 @@  AC_CHECK_TYPES([struct file_dedupe_range],,,[#include <linux/fs.h>])
 AC_CHECK_TYPES([struct fs_quota_statv],,,[#include <xfs/xqm.h>])
 AC_CHECK_TYPES([struct if_nextdqblk],,,[#include <linux/quota.h>])
 AC_CHECK_TYPES([struct iovec],,,[#include <sys/uio.h>])
+AC_CHECK_TYPES([struct ipc64_perm],,,[#include <sys/ipcbuf.h>])
 
 AC_CHECK_TYPES([struct mmsghdr],,,[
 #define _GNU_SOURCE
diff --git a/include/ipcbuf.h b/include/ipcbuf.h
new file mode 100644
index 000000000000..85162296ab44
--- /dev/null
+++ b/include/ipcbuf.h
@@ -0,0 +1,45 @@ 
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Linaro Limited. All rights reserved.
+ * Author: Viresh Kumar <viresh.kumar@linaro.org>
+ */
+
+#ifndef IPCBUF_H
+#define IPCBUF_H
+
+#include <linux/posix_types.h>
+
+#ifndef HAVE_IPC64_PERM
+
+/*
+ * The generic ipc64_perm structure:
+ * Note extra padding because this structure is passed back and forth
+ * between kernel and user space.
+ *
+ * ipc64_perm was originally meant to be architecture specific, but
+ * everyone just ended up making identical copies without specific
+ * optimizations, so we may just as well all use the same one.
+ *
+ * Pad space is left for:
+ * - 32-bit mode_t on architectures that only had 16 bit
+ * - 32-bit seq
+ * - 2 miscellaneous 32-bit values
+ */
+
+struct ipc64_perm {
+	__kernel_key_t		key;
+	__kernel_uid32_t	uid;
+	__kernel_gid32_t	gid;
+	__kernel_uid32_t	cuid;
+	__kernel_gid32_t	cgid;
+	__kernel_mode_t		mode;
+				/* pad if mode_t is u16: */
+	unsigned char		__pad1[4 - sizeof(__kernel_mode_t)];
+	unsigned short		seq;
+	unsigned short		__pad2;
+	__kernel_ulong_t	__unused1;
+	__kernel_ulong_t	__unused2;
+};
+#endif
+
+#endif /* IPCBUF_H */