1 // Copyright 2018 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 #ifndef LIB_ZXIO_INCEPTION_H_ 6 #define LIB_ZXIO_INCEPTION_H_ 7 8 #include <lib/zxio/ops.h> 9 #include <zircon/compiler.h> 10 #include <zircon/types.h> 11 #include <threads.h> 12 13 // This header exposes some guts of zxio in order to transition fdio to build on 14 // top of zxio. 15 16 __BEGIN_CDECLS 17 18 // remote ---------------------------------------------------------------------- 19 20 // A |zxio_t| backend that uses the |fuchsia.io.Node| protocol. 21 // 22 // The |control| handle is a channel that implements the |fuchsia.io.Node|. The 23 // |event| handle is an optional event object used with some |fuchsia.io.Node| 24 // servers. 25 // 26 // Will eventually be an implementation detail of zxio once fdio completes its 27 // transition to the zxio backend. 28 typedef struct zxio_remote { 29 zxio_t io; 30 zx_handle_t control; 31 zx_handle_t event; 32 } zxio_remote_t; 33 34 static_assert(sizeof(zxio_remote_t) <= sizeof(zxio_storage_t), 35 "zxio_remote_t must fit inside zxio_storage_t."); 36 37 zx_status_t zxio_remote_init(zxio_storage_t* remote, zx_handle_t control, 38 zx_handle_t event); 39 40 // vmofile --------------------------------------------------------------------- 41 42 typedef struct zxio_vmofile { 43 zxio_t io; 44 zx_handle_t control; 45 zx_handle_t vmo; 46 zx_off_t off; 47 zx_off_t end; 48 zx_off_t ptr; 49 // TODO: Migrate to sync_mutex_t. 50 mtx_t lock; 51 } zxio_vmofile_t; 52 53 static_assert(sizeof(zxio_vmofile_t) <= sizeof(zxio_storage_t), 54 "zxio_vmofile_t must fit inside zxio_storage_t."); 55 56 zx_status_t zxio_vmofile_init(zxio_storage_t* file, zx_handle_t control, 57 zx_handle_t vmo, zx_off_t offset, zx_off_t length, 58 zx_off_t seek); 59 60 // pipe ------------------------------------------------------------------------ 61 62 // A |zxio_t| backend that uses a Zircon socket object. 63 // 64 // The |socket| handle is a Zircon socket object. 65 // 66 // Will eventually be an implementation detail of zxio once fdio completes its 67 // transition to the zxio backend. 68 typedef struct zxio_pipe { 69 zxio_t io; 70 zx_handle_t socket; 71 } zxio_pipe_t; 72 73 static_assert(sizeof(zxio_pipe_t) <= sizeof(zxio_storage_t), 74 "zxio_vmofile_t must fit inside zxio_storage_t."); 75 76 zx_status_t zxio_pipe_init(zxio_storage_t* pipe, zx_handle_t socket); 77 78 // debuglog -------------------------------------------------------------------- 79 80 typedef struct zxio_debuglog_buffer zxio_debuglog_buffer_t; 81 82 // A |zxio_t| backend that uses a debuglog. 83 // 84 // The |handle| handle is a Zircon debuglog object. 85 typedef struct zxio_debuglog { 86 zxio_t io; 87 zx_handle_t handle; 88 zxio_debuglog_buffer_t* buffer; 89 } zxio_debuglog_t; 90 91 static_assert(sizeof(zxio_debuglog_t) <= sizeof(zxio_storage_t), 92 "zxio_debuglog_t must fit inside zxio_storage_t."); 93 94 // Initializes a |zxio_storage_t| to use the given |handle| for output. 95 // 96 // The |handle| should be a Zircon debuglog object. 97 zx_status_t zxio_debuglog_init(zxio_storage_t* storage, zx_handle_t handle); 98 99 __END_CDECLS 100 101 #endif // LIB_ZXIO_INCEPTION_H_ 102