diff --git a/BUILD.gn b/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..079a47f5c7bbc74462edea88861b11ac79077bcb --- /dev/null +++ b/BUILD.gn @@ -0,0 +1,224 @@ +import("musl_template.gni") + +group("musl_all") { + deps = [ + ":musl_headers", + ":soft_libs", + ":a7_soft_libs", + ":a7_softfp_neon_libs", + # ":a7_hard_neon_libs", + ] +} + +musl_libs("soft") { + target_abi = "soft" +} + +musl_libs("a7_soft") { + target_abi = "a7_soft" +} + +musl_libs("a7_softfp_neon") { + target_abi = "a7_softfp_neon-vfpv4" +} + +musl_libs("a7_hard_neon") { + target_abi = "a7_hard_neon-vfpv4" +} + +group("musl_headers") { + deps = [ + ":create_alltypes_h", + ":create_syscall_h", + ":create_version_h", + ":musl_copy_inc_arpa", + ":musl_copy_inc_bits", + ":musl_copy_inc_net", + ":musl_copy_inc_netinet", + ":musl_copy_inc_netpacket", + ":musl_copy_inc_root", + ":musl_copy_inc_scsi", + ":musl_copy_inc_sys", + ] +} + +action("create_porting_src") { + script = "scripts/porting.sh" + + sources = [ + "//third_party/musl", + ] + + outdir = [ "${target_out_dir}/${musl_ported_dir}" ] + + src_files = musl_src_arch_file + src_files += musl_src_file + src_files += musl_src_ldso + src_files += musl_inc_bits_files + src_files += musl_inc_arpa_files + src_files += musl_inc_net_files + src_files += musl_inc_netinet_files + src_files += musl_inc_netpacket_files + src_files += musl_inc_scsi_files + src_files += musl_inc_sys_files + src_files += musl_inc_root_files + src_files += [ + "crt/${musl_arch}/crti.s", + "crt/${musl_arch}/crtn.s", + "crt/Scrt1.c", + "crt/crt1.c", + "crt/rcrt1.c", + "tools/mkalltypes.sed", + "arch/${musl_arch}/bits/alltypes.h.in", + "arch/${musl_arch}/bits/syscall.h.in", + "include/alltypes.h.in", + "VERSION", + "tools/version.sh", + "tools/install.sh", + "scripts/install.py", + "scripts/create_alltypes.sh", + "scripts/create_vesion.sh", + "scripts/create_syscall.sh", + ] + + outputs = [] + foreach(s, src_files) { + outputs += [ "${target_out_dir}/${musl_ported_dir}/${s}" ] + } + + args = [ "-i" ] + rebase_path(sources) + args += [ "-o" ] + rebase_path(outdir) + args += [ "-p" ] + [ "${musl_target_os}" ] +} + +action("create_alltypes_h") { + script = "${target_out_dir}/${musl_ported_dir}/scripts/create_alltypes.sh" + + outputs = [ "${target_out_dir}/${musl_inc_out_dir}/bits/alltypes.h" ] + + sources = [ + "${target_out_dir}/${musl_ported_dir}/tools/mkalltypes.sed", + "${target_out_dir}/${musl_ported_dir}/arch/${musl_arch}/bits/alltypes.h.in", + "${target_out_dir}/${musl_ported_dir}/include/alltypes.h.in", + ] + + args = [ "-o" ] + rebase_path(outputs, root_build_dir) + args += rebase_path(sources, root_build_dir) + + deps = [ ":create_porting_src" ] +} + +action("create_version_h") { + script = "${target_out_dir}/${musl_ported_dir}/scripts/create_vesion.sh" + + outputs = [ "${target_out_dir}/${musl_inc_out_dir}/version.h" ] + + sources = [ + "${target_out_dir}/${musl_ported_dir}/VERSION", + "${target_out_dir}/${musl_ported_dir}/tools/version.sh", + ] + + args = rebase_path(sources, root_build_dir) + args += + [ rebase_path("${target_out_dir}/${musl_inc_out_dir}", root_build_dir) ] + + deps = [ ":create_porting_src" ] +} + +action("create_syscall_h") { + script = "${target_out_dir}/${musl_ported_dir}/scripts/create_syscall.sh" + + outputs = [ "${target_out_dir}/${musl_inc_out_dir}/bits/syscall.h" ] + + sources = [ "${target_out_dir}/${musl_ported_dir}/arch/${musl_arch}/bits/syscall.h.in" ] + + args = rebase_path(sources, root_build_dir) + args += rebase_path(outputs, root_build_dir) + + deps = [ ":create_porting_src" ] +} + +copy("musl_copy_inc_bits") { + sources = [] + sources_orig = musl_inc_bits_files + foreach(s, sources_orig) { + sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ] + } + outputs = + [ "${target_out_dir}/${musl_inc_out_dir}/bits/{{source_file_part}}" ] + deps = [ ":create_porting_src" ] +} + +copy("musl_copy_inc_arpa") { + sources = [] + sources_orig = musl_inc_arpa_files + foreach(s, sources_orig) { + sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ] + } + outputs = + [ "${target_out_dir}/${musl_inc_out_dir}/arpa/{{source_file_part}}" ] + deps = [ ":create_porting_src" ] +} + +copy("musl_copy_inc_net") { + sources = [] + sources_orig = musl_inc_net_files + foreach(s, sources_orig) { + sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ] + } + outputs = [ "${target_out_dir}/${musl_inc_out_dir}/net/{{source_file_part}}" ] + deps = [ ":create_porting_src" ] +} + +copy("musl_copy_inc_netinet") { + sources = [] + sources_orig = musl_inc_netinet_files + foreach(s, sources_orig) { + sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ] + } + outputs = + [ "${target_out_dir}/${musl_inc_out_dir}/netinet/{{source_file_part}}" ] + deps = [ ":create_porting_src" ] +} + +copy("musl_copy_inc_netpacket") { + sources = [] + sources_orig = musl_inc_netpacket_files + foreach(s, sources_orig) { + sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ] + } + outputs = + [ "${target_out_dir}/${musl_inc_out_dir}/netpacket/{{source_file_part}}" ] + deps = [ ":create_porting_src" ] +} + +copy("musl_copy_inc_scsi") { + sources = [] + sources_orig = musl_inc_scsi_files + foreach(s, sources_orig) { + sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ] + } + outputs = + [ "${target_out_dir}/${musl_inc_out_dir}/scsi/{{source_file_part}}" ] + deps = [ ":create_porting_src" ] +} + +copy("musl_copy_inc_sys") { + sources = [] + sources_orig = musl_inc_sys_files + foreach(s, sources_orig) { + sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ] + } + outputs = [ "${target_out_dir}/${musl_inc_out_dir}/sys/{{source_file_part}}" ] + deps = [ ":create_porting_src" ] +} + +copy("musl_copy_inc_root") { + sources = [] + sources_orig = musl_inc_root_files + foreach(s, sources_orig) { + sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ] + } + outputs = [ "${target_out_dir}/${musl_inc_out_dir}/{{source_file_part}}" ] + deps = [ ":create_porting_src" ] +} diff --git a/musl_config.gni b/musl_config.gni new file mode 100644 index 0000000000000000000000000000000000000000..bc99e8607db0454391b76e47240bb2aebad27b5b --- /dev/null +++ b/musl_config.gni @@ -0,0 +1,45 @@ +# Copyright 2014 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. +import("//build/config/sanitizers/sanitizers.gni") + +declare_args() { + if (target_cpu == "arm") { + musl_arch = "arm" + } else if (target_cpu == "arm64") { + musl_arch = "aarch64" + } + # musl_root = "$root_out_dir/obj/third_party/musl" + # musl_sub_arch = "" + # musl_syslib_dir = "/system/bin" + # musl_linker_extension = "so.1" +} + +declare_args() { + if ((defined(target_os) && target_os == "ohos") || + (defined(ohos_kernel_type) && ohos_kernel_type == "linux")) { + musl_target_os = "linux" + musl_target_triple = "${musl_arch}-linux-ohosmusl" + } else if (defined(ohos_kernel_type) && ohos_kernel_type == "liteos_a") { + musl_target_os = "liteos_a" + musl_target_triple = "arm-liteos" + } +} + +declare_args() { + user_custom_libc = true + musl_ported_dir = "intermidiates/${musl_target_os}/musl_src_ported" + musl_inc_out_dir = "usr/include/${musl_target_triple}" + + # if (is_asan) { + # musl_linker_asan_name = + # musl_syslib_dir + "/ld-musl-${musl_arch}${musl_sub_arch}-asan" + # musl_ldso_path = + # musl_syslib_dir + "/ld-musl-${musl_arch}${musl_sub_arch}-asan." + + # musl_linker_extension + # } else { + # musl_ldso_path = + # musl_syslib_dir + "/ld-musl-${musl_arch}${musl_sub_arch}." + + # musl_linker_extension + # } +} diff --git a/musl_src.gni b/musl_src.gni new file mode 100644 index 0000000000000000000000000000000000000000..35fc989a22e3e0bcc281f85bb1021540d78fb67d --- /dev/null +++ b/musl_src.gni @@ -0,0 +1,1823 @@ +import("musl_config.gni") + +if (musl_arch == "arm") { + musl_src_arch_file = [ + "src/exit/arm/__aeabi_atexit.c", + "src/fenv/arm/fenv-hf.S", + "src/fenv/arm/fenv.c", + "src/ldso/arm/dlsym.s", + "src/ldso/arm/dlsym_time64.S", + "src/ldso/arm/find_exidx.c", + "src/ldso/arm/tlsdesc.S", + "src/math/arm/fabs.c", + "src/math/arm/fabsf.c", + "src/math/arm/fma.c", + "src/math/arm/fmaf.c", + "src/math/arm/sqrt.c", + "src/math/arm/sqrtf.c", + "src/process/arm/vfork.s", + "src/setjmp/arm/longjmp.S", + "src/setjmp/arm/setjmp.S", + "src/signal/arm/restore.s", + "src/signal/arm/sigsetjmp.s", + "src/string/arm/__aeabi_memcpy.s", + "src/string/arm/__aeabi_memset.s", + "src/string/arm/memcpy.c", + "src/string/arm/memcpy_le.S", + "src/thread/arm/__aeabi_read_tp.s", + "src/thread/arm/__set_thread_area.c", + "src/thread/arm/__unmapself.s", + "src/thread/arm/atomics.s", + "src/thread/arm/clone.s", + "src/thread/arm/syscall_cp.s", + "compat/time32/adjtime32.c", + "compat/time32/adjtimex_time32.c", + "compat/time32/aio_suspend_time32.c", + "compat/time32/clock_adjtime32.c", + "compat/time32/clock_getres_time32.c", + "compat/time32/clock_gettime32.c", + "compat/time32/clock_nanosleep_time32.c", + "compat/time32/clock_settime32.c", + "compat/time32/cnd_timedwait_time32.c", + "compat/time32/ctime32.c", + "compat/time32/ctime32_r.c", + "compat/time32/difftime32.c", + "compat/time32/fstatat_time32.c", + "compat/time32/fstat_time32.c", + "compat/time32/ftime32.c", + "compat/time32/futimens_time32.c", + "compat/time32/futimesat_time32.c", + "compat/time32/futimes_time32.c", + "compat/time32/getitimer_time32.c", + "compat/time32/getrusage_time32.c", + "compat/time32/gettimeofday_time32.c", + "compat/time32/gmtime32.c", + "compat/time32/gmtime32_r.c", + "compat/time32/localtime32.c", + "compat/time32/localtime32_r.c", + "compat/time32/lstat_time32.c", + "compat/time32/lutimes_time32.c", + "compat/time32/mktime32.c", + "compat/time32/mq_timedreceive_time32.c", + "compat/time32/mq_timedsend_time32.c", + "compat/time32/mtx_timedlock_time32.c", + "compat/time32/nanosleep_time32.c", + "compat/time32/ppoll_time32.c", + "compat/time32/pselect_time32.c", + "compat/time32/pthread_cond_timedwait_time32.c", + "compat/time32/pthread_mutex_timedlock_time32.c", + "compat/time32/pthread_rwlock_timedrdlock_time32.c", + "compat/time32/pthread_rwlock_timedwrlock_time32.c", + "compat/time32/pthread_timedjoin_np_time32.c", + "compat/time32/recvmmsg_time32.c", + "compat/time32/sched_rr_get_interval_time32.c", + "compat/time32/select_time32.c", + "compat/time32/semtimedop_time32.c", + "compat/time32/sem_timedwait_time32.c", + "compat/time32/setitimer_time32.c", + "compat/time32/settimeofday_time32.c", + "compat/time32/sigtimedwait_time32.c", + "compat/time32/stat_time32.c", + "compat/time32/stime32.c", + "compat/time32/thrd_sleep_time32.c", + "compat/time32/time32.c", + "compat/time32/time32gm.c", + "compat/time32/time32.h", + "compat/time32/timerfd_gettime32.c", + "compat/time32/timerfd_settime32.c", + "compat/time32/timer_gettime32.c", + "compat/time32/timer_settime32.c", + "compat/time32/timespec_get_time32.c", + "compat/time32/utimensat_time32.c", + "compat/time32/utimes_time32.c", + "compat/time32/utime_time32.c", + "compat/time32/wait3_time32.c", + "compat/time32/wait4_time32.c", + "compat/time32/__xstat.c", + ] +} else if (musl_arch == "aarch64") { + musl_src_arch_file = [ + "src/fenv/aarch64/fenv.s", + "src/ldso/aarch64/dlsym.s", + "src/ldso/aarch64/tlsdesc.s", + "src/math/aarch64/ceil.c", + "src/math/aarch64/ceilf.c", + "src/math/aarch64/fabs.c", + "src/math/aarch64/fabsf.c", + "src/math/aarch64/floor.c", + "src/math/aarch64/floorf.c", + "src/math/aarch64/fma.c", + "src/math/aarch64/fmaf.c", + "src/math/aarch64/fmax.c", + "src/math/aarch64/fmaxf.c", + "src/math/aarch64/fmin.c", + "src/math/aarch64/fminf.c", + "src/math/aarch64/llrint.c", + "src/math/aarch64/llrintf.c", + "src/math/aarch64/llround.c", + "src/math/aarch64/llroundf.c", + "src/math/aarch64/lrint.c", + "src/math/aarch64/lrintf.c", + "src/math/aarch64/lround.c", + "src/math/aarch64/lroundf.c", + "src/math/aarch64/nearbyint.c", + "src/math/aarch64/nearbyintf.c", + "src/math/aarch64/rint.c", + "src/math/aarch64/rintf.c", + "src/math/aarch64/round.c", + "src/math/aarch64/roundf.c", + "src/math/aarch64/sqrt.c", + "src/math/aarch64/sqrtf.c", + "src/math/aarch64/trunc.c", + "src/math/aarch64/truncf.c", + "src/setjmp/aarch64/longjmp.s", + "src/setjmp/aarch64/setjmp.s", + "src/signal/aarch64/restore.s", + "src/signal/aarch64/sigsetjmp.s", + "src/thread/aarch64/__set_thread_area.s", + "src/thread/aarch64/__unmapself.s", + "src/thread/aarch64/clone.s", + "src/thread/aarch64/syscall_cp.s", + ] +} + +musl_src_file = [ + "src/aio/aio.c", + "src/aio/aio_suspend.c", + "src/aio/lio_listio.c", + "src/complex/__cexp.c", + "src/complex/__cexpf.c", + "src/complex/cabs.c", + "src/complex/cabsf.c", + "src/complex/cabsl.c", + "src/complex/cacos.c", + "src/complex/cacosf.c", + "src/complex/cacosh.c", + "src/complex/cacoshf.c", + "src/complex/cacoshl.c", + "src/complex/cacosl.c", + "src/complex/carg.c", + "src/complex/cargf.c", + "src/complex/cargl.c", + "src/complex/casin.c", + "src/complex/casinf.c", + "src/complex/casinh.c", + "src/complex/casinhf.c", + "src/complex/casinhl.c", + "src/complex/casinl.c", + "src/complex/catan.c", + "src/complex/catanf.c", + "src/complex/catanh.c", + "src/complex/catanhf.c", + "src/complex/catanhl.c", + "src/complex/catanl.c", + "src/complex/ccos.c", + "src/complex/ccosf.c", + "src/complex/ccosh.c", + "src/complex/ccoshf.c", + "src/complex/ccoshl.c", + "src/complex/ccosl.c", + "src/complex/cexp.c", + "src/complex/cexpf.c", + "src/complex/cexpl.c", + "src/complex/cimag.c", + "src/complex/cimagf.c", + "src/complex/cimagl.c", + "src/complex/clog.c", + "src/complex/clogf.c", + "src/complex/clogl.c", + "src/complex/conj.c", + "src/complex/conjf.c", + "src/complex/conjl.c", + "src/complex/cpow.c", + "src/complex/cpowf.c", + "src/complex/cpowl.c", + "src/complex/cproj.c", + "src/complex/cprojf.c", + "src/complex/cprojl.c", + "src/complex/creal.c", + "src/complex/crealf.c", + "src/complex/creall.c", + "src/complex/csin.c", + "src/complex/csinf.c", + "src/complex/csinh.c", + "src/complex/csinhf.c", + "src/complex/csinhl.c", + "src/complex/csinl.c", + "src/complex/csqrt.c", + "src/complex/csqrtf.c", + "src/complex/csqrtl.c", + "src/complex/ctan.c", + "src/complex/ctanf.c", + "src/complex/ctanh.c", + "src/complex/ctanhf.c", + "src/complex/ctanhl.c", + "src/complex/ctanl.c", + "src/conf/confstr.c", + "src/conf/fpathconf.c", + "src/conf/legacy.c", + "src/conf/pathconf.c", + "src/conf/sysconf.c", + "src/crypt/crypt.c", + "src/crypt/crypt_blowfish.c", + "src/crypt/crypt_des.c", + "src/crypt/crypt_md5.c", + "src/crypt/crypt_r.c", + "src/crypt/crypt_sha256.c", + "src/crypt/crypt_sha512.c", + "src/crypt/encrypt.c", + "src/ctype/__ctype_b_loc.c", + "src/ctype/__ctype_get_mb_cur_max.c", + "src/ctype/__ctype_tolower_loc.c", + "src/ctype/__ctype_toupper_loc.c", + "src/ctype/isalnum.c", + "src/ctype/isalpha.c", + "src/ctype/isascii.c", + "src/ctype/isblank.c", + "src/ctype/iscntrl.c", + "src/ctype/isdigit.c", + "src/ctype/isgraph.c", + "src/ctype/islower.c", + "src/ctype/isprint.c", + "src/ctype/ispunct.c", + "src/ctype/isspace.c", + "src/ctype/isupper.c", + "src/ctype/iswalnum.c", + "src/ctype/iswalpha.c", + "src/ctype/iswblank.c", + "src/ctype/iswcntrl.c", + "src/ctype/iswctype.c", + "src/ctype/iswdigit.c", + "src/ctype/iswgraph.c", + "src/ctype/iswlower.c", + "src/ctype/iswprint.c", + "src/ctype/iswpunct.c", + "src/ctype/iswspace.c", + "src/ctype/iswupper.c", + "src/ctype/iswxdigit.c", + "src/ctype/isxdigit.c", + "src/ctype/toascii.c", + "src/ctype/tolower.c", + "src/ctype/toupper.c", + "src/ctype/towctrans.c", + "src/ctype/wcswidth.c", + "src/ctype/wctrans.c", + "src/ctype/wcwidth.c", + "src/dirent/alphasort.c", + "src/dirent/closedir.c", + "src/dirent/dirfd.c", + "src/dirent/fdopendir.c", + "src/dirent/opendir.c", + "src/dirent/readdir.c", + "src/dirent/readdir_r.c", + "src/dirent/rewinddir.c", + "src/dirent/scandir.c", + "src/dirent/seekdir.c", + "src/dirent/telldir.c", + "src/dirent/versionsort.c", + "src/env/__environ.c", + "src/env/__init_tls.c", + "src/env/__libc_start_main.c", + "src/env/__reset_tls.c", + "src/env/__stack_chk_fail.c", + "src/env/clearenv.c", + "src/env/getenv.c", + "src/env/putenv.c", + "src/env/secure_getenv.c", + "src/env/setenv.c", + "src/env/unsetenv.c", + "src/errno/__errno_location.c", + "src/errno/strerror.c", + "src/exit/_Exit.c", + "src/exit/abort.c", + "src/exit/assert.c", + "src/exit/at_quick_exit.c", + "src/exit/atexit.c", + "src/exit/exit.c", + "src/exit/quick_exit.c", + "src/fcntl/creat.c", + "src/fcntl/fcntl.c", + "src/fcntl/open.c", + "src/fcntl/openat.c", + "src/fcntl/posix_fadvise.c", + "src/fcntl/posix_fallocate.c", + "src/fenv/__flt_rounds.c", + "src/fenv/fegetexceptflag.c", + "src/fenv/feholdexcept.c", + "src/fenv/fenv.c", + "src/fenv/fesetexceptflag.c", + "src/fenv/fesetround.c", + "src/fenv/feupdateenv.c", + "src/internal/defsysinfo.c", + "src/internal/floatscan.c", + "src/internal/intscan.c", + "src/internal/libc.c", + "src/internal/procfdname.c", + "src/internal/shgetc.c", + "src/internal/syscall_ret.c", + "src/internal/vdso.c", + "src/internal/version.c", + "src/ipc/ftok.c", + "src/ipc/msgctl.c", + "src/ipc/msgget.c", + "src/ipc/msgrcv.c", + "src/ipc/msgsnd.c", + "src/ipc/semctl.c", + "src/ipc/semget.c", + "src/ipc/semop.c", + "src/ipc/semtimedop.c", + "src/ipc/shmat.c", + "src/ipc/shmctl.c", + "src/ipc/shmdt.c", + "src/ipc/shmget.c", + "src/ldso/__dlsym.c", + "src/ldso/dl_iterate_phdr.c", + "src/ldso/dladdr.c", + "src/ldso/dlclose.c", + "src/ldso/dlerror.c", + "src/ldso/dlinfo.c", + "src/ldso/dlopen.c", + "src/ldso/dlsym.c", + "src/ldso/tlsdesc.c", + "src/legacy/cuserid.c", + "src/legacy/daemon.c", + "src/legacy/err.c", + "src/legacy/euidaccess.c", + "src/legacy/ftw.c", + "src/legacy/futimes.c", + "src/legacy/getdtablesize.c", + "src/legacy/getloadavg.c", + "src/legacy/getpagesize.c", + "src/legacy/getpass.c", + "src/legacy/getusershell.c", + "src/legacy/isastream.c", + "src/legacy/lutimes.c", + "src/legacy/ulimit.c", + "src/legacy/utmpx.c", + "src/legacy/valloc.c", + "src/linux/adjtime.c", + "src/linux/adjtimex.c", + "src/linux/arch_prctl.c", + "src/linux/brk.c", + "src/linux/cache.c", + "src/linux/cap.c", + "src/linux/chroot.c", + "src/linux/clock_adjtime.c", + "src/linux/clone.c", + "src/linux/copy_file_range.c", + "src/linux/epoll.c", + "src/linux/eventfd.c", + "src/linux/fallocate.c", + "src/linux/fanotify.c", + "src/linux/flock.c", + "src/linux/getdents.c", + "src/linux/getrandom.c", + "src/linux/inotify.c", + "src/linux/ioperm.c", + "src/linux/iopl.c", + "src/linux/klogctl.c", + "src/linux/membarrier.c", + "src/linux/memfd_create.c", + "src/linux/mlock2.c", + "src/linux/module.c", + "src/linux/mount.c", + "src/linux/name_to_handle_at.c", + "src/linux/open_by_handle_at.c", + "src/linux/personality.c", + "src/linux/pivot_root.c", + "src/linux/ppoll.c", + "src/linux/prctl.c", + "src/linux/prlimit.c", + "src/linux/process_vm.c", + "src/linux/ptrace.c", + "src/linux/quotactl.c", + "src/linux/readahead.c", + "src/linux/reboot.c", + "src/linux/remap_file_pages.c", + "src/linux/sbrk.c", + "src/linux/sendfile.c", + "src/linux/setfsgid.c", + "src/linux/setfsuid.c", + "src/linux/setgroups.c", + "src/linux/sethostname.c", + "src/linux/setns.c", + "src/linux/settimeofday.c", + "src/linux/signalfd.c", + "src/linux/splice.c", + "src/linux/stime.c", + "src/linux/swap.c", + "src/linux/sync_file_range.c", + "src/linux/syncfs.c", + "src/linux/sysinfo.c", + "src/linux/tee.c", + "src/linux/timerfd.c", + "src/linux/unshare.c", + "src/linux/utimes.c", + "src/linux/vhangup.c", + "src/linux/vmsplice.c", + "src/linux/wait3.c", + "src/linux/wait4.c", + "src/linux/xattr.c", + "src/locale/__lctrans.c", + "src/locale/__mo_lookup.c", + "src/locale/bind_textdomain_codeset.c", + "src/locale/c_locale.c", + "src/locale/catclose.c", + "src/locale/catgets.c", + "src/locale/catopen.c", + "src/locale/dcngettext.c", + "src/locale/duplocale.c", + "src/locale/freelocale.c", + "src/locale/iconv.c", + "src/locale/iconv_close.c", + "src/locale/langinfo.c", + "src/locale/locale_map.c", + "src/locale/localeconv.c", + "src/locale/newlocale.c", + "src/locale/pleval.c", + "src/locale/setlocale.c", + "src/locale/strcoll.c", + "src/locale/strfmon.c", + "src/locale/strxfrm.c", + "src/locale/textdomain.c", + "src/locale/uselocale.c", + "src/locale/wcscoll.c", + "src/locale/wcsxfrm.c", + "src/malloc/aligned_alloc.c", + "src/malloc/expand_heap.c", + "src/malloc/lite_malloc.c", + "src/malloc/malloc.c", + "src/malloc/malloc_usable_size.c", + "src/malloc/memalign.c", + "src/malloc/posix_memalign.c", + "src/math/__cos.c", + "src/math/__cosdf.c", + "src/math/__cosl.c", + "src/math/__expo2.c", + "src/math/__expo2f.c", + "src/math/__fpclassify.c", + "src/math/__fpclassifyf.c", + "src/math/__fpclassifyl.c", + "src/math/__invtrigl.c", + "src/math/__math_divzero.c", + "src/math/__math_divzerof.c", + "src/math/__math_invalid.c", + "src/math/__math_invalidf.c", + "src/math/__math_oflow.c", + "src/math/__math_oflowf.c", + "src/math/__math_uflow.c", + "src/math/__math_uflowf.c", + "src/math/__math_xflow.c", + "src/math/__math_xflowf.c", + "src/math/__polevll.c", + "src/math/__rem_pio2.c", + "src/math/__rem_pio2_large.c", + "src/math/__rem_pio2f.c", + "src/math/__rem_pio2l.c", + "src/math/__signbit.c", + "src/math/__signbitf.c", + "src/math/__signbitl.c", + "src/math/__sin.c", + "src/math/__sindf.c", + "src/math/__sinl.c", + "src/math/__tan.c", + "src/math/__tandf.c", + "src/math/__tanl.c", + "src/math/acos.c", + "src/math/acosf.c", + "src/math/acosh.c", + "src/math/acoshf.c", + "src/math/acoshl.c", + "src/math/acosl.c", + "src/math/asin.c", + "src/math/asinf.c", + "src/math/asinh.c", + "src/math/asinhf.c", + "src/math/asinhl.c", + "src/math/asinl.c", + "src/math/atan.c", + "src/math/atan2.c", + "src/math/atan2f.c", + "src/math/atan2l.c", + "src/math/atanf.c", + "src/math/atanh.c", + "src/math/atanhf.c", + "src/math/atanhl.c", + "src/math/atanl.c", + "src/math/cbrt.c", + "src/math/cbrtf.c", + "src/math/cbrtl.c", + "src/math/ceil.c", + "src/math/ceilf.c", + "src/math/ceill.c", + "src/math/copysign.c", + "src/math/copysignf.c", + "src/math/copysignl.c", + "src/math/cos.c", + "src/math/cosf.c", + "src/math/cosh.c", + "src/math/coshf.c", + "src/math/coshl.c", + "src/math/cosl.c", + "src/math/erf.c", + "src/math/erff.c", + "src/math/erfl.c", + "src/math/exp.c", + "src/math/exp10.c", + "src/math/exp10f.c", + "src/math/exp10l.c", + "src/math/exp2.c", + "src/math/exp2f.c", + "src/math/exp2f_data.c", + "src/math/exp2l.c", + "src/math/exp_data.c", + "src/math/expf.c", + "src/math/expl.c", + "src/math/expm1.c", + "src/math/expm1f.c", + "src/math/expm1l.c", + "src/math/fabs.c", + "src/math/fabsf.c", + "src/math/fabsl.c", + "src/math/fdim.c", + "src/math/fdimf.c", + "src/math/fdiml.c", + "src/math/finite.c", + "src/math/finitef.c", + "src/math/floor.c", + "src/math/floorf.c", + "src/math/floorl.c", + "src/math/fma.c", + "src/math/fmaf.c", + "src/math/fmal.c", + "src/math/fmax.c", + "src/math/fmaxf.c", + "src/math/fmaxl.c", + "src/math/fmin.c", + "src/math/fminf.c", + "src/math/fminl.c", + "src/math/fmod.c", + "src/math/fmodf.c", + "src/math/fmodl.c", + "src/math/frexp.c", + "src/math/frexpf.c", + "src/math/frexpl.c", + "src/math/hypot.c", + "src/math/hypotf.c", + "src/math/hypotl.c", + "src/math/ilogb.c", + "src/math/ilogbf.c", + "src/math/ilogbl.c", + "src/math/j0.c", + "src/math/j0f.c", + "src/math/j1.c", + "src/math/j1f.c", + "src/math/jn.c", + "src/math/jnf.c", + "src/math/ldexp.c", + "src/math/ldexpf.c", + "src/math/ldexpl.c", + "src/math/lgamma.c", + "src/math/lgamma_r.c", + "src/math/lgammaf.c", + "src/math/lgammaf_r.c", + "src/math/lgammal.c", + "src/math/llrint.c", + "src/math/llrintf.c", + "src/math/llrintl.c", + "src/math/llround.c", + "src/math/llroundf.c", + "src/math/llroundl.c", + "src/math/log.c", + "src/math/log10.c", + "src/math/log10f.c", + "src/math/log10l.c", + "src/math/log1p.c", + "src/math/log1pf.c", + "src/math/log1pl.c", + "src/math/log2.c", + "src/math/log2_data.c", + "src/math/log2f.c", + "src/math/log2f_data.c", + "src/math/log2l.c", + "src/math/log_data.c", + "src/math/logb.c", + "src/math/logbf.c", + "src/math/logbl.c", + "src/math/logf.c", + "src/math/logf_data.c", + "src/math/logl.c", + "src/math/lrint.c", + "src/math/lrintf.c", + "src/math/lrintl.c", + "src/math/lround.c", + "src/math/lroundf.c", + "src/math/lroundl.c", + "src/math/modf.c", + "src/math/modff.c", + "src/math/modfl.c", + "src/math/nan.c", + "src/math/nanf.c", + "src/math/nanl.c", + "src/math/nearbyint.c", + "src/math/nearbyintf.c", + "src/math/nearbyintl.c", + "src/math/nextafter.c", + "src/math/nextafterf.c", + "src/math/nextafterl.c", + "src/math/nexttoward.c", + "src/math/nexttowardf.c", + "src/math/nexttowardl.c", + "src/math/pow.c", + "src/math/pow_data.c", + "src/math/powf.c", + "src/math/powf_data.c", + "src/math/powl.c", + "src/math/remainder.c", + "src/math/remainderf.c", + "src/math/remainderl.c", + "src/math/remquo.c", + "src/math/remquof.c", + "src/math/remquol.c", + "src/math/rint.c", + "src/math/rintf.c", + "src/math/rintl.c", + "src/math/round.c", + "src/math/roundf.c", + "src/math/roundl.c", + "src/math/scalb.c", + "src/math/scalbf.c", + "src/math/scalbln.c", + "src/math/scalblnf.c", + "src/math/scalblnl.c", + "src/math/scalbn.c", + "src/math/scalbnf.c", + "src/math/scalbnl.c", + "src/math/signgam.c", + "src/math/significand.c", + "src/math/significandf.c", + "src/math/sin.c", + "src/math/sincos.c", + "src/math/sincosf.c", + "src/math/sincosl.c", + "src/math/sinf.c", + "src/math/sinh.c", + "src/math/sinhf.c", + "src/math/sinhl.c", + "src/math/sinl.c", + "src/math/sqrt.c", + "src/math/sqrtf.c", + "src/math/sqrtl.c", + "src/math/tan.c", + "src/math/tanf.c", + "src/math/tanh.c", + "src/math/tanhf.c", + "src/math/tanhl.c", + "src/math/tanl.c", + "src/math/tgamma.c", + "src/math/tgammaf.c", + "src/math/tgammal.c", + "src/math/trunc.c", + "src/math/truncf.c", + "src/math/truncl.c", + "src/misc/a64l.c", + "src/misc/basename.c", + "src/misc/dirname.c", + "src/misc/ffs.c", + "src/misc/ffsl.c", + "src/misc/ffsll.c", + "src/misc/fmtmsg.c", + "src/misc/forkpty.c", + "src/misc/get_current_dir_name.c", + "src/misc/getauxval.c", + "src/misc/getdomainname.c", + "src/misc/getentropy.c", + "src/misc/gethostid.c", + "src/misc/getopt.c", + "src/misc/getopt_long.c", + "src/misc/getpriority.c", + "src/misc/getresgid.c", + "src/misc/getresuid.c", + "src/misc/getrlimit.c", + "src/misc/getrusage.c", + "src/misc/getsubopt.c", + "src/misc/initgroups.c", + "src/misc/ioctl.c", + "src/misc/issetugid.c", + "src/misc/lockf.c", + "src/misc/login_tty.c", + "src/misc/mntent.c", + "src/misc/nftw.c", + "src/misc/openpty.c", + "src/misc/ptsname.c", + "src/misc/pty.c", + "src/misc/realpath.c", + "src/misc/setdomainname.c", + "src/misc/setpriority.c", + "src/misc/setrlimit.c", + "src/misc/syscall.c", + "src/misc/syslog.c", + "src/misc/uname.c", + "src/misc/wordexp.c", + "src/mman/madvise.c", + "src/mman/mincore.c", + "src/mman/mlock.c", + "src/mman/mlockall.c", + "src/mman/mmap.c", + "src/mman/mprotect.c", + "src/mman/mremap.c", + "src/mman/msync.c", + "src/mman/munlock.c", + "src/mman/munlockall.c", + "src/mman/munmap.c", + "src/mman/posix_madvise.c", + "src/mman/shm_open.c", + "src/mq/mq_close.c", + "src/mq/mq_getattr.c", + "src/mq/mq_notify.c", + "src/mq/mq_open.c", + "src/mq/mq_receive.c", + "src/mq/mq_send.c", + "src/mq/mq_setattr.c", + "src/mq/mq_timedreceive.c", + "src/mq/mq_timedsend.c", + "src/mq/mq_unlink.c", + "src/multibyte/btowc.c", + "src/multibyte/c16rtomb.c", + "src/multibyte/c32rtomb.c", + "src/multibyte/internal.c", + "src/multibyte/mblen.c", + "src/multibyte/mbrlen.c", + "src/multibyte/mbrtoc16.c", + "src/multibyte/mbrtoc32.c", + "src/multibyte/mbrtowc.c", + "src/multibyte/mbsinit.c", + "src/multibyte/mbsnrtowcs.c", + "src/multibyte/mbsrtowcs.c", + "src/multibyte/mbstowcs.c", + "src/multibyte/mbtowc.c", + "src/multibyte/wcrtomb.c", + "src/multibyte/wcsnrtombs.c", + "src/multibyte/wcsrtombs.c", + "src/multibyte/wcstombs.c", + "src/multibyte/wctob.c", + "src/multibyte/wctomb.c", + "src/network/accept.c", + "src/network/accept4.c", + "src/network/bind.c", + "src/network/connect.c", + "src/network/dn_comp.c", + "src/network/dn_expand.c", + "src/network/dn_skipname.c", + "src/network/dns_parse.c", + "src/network/ent.c", + "src/network/ether.c", + "src/network/freeaddrinfo.c", + "src/network/gai_strerror.c", + "src/network/getaddrinfo.c", + "src/network/gethostbyaddr.c", + "src/network/gethostbyaddr_r.c", + "src/network/gethostbyname.c", + "src/network/gethostbyname2.c", + "src/network/gethostbyname2_r.c", + "src/network/gethostbyname_r.c", + "src/network/getifaddrs.c", + "src/network/getnameinfo.c", + "src/network/getpeername.c", + "src/network/getservbyname.c", + "src/network/getservbyname_r.c", + "src/network/getservbyport.c", + "src/network/getservbyport_r.c", + "src/network/getsockname.c", + "src/network/getsockopt.c", + "src/network/h_errno.c", + "src/network/herror.c", + "src/network/hstrerror.c", + "src/network/htonl.c", + "src/network/htons.c", + "src/network/if_freenameindex.c", + "src/network/if_indextoname.c", + "src/network/if_nameindex.c", + "src/network/if_nametoindex.c", + "src/network/in6addr_any.c", + "src/network/in6addr_loopback.c", + "src/network/inet_addr.c", + "src/network/inet_aton.c", + "src/network/inet_legacy.c", + "src/network/inet_ntoa.c", + "src/network/inet_ntop.c", + "src/network/inet_pton.c", + "src/network/listen.c", + "src/network/lookup_ipliteral.c", + "src/network/lookup_name.c", + "src/network/lookup_serv.c", + "src/network/netlink.c", + "src/network/netname.c", + "src/network/ns_parse.c", + "src/network/ntohl.c", + "src/network/ntohs.c", + "src/network/proto.c", + "src/network/recv.c", + "src/network/recvfrom.c", + "src/network/recvmmsg.c", + "src/network/recvmsg.c", + "src/network/res_init.c", + "src/network/res_mkquery.c", + "src/network/res_msend.c", + "src/network/res_query.c", + "src/network/res_querydomain.c", + "src/network/res_send.c", + "src/network/res_state.c", + "src/network/resolvconf.c", + "src/network/send.c", + "src/network/sendmmsg.c", + "src/network/sendmsg.c", + "src/network/sendto.c", + "src/network/serv.c", + "src/network/setsockopt.c", + "src/network/shutdown.c", + "src/network/sockatmark.c", + "src/network/socket.c", + "src/network/socketpair.c", + "src/passwd/fgetgrent.c", + "src/passwd/fgetpwent.c", + "src/passwd/fgetspent.c", + "src/passwd/getgr_a.c", + "src/passwd/getgr_r.c", + "src/passwd/getgrent.c", + "src/passwd/getgrent_a.c", + "src/passwd/getgrouplist.c", + "src/passwd/getpw_a.c", + "src/passwd/getpw_r.c", + "src/passwd/getpwent.c", + "src/passwd/getpwent_a.c", + "src/passwd/getspent.c", + "src/passwd/getspnam.c", + "src/passwd/getspnam_r.c", + "src/passwd/lckpwdf.c", + "src/passwd/nscd_query.c", + "src/passwd/putgrent.c", + "src/passwd/putpwent.c", + "src/passwd/putspent.c", + "src/prng/__rand48_step.c", + "src/prng/__seed48.c", + "src/prng/drand48.c", + "src/prng/lcong48.c", + "src/prng/lrand48.c", + "src/prng/mrand48.c", + "src/prng/rand.c", + "src/prng/rand_r.c", + "src/prng/random.c", + "src/prng/seed48.c", + "src/prng/srand48.c", + "src/process/execl.c", + "src/process/execle.c", + "src/process/execlp.c", + "src/process/execv.c", + "src/process/execve.c", + "src/process/execvp.c", + "src/process/fexecve.c", + "src/process/fork.c", + "src/process/posix_spawn.c", + "src/process/posix_spawn_file_actions_addchdir.c", + "src/process/posix_spawn_file_actions_addclose.c", + "src/process/posix_spawn_file_actions_adddup2.c", + "src/process/posix_spawn_file_actions_addfchdir.c", + "src/process/posix_spawn_file_actions_addopen.c", + "src/process/posix_spawn_file_actions_destroy.c", + "src/process/posix_spawn_file_actions_init.c", + "src/process/posix_spawnattr_destroy.c", + "src/process/posix_spawnattr_getflags.c", + "src/process/posix_spawnattr_getpgroup.c", + "src/process/posix_spawnattr_getsigdefault.c", + "src/process/posix_spawnattr_getsigmask.c", + "src/process/posix_spawnattr_init.c", + "src/process/posix_spawnattr_sched.c", + "src/process/posix_spawnattr_setflags.c", + "src/process/posix_spawnattr_setpgroup.c", + "src/process/posix_spawnattr_setsigdefault.c", + "src/process/posix_spawnattr_setsigmask.c", + "src/process/posix_spawnp.c", + "src/process/system.c", + "src/process/vfork.c", + "src/process/wait.c", + "src/process/waitid.c", + "src/process/waitpid.c", + "src/regex/fnmatch.c", + "src/regex/glob.c", + "src/regex/regcomp.c", + "src/regex/regerror.c", + "src/regex/regexec.c", + "src/regex/tre-mem.c", + "src/sched/affinity.c", + "src/sched/sched_cpucount.c", + "src/sched/sched_get_priority_max.c", + "src/sched/sched_getcpu.c", + "src/sched/sched_getparam.c", + "src/sched/sched_getscheduler.c", + "src/sched/sched_rr_get_interval.c", + "src/sched/sched_setparam.c", + "src/sched/sched_setscheduler.c", + "src/sched/sched_yield.c", + "src/search/hsearch.c", + "src/search/insque.c", + "src/search/lsearch.c", + "src/search/tdelete.c", + "src/search/tdestroy.c", + "src/search/tfind.c", + "src/search/tsearch.c", + "src/search/twalk.c", + "src/select/poll.c", + "src/select/pselect.c", + "src/select/select.c", + "src/setjmp/longjmp.c", + "src/setjmp/setjmp.c", + "src/signal/block.c", + "src/signal/getitimer.c", + "src/signal/kill.c", + "src/signal/killpg.c", + "src/signal/psiginfo.c", + "src/signal/psignal.c", + "src/signal/raise.c", + "src/signal/restore.c", + "src/signal/setitimer.c", + "src/signal/sigaction.c", + "src/signal/sigaddset.c", + "src/signal/sigaltstack.c", + "src/signal/sigandset.c", + "src/signal/sigdelset.c", + "src/signal/sigemptyset.c", + "src/signal/sigfillset.c", + "src/signal/sighold.c", + "src/signal/sigignore.c", + "src/signal/siginterrupt.c", + "src/signal/sigisemptyset.c", + "src/signal/sigismember.c", + "src/signal/siglongjmp.c", + "src/signal/signal.c", + "src/signal/sigorset.c", + "src/signal/sigpause.c", + "src/signal/sigpending.c", + "src/signal/sigprocmask.c", + "src/signal/sigqueue.c", + "src/signal/sigrelse.c", + "src/signal/sigrtmax.c", + "src/signal/sigrtmin.c", + "src/signal/sigset.c", + "src/signal/sigsetjmp.c", + "src/signal/sigsetjmp_tail.c", + "src/signal/sigsuspend.c", + "src/signal/sigtimedwait.c", + "src/signal/sigwait.c", + "src/signal/sigwaitinfo.c", + "src/stat/__xstat.c", + "src/stat/chmod.c", + "src/stat/fchmod.c", + "src/stat/fchmodat.c", + "src/stat/fstat.c", + "src/stat/fstatat.c", + "src/stat/futimens.c", + "src/stat/futimesat.c", + "src/stat/lchmod.c", + "src/stat/lstat.c", + "src/stat/mkdir.c", + "src/stat/mkdirat.c", + "src/stat/mkfifo.c", + "src/stat/mkfifoat.c", + "src/stat/mknod.c", + "src/stat/mknodat.c", + "src/stat/stat.c", + "src/stat/statvfs.c", + "src/stat/umask.c", + "src/stat/utimensat.c", + "src/stdio/__fclose_ca.c", + "src/stdio/__fdopen.c", + "src/stdio/__fmodeflags.c", + "src/stdio/__fopen_rb_ca.c", + "src/stdio/__lockfile.c", + "src/stdio/__overflow.c", + "src/stdio/__stdio_close.c", + "src/stdio/__stdio_exit.c", + "src/stdio/__stdio_read.c", + "src/stdio/__stdio_seek.c", + "src/stdio/__stdio_write.c", + "src/stdio/__stdout_write.c", + "src/stdio/__string_read.c", + "src/stdio/__toread.c", + "src/stdio/__towrite.c", + "src/stdio/__uflow.c", + "src/stdio/asprintf.c", + "src/stdio/clearerr.c", + "src/stdio/dprintf.c", + "src/stdio/ext.c", + "src/stdio/ext2.c", + "src/stdio/fclose.c", + "src/stdio/feof.c", + "src/stdio/ferror.c", + "src/stdio/fflush.c", + "src/stdio/fgetc.c", + "src/stdio/fgetln.c", + "src/stdio/fgetpos.c", + "src/stdio/fgets.c", + "src/stdio/fgetwc.c", + "src/stdio/fgetws.c", + "src/stdio/fileno.c", + "src/stdio/flockfile.c", + "src/stdio/fmemopen.c", + "src/stdio/fopen.c", + "src/stdio/fopencookie.c", + "src/stdio/fprintf.c", + "src/stdio/fputc.c", + "src/stdio/fputs.c", + "src/stdio/fputwc.c", + "src/stdio/fputws.c", + "src/stdio/fread.c", + "src/stdio/freopen.c", + "src/stdio/fscanf.c", + "src/stdio/fseek.c", + "src/stdio/fsetpos.c", + "src/stdio/ftell.c", + "src/stdio/ftrylockfile.c", + "src/stdio/funlockfile.c", + "src/stdio/fwide.c", + "src/stdio/fwprintf.c", + "src/stdio/fwrite.c", + "src/stdio/fwscanf.c", + "src/stdio/getc.c", + "src/stdio/getc_unlocked.c", + "src/stdio/getchar.c", + "src/stdio/getchar_unlocked.c", + "src/stdio/getdelim.c", + "src/stdio/getline.c", + "src/stdio/gets.c", + "src/stdio/getw.c", + "src/stdio/getwc.c", + "src/stdio/getwchar.c", + "src/stdio/ofl.c", + "src/stdio/ofl_add.c", + "src/stdio/open_memstream.c", + "src/stdio/open_wmemstream.c", + "src/stdio/pclose.c", + "src/stdio/perror.c", + "src/stdio/popen.c", + "src/stdio/printf.c", + "src/stdio/putc.c", + "src/stdio/putc_unlocked.c", + "src/stdio/putchar.c", + "src/stdio/putchar_unlocked.c", + "src/stdio/puts.c", + "src/stdio/putw.c", + "src/stdio/putwc.c", + "src/stdio/putwchar.c", + "src/stdio/remove.c", + "src/stdio/rename.c", + "src/stdio/rewind.c", + "src/stdio/scanf.c", + "src/stdio/setbuf.c", + "src/stdio/setbuffer.c", + "src/stdio/setlinebuf.c", + "src/stdio/setvbuf.c", + "src/stdio/snprintf.c", + "src/stdio/sprintf.c", + "src/stdio/sscanf.c", + "src/stdio/stderr.c", + "src/stdio/stdin.c", + "src/stdio/stdout.c", + "src/stdio/swprintf.c", + "src/stdio/swscanf.c", + "src/stdio/tempnam.c", + "src/stdio/tmpfile.c", + "src/stdio/tmpnam.c", + "src/stdio/ungetc.c", + "src/stdio/ungetwc.c", + "src/stdio/vasprintf.c", + "src/stdio/vdprintf.c", + "src/stdio/vfprintf.c", + "src/stdio/vfscanf.c", + "src/stdio/vfwprintf.c", + "src/stdio/vfwscanf.c", + "src/stdio/vprintf.c", + "src/stdio/vscanf.c", + "src/stdio/vsnprintf.c", + "src/stdio/vsprintf.c", + "src/stdio/vsscanf.c", + "src/stdio/vswprintf.c", + "src/stdio/vswscanf.c", + "src/stdio/vwprintf.c", + "src/stdio/vwscanf.c", + "src/stdio/wprintf.c", + "src/stdio/wscanf.c", + "src/stdlib/abs.c", + "src/stdlib/atof.c", + "src/stdlib/atoi.c", + "src/stdlib/atol.c", + "src/stdlib/atoll.c", + "src/stdlib/bsearch.c", + "src/stdlib/div.c", + "src/stdlib/ecvt.c", + "src/stdlib/fcvt.c", + "src/stdlib/gcvt.c", + "src/stdlib/imaxabs.c", + "src/stdlib/imaxdiv.c", + "src/stdlib/labs.c", + "src/stdlib/ldiv.c", + "src/stdlib/llabs.c", + "src/stdlib/lldiv.c", + "src/stdlib/qsort.c", + "src/stdlib/strtod.c", + "src/stdlib/strtol.c", + "src/stdlib/wcstod.c", + "src/stdlib/wcstol.c", + "src/string/bcmp.c", + "src/string/bcopy.c", + "src/string/bzero.c", + "src/string/explicit_bzero.c", + "src/string/index.c", + "src/string/memccpy.c", + "src/string/memchr.c", + "src/string/memcmp.c", + "src/string/memcpy.c", + "src/string/memmem.c", + "src/string/memmove.c", + "src/string/mempcpy.c", + "src/string/memrchr.c", + "src/string/memset.c", + "src/string/rindex.c", + "src/string/stpcpy.c", + "src/string/stpncpy.c", + "src/string/strcasecmp.c", + "src/string/strcasestr.c", + "src/string/strcat.c", + "src/string/strchr.c", + "src/string/strchrnul.c", + "src/string/strcmp.c", + "src/string/strcpy.c", + "src/string/strcspn.c", + "src/string/strdup.c", + "src/string/strerror_r.c", + "src/string/strlcat.c", + "src/string/strlcpy.c", + "src/string/strlen.c", + "src/string/strncasecmp.c", + "src/string/strncat.c", + "src/string/strncmp.c", + "src/string/strncpy.c", + "src/string/strndup.c", + "src/string/strnlen.c", + "src/string/strpbrk.c", + "src/string/strrchr.c", + "src/string/strsep.c", + "src/string/strsignal.c", + "src/string/strspn.c", + "src/string/strstr.c", + "src/string/strtok.c", + "src/string/strtok_r.c", + "src/string/strverscmp.c", + "src/string/swab.c", + "src/string/wcpcpy.c", + "src/string/wcpncpy.c", + "src/string/wcscasecmp.c", + "src/string/wcscasecmp_l.c", + "src/string/wcscat.c", + "src/string/wcschr.c", + "src/string/wcscmp.c", + "src/string/wcscpy.c", + "src/string/wcscspn.c", + "src/string/wcsdup.c", + "src/string/wcslen.c", + "src/string/wcsncasecmp.c", + "src/string/wcsncasecmp_l.c", + "src/string/wcsncat.c", + "src/string/wcsncmp.c", + "src/string/wcsncpy.c", + "src/string/wcsnlen.c", + "src/string/wcspbrk.c", + "src/string/wcsrchr.c", + "src/string/wcsspn.c", + "src/string/wcsstr.c", + "src/string/wcstok.c", + "src/string/wcswcs.c", + "src/string/wmemchr.c", + "src/string/wmemcmp.c", + "src/string/wmemcpy.c", + "src/string/wmemmove.c", + "src/string/wmemset.c", + "src/temp/__randname.c", + "src/temp/mkdtemp.c", + "src/temp/mkostemp.c", + "src/temp/mkostemps.c", + "src/temp/mkstemp.c", + "src/temp/mkstemps.c", + "src/temp/mktemp.c", + "src/termios/cfgetospeed.c", + "src/termios/cfmakeraw.c", + "src/termios/cfsetospeed.c", + "src/termios/tcdrain.c", + "src/termios/tcflow.c", + "src/termios/tcflush.c", + "src/termios/tcgetattr.c", + "src/termios/tcgetsid.c", + "src/termios/tcsendbreak.c", + "src/termios/tcsetattr.c", + "src/thread/__lock.c", + "src/thread/__set_thread_area.c", + "src/thread/__syscall_cp.c", + "src/thread/__timedwait.c", + "src/thread/__tls_get_addr.c", + "src/thread/__unmapself.c", + "src/thread/__wait.c", + "src/thread/call_once.c", + "src/thread/clone.c", + "src/thread/cnd_broadcast.c", + "src/thread/cnd_destroy.c", + "src/thread/cnd_init.c", + "src/thread/cnd_signal.c", + "src/thread/cnd_timedwait.c", + "src/thread/cnd_wait.c", + "src/thread/default_attr.c", + "src/thread/lock_ptc.c", + "src/thread/mtx_destroy.c", + "src/thread/mtx_init.c", + "src/thread/mtx_lock.c", + "src/thread/mtx_timedlock.c", + "src/thread/mtx_trylock.c", + "src/thread/mtx_unlock.c", + "src/thread/pthread_atfork.c", + "src/thread/pthread_attr_destroy.c", + "src/thread/pthread_attr_get.c", + "src/thread/pthread_attr_init.c", + "src/thread/pthread_attr_setdetachstate.c", + "src/thread/pthread_attr_setguardsize.c", + "src/thread/pthread_attr_setinheritsched.c", + "src/thread/pthread_attr_setschedparam.c", + "src/thread/pthread_attr_setschedpolicy.c", + "src/thread/pthread_attr_setscope.c", + "src/thread/pthread_attr_setstack.c", + "src/thread/pthread_attr_setstacksize.c", + "src/thread/pthread_barrier_destroy.c", + "src/thread/pthread_barrier_init.c", + "src/thread/pthread_barrier_wait.c", + "src/thread/pthread_barrierattr_destroy.c", + "src/thread/pthread_barrierattr_init.c", + "src/thread/pthread_barrierattr_setpshared.c", + "src/thread/pthread_cancel.c", + "src/thread/pthread_cleanup_push.c", + "src/thread/pthread_cond_broadcast.c", + "src/thread/pthread_cond_destroy.c", + "src/thread/pthread_cond_init.c", + "src/thread/pthread_cond_signal.c", + "src/thread/pthread_cond_timedwait.c", + "src/thread/pthread_cond_wait.c", + "src/thread/pthread_condattr_destroy.c", + "src/thread/pthread_condattr_init.c", + "src/thread/pthread_condattr_setclock.c", + "src/thread/pthread_condattr_setpshared.c", + "src/thread/pthread_create.c", + "src/thread/pthread_detach.c", + "src/thread/pthread_equal.c", + "src/thread/pthread_getattr_np.c", + "src/thread/pthread_getconcurrency.c", + "src/thread/pthread_getcpuclockid.c", + "src/thread/pthread_getschedparam.c", + "src/thread/pthread_getspecific.c", + "src/thread/pthread_join.c", + "src/thread/pthread_key_create.c", + "src/thread/pthread_kill.c", + "src/thread/pthread_mutex_consistent.c", + "src/thread/pthread_mutex_destroy.c", + "src/thread/pthread_mutex_getprioceiling.c", + "src/thread/pthread_mutex_init.c", + "src/thread/pthread_mutex_lock.c", + "src/thread/pthread_mutex_setprioceiling.c", + "src/thread/pthread_mutex_timedlock.c", + "src/thread/pthread_mutex_trylock.c", + "src/thread/pthread_mutex_unlock.c", + "src/thread/pthread_mutexattr_destroy.c", + "src/thread/pthread_mutexattr_init.c", + "src/thread/pthread_mutexattr_setprotocol.c", + "src/thread/pthread_mutexattr_setpshared.c", + "src/thread/pthread_mutexattr_setrobust.c", + "src/thread/pthread_mutexattr_settype.c", + "src/thread/pthread_once.c", + "src/thread/pthread_rwlock_destroy.c", + "src/thread/pthread_rwlock_init.c", + "src/thread/pthread_rwlock_rdlock.c", + "src/thread/pthread_rwlock_timedrdlock.c", + "src/thread/pthread_rwlock_timedwrlock.c", + "src/thread/pthread_rwlock_tryrdlock.c", + "src/thread/pthread_rwlock_trywrlock.c", + "src/thread/pthread_rwlock_unlock.c", + "src/thread/pthread_rwlock_wrlock.c", + "src/thread/pthread_rwlockattr_destroy.c", + "src/thread/pthread_rwlockattr_init.c", + "src/thread/pthread_rwlockattr_setpshared.c", + "src/thread/pthread_self.c", + "src/thread/pthread_setattr_default_np.c", + "src/thread/pthread_setcancelstate.c", + "src/thread/pthread_setcanceltype.c", + "src/thread/pthread_setconcurrency.c", + "src/thread/pthread_setname_np.c", + "src/thread/pthread_setschedparam.c", + "src/thread/pthread_setschedprio.c", + "src/thread/pthread_setspecific.c", + "src/thread/pthread_sigmask.c", + "src/thread/pthread_spin_destroy.c", + "src/thread/pthread_spin_init.c", + "src/thread/pthread_spin_lock.c", + "src/thread/pthread_spin_trylock.c", + "src/thread/pthread_spin_unlock.c", + "src/thread/pthread_testcancel.c", + "src/thread/sem_destroy.c", + "src/thread/sem_getvalue.c", + "src/thread/sem_init.c", + "src/thread/sem_open.c", + "src/thread/sem_post.c", + "src/thread/sem_timedwait.c", + "src/thread/sem_trywait.c", + "src/thread/sem_unlink.c", + "src/thread/sem_wait.c", + "src/thread/synccall.c", + "src/thread/syscall_cp.c", + "src/thread/thrd_create.c", + "src/thread/thrd_exit.c", + "src/thread/thrd_join.c", + "src/thread/thrd_sleep.c", + "src/thread/thrd_yield.c", + "src/thread/tls.c", + "src/thread/tss_create.c", + "src/thread/tss_delete.c", + "src/thread/tss_set.c", + "src/thread/vmlock.c", + "src/time/__map_file.c", + "src/time/__month_to_secs.c", + "src/time/__secs_to_tm.c", + "src/time/__tm_to_secs.c", + "src/time/__tz.c", + "src/time/__year_to_secs.c", + "src/time/asctime.c", + "src/time/asctime_r.c", + "src/time/clock.c", + "src/time/clock_getcpuclockid.c", + "src/time/clock_getres.c", + "src/time/clock_gettime.c", + "src/time/clock_nanosleep.c", + "src/time/clock_settime.c", + "src/time/ctime.c", + "src/time/ctime_r.c", + "src/time/difftime.c", + "src/time/ftime.c", + "src/time/getdate.c", + "src/time/gettimeofday.c", + "src/time/gmtime.c", + "src/time/gmtime_r.c", + "src/time/localtime.c", + "src/time/localtime_r.c", + "src/time/mktime.c", + "src/time/nanosleep.c", + "src/time/strftime.c", + "src/time/strptime.c", + "src/time/time.c", + "src/time/timegm.c", + "src/time/timer_create.c", + "src/time/timer_delete.c", + "src/time/timer_getoverrun.c", + "src/time/timer_gettime.c", + "src/time/timer_settime.c", + "src/time/times.c", + "src/time/timespec_get.c", + "src/time/utime.c", + "src/time/wcsftime.c", + "src/unistd/_exit.c", + "src/unistd/access.c", + "src/unistd/acct.c", + "src/unistd/alarm.c", + "src/unistd/chdir.c", + "src/unistd/chown.c", + "src/unistd/close.c", + "src/unistd/ctermid.c", + "src/unistd/dup.c", + "src/unistd/dup2.c", + "src/unistd/dup3.c", + "src/unistd/faccessat.c", + "src/unistd/fchdir.c", + "src/unistd/fchown.c", + "src/unistd/fchownat.c", + "src/unistd/fdatasync.c", + "src/unistd/fsync.c", + "src/unistd/ftruncate.c", + "src/unistd/getcwd.c", + "src/unistd/getegid.c", + "src/unistd/geteuid.c", + "src/unistd/getgid.c", + "src/unistd/getgroups.c", + "src/unistd/gethostname.c", + "src/unistd/getlogin.c", + "src/unistd/getlogin_r.c", + "src/unistd/getpgid.c", + "src/unistd/getpgrp.c", + "src/unistd/getpid.c", + "src/unistd/getppid.c", + "src/unistd/getsid.c", + "src/unistd/getuid.c", + "src/unistd/isatty.c", + "src/unistd/lchown.c", + "src/unistd/link.c", + "src/unistd/linkat.c", + "src/unistd/lseek.c", + "src/unistd/nice.c", + "src/unistd/pause.c", + "src/unistd/pipe.c", + "src/unistd/pipe2.c", + "src/unistd/posix_close.c", + "src/unistd/pread.c", + "src/unistd/preadv.c", + "src/unistd/pwrite.c", + "src/unistd/pwritev.c", + "src/unistd/read.c", + "src/unistd/readlink.c", + "src/unistd/readlinkat.c", + "src/unistd/readv.c", + "src/unistd/renameat.c", + "src/unistd/rmdir.c", + "src/unistd/setegid.c", + "src/unistd/seteuid.c", + "src/unistd/setgid.c", + "src/unistd/setpgid.c", + "src/unistd/setpgrp.c", + "src/unistd/setregid.c", + "src/unistd/setresgid.c", + "src/unistd/setresuid.c", + "src/unistd/setreuid.c", + "src/unistd/setsid.c", + "src/unistd/setuid.c", + "src/unistd/setxid.c", + "src/unistd/sleep.c", + "src/unistd/symlink.c", + "src/unistd/symlinkat.c", + "src/unistd/sync.c", + "src/unistd/tcgetpgrp.c", + "src/unistd/tcsetpgrp.c", + "src/unistd/truncate.c", + "src/unistd/ttyname.c", + "src/unistd/ttyname_r.c", + "src/unistd/ualarm.c", + "src/unistd/unlink.c", + "src/unistd/unlinkat.c", + "src/unistd/usleep.c", + "src/unistd/write.c", + "src/unistd/writev.c", +] + +if (musl_arch == "arm") { + musl_src_filterout = [ + "src/fenv/fenv.c", + "src/ldso/dlsym.c", + "src/ldso/tlsdesc.c", + "src/math/fabs.c", + "src/math/fabsf.c", + "src/math/fma.c", + "src/math/fmaf.c", + "src/math/sqrt.c", + "src/math/sqrtf.c", + "src/process/vfork.c", + "src/setjmp/longjmp.c", + "src/setjmp/setjmp.c", + "src/signal/restore.c", + "src/signal/sigsetjmp.c", + "src/string/memcpy.c", + "src/thread/__set_thread_area.c", + "src/thread/__unmapself.c", + "src/thread/clone.c", + "src/thread/syscall_cp.c", + ] +} else if (musl_arch == "aarch64") { + musl_src_filterout = [ + "src/fenv/fenv.c", + "src/ldso/dlsym.c", + "src/ldso/tlsdesc.c", + "src/math/ceil.c", + "src/math/ceilf.c", + "src/math/fabs.c", + "src/math/fabsf.c", + "src/math/floor.c", + "src/math/floorf.c", + "src/math/fma.c", + "src/math/fmaf.c", + "src/math/fmax.c", + "src/math/fmaxf.c", + "src/math/fmin.c", + "src/math/fminf.c", + "src/math/llrint.c", + "src/math/llrintf.c", + "src/math/llround.c", + "src/math/llroundf.c", + "src/math/lrint.c", + "src/math/lrintf.c", + "src/math/lround.c", + "src/math/lroundf.c", + "src/math/nearbyint.c", + "src/math/nearbyintf.c", + "src/math/rint.c", + "src/math/rintf.c", + "src/math/round.c", + "src/math/roundf.c", + "src/math/sqrt.c", + "src/math/sqrtf.c", + "src/math/trunc.c", + "src/math/truncf.c", + "src/setjmp/longjmp.c", + "src/setjmp/setjmp.c", + "src/signal/restore.c", + "src/signal/sigsetjmp.c", + "src/thread/__set_thread_area.c", + "src/thread/__unmapself.c", + "src/thread/clone.c", + "src/thread/syscall_cp.c", + ] +} + +musl_src_ldso = [ + "ldso/dlstart.c", + "ldso/dynlink.c", +] + +if (musl_arch == "arm") { + musl_inc_bits_files = [ + "arch/arm/bits/fcntl.h", + "arch/arm/bits/fenv.h", + "arch/arm/bits/float.h", + "arch/arm/bits/hwcap.h", + "arch/arm/bits/ioctl_fix.h", + "arch/arm/bits/ipcstat.h", + "arch/arm/bits/msg.h", + "arch/arm/bits/posix.h", + "arch/arm/bits/ptrace.h", + "arch/arm/bits/reg.h", + "arch/arm/bits/sem.h", + "arch/arm/bits/setjmp.h", + "arch/arm/bits/shm.h", + "arch/arm/bits/signal.h", + "arch/arm/bits/stat.h", + "arch/arm/bits/stdint.h", + "arch/arm/bits/user.h", + + "arch/generic/bits/dirent.h", + "arch/generic/bits/errno.h", + "arch/generic/bits/ioctl.h", + "arch/generic/bits/io.h", + "arch/generic/bits/ipc.h", + "arch/generic/bits/kd.h", + "arch/generic/bits/limits.h", + "arch/generic/bits/link.h", + "arch/generic/bits/mman.h", + "arch/generic/bits/poll.h", + "arch/generic/bits/resource.h", + "arch/generic/bits/socket.h", + "arch/generic/bits/soundcard.h", + "arch/generic/bits/statfs.h", + "arch/generic/bits/termios.h", + "arch/generic/bits/vt.h", + ] +} else if (musl_arch == "aarch64") { + musl_inc_bits_files = [ + "arch/aarch64/bits/fcntl.h", + "arch/aarch64/bits/fenv.h", + "arch/aarch64/bits/float.h", + "arch/aarch64/bits/hwcap.h", + "arch/aarch64/bits/posix.h", + "arch/aarch64/bits/reg.h", + "arch/aarch64/bits/setjmp.h", + "arch/aarch64/bits/signal.h", + "arch/aarch64/bits/stat.h", + "arch/aarch64/bits/stdint.h", + "arch/aarch64/bits/user.h", + + "arch/generic/bits/dirent.h", + "arch/generic/bits/errno.h", + "arch/generic/bits/fcntl.h", + "arch/generic/bits/fenv.h", + "arch/generic/bits/hwcap.h", + "arch/generic/bits/ioctl_fix.h", + "arch/generic/bits/ioctl.h", + "arch/generic/bits/io.h", + "arch/generic/bits/ipc.h", + "arch/generic/bits/ipcstat.h", + "arch/generic/bits/kd.h", + "arch/generic/bits/limits.h", + "arch/generic/bits/link.h", + "arch/generic/bits/mman.h", + "arch/generic/bits/msg.h", + "arch/generic/bits/poll.h", + "arch/generic/bits/ptrace.h", + "arch/generic/bits/resource.h", + "arch/generic/bits/sem.h", + "arch/generic/bits/shm.h", + "arch/generic/bits/socket.h", + "arch/generic/bits/soundcard.h", + "arch/generic/bits/statfs.h", + "arch/generic/bits/termios.h", + "arch/generic/bits/vt.h", + ] +} + +musl_inc_arpa_files = [ + "include/arpa/ftp.h", + "include/arpa/inet.h", + "include/arpa/nameser_compat.h", + "include/arpa/nameser.h", + "include/arpa/telnet.h", + "include/arpa/tftp.h", +] + +musl_inc_net_files = [ + "include/net/ethernet.h", + "include/net/if_arp.h", + "include/net/if.h", + "include/net/route.h", +] + +musl_inc_netinet_files = [ + "include/netinet/ether.h", + "include/netinet/icmp6.h", + "include/netinet/if_ether.h", + "include/netinet/igmp.h", + "include/netinet/in.h", + "include/netinet/in_systm.h", + "include/netinet/ip6.h", + "include/netinet/ip.h", + "include/netinet/ip_icmp.h", + "include/netinet/tcp.h", + "include/netinet/udp.h", +] + +musl_inc_netpacket_files = [ "include/netpacket/packet.h" ] + +musl_inc_scsi_files = [ + "include/scsi/scsi.h", + "include/scsi/scsi_ioctl.h", + "include/scsi/sg.h", +] + +musl_inc_sys_files = [ + "include/sys/acct.h", + "include/sys/auxv.h", + "include/sys/cachectl.h", + "include/sys/dir.h", + "include/sys/epoll.h", + "include/sys/errno.h", + "include/sys/eventfd.h", + "include/sys/fanotify.h", + "include/sys/fcntl.h", + "include/sys/file.h", + "include/sys/fsuid.h", + "include/sys/inotify.h", + "include/sys/ioctl.h", + "include/sys/io.h", + "include/sys/ipc.h", + "include/sys/kd.h", + "include/sys/klog.h", + "include/sys/membarrier.h", + "include/sys/mman.h", + "include/sys/mount.h", + "include/sys/msg.h", + "include/sys/mtio.h", + "include/sys/param.h", + "include/sys/personality.h", + "include/sys/poll.h", + "include/sys/prctl.h", + "include/sys/procfs.h", + "include/sys/ptrace.h", + "include/sys/quota.h", + "include/sys/random.h", + "include/sys/reboot.h", + "include/sys/reg.h", + "include/sys/resource.h", + "include/sys/select.h", + "include/sys/sem.h", + "include/sys/sendfile.h", + "include/sys/shm.h", + "include/sys/signalfd.h", + "include/sys/signal.h", + "include/sys/socket.h", + "include/sys/soundcard.h", + "include/sys/statfs.h", + "include/sys/stat.h", + "include/sys/statvfs.h", + "include/sys/stropts.h", + "include/sys/swap.h", + "include/sys/syscall.h", + "include/sys/sysinfo.h", + "include/sys/syslog.h", + "include/sys/sysmacros.h", + "include/sys/termios.h", + "include/sys/timeb.h", + "include/sys/time.h", + "include/sys/timerfd.h", + "include/sys/times.h", + "include/sys/timex.h", + "include/sys/ttydefaults.h", + "include/sys/types.h", + "include/sys/ucontext.h", + "include/sys/uio.h", + "include/sys/un.h", + "include/sys/user.h", + "include/sys/utsname.h", + "include/sys/vfs.h", + "include/sys/vt.h", + "include/sys/wait.h", + "include/sys/xattr.h", +] + +musl_inc_root_files = [ + "include/aio.h", + "include/alloca.h", + "include/ar.h", + "include/assert.h", + "include/byteswap.h", + "include/complex.h", + "include/cpio.h", + "include/crypt.h", + "include/ctype.h", + "include/dirent.h", + "include/dlfcn.h", + "include/elf.h", + "include/endian.h", + "include/err.h", + "include/errno.h", + "include/fcntl.h", + "include/features.h", + "include/fenv.h", + "include/float.h", + "include/fmtmsg.h", + "include/fnmatch.h", + "include/ftw.h", + "include/getopt.h", + "include/glob.h", + "include/grp.h", + "include/iconv.h", + "include/ifaddrs.h", + "include/inttypes.h", + "include/iso646.h", + "include/langinfo.h", + "include/lastlog.h", + "include/libgen.h", + "include/libintl.h", + "include/limits.h", + "include/link.h", + "include/locale.h", + "include/malloc.h", + "include/math.h", + "include/memory.h", + "include/mntent.h", + "include/monetary.h", + "include/mqueue.h", + "include/netdb.h", + "include/nl_types.h", + "include/paths.h", + "include/poll.h", + "include/pthread.h", + "include/pty.h", + "include/pwd.h", + "include/regex.h", + "include/resolv.h", + "include/sched.h", + "include/search.h", + "include/semaphore.h", + "include/setjmp.h", + "include/shadow.h", + "include/signal.h", + "include/spawn.h", + "include/stdalign.h", + "include/stdarg.h", + "include/stdbool.h", + "include/stdc-predef.h", + "include/stddef.h", + "include/stdint.h", + "include/stdio_ext.h", + "include/stdio.h", + "include/stdlib.h", + "include/stdnoreturn.h", + "include/string.h", + "include/strings.h", + "include/stropts.h", + "include/syscall.h", + "include/sysexits.h", + "include/syslog.h", + "include/tar.h", + "include/termios.h", + "include/tgmath.h", + "include/threads.h", + "include/time.h", + "include/uchar.h", + "include/ucontext.h", + "include/ulimit.h", + "include/unistd.h", + "include/utime.h", + "include/utmp.h", + "include/utmpx.h", + "include/values.h", + "include/wait.h", + "include/wchar.h", + "include/wctype.h", + "include/wordexp.h", +] diff --git a/musl_template.gni b/musl_template.gni new file mode 100644 index 0000000000000000000000000000000000000000..69583918b98b13161a2a41109133427d68259855 --- /dev/null +++ b/musl_template.gni @@ -0,0 +1,293 @@ +import("//build/ohos.gni") +import("musl_src.gni") + +template("musl_libs") { + + no_default_deps = true + + forward_variables_from(invoker, ["target_abi"]) + template_prefix = "${target_name}" + + porting_deps = [ + "//third_party/musl:create_porting_src", + "//third_party/musl:create_alltypes_h", + "//third_party/musl:create_syscall_h", + "//third_party/musl:create_version_h", + ] + + if (target_abi == "soft") { + static_lib_out_dir = "usr/lib/${musl_target_triple}" + shared_lib_out_dir = "." + } else { + static_lib_out_dir = "usr/lib/${musl_target_triple}/${target_abi}" + shared_lib_out_dir = "${target_abi}" + } + + group("${template_prefix}_libs") { + deps = [ + ":${template_prefix}_libc_musl_shared", + ":${template_prefix}_libc_musl_static", + ":${template_prefix}_libcrypt", + ":${template_prefix}_libdl", + ":${template_prefix}_libm", + ":${template_prefix}_libpthread", + ":${template_prefix}_libresolv", + ":${template_prefix}_librt", + ":${template_prefix}_libutil", + ":${template_prefix}_libxnet", + ":${template_prefix}_musl_crt_install_action", + ":${template_prefix}_create_linker", + ] + } + + musl_inherited_configs = [ + "//build/config/compiler:afdo", + "//build/config/compiler:afdo_optimize_size", + "//build/config/compiler:compiler", + "//build/config/compiler:compiler_arm_fpu", + "//build/config/compiler:compiler_arm_thumb", + "//build/config/compiler:chromium_code", + "//build/config/compiler:default_include_dirs", + "//build/config/compiler:default_optimization", + "//build/config/compiler:default_stack_frames", + "//build/config/compiler:default_symbols", + "//build/config/compiler:export_dynamic", + "//build/config/compiler:no_exceptions", + "//build/config/compiler:no_rtti", + "//build/config/compiler:runtime_library", + "//build/config/sanitizers:default_sanitizer_flags", + ] + + config("${template_prefix}_musl_abi_config") { + if (target_abi == "soft") { + cflags = [ "-mfloat-abi=soft" ] + } else if (target_abi == "a7_soft") { + cflags = [ + "-mcpu=cortex-a7", + "-mfloat-abi=soft", + ] + } else if (target_abi == "a7_softfp_neon-vfpv4") { + cflags = [ + "-mcpu=cortex-a7", + "-mfloat-abi=softfp", + "-mfpu=neon-vfpv4", + ] + } else if (target_abi == "a7_hard_neon-vfpv4") { + cflags = [ + "-mcpu=cortex-a7", + "-mfloat-abi=hard", + "-mfpu=neon-vfpv4", + ] + } + } + + config("${template_prefix}_musl_config") { + configs = [ ":${template_prefix}_musl_abi_config" ] + + include_dirs = [ + "${target_out_dir}/${musl_ported_dir}/arch/${musl_arch}", + "${target_out_dir}/${musl_ported_dir}/arch/generic", + "${target_out_dir}/${musl_ported_dir}/src/internal", + "${target_out_dir}/${musl_ported_dir}/src/include", + "${target_out_dir}/${musl_ported_dir}/include", + "${target_out_dir}/${musl_inc_out_dir}", + ] + + cflags = [ + "--target=${musl_target_triple}", + "-std=c99", + "-nostdinc", + "-ffreestanding", + "-Wa,--noexecstack", + "-D_XOPEN_SOURCE=700", + "-Os", + "-pipe", + "-fno-omit-frame-pointer", + "-funwind-tables", + "-fasynchronous-unwind-tables", + "-ffunction-sections", + "-fdata-sections", + "-Werror=implicit-function-declaration", + "-Werror=implicit-int", + "-Werror=pointer-sign", + "-Werror=pointer-arith", + "-Wno-bitwise-op-parentheses", + "-Wno-shift-op-parentheses", + ] + + if (musl_arch == "aarch64") { + cflags += [ "-Qunused-arguments" ] + } + + ldflags = [ + "--target=${musl_target_triple}", + "-fuse-ld=lld", + ] + asmflags = cflags + } + + source_set("${template_prefix}_musl_crt") { + cflags = [] + sources = [ + "${target_out_dir}/${musl_ported_dir}/crt/${musl_arch}/crti.s", + "${target_out_dir}/${musl_ported_dir}/crt/${musl_arch}/crtn.s", + "${target_out_dir}/${musl_ported_dir}/crt/Scrt1.c", + "${target_out_dir}/${musl_ported_dir}/crt/crt1.c", + "${target_out_dir}/${musl_ported_dir}/crt/rcrt1.c", + ] + + cflags += [ + "-fPIC", + "-fno-stack-protector", + ] + + defines = [ "CRT" ] + + configs -= musl_inherited_configs + configs += [ ":${template_prefix}_musl_config" ] + + deps = porting_deps + + asmflags = cflags + } + + source_set("${template_prefix}_musl_src") { + cflags = [] + sources_orig = [] + sources = [] + set_sources_assignment_filter([]) + + sources_orig = musl_src_arch_file + musl_src_file + sources_orig -= musl_src_filterout + + foreach(s, sources_orig) { + sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ] + } + + cflags += [ + "-fPIC", + "-fno-stack-protector", + ] + + configs -= musl_inherited_configs + configs += [ ":${template_prefix}_musl_config" ] + + deps = porting_deps + } + + source_set("${template_prefix}_musl_ldso") { + cflags = [] + cflags = [ "-fPIC" ] + sources = [] + sources_orig = musl_src_ldso + + foreach(s, sources_orig) { + sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ] + } + + configs -= musl_inherited_configs + configs += [ ":${template_prefix}_musl_config" ] + + deps = porting_deps + } + + static_library("${template_prefix}_libc_musl_static") { + output_name = "libc" + complete_static_lib = true + + output_dir = "${target_out_dir}/${static_lib_out_dir}" + deps = [ ":${template_prefix}_musl_src" ] + } + + static_library("${template_prefix}_libm") { + output_dir = "${target_out_dir}/${static_lib_out_dir}" + } + + static_library("${template_prefix}_librt") { + output_dir = "${target_out_dir}/${static_lib_out_dir}" + } + + static_library("${template_prefix}_libpthread") { + output_dir = "${target_out_dir}/${static_lib_out_dir}" + } + + static_library("${template_prefix}_libcrypt") { + output_dir = "${target_out_dir}/${static_lib_out_dir}" + } + + static_library("${template_prefix}_libutil") { + output_dir = "${target_out_dir}/${static_lib_out_dir}" + } + + static_library("${template_prefix}_libresolv") { + output_dir = "${target_out_dir}/${static_lib_out_dir}" + } + + static_library("${template_prefix}_libxnet") { + output_dir = "${target_out_dir}/${static_lib_out_dir}" + } + + static_library("${template_prefix}_libdl") { + output_dir = "${target_out_dir}/${static_lib_out_dir}" + } + + ohos_shared_library("${template_prefix}_libc_musl_shared") { + output_name = "libc/${shared_lib_out_dir}/libc" + output_extension = "so" + + ldflags = [ + "-nostdlib", + "-Wl,-e,_dlstart", + ] + + remove_configs = musl_inherited_configs + remove_configs += [ "//build/config:default_libs" ] + + configs = [ ":${template_prefix}_musl_config" ] + + deps = [ + ":${template_prefix}_musl_ldso", + ":${template_prefix}_musl_src", + ] + } + + action_foreach("${template_prefix}_musl_crt_install_action") { + redir = "${root_out_dir}/obj" + script = "${target_out_dir}/${musl_ported_dir}/scripts/install.py" + sources = [ + "${redir}/${target_out_dir}/${musl_ported_dir}/crt/${musl_arch}/${template_prefix}_musl_crt/crti.o", + "${redir}/${target_out_dir}/${musl_ported_dir}/crt/${musl_arch}/${template_prefix}_musl_crt/crtn.o", + "${redir}/${target_out_dir}/${musl_ported_dir}/crt/${template_prefix}_musl_crt/Scrt1.o", + "${redir}/${target_out_dir}/${musl_ported_dir}/crt/${template_prefix}_musl_crt/crt1.o", + "${redir}/${target_out_dir}/${musl_ported_dir}/crt/${template_prefix}_musl_crt/rcrt1.o", + ] + + outputs = [ "${target_out_dir}/${static_lib_out_dir}/{{source_file_part}}" ] + + args = [ + "--input", + "{{source}}", + ] + args += [ "--output" ] + rebase_path(outputs, root_build_dir) + + deps = [ ":${template_prefix}_musl_crt" ] + } + + action("${template_prefix}_create_linker") { + script = "${target_out_dir}/${musl_ported_dir}/tools/install.sh" + + sources = [ "${root_out_dir}/common/common/libc/${shared_lib_out_dir}/libc.so" ] + + outputs = [ "${root_out_dir}/common/common/libc/${shared_lib_out_dir}/ld-musl-${musl_arch}.so.1" ] + + args = [ + "-D", + "-r", + ] + args += rebase_path(sources) + args += rebase_path(outputs) + + deps = [ ":${template_prefix}_libc_musl_shared" ] + } + +} diff --git a/porting/linux/user/Makefile b/porting/linux/user/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..d93a1a0a139dac9b5427229ddfe05bd042431f09 --- /dev/null +++ b/porting/linux/user/Makefile @@ -0,0 +1,236 @@ +# +# Makefile for musl (requires GNU make) +# +# This is how simple every makefile should be... +# No, I take that back - actually most should be less than half this size. +# +# Use config.mak to override any of the following variables. +# Do not make changes here. +# + +srcdir = . +exec_prefix = /usr/local +bindir = $(exec_prefix)/bin + +prefix = /usr/local/musl +includedir = $(prefix)/include +libdir = $(prefix)/lib +syslibdir = /lib + +SRC_DIRS = $(addprefix $(srcdir)/,src/* crt ldso $(COMPAT_SRC_DIRS)) +BASE_GLOBS = $(addsuffix /*.c,$(SRC_DIRS)) +ARCH_GLOBS = $(addsuffix /$(ARCH)/*.[csS],$(SRC_DIRS)) +BASE_SRCS = $(sort $(wildcard $(BASE_GLOBS))) +ARCH_SRCS = $(sort $(wildcard $(ARCH_GLOBS))) +BASE_OBJS = $(patsubst $(srcdir)/%,%.o,$(basename $(BASE_SRCS))) +ARCH_OBJS = $(patsubst $(srcdir)/%,%.o,$(basename $(ARCH_SRCS))) +REPLACED_OBJS = $(sort $(subst /$(ARCH)/,/,$(ARCH_OBJS))) +ALL_OBJS = $(addprefix obj/, $(filter-out $(REPLACED_OBJS), $(sort $(BASE_OBJS) $(ARCH_OBJS)))) + +LIBC_OBJS = $(filter obj/src/%,$(ALL_OBJS)) $(filter obj/compat/%,$(ALL_OBJS)) +LDSO_OBJS = $(filter obj/ldso/%,$(ALL_OBJS:%.o=%.lo)) +CRT_OBJS = $(filter obj/crt/%,$(ALL_OBJS)) + +AOBJS = $(LIBC_OBJS) +LOBJS = $(LIBC_OBJS:.o=.lo) +GENH = obj/include/bits/alltypes.h obj/include/bits/syscall.h +GENH_INT = obj/src/internal/version.h +IMPH = $(addprefix $(srcdir)/, src/internal/stdio_impl.h src/internal/pthread_impl.h src/internal/locale_impl.h src/internal/libc.h) + +LDFLAGS = +LDFLAGS_AUTO = +LIBCC = -lgcc +CPPFLAGS = +CFLAGS = +CFLAGS_AUTO = -Os -pipe +CFLAGS_C99FSE = -std=c99 -ffreestanding -nostdinc + +CFLAGS_ALL = $(CFLAGS_C99FSE) +CFLAGS_ALL += -D_XOPEN_SOURCE=700 -I$(srcdir)/arch/$(ARCH) -I$(srcdir)/arch/generic -Iobj/src/internal -I$(srcdir)/src/include -I$(srcdir)/src/internal -Iobj/include -I$(srcdir)/include +CFLAGS_ALL += $(CPPFLAGS) $(CFLAGS_AUTO) $(CFLAGS) + +LDFLAGS_ALL = $(LDFLAGS_AUTO) $(LDFLAGS) + +AR = $(CROSS_COMPILE)ar +RANLIB = $(CROSS_COMPILE)ranlib +INSTALL = $(srcdir)/tools/install.sh + +ARCH_INCLUDES = $(wildcard $(srcdir)/arch/$(ARCH)/bits/*.h) +GENERIC_INCLUDES = $(wildcard $(srcdir)/arch/generic/bits/*.h) +INCLUDES = $(wildcard $(srcdir)/include/*.h $(srcdir)/include/*/*.h) +ALL_INCLUDES = $(sort $(INCLUDES:$(srcdir)/%=%) $(GENH:obj/%=%) $(ARCH_INCLUDES:$(srcdir)/arch/$(ARCH)/%=include/%) $(GENERIC_INCLUDES:$(srcdir)/arch/generic/%=include/%)) + +EMPTY_LIB_NAMES = m rt pthread crypt util xnet resolv dl +EMPTY_LIBS = $(EMPTY_LIB_NAMES:%=lib/lib%.a) +CRT_LIBS = $(addprefix lib/,$(notdir $(CRT_OBJS))) +STATIC_LIBS = lib/libc.a +SHARED_LIBS = lib/libc.so +TOOL_LIBS = lib/musl-gcc.specs +ALL_LIBS = $(CRT_LIBS) $(STATIC_LIBS) $(SHARED_LIBS) $(EMPTY_LIBS) $(TOOL_LIBS) +ALL_TOOLS = obj/musl-gcc + +WRAPCC_GCC = gcc +WRAPCC_CLANG = clang + +LDSO_PATHNAME = $(syslibdir)/ld-musl-$(ARCH)$(SUBARCH).so.1 + +-include config.mak +-include $(srcdir)/arch/$(ARCH)/arch.mak + +ifeq ($(ARCH),) + +all: + @echo "Please set ARCH in config.mak before running make." + @exit 1 + +else + +all: $(ALL_LIBS) $(ALL_TOOLS) + +OBJ_DIRS = $(sort $(patsubst %/,%,$(dir $(ALL_LIBS) $(ALL_TOOLS) $(ALL_OBJS) $(GENH) $(GENH_INT))) obj/include) + +$(ALL_LIBS) $(ALL_TOOLS) $(ALL_OBJS) $(ALL_OBJS:%.o=%.lo) $(GENH) $(GENH_INT): | $(OBJ_DIRS) + +$(OBJ_DIRS): + mkdir -p $@ + +obj/include/bits/alltypes.h: $(srcdir)/arch/$(ARCH)/bits/alltypes.h.in $(srcdir)/include/alltypes.h.in $(srcdir)/tools/mkalltypes.sed + sed -f $(srcdir)/tools/mkalltypes.sed $(srcdir)/arch/$(ARCH)/bits/alltypes.h.in $(srcdir)/include/alltypes.h.in > $@ + +obj/include/bits/syscall.h: $(srcdir)/arch/$(ARCH)/bits/syscall.h.in + cp $< $@ + sed -n -e s/__NR_/SYS_/p < $< >> $@ + +obj/src/internal/version.h: $(wildcard $(srcdir)/VERSION $(srcdir)/.git) + printf '#define VERSION "%s"\n' "$$(cd $(srcdir); sh tools/version.sh)" > $@ + +obj/src/internal/version.o obj/src/internal/version.lo: obj/src/internal/version.h + +obj/crt/rcrt1.o obj/ldso/dlstart.lo obj/ldso/dynlink.lo: $(srcdir)/src/internal/dynlink.h $(srcdir)/arch/$(ARCH)/reloc.h + +obj/crt/crt1.o obj/crt/scrt1.o obj/crt/rcrt1.o obj/ldso/dlstart.lo: $(srcdir)/arch/$(ARCH)/crt_arch.h + +obj/crt/rcrt1.o: $(srcdir)/ldso/dlstart.c + +obj/crt/Scrt1.o obj/crt/rcrt1.o: CFLAGS_ALL += -fPIC + +OPTIMIZE_SRCS = $(wildcard $(OPTIMIZE_GLOBS:%=$(srcdir)/src/%)) +$(OPTIMIZE_SRCS:$(srcdir)/%.c=obj/%.o) $(OPTIMIZE_SRCS:$(srcdir)/%.c=obj/%.lo): CFLAGS += -O3 + +MEMOPS_OBJS = $(filter %/memcpy.o %/memmove.o %/memcmp.o %/memset.o, $(LIBC_OBJS)) +$(MEMOPS_OBJS) $(MEMOPS_OBJS:%.o=%.lo): CFLAGS_ALL += $(CFLAGS_MEMOPS) + +NOSSP_OBJS = $(CRT_OBJS) $(LDSO_OBJS) $(filter \ + %/__libc_start_main.o %/__init_tls.o %/__stack_chk_fail.o \ + %/__set_thread_area.o %/memset.o %/memcpy.o \ + , $(LIBC_OBJS)) +$(NOSSP_OBJS) $(NOSSP_OBJS:%.o=%.lo): CFLAGS_ALL += $(CFLAGS_NOSSP) + +$(CRT_OBJS): CFLAGS_ALL += -DCRT + +$(LOBJS) $(LDSO_OBJS): CFLAGS_ALL += -fPIC + +CC_CMD = $(CC) $(CFLAGS_ALL) -c -o $@ $< + +# Choose invocation of assembler to be used +ifeq ($(ADD_CFI),yes) + AS_CMD = LC_ALL=C awk -f $(srcdir)/tools/add-cfi.common.awk -f $(srcdir)/tools/add-cfi.$(ARCH).awk $< | $(CC) $(CFLAGS_ALL) -x assembler -c -o $@ - +else + AS_CMD = $(CC_CMD) +endif + +obj/%.o: $(srcdir)/%.s + $(AS_CMD) + +obj/%.o: $(srcdir)/%.S + $(CC_CMD) + +obj/%.o: $(srcdir)/%.c $(GENH) $(IMPH) + $(CC_CMD) + +obj/%.lo: $(srcdir)/%.s + $(AS_CMD) + +obj/%.lo: $(srcdir)/%.S + $(CC_CMD) + +obj/%.lo: $(srcdir)/%.c $(GENH) $(IMPH) + $(CC_CMD) + +lib/libc.so: $(LOBJS) $(LDSO_OBJS) + $(CC) $(CFLAGS_ALL) $(LDFLAGS_ALL) -nostdlib -shared \ + -Wl,-e,_dlstart -o $@ $(LOBJS) $(LDSO_OBJS) $(LIBCC) + +lib/libc.a: $(AOBJS) + rm -f $@ + $(AR) rc $@ $(AOBJS) + $(RANLIB) $@ + +$(EMPTY_LIBS): + rm -f $@ + $(AR) rc $@ + +lib/%.o: obj/crt/$(ARCH)/%.o + cp $< $@ + +lib/%.o: obj/crt/%.o + cp $< $@ + +lib/musl-gcc.specs: $(srcdir)/tools/musl-gcc.specs.sh config.mak + sh $< "$(includedir)" "$(libdir)" "$(LDSO_PATHNAME)" > $@ + +obj/musl-gcc: config.mak + printf '#!/bin/sh\nexec "$${REALGCC:-$(WRAPCC_GCC)}" "$$@" -specs "%s/musl-gcc.specs"\n' "$(libdir)" > $@ + chmod +x $@ + +obj/%-clang: $(srcdir)/tools/%-clang.in config.mak + sed -e 's!@CC@!$(WRAPCC_CLANG)!g' -e 's!@PREFIX@!$(prefix)!g' -e 's!@INCDIR@!$(includedir)!g' -e 's!@LIBDIR@!$(libdir)!g' -e 's!@LDSO@!$(LDSO_PATHNAME)!g' $< > $@ + chmod +x $@ + +$(DESTDIR)$(bindir)/%: obj/% + $(INSTALL) -D $< $@ + +$(DESTDIR)$(libdir)/%.so: lib/%.so + $(INSTALL) -D -m 755 $< $@ + +$(DESTDIR)$(libdir)/%: lib/% + $(INSTALL) -D -m 644 $< $@ + +$(DESTDIR)$(includedir)/bits/%: $(srcdir)/arch/$(ARCH)/bits/% + $(INSTALL) -D -m 644 $< $@ + +$(DESTDIR)$(includedir)/bits/%: $(srcdir)/arch/generic/bits/% + $(INSTALL) -D -m 644 $< $@ + +$(DESTDIR)$(includedir)/bits/%: obj/include/bits/% + $(INSTALL) -D -m 644 $< $@ + +$(DESTDIR)$(includedir)/%: $(srcdir)/include/% + $(INSTALL) -D -m 644 $< $@ + +$(DESTDIR)$(LDSO_PATHNAME): $(DESTDIR)$(libdir)/libc.so + $(INSTALL) -D -r $(DESTDIR)$(libdir)/libc.so $@ || true + +install-libs: $(ALL_LIBS:lib/%=$(DESTDIR)$(libdir)/%) $(if $(SHARED_LIBS),$(DESTDIR)$(LDSO_PATHNAME),) + +install-headers: $(ALL_INCLUDES:include/%=$(DESTDIR)$(includedir)/%) + +install-tools: $(ALL_TOOLS:obj/%=$(DESTDIR)$(bindir)/%) + +install: install-libs install-headers install-tools + +musl-git-%.tar.gz: .git + git --git-dir=$(srcdir)/.git archive --format=tar.gz --prefix=$(patsubst %.tar.gz,%,$@)/ -o $@ $(patsubst musl-git-%.tar.gz,%,$@) + +musl-%.tar.gz: .git + git --git-dir=$(srcdir)/.git archive --format=tar.gz --prefix=$(patsubst %.tar.gz,%,$@)/ -o $@ v$(patsubst musl-%.tar.gz,%,$@) + +endif + +clean: + rm -rf obj lib + +distclean: clean + rm -f config.mak + +.PHONY: all clean install install-libs install-headers install-tools diff --git a/porting/linux/user/arch/arm/bits/fenv.h b/porting/linux/user/arch/arm/bits/fenv.h deleted file mode 100644 index b497a9878800671a9b7ef842062c7c23cee755e1..0000000000000000000000000000000000000000 --- a/porting/linux/user/arch/arm/bits/fenv.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef __ARM_PCS_VFP -#define FE_ALL_EXCEPT 0 -#define FE_TONEAREST 0 -#else -#define FE_INVALID 1 -#define FE_DIVBYZERO 2 -#define FE_OVERFLOW 4 -#define FE_UNDERFLOW 8 -#define FE_INEXACT 16 -#define FE_ALL_EXCEPT 31 -#define FE_TONEAREST 0 -#define FE_TOWARDZERO 0xc00000 -#endif -#define FE_DOWNWARD 0x800000 -#define FE_UPWARD 0x400000 - -typedef unsigned long fexcept_t; - -typedef struct { - unsigned long __cw; -} fenv_t; - -#define FE_DFL_ENV ((const fenv_t *) -1) diff --git a/porting/linux/user/arch/generic/bits/shm.h b/porting/linux/user/arch/generic/bits/shm.h new file mode 100644 index 0000000000000000000000000000000000000000..da07a2a0cb501c186621a653353bd5ec3257e1e9 --- /dev/null +++ b/porting/linux/user/arch/generic/bits/shm.h @@ -0,0 +1,24 @@ +#define SHMLBA (4*4096) + +struct shmid_ds { + struct ipc_perm shm_perm; + size_t shm_segsz; + time_t shm_atime; + time_t shm_dtime; + time_t shm_ctime; + pid_t shm_cpid; + pid_t shm_lpid; + unsigned long shm_nattch; + unsigned long __pad1; + unsigned long __pad2; +}; + +struct shminfo { + unsigned long shmmax, shmmin, shmmni, shmseg, shmall, __unused[4]; +}; + +struct shm_info { + int __used_ids; + unsigned long shm_tot, shm_rss, shm_swp; + unsigned long __swap_attempts, __swap_successes; +}; diff --git a/porting/linux/user/include/sys/capability.h b/porting/linux/user/include/sys/capability.h index ed2ff97783b1712e860fec3c73692d76efbeb9ae..d5ab2504d4735e2300b2565afe0f41e3acc21b2e 100644 --- a/porting/linux/user/include/sys/capability.h +++ b/porting/linux/user/include/sys/capability.h @@ -1,48 +1,2 @@ -/* - * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. - * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used - * to endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef _SYS_CAPABILITY_H -#define _SYS_CAPABILITY_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -int capget(cap_user_header_t hdr_ptr, cap_user_data_t data_ptr); -int capset(cap_user_header_t hdr_ptr, const cap_user_data_t data_ptr); - -#ifdef __cplusplus -} -#endif - -#endif /* _SYS_CAPABILITY_H */ +int capset(void *a, void *b); +int capget(void *a, void *b); diff --git a/porting/linux/user/include/sys/socket.h b/porting/linux/user/include/sys/socket.h deleted file mode 100644 index 8bd3b5d451968575c85f0eae5eb384b9bb674e10..0000000000000000000000000000000000000000 --- a/porting/linux/user/include/sys/socket.h +++ /dev/null @@ -1,411 +0,0 @@ -#ifndef _SYS_SOCKET_H -#define _SYS_SOCKET_H -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_socklen_t -#define __NEED_sa_family_t -#define __NEED_size_t -#define __NEED_ssize_t -#define __NEED_uid_t -#define __NEED_pid_t -#define __NEED_gid_t -#define __NEED_struct_iovec - -#include - -#include - -struct msghdr { - void *msg_name; - socklen_t msg_namelen; - struct iovec *msg_iov; -#if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __BIG_ENDIAN - int __pad1; -#endif - int msg_iovlen; -#if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __LITTLE_ENDIAN - int __pad1; -#endif - void *msg_control; -#if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __BIG_ENDIAN - int __pad2; -#endif - socklen_t msg_controllen; -#if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __LITTLE_ENDIAN - int __pad2; -#endif - int msg_flags; -}; - -struct cmsghdr { -#if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __BIG_ENDIAN - int __pad1; -#endif - socklen_t cmsg_len; -#if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __LITTLE_ENDIAN - int __pad1; -#endif - int cmsg_level; - int cmsg_type; -}; - -#ifdef _GNU_SOURCE -struct ucred { - pid_t pid; - uid_t uid; - gid_t gid; -}; - -struct mmsghdr { - struct msghdr msg_hdr; - unsigned int msg_len; -}; - -struct timespec; - -int sendmmsg (int, struct mmsghdr *, unsigned int, unsigned int); -int recvmmsg (int, struct mmsghdr *, unsigned int, unsigned int, struct timespec *); -#endif - -struct linger { - int l_onoff; - int l_linger; -}; - -#define SHUT_RD 0 -#define SHUT_WR 1 -#define SHUT_RDWR 2 - -#ifndef SOCK_STREAM -#define SOCK_STREAM 1 -#define SOCK_DGRAM 2 -#endif - -#define SOCK_RAW 3 -#define SOCK_RDM 4 -#define SOCK_SEQPACKET 5 -#define SOCK_DCCP 6 -#define SOCK_PACKET 10 - -#ifndef SOCK_CLOEXEC -#define SOCK_CLOEXEC 02000000 -#define SOCK_NONBLOCK 04000 -#endif - -#define PF_UNSPEC 0 -#define PF_LOCAL 1 -#define PF_UNIX PF_LOCAL -#define PF_FILE PF_LOCAL -#define PF_INET 2 -#define PF_AX25 3 -#define PF_IPX 4 -#define PF_APPLETALK 5 -#define PF_NETROM 6 -#define PF_BRIDGE 7 -#define PF_ATMPVC 8 -#define PF_X25 9 -#define PF_INET6 10 -#define PF_ROSE 11 -#define PF_DECnet 12 -#define PF_NETBEUI 13 -#define PF_SECURITY 14 -#define PF_KEY 15 -#define PF_NETLINK 16 -#define PF_ROUTE PF_NETLINK -#define PF_PACKET 17 -#define PF_ASH 18 -#define PF_ECONET 19 -#define PF_ATMSVC 20 -#define PF_RDS 21 -#define PF_SNA 22 -#define PF_IRDA 23 -#define PF_PPPOX 24 -#define PF_WANPIPE 25 -#define PF_LLC 26 -#define PF_IB 27 -#define PF_MPLS 28 -#define PF_CAN 29 -#define PF_TIPC 30 -#define PF_BLUETOOTH 31 -#define PF_IUCV 32 -#define PF_RXRPC 33 -#define PF_ISDN 34 -#define PF_PHONET 35 -#define PF_IEEE802154 36 -#define PF_CAIF 37 -#define PF_ALG 38 -#define PF_NFC 39 -#define PF_VSOCK 40 -#define PF_KCM 41 -#define PF_QIPCRTR 42 -#define PF_SMC 43 -#define PF_XDP 44 -#define PF_MAX 45 - -#define AF_UNSPEC PF_UNSPEC -#define AF_LOCAL PF_LOCAL -#define AF_UNIX AF_LOCAL -#define AF_FILE AF_LOCAL -#define AF_INET PF_INET -#define AF_AX25 PF_AX25 -#define AF_IPX PF_IPX -#define AF_APPLETALK PF_APPLETALK -#define AF_NETROM PF_NETROM -#define AF_BRIDGE PF_BRIDGE -#define AF_ATMPVC PF_ATMPVC -#define AF_X25 PF_X25 -#define AF_INET6 PF_INET6 -#define AF_ROSE PF_ROSE -#define AF_DECnet PF_DECnet -#define AF_NETBEUI PF_NETBEUI -#define AF_SECURITY PF_SECURITY -#define AF_KEY PF_KEY -#define AF_NETLINK PF_NETLINK -#define AF_ROUTE PF_ROUTE -#define AF_PACKET PF_PACKET -#define AF_ASH PF_ASH -#define AF_ECONET PF_ECONET -#define AF_ATMSVC PF_ATMSVC -#define AF_RDS PF_RDS -#define AF_SNA PF_SNA -#define AF_IRDA PF_IRDA -#define AF_PPPOX PF_PPPOX -#define AF_WANPIPE PF_WANPIPE -#define AF_LLC PF_LLC -#define AF_IB PF_IB -#define AF_MPLS PF_MPLS -#define AF_CAN PF_CAN -#define AF_TIPC PF_TIPC -#define AF_BLUETOOTH PF_BLUETOOTH -#define AF_IUCV PF_IUCV -#define AF_RXRPC PF_RXRPC -#define AF_ISDN PF_ISDN -#define AF_PHONET PF_PHONET -#define AF_IEEE802154 PF_IEEE802154 -#define AF_CAIF PF_CAIF -#define AF_ALG PF_ALG -#define AF_NFC PF_NFC -#define AF_VSOCK PF_VSOCK -#define AF_KCM PF_KCM -#define AF_QIPCRTR PF_QIPCRTR -#define AF_SMC PF_SMC -#define AF_XDP PF_XDP -#define AF_MAX PF_MAX - -#ifndef SO_DEBUG -#define SO_DEBUG 1 -#define SO_REUSEADDR 2 -#define SO_TYPE 3 -#define SO_ERROR 4 -#define SO_DONTROUTE 5 -#define SO_BROADCAST 6 -#define SO_SNDBUF 7 -#define SO_RCVBUF 8 -#define SO_KEEPALIVE 9 -#define SO_OOBINLINE 10 -#define SO_NO_CHECK 11 -#define SO_PRIORITY 12 -#define SO_LINGER 13 -#define SO_BSDCOMPAT 14 -#define SO_REUSEPORT 15 -#define SO_PASSCRED 16 -#define SO_PEERCRED 17 -#define SO_RCVLOWAT 18 -#define SO_SNDLOWAT 19 -#define SO_ACCEPTCONN 30 -#define SO_PEERSEC 31 -#define SO_SNDBUFFORCE 32 -#define SO_RCVBUFFORCE 33 -#define SO_PROTOCOL 38 -#define SO_DOMAIN 39 -#endif - -#ifndef SO_RCVTIMEO -#if __LONG_MAX == 0x7fffffff -#define SO_RCVTIMEO 66 -#define SO_SNDTIMEO 67 -#else -#define SO_RCVTIMEO 20 -#define SO_SNDTIMEO 21 -#endif -#endif - -#ifndef SO_TIMESTAMP -#if __LONG_MAX == 0x7fffffff -#define SO_TIMESTAMP 63 -#define SO_TIMESTAMPNS 64 -#define SO_TIMESTAMPING 65 -#else -#define SO_TIMESTAMP 29 -#define SO_TIMESTAMPNS 35 -#define SO_TIMESTAMPING 37 -#endif -#endif - -#define SO_SECURITY_AUTHENTICATION 22 -#define SO_SECURITY_ENCRYPTION_TRANSPORT 23 -#define SO_SECURITY_ENCRYPTION_NETWORK 24 - -#define SO_BINDTODEVICE 25 - -#define SO_ATTACH_FILTER 26 -#define SO_DETACH_FILTER 27 -#define SO_GET_FILTER SO_ATTACH_FILTER - -#define SO_PEERNAME 28 -#define SCM_TIMESTAMP SO_TIMESTAMP -#define SO_PASSSEC 34 -#define SCM_TIMESTAMPNS SO_TIMESTAMPNS -#define SO_MARK 36 -#define SCM_TIMESTAMPING SO_TIMESTAMPING -#define SO_RXQ_OVFL 40 -#define SO_WIFI_STATUS 41 -#define SCM_WIFI_STATUS SO_WIFI_STATUS -#define SO_PEEK_OFF 42 -#define SO_NOFCS 43 -#define SO_LOCK_FILTER 44 -#define SO_SELECT_ERR_QUEUE 45 -#define SO_BUSY_POLL 46 -#define SO_MAX_PACING_RATE 47 -#define SO_BPF_EXTENSIONS 48 -#define SO_INCOMING_CPU 49 -#define SO_ATTACH_BPF 50 -#define SO_DETACH_BPF SO_DETACH_FILTER -#define SO_ATTACH_REUSEPORT_CBPF 51 -#define SO_ATTACH_REUSEPORT_EBPF 52 -#define SO_CNX_ADVICE 53 -#define SCM_TIMESTAMPING_OPT_STATS 54 -#define SO_MEMINFO 55 -#define SO_INCOMING_NAPI_ID 56 -#define SO_COOKIE 57 -#define SCM_TIMESTAMPING_PKTINFO 58 -#define SO_PEERGROUPS 59 -#define SO_ZEROCOPY 60 -#define SO_TXTIME 61 -#define SCM_TXTIME SO_TXTIME -#define SO_BINDTOIFINDEX 62 -#define SO_DETACH_REUSEPORT_BPF 68 - -#ifndef SOL_SOCKET -#define SOL_SOCKET 1 -#endif - -#define SOL_IP 0 -#define SOL_IPV6 41 -#define SOL_ICMPV6 58 - -#define SOL_RAW 255 -#define SOL_DECNET 261 -#define SOL_X25 262 -#define SOL_PACKET 263 -#define SOL_ATM 264 -#define SOL_AAL 265 -#define SOL_IRDA 266 -#define SOL_NETBEUI 267 -#define SOL_LLC 268 -#define SOL_DCCP 269 -#define SOL_NETLINK 270 -#define SOL_TIPC 271 -#define SOL_RXRPC 272 -#define SOL_PPPOL2TP 273 -#define SOL_BLUETOOTH 274 -#define SOL_PNPIPE 275 -#define SOL_RDS 276 -#define SOL_IUCV 277 -#define SOL_CAIF 278 -#define SOL_ALG 279 -#define SOL_NFC 280 -#define SOL_KCM 281 -#define SOL_TLS 282 -#define SOL_XDP 283 - -#define SOMAXCONN 128 - -#define MSG_OOB 0x0001 -#define MSG_PEEK 0x0002 -#define MSG_DONTROUTE 0x0004 -#define MSG_CTRUNC 0x0008 -#define MSG_PROXY 0x0010 -#define MSG_TRUNC 0x0020 -#define MSG_DONTWAIT 0x0040 -#define MSG_EOR 0x0080 -#define MSG_WAITALL 0x0100 -#define MSG_FIN 0x0200 -#define MSG_SYN 0x0400 -#define MSG_CONFIRM 0x0800 -#define MSG_RST 0x1000 -#define MSG_ERRQUEUE 0x2000 -#define MSG_NOSIGNAL 0x4000 -#define MSG_MORE 0x8000 -#define MSG_WAITFORONE 0x10000 -#define MSG_BATCH 0x40000 -#define MSG_ZEROCOPY 0x4000000 -#define MSG_FASTOPEN 0x20000000 -#define MSG_CMSG_CLOEXEC 0x40000000 - -#define __CMSG_LEN(cmsg) (((cmsg)->cmsg_len + sizeof(long) - 1) & ~(long)(sizeof(long) - 1)) -#define __CMSG_NEXT(cmsg) ((unsigned char *)(cmsg) + __CMSG_LEN(cmsg)) -#define __MHDR_END(mhdr) ((unsigned char *)(mhdr)->msg_control + (mhdr)->msg_controllen) - -#define CMSG_DATA(cmsg) ((unsigned char *) (((struct cmsghdr *)(cmsg)) + 1)) -#define CMSG_NXTHDR(mhdr, cmsg) ((cmsg)->cmsg_len < sizeof (struct cmsghdr) || \ - __CMSG_LEN(cmsg) + sizeof(struct cmsghdr) >= __MHDR_END(mhdr) - (unsigned char *)(cmsg) \ - ? 0 : (struct cmsghdr *)__CMSG_NEXT(cmsg)) -#define CMSG_FIRSTHDR(mhdr) ((size_t) (mhdr)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (mhdr)->msg_control : (struct cmsghdr *) 0) - -#define CMSG_ALIGN(len) (((len) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)) -#define CMSG_SPACE(len) (CMSG_ALIGN (len) + CMSG_ALIGN (sizeof (struct cmsghdr))) -#define CMSG_LEN(len) (CMSG_ALIGN (sizeof (struct cmsghdr)) + (len)) - -#define SCM_RIGHTS 0x01 -#define SCM_CREDENTIALS 0x02 - -struct sockaddr { - sa_family_t sa_family; - char sa_data[14]; -}; - -#define __kernel_sockaddr_storage sockaddr_storage -#include -#undef __kernel_sockaddr_storage - -int socket (int, int, int); -int socketpair (int, int, int, int [2]); - -int shutdown (int, int); - -int bind (int, const struct sockaddr *, socklen_t); -int connect (int, const struct sockaddr *, socklen_t); -int listen (int, int); -int accept (int, struct sockaddr *__restrict, socklen_t *__restrict); -int accept4(int, struct sockaddr *__restrict, socklen_t *__restrict, int); - -int getsockname (int, struct sockaddr *__restrict, socklen_t *__restrict); -int getpeername (int, struct sockaddr *__restrict, socklen_t *__restrict); - -ssize_t send (int, const void *, size_t, int); -ssize_t recv (int, void *, size_t, int); -ssize_t sendto (int, const void *, size_t, int, const struct sockaddr *, socklen_t); -ssize_t recvfrom (int, void *__restrict, size_t, int, struct sockaddr *__restrict, socklen_t *__restrict); -ssize_t sendmsg (int, const struct msghdr *, int); -ssize_t recvmsg (int, struct msghdr *, int); - -int getsockopt (int, int, int, void *__restrict, socklen_t *__restrict); -int setsockopt (int, int, int, const void *, socklen_t); - -int sockatmark (int); - -#if _REDIR_TIME64 -#ifdef _GNU_SOURCE -__REDIR(recvmmsg, __recvmmsg_time64); -#endif -#endif - -#ifdef __cplusplus -} -#endif -#endif diff --git a/porting/linux/user/include/unistd.h b/porting/linux/user/include/unistd.h index 6a8437bed9daac22d38fb85ff802c6cc8a1a0502..07584a23e73d73f5706b892f7629a1be65cefeb8 100644 --- a/porting/linux/user/include/unistd.h +++ b/porting/linux/user/include/unistd.h @@ -463,19 +463,6 @@ pid_t gettid(void); #define _CS_V6_ENV 1148 #define _CS_V7_ENV 1149 -#ifdef _GNU_SOURCE -#ifndef TEMP_FAILURE_RETRY -#define MUSL_TEMP_FAILURE_RETRY(expression) \ - (__extension__ \ - ({ long int __result; \ - do __result = (long int)(expression); \ - while(__result == -1L&& errno == EINTR); \ - __result;})) - -#define TEMP_FAILURE_RETRY(expression) MUSL_TEMP_FAILURE_RETRY(expression) -#endif -#endif - #ifdef __cplusplus } #endif diff --git a/porting/linux/user/src/internal/pthread_impl.h b/porting/linux/user/src/internal/pthread_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..df67a3d4f6a42e126f6b28c8264b5d7f4431264d --- /dev/null +++ b/porting/linux/user/src/internal/pthread_impl.h @@ -0,0 +1,200 @@ +#ifndef _PTHREAD_IMPL_H +#define _PTHREAD_IMPL_H + +#include +#include +#include +#include +#include +#include "libc.h" +#include "syscall.h" +#include "atomic.h" +#include "futex.h" + +#define pthread __pthread + +struct pthread { + /* Part 1 -- these fields may be external or + * internal (accessed via asm) ABI. Do not change. */ + struct pthread *self; + uintptr_t *dtv; + struct pthread *prev, *next; /* non-ABI */ + uintptr_t sysinfo; + uintptr_t canary, canary2; + + /* Part 2 -- implementation details, non-ABI. */ + int tid; + int errno_val; + volatile int detach_state; + volatile int cancel; + volatile unsigned char canceldisable, cancelasync; + unsigned char tsd_used:1; + unsigned char dlerror_flag:1; + unsigned char *map_base; + size_t map_size; + void *stack; + size_t stack_size; + size_t guard_size; + void *result; + struct __ptcb *cancelbuf; + void **tsd; + struct { + volatile void *volatile head; + long off; + volatile void *volatile pending; + } robust_list; + volatile int timer_id; + locale_t locale; + volatile int killlock[1]; + char *dlerror_buf; + void *stdio_locks; + + /* Part 3 -- the positions of these fields relative to + * the end of the structure is external and internal ABI. */ + uintptr_t canary_at_end; + uintptr_t *dtv_copy; +}; + +enum { + DT_EXITING = 0, + DT_JOINABLE, + DT_DETACHED, +}; + +struct __timer { + int timerid; + pthread_t thread; +}; + +#define __SU (sizeof(size_t)/sizeof(int)) + +#define _a_stacksize __u.__s[0] +#define _a_guardsize __u.__s[1] +#define _a_stackaddr __u.__s[2] +#define _a_detach __u.__i[3*__SU+0] +#define _a_sched __u.__i[3*__SU+1] +#define _a_policy __u.__i[3*__SU+2] +#define _a_prio __u.__i[3*__SU+3] + +/* we define the original value of _m_* in include/pthread.h + * as macros MUTEX_* to make the user be able to + * access the inner attribute of the mutex struct. + * Then, we modify the value of _m_* macros to MUTEX_* here, + * so that we can immediately be aware of the changes that + * the open source society has made to these original macros, + * because patching will fail if the value of the _m_* are + * changed by musl society */ +#define _m_type MUTEX_TYPE +#define _m_lock MUTEX_LOCK +#define _m_waiters MUTEX_WAITERS +#define _m_prev MUTEX_PREV +#define _m_next MUTEX_NEXT +#define _m_count MUTEX_COUNT + +#define _c_shared __u.__p[0] +#define _c_seq __u.__vi[2] +#define _c_waiters __u.__vi[3] +#define _c_clock __u.__i[4] +#define _c_lock __u.__vi[8] +#define _c_head __u.__p[1] +#define _c_tail __u.__p[5] +#define _rw_lock __u.__vi[0] +#define _rw_waiters __u.__vi[1] +#define _rw_shared __u.__i[2] +#define _b_lock __u.__vi[0] +#define _b_waiters __u.__vi[1] +#define _b_limit __u.__i[2] +#define _b_count __u.__vi[3] +#define _b_waiters2 __u.__vi[4] +#define _b_inst __u.__p[3] + +#include "pthread_arch.h" + +#ifndef CANARY +#define CANARY canary +#endif + +#ifndef DTP_OFFSET +#define DTP_OFFSET 0 +#endif + +#ifndef tls_mod_off_t +#define tls_mod_off_t size_t +#endif + +#define SIGTIMER 32 +#define SIGCANCEL 33 +#define SIGSYNCCALL 34 + +#define SIGALL_SET ((sigset_t *)(const unsigned long long [2]){ -1,-1 }) +#define SIGPT_SET \ + ((sigset_t *)(const unsigned long [_NSIG/8/sizeof(long)]){ \ + [sizeof(long)==4] = 3UL<<(32*(sizeof(long)>4)) }) +#define SIGTIMER_SET \ + ((sigset_t *)(const unsigned long [_NSIG/8/sizeof(long)]){ \ + 0x80000000 }) + +void *__tls_get_addr(tls_mod_off_t *); +hidden int __init_tp(void *); +hidden void *__copy_tls(unsigned char *); +hidden void __reset_tls(); + +hidden void __membarrier_init(void); +hidden void __dl_thread_cleanup(void); +hidden void __testcancel(); +hidden void __do_cleanup_push(struct __ptcb *); +hidden void __do_cleanup_pop(struct __ptcb *); +hidden void __pthread_tsd_run_dtors(); + +hidden void __pthread_key_delete_synccall(void (*)(void *), void *); +hidden int __pthread_key_delete_impl(pthread_key_t); + +extern hidden volatile size_t __pthread_tsd_size; +extern hidden void *__pthread_tsd_main[]; +extern hidden volatile int __aio_fut; +extern hidden volatile int __eintr_valid_flag; + +hidden int __clone(int (*)(void *), void *, int, void *, ...); +hidden int __set_thread_area(void *); +hidden int __libc_sigaction(int, const struct sigaction *, struct sigaction *); +hidden void __unmapself(void *, size_t); + +hidden int __timedwait(volatile int *, int, clockid_t, const struct timespec *, int); +hidden int __timedwait_cp(volatile int *, int, clockid_t, const struct timespec *, int); +hidden void __wait(volatile int *, volatile int *, int, int); +static inline void __wake(volatile void *addr, int cnt, int priv) +{ + if (priv) priv = FUTEX_PRIVATE; + if (cnt<0) cnt = INT_MAX; + __syscall(SYS_futex, addr, FUTEX_WAKE|priv, cnt) != -ENOSYS || + __syscall(SYS_futex, addr, FUTEX_WAKE, cnt); +} +static inline void __futexwait(volatile void *addr, int val, int priv) +{ + if (priv) priv = FUTEX_PRIVATE; + __syscall(SYS_futex, addr, FUTEX_WAIT|priv, val, 0) != -ENOSYS || + __syscall(SYS_futex, addr, FUTEX_WAIT, val, 0); +} + +hidden void __acquire_ptc(void); +hidden void __release_ptc(void); +hidden void __inhibit_ptc(void); + +hidden void __tl_lock(void); +hidden void __tl_unlock(void); +hidden void __tl_sync(pthread_t); + +extern hidden volatile int __thread_list_lock; + +extern hidden unsigned __default_stacksize; +extern hidden unsigned __default_guardsize; + +#define DEFAULT_STACK_SIZE 131072 +#define DEFAULT_GUARD_SIZE 8192 + +#define DEFAULT_STACK_MAX (8<<20) +#define DEFAULT_GUARD_MAX (1<<20) + +#define __ATTRP_C11_THREAD ((void*)(uintptr_t)-1) + +#endif diff --git a/porting/linux/user/src/internal/syscall.h b/porting/linux/user/src/internal/syscall.h new file mode 100644 index 0000000000000000000000000000000000000000..fb64c282263db57faaf10ee27c3e51ee1a2fde65 --- /dev/null +++ b/porting/linux/user/src/internal/syscall.h @@ -0,0 +1,380 @@ +#ifndef _INTERNAL_SYSCALL_H +#define _INTERNAL_SYSCALL_H + +#include +#include +#include "syscall_arch.h" + +#ifndef SYSCALL_RLIM_INFINITY +#define SYSCALL_RLIM_INFINITY (~0ULL) +#endif + +#ifndef SYSCALL_MMAP2_UNIT +#define SYSCALL_MMAP2_UNIT 4096ULL +#endif + +#ifndef __SYSCALL_LL_PRW +#define __SYSCALL_LL_PRW(x) __SYSCALL_LL_O(x) +#endif + +#ifndef __scc +#define __scc(X) ((long) (X)) +typedef long syscall_arg_t; +#endif + +hidden long __syscall_ret(unsigned long), + __syscall_cp(syscall_arg_t, syscall_arg_t, syscall_arg_t, syscall_arg_t, + syscall_arg_t, syscall_arg_t, syscall_arg_t); + +#define __syscall1(n,a) __syscall1(n,__scc(a)) +#define __syscall2(n,a,b) __syscall2(n,__scc(a),__scc(b)) +#define __syscall3(n,a,b,c) __syscall3(n,__scc(a),__scc(b),__scc(c)) +#define __syscall4(n,a,b,c,d) __syscall4(n,__scc(a),__scc(b),__scc(c),__scc(d)) +#define __syscall5(n,a,b,c,d,e) __syscall5(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e)) +#define __syscall6(n,a,b,c,d,e,f) __syscall6(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e),__scc(f)) +#define __syscall7(n,a,b,c,d,e,f,g) __syscall7(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e),__scc(f),__scc(g)) + +#define __SYSCALL_NARGS_X(a,b,c,d,e,f,g,h,n,...) n +#define __SYSCALL_NARGS(...) __SYSCALL_NARGS_X(__VA_ARGS__,7,6,5,4,3,2,1,0,) +#define __SYSCALL_CONCAT_X(a,b) a##b +#define __SYSCALL_CONCAT(a,b) __SYSCALL_CONCAT_X(a,b) +#define __SYSCALL_DISP(b,...) __SYSCALL_CONCAT(b,__SYSCALL_NARGS(__VA_ARGS__))(__VA_ARGS__) + +#define __syscall(...) __SYSCALL_DISP(__syscall,__VA_ARGS__) +#define syscall(...) __syscall_ret(__syscall(__VA_ARGS__)) + +#define socketcall(nm,a,b,c,d,e,f) __syscall_ret(__socketcall(nm,a,b,c,d,e,f)) +#define socketcall_cp(nm,a,b,c,d,e,f) __syscall_ret(__socketcall_cp(nm,a,b,c,d,e,f)) + +#define __syscall_cp0(n) (__syscall_cp)(n,0,0,0,0,0,0) +#define __syscall_cp1(n,a) (__syscall_cp)(n,__scc(a),0,0,0,0,0) +#define __syscall_cp2(n,a,b) (__syscall_cp)(n,__scc(a),__scc(b),0,0,0,0) +#define __syscall_cp3(n,a,b,c) (__syscall_cp)(n,__scc(a),__scc(b),__scc(c),0,0,0) +#define __syscall_cp4(n,a,b,c,d) (__syscall_cp)(n,__scc(a),__scc(b),__scc(c),__scc(d),0,0) +#define __syscall_cp5(n,a,b,c,d,e) (__syscall_cp)(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e),0) +#define __syscall_cp6(n,a,b,c,d,e,f) (__syscall_cp)(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e),__scc(f)) + +#define __syscall_cp(...) __SYSCALL_DISP(__syscall_cp,__VA_ARGS__) +#define syscall_cp(...) __syscall_ret(__syscall_cp(__VA_ARGS__)) + +#ifndef SYSCALL_USE_SOCKETCALL +#define __socketcall(nm,a,b,c,d,e,f) __syscall(SYS_##nm, a, b, c, d, e, f) +#define __socketcall_cp(nm,a,b,c,d,e,f) __syscall_cp(SYS_##nm, a, b, c, d, e, f) +#else +#define __socketcall(nm,a,b,c,d,e,f) __syscall(SYS_socketcall, __SC_##nm, \ + ((long [6]){ (long)a, (long)b, (long)c, (long)d, (long)e, (long)f })) +#define __socketcall_cp(nm,a,b,c,d,e,f) __syscall_cp(SYS_socketcall, __SC_##nm, \ + ((long [6]){ (long)a, (long)b, (long)c, (long)d, (long)e, (long)f })) +#endif + +/* fixup legacy 16-bit junk */ + +#ifdef SYS_getuid32 +#undef SYS_lchown +#undef SYS_getuid +#undef SYS_getgid +#undef SYS_geteuid +#undef SYS_getegid +#undef SYS_setreuid +#undef SYS_setregid +#undef SYS_getgroups +#undef SYS_setgroups +#undef SYS_fchown +#undef SYS_setresuid +#undef SYS_getresuid +#undef SYS_setresgid +#undef SYS_getresgid +#undef SYS_chown +#undef SYS_setuid +#undef SYS_setgid +#undef SYS_setfsuid +#undef SYS_setfsgid +#define SYS_lchown SYS_lchown32 +#define SYS_getuid SYS_getuid32 +#define SYS_getgid SYS_getgid32 +#define SYS_geteuid SYS_geteuid32 +#define SYS_getegid SYS_getegid32 +#define SYS_setreuid SYS_setreuid32 +#define SYS_setregid SYS_setregid32 +#define SYS_getgroups SYS_getgroups32 +#define SYS_setgroups SYS_setgroups32 +#define SYS_fchown SYS_fchown32 +#define SYS_setresuid SYS_setresuid32 +#define SYS_getresuid SYS_getresuid32 +#define SYS_setresgid SYS_setresgid32 +#define SYS_getresgid SYS_getresgid32 +#define SYS_chown SYS_chown32 +#define SYS_setuid SYS_setuid32 +#define SYS_setgid SYS_setgid32 +#define SYS_setfsuid SYS_setfsuid32 +#define SYS_setfsgid SYS_setfsgid32 +#endif + + +/* fixup legacy 32-bit-vs-lfs64 junk */ + +#ifdef SYS_fcntl64 +#undef SYS_fcntl +#define SYS_fcntl SYS_fcntl64 +#endif + +#ifdef SYS_getdents64 +#undef SYS_getdents +#define SYS_getdents SYS_getdents64 +#endif + +#ifdef SYS_ftruncate64 +#undef SYS_ftruncate +#undef SYS_truncate +#define SYS_ftruncate SYS_ftruncate64 +#define SYS_truncate SYS_truncate64 +#endif + +#ifdef SYS_stat64 +#undef SYS_stat +#define SYS_stat SYS_stat64 +#endif + +#ifdef SYS_fstat64 +#undef SYS_fstat +#define SYS_fstat SYS_fstat64 +#endif + +#ifdef SYS_lstat64 +#undef SYS_lstat +#define SYS_lstat SYS_lstat64 +#endif + +#ifdef SYS_statfs64 +#undef SYS_statfs +#define SYS_statfs SYS_statfs64 +#endif + +#ifdef SYS_fstatfs64 +#undef SYS_fstatfs +#define SYS_fstatfs SYS_fstatfs64 +#endif + +#if defined(SYS_newfstatat) +#undef SYS_fstatat +#define SYS_fstatat SYS_newfstatat +#elif defined(SYS_fstatat64) +#undef SYS_fstatat +#define SYS_fstatat SYS_fstatat64 +#endif + +#ifdef SYS_ugetrlimit +#undef SYS_getrlimit +#define SYS_getrlimit SYS_ugetrlimit +#endif + +#ifdef SYS__newselect +#undef SYS_select +#define SYS_select SYS__newselect +#endif + +#ifdef SYS_pread64 +#undef SYS_pread +#undef SYS_pwrite +#define SYS_pread SYS_pread64 +#define SYS_pwrite SYS_pwrite64 +#endif + +#ifdef SYS_fadvise64_64 +#undef SYS_fadvise +#define SYS_fadvise SYS_fadvise64_64 +#elif defined(SYS_fadvise64) +#undef SYS_fadvise +#define SYS_fadvise SYS_fadvise64 +#endif + +#ifdef SYS_sendfile64 +#undef SYS_sendfile +#define SYS_sendfile SYS_sendfile64 +#endif + +#ifndef SYS_timer_settime +#define SYS_timer_settime SYS_timer_settime32 +#endif + +#ifndef SYS_timer_gettime +#define SYS_timer_gettime SYS_timer_gettime32 +#endif + +#ifndef SYS_timerfd_settime +#define SYS_timerfd_settime SYS_timerfd_settime32 +#endif + +#ifndef SYS_timerfd_gettime +#define SYS_timerfd_gettime SYS_timerfd_gettime32 +#endif + +#ifndef SYS_clock_settime +#define SYS_clock_settime SYS_clock_settime32 +#endif + +#ifndef SYS_clock_gettime +#define SYS_clock_gettime SYS_clock_gettime32 +#endif + +#ifndef SYS_clock_getres +#define SYS_clock_getres SYS_clock_getres_time32 +#endif + +#ifndef SYS_clock_nanosleep +#define SYS_clock_nanosleep SYS_clock_nanosleep_time32 +#endif + +#ifndef SYS_gettimeofday +#define SYS_gettimeofday SYS_gettimeofday_time32 +#endif + +#ifndef SYS_settimeofday +#define SYS_settimeofday SYS_settimeofday_time32 +#endif + +/* Ensure that the plain syscall names are defined even for "time64-only" + * archs. These facilitate callers passing null time arguments, and make + * tests for establishing which to use/fallback-to more consistent when + * they do need to be called with time arguments. */ + +#ifndef SYS_clock_gettime +#define SYS_clock_gettime SYS_clock_gettime64 +#endif + +#ifndef SYS_clock_settime +#define SYS_clock_settime SYS_clock_settime64 +#endif + +#ifndef SYS_clock_adjtime +#define SYS_clock_adjtime SYS_clock_adjtime64 +#endif + +#ifndef SYS_clock_getres +#define SYS_clock_getres SYS_clock_getres_time64 +#endif + +#ifndef SYS_clock_nanosleep +#define SYS_clock_nanosleep SYS_clock_nanosleep_time64 +#endif + +#ifndef SYS_timer_gettime +#define SYS_timer_gettime SYS_timer_gettime64 +#endif + +#ifndef SYS_timer_settime +#define SYS_timer_settime SYS_timer_settime64 +#endif + +#ifndef SYS_timerfd_gettime +#define SYS_timerfd_gettime SYS_timerfd_gettime64 +#endif + +#ifndef SYS_timerfd_settime +#define SYS_timerfd_settime SYS_timerfd_settime64 +#endif + +#ifndef SYS_utimensat +#define SYS_utimensat SYS_utimensat_time64 +#endif + +#ifndef SYS_ppoll +#define SYS_ppoll SYS_ppoll_time64 +#endif + +#ifndef SYS_recvmmsg +#define SYS_recvmmsg SYS_recvmmsg_time64 +#endif + +#ifndef SYS_mq_timedsend +#define SYS_mq_timedsend SYS_mq_timedsend_time64 +#endif + +#ifndef SYS_mq_timedreceive +#define SYS_mq_timedreceive SYS_mq_timedreceive_time64 +#endif + +/* SYS_semtimedop omitted because SYS_ipc may provide it */ + +#ifndef SYS_rt_sigtimedwait +#define SYS_rt_sigtimedwait SYS_rt_sigtimedwait_time64 +#endif + +#ifndef SYS_futex +#define SYS_futex SYS_futex_time64 +#endif + +#ifndef SYS_sched_rr_get_interval +#define SYS_sched_rr_get_interval SYS_sched_rr_get_interval_time64 +#endif + + + + +/* socketcall calls */ + +#define __SC_socket 1 +#define __SC_bind 2 +#define __SC_connect 3 +#define __SC_listen 4 +#define __SC_accept 5 +#define __SC_getsockname 6 +#define __SC_getpeername 7 +#define __SC_socketpair 8 +#define __SC_send 9 +#define __SC_recv 10 +#define __SC_sendto 11 +#define __SC_recvfrom 12 +#define __SC_shutdown 13 +#define __SC_setsockopt 14 +#define __SC_getsockopt 15 +#define __SC_sendmsg 16 +#define __SC_recvmsg 17 +#define __SC_accept4 18 +#define __SC_recvmmsg 19 +#define __SC_sendmmsg 20 + +#ifndef SO_RCVTIMEO_OLD +#define SO_RCVTIMEO_OLD 20 +#endif +#ifndef SO_SNDTIMEO_OLD +#define SO_SNDTIMEO_OLD 21 +#endif + +#define SO_TIMESTAMP_OLD 29 +#define SO_TIMESTAMPNS_OLD 35 +#define SO_TIMESTAMPING_OLD 37 +#define SCM_TIMESTAMP_OLD SO_TIMESTAMP_OLD +#define SCM_TIMESTAMPNS_OLD SO_TIMESTAMPNS_OLD +#define SCM_TIMESTAMPING_OLD SO_TIMESTAMPING_OLD + +#ifndef SIOCGSTAMP_OLD +#define SIOCGSTAMP_OLD 0x8906 +#endif +#ifndef SIOCGSTAMPNS_OLD +#define SIOCGSTAMPNS_OLD 0x8907 +#endif + +#ifdef SYS_open +#define __sys_open2(x,pn,fl) __syscall2(SYS_open, pn, (fl)|O_LARGEFILE) +#define __sys_open3(x,pn,fl,mo) __syscall3(SYS_open, pn, (fl)|O_LARGEFILE, mo) +#define __sys_open_cp2(x,pn,fl) __syscall_cp2(SYS_open, pn, (fl)|O_LARGEFILE) +#define __sys_open_cp3(x,pn,fl,mo) __syscall_cp3(SYS_open, pn, (fl)|O_LARGEFILE, mo) +#else +#define __sys_open2(x,pn,fl) __syscall3(SYS_openat, AT_FDCWD, pn, (fl)|O_LARGEFILE) +#define __sys_open3(x,pn,fl,mo) __syscall4(SYS_openat, AT_FDCWD, pn, (fl)|O_LARGEFILE, mo) +#define __sys_open_cp2(x,pn,fl) __syscall_cp3(SYS_openat, AT_FDCWD, pn, (fl)|O_LARGEFILE) +#define __sys_open_cp3(x,pn,fl,mo) __syscall_cp4(SYS_openat, AT_FDCWD, pn, (fl)|O_LARGEFILE, mo) +#endif + +#define __sys_open(...) __SYSCALL_DISP(__sys_open,,__VA_ARGS__) +#define sys_open(...) __syscall_ret(__sys_open(__VA_ARGS__)) + +#define __sys_open_cp(...) __SYSCALL_DISP(__sys_open_cp,,__VA_ARGS__) +#define sys_open_cp(...) __syscall_ret(__sys_open_cp(__VA_ARGS__)) + +hidden void __procfdname(char __buf[static 15+3*sizeof(int)], unsigned); + +hidden void *__vdsosym(const char *, const char *); + +#endif diff --git a/porting/linux/user/src/legacy/ulimit.c b/porting/linux/user/src/legacy/ulimit.c new file mode 100644 index 0000000000000000000000000000000000000000..d1620e6e2812d364d16a0e24bd6316e6de16f7ad --- /dev/null +++ b/porting/linux/user/src/legacy/ulimit.c @@ -0,0 +1,20 @@ +#include +#include +#include +#include + +long ulimit(int cmd, ...) +{ + struct rlimit rl; + getrlimit(RLIMIT_FSIZE, &rl); + if (cmd == UL_SETFSIZE) { + long val; + va_list ap; + va_start(ap, cmd); + val = va_arg(ap, long); + va_end(ap); + rl.rlim_cur = 512ULL * val; + if (setrlimit(RLIMIT_FSIZE, &rl)) return -1; + } + return rl.rlim_cur == RLIM_INFINITY? LONG_MAX : rl.rlim_cur / 512; +} diff --git a/porting/linux/user/src/linux/gettid.c b/porting/linux/user/src/linux/gettid.c new file mode 100644 index 0000000000000000000000000000000000000000..70767137e92fe9a8820aede17af029f13d845a5a --- /dev/null +++ b/porting/linux/user/src/linux/gettid.c @@ -0,0 +1,8 @@ +#define _GNU_SOURCE +#include +#include "pthread_impl.h" + +pid_t gettid(void) +{ + return __pthread_self()->tid; +} diff --git a/porting/linux/user/src/malloc/malloc.c b/porting/linux/user/src/malloc/malloc.c new file mode 100644 index 0000000000000000000000000000000000000000..07848ec1e09afe874d7f6180e7d80a16f39cee30 --- /dev/null +++ b/porting/linux/user/src/malloc/malloc.c @@ -0,0 +1,552 @@ +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include "libc.h" +#include "atomic.h" +#include "pthread_impl.h" +#include "malloc_impl.h" + +#if defined(__GNUC__) && defined(__PIC__) +#define inline inline __attribute__((always_inline)) +#endif + +static struct { + volatile uint64_t binmap; + struct bin bins[64]; + volatile int free_lock[2]; +} mal; + +int __malloc_replaced; + +/* Synchronization tools */ + +static inline void lock(volatile int *lk) +{ + if (libc.threads_minus_1) + while(a_swap(lk, 1)) __wait(lk, lk+1, 1, 1); +} + +static inline void unlock(volatile int *lk) +{ + if (lk[0]) { + a_store(lk, 0); + if (lk[1]) __wake(lk, 1, 1); + } +} + +static inline void lock_bin(int i) +{ + lock(mal.bins[i].lock); + if (!mal.bins[i].head) + mal.bins[i].head = mal.bins[i].tail = BIN_TO_CHUNK(i); +} + +static inline void unlock_bin(int i) +{ + unlock(mal.bins[i].lock); +} + +static int first_set(uint64_t x) +{ +#if 1 + return a_ctz_64(x); +#else + static const char debruijn64[64] = { + 0, 1, 2, 53, 3, 7, 54, 27, 4, 38, 41, 8, 34, 55, 48, 28, + 62, 5, 39, 46, 44, 42, 22, 9, 24, 35, 59, 56, 49, 18, 29, 11, + 63, 52, 6, 26, 37, 40, 33, 47, 61, 45, 43, 21, 23, 58, 17, 10, + 51, 25, 36, 32, 60, 20, 57, 16, 50, 31, 19, 15, 30, 14, 13, 12 + }; + static const char debruijn32[32] = { + 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13, + 31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14 + }; + if (sizeof(long) < 8) { + uint32_t y = x; + if (!y) { + y = x>>32; + return 32 + debruijn32[(y&-y)*0x076be629 >> 27]; + } + return debruijn32[(y&-y)*0x076be629 >> 27]; + } + return debruijn64[(x&-x)*0x022fdd63cc95386dull >> 58]; +#endif +} + +static const unsigned char bin_tab[60] = { + 32,33,34,35,36,36,37,37,38,38,39,39, + 40,40,40,40,41,41,41,41,42,42,42,42,43,43,43,43, + 44,44,44,44,44,44,44,44,45,45,45,45,45,45,45,45, + 46,46,46,46,46,46,46,46,47,47,47,47,47,47,47,47, +}; + +static int bin_index(size_t x) +{ + x = x / SIZE_ALIGN - 1; + if (x <= 32) return x; + if (x < 512) return bin_tab[x/8-4]; + if (x > 0x1c00) return 63; + return bin_tab[x/128-4] + 16; +} + +static int bin_index_up(size_t x) +{ + x = x / SIZE_ALIGN - 1; + if (x <= 32) return x; + x--; + if (x < 512) return bin_tab[x/8-4] + 1; + return bin_tab[x/128-4] + 17; +} + +#if 0 +void __dump_heap(int x) +{ + struct chunk *c; + int i; + for (c = (void *)mal.heap; CHUNK_SIZE(c); c = NEXT_CHUNK(c)) + fprintf(stderr, "base %p size %zu (%d) flags %d/%d\n", + c, CHUNK_SIZE(c), bin_index(CHUNK_SIZE(c)), + c->csize & 15, + NEXT_CHUNK(c)->psize & 15); + for (i=0; i<64; i++) { + if (mal.bins[i].head != BIN_TO_CHUNK(i) && mal.bins[i].head) { + fprintf(stderr, "bin %d: %p\n", i, mal.bins[i].head); + if (!(mal.binmap & 1ULL<psize = 0 | C_INUSE; + } + + /* Record new heap end and fill in footer. */ + end = (char *)p + n; + w = MEM_TO_CHUNK(end); + w->psize = n | C_INUSE; + w->csize = 0 | C_INUSE; + + /* Fill in header, which may be new or may be replacing a + * zero-size sentinel header at the old end-of-heap. */ + w = MEM_TO_CHUNK(p); + w->csize = n | C_INUSE; + + unlock(heap_lock); + + return w; +} + +static int adjust_size(size_t *n) +{ + /* Result of pointer difference must fit in ptrdiff_t. */ + if (*n-1 > PTRDIFF_MAX - SIZE_ALIGN - PAGE_SIZE) { + if (*n) { + errno = ENOMEM; + return -1; + } else { + *n = SIZE_ALIGN; + return 0; + } + } + *n = (*n + OVERHEAD + SIZE_ALIGN - 1) & SIZE_MASK; + return 0; +} + +static void unbin(struct chunk *c, int i) +{ + if (c->prev == c->next) + a_and_64(&mal.binmap, ~(1ULL<prev->next = c->next; + c->next->prev = c->prev; + c->csize |= C_INUSE; + NEXT_CHUNK(c)->psize |= C_INUSE; +} + +static int alloc_fwd(struct chunk *c) +{ + int i; + size_t k; + while (!((k=c->csize) & C_INUSE)) { + i = bin_index(k); + lock_bin(i); + if (c->csize == k) { + unbin(c, i); + unlock_bin(i); + return 1; + } + unlock_bin(i); + } + return 0; +} + +static int alloc_rev(struct chunk *c) +{ + int i; + size_t k; + while (!((k=c->psize) & C_INUSE)) { + i = bin_index(k); + lock_bin(i); + if (c->psize == k) { + unbin(PREV_CHUNK(c), i); + unlock_bin(i); + return 1; + } + unlock_bin(i); + } + return 0; +} + + +/* pretrim - trims a chunk _prior_ to removing it from its bin. + * Must be called with i as the ideal bin for size n, j the bin + * for the _free_ chunk self, and bin j locked. */ +static int pretrim(struct chunk *self, size_t n, int i, int j) +{ + size_t n1; + struct chunk *next, *split; + + /* We cannot pretrim if it would require re-binning. */ + if (j < 40) return 0; + if (j < i+3) { + if (j != 63) return 0; + n1 = CHUNK_SIZE(self); + if (n1-n <= MMAP_THRESHOLD) return 0; + } else { + n1 = CHUNK_SIZE(self); + } + if (bin_index(n1-n) != j) return 0; + + next = NEXT_CHUNK(self); + split = (void *)((char *)self + n); + + split->prev = self->prev; + split->next = self->next; + split->prev->next = split; + split->next->prev = split; + split->psize = n | C_INUSE; + split->csize = n1-n; + next->psize = n1-n; + self->csize = n | C_INUSE; + return 1; +} + +static void trim(struct chunk *self, size_t n) +{ + size_t n1 = CHUNK_SIZE(self); + struct chunk *next, *split; + + if (n >= n1 - DONTCARE) return; + + next = NEXT_CHUNK(self); + split = (void *)((char *)self + n); + + split->psize = n | C_INUSE; + split->csize = n1-n | C_INUSE; + next->psize = n1-n | C_INUSE; + self->csize = n | C_INUSE; + + __bin_chunk(split); +} + +void *malloc(size_t n) +{ + struct chunk *c; + int i, j; + + if (adjust_size(&n) < 0) return 0; + + if (n > MMAP_THRESHOLD) { + size_t len = n + OVERHEAD + PAGE_SIZE - 1 & -PAGE_SIZE; + char *base = __mmap(0, len, PROT_READ|PROT_WRITE, + MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); + if (base == (void *)-1) return 0; + c = (void *)(base + SIZE_ALIGN - OVERHEAD); + c->csize = len - (SIZE_ALIGN - OVERHEAD); + c->psize = SIZE_ALIGN - OVERHEAD; + return CHUNK_TO_MEM(c); + } + + i = bin_index_up(n); + for (;;) { + uint64_t mask = mal.binmap & -(1ULL<psize = c->csize = + x->csize + CHUNK_SIZE(c); + } + break; + } + j = first_set(mask); + lock_bin(j); + c = mal.bins[j].head; + if (c != BIN_TO_CHUNK(j)) { + if (!pretrim(c, n, i, j)) unbin(c, j); + unlock_bin(j); + break; + } + unlock_bin(j); + } + + /* Now patch up in case we over-allocated */ + trim(c, n); + + return CHUNK_TO_MEM(c); +} + +static size_t mal0_clear(char *p, size_t pagesz, size_t n) +{ +#ifdef __GNUC__ + typedef uint64_t __attribute__((__may_alias__)) T; +#else + typedef unsigned char T; +#endif + char *pp = p + n; + size_t i = (uintptr_t)pp & (pagesz - 1); + for (;;) { + pp = memset(pp - i, 0, i); + if (pp - p < pagesz) return pp - p; + for (i = pagesz; i; i -= 2*sizeof(T), pp -= 2*sizeof(T)) + if (((T *)pp)[-1] | ((T *)pp)[-2]) + break; + } +} + +void *calloc(size_t m, size_t n) +{ + if (n && m > (size_t)-1/n) { + errno = ENOMEM; + return 0; + } + n *= m; + void *p = malloc(n); + if (!p) return p; + if (!__malloc_replaced) { + if (IS_MMAPPED(MEM_TO_CHUNK(p))) + return p; + if (n >= PAGE_SIZE) + n = mal0_clear(p, PAGE_SIZE, n); + } + return memset(p, 0, n); +} + +void *realloc(void *p, size_t n) +{ + struct chunk *self, *next; + size_t n0, n1; + void *new; + + if (!p) return malloc(n); + if (!n) { + free(p); + return NULL; + } + + if (adjust_size(&n) < 0) return 0; + + self = MEM_TO_CHUNK(p); + n1 = n0 = CHUNK_SIZE(self); + + if (IS_MMAPPED(self)) { + size_t extra = self->psize; + char *base = (char *)self - extra; + size_t oldlen = n0 + extra; + size_t newlen = n + extra; + /* Crash on realloc of freed chunk */ + if (extra & 1) a_crash(); + if (newlen < PAGE_SIZE && (new = malloc(n-OVERHEAD))) { + n0 = n; + goto copy_free_ret; + } + newlen = (newlen + PAGE_SIZE-1) & -PAGE_SIZE; + if (oldlen == newlen) return p; + base = __mremap(base, oldlen, newlen, MREMAP_MAYMOVE); + if (base == (void *)-1) + goto copy_realloc; + self = (void *)(base + extra); + self->csize = newlen - extra; + return CHUNK_TO_MEM(self); + } + + next = NEXT_CHUNK(self); + + /* Crash on corrupted footer (likely from buffer overflow) */ + if (next->psize != self->csize) a_crash(); + + /* Merge adjacent chunks if we need more space. This is not + * a waste of time even if we fail to get enough space, because our + * subsequent call to free would otherwise have to do the merge. */ + if (n > n1 && alloc_fwd(next)) { + n1 += CHUNK_SIZE(next); + next = NEXT_CHUNK(next); + } + /* FIXME: find what's wrong here and reenable it..? */ + if (0 && n > n1 && alloc_rev(self)) { + self = PREV_CHUNK(self); + n1 += CHUNK_SIZE(self); + } + self->csize = n1 | C_INUSE; + next->psize = n1 | C_INUSE; + + /* If we got enough space, split off the excess and return */ + if (n <= n1) { + //memmove(CHUNK_TO_MEM(self), p, n0-OVERHEAD); + trim(self, n); + return CHUNK_TO_MEM(self); + } + +copy_realloc: + /* As a last resort, allocate a new chunk and copy to it. */ + new = malloc(n-OVERHEAD); + if (!new) return 0; +copy_free_ret: + memcpy(new, p, n0-OVERHEAD); + free(CHUNK_TO_MEM(self)); + return new; +} + +void __bin_chunk(struct chunk *self) +{ + struct chunk *next = NEXT_CHUNK(self); + size_t final_size, new_size, size; + int reclaim=0; + int i; + + final_size = new_size = CHUNK_SIZE(self); + + /* Crash on corrupted footer (likely from buffer overflow) */ + if (next->psize != self->csize) a_crash(); + + for (;;) { + if (self->psize & next->csize & C_INUSE) { + self->csize = final_size | C_INUSE; + next->psize = final_size | C_INUSE; + i = bin_index(final_size); + lock_bin(i); + lock(mal.free_lock); + if (self->psize & next->csize & C_INUSE) + break; + unlock(mal.free_lock); + unlock_bin(i); + } + + if (alloc_rev(self)) { + self = PREV_CHUNK(self); + size = CHUNK_SIZE(self); + final_size += size; + if (new_size+size > RECLAIM && (new_size+size^size) > size) + reclaim = 1; + } + + if (alloc_fwd(next)) { + size = CHUNK_SIZE(next); + final_size += size; + if (new_size+size > RECLAIM && (new_size+size^size) > size) + reclaim = 1; + next = NEXT_CHUNK(next); + } + } + + if (!(mal.binmap & 1ULL<csize = final_size; + next->psize = final_size; + unlock(mal.free_lock); + + self->next = BIN_TO_CHUNK(i); + self->prev = mal.bins[i].tail; + self->next->prev = self; + self->prev->next = self; + + /* Replace middle of large chunks with fresh zero pages */ + if (reclaim) { + uintptr_t a = (uintptr_t)self + SIZE_ALIGN+PAGE_SIZE-1 & -PAGE_SIZE; + uintptr_t b = (uintptr_t)next - SIZE_ALIGN & -PAGE_SIZE; +#if 1 + __madvise((void *)a, b-a, MADV_DONTNEED); +#else + __mmap((void *)a, b-a, PROT_READ|PROT_WRITE, + MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED, -1, 0); +#endif + } + + unlock_bin(i); +} + +static void unmap_chunk(struct chunk *self) +{ + size_t extra = self->psize; + char *base = (char *)self - extra; + size_t len = CHUNK_SIZE(self) + extra; + /* Crash on double free */ + if (extra & 1) a_crash(); + __munmap(base, len); +} + +void free(void *p) +{ + if (!p) return; + + struct chunk *self = MEM_TO_CHUNK(p); + + if (IS_MMAPPED(self)) + unmap_chunk(self); + else + __bin_chunk(self); +} + +void __malloc_donate(char *start, char *end) +{ + size_t align_start_up = (SIZE_ALIGN-1) & (-(uintptr_t)start - OVERHEAD); + size_t align_end_down = (SIZE_ALIGN-1) & (uintptr_t)end; + + /* Getting past this condition ensures that the padding for alignment + * and header overhead will not overflow and will leave a nonzero + * multiple of SIZE_ALIGN bytes between start and end. */ + if (end - start <= OVERHEAD + align_start_up + align_end_down) + return; + start += align_start_up + OVERHEAD; + end -= align_end_down; + + struct chunk *c = MEM_TO_CHUNK(start), *n = MEM_TO_CHUNK(end); + c->psize = n->csize = C_INUSE; + c->csize = n->psize = C_INUSE | (end-start); + __bin_chunk(c); +} diff --git a/porting/linux/user/src/passwd/getspnam_r.c b/porting/linux/user/src/passwd/getspnam_r.c new file mode 100644 index 0000000000000000000000000000000000000000..e738d656cfb727955c9a79310e65b77fa60aedf5 --- /dev/null +++ b/porting/linux/user/src/passwd/getspnam_r.c @@ -0,0 +1,132 @@ +#include +#include +#include +#include +#include +#include "pwf.h" + +/* This implementation support Openwall-style TCB passwords in place of + * traditional shadow, if the appropriate directories and files exist. + * Thus, it is careful to avoid following symlinks or blocking on fifos + * which a malicious user might create in place of his or her TCB shadow + * file. It also avoids any allocation to prevent memory-exhaustion + * attacks via huge TCB shadow files. */ + +static long xatol(char **s) +{ + long x; + int sign; + if (**s == ':' || **s == '\n') return -1; + + sign = (int)(unsigned char)**s; + if (sign == '-' || sign == '+') ++*s; + + for (x=0; **s-'0'<10U; ++*s) x=10*x+(**s-'0'); + + if (sign == '-') return -x; + return x; +} + +int __parsespent(char *s, struct spwd *sp) +{ + sp->sp_namp = s; + if (!(s = strchr(s, ':'))) return -1; + *s = 0; + + sp->sp_pwdp = ++s; + if (!(s = strchr(s, ':'))) return -1; + *s = 0; + + s++; sp->sp_lstchg = xatol(&s); + if (*s != ':') return -1; + + s++; sp->sp_min = xatol(&s); + if (*s != ':') return -1; + + s++; sp->sp_max = xatol(&s); + if (*s != ':') return -1; + + s++; sp->sp_warn = xatol(&s); + if (*s != ':') return -1; + + s++; sp->sp_inact = xatol(&s); + if (*s != ':') return -1; + + s++; sp->sp_expire = xatol(&s); + if (*s != ':') return -1; + + s++; sp->sp_flag = xatol(&s); + if (*s != '\n') return -1; + return 0; +} + +static void cleanup(void *p) +{ + fclose(p); +} + +int getspnam_r(const char *name, struct spwd *sp, char *buf, size_t size, struct spwd **res) +{ + char path[20+NAME_MAX]; + FILE *f = 0; + int rv = 0; + int fd; + size_t k, l = strlen(name); + int skip = 0; + int cs; + int orig_errno = errno; + + *res = 0; + + /* Disallow potentially-malicious user names */ + if (*name=='.' || strchr(name, '/') || !l) + return errno = EINVAL; + + /* Buffer size must at least be able to hold name, plus some.. */ + if (size < l+100) + return errno = ERANGE; + + /* Protect against truncation */ + if (snprintf(path, sizeof path, "/etc/tcb/%s/shadow", name) >= sizeof path) + return errno = EINVAL; + + fd = open(path, O_RDONLY|O_NOFOLLOW|O_NONBLOCK|O_CLOEXEC); + if (fd >= 0) { + struct stat st = { 0 }; + errno = EINVAL; + if (fstat(fd, &st) || !S_ISREG(st.st_mode) || !(f = fdopen(fd, "rb"))) { + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); + close(fd); + pthread_setcancelstate(cs, 0); + return errno; + } + } else { + if (errno != ENOENT && errno != ENOTDIR) + return errno; + f = fopen("/etc/shadow", "rbe"); + if (!f) { + if (errno != ENOENT && errno != ENOTDIR) + return errno; + return 0; + } + } + + pthread_cleanup_push(cleanup, f); + while (fgets(buf, size, f) && (k=strlen(buf))>0) { + if (skip || strncmp(name, buf, l) || buf[l]!=':') { + skip = buf[k-1] != '\n'; + continue; + } + if (buf[k-1] != '\n') { + rv = ERANGE; + break; + } + + if (__parsespent(buf, sp) < 0) continue; + *res = sp; + break; + } + pthread_cleanup_pop(1); + errno = rv ? rv : orig_errno; + return rv; +} diff --git a/porting/linux/user/tools/install.sh b/porting/linux/user/tools/install.sh new file mode 100755 index 0000000000000000000000000000000000000000..b6a7f797898f8228f19f802454265486f2e57dcf --- /dev/null +++ b/porting/linux/user/tools/install.sh @@ -0,0 +1,66 @@ +#!/bin/sh +# +# This is an actually-safe install command which installs the new +# file atomically in the new location, rather than overwriting +# existing files. +# + +usage() { +printf "usage: %s [-D] [-l] [-r] [-m mode] src dest\n" "$0" 1>&2 +exit 1 +} + +mkdirp= +symlink= +symlinkflags="-s" +mode=755 + +while getopts Dlrm: name ; do +case "$name" in +D) mkdirp=yes ;; +l) symlink=yes ;; +r) symlink=yes; symlinkflags="$symlinkflags -r" ;; +m) mode=$OPTARG ;; +?) usage ;; +esac +done +shift $(($OPTIND - 1)) + +test "$#" -eq 2 || usage +src=$1 +dst=$2 +tmp="$dst.tmp.$$" + +case "$dst" in +*/) printf "%s: %s ends in /\n", "$0" "$dst" 1>&2 ; exit 1 ;; +esac + +set -C +set -e + +if test "$mkdirp" ; then +umask 022 +case "$2" in +*/*) mkdir -p "${dst%/*}" ;; +esac +fi + +trap 'rm -f "$tmp"' EXIT INT QUIT TERM HUP + +umask 077 + +if test "$symlink" ; then +ln $symlinkflags "$1" "$tmp" +else +cat < "$1" > "$tmp" +chmod "$mode" "$tmp" +fi + +mv -f "$tmp" "$2" +test -d "$2" && { +rm -f "$2/$tmp" +printf "%s: %s is a directory\n" "$0" "$dst" 1>&2 +exit 1 +} + +exit 0 diff --git a/scripts/create_alltypes.sh b/scripts/create_alltypes.sh new file mode 100755 index 0000000000000000000000000000000000000000..4d1874d2f932b4852fe43bae9874f4ac628b17d4 --- /dev/null +++ b/scripts/create_alltypes.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env sh + +# not check args + +while getopts o: opt +do + case $opt in + s) + src=$OPTARG + ;; + o) + output=$OPTARG + ;; + ?) + #usage + ;; + esac +done +shift $(($OPTIND - 1)) + +echo $0 "$@" $output + +sed -f $@ > $output diff --git a/scripts/create_syscall.sh b/scripts/create_syscall.sh new file mode 100755 index 0000000000000000000000000000000000000000..27d150e2730fc7f129800e43f431b23255303733 --- /dev/null +++ b/scripts/create_syscall.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env sh + +if [ $# -ne 2 ]; then + echo "$0 need 2 parameters, but the actual number is $#, please check!" + exit 1 +fi + +rm -f $2 + +cp $1 $2 + +sed -n -e s/__NR_/SYS_/p < $1 >> $2 diff --git a/scripts/create_vesion.sh b/scripts/create_vesion.sh new file mode 100755 index 0000000000000000000000000000000000000000..228a3e3fbc7fe3ecd139d8bd81005ed66cf00274 --- /dev/null +++ b/scripts/create_vesion.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env sh + +out_putdir=$3 + +if [ ! -d $out_putdir ] +then + mkdir -p $out_putdir +fi + +cp $1 $out_putdir/VERSION +cp $2 $out_putdir/version.sh + +cd $out_putdir + +version=$(sh version.sh) + +printf '#define VERSION "%s"\n' $version > version.h + +rm VERSION version.sh diff --git a/scripts/install.py b/scripts/install.py new file mode 100755 index 0000000000000000000000000000000000000000..8c6f9be5cab6b1f6456b8a0a7c691968fa35545b --- /dev/null +++ b/scripts/install.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python + +import os +import sys +import argparse +from shutil import copy + +def musl_copy_file(src, dest): + dest_dir = os.path.dirname(dest) + if not os.path.exists(dest_dir): + os.makedirs(dest_dir) + copy(src, dest) + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + + parser.add_argument('--input', + required = True, + help = 'The header source path', + metavar = 'FILE') + + parser.add_argument('--output', + required = True, + help = 'The output directory', + metavar = 'FILE') + + args = parser.parse_args() + + musl_copy_file(args.input, args.output) + +if __name__ == "__main__": + sys.exit(main()) diff --git a/scripts/porting.sh b/scripts/porting.sh new file mode 100755 index 0000000000000000000000000000000000000000..a84293ce87a25fc256f3cb4ce1cf4eb6ae34c366 --- /dev/null +++ b/scripts/porting.sh @@ -0,0 +1,31 @@ +SRC_DIR= +DST_DIR= +PORTING= + +while getopts "i:o:p:h" arg +do + case "${arg}" in + "i") + SRC_DIR=${OPTARG} + ;; + "o") + DST_DIR=${OPTARG} + ;; + "p") + PORTING=${OPTARG} + ;; + "h") + echo "help" + ;; + ?) + echo "unkonw argument" + exit 1 + ;; + esac +done + +if [ ! -d ${DST_DIR} ]; then + mkdir -p ${DST_DIR} +fi +cp -rfp ${SRC_DIR}/* ${DST_DIR} +cp -rfp ${SRC_DIR}/porting/${PORTING}/user/* ${DST_DIR}