Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions arch/lkl/include/uapi/asm/host_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,18 @@ void lkl_cleanup(void);
*/
int lkl_is_running(void);

int lkl_printf(const char *, ...);
void lkl_bug(const char *, ...);
/**
* lkl_printf - print a message via the host print operation
*
* @fmt: printf like format string
*/
int lkl_printf(const char *fmt, ...);

/**
* lkl_bug - print a message and panic via the host operations
*
* @fmt: printf like format string
*/
void lkl_bug(const char *fmt, ...);

#endif
2 changes: 1 addition & 1 deletion arch/lkl/lib/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# SPDX-License-Identifier: GPL-2.0

obj-y += string.o
obj-y += host_ops.o string.o
53 changes: 53 additions & 0 deletions arch/lkl/lib/host_ops.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// SPDX-License-Identifier: GPL-2.0

#include <asm/host_ops.h>
#include <linux/stdarg.h>
#include <linux/sprintf.h>

static int lkl_vprintf(const char *fmt, va_list args)
{
int n;
char *buffer;
va_list copy;

if (!lkl_ops->print)
return 0;

va_copy(copy, args);
n = vsnprintf(NULL, 0, fmt, copy);
va_end(copy);

buffer = lkl_ops->mem_alloc(n + 1);
if (!buffer)
return -1;

vsnprintf(buffer, n + 1, fmt, args);

lkl_ops->print(buffer, n);
lkl_ops->mem_free(buffer);

return n;
}

int lkl_printf(const char *fmt, ...)
{
int n;
va_list args;

va_start(args, fmt);
n = lkl_vprintf(fmt, args);
va_end(args);

return n;
}

void lkl_bug(const char *fmt, ...)
{
va_list args;

va_start(args, fmt);
lkl_vprintf(fmt, args);
va_end(args);

lkl_ops->panic();
}
7 changes: 0 additions & 7 deletions tools/lkl/include/lkl_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ extern "C" {
extern struct lkl_host_operations lkl_host_ops;
extern void lkl_change_tls_mode(void);

/**
* lkl_printf - print a message via the host print operation
*
* @fmt: printf like format string
*/
int lkl_printf(const char *fmt, ...);

extern char lkl_virtio_devs[4096];

#if defined(LKL_HOST_CONFIG_POSIX) || defined(__MSYS__)
Expand Down
49 changes: 0 additions & 49 deletions tools/lkl/lib/utils.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <lkl_host.h>
Expand Down Expand Up @@ -159,54 +158,6 @@ void lkl_perror(char *msg, int err)
lkl_printf("%s: %s\n", msg, err_msg);
}

static int lkl_vprintf(const char *fmt, va_list args)
{
int n;
char *buffer;
va_list copy;

if (!lkl_host_ops.print)
return 0;

va_copy(copy, args);
n = vsnprintf(NULL, 0, fmt, copy);
va_end(copy);

buffer = lkl_host_ops.mem_alloc(n + 1);
if (!buffer)
return -1;

vsnprintf(buffer, n + 1, fmt, args);

lkl_host_ops.print(buffer, n);
lkl_host_ops.mem_free(buffer);

return n;
}

int lkl_printf(const char *fmt, ...)
{
int n;
va_list args;

va_start(args, fmt);
n = lkl_vprintf(fmt, args);
va_end(args);

return n;
}

void lkl_bug(const char *fmt, ...)
{
va_list args;

va_start(args, fmt);
lkl_vprintf(fmt, args);
va_end(args);

lkl_host_ops.panic();
}

int lkl_sysctl(const char *path, const char *value)
{
int ret;
Expand Down
Loading