1e41f4b71Sopenharmony_ci# Restricted musl libc APIs
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci## Overview
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ciYou 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.
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ci## Scenarios
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ciThe use of musl libc APIs may be restricted by the following factors:
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci1. The use of the musl libc API is restricted by the secure computing (seccomp) mechanism.<!--Del-->
12e41f4b71Sopenharmony_ci   For details about the seccomp mechanism, see [Seccomp Policy Development](../../../device-dev/subsystems/subsys-boot-init-seccomp.md).<!--DelEnd-->
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ci    A common error caused by seccomp is as follows:
15e41f4b71Sopenharmony_ci    - Top function is the musl function in stacktrace.
16e41f4b71Sopenharmony_ci    - The reason is "signal:SIGSYS", as shown in the following example:
17e41f4b71Sopenharmony_ci        ```
18e41f4b71Sopenharmony_ci        Process name:com.example.myapplication
19e41f4b71Sopenharmony_ci        Reason:Signal:SIGSYS(UNKNOWN)
20e41f4b71Sopenharmony_ci        Fault thread Info:
21e41f4b71Sopenharmony_ci        Tid:13893, Name:e.myapplication
22e41f4b71Sopenharmony_ci        #00 pc 000a5d30 /system/lib/ld-musl-arm.so.1(sethostname+16)(584c9d0a0e9000497bb0d66799a9526a)
23e41f4b71Sopenharmony_ci        #01 pc 00002f68 /data/storage/el1/bundle/libs/arm/libentry.so(test()+64)
24e41f4b71Sopenharmony_ci        ```
25e41f4b71Sopenharmony_ci
26e41f4b71Sopenharmony_ci2. The API cannot be used because it is a kernel API that is not exposed.
27e41f4b71Sopenharmony_ci
28e41f4b71Sopenharmony_ci3. The use of the musl libc API is restricted by SELinux.<!--Del-->
29e41f4b71Sopenharmony_ci   For details about SELinux, see [OpenHarmony SELinux Overview](../../../device-dev/subsystems/subsys-security-selinux-overview.md).<!--DelEnd-->
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci4. The use of the musl libc API is restricted by the sandbox mechanism. For details about the sandbox mechanism, see [Application Sandbox](../../file-management/app-sandbox-directory.md).
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci5. The musl libc API is a null implementation or failed by default.
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci6. The API can be executed after special permissions are granted.
36e41f4b71Sopenharmony_ci
37e41f4b71Sopenharmony_ci## Restricted musl libc APIs
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ciThe following table lists the musl libc APIs that cannot be used.
40e41f4b71Sopenharmony_ci
41e41f4b71Sopenharmony_ci| Restricted By         | Header File       | Symbol        |
42e41f4b71Sopenharmony_ci| -------------------- | ------------ | ---------------- |
43e41f4b71Sopenharmony_ci| seccomp    | sys/fsuid.h  | setfsgid |
44e41f4b71Sopenharmony_ci| seccomp    | sys/fsuid.h  | setfsuid |
45e41f4b71Sopenharmony_ci| seccomp    | unistd.h     | setgid |
46e41f4b71Sopenharmony_ci| seccomp    | unistd.h     | setegid |
47e41f4b71Sopenharmony_ci| seccomp    | unistd.h     | setreuid |
48e41f4b71Sopenharmony_ci| seccomp    | unistd.h     | setregid |
49e41f4b71Sopenharmony_ci| seccomp    | unistd.h     | setresgid |
50e41f4b71Sopenharmony_ci| seccomp    | unistd.h     | setgroups |
51e41f4b71Sopenharmony_ci| seccomp    | unistd.h     | chroot |
52e41f4b71Sopenharmony_ci| seccomp    | unistd.h     | sethostname |
53e41f4b71Sopenharmony_ci| seccomp    | unistd.h     | setdomainname |
54e41f4b71Sopenharmony_ci| seccomp    | unistd.h     | acct |
55e41f4b71Sopenharmony_ci| seccomp    | sys/xattr.h  | setxattr |
56e41f4b71Sopenharmony_ci| seccomp    | time.h       | clock_settime |
57e41f4b71Sopenharmony_ci| seccomp    | time.h       | settimeofday |
58e41f4b71Sopenharmony_ci| seccomp    | sys/stat.h   | mknod |
59e41f4b71Sopenharmony_ci| seccomp    | sys/stat.h   | mknodat |
60e41f4b71Sopenharmony_ci| seccomp    | sys/stat.h   | mkfifo |
61e41f4b71Sopenharmony_ci| seccomp    | fcntl.h      | name_to_handle_at |
62e41f4b71Sopenharmony_ci| seccomp    | fcntl.h      | open_by_handle_at |
63e41f4b71Sopenharmony_ci| seccomp    | sys/klog.h   | klogctl |
64e41f4b71Sopenharmony_ci| seccomp    | sys/swap.h   | swapon |
65e41f4b71Sopenharmony_ci| seccomp    | sys/swap.h   | swapoff |
66e41f4b71Sopenharmony_ci| seccomp    | sys/sem.h    | semctl |
67e41f4b71Sopenharmony_ci| seccomp    | sys/sem.h    | semop |
68e41f4b71Sopenharmony_ci| seccomp    | sys/sem.h    | semtimedop |
69e41f4b71Sopenharmony_ci| seccomp    | sys/mount.h  | mount |
70e41f4b71Sopenharmony_ci| seccomp    | sys/mount.h  | umount2 |
71e41f4b71Sopenharmony_ci| seccomp    | sys/mount.h  | umount |
72e41f4b71Sopenharmony_ci| seccomp    | sys/msg.h    | msgctl |
73e41f4b71Sopenharmony_ci| seccomp    | sys/msg.h    | msgget |
74e41f4b71Sopenharmony_ci| seccomp    | sys/msg.h    | msgrcv |
75e41f4b71Sopenharmony_ci| seccomp    | sys/msg.h    | msgsnd |
76e41f4b71Sopenharmony_ci| seccomp    | grp.h        | initgroups |
77e41f4b71Sopenharmony_ci| seccomp    | grp.h        | init_module |
78e41f4b71Sopenharmony_ci| seccomp    | sched.h      | unshare |
79e41f4b71Sopenharmony_ci| seccomp    | sched.h      | setns |
80e41f4b71Sopenharmony_ci| seccomp    | None         | pivot_root |
81e41f4b71Sopenharmony_ci| Kernel API not exposed| sys/fanotify.h | fanotify_init |
82e41f4b71Sopenharmony_ci| Kernel API not exposed| sys/fanotify.h | fanotify_mark |
83e41f4b71Sopenharmony_ci| Kernel API not exposed| syslog.h       | syslog |
84e41f4b71Sopenharmony_ci| Kernel API not exposed| syslog.h       | vsyslog |
85e41f4b71Sopenharmony_ci| SELinux    | pty.h          | forkpty |
86e41f4b71Sopenharmony_ci| SELinux    | pty.h          | openpty |
87e41f4b71Sopenharmony_ci| SELinux    | stdlib.h       | ptsname |
88e41f4b71Sopenharmony_ci| SELinux    | stdlib.h       | ptsname_r |
89e41f4b71Sopenharmony_ci| SELinux    | stdlib.h       | posix_openpt |
90e41f4b71Sopenharmony_ci| SELinux    | stdlib.h       | unlockpt |
91e41f4b71Sopenharmony_ci| SELinux    | sys/shm.h      | shmget |
92e41f4b71Sopenharmony_ci| SELinux    | sys/shm.h      | shmat |
93e41f4b71Sopenharmony_ci| SELinux    | sys/shm.h      | shmdt |
94e41f4b71Sopenharmony_ci| SELinux    | sys/shm.h      | shmctl |
95e41f4b71Sopenharmony_ci| SELinux    | sys/sem.h      | semget |
96e41f4b71Sopenharmony_ci| SELinux    | stdio.h        | popen |
97e41f4b71Sopenharmony_ci| SELinux    | stdio.h        | pclose |
98e41f4b71Sopenharmony_ci| SELinux    | unistd.h       | tcgetpgrp |
99e41f4b71Sopenharmony_ci| SELinux    | unistd.h       | tcsetpgrp |
100e41f4b71Sopenharmony_ci| SELinux    | unistd.h       | link |
101e41f4b71Sopenharmony_ci| SELinux    | unistd.h       | linkat |
102e41f4b71Sopenharmony_ci| SELinux    | unistd.h       | readlink |
103e41f4b71Sopenharmony_ci| SELinux    | unistd.h       | readlinkat |
104e41f4b71Sopenharmony_ci| SELinux    | unistd.h       | symlink |
105e41f4b71Sopenharmony_ci| SELinux    | unistd.h       | symlinkat |
106e41f4b71Sopenharmony_ci| SELinux    | sys/stat.h     | mkfifoat |
107e41f4b71Sopenharmony_ci| SELinux    | termios        | tcgetattr |
108e41f4b71Sopenharmony_ci| SELinux    | termios        | tcsetattr |
109e41f4b71Sopenharmony_ci| SELinux    | termios        | tcsendbreak |
110e41f4b71Sopenharmony_ci| SELinux    | termios        | tcdrain |
111e41f4b71Sopenharmony_ci| SELinux    | termios        | tcflush |
112e41f4b71Sopenharmony_ci| SELinux    | termios        | tcflow |
113e41f4b71Sopenharmony_ci| SELinux    | termios        | tcgetsid |
114e41f4b71Sopenharmony_ci| SELinux    | net/if.h       | if_indextoname |
115e41f4b71Sopenharmony_ci| SELinux    | net/if.h       | if_nametoindex |
116e41f4b71Sopenharmony_ci| Sandbox       | stdio.h        | tmpfile |
117e41f4b71Sopenharmony_ci| Sandbox       | stdio.h        | tmpfile64 |
118e41f4b71Sopenharmony_ci| Sandbox       | nl_type.h      | catgets |
119e41f4b71Sopenharmony_ci| Sandbox       | nl_type.h      | catclose |
120e41f4b71Sopenharmony_ci| Null implementation or failed by default     | utmp.h         | setutent |
121e41f4b71Sopenharmony_ci| Null implementation or failed by default     | utmp.h         | pututline |
122e41f4b71Sopenharmony_ci| Null implementation or failed by default     | utmp.h         | getutent |
123e41f4b71Sopenharmony_ci| Null implementation or failed by default     | utmp.h         | utmpname |
124e41f4b71Sopenharmony_ci| Null implementation or failed by default     | unistd.h       | brk |
125e41f4b71Sopenharmony_ci| Null implementation or failed by default     | stdio_ext.h    | __fsetlocking |
126e41f4b71Sopenharmony_ci| Null implementation or failed by default     | netdb.h        | getnetbyaddr |
127e41f4b71Sopenharmony_ci| Null implementation or failed by default     | netdb.h        | getnetbyname |
128e41f4b71Sopenharmony_ci| **CAP_SYS_ADMIN** permission required| None          | pivot_root |
129