openharmony 鸿蒙 musl

2025-06-12 浏览 (1)

musl libc

Overview

The C standard library (libc) provides standard header files and common library implementations (such as input/output processing and string handling) in C language programming.

OpenHarmony uses musl as the libc. musl is a lightweight, fast, simple, and free open-source libc. For details, see musl libc Reference Manual.

For details about the differences between musl and glibc, see Functional differences from glibc.

libc Components

C11 is implemented by libc, libm, and libdl.

  • libc: provides thread-related interfaces and a majority of standard interfaces.

  • libm: provides mathematical library interfaces. Currently, OpenHarmony provides a link to libm, and the interfaces are defined in libc.

  • libdl: provides dynamic linker interfaces such as dlopen. Currently, OpenHarmony provides a link to libdl, and the interfaces are defined in libc.

musl Version

  • 1.2.0

  • 1.2.3 since OpenHarmony 4.0

  • 1.2.5 since OpenHarmony 5.0

Supported Capabilities

OpenHarmony provides header files and library interfaces that align with C99, C11, and POSIX standards, though not fully compliant. It supports Armv7-A, Arm64, and x86_64 architectures.

To better accommodate the basic features of OpenHarmony devices, such as high performance, low memory usage, high security, lightweight design, and multi-device adaptability, the musl library has been optimized and enhanced, with interfaces unsuitable for embedded devices removed according.

New Capabilities

  1. The dynamic loader supports isolation by namespace. The dynamic libraries that can be loaded by dlopen() are restricted by the system namespace. For example, the system dynamic libraries cannot be opened.
  2. dlclose() can be used to unload a dynamic library. This capability is not supported by musl.
  3. The symbol-versioning is supported.
  4. dlopen() can directly load uncompressed files in a .zip package.

Debugging Capabilities

The libc provides dynamic enabling of debug logging (disabled by default). The debug logs help you learn about exceptions of the libc. With this function, you only need to set param, which eliminates the need for rebuilding the libc. However, you are advised not to enable debug logging in official versions because it affects the running performance.

musl.log

Set musl.log.enable to true to enable printing of musl debug logs. You need to enable musl.log before printing other logs.

param set musl.log.enable true

Loader Logging

The loader starts applications and invokes dlopen and dlclose in the libc. To view exceptions during the loading process, you need to enable the loader logging function. The following describes common operations.

  • Enable the loader logging for all applications. Exercise caution when enabling this function because a large number of logs will be generated.
param set musl.log.ld.app true
  • Enable the loader logging for an application specified by {app_name}.
param set musl.log.ld.all false
param set musl.log.ld.app.{app_name} true
  • Enable the loader logging for all applications except the specified application.
param set musl.log.ld.all true
param set musl.log.ld.app.{app_name} false

musl API Difference

APIDescription
epoll_createIn OpenHarmony 5.0, this API uses the same logic as in musl 1.2.3. Specifically, the API does not verify input parameters or process them if the input parameter value is less than or equal to 0. In the next version, this API will adopt the logic from musl 1.2.5, which includes input parameter verification. If the input parameter value is less than or equal to 0, the error code EINVAL will be returned.

Character Encoding Formats Supported by iconv

The following lists the character encoding formats and aliases supported by musl.

NOTE

The character conversion can be successful only when the source character encoding format is correct and the target character encoding format is supported. musl does not support the following target encoding formats: gb18030, gbk, gb2312, big5, and euckr.

Encoding FormatAliasSupported by musl
utf8Yes
wchartYes
ucs2beYes
ucs2leYes
utf16beYes
utf16leYes
ucs4beutf32beYes
ucs4leutf32leYes
asciiusascii, iso646, iso646usYes
utf16Yes
ucs4utf32Yes
ucs2Yes
eucjpYes
shiftjissjis, cp932Yes
iso2022jpYes
gb18030Yes
gbkYes
gb2312Yes
big5bigfive, cp950, big5hkscsYes
euckrksc5601, ksx1001, cp949Yes
iso88591latin1Yes
iso88592Yes
iso88593Yes
iso88594Yes
iso88595Yes
iso88596Yes
iso88597Yes
iso88598Yes
iso88599Yes
iso885910Yes
iso885911tis620Yes
iso885913Yes
iso885914Yes
iso885915latin9Yes
iso885916Yes
cp1250windows1250Yes
cp1251windows1251Yes
cp1252windows1252Yes
cp1253windows1253Yes
cp1254windows1254Yes
cp1255windows1255Yes
cp1256windows1256Yes
cp1257windows1257Yes
cp1258windows1258Yes
koi8rYes
koi8uYes
cp437Yes
cp850Yes
cp866Yes
cp1047ibm1047Yes

musl APIs Not Supported

Native API Symbols Not Exported

Restricted musl libc APIs

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Native API Standard Libraries

harmony 鸿蒙VkExternalFormatOHOS

harmony 鸿蒙VkImportNativeBufferInfoOHOS

harmony 鸿蒙VkMemoryGetNativeBufferInfoOHOS

harmony 鸿蒙VkNativeBufferFormatPropertiesOHOS

harmony 鸿蒙VkNativeBufferPropertiesOHOS

harmony 鸿蒙VkNativeBufferUsageOHOS

harmony 鸿蒙VkSurfaceCreateInfoOHOS

harmony 鸿蒙Vulkan Module

harmony 鸿蒙libc++

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/AvVF3r