summaryrefslogtreecommitdiffstats
path: root/ipc/chromium/src/base/linux_memfd_defs.h
blob: f5b0de1de85340d1c4a1bce9a30f99f39a48cbf2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */

#ifndef BASE_LINUX_MEMFD_DEFS_H
#define BASE_LINUX_MEMFD_DEFS_H

#include <sys/syscall.h>

// glibc before 2.27 didn't have a memfd_create wrapper, and if the
// build system is old enough then it won't have the syscall number
// and various related constants either.

#if defined(__x86_64__)
#  define MEMFD_CREATE_NR 319
#elif defined(__i386__)
#  define MEMFD_CREATE_NR 356
#elif defined(__aarch64__)
#  define MEMFD_CREATE_NR 279
#elif defined(__arm__)
#  define MEMFD_CREATE_NR 385
#elif defined(__powerpc__)
#  define MEMFD_CREATE_NR 360
#elif defined(__s390__)
#  define MEMFD_CREATE_NR 350
#elif defined(__mips__)
#  include <sgidefs.h>
#  if _MIPS_SIM == _MIPS_SIM_ABI32
#    define MEMFD_CREATE_NR 4354
#  elif _MIPS_SIM == _MIPS_SIM_ABI64
#    define MEMFD_CREATE_NR 5314
#  elif _MIPS_SIM == _MIPS_SIM_NABI32
#    define MEMFD_CREATE_NR 6318
#  endif  // mips subarch
#endif    // arch

#ifdef MEMFD_CREATE_NR
#  ifdef SYS_memfd_create
static_assert(MEMFD_CREATE_NR == SYS_memfd_create,
              "MEMFD_CREATE_NR should match the actual SYS_memfd_create value");
#  else  // defined here but not in system headers
#    define SYS_memfd_create MEMFD_CREATE_NR
#  endif
#endif

#ifndef MFD_CLOEXEC
#  define MFD_CLOEXEC 0x0001U
#  define MFD_ALLOW_SEALING 0x0002U
#endif

#ifndef F_ADD_SEALS
#  ifndef F_LINUX_SPECIFIC_BASE
#    define F_LINUX_SPECIFIC_BASE 1024
#  endif
#  define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9)
#  define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10)
#  define F_SEAL_SEAL 0x0001   /* prevent further seals from being set */
#  define F_SEAL_SHRINK 0x0002 /* prevent file from shrinking */
#  define F_SEAL_GROW 0x0004   /* prevent file from growing */
#  define F_SEAL_WRITE 0x0008  /* prevent writes */
#endif

#ifndef F_SEAL_FUTURE_WRITE
#  define F_SEAL_FUTURE_WRITE 0x0010
#endif

#endif  // BASE_LINUX_MEMFD_DEFS_H