• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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 SRC_TRACING_IPC_MEMFD_H_
18 #define SRC_TRACING_IPC_MEMFD_H_
19 
20 #include "perfetto/base/build_config.h"
21 
22 #include "perfetto/ext/base/scoped_file.h"
23 
24 // Some android build bots use a sysroot that doesn't support memfd when
25 // compiling for the host, so we define the flags we need ourselves.
26 
27 // from memfd.h
28 #ifndef MFD_CLOEXEC
29 #define MFD_CLOEXEC 0x0001U
30 #define MFD_ALLOW_SEALING 0x0002U
31 #endif
32 
33 // from fcntl.h
34 #ifndef F_ADD_SEALS
35 #define F_ADD_SEALS 1033
36 #define F_GET_SEALS 1034
37 #define F_SEAL_SEAL 0x0001
38 #define F_SEAL_SHRINK 0x0002
39 #define F_SEAL_GROW 0x0004
40 #define F_SEAL_WRITE 0x0008
41 #endif
42 
43 namespace perfetto {
44 
45 // Whether the operating system supports memfd.
46 bool HasMemfdSupport();
47 
48 // Call memfd(2) if available on platform and return the fd as result. This call
49 // also makes a kernel version check for safety on older kernels (b/116769556).
50 // Returns an invalid ScopedFile on failure.
51 base::ScopedFile CreateMemfd(const char* name, unsigned int flags);
52 
53 }  // namespace perfetto
54 
55 #endif  // SRC_TRACING_IPC_MEMFD_H_
56