#ifndef XPC_BUFFER_H_ #define XPC_BUFFER_H_ #include #include #define XPC_BUFFER_IN(msg, offset, size) \ { \ .buf_flags = XPC_BUFFER_F_IN | XPC_BUFFER_F_REMOTE, \ .buf_origin = (msg), \ .buf_offset = (offset), \ .buf_len = (size), \ } #define XPC_BUFFER_OUT(msg, offset, size) \ { \ .buf_flags = XPC_BUFFER_F_OUT | XPC_BUFFER_F_REMOTE, \ .buf_origin = (msg), \ .buf_offset = (offset), \ .buf_len = (size), \ } struct xpc_msg; typedef enum xpc_buffer_flags { /* the buffer can be read from */ XPC_BUFFER_F_IN = 0x01u, /* the buffer can be written to */ XPC_BUFFER_F_OUT = 0x02u, /* the buffer is backed by a buffer located in another address space. * the buffer can only be accessed via xpc_buffer_read and/or * xpc_buffer_write */ XPC_BUFFER_F_REMOTE = 0x04u, /* free the buffer backing this buffer when the buffer is discarded. * this is only used for out-buffers. the buffer must have been * allocated using xpc_context_alloc, as it will be freed via a call * to xpc_context_free */ XPC_BUFFER_F_FREE_ON_DISCARD = 0x08u, } xpc_buffer_flags_t; typedef struct xpc_buffer { xpc_buffer_flags_t buf_flags; union { /* fields that are only valid if F_OUT is set */ struct { /* only valid if F_OUT is set. specifies the maximum * number of chars that can be written to buf_buf, * including the null terminator. */ size_t buf_max; /* only valid if F_OUT is set. * if F_FREE_ON_DISCARD is set, must be either NULL or * allocated via xpc_context_alloc */ const char *buf_ptr; }; /* fields that are only valid if F_IN is set */ struct { /* only valid if F_IN is set. offset of the buffer data * within the associated message. used when reading * buffer data from a message. */ size_t buf_offset; }; }; /* only valid if F_REMOTE is set. * used to read/write buffer data from/to the sender's address * space. */ const struct xpc_msg *buf_origin; /* valid for both F_IN and F_OUT buffers. * F_IN: specifies the length of the incoming buffer data. * F_OUT: specifies how many bytes from buf_ptr to send. */ size_t buf_len; } xpc_buffer_t; extern xpc_status_t xpc_buffer_read( const xpc_buffer_t *s, void *out, size_t max, size_t *nr_read); extern xpc_status_t xpc_buffer_write( xpc_buffer_t *s, const void *in, size_t len, size_t *nr_written); #endif