/* See the end of this file for copyright and license terms. */ #pragma once /** * @brief Header for the `kprintf()` family of functions. */ #include #include #include /** * @brief Print to the kernel log. * * @param fmt A printf style format string * @returns The amount of bytes written, * or a negative number from `errno.h` on failure */ __attribute__(( format(printf, 1, 2) )) int kprintf(const char *__restrict fmt, ...); /** * @brief Print to the kernel log. * * @param fmt A printf style format string * @param args The variable arguments pointer * @returns The amount of bytes written, * or a negative number from `errno.h` on failure */ int kvprintf(const char *__restrict fmt, va_list args); /** * @brief Printing functions that `kprintf()` and friends call for writing. * Depending on the current kernel log output target (which in turn depends * primarily on the current runlevel), this will be implemented by different * subsystems. To change the printer, call `kprintf_set_printer()`. */ struct kprintf_printer { /** * @brief Write to the kernel log. * The data itself may be cached in a buffer rather than written to the * target immediately; `krpintf()` will call `flush()` when needed. * * @param printer A reference to the original structure * @param buf Data to write * @param len Length of `buf` in bytes * @returns The amount of bytes actually written, * or a negative code from `errno.h` on failure */ ssize_t (*write)(struct kprintf_printer *printer, const void *buf, size_t len); /** * @brief Flush the kernel log buffer. * On implementations that don't have a buffer, this can be a no-op. * If that is the case, this call should always return 0. * * @param printer A reference to the original structure * @returns The amount of bytes flushed out (0 if none), * or a negative code from `errno.h` on failure */ ssize_t (*flush)(struct kprintf_printer *printer); }; /** * @brief Set the current printer for the `kprintf()` family of functions. * * @param new Implementation of the write and flush functions * @returns 0 on success, or a negative code from `errno.h` on failure */ int kprintf_set_printer(struct kprintf_printer *new); /* * This file is part of GayBSD. * Copyright (c) 2021 fef . * * GayBSD is nonviolent software: you may only use, redistribute, and/or * modify it under the terms of the Cooperative Nonviolent Public License * (CNPL) as found in the LICENSE file in the source code root directory * or at ; either version 7 * of the license, or (at your option) any later version. * * GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent * permitted by applicable law. See the CNPL for details. */