This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 01d8ee3d4bf119eb2910ad2cabc3368404f1e934 Author: Marco Casaroli <[email protected]> AuthorDate: Wed Oct 28 17:25:49 2026 +0100 libs/libc: Move posix_madvise() from fs/mmap to the C library. posix_madvise() was defined in fs/mmap/fs_mmisc.c and has no system call, so in protected and kernel builds a user program that calls it (or madvise(), which <sys/mman.h> maps to it) does not link. The function ignores the advice and touches no kernel state, so it does not need a system call. Move it to libs/libc/misc as it is, and add it to libc.csv. Flat builds link the same function from the C library instead of fs/. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]> --- fs/mmap/fs_mmisc.c | 7 ----- libs/libc/libc.csv | 1 + libs/libc/misc/CMakeLists.txt | 1 + libs/libc/misc/Make.defs | 2 +- libs/libc/misc/lib_posix_madvise.c | 53 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 56 insertions(+), 8 deletions(-) diff --git a/fs/mmap/fs_mmisc.c b/fs/mmap/fs_mmisc.c index b77858315b6..fef6c9dd1ba 100644 --- a/fs/mmap/fs_mmisc.c +++ b/fs/mmap/fs_mmisc.c @@ -123,10 +123,3 @@ errout: set_errno(-ret); return ERROR; } - -/* Ignore the advice since there is no alternative strategy to select. */ - -int posix_madvise(FAR void *addr, size_t len, int advice) -{ - return 0; -} diff --git a/libs/libc/libc.csv b/libs/libc/libc.csv index ae49af9d37e..082797bd84a 100644 --- a/libs/libc/libc.csv +++ b/libs/libc/libc.csv @@ -205,6 +205,7 @@ "perror","stdio.h","defined(CONFIG_FILE_STREAM)","void","FAR const char *" "pipe","unistd.h","defined(CONFIG_PIPES) && CONFIG_DEV_PIPE_SIZE > 0","int","int [2]|FAR int *" "posix_fallocate","fcntl.h","","int","int","off_t","off_t" +"posix_madvise","sys/mman.h","","int","FAR void *","size_t","int" "posix_memalign","stdlib.h","","int","FAR void **","size_t","size_t" "preadv","sys/uio.h","","ssize_t","int","FAR const struct iovec *","int","off_t" "printf","stdio.h","","int","FAR const IPTR char *","..." diff --git a/libs/libc/misc/CMakeLists.txt b/libs/libc/misc/CMakeLists.txt index fd504de5ab2..ac67adcf594 100644 --- a/libs/libc/misc/CMakeLists.txt +++ b/libs/libc/misc/CMakeLists.txt @@ -38,6 +38,7 @@ list( lib_idr.c lib_impure.c lib_memfd.c + lib_posix_madvise.c lib_mutex.c lib_fchmodat.c lib_fstatat.c diff --git a/libs/libc/misc/Make.defs b/libs/libc/misc/Make.defs index 62d64118321..916325be4cf 100644 --- a/libs/libc/misc/Make.defs +++ b/libs/libc/misc/Make.defs @@ -24,7 +24,7 @@ CSRCS += lib_bitmap.c lib_circbuf.c lib_creat.c lib_mknod.c CSRCS += lib_utsname.c lib_getrandom.c lib_xorshift128.c lib_tea_encrypt.c -CSRCS += lib_tea_decrypt.c lib_impure.c lib_memfd.c +CSRCS += lib_tea_decrypt.c lib_impure.c lib_memfd.c lib_posix_madvise.c CSRCS += lib_mutex.c lib_fchmodat.c lib_fstatat.c lib_getfullpath.c CSRCS += lib_openat.c lib_mkdirat.c lib_utimensat.c lib_mallopt.c CSRCS += lib_idr.c lib_getnprocs.c lib_getstacksize.c lib_mntent.c diff --git a/libs/libc/misc/lib_posix_madvise.c b/libs/libc/misc/lib_posix_madvise.c new file mode 100644 index 00000000000..c560d311543 --- /dev/null +++ b/libs/libc/misc/lib_posix_madvise.c @@ -0,0 +1,53 @@ +/**************************************************************************** + * libs/libc/misc/lib_posix_madvise.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <sys/mman.h> + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: posix_madvise + * + * Description: + * Advise the system about the expected use of a memory range. NuttX + * has no other paging strategy to select, so the advice is ignored. + * + * Input Parameters: + * addr - The start of the range + * len - The length of the range + * advice - The advice (POSIX_MADV_xxx or MADV_xxx) + * + * Returned Value: + * Zero (always). + * + ****************************************************************************/ + +int posix_madvise(FAR void *addr, size_t len, int advice) +{ + return 0; +}
