• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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_BASE_VM_SOCKETS_H_
18 #define SRC_BASE_VM_SOCKETS_H_
19 
20 #include "perfetto/base/build_config.h"
21 
22 #if PERFETTO_BUILDFLAG(PERFETTO_OS_LINUX) || \
23     PERFETTO_BUILDFLAG(PERFETTO_OS_ANDROID)
24 
25 #include <sys/socket.h>
26 
27 #if PERFETTO_BUILDFLAG(PERFETTO_OS_QNX)
28 // Requires the QNX Advanced Virtualization Framework
29 #include <vm_sockets.h>
30 #elif defined(AF_VSOCK)
31 // Use system vm_socket.h if available.
32 #include <linux/vm_sockets.h>
33 #else  // defined(AF_SOCK)
34 // Fallback and use the stripped copy from the UAPI vm_sockets.h.
35 
36 #include <stdint.h>  // For uint8_t.
37 
38 #define AF_VSOCK 40
39 
40 struct sockaddr_vm {
41   sa_family_t svm_family;
42   unsigned short svm_reserved1;
43   unsigned int svm_port;
44   unsigned int svm_cid;
45   uint8_t svm_flags;
46   unsigned char svm_zero[sizeof(struct sockaddr) - sizeof(sa_family_t) -
47                          sizeof(unsigned short) - sizeof(unsigned int) -
48                          sizeof(unsigned int) - sizeof(uint8_t)];
49 };
50 
51 #endif  // defined(AF_SOCK)
52 
53 #endif  // PERFETTO_BUILDFLAG(PERFETTO_OS_LINUX) ||
54         // PERFETTO_BUILDFLAG(PERFETTO_OS_ANDROID)
55 
56 #endif  // SRC_BASE_VM_SOCKETS_H_
57