1/** 2 * \file 3 * \brief Generic bag-o-bytes message format 4 */ 5 6/* 7 * Copyright (c) 2009, ETH Zurich. 8 * All rights reserved. 9 * 10 * This file is distributed under the terms in the attached LICENSE file. 11 * If you do not find this file, copies can be found by writing to: 12 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group. 13 */ 14 15#ifndef BARRELFISH_MSGBUF_H 16#define BARRELFISH_MSGBUF_H 17 18#include <sys/cdefs.h> 19 20__BEGIN_DECLS 21 22/// A generic message buffer into which things can be marshalled 23struct msgbuf { 24 char *buf; ///< Pointer to start of message buffer 25 size_t pos; ///< Current position (byte-offset) in buffer 26 size_t len; ///< Currently-allocated length (in bytes) of buffer 27 struct capref *caps; 28 size_t cap_pos; 29 size_t ncaps; 30 bool dynamic; ///< Buffer is dynamically allocated (from malloc/realloc) 31}; 32 33void msgbuf_init_dynamic(struct msgbuf *msgbuf, size_t hintlen, size_t hintcaps); 34void msgbuf_init_static(struct msgbuf *msgbuf, void *buf, size_t buflen, 35 struct capref *capbuf, size_t capbuflen); 36void msgbuf_destroy(struct msgbuf *msgbuf); 37 38errval_t msgbuf_marshall_buffer(struct msgbuf *msgbuf, const void *src_buf, 39 size_t len); 40errval_t msgbuf_unmarshall_buffer(struct msgbuf *msgbuf, size_t *retlen, 41 void **retbuf); 42errval_t msgbuf_unmarshall_buffer_to_buf(struct msgbuf *msgbuf, void *dest_buf, 43 size_t buflen, size_t *retlen); 44errval_t msgbuf_marshall_string(struct msgbuf *msgbuf, const char *string); 45errval_t msgbuf_unmarshall_string(struct msgbuf *msgbuf, char **ret); 46errval_t msgbuf_unmarshall_string_to_buf(struct msgbuf *msgbuf, char *buf, 47 size_t buflen, size_t *retlen); 48errval_t msgbuf_marshall_cap(struct msgbuf *msgbuf, struct capref cap); 49errval_t msgbuf_unmarshall_cap(struct msgbuf *msgbuf, struct capref *retcap); 50 51#define DECLARE_PRIM_MARSHALLING(NAME, TYPE) \ 52 errval_t msgbuf_marshall_##NAME(struct msgbuf *msgbuf, TYPE val); \ 53 errval_t msgbuf_unmarshall_##NAME(struct msgbuf *msgbuf, TYPE *ret); 54 55DECLARE_PRIM_MARSHALLING(uintptr, uintptr_t) 56DECLARE_PRIM_MARSHALLING(intptr, intptr_t) 57DECLARE_PRIM_MARSHALLING(uint64, uint64_t) 58DECLARE_PRIM_MARSHALLING(int64, int64_t) 59DECLARE_PRIM_MARSHALLING(uint32, uint32_t) 60DECLARE_PRIM_MARSHALLING(int32, int32_t) 61DECLARE_PRIM_MARSHALLING(uint16, uint16_t) 62DECLARE_PRIM_MARSHALLING(int16, int16_t) 63DECLARE_PRIM_MARSHALLING(uint8, uint8_t) 64DECLARE_PRIM_MARSHALLING(int8, int8_t) 65DECLARE_PRIM_MARSHALLING(int, int) 66DECLARE_PRIM_MARSHALLING(float, float) 67DECLARE_PRIM_MARSHALLING(double, double) 68DECLARE_PRIM_MARSHALLING(size, size_t) 69DECLARE_PRIM_MARSHALLING(iref, iref_t) 70 71#undef DECLARE_PRIM_MARSHALLING 72 73__END_DECLS 74 75#endif // BARRELFISH_MSGBUF_H 76