Libc

XWOS/xwos Kernel Dependencies on libc

  • string.h: depends on memset(), 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_MM or XWOSCFG_LOCK_MTX_STDC_MM is configured, depends on malloc() and free() for dynamic object creation and deletion;
  • 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_SC is configured as 1, xwos/lib/sc.h requires variadic functions;
    • If XWLIBCFG_LOG is configured as 1, xwos/lib/xwlog.c requires variadic functions;
  • stdio.h: If XWLIBCFG_LOG is configured as 1, formatted logging in xwos/lib/xwlog.c depends on vsnprintf().

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_LIBC is configured as newlib, these functions are supported at the bottom layer by xwmd/libc/newlibac/mem.c, which overrides the original newlib implementation. The implementation in xwmd/libc/newlibac/mem.c is a wrapper around mempool.
    • mempool must be initialized by selecting a memory device in board_init() before use, and newlibac_mempool must be provided before stdlib.h functions can be used.
  • When XWCFG_LIBC is configured as picolibc, these functions are supported at the bottom layer by xwmd/libc/picolibcac/mem.c, which overrides the original picolibc implementation. The implementation in xwmd/libc/picolibcac/mem.c is a wrapper around mempool.
    • mempool must be initialized by selecting a memory device in board_init() before use, and picolibcac_mempool must be provided before stdlib.h functions can be used.

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:

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_LIBC is configured as newlib, the errno implementation is in xwmd/libc/newlibac/errno.c;
  • When XWCFG_LIBC is configured as picolibc, the errno implementation is in xwmd/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_LIBC is configured as newlib, these functions are supported at the bottom layer by xwmd/libc/newlibac/fops.c, which in turn depends on third-party software xwem/fs/fatfs;
  • When XWCFG_LIBC is configured as picolibc, these functions are supported at the bottom layer by xwmd/libc/picolibcac/fops.c, which in turn depends on third-party software xwem/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:

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