diff options
-rw-r--r-- | bioniccompat/Android.bp | 15 | ||||
-rw-r--r-- | bioniccompat/include/android/api-level.h | 63 | ||||
-rw-r--r-- | bioniccompat/include/android/versioning.h | 32 | ||||
-rw-r--r-- | bioniccompat/include/basename.h | 27 | ||||
-rw-r--r-- | bioniccompat/include/compat/fcntl.h | 41 | ||||
-rw-r--r-- | bioniccompat/include/compat/pwd.h | 52 | ||||
-rw-r--r-- | bioniccompat/include/stdbool.h | 47 | ||||
-rw-r--r-- | bioniccompat/include/stdint.h | 271 | ||||
-rw-r--r-- | bioniccompat/include/sys/capability.h | 43 | ||||
-rw-r--r-- | bioniccompat/include/sys/cdefs.h | 23 | ||||
-rw-r--r-- | bioniccompat/include/sys/compat/mman.h | 30 | ||||
-rw-r--r-- | bioniccompat/include/sys/compat/types.h | 35 | ||||
-rw-r--r-- | bioniccompat/include/sys/prctl.h | 31 | ||||
-rw-r--r-- | bioniccompat/include/sys/resource.h | 44 | ||||
-rw-r--r-- | bioniccompat/include/sys/sendfile.h | 39 | ||||
-rw-r--r-- | bioniccompat/include/sys/xattr.h | 59 | ||||
-rw-r--r-- | bioniccompat/src/sendfile.cc | 65 |
17 files changed, 917 insertions, 0 deletions
diff --git a/bioniccompat/Android.bp b/bioniccompat/Android.bp new file mode 100644 index 0000000..2416aa4 --- /dev/null +++ b/bioniccompat/Android.bp @@ -0,0 +1,15 @@ +cc_library { + name: "libbioniccompat", + local_include_dirs: [ + "include", + ], + export_include_dirs: [ + "include", + ], + stl: "none", + target: { + fuchsia: { + srcs: [ "src/*.cc" ], + }, + }, +} diff --git a/bioniccompat/include/android/api-level.h b/bioniccompat/include/android/api-level.h new file mode 100644 index 0000000..7a909d7 --- /dev/null +++ b/bioniccompat/include/android/api-level.h @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef ANDROID_API_LEVEL_H +#define ANDROID_API_LEVEL_H + +#include <sys/cdefs.h> + +/* + * Magic version number for a current development build, which has + * not yet turned into an official release. + */ +#ifndef __ANDROID_API_FUTURE__ +#define __ANDROID_API_FUTURE__ 10000 +#endif + +#ifndef __ANDROID_API__ +#define __ANDROID_API__ __ANDROID_API_FUTURE__ +#else +#define __ANDROID_NDK__ 1 +#endif + +#define __ANDROID_API_G__ 9 +#define __ANDROID_API_I__ 14 +#define __ANDROID_API_J__ 16 +#define __ANDROID_API_J_MR1__ 17 +#define __ANDROID_API_J_MR2__ 18 +#define __ANDROID_API_K__ 19 +#define __ANDROID_API_L__ 21 +#define __ANDROID_API_L_MR1__ 22 +#define __ANDROID_API_M__ 23 +#define __ANDROID_API_N__ 24 +#define __ANDROID_API_N_MR1__ 25 +#define __ANDROID_API_O__ 26 +#define __ANDROID_API_O_MR1__ 27 +#define __ANDROID_API_P__ 28 + +#endif diff --git a/bioniccompat/include/android/versioning.h b/bioniccompat/include/android/versioning.h new file mode 100644 index 0000000..4e1a185 --- /dev/null +++ b/bioniccompat/include/android/versioning.h @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_VERSIONING_H +#define ANDROID_VERSIONING_H + +#define __INTRODUCED_IN(api_level) __attribute__((annotate("introduced_in=" #api_level))) +#define __INTRODUCED_IN_FUTURE __attribute__((annotate("introduced_in_future"))) +#define __DEPRECATED_IN(api_level) __attribute__((annotate("deprecated_in=" #api_level))) +#define __REMOVED_IN(api_level) __attribute__((annotate("obsoleted_in=" #api_level))) +#define __INTRODUCED_IN_32(api_level) __attribute__((annotate("introduced_in_32=" #api_level))) +#define __INTRODUCED_IN_64(api_level) __attribute__((annotate("introduced_in_64=" #api_level))) +#define __INTRODUCED_IN_ARM(api_level) __attribute__((annotate("introduced_in_arm=" #api_level))) +#define __INTRODUCED_IN_X86(api_level) __attribute__((annotate("introduced_in_x86=" #api_level))) +#define __INTRODUCED_IN_MIPS(api_level) __attribute__((annotate("introduced_in_mips=" #api_level))) + +#define __VERSIONER_NO_GUARD __attribute__((annotate("versioner_no_guard"))) + +#endif /* ANDROID_VERSIONING_H */ diff --git a/bioniccompat/include/basename.h b/bioniccompat/include/basename.h new file mode 100644 index 0000000..b19540b --- /dev/null +++ b/bioniccompat/include/basename.h @@ -0,0 +1,27 @@ + +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BASENAME_H +#define BASENAME_H + +extern "C" inline const char* __gnu_basename(const char* path) { + const char* last_slash = strrchr(path, '/'); + return (last_slash != NULL) ? last_slash + 1 : path; +} +#define basename __gnu_basename + +#endif // BASENAME_H diff --git a/bioniccompat/include/compat/fcntl.h b/bioniccompat/include/compat/fcntl.h new file mode 100644 index 0000000..8891e07 --- /dev/null +++ b/bioniccompat/include/compat/fcntl.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef COMPAT_FCNTL_H +#define COMPAT_FCNTL_H + +#include <fcntl.h> + +#include <errno.h> + +/* + * zircon does not support this operation. + * + * This is super hacky: supply a function that takes a long * and explicitly + * cast to loff_t, which on Fuchsia is long long. This is safe on Fuchsia but + * obviously not portable, yet it allows us to leave libcore code alone. + */ +ssize_t splice(int fd_in, long *off_in, int fd_out, + long *off_out, size_t len, unsigned int flags) { + return splice(fd_in, (loff_t *)off_in, fd_out, (loff_t *)off_out, len, flags); +} + +ssize_t splice(int fd_in __UNUSED, loff_t *off_in __UNUSED, int fd_out __UNUSED, + loff_t *off_out __UNUSED, size_t len __UNUSED, unsigned int flags __UNUSED) { + errno = EINVAL; + return -1; +} + +#endif // COMPAT_FCNTL_H diff --git a/bioniccompat/include/compat/pwd.h b/bioniccompat/include/compat/pwd.h new file mode 100644 index 0000000..3d07972 --- /dev/null +++ b/bioniccompat/include/compat/pwd.h @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef COMPAT_PWD_H +#define COMPAT_PWD_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <pwd.h> + +static struct passwd PASSWORD = { + .pw_name = (char *)"android", + .pw_uid = 1, + .pw_gid = 1, + .pw_passwd = (char *)"", + .pw_dir = (char *)"/", + .pw_gecos = NULL, + .pw_shell = (char *)"/bin/bash", +}; + +int getpwnam_r(const char *name __UNUSED, struct passwd *pwd __UNUSED, + char *buf __UNUSED, size_t buflen __UNUSED, struct passwd **result) { + *result = &PASSWORD; + return 0; +} + +int getpwuid_r(uid_t uid __UNUSED, passwd* pwd __UNUSED, char *buf __UNUSED, + size_t byte_count __UNUSED, struct passwd** result) { + *result = &PASSWORD; + return 0; +} + +#ifdef __cplusplus +} +#endif + +#endif // COMPAT_PWD_H diff --git a/bioniccompat/include/stdbool.h b/bioniccompat/include/stdbool.h new file mode 100644 index 0000000..5cb66b5 --- /dev/null +++ b/bioniccompat/include/stdbool.h @@ -0,0 +1,47 @@ +/*===---- stdbool.h - Standard header for booleans -------------------------=== + * + * Copyright (c) 2008 Eli Friedman + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + *===-----------------------------------------------------------------------=== + */ + +#ifndef __STDBOOL_H +#define __STDBOOL_H + +/* Don't define bool, true, and false in C++, except as a GNU extension. */ +#ifndef __cplusplus +#define bool _Bool +#define true 1 +#define false 0 +#elif defined(__GNUC__) && !defined(__STRICT_ANSI__) +/* Define _Bool as a GNU extension. */ +#define _Bool bool +#if __cplusplus < 201103L +/* For C++98, define bool, false, true as a GNU extension. */ +#define bool bool +#define false false +#define true true +#endif +#endif + +#define __bool_true_false_are_defined 1 + +#endif /* __STDBOOL_H */ diff --git a/bioniccompat/include/stdint.h b/bioniccompat/include/stdint.h new file mode 100644 index 0000000..a16f91d --- /dev/null +++ b/bioniccompat/include/stdint.h @@ -0,0 +1,271 @@ +// Copyright 2016 The Fuchsia Authors +// +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file or at +// https://opensource.org/licenses/MIT + +#pragma once + +// The compiler predefines macros __<type>_TYPE__, __<type>_MAX__, +// and __<type>_C for the various types. All we have to do here is +// define the public names based on those macros. + +// Clang predefines macros __<type>_FMT<letter>__ for each type, +// with <letter> being i and for signed types, and o, u, x, and X +// for unsigned types. That lets <inttypes.h> do its work without +// any special knowledge of what the underlying types are. +// Unfortunately, GCC does not define these macros. To keep all +// knowledge of the compiler's choices isolated to this file, define +// them here for GCC so that <inttypes.h> can use them unconditionally. +#ifndef __INTMAX_FMTd__ + +#define __INT8_FMT_MODIFIER__ "hh" +#define __INT16_FMT_MODIFIER__ "h" +#define __INT32_FMT_MODIFIER__ "" + +#define __INT_LEAST8_FMT_MODIFIER__ __INT8_FMT_MODIFIER__ +#define __INT_LEAST16_FMT_MODIFIER__ __INT16_FMT_MODIFIER__ +#define __INT_LEAST32_FMT_MODIFIER__ __INT32_FMT_MODIFIER__ +#define __INT_LEAST64_FMT_MODIFIER__ __INT64_FMT_MODIFIER__ + +// The *-elf and arm-eabi GCC targets use 'int' for the fast{8,16,32} +// types. On LP64 systems, 'long' is used for the fast64 type, and +// 'long long' on non-LP64 systems. +#define __INT_FAST8_FMT_MODIFIER__ "" +#define __INT_FAST16_FMT_MODIFIER__ "" +#define __INT_FAST32_FMT_MODIFIER__ "" +#if _LP64 +#define __INT_FAST64_FMT_MODIFIER__ "l" +#else +#define __INT_FAST64_FMT_MODIFIER__ "ll" +#endif + +// On machines where 'long' types are 64 bits, the compiler defines +// __INT64_TYPE__ et al using 'long', not 'long long', though both are +// 64-bit types. +#ifdef _LP64 +#define __INT64_FMT_MODIFIER__ "l" +#define __INTPTR_FMT_MODIFIER__ "l" +#else +#define __INT64_FMT_MODIFIER__ "ll" +#define __INTPTR_FMT_MODIFIER__ "" +#endif + +#define __INTMAX_FMT_MODIFIER__ __INT64_FMT_MODIFIER__ + +#define __INTMAX_FMTd__ __INTMAX_FMT_MODIFIER__ "d" +#define __INTMAX_FMTi__ __INTMAX_FMT_MODIFIER__ "i" +#define __UINTMAX_FMTo__ __INTMAX_FMT_MODIFIER__ "o" +#define __UINTMAX_FMTu__ __INTMAX_FMT_MODIFIER__ "u" +#define __UINTMAX_FMTx__ __INTMAX_FMT_MODIFIER__ "x" +#define __UINTMAX_FMTX__ __INTMAX_FMT_MODIFIER__ "X" +#define __INTPTR_FMTd__ __INTPTR_FMT_MODIFIER__ "d" +#define __INTPTR_FMTi__ __INTPTR_FMT_MODIFIER__ "i" +#define __UINTPTR_FMTo__ __INTPTR_FMT_MODIFIER__ "o" +#define __UINTPTR_FMTu__ __INTPTR_FMT_MODIFIER__ "u" +#define __UINTPTR_FMTx__ __INTPTR_FMT_MODIFIER__ "x" +#define __UINTPTR_FMTX__ __INTPTR_FMT_MODIFIER__ "X" +#define __INT8_FMTd__ __INT8_FMT_MODIFIER__ "d" +#define __INT8_FMTi__ __INT8_FMT_MODIFIER__ "i" +#define __INT16_FMTd__ __INT16_FMT_MODIFIER__ "d" +#define __INT16_FMTi__ __INT16_FMT_MODIFIER__ "i" +#define __INT32_FMTd__ __INT32_FMT_MODIFIER__ "d" +#define __INT32_FMTi__ __INT32_FMT_MODIFIER__ "i" +#define __INT64_FMTd__ __INT64_FMT_MODIFIER__ "d" +#define __INT64_FMTi__ __INT64_FMT_MODIFIER__ "i" +#define __UINT8_FMTo__ __INT8_FMT_MODIFIER__ "o" +#define __UINT8_FMTu__ __INT8_FMT_MODIFIER__ "u" +#define __UINT8_FMTx__ __INT8_FMT_MODIFIER__ "x" +#define __UINT8_FMTX__ __INT8_FMT_MODIFIER__ "X" +#define __UINT16_FMTo__ __INT16_FMT_MODIFIER__ "o" +#define __UINT16_FMTu__ __INT16_FMT_MODIFIER__ "u" +#define __UINT16_FMTx__ __INT16_FMT_MODIFIER__ "x" +#define __UINT16_FMTX__ __INT16_FMT_MODIFIER__ "X" +#define __UINT32_FMTo__ __INT32_FMT_MODIFIER__ "o" +#define __UINT32_FMTu__ __INT32_FMT_MODIFIER__ "u" +#define __UINT32_FMTx__ __INT32_FMT_MODIFIER__ "x" +#define __UINT32_FMTX__ __INT32_FMT_MODIFIER__ "X" +#define __UINT64_FMTo__ __INT64_FMT_MODIFIER__ "o" +#define __UINT64_FMTu__ __INT64_FMT_MODIFIER__ "u" +#define __UINT64_FMTx__ __INT64_FMT_MODIFIER__ "x" +#define __UINT64_FMTX__ __INT64_FMT_MODIFIER__ "X" +#define __INT_LEAST8_FMTd__ __INT_LEAST8_FMT_MODIFIER__ "d" +#define __INT_LEAST8_FMTi__ __INT_LEAST8_FMT_MODIFIER__ "i" +#define __UINT_LEAST8_FMTo__ __INT_LEAST8_FMT_MODIFIER__ "o" +#define __UINT_LEAST8_FMTu__ __INT_LEAST8_FMT_MODIFIER__ "u" +#define __UINT_LEAST8_FMTx__ __INT_LEAST8_FMT_MODIFIER__ "x" +#define __UINT_LEAST8_FMTX__ __INT_LEAST8_FMT_MODIFIER__ "X" +#define __INT_LEAST16_FMTd__ __INT_LEAST16_FMT_MODIFIER__ "d" +#define __INT_LEAST16_FMTi__ __INT_LEAST16_FMT_MODIFIER__ "i" +#define __UINT_LEAST16_FMTo__ __INT_LEAST16_FMT_MODIFIER__ "o" +#define __UINT_LEAST16_FMTu__ __INT_LEAST16_FMT_MODIFIER__ "u" +#define __UINT_LEAST16_FMTx__ __INT_LEAST16_FMT_MODIFIER__ "x" +#define __UINT_LEAST16_FMTX__ __INT_LEAST16_FMT_MODIFIER__ "X" +#define __INT_LEAST32_FMTd__ __INT_LEAST32_FMT_MODIFIER__ "d" +#define __INT_LEAST32_FMTi__ __INT_LEAST32_FMT_MODIFIER__ "i" +#define __UINT_LEAST32_FMTo__ __INT_LEAST32_FMT_MODIFIER__ "o" +#define __UINT_LEAST32_FMTu__ __INT_LEAST32_FMT_MODIFIER__ "u" +#define __UINT_LEAST32_FMTx__ __INT_LEAST32_FMT_MODIFIER__ "x" +#define __UINT_LEAST32_FMTX__ __INT_LEAST32_FMT_MODIFIER__ "X" +#define __INT_LEAST64_FMTd__ __INT_LEAST64_FMT_MODIFIER__ "d" +#define __INT_LEAST64_FMTi__ __INT_LEAST64_FMT_MODIFIER__ "i" +#define __UINT_LEAST64_FMTo__ __INT_LEAST64_FMT_MODIFIER__ "o" +#define __UINT_LEAST64_FMTu__ __INT_LEAST64_FMT_MODIFIER__ "u" +#define __UINT_LEAST64_FMTx__ __INT_LEAST64_FMT_MODIFIER__ "x" +#define __UINT_LEAST64_FMTX__ __INT_LEAST64_FMT_MODIFIER__ "X" +#define __INT_FAST8_FMTd__ __INT_FAST8_FMT_MODIFIER__ "d" +#define __INT_FAST8_FMTi__ __INT_FAST8_FMT_MODIFIER__ "i" +#define __UINT_FAST8_FMTo__ __INT_FAST8_FMT_MODIFIER__ "o" +#define __UINT_FAST8_FMTu__ __INT_FAST8_FMT_MODIFIER__ "u" +#define __UINT_FAST8_FMTx__ __INT_FAST8_FMT_MODIFIER__ "x" +#define __UINT_FAST8_FMTX__ __INT_FAST8_FMT_MODIFIER__ "X" +#define __INT_FAST16_FMTd__ __INT_FAST16_FMT_MODIFIER__ "d" +#define __INT_FAST16_FMTi__ __INT_FAST16_FMT_MODIFIER__ "i" +#define __UINT_FAST16_FMTo__ __INT_FAST16_FMT_MODIFIER__ "o" +#define __UINT_FAST16_FMTu__ __INT_FAST16_FMT_MODIFIER__ "u" +#define __UINT_FAST16_FMTx__ __INT_FAST16_FMT_MODIFIER__ "x" +#define __UINT_FAST16_FMTX__ __INT_FAST16_FMT_MODIFIER__ "X" +#define __INT_FAST32_FMTd__ __INT_FAST32_FMT_MODIFIER__ "d" +#define __INT_FAST32_FMTi__ __INT_FAST32_FMT_MODIFIER__ "i" +#define __UINT_FAST32_FMTo__ __INT_FAST32_FMT_MODIFIER__ "o" +#define __UINT_FAST32_FMTu__ __INT_FAST32_FMT_MODIFIER__ "u" +#define __UINT_FAST32_FMTx__ __INT_FAST32_FMT_MODIFIER__ "x" +#define __UINT_FAST32_FMTX__ __INT_FAST32_FMT_MODIFIER__ "X" +#define __INT_FAST64_FMTd__ __INT_FAST64_FMT_MODIFIER__ "d" +#define __INT_FAST64_FMTi__ __INT_FAST64_FMT_MODIFIER__ "i" +#define __UINT_FAST64_FMTo__ __INT_FAST64_FMT_MODIFIER__ "o" +#define __UINT_FAST64_FMTu__ __INT_FAST64_FMT_MODIFIER__ "u" +#define __UINT_FAST64_FMTx__ __INT_FAST64_FMT_MODIFIER__ "x" +#define __UINT_FAST64_FMTX__ __INT_FAST64_FMT_MODIFIER__ "X" + +#endif + +typedef __UINT8_TYPE__ uint8_t; +typedef __UINT16_TYPE__ uint16_t; +typedef __UINT32_TYPE__ uint32_t; +typedef __UINT64_TYPE__ uint64_t; +typedef __INT8_TYPE__ int8_t; +typedef __INT16_TYPE__ int16_t; +typedef __INT32_TYPE__ int32_t; +typedef __INT64_TYPE__ int64_t; + +#define UINT8_MAX __UINT8_MAX__ +#define UINT16_MAX __UINT16_MAX__ +#define UINT32_MAX __UINT32_MAX__ +#define UINT64_MAX __UINT64_MAX__ + +#define INT8_MAX __INT8_MAX__ +#define INT16_MAX __INT16_MAX__ +#define INT32_MAX __INT32_MAX__ +#define INT64_MAX __INT64_MAX__ + +#define INT8_MIN (-INT8_MAX - 1) +#define INT16_MIN (-INT16_MAX - 1) +#define INT32_MIN (-INT32_MAX - 1) +#define INT64_MIN (-INT64_MAX - 1) + +typedef __UINT_LEAST8_TYPE__ uint_least8_t; +typedef __UINT_LEAST16_TYPE__ uint_least16_t; +typedef __UINT_LEAST32_TYPE__ uint_least32_t; +typedef __UINT_LEAST64_TYPE__ uint_least64_t; +typedef __INT_LEAST8_TYPE__ int_least8_t; +typedef __INT_LEAST16_TYPE__ int_least16_t; +typedef __INT_LEAST32_TYPE__ int_least32_t; +typedef __INT_LEAST64_TYPE__ int_least64_t; + +#define UINT_LEAST8_MAX __UINT_LEAST8_MAX__ +#define UINT_LEAST16_MAX __UINT_LEAST16_MAX__ +#define UINT_LEAST32_MAX __UINT_LEAST32_MAX__ +#define UINT_LEAST64_MAX __UINT_LEAST64_MAX__ + +#define INT_LEAST8_MAX __INT_LEAST8_MAX__ +#define INT_LEAST16_MAX __INT_LEAST16_MAX__ +#define INT_LEAST32_MAX __INT_LEAST32_MAX__ +#define INT_LEAST64_MAX __INT_LEAST64_MAX__ + +#define INT_LEAST8_MIN (-INT_LEAST8_MAX - 1) +#define INT_LEAST16_MIN (-INT_LEAST16_MAX - 1) +#define INT_LEAST32_MIN (-INT_LEAST32_MAX - 1) +#define INT_LEAST64_MIN (-INT_LEAST64_MAX - 1) + +typedef __UINT_FAST8_TYPE__ uint_fast8_t; +typedef __UINT_FAST16_TYPE__ uint_fast16_t; +typedef __UINT_FAST32_TYPE__ uint_fast32_t; +typedef __UINT_FAST64_TYPE__ uint_fast64_t; +typedef __INT_FAST8_TYPE__ int_fast8_t; +typedef __INT_FAST16_TYPE__ int_fast16_t; +typedef __INT_FAST32_TYPE__ int_fast32_t; +typedef __INT_FAST64_TYPE__ int_fast64_t; + +#define UINT_FAST8_MAX __UINT_FAST8_MAX__ +#define UINT_FAST16_MAX __UINT_FAST16_MAX__ +#define UINT_FAST32_MAX __UINT_FAST32_MAX__ +#define UINT_FAST64_MAX __UINT_FAST64_MAX__ + +#define INT_FAST8_MAX __INT_FAST8_MAX__ +#define INT_FAST16_MAX __INT_FAST16_MAX__ +#define INT_FAST32_MAX __INT_FAST32_MAX__ +#define INT_FAST64_MAX __INT_FAST64_MAX__ + +#define INT_FAST8_MIN (-INT_FAST8_MAX - 1) +#define INT_FAST16_MIN (-INT_FAST16_MAX - 1) +#define INT_FAST32_MIN (-INT_FAST32_MAX - 1) +#define INT_FAST64_MIN (-INT_FAST64_MAX - 1) + +typedef __INTPTR_TYPE__ intptr_t; +typedef __UINTPTR_TYPE__ uintptr_t; + +#define INTPTR_MAX __INTPTR_MAX__ +#define INTPTR_MIN (-INTPTR_MAX - 1) +#define UINTPTR_MAX __UINTPTR_MAX__ + +typedef __INTMAX_TYPE__ intmax_t; +typedef __UINTMAX_TYPE__ uintmax_t; + +#define INTMAX_MAX __INTMAX_MAX__ +#define INTMAX_MIN (-INTMAX_MAX - 1) +#define UINTMAX_MAX __UINTMAX_MAX__ + +#define SIZE_MAX __SIZE_MAX__ + +// GCC defines __<type>INT<size>_C macros which append the correct suffix +// to an (un)signed integer literal, with <size> being one of 8, 16, 32, 64 +// and MAX, and type being U for unsigned types. The standard stdint.h macros +// with the same names without the leading __ could be implemented in terms of +// these macros. +// +// Clang predefines macros __<type>INT<size>_C_SUFFIX__ which expand to the +// suffix itself. We define the standard stdint.h macros in terms of the GCC +// variants and for Clang we define their equivalents. +#ifndef __INTMAX_C + +#define __int_c_join(a, b) a ## b +#define __int_c(v, suffix) __int_c_join(v, suffix) + +#define __INT8_C(c) __int_c(c, __INT8_C_SUFFIX__) +#define __INT16_C(c) __int_c(c, __INT16_C_SUFFIX__) +#define __INT32_C(c) __int_c(c, __INT32_C_SUFFIX__) +#define __INT64_C(c) __int_c(c, __INT64_C_SUFFIX__) + +#define __UINT8_C(c) __int_c(c, __UINT8_C_SUFFIX__) +#define __UINT16_C(c) __int_c(c, __UINT16_C_SUFFIX__) +#define __UINT32_C(c) __int_c(c, __UINT32_C_SUFFIX__) +#define __UINT64_C(c) __int_c(c, __UINT64_C_SUFFIX__) + +#define __INTMAX_C(c) __int_c(c, __INTMAX_C_SUFFIX__) +#define __UINTMAX_C(c) __int_c(c, __UINTMAX_C_SUFFIX__) + +#endif + +#define INT8_C(c) __INT8_C(c) +#define INT16_C(c) __INT16_C(c) +#define INT32_C(c) __INT32_C(c) +#define INT64_C(c) __INT64_C(c) + +#define UINT8_C(c) __UINT8_C(c) +#define UINT16_C(c) __UINT16_C(c) +#define UINT32_C(c) __UINT32_C(c) +#define UINT64_C(c) __UINT64_C(c) + +#define INTMAX_C(c) __INTMAX_C(c) +#define UINTMAX_C(c) __UINTMAX_C(c) diff --git a/bioniccompat/include/sys/capability.h b/bioniccompat/include/sys/capability.h new file mode 100644 index 0000000..c49d103 --- /dev/null +++ b/bioniccompat/include/sys/capability.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SYS_CAPABILITY_H +#define SYS_CAPABILITY_H + +#include <errno.h> + +typedef struct __user_cap_header_struct { + u_int32_t version; + int pid; +} *cap_user_header_t; + +typedef struct __user_cap_data_struct { + u_int32_t effective; + u_int32_t permitted; + u_int32_t inheritable; +} *cap_user_data_t; + +extern "C" inline int capget(cap_user_header_t hdrp, cap_user_data_t datap) { + datap->effective = datap->permitted = datap->inheritable = 0; + return 0; +} + +extern "C" inline int capset(cap_user_header_t hdrp, const cap_user_data_t datap) { + errno = EPERM; + return -1; +} + +#endif // SYS_CAPABILITY_H diff --git a/bioniccompat/include/sys/cdefs.h b/bioniccompat/include/sys/cdefs.h new file mode 100644 index 0000000..3f721bf --- /dev/null +++ b/bioniccompat/include/sys/cdefs.h @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2019 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. + */ + +#if defined(__cplusplus) +#define __BEGIN_DECLS extern "C" { +#define __END_DECLS } +#else +#define __BEGIN_DECLS +#define __END_DECLS +#endif diff --git a/bioniccompat/include/sys/compat/mman.h b/bioniccompat/include/sys/compat/mman.h new file mode 100644 index 0000000..9336def --- /dev/null +++ b/bioniccompat/include/sys/compat/mman.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SYS_COMPAT_MMAN_H +#define SYS_COMPAT_MMAN_H + +#include "mman.h" + +// Fuchsia holds all pages in memory, see http://b/119503290 for more. +extern "C" inline int mincore(void *addr __UNUSED, size_t length, unsigned char *vec) { + for(size_t i = 0; i < length; i++) { + vec[i] = 1; + } + return 0; +} + +#endif // SYS_COMPAT_MMAN_H diff --git a/bioniccompat/include/sys/compat/types.h b/bioniccompat/include/sys/compat/types.h new file mode 100644 index 0000000..a477235 --- /dev/null +++ b/bioniccompat/include/sys/compat/types.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SYS_COMPAT_TYPES_H +#define SYS_COMPAT_TYPES_H + +#include <threads.h> +#include <zircon/process.h> + +/* + * Zircon does not define an identifier for thread id. Instead + * we rely on the handle. This is slightly risky as there is a + * chance that other code may replace this handle with a different + * one, so we will need to come up with a better solution in the + * future. In particular, we should revisit when the Zircon team + * determines whether or not to implement actual thread IDs. + */ +extern "C" inline pid_t gettid() { + return zx_thread_self(); +} + +#endif // SYS_COMPAT_TYPES_H diff --git a/bioniccompat/include/sys/prctl.h b/bioniccompat/include/sys/prctl.h new file mode 100644 index 0000000..ec5b127 --- /dev/null +++ b/bioniccompat/include/sys/prctl.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SYS_PRCTL_H +#define SYS_PRCTL_H + +#include <errno.h> + +extern "C" inline int prctl(int option, + unsigned long arg2, + unsigned long arg3, + unsigned long arg4, + unsigned long arg5) { + errno = EINVAL; + return -1; +} + +#endif // SYS_PRCTL_H diff --git a/bioniccompat/include/sys/resource.h b/bioniccompat/include/sys/resource.h new file mode 100644 index 0000000..bc4cab1 --- /dev/null +++ b/bioniccompat/include/sys/resource.h @@ -0,0 +1,44 @@ + +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SYS_RESOURCE_H +#define SYS_RESOURCE_H + +typedef unsigned long rlim_t; + +#define RLIM_INFINITY ((rlim_t) -1) + +struct rlimit { + rlim_t rlim_cur; + rlim_t rlim_max; +}; + +/* + * Fuchsia has no concept of resource limits yet. Tell the system that + * usage is unlimited (no soft or hard cap). + */ +extern "C" inline int getrlimit(int resource, struct rlimit *rlim) { + if (!rlim) { + errno = EINVAL; + return -1; + } + rlim->rlim_cur = RLIM_INFINITY; + rlim->rlim_max = RLIM_INFINITY; + return 0; +} + +#endif // SYS_RESOURCE_H diff --git a/bioniccompat/include/sys/sendfile.h b/bioniccompat/include/sys/sendfile.h new file mode 100644 index 0000000..80e2878 --- /dev/null +++ b/bioniccompat/include/sys/sendfile.h @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SYS_SENDFILE_H +#define SYS_SENDFILE_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <sys/cdefs.h> +#include <sys/types.h> + +/* + * sendfile() here is a relatively straightforward implementation, but + * obviously not as efficient as the typical syscall implementation which + * does not require buffers be transferred to userspace and can take + * advantage of DMA vectored I/O. + */ +ssize_t sendfile(int out_fd, int in_fd, off_t* offset, size_t count); + +#ifdef __cplusplus +} +#endif + +#endif // SYS_SENDFILE_H diff --git a/bioniccompat/include/sys/xattr.h b/bioniccompat/include/sys/xattr.h new file mode 100644 index 0000000..77674ca --- /dev/null +++ b/bioniccompat/include/sys/xattr.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SYS_XATTR_H +#define SYS_XATTR_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <errno.h> + +#ifndef ENOATTR +#define ENOATTR ENODATA +#endif + +/* + * Fuchsia does not support extended attirbutes on inodes (yet?), so + * any getxattr implementation will not make much sense. Simply report + * that the requested attribute does not exist and return. + */ +inline ssize_t getxattr(const char* path __UNUSED, const char* name __UNUSED, void* value __UNUSED, size_t size __UNUSED) { + errno = ENOTSUP; + return -1; +} + +inline ssize_t listxattr(const char *path __UNUSED, char *list __UNUSED, size_t size __UNUSED) { + errno = ENOTSUP; + return -1; +} + +inline int setxattr(const char *path __UNUSED, const char *name __UNUSED, const void *value __UNUSED, size_t size __UNUSED, int flags __UNUSED) { + errno = ENOTSUP; + return -1; +} + +inline int removexattr(const char *path __UNUSED, const char *name __UNUSED) { + errno = ENOTSUP; + return -1; +} + +#ifdef __cplusplus +} +#endif + +#endif // SYS_XATTR_H diff --git a/bioniccompat/src/sendfile.cc b/bioniccompat/src/sendfile.cc new file mode 100644 index 0000000..f780aec --- /dev/null +++ b/bioniccompat/src/sendfile.cc @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2019 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 "sys/sendfile.h" + +#include <errno.h> +#include <unistd.h> + +namespace { +// This value is arbitrarily chosen. +constexpr size_t kBufSize = 4096; +} // namespace + +// TODO(ZX-429): This is a painfully simple sendfile implementation that does +// not attempt to optimize for anything and is only provided as something that "works". +ssize_t sendfile(int out_fd, int in_fd, off_t *offset, size_t count) { + // We don't support seek() for now. + if (offset != nullptr) { + errno = ESPIPE; + return -1; + } + + size_t total = 0; + unsigned char buffer[kBufSize]; + while(count > 0) { + int bytes = read(in_fd, buffer, sizeof(buffer)); + if (bytes == 0) { + break; + } + + if (bytes < 0) { + return bytes; + } + + count -= bytes; + + unsigned char *data = buffer; + while(bytes > 0) { + int written = write(out_fd, data, bytes); + if (written < 0) { + return written; + } + + + bytes -= written; + data += written; + total += written; + } + } + + return total; +} |