Merge "Adding kuser_helper on note to all arm32 binaries."
diff --git a/libc/dns/include/resolv_netid.h b/libc/dns/include/resolv_netid.h
index 7182ca6..37c1891 100644
--- a/libc/dns/include/resolv_netid.h
+++ b/libc/dns/include/resolv_netid.h
@@ -71,7 +71,7 @@
     unsigned dns_netid;
     unsigned dns_mark;
     uid_t uid;
-} __attribute__((packed));
+};
 
 #define NET_CONTEXT_INVALID_UID ((uid_t)-1)
 
diff --git a/libc/dns/include/resolv_params.h b/libc/dns/include/resolv_params.h
index 5ee265f..49ae691 100644
--- a/libc/dns/include/resolv_params.h
+++ b/libc/dns/include/resolv_params.h
@@ -41,6 +41,6 @@
     uint8_t success_threshold; // 0: disable, value / 100 otherwise
     uint8_t min_samples; // min # samples needed for statistics to be considered meaningful
     uint8_t max_samples; // max # samples taken into account for statistics
-} __attribute__((__packed__));
+};
 
 #endif // _RESOLV_PARAMS_H
diff --git a/libc/seccomp/arm64_policy.c b/libc/seccomp/arm64_policy.c
index d5a87d6..6a8bda0 100644
--- a/libc/seccomp/arm64_policy.c
+++ b/libc/seccomp/arm64_policy.c
@@ -41,7 +41,7 @@
 BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 268, 1, 0),
 BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 267, 1, 2), //clock_adjtime
 BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 272, 0, 1), //setns|sendmmsg|process_vm_readv|process_vm_writev
-BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_KILL),
+BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_TRAP),
 BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW),
 };
 
diff --git a/libc/seccomp/arm_policy.c b/libc/seccomp/arm_policy.c
index 44e734e..de03f45 100644
--- a/libc/seccomp/arm_policy.c
+++ b/libc/seccomp/arm_policy.c
@@ -139,7 +139,7 @@
 BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 983045, 1, 0),
 BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 983043, 1, 2), //__ARM_NR_cacheflush
 BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 983046, 0, 1), //__ARM_NR_set_tls
-BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_KILL),
+BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_TRAP),
 BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW),
 };
 
diff --git a/libc/tools/genseccomp.py b/libc/tools/genseccomp.py
index b82bb12..bd003a3 100755
--- a/libc/tools/genseccomp.py
+++ b/libc/tools/genseccomp.py
@@ -126,7 +126,7 @@
              ", 0, " + str(len(bpf)) + "),")
 
   # Add the error and allow calls at the end
-  bpf.append("BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_KILL),")
+  bpf.append("BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_TRAP),")
   bpf.append("BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW),")
 
   # And output policy
diff --git a/tests/dlfcn_test.cpp b/tests/dlfcn_test.cpp
index 2e4d635..a56e3a7 100644
--- a/tests/dlfcn_test.cpp
+++ b/tests/dlfcn_test.cpp
@@ -921,7 +921,25 @@
 #else
 #define PATH_TO_SYSTEM_LIB "/system/lib/"
 #endif
+#if defined (__aarch64__)
+#define ALTERNATE_PATH_TO_SYSTEM_LIB "/system/lib/arm64/"
+#elif defined (__arm__)
+#define ALTERNATE_PATH_TO_SYSTEM_LIB "/system/lib/arm/"
+#elif defined (__i386__)
+#define ALTERNATE_PATH_TO_SYSTEM_LIB "/system/lib/x86/"
+#elif defined (__x86_64__)
+#define ALTERNATE_PATH_TO_SYSTEM_LIB "/system/lib/x86_64/"
+#elif defined (__mips__)
+#if defined(__LP64__)
+#define ALTERNATE_PATH_TO_SYSTEM_LIB "/system/lib/mips64/"
+#else
+#define ALTERNATE_PATH_TO_SYSTEM_LIB "/system/lib/mips/"
+#endif
+#else
+#error "Unknown architecture"
+#endif
 #define PATH_TO_LIBC PATH_TO_SYSTEM_LIB "libc.so"
