Skip to content

Commit 6f9f8c1

Browse files
keith-packardstephanosio
authored andcommitted
samples, tests: Add z_libc_partition to all test domains
When a memory domain is initialized, the z_libc_partition must be included so that critical libc-related data can be accessed. On ARM processors without TPIDRURO when THREAD_LOCAL_STORAGE is enabled, this includes the TLS base pointer, which is used for several thread-local variables in the kernel. Signed-off-by: Keith Packard <[email protected]>
1 parent 19c8956 commit 6f9f8c1

File tree

5 files changed

+42
-8
lines changed

5 files changed

+42
-8
lines changed

samples/userspace/shared_mem/src/main.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
#include <sys/__assert.h>
18+
#include <sys/libc-hooks.h> /* for z_libc_partition */
1819

1920
#include "main.h"
2021
#include "enc.h"
@@ -101,8 +102,18 @@ _app_ct_d char ctMSG[] = "CT!\n";
101102

102103
void main(void)
103104
{
104-
struct k_mem_partition *enc_parts[] = {&enc_part, &red_part, &blk_part};
105-
struct k_mem_partition *pt_parts[] = {&user_part, &red_part};
105+
struct k_mem_partition *enc_parts[] = {
106+
#if Z_LIBC_PARTITION_EXISTS
107+
&z_libc_partition,
108+
#endif
109+
&enc_part, &red_part, &blk_part
110+
};
111+
struct k_mem_partition *pt_parts[] = {
112+
#if Z_LIBC_PARTITION_EXISTS
113+
&z_libc_partition,
114+
#endif
115+
&user_part, &red_part
116+
};
106117
k_tid_t tPT, tENC, tCT;
107118
int ret;
108119

@@ -129,7 +140,7 @@ void main(void)
129140
/* use K_FOREVER followed by k_thread_start*/
130141
printk("ENC Thread Created %p\n", tENC);
131142

132-
ret = k_mem_domain_init(&enc_domain, 3, enc_parts);
143+
ret = k_mem_domain_init(&enc_domain, ARRAY_SIZE(enc_parts), enc_parts);
133144
__ASSERT(ret == 0, "k_mem_domain_init() on enc_domain failed %d", ret);
134145
ARG_UNUSED(ret);
135146

@@ -145,7 +156,7 @@ void main(void)
145156
k_thread_access_grant(tPT, &allforone);
146157
printk("PT Thread Created %p\n", tPT);
147158

148-
ret = k_mem_domain_init(&pt_domain, 2, pt_parts);
159+
ret = k_mem_domain_init(&pt_domain, ARRAY_SIZE(pt_parts), pt_parts);
149160
__ASSERT(ret == 0, "k_mem_domain_init() on pt_domain failed %d", ret);
150161

151162
k_mem_domain_add_thread(&pt_domain, tPT);

tests/benchmarks/footprints/src/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include <kernel.h>
1414
#include <zephyr.h>
1515
#include <ksched.h>
16-
16+
#include <sys/libc-hooks.h>
1717
#include "footprint.h"
1818

1919
#ifdef CONFIG_USERSPACE
@@ -44,7 +44,10 @@ void main(void)
4444
#ifdef CONFIG_USERSPACE
4545
int ret;
4646
struct k_mem_partition *mem_parts[] = {
47-
&footprint_mem_partition
47+
#if Z_LIBC_PARTITION_EXISTS
48+
&z_libc_partition,
49+
#endif
50+
&footprint_mem_partition
4851
};
4952

5053
ret = k_mem_domain_init(&footprint_mem_domain,

tests/kernel/mem_protect/mem_protect/src/inherit.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "mem_protect.h"
88
#include <syscall_handler.h>
9+
#include <sys/libc-hooks.h> /* for z_libc_partition */
910

1011
/* function prototypes */
1112
static inline void dummy_start(struct k_timer *timer)
@@ -38,6 +39,9 @@ K_MEM_PARTITION_DEFINE(inherit_memory_partition,
3839
K_MEM_PARTITION_P_RW_U_RW);
3940

4041
struct k_mem_partition *inherit_memory_partition_array[] = {
42+
#if Z_LIBC_PARTITION_EXISTS
43+
&z_libc_partition,
44+
#endif
4145
&inherit_memory_partition,
4246
&ztest_mem_partition
4347
};

tests/kernel/mem_protect/mem_protect/src/mem_domain.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,19 @@
66

77
#include "mem_protect.h"
88
#include <kernel_internal.h> /* For z_main_thread */
9+
#include <sys/libc-hooks.h> /* for z_libc_partition */
910

1011
static struct k_thread child_thread;
1112
static K_THREAD_STACK_DEFINE(child_stack, 512 + CONFIG_TEST_EXTRA_STACK_SIZE);
1213

1314
/* Special memory domain for test case purposes */
1415
static struct k_mem_domain test_domain;
1516

17+
#if Z_LIBC_PARTITION_EXISTS
18+
#define PARTS_USED 3
19+
#else
1620
#define PARTS_USED 2
21+
#endif
1722
/* Maximum number of allowable memory partitions defined by the build */
1823
#define NUM_RW_PARTS (CONFIG_MAX_DOMAIN_PARTITIONS - PARTS_USED)
1924

@@ -45,7 +50,12 @@ static K_THREAD_DEFINE(zzz_thread, 256 + CONFIG_TEST_EXTRA_STACK_SIZE,
4550
void test_mem_domain_setup(void)
4651
{
4752
int max_parts = arch_mem_domain_max_partitions_get();
48-
struct k_mem_partition *parts[] = { &ro_part, &ztest_mem_partition };
53+
struct k_mem_partition *parts[] = {
54+
#if Z_LIBC_PARTITION_EXISTS
55+
&z_libc_partition,
56+
#endif
57+
&ro_part, &ztest_mem_partition
58+
};
4959

5060
num_rw_parts = max_parts - PARTS_USED;
5161
zassert_true(num_rw_parts <= NUM_RW_PARTS,

tests/kernel/mem_protect/userspace/src/main.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <debug/stack.h>
1818
#include <syscall_handler.h>
1919
#include "test_syscall.h"
20+
#include <sys/libc-hooks.h> /* for z_libc_partition */
2021

2122
#if defined(CONFIG_ARC)
2223
#include <arch/arc/v2/mpu/arc_core_mpu.h>
@@ -680,7 +681,12 @@ static void drop_user(volatile bool *to_modify)
680681
*/
681682
static void test_init_and_access_other_memdomain(void)
682683
{
683-
struct k_mem_partition *parts[] = { &ztest_mem_partition, &alt_part };
684+
struct k_mem_partition *parts[] = {
685+
#if Z_LIBC_PARTITION_EXISTS
686+
&z_libc_partition,
687+
#endif
688+
&ztest_mem_partition, &alt_part
689+
};
684690

685691
zassert_equal(
686692
k_mem_domain_init(&alternate_domain, ARRAY_SIZE(parts), parts),

0 commit comments

Comments
 (0)