Skip to content

Commit

Permalink
usermode: add USTR() macro to easily create user string literals
Browse files Browse the repository at this point in the history
Signed-off-by: Pawel Wieczorkiewicz <[email protected]>
  • Loading branch information
wipawel committed Aug 23, 2023
1 parent df73782 commit 375dbdb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 6 additions & 0 deletions include/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,10 @@ typedef uint64_t off_t;

#define __always_inline __inline __attribute__((always_inline))

#define USTR(str) \
({ \
static char _str[] __user_data = str; \
_str; \
})

#endif /* KTF_COMPILER_H */
8 changes: 3 additions & 5 deletions tests/unittests.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,19 @@ static unsigned long test_kernel_task_func(void *arg) {
}

static unsigned long __user_text test_user_task_func1(void *arg) {
static char *fmt_printf __user_data = "printf: %u %x %d\n";

printf(fmt_printf, 1234, 0x41414141, 9);
printf(fmt_printf, 1235, 0x42424242, -9);
printf(USTR("printf: %u %x %d\n"), 1234, 0x41414141, 9);
printf(USTR("printf: %u %x %d\n"), 1235, 0x42424242, -9);

exit(9);
return 0;
}

static unsigned long __user_text test_user_task_func2(void *arg) {
static char *fmt_mmap __user_data = "mmap: %lx\n";
void *va;

va = mmap(_ptr(0xfff80000), PAGE_ORDER_4K);
printf(fmt_mmap, _ul(va), 0, 0);
printf(USTR("mmap: %lx\n"), _ul(va));

memset(va, 0xcc, 0x1000);
((void (*)(void)) va)();
Expand Down

0 comments on commit 375dbdb

Please sign in to comment.