You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.2 KiB
C

/* Copyright (C) 2021,2022 fef <owo@fef.moe>. All rights reserved. */
#pragma once
/**
* @brief Header for the `kprintf()` family of functions.
*/
#include <stdarg.h>
#include <gay/cdefs.h>
#include <gay/types.h>
/**
* @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
*/
int kprintf(const char *__restrict fmt, ...) __printflike(1, 2);
/**
* @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) __printflike(1, 0);
/**
* @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; `kprintf()` 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
*/
isize (*write)(struct kprintf_printer *printer, const void *buf, usize 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
*/
isize (*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);