ustream: prevent recursive calls to the read callback
[project/libubox.git] / udebug-proto.h
1 /*
2 * udebug - debug ring buffer library
3 *
4 * Copyright (C) 2023 Felix Fietkau <nbd@nbd.name>
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 #ifndef __UDEBUG_PROTO_H
19 #define __UDEBUG_PROTO_H
20
21 #include "udebug.h"
22
23 struct udebug_hdr {
24 uint32_t ring_size;
25 uint32_t data_size;
26
27 uint32_t format;
28 uint32_t sub_format;
29
30 uintptr_t flags[8 / sizeof(uintptr_t)];
31 uintptr_t notify;
32
33 uint32_t head_hi;
34 uint32_t head;
35 uint32_t data_head;
36 uint32_t data_used;
37 };
38
39 enum udebug_client_msg_type {
40 CL_MSG_RING_ADD,
41 CL_MSG_RING_REMOVE,
42 CL_MSG_RING_NOTIFY,
43 CL_MSG_GET_HANDLE,
44 CL_MSG_RING_GET,
45 CL_MSG_ERROR,
46 };
47
48 struct udebug_client_msg {
49 uint8_t type;
50 uint8_t _pad[3];
51 uint32_t id;
52 union {
53 struct {
54 uint32_t ring_size, data_size;
55 };
56 uint32_t notify_mask;
57 };
58 } __attribute__((packed, aligned(4)));
59
60 static inline struct udebug_ptr *
61 udebug_ring_ptr(struct udebug_hdr *hdr, uint32_t idx)
62 {
63 struct udebug_ptr *ring = (struct udebug_ptr *)&hdr[1];
64 return &ring[idx & (hdr->ring_size - 1)];
65 }
66
67 static inline void *udebug_buf_ptr(struct udebug_buf *buf, uint32_t ofs)
68 {
69 return buf->data + (ofs & (buf->data_size - 1));
70 }
71
72 #endif