link librt if needed for shm_open
[project/libubox.git] / udebug-priv.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_UTIL_H
19 #define __UDEBUG_UTIL_H
20
21 #include "blobmsg.h"
22 #include "udebug.h"
23 #include "udebug-proto.h"
24
25 #define UDEBUG_TIMEOUT 1000
26
27 __hidden int udebug_buf_open(struct udebug_buf *buf, int fd, uint32_t ring_size, uint32_t data_size);
28 __hidden struct udebug_client_msg *__udebug_poll(struct udebug *ctx, int *fd, bool wait);
29 __hidden void udebug_send_msg(struct udebug *ctx, struct udebug_client_msg *msg,
30 struct blob_attr *meta, int fd);
31
32 static inline int32_t u32_sub(uint32_t a, uint32_t b)
33 {
34 return a - b;
35 }
36
37 static inline int32_t u32_max(uint32_t a, uint32_t b)
38 {
39 return u32_sub(a, b) > 0 ? a : b;
40 }
41
42 static inline void u32_set(void *ptr, uint32_t val)
43 {
44 volatile uint32_t *v = ptr;
45 *v = val;
46 }
47
48 static inline uint32_t u32_get(void *ptr)
49 {
50 volatile uint32_t *v = ptr;
51 return *v;
52 }
53
54 #endif