Zephyr Project API  3.1.0
A Scalable Open Source RTOS
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/*
16 * Private header for specifying accessory functions to the C library internals
17 * that need to call into the kernel as system calls
18 */
19
20#if defined(CONFIG_NEWLIB_LIBC) || defined(CONFIG_ARCMWDT_LIBC)
21
22/* syscall generation ignores preprocessor, ensure this is defined to ensure
23 * we don't have compile errors
24 */
25__syscall int zephyr_read_stdin(char *buf, int nbytes);
26
27__syscall int zephyr_write_stdout(const void *buf, int nbytes);
28
29#else
30/* Minimal libc */
31
32__syscall int zephyr_fputc(int c, FILE * stream);
33
34__syscall size_t zephyr_fwrite(const void *ZRESTRICT ptr, size_t size,
35 size_t nitems, FILE *ZRESTRICT stream);
36#endif /* CONFIG_NEWLIB_LIBC */
37
38#ifdef CONFIG_USERSPACE
39#if defined(CONFIG_NEWLIB_LIBC)
40/* If we are using newlib, the heap arena is in one of two areas:
41 * - If we have an MPU that requires power of two alignment, the heap bounds
42 * must be specified in Kconfig via CONFIG_NEWLIB_LIBC_ALIGNED_HEAP_SIZE.
43 * - Otherwise, the heap arena on most arches starts at a suitably
44 * aligned base addreess after the `_end` linker symbol, through to the end
45 * of system RAM.
46 */
47#if (!defined(CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT) || \
48 (defined(CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT) && \
49 CONFIG_NEWLIB_LIBC_ALIGNED_HEAP_SIZE))
50#define Z_MALLOC_PARTITION_EXISTS 1
51extern struct k_mem_partition z_malloc_partition;
52#endif
53#elif defined(CONFIG_MINIMAL_LIBC)
54#if (CONFIG_MINIMAL_LIBC_MALLOC_ARENA_SIZE > 0)
55/* Minimal libc by default has no malloc arena, its size must be set in
56 * Kconfig via CONFIG_MINIMAL_LIBC_MALLOC_ARENA_SIZE
57 */
58#define Z_MALLOC_PARTITION_EXISTS 1
59#endif /* CONFIG_MINIMAL_LIBC_MALLOC_ARENA_SIZE > 0 */
60#endif /* CONFIG_MINIMAL_LIBC */
61
62#ifdef Z_MALLOC_PARTITION_EXISTS
63/* Memory partition containing the libc malloc arena. Configuration controls
64 * whether this is available, and an arena size may need to be set.
65 */
66extern struct k_mem_partition z_malloc_partition;
67#endif
68
69#if defined(CONFIG_NEWLIB_LIBC) || defined(CONFIG_STACK_CANARIES) || \
70 defined(CONFIG_NEED_LIBC_MEM_PARTITION)
71/* - All newlib globals will be placed into z_libc_partition.
72 * - Minimal C library globals, if any, will be placed into
73 * z_libc_partition.
74 * - Stack canary globals will be placed into z_libc_partition since
75 * it is not worth placing in its own partition.
76 * - Some architectures may place the global pointer to the thread local
77 * storage in z_libc_partition since it is not worth placing in its
78 * own partition.
79 */
80#define Z_LIBC_PARTITION_EXISTS 1
81
82/* C library globals, except the malloc arena */
83extern struct k_mem_partition z_libc_partition;
84#endif
85#endif /* CONFIG_USERSPACE */
86
87#include <syscalls/libc-hooks.h>
88
89/* C library memory partitions */
90#define Z_LIBC_DATA K_APP_DMEM(z_libc_partition)
91
92#endif /* ZEPHYR_INCLUDE_SYS_LIBC_HOOKS_H_ */
#define ZRESTRICT
Definition: common.h:31
size_t zephyr_fwrite(const void *ZRESTRICT ptr, size_t size, size_t nitems, FILE *ZRESTRICT stream)
int zephyr_fputc(int c, FILE *stream)
char c
Definition: printk.c:71
void * ptr
Definition: printk.c:79
int FILE
Definition: stdio.h:22
Memory Partition.
Definition: mem_domain.h:55
Macros to abstract toolchain specific capabilities.