1 // Copyright 2016 The Fuchsia Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #pragma once 6 7 #include <limits.h> 8 #include <poll.h> 9 #include <stdbool.h> 10 #include <unistd.h> // for ssize_t 11 12 #include <zircon/types.h> 13 #include <zircon/compiler.h> 14 15 #include <lib/fdio/limits.h> 16 17 // flag on handle args in processargs 18 // instructing that this fd should be dup'd to 0/1/2 19 // and be used for all of stdio 20 #define FDIO_FLAG_USE_FOR_STDIO 0x8000 21 22 // events for fdio_wait_fd() 23 #define FDIO_EVT_READABLE POLLIN 24 #define FDIO_EVT_WRITABLE POLLOUT 25 #define FDIO_EVT_ERROR POLLERR 26 #define FDIO_EVT_PEER_CLOSED POLLRDHUP 27 #define FDIO_EVT_ALL (POLLIN | POLLOUT | POLLERR | POLLRDHUP) 28 29 __BEGIN_CDECLS 30 31 // wait until one or more events are pending 32 zx_status_t fdio_wait_fd(int fd, uint32_t events, uint32_t* pending, zx_time_t deadline); 33 34 // create a fd that works with wait APIs (epoll, select, etc.) from a handle 35 // and expected signals (signals_in/signals_out correspond to POLLIN/POLLOUT 36 // events respectively). The handle will be closed when the fd is closed, unless 37 // shared_handle is true. 38 int fdio_handle_fd(zx_handle_t h, zx_signals_t signals_in, zx_signals_t signals_out, bool shared_handle); 39 40 // invoke a raw fdio ioctl 41 ssize_t fdio_ioctl(int fd, int op, const void* in_buf, size_t in_len, void* out_buf, size_t out_len); 42 43 // create a pipe, installing one half in a fd, returning the other 44 // for transport to another process 45 zx_status_t fdio_pipe_half(zx_handle_t* handle, uint32_t* type); 46 47 // Get a read-only VMO containing the whole contents of the file. 48 // This function creates a clone of the underlying VMO when possible, falling 49 // back to eagerly reading the contents into a freshly-created VMO. 50 zx_status_t fdio_get_vmo_copy(int fd, zx_handle_t* out_vmo); 51 52 // Gets a read-only VMO containing a clone of the underlying VMO. 53 // This function will fail rather than copying the contents if it cannot clone. 54 zx_status_t fdio_get_vmo_clone(int fd, zx_handle_t* out_vmo); 55 56 // Get a read-only handle to the exact VMO used by the file system server to 57 // represent the file. This function fails if the server does not have an exact 58 // VMO representation of the file (e.g., if fdio_get_vmo would need to copy 59 // or clone data into a new VMO). 60 zx_status_t fdio_get_vmo_exact(int fd, zx_handle_t* out_vmo); 61 62 __END_CDECLS 63