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