| // Copyright Microsoft and CHERIoT Contributors. |
| // SPDX-License-Identifier: MIT |
| |
| #ifndef __STDIO_H__ |
| #define __STDIO_H__ |
| |
| #include <cdefs.h> |
| #include <compartment-macros.h> |
| #include <stdarg.h> |
| #include <stddef.h> |
| |
| #define PRT_MAX_SIZE (0x80) |
| #define EOF (-1) |
| |
| __BEGIN_DECLS |
| |
| /** |
| * This is a very simple implementation of a subset of stdio and supports only |
| * UARTs. The Uart type is often a C++ template type and so we can't forward |
| * declare it in a C header and so we use a volatile void* instead, which can |
| * be cast to the correct type inside the library. |
| */ |
| typedef volatile void FILE; |
| |
| #if DEVICE_EXISTS(uart0) |
| # define stdout MMIO_CAPABILITY(void, uart0) |
| # define stdin MMIO_CAPABILITY(void, uart0) |
| #elif DEVICE_EXISTS(uart) |
| # define stdout MMIO_CAPABILITY(void, uart) |
| # define stdin MMIO_CAPABILITY(void uart) |
| #endif |
| |
| #if DEVICE_EXISTS(uart1) |
| # define stderr MMIO_CAPABILITY(void, uart1) |
| #elif defined(stdout) |
| # define stderr stdout |
| #endif |
| |
| int __cheri_libcall vfprintf(FILE *stream, const char *fmt, va_list ap); |
| |
| static inline int fprintf(FILE *stream, const char *format, ...) |
| { |
| va_list ap; |
| |
| va_start(ap, format); |
| int ret = vfprintf(stream, format, ap); |
| va_end(ap); |
| return ret; |
| } |
| |
| #ifdef stdout |
| static inline int printf(const char *format, ...) |
| { |
| va_list ap; |
| |
| va_start(ap, format); |
| int ret = vfprintf(stdout, format, ap); |
| va_end(ap); |
| return ret; |
| } |
| #endif |
| |
| int __cheri_libcall snprintf(char *str, size_t size, const char *format, ...); |
| int __cheri_libcall vsnprintf(const char *str, |
| size_t size, |
| const char *format, |
| va_list ap); |
| __END_DECLS |
| |
| #endif /* !__STDIO_H__ */ |