Merge "linker: add more directories to default lib paths"
diff --git a/benchmarks/property_benchmark.cpp b/benchmarks/property_benchmark.cpp
index ef5f225..97eb832 100644
--- a/benchmarks/property_benchmark.cpp
+++ b/benchmarks/property_benchmark.cpp
@@ -28,8 +28,6 @@
#include <benchmark/benchmark.h>
-extern void* __system_property_area__;
-
// Do not exceed 512, that is about the largest number of properties
// that can be created with the current property area size.
#define TEST_NUM_PROPS \
@@ -53,9 +51,6 @@
return;
}
- old_pa = __system_property_area__;
- __system_property_area__ = NULL;
-
pa_dirname = dirname;
pa_filename = pa_dirname + "/__properties__";
@@ -111,9 +106,8 @@
if (!valid)
return;
- __system_property_area__ = old_pa;
-
__system_property_set_filename(PROP_FILENAME);
+ __system_property_area_init();
unlink(pa_filename.c_str());
rmdir(pa_dirname.c_str());
@@ -138,7 +132,6 @@
private:
std::string pa_dirname;
std::string pa_filename;
- void* old_pa;
};
static void BM_property_get(benchmark::State& state) {
diff --git a/libc/Android.bp b/libc/Android.bp
index f663a97..1ecef1f 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -1665,8 +1665,6 @@
keep_symbols: true,
},
- ldflags: ["-Wl,-z,global"],
-
// Do not pack libc.so relocations; see http://b/20645321 for details.
pack_relocations: false,
@@ -2157,4 +2155,4 @@
first_version: "9",
}
-subdirs = ["malloc_debug"]
+subdirs = ["*"]
diff --git a/libc/NOTICE b/libc/NOTICE
index 6882d0c..9f0d2c5 100644
--- a/libc/NOTICE
+++ b/libc/NOTICE
@@ -961,6 +961,22 @@
-------------------------------------------------------------------
Copyright (C) 2017 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.
+
+-------------------------------------------------------------------
+
+Copyright (C) 2017 The Android Open Source Project
All rights reserved.
Redistribution and use in source and binary forms, with or without
diff --git a/libc/SECCOMP_WHITELIST.TXT b/libc/SECCOMP_WHITELIST.TXT
index 22e8987..7cae1e1 100644
--- a/libc/SECCOMP_WHITELIST.TXT
+++ b/libc/SECCOMP_WHITELIST.TXT
@@ -25,69 +25,72 @@
# This file is processed by a python script named gensyscalls.py.
# syscalls needed to boot android
-int pivot_root:pivot_root(const char *new_root, const char *put_old) arm64
-int ioprio_get:ioprio_get(int which, int who) arm64
-int ioprio_set:ioprio_set(int which, int who, int ioprio) arm64
-pid_t gettid:gettid() arm64,arm
-int futex:futex(int *uaddr, int futex_op, int val, const struct timespec *timeout, int *uaddr2, int val3) arm64,arm
-int clone:clone(int (*fn)(void *), void *child_stack, int flags, void *arg, ..) arm64,arm
-int rt_sigreturn:rt_sigreturn(unsigned long __unused) arm64,arm
-int rt_tgsigqueueinfo:int rt_tgsigqueueinfo(pid_t tgid, pid_t tid, int sig, siginfo_t *uinfo) arm64,arm
-int restart_syscall:int restart_syscall() arm64,arm
-int getrandom:int getrandom(void *buf, size_t buflen, unsigned int flags) arm64,arm
+int pivot_root:pivot_root(const char *new_root, const char *put_old) arm64,x86_64,mips64
+int ioprio_get:ioprio_get(int which, int who) arm64,x86_64,mips64
+int ioprio_set:ioprio_set(int which, int who, int ioprio) arm64,x86_64,mips64
+pid_t gettid:gettid() all
+int futex:futex(int *uaddr, int futex_op, int val, const struct timespec *timeout, int *uaddr2, int val3) all
+int clone:clone(int (*fn)(void *), void *child_stack, int flags, void *arg, ..) all
+int rt_sigreturn:rt_sigreturn(unsigned long __unused) all
+int rt_tgsigqueueinfo:int rt_tgsigqueueinfo(pid_t tgid, pid_t tid, int sig, siginfo_t *uinfo) all
+int restart_syscall:int restart_syscall() all
+int getrandom:int getrandom(void *buf, size_t buflen, unsigned int flags) all
# Needed for performance tools
-int perf_event_open:perf_event_open(struct perf_event_attr *attr, pid_t pid, int cpu, int group_fd, unsigned long flags) arm64,arm
+int perf_event_open:perf_event_open(struct perf_event_attr *attr, pid_t pid, int cpu, int group_fd, unsigned long flags) all
# Needed for strace
-int tkill:tkill(int tid, int sig) arm64,arm
+int tkill:tkill(int tid, int sig) all
# b/35034743
-int syncfs:syncfs(int fd) arm64
+int syncfs:syncfs(int fd) all
# b/34763393
-int seccomp:seccomp(unsigned int operation, unsigned int flags, void *args) arm64,arm
+int seccomp:seccomp(unsigned int operation, unsigned int flags, void *args) all
# syscalls needed to boot android
-int sigreturn:sigreturn(unsigned long __unused) arm
+int sigreturn:sigreturn(unsigned long __unused) arm,x86,mips
# Syscalls needed to run GFXBenchmark
-pid_t vfork:vfork() arm
+pid_t vfork:vfork() arm,x86,x86_64
# Needed for debugging 32-bit Chrome
-int pipe:pipe(int pipefd[2]) arm
+int pipe:pipe(int pipefd[2]) arm,x86,mips
# b/34651972
-int access:access(const char *pathname, int mode) arm
-int stat64:stat64(const char *restrict path, struct stat64 *restrict buf) arm
+int access:access(const char *pathname, int mode) arm,x86,mips
+int stat64:stat64(const char *restrict path, struct stat64 *restrict buf) arm,x86,mips
# b/34813887
-int open:open(const char *path, int oflag, ... ) arm
-int getdents:getdents(unsigned int fd, struct linux_dirent *dirp, unsigned int count) arm
-int getdents64:getdents64(unsigned int fd, struct linux_dirent64 *dirp, unsigned int count) arm
+int open:open(const char *path, int oflag, ... ) arm,x86,mips
+int getdents:getdents(unsigned int fd, struct linux_dirent *dirp, unsigned int count) arm,x86,mips
# b/34719286
-int eventfd:eventfd(unsigned int initval, int flags) arm
+int eventfd:eventfd(unsigned int initval, int flags) arm,x86,mips
# b/34817266
-int epoll_wait:epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout) arm
+int epoll_wait:epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout) arm,x86,mips
# Needed by sanitizers (b/34606909)
# 5 (__NR_open) and 195 (__NR_stat64) are also required, but they are
# already allowed.
-ssize_t readlink:readlink(const char *path, char *buf, size_t bufsiz) arm
+ssize_t readlink:readlink(const char *path, char *buf, size_t bufsiz) arm,x86,mips
# b/34908783
-int epoll_create:epoll_create(int size) arm
+int epoll_create:epoll_create(int size) arm,x86,mips
# b/34979910
-int creat:creat(const char *pathname, mode_t mode) arm
-int unlink:unlink(const char *pathname) arm
+int creat:creat(const char *pathname, mode_t mode) arm,x86,mips
+int unlink:unlink(const char *pathname) arm,x86,mips
# b/35059702
-int lstat64:lstat64(const char *restrict path, struct stat64 *restrict buf) arm
+int lstat64:lstat64(const char *restrict path, struct stat64 *restrict buf) arm,x86,mips
# b/35217603
-int fcntl:fcntl(int fd, int cmd, ... /* arg */ ) arm
-pid_t fork:fork() arm
-int poll:poll(struct pollfd *fds, nfds_t nfds, int timeout) arm
+int fcntl:fcntl(int fd, int cmd, ... /* arg */ ) arm,x86,mips
+pid_t fork:fork() arm,x86,mips
+int poll:poll(struct pollfd *fds, nfds_t nfds, int timeout) arm,x86,mips
+
+# b/35906875. Note mips already has getuid from SYSCALLS.TXT
+int inotify_init() arm,x86,mips
+uid_t getuid() arm,x86
diff --git a/libc/bionic/pthread_create.cpp b/libc/bionic/pthread_create.cpp
index f591c86..6b3e148 100644
--- a/libc/bionic/pthread_create.cpp
+++ b/libc/bionic/pthread_create.cpp
@@ -62,11 +62,13 @@
if (allocation == MAP_FAILED) {
__libc_fatal("failed to allocate TLS");
}
+ prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, allocation, allocation_size, "bionic TLS guard page");
thread->bionic_tls = reinterpret_cast<bionic_tls*>(static_cast<char*>(allocation) + PAGE_SIZE);
if (mprotect(thread->bionic_tls, BIONIC_TLS_SIZE, PROT_READ | PROT_WRITE) != 0) {
__libc_fatal("failed to mprotect TLS");
}
+ prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, thread->bionic_tls, BIONIC_TLS_SIZE, "bionic TLS");
}
void __init_thread_stack_guard(pthread_internal_t* thread) {
diff --git a/libc/bionic/pthread_exit.cpp b/libc/bionic/pthread_exit.cpp
index 3401ed7..9adf405 100644
--- a/libc/bionic/pthread_exit.cpp
+++ b/libc/bionic/pthread_exit.cpp
@@ -92,6 +92,10 @@
thread->alternate_signal_stack = NULL;
}
+ // Unmap the bionic TLS, including guard pages.
+ void* allocation = reinterpret_cast<char*>(thread->bionic_tls) - PAGE_SIZE;
+ munmap(allocation, BIONIC_TLS_SIZE + 2 * PAGE_SIZE);
+
ThreadJoinState old_state = THREAD_NOT_JOINED;
while (old_state == THREAD_NOT_JOINED &&
!atomic_compare_exchange_weak(&thread->join_state, &old_state, THREAD_EXITED_NOT_JOINED)) {
diff --git a/libc/bionic/pthread_internal.cpp b/libc/bionic/pthread_internal.cpp
index 2bc2bfb..5819bc1 100644
--- a/libc/bionic/pthread_internal.cpp
+++ b/libc/bionic/pthread_internal.cpp
@@ -86,10 +86,6 @@
}
static void __pthread_internal_free(pthread_internal_t* thread) {
- // Unmap the TLS, including guard pages.
- void* allocation = reinterpret_cast<char*>(thread->bionic_tls) - PAGE_SIZE;
- munmap(allocation, BIONIC_TLS_SIZE + 2 * PAGE_SIZE);
-
if (thread->mmap_size != 0) {
// Free mapped space, including thread stack and pthread_internal_t.
munmap(thread->attr.stack_base, thread->mmap_size);
diff --git a/libc/bionic/pthread_internal.h b/libc/bionic/pthread_internal.h
index b170299..6faf5a4 100644
--- a/libc/bionic/pthread_internal.h
+++ b/libc/bionic/pthread_internal.h
@@ -141,13 +141,11 @@
__LIBC_HIDDEN__ void pthread_key_clean_all(void);
-#if defined(__LP64__)
-// SIGSTKSZ is not big enough for 64-bit arch.
-// See https://code.google.com/p/android/issues/detail?id=187064.
+// SIGSTKSZ (8kB) is not big enough.
+// snprintf to a stack buffer of size PATH_MAX consumes ~7kB of stack.
+// Also, on 64-bit, logging uses more than 8kB by itself:
+// https://code.google.com/p/android/issues/detail?id=187064
#define SIGNAL_STACK_SIZE_WITHOUT_GUARD_PAGE (16 * 1024)
-#else
-#define SIGNAL_STACK_SIZE_WITHOUT_GUARD_PAGE SIGSTKSZ
-#endif
/*
* Traditionally we gave threads a 1MiB stack. When we started
diff --git a/libc/bionic/system_properties.cpp b/libc/bionic/system_properties.cpp
index ec1d18f..a4faf85 100644
--- a/libc/bionic/system_properties.cpp
+++ b/libc/bionic/system_properties.cpp
@@ -209,7 +209,6 @@
};
// This is public because it was exposed in the NDK. As of 2017-01, ~60 apps reference this symbol.
-// It's also used in a libnativehelper test.
prop_area* __system_property_area__ = nullptr;
static char property_filename[PROP_FILENAME_MAX] = PROP_FILENAME;
@@ -1059,15 +1058,23 @@
return true;
}
- // TODO: Change path to /system/property_contexts after b/27805372
- if (!initialize_properties_from_file("/plat_property_contexts")) {
- return false;
+ // Use property_contexts from /system & /vendor, fall back to those from /
+ if (access("/system/etc/selinux/plat_property_contexts", R_OK) != -1) {
+ if (!initialize_properties_from_file("/system/etc/selinux/plat_property_contexts")) {
+ return false;
+ }
+ if (!initialize_properties_from_file("/vendor/etc/selinux/nonplat_property_contexts")) {
+ return false;
+ }
+ } else {
+ if (!initialize_properties_from_file("/plat_property_contexts")) {
+ return false;
+ }
+ if (!initialize_properties_from_file("/nonplat_property_contexts")) {
+ return false;
+ }
}
- // TODO: Change path to /vendor/property_contexts after b/27805372
- // device-specific property context is optional, so load if it exists.
- initialize_properties_from_file("/nonplat_property_contexts");
-
return true;
}
diff --git a/libc/kernel/tools/clean_header.py b/libc/kernel/tools/clean_header.py
index 99f4c7f..f474f74 100755
--- a/libc/kernel/tools/clean_header.py
+++ b/libc/kernel/tools/clean_header.py
@@ -79,55 +79,33 @@
sys.stderr.write("warning: " + msg)
-def cleanupFile(dst_dir, src_dir, rel_path, no_update = True):
+def cleanupFile(dst_file, src_file, rel_path, no_update = True):
"""reads an original header and perform the cleanup operation on it
this functions returns the destination path and the clean header
as a single string"""
- # check the header path
- full_path = os.path.join(src_dir, rel_path)
-
- if not os.path.exists(full_path):
- print_error(no_update, "file does not exist: '%s'\n" % full_path)
+ # Check the header path
+ if not os.path.exists(src_file):
+ print_error(no_update, "'%s' does not exist\n" % src_file)
return None, None
- if not os.path.isfile(full_path):
- print_error(no_update, "path is not a file: '%s'\n" % full_path)
+ if not os.path.isfile(src_file):
+ print_error(no_update, "'%s' is not a file\n" % src_file)
return None, None
- # convert into destination path, extracting architecture if needed
- # and the corresponding list of known static functions
- #
+ # Extract the architecture if found.
arch = None
statics = kernel_known_generic_statics
- m = re.match(r"asm-([\w\d_\+\.\-]+)(/.*)", rel_path)
- if m and m.group(1) != 'generic':
- dst_path = "arch-%s/asm/%s" % m.groups()
- arch = m.group(1)
- statics = statics.union(kernel_known_statics.get(arch, set()))
- else:
- # process headers under the uapi directory
- # note the "asm" level has been explicitly added in the original
- # kernel header tree for architectural-dependent uapi headers
- m_uapi = re.match(r"(uapi)/([\w\d_\+\.\-]+)(/.*)", rel_path)
- if m_uapi:
- dst_path = rel_path
- m_uapi_arch = re.match(r"asm-([\w\d_\+\.\-]+)", m_uapi.group(2))
- if m_uapi_arch and m_uapi_arch.group(1) != 'generic':
- arch = m_uapi_arch.group(1)
- statics = statics.union(kernel_known_statics.get(arch, set()))
- # common headers (ie non-asm and non-uapi)
- else:
- dst_path = os.path.join("android", rel_path)
+ m = re.search(r"(^|/)asm-([\w\d_\+\.\-]+)/.*", rel_path)
+ if m and m.group(2) != 'generic':
+ arch = m.group(2)
+ statics = statics.union(kernel_known_statics.get(arch, set()))
- dst_path = os.path.join(dst_dir, dst_path)
-
- # now, let's parse the file
- #
+ # Now, let's parse the file.
parser = cpp.BlockParser()
- blocks = parser.parseFile(full_path)
+ blocks = parser.parseFile(src_file)
if not parser.parsed:
- print_error(no_update, "can't parse '%s'%" % full_path)
- return None, None
+ print_error(no_update, "Can't parse '%s'" % src_file)
+ return None
macros = kernel_known_macros.copy()
if arch and arch in kernel_default_arch_macros:
@@ -145,7 +123,7 @@
out = StringOutput()
out.write(kernel_disclaimer)
blocks.writeWithWarning(out, kernel_warning, 4)
- return dst_path, out.get()
+ return out.get()
if __name__ == "__main__":
@@ -194,22 +172,26 @@
if no_update:
for path in args:
- dst_path, newdata = cleanupFile(dst_dir, src_dir, path)
- print newdata
+ dst_file = os.path.join(dst_dir, path)
+ src_file = os.path.join(src_dir, path)
+ new_data = cleanupFile(dst_file, src_file, path)
+ print new_data
sys.exit(0)
- # now let's update our files.
+ # Now let's update our files.
b = BatchFileUpdater()
for path in args:
- dst_path, newdata = cleanupFile(dst_dir, src_dir, path, no_update)
- if not dst_path:
+ dst_file = os.path.join(dst_dir, path)
+ src_file = os.path.join(src_dir, path)
+ new_data = cleanupFile(dst_file, src_file, path, no_update)
+ if not new_data:
continue
- b.readFile(dst_path)
- r = b.editFile(dst_path, newdata)
+ b.readFile(path)
+ r = b.editFile(path, new_data)
if r == 0:
r = "unchanged"
elif r == 1:
@@ -217,7 +199,7 @@
else:
r = "added"
- print "cleaning: %-*s -> %-*s (%s)" % (35, path, 35, dst_path, r)
+ print "cleaning: %-*s -> %-*s (%s)" % (35, path, 35, path, r)
b.updateGitFiles()
diff --git a/libc/kernel/tools/update_all.py b/libc/kernel/tools/update_all.py
index 5031168..e5a07f8 100755
--- a/libc/kernel/tools/update_all.py
+++ b/libc/kernel/tools/update_all.py
@@ -24,105 +24,77 @@
""" % { "progname" : os.path.basename(sys.argv[0]) }
sys.exit(0)
+def processFiles(updater, original_dir, modified_dir, src_rel_dir, update_rel_dir):
+ # Delete the old headers before updating to the new headers.
+ update_dir = os.path.join(get_kernel_dir(), update_rel_dir)
+ shutil.rmtree(update_dir)
+ os.mkdir(update_dir, 0755)
+
+ src_dir = os.path.normpath(os.path.join(original_dir, src_rel_dir))
+ src_dir_len = len(src_dir) + 1
+ mod_src_dir = os.path.join(modified_dir, src_rel_dir)
+ update_dir = os.path.join(get_kernel_dir(), update_rel_dir)
+
+ kernel_dir = get_kernel_dir()
+ for root, _, files in os.walk(src_dir):
+ for file in sorted(files):
+ _, ext = os.path.splitext(file)
+ if ext != ".h":
+ continue
+ src_file = os.path.normpath(os.path.join(root, file))
+ rel_path = src_file[src_dir_len:]
+ # Check to see if there is a modified header to use instead.
+ if os.path.exists(os.path.join(mod_src_dir, rel_path)):
+ src_file = os.path.join(mod_src_dir, rel_path)
+ src_str = os.path.join("<modified>", src_rel_dir, rel_path)
+ else:
+ src_str = os.path.join("<original>", src_rel_dir, rel_path)
+ dst_file = os.path.join(update_dir, rel_path)
+ new_data = clean_header.cleanupFile(dst_file, src_file, rel_path)
+ if not new_data:
+ continue
+ updater.readFile(dst_file)
+ ret_val = updater.editFile(dst_file, new_data)
+ if ret_val == 0:
+ state = "unchanged"
+ elif ret_val == 1:
+ state = "edited"
+ else:
+ state = "added"
+ update_path = os.path.join(update_rel_dir, rel_path)
+ print "cleaning %s -> %s (%s)" % (src_str, update_path, state)
+
try:
optlist, args = getopt.getopt(sys.argv[1:], '')
except:
- # unrecognized option
+ # Unrecognized option
sys.stderr.write("error: unrecognized option\n")
usage()
if len(optlist) > 0 or len(args) > 2:
usage()
-modified_dir = get_kernel_headers_modified_dir()
-if len(args) == 1 or len(args) == 2:
+if len(args) > 0:
original_dir = args[0]
- if not os.path.isdir(original_dir):
- panic("Not a directory: %s\n" % original_dir)
-
- if len(args) == 2:
- modified_dir = args[1]
- if not os.path.isdir(modified_dir):
- panic("Not a directory: %s\n" % modified_dir)
else:
original_dir = get_kernel_headers_original_dir()
- if not os.path.isdir(original_dir):
- panic("Missing directory, please specify one through command-line: %s\n" % original_dir)
+
+if len(args) > 1:
+ modified_dir = args[1]
+else:
+ modified_dir = get_kernel_headers_modified_dir()
+
+if not os.path.isdir(original_dir):
+ panic("The kernel directory %s is not a directory\n" % original_dir)
if not os.path.isdir(modified_dir):
- modified_dir = None
+ panic("The kernel modified directory %s is not a directory\n" % modified_dir)
-# Find all source files in 'original'.
-sources = dict()
-original_dir = os.path.normpath(original_dir)
-original_dir_len = len(original_dir) + 1
-for root, _, files in os.walk(original_dir):
- for file in files:
- _, ext = os.path.splitext(file)
- if ext == ".h":
- rel_path = os.path.normpath(os.path.join(root, file))
- rel_path = rel_path[original_dir_len:]
- # Check to see if there is a modified header to use instead.
- if modified_dir and os.path.exists(os.path.join(modified_dir, rel_path)):
- sources[rel_path] = False
- else:
- sources[rel_path] = True
+updater = BatchFileUpdater()
+# Process the original uapi headers first.
+processFiles(updater, original_dir, modified_dir, "uapi", "uapi"),
+# Now process the special files.
+processFiles(updater, original_dir, modified_dir, "scsi", os.path.join("android", "scsi"))
-b = BatchFileUpdater()
-
-kernel_dir = get_kernel_dir()
-for arch in kernel_archs:
- b.readDir(os.path.join(kernel_dir, "arch-%s" % arch))
-
-b.readDir(os.path.join(kernel_dir, "android"))
-
-# Delete the old uapi headers before updating to handle headers that
-# get moved/deleted.
-uapi_dir = os.path.join(get_kernel_dir(), "uapi")
-shutil.rmtree(uapi_dir)
-os.mkdir(uapi_dir, 0755)
-
-oldlen = 120
-android_root_len = len(get_android_root()) + 1
-for rel_path in sorted(sources):
- if sources[rel_path]:
- src_dir = original_dir
- src_str = "<original>/"
- else:
- src_dir = modified_dir
- src_str = "<modified>/"
- dst_path, newdata = clean_header.cleanupFile(kernel_dir, src_dir, rel_path)
- if not dst_path:
- continue
-
- dst_path = os.path.join(kernel_dir, dst_path)
- b.readFile(dst_path)
- r = b.editFile(dst_path, newdata)
- if r == 0:
- state = "unchanged"
- elif r == 1:
- state = "edited"
- else:
- state = "added"
-
- # dst_path is guaranteed to include android root.
- rel_dst_path = dst_path[android_root_len:]
- str = "cleaning: %-*s -> %-*s (%s)" % (35, src_str + rel_path, 35, rel_dst_path, state)
- if sys.stdout.isatty():
- print "%-*s" % (oldlen, str),
- if (r == 0):
- print "\r",
- else:
- print "\n",
- oldlen = 0
- else:
- print str
-
- oldlen = len(str)
-
-print "%-*s" % (oldlen, "Done!")
-
-b.updateGitFiles()
-
-sys.exit(0)
+updater.updateGitFiles()
diff --git a/libc/kernel/tools/utils.py b/libc/kernel/tools/utils.py
index e2cc9ce..1b06b1b 100644
--- a/libc/kernel/tools/utils.py
+++ b/libc/kernel/tools/utils.py
@@ -31,8 +31,14 @@
def get_android_root():
if "ANDROID_BUILD_TOP" in os.environ:
+ # Verify that the current directory is in the root.
+ # If not, then print an error.
+ cwd = os.getcwd()
+ root = os.environ["ANDROID_BUILD_TOP"]
+ if len(cwd) < len(root) or not root == cwd[:len(root)]:
+ panic("Not in android tree pointed at by ANDROID_BUILD_TOP (%s)\n" % root)
return os.environ["ANDROID_BUILD_TOP"]
- panic("Unable to find root of tree, did you forget to lunch a target?")
+ panic("Unable to find root of tree, did you forget to lunch a target?\n")
class StringOutput:
diff --git a/libc/malloc_debug/README_api.md b/libc/malloc_debug/README_api.md
index 9d07cb3..b2c46d8 100644
--- a/libc/malloc_debug/README_api.md
+++ b/libc/malloc_debug/README_api.md
@@ -26,7 +26,7 @@
### Format of info Buffer
size_t size_of_original_allocation
- size_t num_backtrace_frames
+ size_t num_allocations
uintptr_t pc1
uintptr_t pc2
uintptr_t pc3
@@ -38,8 +38,12 @@
*backtrace\_size* as returned by the original call to
*get\_malloc\_leak\_info*. This value is not variable, it is the same
for all the returned data. The value
-*num\_backtrace\_frames* contains the real number of frames found. The
-extra frames are set to zero. Each *uintptr\_t* is a pc of the callstack.
+*num\_allocations* contains the total number of allocations with the same
+backtrace and size as this allocation. On Android Nougat, this value was
+incorrectly set to the number of frames in the backtrace.
+Each *uintptr\_t* is a pc of the callstack. If the total number
+of backtrace entries is less than *backtrace\_size*, the rest of the
+entries are zero.
The calls from within the malloc debug library are automatically removed.
For 32 bit systems, *size\_t* and *uintptr\_t* are both 4 byte values.
diff --git a/libc/malloc_debug/TrackData.cpp b/libc/malloc_debug/TrackData.cpp
index 18f428b..d4064f8 100644
--- a/libc/malloc_debug/TrackData.cpp
+++ b/libc/malloc_debug/TrackData.cpp
@@ -123,11 +123,12 @@
GetList(&list);
uint8_t* data = *info;
+ size_t num_allocations = 1;
for (const auto& header : list) {
BacktraceHeader* back_header = debug_->GetAllocBacktrace(header);
if (back_header->num_frames > 0) {
memcpy(data, &header->size, sizeof(size_t));
- memcpy(&data[sizeof(size_t)], &back_header->num_frames, sizeof(size_t));
+ memcpy(&data[sizeof(size_t)], &num_allocations, sizeof(size_t));
memcpy(&data[2 * sizeof(size_t)], &back_header->frames[0],
back_header->num_frames * sizeof(uintptr_t));
diff --git a/libc/malloc_debug/tests/malloc_debug_unit_tests.cpp b/libc/malloc_debug/tests/malloc_debug_unit_tests.cpp
index 1b08a39..219c21e 100644
--- a/libc/malloc_debug/tests/malloc_debug_unit_tests.cpp
+++ b/libc/malloc_debug/tests/malloc_debug_unit_tests.cpp
@@ -999,7 +999,7 @@
struct InfoEntry {
size_t size;
- size_t num_frames;
+ size_t num_allocations;
uintptr_t frames[0];
} __attribute__((packed));
@@ -1033,7 +1033,7 @@
InfoEntry* entry = reinterpret_cast<InfoEntry*>(expected_info.data());
entry->size = 200;
- entry->num_frames = 3;
+ entry->num_allocations = 1;
entry->frames[0] = 0xf;
entry->frames[1] = 0xe;
entry->frames[2] = 0xd;
@@ -1082,7 +1082,7 @@
// These values will be in the reverse order that we create.
entry2->size = 500;
- entry2->num_frames = 4;
+ entry2->num_allocations = 1;
entry2->frames[0] = 0xf;
entry2->frames[1] = 0xe;
entry2->frames[2] = 0xd;
@@ -1097,7 +1097,7 @@
memset(pointers[0], 0, entry2->size);
entry1->size = 4100;
- entry1->num_frames = 16;
+ entry1->num_allocations = 1;
for (size_t i = 0; i < 16; i++) {
entry1->frames[i] = 0xbc000 + i;
}
@@ -1112,7 +1112,7 @@
memset(pointers[1], 0, entry1->size);
entry0->size = 9000;
- entry0->num_frames = 1;
+ entry0->num_allocations = 1;
entry0->frames[0] = 0x104;
backtrace_fake_add(std::vector<uintptr_t> {0x104});
@@ -1159,7 +1159,7 @@
// These values will be in the reverse order that we create.
entry1->size = 500;
- entry1->num_frames = 4;
+ entry1->num_allocations = 1;
entry1->frames[0] = 0xf;
entry1->frames[1] = 0xe;
entry1->frames[2] = 0xd;
@@ -1174,7 +1174,7 @@
memset(pointers[0], 0, entry1->size);
entry0->size = 4100;
- entry0->num_frames = 16;
+ entry0->num_allocations = 1;
for (size_t i = 0; i < 16; i++) {
entry0->frames[i] = 0xbc000 + i;
}
@@ -1373,7 +1373,7 @@
memset(expected_info.data(), 0, expected_info_size);
InfoEntry* entry = reinterpret_cast<InfoEntry*>(expected_info.data());
entry->size = memory_bytes | (1U << 31);
- entry->num_frames = 1;
+ entry->num_allocations = 1;
entry->frames[0] = 0x1;
uint8_t* info;
diff --git a/libc/seccomp/Android.bp b/libc/seccomp/Android.bp
new file mode 100644
index 0000000..c341781
--- /dev/null
+++ b/libc/seccomp/Android.bp
@@ -0,0 +1,19 @@
+cc_library {
+ name: "libseccomp_policy",
+ srcs: [
+ "seccomp_policy.cpp",
+ "arm_policy.cpp",
+ "arm64_policy.cpp",
+ "x86_policy.cpp",
+ "x86_64_policy.cpp",
+ "mips_policy.cpp",
+ "mips64_policy.cpp",
+ ],
+ export_include_dirs: ["include"],
+ shared: {
+ shared_libs: ["libbase"],
+ },
+ static: {
+ static_libs: ["libbase"],
+ },
+}
diff --git a/libc/seccomp/Android.mk b/libc/seccomp/Android.mk
deleted file mode 100644
index af1311c..0000000
--- a/libc/seccomp/Android.mk
+++ /dev/null
@@ -1,12 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-LOCAL_MODULE := libseccomp_policy
-LOCAL_CLANG := true
-LOCAL_SRC_FILES := arm_policy.c arm64_policy.c
-LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
-
-include $(BUILD_STATIC_LIBRARY)
-
diff --git a/libc/seccomp/arm64_policy.c b/libc/seccomp/arm64_policy.cpp
similarity index 97%
rename from libc/seccomp/arm64_policy.c
rename to libc/seccomp/arm64_policy.cpp
index fc7127f..0bf85a3 100644
--- a/libc/seccomp/arm64_policy.c
+++ b/libc/seccomp/arm64_policy.cpp
@@ -3,8 +3,8 @@
#include <linux/filter.h>
#include <errno.h>
-#include "seccomp_policy.h"
-const struct sock_filter arm64_filter[] = {
+#include "seccomp_bpfs.h"
+const sock_filter arm64_filter[] = {
BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5, 0, 25),
BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 203, 13, 0),
BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 101, 7, 0),
diff --git a/libc/seccomp/arm_policy.c b/libc/seccomp/arm_policy.c
deleted file mode 100644
index f175d6a..0000000
--- a/libc/seccomp/arm_policy.c
+++ /dev/null
@@ -1,137 +0,0 @@
-// Autogenerated file - edit at your peril!!
-
-#include <linux/filter.h>
-#include <errno.h>
-
-#include "seccomp_policy.h"
-const struct sock_filter arm_filter[] = {
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 0, 0, 125),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 168, 63, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 77, 31, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 45, 15, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 26, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 10, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 8, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 7, 119, 118), //restart_syscall|exit|fork|read|write|open|close
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 9, 118, 117), //creat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 19, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 13, 116, 115), //unlink|execve|chdir
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 22, 115, 114), //lseek|getpid|mount
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 36, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 33, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 27, 112, 111), //ptrace
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 34, 111, 110), //access
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 41, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 38, 109, 108), //sync|kill
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 44, 108, 107), //dup|pipe|times
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 60, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 54, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 51, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 46, 104, 103), //brk
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 53, 103, 102), //acct|umount2
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 57, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 56, 101, 100), //ioctl|fcntl
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 58, 100, 99), //setpgid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 66, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 64, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 62, 97, 96), //umask|chroot
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 65, 96, 95), //getppid
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 74, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 68, 94, 93), //setsid|sigaction
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 76, 93, 92), //sethostname|setrlimit
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 118, 15, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 94, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 87, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 85, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 80, 88, 87), //getrusage|gettimeofday|settimeofday
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 86, 87, 86), //readlink
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 91, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 89, 85, 84), //swapon|reboot
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 93, 84, 83), //munmap|truncate
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 103, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 96, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 95, 81, 80), //fchmod
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 98, 80, 79), //getpriority|setpriority
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 114, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 106, 78, 77), //syslog|setitimer|getitimer
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 117, 77, 76), //wait4|swapoff|sysinfo
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 136, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 128, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 124, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 123, 73, 72), //fsync|sigreturn|clone|setdomainname|uname
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 126, 72, 71), //adjtimex|mprotect
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 131, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 130, 70, 69), //init_module|delete_module
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 134, 69, 68), //quotactl|getpgid|fchdir
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 143, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 138, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 137, 66, 65), //personality
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 142, 65, 64), //setfsuid|setfsgid|_llseek|getdents
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 150, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 149, 63, 62), //flock|msync|readv|writev|getsid|fdatasync
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 164, 62, 61), //mlock|munlock|mlockall|munlockall|sched_setparam|sched_getparam|sched_setscheduler|sched_getscheduler|sched_yield|sched_get_priority_max|sched_get_priority_min|sched_rr_get_interval|nanosleep|mremap
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 290, 31, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 219, 15, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 199, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 183, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 172, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 169, 56, 55), //poll
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 182, 55, 54), //prctl|rt_sigreturn|rt_sigaction|rt_sigprocmask|rt_sigpending|rt_sigtimedwait|rt_sigqueueinfo|rt_sigsuspend|pread64|pwrite64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 190, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 188, 53, 52), //getcwd|capget|capset|sigaltstack|sendfile
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 198, 52, 51), //vfork|ugetrlimit|mmap2|truncate64|ftruncate64|stat64|lstat64|fstat64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 217, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 213, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 212, 49, 48), //getuid32|getgid32|geteuid32|getegid32|setreuid32|setregid32|getgroups32|setgroups32|fchown32|setresuid32|getresuid32|setresgid32|getresgid32
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 215, 48, 47), //setuid32|setgid32
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 217, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 218, 46, 45), //getdents64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 218, 45, 44), //getdents64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 256, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 248, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 224, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 222, 41, 40), //mincore|madvise|fcntl64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 243, 40, 39), //gettid|readahead|setxattr|lsetxattr|fsetxattr|getxattr|lgetxattr|fgetxattr|listxattr|llistxattr|flistxattr|removexattr|lremovexattr|fremovexattr|tkill|sendfile64|futex|sched_setaffinity|sched_getaffinity
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 250, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 249, 38, 37), //exit_group
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 253, 37, 36), //epoll_create|epoll_ctl|epoll_wait
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 280, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 270, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 269, 34, 33), //set_tid_address|timer_create|timer_settime|timer_gettime|timer_getoverrun|timer_delete|clock_settime|clock_gettime|clock_getres|clock_nanosleep|statfs64|fstatfs64|tgkill
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 271, 33, 32), //arm_fadvise64_64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 286, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 285, 31, 30), //waitid|socket|bind|connect|listen
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 289, 30, 29), //getsockname|getpeername|socketpair
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 350, 15, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 327, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 317, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 292, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 291, 25, 24), //sendto
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 298, 24, 23), //recvfrom|shutdown|setsockopt|getsockopt|sendmsg|recvmsg
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 322, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 319, 22, 21), //inotify_add_watch|inotify_rm_watch
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 326, 21, 20), //openat|mkdirat|mknodat|fchownat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 345, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 340, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 338, 18, 17), //fstatat64|unlinkat|renameat|linkat|symlinkat|readlinkat|fchmodat|faccessat|pselect6|ppoll|unshare
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 344, 17, 16), //splice|sync_file_range2|tee|vmsplice
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 348, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 347, 15, 14), //getcpu|epoll_pwait
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 349, 14, 13), //utimensat
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 383, 7, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 372, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 369, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 367, 10, 9), //timerfd_create|eventfd|fallocate|timerfd_settime|timerfd_gettime|signalfd4|eventfd2|epoll_create1|dup3|pipe2|inotify_init1|preadv|pwritev|rt_tgsigqueueinfo|perf_event_open|recvmmsg|accept4
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 370, 9, 8), //prlimit64
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 374, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 373, 7, 6), //clock_adjtime
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 378, 6, 5), //sendmmsg|setns|process_vm_readv|process_vm_writev
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 983045, 3, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 983042, 1, 0),
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 385, 3, 2), //seccomp|getrandom
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 983043, 2, 1), //__ARM_NR_cacheflush
-BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 983046, 1, 0), //__ARM_NR_set_tls
-BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW),
-};
-
-const size_t arm_filter_size = sizeof(arm_filter) / sizeof(struct sock_filter);
diff --git a/libc/seccomp/arm_policy.cpp b/libc/seccomp/arm_policy.cpp
new file mode 100644
index 0000000..fd7d48b
--- /dev/null
+++ b/libc/seccomp/arm_policy.cpp
@@ -0,0 +1,135 @@
+// Autogenerated file - edit at your peril!!
+
+#include <linux/filter.h>
+#include <errno.h>
+
+#include "seccomp_bpfs.h"
+const sock_filter arm_filter[] = {
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 0, 0, 123),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 143, 61, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 74, 31, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 41, 15, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 24, 7, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 10, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 8, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 7, 117, 116), //restart_syscall|exit|fork|read|write|open|close
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 9, 116, 115), //creat
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 19, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 13, 114, 113), //unlink|execve|chdir
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 22, 113, 112), //lseek|getpid|mount
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 33, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 26, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 25, 110, 109), //getuid
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 27, 109, 108), //ptrace
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 36, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 34, 107, 106), //access
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 38, 106, 105), //sync|kill
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 57, 7, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 51, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 45, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 44, 102, 101), //dup|pipe|times
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 46, 101, 100), //brk
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 54, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 53, 99, 98), //acct|umount2
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 56, 98, 97), //ioctl|fcntl
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 64, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 60, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 58, 95, 94), //setpgid
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 62, 94, 93), //umask|chroot
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 66, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 65, 92, 91), //getppid
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 68, 91, 90), //setsid|sigaction
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 114, 15, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 91, 7, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 85, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 77, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 76, 86, 85), //sethostname|setrlimit
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 80, 85, 84), //getrusage|gettimeofday|settimeofday
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 87, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 86, 83, 82), //readlink
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 89, 82, 81), //swapon|reboot
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 96, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 94, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 93, 79, 78), //munmap|truncate
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 95, 78, 77), //fchmod
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 103, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 98, 76, 75), //getpriority|setpriority
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 106, 75, 74), //syslog|setitimer|getitimer
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 131, 7, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 124, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 118, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 117, 71, 70), //wait4|swapoff|sysinfo
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 123, 70, 69), //fsync|sigreturn|clone|setdomainname|uname
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 128, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 126, 68, 67), //adjtimex|mprotect
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 130, 67, 66), //init_module|delete_module
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 138, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 136, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 134, 64, 63), //quotactl|getpgid|fchdir
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 137, 63, 62), //personality
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 142, 62, 61), //setfsuid|setfsgid|_llseek|getdents
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 286, 31, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 217, 15, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 183, 7, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 168, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 150, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 149, 56, 55), //flock|msync|readv|writev|getsid|fdatasync
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 164, 55, 54), //mlock|munlock|mlockall|munlockall|sched_setparam|sched_getparam|sched_setscheduler|sched_getscheduler|sched_yield|sched_get_priority_max|sched_get_priority_min|sched_rr_get_interval|nanosleep|mremap
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 172, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 169, 53, 52), //poll
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 182, 52, 51), //prctl|rt_sigreturn|rt_sigaction|rt_sigprocmask|rt_sigpending|rt_sigtimedwait|rt_sigqueueinfo|rt_sigsuspend|pread64|pwrite64
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 199, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 190, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 188, 49, 48), //getcwd|capget|capset|sigaltstack|sendfile
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 198, 48, 47), //vfork|ugetrlimit|mmap2|truncate64|ftruncate64|stat64|lstat64|fstat64
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 213, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 212, 46, 45), //getuid32|getgid32|geteuid32|getegid32|setreuid32|setregid32|getgroups32|setgroups32|fchown32|setresuid32|getresuid32|setresgid32|getresgid32
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 215, 45, 44), //setuid32|setgid32
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 250, 7, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 224, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 219, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 218, 41, 40), //getdents64
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 222, 40, 39), //mincore|madvise|fcntl64
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 248, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 243, 38, 37), //gettid|readahead|setxattr|lsetxattr|fsetxattr|getxattr|lgetxattr|fgetxattr|listxattr|llistxattr|flistxattr|removexattr|lremovexattr|fremovexattr|tkill|sendfile64|futex|sched_setaffinity|sched_getaffinity
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 249, 37, 36), //exit_group
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 270, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 256, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 253, 34, 33), //epoll_create|epoll_ctl|epoll_wait
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 269, 33, 32), //set_tid_address|timer_create|timer_settime|timer_gettime|timer_getoverrun|timer_delete|clock_settime|clock_gettime|clock_getres|clock_nanosleep|statfs64|fstatfs64|tgkill
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 280, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 271, 31, 30), //arm_fadvise64_64
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 285, 30, 29), //waitid|socket|bind|connect|listen
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 348, 15, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 322, 7, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 292, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 290, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 289, 25, 24), //getsockname|getpeername|socketpair
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 291, 24, 23), //sendto
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 316, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 298, 22, 21), //recvfrom|shutdown|setsockopt|getsockopt|sendmsg|recvmsg
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 319, 21, 20), //inotify_init|inotify_add_watch|inotify_rm_watch
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 340, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 327, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 326, 18, 17), //openat|mkdirat|mknodat|fchownat
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 338, 17, 16), //fstatat64|unlinkat|renameat|linkat|symlinkat|readlinkat|fchmodat|faccessat|pselect6|ppoll|unshare
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 345, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 344, 15, 14), //splice|sync_file_range2|tee|vmsplice
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 347, 14, 13), //getcpu|epoll_pwait
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 383, 7, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 369, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 350, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 349, 10, 9), //utimensat
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 367, 9, 8), //timerfd_create|eventfd|fallocate|timerfd_settime|timerfd_gettime|signalfd4|eventfd2|epoll_create1|dup3|pipe2|inotify_init1|preadv|pwritev|rt_tgsigqueueinfo|perf_event_open|recvmmsg|accept4
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 372, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 370, 7, 6), //prlimit64
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 378, 6, 5), //clock_adjtime|syncfs|sendmmsg|setns|process_vm_readv|process_vm_writev
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 983045, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 983042, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 385, 3, 2), //seccomp|getrandom
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 983043, 2, 1), //__ARM_NR_cacheflush
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 983046, 1, 0), //__ARM_NR_set_tls
+BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW),
+};
+
+const size_t arm_filter_size = sizeof(arm_filter) / sizeof(struct sock_filter);
diff --git a/libc/seccomp/seccomp_policy.h b/libc/seccomp/include/seccomp_policy.h
similarity index 75%
rename from libc/seccomp/seccomp_policy.h
rename to libc/seccomp/include/seccomp_policy.h
index e0282bd..33b5d0e 100644
--- a/libc/seccomp/seccomp_policy.h
+++ b/libc/seccomp/include/seccomp_policy.h
@@ -17,12 +17,6 @@
#ifndef SECCOMP_POLICY_H
#define SECCOMP_POLICY_H
-#include <stddef.h>
-#include <linux/seccomp.h>
-
-extern const struct sock_filter arm_filter[];
-extern const size_t arm_filter_size;
-extern const struct sock_filter arm64_filter[];
-extern const size_t arm64_filter_size;
+bool set_seccomp_filter();
#endif
diff --git a/libc/seccomp/mips64_policy.cpp b/libc/seccomp/mips64_policy.cpp
new file mode 100644
index 0000000..9439922
--- /dev/null
+++ b/libc/seccomp/mips64_policy.cpp
@@ -0,0 +1,89 @@
+// Autogenerated file - edit at your peril!!
+
+#include <linux/filter.h>
+#include <errno.h>
+
+#include "seccomp_bpfs.h"
+const sock_filter mips64_filter[] = {
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5000, 0, 77),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5168, 39, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5077, 19, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5034, 9, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5023, 5, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5008, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5003, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5002, 71, 70), //read|write
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5004, 70, 69), //close
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5020, 69, 68), //lseek|mmap|mprotect|munmap|brk|rt_sigaction|rt_sigprocmask|ioctl|pread64|pwrite64|readv|writev
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5031, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5028, 67, 66), //sched_yield|mremap|msync|mincore|madvise
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5032, 66, 65), //dup
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5057, 5, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5043, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5038, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5037, 62, 61), //nanosleep|getitimer|setitimer
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5042, 61, 60), //getpid|sendfile|socket|connect
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5056, 60, 59), //sendto|recvfrom|sendmsg|recvmsg|shutdown|bind|listen|getsockname|getpeername|socketpair|setsockopt|getsockopt|clone
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5070, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5062, 58, 57), //execve|exit|wait4|kill|uname
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5076, 57, 56), //fcntl|flock|fsync|fdatasync|truncate|ftruncate
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5132, 9, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5093, 5, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5091, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5089, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5080, 52, 51), //getcwd|chdir|fchdir
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5090, 51, 50), //fchmod
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5092, 50, 49), //fchown
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5110, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5109, 48, 47), //umask|gettimeofday|getrlimit|getrusage|sysinfo|times|ptrace|getuid|syslog|getgid|setuid|setgid|geteuid|getegid|setpgid|getppid
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5130, 47, 46), //setsid|setreuid|setregid|getgroups|setgroups|setresuid|getresuid|setresgid|getresgid|getpgid|setfsuid|setfsgid|getsid|capget|capset|rt_sigpending|rt_sigtimedwait|rt_sigqueueinfo|rt_sigsuspend|sigaltstack
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5151, 5, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5137, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5134, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5133, 43, 42), //personality
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5136, 42, 41), //statfs|fstatfs
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5150, 41, 40), //getpriority|setpriority|sched_setparam|sched_getparam|sched_setscheduler|sched_getscheduler|sched_get_priority_max|sched_get_priority_min|sched_rr_get_interval|mlock|munlock|mlockall|munlockall
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5153, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5152, 39, 38), //pivot_root
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5167, 38, 37), //prctl|adjtimex|setrlimit|chroot|sync|acct|settimeofday|mount|umount2|swapon|swapoff|reboot|sethostname|setdomainname
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5244, 19, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5208, 9, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5194, 5, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5178, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5172, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5170, 32, 31), //init_module|delete_module
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5173, 31, 30), //quotactl
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5193, 30, 29), //gettid|readahead|setxattr|lsetxattr|fsetxattr|getxattr|lgetxattr|fgetxattr|listxattr|llistxattr|flistxattr|removexattr|lremovexattr|fremovexattr|tkill
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5205, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5197, 28, 27), //futex|sched_setaffinity|sched_getaffinity
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5206, 27, 26), //exit_group
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5237, 5, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5215, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5211, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5209, 23, 22), //epoll_ctl
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5214, 22, 21), //rt_sigreturn|set_tid_address|restart_syscall
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5226, 21, 20), //fadvise64|timer_create|timer_settime|timer_gettime|timer_getoverrun|timer_delete|clock_settime|clock_gettime|clock_getres|clock_nanosleep|tgkill
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5242, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5238, 19, 18), //waitid
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5243, 18, 17), //set_thread_area
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5297, 9, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5271, 5, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5253, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5247, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5246, 13, 12), //inotify_add_watch|inotify_rm_watch
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5251, 12, 11), //openat|mkdirat|mknodat|fchownat
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5267, 11, 10), //unlinkat|renameat|linkat|symlinkat|readlinkat|fchmodat|faccessat|pselect6|ppoll|unshare|splice|sync_file_range|tee|vmsplice
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5279, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5276, 9, 8), //getcpu|epoll_pwait|ioprio_set|ioprio_get|utimensat
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5295, 8, 7), //fallocate|timerfd_create|timerfd_gettime|timerfd_settime|signalfd4|eventfd2|epoll_create1|dup3|pipe2|inotify_init1|preadv|pwritev|rt_tgsigqueueinfo|perf_event_open|accept4|recvmmsg
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5308, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5300, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5298, 5, 4), //prlimit64
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5306, 4, 3), //clock_adjtime|syncfs|sendmmsg|setns|process_vm_readv|process_vm_writev
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5312, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5309, 2, 1), //getdents64
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5314, 1, 0), //seccomp|getrandom
+BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW),
+};
+
+const size_t mips64_filter_size = sizeof(mips64_filter) / sizeof(struct sock_filter);
diff --git a/libc/seccomp/mips_policy.cpp b/libc/seccomp/mips_policy.cpp
new file mode 100644
index 0000000..d2c7515
--- /dev/null
+++ b/libc/seccomp/mips_policy.cpp
@@ -0,0 +1,121 @@
+// Autogenerated file - edit at your peril!!
+
+#include <linux/filter.h>
+#include <errno.h>
+
+#include "seccomp_bpfs.h"
+const sock_filter mips_filter[] = {
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4001, 0, 109),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4136, 55, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4064, 27, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4036, 13, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4023, 7, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4010, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4008, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4007, 103, 102), //exit|fork|read|write|open|close
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4009, 102, 101), //creat
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4019, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4013, 100, 99), //unlink|execve|chdir
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4022, 99, 98), //lseek|getpid|mount
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4033, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4026, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4025, 96, 95), //setuid|getuid
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4027, 95, 94), //ptrace
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4034, 94, 93), //access
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4054, 7, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4045, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4041, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4038, 90, 89), //sync|kill
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4044, 89, 88), //dup|pipe|times
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4049, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4048, 87, 86), //brk|setgid|getgid
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4053, 86, 85), //geteuid|getegid|acct|umount2
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4060, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4057, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4056, 83, 82), //ioctl|fcntl
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4058, 82, 81), //setpgid
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4062, 81, 80), //umask|chroot
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4094, 13, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4085, 7, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4070, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4066, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4065, 76, 75), //getppid
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4068, 75, 74), //setsid|sigaction
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4074, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4072, 73, 72), //setreuid|setregid
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4082, 72, 71), //sethostname|setrlimit|getrlimit|getrusage|gettimeofday|settimeofday|getgroups|setgroups
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4091, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4087, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4086, 69, 68), //readlink
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4089, 68, 67), //swapon|reboot
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4093, 67, 66), //munmap|truncate
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4124, 7, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4114, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4103, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4098, 63, 62), //fchmod|fchown|getpriority|setpriority
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4106, 62, 61), //syslog|setitimer|getitimer
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4118, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4117, 60, 59), //wait4|swapoff|sysinfo
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4123, 59, 58), //fsync|sigreturn|clone|setdomainname|uname
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4131, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4128, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4126, 56, 55), //adjtimex|mprotect
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4130, 55, 54), //init_module|delete_module
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4134, 54, 53), //quotactl|getpgid|fchdir
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4246, 27, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4179, 13, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4154, 7, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4143, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4138, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4137, 48, 47), //personality
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4142, 47, 46), //setfsuid|setfsgid|_llseek|getdents
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4151, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4148, 45, 44), //flock|msync|readv|writev|cacheflush
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4153, 44, 43), //getsid|fdatasync
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4176, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4169, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4168, 41, 40), //mlock|munlock|mlockall|munlockall|sched_setparam|sched_getparam|sched_setscheduler|sched_getscheduler|sched_yield|sched_get_priority_max|sched_get_priority_min|sched_rr_get_interval|nanosleep|mremap
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4175, 40, 39), //bind|connect|getpeername|getsockname|getsockopt|listen
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4178, 39, 38), //recvfrom|recvmsg
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4210, 7, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4190, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4188, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4187, 35, 34), //sendmsg|sendto|setsockopt|shutdown|socket|socketpair|setresuid|getresuid
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4189, 34, 33), //poll
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4203, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4202, 32, 31), //setresgid|getresgid|prctl|rt_sigreturn|rt_sigaction|rt_sigprocmask|rt_sigpending|rt_sigtimedwait|rt_sigqueueinfo|rt_sigsuspend|pread64|pwrite64
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4208, 31, 30), //getcwd|capget|capset|sigaltstack|sendfile
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4222, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4217, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4216, 28, 27), //mmap2|truncate64|ftruncate64|stat64|lstat64|fstat64
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4221, 27, 26), //mincore|madvise|getdents64|fcntl64
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4241, 26, 25), //gettid|readahead|setxattr|lsetxattr|fsetxattr|getxattr|lgetxattr|fgetxattr|listxattr|llistxattr|flistxattr|removexattr|lremovexattr|fremovexattr|tkill|sendfile64|futex|sched_setaffinity|sched_getaffinity
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4312, 13, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4283, 7, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4252, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4248, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4247, 21, 20), //exit_group
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4251, 20, 19), //epoll_create|epoll_ctl|epoll_wait
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4278, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4267, 18, 17), //set_tid_address|restart_syscall|fadvise64|statfs64|fstatfs64|timer_create|timer_settime|timer_gettime|timer_getoverrun|timer_delete|clock_settime|clock_gettime|clock_getres|clock_nanosleep|tgkill
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4279, 17, 16), //waitid
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4293, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4288, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4287, 14, 13), //set_thread_area|inotify_init|inotify_add_watch|inotify_rm_watch
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4292, 13, 12), //openat|mkdirat|mknodat|fchownat
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4308, 12, 11), //fstatat64|unlinkat|renameat|linkat|symlinkat|readlinkat|fchmodat|faccessat|pselect6|ppoll|unshare|splice|sync_file_range|tee|vmsplice
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4338, 5, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4319, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4316, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4314, 8, 7), //getcpu|epoll_pwait
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4317, 7, 6), //utimensat
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4336, 6, 5), //eventfd|fallocate|timerfd_create|timerfd_gettime|timerfd_settime|signalfd4|eventfd2|epoll_create1|dup3|pipe2|inotify_init1|preadv|pwritev|rt_tgsigqueueinfo|perf_event_open|accept4|recvmmsg
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4352, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4341, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4339, 3, 2), //prlimit64
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4347, 2, 1), //clock_adjtime|syncfs|sendmmsg|setns|process_vm_readv|process_vm_writev
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4354, 1, 0), //seccomp|getrandom
+BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW),
+};
+
+const size_t mips_filter_size = sizeof(mips_filter) / sizeof(struct sock_filter);
diff --git a/libc/seccomp/seccomp_policy.h b/libc/seccomp/seccomp_bpfs.h
similarity index 63%
copy from libc/seccomp/seccomp_policy.h
copy to libc/seccomp/seccomp_bpfs.h
index e0282bd..96e127e 100644
--- a/libc/seccomp/seccomp_policy.h
+++ b/libc/seccomp/seccomp_bpfs.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 The Android Open Source Project
+ * Copyright (C) 2017 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.
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-#ifndef SECCOMP_POLICY_H
-#define SECCOMP_POLICY_H
+#ifndef SECCOMP_BPFS_H
+#define SECCOMP_BPFS_H
#include <stddef.h>
#include <linux/seccomp.h>
@@ -24,5 +24,13 @@
extern const size_t arm_filter_size;
extern const struct sock_filter arm64_filter[];
extern const size_t arm64_filter_size;
+extern const struct sock_filter x86_filter[];
+extern const size_t x86_filter_size;
+extern const struct sock_filter x86_64_filter[];
+extern const size_t x86_64_filter_size;
+extern const struct sock_filter mips_filter[];
+extern const size_t mips_filter_size;
+extern const struct sock_filter mips64_filter[];
+extern const size_t mips64_filter_size;
#endif
diff --git a/libc/seccomp/seccomp_policy.cpp b/libc/seccomp/seccomp_policy.cpp
new file mode 100644
index 0000000..d93ae1e
--- /dev/null
+++ b/libc/seccomp/seccomp_policy.cpp
@@ -0,0 +1,156 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "seccomp_policy.h"
+
+#include <assert.h>
+#include <linux/audit.h>
+#include <linux/filter.h>
+#include <linux/seccomp.h>
+#include <sys/prctl.h>
+
+#include <vector>
+
+#include <android-base/logging.h>
+
+#include "seccomp_bpfs.h"
+
+
+#if defined __arm__ || defined __aarch64__
+
+#define DUAL_ARCH
+#define PRIMARY_ARCH AUDIT_ARCH_AARCH64
+static const struct sock_filter* primary_filter = arm64_filter;
+static const size_t primary_filter_size = arm64_filter_size;
+#define SECONDARY_ARCH AUDIT_ARCH_ARM
+static const struct sock_filter* secondary_filter = arm_filter;
+static const size_t secondary_filter_size = arm_filter_size;
+
+#elif defined __i386__ || defined __x86_64__
+
+#define DUAL_ARCH
+#define PRIMARY_ARCH AUDIT_ARCH_X86_64
+static const struct sock_filter* primary_filter = x86_64_filter;
+static const size_t primary_filter_size = x86_64_filter_size;
+#define SECONDARY_ARCH AUDIT_ARCH_I386
+static const struct sock_filter* secondary_filter = x86_filter;
+static const size_t secondary_filter_size = x86_filter_size;
+
+#elif defined __mips__ || defined __mips64__
+
+#define DUAL_ARCH
+#define PRIMARY_ARCH AUDIT_ARCH_MIPS64
+static const struct sock_filter* primary_filter = mips64_filter;
+static const size_t primary_filter_size = mips64_filter_size;
+#define SECONDARY_ARCH AUDIT_ARCH_MIPS
+static const struct sock_filter* secondary_filter = mips_filter;
+static const size_t secondary_filter_size = mips_filter_size;
+
+#else
+#error No architecture was defined!
+#endif
+
+
+#define syscall_nr (offsetof(struct seccomp_data, nr))
+#define arch_nr (offsetof(struct seccomp_data, arch))
+
+typedef std::vector<sock_filter> filter;
+
+inline void Disallow(filter& f) {
+ f.push_back(BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_TRAP));
+}
+
+static void ExamineSyscall(filter& f) {
+ f.push_back(BPF_STMT(BPF_LD|BPF_W|BPF_ABS, syscall_nr));
+}
+
+#ifdef DUAL_ARCH
+static bool SetValidateArchitectureJumpTarget(size_t offset, filter& f) {
+ size_t jump_length = f.size() - offset - 1;
+ auto u8_jump_length = (__u8) jump_length;
+ if (u8_jump_length != jump_length) {
+ LOG(FATAL)
+ << "Can't set jump greater than 255 - actual jump is " << jump_length;
+ return false;
+ }
+ f[offset] = BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, SECONDARY_ARCH, u8_jump_length, 0);
+ return true;
+}
+
+static size_t ValidateArchitectureAndJumpIfNeeded(filter& f) {
+ f.push_back(BPF_STMT(BPF_LD|BPF_W|BPF_ABS, arch_nr));
+ f.push_back(BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, PRIMARY_ARCH, 2, 0));
+ f.push_back(BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, SECONDARY_ARCH, 1, 0));
+ Disallow(f);
+ return f.size() - 2;
+}
+#else
+static void ValidateArchitecture(filter& f) {
+ f.push_back(BPF_STMT(BPF_LD|BPF_W|BPF_ABS, arch_nr));
+ f.push_back(BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, PRIMARY_ARCH, 1, 0));
+ Disallow(f);
+}
+#endif
+
+static bool install_filter(filter const& f) {
+ struct sock_fprog prog = {
+ static_cast<unsigned short>(f.size()),
+ const_cast<struct sock_filter*>(&f[0]),
+ };
+
+ if (prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog) < 0) {
+ PLOG(FATAL) << "Could not set seccomp filter of size " << f.size();
+ return false;
+ }
+
+ LOG(INFO) << "Global filter of size " << f.size() << " installed";
+ return true;
+}
+
+bool set_seccomp_filter() {
+ filter f;
+
+#ifdef DUAL_ARCH
+ // Note that for mixed 64/32 bit architectures, ValidateArchitecture inserts a
+ // jump that must be changed to point to the start of the 32-bit policy
+ // 32 bit syscalls will not hit the policy between here and the call to SetJump
+ auto offset_to_secondary_filter = ValidateArchitectureAndJumpIfNeeded(f);
+#else
+ ValidateArchitecture(f);
+#endif
+
+ ExamineSyscall(f);
+
+ for (size_t i = 0; i < primary_filter_size; ++i) {
+ f.push_back(primary_filter[i]);
+ }
+ Disallow(f);
+
+#ifdef DUAL_ARCH
+ if (!SetValidateArchitectureJumpTarget(offset_to_secondary_filter, f)) {
+ return false;
+ }
+
+ ExamineSyscall(f);
+
+ for (size_t i = 0; i < secondary_filter_size; ++i) {
+ f.push_back(secondary_filter[i]);
+ }
+ Disallow(f);
+#endif
+
+ return install_filter(f);
+}
diff --git a/libc/seccomp/x86_64_policy.cpp b/libc/seccomp/x86_64_policy.cpp
new file mode 100644
index 0000000..e1f0aa3
--- /dev/null
+++ b/libc/seccomp/x86_64_policy.cpp
@@ -0,0 +1,91 @@
+// Autogenerated file - edit at your peril!!
+
+#include <linux/filter.h>
+#include <errno.h>
+
+#include "seccomp_bpfs.h"
+const sock_filter x86_64_filter[] = {
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 0, 0, 79),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 157, 39, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 72, 19, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 32, 9, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 8, 5, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 3, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 2, 73, 72), //read|write
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4, 72, 71), //close
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 6, 71, 70), //fstat
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 24, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 21, 69, 68), //lseek|mmap|mprotect|munmap|brk|rt_sigaction|rt_sigprocmask|rt_sigreturn|ioctl|pread64|pwrite64|readv|writev
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 29, 68, 67), //sched_yield|mremap|msync|mincore|madvise
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 44, 5, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 38, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 35, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 33, 64, 63), //dup
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 37, 63, 62), //nanosleep|getitimer
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 43, 62, 61), //setitimer|getpid|sendfile|socket|connect
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 58, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 57, 60, 59), //sendto|recvfrom|sendmsg|recvmsg|shutdown|bind|listen|getsockname|getpeername|socketpair|setsockopt|getsockopt|clone
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 64, 59, 58), //vfork|execve|exit|wait4|kill|uname
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 112, 9, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 93, 5, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 91, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 79, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 78, 54, 53), //fcntl|flock|fsync|fdatasync|truncate|ftruncate
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 82, 53, 52), //getcwd|chdir|fchdir
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 92, 52, 51), //fchmod
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 95, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 94, 50, 49), //fchown
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 111, 49, 48), //umask|gettimeofday|getrlimit|getrusage|sysinfo|times|ptrace|getuid|syslog|getgid|setuid|setgid|geteuid|getegid|setpgid|getppid
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 140, 5, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 137, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 135, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 132, 45, 44), //setsid|setreuid|setregid|getgroups|setgroups|setresuid|getresuid|setresgid|getresgid|getpgid|setfsuid|setfsgid|getsid|capget|capset|rt_sigpending|rt_sigtimedwait|rt_sigqueueinfo|rt_sigsuspend|sigaltstack
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 136, 44, 43), //personality
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 139, 43, 42), //statfs|fstatfs
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 155, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 153, 41, 40), //getpriority|setpriority|sched_setparam|sched_getparam|sched_setscheduler|sched_getscheduler|sched_get_priority_max|sched_get_priority_min|sched_rr_get_interval|mlock|munlock|mlockall|munlockall
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 156, 40, 39), //pivot_root
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 254, 19, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 217, 9, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 186, 5, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 179, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 175, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 172, 34, 33), //prctl|arch_prctl|adjtimex|setrlimit|chroot|sync|acct|settimeofday|mount|umount2|swapon|swapoff|reboot|sethostname|setdomainname
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 177, 33, 32), //init_module|delete_module
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 180, 32, 31), //quotactl
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 202, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 201, 30, 29), //gettid|readahead|setxattr|lsetxattr|fsetxattr|getxattr|lgetxattr|fgetxattr|listxattr|llistxattr|flistxattr|removexattr|lremovexattr|fremovexattr|tkill
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 205, 29, 28), //futex|sched_setaffinity|sched_getaffinity
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 247, 5, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 233, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 221, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 220, 25, 24), //getdents64|set_tid_address|restart_syscall
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 232, 24, 23), //fadvise64|timer_create|timer_settime|timer_gettime|timer_getoverrun|timer_delete|clock_settime|clock_gettime|clock_getres|clock_nanosleep|exit_group
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 235, 23, 22), //epoll_ctl|tgkill
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 251, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 248, 21, 20), //waitid
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 253, 20, 19), //ioprio_set|ioprio_get
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 283, 9, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 275, 5, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 262, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 257, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 256, 15, 14), //inotify_add_watch|inotify_rm_watch
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 261, 14, 13), //openat|mkdirat|mknodat|fchownat
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 273, 13, 12), //newfstatat|unlinkat|renameat|linkat|symlinkat|readlinkat|fchmodat|faccessat|pselect6|ppoll|unshare
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 280, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 279, 11, 10), //splice|tee|sync_file_range|vmsplice
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 282, 10, 9), //utimensat|epoll_pwait
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 305, 5, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 302, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 285, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 284, 6, 5), //timerfd_create
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 300, 5, 4), //fallocate|timerfd_settime|timerfd_gettime|accept4|signalfd4|eventfd2|epoll_create1|dup3|pipe2|inotify_init1|preadv|pwritev|rt_tgsigqueueinfo|perf_event_open|recvmmsg
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 303, 4, 3), //prlimit64
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 317, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 312, 2, 1), //clock_adjtime|syncfs|sendmmsg|setns|getcpu|process_vm_readv|process_vm_writev
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 319, 1, 0), //seccomp|getrandom
+BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW),
+};
+
+const size_t x86_64_filter_size = sizeof(x86_64_filter) / sizeof(struct sock_filter);
diff --git a/libc/seccomp/x86_policy.cpp b/libc/seccomp/x86_policy.cpp
new file mode 100644
index 0000000..00b123b
--- /dev/null
+++ b/libc/seccomp/x86_policy.cpp
@@ -0,0 +1,123 @@
+// Autogenerated file - edit at your peril!!
+
+#include <linux/filter.h>
+#include <errno.h>
+
+#include "seccomp_bpfs.h"
+const sock_filter x86_filter[] = {
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 0, 0, 111),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 131, 55, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 64, 27, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 36, 13, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 24, 7, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 10, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 8, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 7, 105, 104), //restart_syscall|exit|fork|read|write|open|close
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 9, 104, 103), //creat
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 19, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 13, 102, 101), //unlink|execve|chdir
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 22, 101, 100), //lseek|getpid|mount
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 33, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 26, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 25, 98, 97), //getuid
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 27, 97, 96), //ptrace
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 34, 96, 95), //access
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 54, 7, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 45, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 41, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 38, 92, 91), //sync|kill
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 44, 91, 90), //dup|pipe|times
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 51, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 46, 89, 88), //brk
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 53, 88, 87), //acct|umount2
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 60, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 57, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 56, 85, 84), //ioctl|fcntl
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 58, 84, 83), //setpgid
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 62, 83, 82), //umask|chroot
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 94, 13, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 85, 7, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 74, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 66, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 65, 78, 77), //getppid
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 68, 77, 76), //setsid|sigaction
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 77, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 76, 75, 74), //sethostname|setrlimit
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 80, 74, 73), //getrusage|gettimeofday|settimeofday
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 91, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 87, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 86, 71, 70), //readlink
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 89, 70, 69), //swapon|reboot
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 93, 69, 68), //munmap|truncate
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 118, 7, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 102, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 96, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 95, 65, 64), //fchmod
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 98, 64, 63), //getpriority|setpriority
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 114, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 106, 62, 61), //socketcall|syslog|setitimer|getitimer
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 117, 61, 60), //wait4|swapoff|sysinfo
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 128, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 124, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 123, 58, 57), //fsync|sigreturn|clone|setdomainname|uname
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 126, 57, 56), //adjtimex|mprotect
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 130, 56, 55), //init_module|delete_module
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 254, 27, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 183, 13, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 150, 7, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 138, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 136, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 134, 50, 49), //quotactl|getpgid|fchdir
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 137, 49, 48), //personality
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 143, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 142, 47, 46), //setfsuid|setfsgid|_llseek|getdents
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 149, 46, 45), //flock|msync|readv|writev|getsid|fdatasync
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 172, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 168, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 164, 43, 42), //mlock|munlock|mlockall|munlockall|sched_setparam|sched_getparam|sched_setscheduler|sched_getscheduler|sched_yield|sched_get_priority_max|sched_get_priority_min|sched_rr_get_interval|nanosleep|mremap
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 169, 42, 41), //poll
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 182, 41, 40), //prctl|rt_sigreturn|rt_sigaction|rt_sigprocmask|rt_sigpending|rt_sigtimedwait|rt_sigqueueinfo|rt_sigsuspend|pread64|pwrite64
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 218, 7, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 199, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 190, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 188, 37, 36), //getcwd|capget|capset|sigaltstack|sendfile
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 198, 36, 35), //vfork|ugetrlimit|mmap2|truncate64|ftruncate64|stat64|lstat64|fstat64
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 213, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 212, 34, 33), //getuid32|getgid32|geteuid32|getegid32|setreuid32|setregid32|getgroups32|setgroups32|fchown32|setresuid32|getresuid32|setresgid32|getresgid32
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 215, 33, 32), //setuid32|setgid32
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 252, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 224, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 222, 30, 29), //mincore|madvise|getdents64|fcntl64
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 244, 29, 28), //gettid|readahead|setxattr|lsetxattr|fsetxattr|getxattr|lgetxattr|fgetxattr|listxattr|llistxattr|flistxattr|removexattr|lremovexattr|fremovexattr|tkill|sendfile64|futex|sched_setaffinity|sched_getaffinity|set_thread_area
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 253, 28, 27), //exit_group
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 313, 13, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 291, 7, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 272, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 258, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 257, 23, 22), //epoll_create|epoll_ctl|epoll_wait
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 271, 22, 21), //set_tid_address|timer_create|timer_settime|timer_gettime|timer_getoverrun|timer_delete|clock_settime|clock_gettime|clock_getres|clock_nanosleep|statfs64|fstatfs64|tgkill
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 284, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 273, 20, 19), //fadvise64_64
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 285, 19, 18), //waitid
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 300, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 295, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 294, 16, 15), //inotify_init|inotify_add_watch|inotify_rm_watch
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 299, 15, 14), //openat|mkdirat|mknodat|fchownat
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 311, 14, 13), //fstatat64|unlinkat|renameat|linkat|symlinkat|readlinkat|fchmodat|faccessat|pselect6|ppoll|unshare
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 343, 7, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 322, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 318, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 317, 10, 9), //splice|sync_file_range|tee|vmsplice
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 321, 9, 8), //getcpu|epoll_pwait|utimensat
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 340, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 337, 7, 6), //timerfd_create|eventfd|fallocate|timerfd_settime|timerfd_gettime|signalfd4|eventfd2|epoll_create1|dup3|pipe2|inotify_init1|preadv|pwritev|rt_tgsigqueueinfo|perf_event_open
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 341, 6, 5), //prlimit64
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 354, 3, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 346, 1, 0),
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 345, 3, 2), //clock_adjtime|syncfs
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 349, 2, 1), //setns|process_vm_readv|process_vm_writev
+BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 356, 1, 0), //seccomp|getrandom
+BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW),
+};
+
+const size_t x86_filter_size = sizeof(x86_filter) / sizeof(struct sock_filter);
diff --git a/libc/tools/genseccomp.py b/libc/tools/genseccomp.py
index 7d2b1da..d9e0819 100755
--- a/libc/tools/genseccomp.py
+++ b/libc/tools/genseccomp.py
@@ -1,8 +1,9 @@
#!/usr/bin/env python
+import collections
import os
-from subprocess import Popen, PIPE
import textwrap
from gensyscalls import SysCallsTxtParser
+from subprocess import Popen, PIPE
BPF_JGE = "BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, {0}, {1}, {2})"
@@ -36,15 +37,31 @@
syscalls = [x for x in syscalls if architecture in x and x[architecture]]
# We only want the name
- return [x["name"] for x in syscalls]
+ names = [x["name"] for x in syscalls]
+
+ # Check for duplicates
+ dups = [name for name, count in collections.Counter(names).items() if count > 1]
+
+ # x86 has duplicate socketcall entries, so hard code for this
+ if architecture == "x86":
+ dups.remove("socketcall")
+
+ if len(dups) > 0:
+ print "Duplicate entries found - aborting ", dups
+ exit(-1)
+
+ # Remove remaining duplicates
+ return list(set(names))
-def convert_names_to_NRs(names, header_dir):
+def convert_names_to_NRs(names, header_dir, extra_switches):
# Run preprocessor over the __NR_syscall symbols, including unistd.h,
# to get the actual numbers
prefix = "__SECCOMP_" # prefix to ensure no name collisions
cpp = Popen(["../../prebuilts/clang/host/linux-x86/clang-stable/bin/clang",
- "-E", "-nostdinc", "-I" + header_dir, "-Ikernel/uapi/", "-"],
+ "-E", "-nostdinc", "-I" + header_dir, "-Ikernel/uapi/"]
+ + extra_switches
+ + ["-"],
stdin=PIPE, stdout=PIPE)
cpp.stdin.write("#include <asm/unistd.h>\n")
for name in names:
@@ -149,8 +166,8 @@
#include <linux/filter.h>
#include <errno.h>
- #include "seccomp_policy.h"
- const struct sock_filter {architecture}_filter[] = {{
+ #include "seccomp_bpfs.h"
+ const sock_filter {architecture}_filter[] = {{
""").format(architecture=architecture)
footer = textwrap.dedent("""\
@@ -162,25 +179,23 @@
return header + "\n".join(bpf) + footer
-def construct_bpf(syscall_files, architecture, header_dir):
+def construct_bpf(syscall_files, architecture, header_dir, extra_switches):
names = get_names(syscall_files, architecture)
- syscalls = convert_names_to_NRs(names, header_dir)
+ syscalls = convert_names_to_NRs(names, header_dir, extra_switches)
ranges = convert_NRs_to_ranges(syscalls)
bpf = convert_ranges_to_bpf(ranges)
return convert_bpf_to_output(bpf, architecture)
-android_syscall_files = ["SYSCALLS.TXT", "SECCOMP_WHITELIST.TXT"]
-arm_headers = "kernel/uapi/asm-arm"
-arm64_headers = "kernel/uapi/asm-arm64"
-arm_architecture = "arm"
-arm64_architecture = "arm64"
-
-
ANDROID_SYSCALL_FILES = ["SYSCALLS.TXT", "SECCOMP_WHITELIST.TXT"]
-POLICY_CONFIGS = [("arm", "kernel/uapi/asm-arm"),
- ("arm64", "kernel/uapi/asm-arm64")]
+
+POLICY_CONFIGS = [("arm", "kernel/uapi/asm-arm", []),
+ ("arm64", "kernel/uapi/asm-arm64", []),
+ ("x86", "kernel/uapi/asm-x86", ["-D__i386__"]),
+ ("x86_64", "kernel/uapi/asm-x86", []),
+ ("mips", "kernel/uapi/asm-mips", ["-D_MIPS_SIM=_MIPS_SIM_ABI32"]),
+ ("mips64", "kernel/uapi/asm-mips", ["-D_MIPS_SIM=_MIPS_SIM_ABI64"])]
def set_dir():
@@ -190,13 +205,13 @@
def main():
set_dir()
- for arch, header_path in POLICY_CONFIGS:
+ for arch, header_path, switches in POLICY_CONFIGS:
files = [open(filename) for filename in ANDROID_SYSCALL_FILES]
- output = construct_bpf(files, arch, header_path)
+ output = construct_bpf(files, arch, header_path, switches)
# And output policy
existing = ""
- output_path = "seccomp/{}_policy.c".format(arch)
+ output_path = "seccomp/{}_policy.cpp".format(arch)
if os.path.isfile(output_path):
existing = open(output_path).read()
if output == existing:
@@ -206,6 +221,5 @@
output_file.write(output)
print "Generated file " + output_path
-
if __name__ == "__main__":
main()
diff --git a/libc/tools/test_genseccomp.py b/libc/tools/test_genseccomp.py
index de1e5fe..19672a1 100755
--- a/libc/tools/test_genseccomp.py
+++ b/libc/tools/test_genseccomp.py
@@ -20,6 +20,9 @@
def get_headers(self, arch):
return self.get_config(arch)[1]
+ def get_switches(self, arch):
+ return self.get_config(arch)[2]
+
def test_get_names(self):
syscalls = cStringIO.StringIO(textwrap.dedent("""\
int __llseek:_llseek(int, unsigned long, unsigned long, off64_t*, int) arm,mips,x86
@@ -45,17 +48,40 @@
def test_convert_names_to_NRs(self):
self.assertEquals(genseccomp.convert_names_to_NRs(["open"],
- self.get_headers("arm")),
+ self.get_headers("arm"),
+ self.get_switches("arm")),
[("open", 5)])
self.assertEquals(genseccomp.convert_names_to_NRs(["__ARM_NR_set_tls"],
- self.get_headers("arm")),
+ self.get_headers("arm"),
+ self.get_switches("arm")),
[('__ARM_NR_set_tls', 983045)])
self.assertEquals(genseccomp.convert_names_to_NRs(["openat"],
- self.get_headers("arm64")),
+ self.get_headers("arm64"),
+ self.get_switches("arm64")),
[("openat", 56)])
+ self.assertEquals(genseccomp.convert_names_to_NRs(["openat"],
+ self.get_headers("x86"),
+ self.get_switches("x86")),
+ [("openat", 295)])
+
+ self.assertEquals(genseccomp.convert_names_to_NRs(["openat"],
+ self.get_headers("x86_64"),
+ self.get_switches("x86_64")),
+ [("openat", 257)])
+
+ self.assertEquals(genseccomp.convert_names_to_NRs(["openat"],
+ self.get_headers("mips"),
+ self.get_switches("mips")),
+ [("openat", 4288)])
+
+ self.assertEquals(genseccomp.convert_names_to_NRs(["openat"],
+ self.get_headers("mips64"),
+ self.get_switches("mips64")),
+ [("openat", 5247)])
+
def test_convert_NRs_to_ranges(self):
ranges = genseccomp.convert_NRs_to_ranges([("b", 2), ("a", 1)])
@@ -107,8 +133,8 @@
#include <linux/filter.h>
#include <errno.h>
- #include "seccomp_policy.h"
- const struct sock_filter arm_filter[] = {
+ #include "seccomp_bpfs.h"
+ const sock_filter arm_filter[] = {
line1
line2
};
@@ -128,7 +154,8 @@
"""))
syscall_files = [syscalls, whitelist]
- output = genseccomp.construct_bpf(syscall_files, "arm", self.get_headers("arm"))
+ output = genseccomp.construct_bpf(syscall_files, "arm", self.get_headers("arm"),
+ self.get_switches("arm"))
expected_output = textwrap.dedent("""\
// Autogenerated file - edit at your peril!!
@@ -136,8 +163,8 @@
#include <linux/filter.h>
#include <errno.h>
- #include "seccomp_policy.h"
- const struct sock_filter arm_filter[] = {
+ #include "seccomp_bpfs.h"
+ const sock_filter arm_filter[] = {
BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 3, 0, 3),
BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 140, 1, 0),
BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4, 2, 1), //read
diff --git a/libc/zoneinfo/tzdata b/libc/zoneinfo/tzdata
index 577ede6..a2e8da6 100644
--- a/libc/zoneinfo/tzdata
+++ b/libc/zoneinfo/tzdata
Binary files differ
diff --git a/linker/linker.cpp b/linker/linker.cpp
index 7740aa9..7b16cc3 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -235,7 +235,6 @@
}
// END OF WORKAROUND
-static const char* const* g_default_ld_paths;
static std::vector<std::string> g_ld_preload_names;
static bool g_anonymous_namespace_initialized;
@@ -1811,18 +1810,22 @@
// See b/17302493 for further details.
// Once the above bug is fixed, this code can be modified to use
// snprintf again.
- size_t required_len = 0;
- for (size_t i = 0; g_default_ld_paths[i] != nullptr; ++i) {
- required_len += strlen(g_default_ld_paths[i]) + 1;
+ const auto& default_ld_paths = g_default_namespace.get_default_library_paths();
+
+ size_t required_size = 0;
+ for (const auto& path : default_ld_paths) {
+ required_size += path.size() + 1;
}
- if (buffer_size < required_len) {
+
+ if (buffer_size < required_size) {
__libc_fatal("android_get_LD_LIBRARY_PATH failed, buffer too small: "
- "buffer len %zu, required len %zu", buffer_size, required_len);
+ "buffer len %zu, required len %zu", buffer_size, required_size);
}
+
char* end = buffer;
- for (size_t i = 0; g_default_ld_paths[i] != nullptr; ++i) {
+ for (size_t i = 0; i < default_ld_paths.size(); ++i) {
if (i > 0) *end++ = ':';
- end = stpcpy(end, g_default_ld_paths[i]);
+ end = stpcpy(end, default_ld_paths[i].c_str());
}
}
@@ -1914,14 +1917,16 @@
if (g_is_asan && translated_name != nullptr && translated_name[0] == '/') {
char translated_path[PATH_MAX];
if (realpath(translated_name, translated_path) != nullptr) {
- if (file_is_in_dir(translated_path, kSystemLibDir)) {
- asan_name_holder = std::string(kAsanSystemLibDir) + "/" + basename(translated_path);
+ if (file_is_under_dir(translated_path, kSystemLibDir)) {
+ asan_name_holder = std::string(kAsanSystemLibDir) + "/" +
+ (translated_path + strlen(kSystemLibDir) + 1);
if (file_exists(asan_name_holder.c_str())) {
translated_name = asan_name_holder.c_str();
PRINT("linker_asan dlopen translating \"%s\" -> \"%s\"", name, translated_name);
}
- } else if (file_is_in_dir(translated_path, kVendorLibDir)) {
- asan_name_holder = std::string(kAsanVendorLibDir) + "/" + basename(translated_path);
+ } else if (file_is_under_dir(translated_path, kVendorLibDir)) {
+ asan_name_holder = std::string(kAsanVendorLibDir) + "/" +
+ (translated_path + strlen(kVendorLibDir) + 1);
if (file_exists(asan_name_holder.c_str())) {
translated_name = asan_name_holder.c_str();
PRINT("linker_asan dlopen translating \"%s\" -> \"%s\"", name, translated_name);
@@ -2083,8 +2088,6 @@
ProtectedDataGuard guard;
- g_anonymous_namespace_initialized = true;
-
// create anonymous namespace
// When the caller is nullptr - create_namespace will take global group
// from the anonymous namespace, which is fine because anonymous namespace
@@ -2100,16 +2103,15 @@
&g_default_namespace);
if (anon_ns == nullptr) {
- g_anonymous_namespace_initialized = false;
return false;
}
if (!link_namespaces(anon_ns, &g_default_namespace, shared_lib_sonames)) {
- g_anonymous_namespace_initialized = false;
return false;
}
g_anonymous_namespace = anon_ns;
+ g_anonymous_namespace_initialized = true;
return true;
}
@@ -2128,11 +2130,6 @@
uint64_t type,
const char* permitted_when_isolated_path,
android_namespace_t* parent_namespace) {
- if (!g_anonymous_namespace_initialized) {
- DL_ERR("cannot create namespace: anonymous namespace is not initialized.");
- return nullptr;
- }
-
if (parent_namespace == nullptr) {
// if parent_namespace is nullptr -> set it to the caller namespace
soinfo* caller_soinfo = find_containing_library(caller_addr);
@@ -3370,20 +3367,20 @@
const char *interp = phdr_table_get_interpreter_name(somain->phdr, somain->phnum,
somain->load_bias);
const char* bname = basename(interp);
- if (bname && (strcmp(bname, "linker_asan") == 0 || strcmp(bname, "linker_asan64") == 0)) {
- g_default_ld_paths = kAsanDefaultLdPaths;
- g_is_asan = true;
- } else {
- g_default_ld_paths = kDefaultLdPaths;
- }
+
+ bool is_asan = bname != nullptr &&
+ (strcmp(bname, "linker_asan") == 0 ||
+ strcmp(bname, "linker_asan64") == 0);
+ auto default_ld_paths = is_asan ? kAsanDefaultLdPaths : kDefaultLdPaths;
+ g_is_asan = is_asan;
char real_path[PATH_MAX];
std::vector<std::string> ld_default_paths;
- for (size_t i = 0; g_default_ld_paths[i] != nullptr; ++i) {
- if (realpath(g_default_ld_paths[i], real_path) != nullptr) {
+ for (size_t i = 0; default_ld_paths[i] != nullptr; ++i) {
+ if (realpath(default_ld_paths[i], real_path) != nullptr) {
ld_default_paths.push_back(real_path);
} else {
- ld_default_paths.push_back(g_default_ld_paths[i]);
+ ld_default_paths.push_back(default_ld_paths[i]);
}
}
diff --git a/linker/linker_memory.cpp b/linker/linker_memory.cpp
index 18ef93e..f8852e1 100644
--- a/linker/linker_memory.cpp
+++ b/linker/linker_memory.cpp
@@ -39,16 +39,22 @@
// Used by libdebuggerd_handler to switch allocators during a crash dump, in
// case the linker heap is corrupted. Do not use this function.
-extern "C" void __linker_use_fallback_allocator() {
+extern "C" void __linker_enable_fallback_allocator() {
if (fallback_tid != 0) {
- __libc_format_log(ANDROID_LOG_ERROR, "libc",
- "attempted to set fallback allocator multiple times");
- return;
+ __libc_fatal("attempted to use currently-in-use fallback allocator");
}
fallback_tid = gettid();
}
+extern "C" void __linker_disable_fallback_allocator() {
+ if (fallback_tid == 0) {
+ __libc_fatal("attempted to disable unused fallback allocator");
+ }
+
+ fallback_tid = 0;
+}
+
static LinkerMemoryAllocator& get_fallback_allocator() {
static LinkerMemoryAllocator fallback_allocator;
return fallback_allocator;
diff --git a/tests/pthread_test.cpp b/tests/pthread_test.cpp
index 024a675..4fb15ad 100755
--- a/tests/pthread_test.cpp
+++ b/tests/pthread_test.cpp
@@ -1888,17 +1888,26 @@
static void SignalHandlerOnAltStack(int signo, siginfo_t*, void*) {
ASSERT_EQ(SIGUSR1, signo);
- // Check if we have enough stack space for unwinding.
- int count = 0;
- _Unwind_Backtrace(FrameCounter, &count);
- ASSERT_GT(count, 0);
- // Check if we have enough stack space for logging.
- std::string s(2048, '*');
- GTEST_LOG_(INFO) << s;
- signal_handler_on_altstack_done = true;
+ {
+ // Check if we have enough stack space for unwinding.
+ int count = 0;
+ _Unwind_Backtrace(FrameCounter, &count);
+ ASSERT_GT(count, 0);
+ }
+ {
+ // Check if we have enough stack space for logging.
+ std::string s(2048, '*');
+ GTEST_LOG_(INFO) << s;
+ signal_handler_on_altstack_done = true;
+ }
+ {
+ // Check if we have enough stack space for snprintf to a PATH_MAX buffer, plus some extra.
+ char buf[PATH_MAX + 2048];
+ ASSERT_GT(snprintf(buf, sizeof(buf), "/proc/%d/status", getpid()), 0);
+ }
}
-TEST(pthread, big_enough_signal_stack_for_64bit_arch) {
+TEST(pthread, big_enough_signal_stack) {
signal_handler_on_altstack_done = false;
ScopedSignalHandler handler(SIGUSR1, SignalHandlerOnAltStack, SA_SIGINFO | SA_ONSTACK);
kill(getpid(), SIGUSR1);
diff --git a/tests/system_properties_test.cpp b/tests/system_properties_test.cpp
index ff97549..23d0cad 100644
--- a/tests/system_properties_test.cpp
+++ b/tests/system_properties_test.cpp
@@ -29,8 +29,6 @@
#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
#include <sys/_system_properties.h>
-extern void *__system_property_area__;
-
struct LocalPropertyTestState {
LocalPropertyTestState() : valid(false) {
const char* ANDROID_DATA = getenv("ANDROID_DATA");