Zephyr Project API 3.7.0
A Scalable Open Source RTOS
|
#include <zephyr/kernel.h>
#include <zephyr/ztest.h>
#include <zephyr/kernel_structs.h>
#include <string.h>
#include <stdlib.h>
#include <zephyr/app_memory/app_memdomain.h>
#include <zephyr/sys/util.h>
#include <zephyr/sys/barrier.h>
#include <zephyr/debug/stack.h>
#include <zephyr/internal/syscall_handler.h>
#include "test_syscall.h"
#include <zephyr/sys/libc-hooks.h>
#include <zephyr/linker/linker-defs.h>
#include <zephyr/syscalls/check_syscall_context_mrsh.c>
Macros | |
#define | INFO(fmt, ...) printk(fmt, ##__VA_ARGS__) |
#define | PIPE_LEN 1 |
#define | BYTES_TO_READ_WRITE 1 |
#define | STACKSIZE (256 + CONFIG_TEST_EXTRA_STACK_SIZE) |
#define | test_oops(provided, expected) |
#define | KERNEL_ONLY_THREAD_STACK_SIZE (ROUND_UP(1024, CONFIG_MMU_PAGE_SIZE)) |
Functions | |
K_SEM_DEFINE (test_revoke_sem, 0, 1) | |
K_APPMEM_PARTITION_DEFINE (default_part) | |
K_APP_BMEM (default_part) volatile | |
static void | set_fault (unsigned int reason) |
void | k_sys_fatal_error_handler (unsigned int reason, const struct arch_esf *pEsf) |
Fatal error policy handler. | |
ZTEST_USER (userspace, test_is_usermode) | |
Test to check if the thread is in user mode. | |
ZTEST_USER (userspace, test_write_control) | |
Test to write to a control register. | |
ZTEST_USER (userspace, test_disable_mmu_mpu) | |
Test to disable memory protection. | |
ZTEST_USER (userspace, test_read_kernram) | |
Test to read from kernel RAM. | |
ZTEST_USER (userspace, test_write_kernram) | |
Test to write to kernel RAM. | |
ZTEST_USER (userspace, test_write_kernro) | |
Test to write kernel RO. | |
ZTEST_USER (userspace, test_write_kerntext) | |
Test to write to kernel text section. | |
ZTEST_USER (userspace, test_read_kernel_data) | |
Test to read from kernel data section. | |
ZTEST_USER (userspace, test_write_kernel_data) | |
Test to write to kernel data section. | |
K_APP_DMEM (default_part) volatile | |
ZTEST_USER (userspace, test_write_priv_stack) | |
Test to write to privilege stack. | |
ZTEST_USER (userspace, test_pass_noperms_object) | |
Test to pass object to a system call without permissions. | |
void | thread_body (void *p1, void *p2, void *p3) |
ZTEST_USER (userspace, test_start_kernel_thread) | |
Test to start kernel thread from usermode. | |
static void | uthread_read_body (void *p1, void *p2, void *p3) |
static void | uthread_write_body (void *p1, void *p2, void *p3) |
ZTEST_USER (userspace, test_read_other_stack) | |
Test to read from another thread's stack. | |
ZTEST_USER (userspace, test_write_other_stack) | |
Test to write to other thread's stack. | |
ZTEST_USER (userspace, test_revoke_noperms_object) | |
Test to revoke access to kobject without permission. | |
ZTEST_USER (userspace, test_access_after_revoke) | |
Test to access object after revoking access. | |
static void | umode_enter_func (void *p1, void *p2, void *p3) |
ZTEST (userspace, test_user_mode_enter) | |
Test to check supervisor thread enter one-way to usermode. | |
K_PIPE_DEFINE (kpipe, 1, 1) | |
ZTEST_USER (userspace, test_read_kobject_user_pipe) | |
Test to read from kobject using pipe. | |
static void | user_half (void *arg1, void *arg2, void *arg3) |
static void | spawn_user (volatile bool *to_modify) |
static void | drop_user (volatile bool *to_modify) |
ZTEST (userspace_domain, test_1st_init_and_access_other_memdomain) | |
Test creation of new memory domains. | |
ZTEST (userspace_domain, test_domain_add_thread_drop_to_user) | |
Show that changing between memory domains and dropping to user mode works as expected. | |
ZTEST (userspace_domain, test_domain_add_part_drop_to_user) | |
ZTEST (userspace_domain, test_domain_remove_part_drop_to_user) | |
Show that self-removing a partition from a domain we are a member of, and then dropping to user mode faults as expected. | |
ZTEST (userspace_domain_ctx, test_domain_add_thread_context_switch) | |
Show that changing between memory domains and then switching to another thread in the same domain works as expected. | |
ZTEST (userspace_domain_ctx, test_domain_add_part_context_switch) | |
ZTEST (userspace_domain_ctx, test_domain_remove_part_context_switch) | |
Show that self-removing a partition from a domain we are a member of, and then switching to another user thread in the same domain faults as expected. | |
ZTEST_USER (userspace, test_unimplemented_syscall) | |
Test unimplemented system call. | |
ZTEST_USER (userspace, test_bad_syscall) | |
Test bad syscall handler. | |
ZTEST (userspace, test_object_recycle) | |
Test recycle object. | |
ZTEST_USER (userspace, test_oops_panic) | |
ZTEST_USER (userspace, test_oops_oops) | |
ZTEST_USER (userspace, test_oops_exception) | |
ZTEST_USER (userspace, test_oops_maxint) | |
ZTEST_USER (userspace, test_oops_stackcheck) | |
ZTEST_USER (userspace, test_syscall_context) | |
ZTEST (userspace, test_tls_leakage) | |
ZTEST (userspace, test_tls_pointer) | |
void | kernel_only_thread_entry (void *p1, void *p2, void *p3) |
static | K_KERNEL_THREAD_DEFINE (kernel_only_thread,(ROUND_UP(1024, CONFIG_MMU_PAGE_SIZE)), kernel_only_thread_entry, NULL, NULL, NULL, 0, 0, 0) |
ZTEST (userspace, test_kernel_only_thread) | |
void * | userspace_setup (void) |
ZTEST_SUITE (userspace, NULL, userspace_setup, NULL, NULL, NULL) | |
ZTEST_SUITE (userspace_domain, NULL, NULL, NULL, NULL, NULL) | |
ZTEST_SUITE (userspace_domain_ctx, NULL, NULL, NULL, NULL, NULL) | |
Variables | |
struct k_mem_domain | alternate_domain |
static ZTEST_BMEM volatile bool | expect_fault |
static ZTEST_BMEM volatile unsigned int | expected_reason |
static int | kernel_data |
static struct k_sem | ksem |
k_thread_stack_t | ztest_thread_stack [] |
static struct k_sem | recycle_sem |
#define BYTES_TO_READ_WRITE 1 |
#define INFO | ( | fmt, | |
... | |||
) | printk(fmt, ##__VA_ARGS__) |
#define KERNEL_ONLY_THREAD_STACK_SIZE (ROUND_UP(1024, CONFIG_MMU_PAGE_SIZE)) |
#define PIPE_LEN 1 |
#define STACKSIZE (256 + CONFIG_TEST_EXTRA_STACK_SIZE) |
#define test_oops | ( | provided, | |
expected | |||
) |
|
static |
K_APP_BMEM | ( | default_part | ) | volatile |
K_APP_DMEM | ( | default_part | ) | volatile |
K_APPMEM_PARTITION_DEFINE | ( | default_part | ) |
|
static |
K_PIPE_DEFINE | ( | kpipe | , |
1 | , | ||
1 | |||
) |
K_SEM_DEFINE | ( | test_revoke_sem | , |
0 | , | ||
1 | |||
) |
void kernel_only_thread_entry | ( | void * | p1, |
void * | p2, | ||
void * | p3 | ||
) |
|
static |
|
static |
void thread_body | ( | void * | p1, |
void * | p2, | ||
void * | p3 | ||
) |
|
static |
|
static |
void * userspace_setup | ( | void | ) |
|
static |
|
static |
ZTEST | ( | userspace | , |
test_kernel_only_thread | |||
) |
ZTEST | ( | userspace | , |
test_object_recycle | |||
) |
Test recycle object.
Test recycle valid/invalid kernel object, see if perms_count changes as expected.
ZTEST | ( | userspace | , |
test_tls_leakage | |||
) |
ZTEST | ( | userspace | , |
test_tls_pointer | |||
) |
ZTEST | ( | userspace | , |
test_user_mode_enter | |||
) |
Test to check supervisor thread enter one-way to usermode.
A thread running in supervisor mode must have one-way operation ability to drop privileges to user mode.
ZTEST | ( | userspace_domain | , |
test_1st_init_and_access_other_memdomain | |||
) |
Test creation of new memory domains.
We initialize a new memory domain and show that its partition configuration is correct. This new domain has "alt_part" in it, but not "default_part". We then try to modify data in "default_part" and show it produces an exception since that partition is not in the new domain.
This caught a bug once where an MMU system copied page tables for the new domain and accidentally copied memory partition permissions from the source page tables, allowing the write to "default_part" to work.
ZTEST | ( | userspace_domain | , |
test_domain_add_part_drop_to_user | |||
) |
ZTEST | ( | userspace_domain | , |
test_domain_add_thread_drop_to_user | |||
) |
Show that changing between memory domains and dropping to user mode works as expected.
ZTEST | ( | userspace_domain | , |
test_domain_remove_part_drop_to_user | |||
) |
Show that self-removing a partition from a domain we are a member of, and then dropping to user mode faults as expected.
ZTEST | ( | userspace_domain_ctx | , |
test_domain_add_part_context_switch | |||
) |
ZTEST | ( | userspace_domain_ctx | , |
test_domain_add_thread_context_switch | |||
) |
Show that changing between memory domains and then switching to another thread in the same domain works as expected.
ZTEST | ( | userspace_domain_ctx | , |
test_domain_remove_part_context_switch | |||
) |
Show that self-removing a partition from a domain we are a member of, and then switching to another user thread in the same domain faults as expected.
ZTEST_SUITE | ( | userspace | , |
NULL | , | ||
userspace_setup | , | ||
NULL | , | ||
NULL | , | ||
NULL | |||
) |
ZTEST_SUITE | ( | userspace_domain | , |
NULL | , | ||
NULL | , | ||
NULL | , | ||
NULL | , | ||
NULL | |||
) |
ZTEST_SUITE | ( | userspace_domain_ctx | , |
NULL | , | ||
NULL | , | ||
NULL | , | ||
NULL | , | ||
NULL | |||
) |
ZTEST_USER | ( | userspace | , |
test_access_after_revoke | |||
) |
Test to access object after revoking access.
ZTEST_USER | ( | userspace | , |
test_bad_syscall | |||
) |
Test bad syscall handler.
When a system call handler decides to terminate the calling thread, the kernel will produce error which indicates the context, where the faulting system call was made from user code.
ZTEST_USER | ( | userspace | , |
test_disable_mmu_mpu | |||
) |
Test to disable memory protection.
ZTEST_USER | ( | userspace | , |
test_is_usermode | |||
) |
Test to check if the thread is in user mode.
ZTEST_USER | ( | userspace | , |
test_oops_exception | |||
) |
ZTEST_USER | ( | userspace | , |
test_oops_maxint | |||
) |
ZTEST_USER | ( | userspace | , |
test_oops_oops | |||
) |
ZTEST_USER | ( | userspace | , |
test_oops_panic | |||
) |
ZTEST_USER | ( | userspace | , |
test_oops_stackcheck | |||
) |
ZTEST_USER | ( | userspace | , |
test_pass_noperms_object | |||
) |
Test to pass object to a system call without permissions.
ZTEST_USER | ( | userspace | , |
test_read_kernel_data | |||
) |
Test to read from kernel data section.
ZTEST_USER | ( | userspace | , |
test_read_kernram | |||
) |
Test to read from kernel RAM.
ZTEST_USER | ( | userspace | , |
test_read_kobject_user_pipe | |||
) |
Test to read from kobject using pipe.
ZTEST_USER | ( | userspace | , |
test_read_other_stack | |||
) |
Test to read from another thread's stack.
ZTEST_USER | ( | userspace | , |
test_revoke_noperms_object | |||
) |
Test to revoke access to kobject without permission.
User thread can only revoke their own access to an object. In that test user thread to revokes access to unathorized object, as a result the system will assert.
ZTEST_USER | ( | userspace | , |
test_start_kernel_thread | |||
) |
Test to start kernel thread from usermode.
ZTEST_USER | ( | userspace | , |
test_syscall_context | |||
) |
ZTEST_USER | ( | userspace | , |
test_unimplemented_syscall | |||
) |
Test unimplemented system call.
Created a syscall with name missing_syscall() without a verification function. The kernel shall safety handle invocations of unimplemented system calls.
ZTEST_USER | ( | userspace | , |
test_write_control | |||
) |
Test to write to a control register.
ZTEST_USER | ( | userspace | , |
test_write_kernel_data | |||
) |
Test to write to kernel data section.
ZTEST_USER | ( | userspace | , |
test_write_kernram | |||
) |
Test to write to kernel RAM.
ZTEST_USER | ( | userspace | , |
test_write_kernro | |||
) |
Test to write kernel RO.
ZTEST_USER | ( | userspace | , |
test_write_kerntext | |||
) |
Test to write to kernel text section.
ZTEST_USER | ( | userspace | , |
test_write_other_stack | |||
) |
Test to write to other thread's stack.
ZTEST_USER | ( | userspace | , |
test_write_priv_stack | |||
) |
Test to write to privilege stack.
struct k_mem_domain alternate_domain |
|
static |
|
static |
|
static |
|
static |
|
static |
|
extern |