openharmony 鸿蒙 guidance-on-ndk-libc-interfaces-affected-by-permissions

2025-06-12 浏览 (1)

Restricted musl libc APIs

Overview

You may need to use musl libc APIs when developing your app with the NDK. However, some musl libc APIs cannot be used due to system or environment restrictions. Errors may occur when some musl libc APIs are used with DevEco Studio. This topic helps you learn about the musl libc APIs that cannot be used with the NDK.

Scenarios

The use of musl libc APIs may be restricted by the following factors:

  1. The use of the musl libc API is restricted by the secure computing (seccomp) mechanism. For details about the seccomp mechanism, see Seccomp Policy Development.

    A common error caused by seccomp is as follows:

    • Top function is the musl function in stacktrace.
    • The reason is "signal:SIGSYS", as shown in the following example:
      Process name:com.example.myapplication
      Reason:Signal:SIGSYS(UNKNOWN)
      Fault thread Info:
      Tid:13893, Name:e.myapplication
      #00 pc 000a5d30 /system/lib/ld-musl-arm.so.1(sethostname+16)(584c9d0a0e9000497bb0d66799a9526a)
      #01 pc 00002f68 /data/storage/el1/bundle/libs/arm/libentry.so(test()+64)
      
  2. The API cannot be used because it is a kernel API that is not exposed.

  3. The use of the musl libc API is restricted by SELinux. For details about SELinux, see OpenHarmony SELinux Overview.

  4. The use of the musl libc API is restricted by the sandbox mechanism. For details about the sandbox mechanism, see Application Sandbox.

  5. The musl libc API is a null implementation or failed by default.

  6. The API can be executed after special permissions are granted.

Restricted musl libc APIs

The following table lists the musl libc APIs that cannot be used.

Restricted ByHeader FileSymbol
seccompsys/fsuid.hsetfsgid
seccompsys/fsuid.hsetfsuid
seccompunistd.hsetgid
seccompunistd.hsetegid
seccompunistd.hsetreuid
seccompunistd.hsetregid
seccompunistd.hsetresgid
seccompunistd.hsetgroups
seccompunistd.hchroot
seccompunistd.hsethostname
seccompunistd.hsetdomainname
seccompunistd.hacct
seccompsys/xattr.hsetxattr
seccomptime.hclock_settime
seccomptime.hsettimeofday
seccompsys/stat.hmknod
seccompsys/stat.hmknodat
seccompsys/stat.hmkfifo
seccompfcntl.hname_to_handle_at
seccompfcntl.hopen_by_handle_at
seccompsys/klog.hklogctl
seccompsys/swap.hswapon
seccompsys/swap.hswapoff
seccompsys/sem.hsemctl
seccompsys/sem.hsemop
seccompsys/sem.hsemtimedop
seccompsys/mount.hmount
seccompsys/mount.humount2
seccompsys/mount.humount
seccompsys/msg.hmsgctl
seccompsys/msg.hmsgget
seccompsys/msg.hmsgrcv
seccompsys/msg.hmsgsnd
seccompgrp.hinitgroups
seccompgrp.hinit_module
seccompsched.hunshare
seccompsched.hsetns
seccompNonepivot_root
Kernel API not exposedsys/fanotify.hfanotify_init
Kernel API not exposedsys/fanotify.hfanotify_mark
Kernel API not exposedsyslog.hsyslog
Kernel API not exposedsyslog.hvsyslog
SELinuxpty.hforkpty
SELinuxpty.hopenpty
SELinuxstdlib.hptsname
SELinuxstdlib.hptsname_r
SELinuxstdlib.hposix_openpt
SELinuxstdlib.hunlockpt
SELinuxsys/shm.hshmget
SELinuxsys/shm.hshmat
SELinuxsys/shm.hshmdt
SELinuxsys/shm.hshmctl
SELinuxsys/sem.hsemget
SELinuxstdio.hpopen
SELinuxstdio.hpclose
SELinuxunistd.htcgetpgrp
SELinuxunistd.htcsetpgrp
SELinuxunistd.hlink
SELinuxunistd.hlinkat
SELinuxunistd.hreadlink
SELinuxunistd.hreadlinkat
SELinuxunistd.hsymlink
SELinuxunistd.hsymlinkat
SELinuxsys/stat.hmkfifoat
SELinuxtermiostcgetattr
SELinuxtermiostcsetattr
SELinuxtermiostcsendbreak
SELinuxtermiostcdrain
SELinuxtermiostcflush
SELinuxtermiostcflow
SELinuxtermiostcgetsid
SELinuxnet/if.hif_indextoname
SELinuxnet/if.hif_nametoindex
Sandboxstdio.htmpfile
Sandboxstdio.htmpfile64
Sandboxnl_type.hcatgets
Sandboxnl_type.hcatclose
Null implementation or failed by defaultutmp.hsetutent
Null implementation or failed by defaultutmp.hpututline
Null implementation or failed by defaultutmp.hgetutent
Null implementation or failed by defaultutmp.hutmpname
Null implementation or failed by defaultunistd.hbrk
Null implementation or failed by defaultstdio_ext.h__fsetlocking
Null implementation or failed by defaultnetdb.hgetnetbyaddr
Null implementation or failed by defaultnetdb.hgetnetbyname
CAP_SYS_ADMIN permission requiredNonepivot_root

你可能感兴趣的鸿蒙文章

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/fSRDbf