• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ART_LIBARTBASE_BASE_MEMFD_H_
18 #define ART_LIBARTBASE_BASE_MEMFD_H_
19 
20 #include <fcntl.h>
21 #include <unistd.h>
22 
23 #if defined(__BIONIC__)
24 #include <linux/memfd.h>  // To access memfd flags.
25 #else
26 
27 // If memfd flags don't exist in the current toolchain, define them ourselves.
28 #ifndef F_ADD_SEALS
29 # define F_ADD_SEALS          (1033)
30 #endif
31 
32 #ifndef F_GET_SEALS
33 # define F_GET_SEALS          (1034)
34 #endif
35 
36 #ifndef F_SEAL_SEAL
37 # define F_SEAL_SEAL          0x0001
38 #endif
39 
40 #ifndef F_SEAL_SHRINK
41 # define F_SEAL_SHRINK        0x0002
42 #endif
43 
44 #ifndef F_SEAL_GROW
45 # define F_SEAL_GROW          0x0004
46 #endif
47 
48 #ifndef F_SEAL_WRITE
49 # define F_SEAL_WRITE         0x0008
50 #endif
51 
52 #ifndef F_SEAL_FUTURE_WRITE
53 # define F_SEAL_FUTURE_WRITE  0x0010
54 #endif
55 
56 #ifndef MFD_CLOEXEC
57 # define MFD_CLOEXEC    0x0001U
58 #endif
59 
60 #ifndef MFD_ALLOW_SEALING
61 # define MFD_ALLOW_SEALING    0x0002U
62 #endif
63 
64 #endif
65 
66 namespace art {
67 
68 // Call memfd(2) if available on platform and return result. This call also makes a kernel version
69 // check for safety on older kernels (b/116769556)..
70 int memfd_create(const char* name, unsigned int flags);
71 
72 // Call memfd(2) if available on platform and return result. Try to give us an unlinked FD in some
73 // other way if memfd fails or isn't supported.
74 int memfd_create_compat(const char* name, unsigned int flags);
75 
76 // Return whether the kernel supports sealing future writes of a memfd.
77 bool IsSealFutureWriteSupported();
78 
79 }  // namespace art
80 
81 #endif  // ART_LIBARTBASE_BASE_MEMFD_H_
82