1 /* 2 * Copyright 2016, 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 #pragma once 18 19 #include <string> 20 21 #include <sys/cdefs.h> 22 #include <sys/types.h> 23 24 #include <android-base/unique_fd.h> 25 26 // *** WARNING *** 27 // tombstoned's sockets are SOCK_SEQPACKET sockets. 28 // Short reads are treated as errors and short writes are assumed to not happen. 29 30 // Sends a packet with an attached fd. 31 ssize_t send_fd(int sockfd, const void* _Nonnull data, size_t len, android::base::unique_fd fd); 32 33 // Receives a packet and optionally, its attached fd. 34 // If out_fd is non-null, packets can optionally have an attached fd. 35 // If out_fd is null, received packets must not have an attached fd. 36 // 37 // Errors: 38 // EOVERFLOW: sockfd is SOCK_DGRAM or SOCK_SEQPACKET and buffer is too small. 39 // The first len bytes of the packet are stored in data, but the 40 // rest of the packet is dropped. 41 // ERANGE: too many file descriptors were attached to the packet. 42 // ENOMSG: not enough file descriptors were attached to the packet. 43 // 44 // plus any errors returned by the underlying recvmsg. 45 ssize_t recv_fd(int sockfd, void* _Nonnull data, size_t len, 46 android::base::unique_fd* _Nullable out_fd); 47 48 std::string get_process_name(pid_t pid); 49 std::string get_thread_name(pid_t tid); 50