Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.openwrt.org/project/libubox.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@nbd.name>2023-11-27 17:44:33 +0300
committerFelix Fietkau <nbd@nbd.name>2023-11-27 20:30:01 +0300
commitd4c3066e7c5efa5f395c21db77609516d386cbf8 (patch)
tree405d0aaa23f7207eb9d2f0c891ac2fb54bca8659 /udebug-proto.h
parentb3fa3d92e3ebae9b224a0111427d6bdd8b869399 (diff)
udebug: add udebug library code
Copied and adapted from udebug.git Signed-off-by: Felix Fietkau <nbd@nbd.name>
Diffstat (limited to 'udebug-proto.h')
-rw-r--r--udebug-proto.h72
1 files changed, 72 insertions, 0 deletions
diff --git a/udebug-proto.h b/udebug-proto.h
new file mode 100644
index 0000000..916c5fa
--- /dev/null
+++ b/udebug-proto.h
@@ -0,0 +1,72 @@
+/*
+ * udebug - debug ring buffer library
+ *
+ * Copyright (C) 2023 Felix Fietkau <nbd@nbd.name>
+ *
+ * Permission to use, copy, modify, and/or 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.
+ */
+#ifndef __UDEBUG_PROTO_H
+#define __UDEBUG_PROTO_H
+
+#include "udebug.h"
+
+struct udebug_hdr {
+ uint32_t ring_size;
+ uint32_t data_size;
+
+ uint32_t format;
+ uint32_t sub_format;
+
+ uintptr_t flags[8 / sizeof(uintptr_t)];
+ uintptr_t notify;
+
+ uint32_t head_hi;
+ uint32_t head;
+ uint32_t data_head;
+ uint32_t data_used;
+};
+
+enum udebug_client_msg_type {
+ CL_MSG_RING_ADD,
+ CL_MSG_RING_REMOVE,
+ CL_MSG_RING_NOTIFY,
+ CL_MSG_GET_HANDLE,
+ CL_MSG_RING_GET,
+ CL_MSG_ERROR,
+};
+
+struct udebug_client_msg {
+ uint8_t type;
+ uint8_t _pad[3];
+ uint32_t id;
+ union {
+ struct {
+ uint32_t ring_size, data_size;
+ };
+ uint32_t notify_mask;
+ };
+} __attribute__((packed, aligned(4)));
+
+static inline struct udebug_ptr *
+udebug_ring_ptr(struct udebug_hdr *hdr, uint32_t idx)
+{
+ struct udebug_ptr *ring = (struct udebug_ptr *)&hdr[1];
+ return &ring[idx & (hdr->ring_size - 1)];
+}
+
+static inline void *udebug_buf_ptr(struct udebug_buf *buf, uint32_t ofs)
+{
+ return buf->data + (ofs & (buf->data_size - 1));
+}
+
+#endif