diff --git a/build.py b/build.py index 83f9b3447..f154a10c8 100755 --- a/build.py +++ b/build.py @@ -119,12 +119,12 @@ def build_binary(args): error('Build Magisk binary failed!') collect_binary() - old_platform = False + old_plat = False flags = base_flags if 'b64xz' in targets: flags += ' B_BXZ=1' - old_platform = True + old_plat = True if 'magiskinit' in targets: for arch in archs: @@ -144,27 +144,27 @@ def build_binary(args): xz_dump(src, out, 'manager_xz') flags += ' B_INIT=1' - old_platform = True + old_plat = True if 'magiskboot' in targets: flags += ' B_BOOT=1' - old_platform = True + old_plat = True - if old_platform: - proc = subprocess.run('{} -C native OLD_PLAT=1 {} -j{}'.format(ndk_build, flags, cpu_count), shell=True, stdout=STDOUT) + if old_plat: + proc = subprocess.run('{} -C native {} -j{}'.format(ndk_build, flags, cpu_count), shell=True, stdout=STDOUT) if proc.returncode != 0: error('Build binaries failed!') collect_binary() - other = False + new_plat = False flags = base_flags if 'busybox' in targets: flags += ' B_BB=1' - other = True + new_plat = True - if other: - proc = subprocess.run('{} -C native {} -j{}'.format(ndk_build, flags, cpu_count), shell=True, stdout=STDOUT) + if new_plat: + proc = subprocess.run('{} -C native NEW_PLAT=1 {} -j{}'.format(ndk_build, flags, cpu_count), shell=True, stdout=STDOUT) if proc.returncode != 0: error('Build binaries failed!') collect_binary() diff --git a/native/jni/Application.mk b/native/jni/Application.mk index d8f23ecf7..dc65cdfaf 100644 --- a/native/jni/Application.mk +++ b/native/jni/Application.mk @@ -1,11 +1,11 @@ -APP_ABI := x86 armeabi-v7a +APP_ABI := armeabi-v7a x86 APP_CFLAGS := -std=gnu99 ${MAGISK_DEBUG} \ -DMAGISK_VERSION="${MAGISK_VERSION}" -DMAGISK_VER_CODE=${MAGISK_VER_CODE} APP_CPPFLAGS := -std=c++11 APP_SHORT_COMMANDS := true -ifdef OLD_PLAT +ifdef NEW_PLAT +APP_PLATFORM := android-21 +else APP_PLATFORM := android-16 APP_CFLAGS += -Wno-implicit-function-declaration -else -APP_PLATFORM := android-21 endif diff --git a/native/jni/core/magiskinit.c b/native/jni/core/magiskinit.c index 7d59e807a..f1ccd99dd 100644 --- a/native/jni/core/magiskinit.c +++ b/native/jni/core/magiskinit.c @@ -76,12 +76,11 @@ static void parse_cmdline(struct cmdline *cmd) { memset(cmd, 0, sizeof(*cmd)); char cmdline[4096]; - mkdir("/proc", 0555); + mkdir("/proc", 0755); xmount("proc", "/proc", "proc", 0, NULL); int fd = open("/proc/cmdline", O_RDONLY | O_CLOEXEC); cmdline[read(fd, cmdline, sizeof(cmdline))] = '\0'; close(fd); - umount("/proc"); for (char *tok = strtok(cmdline, " "); tok; tok = strtok(NULL, " ")) { if (strncmp(tok, "androidboot.slot_suffix", 23) == 0) { sscanf(tok, "androidboot.slot_suffix=%s", cmd->slot); @@ -402,7 +401,7 @@ int main(int argc, char *argv[]) { if (cmd.skip_initramfs) { // Clear rootfs - excl_list = (char *[]) { "overlay", ".backup", "init.bak", NULL }; + excl_list = (char *[]) { "overlay", ".backup", "proc", "init.bak", NULL }; frm_rf(root); } else if (access("/ramdisk.cpio.xz", R_OK) == 0) { // High compression mode @@ -499,6 +498,8 @@ int main(int argc, char *argv[]) { // Clean up close(root); + umount("/proc"); + umount("/sys"); if (mounted_system) umount("/system"); if (mounted_vendor) diff --git a/native/jni/include/utils.h b/native/jni/include/utils.h index 311508688..5718e0bd1 100644 --- a/native/jni/include/utils.h +++ b/native/jni/include/utils.h @@ -38,6 +38,7 @@ ssize_t xread(int fd, void *buf, size_t count); ssize_t xxread(int fd, void *buf, size_t count); int xpipe2(int pipefd[2], int flags); int xsetns(int fd, int nstype); +int xunshare(int flags); DIR *xopendir(const char *name); DIR *xfdopendir(int fd); struct dirent *xreaddir(DIR *dirp); @@ -81,6 +82,8 @@ pid_t xfork(); // misc.c #define quit_signals ((int []) { SIGALRM, SIGABRT, SIGHUP, SIGPIPE, SIGQUIT, SIGTERM, SIGINT, 0 }) +#define getline my_getline +#define getdelim my_getdelim unsigned get_shell_uid(); unsigned get_system_uid(); @@ -89,6 +92,8 @@ int check_data(); int file_to_vector(const char* filename, struct vector *v); int vector_to_file(const char* filename, struct vector *v); ssize_t fdgets(char *buf, size_t size, int fd); +ssize_t my_getline(char **lineptr, size_t *n, FILE *stream); +ssize_t my_getdelim(char **lineptr, size_t *n, int delim, FILE *stream); void ps(void (*func)(int)); void ps_filter_proc_name(const char *filter, void (*func)(int)); void unlock_blocks(); diff --git a/native/jni/magiskboot/bootimg.h b/native/jni/magiskboot/bootimg.h index f26bd2035..e71c6fec8 100644 --- a/native/jni/magiskboot/bootimg.h +++ b/native/jni/magiskboot/bootimg.h @@ -99,9 +99,9 @@ typedef struct mtk_hdr { } __attribute__((packed)) mtk_hdr; typedef struct dhtb_hdr { - char magic[8]; /* DHTB magic */ - char checksum[40]; /* Payload SHA256, whole image + SEANDROIDENFORCE + 0xFFFFFFFF */ - uint32_t size; /* Payload size, whole image + SEANDROIDENFORCE + 0xFFFFFFFF */ + char magic[8]; /* DHTB magic */ + uint8_t checksum[40]; /* Payload SHA256, whole image + SEANDROIDENFORCE + 0xFFFFFFFF */ + uint32_t size; /* Payload size, whole image + SEANDROIDENFORCE + 0xFFFFFFFF */ } __attribute__((packed)) dhtb_hdr; typedef struct blob_hdr { diff --git a/native/jni/magiskboot/dtb.c b/native/jni/magiskboot/dtb.c index 37e52d892..19cbbd1ae 100644 --- a/native/jni/magiskboot/dtb.c +++ b/native/jni/magiskboot/dtb.c @@ -78,7 +78,7 @@ static void dtb_patch(const char *file, int patch) { fdt_for_each_subnode(block, fdt, fstab) { fprintf(stderr, "Found block [%s] in fstab\n", fdt_get_name(fdt, block, NULL)); uint32_t value_size; - void *value = (void *) fdt_getprop(fdt, block, "fsmgr_flags", &value_size); + void *value = (void *) fdt_getprop(fdt, block, "fsmgr_flags", (int *)&value_size); if (patch) { void *dup = xmalloc(value_size); memcpy(dup, value, value_size); diff --git a/native/jni/magiskhide/hide_utils.c b/native/jni/magiskhide/hide_utils.c index 019d0d7c6..9d938ff2b 100644 --- a/native/jni/magiskhide/hide_utils.c +++ b/native/jni/magiskhide/hide_utils.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include diff --git a/native/jni/magiskhide/proc_monitor.c b/native/jni/magiskhide/proc_monitor.c index ecd7cc8aa..bcbf79e0a 100644 --- a/native/jni/magiskhide/proc_monitor.c +++ b/native/jni/magiskhide/proc_monitor.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include diff --git a/native/jni/resetprop/ErrnoRestorer.h b/native/jni/resetprop/ErrnoRestorer.h deleted file mode 100644 index f4673936a..000000000 --- a/native/jni/resetprop/ErrnoRestorer.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef ERRNO_RESTORER_H -#define ERRNO_RESTORER_H - -#include - -#include "bionic_macros.h" - -class ErrnoRestorer { - public: - explicit ErrnoRestorer() : saved_errno_(errno) { - } - - ~ErrnoRestorer() { - errno = saved_errno_; - } - - void override(int new_errno) { - saved_errno_ = new_errno; - } - - private: - int saved_errno_; - - DISALLOW_COPY_AND_ASSIGN(ErrnoRestorer); -}; - -#endif // ERRNO_RESTORER_H diff --git a/native/jni/resetprop/bionic_futex.h b/native/jni/resetprop/private/bionic_futex.h similarity index 96% rename from native/jni/resetprop/bionic_futex.h rename to native/jni/resetprop/private/bionic_futex.h index 946d9dd1f..3c7d81d19 100644 --- a/native/jni/resetprop/bionic_futex.h +++ b/native/jni/resetprop/private/bionic_futex.h @@ -29,7 +29,7 @@ #define _BIONIC_FUTEX_H #include -#include +#include "futex.h" #include #include #include @@ -40,7 +40,7 @@ __BEGIN_DECLS struct timespec; -static inline __always_inline int __futex(volatile void* ftx, int op, int value, +static inline int __futex(volatile void* ftx, int op, int value, const struct timespec* timeout, int bitset) { // Our generated syscall assembler sets errno, but our callers (pthread functions) don't want to. diff --git a/native/jni/resetprop/bionic_lock.h b/native/jni/resetprop/private/bionic_lock.h similarity index 99% rename from native/jni/resetprop/bionic_lock.h rename to native/jni/resetprop/private/bionic_lock.h index 60c440b00..828366f47 100644 --- a/native/jni/resetprop/bionic_lock.h +++ b/native/jni/resetprop/private/bionic_lock.h @@ -28,7 +28,7 @@ #ifndef _BIONIC_LOCK_H #define _BIONIC_LOCK_H -#include +#include "stdatomic.h" #include "bionic_futex.h" #include "bionic_macros.h" diff --git a/native/jni/resetprop/bionic_macros.h b/native/jni/resetprop/private/bionic_macros.h similarity index 100% rename from native/jni/resetprop/bionic_macros.h rename to native/jni/resetprop/private/bionic_macros.h diff --git a/native/jni/resetprop/private/futex.h b/native/jni/resetprop/private/futex.h new file mode 100644 index 000000000..968936678 --- /dev/null +++ b/native/jni/resetprop/private/futex.h @@ -0,0 +1,77 @@ +/**************************************************************************** + **************************************************************************** + *** + *** This header was automatically generated from a Linux kernel header + *** of the same name, to make information necessary for userspace to + *** call into the kernel available to libc. It contains only constants, + *** structures, and macros generated from the original header, and thus, + *** contains no copyrightable information. + *** + *** To edit the content of this header, modify the corresponding + *** source file (e.g. under external/kernel-headers/original/) then + *** run bionic/libc/kernel/tools/update_all.py + *** + *** Any manual change here will be lost the next time this script will + *** be run. You've been warned! + *** + **************************************************************************** + ****************************************************************************/ +#ifndef _UAPI_LINUX_FUTEX_H +#define _UAPI_LINUX_FUTEX_H +#include +#include +#define FUTEX_WAIT 0 +#define FUTEX_WAKE 1 +#define FUTEX_FD 2 +#define FUTEX_REQUEUE 3 +#define FUTEX_CMP_REQUEUE 4 +#define FUTEX_WAKE_OP 5 +#define FUTEX_LOCK_PI 6 +#define FUTEX_UNLOCK_PI 7 +#define FUTEX_TRYLOCK_PI 8 +#define FUTEX_WAIT_BITSET 9 +#define FUTEX_WAKE_BITSET 10 +#define FUTEX_WAIT_REQUEUE_PI 11 +#define FUTEX_CMP_REQUEUE_PI 12 +#define FUTEX_PRIVATE_FLAG 128 +#define FUTEX_CLOCK_REALTIME 256 +#define FUTEX_CMD_MASK ~(FUTEX_PRIVATE_FLAG | FUTEX_CLOCK_REALTIME) +#define FUTEX_WAIT_PRIVATE (FUTEX_WAIT | FUTEX_PRIVATE_FLAG) +#define FUTEX_WAKE_PRIVATE (FUTEX_WAKE | FUTEX_PRIVATE_FLAG) +#define FUTEX_REQUEUE_PRIVATE (FUTEX_REQUEUE | FUTEX_PRIVATE_FLAG) +#define FUTEX_CMP_REQUEUE_PRIVATE (FUTEX_CMP_REQUEUE | FUTEX_PRIVATE_FLAG) +#define FUTEX_WAKE_OP_PRIVATE (FUTEX_WAKE_OP | FUTEX_PRIVATE_FLAG) +#define FUTEX_LOCK_PI_PRIVATE (FUTEX_LOCK_PI | FUTEX_PRIVATE_FLAG) +#define FUTEX_UNLOCK_PI_PRIVATE (FUTEX_UNLOCK_PI | FUTEX_PRIVATE_FLAG) +#define FUTEX_TRYLOCK_PI_PRIVATE (FUTEX_TRYLOCK_PI | FUTEX_PRIVATE_FLAG) +#define FUTEX_WAIT_BITSET_PRIVATE (FUTEX_WAIT_BITSET | FUTEX_PRIVATE_FLAG) +#define FUTEX_WAKE_BITSET_PRIVATE (FUTEX_WAKE_BITSET | FUTEX_PRIVATE_FLAG) +#define FUTEX_WAIT_REQUEUE_PI_PRIVATE (FUTEX_WAIT_REQUEUE_PI | FUTEX_PRIVATE_FLAG) +#define FUTEX_CMP_REQUEUE_PI_PRIVATE (FUTEX_CMP_REQUEUE_PI | FUTEX_PRIVATE_FLAG) +struct robust_list { + struct robust_list __user * next; +}; +struct robust_list_head { + struct robust_list list; + long futex_offset; + struct robust_list __user * list_op_pending; +}; +#define FUTEX_WAITERS 0x80000000 +#define FUTEX_OWNER_DIED 0x40000000 +#define FUTEX_TID_MASK 0x3fffffff +#define ROBUST_LIST_LIMIT 2048 +#define FUTEX_BITSET_MATCH_ANY 0xffffffff +#define FUTEX_OP_SET 0 +#define FUTEX_OP_ADD 1 +#define FUTEX_OP_OR 2 +#define FUTEX_OP_ANDN 3 +#define FUTEX_OP_XOR 4 +#define FUTEX_OP_OPARG_SHIFT 8 +#define FUTEX_OP_CMP_EQ 0 +#define FUTEX_OP_CMP_NE 1 +#define FUTEX_OP_CMP_LT 2 +#define FUTEX_OP_CMP_LE 3 +#define FUTEX_OP_CMP_GT 4 +#define FUTEX_OP_CMP_GE 5 +#define FUTEX_OP(op,oparg,cmp,cmparg) (((op & 0xf) << 28) | ((cmp & 0xf) << 24) | ((oparg & 0xfff) << 12) | (cmparg & 0xfff)) +#endif diff --git a/native/jni/resetprop/private/stdatomic.h b/native/jni/resetprop/private/stdatomic.h new file mode 100644 index 000000000..c0b639d63 --- /dev/null +++ b/native/jni/resetprop/private/stdatomic.h @@ -0,0 +1,370 @@ +/* + * An implementation of C11 stdatomic.h directly borrowed from FreeBSD + * (original copyright follows), with minor modifications for + * portability to other systems. Works for recent Clang (that + * implement the feature c_atomic) and GCC 4.7+; includes + * compatibility for GCC below 4.7 but I wouldn't recommend it. + * + * Caveats and limitations: + * - Only the ``_Atomic parentheses'' notation is implemented, while + * the ``_Atomic space'' one is not. + * - _Atomic types must be typedef'ed, or programs using them will + * not type check correctly (incompatible anonymous structure + * types). + * - Non-scalar _Atomic types would require runtime support for + * runtime locking, which, as far as I know, is not currently + * available on any system. + */ + +/*- + * Copyright (c) 2011 Ed Schouten + * David Chisnall + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/include/stdatomic.h,v 1.10.2.2 2012/05/30 19:21:54 theraven Exp $ + */ + +#ifndef _STDATOMIC_H_ +#define _STDATOMIC_H_ + +#include +#include +#define _Bool bool + +#if !defined(__has_feature) +#define __has_feature(x) 0 +#endif +#if !defined(__has_builtin) +#define __has_builtin(x) 0 +#endif +#if !defined(__GNUC_PREREQ__) +#if defined(__GNUC__) && defined(__GNUC_MINOR__) +#define __GNUC_PREREQ__(maj, min) \ + ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) +#else +#define __GNUC_PREREQ__(maj, min) 0 +#endif +#endif + +#if !defined(__CLANG_ATOMICS) && !defined(__GNUC_ATOMICS) +#if __has_feature(c_atomic) +#define __CLANG_ATOMICS +#elif __GNUC_PREREQ__(4, 7) +#define __GNUC_ATOMICS +#elif !defined(__GNUC__) +#error "stdatomic.h does not support your compiler" +#endif +#endif + +#if !defined(__CLANG_ATOMICS) +#define _Atomic(T) struct { volatile __typeof__(T) __val; } +#endif + +/* + * 7.17.2 Initialization. + */ + +#if defined(__CLANG_ATOMICS) +#define ATOMIC_VAR_INIT(value) (value) +#define atomic_init(obj, value) __c11_atomic_init(obj, value) +#else +#define ATOMIC_VAR_INIT(value) { .__val = (value) } +#define atomic_init(obj, value) do { \ + (obj)->__val = (value); \ +} while (0) +#endif + +/* + * Clang and recent GCC both provide predefined macros for the memory + * orderings. If we are using a compiler that doesn't define them, use the + * clang values - these will be ignored in the fallback path. + */ + +#ifndef __ATOMIC_RELAXED +#define __ATOMIC_RELAXED 0 +#endif +#ifndef __ATOMIC_CONSUME +#define __ATOMIC_CONSUME 1 +#endif +#ifndef __ATOMIC_ACQUIRE +#define __ATOMIC_ACQUIRE 2 +#endif +#ifndef __ATOMIC_RELEASE +#define __ATOMIC_RELEASE 3 +#endif +#ifndef __ATOMIC_ACQ_REL +#define __ATOMIC_ACQ_REL 4 +#endif +#ifndef __ATOMIC_SEQ_CST +#define __ATOMIC_SEQ_CST 5 +#endif + +/* + * 7.17.3 Order and consistency. + * + * The memory_order_* constants that denote the barrier behaviour of the + * atomic operations. + */ + +enum memory_order { + memory_order_relaxed = __ATOMIC_RELAXED, + memory_order_consume = __ATOMIC_CONSUME, + memory_order_acquire = __ATOMIC_ACQUIRE, + memory_order_release = __ATOMIC_RELEASE, + memory_order_acq_rel = __ATOMIC_ACQ_REL, + memory_order_seq_cst = __ATOMIC_SEQ_CST +}; + +typedef enum memory_order memory_order; + +/* + * 7.17.4 Fences. + */ + +#ifdef __CLANG_ATOMICS +#define atomic_thread_fence(order) __c11_atomic_thread_fence(order) +#define atomic_signal_fence(order) __c11_atomic_signal_fence(order) +#elif defined(__GNUC_ATOMICS) +#define atomic_thread_fence(order) __atomic_thread_fence(order) +#define atomic_signal_fence(order) __atomic_signal_fence(order) +#else +#define atomic_thread_fence(order) __sync_synchronize() +#define atomic_signal_fence(order) __asm volatile ("" : : : "memory") +#endif + +/* + * 7.17.5 Lock-free property. + */ + +#if defined(__CLANG_ATOMICS) +#define atomic_is_lock_free(obj) \ + __c11_atomic_is_lock_free(sizeof(obj)) +#elif defined(__GNUC_ATOMICS) +#define atomic_is_lock_free(obj) \ + __atomic_is_lock_free(sizeof((obj)->__val)) +#else +#define atomic_is_lock_free(obj) \ + (sizeof((obj)->__val) <= sizeof(void *)) +#endif + +/* + * 7.17.6 Atomic integer types. + */ + +typedef _Atomic(_Bool) atomic_bool; +typedef _Atomic(char) atomic_char; +typedef _Atomic(signed char) atomic_schar; +typedef _Atomic(unsigned char) atomic_uchar; +typedef _Atomic(short) atomic_short; +typedef _Atomic(unsigned short) atomic_ushort; +typedef _Atomic(int) atomic_int; +typedef _Atomic(unsigned int) atomic_uint; +typedef _Atomic(long) atomic_long; +typedef _Atomic(unsigned long) atomic_ulong; +typedef _Atomic(long long) atomic_llong; +typedef _Atomic(unsigned long long) atomic_ullong; +#if 0 +typedef _Atomic(char16_t) atomic_char16_t; +typedef _Atomic(char32_t) atomic_char32_t; +#endif +typedef _Atomic(wchar_t) atomic_wchar_t; +typedef _Atomic(int_least8_t) atomic_int_least8_t; +typedef _Atomic(uint_least8_t) atomic_uint_least8_t; +typedef _Atomic(int_least16_t) atomic_int_least16_t; +typedef _Atomic(uint_least16_t) atomic_uint_least16_t; +typedef _Atomic(int_least32_t) atomic_int_least32_t; +typedef _Atomic(uint_least32_t) atomic_uint_least32_t; +typedef _Atomic(int_least64_t) atomic_int_least64_t; +typedef _Atomic(uint_least64_t) atomic_uint_least64_t; +typedef _Atomic(int_fast8_t) atomic_int_fast8_t; +typedef _Atomic(uint_fast8_t) atomic_uint_fast8_t; +typedef _Atomic(int_fast16_t) atomic_int_fast16_t; +typedef _Atomic(uint_fast16_t) atomic_uint_fast16_t; +typedef _Atomic(int_fast32_t) atomic_int_fast32_t; +typedef _Atomic(uint_fast32_t) atomic_uint_fast32_t; +typedef _Atomic(int_fast64_t) atomic_int_fast64_t; +typedef _Atomic(uint_fast64_t) atomic_uint_fast64_t; +typedef _Atomic(intptr_t) atomic_intptr_t; +typedef _Atomic(uintptr_t) atomic_uintptr_t; +typedef _Atomic(size_t) atomic_size_t; +typedef _Atomic(ptrdiff_t) atomic_ptrdiff_t; +typedef _Atomic(intmax_t) atomic_intmax_t; +typedef _Atomic(uintmax_t) atomic_uintmax_t; + +/* + * 7.17.7 Operations on atomic types. + */ + +/* + * Compiler-specific operations. + */ + +#if defined(__CLANG_ATOMICS) +#define atomic_compare_exchange_strong_explicit(object, expected, \ + desired, success, failure) \ + __c11_atomic_compare_exchange_strong(object, expected, desired, \ + success, failure) +#define atomic_compare_exchange_weak_explicit(object, expected, \ + desired, success, failure) \ + __c11_atomic_compare_exchange_weak(object, expected, desired, \ + success, failure) +#define atomic_exchange_explicit(object, desired, order) \ + __c11_atomic_exchange(object, desired, order) +#define atomic_fetch_add_explicit(object, operand, order) \ + __c11_atomic_fetch_add(object, operand, order) +#define atomic_fetch_and_explicit(object, operand, order) \ + __c11_atomic_fetch_and(object, operand, order) +#define atomic_fetch_or_explicit(object, operand, order) \ + __c11_atomic_fetch_or(object, operand, order) +#define atomic_fetch_sub_explicit(object, operand, order) \ + __c11_atomic_fetch_sub(object, operand, order) +#define atomic_fetch_xor_explicit(object, operand, order) \ + __c11_atomic_fetch_xor(object, operand, order) +#define atomic_load_explicit(object, order) \ + __c11_atomic_load(object, order) +#define atomic_store_explicit(object, desired, order) \ + __c11_atomic_store(object, desired, order) +#elif defined(__GNUC_ATOMICS) +#define atomic_compare_exchange_strong_explicit(object, expected, \ + desired, success, failure) \ + __atomic_compare_exchange_n(&(object)->__val, expected, \ + desired, 0, success, failure) +#define atomic_compare_exchange_weak_explicit(object, expected, \ + desired, success, failure) \ + __atomic_compare_exchange_n(&(object)->__val, expected, \ + desired, 1, success, failure) +#define atomic_exchange_explicit(object, desired, order) \ + __atomic_exchange_n(&(object)->__val, desired, order) +#define atomic_fetch_add_explicit(object, operand, order) \ + __atomic_fetch_add(&(object)->__val, operand, order) +#define atomic_fetch_and_explicit(object, operand, order) \ + __atomic_fetch_and(&(object)->__val, operand, order) +#define atomic_fetch_or_explicit(object, operand, order) \ + __atomic_fetch_or(&(object)->__val, operand, order) +#define atomic_fetch_sub_explicit(object, operand, order) \ + __atomic_fetch_sub(&(object)->__val, operand, order) +#define atomic_fetch_xor_explicit(object, operand, order) \ + __atomic_fetch_xor(&(object)->__val, operand, order) +#define atomic_load_explicit(object, order) \ + __atomic_load_n(&(object)->__val, order) +#define atomic_store_explicit(object, desired, order) \ + __atomic_store_n(&(object)->__val, desired, order) +#else +#define atomic_compare_exchange_strong_explicit(object, expected, \ + desired, success, failure) ({ \ + __typeof__((object)->__val) __v; \ + _Bool __r; \ + __v = __sync_val_compare_and_swap(&(object)->__val, \ + *(expected), desired); \ + __r = *(expected) == __v; \ + *(expected) = __v; \ + __r; \ +}) + +#define atomic_compare_exchange_weak_explicit(object, expected, \ + desired, success, failure) \ + atomic_compare_exchange_strong_explicit(object, expected, \ + desired, success, failure) +#if __has_builtin(__sync_swap) +/* Clang provides a full-barrier atomic exchange - use it if available. */ +#define atomic_exchange_explicit(object, desired, order) \ + __sync_swap(&(object)->__val, desired) +#else +/* + * __sync_lock_test_and_set() is only an acquire barrier in theory (although in + * practice it is usually a full barrier) so we need an explicit barrier after + * it. + */ +#define atomic_exchange_explicit(object, desired, order) ({ \ + __typeof__((object)->__val) __v; \ + __v = __sync_lock_test_and_set(&(object)->__val, desired); \ + __sync_synchronize(); \ + __v; \ +}) +#endif +#define atomic_fetch_add_explicit(object, operand, order) \ + __sync_fetch_and_add(&(object)->__val, operand) +#define atomic_fetch_and_explicit(object, operand, order) \ + __sync_fetch_and_and(&(object)->__val, operand) +#define atomic_fetch_or_explicit(object, operand, order) \ + __sync_fetch_and_or(&(object)->__val, operand) +#define atomic_fetch_sub_explicit(object, operand, order) \ + __sync_fetch_and_sub(&(object)->__val, operand) +#define atomic_fetch_xor_explicit(object, operand, order) \ + __sync_fetch_and_xor(&(object)->__val, operand) +#define atomic_load_explicit(object, order) \ + __sync_fetch_and_add(&(object)->__val, 0) +#define atomic_store_explicit(object, desired, order) do { \ + __sync_synchronize(); \ + (object)->__val = (desired); \ + __sync_synchronize(); \ +} while (0) +#endif + +/* + * Convenience functions. + */ + +#define atomic_compare_exchange_strong(object, expected, desired) \ + atomic_compare_exchange_strong_explicit(object, expected, \ + desired, memory_order_seq_cst, memory_order_seq_cst) +#define atomic_compare_exchange_weak(object, expected, desired) \ + atomic_compare_exchange_weak_explicit(object, expected, \ + desired, memory_order_seq_cst, memory_order_seq_cst) +#define atomic_exchange(object, desired) \ + atomic_exchange_explicit(object, desired, memory_order_seq_cst) +#define atomic_fetch_add(object, operand) \ + atomic_fetch_add_explicit(object, operand, memory_order_seq_cst) +#define atomic_fetch_and(object, operand) \ + atomic_fetch_and_explicit(object, operand, memory_order_seq_cst) +#define atomic_fetch_or(object, operand) \ + atomic_fetch_or_explicit(object, operand, memory_order_seq_cst) +#define atomic_fetch_sub(object, operand) \ + atomic_fetch_sub_explicit(object, operand, memory_order_seq_cst) +#define atomic_fetch_xor(object, operand) \ + atomic_fetch_xor_explicit(object, operand, memory_order_seq_cst) +#define atomic_load(object) \ + atomic_load_explicit(object, memory_order_seq_cst) +#define atomic_store(object, desired) \ + atomic_store_explicit(object, desired, memory_order_seq_cst) + +/* + * 7.17.8 Atomic flag type and operations. + */ + +typedef atomic_bool atomic_flag; + +#define ATOMIC_FLAG_INIT ATOMIC_VAR_INIT(0) + +#define atomic_flag_clear_explicit(object, order) \ + atomic_store_explicit(object, 0, order) +#define atomic_flag_test_and_set_explicit(object, order) \ + atomic_compare_exchange_strong_explicit(object, 0, 1, order, order) + +#define atomic_flag_clear(object) \ + atomic_flag_clear_explicit(object, memory_order_seq_cst) +#define atomic_flag_test_and_set(object) \ + atomic_flag_test_and_set_explicit(object, memory_order_seq_cst) + +#endif /* !_STDATOMIC_H_ */ \ No newline at end of file diff --git a/native/jni/resetprop/private/xattr.h b/native/jni/resetprop/private/xattr.h new file mode 100644 index 000000000..1da49d123 --- /dev/null +++ b/native/jni/resetprop/private/xattr.h @@ -0,0 +1,61 @@ +/**************************************************************************** + **************************************************************************** + *** + *** This header was automatically generated from a Linux kernel header + *** of the same name, to make information necessary for userspace to + *** call into the kernel available to libc. It contains only constants, + *** structures, and macros generated from the original header, and thus, + *** contains no copyrightable information. + *** + *** To edit the content of this header, modify the corresponding + *** source file (e.g. under external/kernel-headers/original/) then + *** run bionic/libc/kernel/tools/update_all.py + *** + *** Any manual change here will be lost the next time this script will + *** be run. You've been warned! + *** + **************************************************************************** + ****************************************************************************/ +#ifndef _UAPI_LINUX_XATTR_H +#define _UAPI_LINUX_XATTR_H +#define XATTR_OS2_PREFIX "os2." +#define XATTR_OS2_PREFIX_LEN (sizeof(XATTR_OS2_PREFIX) - 1) +#define XATTR_MAC_OSX_PREFIX "osx." +#define XATTR_MAC_OSX_PREFIX_LEN (sizeof(XATTR_MAC_OSX_PREFIX) - 1) +#define XATTR_BTRFS_PREFIX "btrfs." +#define XATTR_BTRFS_PREFIX_LEN (sizeof(XATTR_BTRFS_PREFIX) - 1) +#define XATTR_SECURITY_PREFIX "security." +#define XATTR_SECURITY_PREFIX_LEN (sizeof(XATTR_SECURITY_PREFIX) - 1) +#define XATTR_SYSTEM_PREFIX "system." +#define XATTR_SYSTEM_PREFIX_LEN (sizeof(XATTR_SYSTEM_PREFIX) - 1) +#define XATTR_TRUSTED_PREFIX "trusted." +#define XATTR_TRUSTED_PREFIX_LEN (sizeof(XATTR_TRUSTED_PREFIX) - 1) +#define XATTR_USER_PREFIX "user." +#define XATTR_USER_PREFIX_LEN (sizeof(XATTR_USER_PREFIX) - 1) +#define XATTR_EVM_SUFFIX "evm" +#define XATTR_NAME_EVM XATTR_SECURITY_PREFIX XATTR_EVM_SUFFIX +#define XATTR_IMA_SUFFIX "ima" +#define XATTR_NAME_IMA XATTR_SECURITY_PREFIX XATTR_IMA_SUFFIX +#define XATTR_SELINUX_SUFFIX "selinux" +#define XATTR_NAME_SELINUX XATTR_SECURITY_PREFIX XATTR_SELINUX_SUFFIX +#define XATTR_SMACK_SUFFIX "SMACK64" +#define XATTR_SMACK_IPIN "SMACK64IPIN" +#define XATTR_SMACK_IPOUT "SMACK64IPOUT" +#define XATTR_SMACK_EXEC "SMACK64EXEC" +#define XATTR_SMACK_TRANSMUTE "SMACK64TRANSMUTE" +#define XATTR_SMACK_MMAP "SMACK64MMAP" +#define XATTR_NAME_SMACK XATTR_SECURITY_PREFIX XATTR_SMACK_SUFFIX +#define XATTR_NAME_SMACKIPIN XATTR_SECURITY_PREFIX XATTR_SMACK_IPIN +#define XATTR_NAME_SMACKIPOUT XATTR_SECURITY_PREFIX XATTR_SMACK_IPOUT +#define XATTR_NAME_SMACKEXEC XATTR_SECURITY_PREFIX XATTR_SMACK_EXEC +#define XATTR_NAME_SMACKTRANSMUTE XATTR_SECURITY_PREFIX XATTR_SMACK_TRANSMUTE +#define XATTR_NAME_SMACKMMAP XATTR_SECURITY_PREFIX XATTR_SMACK_MMAP +#define XATTR_APPARMOR_SUFFIX "apparmor" +#define XATTR_NAME_APPARMOR XATTR_SECURITY_PREFIX XATTR_APPARMOR_SUFFIX +#define XATTR_CAPS_SUFFIX "capability" +#define XATTR_NAME_CAPS XATTR_SECURITY_PREFIX XATTR_CAPS_SUFFIX +#define XATTR_POSIX_ACL_ACCESS "posix_acl_access" +#define XATTR_NAME_POSIX_ACL_ACCESS XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_ACCESS +#define XATTR_POSIX_ACL_DEFAULT "posix_acl_default" +#define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT +#endif diff --git a/native/jni/resetprop/system_properties.cpp b/native/jni/resetprop/system_properties.cpp index 85c269aba..d3cd6621b 100644 --- a/native/jni/resetprop/system_properties.cpp +++ b/native/jni/resetprop/system_properties.cpp @@ -26,13 +26,13 @@ * SUCH DAMAGE. */ +#define typeof __typeof__ #include #include #include #include #include -#include -#include +#include "private/stdatomic.h" #include #include #include @@ -41,7 +41,7 @@ #include #include -#include +#include "private/xattr.h" #include #include #include @@ -50,10 +50,7 @@ #include #include #include - -#undef XATTR_CREATE -#undef XATTR_REPLACE -#include +//#include #define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ #include "_system_properties.h" @@ -61,10 +58,32 @@ // #include -#include "ErrnoRestorer.h" -#include "bionic_futex.h" -#include "bionic_lock.h" -#include "bionic_macros.h" +// #include "private/ErrnoRestorer.h" +#include "private/bionic_futex.h" +#include "private/bionic_lock.h" +#include "private/bionic_macros.h" +// #include "private/bionic_sdk_version.h" + +/*************** + * Workarounds * + ***************/ +#define async_safe_format_buffer snprintf +#define async_safe_format_log(...) /* NOP */ +#define CHECK(...) /* NOP */ +#define getline my_getline +static int fsetxattr(int fd, const char *name, const void *value, size_t size, int flags) { + return (int) syscall(__NR_fsetxattr, fd, name, value, size, flags); +} +#ifndef SOCK_CLOEXEC +#define SOCK_CLOEXEC O_CLOEXEC +#endif +#ifndef INT32_MAX +#define INT32_MAX (2147483647) +#endif +extern "C" ssize_t my_getline(char**, size_t*, FILE*); +/****************** + * Workaround End * + ******************/ static constexpr int PROP_FILENAME_MAX = 1024; @@ -96,16 +115,6 @@ static const char* kServiceVersionPropertyName = "ro.property_service.version"; * +-----+ +-----+ +-----+ +===========+ */ -// This is a alternative implementation for async_safe_format_buffer -// A workaround to not include the async_safe header -static int async_safe_format_buffer(char * s, size_t n, const char * format, ...) { - va_list vl; - va_start(vl, format); - int ret = vsnprintf(s, n, format, vl); - va_end(vl); - return ret; -} - // Represents a node in the trie. struct prop_bt { uint32_t namelen; @@ -246,8 +255,8 @@ static prop_area* map_prop_area_rw(const char* filename, const char* context, if (context) { if (fsetxattr(fd, XATTR_NAME_SELINUX, context, strlen(context) + 1, 0) != 0) { - // async_safe_format_log(ANDROID_LOG_ERROR, "libc", - // "fsetxattr failed to set context (%s) for \"%s\"", context, filename); + async_safe_format_log(ANDROID_LOG_ERROR, "libc", + "fsetxattr failed to set context (%s) for \"%s\"", context, filename); /* * fsetxattr() will fail during system properties tests due to selinux policy. * We do not want to create a custom policy for the tester, so we will continue in @@ -610,8 +619,8 @@ class SocketWriter { {} SocketWriter& WriteUint32(uint32_t value) { - // CHECK(uint_buf_index_ < kUintBufSize); - // CHECK(iov_index_ < kIovSize); + CHECK(uint_buf_index_ < kUintBufSize); + CHECK(iov_index_ < kIovSize); uint32_t* ptr = uint_buf_ + uint_buf_index_; uint_buf_[uint_buf_index_++] = value; iov_[iov_index_].iov_base = ptr; @@ -627,7 +636,7 @@ class SocketWriter { return *this; } - // CHECK(iov_index_ < kIovSize); + CHECK(iov_index_ < kIovSize); iov_[iov_index_].iov_base = const_cast(value); iov_[iov_index_].iov_len = valuelen; ++iov_index_; @@ -703,9 +712,9 @@ static int send_prop_msg(const prop_msg* msg) { // ms so callers who do read-after-write can reliably see // what they've written. Most of the time. // TODO: fix the system properties design. - // async_safe_format_log(ANDROID_LOG_WARN, "libc", - // "Property service has timed out while trying to set \"%s\" to \"%s\"", - // msg->name, msg->value); + async_safe_format_log(ANDROID_LOG_WARN, "libc", + "Property service has timed out while trying to set \"%s\" to \"%s\"", + msg->name, msg->value); result = 0; } } @@ -1151,7 +1160,7 @@ static void free_and_unmap_contexts() { int __system_properties_init2() { // This is called from __libc_init_common, and should leave errno at 0 (http://b/37248982). - ErrnoRestorer errno_restorer; + // ErrnoRestorer errno_restorer; if (initialized) { // list_foreach(contexts, [](context_node* l) { l->reset_access(); }); // resetprop remove @@ -1275,13 +1284,13 @@ int __system_property_read2(const prop_info* pi, char* name, char* value) { if (serial == load_const_atomic(&(pi->serial), memory_order_relaxed)) { if (name != nullptr) { size_t namelen = strlcpy(name, pi->name, PROP_NAME_MAX); - // if (namelen >= PROP_NAME_MAX) { - // async_safe_format_log(ANDROID_LOG_ERROR, "libc", - // "The property name length for \"%s\" is >= %d;" - // " please use __system_property_read_callback2" - // " to read this property. (the name is truncated to \"%s\")", - // pi->name, PROP_NAME_MAX - 1, name); - // } + if (namelen >= PROP_NAME_MAX) { + async_safe_format_log(ANDROID_LOG_ERROR, "libc", + "The property name length for \"%s\" is >= %d;" + " please use __system_property_read_callback" + " to read this property. (the name is truncated to \"%s\")", + pi->name, PROP_NAME_MAX - 1, name); + } } return len; } @@ -1331,17 +1340,17 @@ static void detect_protocol_version() { char value[PROP_VALUE_MAX]; if (__system_property_get2(kServiceVersionPropertyName, value) == 0) { g_propservice_protocol_version = kProtocolVersion1; - // async_safe_format_log(ANDROID_LOG_WARN, "libc", - // "Using old property service protocol (\"%s\" is not set)", - // kServiceVersionPropertyName); + async_safe_format_log(ANDROID_LOG_WARN, "libc", + "Using old property service protocol (\"%s\" is not set)", + kServiceVersionPropertyName); } else { uint32_t version = static_cast(atoll(value)); if (version >= kProtocolVersion2) { g_propservice_protocol_version = kProtocolVersion2; } else { - // async_safe_format_log(ANDROID_LOG_WARN, "libc", - // "Using old property service protocol (\"%s\"=\"%s\")", - // kServiceVersionPropertyName, value); + async_safe_format_log(ANDROID_LOG_WARN, "libc", + "Using old property service protocol (\"%s\"=\"%s\")", + kServiceVersionPropertyName, value); g_propservice_protocol_version = kProtocolVersion1; } } @@ -1371,50 +1380,50 @@ int __system_property_set2(const char* key, const char* value) { // Use proper protocol PropertyServiceConnection connection; if (!connection.IsValid()) { - // errno = connection.GetLastError(); - // async_safe_format_log(ANDROID_LOG_WARN, - // "libc", - // "Unable to set property \"%s\" to \"%s\": connection failed; errno=%d (%s)", - // key, - // value, - // errno, - // strerror(errno)); + errno = connection.GetLastError(); + async_safe_format_log(ANDROID_LOG_WARN, + "libc", + "Unable to set property \"%s\" to \"%s\": connection failed; errno=%d (%s)", + key, + value, + errno, + strerror(errno)); return -1; } SocketWriter writer(&connection); if (!writer.WriteUint32(PROP_MSG_SETPROP2).WriteString(key).WriteString(value).Send()) { - // errno = connection.GetLastError(); - // async_safe_format_log(ANDROID_LOG_WARN, - // "libc", - // "Unable to set property \"%s\" to \"%s\": write failed; errno=%d (%s)", - // key, - // value, - // errno, - // strerror(errno)); + errno = connection.GetLastError(); + async_safe_format_log(ANDROID_LOG_WARN, + "libc", + "Unable to set property \"%s\" to \"%s\": write failed; errno=%d (%s)", + key, + value, + errno, + strerror(errno)); return -1; } int result = -1; if (!connection.RecvInt32(&result)) { - // errno = connection.GetLastError(); - // async_safe_format_log(ANDROID_LOG_WARN, - // "libc", - // "Unable to set property \"%s\" to \"%s\": recv failed; errno=%d (%s)", - // key, - // value, - // errno, - // strerror(errno)); + errno = connection.GetLastError(); + async_safe_format_log(ANDROID_LOG_WARN, + "libc", + "Unable to set property \"%s\" to \"%s\": recv failed; errno=%d (%s)", + key, + value, + errno, + strerror(errno)); return -1; } if (result != PROP_SUCCESS) { - // async_safe_format_log(ANDROID_LOG_WARN, - // "libc", - // "Unable to set property \"%s\" to \"%s\": error code: 0x%x", - // key, - // value, - // result); + async_safe_format_log(ANDROID_LOG_WARN, + "libc", + "Unable to set property \"%s\" to \"%s\": error code: 0x%x", + key, + value, + result); return -1; } @@ -1469,7 +1478,7 @@ int __system_property_add2(const char* name, unsigned int namelen, const char* v prop_area* pa = get_prop_area_for_name(name); if (!pa) { - // async_safe_format_log(ANDROID_LOG_ERROR, "libc", "Access denied adding property \"%s\"", name); + async_safe_format_log(ANDROID_LOG_ERROR, "libc", "Access denied adding property \"%s\"", name); return -1; } diff --git a/native/jni/su b/native/jni/su index 69b226b00..001294317 160000 --- a/native/jni/su +++ b/native/jni/su @@ -1 +1 @@ -Subproject commit 69b226b005e3f87c4c872fa3382e05006969118e +Subproject commit 001294317f7d8b3e209567005edd25df0dc6e3c6 diff --git a/native/jni/utils/misc.c b/native/jni/utils/misc.c index 4b9efda92..58f121646 100644 --- a/native/jni/utils/misc.c +++ b/native/jni/utils/misc.c @@ -85,6 +85,80 @@ int check_data() { return data; } +/* Original source: https://opensource.apple.com/source/cvs/cvs-19/cvs/lib/getline.c + * License: GPL 2 or later + * Adjusted to match POSIX */ +#define MIN_CHUNK 64 +ssize_t my_getdelim(char **lineptr, size_t *n, int delim, FILE *stream) { + size_t nchars_avail; + char *read_pos; + + if (!lineptr || !n || !stream) { + errno = EINVAL; + return -1; + } + + if (!*lineptr) { + *n = MIN_CHUNK; + *lineptr = malloc(*n); + if (!*lineptr) { + errno = ENOMEM; + return -1; + } + } + + nchars_avail = *n; + read_pos = *lineptr; + + while (1) { + int save_errno; + register int c = getc(stream); + + save_errno = errno; + + if (nchars_avail < 2) { + if (*n > MIN_CHUNK) + *n *= 2; + else + *n += MIN_CHUNK; + + nchars_avail = *n + *lineptr - read_pos; + *lineptr = realloc(*lineptr, *n); + if (!*lineptr) { + errno = ENOMEM; + return -1; + } + read_pos = *n - nchars_avail + *lineptr; + } + + if (ferror(stream)) { + errno = save_errno; + return -1; + } + + if (c == EOF) { + if (read_pos == *lineptr) + return -1; + else + break; + } + + *read_pos++ = c; + nchars_avail--; + + if (c == delim) + break; + } + + *read_pos = '\0'; + + return read_pos - *lineptr; +} + +ssize_t my_getline(char **lineptr, size_t *n, FILE *stream) { + return my_getdelim(lineptr, n, '\n', stream); +} + /* All the string should be freed manually!! */ int file_to_vector(const char* filename, struct vector *v) { if (access(filename, R_OK) != 0) @@ -261,7 +335,7 @@ int exec_array(int err, int *fd, void (*setenv)(struct vector *), char *const *a } // Setup environment - char *const *envp; + char **envp; struct vector env; vec_init(&env); if (setenv) { @@ -289,8 +363,9 @@ int exec_array(int err, int *fd, void (*setenv)(struct vector *), char *const *a xdup2(writeEnd, STDERR_FILENO); } - execvpe(argv[0], argv, envp); - PLOGE("execvpe %s", argv[0]); + environ = envp; + execvp(argv[0], argv); + PLOGE("execvp %s", argv[0]); return -1; } diff --git a/native/jni/utils/xwrap.c b/native/jni/utils/xwrap.c index 72ee47026..f8a5c2684 100644 --- a/native/jni/utils/xwrap.c +++ b/native/jni/utils/xwrap.c @@ -108,6 +108,14 @@ int xsetns(int fd, int nstype) { return ret; } +int xunshare(int flags) { + int ret = (int) syscall(__NR_unshare, flags); + if (ret == -1) { + PLOGE("unshare"); + } + return ret; +} + DIR *xopendir(const char *name) { DIR *d = opendir(name); if (d == NULL) {