Zephyr API Documentation 4.1.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
main.c File Reference
#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, ...)
 
#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)
 Test to pass a user object to system call.
 
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.
 
void test_is_usermode (void)
 Test to check if the thread is in user mode.
 
void test_write_control (void)
 Test to write to a control register.
 
void test_disable_mmu_mpu (void)
 Test to disable memory protection.
 
void test_read_kernram (void)
 Test to read from kernel RAM.
 
void test_write_kernram (void)
 Test to write to kernel RAM.
 
void test_write_kernro (void)
 Test to write kernel RO.
 
void test_write_kerntext (void)
 Test to write to kernel text section.
 
void test_read_kernel_data (void)
 Test to read from kernel data section.
 
void test_write_kernel_data (void)
 Test to write to kernel data section.
 
 K_APP_DMEM (default_part) volatile
 Test to read privileged stack.
 
void test_write_priv_stack (void)
 Test to write to privilege stack.
 
void test_pass_noperms_object (void)
 Test to pass object to a system call without permissions.
 
void thread_body (void *p1, void *p2, void *p3)
 
void test_start_kernel_thread (void)
 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)
 
void test_read_other_stack (void)
 Test to read from another thread's stack.
 
void test_write_other_stack (void)
 Test to write to other thread's stack.
 
void test_revoke_noperms_object (void)
 Test to revoke access to kobject without permission.
 
void test_access_after_revoke (void)
 Test to access object after revoking access.
 
static void umode_enter_func (void *p1, void *p2, void *p3)
 
void test_user_mode_enter (void)
 Test to check supervisor thread enter one-way to usermode.
 
 K_PIPE_DEFINE (kpipe, 1, 1)
 
void test_write_kobject_user_pipe (void)
 Test to write to kobject using pipe.
 
void test_read_kobject_user_pipe (void)
 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)
 
void test_1st_init_and_access_other_memdomain (void)
 Test creation of new memory domains.
 
void test_domain_add_thread_drop_to_user (void)
 Show that changing between memory domains and dropping to user mode works as expected.
 
void test_domain_add_part_drop_to_user (void)
 
void test_domain_remove_part_drop_to_user (void)
 Show that self-removing a partition from a domain we are a member of, and then dropping to user mode faults as expected.
 
void test_domain_add_thread_context_switch (void)
 Show that changing between memory domains and then switching to another thread in the same domain works as expected.
 
void test_domain_add_part_context_switch (void)
 
void test_domain_remove_part_context_switch (void)
 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.
 
void test_unimplemented_syscall (void)
 Test unimplemented system call.
 
void test_bad_syscall (void)
 Test bad syscall handler.
 
void test_object_recycle (void)
 Test recycle object.
 
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)
 
void test_tls_leakage (void)
 
void test_tls_pointer (void)
 
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)
 
void test_kernel_only_thread (void)
 
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
 

Macro Definition Documentation

◆ BYTES_TO_READ_WRITE

#define BYTES_TO_READ_WRITE   1

◆ INFO

#define INFO ( fmt,
... )
Value:
printk(fmt, ##__VA_ARGS__)
static void printk(const char *fmt,...)
Print kernel debugging message.
Definition printk.h:51

◆ KERNEL_ONLY_THREAD_STACK_SIZE

#define KERNEL_ONLY_THREAD_STACK_SIZE   (ROUND_UP(1024, CONFIG_MMU_PAGE_SIZE))

◆ PIPE_LEN

#define PIPE_LEN   1

◆ STACKSIZE

#define STACKSIZE   (256 + CONFIG_TEST_EXTRA_STACK_SIZE)

◆ test_oops

#define test_oops ( provided,
expected )
Value:
do { \
expect_fault = true; \
z_except_reason(provided); \
} while (false)
static ZTEST_BMEM volatile bool expect_fault
Definition main.c:53
static ZTEST_BMEM volatile unsigned int expected_reason
Definition main.c:54
static ZTEST_BMEM struct thread_data expected

Function Documentation

◆ drop_user()

static void drop_user ( volatile bool * to_modify)
static

◆ K_APPMEM_PARTITION_DEFINE()

K_APPMEM_PARTITION_DEFINE ( default_part )

◆ K_KERNEL_THREAD_DEFINE()

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  )
static

◆ K_PIPE_DEFINE()

K_PIPE_DEFINE ( kpipe ,
1 ,
1  )

◆ K_SEM_DEFINE()

K_SEM_DEFINE ( test_revoke_sem ,
0 ,
1  )

◆ kernel_only_thread_entry()

void kernel_only_thread_entry ( void * p1,
void * p2,
void * p3 )

◆ set_fault()

static void set_fault ( unsigned int reason)
static

◆ spawn_user()

static void spawn_user ( volatile bool * to_modify)
static

◆ test_domain_add_part_context_switch()

void test_domain_add_part_context_switch ( void )

◆ test_domain_add_part_drop_to_user()

void test_domain_add_part_drop_to_user ( void )

◆ test_kernel_only_thread()

void test_kernel_only_thread ( void )

◆ test_oops_exception()

void test_oops_exception ( void )

◆ test_oops_maxint()

void test_oops_maxint ( void )

◆ test_oops_oops()

void test_oops_oops ( void )

◆ test_oops_panic()

void test_oops_panic ( void )

◆ test_oops_stackcheck()

void test_oops_stackcheck ( void )

◆ test_syscall_context()

void test_syscall_context ( void )

◆ test_tls_leakage()

void test_tls_leakage ( void )

◆ test_tls_pointer()

void test_tls_pointer ( void )

◆ thread_body()

void thread_body ( void * p1,
void * p2,
void * p3 )

◆ umode_enter_func()

static void umode_enter_func ( void * p1,
void * p2,
void * p3 )
static

◆ user_half()

static void user_half ( void * arg1,
void * arg2,
void * arg3 )
static

◆ userspace_setup()

void * userspace_setup ( void )

◆ uthread_read_body()

static void uthread_read_body ( void * p1,
void * p2,
void * p3 )
static

◆ uthread_write_body()

static void uthread_write_body ( void * p1,
void * p2,
void * p3 )
static

◆ ZTEST_SUITE() [1/3]

ZTEST_SUITE ( userspace ,
NULL ,
userspace_setup ,
NULL ,
NULL ,
NULL  )

◆ ZTEST_SUITE() [2/3]

ZTEST_SUITE ( userspace_domain ,
NULL ,
NULL ,
NULL ,
NULL ,
NULL  )

◆ ZTEST_SUITE() [3/3]

ZTEST_SUITE ( userspace_domain_ctx ,
NULL ,
NULL ,
NULL ,
NULL ,
NULL  )

Variable Documentation

◆ alternate_domain

struct k_mem_domain alternate_domain

◆ expect_fault

ZTEST_BMEM volatile bool expect_fault
static

◆ expected_reason

ZTEST_BMEM volatile unsigned int expected_reason
static

◆ kernel_data

int kernel_data
static

◆ ksem

struct k_sem ksem
static

◆ recycle_sem

struct k_sem recycle_sem
static

◆ ztest_thread_stack

k_thread_stack_t ztest_thread_stack[]
extern