Skip to content

Commit

Permalink
cleanup: include/: move misc/libc-hooks.h to sys/libc-hooks.h
Browse files Browse the repository at this point in the history
move misc/libc-hooks.h to sys/libc-hooks.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
  • Loading branch information
nashif committed Jun 28, 2019
1 parent 8be9f5d commit 447311e
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 53 deletions.
53 changes: 4 additions & 49 deletions include/misc/libc-hooks.h
Original file line number Diff line number Diff line change
@@ -1,60 +1,15 @@
/*
* Copyright (c) 2018, Intel Corporation.
* Copyright (c) 2019 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef ZEPHYR_INCLUDE_MISC_LIBC_HOOKS_H_
#define ZEPHYR_INCLUDE_MISC_LIBC_HOOKS_H_

#include <toolchain.h>
#include <stdio.h>
#include <stddef.h>

/*
* Private header for specifying accessory functions to the C library internals
* that need to call into the kernel as system calls
*/

#ifdef CONFIG_NEWLIB_LIBC

/* syscall generation ignores preprocessor, ensure this is defined to ensure
* we don't have compile errors
*/
#define _MLIBC_RESTRICT

__syscall int z_zephyr_read_stdin(char *buf, int nbytes);

__syscall int z_zephyr_write_stdout(const void *buf, int nbytes);

#else
/* Minimal libc */

__syscall int zephyr_fputc(int c, FILE * stream);

__syscall size_t zephyr_fwrite(const void *_MLIBC_RESTRICT ptr, size_t size,
size_t nitems, FILE *_MLIBC_RESTRICT stream);
#endif /* CONFIG_NEWLIB_LIBC */

#ifdef CONFIG_USERSPACE
#if defined(CONFIG_NEWLIB_LIBC) || (CONFIG_MINIMAL_LIBC_MALLOC_ARENA_SIZE > 0)
#define Z_MALLOC_PARTITION_EXISTS 1

/* Memory partition containing the libc malloc arena */
extern struct k_mem_partition z_malloc_partition;
#endif

#if defined(CONFIG_NEWLIB_LIBC) || defined(CONFIG_STACK_CANARIES)
/* Minimal libc has no globals. We do put the stack canary global in the
* libc partition since it is not worth placing in a partition of its own.
*/
#define Z_LIBC_PARTITION_EXISTS 1

/* C library globals, except the malloc arena */
extern struct k_mem_partition z_libc_partition;
#ifndef CONFIG_COMPAT_INCLUDES
#warning "This header file has moved, include <sys/libc-hooks.h> instead."
#endif
#endif /* CONFIG_USERSPACE */

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

#endif /* ZEPHYR_INCLUDE_MISC_LIBC_HOOKS_H_ */
60 changes: 60 additions & 0 deletions include/sys/libc-hooks.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (c) 2018, Intel Corporation.
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef ZEPHYR_INCLUDE_SYS_LIBC_HOOKS_H_
#define ZEPHYR_INCLUDE_SYS_LIBC_HOOKS_H_

#include <toolchain.h>
#include <stdio.h>
#include <stddef.h>

/*
* Private header for specifying accessory functions to the C library internals
* that need to call into the kernel as system calls
*/

#ifdef CONFIG_NEWLIB_LIBC

/* syscall generation ignores preprocessor, ensure this is defined to ensure
* we don't have compile errors
*/
#define _MLIBC_RESTRICT

__syscall int z_zephyr_read_stdin(char *buf, int nbytes);

__syscall int z_zephyr_write_stdout(const void *buf, int nbytes);

#else
/* Minimal libc */

__syscall int zephyr_fputc(int c, FILE * stream);

__syscall size_t zephyr_fwrite(const void *_MLIBC_RESTRICT ptr, size_t size,
size_t nitems, FILE *_MLIBC_RESTRICT stream);
#endif /* CONFIG_NEWLIB_LIBC */

#ifdef CONFIG_USERSPACE
#if defined(CONFIG_NEWLIB_LIBC) || (CONFIG_MINIMAL_LIBC_MALLOC_ARENA_SIZE > 0)
#define Z_MALLOC_PARTITION_EXISTS 1

/* Memory partition containing the libc malloc arena */
extern struct k_mem_partition z_malloc_partition;
#endif

#if defined(CONFIG_NEWLIB_LIBC) || defined(CONFIG_STACK_CANARIES)
/* Minimal libc has no globals. We do put the stack canary global in the
* libc partition since it is not worth placing in a partition of its own.
*/
#define Z_LIBC_PARTITION_EXISTS 1

/* C library globals, except the malloc arena */
extern struct k_mem_partition z_libc_partition;
#endif
#endif /* CONFIG_USERSPACE */

#include <syscalls/libc-hooks.h>

#endif /* ZEPHYR_INCLUDE_SYS_LIBC_HOOKS_H_ */
2 changes: 1 addition & 1 deletion kernel/userspace.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <init.h>
#include <stdbool.h>
#include <app_memory/app_memdomain.h>
#include <misc/libc-hooks.h>
#include <sys/libc-hooks.h>
#include <misc/mutex.h>

#ifdef Z_LIBC_PARTITION_EXISTS
Expand Down
2 changes: 1 addition & 1 deletion lib/libc/minimal/source/stdout/stdout_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

#include <stdio.h>
#include <misc/libc-hooks.h>
#include <sys/libc-hooks.h>
#include <syscall_handler.h>
#include <string.h>

Expand Down
2 changes: 1 addition & 1 deletion lib/libc/newlib/libc-hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <misc/util.h>
#include <kernel_internal.h>
#include <sys/errno_private.h>
#include <misc/libc-hooks.h>
#include <sys/libc-hooks.h>
#include <syscall_handler.h>
#include <app_memory/app_memdomain.h>
#include <init.h>
Expand Down
2 changes: 1 addition & 1 deletion subsys/testsuite/ztest/src/ztest.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <stdio.h>
#include <app_memory/app_memdomain.h>
#ifdef CONFIG_USERSPACE
#include <misc/libc-hooks.h>
#include <sys/libc-hooks.h>
#endif

#ifdef KERNEL
Expand Down

0 comments on commit 447311e

Please sign in to comment.