^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: LGPL-2.1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #ifndef _TRACE_SEQ_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #define _TRACE_SEQ_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <stdarg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <stdio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) /* ----------------------- trace_seq ----------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #ifndef TRACE_SEQ_BUF_SIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define TRACE_SEQ_BUF_SIZE 4096
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) enum trace_seq_fail {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) TRACE_SEQ__GOOD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) TRACE_SEQ__BUFFER_POISONED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) TRACE_SEQ__MEM_ALLOC_FAILED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * Trace sequences are used to allow a function to call several other functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * to create a string of data to use (up to a max of PAGE_SIZE).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct trace_seq {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) char *buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) unsigned int buffer_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) unsigned int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) unsigned int readpos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) enum trace_seq_fail state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) void trace_seq_init(struct trace_seq *s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) void trace_seq_reset(struct trace_seq *s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) void trace_seq_destroy(struct trace_seq *s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) extern int trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) __attribute__ ((format (printf, 2, 3)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) extern int trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) __attribute__ ((format (printf, 2, 0)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) extern int trace_seq_puts(struct trace_seq *s, const char *str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) extern int trace_seq_putc(struct trace_seq *s, unsigned char c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) extern void trace_seq_terminate(struct trace_seq *s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) extern int trace_seq_do_fprintf(struct trace_seq *s, FILE *fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) extern int trace_seq_do_printf(struct trace_seq *s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #endif /* _TRACE_SEQ_H */