/* * The Qubes OS Project, http://www.qubes-os.org * * Copyright (C) 2010 Rafal Wojtczuk * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * */ #include #include typedef uint32_t VCHAN_RING_IDX; /// struct vchan_interface is placed in memory shared between domains struct vchan_interface { // One buffer for each data direction char buf_in[1024]; char buf_out[2048]; // standard consumer/producer interface, one pair per buffer VCHAN_RING_IDX cons_in, prod_in, cons_out, prod_out; uint32_t debug; int client_closed, server_closed; }; /// struct libvchan is a control structure, passed to all library calls struct libvchan { // person we communicate with int other_domain_id; // "port" we communicate on (allows multiple vchans to exist) int device_number; // Shared ring page, its kernel FD, and its grant reference struct vchan_interface *ring; int ring_fd; uint32_t ring_ref; // event channel interface int event_fd; int event_port; // boolean controlling read/write locations int is_server; }; struct libvchan *libvchan_server_init(int domain, int devno); struct libvchan *libvchan_client_init(int domain, int devno); // reads exactly size or aborts int libvchan_recv(struct libvchan *ctrl, void *data, size_t size); // reads up to size bytes (including zero) without blocking int libvchan_read(struct libvchan *ctrl, void *data, size_t size); // sends entire buffer or aborts int libvchan_send(struct libvchan *ctrl, const void *data, size_t size); // sends as much data as possible without blocking int libvchan_write(struct libvchan *ctrl, const void *data, size_t size); // waits for reads or writes to unblock int libvchan_wait(struct libvchan *ctrl); int libvchan_close(struct libvchan *ctrl); // (only) when this FD is readable, libvchan_wait() will not block int libvchan_fd_for_select(struct libvchan *ctrl); int libvchan_is_eof(struct libvchan *ctrl); int libvchan_data_ready(struct libvchan *ctrl); int libvchan_buffer_space(struct libvchan *ctrl);