xref: /aosp_15_r20/external/perfetto/src/base/vm_sockets.h (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
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 #ifdef AF_VSOCK
28 // Use system vm_socket.h if avaialbe.
29 #include <linux/vm_sockets.h>
30 #else  // defined(AF_SOCK)
31 // Fallback and use the stripped copy from the UAPI vm_sockets.h.
32 
33 #include <stdint.h>  // For uint8_t.
34 
35 #define AF_VSOCK 40
36 
37 struct sockaddr_vm {
38   sa_family_t svm_family;
39   unsigned short svm_reserved1;
40   unsigned int svm_port;
41   unsigned int svm_cid;
42   uint8_t svm_flags;
43   unsigned char svm_zero[sizeof(struct sockaddr) - sizeof(sa_family_t) -
44                          sizeof(unsigned short) - sizeof(unsigned int) -
45                          sizeof(unsigned int) - sizeof(uint8_t)];
46 };
47 
48 #endif  // defined(AF_SOCK)
49 
50 #endif  // PERFETTO_BUILDFLAG(PERFETTO_OS_LINUX) ||
51         // PERFETTO_BUILDFLAG(PERFETTO_OS_ANDROID)
52 
53 #endif  // SRC_BASE_VM_SOCKETS_H_
54