1/*
2 * Copyright 2017, Data61
3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO)
4 * ABN 41 687 119 230.
5 *
6 * This software may be distributed and modified according to the terms of
7 * the BSD 2-Clause license. Note that NO WARRANTY is provided.
8 * See "LICENSE_BSD2.txt" for details.
9 *
10 * @TAG(DATA61_BSD)
11 */
12
13#include <sel4debug/debug.h>
14#include <sel4/sel4.h>
15#include <stdarg.h>
16#include <stdio.h>
17
18int
19debug_safe_printf(const char *format, ...)
20{
21    seL4_IPCBuffer shadow_buffer; /* XXX: Should we avoid allocating
22                                   * this large struct on the stack?
23                                   */
24
25    /* Assume that the standard printf may clobber the IPC buffer, so save it
26     * before.
27     */
28    shadow_buffer = *(seL4_GetIPCBuffer());
29
30    /* Copied from printf: */
31    int ret;
32    va_list ap;
33
34    va_start(ap, format);
35    ret = vfprintf(stdout, format, ap);
36    va_end(ap);
37
38    /* Now restore the IPC buffer. */
39    *(seL4_GetIPCBuffer()) = shadow_buffer;
40
41    return ret;
42}
43