mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-01 10:40:47 +03:00
Rework the syscall interposition architecture so FreeRTOS works standalone (without VFS) and VFS optionally overrides with strong symbols. All kernel FDs are registered with VFS via esp_vfs_register_fd_with_local_fd, so the application only sees VFS-allocated FD numbers, preventing numerical collisions between kernel FDs and VFS-internal FD slots. FreeRTOS side: - Create linux_port_coop_internal.h with LINUX_COOP_IO_LOOP, LINUX_COOP_RESOLVE, linux_coop_yield and FD state table functions - Export cooperative I/O primitives (freertos_linux_coop_read/write/ open/close/fcntl/select/pread/pwrite/readv/writev/recv/send/ recvfrom/sendto/recvmsg/sendmsg/connect/accept/pselect/poll/ socket/socketpair/pipe/pipe2/dup/dup2/syscalls_init) - Define weak POSIX symbols calling through to the cooperative primitives; keep nanosleep/sleep/usleep as strong (not FD-related) - Refactor freertos_linux_coop_syscalls.h into a pure public API header VFS side: - Register the Linux host FS with esp_vfs_register_fs_with_id() as a proper VFS driver; register stdin/stdout/stderr at init (priority 99) - Rewrite vfs_linux.c with strong POSIX symbols dispatching through esp_vfs_* - Add strong overrides for FD-creating syscalls (open, pipe, pipe2, socket, socketpair, dup, dup2, accept) that register returned FDs with VFS - Add strong overrides for FD-translating syscalls (readv, writev, recv, send, recvfrom, sendto, recvmsg, sendmsg, connect, pselect, poll) that translate VFS FD to kernel FD - Delete vfs_coop_syscalls.c (absorbed into FreeRTOS weak + VFS strong) - Update CMakeLists.txt: remove vfs_coop_syscalls.c, add linker hook
39 lines
2.1 KiB
CMake
39 lines
2.1 KiB
CMake
# NOTE: This kind of mocking currently works on Linux targets only.
|
|
# On Espressif chips, too many dependencies are missing at the moment.
|
|
message(STATUS "building FREERTOS MOCKS (only task, event-groups and queue)")
|
|
|
|
idf_component_get_property(original_freertos_dir freertos COMPONENT_OVERRIDEN_DIR)
|
|
|
|
set(kernel_dir "${original_freertos_dir}/FreeRTOS-Kernel")
|
|
|
|
set(include_dirs
|
|
"${kernel_dir}/include"
|
|
"${original_freertos_dir}/config/include" # For "freertos/FreeRTOSConfig.h"
|
|
"${original_freertos_dir}/config/include/freertos" # For "FreeRTOSConfig.h"
|
|
"${original_freertos_dir}/config/linux/include" # For "freertos/FreeRTOSConfig_arch.h"
|
|
"${original_freertos_dir}/esp_additions/include"
|
|
# Required because CMock tries to include "idf_additions.h" instead of "freertos/idf_additions.h"
|
|
"${original_freertos_dir}/esp_additions/include/freertos"
|
|
"${kernel_dir}/portable/linux/include" # For "spinlock.h"
|
|
"${kernel_dir}/portable/linux/include/freertos" # For "portmacro.h"
|
|
"${kernel_dir}/portable/linux/include/esp_private" # CMock strips directory prefixes from includes
|
|
"${kernel_dir}/include/freertos" # this is due to the way includes are generated in CMock (without freertos prefix)
|
|
)
|
|
|
|
idf_component_mock(INCLUDE_DIRS ${include_dirs}
|
|
REQUIRES esp_common
|
|
MOCK_HEADER_FILES
|
|
${original_freertos_dir}/esp_additions/include/freertos/idf_additions.h
|
|
${original_freertos_dir}/FreeRTOS-Kernel/include/freertos/task.h
|
|
${original_freertos_dir}/FreeRTOS-Kernel/include/freertos/event_groups.h
|
|
${original_freertos_dir}/FreeRTOS-Kernel/include/freertos/queue.h
|
|
${original_freertos_dir}/FreeRTOS-Kernel/portable/linux/include/freertos/portmacro.h
|
|
${kernel_dir}/portable/linux/include/esp_private/freertos_linux_coop_syscalls.h)
|
|
|
|
idf_component_get_property(freertos_lib freertos COMPONENT_LIB)
|
|
target_compile_definitions(${freertos_lib} PUBLIC "projCOVERAGE_TEST=0")
|
|
|
|
# When using FreeRTOS mocks, prevent esp_system from providing main() so tests can provide their own
|
|
idf_component_get_property(esp_system_lib esp_system COMPONENT_LIB)
|
|
target_compile_definitions(${esp_system_lib} PRIVATE ESP_SYSTEM_LINUX_NO_MAIN)
|