Zephyr Project API 3.7.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
libc-hooks.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018, Intel Corporation.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef ZEPHYR_INCLUDE_SYS_LIBC_HOOKS_H_
8#define ZEPHYR_INCLUDE_SYS_LIBC_HOOKS_H_
9
10#include <zephyr/toolchain.h>
12#include <stdio.h>
13#include <stddef.h>
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
19/*
20 * Private header for specifying accessory functions to the C library internals
21 * that need to call into the kernel as system calls
22 */
23
24#if defined(CONFIG_NEWLIB_LIBC) || defined(CONFIG_ARCMWDT_LIBC)
25
26/* syscall generation ignores preprocessor, ensure this is defined to ensure
27 * we don't have compile errors
28 */
29__syscall int zephyr_read_stdin(char *buf, int nbytes);
30
31__syscall int zephyr_write_stdout(const void *buf, int nbytes);
32
33#else
34/* Minimal libc and picolibc */
35
36__syscall int zephyr_fputc(int c, FILE * stream);
37
38#ifdef CONFIG_MINIMAL_LIBC
39/* Minimal libc only */
40
41__syscall size_t zephyr_fwrite(const void *ZRESTRICT ptr, size_t size,
42 size_t nitems, FILE *ZRESTRICT stream);
43#endif
44
45#endif /* CONFIG_NEWLIB_LIBC */
46
47#ifdef CONFIG_USERSPACE
48#ifdef CONFIG_COMMON_LIBC_MALLOC
49
50/* When using the common malloc implementation with CONFIG_USERSPACE, the
51 * heap will be in a separate partition when there's an MPU or MMU
52 * available.
53 */
54#if CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE != 0 && \
55(defined(CONFIG_MPU) || defined(CONFIG_MMU))
56#define Z_MALLOC_PARTITION_EXISTS 1
57#endif
58
59#elif defined(CONFIG_NEWLIB_LIBC)
60/* If we are using newlib, the heap arena is in one of two areas:
61 * - If we have an MPU that requires power of two alignment, the heap bounds
62 * must be specified in Kconfig via CONFIG_NEWLIB_LIBC_ALIGNED_HEAP_SIZE.
63 * - Otherwise, the heap arena on most arches starts at a suitably
64 * aligned base address after the `_end` linker symbol, through to the end
65 * of system RAM.
66 */
67#if (!defined(CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT) || \
68 (defined(CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT) && \
69 CONFIG_NEWLIB_LIBC_ALIGNED_HEAP_SIZE))
70#define Z_MALLOC_PARTITION_EXISTS 1
71#endif
72
73#endif /* CONFIG_NEWLIB_LIBC */
74
75#ifdef Z_MALLOC_PARTITION_EXISTS
76/* Memory partition containing the libc malloc arena. Configuration controls
77 * whether this is available, and an arena size may need to be set.
78 */
79extern struct k_mem_partition z_malloc_partition;
80#endif
81
82#ifdef CONFIG_NEED_LIBC_MEM_PARTITION
83/* - All newlib globals will be placed into z_libc_partition.
84 * - Minimal C library globals, if any, will be placed into
85 * z_libc_partition.
86 * - Stack canary globals will be placed into z_libc_partition since
87 * it is not worth placing in its own partition.
88 * - Some architectures may place the global pointer to the thread local
89 * storage in z_libc_partition since it is not worth placing in its
90 * own partition.
91 */
92#define Z_LIBC_PARTITION_EXISTS 1
93
94/* C library globals, except the malloc arena */
95extern struct k_mem_partition z_libc_partition;
96#endif
97#endif /* CONFIG_USERSPACE */
98
99#include <zephyr/syscalls/libc-hooks.h>
100
101/* C library memory partitions */
102#define Z_LIBC_DATA K_APP_DMEM(z_libc_partition)
103
104#ifdef __cplusplus
105}
106#endif
107
108#endif /* ZEPHYR_INCLUDE_SYS_LIBC_HOOKS_H_ */
#define ZRESTRICT
Definition common.h:36
int zephyr_fputc(int c, FILE *stream)
char c
Definition printk.c:169
void * ptr
Definition printk.c:177
int FILE
Definition stdio.h:22
Memory Partition.
Definition mem_domain.h:55
Macros to abstract toolchain specific capabilities.