Zephyr Project API 3.7.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
inherit.c File Reference
#include "mem_protect.h"
#include <zephyr/internal/syscall_handler.h>
#include <zephyr/sys/libc-hooks.h>
#include <zephyr/syscalls/ret_resource_pool_ptr_mrsh.c>

Functions

static void dummy_start (struct k_timer *timer)
 
static void dummy_end (struct k_timer *timer)
 
 K_THREAD_STACK_DEFINE (test_1_stack, CONFIG_MAIN_STACK_SIZE)
 
 K_THREAD_STACK_DEFINE (parent_thr_stack,(512+CONFIG_TEST_EXTRA_STACK_SIZE))
 
 K_THREAD_STACK_DEFINE (child_thr_stack,(512+CONFIG_TEST_EXTRA_STACK_SIZE))
 
 K_HEAP_DEFINE (heap_mem, 64 *2)
 
 K_SEM_DEFINE (inherit_sem,(0),(10))
 
 K_SEM_DEFINE (sync_sem,(0U),(1U))
 
 K_MUTEX_DEFINE (inherit_mutex)
 
 K_TIMER_DEFINE (inherit_timer, dummy_start, dummy_end)
 
 K_MSGQ_DEFINE (inherit_msgq,(10),(10),(2))
 
 K_MEM_PARTITION_DEFINE (inherit_memory_partition, inherit_buf, sizeof(inherit_buf), K_MEM_PARTITION_P_RW_U_RW)
 
static void access_test (void)
 
static void test_thread_1_for_user (void *p1, void *p2, void *p3)
 
static void test_thread_1_for_SU (void *p1, void *p2, void *p3)
 
 ZTEST (mem_protect, test_permission_inheritance)
 Test object permission inheritance except of the parent thread object.
 
void child_handler (void *p1, void *p2, void *p3)
 
void parent_handler (void *p1, void *p2, void *p3)
 
 ZTEST (mem_protect, test_inherit_resource_pool)
 Test child thread inherits parent's thread resource pool.
 
void mem_protect_inhert_setup (void)
 
 K_HEAP_DEFINE (test_mem_heap,(2<< CONFIG_MAX_THREAD_BYTES) *256)
 
void * mem_protect_setup (void)
 
 ZTEST_SUITE (mem_protect, NULL, mem_protect_setup, NULL, NULL, NULL)
 

Variables

struct k_thread test_1_tid parent_thr child_thr
 
k_tid_t parent_tid
 
uint8_t inherit_buf [MEM_REGION_ALLOC]
 
struct k_mem_partitioninherit_memory_partition_array []
 
struct k_mem_domain inherit_mem_domain
 
struct k_heapchild_heap_mem_ptr
 
struct k_heapparent_heap_mem_ptr
 

Function Documentation

◆ access_test()

static void access_test ( void  )
static

◆ child_handler()

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

◆ dummy_end()

static void dummy_end ( struct k_timer *  timer)
inlinestatic

◆ dummy_start()

static void dummy_start ( struct k_timer *  timer)
inlinestatic

◆ K_HEAP_DEFINE() [1/2]

K_HEAP_DEFINE ( heap_mem  ,
64 *  2 
)

◆ K_HEAP_DEFINE() [2/2]

K_HEAP_DEFINE ( test_mem_heap  ,
(2<< CONFIG_MAX_THREAD_BYTES) *  256 
)

◆ K_MEM_PARTITION_DEFINE()

K_MEM_PARTITION_DEFINE ( inherit_memory_partition  ,
inherit_buf  ,
sizeof(inherit_buf ,
K_MEM_PARTITION_P_RW_U_RW   
)

◆ K_MSGQ_DEFINE()

K_MSGQ_DEFINE ( inherit_msgq  ,
(10)  ,
(10)  ,
(2)   
)

◆ K_MUTEX_DEFINE()

K_MUTEX_DEFINE ( inherit_mutex  )

◆ K_SEM_DEFINE() [1/2]

K_SEM_DEFINE ( inherit_sem  ,
(0)  ,
(10)   
)

◆ K_SEM_DEFINE() [2/2]

K_SEM_DEFINE ( sync_sem  ,
(0U)  ,
(1U)   
)

◆ K_THREAD_STACK_DEFINE() [1/3]

K_THREAD_STACK_DEFINE ( child_thr_stack  ,
(512+CONFIG_TEST_EXTRA_STACK_SIZE)   
)

◆ K_THREAD_STACK_DEFINE() [2/3]

K_THREAD_STACK_DEFINE ( parent_thr_stack  ,
(512+CONFIG_TEST_EXTRA_STACK_SIZE)   
)

◆ K_THREAD_STACK_DEFINE() [3/3]

K_THREAD_STACK_DEFINE ( test_1_stack  ,
CONFIG_MAIN_STACK_SIZE   
)

◆ K_TIMER_DEFINE()

K_TIMER_DEFINE ( inherit_timer  ,
dummy_start  ,
dummy_end   
)

◆ mem_protect_inhert_setup()

void mem_protect_inhert_setup ( void  )

◆ mem_protect_setup()

void * mem_protect_setup ( void  )

◆ parent_handler()

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

◆ test_thread_1_for_SU()

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

◆ test_thread_1_for_user()

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

◆ ZTEST() [1/2]

ZTEST ( mem_protect  ,
test_inherit_resource_pool   
)

Test child thread inherits parent's thread resource pool.

  • Create a memory heap heap_mem for the parent thread.
  • Then special system call ret_resource_pool_ptr() returns pointer to the resource pool of the current thread.
  • Call it in the parent_handler() and in the child_handler()
  • Then in the main test function test_inherit_resource_pool() compare returned addresses
  • If the addresses are the same, it means that child thread inherited resource pool of the parent's thread -test passed.
See also
k_thread_heap_assign()

◆ ZTEST() [2/2]

ZTEST ( mem_protect  ,
test_permission_inheritance   
)

Test object permission inheritance except of the parent thread object.

  • To the parent current thread grant permissions on kernel objects.
  • Create a child thread and check that it inherited permissions on that kernel objects.
  • Then check child thread can't access to the parent thread object using API command k_thread_priority_get()
  • At the same moment that test verifies that child thread was granted permission on a kernel objects. That means child user thread caller already has permission on the thread objects being granted.
See also
k_mem_domain_init(), k_mem_domain_add_thread(), k_thread_access_grant()

◆ ZTEST_SUITE()

ZTEST_SUITE ( mem_protect  ,
NULL  ,
mem_protect_setup  ,
NULL  ,
NULL  ,
NULL   
)

Variable Documentation

◆ child_heap_mem_ptr

struct k_heap* child_heap_mem_ptr

◆ child_thr

struct k_thread test_1_tid parent_thr child_thr

◆ inherit_buf

uint8_t inherit_buf[MEM_REGION_ALLOC]

◆ inherit_mem_domain

struct k_mem_domain inherit_mem_domain

◆ inherit_memory_partition_array

struct k_mem_partition* inherit_memory_partition_array[]
Initial value:
= {
&inherit_memory_partition,
}
struct k_mem_partition ztest_mem_partition

◆ parent_heap_mem_ptr

struct k_heap* parent_heap_mem_ptr

◆ parent_tid

k_tid_t parent_tid