Libc
Categories:
3 minute read
XWOS/xwos Kernel Dependencies on libc
string.h: depends onmemset(),memcpy();stdlib.h- When
XWOSCFG_SKD_THD_STDC_MM,XWOSCFG_SKD_SWT_STDC_MM,XWOSCFG_SYNC_SEM_STDC_MM,XWOSCFG_SYNC_COND_STDC_MM,XWOSCFG_SYNC_EVT_STDC_MMorXWOSCFG_LOCK_MTX_STDC_MMis configured, depends onmalloc()andfree()for dynamic object creation and deletion;
- When
inttypes.h,stdint.h,stddef.h: XWOS base types are defined based on standard C base types;stdbool.h: depends on the bool type definition;stdatomic.h: depends on atomic operation memory barrier definitions;stdarg.h- If
XWLIBCFG_SCis configured as1,xwos/lib/sc.hrequires variadic functions; - If
XWLIBCFG_LOGis configured as1,xwos/lib/xwlog.crequires variadic functions;
- If
stdio.h: IfXWLIBCFG_LOGis configured as1, formatted logging inxwos/lib/xwlog.cdepends onvsnprintf().
libc Support Provided by XWOS/xwmd
Dynamic Memory Management
-
stdlib.h-
malloc() -
free() -
cfree() -
realloc() -
calloc() -
memalign() -
aligned_alloc() -
valloc() -
pvalloc()
-
Depending on the libc selected in the configuration:
- When
XWCFG_LIBCis configured asnewlib, these functions are supported at the bottom layer byxwmd/libc/newlibac/mem.c, which overrides the original newlib implementation. The implementation inxwmd/libc/newlibac/mem.cis a wrapper around mempool.- mempool must be initialized by selecting a memory device in
board_init()before use, andnewlibac_mempoolmust be provided beforestdlib.hfunctions can be used.
- mempool must be initialized by selecting a memory device in
- When
XWCFG_LIBCis configured aspicolibc, these functions are supported at the bottom layer byxwmd/libc/picolibcac/mem.c, which overrides the original picolibc implementation. The implementation inxwmd/libc/picolibcac/mem.cis a wrapper around mempool.- mempool must be initialized by selecting a memory device in
board_init()before use, andpicolibcac_mempoolmust be provided beforestdlib.hfunctions can be used.
- mempool must be initialized by selecting a memory device in
newlibac_mempool or picolibcac_mempool must be defined in the BSP. Different projects have different configurations. The XWOS project team provides several example projects;
refer to the libc section in each project’s README.md for guidance:
- ATKSTM32F407ZXWOS: ALIENTEK F407 Core Board
- EmbedFireStm32H743XWOS: EmbedFire STM32H743-Pro Dev Board
- AtkApolloH743XWOS: ALIENTEK Apollo STM32H743 Dev Board
- FK429M1XWOS: Fanke STM32F429-M1 Dev Board
- WeActMiniStm32H750XWOS: WeAct MiniStm32H750 Dev Board
setjmp()/longjmp()
The setjmp() and longjmp() functions enable goto-like jumps between different functions.
Users should use the header file xwos/lib/setjmp.h instead of the standard C header setjmp.h,
and should also use xwlib_setjmp() and xwlib_longjmp() instead of setjmp() and longjmp().
In addition, setjmp()/longjmp() is prohibited by the MISRA-C:2012 standard.
errno
XWOS restructures the errno implementation, making errno a per-thread private variable.
When a thread accesses errno, it only accesses its own errno.
Users should use xwos/lib/errno.h instead of the libc errno.h.
Depending on the libc selected in the configuration:
- When
XWCFG_LIBCis configured asnewlib, theerrnoimplementation is inxwmd/libc/newlibac/errno.c; - When
XWCFG_LIBCis configured aspicolibc, theerrnoimplementation is inxwmd/libc/picolibcac/errno.c.
File Operations
- Header
stdio.h-
fopen() -
fclose() -
fread() -
fwrite() -
fseek() -
remove() -
rename()
-
Depending on the libc selected in the configuration:
- When
XWCFG_LIBCis configured asnewlib, these functions are supported at the bottom layer byxwmd/libc/newlibac/fops.c, which in turn depends on third-party softwarexwem/fs/fatfs; - When
XWCFG_LIBCis configured aspicolibc, these functions are supported at the bottom layer byxwmd/libc/picolibcac/fops.c, which in turn depends on third-party softwarexwem/fs/fatfs.
FatFs requires block device operation support from the BSP. Different boards have different levels of file operation support. The XWOS project team provides several example projects;
refer to the FatFS section in each project’s README.md for guidance:
- ATKSTM32F407ZXWOS: ALIENTEK F407 Core Board
- EmbedFireStm32H743XWOS: EmbedFire STM32H743-Pro Dev Board
- AtkApolloH743XWOS: ALIENTEK Apollo STM32H743 Dev Board
- FK429M1XWOS: Fanke STM32F429-M1 Dev Board
- WeActMiniStm32H750XWOS: WeAct MiniStm32H750 Dev Board
TLS
TODO
stdatomic
TODO
Math Library
If the SOC has an FPU and ARCHCFG_FPU is configured as 1, libm is supported.
Other libc Features
- ctype: character types
- wchar: multi-byte characters
- iconv: character set conversion
- locale: not yet supported
- search: search
- argz: string arrays
- time: not yet supported; requires an underlying RTC driver