tests/kernel/mem_protect/syscalls: Add cases to test 64 bit arguments
Add some simple tests of the new code generation for syscalls with 64 bit arguments. Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
This commit is contained in:
parent
6564974bae
commit
4723def90d
3 changed files with 85 additions and 19 deletions
|
@ -594,7 +594,11 @@ void z_impl_log_panic(void)
|
|||
}
|
||||
|
||||
#ifdef CONFIG_USERSPACE
|
||||
Z_SYSCALL_HANDLER0_SIMPLE_VOID(log_panic);
|
||||
void z_vrfy_log_panic(void)
|
||||
{
|
||||
z_impl_log_panic();
|
||||
}
|
||||
#include <syscalls/log_panic_mrsh.c>
|
||||
#endif
|
||||
|
||||
static bool msg_filter_check(struct log_backend const *backend,
|
||||
|
@ -677,10 +681,11 @@ bool z_impl_log_process(bool bypass)
|
|||
}
|
||||
|
||||
#ifdef CONFIG_USERSPACE
|
||||
Z_SYSCALL_HANDLER(log_process, bypass)
|
||||
bool z_vrfy_log_process(bool bypass)
|
||||
{
|
||||
return (u32_t)log_process((bool)(bypass));
|
||||
return z_impl_log_process(bypass);
|
||||
}
|
||||
#include <syscalls/log_process_mrsh.c>
|
||||
#endif
|
||||
|
||||
u32_t z_impl_log_buffered_cnt(void)
|
||||
|
@ -689,7 +694,11 @@ u32_t z_impl_log_buffered_cnt(void)
|
|||
}
|
||||
|
||||
#ifdef CONFIG_USERSPACE
|
||||
Z_SYSCALL_HANDLER0_SIMPLE(log_buffered_cnt);
|
||||
u32_t z_vrfy_log_buffered_cnt(void)
|
||||
{
|
||||
return z_impl_log_buffered_cnt();
|
||||
}
|
||||
#include <syscalls/log_buffered_cnt_mrsh.c>
|
||||
#endif
|
||||
|
||||
void log_dropped(void)
|
||||
|
@ -774,7 +783,10 @@ u32_t z_impl_log_filter_set(struct log_backend const *const backend,
|
|||
}
|
||||
|
||||
#ifdef CONFIG_USERSPACE
|
||||
Z_SYSCALL_HANDLER(log_filter_set, backend, domain_id, src_id, level)
|
||||
u32_t z_vrfy_log_filter_set(struct log_backend const *const backend,
|
||||
u32_t domain_id,
|
||||
u32_t src_id,
|
||||
u32_t level)
|
||||
{
|
||||
Z_OOPS(Z_SYSCALL_VERIFY_MSG(backend == 0,
|
||||
"Setting per-backend filters from user mode is not supported"));
|
||||
|
@ -788,6 +800,7 @@ Z_SYSCALL_HANDLER(log_filter_set, backend, domain_id, src_id, level)
|
|||
|
||||
return z_impl_log_filter_set(NULL, domain_id, src_id, level);
|
||||
}
|
||||
#include <syscalls/log_filter_set_mrsh.c>
|
||||
#endif
|
||||
|
||||
static void backend_filter_set(struct log_backend const *const backend,
|
||||
|
@ -916,9 +929,8 @@ void z_impl_z_log_string_from_user(u32_t src_level_val, const char *str)
|
|||
__ASSERT(false, "This function can be called from user mode only.");
|
||||
}
|
||||
|
||||
Z_SYSCALL_HANDLER(z_log_string_from_user, src_level_val, user_string_ptr)
|
||||
void z_vrfy_z_log_string_from_user(u32_t src_level_val, const char *str)
|
||||
{
|
||||
const char *str = (const char *)(user_string_ptr);
|
||||
u8_t level, domain_id, source_id;
|
||||
union {
|
||||
struct log_msg_ids structure;
|
||||
|
@ -946,7 +958,7 @@ Z_SYSCALL_HANDLER(z_log_string_from_user, src_level_val, user_string_ptr)
|
|||
(level > LOG_FILTER_SLOT_GET(log_dynamic_filters_get(source_id),
|
||||
LOG_FILTER_AGGR_SLOT_IDX))) {
|
||||
/* Skip filtered out messages. */
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -975,9 +987,8 @@ Z_SYSCALL_HANDLER(z_log_string_from_user, src_level_val, user_string_ptr)
|
|||
str = log_strdup(str);
|
||||
log_1("%s", (log_arg_t)str, src_level_union.structure);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#include <syscalls/z_log_string_from_user_mrsh.c>
|
||||
|
||||
void log_generic_from_user(struct log_msg_ids src_level,
|
||||
const char *fmt, va_list ap)
|
||||
|
@ -1015,11 +1026,9 @@ void z_impl_z_log_hexdump_from_user(u32_t src_level_val, const char *metadata,
|
|||
__ASSERT(false, "This function can be called from user mode only.");
|
||||
}
|
||||
|
||||
Z_SYSCALL_HANDLER(z_log_hexdump_from_user, src_level_val,
|
||||
user_metadata_ptr, user_data_ptr, len)
|
||||
void z_vrfy_z_log_hexdump_from_user(u32_t src_level_val, const char *metadata,
|
||||
const u8_t *data, u32_t len)
|
||||
{
|
||||
const char *metadata = (const char *)(user_metadata_ptr);
|
||||
const void *data = (const void *)(user_data_ptr);
|
||||
union {
|
||||
struct log_msg_ids structure;
|
||||
u32_t value;
|
||||
|
@ -1045,7 +1054,7 @@ Z_SYSCALL_HANDLER(z_log_hexdump_from_user, src_level_val,
|
|||
log_dynamic_filters_get(src_level_union.structure.source_id),
|
||||
LOG_FILTER_AGGR_SLOT_IDX))) {
|
||||
/* Skip filtered out messages. */
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1065,9 +1074,8 @@ Z_SYSCALL_HANDLER(z_log_hexdump_from_user, src_level_val,
|
|||
metadata = log_strdup(metadata);
|
||||
log_hexdump(metadata, data, len, src_level_union.structure);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#include <syscalls/z_log_hexdump_from_user_mrsh.c>
|
||||
|
||||
void log_hexdump_from_user(struct log_msg_ids src_level, const char *metadata,
|
||||
const u8_t *data, u32_t len)
|
||||
|
@ -1097,7 +1105,7 @@ void z_impl_z_log_string_from_user(u32_t src_level_val, const char *str)
|
|||
__ASSERT_NO_MSG(false);
|
||||
}
|
||||
|
||||
void z_impl_z_log_hexdump_from_user(u32_t src_level_val, const char *metadata,
|
||||
void z_vrfy_z_log_hexdump_from_user(u32_t src_level_val, const char *metadata,
|
||||
const u8_t *data, u32_t len)
|
||||
{
|
||||
ARG_UNUSED(src_level_val);
|
||||
|
|
|
@ -98,6 +98,47 @@ static inline int z_vrfy_to_copy(char *dest)
|
|||
}
|
||||
#include <syscalls/to_copy_mrsh.c>
|
||||
|
||||
int z_impl_syscall_arg64(u64_t arg)
|
||||
{
|
||||
/* "Hash" (heh) the return to avoid accidental false positives
|
||||
* due to using common/predictable values.
|
||||
*/
|
||||
return (int)(arg + 0x8c32a9eda4ca2621ULL + (size_t)&kernel_string);
|
||||
}
|
||||
|
||||
static inline int z_vrfy_syscall_arg64(u64_t arg)
|
||||
{
|
||||
return z_impl_syscall_arg64(arg);
|
||||
}
|
||||
#include <syscalls/syscall_arg64_mrsh.c>
|
||||
|
||||
/* Bigger 64 bit arg syscall to exercise marshalling 7+ words of
|
||||
* arguments (this one happens to need 9), and to test generation of
|
||||
* 64 bit return values.
|
||||
*/
|
||||
u64_t z_impl_syscall_arg64_big(u32_t arg1, u32_t arg2,
|
||||
u64_t arg3, u32_t arg4,
|
||||
u32_t arg5, u64_t arg6)
|
||||
{
|
||||
u64_t args[] = { arg1, arg2, arg3, arg4, arg5, arg6 };
|
||||
u64_t ret = 0xae751a24ef464cc0ULL;
|
||||
|
||||
for (int i = 0; i < ARRAY_SIZE(args); i++) {
|
||||
ret += args[i];
|
||||
ret = (ret << 11) | (ret >> 53);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline u64_t z_vrfy_syscall_arg64_big(u32_t arg1, u32_t arg2,
|
||||
u64_t arg3, u32_t arg4,
|
||||
u32_t arg5, u64_t arg6)
|
||||
{
|
||||
return z_impl_syscall_arg64_big(arg1, arg2, arg3, arg4, arg5, arg6);
|
||||
}
|
||||
#include <syscalls/syscall_arg64_big_mrsh.c>
|
||||
|
||||
/**
|
||||
* @brief Test to demonstrate usage of z_user_string_nlen()
|
||||
*
|
||||
|
@ -203,6 +244,17 @@ void test_to_copy(void)
|
|||
zassert_equal(ret, 0, "string should have matched");
|
||||
}
|
||||
|
||||
void test_arg64(void)
|
||||
{
|
||||
zassert_equal(syscall_arg64(54321),
|
||||
z_impl_syscall_arg64(54321),
|
||||
"syscall didn't match impl");
|
||||
|
||||
zassert_equal(syscall_arg64_big(1, 2, 3, 4, 5, 6),
|
||||
z_impl_syscall_arg64_big(1, 2, 3, 4, 5, 6),
|
||||
"syscall didn't match impl");
|
||||
}
|
||||
|
||||
K_MEM_POOL_DEFINE(test_pool, BUF_SIZE, BUF_SIZE, 4, 4);
|
||||
|
||||
void test_main(void)
|
||||
|
@ -216,6 +268,7 @@ void test_main(void)
|
|||
ztest_user_unit_test(test_string_nlen),
|
||||
ztest_user_unit_test(test_to_copy),
|
||||
ztest_user_unit_test(test_user_string_copy),
|
||||
ztest_user_unit_test(test_user_string_alloc_copy));
|
||||
ztest_user_unit_test(test_user_string_alloc_copy),
|
||||
ztest_user_unit_test(test_arg64));
|
||||
ztest_run_test_suite(syscalls);
|
||||
}
|
||||
|
|
|
@ -16,6 +16,11 @@ __syscall int to_copy(char *dest);
|
|||
|
||||
__syscall size_t string_nlen(char *src, size_t maxlen, int *err);
|
||||
|
||||
__syscall int syscall_arg64(u64_t arg);
|
||||
|
||||
__syscall u64_t syscall_arg64_big(u32_t arg1, u32_t arg2, u64_t arg3,
|
||||
u32_t arg4, u32_t arg5, u64_t arg6);
|
||||
|
||||
#include <syscalls/test_syscalls.h>
|
||||
|
||||
#endif /* _TEST_SYSCALLS_H_ */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue