Skip to content

Commit

Permalink
lib/ukprint: PR unikraft#1527
Browse files Browse the repository at this point in the history
Introduce libukprint

Checkpatch-Ignore: LONG_LINE
Checkpatch-Ignore: COMPLEX_MACRO
Checkpatch-Ignore: SPACING
Checkpatch-Ignore: LINE_SPACING
Checkpatch-Ignore: CAMELCASE
Checkpatch-Ignore: MULTISTATEMENT_MACRO_USE_DO_WHILE
Checkpatch-Ignore: MACRO_ARG_REUSE
Signed-off-by: Michalis Pappas <[email protected]>
  • Loading branch information
michpappas committed Nov 5, 2024
1 parent eaf6fda commit a229a75
Show file tree
Hide file tree
Showing 41 changed files with 1,220 additions and 1,710 deletions.
12 changes: 5 additions & 7 deletions arch/arm/arm64/tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,17 @@
#endif /* CONFIG_LIBCONTEXT_CLEAR_TBSS */

#include <string.h>
#include <uk/print.h>
#include <uk/hexdump.h>
#include <uk/assert.h>
#include <uk/essentials.h>

#include <uk/arch/types.h>
#include <uk/arch/tls.h>
#include <uk/essentials.h>
#include <uk/print.h>
#include <uk/print/hexdump.h>

#if CONFIG_LIBUKDEBUG
#include <uk/assert.h>
#include <uk/print.h>
#else /* !CONFIG_LIBUKDEBUG */
#define UK_ASSERT(..) do {} while (0)
#define uk_pr_debug(..) do {} while (0)
#endif /* !CONFIG_LIBUKDEBUG */

/*
Expand Down Expand Up @@ -284,6 +282,6 @@ void ukarch_tls_area_init(void *tls_area)

UK_ASSERT(ukarch_tls_area_size() ==
(__sz) (writepos - (__u8 *) tls_area));
uk_hexdumpCd(tls_area, ukarch_tls_area_size());
uk_hexdumpCk(UK_PRINT_KLVL_DEBUG, tls_area, ukarch_tls_area_size());
}

6 changes: 3 additions & 3 deletions arch/x86/ectx.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include <uk/essentials.h>
#include <uk/assert.h>
#include <uk/print.h>
#include <uk/hexdump.h>
#include <uk/print/hexdump.h>
#include <uk/isr/string.h> /* memset_isr */

