1 /*
2 * Copyright (c) 2013 Google, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files
6 * (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23 #pragma once
24
25 #include <stddef.h>
26 #include <stdbool.h>
27 #include <sys/types.h>
28 #include <iovec.h>
29 #include <compiler.h>
30 #include <stdarg.h>
31
32 #if WITH_LIB_KLOG
33
34 #define KLOG_CURRENT_BUFFER -1
35
36 void klog_init(void);
37
38 ssize_t klog_recover(void *ptr);
39 status_t klog_create(void *ptr, size_t len, uint count);
40
41 uint klog_buffer_count(void);
42 uint klog_current_buffer(void);
43 status_t klog_set_current_buffer(uint buffer);
44
45 /* dump the klog to the console, -1 is current buffer */
46 void klog_dump(int buffer);
47
48 /*
49 * Fill in an iovec that points to the requested buffer, -1 is current buffer.
50 * The buffer may be in 2 pieces, due to the internal circular buffer.
51 * Return is number of iovec runs.
52 */
53 int klog_get_buffer(int buffer, iovec_t *vec);
54
55 /*
56 * Read functions actively remove data from the klog on read
57 */
58 ssize_t klog_read(char *buf, size_t len, int buf_id);
59 char klog_getc(int buf_id);
60 char klog_getchar(void);
61 bool klog_has_data(void);
62
63 void klog_putchar(char c);
64 void klog_puts(const char *str);
65 void klog_printf(const char *fmt, ...) __PRINTFLIKE(1, 2);
66 void klog_vprintf(const char *fmt, va_list ap);
67
68 #else
69
70 /* if klog is not present, stub out the input routines */
klog_putc(char c)71 static inline void klog_putc(char c) {}
klog_puts(const char * str)72 static inline void klog_puts(const char *str) {}
klog_printf(const char * fmt,...)73 static inline void klog_printf(const char *fmt, ...) {}
klog_vprintf(const char * fmt,va_list ap)74 static inline void klog_vprintf(const char *fmt, va_list ap) {}
75
76 #endif
77