Zephyr API Documentation
3.0.0
A Scalable Open Source RTOS
|
|
3.0.0 |
#include <zephyr.h>
#include <ztest.h>
#include <kernel_structs.h>
#include <string.h>
#include <stdlib.h>
#include <app_memory/app_memdomain.h>
#include <sys/util.h>
#include <debug/stack.h>
#include <syscall_handler.h>
#include "test_syscall.h"
#include <linker/linker-defs.h>
#include <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_STACKSIZE) |
#define | test_oops(provided, expected) |
Functions | |
K_SEM_DEFINE (test_revoke_sem, 0, 1) | |
K_APPMEM_PARTITION_DEFINE (default_part) | |
K_APP_BMEM (default_part) | |
Test to pass a user object to system call. More... | |
static void | set_fault (unsigned int reason) |
void | k_sys_fatal_error_handler (unsigned int reason, const z_arch_esf_t *pEsf) |
Fatal error policy handler. More... | |
static void | test_is_usermode (void) |
Test to check if the thread is in user mode. More... | |
static void | test_write_control (void) |
Test to write to a control register. More... | |
static void | test_disable_mmu_mpu (void) |
Test to disable memory protection. More... | |
static void | test_read_kernram (void) |
Test to read from kernel RAM. More... | |
static void | test_write_kernram (void) |
Test to write to kernel RAM. More... | |
static void | test_write_kernro (void) |
Test to write kernel RO. More... | |
static void | test_write_kerntext (void) |
Test to write to kernel text section. More... | |
static void | test_read_kernel_data (void) |
Test to read from kernel data section. More... | |
static void | test_write_kernel_data (void) |
Test to write to kernel data section. More... | |
K_APP_DMEM (default_part) volatile | |
Test to read provileged stack. More... | |
static void | test_write_priv_stack (void) |
Test to write to privilege stack. More... | |
static void | test_pass_noperms_object (void) |
Test to pass object to a system call without permissions. More... | |
void | thread_body (void) |
static void | test_start_kernel_thread (void) |
Test to start kernel thread from usermode. More... | |
static void | test_read_other_stack (void) |
static void | test_write_other_stack (void) |
static void | test_revoke_noperms_object (void) |
Test to revoke access to kobject without permission. More... | |
static void | test_access_after_revoke (void) |
Test to access object after revoking access. More... | |
static void | umode_enter_func (void) |
static void | test_user_mode_enter (void) |
Test to check supervisor thread enter one-way to usermode. More... | |
K_PIPE_DEFINE (kpipe, 1, 1) | |
static void | test_read_kobject_user_pipe (void) |
Test to read from kobject using pipe. More... | |
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) |
static void | test_init_and_access_other_memdomain (void) |
Test creation of new memory domains. More... | |
static void | test_domain_add_thread_drop_to_user (void) |
static void | test_domain_add_part_drop_to_user (void) |
static void | test_domain_remove_part_drop_to_user (void) |
static void | test_domain_add_thread_context_switch (void) |
static void | test_domain_add_part_context_switch (void) |
static void | test_domain_remove_part_context_switch (void) |
void | test_unimplemented_syscall (void) |
Test unimplemented system call. More... | |
void | test_bad_syscall (void) |
Test bad syscall handler. More... | |
void | test_object_recycle (void) |
Test recycle object. More... | |
void | test_oops_panic (void) |
void | test_oops_oops (void) |
void | test_oops_exception (void) |
void | test_oops_maxint (void) |
void | test_oops_stackcheck (void) |
void | test_syscall_context (void) |
static void | tls_leakage_user_part (void *p1, void *p2, void *p3) |
void | test_tls_leakage (void) |
void | tls_entry (void *p1, void *p2, void *p3) |
void | test_tls_pointer (void) |
void | test_main (void) |
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 PIPE_LEN 1 |
#define STACKSIZE (256 + CONFIG_TEST_EXTRA_STACKSIZE) |
#define test_oops | ( | provided, | |
expected | |||
) |
|
static |
K_APP_BMEM | ( | default_part | ) | volatile |
Test to pass a user object to system call.
Test to write to kobject using pipe.
K_APP_DMEM | ( | default_part | ) | volatile |
Test to read provileged stack.
K_APPMEM_PARTITION_DEFINE | ( | default_part | ) |
K_PIPE_DEFINE | ( | kpipe | , |
1 | , | ||
1 | |||
) |
K_SEM_DEFINE | ( | test_revoke_sem | , |
0 | , | ||
1 | |||
) |
|
static |
|
static |
|
static |
Test to access object after revoking access.
void test_bad_syscall | ( | void | ) |
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.
|
static |
Test to disable memory protection.
|
static |
|
static |
|
static |
Show that changing between memory domains and then switching to another thread in the same domain works as expected.
|
static |
Show that changing between memory domains and dropping to user mode works as expected.
|
static |
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.
|
static |
Show that self-removing a partition from a domain we are a member of, and then dropping to user mode faults as expected.
|
static |
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.
|
static |
Test to check if the thread is in user mode.
void test_main | ( | void | ) |
test case main entry
void test_object_recycle | ( | void | ) |
Test recycle object.
Test recycle valid/invalid kernel object, see if perms_count changes as expected.
void test_oops_exception | ( | void | ) |
void test_oops_maxint | ( | void | ) |
void test_oops_oops | ( | void | ) |
void test_oops_panic | ( | void | ) |
void test_oops_stackcheck | ( | void | ) |
|
static |
Test to pass object to a system call without permissions.
|
static |
Test to read from kernel data section.
|
static |
Test to read from kernel RAM.
|
static |
Test to read from kobject using pipe.
|
static |
|
static |
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.
|
static |
Test to start kernel thread from usermode.
void test_syscall_context | ( | void | ) |
void test_tls_leakage | ( | void | ) |
void test_tls_pointer | ( | void | ) |
void test_unimplemented_syscall | ( | void | ) |
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.
|
static |
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.
|
static |
Test to write to a control register.
|
static |
Test to write to kernel data section.
|
static |
Test to write to kernel RAM.
|
static |
Test to write kernel RO.
|
static |
Test to write to kernel text section.
|
static |
|
static |
Test to write to privilege stack.
void thread_body | ( | void | ) |
void tls_entry | ( | void * | p1, |
void * | p2, | ||
void * | p3 | ||
) |
|
static |
|
static |
|
static |
struct k_mem_domain alternate_domain |
|
static |
|
static |
|
static |
|
static |
|
static |
|
extern |