enum x86_save_method {
Expand Down Expand Up @@ -215,12 +215,12 @@ void ukarch_ectx_assert_equal(struct ukarch_ectx *state)
if (memcmp_isr(current, state, ectx_size) != 0) {
uk_pr_crit("Modified ECTX detected!\n");
uk_pr_crit("Current:\n");
uk_hexdumpk(KLVL_CRIT, current, ectx_size,
uk_hexdumpk(UK_PRINT_KLVL_CRIT, current, ectx_size,
UK_HXDF_ADDR | UK_HXDF_GRPQWORD | UK_HXDF_COMPRESS,
2);

uk_pr_crit("Expected:\n");
uk_hexdumpk(KLVL_CRIT, state, ectx_size,
uk_hexdumpk(UK_PRINT_KLVL_CRIT, state, ectx_size,
UK_HXDF_ADDR | UK_HXDF_GRPQWORD | UK_HXDF_COMPRESS,
2);

Expand Down
4 changes: 2 additions & 2 deletions arch/x86/x86_64/tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

#include <string.h>
#include <uk/print.h>
#include <uk/hexdump.h>
#include <uk/print/hexdump.h>
#include <uk/assert.h>
#include <uk/essentials.h>
#include <uk/arch/types.h>
Expand Down Expand Up @@ -201,5 +201,5 @@ void ukarch_tls_area_init(void *tls_area)
ukarch_tls_tcb_init((void *) ukarch_tls_tlsp(tls_area));
#endif /* CONFIG_UKARCH_TLS_HAVE_TCB */

uk_hexdumpCd(tls_area, ukarch_tls_area_size());
uk_hexdumpCk(UK_PRINT_KLVL_DEBUG, tls_area, ukarch_tls_area_size());
}
1 change: 1 addition & 0 deletions lib/Makefile.uk
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ $(eval $(call import_lib,$(CONFIG_UK_BASE)/lib/ukmmap))
$(eval $(call import_lib,$(CONFIG_UK_BASE)/lib/ukmpi))
$(eval $(call import_lib,$(CONFIG_UK_BASE)/lib/uknetdev))
$(eval $(call import_lib,$(CONFIG_UK_BASE)/lib/uknofault))
$(eval $(call import_lib,$(CONFIG_UK_BASE)/lib/ukprint))
$(eval $(call import_lib,$(CONFIG_UK_BASE)/lib/ukring))
$(eval $(call import_lib,$(CONFIG_UK_BASE)/lib/uksched))
$(eval $(call import_lib,$(CONFIG_UK_BASE)/lib/ukschedcoop))
Expand Down
33 changes: 13 additions & 20 deletions lib/nolibc/syslog.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,14 @@
static int log_facility = LOG_USER;

static const int level_map[] = {
KLVL_CRIT, /* LOG_EMERG */
KLVL_CRIT, /* LOG_ALERT */
KLVL_CRIT, /* LOG_CRIT */
KLVL_ERR, /* LOG_ERR */
KLVL_WARN, /* LOG_WARNING */
KLVL_INFO, /* LOG_NOTICE */
KLVL_INFO, /* LOG_INFO */

/* This one maps to a different macro on unikraft */
/* KLVL_INFO, */ /* LOG_DEBUG */
UK_PRINT_KLVL_CRIT, /* LOG_EMERG */
UK_PRINT_KLVL_CRIT, /* LOG_ALERT */
UK_PRINT_KLVL_CRIT, /* LOG_CRIT */
UK_PRINT_KLVL_ERR, /* LOG_ERR */
UK_PRINT_KLVL_WARN, /* LOG_WARNING */
UK_PRINT_KLVL_INFO, /* LOG_NOTICE */
UK_PRINT_KLVL_INFO, /* LOG_INFO */
UK_PRINT_KLVL_DEBUG, /* LOG_DEBUG */
};

static const char *facility_to_str(int facility)
Expand Down Expand Up @@ -127,14 +125,9 @@ void vsyslog(int priority, const char *format, va_list ap)
priority &= LOG_PRIMASK;

/* Forward call */
if (priority == LOG_DEBUG) {
uk_printd("[%s] ", facility_to_str(facility));
uk_printd(format, ap);
} else {
priority = MAX(priority, 0);
priority = MIN(priority, (int)ARRAY_SIZE(level_map));
uk_printk(level_map[priority], "[%s] ",
facility_to_str(facility));
uk_printk(level_map[priority], format, ap);
}
priority = MAX(priority, 0);
priority = MIN(priority, (int)ARRAY_SIZE(level_map));
uk_printk(level_map[priority], "[%s] ",
facility_to_str(facility));
uk_printk(level_map[priority], format, ap);
}
2 changes: 1 addition & 1 deletion lib/posix-mmap/tests/test_posix_mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <uk/vmem.h>

#define pr_info(fmt, ...) \
_uk_printk(KLVL_INFO, __NULL, __NULL, 0x0, fmt, ##__VA_ARGS__)
_uk_printk(UK_PRINT_KLVL_INFO, __NULL, __NULL, 0x0, fmt, ##__VA_ARGS__)

#define pm_bug_on(cond) \
do { \
Expand Down
1 change: 0 additions & 1 deletion lib/syscall_shim/Config.uk
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ if LIBSYSCALL_SHIM
depends on LIBSYSCALL_SHIM_HANDLER
bool "'strace'-like messages for binary system calls"
default n
select LIBUKDEBUG if !LIBUKCONSOLE
help
Emits a `strace`-like message as soon as a binary system call request
was finished handling. The result/return code of the system call is
Expand Down
13 changes: 8 additions & 5 deletions lib/syscall_shim/include/uk/syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ typedef long uk_syscall_arg_t;
#define UK_EXECENV_DECLMAPx(__syscall_rarg, nr_args, ...) \
__syscall_rarg UK_ARG_EMAPx(nr_args, __VA_ARGS__)

#if CONFIG_LIBSYSCALL_SHIM_DEBUG_SYSCALLS || CONFIG_LIBUKDEBUG_PRINTD
#if CONFIG_LIBSYSCALL_SHIM_DEBUG_SYSCALLS
#define UK_ARG_FMT_MAP0(...)
#define UK_ARG_FMT_MAP2(m, type, arg) m(type, arg)
#define UK_ARG_FMT_MAP4(m, type, arg, ...) m(type, arg) ", " UK_ARG_FMT_MAP2(m, __VA_ARGS__)
Expand All @@ -219,15 +219,18 @@ typedef long uk_syscall_arg_t;
#define UK_S_ARG_FMT_LONGX(type, arg) "(" STRINGIFY(type) ") 0x%lx"

#define __UK_SYSCALL_PRINTD(x, rtype, fname, ...) \
_uk_printd(uk_libid_self(), __STR_BASENAME__, __LINE__, \
_uk_printk(UK_PRINT_KLVL_DEBUG | UK_PRINT_RAW, \
uk_libid_self(), __STR_BASENAME__, __LINE__, \
"(" STRINGIFY(rtype) ") " STRINGIFY(fname) \
"(" UK_ARG_FMT_MAPx(x, UK_S_ARG_FMT_LONGX, __VA_ARGS__) ")\n" \
UK_ARG_EMAPx(x, UK_S_ARG_CAST_LONG, __VA_ARGS__) )

#define __UK_SYSCALL_EXECENV_PRINTD(x, rtype, fname, ...) \
uk_printd("\nInvoking context saving %s system call.\n", \
#define __UK_SYSCALL_EXECENV_PRINTD(x, rtype, fname, ...) \
uk_printk(UK_PRINT_KLVL_DEBUG | UK_PRINT_RAW, \
"\nInvoking context saving %s system call.\n", \
STRINGIFY(fname)); \
_uk_printd(uk_libid_self(), __STR_BASENAME__, __LINE__, \
_uk_printk(UK_PRINT_KLVL_DEBUG | UK_PRINT_RAW, \
uk_libid_self(), __STR_BASENAME__, __LINE__, \
"(" STRINGIFY(rtype) ") " STRINGIFY(fname) \
"( execenv 0x%lx, " UK_ARG_FMT_MAPx(x, \
UK_S_ARG_FMT_LONGX,\
Expand Down
22 changes: 4 additions & 18 deletions lib/syscall_shim/uk_syscall_binary.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@
#include <uk/essentials.h>
#include <uk/thread.h>
#if CONFIG_LIBSYSCALL_SHIM_STRACE
#if CONFIG_LIBUKCONSOLE
#include <uk/console.h>
#else /* !CONFIG_LIBUKCONSOLE */
#include <uk/print.h>
#endif /* !CONFIG_LIBUKCONSOLE */
#endif /* CONFIG_LIBSYSCALL_SHIM_STRACE */

/**
Expand Down Expand Up @@ -107,8 +103,9 @@ void ukplat_syscall_handler(struct uk_syscall_ctx *usc)
#endif /* CONFIG_LIBSYSCALL_SHIM_HANDLER_ULTLS */

#if CONFIG_LIBSYSCALL_SHIM_DEBUG_HANDLER
_uk_printd(uk_libid_self(), __STR_BASENAME__, __LINE__,
"Binary system call request \"%s\" (%lu) at ip:%p (arg0=0x%lx, arg1=0x%lx, ...)\n",
_uk_printk(UK_PRINT_KLVL_DEBUG,
uk_libid_self(), __STR_BASENAME__, __LINE__,
"Binary system call request \"%s\" (%lu) at ip:%p (arg0=0x%lx, arg1=0x%lx, ...)\n",
uk_syscall_name(execenv->regs.__syscall_rsyscall),
execenv->regs.__syscall_rsyscall,
(void *)execenv->regs.__syscall_rip,
Expand All @@ -133,18 +130,7 @@ void ukplat_syscall_handler(struct uk_syscall_ctx *usc)
execenv->regs.__syscall_rarg3,
execenv->regs.__syscall_rarg4,
execenv->regs.__syscall_rarg5);
/*
* FIXME:
* Replace the call to `uk_pr_info` with a call to the kernel printing
* library once that exists. We also don't want to print all the meta
* data that `uk_pr_info` includes. Note also that right now, debug
* print calls also turn into a no-op if `ukconsole` is not available.
*/
#if CONFIG_LIBUKCONSOLE
uk_console_out(prsyscallbuf, (__sz) prsyscalllen);
#else /* !CONFIG_LIBUKCONSOLE */
uk_pr_info(prsyscallbuf);
#endif /* !CONFIG_LIBUKCONSOLE */
uk_printk(UK_PRINT_KLVL_INFO | UK_PRINT_RAW, "%s", prsyscallbuf);
#endif /* CONFIG_LIBSYSCALL_SHIM_STRACE */

#if CONFIG_LIBSYSCALL_SHIM_HANDLER_ULTLS
Expand Down
93 changes: 0 additions & 93 deletions lib/ukdebug/Config.uk
Original file line number Diff line number Diff line change
Expand Up @@ -5,99 +5,6 @@ menuconfig LIBUKDEBUG
default y

if LIBUKDEBUG
config LIBUKDEBUG_PRINTK
bool "Enable kernel messages (uk_printk)"
default y
help
Enables kernel message console.

choice
prompt "Kernel message level"
default LIBUKDEBUG_PRINTK_ERR
depends on LIBUKDEBUG_PRINTK
help
Set the level of detail of kernel messages

config LIBUKDEBUG_PRINTK_INFO
bool "Show all types of messages"

config LIBUKDEBUG_PRINTK_WARN
bool "Show critical, error, and warning messages"

config LIBUKDEBUG_PRINTK_ERR
bool "Show critical and error messages (default)"

config LIBUKDEBUG_PRINTK_CRIT
bool "Show critical messages only"
endchoice

config LIBUKDEBUG_PRINTD
bool "Enable debug messages globally (uk_printd)"
default n
help
Enables debug messages globally. Without this configuration,
debug messages can still be enabled for each compilation unit
individually. This happens as soon the UK_DEBUG macro is defined.

choice
prompt "Message redirection"
default LIBUKDEBUG_REDIR_PRINTD
help
Output for uk_printk() and uk_printd()

config LIBUKDEBUG_NOREDIR
bool "No redirection"
help
Keep debug and kernel output separated

config LIBUKDEBUG_REDIR_PRINTD
bool "Debug messages on kernel output (default)"
help
Debug message are redirected to standard kernel output

config LIBUKDEBUG_REDIR_PRINTK
bool "Kernel messages on debug output"
depends on LIBUKDEBUG_PRINTK
help
Kernel message are redirected to the standard debug output
endchoice

config LIBUKDEBUG_PRINT_TIME
bool "Show timestamp in messages"
default y

config LIBUKDEBUG_PRINT_THREAD
bool "Show thread identifier"
default n
depends on LIBUKSCHED
help
Prints the thread name or, if unnamed, the address of
the TCB (struct uk_thread) of the currently scheduled
thread. For the case `uk_thread_current()` returns
NULL, the placeholder "<<n/a>>" is printed instead.

config LIBUKDEBUG_PRINT_CALLER
bool "Show caller information"
default n
help
Prints the current return address and current stack frame
address for the message command. The return address can be
useful in combination with a debugger. The stack frame
address is a handy information for analysing the state of
the currently active stack.
Format: "{r:<return address>,f:<stack frame address>}"

config LIBUKDEBUG_PRINT_SRCNAME
bool "Print source code location of messages"
default y

config LIBUKDEBUG_ANSI_COLOR
bool "Colored output"
default n
help
Use ANSI control sequences to colorize console output.
Before activating this option, please make sure that
your console output/display supports ANSI.

config LIBUKDEBUG_ENABLE_ASSERT
bool "Enable assertions"
Expand Down
9 changes: 0 additions & 9 deletions lib/ukdebug/Makefile.uk
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,6 @@ CXXINCLUDES-$(CONFIG_LIBUKDEBUG) += -I$(LIBUKDEBUG_BASE)/include
LIBUKDEBUG_ASINCLUDES-y += -I$(LIBUKDEBUG_BASE)/arch/$(CONFIG_UK_ARCH)
LIBUKDEBUG_CINCLUDES-y += -I$(LIBUKDEBUG_BASE)/arch/$(CONFIG_UK_ARCH)

LIBUKDEBUG_CFLAGS-y += -D__IN_LIBUKDEBUG__
LIBUKDEBUG_CXXFLAGS-y += -D__IN_LIBUKDEBUG__

LIBUKDEBUG_SRCS-y += $(LIBUKDEBUG_BASE)/print.c
LIBUKDEBUG_SRCS-$(CONFIG_HAVE_LIBC) += $(LIBUKDEBUG_BASE)/snprintf.c
LIBUKDEBUG_SRCS-y += $(LIBUKDEBUG_BASE)/outf.c
LIBUKDEBUG_SRCS-y += $(LIBUKDEBUG_BASE)/hexdump.c
LIBUKDEBUG_SRCS-$(CONFIG_LIBZYDIS) += $(LIBUKDEBUG_BASE)/asmdump.c

LIBUKDEBUG_SRCS-$(CONFIG_LIBUKDEBUG_GDBSTUB) += $(LIBUKDEBUG_BASE)/gdbstub.c|isr
LIBUKDEBUG_SRCS-$(CONFIG_LIBUKDEBUG_GDBSTUB) += $(LIBUKDEBUG_BASE)/gdbtargetxml.ld
LIBUKDEBUG_SRCS-$(CONFIG_LIBUKDEBUG_GDBSTUB) += $(LIBUKDEBUG_BASE)/gdbtargetxml.S
Expand Down
Loading

0 comments on commit a229a75

Please sign in to comment.