/* $OpenBSD$ */ /* * Copyright (c) 2019, 2020 David Gwynne * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include "msgtap/libmsgtap.h" void * msgtap_md(struct msgtap_metadata *md, uint8_t class, uint8_t type, uint16_t len) { uint8_t *md_len = (uint8_t *)&md->md_len; md->md_class = class; md->md_type = type; md_len[0] = len >> 8; md_len[1] = len; return (md + 1); } void msgtap_md_u8(struct msgtap_metadata *md, uint8_t class, uint8_t type, uint8_t u8) { uint8_t *u8p; u8p = msgtap_md(md, class, type, sizeof(u8)); u8p[0] = u8; } void msgtap_md_u16(struct msgtap_metadata *md, uint8_t class, uint8_t type, uint16_t u16) { uint8_t *u16p; u16p = msgtap_md(md, class, type, sizeof(u16)); u16p[0] = u16 >> 8; u16p[1] = u16; } void msgtap_md_u32(struct msgtap_metadata *md, uint8_t class, uint8_t type, uint32_t u32) { uint8_t *u32p; u32p = msgtap_md(md, class, type, sizeof(u32)); u32p[0] = u32 >> 24; u32p[1] = u32 >> 16; u32p[2] = u32 >> 8; u32p[3] = u32; } void msgtap_md_u64(struct msgtap_metadata *md, uint8_t class, uint8_t type, uint64_t u64) { uint8_t *u64p; u64p = msgtap_md(md, class, type, sizeof(u64)); u64p[0] = u64 >> 56; u64p[1] = u64 >> 48; u64p[2] = u64 >> 40; u64p[3] = u64 >> 32; u64p[4] = u64 >> 24; u64p[5] = u64 >> 16; u64p[6] = u64 >> 8; u64p[7] = u64; } void msgtap_md_mem(struct msgtap_metadata *md, uint8_t class, uint8_t type, const void *src, uint16_t len) { void *dst; dst = msgtap_md(md, class, type, len); memcpy(dst, src, len); }