Keith Burns (alagalah) | b327c2b | 2017-10-09 08:52:59 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | |
| 16 | /* |
| 17 | * Copyright (c) 2005-2008 Jelmer Vernooij <jelmer@samba.org> |
| 18 | * Copyright (C) 2006-2014 Stefan Metzmacher <metze@samba.org> |
| 19 | * Copyright (C) 2013-2014 Andreas Schneider <asn@samba.org> |
| 20 | * |
| 21 | * All rights reserved. |
| 22 | * |
| 23 | * Redistribution and use in source and binary forms, with or without |
| 24 | * modification, are permitted provided that the following conditions |
| 25 | * are met: |
| 26 | * |
| 27 | * 1. Redistributions of source code must retain the above copyright |
| 28 | * notice, this list of conditions and the following disclaimer. |
| 29 | * |
| 30 | * 2. Redistributions in binary form must reproduce the above copyright |
| 31 | * notice, this list of conditions and the following disclaimer in the |
| 32 | * documentation and/or other materials provided with the distribution. |
| 33 | * |
| 34 | * 3. Neither the name of the author nor the names of its contributors |
| 35 | * may be used to endorse or promote products derived from this software |
| 36 | * without specific prior written permission. |
| 37 | * |
| 38 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
| 39 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 40 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 41 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
| 42 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 43 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 44 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 45 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 46 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 47 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 48 | * SUCH DAMAGE. |
| 49 | * |
| 50 | */ |
| 51 | |
| 52 | /* |
| 53 | Socket wrapper library. Passes all socket communication over |
| 54 | unix domain sockets if the environment variable SOCKET_WRAPPER_DIR |
| 55 | is set. |
| 56 | */ |
| 57 | |
| 58 | #ifndef included_vcom_socket_wrapper_h |
| 59 | #define included_vcom_socket_wrapper_h |
| 60 | |
| 61 | #include <sys/types.h> |
| 62 | #include <sys/socket.h> |
| 63 | #include <sys/ioctl.h> |
| 64 | #include <sys/select.h> |
| 65 | #include <sys/epoll.h> |
shrinivasan ganapathy | 1d35963 | 2017-10-15 15:46:09 -0700 | [diff] [blame] | 66 | #include <poll.h> |
Keith Burns (alagalah) | b327c2b | 2017-10-09 08:52:59 -0700 | [diff] [blame] | 67 | #include <sys/uio.h> |
| 68 | #include <stdlib.h> |
| 69 | |
| 70 | |
| 71 | /* GCC have printf type attribute check. */ |
| 72 | #ifdef HAVE_FUNCTION_ATTRIBUTE_FORMAT |
| 73 | #define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b))) |
| 74 | #else |
| 75 | #define PRINTF_ATTRIBUTE(a,b) |
| 76 | #endif /* HAVE_FUNCTION_ATTRIBUTE_FORMAT */ |
| 77 | |
| 78 | #define HAVE_CONSTRUCTOR_ATTRIBUTE |
| 79 | #ifdef HAVE_CONSTRUCTOR_ATTRIBUTE |
| 80 | #define CONSTRUCTOR_ATTRIBUTE __attribute__ ((constructor)) |
| 81 | #else |
| 82 | #define CONSTRUCTOR_ATTRIBUTE |
| 83 | #endif /* HAVE_CONSTRUCTOR_ATTRIBUTE */ |
| 84 | |
| 85 | #define HAVE_DESTRUCTOR_ATTRIBUTE |
| 86 | #ifdef HAVE_DESTRUCTOR_ATTRIBUTE |
| 87 | #define DESTRUCTOR_ATTRIBUTE __attribute__ ((destructor)) |
| 88 | #else |
| 89 | #define DESTRUCTOR_ATTRIBUTE |
| 90 | #endif |
| 91 | |
| 92 | #define HAVE_ADDRESS_SANITIZER_ATTRIBUTE |
| 93 | #ifdef HAVE_ADDRESS_SANITIZER_ATTRIBUTE |
| 94 | #define DO_NOT_SANITIZE_ADDRESS_ATTRIBUTE __attribute__((no_sanitize_address)) |
| 95 | #else |
| 96 | #define DO_NOT_SANITIZE_ADDRESS_ATTRIBUTE |
| 97 | #endif |
| 98 | |
| 99 | /* |
| 100 | * IMPORTANT |
| 101 | * |
| 102 | * Functions especially from libc need to be loaded individually, you can't load |
| 103 | * all at once or gdb will segfault at startup. The same applies to valgrind and |
| 104 | * has probably something todo with with the linker. |
| 105 | * So we need load each function at the point it is called the first time. |
| 106 | */ |
| 107 | #ifdef HAVE_ACCEPT4 |
| 108 | int |
| 109 | libc_accept4 (int sockfd, |
| 110 | struct sockaddr *addr, socklen_t * addrlen, int flags); |
| 111 | #else /* HAVE_ACCEPT4 */ |
| 112 | int libc_accept (int sockfd, struct sockaddr *addr, socklen_t * addrlen); |
| 113 | #endif /* HAVE_ACCEPT4 */ |
| 114 | |
| 115 | int libc_bind (int sockfd, const struct sockaddr *addr, socklen_t addrlen); |
| 116 | |
| 117 | int libc_close (int fd); |
| 118 | |
| 119 | int libc_connect (int sockfd, const struct sockaddr *addr, socklen_t addrlen); |
| 120 | |
| 121 | #if 0 |
| 122 | /* TBD: dup and dup2 to be implemented later */ |
| 123 | int libc_dup (int fd); |
| 124 | |
| 125 | int libc_dup2 (int oldfd, int newfd); |
| 126 | #endif |
| 127 | |
| 128 | #ifdef HAVE_EVENTFD |
| 129 | int libc_eventfd (int count, int flags); |
| 130 | #endif |
| 131 | |
| 132 | DO_NOT_SANITIZE_ADDRESS_ATTRIBUTE int |
| 133 | libc_vfcntl (int fd, int cmd, va_list ap); |
| 134 | |
Steven | b59f227 | 2017-10-12 17:10:33 -0700 | [diff] [blame] | 135 | DO_NOT_SANITIZE_ADDRESS_ATTRIBUTE int |
| 136 | libc_vioctl (int fd, int cmd, va_list ap); |
| 137 | |
Keith Burns (alagalah) | b327c2b | 2017-10-09 08:52:59 -0700 | [diff] [blame] | 138 | int libc_getpeername (int sockfd, struct sockaddr *addr, socklen_t * addrlen); |
| 139 | |
| 140 | int libc_getsockname (int sockfd, struct sockaddr *addr, socklen_t * addrlen); |
| 141 | |
| 142 | int |
| 143 | libc_getsockopt (int sockfd, |
| 144 | int level, int optname, void *optval, socklen_t * optlen); |
| 145 | |
| 146 | int libc_listen (int sockfd, int backlog); |
| 147 | |
| 148 | int libc_read (int fd, void *buf, size_t count); |
| 149 | |
| 150 | ssize_t libc_readv (int fd, const struct iovec *iov, int iovcnt); |
| 151 | |
| 152 | int libc_recv (int sockfd, void *buf, size_t len, int flags); |
| 153 | |
| 154 | int |
| 155 | libc_recvfrom (int sockfd, |
| 156 | void *buf, |
| 157 | size_t len, |
| 158 | int flags, struct sockaddr *src_addr, socklen_t * addrlen); |
| 159 | |
| 160 | int libc_recvmsg (int sockfd, struct msghdr *msg, int flags); |
| 161 | |
| 162 | int libc_send (int sockfd, const void *buf, size_t len, int flags); |
| 163 | |
| 164 | int libc_sendmsg (int sockfd, const struct msghdr *msg, int flags); |
| 165 | |
| 166 | int |
| 167 | libc_sendto (int sockfd, |
| 168 | const void *buf, |
| 169 | size_t len, |
| 170 | int flags, const struct sockaddr *dst_addr, socklen_t addrlen); |
| 171 | |
| 172 | int |
| 173 | libc_setsockopt (int sockfd, |
| 174 | int level, int optname, const void *optval, |
| 175 | socklen_t optlen); |
| 176 | |
| 177 | int libc_socket (int domain, int type, int protocol); |
| 178 | |
| 179 | int libc_socketpair (int domain, int type, int protocol, int sv[2]); |
| 180 | |
| 181 | ssize_t libc_write (int fd, const void *buf, size_t count); |
| 182 | |
| 183 | ssize_t libc_writev (int fd, const struct iovec *iov, int iovcnt); |
| 184 | |
| 185 | int libc_shutdown (int fd, int how); |
| 186 | |
| 187 | int |
| 188 | libc_select (int __nfds, fd_set * __restrict __readfds, |
| 189 | fd_set * __restrict __writefds, |
| 190 | fd_set * __restrict __exceptfds, |
| 191 | struct timeval *__restrict __timeout); |
| 192 | |
| 193 | #ifdef __USE_XOPEN2K |
| 194 | int |
| 195 | libc_pselect (int __nfds, fd_set * __restrict __readfds, |
| 196 | fd_set * __restrict __writefds, |
| 197 | fd_set * __restrict __exceptfds, |
| 198 | const struct timespec *__restrict __timeout, |
| 199 | const __sigset_t * __restrict __sigmask); |
| 200 | #endif |
| 201 | |
| 202 | int libc_epoll_create (int __size); |
| 203 | |
| 204 | int libc_epoll_create1 (int __flags); |
| 205 | |
| 206 | int libc_epoll_ctl (int __epfd, int __op, int __fd, |
| 207 | struct epoll_event *__event); |
| 208 | |
| 209 | int libc_epoll_wait (int __epfd, struct epoll_event *__events, |
| 210 | int __maxevents, int __timeout); |
| 211 | |
| 212 | int libc_epoll_pwait (int __epfd, struct epoll_event *__events, |
| 213 | int __maxevents, int __timeout, |
| 214 | const __sigset_t * __ss); |
| 215 | |
shrinivasan ganapathy | 1d35963 | 2017-10-15 15:46:09 -0700 | [diff] [blame] | 216 | int libc_poll (struct pollfd *__fds, nfds_t __nfds, int __timeout); |
| 217 | |
| 218 | #ifdef __USE_GNU |
| 219 | int libc_ppoll (struct pollfd *__fds, nfds_t __nfds, |
| 220 | const struct timespec *__timeout, const __sigset_t * __ss); |
| 221 | #endif |
| 222 | |
Keith Burns (alagalah) | b327c2b | 2017-10-09 08:52:59 -0700 | [diff] [blame] | 223 | void swrap_constructor (void); |
| 224 | |
| 225 | void swrap_destructor (void); |
| 226 | |
| 227 | #endif /* included_vcom_socket_wrapper_h */ |
| 228 | |
| 229 | /* |
| 230 | * fd.io coding-style-patch-verification: ON |
| 231 | * |
| 232 | * Local Variables: |
| 233 | * eval: (c-set-style "gnu") |
| 234 | * End: |
| 235 | */ |