igt-dev.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Lucas De Marchi <lucas.demarchi@intel.com>
To: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [PATCH i-g-t 2/2] stubs: provide implementation for memfd_create
Date: Thu, 19 Jul 2018 13:54:45 -0700	[thread overview]
Message-ID: <20180719205445.3040-3-lucas.demarchi@intel.com> (raw)
In-Reply-To: <20180719205445.3040-1-lucas.demarchi@intel.com>

When libc misses memfd_create(), provide a stub implementation to go
through the syscall() route. Syscall numbers are provided for platforms
currently supported by i-g-t only.

Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
---
 lib/stubs/syscall/sys/mman.h | 37 ++++++++++++++++++++++++++++++++++++
 meson.build                  |  3 +++
 2 files changed, 40 insertions(+)
 create mode 100644 lib/stubs/syscall/sys/mman.h

diff --git a/lib/stubs/syscall/sys/mman.h b/lib/stubs/syscall/sys/mman.h
new file mode 100644
index 00000000..36060bda
--- /dev/null
+++ b/lib/stubs/syscall/sys/mman.h
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: MIT */
+
+#pragma once
+
+#include_next <sys/mman.h>
+
+#if !HAVE_MEMFD_CREATE
+#include <errno.h>
+#include <sys/syscall.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#ifndef __NR_memfd_create
+#if defined __x86_64__
+#define __NR_memfd_create 319
+#elif defined __i386__
+#define __NR_memfd_create 356
+#elif defined __arm__
+#define __NR_memfd_create 385
+#else
+#warning "__NR_memfd_create unknown for your architecture"
+#endif
+#endif
+
+static inline int missing_memfd_create(const char *name, unsigned int flags)
+{
+#ifdef __NR_memfd_create
+	return syscall(__NR_memfd_create, name, flags);
+#else
+	errno = ENOSYS;
+	return -1;
+#endif
+}
+
+#define memfd_create missing_memfd_create
+
+#endif
diff --git a/meson.build b/meson.build
index c24a3cf4..188301ca 100644
--- a/meson.build
+++ b/meson.build
@@ -196,6 +196,9 @@ if cc.has_member('struct sysinfo', 'totalram',
 	config.set('HAVE_STRUCT_SYSINFO_TOTALRAM', 1)
 endif
 
+have = cc.has_function('memfd_create', prefix : '''#include <sys/mman.h>''', args : '-D_GNU_SOURCE')
+config.set10('HAVE_MEMFD_CREATE', have)
+
 add_project_arguments('-D_GNU_SOURCE', language : 'c')
 add_project_arguments('-include', 'config.h', language : 'c')
 
-- 
2.17.1

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

  parent reply	other threads:[~2018-07-19 20:55 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-19 20:54 [igt-dev] [PATCH i-g-t 0/2] Fix i-g-t on old systems Lucas De Marchi
2018-07-19 20:54 ` [igt-dev] [PATCH i-g-t 1/2] build: provide include for missing syscalls Lucas De Marchi
2018-07-19 20:54 ` Lucas De Marchi [this message]
2018-07-19 21:14   ` [igt-dev] [PATCH i-g-t 2/2] stubs: provide implementation for memfd_create Antonio Argenziano
2018-07-19 21:43     ` De Marchi, Lucas
2018-07-19 22:17       ` Antonio Argenziano
2018-07-20  7:05         ` Chris Wilson
2018-07-20 19:05           ` Lucas De Marchi
2018-07-20  9:48       ` Tvrtko Ursulin
2018-07-19 23:20   ` Antonio Argenziano
2018-07-20  0:41     ` Lucas De Marchi
2018-07-20  0:56       ` Lucas De Marchi
2018-07-20 19:06       ` Lucas De Marchi
2018-07-19 21:48 ` [igt-dev] ✓ Fi.CI.BAT: success for Fix i-g-t on old systems Patchwork
2018-07-20  4:15 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180719205445.3040-3-lucas.demarchi@intel.com \
    --to=lucas.demarchi@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).