+#define ALTERNATE_PATH_TO_LIBC ALTERNATE_PATH_TO_SYSTEM_LIB "libc.so"
 
 TEST(dlfcn, dladdr_libc) {
 #if defined(__BIONIC__)
@@ -929,9 +947,18 @@
   void* addr = reinterpret_cast<void*>(puts); // well-known libc function
   ASSERT_TRUE(dladdr(addr, &info) != 0);
 
-  // /system/lib is symlink when this test is executed on host.
   char libc_realpath[PATH_MAX];
-  ASSERT_TRUE(realpath(PATH_TO_LIBC, libc_realpath) == libc_realpath);
+
+  // Check if libc is in canonical path or in alternate path.
+  if (strncmp(ALTERNATE_PATH_TO_SYSTEM_LIB,
+              info.dli_fname,
+              sizeof(ALTERNATE_PATH_TO_SYSTEM_LIB) - 1) == 0) {
+    // Platform with emulated architecture.  Symlink on ARC++.
+    ASSERT_TRUE(realpath(ALTERNATE_PATH_TO_LIBC, libc_realpath) == libc_realpath);
+  } else {
+    // /system/lib is symlink when this test is executed on host.
+    ASSERT_TRUE(realpath(PATH_TO_LIBC, libc_realpath) == libc_realpath);
+  }
 
   ASSERT_STREQ(libc_realpath, info.dli_fname);
   // TODO: add check for dfi_fbase
@@ -1248,8 +1275,14 @@
 }
 
 void validate_compatibility_of_native_library(const char* soname) {
-  std::string path = std::string(PATH_TO_SYSTEM_LIB) + soname;
+  // On the systems with emulation system libraries would be of different
+  // architecture.  Try to use alternate paths first.
+  std::string path = std::string(ALTERNATE_PATH_TO_SYSTEM_LIB) + soname;
   auto binary_or_error = llvm::object::createBinary(path);
+  if (!binary_or_error) {
+    path = std::string(PATH_TO_SYSTEM_LIB) + soname;
+    binary_or_error = llvm::object::createBinary(path);
+  }
   ASSERT_FALSE(!binary_or_error);
 
   llvm::object::Binary* binary = binary_or_error.get().getBinary();
diff --git a/tests/gtest_globals.cpp b/tests/gtest_globals.cpp
index bb99dd6..75c08b1 100644
--- a/tests/gtest_globals.cpp
+++ b/tests/gtest_globals.cpp
@@ -22,27 +22,18 @@
 #include <string>
 
 static std::string init_testlib_root() {
+  // Calculate ANDROID_DATA assuming the binary is in "$ANDROID_DATA/somedir/binary-dir/binary"
+  std::string path = get_executable_path();
+
+  path = get_dirname(path.c_str());
+  path += "/..";
+
   std::string out_path;
-  const char* data_dir = getenv("ANDROID_DATA");
-  if (data_dir == nullptr) {
-    // Calculate ANDROID_DATA assuming the binary is in "$ANDROID_DATA/somedir/binary-dir/binary"
-    std::string path = get_executable_path();
-
-    path = get_dirname(path.c_str());
-    path += "/../..";
-
-    if (!get_realpath(path.c_str(), &out_path)) {
-      printf("Failed to get realpath for \"%s\"", path.c_str());
-      abort();
-    }
-  } else {
-    out_path = data_dir;
+  if (!get_realpath(path.c_str(), &out_path)) {
+    printf("Failed to get realpath for \"%s\"", path.c_str());
+    abort();
   }
 
-  out_path = out_path + "/nativetest";
-#if defined(__LP64__)
-  out_path += "64";
-#endif
   out_path += "/bionic-loader-test-libs";
 
   std::string real_path;