Skip to content

Commit 17ce822

Browse files
Andrew Boienashif
authored andcommitted
app_shmem: create generic libc partition
We need a generic name for the partition containing essential C library globals. We're going to need to add the stack canary guard to this area so user mode can read it. Signed-off-by: Andrew Boie <[email protected]>
1 parent 80e3a2c commit 17ce822

File tree

5 files changed

+12
-23
lines changed

5 files changed

+12
-23
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,7 @@ if(CONFIG_APP_SHARED_MEM AND CONFIG_USERSPACE)
11571157
)
11581158

11591159
if(CONFIG_NEWLIB_LIBC)
1160-
set(NEWLIB_PART -l libc.a z_newlib_partition)
1160+
set(NEWLIB_PART -l libc.a z_libc_partition)
11611161
endif()
11621162
add_custom_command(
11631163
OUTPUT ${APP_SMEM_LD}

include/misc/libc-hooks.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,6 @@ __syscall int _zephyr_read(char *buf, int nbytes);
2727

2828
__syscall int _zephyr_write(const void *buf, int nbytes);
2929

30-
#ifdef CONFIG_APP_SHARED_MEM
31-
/* Memory partition containing newlib's globals. This includes all the globals
32-
* within libc.a and the supporting zephyr hooks, but not the malloc arena.
33-
*/
34-
extern struct k_mem_partition z_newlib_partition;
35-
#endif /* CONFIG_APP_SHARED_MEM */
36-
3730
#else
3831
/* Minimal libc */
3932

@@ -46,6 +39,9 @@ __syscall size_t _zephyr_fwrite(const void *_MLIBC_RESTRICT ptr, size_t size,
4639
#ifdef CONFIG_APP_SHARED_MEM
4740
/* Memory partition containing the libc malloc arena */
4841
extern struct k_mem_partition z_malloc_partition;
42+
43+
/* C library globals, except the malloc arena */
44+
extern struct k_mem_partition z_libc_partition;
4945
#endif
5046

5147
#include <syscalls/libc-hooks.h>

kernel/userspace.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
#include <device.h>
1818
#include <init.h>
1919
#include <stdbool.h>
20+
#include <app_memory/app_memdomain.h>
21+
22+
K_APPMEM_PARTITION_DEFINE(z_libc_partition);
2023

2124
#define LOG_LEVEL CONFIG_KERNEL_LOG_LEVEL
2225
#include <logging/log.h>

lib/libc/newlib/libc-hooks.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,14 @@
1717
#include <app_memory/app_memdomain.h>
1818
#include <init.h>
1919

20-
#ifdef CONFIG_APP_SHARED_MEM
21-
K_APPMEM_PARTITION_DEFINE(z_newlib_partition);
22-
#define LIBC_BSS K_APP_BMEM(z_newlib_partition)
23-
#define LIBC_DATA K_APP_DMEM(z_newlib_partition)
20+
#define LIBC_BSS K_APP_BMEM(z_libc_partition)
21+
#define LIBC_DATA K_APP_DMEM(z_libc_partition)
2422

2523
#if CONFIG_NEWLIB_LIBC_ALIGNED_HEAP_SIZE
2624
K_APPMEM_PARTITION_DEFINE(z_malloc_partition);
2725
#define MALLOC_BSS K_APP_BMEM(z_malloc_partition)
2826
#endif /* CONFIG_NEWLIB_LIBC_ALIGNED_HEAP_SIZE */
2927

30-
#else
31-
#define LIBC_BSS
32-
#define LIBC_DATA
33-
#define MALLOC_BSS
34-
#endif /* CONFIG_APP_SHARED_MEM */
35-
3628
#define USED_RAM_END_ADDR POINTER_TO_UINT(&_end)
3729

3830
#if CONFIG_NEWLIB_LIBC_ALIGNED_HEAP_SIZE

subsys/testsuite/ztest/src/ztest.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,9 @@ void main(void)
302302
#ifdef CONFIG_APP_SHARED_MEM
303303
struct k_mem_partition *parts[] = {
304304
&ztest_mem_partition,
305-
#ifdef CONFIG_NEWLIB_LIBC
306-
/* Newlib libc.a library and hooks globals */
307-
&z_newlib_partition,
308-
#endif
309-
/* Both minimal and newlib libc expose this for malloc arena */
305+
/* C library globals, stack canary storage, etc */
306+
&z_libc_partition,
307+
/* Required for access to malloc arena */
310308
&z_malloc_partition
311309
};
312310

0 commit comments

Comments
 (0)