diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 91612aa30..f0441a1a9 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -23,6 +23,7 @@ workflow: # defines all the stages in the CI, this includes all stages defined inside the included yml files stages: - build + - integration - bindings - wasm - rust diff --git a/.gitlab/issue_templates/new_issue.md b/.gitlab/issue_templates/new_issue.md new file mode 100644 index 000000000..d300ccf80 --- /dev/null +++ b/.gitlab/issue_templates/new_issue.md @@ -0,0 +1,44 @@ +## Summary + +(Summarize the bug encountered concisely) + + +## Is there an open issue + +Please search if there are open issues (same or related) before creating a new one. + +## What is the expected correct behavior? + +(What you should see instead) + +## What is the current bug behavior? + +(What actually happens) + +## Steps to reproduce + +(How one can reproduce the issue - this is very important) + + +## Example Project + +(If possible or relevant, please create an example project here on [git.slock.it/in3/c](https://git.slock.it/in3/c) that exhibits the problematic behaviour, and link to it here in the bug report) + + +## Relevant logs and/or screenshots + +(Paste any relevant logs - please use code blocks (```) to format console output, +logs, and code as it's very hard to read otherwise.) + +## Is there a issue previously reported at sentry? + +Please check if the issue is happening at [incubed-core sentry](https://sentry.slock.it/organizations/slock-it/issues/?project=37) + + +## Possible fixes + +(If you can, link to the line of code that might be responsible for the problem) + +/label ~bug ~reproduced ~needs-investigation +/cc @project-manager +/assign @qa-tester \ No newline at end of file diff --git a/.gitlab/merge_request_templates/new_merge_request.md b/.gitlab/merge_request_templates/new_merge_request.md new file mode 100644 index 000000000..ae30e9f31 --- /dev/null +++ b/.gitlab/merge_request_templates/new_merge_request.md @@ -0,0 +1,54 @@ +## Merge request checklist + +Check if your MR fulfills the following requirements: + +- [ ] Tests for the changes have been added (for bug fixes / features) +- [ ] Docs have been reviewed and added / updated if needed (for bug fixes / features) +- [ ] Build was run locally +- [ ] Gitlab CI pipeline is green +- [ ] Lint has passed locally and any fixes were made for failures +- [ ] Format check clang-format, (ran [format_all.sh](https://git.slock.it/in3/c/in3-core/-/blob/develop/scripts/format_all.sh)) +- [ ] Check for private keys or login info and remove them +- [ ] An example has been added or an existing one has been updated/reviewed if needed (bug fixes / new features / signature changes) +- [ ] Ran all the examples in your local machine. (ci doesn't run them) +- [ ] CHANGELOG.md has been updated. Add one if it does not have it. Add a line per MR +- [ ] Code coverage badge was updated. Add one if it does not have it. + + +## Merge request type + +Do not submit updates to dependencies unless it fixes an issue. also try to limit your pull request to one type, submit multiple pull requests if needed. + +Check the type of change your MR introduces: +- [ ] Bugfix +- [ ] Feature +- [ ] Code style update (formatting, renaming) +- [ ] Refactoring (no functional changes, no api changes) +- [ ] Build related changes +- [ ] Documentation content changes + + +## What is the current behavior? +Describe the current behavior that you are modifying, or link to a relevant issue. + +Issue Number: N/A + + +## What is the new behavior? +Describe the behavior or changes that are being added by this MR. + +- +- +- + +## Does this introduce a breaking change? + +- [ ] Yes +- [ ] No + +If this introduces a breaking change, please describe the impact and migration path for existing applications below. + + +## Other information + +Any other information that is important to this MR such as screenshots of how the component looks before and after the change. diff --git a/.vscode/launch.json b/.vscode/launch.json index 05300a6c5..316a69409 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -164,6 +164,13 @@ "program": "${workspaceFolder}/build/test/test_recorder", "cwd": "${workspaceFolder}/build" }, + { + "type": "lldb", + "request": "launch", + "name": "run request test", + "program": "${workspaceFolder}/build/test/test_request", + "cwd": "${workspaceFolder}/build" + }, { "type": "lldb", "request": "launch", diff --git a/c/ci-analyse.yml b/c/ci-analyse.yml index 7cd65e6ba..6dc035212 100644 --- a/c/ci-analyse.yml +++ b/c/ci-analyse.yml @@ -33,7 +33,7 @@ clangcheck: extends: .only_full allow_failure: false tags: - - short-jobs + - long-jobs script: - mkdir _build - cd _build diff --git a/c/ci.yml b/c/ci.yml index d0f081b74..01704aeb1 100644 --- a/c/ci.yml +++ b/c/ci.yml @@ -267,17 +267,17 @@ examples_macos: integration_longrun: - stage: test + stage: integration extends: .only_release trigger: project: qa/long-run strategy: depend branch: develop -integration_browsertest: - stage: test +integration_browser: + stage: integration extends: .only_release trigger: project: in3/ts/browser-test strategy: depend - branch: 2-release-branch-test \ No newline at end of file + branch: develop \ No newline at end of file diff --git a/c/src/cmd/in3/main.c b/c/src/cmd/in3/main.c index 56f9639da..ab938868b 100644 --- a/c/src/cmd/in3/main.c +++ b/c/src/cmd/in3/main.c @@ -90,7 +90,7 @@ void show_help(char* name) { recorder_print(0, "Usage: %s method ... \n\ \n\ --c, -chain the chain to use. (mainnet,kovan,tobalaba,goerli,local or any RPCURL)\n\ +-c, -chain the chain to use. (mainnet,ewc,goerli,local or any RPCURL)\n\ -a max number of attempts before giving up (default 5)\n\ -rc number of request per try (default 1)\n\ -ns no stats if set requests will not be part of the official metrics and considered a service request\n\ @@ -359,7 +359,6 @@ bytes_t* get_std_in() { // convert the name to a chain_id uint64_t getchain_id(char* name) { if (strcmp(name, "mainnet") == 0) return CHAIN_ID_MAINNET; - if (strcmp(name, "kovan") == 0) return CHAIN_ID_KOVAN; if (strcmp(name, "goerli") == 0) return CHAIN_ID_GOERLI; if (strcmp(name, "ewc") == 0) return CHAIN_ID_EWC; if (strcmp(name, "ipfs") == 0) return CHAIN_ID_IPFS; diff --git a/c/src/core/client/context.c b/c/src/core/client/context.c index 85b640b08..4cae82b67 100644 --- a/c/src/core/client/context.c +++ b/c/src/core/client/context.c @@ -161,8 +161,9 @@ in3_ret_t ctx_set_error_intern(in3_ctx_t* ctx, char* message, in3_ret_t errnumbe dst = _malloc(l + 1); strcpy(dst, message); } - ctx->error = dst; - error_log_ctx_t sctx = {.msg = message, .error = -errnumber}; + ctx->error = dst; + + error_log_ctx_t sctx = {.msg = message, .error = -errnumber, .ctx = ctx}; in3_plugin_execute_first_or_none(ctx, PLGN_ACT_LOG_ERROR, &sctx); in3_log_trace("Intermediate error -> %s\n", message); diff --git a/c/src/core/client/plugin.h b/c/src/core/client/plugin.h index 6cfc4af64..9b68d0dc7 100644 --- a/c/src/core/client/plugin.h +++ b/c/src/core/client/plugin.h @@ -387,8 +387,9 @@ typedef struct { } in3_pay_sign_req_ctx_t; typedef struct { - char* msg; /**< the error message. */ - uint16_t error; /**< error code. */ + char* msg; /**< the error message. */ + uint16_t error; /**< error code. */ + in3_ctx_t* ctx; /**< ctx . */ } error_log_ctx_t; #endif diff --git a/c/src/core/util/data.c b/c/src/core/util/data.c index bc8bbc428..8e8f51208 100644 --- a/c/src/core/util/data.c +++ b/c/src/core/util/data.c @@ -184,6 +184,7 @@ int d_bytes_to(d_token_t* item, uint8_t* dst, const int max_size) { return 1; case T_INTEGER: val = item->len & 0xFFFFFFF; + l = 0; if (max == -1) max = val & 0xFF000000 ? 4 : (val & 0xFF0000 ? 3 : (val & 0xFF00 ? 2 : 1)); for (i = max < 3 ? max : 3; i >= 0; i--) { if (val & 0xFF << (i << 3)) { @@ -198,6 +199,10 @@ int d_bytes_to(d_token_t* item, uint8_t* dst, const int max_size) { return l; } } + if (l == 0) { + memset(dst, 0, max); + return 1; + } break; default: break; diff --git a/c/src/third-party/sentry-native/external/crashpad/third_party/lss/lss/README.md b/c/src/third-party/sentry-native/external/crashpad/third_party/lss/lss/README.md new file mode 100644 index 000000000..70cbc8531 --- /dev/null +++ b/c/src/third-party/sentry-native/external/crashpad/third_party/lss/lss/README.md @@ -0,0 +1,137 @@ +# Linux Syscall Support (LSS) + +Every so often, projects need to directly embed Linux system calls instead of +calling the implementations in the system runtime library. + +This project provides a header file that can be included into your application +whenever you need to make direct system calls. + +The goal is to provide an API that generally mirrors the standard C library +while still making direct syscalls. We try to hide some of the differences +between arches when reasonably feasible. e.g. Newer architectures no longer +provide an `open` syscall, but do provide `openat`. We will still expose a +`sys_open` helper by default that calls into `openat` instead. + +We explicitly do not expose the raw syscall ABI including all of its historical +warts to the user. We want people to be able to easily make a syscall, not have +to worry that on some arches size args are swapped or they are shifted. + +Please be sure to review the Caveats section below however. + +## How to include linux\_syscall\_support.h in your project + +You can either copy the file into your project, or preferably, you can set up +Git submodules to automatically pull from our source repository. + +## Supported targets + +The following architectures/ABIs have been tested (at some point) and should +generally work. If you don't see your combo listed here, please double check +the header itself as this list might be out of date. + +* x86 32-bit (i.e. i386, i486, i586, i686, Intel, AMD, etc...) +* [x86_64 64-bit](https://en.wikipedia.org/wiki/X86-64) (i.e. x86-64, amd64, etc...) +* [x32 32-bit](https://sites.google.com/site/x32abi/) +* [ARM 32-bit](https://en.wikipedia.org/wiki/ARM_architecture) OABI +* [ARM 32-bit](https://en.wikipedia.org/wiki/ARM_architecture) EABI (i.e. armv6, armv7, etc...) +* AARCH64 64-bit (i.e. arm64, armv8, etc...) +* PowerPC 32-bit (i.e. ppc, ppc32, etc...) +* MIPS 32-bit o32 ABI +* MIPS 32-bit n32 ABI +* MIPS 64-bit n64 ABI + +## API + +By default, you can just add a `sys_` prefix to any function you want to call. +So if you want to call `open(...)`, use `sys_open(...)` instead. + +### Knobs + +The linux\_syscall\_support.h header provides many knobs for you to control +the exported API. These are all documented in the top of the header in a big +comment block, so refer to that instead. + +## Caveats + +### ABI differences + +Some functions that the standard C library exposes use a different ABI than +what the Linux kernel uses. Care must be taken when making syscalls directly +that you use the right structure and flags. e.g. Most C libraries define a +`struct stat` (commonly in `sys/stat.h` or `bits/stat.h`) that is different +from the `struct stat` the kernel uses (commonly in `asm/stat.h`). If you use +the wrong structure layout, then you can see errors like memory corruption or +weird/shifted values. If you plan on making syscalls directly, you should +focus on headers that are available under the `linux/` and `asm/` namespaces. + +Note: LSS provides structs for most of these cases. For `sys_stat()`, it +provides `struct kernel_stat` for you to use. + +### Transparent backwards compatibility with older kernels + +While some C libraries (notably, glibc) take care to fallback to older syscalls +when running on older kernels, there is no such support in LSS. If you plan on +trying to run on older kernels, you will need to handle errors yourself (e.g. +`ENOSYS` when using a too new syscall). + +Remember that this can happen with new flag bits too. e.g. The `O_CLOEXEC` +flag was added to many syscalls, but if you try to run use it on older kernels, +it will fail with `EINVAL`. In that case, you must handle the fallback logic +yourself. + +### Variable arguments (varargs) + +We do not support vararg type functions. e.g. While the standard `open()` +function can accept 2 or 3 arguments (with the mode field being optional), +the `sys_open()` function always requires 3 arguments. + +## Bug reports & feature requests + +If you wish to report a problem or request a feature, please file them in our +[bug tracker](https://bugs.chromium.org/p/linux-syscall-support/issues/). + +Please do not post patches to the tracker. Instead, see below for how to send +patches to us directly. + +While we welcome feature requests, please keep in mind that it is unlikely that +anyone will find time to implement them for you. Sending patches is strongly +preferred and will often move things much faster. + +## Projects that use LSS + +* [Chromium](https://www.chromium.org/) +* [Breakpad](https://chromium.googlesource.com/breakpad/breakpad) +* [Native Client](https://developer.chrome.com/native-client), in nacl\_bootstrap.c + +## How to get an LSS change committed + +### Review + +You get your change reviewed, you can upload it to +[Gerrit](https://chromium-review.googlesource.com/q/project:linux-syscall-support+status:open) +using `git cl upload` from +[Chromium's depot-tools](https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html). + +### Testing + +Tests are found in the [tests/](./tests/) subdirectory. It does not (yet) offer +100% coverage, but should grow over time. + +New commits that update/change/add syscall wrappers should include tests for +them too. Consult the [test documentation](./tests/README.md) for more details. + +To run, just run `make` inside the tests directory. It will compile & execute +the tests locally. + +There is some limited cross-compile coverage available if you run `make cross`. +It only compiles things (does not execute at all). + +### Rolling into Chromium + +If you commit a change to LSS, please also commit a Chromium change to update +`lss_revision` in +[Chromium's DEPS](https://chromium.googlesource.com/chromium/src/+/master/DEPS) +file. + +This ensures that the LSS change gets tested, so that people who commit later +LSS changes don't run into problems with updating `lss_revision`. diff --git a/c/src/third-party/sentry-native/external/crashpad/third_party/lss/lss/codereview.settings b/c/src/third-party/sentry-native/external/crashpad/third_party/lss/lss/codereview.settings new file mode 100644 index 000000000..b5082e8d3 --- /dev/null +++ b/c/src/third-party/sentry-native/external/crashpad/third_party/lss/lss/codereview.settings @@ -0,0 +1,5 @@ +# This file is used by git cl to get repository specific information. +CC_LIST: chromium-reviews@chromium.org,mseaborn@chromium.org +CODE_REVIEW_SERVER: codereview.chromium.org +GERRIT_HOST: True +VIEW_VC: https://chromium.googlesource.com/linux-syscall-support/+/ diff --git a/c/src/third-party/sentry-native/external/crashpad/third_party/lss/lss/linux_syscall_support.h b/c/src/third-party/sentry-native/external/crashpad/third_party/lss/lss/linux_syscall_support.h new file mode 100644 index 000000000..be7ea9d50 --- /dev/null +++ b/c/src/third-party/sentry-native/external/crashpad/third_party/lss/lss/linux_syscall_support.h @@ -0,0 +1,4533 @@ +/* Copyright (c) 2005-2011, Google Inc. + * 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. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * 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. + * + * --- + * Author: Markus Gutschke + */ + +/* This file includes Linux-specific support functions common to the + * coredumper and the thread lister; primarily, this is a collection + * of direct system calls, and a couple of symbols missing from + * standard header files. + * There are a few options that the including file can set to control + * the behavior of this file: + * + * SYS_CPLUSPLUS: + * The entire header file will normally be wrapped in 'extern "C" { }", + * making it suitable for compilation as both C and C++ source. If you + * do not want to do this, you can set the SYS_CPLUSPLUS macro to inhibit + * the wrapping. N.B. doing so will suppress inclusion of all prerequisite + * system header files, too. It is the caller's responsibility to provide + * the necessary definitions. + * + * SYS_ERRNO: + * All system calls will update "errno" unless overriden by setting the + * SYS_ERRNO macro prior to including this file. SYS_ERRNO should be + * an l-value. + * + * SYS_INLINE: + * New symbols will be defined "static inline", unless overridden by + * the SYS_INLINE macro. + * + * SYS_LINUX_SYSCALL_SUPPORT_H + * This macro is used to avoid multiple inclusions of this header file. + * If you need to include this file more than once, make sure to + * unset SYS_LINUX_SYSCALL_SUPPORT_H before each inclusion. + * + * SYS_PREFIX: + * New system calls will have a prefix of "sys_" unless overridden by + * the SYS_PREFIX macro. Valid values for this macro are [0..9] which + * results in prefixes "sys[0..9]_". It is also possible to set this + * macro to -1, which avoids all prefixes. + * + * SYS_SYSCALL_ENTRYPOINT: + * Some applications (such as sandboxes that filter system calls), need + * to be able to run custom-code each time a system call is made. If this + * macro is defined, it expands to the name of a "common" symbol. If + * this symbol is assigned a non-NULL pointer value, it is used as the + * address of the system call entrypoint. + * A pointer to this symbol can be obtained by calling + * get_syscall_entrypoint() + * + * This file defines a few internal symbols that all start with "LSS_". + * Do not access these symbols from outside this file. They are not part + * of the supported API. + */ +#ifndef SYS_LINUX_SYSCALL_SUPPORT_H +#define SYS_LINUX_SYSCALL_SUPPORT_H + +/* We currently only support x86-32, x86-64, ARM, MIPS, PPC, s390 and s390x + * on Linux. + * Porting to other related platforms should not be difficult. + */ +#if (defined(__i386__) || defined(__x86_64__) || defined(__ARM_ARCH_3__) || \ + defined(__mips__) || defined(__PPC__) || defined(__ARM_EABI__) || \ + defined(__aarch64__) || defined(__s390__)) \ + && (defined(__linux) || defined(__ANDROID__)) + +#ifndef SYS_CPLUSPLUS +#ifdef __cplusplus +/* Some system header files in older versions of gcc neglect to properly + * handle being included from C++. As it appears to be harmless to have + * multiple nested 'extern "C"' blocks, just add another one here. + */ +extern "C" { +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef __mips__ +/* Include definitions of the ABI currently in use. */ +#ifdef __ANDROID__ +/* Android doesn't have sgidefs.h, but does have asm/sgidefs.h, + * which has the definitions we need. + */ +#include +#else +#include +#endif +#endif +#endif + +/* Some libcs, for example Android NDK and musl, #define these + * macros as aliases to their non-64 counterparts. To avoid naming + * conflict, remove them. + * + * These are restored by the corresponding #pragma pop_macro near + * the end of this file. + */ +#pragma push_macro("stat64") +#pragma push_macro("fstat64") +#pragma push_macro("lstat64") +#pragma push_macro("pread64") +#pragma push_macro("pwrite64") +#undef stat64 +#undef fstat64 +#undef lstat64 +#undef pread64 +#undef pwrite64 + +#if defined(__ANDROID__) && defined(__x86_64__) +// A number of x86_64 syscalls are blocked by seccomp on recent Android; +// undefine them so that modern alternatives will be used instead where +// possible. +// The alternative syscalls have been sanity checked against linux-3.4+; +// older versions might not work. +# undef __NR_getdents +# undef __NR_dup2 +# undef __NR_fork +# undef __NR_getpgrp +# undef __NR_open +# undef __NR_poll +# undef __NR_readlink +# undef __NR_stat +# undef __NR_unlink +# undef __NR_pipe +#endif + +#if defined(__ANDROID__) +// waitpid is blocked by seccomp on all architectures on recent Android. +# undef __NR_waitpid +#endif + +/* As glibc often provides subtly incompatible data structures (and implicit + * wrapper functions that convert them), we provide our own kernel data + * structures for use by the system calls. + * These structures have been developed by using Linux 2.6.23 headers for + * reference. Note though, we do not care about exact API compatibility + * with the kernel, and in fact the kernel often does not have a single + * API that works across architectures. Instead, we try to mimic the glibc + * API where reasonable, and only guarantee ABI compatibility with the + * kernel headers. + * Most notably, here are a few changes that were made to the structures + * defined by kernel headers: + * + * - we only define structures, but not symbolic names for kernel data + * types. For the latter, we directly use the native C datatype + * (i.e. "unsigned" instead of "mode_t"). + * - in a few cases, it is possible to define identical structures for + * both 32bit (e.g. i386) and 64bit (e.g. x86-64) platforms by + * standardizing on the 64bit version of the data types. In particular, + * this means that we use "unsigned" where the 32bit headers say + * "unsigned long". + * - overall, we try to minimize the number of cases where we need to + * conditionally define different structures. + * - the "struct kernel_sigaction" class of structures have been + * modified to more closely mimic glibc's API by introducing an + * anonymous union for the function pointer. + * - a small number of field names had to have an underscore appended to + * them, because glibc defines a global macro by the same name. + */ + +/* include/linux/dirent.h */ +struct kernel_dirent64 { + unsigned long long d_ino; + long long d_off; + unsigned short d_reclen; + unsigned char d_type; + char d_name[256]; +}; + +/* include/linux/dirent.h */ +#if !defined(__NR_getdents) +// when getdents is not available, getdents64 is used for both. +#define kernel_dirent kernel_dirent64 +#else +struct kernel_dirent { + long d_ino; + long d_off; + unsigned short d_reclen; + char d_name[256]; +}; +#endif + +/* include/linux/uio.h */ +struct kernel_iovec { + void *iov_base; + unsigned long iov_len; +}; + +/* include/linux/socket.h */ +struct kernel_msghdr { + void *msg_name; + int msg_namelen; + struct kernel_iovec*msg_iov; + unsigned long msg_iovlen; + void *msg_control; + unsigned long msg_controllen; + unsigned msg_flags; +}; + +/* include/asm-generic/poll.h */ +struct kernel_pollfd { + int fd; + short events; + short revents; +}; + +/* include/linux/resource.h */ +struct kernel_rlimit { + unsigned long rlim_cur; + unsigned long rlim_max; +}; + +/* include/linux/time.h */ +struct kernel_timespec { + long tv_sec; + long tv_nsec; +}; + +/* include/linux/time.h */ +struct kernel_timeval { + long tv_sec; + long tv_usec; +}; + +/* include/linux/resource.h */ +struct kernel_rusage { + struct kernel_timeval ru_utime; + struct kernel_timeval ru_stime; + long ru_maxrss; + long ru_ixrss; + long ru_idrss; + long ru_isrss; + long ru_minflt; + long ru_majflt; + long ru_nswap; + long ru_inblock; + long ru_oublock; + long ru_msgsnd; + long ru_msgrcv; + long ru_nsignals; + long ru_nvcsw; + long ru_nivcsw; +}; + +#if defined(__i386__) || defined(__ARM_EABI__) || defined(__ARM_ARCH_3__) \ + || defined(__PPC__) || (defined(__s390__) && !defined(__s390x__)) + +/* include/asm-{arm,i386,mips,ppc}/signal.h */ +struct kernel_old_sigaction { + union { + void (*sa_handler_)(int); + void (*sa_sigaction_)(int, siginfo_t *, void *); + }; + unsigned long sa_mask; + unsigned long sa_flags; + void (*sa_restorer)(void); +} __attribute__((packed,aligned(4))); +#elif (defined(__mips__) && _MIPS_SIM == _MIPS_SIM_ABI32) + #define kernel_old_sigaction kernel_sigaction +#elif defined(__aarch64__) + // No kernel_old_sigaction defined for arm64. +#endif + +/* Some kernel functions (e.g. sigaction() in 2.6.23) require that the + * exactly match the size of the signal set, even though the API was + * intended to be extensible. We define our own KERNEL_NSIG to deal with + * this. + * Please note that glibc provides signals [1.._NSIG-1], whereas the + * kernel (and this header) provides the range [1..KERNEL_NSIG]. The + * actual number of signals is obviously the same, but the constants + * differ by one. + */ +#ifdef __mips__ +#define KERNEL_NSIG 128 +#else +#define KERNEL_NSIG 64 +#endif + +/* include/asm-{arm,aarch64,i386,mips,x86_64}/signal.h */ +struct kernel_sigset_t { + unsigned long sig[(KERNEL_NSIG + 8*sizeof(unsigned long) - 1)/ + (8*sizeof(unsigned long))]; +}; + +/* include/asm-{arm,i386,mips,x86_64,ppc}/signal.h */ +struct kernel_sigaction { +#ifdef __mips__ + unsigned long sa_flags; + union { + void (*sa_handler_)(int); + void (*sa_sigaction_)(int, siginfo_t *, void *); + }; + struct kernel_sigset_t sa_mask; +#else + union { + void (*sa_handler_)(int); + void (*sa_sigaction_)(int, siginfo_t *, void *); + }; + unsigned long sa_flags; + void (*sa_restorer)(void); + struct kernel_sigset_t sa_mask; +#endif +}; + +/* include/linux/socket.h */ +struct kernel_sockaddr { + unsigned short sa_family; + char sa_data[14]; +}; + +/* include/asm-{arm,aarch64,i386,mips,ppc,s390}/stat.h */ +#ifdef __mips__ +#if _MIPS_SIM == _MIPS_SIM_ABI64 +struct kernel_stat { +#else +struct kernel_stat64 { +#endif + unsigned st_dev; + unsigned __pad0[3]; + unsigned long long st_ino; + unsigned st_mode; + unsigned st_nlink; + unsigned st_uid; + unsigned st_gid; + unsigned st_rdev; + unsigned __pad1[3]; + long long st_size; + unsigned st_atime_; + unsigned st_atime_nsec_; + unsigned st_mtime_; + unsigned st_mtime_nsec_; + unsigned st_ctime_; + unsigned st_ctime_nsec_; + unsigned st_blksize; + unsigned __pad2; + unsigned long long st_blocks; +}; +#elif defined __PPC__ +struct kernel_stat64 { + unsigned long long st_dev; + unsigned long long st_ino; + unsigned st_mode; + unsigned st_nlink; + unsigned st_uid; + unsigned st_gid; + unsigned long long st_rdev; + unsigned short int __pad2; + long long st_size; + long st_blksize; + long long st_blocks; + long st_atime_; + unsigned long st_atime_nsec_; + long st_mtime_; + unsigned long st_mtime_nsec_; + long st_ctime_; + unsigned long st_ctime_nsec_; + unsigned long __unused4; + unsigned long __unused5; +}; +#else +struct kernel_stat64 { + unsigned long long st_dev; + unsigned char __pad0[4]; + unsigned __st_ino; + unsigned st_mode; + unsigned st_nlink; + unsigned st_uid; + unsigned st_gid; + unsigned long long st_rdev; + unsigned char __pad3[4]; + long long st_size; + unsigned st_blksize; + unsigned long long st_blocks; + unsigned st_atime_; + unsigned st_atime_nsec_; + unsigned st_mtime_; + unsigned st_mtime_nsec_; + unsigned st_ctime_; + unsigned st_ctime_nsec_; + unsigned long long st_ino; +}; +#endif + +/* include/asm-{arm,aarch64,i386,mips,x86_64,ppc,s390}/stat.h */ +#if defined(__i386__) || defined(__ARM_ARCH_3__) || defined(__ARM_EABI__) +struct kernel_stat { + /* The kernel headers suggest that st_dev and st_rdev should be 32bit + * quantities encoding 12bit major and 20bit minor numbers in an interleaved + * format. In reality, we do not see useful data in the top bits. So, + * we'll leave the padding in here, until we find a better solution. + */ + unsigned short st_dev; + short pad1; + unsigned st_ino; + unsigned short st_mode; + unsigned short st_nlink; + unsigned short st_uid; + unsigned short st_gid; + unsigned short st_rdev; + short pad2; + unsigned st_size; + unsigned st_blksize; + unsigned st_blocks; + unsigned st_atime_; + unsigned st_atime_nsec_; + unsigned st_mtime_; + unsigned st_mtime_nsec_; + unsigned st_ctime_; + unsigned st_ctime_nsec_; + unsigned __unused4; + unsigned __unused5; +}; +#elif defined(__x86_64__) +struct kernel_stat { + uint64_t st_dev; + uint64_t st_ino; + uint64_t st_nlink; + unsigned st_mode; + unsigned st_uid; + unsigned st_gid; + unsigned __pad0; + uint64_t st_rdev; + int64_t st_size; + int64_t st_blksize; + int64_t st_blocks; + uint64_t st_atime_; + uint64_t st_atime_nsec_; + uint64_t st_mtime_; + uint64_t st_mtime_nsec_; + uint64_t st_ctime_; + uint64_t st_ctime_nsec_; + int64_t __unused4[3]; +}; +#elif defined(__PPC__) +struct kernel_stat { + unsigned st_dev; + unsigned long st_ino; // ino_t + unsigned long st_mode; // mode_t + unsigned short st_nlink; // nlink_t + unsigned st_uid; // uid_t + unsigned st_gid; // gid_t + unsigned st_rdev; + long st_size; // off_t + unsigned long st_blksize; + unsigned long st_blocks; + unsigned long st_atime_; + unsigned long st_atime_nsec_; + unsigned long st_mtime_; + unsigned long st_mtime_nsec_; + unsigned long st_ctime_; + unsigned long st_ctime_nsec_; + unsigned long __unused4; + unsigned long __unused5; +}; +#elif (defined(__mips__) && _MIPS_SIM != _MIPS_SIM_ABI64) +struct kernel_stat { + unsigned st_dev; + int st_pad1[3]; + unsigned st_ino; + unsigned st_mode; + unsigned st_nlink; + unsigned st_uid; + unsigned st_gid; + unsigned st_rdev; + int st_pad2[2]; + long st_size; + int st_pad3; + long st_atime_; + long st_atime_nsec_; + long st_mtime_; + long st_mtime_nsec_; + long st_ctime_; + long st_ctime_nsec_; + int st_blksize; + int st_blocks; + int st_pad4[14]; +}; +#elif defined(__aarch64__) +struct kernel_stat { + unsigned long st_dev; + unsigned long st_ino; + unsigned int st_mode; + unsigned int st_nlink; + unsigned int st_uid; + unsigned int st_gid; + unsigned long st_rdev; + unsigned long __pad1; + long st_size; + int st_blksize; + int __pad2; + long st_blocks; + long st_atime_; + unsigned long st_atime_nsec_; + long st_mtime_; + unsigned long st_mtime_nsec_; + long st_ctime_; + unsigned long st_ctime_nsec_; + unsigned int __unused4; + unsigned int __unused5; +}; +#elif defined(__s390x__) +struct kernel_stat { + unsigned long st_dev; + unsigned long st_ino; + unsigned long st_nlink; + unsigned int st_mode; + unsigned int st_uid; + unsigned int st_gid; + unsigned int __pad1; + unsigned long st_rdev; + unsigned long st_size; + unsigned long st_atime_; + unsigned long st_atime_nsec_; + unsigned long st_mtime_; + unsigned long st_mtime_nsec_; + unsigned long st_ctime_; + unsigned long st_ctime_nsec_; + unsigned long st_blksize; + long st_blocks; + unsigned long __unused[3]; +}; +#elif defined(__s390__) +struct kernel_stat { + unsigned short st_dev; + unsigned short __pad1; + unsigned long st_ino; + unsigned short st_mode; + unsigned short st_nlink; + unsigned short st_uid; + unsigned short st_gid; + unsigned short st_rdev; + unsigned short __pad2; + unsigned long st_size; + unsigned long st_blksize; + unsigned long st_blocks; + unsigned long st_atime_; + unsigned long st_atime_nsec_; + unsigned long st_mtime_; + unsigned long st_mtime_nsec_; + unsigned long st_ctime_; + unsigned long st_ctime_nsec_; + unsigned long __unused4; + unsigned long __unused5; +}; +#endif + +/* include/asm-{arm,aarch64,i386,mips,x86_64,ppc,s390}/statfs.h */ +#ifdef __mips__ +#if _MIPS_SIM != _MIPS_SIM_ABI64 +struct kernel_statfs64 { + unsigned long f_type; + unsigned long f_bsize; + unsigned long f_frsize; + unsigned long __pad; + unsigned long long f_blocks; + unsigned long long f_bfree; + unsigned long long f_files; + unsigned long long f_ffree; + unsigned long long f_bavail; + struct { int val[2]; } f_fsid; + unsigned long f_namelen; + unsigned long f_spare[6]; +}; +#endif +#elif defined(__s390__) +/* See also arch/s390/include/asm/compat.h */ +struct kernel_statfs64 { + unsigned int f_type; + unsigned int f_bsize; + unsigned long long f_blocks; + unsigned long long f_bfree; + unsigned long long f_bavail; + unsigned long long f_files; + unsigned long long f_ffree; + struct { int val[2]; } f_fsid; + unsigned int f_namelen; + unsigned int f_frsize; + unsigned int f_flags; + unsigned int f_spare[4]; +}; +#elif !defined(__x86_64__) +struct kernel_statfs64 { + unsigned long f_type; + unsigned long f_bsize; + unsigned long long f_blocks; + unsigned long long f_bfree; + unsigned long long f_bavail; + unsigned long long f_files; + unsigned long long f_ffree; + struct { int val[2]; } f_fsid; + unsigned long f_namelen; + unsigned long f_frsize; + unsigned long f_spare[5]; +}; +#endif + +/* include/asm-{arm,i386,mips,x86_64,ppc,generic,s390}/statfs.h */ +#ifdef __mips__ +struct kernel_statfs { + long f_type; + long f_bsize; + long f_frsize; + long f_blocks; + long f_bfree; + long f_files; + long f_ffree; + long f_bavail; + struct { int val[2]; } f_fsid; + long f_namelen; + long f_spare[6]; +}; +#elif defined(__x86_64__) +struct kernel_statfs { + /* x86_64 actually defines all these fields as signed, whereas all other */ + /* platforms define them as unsigned. Leaving them at unsigned should not */ + /* cause any problems. Make sure these are 64-bit even on x32. */ + uint64_t f_type; + uint64_t f_bsize; + uint64_t f_blocks; + uint64_t f_bfree; + uint64_t f_bavail; + uint64_t f_files; + uint64_t f_ffree; + struct { int val[2]; } f_fsid; + uint64_t f_namelen; + uint64_t f_frsize; + uint64_t f_spare[5]; +}; +#elif defined(__s390__) +struct kernel_statfs { + unsigned int f_type; + unsigned int f_bsize; + unsigned long f_blocks; + unsigned long f_bfree; + unsigned long f_bavail; + unsigned long f_files; + unsigned long f_ffree; + struct { int val[2]; } f_fsid; + unsigned int f_namelen; + unsigned int f_frsize; + unsigned int f_flags; + unsigned int f_spare[4]; +}; +#else +struct kernel_statfs { + unsigned long f_type; + unsigned long f_bsize; + unsigned long f_blocks; + unsigned long f_bfree; + unsigned long f_bavail; + unsigned long f_files; + unsigned long f_ffree; + struct { int val[2]; } f_fsid; + unsigned long f_namelen; + unsigned long f_frsize; + unsigned long f_spare[5]; +}; +#endif + + +/* Definitions missing from the standard header files */ +#ifndef O_DIRECTORY +#if defined(__ARM_ARCH_3__) || defined(__ARM_EABI__) || defined(__aarch64__) +#define O_DIRECTORY 0040000 +#else +#define O_DIRECTORY 0200000 +#endif +#endif +#ifndef NT_PRXFPREG +#define NT_PRXFPREG 0x46e62b7f +#endif +#ifndef PTRACE_GETFPXREGS +#define PTRACE_GETFPXREGS ((enum __ptrace_request)18) +#endif +#ifndef PR_GET_DUMPABLE +#define PR_GET_DUMPABLE 3 +#endif +#ifndef PR_SET_DUMPABLE +#define PR_SET_DUMPABLE 4 +#endif +#ifndef PR_GET_SECCOMP +#define PR_GET_SECCOMP 21 +#endif +#ifndef PR_SET_SECCOMP +#define PR_SET_SECCOMP 22 +#endif +#ifndef AT_FDCWD +#define AT_FDCWD (-100) +#endif +#ifndef AT_SYMLINK_NOFOLLOW +#define AT_SYMLINK_NOFOLLOW 0x100 +#endif +#ifndef AT_REMOVEDIR +#define AT_REMOVEDIR 0x200 +#endif +#ifndef MREMAP_FIXED +#define MREMAP_FIXED 2 +#endif +#ifndef SA_RESTORER +#define SA_RESTORER 0x04000000 +#endif +#ifndef CPUCLOCK_PROF +#define CPUCLOCK_PROF 0 +#endif +#ifndef CPUCLOCK_VIRT +#define CPUCLOCK_VIRT 1 +#endif +#ifndef CPUCLOCK_SCHED +#define CPUCLOCK_SCHED 2 +#endif +#ifndef CPUCLOCK_PERTHREAD_MASK +#define CPUCLOCK_PERTHREAD_MASK 4 +#endif +#ifndef MAKE_PROCESS_CPUCLOCK +#define MAKE_PROCESS_CPUCLOCK(pid, clock) \ + ((int)(~(unsigned)(pid) << 3) | (int)(clock)) +#endif +#ifndef MAKE_THREAD_CPUCLOCK +#define MAKE_THREAD_CPUCLOCK(tid, clock) \ + ((int)(~(unsigned)(tid) << 3) | \ + (int)((clock) | CPUCLOCK_PERTHREAD_MASK)) +#endif + +#ifndef FUTEX_WAIT +#define FUTEX_WAIT 0 +#endif +#ifndef FUTEX_WAKE +#define FUTEX_WAKE 1 +#endif +#ifndef FUTEX_FD +#define FUTEX_FD 2 +#endif +#ifndef FUTEX_REQUEUE +#define FUTEX_REQUEUE 3 +#endif +#ifndef FUTEX_CMP_REQUEUE +#define FUTEX_CMP_REQUEUE 4 +#endif +#ifndef FUTEX_WAKE_OP +#define FUTEX_WAKE_OP 5 +#endif +#ifndef FUTEX_LOCK_PI +#define FUTEX_LOCK_PI 6 +#endif +#ifndef FUTEX_UNLOCK_PI +#define FUTEX_UNLOCK_PI 7 +#endif +#ifndef FUTEX_TRYLOCK_PI +#define FUTEX_TRYLOCK_PI 8 +#endif +#ifndef FUTEX_PRIVATE_FLAG +#define FUTEX_PRIVATE_FLAG 128 +#endif +#ifndef FUTEX_CMD_MASK +#define FUTEX_CMD_MASK ~FUTEX_PRIVATE_FLAG +#endif +#ifndef FUTEX_WAIT_PRIVATE +#define FUTEX_WAIT_PRIVATE (FUTEX_WAIT | FUTEX_PRIVATE_FLAG) +#endif +#ifndef FUTEX_WAKE_PRIVATE +#define FUTEX_WAKE_PRIVATE (FUTEX_WAKE | FUTEX_PRIVATE_FLAG) +#endif +#ifndef FUTEX_REQUEUE_PRIVATE +#define FUTEX_REQUEUE_PRIVATE (FUTEX_REQUEUE | FUTEX_PRIVATE_FLAG) +#endif +#ifndef FUTEX_CMP_REQUEUE_PRIVATE +#define FUTEX_CMP_REQUEUE_PRIVATE (FUTEX_CMP_REQUEUE | FUTEX_PRIVATE_FLAG) +#endif +#ifndef FUTEX_WAKE_OP_PRIVATE +#define FUTEX_WAKE_OP_PRIVATE (FUTEX_WAKE_OP | FUTEX_PRIVATE_FLAG) +#endif +#ifndef FUTEX_LOCK_PI_PRIVATE +#define FUTEX_LOCK_PI_PRIVATE (FUTEX_LOCK_PI | FUTEX_PRIVATE_FLAG) +#endif +#ifndef FUTEX_UNLOCK_PI_PRIVATE +#define FUTEX_UNLOCK_PI_PRIVATE (FUTEX_UNLOCK_PI | FUTEX_PRIVATE_FLAG) +#endif +#ifndef FUTEX_TRYLOCK_PI_PRIVATE +#define FUTEX_TRYLOCK_PI_PRIVATE (FUTEX_TRYLOCK_PI | FUTEX_PRIVATE_FLAG) +#endif + + +#if defined(__x86_64__) +#ifndef ARCH_SET_GS +#define ARCH_SET_GS 0x1001 +#endif +#ifndef ARCH_GET_GS +#define ARCH_GET_GS 0x1004 +#endif +#endif + +#if defined(__i386__) +#ifndef __NR_quotactl +#define __NR_quotactl 131 +#endif +#ifndef __NR_setresuid +#define __NR_setresuid 164 +#define __NR_getresuid 165 +#define __NR_setresgid 170 +#define __NR_getresgid 171 +#endif +#ifndef __NR_rt_sigaction +#define __NR_rt_sigreturn 173 +#define __NR_rt_sigaction 174 +#define __NR_rt_sigprocmask 175 +#define __NR_rt_sigpending 176 +#define __NR_rt_sigsuspend 179 +#endif +#ifndef __NR_pread64 +#define __NR_pread64 180 +#endif +#ifndef __NR_pwrite64 +#define __NR_pwrite64 181 +#endif +#ifndef __NR_ugetrlimit +#define __NR_ugetrlimit 191 +#endif +#ifndef __NR_stat64 +#define __NR_stat64 195 +#endif +#ifndef __NR_fstat64 +#define __NR_fstat64 197 +#endif +#ifndef __NR_setresuid32 +#define __NR_setresuid32 208 +#define __NR_getresuid32 209 +#define __NR_setresgid32 210 +#define __NR_getresgid32 211 +#endif +#ifndef __NR_setfsuid32 +#define __NR_setfsuid32 215 +#define __NR_setfsgid32 216 +#endif +#ifndef __NR_getdents64 +#define __NR_getdents64 220 +#endif +#ifndef __NR_gettid +#define __NR_gettid 224 +#endif +#ifndef __NR_readahead +#define __NR_readahead 225 +#endif +#ifndef __NR_setxattr +#define __NR_setxattr 226 +#endif +#ifndef __NR_lsetxattr +#define __NR_lsetxattr 227 +#endif +#ifndef __NR_getxattr +#define __NR_getxattr 229 +#endif +#ifndef __NR_lgetxattr +#define __NR_lgetxattr 230 +#endif +#ifndef __NR_listxattr +#define __NR_listxattr 232 +#endif +#ifndef __NR_llistxattr +#define __NR_llistxattr 233 +#endif +#ifndef __NR_tkill +#define __NR_tkill 238 +#endif +#ifndef __NR_futex +#define __NR_futex 240 +#endif +#ifndef __NR_sched_setaffinity +#define __NR_sched_setaffinity 241 +#define __NR_sched_getaffinity 242 +#endif +#ifndef __NR_set_tid_address +#define __NR_set_tid_address 258 +#endif +#ifndef __NR_clock_gettime +#define __NR_clock_gettime 265 +#endif +#ifndef __NR_clock_getres +#define __NR_clock_getres 266 +#endif +#ifndef __NR_statfs64 +#define __NR_statfs64 268 +#endif +#ifndef __NR_fstatfs64 +#define __NR_fstatfs64 269 +#endif +#ifndef __NR_fadvise64_64 +#define __NR_fadvise64_64 272 +#endif +#ifndef __NR_ioprio_set +#define __NR_ioprio_set 289 +#endif +#ifndef __NR_ioprio_get +#define __NR_ioprio_get 290 +#endif +#ifndef __NR_openat +#define __NR_openat 295 +#endif +#ifndef __NR_fstatat64 +#define __NR_fstatat64 300 +#endif +#ifndef __NR_unlinkat +#define __NR_unlinkat 301 +#endif +#ifndef __NR_move_pages +#define __NR_move_pages 317 +#endif +#ifndef __NR_getcpu +#define __NR_getcpu 318 +#endif +#ifndef __NR_fallocate +#define __NR_fallocate 324 +#endif +/* End of i386 definitions */ +#elif defined(__ARM_ARCH_3__) || defined(__ARM_EABI__) +#ifndef __NR_setresuid +#define __NR_setresuid (__NR_SYSCALL_BASE + 164) +#define __NR_getresuid (__NR_SYSCALL_BASE + 165) +#define __NR_setresgid (__NR_SYSCALL_BASE + 170) +#define __NR_getresgid (__NR_SYSCALL_BASE + 171) +#endif +#ifndef __NR_rt_sigaction +#define __NR_rt_sigreturn (__NR_SYSCALL_BASE + 173) +#define __NR_rt_sigaction (__NR_SYSCALL_BASE + 174) +#define __NR_rt_sigprocmask (__NR_SYSCALL_BASE + 175) +#define __NR_rt_sigpending (__NR_SYSCALL_BASE + 176) +#define __NR_rt_sigsuspend (__NR_SYSCALL_BASE + 179) +#endif +#ifndef __NR_pread64 +#define __NR_pread64 (__NR_SYSCALL_BASE + 180) +#endif +#ifndef __NR_pwrite64 +#define __NR_pwrite64 (__NR_SYSCALL_BASE + 181) +#endif +#ifndef __NR_ugetrlimit +#define __NR_ugetrlimit (__NR_SYSCALL_BASE + 191) +#endif +#ifndef __NR_stat64 +#define __NR_stat64 (__NR_SYSCALL_BASE + 195) +#endif +#ifndef __NR_fstat64 +#define __NR_fstat64 (__NR_SYSCALL_BASE + 197) +#endif +#ifndef __NR_setresuid32 +#define __NR_setresuid32 (__NR_SYSCALL_BASE + 208) +#define __NR_getresuid32 (__NR_SYSCALL_BASE + 209) +#define __NR_setresgid32 (__NR_SYSCALL_BASE + 210) +#define __NR_getresgid32 (__NR_SYSCALL_BASE + 211) +#endif +#ifndef __NR_setfsuid32 +#define __NR_setfsuid32 (__NR_SYSCALL_BASE + 215) +#define __NR_setfsgid32 (__NR_SYSCALL_BASE + 216) +#endif +#ifndef __NR_getdents64 +#define __NR_getdents64 (__NR_SYSCALL_BASE + 217) +#endif +#ifndef __NR_gettid +#define __NR_gettid (__NR_SYSCALL_BASE + 224) +#endif +#ifndef __NR_readahead +#define __NR_readahead (__NR_SYSCALL_BASE + 225) +#endif +#ifndef __NR_setxattr +#define __NR_setxattr (__NR_SYSCALL_BASE + 226) +#endif +#ifndef __NR_lsetxattr +#define __NR_lsetxattr (__NR_SYSCALL_BASE + 227) +#endif +#ifndef __NR_getxattr +#define __NR_getxattr (__NR_SYSCALL_BASE + 229) +#endif +#ifndef __NR_lgetxattr +#define __NR_lgetxattr (__NR_SYSCALL_BASE + 230) +#endif +#ifndef __NR_listxattr +#define __NR_listxattr (__NR_SYSCALL_BASE + 232) +#endif +#ifndef __NR_llistxattr +#define __NR_llistxattr (__NR_SYSCALL_BASE + 233) +#endif +#ifndef __NR_tkill +#define __NR_tkill (__NR_SYSCALL_BASE + 238) +#endif +#ifndef __NR_futex +#define __NR_futex (__NR_SYSCALL_BASE + 240) +#endif +#ifndef __NR_sched_setaffinity +#define __NR_sched_setaffinity (__NR_SYSCALL_BASE + 241) +#define __NR_sched_getaffinity (__NR_SYSCALL_BASE + 242) +#endif +#ifndef __NR_set_tid_address +#define __NR_set_tid_address (__NR_SYSCALL_BASE + 256) +#endif +#ifndef __NR_clock_gettime +#define __NR_clock_gettime (__NR_SYSCALL_BASE + 263) +#endif +#ifndef __NR_clock_getres +#define __NR_clock_getres (__NR_SYSCALL_BASE + 264) +#endif +#ifndef __NR_statfs64 +#define __NR_statfs64 (__NR_SYSCALL_BASE + 266) +#endif +#ifndef __NR_fstatfs64 +#define __NR_fstatfs64 (__NR_SYSCALL_BASE + 267) +#endif +#ifndef __NR_ioprio_set +#define __NR_ioprio_set (__NR_SYSCALL_BASE + 314) +#endif +#ifndef __NR_ioprio_get +#define __NR_ioprio_get (__NR_SYSCALL_BASE + 315) +#endif +#ifndef __NR_move_pages +#define __NR_move_pages (__NR_SYSCALL_BASE + 344) +#endif +#ifndef __NR_getcpu +#define __NR_getcpu (__NR_SYSCALL_BASE + 345) +#endif +/* End of ARM 3/EABI definitions */ +#elif defined(__aarch64__) +#ifndef __NR_setxattr +#define __NR_setxattr 5 +#endif +#ifndef __NR_lsetxattr +#define __NR_lsetxattr 6 +#endif +#ifndef __NR_getxattr +#define __NR_getxattr 8 +#endif +#ifndef __NR_lgetxattr +#define __NR_lgetxattr 9 +#endif +#ifndef __NR_listxattr +#define __NR_listxattr 11 +#endif +#ifndef __NR_llistxattr +#define __NR_llistxattr 12 +#endif +#ifndef __NR_ioprio_set +#define __NR_ioprio_set 30 +#endif +#ifndef __NR_ioprio_get +#define __NR_ioprio_get 31 +#endif +#ifndef __NR_unlinkat +#define __NR_unlinkat 35 +#endif +#ifndef __NR_fallocate +#define __NR_fallocate 47 +#endif +#ifndef __NR_openat +#define __NR_openat 56 +#endif +#ifndef __NR_quotactl +#define __NR_quotactl 60 +#endif +#ifndef __NR_getdents64 +#define __NR_getdents64 61 +#endif +#ifndef __NR_getdents +// when getdents is not available, getdents64 is used for both. +#define __NR_getdents __NR_getdents64 +#endif +#ifndef __NR_pread64 +#define __NR_pread64 67 +#endif +#ifndef __NR_pwrite64 +#define __NR_pwrite64 68 +#endif +#ifndef __NR_ppoll +#define __NR_ppoll 73 +#endif +#ifndef __NR_readlinkat +#define __NR_readlinkat 78 +#endif +#ifndef __NR_newfstatat +#define __NR_newfstatat 79 +#endif +#ifndef __NR_set_tid_address +#define __NR_set_tid_address 96 +#endif +#ifndef __NR_futex +#define __NR_futex 98 +#endif +#ifndef __NR_clock_gettime +#define __NR_clock_gettime 113 +#endif +#ifndef __NR_clock_getres +#define __NR_clock_getres 114 +#endif +#ifndef __NR_sched_setaffinity +#define __NR_sched_setaffinity 122 +#define __NR_sched_getaffinity 123 +#endif +#ifndef __NR_tkill +#define __NR_tkill 130 +#endif +#ifndef __NR_setresuid +#define __NR_setresuid 147 +#define __NR_getresuid 148 +#define __NR_setresgid 149 +#define __NR_getresgid 150 +#endif +#ifndef __NR_gettid +#define __NR_gettid 178 +#endif +#ifndef __NR_readahead +#define __NR_readahead 213 +#endif +#ifndef __NR_fadvise64 +#define __NR_fadvise64 223 +#endif +#ifndef __NR_move_pages +#define __NR_move_pages 239 +#endif +/* End of aarch64 definitions */ +#elif defined(__x86_64__) +#ifndef __NR_pread64 +#define __NR_pread64 17 +#endif +#ifndef __NR_pwrite64 +#define __NR_pwrite64 18 +#endif +#ifndef __NR_setresuid +#define __NR_setresuid 117 +#define __NR_getresuid 118 +#define __NR_setresgid 119 +#define __NR_getresgid 120 +#endif +#ifndef __NR_quotactl +#define __NR_quotactl 179 +#endif +#ifndef __NR_gettid +#define __NR_gettid 186 +#endif +#ifndef __NR_readahead +#define __NR_readahead 187 +#endif +#ifndef __NR_setxattr +#define __NR_setxattr 188 +#endif +#ifndef __NR_lsetxattr +#define __NR_lsetxattr 189 +#endif +#ifndef __NR_getxattr +#define __NR_getxattr 191 +#endif +#ifndef __NR_lgetxattr +#define __NR_lgetxattr 192 +#endif +#ifndef __NR_listxattr +#define __NR_listxattr 194 +#endif +#ifndef __NR_llistxattr +#define __NR_llistxattr 195 +#endif +#ifndef __NR_tkill +#define __NR_tkill 200 +#endif +#ifndef __NR_futex +#define __NR_futex 202 +#endif +#ifndef __NR_sched_setaffinity +#define __NR_sched_setaffinity 203 +#define __NR_sched_getaffinity 204 +#endif +#ifndef __NR_getdents64 +#define __NR_getdents64 217 +#endif +#ifndef __NR_getdents +// when getdents is not available, getdents64 is used for both. +#define __NR_getdents __NR_getdents64 +#endif +#ifndef __NR_set_tid_address +#define __NR_set_tid_address 218 +#endif +#ifndef __NR_fadvise64 +#define __NR_fadvise64 221 +#endif +#ifndef __NR_clock_gettime +#define __NR_clock_gettime 228 +#endif +#ifndef __NR_clock_getres +#define __NR_clock_getres 229 +#endif +#ifndef __NR_ioprio_set +#define __NR_ioprio_set 251 +#endif +#ifndef __NR_ioprio_get +#define __NR_ioprio_get 252 +#endif +#ifndef __NR_openat +#define __NR_openat 257 +#endif +#ifndef __NR_newfstatat +#define __NR_newfstatat 262 +#endif +#ifndef __NR_unlinkat +#define __NR_unlinkat 263 +#endif +#ifndef __NR_move_pages +#define __NR_move_pages 279 +#endif +#ifndef __NR_fallocate +#define __NR_fallocate 285 +#endif +/* End of x86-64 definitions */ +#elif defined(__mips__) +#if _MIPS_SIM == _MIPS_SIM_ABI32 +#ifndef __NR_setresuid +#define __NR_setresuid (__NR_Linux + 185) +#define __NR_getresuid (__NR_Linux + 186) +#define __NR_setresgid (__NR_Linux + 190) +#define __NR_getresgid (__NR_Linux + 191) +#endif +#ifndef __NR_rt_sigaction +#define __NR_rt_sigreturn (__NR_Linux + 193) +#define __NR_rt_sigaction (__NR_Linux + 194) +#define __NR_rt_sigprocmask (__NR_Linux + 195) +#define __NR_rt_sigpending (__NR_Linux + 196) +#define __NR_rt_sigsuspend (__NR_Linux + 199) +#endif +#ifndef __NR_pread64 +#define __NR_pread64 (__NR_Linux + 200) +#endif +#ifndef __NR_pwrite64 +#define __NR_pwrite64 (__NR_Linux + 201) +#endif +#ifndef __NR_stat64 +#define __NR_stat64 (__NR_Linux + 213) +#endif +#ifndef __NR_fstat64 +#define __NR_fstat64 (__NR_Linux + 215) +#endif +#ifndef __NR_getdents64 +#define __NR_getdents64 (__NR_Linux + 219) +#endif +#ifndef __NR_gettid +#define __NR_gettid (__NR_Linux + 222) +#endif +#ifndef __NR_readahead +#define __NR_readahead (__NR_Linux + 223) +#endif +#ifndef __NR_setxattr +#define __NR_setxattr (__NR_Linux + 224) +#endif +#ifndef __NR_lsetxattr +#define __NR_lsetxattr (__NR_Linux + 225) +#endif +#ifndef __NR_getxattr +#define __NR_getxattr (__NR_Linux + 227) +#endif +#ifndef __NR_lgetxattr +#define __NR_lgetxattr (__NR_Linux + 228) +#endif +#ifndef __NR_listxattr +#define __NR_listxattr (__NR_Linux + 230) +#endif +#ifndef __NR_llistxattr +#define __NR_llistxattr (__NR_Linux + 231) +#endif +#ifndef __NR_tkill +#define __NR_tkill (__NR_Linux + 236) +#endif +#ifndef __NR_futex +#define __NR_futex (__NR_Linux + 238) +#endif +#ifndef __NR_sched_setaffinity +#define __NR_sched_setaffinity (__NR_Linux + 239) +#define __NR_sched_getaffinity (__NR_Linux + 240) +#endif +#ifndef __NR_set_tid_address +#define __NR_set_tid_address (__NR_Linux + 252) +#endif +#ifndef __NR_statfs64 +#define __NR_statfs64 (__NR_Linux + 255) +#endif +#ifndef __NR_fstatfs64 +#define __NR_fstatfs64 (__NR_Linux + 256) +#endif +#ifndef __NR_clock_gettime +#define __NR_clock_gettime (__NR_Linux + 263) +#endif +#ifndef __NR_clock_getres +#define __NR_clock_getres (__NR_Linux + 264) +#endif +#ifndef __NR_openat +#define __NR_openat (__NR_Linux + 288) +#endif +#ifndef __NR_fstatat +#define __NR_fstatat (__NR_Linux + 293) +#endif +#ifndef __NR_unlinkat +#define __NR_unlinkat (__NR_Linux + 294) +#endif +#ifndef __NR_move_pages +#define __NR_move_pages (__NR_Linux + 308) +#endif +#ifndef __NR_getcpu +#define __NR_getcpu (__NR_Linux + 312) +#endif +#ifndef __NR_ioprio_set +#define __NR_ioprio_set (__NR_Linux + 314) +#endif +#ifndef __NR_ioprio_get +#define __NR_ioprio_get (__NR_Linux + 315) +#endif +/* End of MIPS (old 32bit API) definitions */ +#elif _MIPS_SIM == _MIPS_SIM_ABI64 +#ifndef __NR_pread64 +#define __NR_pread64 (__NR_Linux + 16) +#endif +#ifndef __NR_pwrite64 +#define __NR_pwrite64 (__NR_Linux + 17) +#endif +#ifndef __NR_setresuid +#define __NR_setresuid (__NR_Linux + 115) +#define __NR_getresuid (__NR_Linux + 116) +#define __NR_setresgid (__NR_Linux + 117) +#define __NR_getresgid (__NR_Linux + 118) +#endif +#ifndef __NR_gettid +#define __NR_gettid (__NR_Linux + 178) +#endif +#ifndef __NR_readahead +#define __NR_readahead (__NR_Linux + 179) +#endif +#ifndef __NR_setxattr +#define __NR_setxattr (__NR_Linux + 180) +#endif +#ifndef __NR_lsetxattr +#define __NR_lsetxattr (__NR_Linux + 181) +#endif +#ifndef __NR_getxattr +#define __NR_getxattr (__NR_Linux + 183) +#endif +#ifndef __NR_lgetxattr +#define __NR_lgetxattr (__NR_Linux + 184) +#endif +#ifndef __NR_listxattr +#define __NR_listxattr (__NR_Linux + 186) +#endif +#ifndef __NR_llistxattr +#define __NR_llistxattr (__NR_Linux + 187) +#endif +#ifndef __NR_tkill +#define __NR_tkill (__NR_Linux + 192) +#endif +#ifndef __NR_futex +#define __NR_futex (__NR_Linux + 194) +#endif +#ifndef __NR_sched_setaffinity +#define __NR_sched_setaffinity (__NR_Linux + 195) +#define __NR_sched_getaffinity (__NR_Linux + 196) +#endif +#ifndef __NR_set_tid_address +#define __NR_set_tid_address (__NR_Linux + 212) +#endif +#ifndef __NR_clock_gettime +#define __NR_clock_gettime (__NR_Linux + 222) +#endif +#ifndef __NR_clock_getres +#define __NR_clock_getres (__NR_Linux + 223) +#endif +#ifndef __NR_openat +#define __NR_openat (__NR_Linux + 247) +#endif +#ifndef __NR_fstatat +#define __NR_fstatat (__NR_Linux + 252) +#endif +#ifndef __NR_unlinkat +#define __NR_unlinkat (__NR_Linux + 253) +#endif +#ifndef __NR_move_pages +#define __NR_move_pages (__NR_Linux + 267) +#endif +#ifndef __NR_getcpu +#define __NR_getcpu (__NR_Linux + 271) +#endif +#ifndef __NR_ioprio_set +#define __NR_ioprio_set (__NR_Linux + 273) +#endif +#ifndef __NR_ioprio_get +#define __NR_ioprio_get (__NR_Linux + 274) +#endif +/* End of MIPS (64bit API) definitions */ +#else +#ifndef __NR_setresuid +#define __NR_setresuid (__NR_Linux + 115) +#define __NR_getresuid (__NR_Linux + 116) +#define __NR_setresgid (__NR_Linux + 117) +#define __NR_getresgid (__NR_Linux + 118) +#endif +#ifndef __NR_gettid +#define __NR_gettid (__NR_Linux + 178) +#endif +#ifndef __NR_readahead +#define __NR_readahead (__NR_Linux + 179) +#endif +#ifndef __NR_setxattr +#define __NR_setxattr (__NR_Linux + 180) +#endif +#ifndef __NR_lsetxattr +#define __NR_lsetxattr (__NR_Linux + 181) +#endif +#ifndef __NR_getxattr +#define __NR_getxattr (__NR_Linux + 183) +#endif +#ifndef __NR_lgetxattr +#define __NR_lgetxattr (__NR_Linux + 184) +#endif +#ifndef __NR_listxattr +#define __NR_listxattr (__NR_Linux + 186) +#endif +#ifndef __NR_llistxattr +#define __NR_llistxattr (__NR_Linux + 187) +#endif +#ifndef __NR_tkill +#define __NR_tkill (__NR_Linux + 192) +#endif +#ifndef __NR_futex +#define __NR_futex (__NR_Linux + 194) +#endif +#ifndef __NR_sched_setaffinity +#define __NR_sched_setaffinity (__NR_Linux + 195) +#define __NR_sched_getaffinity (__NR_Linux + 196) +#endif +#ifndef __NR_set_tid_address +#define __NR_set_tid_address (__NR_Linux + 213) +#endif +#ifndef __NR_statfs64 +#define __NR_statfs64 (__NR_Linux + 217) +#endif +#ifndef __NR_fstatfs64 +#define __NR_fstatfs64 (__NR_Linux + 218) +#endif +#ifndef __NR_clock_gettime +#define __NR_clock_gettime (__NR_Linux + 226) +#endif +#ifndef __NR_clock_getres +#define __NR_clock_getres (__NR_Linux + 227) +#endif +#ifndef __NR_openat +#define __NR_openat (__NR_Linux + 251) +#endif +#ifndef __NR_fstatat +#define __NR_fstatat (__NR_Linux + 256) +#endif +#ifndef __NR_unlinkat +#define __NR_unlinkat (__NR_Linux + 257) +#endif +#ifndef __NR_move_pages +#define __NR_move_pages (__NR_Linux + 271) +#endif +#ifndef __NR_getcpu +#define __NR_getcpu (__NR_Linux + 275) +#endif +#ifndef __NR_ioprio_set +#define __NR_ioprio_set (__NR_Linux + 277) +#endif +#ifndef __NR_ioprio_get +#define __NR_ioprio_get (__NR_Linux + 278) +#endif +/* End of MIPS (new 32bit API) definitions */ +#endif +/* End of MIPS definitions */ +#elif defined(__PPC__) +#ifndef __NR_setfsuid +#define __NR_setfsuid 138 +#define __NR_setfsgid 139 +#endif +#ifndef __NR_setresuid +#define __NR_setresuid 164 +#define __NR_getresuid 165 +#define __NR_setresgid 169 +#define __NR_getresgid 170 +#endif +#ifndef __NR_rt_sigaction +#define __NR_rt_sigreturn 172 +#define __NR_rt_sigaction 173 +#define __NR_rt_sigprocmask 174 +#define __NR_rt_sigpending 175 +#define __NR_rt_sigsuspend 178 +#endif +#ifndef __NR_pread64 +#define __NR_pread64 179 +#endif +#ifndef __NR_pwrite64 +#define __NR_pwrite64 180 +#endif +#ifndef __NR_ugetrlimit +#define __NR_ugetrlimit 190 +#endif +#ifndef __NR_readahead +#define __NR_readahead 191 +#endif +#ifndef __NR_stat64 +#define __NR_stat64 195 +#endif +#ifndef __NR_fstat64 +#define __NR_fstat64 197 +#endif +#ifndef __NR_getdents64 +#define __NR_getdents64 202 +#endif +#ifndef __NR_gettid +#define __NR_gettid 207 +#endif +#ifndef __NR_tkill +#define __NR_tkill 208 +#endif +#ifndef __NR_setxattr +#define __NR_setxattr 209 +#endif +#ifndef __NR_lsetxattr +#define __NR_lsetxattr 210 +#endif +#ifndef __NR_getxattr +#define __NR_getxattr 212 +#endif +#ifndef __NR_lgetxattr +#define __NR_lgetxattr 213 +#endif +#ifndef __NR_listxattr +#define __NR_listxattr 215 +#endif +#ifndef __NR_llistxattr +#define __NR_llistxattr 216 +#endif +#ifndef __NR_futex +#define __NR_futex 221 +#endif +#ifndef __NR_sched_setaffinity +#define __NR_sched_setaffinity 222 +#define __NR_sched_getaffinity 223 +#endif +#ifndef __NR_set_tid_address +#define __NR_set_tid_address 232 +#endif +#ifndef __NR_clock_gettime +#define __NR_clock_gettime 246 +#endif +#ifndef __NR_clock_getres +#define __NR_clock_getres 247 +#endif +#ifndef __NR_statfs64 +#define __NR_statfs64 252 +#endif +#ifndef __NR_fstatfs64 +#define __NR_fstatfs64 253 +#endif +#ifndef __NR_fadvise64_64 +#define __NR_fadvise64_64 254 +#endif +#ifndef __NR_ioprio_set +#define __NR_ioprio_set 273 +#endif +#ifndef __NR_ioprio_get +#define __NR_ioprio_get 274 +#endif +#ifndef __NR_openat +#define __NR_openat 286 +#endif +#ifndef __NR_fstatat64 +#define __NR_fstatat64 291 +#endif +#ifndef __NR_unlinkat +#define __NR_unlinkat 292 +#endif +#ifndef __NR_move_pages +#define __NR_move_pages 301 +#endif +#ifndef __NR_getcpu +#define __NR_getcpu 302 +#endif +/* End of powerpc defininitions */ +#elif defined(__s390__) +#ifndef __NR_quotactl +#define __NR_quotactl 131 +#endif +#ifndef __NR_rt_sigreturn +#define __NR_rt_sigreturn 173 +#endif +#ifndef __NR_rt_sigaction +#define __NR_rt_sigaction 174 +#endif +#ifndef __NR_rt_sigprocmask +#define __NR_rt_sigprocmask 175 +#endif +#ifndef __NR_rt_sigpending +#define __NR_rt_sigpending 176 +#endif +#ifndef __NR_rt_sigsuspend +#define __NR_rt_sigsuspend 179 +#endif +#ifndef __NR_pread64 +#define __NR_pread64 180 +#endif +#ifndef __NR_pwrite64 +#define __NR_pwrite64 181 +#endif +#ifndef __NR_getdents64 +#define __NR_getdents64 220 +#endif +#ifndef __NR_readahead +#define __NR_readahead 222 +#endif +#ifndef __NR_setxattr +#define __NR_setxattr 224 +#endif +#ifndef __NR_lsetxattr +#define __NR_lsetxattr 225 +#endif +#ifndef __NR_getxattr +#define __NR_getxattr 227 +#endif +#ifndef __NR_lgetxattr +#define __NR_lgetxattr 228 +#endif +#ifndef __NR_listxattr +#define __NR_listxattr 230 +#endif +#ifndef __NR_llistxattr +#define __NR_llistxattr 231 +#endif +#ifndef __NR_gettid +#define __NR_gettid 236 +#endif +#ifndef __NR_tkill +#define __NR_tkill 237 +#endif +#ifndef __NR_futex +#define __NR_futex 238 +#endif +#ifndef __NR_sched_setaffinity +#define __NR_sched_setaffinity 239 +#endif +#ifndef __NR_sched_getaffinity +#define __NR_sched_getaffinity 240 +#endif +#ifndef __NR_set_tid_address +#define __NR_set_tid_address 252 +#endif +#ifndef __NR_clock_gettime +#define __NR_clock_gettime 260 +#endif +#ifndef __NR_clock_getres +#define __NR_clock_getres 261 +#endif +#ifndef __NR_statfs64 +#define __NR_statfs64 265 +#endif +#ifndef __NR_fstatfs64 +#define __NR_fstatfs64 266 +#endif +#ifndef __NR_ioprio_set +#define __NR_ioprio_set 282 +#endif +#ifndef __NR_ioprio_get +#define __NR_ioprio_get 283 +#endif +#ifndef __NR_openat +#define __NR_openat 288 +#endif +#ifndef __NR_unlinkat +#define __NR_unlinkat 294 +#endif +#ifndef __NR_move_pages +#define __NR_move_pages 310 +#endif +#ifndef __NR_getcpu +#define __NR_getcpu 311 +#endif +#ifndef __NR_fallocate +#define __NR_fallocate 314 +#endif +/* Some syscalls are named/numbered differently between s390 and s390x. */ +#ifdef __s390x__ +# ifndef __NR_getrlimit +# define __NR_getrlimit 191 +# endif +# ifndef __NR_setresuid +# define __NR_setresuid 208 +# endif +# ifndef __NR_getresuid +# define __NR_getresuid 209 +# endif +# ifndef __NR_setresgid +# define __NR_setresgid 210 +# endif +# ifndef __NR_getresgid +# define __NR_getresgid 211 +# endif +# ifndef __NR_setfsuid +# define __NR_setfsuid 215 +# endif +# ifndef __NR_setfsgid +# define __NR_setfsgid 216 +# endif +# ifndef __NR_fadvise64 +# define __NR_fadvise64 253 +# endif +# ifndef __NR_newfstatat +# define __NR_newfstatat 293 +# endif +#else /* __s390x__ */ +# ifndef __NR_getrlimit +# define __NR_getrlimit 76 +# endif +# ifndef __NR_setfsuid +# define __NR_setfsuid 138 +# endif +# ifndef __NR_setfsgid +# define __NR_setfsgid 139 +# endif +# ifndef __NR_setresuid +# define __NR_setresuid 164 +# endif +# ifndef __NR_getresuid +# define __NR_getresuid 165 +# endif +# ifndef __NR_setresgid +# define __NR_setresgid 170 +# endif +# ifndef __NR_getresgid +# define __NR_getresgid 171 +# endif +# ifndef __NR_ugetrlimit +# define __NR_ugetrlimit 191 +# endif +# ifndef __NR_mmap2 +# define __NR_mmap2 192 +# endif +# ifndef __NR_setresuid32 +# define __NR_setresuid32 208 +# endif +# ifndef __NR_getresuid32 +# define __NR_getresuid32 209 +# endif +# ifndef __NR_setresgid32 +# define __NR_setresgid32 210 +# endif +# ifndef __NR_getresgid32 +# define __NR_getresgid32 211 +# endif +# ifndef __NR_setfsuid32 +# define __NR_setfsuid32 215 +# endif +# ifndef __NR_setfsgid32 +# define __NR_setfsgid32 216 +# endif +# ifndef __NR_fadvise64_64 +# define __NR_fadvise64_64 264 +# endif +# ifndef __NR_fstatat64 +# define __NR_fstatat64 293 +# endif +#endif /* __s390__ */ +/* End of s390/s390x definitions */ +#endif + + +/* After forking, we must make sure to only call system calls. */ +#if defined(__BOUNDED_POINTERS__) + #error "Need to port invocations of syscalls for bounded ptrs" +#else + /* The core dumper and the thread lister get executed after threads + * have been suspended. As a consequence, we cannot call any functions + * that acquire locks. Unfortunately, libc wraps most system calls + * (e.g. in order to implement pthread_atfork, and to make calls + * cancellable), which means we cannot call these functions. Instead, + * we have to call syscall() directly. + */ + #undef LSS_ERRNO + #ifdef SYS_ERRNO + /* Allow the including file to override the location of errno. This can + * be useful when using clone() with the CLONE_VM option. + */ + #define LSS_ERRNO SYS_ERRNO + #else + #define LSS_ERRNO errno + #endif + + #undef LSS_INLINE + #ifdef SYS_INLINE + #define LSS_INLINE SYS_INLINE + #else + #define LSS_INLINE static inline + #endif + + /* Allow the including file to override the prefix used for all new + * system calls. By default, it will be set to "sys_". + */ + #undef LSS_NAME + #ifndef SYS_PREFIX + #define LSS_NAME(name) sys_##name + #elif defined(SYS_PREFIX) && SYS_PREFIX < 0 + #define LSS_NAME(name) name + #elif defined(SYS_PREFIX) && SYS_PREFIX == 0 + #define LSS_NAME(name) sys0_##name + #elif defined(SYS_PREFIX) && SYS_PREFIX == 1 + #define LSS_NAME(name) sys1_##name + #elif defined(SYS_PREFIX) && SYS_PREFIX == 2 + #define LSS_NAME(name) sys2_##name + #elif defined(SYS_PREFIX) && SYS_PREFIX == 3 + #define LSS_NAME(name) sys3_##name + #elif defined(SYS_PREFIX) && SYS_PREFIX == 4 + #define LSS_NAME(name) sys4_##name + #elif defined(SYS_PREFIX) && SYS_PREFIX == 5 + #define LSS_NAME(name) sys5_##name + #elif defined(SYS_PREFIX) && SYS_PREFIX == 6 + #define LSS_NAME(name) sys6_##name + #elif defined(SYS_PREFIX) && SYS_PREFIX == 7 + #define LSS_NAME(name) sys7_##name + #elif defined(SYS_PREFIX) && SYS_PREFIX == 8 + #define LSS_NAME(name) sys8_##name + #elif defined(SYS_PREFIX) && SYS_PREFIX == 9 + #define LSS_NAME(name) sys9_##name + #endif + + #undef LSS_RETURN + #if (defined(__i386__) || defined(__x86_64__) || defined(__ARM_ARCH_3__) \ + || defined(__ARM_EABI__) || defined(__aarch64__) || defined(__s390__)) + /* Failing system calls return a negative result in the range of + * -1..-4095. These are "errno" values with the sign inverted. + */ + #define LSS_RETURN(type, res) \ + do { \ + if ((unsigned long)(res) >= (unsigned long)(-4095)) { \ + LSS_ERRNO = -(res); \ + res = -1; \ + } \ + return (type) (res); \ + } while (0) + #elif defined(__mips__) + /* On MIPS, failing system calls return -1, and set errno in a + * separate CPU register. + */ + #define LSS_RETURN(type, res, err) \ + do { \ + if (err) { \ + unsigned long __errnovalue = (res); \ + LSS_ERRNO = __errnovalue; \ + res = -1; \ + } \ + return (type) (res); \ + } while (0) + #elif defined(__PPC__) + /* On PPC, failing system calls return -1, and set errno in a + * separate CPU register. See linux/unistd.h. + */ + #define LSS_RETURN(type, res, err) \ + do { \ + if (err & 0x10000000 ) { \ + LSS_ERRNO = (res); \ + res = -1; \ + } \ + return (type) (res); \ + } while (0) + #endif + #if defined(__i386__) + /* In PIC mode (e.g. when building shared libraries), gcc for i386 + * reserves ebx. Unfortunately, most distribution ship with implementations + * of _syscallX() which clobber ebx. + * Also, most definitions of _syscallX() neglect to mark "memory" as being + * clobbered. This causes problems with compilers, that do a better job + * at optimizing across __asm__ calls. + * So, we just have to redefine all of the _syscallX() macros. + */ + #undef LSS_ENTRYPOINT + #ifdef SYS_SYSCALL_ENTRYPOINT + static inline void (**LSS_NAME(get_syscall_entrypoint)(void))(void) { + void (**entrypoint)(void); + asm volatile(".bss\n" + ".align 8\n" + ".globl " SYS_SYSCALL_ENTRYPOINT "\n" + ".common " SYS_SYSCALL_ENTRYPOINT ",8,8\n" + ".previous\n" + /* This logically does 'lea "SYS_SYSCALL_ENTRYPOINT", %0' */ + "call 0f\n" + "0:pop %0\n" + "add $_GLOBAL_OFFSET_TABLE_+[.-0b], %0\n" + "mov " SYS_SYSCALL_ENTRYPOINT "@GOT(%0), %0\n" + : "=r"(entrypoint)); + return entrypoint; + } + + #define LSS_ENTRYPOINT ".bss\n" \ + ".align 8\n" \ + ".globl " SYS_SYSCALL_ENTRYPOINT "\n" \ + ".common " SYS_SYSCALL_ENTRYPOINT ",8,8\n" \ + ".previous\n" \ + /* Check the SYS_SYSCALL_ENTRYPOINT vector */ \ + "push %%eax\n" \ + "call 10000f\n" \ + "10000:pop %%eax\n" \ + "add $_GLOBAL_OFFSET_TABLE_+[.-10000b], %%eax\n" \ + "mov " SYS_SYSCALL_ENTRYPOINT \ + "@GOT(%%eax), %%eax\n" \ + "mov 0(%%eax), %%eax\n" \ + "test %%eax, %%eax\n" \ + "jz 10002f\n" \ + "push %%eax\n" \ + "call 10001f\n" \ + "10001:pop %%eax\n" \ + "add $(10003f-10001b), %%eax\n" \ + "xchg 4(%%esp), %%eax\n" \ + "ret\n" \ + "10002:pop %%eax\n" \ + "int $0x80\n" \ + "10003:\n" + #else + #define LSS_ENTRYPOINT "int $0x80\n" + #endif + #undef LSS_BODY + #define LSS_BODY(type,args...) \ + long __res; \ + __asm__ __volatile__("push %%ebx\n" \ + "movl %2,%%ebx\n" \ + LSS_ENTRYPOINT \ + "pop %%ebx" \ + args \ + : "esp", "memory"); \ + LSS_RETURN(type,__res) + #undef _syscall0 + #define _syscall0(type,name) \ + type LSS_NAME(name)(void) { \ + long __res; \ + __asm__ volatile(LSS_ENTRYPOINT \ + : "=a" (__res) \ + : "0" (__NR_##name) \ + : "memory"); \ + LSS_RETURN(type,__res); \ + } + #undef _syscall1 + #define _syscall1(type,name,type1,arg1) \ + type LSS_NAME(name)(type1 arg1) { \ + LSS_BODY(type, \ + : "=a" (__res) \ + : "0" (__NR_##name), "ri" ((long)(arg1))); \ + } + #undef _syscall2 + #define _syscall2(type,name,type1,arg1,type2,arg2) \ + type LSS_NAME(name)(type1 arg1,type2 arg2) { \ + LSS_BODY(type, \ + : "=a" (__res) \ + : "0" (__NR_##name),"ri" ((long)(arg1)), "c" ((long)(arg2))); \ + } + #undef _syscall3 + #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \ + type LSS_NAME(name)(type1 arg1,type2 arg2,type3 arg3) { \ + LSS_BODY(type, \ + : "=a" (__res) \ + : "0" (__NR_##name), "ri" ((long)(arg1)), "c" ((long)(arg2)), \ + "d" ((long)(arg3))); \ + } + #undef _syscall4 + #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ + type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \ + LSS_BODY(type, \ + : "=a" (__res) \ + : "0" (__NR_##name), "ri" ((long)(arg1)), "c" ((long)(arg2)), \ + "d" ((long)(arg3)),"S" ((long)(arg4))); \ + } + #undef _syscall5 + #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ + type5,arg5) \ + type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \ + type5 arg5) { \ + long __res; \ + __asm__ __volatile__("push %%ebx\n" \ + "movl %2,%%ebx\n" \ + "movl %1,%%eax\n" \ + LSS_ENTRYPOINT \ + "pop %%ebx" \ + : "=a" (__res) \ + : "i" (__NR_##name), "ri" ((long)(arg1)), \ + "c" ((long)(arg2)), "d" ((long)(arg3)), \ + "S" ((long)(arg4)), "D" ((long)(arg5)) \ + : "esp", "memory"); \ + LSS_RETURN(type,__res); \ + } + #undef _syscall6 + #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ + type5,arg5,type6,arg6) \ + type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \ + type5 arg5, type6 arg6) { \ + long __res; \ + struct { long __a1; long __a6; } __s = { (long)arg1, (long) arg6 }; \ + __asm__ __volatile__("push %%ebp\n" \ + "push %%ebx\n" \ + "movl 4(%2),%%ebp\n" \ + "movl 0(%2), %%ebx\n" \ + "movl %1,%%eax\n" \ + LSS_ENTRYPOINT \ + "pop %%ebx\n" \ + "pop %%ebp" \ + : "=a" (__res) \ + : "i" (__NR_##name), "0" ((long)(&__s)), \ + "c" ((long)(arg2)), "d" ((long)(arg3)), \ + "S" ((long)(arg4)), "D" ((long)(arg5)) \ + : "esp", "memory"); \ + LSS_RETURN(type,__res); \ + } + LSS_INLINE int LSS_NAME(clone)(int (*fn)(void *), void *child_stack, + int flags, void *arg, int *parent_tidptr, + void *newtls, int *child_tidptr) { + long __res; + __asm__ __volatile__(/* if (fn == NULL) + * return -EINVAL; + */ + "movl %3,%%ecx\n" + "jecxz 1f\n" + + /* if (child_stack == NULL) + * return -EINVAL; + */ + "movl %4,%%ecx\n" + "jecxz 1f\n" + + /* Set up alignment of the child stack: + * child_stack = (child_stack & ~0xF) - 20; + */ + "andl $-16,%%ecx\n" + "subl $20,%%ecx\n" + + /* Push "arg" and "fn" onto the stack that will be + * used by the child. + */ + "movl %6,%%eax\n" + "movl %%eax,4(%%ecx)\n" + "movl %3,%%eax\n" + "movl %%eax,(%%ecx)\n" + + /* %eax = syscall(%eax = __NR_clone, + * %ebx = flags, + * %ecx = child_stack, + * %edx = parent_tidptr, + * %esi = newtls, + * %edi = child_tidptr) + * Also, make sure that %ebx gets preserved as it is + * used in PIC mode. + */ + "movl %8,%%esi\n" + "movl %7,%%edx\n" + "movl %5,%%eax\n" + "movl %9,%%edi\n" + "pushl %%ebx\n" + "movl %%eax,%%ebx\n" + "movl %2,%%eax\n" + LSS_ENTRYPOINT + + /* In the parent: restore %ebx + * In the child: move "fn" into %ebx + */ + "popl %%ebx\n" + + /* if (%eax != 0) + * return %eax; + */ + "test %%eax,%%eax\n" + "jnz 1f\n" + + /* In the child, now. Terminate frame pointer chain. + */ + "movl $0,%%ebp\n" + + /* Call "fn". "arg" is already on the stack. + */ + "call *%%ebx\n" + + /* Call _exit(%ebx). Unfortunately older versions + * of gcc restrict the number of arguments that can + * be passed to asm(). So, we need to hard-code the + * system call number. + */ + "movl %%eax,%%ebx\n" + "movl $1,%%eax\n" + LSS_ENTRYPOINT + + /* Return to parent. + */ + "1:\n" + : "=a" (__res) + : "0"(-EINVAL), "i"(__NR_clone), + "m"(fn), "m"(child_stack), "m"(flags), "m"(arg), + "m"(parent_tidptr), "m"(newtls), "m"(child_tidptr) + : "esp", "memory", "ecx", "edx", "esi", "edi"); + LSS_RETURN(int, __res); + } + + LSS_INLINE _syscall1(int, set_thread_area, void *, u) + LSS_INLINE _syscall1(int, get_thread_area, void *, u) + + LSS_INLINE void (*LSS_NAME(restore_rt)(void))(void) { + /* On i386, the kernel does not know how to return from a signal + * handler. Instead, it relies on user space to provide a + * restorer function that calls the {rt_,}sigreturn() system call. + * Unfortunately, we cannot just reference the glibc version of this + * function, as glibc goes out of its way to make it inaccessible. + */ + void (*res)(void); + __asm__ __volatile__("call 2f\n" + "0:.align 16\n" + "1:movl %1,%%eax\n" + LSS_ENTRYPOINT + "2:popl %0\n" + "addl $(1b-0b),%0\n" + : "=a" (res) + : "i" (__NR_rt_sigreturn)); + return res; + } + LSS_INLINE void (*LSS_NAME(restore)(void))(void) { + /* On i386, the kernel does not know how to return from a signal + * handler. Instead, it relies on user space to provide a + * restorer function that calls the {rt_,}sigreturn() system call. + * Unfortunately, we cannot just reference the glibc version of this + * function, as glibc goes out of its way to make it inaccessible. + */ + void (*res)(void); + __asm__ __volatile__("call 2f\n" + "0:.align 16\n" + "1:pop %%eax\n" + "movl %1,%%eax\n" + LSS_ENTRYPOINT + "2:popl %0\n" + "addl $(1b-0b),%0\n" + : "=a" (res) + : "i" (__NR_sigreturn)); + return res; + } + #elif defined(__x86_64__) + /* There are no known problems with any of the _syscallX() macros + * currently shipping for x86_64, but we still need to be able to define + * our own version so that we can override the location of the errno + * location (e.g. when using the clone() system call with the CLONE_VM + * option). + */ + #undef LSS_ENTRYPOINT + #ifdef SYS_SYSCALL_ENTRYPOINT + static inline void (**LSS_NAME(get_syscall_entrypoint)(void))(void) { + void (**entrypoint)(void); + asm volatile(".bss\n" + ".align 8\n" + ".globl " SYS_SYSCALL_ENTRYPOINT "\n" + ".common " SYS_SYSCALL_ENTRYPOINT ",8,8\n" + ".previous\n" + "mov " SYS_SYSCALL_ENTRYPOINT "@GOTPCREL(%%rip), %0\n" + : "=r"(entrypoint)); + return entrypoint; + } + + #define LSS_ENTRYPOINT \ + ".bss\n" \ + ".align 8\n" \ + ".globl " SYS_SYSCALL_ENTRYPOINT "\n" \ + ".common " SYS_SYSCALL_ENTRYPOINT ",8,8\n" \ + ".previous\n" \ + "mov " SYS_SYSCALL_ENTRYPOINT "@GOTPCREL(%%rip), %%rcx\n" \ + "mov 0(%%rcx), %%rcx\n" \ + "test %%rcx, %%rcx\n" \ + "jz 10001f\n" \ + "call *%%rcx\n" \ + "jmp 10002f\n" \ + "10001:syscall\n" \ + "10002:\n" + + #else + #define LSS_ENTRYPOINT "syscall\n" + #endif + + /* The x32 ABI has 32 bit longs, but the syscall interface is 64 bit. + * We need to explicitly cast to an unsigned 64 bit type to avoid implicit + * sign extension. We can't cast pointers directly because those are + * 32 bits, and gcc will dump ugly warnings about casting from a pointer + * to an integer of a different size. + */ + #undef LSS_SYSCALL_ARG + #define LSS_SYSCALL_ARG(a) ((uint64_t)(uintptr_t)(a)) + #undef _LSS_RETURN + #define _LSS_RETURN(type, res, cast) \ + do { \ + if ((uint64_t)(res) >= (uint64_t)(-4095)) { \ + LSS_ERRNO = -(res); \ + res = -1; \ + } \ + return (type)(cast)(res); \ + } while (0) + #undef LSS_RETURN + #define LSS_RETURN(type, res) _LSS_RETURN(type, res, uintptr_t) + + #undef _LSS_BODY + #define _LSS_BODY(nr, type, name, cast, ...) \ + long long __res; \ + __asm__ __volatile__(LSS_BODY_ASM##nr LSS_ENTRYPOINT \ + : "=a" (__res) \ + : "0" (__NR_##name) LSS_BODY_ARG##nr(__VA_ARGS__) \ + : LSS_BODY_CLOBBER##nr "r11", "rcx", "memory"); \ + _LSS_RETURN(type, __res, cast) + #undef LSS_BODY + #define LSS_BODY(nr, type, name, args...) \ + _LSS_BODY(nr, type, name, uintptr_t, ## args) + + #undef LSS_BODY_ASM0 + #undef LSS_BODY_ASM1 + #undef LSS_BODY_ASM2 + #undef LSS_BODY_ASM3 + #undef LSS_BODY_ASM4 + #undef LSS_BODY_ASM5 + #undef LSS_BODY_ASM6 + #define LSS_BODY_ASM0 + #define LSS_BODY_ASM1 LSS_BODY_ASM0 + #define LSS_BODY_ASM2 LSS_BODY_ASM1 + #define LSS_BODY_ASM3 LSS_BODY_ASM2 + #define LSS_BODY_ASM4 LSS_BODY_ASM3 "movq %5,%%r10;" + #define LSS_BODY_ASM5 LSS_BODY_ASM4 "movq %6,%%r8;" + #define LSS_BODY_ASM6 LSS_BODY_ASM5 "movq %7,%%r9;" + + #undef LSS_BODY_CLOBBER0 + #undef LSS_BODY_CLOBBER1 + #undef LSS_BODY_CLOBBER2 + #undef LSS_BODY_CLOBBER3 + #undef LSS_BODY_CLOBBER4 + #undef LSS_BODY_CLOBBER5 + #undef LSS_BODY_CLOBBER6 + #define LSS_BODY_CLOBBER0 + #define LSS_BODY_CLOBBER1 LSS_BODY_CLOBBER0 + #define LSS_BODY_CLOBBER2 LSS_BODY_CLOBBER1 + #define LSS_BODY_CLOBBER3 LSS_BODY_CLOBBER2 + #define LSS_BODY_CLOBBER4 LSS_BODY_CLOBBER3 "r10", + #define LSS_BODY_CLOBBER5 LSS_BODY_CLOBBER4 "r8", + #define LSS_BODY_CLOBBER6 LSS_BODY_CLOBBER5 "r9", + + #undef LSS_BODY_ARG0 + #undef LSS_BODY_ARG1 + #undef LSS_BODY_ARG2 + #undef LSS_BODY_ARG3 + #undef LSS_BODY_ARG4 + #undef LSS_BODY_ARG5 + #undef LSS_BODY_ARG6 + #define LSS_BODY_ARG0() + #define LSS_BODY_ARG1(arg1) \ + LSS_BODY_ARG0(), "D" (arg1) + #define LSS_BODY_ARG2(arg1, arg2) \ + LSS_BODY_ARG1(arg1), "S" (arg2) + #define LSS_BODY_ARG3(arg1, arg2, arg3) \ + LSS_BODY_ARG2(arg1, arg2), "d" (arg3) + #define LSS_BODY_ARG4(arg1, arg2, arg3, arg4) \ + LSS_BODY_ARG3(arg1, arg2, arg3), "r" (arg4) + #define LSS_BODY_ARG5(arg1, arg2, arg3, arg4, arg5) \ + LSS_BODY_ARG4(arg1, arg2, arg3, arg4), "r" (arg5) + #define LSS_BODY_ARG6(arg1, arg2, arg3, arg4, arg5, arg6) \ + LSS_BODY_ARG5(arg1, arg2, arg3, arg4, arg5), "r" (arg6) + + #undef _syscall0 + #define _syscall0(type,name) \ + type LSS_NAME(name)(void) { \ + LSS_BODY(0, type, name); \ + } + #undef _syscall1 + #define _syscall1(type,name,type1,arg1) \ + type LSS_NAME(name)(type1 arg1) { \ + LSS_BODY(1, type, name, LSS_SYSCALL_ARG(arg1)); \ + } + #undef _syscall2 + #define _syscall2(type,name,type1,arg1,type2,arg2) \ + type LSS_NAME(name)(type1 arg1, type2 arg2) { \ + LSS_BODY(2, type, name, LSS_SYSCALL_ARG(arg1), LSS_SYSCALL_ARG(arg2));\ + } + #undef _syscall3 + #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \ + type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3) { \ + LSS_BODY(3, type, name, LSS_SYSCALL_ARG(arg1), LSS_SYSCALL_ARG(arg2), \ + LSS_SYSCALL_ARG(arg3)); \ + } + #undef _syscall4 + #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ + type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \ + LSS_BODY(4, type, name, LSS_SYSCALL_ARG(arg1), LSS_SYSCALL_ARG(arg2), \ + LSS_SYSCALL_ARG(arg3), LSS_SYSCALL_ARG(arg4));\ + } + #undef _syscall5 + #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ + type5,arg5) \ + type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \ + type5 arg5) { \ + LSS_BODY(5, type, name, LSS_SYSCALL_ARG(arg1), LSS_SYSCALL_ARG(arg2), \ + LSS_SYSCALL_ARG(arg3), LSS_SYSCALL_ARG(arg4), \ + LSS_SYSCALL_ARG(arg5)); \ + } + #undef _syscall6 + #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ + type5,arg5,type6,arg6) \ + type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \ + type5 arg5, type6 arg6) { \ + LSS_BODY(6, type, name, LSS_SYSCALL_ARG(arg1), LSS_SYSCALL_ARG(arg2), \ + LSS_SYSCALL_ARG(arg3), LSS_SYSCALL_ARG(arg4), \ + LSS_SYSCALL_ARG(arg5), LSS_SYSCALL_ARG(arg6));\ + } + LSS_INLINE int LSS_NAME(clone)(int (*fn)(void *), void *child_stack, + int flags, void *arg, int *parent_tidptr, + void *newtls, int *child_tidptr) { + long long __res; + { + __asm__ __volatile__(/* if (fn == NULL) + * return -EINVAL; + */ + "testq %4,%4\n" + "jz 1f\n" + + /* if (child_stack == NULL) + * return -EINVAL; + */ + "testq %5,%5\n" + "jz 1f\n" + + /* childstack -= 2*sizeof(void *); + */ + "subq $16,%5\n" + + /* Push "arg" and "fn" onto the stack that will be + * used by the child. + */ + "movq %7,8(%5)\n" + "movq %4,0(%5)\n" + + /* %rax = syscall(%rax = __NR_clone, + * %rdi = flags, + * %rsi = child_stack, + * %rdx = parent_tidptr, + * %r8 = new_tls, + * %r10 = child_tidptr) + */ + "movq %2,%%rax\n" + "movq %9,%%r8\n" + "movq %10,%%r10\n" + LSS_ENTRYPOINT + + /* if (%rax != 0) + * return; + */ + "testq %%rax,%%rax\n" + "jnz 1f\n" + + /* In the child. Terminate frame pointer chain. + */ + "xorq %%rbp,%%rbp\n" + + /* Call "fn(arg)". + */ + "popq %%rax\n" + "popq %%rdi\n" + "call *%%rax\n" + + /* Call _exit(%ebx). + */ + "movq %%rax,%%rdi\n" + "movq %3,%%rax\n" + LSS_ENTRYPOINT + + /* Return to parent. + */ + "1:\n" + : "=a" (__res) + : "0"(-EINVAL), "i"(__NR_clone), "i"(__NR_exit), + "r"(LSS_SYSCALL_ARG(fn)), + "S"(LSS_SYSCALL_ARG(child_stack)), + "D"(LSS_SYSCALL_ARG(flags)), + "r"(LSS_SYSCALL_ARG(arg)), + "d"(LSS_SYSCALL_ARG(parent_tidptr)), + "r"(LSS_SYSCALL_ARG(newtls)), + "r"(LSS_SYSCALL_ARG(child_tidptr)) + : "memory", "r8", "r10", "r11", "rcx"); + } + LSS_RETURN(int, __res); + } + LSS_INLINE _syscall2(int, arch_prctl, int, c, void *, a) + + LSS_INLINE void (*LSS_NAME(restore_rt)(void))(void) { + /* On x86-64, the kernel does not know how to return from + * a signal handler. Instead, it relies on user space to provide a + * restorer function that calls the rt_sigreturn() system call. + * Unfortunately, we cannot just reference the glibc version of this + * function, as glibc goes out of its way to make it inaccessible. + */ + long long res; + __asm__ __volatile__("jmp 2f\n" + ".align 16\n" + "1:movq %1,%%rax\n" + LSS_ENTRYPOINT + "2:leaq 1b(%%rip),%0\n" + : "=r" (res) + : "i" (__NR_rt_sigreturn)); + return (void (*)(void))(uintptr_t)res; + } + #elif defined(__ARM_ARCH_3__) + /* Most definitions of _syscallX() neglect to mark "memory" as being + * clobbered. This causes problems with compilers, that do a better job + * at optimizing across __asm__ calls. + * So, we just have to redefine all of the _syscallX() macros. + */ + #undef LSS_REG + #define LSS_REG(r,a) register long __r##r __asm__("r"#r) = (long)a + #undef LSS_BODY + #define LSS_BODY(type,name,args...) \ + register long __res_r0 __asm__("r0"); \ + long __res; \ + __asm__ __volatile__ (__syscall(name) \ + : "=r"(__res_r0) : args : "lr", "memory"); \ + __res = __res_r0; \ + LSS_RETURN(type, __res) + #undef _syscall0 + #define _syscall0(type, name) \ + type LSS_NAME(name)(void) { \ + LSS_BODY(type, name); \ + } + #undef _syscall1 + #define _syscall1(type, name, type1, arg1) \ + type LSS_NAME(name)(type1 arg1) { \ + LSS_REG(0, arg1); LSS_BODY(type, name, "r"(__r0)); \ + } + #undef _syscall2 + #define _syscall2(type, name, type1, arg1, type2, arg2) \ + type LSS_NAME(name)(type1 arg1, type2 arg2) { \ + LSS_REG(0, arg1); LSS_REG(1, arg2); \ + LSS_BODY(type, name, "r"(__r0), "r"(__r1)); \ + } + #undef _syscall3 + #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3) \ + type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3) { \ + LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3); \ + LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2)); \ + } + #undef _syscall4 + #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ + type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \ + LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3); \ + LSS_REG(3, arg4); \ + LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2), "r"(__r3)); \ + } + #undef _syscall5 + #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ + type5,arg5) \ + type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \ + type5 arg5) { \ + LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3); \ + LSS_REG(3, arg4); LSS_REG(4, arg5); \ + LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2), "r"(__r3), \ + "r"(__r4)); \ + } + #undef _syscall6 + #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ + type5,arg5,type6,arg6) \ + type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \ + type5 arg5, type6 arg6) { \ + LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3); \ + LSS_REG(3, arg4); LSS_REG(4, arg5); LSS_REG(5, arg6); \ + LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2), "r"(__r3), \ + "r"(__r4), "r"(__r5)); \ + } + LSS_INLINE int LSS_NAME(clone)(int (*fn)(void *), void *child_stack, + int flags, void *arg, int *parent_tidptr, + void *newtls, int *child_tidptr) { + long __res; + { + register int __flags __asm__("r0") = flags; + register void *__stack __asm__("r1") = child_stack; + register void *__ptid __asm__("r2") = parent_tidptr; + register void *__tls __asm__("r3") = newtls; + register int *__ctid __asm__("r4") = child_tidptr; + __asm__ __volatile__(/* if (fn == NULL || child_stack == NULL) + * return -EINVAL; + */ + "cmp %2,#0\n" + "cmpne %3,#0\n" + "moveq %0,%1\n" + "beq 1f\n" + + /* Push "arg" and "fn" onto the stack that will be + * used by the child. + */ + "str %5,[%3,#-4]!\n" + "str %2,[%3,#-4]!\n" + + /* %r0 = syscall(%r0 = flags, + * %r1 = child_stack, + * %r2 = parent_tidptr, + * %r3 = newtls, + * %r4 = child_tidptr) + */ + __syscall(clone)"\n" + + /* if (%r0 != 0) + * return %r0; + */ + "movs %0,r0\n" + "bne 1f\n" + + /* In the child, now. Call "fn(arg)". + */ + "ldr r0,[sp, #4]\n" + "mov lr,pc\n" + "ldr pc,[sp]\n" + + /* Call _exit(%r0). + */ + __syscall(exit)"\n" + "1:\n" + : "=r" (__res) + : "i"(-EINVAL), + "r"(fn), "r"(__stack), "r"(__flags), "r"(arg), + "r"(__ptid), "r"(__tls), "r"(__ctid) + : "cc", "lr", "memory"); + } + LSS_RETURN(int, __res); + } + #elif defined(__ARM_EABI__) + /* Most definitions of _syscallX() neglect to mark "memory" as being + * clobbered. This causes problems with compilers, that do a better job + * at optimizing across __asm__ calls. + * So, we just have to redefine all fo the _syscallX() macros. + */ + #undef LSS_REG + #define LSS_REG(r,a) register long __r##r __asm__("r"#r) = (long)a + #undef LSS_BODY + #define LSS_BODY(type,name,args...) \ + register long __res_r0 __asm__("r0"); \ + long __res; \ + __asm__ __volatile__ ("push {r7}\n" \ + "mov r7, %1\n" \ + "swi 0x0\n" \ + "pop {r7}\n" \ + : "=r"(__res_r0) \ + : "i"(__NR_##name) , ## args \ + : "lr", "memory"); \ + __res = __res_r0; \ + LSS_RETURN(type, __res) + #undef _syscall0 + #define _syscall0(type, name) \ + type LSS_NAME(name)(void) { \ + LSS_BODY(type, name); \ + } + #undef _syscall1 + #define _syscall1(type, name, type1, arg1) \ + type LSS_NAME(name)(type1 arg1) { \ + LSS_REG(0, arg1); LSS_BODY(type, name, "r"(__r0)); \ + } + #undef _syscall2 + #define _syscall2(type, name, type1, arg1, type2, arg2) \ + type LSS_NAME(name)(type1 arg1, type2 arg2) { \ + LSS_REG(0, arg1); LSS_REG(1, arg2); \ + LSS_BODY(type, name, "r"(__r0), "r"(__r1)); \ + } + #undef _syscall3 + #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3) \ + type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3) { \ + LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3); \ + LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2)); \ + } + #undef _syscall4 + #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ + type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \ + LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3); \ + LSS_REG(3, arg4); \ + LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2), "r"(__r3)); \ + } + #undef _syscall5 + #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ + type5,arg5) \ + type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \ + type5 arg5) { \ + LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3); \ + LSS_REG(3, arg4); LSS_REG(4, arg5); \ + LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2), "r"(__r3), \ + "r"(__r4)); \ + } + #undef _syscall6 + #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ + type5,arg5,type6,arg6) \ + type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \ + type5 arg5, type6 arg6) { \ + LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3); \ + LSS_REG(3, arg4); LSS_REG(4, arg5); LSS_REG(5, arg6); \ + LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2), "r"(__r3), \ + "r"(__r4), "r"(__r5)); \ + } + LSS_INLINE int LSS_NAME(clone)(int (*fn)(void *), void *child_stack, + int flags, void *arg, int *parent_tidptr, + void *newtls, int *child_tidptr) { + long __res; + if (fn == NULL || child_stack == NULL) { + __res = -EINVAL; + LSS_RETURN(int, __res); + } + + /* Push "arg" and "fn" onto the stack that will be + * used by the child. + */ + { + uintptr_t* cstack = (uintptr_t*)child_stack - 2; + cstack[0] = (uintptr_t)fn; + cstack[1] = (uintptr_t)arg; + child_stack = cstack; + } + { + register int __flags __asm__("r0") = flags; + register void *__stack __asm__("r1") = child_stack; + register void *__ptid __asm__("r2") = parent_tidptr; + register void *__tls __asm__("r3") = newtls; + register int *__ctid __asm__("r4") = child_tidptr; + __asm__ __volatile__( +#ifdef __thumb2__ + "push {r7}\n" +#endif + /* %r0 = syscall(%r0 = flags, + * %r1 = child_stack, + * %r2 = parent_tidptr, + * %r3 = newtls, + * %r4 = child_tidptr) + */ + "mov r7, %6\n" + "swi 0x0\n" + + /* if (%r0 != 0) + * return %r0; + */ + "cmp r0, #0\n" + "bne 1f\n" + + /* In the child, now. Call "fn(arg)". + */ + "ldr r0,[sp, #4]\n" + + "ldr lr,[sp]\n" + "blx lr\n" + + /* Call _exit(%r0). + */ + "mov r7, %7\n" + "swi 0x0\n" + /* Unreachable */ + "bkpt #0\n" + "1:\n" +#ifdef __thumb2__ + "pop {r7}\n" +#endif + "movs %0,r0\n" + : "=r"(__res) + : "r"(__stack), "r"(__flags), "r"(__ptid), "r"(__tls), "r"(__ctid), + "i"(__NR_clone), "i"(__NR_exit) + : "cc", "lr", "memory" +#ifndef __thumb2__ + , "r7" +#endif + ); + } + LSS_RETURN(int, __res); + } + #elif defined(__aarch64__) + /* Most definitions of _syscallX() neglect to mark "memory" as being + * clobbered. This causes problems with compilers, that do a better job + * at optimizing across __asm__ calls. + * So, we just have to redefine all of the _syscallX() macros. + */ + #undef LSS_REG + #define LSS_REG(r,a) register int64_t __r##r __asm__("x"#r) = (int64_t)a + #undef LSS_BODY + #define LSS_BODY(type,name,args...) \ + register int64_t __res_x0 __asm__("x0"); \ + int64_t __res; \ + __asm__ __volatile__ ("mov x8, %1\n" \ + "svc 0x0\n" \ + : "=r"(__res_x0) \ + : "i"(__NR_##name) , ## args \ + : "x8", "memory"); \ + __res = __res_x0; \ + LSS_RETURN(type, __res) + #undef _syscall0 + #define _syscall0(type, name) \ + type LSS_NAME(name)(void) { \ + LSS_BODY(type, name); \ + } + #undef _syscall1 + #define _syscall1(type, name, type1, arg1) \ + type LSS_NAME(name)(type1 arg1) { \ + LSS_REG(0, arg1); LSS_BODY(type, name, "r"(__r0)); \ + } + #undef _syscall2 + #define _syscall2(type, name, type1, arg1, type2, arg2) \ + type LSS_NAME(name)(type1 arg1, type2 arg2) { \ + LSS_REG(0, arg1); LSS_REG(1, arg2); \ + LSS_BODY(type, name, "r"(__r0), "r"(__r1)); \ + } + #undef _syscall3 + #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3) \ + type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3) { \ + LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3); \ + LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2)); \ + } + #undef _syscall4 + #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ + type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \ + LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3); \ + LSS_REG(3, arg4); \ + LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2), "r"(__r3)); \ + } + #undef _syscall5 + #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ + type5,arg5) \ + type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \ + type5 arg5) { \ + LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3); \ + LSS_REG(3, arg4); LSS_REG(4, arg5); \ + LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2), "r"(__r3), \ + "r"(__r4)); \ + } + #undef _syscall6 + #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ + type5,arg5,type6,arg6) \ + type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \ + type5 arg5, type6 arg6) { \ + LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3); \ + LSS_REG(3, arg4); LSS_REG(4, arg5); LSS_REG(5, arg6); \ + LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2), "r"(__r3), \ + "r"(__r4), "r"(__r5)); \ + } + + LSS_INLINE int LSS_NAME(clone)(int (*fn)(void *), void *child_stack, + int flags, void *arg, int *parent_tidptr, + void *newtls, int *child_tidptr) { + int64_t __res; + { + register uint64_t __flags __asm__("x0") = flags; + register void *__stack __asm__("x1") = child_stack; + register void *__ptid __asm__("x2") = parent_tidptr; + register void *__tls __asm__("x3") = newtls; + register int *__ctid __asm__("x4") = child_tidptr; + __asm__ __volatile__(/* Push "arg" and "fn" onto the stack that will be + * used by the child. + */ + "stp %1, %4, [%2, #-16]!\n" + + /* %x0 = syscall(%x0 = flags, + * %x1 = child_stack, + * %x2 = parent_tidptr, + * %x3 = newtls, + * %x4 = child_tidptr) + */ + "mov x8, %8\n" + "svc 0x0\n" + + /* if (%r0 != 0) + * return %r0; + */ + "mov %0, x0\n" + "cbnz x0, 1f\n" + + /* In the child, now. Call "fn(arg)". + */ + "ldp x1, x0, [sp], #16\n" + "blr x1\n" + + /* Call _exit(%r0). + */ + "mov x8, %9\n" + "svc 0x0\n" + "1:\n" + : "=r" (__res) + : "r"(fn), "r"(__stack), "r"(__flags), "r"(arg), + "r"(__ptid), "r"(__tls), "r"(__ctid), + "i"(__NR_clone), "i"(__NR_exit) + : "cc", "x8", "memory"); + } + LSS_RETURN(int, __res); + } + #elif defined(__mips__) + #undef LSS_REG + #define LSS_REG(r,a) register unsigned long __r##r __asm__("$"#r) = \ + (unsigned long)(a) + #undef LSS_BODY + #undef LSS_SYSCALL_CLOBBERS + #if _MIPS_SIM == _MIPS_SIM_ABI32 + #define LSS_SYSCALL_CLOBBERS "$1", "$3", "$8", "$9", "$10", \ + "$11", "$12", "$13", "$14", "$15", \ + "$24", "$25", "hi", "lo", "memory" + #else + #define LSS_SYSCALL_CLOBBERS "$1", "$3", "$10", "$11", "$12", \ + "$13", "$14", "$15", "$24", "$25", \ + "hi", "lo", "memory" + #endif + #define LSS_BODY(type,name,r7,...) \ + register unsigned long __v0 __asm__("$2") = __NR_##name; \ + __asm__ __volatile__ ("syscall\n" \ + : "=r"(__v0), r7 (__r7) \ + : "0"(__v0), ##__VA_ARGS__ \ + : LSS_SYSCALL_CLOBBERS); \ + LSS_RETURN(type, __v0, __r7) + #undef _syscall0 + #define _syscall0(type, name) \ + type LSS_NAME(name)(void) { \ + register unsigned long __r7 __asm__("$7"); \ + LSS_BODY(type, name, "=r"); \ + } + #undef _syscall1 + #define _syscall1(type, name, type1, arg1) \ + type LSS_NAME(name)(type1 arg1) { \ + register unsigned long __r7 __asm__("$7"); \ + LSS_REG(4, arg1); LSS_BODY(type, name, "=r", "r"(__r4)); \ + } + #undef _syscall2 + #define _syscall2(type, name, type1, arg1, type2, arg2) \ + type LSS_NAME(name)(type1 arg1, type2 arg2) { \ + register unsigned long __r7 __asm__("$7"); \ + LSS_REG(4, arg1); LSS_REG(5, arg2); \ + LSS_BODY(type, name, "=r", "r"(__r4), "r"(__r5)); \ + } + #undef _syscall3 + #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3) \ + type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3) { \ + register unsigned long __r7 __asm__("$7"); \ + LSS_REG(4, arg1); LSS_REG(5, arg2); LSS_REG(6, arg3); \ + LSS_BODY(type, name, "=r", "r"(__r4), "r"(__r5), "r"(__r6)); \ + } + #undef _syscall4 + #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ + type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \ + LSS_REG(4, arg1); LSS_REG(5, arg2); LSS_REG(6, arg3); \ + LSS_REG(7, arg4); \ + LSS_BODY(type, name, "+r", "r"(__r4), "r"(__r5), "r"(__r6)); \ + } + #undef _syscall5 + #if _MIPS_SIM == _MIPS_SIM_ABI32 + /* The old 32bit MIPS system call API passes the fifth and sixth argument + * on the stack, whereas the new APIs use registers "r8" and "r9". + */ + #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ + type5,arg5) \ + type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \ + type5 arg5) { \ + LSS_REG(4, arg1); LSS_REG(5, arg2); LSS_REG(6, arg3); \ + LSS_REG(7, arg4); \ + register unsigned long __v0 __asm__("$2") = __NR_##name; \ + __asm__ __volatile__ (".set noreorder\n" \ + "subu $29, 32\n" \ + "sw %5, 16($29)\n" \ + "syscall\n" \ + "addiu $29, 32\n" \ + ".set reorder\n" \ + : "+r"(__v0), "+r" (__r7) \ + : "r"(__r4), "r"(__r5), \ + "r"(__r6), "r" ((unsigned long)arg5) \ + : "$8", "$9", "$10", "$11", "$12", \ + "$13", "$14", "$15", "$24", "$25", \ + "memory"); \ + LSS_RETURN(type, __v0, __r7); \ + } + #else + #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ + type5,arg5) \ + type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \ + type5 arg5) { \ + LSS_REG(4, arg1); LSS_REG(5, arg2); LSS_REG(6, arg3); \ + LSS_REG(7, arg4); LSS_REG(8, arg5); \ + LSS_BODY(type, name, "+r", "r"(__r4), "r"(__r5), "r"(__r6), \ + "r"(__r8)); \ + } + #endif + #undef _syscall6 + #if _MIPS_SIM == _MIPS_SIM_ABI32 + /* The old 32bit MIPS system call API passes the fifth and sixth argument + * on the stack, whereas the new APIs use registers "r8" and "r9". + */ + #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ + type5,arg5,type6,arg6) \ + type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \ + type5 arg5, type6 arg6) { \ + LSS_REG(4, arg1); LSS_REG(5, arg2); LSS_REG(6, arg3); \ + LSS_REG(7, arg4); \ + register unsigned long __v0 __asm__("$2") = __NR_##name; \ + __asm__ __volatile__ (".set noreorder\n" \ + "subu $29, 32\n" \ + "sw %5, 16($29)\n" \ + "sw %6, 20($29)\n" \ + "syscall\n" \ + "addiu $29, 32\n" \ + ".set reorder\n" \ + : "+r"(__v0), "+r" (__r7) \ + : "r"(__r4), "r"(__r5), \ + "r"(__r6), "r" ((unsigned long)arg5), \ + "r" ((unsigned long)arg6) \ + : "$8", "$9", "$10", "$11", "$12", \ + "$13", "$14", "$15", "$24", "$25", \ + "memory"); \ + LSS_RETURN(type, __v0, __r7); \ + } + #else + #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ + type5,arg5,type6,arg6) \ + type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \ + type5 arg5,type6 arg6) { \ + LSS_REG(4, arg1); LSS_REG(5, arg2); LSS_REG(6, arg3); \ + LSS_REG(7, arg4); LSS_REG(8, arg5); LSS_REG(9, arg6); \ + LSS_BODY(type, name, "+r", "r"(__r4), "r"(__r5), "r"(__r6), \ + "r"(__r8), "r"(__r9)); \ + } + #endif + LSS_INLINE int LSS_NAME(clone)(int (*fn)(void *), void *child_stack, + int flags, void *arg, int *parent_tidptr, + void *newtls, int *child_tidptr) { + register unsigned long __v0 __asm__("$2") = -EINVAL; + register unsigned long __r7 __asm__("$7") = (unsigned long)newtls; + { + register int __flags __asm__("$4") = flags; + register void *__stack __asm__("$5") = child_stack; + register void *__ptid __asm__("$6") = parent_tidptr; + register int *__ctid __asm__("$8") = child_tidptr; + __asm__ __volatile__( + #if _MIPS_SIM == _MIPS_SIM_ABI32 && _MIPS_SZPTR == 32 + "subu $29,24\n" + #elif _MIPS_SIM == _MIPS_SIM_NABI32 + "sub $29,16\n" + #else + "dsubu $29,16\n" + #endif + + /* if (fn == NULL || child_stack == NULL) + * return -EINVAL; + */ + "beqz %4,1f\n" + "beqz %5,1f\n" + + /* Push "arg" and "fn" onto the stack that will be + * used by the child. + */ + #if _MIPS_SIM == _MIPS_SIM_ABI32 && _MIPS_SZPTR == 32 + "subu %5,32\n" + "sw %4,0(%5)\n" + "sw %7,4(%5)\n" + #elif _MIPS_SIM == _MIPS_SIM_NABI32 + "sub %5,32\n" + "sw %4,0(%5)\n" + "sw %7,8(%5)\n" + #else + "dsubu %5,32\n" + "sd %4,0(%5)\n" + "sd %7,8(%5)\n" + #endif + + /* $7 = syscall($4 = flags, + * $5 = child_stack, + * $6 = parent_tidptr, + * $7 = newtls, + * $8 = child_tidptr) + */ + "li $2,%2\n" + "syscall\n" + + /* if ($7 != 0) + * return $2; + */ + "bnez $7,1f\n" + "bnez $2,1f\n" + + /* In the child, now. Call "fn(arg)". + */ + #if _MIPS_SIM == _MIPS_SIM_ABI32 && _MIPS_SZPTR == 32 + "lw $25,0($29)\n" + "lw $4,4($29)\n" + #elif _MIPS_SIM == _MIPS_SIM_NABI32 + "lw $25,0($29)\n" + "lw $4,8($29)\n" + #else + "ld $25,0($29)\n" + "ld $4,8($29)\n" + #endif + "jalr $25\n" + + /* Call _exit($2) + */ + "move $4,$2\n" + "li $2,%3\n" + "syscall\n" + + "1:\n" + #if _MIPS_SIM == _MIPS_SIM_ABI32 && _MIPS_SZPTR == 32 + "addu $29, 24\n" + #elif _MIPS_SIM == _MIPS_SIM_NABI32 + "add $29, 16\n" + #else + "daddu $29,16\n" + #endif + : "+r" (__v0), "+r" (__r7) + : "i"(__NR_clone), "i"(__NR_exit), "r"(fn), + "r"(__stack), "r"(__flags), "r"(arg), + "r"(__ptid), "r"(__ctid) + : "$9", "$10", "$11", "$12", "$13", "$14", "$15", + "$24", "$25", "memory"); + } + LSS_RETURN(int, __v0, __r7); + } + #elif defined (__PPC__) + #undef LSS_LOADARGS_0 + #define LSS_LOADARGS_0(name, dummy...) \ + __sc_0 = __NR_##name + #undef LSS_LOADARGS_1 + #define LSS_LOADARGS_1(name, arg1) \ + LSS_LOADARGS_0(name); \ + __sc_3 = (unsigned long) (arg1) + #undef LSS_LOADARGS_2 + #define LSS_LOADARGS_2(name, arg1, arg2) \ + LSS_LOADARGS_1(name, arg1); \ + __sc_4 = (unsigned long) (arg2) + #undef LSS_LOADARGS_3 + #define LSS_LOADARGS_3(name, arg1, arg2, arg3) \ + LSS_LOADARGS_2(name, arg1, arg2); \ + __sc_5 = (unsigned long) (arg3) + #undef LSS_LOADARGS_4 + #define LSS_LOADARGS_4(name, arg1, arg2, arg3, arg4) \ + LSS_LOADARGS_3(name, arg1, arg2, arg3); \ + __sc_6 = (unsigned long) (arg4) + #undef LSS_LOADARGS_5 + #define LSS_LOADARGS_5(name, arg1, arg2, arg3, arg4, arg5) \ + LSS_LOADARGS_4(name, arg1, arg2, arg3, arg4); \ + __sc_7 = (unsigned long) (arg5) + #undef LSS_LOADARGS_6 + #define LSS_LOADARGS_6(name, arg1, arg2, arg3, arg4, arg5, arg6) \ + LSS_LOADARGS_5(name, arg1, arg2, arg3, arg4, arg5); \ + __sc_8 = (unsigned long) (arg6) + #undef LSS_ASMINPUT_0 + #define LSS_ASMINPUT_0 "0" (__sc_0) + #undef LSS_ASMINPUT_1 + #define LSS_ASMINPUT_1 LSS_ASMINPUT_0, "1" (__sc_3) + #undef LSS_ASMINPUT_2 + #define LSS_ASMINPUT_2 LSS_ASMINPUT_1, "2" (__sc_4) + #undef LSS_ASMINPUT_3 + #define LSS_ASMINPUT_3 LSS_ASMINPUT_2, "3" (__sc_5) + #undef LSS_ASMINPUT_4 + #define LSS_ASMINPUT_4 LSS_ASMINPUT_3, "4" (__sc_6) + #undef LSS_ASMINPUT_5 + #define LSS_ASMINPUT_5 LSS_ASMINPUT_4, "5" (__sc_7) + #undef LSS_ASMINPUT_6 + #define LSS_ASMINPUT_6 LSS_ASMINPUT_5, "6" (__sc_8) + #undef LSS_BODY + #define LSS_BODY(nr, type, name, args...) \ + long __sc_ret, __sc_err; \ + { \ + register unsigned long __sc_0 __asm__ ("r0"); \ + register unsigned long __sc_3 __asm__ ("r3"); \ + register unsigned long __sc_4 __asm__ ("r4"); \ + register unsigned long __sc_5 __asm__ ("r5"); \ + register unsigned long __sc_6 __asm__ ("r6"); \ + register unsigned long __sc_7 __asm__ ("r7"); \ + register unsigned long __sc_8 __asm__ ("r8"); \ + \ + LSS_LOADARGS_##nr(name, args); \ + __asm__ __volatile__ \ + ("sc\n\t" \ + "mfcr %0" \ + : "=&r" (__sc_0), \ + "=&r" (__sc_3), "=&r" (__sc_4), \ + "=&r" (__sc_5), "=&r" (__sc_6), \ + "=&r" (__sc_7), "=&r" (__sc_8) \ + : LSS_ASMINPUT_##nr \ + : "cr0", "ctr", "memory", \ + "r9", "r10", "r11", "r12"); \ + __sc_ret = __sc_3; \ + __sc_err = __sc_0; \ + } \ + LSS_RETURN(type, __sc_ret, __sc_err) + #undef _syscall0 + #define _syscall0(type, name) \ + type LSS_NAME(name)(void) { \ + LSS_BODY(0, type, name); \ + } + #undef _syscall1 + #define _syscall1(type, name, type1, arg1) \ + type LSS_NAME(name)(type1 arg1) { \ + LSS_BODY(1, type, name, arg1); \ + } + #undef _syscall2 + #define _syscall2(type, name, type1, arg1, type2, arg2) \ + type LSS_NAME(name)(type1 arg1, type2 arg2) { \ + LSS_BODY(2, type, name, arg1, arg2); \ + } + #undef _syscall3 + #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3) \ + type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3) { \ + LSS_BODY(3, type, name, arg1, arg2, arg3); \ + } + #undef _syscall4 + #define _syscall4(type, name, type1, arg1, type2, arg2, type3, arg3, \ + type4, arg4) \ + type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \ + LSS_BODY(4, type, name, arg1, arg2, arg3, arg4); \ + } + #undef _syscall5 + #define _syscall5(type, name, type1, arg1, type2, arg2, type3, arg3, \ + type4, arg4, type5, arg5) \ + type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \ + type5 arg5) { \ + LSS_BODY(5, type, name, arg1, arg2, arg3, arg4, arg5); \ + } + #undef _syscall6 + #define _syscall6(type, name, type1, arg1, type2, arg2, type3, arg3, \ + type4, arg4, type5, arg5, type6, arg6) \ + type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \ + type5 arg5, type6 arg6) { \ + LSS_BODY(6, type, name, arg1, arg2, arg3, arg4, arg5, arg6); \ + } + /* clone function adapted from glibc 2.3.6 clone.S */ + /* TODO(csilvers): consider wrapping some args up in a struct, like we + * do for i386's _syscall6, so we can compile successfully on gcc 2.95 + */ + LSS_INLINE int LSS_NAME(clone)(int (*fn)(void *), void *child_stack, + int flags, void *arg, int *parent_tidptr, + void *newtls, int *child_tidptr) { + long __ret, __err; + { + register int (*__fn)(void *) __asm__ ("r8") = fn; + register void *__cstack __asm__ ("r4") = child_stack; + register int __flags __asm__ ("r3") = flags; + register void * __arg __asm__ ("r9") = arg; + register int * __ptidptr __asm__ ("r5") = parent_tidptr; + register void * __newtls __asm__ ("r6") = newtls; + register int * __ctidptr __asm__ ("r7") = child_tidptr; + __asm__ __volatile__( + /* check for fn == NULL + * and child_stack == NULL + */ + "cmpwi cr0, %6, 0\n\t" + "cmpwi cr1, %7, 0\n\t" + "cror cr0*4+eq, cr1*4+eq, cr0*4+eq\n\t" + "beq- cr0, 1f\n\t" + + /* set up stack frame for child */ + "clrrwi %7, %7, 4\n\t" + "li 0, 0\n\t" + "stwu 0, -16(%7)\n\t" + + /* fn, arg, child_stack are saved across the syscall: r28-30 */ + "mr 28, %6\n\t" + "mr 29, %7\n\t" + "mr 27, %9\n\t" + + /* syscall */ + "li 0, %4\n\t" + /* flags already in r3 + * child_stack already in r4 + * ptidptr already in r5 + * newtls already in r6 + * ctidptr already in r7 + */ + "sc\n\t" + + /* Test if syscall was successful */ + "cmpwi cr1, 3, 0\n\t" + "crandc cr1*4+eq, cr1*4+eq, cr0*4+so\n\t" + "bne- cr1, 1f\n\t" + + /* Do the function call */ + "mtctr 28\n\t" + "mr 3, 27\n\t" + "bctrl\n\t" + + /* Call _exit(r3) */ + "li 0, %5\n\t" + "sc\n\t" + + /* Return to parent */ + "1:\n" + "mfcr %1\n\t" + "mr %0, 3\n\t" + : "=r" (__ret), "=r" (__err) + : "0" (-1), "1" (EINVAL), + "i" (__NR_clone), "i" (__NR_exit), + "r" (__fn), "r" (__cstack), "r" (__flags), + "r" (__arg), "r" (__ptidptr), "r" (__newtls), + "r" (__ctidptr) + : "cr0", "cr1", "memory", "ctr", + "r0", "r29", "r27", "r28"); + } + LSS_RETURN(int, __ret, __err); + } + #elif defined(__s390__) + #undef LSS_REG + #define LSS_REG(r, a) register unsigned long __r##r __asm__("r"#r) = (unsigned long) a + #undef LSS_BODY + #define LSS_BODY(type, name, args...) \ + register unsigned long __nr __asm__("r1") \ + = (unsigned long)(__NR_##name); \ + register long __res_r2 __asm__("r2"); \ + long __res; \ + __asm__ __volatile__ \ + ("svc 0\n\t" \ + : "=d"(__res_r2) \ + : "d"(__nr), ## args \ + : "memory"); \ + __res = __res_r2; \ + LSS_RETURN(type, __res) + #undef _syscall0 + #define _syscall0(type, name) \ + type LSS_NAME(name)(void) { \ + LSS_BODY(type, name); \ + } + #undef _syscall1 + #define _syscall1(type, name, type1, arg1) \ + type LSS_NAME(name)(type1 arg1) { \ + LSS_REG(2, arg1); \ + LSS_BODY(type, name, "0"(__r2)); \ + } + #undef _syscall2 + #define _syscall2(type, name, type1, arg1, type2, arg2) \ + type LSS_NAME(name)(type1 arg1, type2 arg2) { \ + LSS_REG(2, arg1); LSS_REG(3, arg2); \ + LSS_BODY(type, name, "0"(__r2), "d"(__r3)); \ + } + #undef _syscall3 + #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3) \ + type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3) { \ + LSS_REG(2, arg1); LSS_REG(3, arg2); LSS_REG(4, arg3); \ + LSS_BODY(type, name, "0"(__r2), "d"(__r3), "d"(__r4)); \ + } + #undef _syscall4 + #define _syscall4(type, name, type1, arg1, type2, arg2, type3, arg3, \ + type4, arg4) \ + type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, \ + type4 arg4) { \ + LSS_REG(2, arg1); LSS_REG(3, arg2); LSS_REG(4, arg3); \ + LSS_REG(5, arg4); \ + LSS_BODY(type, name, "0"(__r2), "d"(__r3), "d"(__r4), \ + "d"(__r5)); \ + } + #undef _syscall5 + #define _syscall5(type, name, type1, arg1, type2, arg2, type3, arg3, \ + type4, arg4, type5, arg5) \ + type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, \ + type4 arg4, type5 arg5) { \ + LSS_REG(2, arg1); LSS_REG(3, arg2); LSS_REG(4, arg3); \ + LSS_REG(5, arg4); LSS_REG(6, arg5); \ + LSS_BODY(type, name, "0"(__r2), "d"(__r3), "d"(__r4), \ + "d"(__r5), "d"(__r6)); \ + } + #undef _syscall6 + #define _syscall6(type, name, type1, arg1, type2, arg2, type3, arg3, \ + type4, arg4, type5, arg5, type6, arg6) \ + type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, \ + type4 arg4, type5 arg5, type6 arg6) { \ + LSS_REG(2, arg1); LSS_REG(3, arg2); LSS_REG(4, arg3); \ + LSS_REG(5, arg4); LSS_REG(6, arg5); LSS_REG(7, arg6); \ + LSS_BODY(type, name, "0"(__r2), "d"(__r3), "d"(__r4), \ + "d"(__r5), "d"(__r6), "d"(__r7)); \ + } + LSS_INLINE int LSS_NAME(clone)(int (*fn)(void *), void *child_stack, + int flags, void *arg, int *parent_tidptr, + void *newtls, int *child_tidptr) { + long __ret; + { + register int (*__fn)(void *) __asm__ ("r1") = fn; + register void *__cstack __asm__ ("r2") = child_stack; + register int __flags __asm__ ("r3") = flags; + register void *__arg __asm__ ("r0") = arg; + register int *__ptidptr __asm__ ("r4") = parent_tidptr; + register void *__newtls __asm__ ("r6") = newtls; + register int *__ctidptr __asm__ ("r5") = child_tidptr; + __asm__ __volatile__ ( + #ifndef __s390x__ + /* arg already in r0 */ + "ltr %4, %4\n\t" /* check fn, which is already in r1 */ + "jz 1f\n\t" /* NULL function pointer, return -EINVAL */ + "ltr %5, %5\n\t" /* check child_stack, which is already in r2 */ + "jz 1f\n\t" /* NULL stack pointer, return -EINVAL */ + /* flags already in r3 */ + /* parent_tidptr already in r4 */ + /* child_tidptr already in r5 */ + /* newtls already in r6 */ + "svc %2\n\t" /* invoke clone syscall */ + "ltr %0,%%r2\n\t" /* load return code into __ret and test */ + "jnz 1f\n\t" /* return to parent if non-zero */ + /* start child thread */ + "lr %%r2, %7\n\t" /* set first parameter to void *arg */ + "ahi %%r15, -96\n\t" /* make room on the stack for the save area */ + "xc 0(4,%%r15), 0(%%r15)\n\t" + "basr %%r14, %4\n\t" /* jump to fn */ + "svc %3\n" /* invoke exit syscall */ + "1:\n" + #else + /* arg already in r0 */ + "ltgr %4, %4\n\t" /* check fn, which is already in r1 */ + "jz 1f\n\t" /* NULL function pointer, return -EINVAL */ + "ltgr %5, %5\n\t" /* check child_stack, which is already in r2 */ + "jz 1f\n\t" /* NULL stack pointer, return -EINVAL */ + /* flags already in r3 */ + /* parent_tidptr already in r4 */ + /* child_tidptr already in r5 */ + /* newtls already in r6 */ + "svc %2\n\t" /* invoke clone syscall */ + "ltgr %0, %%r2\n\t" /* load return code into __ret and test */ + "jnz 1f\n\t" /* return to parent if non-zero */ + /* start child thread */ + "lgr %%r2, %7\n\t" /* set first parameter to void *arg */ + "aghi %%r15, -160\n\t" /* make room on the stack for the save area */ + "xc 0(8,%%r15), 0(%%r15)\n\t" + "basr %%r14, %4\n\t" /* jump to fn */ + "svc %3\n" /* invoke exit syscall */ + "1:\n" + #endif + : "=r" (__ret) + : "0" (-EINVAL), "i" (__NR_clone), "i" (__NR_exit), + "d" (__fn), "d" (__cstack), "d" (__flags), "d" (__arg), + "d" (__ptidptr), "d" (__newtls), "d" (__ctidptr) + : "cc", "r14", "memory" + ); + } + LSS_RETURN(int, __ret); + } + #endif + #define __NR__exit __NR_exit + #define __NR__gettid __NR_gettid + #define __NR__mremap __NR_mremap + LSS_INLINE _syscall1(void *, brk, void *, e) + LSS_INLINE _syscall1(int, chdir, const char *,p) + LSS_INLINE _syscall1(int, close, int, f) + LSS_INLINE _syscall2(int, clock_getres, int, c, + struct kernel_timespec*, t) + LSS_INLINE _syscall2(int, clock_gettime, int, c, + struct kernel_timespec*, t) + LSS_INLINE _syscall1(int, dup, int, f) + #if defined(__NR_dup2) + // dup2 is polyfilled below when not available. + LSS_INLINE _syscall2(int, dup2, int, s, + int, d) + #endif + #if defined(__NR_dup3) + LSS_INLINE _syscall3(int, dup3, int, s, int, d, int, f) + #endif + LSS_INLINE _syscall3(int, execve, const char*, f, + const char*const*,a,const char*const*, e) + LSS_INLINE _syscall1(int, _exit, int, e) + LSS_INLINE _syscall1(int, exit_group, int, e) + LSS_INLINE _syscall3(int, fcntl, int, f, + int, c, long, a) + #if defined(__NR_fork) + // fork is polyfilled below when not available. + LSS_INLINE _syscall0(pid_t, fork) + #endif + LSS_INLINE _syscall2(int, fstat, int, f, + struct kernel_stat*, b) + LSS_INLINE _syscall2(int, fstatfs, int, f, + struct kernel_statfs*, b) + #if defined(__x86_64__) + /* Need to make sure off_t isn't truncated to 32-bits under x32. */ + LSS_INLINE int LSS_NAME(ftruncate)(int f, off_t l) { + LSS_BODY(2, int, ftruncate, LSS_SYSCALL_ARG(f), (uint64_t)(l)); + } + #else + LSS_INLINE _syscall2(int, ftruncate, int, f, + off_t, l) + #endif + LSS_INLINE _syscall6(int, futex, int*, u, + int, o, int, v, + struct kernel_timespec*, t, + int*, u2, int, v2) + LSS_INLINE _syscall3(int, getdents, int, f, + struct kernel_dirent*, d, int, c) + LSS_INLINE _syscall3(int, getdents64, int, f, + struct kernel_dirent64*, d, int, c) + LSS_INLINE _syscall0(gid_t, getegid) + LSS_INLINE _syscall0(uid_t, geteuid) + #if defined(__NR_getpgrp) + LSS_INLINE _syscall0(pid_t, getpgrp) + #endif + LSS_INLINE _syscall0(pid_t, getpid) + LSS_INLINE _syscall0(pid_t, getppid) + LSS_INLINE _syscall2(int, getpriority, int, a, + int, b) + LSS_INLINE _syscall3(int, getresgid, gid_t *, r, + gid_t *, e, gid_t *, s) + LSS_INLINE _syscall3(int, getresuid, uid_t *, r, + uid_t *, e, uid_t *, s) +#if !defined(__ARM_EABI__) + LSS_INLINE _syscall2(int, getrlimit, int, r, + struct kernel_rlimit*, l) +#endif + LSS_INLINE _syscall1(pid_t, getsid, pid_t, p) + LSS_INLINE _syscall0(pid_t, _gettid) + LSS_INLINE _syscall2(pid_t, gettimeofday, struct kernel_timeval*, t, + void*, tz) + LSS_INLINE _syscall5(int, setxattr, const char *,p, + const char *, n, const void *,v, + size_t, s, int, f) + LSS_INLINE _syscall5(int, lsetxattr, const char *,p, + const char *, n, const void *,v, + size_t, s, int, f) + LSS_INLINE _syscall4(ssize_t, getxattr, const char *,p, + const char *, n, void *, v, size_t, s) + LSS_INLINE _syscall4(ssize_t, lgetxattr, const char *,p, + const char *, n, void *, v, size_t, s) + LSS_INLINE _syscall3(ssize_t, listxattr, const char *,p, + char *, l, size_t, s) + LSS_INLINE _syscall3(ssize_t, llistxattr, const char *,p, + char *, l, size_t, s) + LSS_INLINE _syscall3(int, ioctl, int, d, + int, r, void *, a) + LSS_INLINE _syscall2(int, ioprio_get, int, which, + int, who) + LSS_INLINE _syscall3(int, ioprio_set, int, which, + int, who, int, ioprio) + LSS_INLINE _syscall2(int, kill, pid_t, p, + int, s) + #if defined(__x86_64__) + /* Need to make sure off_t isn't truncated to 32-bits under x32. */ + LSS_INLINE off_t LSS_NAME(lseek)(int f, off_t o, int w) { + _LSS_BODY(3, off_t, lseek, off_t, LSS_SYSCALL_ARG(f), (uint64_t)(o), + LSS_SYSCALL_ARG(w)); + } + #else + LSS_INLINE _syscall3(off_t, lseek, int, f, + off_t, o, int, w) + #endif + LSS_INLINE _syscall2(int, munmap, void*, s, + size_t, l) + LSS_INLINE _syscall6(long, move_pages, pid_t, p, + unsigned long, n, void **,g, int *, d, + int *, s, int, f) + LSS_INLINE _syscall3(int, mprotect, const void *,a, + size_t, l, int, p) + LSS_INLINE _syscall5(void*, _mremap, void*, o, + size_t, os, size_t, ns, + unsigned long, f, void *, a) + #if defined(__NR_open) + // open is polyfilled below when not available. + LSS_INLINE _syscall3(int, open, const char*, p, + int, f, int, m) + #endif + #if defined(__NR_poll) + // poll is polyfilled below when not available. + LSS_INLINE _syscall3(int, poll, struct kernel_pollfd*, u, + unsigned int, n, int, t) + #endif + #if defined(__NR_ppoll) + LSS_INLINE _syscall5(int, ppoll, struct kernel_pollfd *, u, + unsigned int, n, const struct kernel_timespec *, t, + const struct kernel_sigset_t *, sigmask, size_t, s) + #endif + LSS_INLINE _syscall5(int, prctl, int, option, + unsigned long, arg2, + unsigned long, arg3, + unsigned long, arg4, + unsigned long, arg5) + LSS_INLINE _syscall4(long, ptrace, int, r, + pid_t, p, void *, a, void *, d) + #if defined(__NR_quotactl) + // Defined on x86_64 / i386 only + LSS_INLINE _syscall4(int, quotactl, int, cmd, const char *, special, + int, id, caddr_t, addr) + #endif + LSS_INLINE _syscall3(ssize_t, read, int, f, + void *, b, size_t, c) + #if defined(__NR_readlink) + // readlink is polyfilled below when not available. + LSS_INLINE _syscall3(int, readlink, const char*, p, + char*, b, size_t, s) + #endif + #if defined(__NR_readlinkat) + LSS_INLINE _syscall4(int, readlinkat, int, d, const char *, p, char *, b, + size_t, s) + #endif + LSS_INLINE _syscall4(int, rt_sigaction, int, s, + const struct kernel_sigaction*, a, + struct kernel_sigaction*, o, size_t, c) + LSS_INLINE _syscall2(int, rt_sigpending, struct kernel_sigset_t *, s, + size_t, c) + LSS_INLINE _syscall4(int, rt_sigprocmask, int, h, + const struct kernel_sigset_t*, s, + struct kernel_sigset_t*, o, size_t, c) + LSS_INLINE _syscall2(int, rt_sigsuspend, + const struct kernel_sigset_t*, s, size_t, c) + LSS_INLINE _syscall4(int, rt_sigtimedwait, const struct kernel_sigset_t*, s, + siginfo_t*, i, const struct timespec*, t, size_t, c) + LSS_INLINE _syscall3(int, sched_getaffinity,pid_t, p, + unsigned int, l, unsigned long *, m) + LSS_INLINE _syscall3(int, sched_setaffinity,pid_t, p, + unsigned int, l, unsigned long *, m) + LSS_INLINE _syscall0(int, sched_yield) + LSS_INLINE _syscall1(long, set_tid_address, int *, t) + LSS_INLINE _syscall1(int, setfsgid, gid_t, g) + LSS_INLINE _syscall1(int, setfsuid, uid_t, u) + LSS_INLINE _syscall1(int, setuid, uid_t, u) + LSS_INLINE _syscall1(int, setgid, gid_t, g) + LSS_INLINE _syscall2(int, setpgid, pid_t, p, + pid_t, g) + LSS_INLINE _syscall3(int, setpriority, int, a, + int, b, int, p) + LSS_INLINE _syscall3(int, setresgid, gid_t, r, + gid_t, e, gid_t, s) + LSS_INLINE _syscall3(int, setresuid, uid_t, r, + uid_t, e, uid_t, s) + LSS_INLINE _syscall2(int, setrlimit, int, r, + const struct kernel_rlimit*, l) + LSS_INLINE _syscall0(pid_t, setsid) + LSS_INLINE _syscall2(int, sigaltstack, const stack_t*, s, + const stack_t*, o) + #if defined(__NR_sigreturn) + LSS_INLINE _syscall1(int, sigreturn, unsigned long, u) + #endif + #if defined(__NR_stat) + // stat is polyfilled below when not available. + LSS_INLINE _syscall2(int, stat, const char*, f, + struct kernel_stat*, b) + #endif + LSS_INLINE _syscall2(int, statfs, const char*, f, + struct kernel_statfs*, b) + LSS_INLINE _syscall3(int, tgkill, pid_t, p, + pid_t, t, int, s) + LSS_INLINE _syscall2(int, tkill, pid_t, p, + int, s) + #if defined(__NR_unlink) + // unlink is polyfilled below when not available. + LSS_INLINE _syscall1(int, unlink, const char*, f) + #endif + LSS_INLINE _syscall3(ssize_t, write, int, f, + const void *, b, size_t, c) + LSS_INLINE _syscall3(ssize_t, writev, int, f, + const struct kernel_iovec*, v, size_t, c) + #if defined(__NR_getcpu) + LSS_INLINE _syscall3(long, getcpu, unsigned *, cpu, + unsigned *, node, void *, unused) + #endif + #if defined(__x86_64__) || \ + (defined(__mips__) && _MIPS_SIM != _MIPS_SIM_ABI32) + LSS_INLINE _syscall3(int, recvmsg, int, s, + struct kernel_msghdr*, m, int, f) + LSS_INLINE _syscall3(int, sendmsg, int, s, + const struct kernel_msghdr*, m, int, f) + LSS_INLINE _syscall6(int, sendto, int, s, + const void*, m, size_t, l, + int, f, + const struct kernel_sockaddr*, a, int, t) + LSS_INLINE _syscall2(int, shutdown, int, s, + int, h) + LSS_INLINE _syscall3(int, socket, int, d, + int, t, int, p) + LSS_INLINE _syscall4(int, socketpair, int, d, + int, t, int, p, int*, s) + #endif + #if defined(__NR_fadvise64) + #if defined(__x86_64__) + /* Need to make sure loff_t isn't truncated to 32-bits under x32. */ + LSS_INLINE int LSS_NAME(fadvise64)(int fd, loff_t offset, loff_t len, + int advice) { + LSS_BODY(4, int, fadvise64, LSS_SYSCALL_ARG(fd), (uint64_t)(offset), + (uint64_t)(len), LSS_SYSCALL_ARG(advice)); + } + #else + LSS_INLINE _syscall4(int, fadvise64, + int, fd, loff_t, offset, loff_t, len, int, advice) + #endif + #elif defined(__i386__) + #define __NR__fadvise64_64 __NR_fadvise64_64 + LSS_INLINE _syscall6(int, _fadvise64_64, int, fd, + unsigned, offset_lo, unsigned, offset_hi, + unsigned, len_lo, unsigned, len_hi, + int, advice) + + LSS_INLINE int LSS_NAME(fadvise64)(int fd, loff_t offset, + loff_t len, int advice) { + return LSS_NAME(_fadvise64_64)(fd, + (unsigned)offset, (unsigned)(offset >>32), + (unsigned)len, (unsigned)(len >> 32), + advice); + } + + #elif defined(__s390__) && !defined(__s390x__) + #define __NR__fadvise64_64 __NR_fadvise64_64 + struct kernel_fadvise64_64_args { + int fd; + long long offset; + long long len; + int advice; + }; + + LSS_INLINE _syscall1(int, _fadvise64_64, + struct kernel_fadvise64_64_args *args) + + LSS_INLINE int LSS_NAME(fadvise64)(int fd, loff_t offset, + loff_t len, int advice) { + struct kernel_fadvise64_64_args args = { fd, offset, len, advice }; + return LSS_NAME(_fadvise64_64)(&args); + } + #endif + #if defined(__NR_fallocate) + #if defined(__x86_64__) + /* Need to make sure loff_t isn't truncated to 32-bits under x32. */ + LSS_INLINE int LSS_NAME(fallocate)(int f, int mode, loff_t offset, + loff_t len) { + LSS_BODY(4, int, fallocate, LSS_SYSCALL_ARG(f), LSS_SYSCALL_ARG(mode), + (uint64_t)(offset), (uint64_t)(len)); + } + #elif (defined(__i386__) || (defined(__s390__) && !defined(__s390x__)) \ + || defined(__ARM_ARCH_3__) || defined(__ARM_EABI__) \ + || (defined(__mips__) && _MIPS_SIM == _MIPS_SIM_ABI32) \ + || defined(__PPC__)) + #define __NR__fallocate __NR_fallocate + LSS_INLINE _syscall6(int, _fallocate, int, fd, + int, mode, + unsigned, offset_lo, unsigned, offset_hi, + unsigned, len_lo, unsigned, len_hi) + + LSS_INLINE int LSS_NAME(fallocate)(int fd, int mode, + loff_t offset, loff_t len) { + union { loff_t off; unsigned w[2]; } o = { offset }, l = { len }; + return LSS_NAME(_fallocate)(fd, mode, o.w[0], o.w[1], l.w[0], l.w[1]); + } + #else + LSS_INLINE _syscall4(int, fallocate, + int, f, int, mode, loff_t, offset, loff_t, len) + #endif + #endif + #if defined(__NR_newfstatat) + LSS_INLINE _syscall4(int, newfstatat, int, d, + const char *, p, + struct kernel_stat*, b, int, f) + #endif + #if defined(__x86_64__) || defined(__s390x__) + LSS_INLINE int LSS_NAME(getresgid32)(gid_t *rgid, + gid_t *egid, + gid_t *sgid) { + return LSS_NAME(getresgid)(rgid, egid, sgid); + } + + LSS_INLINE int LSS_NAME(getresuid32)(uid_t *ruid, + uid_t *euid, + uid_t *suid) { + return LSS_NAME(getresuid)(ruid, euid, suid); + } + + LSS_INLINE int LSS_NAME(setfsgid32)(gid_t gid) { + return LSS_NAME(setfsgid)(gid); + } + + LSS_INLINE int LSS_NAME(setfsuid32)(uid_t uid) { + return LSS_NAME(setfsuid)(uid); + } + + LSS_INLINE int LSS_NAME(setresgid32)(gid_t rgid, gid_t egid, gid_t sgid) { + return LSS_NAME(setresgid)(rgid, egid, sgid); + } + + LSS_INLINE int LSS_NAME(setresuid32)(uid_t ruid, uid_t euid, uid_t suid) { + return LSS_NAME(setresuid)(ruid, euid, suid); + } + + LSS_INLINE int LSS_NAME(sigaction)(int signum, + const struct kernel_sigaction *act, + struct kernel_sigaction *oldact) { + #if defined(__x86_64__) + /* On x86_64, the kernel requires us to always set our own + * SA_RESTORER in order to be able to return from a signal handler. + * This function must have a "magic" signature that the "gdb" + * (and maybe the kernel?) can recognize. + */ + if (act != NULL && !(act->sa_flags & SA_RESTORER)) { + struct kernel_sigaction a = *act; + a.sa_flags |= SA_RESTORER; + a.sa_restorer = LSS_NAME(restore_rt)(); + return LSS_NAME(rt_sigaction)(signum, &a, oldact, + (KERNEL_NSIG+7)/8); + } else + #endif + return LSS_NAME(rt_sigaction)(signum, act, oldact, + (KERNEL_NSIG+7)/8); + } + + LSS_INLINE int LSS_NAME(sigpending)(struct kernel_sigset_t *set) { + return LSS_NAME(rt_sigpending)(set, (KERNEL_NSIG+7)/8); + } + + LSS_INLINE int LSS_NAME(sigsuspend)(const struct kernel_sigset_t *set) { + return LSS_NAME(rt_sigsuspend)(set, (KERNEL_NSIG+7)/8); + } + #endif + #if defined(__NR_rt_sigprocmask) + LSS_INLINE int LSS_NAME(sigprocmask)(int how, + const struct kernel_sigset_t *set, + struct kernel_sigset_t *oldset) { + return LSS_NAME(rt_sigprocmask)(how, set, oldset, (KERNEL_NSIG+7)/8); + } + #endif + #if defined(__NR_rt_sigtimedwait) + LSS_INLINE int LSS_NAME(sigtimedwait)(const struct kernel_sigset_t *set, + siginfo_t *info, + const struct timespec *timeout) { + return LSS_NAME(rt_sigtimedwait)(set, info, timeout, (KERNEL_NSIG+7)/8); + } + #endif + #if defined(__NR_wait4) + LSS_INLINE _syscall4(pid_t, wait4, pid_t, p, + int*, s, int, o, + struct kernel_rusage*, r) + #endif + #if defined(__NR_openat) + LSS_INLINE _syscall4(int, openat, int, d, const char *, p, int, f, int, m) + #endif + #if defined(__NR_unlinkat) + LSS_INLINE _syscall3(int, unlinkat, int, d, const char *, p, int, f) + #endif + #if defined(__i386__) || defined(__ARM_ARCH_3__) || defined(__ARM_EABI__) || \ + (defined(__s390__) && !defined(__s390x__)) + #define __NR__getresgid32 __NR_getresgid32 + #define __NR__getresuid32 __NR_getresuid32 + #define __NR__setfsgid32 __NR_setfsgid32 + #define __NR__setfsuid32 __NR_setfsuid32 + #define __NR__setresgid32 __NR_setresgid32 + #define __NR__setresuid32 __NR_setresuid32 +#if defined(__ARM_EABI__) + LSS_INLINE _syscall2(int, ugetrlimit, int, r, + struct kernel_rlimit*, l) +#endif + LSS_INLINE _syscall3(int, _getresgid32, gid_t *, r, + gid_t *, e, gid_t *, s) + LSS_INLINE _syscall3(int, _getresuid32, uid_t *, r, + uid_t *, e, uid_t *, s) + LSS_INLINE _syscall1(int, _setfsgid32, gid_t, f) + LSS_INLINE _syscall1(int, _setfsuid32, uid_t, f) + LSS_INLINE _syscall3(int, _setresgid32, gid_t, r, + gid_t, e, gid_t, s) + LSS_INLINE _syscall3(int, _setresuid32, uid_t, r, + uid_t, e, uid_t, s) + + LSS_INLINE int LSS_NAME(getresgid32)(gid_t *rgid, + gid_t *egid, + gid_t *sgid) { + int rc; + if ((rc = LSS_NAME(_getresgid32)(rgid, egid, sgid)) < 0 && + LSS_ERRNO == ENOSYS) { + if ((rgid == NULL) || (egid == NULL) || (sgid == NULL)) { + return EFAULT; + } + // Clear the high bits first, since getresgid only sets 16 bits + *rgid = *egid = *sgid = 0; + rc = LSS_NAME(getresgid)(rgid, egid, sgid); + } + return rc; + } + + LSS_INLINE int LSS_NAME(getresuid32)(uid_t *ruid, + uid_t *euid, + uid_t *suid) { + int rc; + if ((rc = LSS_NAME(_getresuid32)(ruid, euid, suid)) < 0 && + LSS_ERRNO == ENOSYS) { + if ((ruid == NULL) || (euid == NULL) || (suid == NULL)) { + return EFAULT; + } + // Clear the high bits first, since getresuid only sets 16 bits + *ruid = *euid = *suid = 0; + rc = LSS_NAME(getresuid)(ruid, euid, suid); + } + return rc; + } + + LSS_INLINE int LSS_NAME(setfsgid32)(gid_t gid) { + int rc; + if ((rc = LSS_NAME(_setfsgid32)(gid)) < 0 && + LSS_ERRNO == ENOSYS) { + if ((unsigned int)gid & ~0xFFFFu) { + rc = EINVAL; + } else { + rc = LSS_NAME(setfsgid)(gid); + } + } + return rc; + } + + LSS_INLINE int LSS_NAME(setfsuid32)(uid_t uid) { + int rc; + if ((rc = LSS_NAME(_setfsuid32)(uid)) < 0 && + LSS_ERRNO == ENOSYS) { + if ((unsigned int)uid & ~0xFFFFu) { + rc = EINVAL; + } else { + rc = LSS_NAME(setfsuid)(uid); + } + } + return rc; + } + + LSS_INLINE int LSS_NAME(setresgid32)(gid_t rgid, gid_t egid, gid_t sgid) { + int rc; + if ((rc = LSS_NAME(_setresgid32)(rgid, egid, sgid)) < 0 && + LSS_ERRNO == ENOSYS) { + if ((unsigned int)rgid & ~0xFFFFu || + (unsigned int)egid & ~0xFFFFu || + (unsigned int)sgid & ~0xFFFFu) { + rc = EINVAL; + } else { + rc = LSS_NAME(setresgid)(rgid, egid, sgid); + } + } + return rc; + } + + LSS_INLINE int LSS_NAME(setresuid32)(uid_t ruid, uid_t euid, uid_t suid) { + int rc; + if ((rc = LSS_NAME(_setresuid32)(ruid, euid, suid)) < 0 && + LSS_ERRNO == ENOSYS) { + if ((unsigned int)ruid & ~0xFFFFu || + (unsigned int)euid & ~0xFFFFu || + (unsigned int)suid & ~0xFFFFu) { + rc = EINVAL; + } else { + rc = LSS_NAME(setresuid)(ruid, euid, suid); + } + } + return rc; + } + #endif + LSS_INLINE int LSS_NAME(sigemptyset)(struct kernel_sigset_t *set) { + memset(&set->sig, 0, sizeof(set->sig)); + return 0; + } + + LSS_INLINE int LSS_NAME(sigfillset)(struct kernel_sigset_t *set) { + memset(&set->sig, -1, sizeof(set->sig)); + return 0; + } + + LSS_INLINE int LSS_NAME(sigaddset)(struct kernel_sigset_t *set, + int signum) { + if (signum < 1 || signum > (int)(8*sizeof(set->sig))) { + LSS_ERRNO = EINVAL; + return -1; + } else { + set->sig[(signum - 1)/(8*sizeof(set->sig[0]))] + |= 1UL << ((signum - 1) % (8*sizeof(set->sig[0]))); + return 0; + } + } + + LSS_INLINE int LSS_NAME(sigdelset)(struct kernel_sigset_t *set, + int signum) { + if (signum < 1 || signum > (int)(8*sizeof(set->sig))) { + LSS_ERRNO = EINVAL; + return -1; + } else { + set->sig[(signum - 1)/(8*sizeof(set->sig[0]))] + &= ~(1UL << ((signum - 1) % (8*sizeof(set->sig[0])))); + return 0; + } + } + + LSS_INLINE int LSS_NAME(sigismember)(struct kernel_sigset_t *set, + int signum) { + if (signum < 1 || signum > (int)(8*sizeof(set->sig))) { + LSS_ERRNO = EINVAL; + return -1; + } else { + return !!(set->sig[(signum - 1)/(8*sizeof(set->sig[0]))] & + (1UL << ((signum - 1) % (8*sizeof(set->sig[0]))))); + } + } + #if defined(__i386__) || \ + defined(__ARM_ARCH_3__) || defined(__ARM_EABI__) || \ + (defined(__mips__) && _MIPS_SIM == _MIPS_SIM_ABI32) || \ + defined(__PPC__) || \ + (defined(__s390__) && !defined(__s390x__)) + #define __NR__sigaction __NR_sigaction + #define __NR__sigpending __NR_sigpending + #define __NR__sigsuspend __NR_sigsuspend + #define __NR__socketcall __NR_socketcall + LSS_INLINE _syscall2(int, fstat64, int, f, + struct kernel_stat64 *, b) + LSS_INLINE _syscall5(int, _llseek, uint, fd, + unsigned long, hi, unsigned long, lo, + loff_t *, res, uint, wh) +#if defined(__s390__) && !defined(__s390x__) + /* On s390, mmap2() arguments are passed in memory. */ + LSS_INLINE void* LSS_NAME(_mmap2)(void *s, size_t l, int p, int f, int d, + off_t o) { + unsigned long buf[6] = { (unsigned long) s, (unsigned long) l, + (unsigned long) p, (unsigned long) f, + (unsigned long) d, (unsigned long) o }; + LSS_REG(2, buf); + LSS_BODY(void*, mmap2, "0"(__r2)); + } +#else + #define __NR__mmap2 __NR_mmap2 + LSS_INLINE _syscall6(void*, _mmap2, void*, s, + size_t, l, int, p, + int, f, int, d, + off_t, o) +#endif + LSS_INLINE _syscall3(int, _sigaction, int, s, + const struct kernel_old_sigaction*, a, + struct kernel_old_sigaction*, o) + LSS_INLINE _syscall1(int, _sigpending, unsigned long*, s) + #ifdef __PPC__ + LSS_INLINE _syscall1(int, _sigsuspend, unsigned long, s) + #else + LSS_INLINE _syscall3(int, _sigsuspend, const void*, a, + int, b, + unsigned long, s) + #endif + LSS_INLINE _syscall2(int, stat64, const char *, p, + struct kernel_stat64 *, b) + + LSS_INLINE int LSS_NAME(sigaction)(int signum, + const struct kernel_sigaction *act, + struct kernel_sigaction *oldact) { + int old_errno = LSS_ERRNO; + int rc; + struct kernel_sigaction a; + if (act != NULL) { + a = *act; + #ifdef __i386__ + /* On i386, the kernel requires us to always set our own + * SA_RESTORER when using realtime signals. Otherwise, it does not + * know how to return from a signal handler. This function must have + * a "magic" signature that the "gdb" (and maybe the kernel?) can + * recognize. + * Apparently, a SA_RESTORER is implicitly set by the kernel, when + * using non-realtime signals. + * + * TODO: Test whether ARM needs a restorer + */ + if (!(a.sa_flags & SA_RESTORER)) { + a.sa_flags |= SA_RESTORER; + a.sa_restorer = (a.sa_flags & SA_SIGINFO) + ? LSS_NAME(restore_rt)() : LSS_NAME(restore)(); + } + #endif + } + rc = LSS_NAME(rt_sigaction)(signum, act ? &a : act, oldact, + (KERNEL_NSIG+7)/8); + if (rc < 0 && LSS_ERRNO == ENOSYS) { + struct kernel_old_sigaction oa, ooa, *ptr_a = &oa, *ptr_oa = &ooa; + if (!act) { + ptr_a = NULL; + } else { + oa.sa_handler_ = act->sa_handler_; + memcpy(&oa.sa_mask, &act->sa_mask, sizeof(oa.sa_mask)); + #ifndef __mips__ + oa.sa_restorer = act->sa_restorer; + #endif + oa.sa_flags = act->sa_flags; + } + if (!oldact) { + ptr_oa = NULL; + } + LSS_ERRNO = old_errno; + rc = LSS_NAME(_sigaction)(signum, ptr_a, ptr_oa); + if (rc == 0 && oldact) { + if (act) { + memcpy(oldact, act, sizeof(*act)); + } else { + memset(oldact, 0, sizeof(*oldact)); + } + oldact->sa_handler_ = ptr_oa->sa_handler_; + oldact->sa_flags = ptr_oa->sa_flags; + memcpy(&oldact->sa_mask, &ptr_oa->sa_mask, sizeof(ptr_oa->sa_mask)); + #ifndef __mips__ + oldact->sa_restorer = ptr_oa->sa_restorer; + #endif + } + } + return rc; + } + + LSS_INLINE int LSS_NAME(sigpending)(struct kernel_sigset_t *set) { + int old_errno = LSS_ERRNO; + int rc = LSS_NAME(rt_sigpending)(set, (KERNEL_NSIG+7)/8); + if (rc < 0 && LSS_ERRNO == ENOSYS) { + LSS_ERRNO = old_errno; + LSS_NAME(sigemptyset)(set); + rc = LSS_NAME(_sigpending)(&set->sig[0]); + } + return rc; + } + + LSS_INLINE int LSS_NAME(sigsuspend)(const struct kernel_sigset_t *set) { + int olderrno = LSS_ERRNO; + int rc = LSS_NAME(rt_sigsuspend)(set, (KERNEL_NSIG+7)/8); + if (rc < 0 && LSS_ERRNO == ENOSYS) { + LSS_ERRNO = olderrno; + rc = LSS_NAME(_sigsuspend)( + #ifndef __PPC__ + set, 0, + #endif + set->sig[0]); + } + return rc; + } + #endif + #if defined(__i386__) || \ + defined(__ARM_ARCH_3__) || defined(__ARM_EABI__) || \ + (defined(__mips__) && _MIPS_SIM == _MIPS_SIM_ABI32) || \ + defined(__PPC__) || \ + (defined(__s390__) && !defined(__s390x__)) + /* On these architectures, implement mmap() with mmap2(). */ + LSS_INLINE void* LSS_NAME(mmap)(void *s, size_t l, int p, int f, int d, + int64_t o) { + if (o % 4096) { + LSS_ERRNO = EINVAL; + return (void *) -1; + } + return LSS_NAME(_mmap2)(s, l, p, f, d, (o / 4096)); + } + #elif defined(__s390x__) + /* On s390x, mmap() arguments are passed in memory. */ + LSS_INLINE void* LSS_NAME(mmap)(void *s, size_t l, int p, int f, int d, + int64_t o) { + unsigned long buf[6] = { (unsigned long) s, (unsigned long) l, + (unsigned long) p, (unsigned long) f, + (unsigned long) d, (unsigned long) o }; + LSS_REG(2, buf); + LSS_BODY(void*, mmap, "0"(__r2)); + } + #elif defined(__x86_64__) + /* Need to make sure __off64_t isn't truncated to 32-bits under x32. */ + LSS_INLINE void* LSS_NAME(mmap)(void *s, size_t l, int p, int f, int d, + int64_t o) { + LSS_BODY(6, void*, mmap, LSS_SYSCALL_ARG(s), LSS_SYSCALL_ARG(l), + LSS_SYSCALL_ARG(p), LSS_SYSCALL_ARG(f), + LSS_SYSCALL_ARG(d), (uint64_t)(o)); + } + #else + /* Remaining 64-bit architectures. */ + LSS_INLINE _syscall6(void*, mmap, void*, addr, size_t, length, int, prot, + int, flags, int, fd, int64_t, offset) + #endif + #if defined(__PPC__) + #undef LSS_SC_LOADARGS_0 + #define LSS_SC_LOADARGS_0(dummy...) + #undef LSS_SC_LOADARGS_1 + #define LSS_SC_LOADARGS_1(arg1) \ + __sc_4 = (unsigned long) (arg1) + #undef LSS_SC_LOADARGS_2 + #define LSS_SC_LOADARGS_2(arg1, arg2) \ + LSS_SC_LOADARGS_1(arg1); \ + __sc_5 = (unsigned long) (arg2) + #undef LSS_SC_LOADARGS_3 + #define LSS_SC_LOADARGS_3(arg1, arg2, arg3) \ + LSS_SC_LOADARGS_2(arg1, arg2); \ + __sc_6 = (unsigned long) (arg3) + #undef LSS_SC_LOADARGS_4 + #define LSS_SC_LOADARGS_4(arg1, arg2, arg3, arg4) \ + LSS_SC_LOADARGS_3(arg1, arg2, arg3); \ + __sc_7 = (unsigned long) (arg4) + #undef LSS_SC_LOADARGS_5 + #define LSS_SC_LOADARGS_5(arg1, arg2, arg3, arg4, arg5) \ + LSS_SC_LOADARGS_4(arg1, arg2, arg3, arg4); \ + __sc_8 = (unsigned long) (arg5) + #undef LSS_SC_BODY + #define LSS_SC_BODY(nr, type, opt, args...) \ + long __sc_ret, __sc_err; \ + { \ + register unsigned long __sc_0 __asm__ ("r0") = __NR_socketcall; \ + register unsigned long __sc_3 __asm__ ("r3") = opt; \ + register unsigned long __sc_4 __asm__ ("r4"); \ + register unsigned long __sc_5 __asm__ ("r5"); \ + register unsigned long __sc_6 __asm__ ("r6"); \ + register unsigned long __sc_7 __asm__ ("r7"); \ + register unsigned long __sc_8 __asm__ ("r8"); \ + LSS_SC_LOADARGS_##nr(args); \ + __asm__ __volatile__ \ + ("stwu 1, -48(1)\n\t" \ + "stw 4, 20(1)\n\t" \ + "stw 5, 24(1)\n\t" \ + "stw 6, 28(1)\n\t" \ + "stw 7, 32(1)\n\t" \ + "stw 8, 36(1)\n\t" \ + "addi 4, 1, 20\n\t" \ + "sc\n\t" \ + "mfcr %0" \ + : "=&r" (__sc_0), \ + "=&r" (__sc_3), "=&r" (__sc_4), \ + "=&r" (__sc_5), "=&r" (__sc_6), \ + "=&r" (__sc_7), "=&r" (__sc_8) \ + : LSS_ASMINPUT_##nr \ + : "cr0", "ctr", "memory"); \ + __sc_ret = __sc_3; \ + __sc_err = __sc_0; \ + } \ + LSS_RETURN(type, __sc_ret, __sc_err) + + LSS_INLINE ssize_t LSS_NAME(recvmsg)(int s,struct kernel_msghdr *msg, + int flags){ + LSS_SC_BODY(3, ssize_t, 17, s, msg, flags); + } + + LSS_INLINE ssize_t LSS_NAME(sendmsg)(int s, + const struct kernel_msghdr *msg, + int flags) { + LSS_SC_BODY(3, ssize_t, 16, s, msg, flags); + } + + // TODO(csilvers): why is this ifdef'ed out? +#if 0 + LSS_INLINE ssize_t LSS_NAME(sendto)(int s, const void *buf, size_t len, + int flags, + const struct kernel_sockaddr *to, + unsigned int tolen) { + LSS_BODY(6, ssize_t, 11, s, buf, len, flags, to, tolen); + } +#endif + + LSS_INLINE int LSS_NAME(shutdown)(int s, int how) { + LSS_SC_BODY(2, int, 13, s, how); + } + + LSS_INLINE int LSS_NAME(socket)(int domain, int type, int protocol) { + LSS_SC_BODY(3, int, 1, domain, type, protocol); + } + + LSS_INLINE int LSS_NAME(socketpair)(int d, int type, int protocol, + int sv[2]) { + LSS_SC_BODY(4, int, 8, d, type, protocol, sv); + } + #endif + #if defined(__ARM_EABI__) || defined (__aarch64__) + LSS_INLINE _syscall3(ssize_t, recvmsg, int, s, struct kernel_msghdr*, msg, + int, flags) + LSS_INLINE _syscall3(ssize_t, sendmsg, int, s, const struct kernel_msghdr*, + msg, int, flags) + LSS_INLINE _syscall6(ssize_t, sendto, int, s, const void*, buf, size_t,len, + int, flags, const struct kernel_sockaddr*, to, + unsigned int, tolen) + LSS_INLINE _syscall2(int, shutdown, int, s, int, how) + LSS_INLINE _syscall3(int, socket, int, domain, int, type, int, protocol) + LSS_INLINE _syscall4(int, socketpair, int, d, int, type, int, protocol, + int*, sv) + #endif + #if defined(__i386__) || defined(__ARM_ARCH_3__) || \ + (defined(__mips__) && _MIPS_SIM == _MIPS_SIM_ABI32) || \ + defined(__s390__) + #define __NR__socketcall __NR_socketcall + LSS_INLINE _syscall2(int, _socketcall, int, c, + va_list, a) + LSS_INLINE int LSS_NAME(socketcall)(int op, ...) { + int rc; + va_list ap; + va_start(ap, op); + rc = LSS_NAME(_socketcall)(op, ap); + va_end(ap); + return rc; + } + + LSS_INLINE ssize_t LSS_NAME(recvmsg)(int s,struct kernel_msghdr *msg, + int flags){ + return (ssize_t)LSS_NAME(socketcall)(17, s, msg, flags); + } + + LSS_INLINE ssize_t LSS_NAME(sendmsg)(int s, + const struct kernel_msghdr *msg, + int flags) { + return (ssize_t)LSS_NAME(socketcall)(16, s, msg, flags); + } + + LSS_INLINE ssize_t LSS_NAME(sendto)(int s, const void *buf, size_t len, + int flags, + const struct kernel_sockaddr *to, + unsigned int tolen) { + return (ssize_t)LSS_NAME(socketcall)(11, s, buf, len, flags, to, tolen); + } + + LSS_INLINE int LSS_NAME(shutdown)(int s, int how) { + return LSS_NAME(socketcall)(13, s, how); + } + + LSS_INLINE int LSS_NAME(socket)(int domain, int type, int protocol) { + return LSS_NAME(socketcall)(1, domain, type, protocol); + } + + LSS_INLINE int LSS_NAME(socketpair)(int d, int type, int protocol, + int sv[2]) { + return LSS_NAME(socketcall)(8, d, type, protocol, sv); + } + #endif + #if defined(__NR_fstatat64) + LSS_INLINE _syscall4(int, fstatat64, int, d, + const char *, p, + struct kernel_stat64 *, b, int, f) + #endif + #if defined(__NR_waitpid) + // waitpid is polyfilled below when not available. + LSS_INLINE _syscall3(pid_t, waitpid, pid_t, p, + int*, s, int, o) + #endif + #if defined(__mips__) + /* sys_pipe() on MIPS has non-standard calling conventions, as it returns + * both file handles through CPU registers. + */ + LSS_INLINE int LSS_NAME(pipe)(int *p) { + register unsigned long __v0 __asm__("$2") = __NR_pipe; + register unsigned long __v1 __asm__("$3"); + register unsigned long __r7 __asm__("$7"); + __asm__ __volatile__ ("syscall\n" + : "=r"(__v0), "=r"(__v1), "=r" (__r7) + : "0"(__v0) + : "$8", "$9", "$10", "$11", "$12", + "$13", "$14", "$15", "$24", "$25", "memory"); + if (__r7) { + unsigned long __errnovalue = __v0; + LSS_ERRNO = __errnovalue; + return -1; + } else { + p[0] = __v0; + p[1] = __v1; + return 0; + } + } + #elif defined(__NR_pipe) + // pipe is polyfilled below when not available. + LSS_INLINE _syscall1(int, pipe, int *, p) + #endif + #if defined(__NR_pipe2) + LSS_INLINE _syscall2(int, pipe2, int *, pipefd, int, flags) + #endif + /* TODO(csilvers): see if ppc can/should support this as well */ + #if defined(__i386__) || defined(__ARM_ARCH_3__) || \ + defined(__ARM_EABI__) || \ + (defined(__mips__) && _MIPS_SIM != _MIPS_SIM_ABI64) || \ + (defined(__s390__) && !defined(__s390x__)) + #define __NR__statfs64 __NR_statfs64 + #define __NR__fstatfs64 __NR_fstatfs64 + LSS_INLINE _syscall3(int, _statfs64, const char*, p, + size_t, s,struct kernel_statfs64*, b) + LSS_INLINE _syscall3(int, _fstatfs64, int, f, + size_t, s,struct kernel_statfs64*, b) + LSS_INLINE int LSS_NAME(statfs64)(const char *p, + struct kernel_statfs64 *b) { + return LSS_NAME(_statfs64)(p, sizeof(*b), b); + } + LSS_INLINE int LSS_NAME(fstatfs64)(int f,struct kernel_statfs64 *b) { + return LSS_NAME(_fstatfs64)(f, sizeof(*b), b); + } + #endif + + LSS_INLINE int LSS_NAME(execv)(const char *path, const char *const argv[]) { + extern char **environ; + return LSS_NAME(execve)(path, argv, (const char *const *)environ); + } + + LSS_INLINE pid_t LSS_NAME(gettid)(void) { + pid_t tid = LSS_NAME(_gettid)(); + if (tid != -1) { + return tid; + } + return LSS_NAME(getpid)(); + } + + LSS_INLINE void *LSS_NAME(mremap)(void *old_address, size_t old_size, + size_t new_size, int flags, ...) { + va_list ap; + void *new_address, *rc; + va_start(ap, flags); + new_address = va_arg(ap, void *); + rc = LSS_NAME(_mremap)(old_address, old_size, new_size, + flags, new_address); + va_end(ap); + return rc; + } + + LSS_INLINE int LSS_NAME(ptrace_detach)(pid_t pid) { + /* PTRACE_DETACH can sometimes forget to wake up the tracee and it + * then sends job control signals to the real parent, rather than to + * the tracer. We reduce the risk of this happening by starting a + * whole new time slice, and then quickly sending a SIGCONT signal + * right after detaching from the tracee. + * + * We use tkill to ensure that we only issue a wakeup for the thread being + * detached. Large multi threaded apps can take a long time in the kernel + * processing SIGCONT. + */ + int rc, err; + LSS_NAME(sched_yield)(); + rc = LSS_NAME(ptrace)(PTRACE_DETACH, pid, (void *)0, (void *)0); + err = LSS_ERRNO; + LSS_NAME(tkill)(pid, SIGCONT); + /* Old systems don't have tkill */ + if (LSS_ERRNO == ENOSYS) + LSS_NAME(kill)(pid, SIGCONT); + LSS_ERRNO = err; + return rc; + } + + LSS_INLINE int LSS_NAME(raise)(int sig) { + return LSS_NAME(kill)(LSS_NAME(getpid)(), sig); + } + + LSS_INLINE int LSS_NAME(setpgrp)(void) { + return LSS_NAME(setpgid)(0, 0); + } + + #if defined(__x86_64__) + /* Need to make sure loff_t isn't truncated to 32-bits under x32. */ + LSS_INLINE ssize_t LSS_NAME(pread64)(int f, void *b, size_t c, loff_t o) { + LSS_BODY(4, ssize_t, pread64, LSS_SYSCALL_ARG(f), LSS_SYSCALL_ARG(b), + LSS_SYSCALL_ARG(c), (uint64_t)(o)); + } + + LSS_INLINE ssize_t LSS_NAME(pwrite64)(int f, const void *b, size_t c, + loff_t o) { + LSS_BODY(4, ssize_t, pwrite64, LSS_SYSCALL_ARG(f), LSS_SYSCALL_ARG(b), + LSS_SYSCALL_ARG(c), (uint64_t)(o)); + } + + LSS_INLINE int LSS_NAME(readahead)(int f, loff_t o, unsigned c) { + LSS_BODY(3, int, readahead, LSS_SYSCALL_ARG(f), (uint64_t)(o), + LSS_SYSCALL_ARG(c)); + } + #elif defined(__mips__) && _MIPS_SIM == _MIPS_SIM_ABI64 + LSS_INLINE _syscall4(ssize_t, pread64, int, f, + void *, b, size_t, c, + loff_t, o) + LSS_INLINE _syscall4(ssize_t, pwrite64, int, f, + const void *, b, size_t, c, + loff_t, o) + LSS_INLINE _syscall3(int, readahead, int, f, + loff_t, o, unsigned, c) + #else + #define __NR__pread64 __NR_pread64 + #define __NR__pwrite64 __NR_pwrite64 + #define __NR__readahead __NR_readahead + #if defined(__ARM_EABI__) || defined(__mips__) + /* On ARM and MIPS, a 64-bit parameter has to be in an even-odd register + * pair. Hence these calls ignore their fourth argument (r3) so that their + * fifth and sixth make such a pair (r4,r5). + */ + #define LSS_LLARG_PAD 0, + LSS_INLINE _syscall6(ssize_t, _pread64, int, f, + void *, b, size_t, c, + unsigned, skip, unsigned, o1, unsigned, o2) + LSS_INLINE _syscall6(ssize_t, _pwrite64, int, f, + const void *, b, size_t, c, + unsigned, skip, unsigned, o1, unsigned, o2) + LSS_INLINE _syscall5(int, _readahead, int, f, + unsigned, skip, + unsigned, o1, unsigned, o2, size_t, c) + #else + #define LSS_LLARG_PAD + LSS_INLINE _syscall5(ssize_t, _pread64, int, f, + void *, b, size_t, c, unsigned, o1, + unsigned, o2) + LSS_INLINE _syscall5(ssize_t, _pwrite64, int, f, + const void *, b, size_t, c, unsigned, o1, + long, o2) + LSS_INLINE _syscall4(int, _readahead, int, f, + unsigned, o1, unsigned, o2, size_t, c) + #endif + /* We force 64bit-wide parameters onto the stack, then access each + * 32-bit component individually. This guarantees that we build the + * correct parameters independent of the native byte-order of the + * underlying architecture. + */ + LSS_INLINE ssize_t LSS_NAME(pread64)(int fd, void *buf, size_t count, + loff_t off) { + union { loff_t off; unsigned arg[2]; } o = { off }; + return LSS_NAME(_pread64)(fd, buf, count, + LSS_LLARG_PAD o.arg[0], o.arg[1]); + } + LSS_INLINE ssize_t LSS_NAME(pwrite64)(int fd, const void *buf, + size_t count, loff_t off) { + union { loff_t off; unsigned arg[2]; } o = { off }; + return LSS_NAME(_pwrite64)(fd, buf, count, + LSS_LLARG_PAD o.arg[0], o.arg[1]); + } + LSS_INLINE int LSS_NAME(readahead)(int fd, loff_t off, int len) { + union { loff_t off; unsigned arg[2]; } o = { off }; + return LSS_NAME(_readahead)(fd, LSS_LLARG_PAD o.arg[0], o.arg[1], len); + } + #endif +#endif + +/* + * Polyfills for deprecated syscalls. + */ + +#if !defined(__NR_dup2) + LSS_INLINE int LSS_NAME(dup2)(int s, int d) { + return LSS_NAME(dup3)(s, d, 0); + } +#endif + +#if !defined(__NR_open) + LSS_INLINE int LSS_NAME(open)(const char *pathname, int flags, int mode) { + return LSS_NAME(openat)(AT_FDCWD, pathname, flags, mode); + } +#endif + +#if !defined(__NR_unlink) + LSS_INLINE int LSS_NAME(unlink)(const char *pathname) { + return LSS_NAME(unlinkat)(AT_FDCWD, pathname, 0); + } +#endif + +#if !defined(__NR_readlink) + LSS_INLINE int LSS_NAME(readlink)(const char *pathname, char *buffer, + size_t size) { + return LSS_NAME(readlinkat)(AT_FDCWD, pathname, buffer, size); + } +#endif + +#if !defined(__NR_pipe) + LSS_INLINE int LSS_NAME(pipe)(int *pipefd) { + return LSS_NAME(pipe2)(pipefd, 0); + } +#endif + +#if !defined(__NR_poll) + LSS_INLINE int LSS_NAME(poll)(struct kernel_pollfd *fds, unsigned int nfds, + int timeout) { + struct kernel_timespec timeout_ts; + struct kernel_timespec *timeout_ts_p = NULL; + + if (timeout >= 0) { + timeout_ts.tv_sec = timeout / 1000; + timeout_ts.tv_nsec = (timeout % 1000) * 1000000; + timeout_ts_p = &timeout_ts; + } + return LSS_NAME(ppoll)(fds, nfds, timeout_ts_p, NULL, 0); + } +#endif + +#if !defined(__NR_stat) + LSS_INLINE int LSS_NAME(stat)(const char *pathname, + struct kernel_stat *buf) { + return LSS_NAME(newfstatat)(AT_FDCWD, pathname, buf, 0); + } +#endif + +#if !defined(__NR_waitpid) + LSS_INLINE pid_t LSS_NAME(waitpid)(pid_t pid, int *status, int options) { + return LSS_NAME(wait4)(pid, status, options, 0); + } +#endif + +#if !defined(__NR_fork) +// TODO: define this in an arch-independant way instead of inlining the clone +// syscall body. + +# if defined(__aarch64__) + LSS_INLINE pid_t LSS_NAME(fork)(void) { + // No fork syscall on aarch64 - implement by means of the clone syscall. + // Note that this does not reset glibc's cached view of the PID/TID, so + // some glibc interfaces might go wrong in the forked subprocess. + int flags = SIGCHLD; + void *child_stack = NULL; + void *parent_tidptr = NULL; + void *newtls = NULL; + void *child_tidptr = NULL; + + LSS_REG(0, flags); + LSS_REG(1, child_stack); + LSS_REG(2, parent_tidptr); + LSS_REG(3, newtls); + LSS_REG(4, child_tidptr); + LSS_BODY(pid_t, clone, "r"(__r0), "r"(__r1), "r"(__r2), "r"(__r3), + "r"(__r4)); + } +# elif defined(__x86_64__) + LSS_INLINE pid_t LSS_NAME(fork)(void) { + // Android disallows the fork syscall on x86_64 - implement by means of the + // clone syscall as above for aarch64. + int flags = SIGCHLD; + void *child_stack = NULL; + void *parent_tidptr = NULL; + void *newtls = NULL; + void *child_tidptr = NULL; + + LSS_BODY(5, pid_t, clone, LSS_SYSCALL_ARG(flags), + LSS_SYSCALL_ARG(child_stack), LSS_SYSCALL_ARG(parent_tidptr), + LSS_SYSCALL_ARG(newtls), LSS_SYSCALL_ARG(child_tidptr)); + } +# else +# error missing fork polyfill for this architecture +# endif +#endif + +/* These restore the original values of these macros saved by the + * corresponding #pragma push_macro near the top of this file. */ +#pragma pop_macro("stat64") +#pragma pop_macro("fstat64") +#pragma pop_macro("lstat64") +#pragma pop_macro("pread64") +#pragma pop_macro("pwrite64") + +#if defined(__cplusplus) && !defined(SYS_CPLUSPLUS) +} +#endif + +#endif +#endif diff --git a/c/src/third-party/sentry-native/external/crashpad/third_party/lss/lss/tests/.gitignore b/c/src/third-party/sentry-native/external/crashpad/third_party/lss/lss/tests/.gitignore new file mode 100644 index 000000000..89c5d3c93 --- /dev/null +++ b/c/src/third-party/sentry-native/external/crashpad/third_party/lss/lss/tests/.gitignore @@ -0,0 +1,4 @@ +/*_test + +# Some tests create temp files. +/tempfile.* diff --git a/c/src/third-party/sentry-native/external/crashpad/third_party/lss/lss/tests/Makefile b/c/src/third-party/sentry-native/external/crashpad/third_party/lss/lss/tests/Makefile new file mode 100644 index 000000000..5e37345f1 --- /dev/null +++ b/c/src/third-party/sentry-native/external/crashpad/third_party/lss/lss/tests/Makefile @@ -0,0 +1,131 @@ +# Copyright 2018, Google Inc. 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. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# 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. + +top_srcdir ?= .. + +DEF_FLAGS = -g -pipe +DEF_WFLAGS = -Wall +CFLAGS ?= $(DEF_FLAGS) +CXXFLAGS ?= $(DEF_FLAGS) +CFLAGS += $(DEF_WFLAGS) -Wstrict-prototypes +CXXFLAGS += $(DEF_WFLAGS) +CPPFLAGS += -I$(top_srcdir) +# We use static linking here so that if people run through qemu/etc... by hand, +# it's a lot easier to run/debug. Same for strace output. +LDFLAGS += -static + +TESTS = \ + fallocate \ + sigtimedwait \ + unlink \ + +all: check + +%_test: %.c test_skel.h $(top_srcdir)/linux_syscall_support.h + $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $< + +%_test: %.cc test_skel.h $(top_srcdir)/linux_syscall_support.h + $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $< + +%_run: %_test + @t=$(@:_run=_test); \ + echo "./$$t"; \ + if ! env -i ./$$t; then \ + env -i strace -f -v ./$$t; \ + echo "TRY: gdb -q -ex r -ex bt ./$$t"; \ + exit 1; \ + fi + +ALL_TEST_TARGETS = $(TESTS:=_test) +compile_tests: $(ALL_TEST_TARGETS) + +ALL_RUN_TARGETS = $(TESTS:=_run) +check: $(ALL_RUN_TARGETS) + +# The "tempfile" targets are the names we use with temp files. +# Clean them out in case some tests crashed in the middle. +clean: + rm -f *~ *.o tempfile.* a.out core $(ALL_TEST_TARGETS) + +.SUFFIXES: +.PHONY: all check clean compile_tests +.SECONDARY: $(ALL_TEST_TARGETS) + +# Try to cross-compile the tests for all our supported arches. We test with +# both gcc and clang. We don't support execution (yet?), but just compiling +# & linking helps catch common bugs. +.PHONY: cross compile_cross +cross_compile: + @echo "Running: $(MAKE) $@ CC='$(CC)' CXX='$(CXX)'"; \ + if (echo '#include ' | $(CC) -x c -c -o /dev/null -) 2>/dev/null; then \ + $(MAKE) -s clean; \ + $(MAKE) -k --no-print-directory compile_tests; \ + else \ + echo "Skipping $(CC) test: not installed"; \ + fi; \ + echo + +# The names here are a best effort. Not easy to probe for. +cross: + @for cc in \ + "x86_64-pc-linux-gnu-gcc" \ + "i686-pc-linux-gnu-gcc" \ + "x86_64-pc-linux-gnu-gcc -mx32" \ + "armv7a-unknown-linux-gnueabi-gcc -marm -mhard-float" \ + "armv7a-unknown-linux-gnueabi-gcc -mthumb -mhard-float" \ + "powerpc-unknown-linux-gnu-gcc" \ + "aarch64-unknown-linux-gnu-gcc" \ + "mips64-unknown-linux-gnu-gcc -mabi=64" \ + "mips64-unknown-linux-gnu-gcc -mabi=32" \ + "mips64-unknown-linux-gnu-gcc -mabi=n32" \ + "s390-ibm-linux-gnu-gcc" \ + "s390x-ibm-linux-gnu-gcc" \ + ; do \ + cxx=`echo "$$cc" | sed 's:-gcc:-g++:'`; \ + $(MAKE) --no-print-directory CC="$$cc" CXX="$$cxx" cross_compile; \ + \ + sysroot=`$$cc --print-sysroot 2>/dev/null`; \ + gccdir=`$$cc -print-file-name=libgcc.a 2>/dev/null`; \ + gccdir=`dirname "$$gccdir"`; \ + : Skip building for clang for mips/o32 and s390/31-bit until it works.; \ + case $$cc in \ + mips64*-mabi=32) continue;; \ + s390-*) continue;; \ + esac; \ + set -- $$cc; \ + tuple=$${1%-gcc}; \ + shift; \ + cc="clang -target $$tuple $$*"; \ + : Assume the build system is x86_64 based, so ignore the sysroot.; \ + case $$tuple in \ + x86_64*) ;; \ + *) cc="$$cc --sysroot $$sysroot -B$$gccdir -L$$gccdir";; \ + esac; \ + cxx=`echo "$$cc" | sed 's:^clang:clang++:'`; \ + $(MAKE) --no-print-directory CC="$$cc" CXX="$$cxx" cross_compile; \ + done diff --git a/c/src/third-party/sentry-native/external/crashpad/third_party/lss/lss/tests/README.md b/c/src/third-party/sentry-native/external/crashpad/third_party/lss/lss/tests/README.md new file mode 100644 index 000000000..45af3c37e --- /dev/null +++ b/c/src/third-party/sentry-native/external/crashpad/third_party/lss/lss/tests/README.md @@ -0,0 +1,52 @@ +# LSS Tests + +## Source Layout + +The general layout of the tests: +* [test_skel.h]: Test helpers for common checks/etc... +* xxx.c: Unittest for the xxx syscall (e.g. `open.c`). +* [Makefile]: New tests should be registered in the `TESTS` variable. + +## Test Guidelines + +The unittest itself generally follows the conventions: +* Written in C (unless a very specific language behavior is needed). +* You should only need to `#include "test_skel.h"`. For new system headers, try + to add them here rather than copying to exact unittest (if possible). + It might slow compilation down slightly, but makes the code easier to manage. + Make sure it is included first. +* Use `assert()` on everything to check return values. +* Use `sys_xxx()` to access the syscall via LSS (compared to `xxx()` which tends + to come from the C library). +* If you need a tempfile, use `tempfile.XXXXXX` for templates with helpers like + `mkstemp`. Try to clean them up when you're done with them. + These will be created in the cwd, but that's fine. +* Don't worry about trying to verify the kernel/C library API and various edge + cases. The goal of LSS is to make sure that we pass args along correctly to + the syscall only. +* Make sure to leave comments in the test so it's clear what behavior you're + trying to verify (and how). + +Feel free to extend [test_skel.h] with more helpers if they're useful to more +than one test. + +If you're looking for a simple example, start with [unlink.c](./unlink.c). +You should be able to copy this over and replace the content of `main()`. + +## Running The Tests + +Simply run `make`. This will compile & execute all the tests on your local +system. A standard `make clean` will clean up all the objects. + +If you need to debug something, then the programs are simply named `xxx_test` +and can easily be thrown into `gdb ./xxx_test`. + +We have rudimentary cross-compile testing via gcc and clang. Try running +`make cross` -- for any toolchains you don't have available, it should skip +things automatically. This only verifies the compilation & linking stages +though. + +The cross-compilers can be created using . + +[Makefile]: ./Makefile +[test_skel.h]: ./test_skel.h diff --git a/c/src/third-party/sentry-native/external/crashpad/third_party/lss/lss/tests/fallocate.c b/c/src/third-party/sentry-native/external/crashpad/third_party/lss/lss/tests/fallocate.c new file mode 100644 index 000000000..c156e5898 --- /dev/null +++ b/c/src/third-party/sentry-native/external/crashpad/third_party/lss/lss/tests/fallocate.c @@ -0,0 +1,67 @@ +/* Copyright 2019, Google Inc. 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. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * 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. + */ + +#include "test_skel.h" + +int main(int argc, char *argv[]) { + int fd = 0, mode = 0; + loff_t offset = 0, len = 0; + + // Bad file descriptor. + fd = -1; + assert(sys_fallocate(fd, mode, offset, len) == -1); + assert(errno == EBADF); + + char filename[] = "tempfile.XXXXXX"; + fd = mkstemp(filename); + assert(fd >= 0); + + // Invalid len. + assert(sys_fallocate(fd, mode, offset, len) == -1); + assert(errno == EINVAL); + + // Small offset and length succeeds. + len = 4096; + assert(sys_fallocate(fd, mode, offset, len) == 0); + + // Large offset succeeds and isn't truncated. + offset = 1llu + UINT32_MAX; + assert(sys_fallocate(fd, mode , offset, len) == 0); + +#if defined(__NR_fstat64) + struct kernel_stat64 st; + assert(sys_fstat64(fd, &st) == 0); +#else + struct kernel_stat st; + assert(sys_fstat(fd, &st) == 0); +#endif + assert(st.st_size == offset + len); + + return 0; +} diff --git a/c/src/third-party/sentry-native/external/crashpad/third_party/lss/lss/tests/sigtimedwait.c b/c/src/third-party/sentry-native/external/crashpad/third_party/lss/lss/tests/sigtimedwait.c new file mode 100644 index 000000000..ee2f740fe --- /dev/null +++ b/c/src/third-party/sentry-native/external/crashpad/third_party/lss/lss/tests/sigtimedwait.c @@ -0,0 +1,58 @@ +/* Copyright 2019, Google Inc. 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. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * 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. + */ + +#include "test_skel.h" + +int main(int argc, char *argv[]) { + + struct kernel_sigset_t sigset = {}; + siginfo_t siginfo = {}; + struct timespec timeout = {}; + + // Invalid timeouts. + timeout.tv_sec = -1; + assert(sys_sigtimedwait(&sigset, &siginfo, &timeout) == -1); + assert(errno == EINVAL); + + // Expired timeouts. + timeout.tv_sec = 0; + assert(sys_sigtimedwait(&sigset, &siginfo, &timeout) == -1); + assert(errno == EAGAIN); + + // Success. + const int kTestSignal = SIGCONT; + assert(sys_sigemptyset(&sigset) == 0); + assert(sys_sigaddset(&sigset, kTestSignal) == 0); + assert(sys_sigprocmask(SIG_BLOCK, &sigset, NULL) == 0); + assert(raise(kTestSignal) == 0); + assert(sys_sigtimedwait(&sigset, &siginfo, &timeout) == kTestSignal); + assert(siginfo.si_signo == kTestSignal); + + return 0; +} diff --git a/c/src/third-party/sentry-native/external/crashpad/third_party/lss/lss/tests/test_skel.h b/c/src/third-party/sentry-native/external/crashpad/third_party/lss/lss/tests/test_skel.h new file mode 100644 index 000000000..9ff0eb371 --- /dev/null +++ b/c/src/third-party/sentry-native/external/crashpad/third_party/lss/lss/tests/test_skel.h @@ -0,0 +1,70 @@ +/* Copyright 2018, Google Inc. 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. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * 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. + */ + +/* + * Make sure it's defined before including anything else. A number of syscalls + * are GNU extensions and rely on being exported by glibc. + */ +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + +/* + * Make sure the assert checks aren't removed as all the unittests are based + * on them. + */ +#undef NDEBUG + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "linux_syscall_support.h" + +void assert_buffers_eq_len(const void *buf1, const void *buf2, size_t len) { + const uint8_t *u8_1 = (const uint8_t *)buf1; + const uint8_t *u8_2 = (const uint8_t *)buf2; + size_t i; + + for (i = 0; i < len; ++i) { + if (u8_1[i] != u8_2[i]) + printf("offset %zu: %02x != %02x\n", i, u8_1[i], u8_2[i]); + } +} +#define assert_buffers_eq(obj1, obj2) assert_buffers_eq_len(obj1, obj2, sizeof(*obj1)) diff --git a/c/src/third-party/sentry-native/external/crashpad/third_party/lss/lss/tests/unlink.c b/c/src/third-party/sentry-native/external/crashpad/third_party/lss/lss/tests/unlink.c new file mode 100644 index 000000000..70c8bc9a5 --- /dev/null +++ b/c/src/third-party/sentry-native/external/crashpad/third_party/lss/lss/tests/unlink.c @@ -0,0 +1,48 @@ +/* Copyright 2018, Google Inc. 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. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * 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. + */ + +#include "test_skel.h" + +int main(int argc, char *argv[]) { + // Get a unique path to play with. + char foo[] = "tempfile.XXXXXX"; + int fd = mkstemp(foo); + assert(fd != -1); + + // Make sure it exists. + assert(access(foo, F_OK) == 0); + + // Then delete it. + assert(sys_unlink(foo) == 0); + + // Make sure it's gone. + assert(access(foo, F_OK) != 0); + + return 0; +} diff --git a/c/src/tools/sentry/sentry.c b/c/src/tools/sentry/sentry.c index 328b3e133..738f49237 100644 --- a/c/src/tools/sentry/sentry.c +++ b/c/src/tools/sentry/sentry.c @@ -5,7 +5,10 @@ void init_sentry_once(sentry_conf_t* conf) { if (!SENTRY_INIT) { sentry_options_t* options = sentry_options_new(); in3_log_info("sentry-init\n"); + sentry_options_set_environment(options, "Debug"); + sentry_options_set_release(options, IN3_VERSION); sentry_options_set_database_path(options, conf->db); + sentry_options_set_handler_path(options, "/tmp/crashpad_handler"); sentry_options_set_debug(options, conf->debug); sentry_options_set_dsn(options, conf->dsn); sentry_init(options); @@ -19,9 +22,37 @@ static in3_ret_t handle_sentry(void* cptr, in3_plugin_act_t action, void* arg) { case PLGN_ACT_LOG_ERROR: { init_sentry_once(conf); error_log_ctx_t* t = arg; + + char* res = NULL; + char* req = NULL; + if (t->ctx->request_context) { + req = t->ctx->request_context->c; + } + if (t->ctx->response_context) { + res = t->ctx->response_context->c; + } + else if (t->ctx->raw_response) { + res = t->ctx->raw_response->data.data; + } + + if(req){ + sentry_value_t crumb_req + = sentry_value_new_breadcrumb(0, req); + sentry_add_breadcrumb(crumb_req); + } + if (res){ + sentry_value_t crumb_res + = sentry_value_new_breadcrumb(0, res); + sentry_add_breadcrumb(crumb_res); + } + char* conf = in3_get_config(t->ctx->client); + sentry_add_breadcrumb( sentry_value_new_breadcrumb( 0, conf)); + _free(conf); + + sentry_value_t event = sentry_value_new_message_event( SENTRY_LEVEL_ERROR, IN3_VERSION, t->msg); - // sentry_event_value_add_stacktrace(event, NULL, 0); + sentry_event_value_add_stacktrace(event, NULL, 64); sentry_capture_event(event); in3_log_info("sentry-event-sent\n"); return IN3_OK; diff --git a/c/src/verifier/eth1/basic/eth_account.c b/c/src/verifier/eth1/basic/eth_account.c index 3a6f8ce4a..5a8a6002f 100644 --- a/c/src/verifier/eth1/basic/eth_account.c +++ b/c/src/verifier/eth1/basic/eth_account.c @@ -98,7 +98,7 @@ static in3_ret_t verify_proof(in3_vctx_t* vc, bytes_t* header, d_token_t* accoun optimize_len(vp, bb.b.len); if (bb.b.len > 1 || (bb.b.len == 1 && *vp)) return vc_err(vc, "empty storagehash, so we exepct 0 values"); - if (d_type(pt) != T_ARRAY || d_len(pt) != 1 || d_type(pt + 1) != T_INTEGER || d_int(pt + 1) != 0x80) + if (d_type(pt) != T_ARRAY || d_len(pt) > 1 || (d_len(pt) == 1 && (d_type(pt + 1) != T_INTEGER || d_int(pt + 1) != 0x80))) return vc_err(vc, "invalid proof"); } else { @@ -197,11 +197,16 @@ in3_ret_t eth_verify_account_proof(in3_vctx_t* vc) { else if (strcmp(method, "eth_getStorageAt") == 0) { uint8_t result[32], proofed_result[32]; d_bytes_to(vc->result, result, 32); - d_token_t* storage = d_get(proofed_account, K_STORAGE_PROOF); - d_token_t* skey = d_get_at(d_get(vc->request, K_PARAMS), 1); + d_token_t* storage = d_get(proofed_account, K_STORAGE_PROOF); + d_token_t* skey = d_get_at(d_get(vc->request, K_PARAMS), 1); + bytes_t requested_key = d_to_bytes(skey); + if (!requested_key.data) return vc_err(vc, "missing key"); + b_optimize_len(&requested_key); for (i = 0, t = storage + 1; i < d_len(storage); i++, t = d_next(t)) { - if (d_eq(skey, d_get(t, K_KEY))) { + bytes_t storage_key = d_to_bytes(d_get(t, K_KEY)); + b_optimize_len(&storage_key); + if (b_cmp(&storage_key, &requested_key)) { d_bytes_to(d_get(t, K_VALUE), proofed_result, 32); if (memcmp(result, proofed_result, 32) == 0) return IN3_OK; diff --git a/c/src/verifier/eth1/evm/call.c b/c/src/verifier/eth1/evm/call.c index 01b8e017d..54da094fd 100644 --- a/c/src/verifier/eth1/evm/call.c +++ b/c/src/verifier/eth1/evm/call.c @@ -184,8 +184,12 @@ int evm_sub_call(evm_t* parent, evm.call_value.data = value; evm.call_value.len = l_value; + // if this is a delecate call, we set the address of the account storage we should use + if (mode == EVM_CALL_MODE_DELEGATE) evm.account = parent->account; + // if this is a static call, we set the static flag which can be checked before any state-chage occur. - if (mode == EVM_CALL_MODE_STATIC) evm.properties |= EVM_PROP_STATIC; + else if (mode == EVM_CALL_MODE_STATIC) + evm.properties |= EVM_PROP_STATIC; account_t* new_account = NULL; UNUSED_VAR(new_account); diff --git a/c/src/verifier/eth1/evm/evm.c b/c/src/verifier/eth1/evm/evm.c index 14008bc51..f8a50d5e1 100644 --- a/c/src/verifier/eth1/evm/evm.c +++ b/c/src/verifier/eth1/evm/evm.c @@ -496,6 +496,7 @@ int evm_run(evm_t* evm, address_t code_address) { // execute the opcode res = evm_execute(evm); // display the result of the opcode (only if the debug flag is set) + #ifdef EVM_GAS // debug gas output EVM_DEBUG_BLOCK({ evm_print_stack(evm, last_gas, last); }); diff --git a/c/src/verifier/eth1/evm/evm.h b/c/src/verifier/eth1/evm/evm.h index 8e7a4211e..f9c2d6bba 100644 --- a/c/src/verifier/eth1/evm/evm.h +++ b/c/src/verifier/eth1/evm/evm.h @@ -75,6 +75,7 @@ typedef enum evm_state { #define EVM_ERROR_BALANCE_TOO_LOW -30 /**< not enough funds to transfer the requested value. */ #define EVM_ERROR_STACK_LIMIT -31 /**< stack limit reached */ #define EVM_ERROR_SUCCESS_CONSUME_GAS -32 /**< write success but consume all gas */ +#define EVM_ERROR_MAX_CODE_SIZE_EXCEEDED -33 /**< tried to create a contract with code bigger than the maximum size limit */ #define EVM_PROP_FRONTIER 1 #define EVM_PROP_EIP150 2 @@ -83,6 +84,7 @@ typedef enum evm_state { #define EVM_PROP_ISTANBUL 32 #define EVM_PROP_NO_FINALIZE 32768 #define EVM_PROP_STATIC 256 +#define EVM_PROP_TXCREATE 512 /**< executing a creation transaction > */ #define EVM_ENV_BALANCE 1 #define EVM_ENV_CODE_SIZE 2 @@ -230,7 +232,6 @@ typedef struct account { typedef struct evm { // internal data bytes_builder_t stack; - // bytes_builder_t memory; bytes_builder_t memory; int stack_size; bytes_t code; diff --git a/c/src/verifier/eth1/evm/opcodes.c b/c/src/verifier/eth1/evm/opcodes.c index 5256171ab..16ed7971b 100644 --- a/c/src/verifier/eth1/evm/opcodes.c +++ b/c/src/verifier/eth1/evm/opcodes.c @@ -347,11 +347,34 @@ int op_datacopy(evm_t* evm, bytes_t* src, uint_fast8_t check_size) { src_data.len = src_data.data ? min(src_data.len, ((uint32_t) data_len)) : 0; if (check_size && !src_data.data) return EVM_ERROR_ILLEGAL_MEMORY_ACCESS; + // check if we are executing a creation transaction + if (evm->properties & EVM_PROP_TXCREATE) { + if (!(evm->properties & (EVM_PROP_FRONTIER | EVM_PROP_EIP150 | EVM_PROP_EIP158)) && (src_data.len > EVM_MAX_CODE_SIZE)) { + return EVM_ERROR_MAX_CODE_SIZE_EXCEEDED; + } + else { + subgas(src_data.len * G_CODEDEPOSIT); // subtract gas cost for ceation transactions + } + } + if (src_data.len < (uint32_t) data_len) res = evm_mem_write(evm, mem_pos + src_data.len, bytes(NULL, 0), data_len - src_data.len); - if (src_data.len && res == 0) + if (src_data.len && res == 0) { res = evm_mem_write(evm, mem_pos, src_data, src_data.len); + +#ifdef EVM_GAS + // Check if evm is executing a creation transaction + if (evm->properties & EVM_PROP_TXCREATE) { + // Modify state + account_t* acc_adr = evm_get_account(evm, evm->account, true); + acc_adr->code = src_data; + } +#else + return EVM_ERROR_INVALID_OPCODE; +#endif + } + return res; } diff --git a/c/test/CMakeLists.txt b/c/test/CMakeLists.txt index ec8ac5631..09bb90340 100644 --- a/c/test/CMakeLists.txt +++ b/c/test/CMakeLists.txt @@ -152,7 +152,7 @@ foreach (testdir #GeneralStateTests/stExtCodeHash #GeneralStateTests/stBugs GeneralStateTests/stExample - #GeneralStateTests/stTransitionTest + GeneralStateTests/stTransitionTest GeneralStateTests/stCallCodes #GeneralStateTests/stPreCompiledContracts2 #GeneralStateTests/stZeroCallsTest @@ -168,7 +168,7 @@ foreach (testdir GeneralStateTests/stMemoryTest #GeneralStateTests/stEWASMTests #GeneralStateTests/stNonZeroCallsTest - #GeneralStateTests/stCodeSizeLimit + GeneralStateTests/stCodeSizeLimit #GeneralStateTests/stSystemOperationsTest #GeneralStateTests/stHomesteadSpecific #GeneralStateTests/stCreate2 @@ -201,9 +201,9 @@ foreach (testdir list(FILTER files EXCLUDE REGEX ".*pairingTest.json$") list(FILTER files EXCLUDE REGEX ".*ecmul_0-3_5616_28000_96.json$") list(FILTER files EXCLUDE REGEX ".*(InInitcodeToExisContractWithVTransferNEMoney|DynamicCode|OOGE_valueTransfer|additionalGasCosts2|ExtCodeCopyTargetRangeLongerThanCodeTests|ExtCodeCopyTests).json$") - list(FILTER files EXCLUDE REGEX ".*(pointMulAdd2).json$") + foreach (file ${files}) get_filename_component(testname "${file}" NAME_WE) add_test( diff --git a/c/test/test_evm.c b/c/test/test_evm.c index 2a7f694a2..f248d8de6 100644 --- a/c/test/test_evm.c +++ b/c/test/test_evm.c @@ -429,7 +429,9 @@ int run_evm(json_ctx_t* jctx, d_token_t* test, uint32_t props, uint64_t* ms, cha d_token_t* transaction = d_get(test, ikey(jc, "transaction")); d_token_t* post = d_get(test, ikey(jc, "post")); d_token_t* indexes = NULL; - uint64_t total_gas; + uint64_t total_gas = 0; + bool has_enough_gas = true; + address_t _to; memset(_to, 0, 20); @@ -518,62 +520,75 @@ int run_evm(json_ctx_t* jctx, d_token_t* test, uint32_t props, uint64_t* ms, cha evm.refund = 0; evm.init_gas = evm.gas; - // prepare all accounts - read_accounts(&evm, d_get(test, ikey(jc, "pre"))); + // check if we have enough gas to pay for intrinsic transaction cost + uint64_t tx_intrinsic_gas = G_TRANSACTION; // base gas cost for any transaction + // -- add the cost for transaction data + for (int i = 0; i < evm.call_data.len; i++) { + tx_intrinsic_gas += evm.call_data.data[i] ? G_TXDATA_NONZERO : G_TXDATA_ZERO; + } + // -- check if we are executing a creation transaction + if (transaction && !d_len(d_get(transaction, ikey(jc, "to")))) { + tx_intrinsic_gas += G_TXCREATE; + evm.properties |= EVM_PROP_TXCREATE; + } + has_enough_gas = (tx_intrinsic_gas < evm.init_gas); - // we need to create an account since we don't have one - if (big_is_zero(evm.address, 20)) { + // execution should only continue if gasLimit is enough to pay for the transaction + if(has_enough_gas) { - // calculate the generated address - uint8_t* nonce = evm_get_account(&evm, caller, true)->nonce; - bytes_builder_t* bb = bb_new(); - bytes_t tmp = bytes(caller, 20); - bytes32_t hash; - rlp_encode_item(bb, &tmp); - if (big_is_zero(nonce, 32)) - tmp.len = 0; - else { - tmp.len = 32; - tmp.data = nonce; - optimize_len(tmp.data, tmp.len); - } - rlp_encode_item(bb, &tmp); - rlp_encode_to_list(bb); - keccak(bb->b, hash); - bb_free(bb); - memcpy(_to, hash + 12, 20); + // prepare all accounts + read_accounts(&evm, d_get(test, ikey(jc, "pre"))); - evm_get_account(&evm, _to, true)->nonce[31]++; - } + // we need to create an account since we don't have one + if (big_is_zero(evm.address, 20)) { + + // calculate the generated address + uint8_t* nonce = evm_get_account(&evm, caller, true)->nonce; + bytes_builder_t* bb = bb_new(); + bytes_t tmp = bytes(caller, 20); + bytes32_t hash; + rlp_encode_item(bb, &tmp); + if (big_is_zero(nonce, 32)) + tmp.len = 0; + else { + tmp.len = 32; + tmp.data = nonce; + optimize_len(tmp.data, tmp.len); + } + rlp_encode_item(bb, &tmp); + rlp_encode_to_list(bb); + keccak(bb->b, hash); + bb_free(bb); + memcpy(_to, hash + 12, 20); - // increase the nonce and pay for gas - account_t* c_adr = evm_get_account(&evm, evm.caller, true); - uint256_setn(c_adr->nonce, bytes_to_long(c_adr->nonce, 32) + 1); - uint8_t tmp[32], txval[64]; - int l; - - // handle balance for sender - long_to_bytes(evm.gas, tmp); - l = big_mul(evm.gas_price.data, evm.gas_price.len, tmp, 8, txval, 32); - l = big_add(txval, l, evm.call_value.data, evm.call_value.len, tmp, 32); - if (big_cmp(tmp, l, c_adr->balance, 32) > 0) { - print_error("not enough value to pay for the gas"); - evm_free(&evm); - return 1; - } - l = big_sub(c_adr->balance, 32, tmp, l, txval); - uint256_setb(c_adr->balance, txval, l); + evm_get_account(&evm, _to, true)->nonce[31]++; + } + + // increase the nonce and pay for gas + account_t* c_adr = evm_get_account(&evm, evm.caller, true); + uint256_setn(c_adr->nonce, bytes_to_long(c_adr->nonce, 32) + 1); + uint8_t tmp[32], txval[64]; + int l; - // handle balance for receiver - account_t* to_adr = evm_get_account(&evm, evm.address, true); - uint256_setb(to_adr->balance, tmp, big_add(to_adr->balance, 32, evm.call_value.data, evm.call_value.len, tmp, 32)); + // handle balance for sender + long_to_bytes(evm.gas, tmp); + l = big_mul(evm.gas_price.data, evm.gas_price.len, tmp, 8, txval, 32); + l = big_add(txval, l, evm.call_value.data, evm.call_value.len, tmp, 32); + if (big_cmp(tmp, l, c_adr->balance, 32) > 0) { + print_error("not enough value to pay for the gas"); + evm_free(&evm); + return 1; + } + l = big_sub(c_adr->balance, 32, tmp, l, txval); + uint256_setb(c_adr->balance, txval, l); - // handle gas - total_gas = G_TRANSACTION; - for (int i = 0; i < evm.call_data.len; i++) - total_gas += evm.call_data.data[i] ? G_TXDATA_NONZERO : G_TXDATA_ZERO; + // handle balance for receiver + account_t* to_adr = evm_get_account(&evm, evm.address, true); + uint256_setb(to_adr->balance, tmp, big_add(to_adr->balance, 32, evm.call_value.data, evm.call_value.len, tmp, 32)); - evm.gas = (total_gas > evm.gas) ? 0 : evm.gas - total_gas; + total_gas = tx_intrinsic_gas; + evm.gas -= total_gas; + } #endif } @@ -586,72 +601,68 @@ int run_evm(json_ctx_t* jctx, d_token_t* test, uint32_t props, uint64_t* ms, cha prepare_header(d_get(test, ikey(jc, "env"))); uint64_t start = clock(), gas_before = evm.gas; -#ifdef EVM_GAS - if (transaction && !d_len(d_get(transaction, ikey(jc, "to")))) - evm.gas -= G_TXCREATE; -#endif - - int fail = evm_run(&evm, evm.account); + int fail = has_enough_gas ? evm_run(&evm, evm.account) : 0; *ms = (clock() - start) / 1000; if (transaction) { #ifdef EVM_GAS - total_gas += gas_before - evm.gas; - if (fail) { - // it failed, so the transaction used up all the gas and we reverse all accounts - total_gas = d_long(get_test_val(transaction, "gasLimit", indexes)); - evm.gas = 0; - fail = 0; - uint8_t gas_tmp[32], gas_tmp2[32]; - account_t* ac = NULL; - storage_t* s = NULL; - // reset all accounts except the sender - while (evm.accounts) { - ac = evm.accounts; - // if (ac->code.data) _free(ac->code.data); - s = NULL; - while (ac->storage) { - s = ac->storage; - ac->storage = s->next; - _free(s); + if(has_enough_gas) { + total_gas += gas_before - evm.gas; + if (fail) { + // it failed, so the transaction used up all the gas and we reverse all accounts + total_gas = d_long(get_test_val(transaction, "gasLimit", indexes)); + evm.gas = 0; + fail = 0; + uint8_t gas_tmp[32], gas_tmp2[32]; + account_t* ac = NULL; + storage_t* s = NULL; + // reset all accounts except the sender + while (evm.accounts) { + ac = evm.accounts; + // if (ac->code.data) _free(ac->code.data); + s = NULL; + while (ac->storage) { + s = ac->storage; + ac->storage = s->next; + _free(s); + } + evm.accounts = ac->next; + _free(ac); } - evm.accounts = ac->next; - _free(ac); - } - - // read the accounts from pre-state - read_accounts(&evm, d_get(test, ikey(jc, "pre"))); - // reduce the gasLimit*price from caller the - account_t* sender = evm_get_account(&evm, evm.caller, true); - long_to_bytes(total_gas, gas_tmp); - int l = big_mul(evm.gas_price.data, evm.gas_price.len, gas_tmp, 8, gas_tmp2, 32); - uint256_setb(sender->balance, gas_tmp, big_sub(sender->balance, 32, gas_tmp2, l, gas_tmp)); + // read the accounts from pre-state + read_accounts(&evm, d_get(test, ikey(jc, "pre"))); - // incremente the nonce - uint256_setn(sender->nonce, bytes_to_long(sender->nonce, 32) + 1); - } + // reduce the gasLimit*price from caller the + account_t* sender = evm_get_account(&evm, evm.caller, true); + long_to_bytes(total_gas, gas_tmp); + int l = big_mul(evm.gas_price.data, evm.gas_price.len, gas_tmp, 8, gas_tmp2, 32); + uint256_setb(sender->balance, gas_tmp, big_sub(sender->balance, 32, gas_tmp2, l, gas_tmp)); - uint8_t tmp[32], tmp2[32], eth3[8]; - int l; + // incremente the nonce + uint256_setn(sender->nonce, bytes_to_long(sender->nonce, 32) + 1); + } - // if there is gas left we return it to the sender - if (evm.gas > 0) { - account_t* c_adr = evm_get_account(&evm, evm.caller, true); - long_to_bytes(evm.gas, tmp); - l = big_mul(evm.gas_price.data, evm.gas_price.len, tmp, 8, tmp2, 32); - l = big_add(tmp2, l, c_adr->balance, 32, tmp, 32); - uint256_setb(c_adr->balance, tmp, l); - } + uint8_t tmp[32], tmp2[32], eth3[8]; + int l; - // pay the miner the total gas - account_t* miner = evm_get_account(&evm, d_get_bytesk(d_get(test, ikey(jc, "env")), ikey(jc, "currentCoinbase"))->data, 1); + // if there is gas left we return it to the sender + if (evm.gas > 0) { + account_t* c_adr = evm_get_account(&evm, evm.caller, true); + long_to_bytes(evm.gas, tmp); + l = big_mul(evm.gas_price.data, evm.gas_price.len, tmp, 8, tmp2, 32); + l = big_add(tmp2, l, c_adr->balance, 32, tmp, 32); + uint256_setb(c_adr->balance, tmp, l); + } - // increase balance of the miner - long_to_bytes(total_gas, tmp); - l = big_mul(evm.gas_price.data, evm.gas_price.len, tmp, 8, tmp2, 32); - uint256_setb(miner->balance, tmp, big_add(tmp2, l, miner->balance, 32, tmp, 32)); + // pay the miner the total gas + account_t* miner = evm_get_account(&evm, d_get_bytesk(d_get(test, ikey(jc, "env")), ikey(jc, "currentCoinbase"))->data, 1); + // increase balance of the miner + long_to_bytes(total_gas, tmp); + l = big_mul(evm.gas_price.data, evm.gas_price.len, tmp, 8, tmp2, 32); + uint256_setb(miner->balance, tmp, big_add(tmp2, l, miner->balance, 32, tmp, 32)); + } #endif } diff --git a/c/test/test_rlp.c b/c/test/test_rlp.c index d08192d75..f546e7278 100644 --- a/c/test/test_rlp.c +++ b/c/test/test_rlp.c @@ -59,6 +59,7 @@ void append_rlp(bytes_builder_t* bb, d_token_t* in) { return; } bytes_t b = d_to_bytes(in); + if (d_type(in) == T_INTEGER && d_int(in) == 0) b.len = 0; rlp_encode_item(bb, &b); } diff --git a/c/test/testdata/cmd/eth_getStorageAt_empty.txt b/c/test/testdata/cmd/eth_getStorageAt_empty.txt new file mode 100644 index 000000000..377e96547 --- /dev/null +++ b/c/test/testdata/cmd/eth_getStorageAt_empty.txt @@ -0,0 +1,109 @@ +:: cmd bin/in3 eth_getStorageAt 0xe0060c57527ff36122342daebbeb19e910f3038b 0x0000000000000000000000000000000000000000000000000000000000000000 latest -fi ../c/test/testdata/cmd/eth_getStorageAt_empty.txt + +:: time 1602232122 + +:: cache nodelist_1_0xac1b824795e1eb1f6e609fe0da9b9af8beaab60f 1 +06ac1b824795e1eb1f6e609fe0da9b9af8beaab60f0000000000a825ce000000180200000024050000d264815f0000000001000000f2020000000000000000000006000000a5080000d164815f00000000050000003b06000000000000000000000500000057060000000000000000000005000000a20a000000000000000000000400000069030000000000000000000005000000a1040000d064815f0000000004000000b904000000000000000000000100000030070000000000000000000005000000dd050000d164815f00000000020000000a0400000000000000000000050000008e070000000000000000000004000000cc06000000000000000000000400000091060000000000000000000004000000da06000000000000000000000500000054090000000000000000000005000000f1080000d064815f0000000005000000ab0a0000000000000000000005000000ec0800000000000000000000050000007b1900000000000000000000040000000b160000000000000000000005000000034d00000000000000000000040000006d170000000000000000000000000001000000000e043da61725000000000006000001dd45d45e6ff99e6c34a235d263965910298985fcfe68747470733a2f2f696e332d76322e736c6f636b2e69742f6d61696e6e65742f6e642d310000000001000000011be4f459be89000000000006000001dd1fe2e9bf29aa1938859af64c413361227d04059a68747470733a2f2f696e332d76322e736c6f636b2e69742f6d61696e6e65742f6e642d3200000000010000000245871874b4b5000000000006000001dd945f75c0408c0026a3cd204d36f5e47745182fd468747470733a2f2f696e332d76322e736c6f636b2e69742f6d61696e6e65742f6e642d330000000001000000038aeaa9f6f9a9000000000006000001ddc513a534de5a9d3f413152c41b09bd8116237fc868747470733a2f2f696e332d76322e736c6f636b2e69742f6d61696e6e65742f6e642d3400000000010000000415b1ccfb8391000100000006000001ddbcdf4e3e90cc7288b578329efd7bcc90655148d268747470733a2f2f696e332d76322e736c6f636b2e69742f6d61696e6e65742f6e642d3500000000010000000503782dace9d9000000000006000001dde9a1f583c6591566b0cda30dd2a647126d1ce0c2687474703a2f2f6574682d6d61696e6e65742d30312e696e63756265642d6e6f64652e64653a38353030000000000100000006016345785d8a00000000000a000001d1cff39dbe511bcf14b65e4030b3d8700e0ed67cea68747470733a2f2f696e332d6e6f64652d312e6b65696c2d636f6e6e6563742e636f6d000000000100000007002386f26fc100000000000a000001d9792cc04f89b012ac1f98c19b7281fbda8a3e1a9268747470733a2f2f696e332d6e6f64652d66726f6d2e7370616365000000000100000008002386f26fc100000000000a000001d1b8cf3f02c24ca897b157a34019711679c6e556a868747470733a2f2f696e332e696f74656e61626c65722e636f6d000000000100000009002386f26fc100000000000f000001d977a4a0e80d7786dec85e3087cc1c6ac3802af9cd68747470733a2f2f696e63756265642e6f6e6c696e6500000000010000000a002386f26fc100000000000f000001d9591761898ba2dfcf3b230bd3ab7d0de0c4ef168f68747470733a2f2f696e332e696e64656e776f6c6b656e2e7465636800000000010000000b002386f26fc100000000000f000001d90cea2ff03adcfa047e8f54f98d41d9147c3ccd4d68747470733a2f2f696e332d672e6f70656e2d646e612e646500000000010000000c002386f26fc100000000000a000001d1510ee7f6f198e018e3529164da2473a96eeb3dc868747470733a2f2f303030312e6d61696e6e65742e696e332e616e79626c6f636b2e746f6f6c7300000000010000000d002386f26fc100000000000a000001d14323d321a39ed4a197524c6acd18c072f753c1b068747470733a2f2f696e332d7061726974792e696f74656e61626c65722e636f6d2f00000000010000000e002386f26fc100000000000a000001d18db016dbdc03e76990adda627aab64db8106be4b68747470733a2f2f696e332d676574682e696f74656e61626c65722e636f6d2f00000000010000000f002386f26fc100000000000a000001d119580b648bb23163136b583ff5f56657fffb661068747470733a2f2f696e332d696e667572612e696f74656e61626c65722e636f6d2f000000000100000010002386f26fc1000000000006000001d965b9464bc41dc35534f8b6ea5108f4905161efd268747470733a2f2f696e336e6f2e6465000000000100000011002386f26fc1000000000006000001d91389e3b68bbef358e4ee6fabf94d3c884deda37668747470733a2f2f6c657473696e63756265642e636f6d000000000100000012002386f26fc100000000000f000001d900a329c0648769a73afac7f9381e08fb43dbea7268747470733a2f2f696e336e6f64652e636f6d000000000100000013002386f26fc1000000000006000001d9ccd12a2222995e62eca64426989c2688d828aa4768747470733a2f2f636861696e642e64652f6574682f6d61696e6e657431000000000100000014002386f26fc100000000000a000001d16d172460c0303736c2fd4a329664fe03c2f0951268747470733a2f2f696e332e74756334372e78797a000000000100000015002386f26fc1000000000006000001d96e314c4c7b5ae5c6f49aea2d90a1d083abab045d68747470733a2f2f696e332e61686e656e706f737465722e6465000000000100000016002386f26fc100000000000a000001d1daaf752eabf0dc0e8b0ef00045efed6cfda727d668747470733a2f2f696e332e7468656d7973746572696f7573636c6f776e2e636f6d000000000100000017002386f26fc100000000000a000001d150ac4400652a4a0b29162cf7eac173bd6a67162768747470733a2f2f626974636875722e63682f696e332f6d61696e6e65740000000001ce25a8000000000079347c0804706a470c9ce023046d1559611bbc778eebcc345fee301d8fd1deb8 + +:: cache nodelist_42_0x4c396dcf50ac396e5fdea18163251699b5fcca25 0 + +:: cache nodelist_5_0x5f51e413581dd76759e9eed51e63d14c8d1379c8 0 + +:: cache nodelist_2000_0xa93b57289070550c82edb1106e12bb37138948b8 0 + +:: cache nodelist_153_0xc2c05fbfe76ee7748ae5f5b61b57a46cc4061c32 1 +06c2c05fbfe76ee7748ae5f5b61b57a46cc4061c3200000000003548a1000000050e000000ee0b000007a2755f000000000e000000cd0d000000000000000000000d000000130c000000000000000000000d000000b417000000000000000000000d0000009813000000000000000000000000000100000000002386f26fc1000000000002000001dd45d45e6ff99e6c34a235d263965910298985fcfe68747470733a2f2f696e332d76322e736c6f636b2e69742f6274632f6e642d31000000000100000001002386f26fc1000000000002000001dd1fe2e9bf29aa1938859af64c413361227d04059a68747470733a2f2f696e332d76322e736c6f636b2e69742f6274632f6e642d32000000000100000002002386f26fc1000000000002000001dd945f75c0408c0026a3cd204d36f5e47745182fd468747470733a2f2f696e332d76322e736c6f636b2e69742f6274632f6e642d33000000000100000003002386f26fc1000000000002000001ddc513a534de5a9d3f413152c41b09bd8116237fc868747470733a2f2f696e332d76322e736c6f636b2e69742f6274632f6e642d34000000000100000004002386f26fc1000000000002000001ddbcdf4e3e90cc7288b578329efd7bcc90655148d268747470733a2f2f696e332d76322e736c6f636b2e69742f6274632f6e642d350000000000 + +:: cache nodelist_246_0x039562872008f7a76674a6e7842804f0ad37cb13 1 +06039562872008f7a76674a6e7842804f0ad37cb130000000000732363000000050100000016270000de65785f0000000001000000250100000000000000000000420c0000573502008051010000000000430c00009a5a0200d465785f00000000430c0000c6780200ca65785f000000000000000100000000002386f26fc1000000000002000001dd45d45e6ff99e6c34a235d263965910298985fcfe68747470733a2f2f696e332d76322e736c6f636b2e69742f6577632f6e642d31000000000100000001002386f26fc1000000000002000001dd1fe2e9bf29aa1938859af64c413361227d04059a68747470733a2f2f696e332d76322e736c6f636b2e69742f6577632f6e642d32000000000100000002002386f26fc1000000000002000001dd945f75c0408c0026a3cd204d36f5e47745182fd468747470733a2f2f696e332d76322e736c6f636b2e69742f6577632f6e642d33000000000100000003002386f26fc1000000000002000001ddc513a534de5a9d3f413152c41b09bd8116237fc868747470733a2f2f696e332d76322e736c6f636b2e69742f6577632f6e642d34000000000100000004002386f26fc1000000000002000001ddbcdf4e3e90cc7288b578329efd7bcc90655148d268747470733a2f2f696e332d76322e736c6f636b2e69742f6577632f6e642d3500000000016323730000000000822678d7e7ff274c3ee8c55199d2ce12c45637362c511f86fc948592d585be24 + +:: cache nodelist_17_0xf0fb87f4757c77ea3416afe87f36acaa0496c7e9 0 + +:: rand 488640082 + +:: request https://in3-geth.iotenabler.com/ + [{"id":1,"jsonrpc":"2.0","method":"eth_getStorageAt","params":["0xe0060c57527ff36122342daebbeb19e910f3038b","0x0000000000000000000000000000000000000000000000000000000000000000","latest"],"in3":{"verification":"proof","version": "2.1.0","verifiedHashes":["0x79347c0804706a470c9ce023046d1559611bbc778eebcc345fee301d8fd1deb8"]}}] + +:: response eth_getStorageAt 0 https://in3-geth.iotenabler.com/ -11 153 +Invalid response:SSL peer certificate or SSH remote key was not OK + +:: rand 596392046 + +:: request https://in3.iotenabler.com + [{"id":1,"jsonrpc":"2.0","method":"eth_getStorageAt","params":["0xe0060c57527ff36122342daebbeb19e910f3038b","0x0000000000000000000000000000000000000000000000000000000000000000","latest"],"in3":{"verification":"proof","version": "2.1.0","verifiedHashes":["0x79347c0804706a470c9ce023046d1559611bbc778eebcc345fee301d8fd1deb8"]}}] + +:: response eth_getStorageAt 0 https://in3.iotenabler.com -11 141 +Invalid response:SSL peer certificate or SSH remote key was not OK + +:: rand 1254936573 + +:: request https://bitchur.ch/in3/mainnet + [{"id":1,"jsonrpc":"2.0","method":"eth_getStorageAt","params":["0xe0060c57527ff36122342daebbeb19e910f3038b","0x0000000000000000000000000000000000000000000000000000000000000000","latest"],"in3":{"verification":"proof","version": "2.1.0","verifiedHashes":["0x79347c0804706a470c9ce023046d1559611bbc778eebcc345fee301d8fd1deb8"]}}] + +:: response eth_getStorageAt 0 https://bitchur.ch/in3/mainnet -11 214 + +502 Bad Gateway + +

502 Bad Gateway

+
nginx/1.10.3
+ + + + +:: rand 1282085224 + +:: request https://in3-infura.iotenabler.com/ + [{"id":1,"jsonrpc":"2.0","method":"eth_getStorageAt","params":["0xe0060c57527ff36122342daebbeb19e910f3038b","0x0000000000000000000000000000000000000000000000000000000000000000","latest"],"in3":{"verification":"proof","version": "2.1.0","verifiedHashes":["0x79347c0804706a470c9ce023046d1559611bbc778eebcc345fee301d8fd1deb8"]}}] + +:: response eth_getStorageAt 0 https://in3-infura.iotenabler.com/ -11 86 +Invalid response:SSL peer certificate or SSH remote key was not OK + +:: rand 155445770 + +:: request https://in3-g.open-dna.de + [{"id":1,"jsonrpc":"2.0","method":"eth_getStorageAt","params":["0xe0060c57527ff36122342daebbeb19e910f3038b","0x0000000000000000000000000000000000000000000000000000000000000000","latest"],"in3":{"verification":"proof","version": "2.1.0","verifiedHashes":["0x79347c0804706a470c9ce023046d1559611bbc778eebcc345fee301d8fd1deb8"]}}] + +:: response eth_getStorageAt 0 https://in3-g.open-dna.de 0 590 +[{ + "id":1, + "jsonrpc":"2.0", + "result":"0x0", + "in3":{ + "proof":{ + "type":"accountProof", + "block":"0xf90212a0331d518bc337765aafcbc4b3dc9028926897ea2ade6f322181ba73a4811e58f1a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794ea674fdde714fd979de3edf0f56aa9716b898ec8a05e555b754926ca1bce1f7e29b0b22c8c18f43410da7f90a72f55e3ca37044068a00f6685c3ae5477b2a670a84e653ba664d4f7f2830de77da4e5ac10aff97a3c92a01e9031218995ef6a14e06ba97c4d006e387c0ac7fa27c33b6ae362e646306724b90100142678acc21bbae5808c6701e9e15a9c922398ebcefbab14a6cd7d66e24b1374c494574a2fdaf8424131466a166f9b849618b5fe497e9d230098f68dd268021f35f2436feb3c6603dc41b7af95b178e06592e8ce82672d113db237c28a6c1558989ea966364bd318bff4cb43a014391ac47272001208a40dccb8c07562021a002c5d8e6de4822d2c16c81ef9997d080a049eeff74161838aab80c5db26f3c456a66d82e00a8c26722db59aede1f616642f161929848e1ba2511f633bda476e78556e850eb501c2046dc1a0fab27a52c592246f4b396e829039b3120b1140acc58118b9072b23dca1928af630a58da38275c4428225390e521c9c108a58e16f7c870b947d78b30edd83a8278483be8bef83be56c7845f801f1b9165746865726d696e652d61736961312d34a00771b62763cb4ae1ed3464eddced930d2da8e4e4f19a02d42480e485b4c5448788947724895ebfde91", + "signatures":[], + "accounts":{ + "0xe0060c57527ff36122342DAEbBeB19E910F3038B":{ + "accountProof":["0xf90211a00ef2d006be3d9fcdb69f97ae55101ea74a5923a8c2d271529839ee3ed9fb2a04a0090a6cd6ebdd3b08c6f948389c10ba1ececcc960da8c899f291de090583c546da039bdacdedd8dfae7cae9b19c89046e87c6009e09ed4c006fcc34c56f969ed516a0aedde62f71fc182c59db811d344988bf1112faf0666e7331ebf5f7e055aab7cca0a19d33ce7a00f6eb7c517153dc68358a4413afba03160a1f41d4be854ca82d73a072cf3098f964ee754b136c931a62e4e3eb3c819d4e30aadba2c28a9d8db796bba0a2744003b1924c87de341270445896ea34fcb6c91a1865372c8cd5b730b33fcda0b9860d6a14a702c96ab0e92babe93472b4975733141143065ef90cc20810788da0bc801b8b285d8e8614da5fab52d9bface22976f59828e637503465bbe2b4f6bea01cb3f16f0f68a5cda4608248de132371846b682d58a77d0bf2a234000d3186eea0fe456d68cc9f453af850100b22b21e95f9777c54951d81dd566abe58f6c73884a0e4961244e6bee3ad7eb8f56b2903c3e1f8d91f416547a1902fa54f7e62cde119a01aee0c50b00fc68b2c72ac03d0738cccd8000fc060d949a3b67cd3b5e95e4237a08d9ec7bf169d7805f18e4934a8653e07ea95e72e195430e4725f80a609cec205a0a344e45a5021a735e5253fa67fbd67d3dbc98370a4385d9db0c48bce2d688185a044bcd77da7bbb5e1d987be562e9d84ef73ab9d9c2e87b8a5086419d61d23ed1e80", + "0xf90211a02992a88c15f43ac9d861b997c0121ae47de9a59e6906c0b175b63aaf7d9f0d05a01902fbb32af4ab4f052ec99f8d449a7204dba21b8f2df43d1189c573784a973ca016925352ed65b6397d2c655b52709ed41a4d703e9aee852bfd5df0e758d9a951a073adae8023caf74dc322fb48731f95e19e7b350c118890e6b78293d44149106fa085102fcfd74b053de1a79aeb3dfb4d6524329e0996e346f39a349f3d53bdc25aa0dce6e3bceb70a0d8975a87f9a9be4ce4effd87ddec638f8b7fd34c5dbdd89c0fa04a7228d4a63abdc5ba7fe2c3c034fefa6e5b7d10300bd26d4080daee8a779135a0310a7d0d44e7bf30307e50ae8040964d451db32f7933586f1a1d3c66c0d1680ca0e116ec786f2a7c7cbe2dc0c654f29bc689337f43b45351e33c080a0e74830823a0fb273d81cad1e6aeed88eb894b20fc247f8ef1fa21a0428a5704cd11ad7a7feea053be07cc3902d04e8d4a4b170060c6d42e8a0d701e9e33aa9c77399a8f071a3aa0333adcc4b1f36bc9e24a848751b320359da508e96061404dc5f05bdf86e48c0da0deba64a5cd4874b0f05da93637703a9b5306a13217975cdb5a876f0ed2d32a4ea00c0787587d3984de5ee7cd8c5d66461bc4868eacf5d7711c0b9026172b00ab11a0c46df84311c8b9ce15ac978b72eb10ef76f986c39c2a24590e733f263f7eb5aca0d3b2ead9bf048077ac65d0839dcf59173b527b3422b8061336fa4c7b9fb65d8c80", + "0xf90211a0dee3bc6ad4175d8fec43ae9afa85710a4c83840b835f53e77bd010d67f7becf7a0f9a69ec1f7e2e4ba745d56f597f29f2533051882aa3073a63ea568c5fa890bc0a0328954616f74144c80bf20c464cb2e7bfdaa0955bad88039512cc6b8554f9f6da01e87066d22c2b812a53dc7571cb4a2681ec6303f2854cfbfa3bad1b163987190a0cfb747d40f6a1c89b54e6845d74cbbdcf9bb8e593b6afcf686334c824af3697ba03caa9bdf69880e0cca42a77309aac4ac4de21ea614733439cf83450bca2d2803a0787b67da2f2cb636ffb65ec9631640679e3dfc9060f0117569607183971bafaba01b29b6a2593df2af2cc7745e30b9837e98705532f8d07a6d8ceb2b74810c0164a00495458cb693ed477d549fdb85e4b03e7c841249a44b797d2aab09e81a931bdea045db1ab0249c7d849ea2317efc7863ab80867a3c4a5704a7acc1046796a00baaa03dd772e2ac1953b0f4f11d492abd4d2ab2cddcaef296df3217003e712d3ff3d0a00d4d7f512e11a256f4f57c374e5920d2fe946808681eef8f7b2e969d165410afa0d843f3461167e1852ac6a0db894b3d53e70b2cf76eb68fef95a70c44f9950ec1a0b04340964658da20712a5517d99896f0adff59c377bbb17912ff935aaf8cca2aa0f1f2f7e3bd96d458188317193175e86048ea3de408d0ac96fcfd5c76842bbdefa01d889b35b1191473edba352a2699372e7d1ecb43d31dbf29cd63dcf138d97bba80", + "0xf90211a0589b928e69f5a70eecfae7f67abaf3cc1cfb1b9335191ef5c2bbc2f435dd122ea03aec2a7cef6cf413e7781e1abe00852cead38c096588ae4729e483257717b961a011b34d5b0eb03e6326c870b65a55e29bf2c3b969093644e09c021776074e616ca0f1b077d9ddf79b84b4ab5a58abc1d27263605a0bcb7a59b02fa5cdda66941886a09985054ac694758018cc979a7169d39874fc01566e4494300c90436b2480df11a07f389df34dcebf91d08869c356228bd2b75e5b29708d266e58542489f5a8fb87a02c69f921e32a0fa937286484f62e23126abee6d310bb37936634f50ddaab22a3a008248c1ed091d08aa7a039c3fe155b327515838cd4b870dd7b9874cbeed240c0a0b6a3ef286d658033e72bc1c11a6adbe5fe8fb48438fd210e7d109ee7c9e1777fa06f439f03442fe6f8d241be72a47c1b2615168ea56e5368a35c151c9bcdb52da7a036b5f0469cc365bb0a08d26ecdaee205a391d0ac401ca2e038ba3f70d35c08f0a0ac7effdd6cd5ce36aa046a222bb8643d5c333e72a7e1cb3e745034ad09e3065aa05e5dd8f5e81b1f1e84a5d85ba4325050df8c78cf4b8756a184329ae185c8a0fca09df98d0fed021b4d71a2f14382dfb80738e8aa39431aed9412bbb44d78cb7540a046eb0df84056e41440ab48b10e914c2bf0466c9b1acaf5914dff42ee260d5e1aa09bd7568a3f7c0d1201a523de767782546c780cc65d883b7b4d154de5d90e96e980", + "0xf90211a08f39288e94146424689cad583c7bec93c8899c694475926da4acc1c3d1233864a007a7029f60af3a79f7a18cc71391bfccd2626dd3d4f7b025a4d3153f5b91e53ba0ca9b439425e7e709a1295e18158192cc7ea1e272fd451615f402abe188680265a0ad9237c812a1dc07f18a76e70cb230439f641fe2ccbf1587db9e007a7c1c2a63a092f20d8859bc9369dd5676571637ef66e793bfb19aff7ab4113a94573b046647a061ff093419179b311df106448abe0cafbdd08782386b9719f60662efde92baaaa089d842890b920f8c7c520f400c0706c6e18d53bb1c3c858278352287b2688740a0a6f3a5f249be0b4dc567a4dd8a2fffdc90a7d1f23c01f36fc3f0a14303f257d1a0a82a755edad5e3d7214be2df2f793303ab731d47ed1720f87ae9d5b7e9571c47a0a1404a2dc092ddfaae16f3281108ca8e3168740148b0d1cdea18a6c07f12142da045f250035c3f27184281150383cbcd0870b0b202225bd07639d95474f8b8deaca01e65f66c37f374bb7ff76feb4a62bafbc121cb2e9114c676cfc1da4838b54e90a0385f9b2db2b89b88d81e889200c35ad34ecca93b36eb141de7c88d1d6809aae7a0d71fadbf95ad10fc685ab3946164bb4f426aded789823dddc191b83c8897137ea01486dc7014c3048415d6b80831ba470d6d5eb9fcf9a882829d9a4d7f90c812b5a02fc30d474d417715359fdcd77ff8730b1cc479078da4b6b58dd49cf8a67aad7380", + "0xf90211a0ed6880e8324b7de6bb55c75d96cdda41115f2044962a1da5d4adc33b14730ceea0cac25a696094fd20f5dd58f791bcf545063ac2fef672969ee472bf87e97bc319a0f790f5257baef16836bda5b1357e3fe3019d0812fb6cf2d994dca981d9f765cba0f387ec8d6f2ee307bd878d1afdb474c996db217a7bbb5adeb72e7555d823fb01a0355979e38eb57f7bd2a0142e022846c6ae05b05812f3935a7746abe015470320a0588cd4eff4fd7cc1efd3f06de869ac25ab33a1e396b82e2e6da09616322d774ba064c77a9e8d4eea673b5bfe7d20d3038a7dbae9dc8b4244f49e828773781f31fea0525e9af3ecfc4ecf42904a84556e375fae067fff98294c2c604ca2be124d6efea0e2f621d6dda063c6f9e18399c807d736f5d66dbae56c01fe49fea06458ee23c5a0e331d1f4d0fb91258509d130fdfceed4ef16738611f033ca24b638e9fa6b0fe0a0251d145d3e2c3269690a0fc4acfaf01f384a98e189db596598ceeeab725c5836a0b4f8ea430ed8614d4599d70b8210297909a225d4bb559e5944f6c6a21091a2aca0fb4413c79cc79dfffc233b2566656a8d907967480411b5cd5b996b89c924d75ba08c679b8c175ab96ca7b34ecd5446005d0d32d3f8abb9897fd441088bf41a3f85a0c563e9aa6b4ca98b6b1ac6f312dc06247cde7861f640cfae6b6e91f1dd3ce1fda0c9cc936ce4ee00ec8efbe362299626fd4a3395511c80c289f279f6be26ca51aa80", + "0xf8d18080a0496479b5659c424273e5bcafa7711e2da79a8437b91a03a28a788f19edbd773ca036d1a0692f1f1991ec5e9299d69d1eb9b5be63a9524809a7313cc981e915f3c5a08d3ace282c8899f98fb83c624756387afc64ec42622e7deb78ba584b12d09af48080a02806ee4a9eaaf72fface6341f37382853156d34c0d2d2fce2b3fd384dbd1d6fb808080a03fc506c18af266f80d111523b60abbd931d9efcf326cbbe7af1b3be298f7458a80a05943e080756c5b5a77de4f5169ba222e67010979b678631cdf6f4f3f6cc0193c808080"], + "address":"0xe0060c57527ff36122342daebbeb19e910f3038b", + "balance":"0x0", + "codeHash":"0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470", + "nonce":"0x0", + "storageHash":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "storageProof":[{ + "key":"0x0", + "proof":[], + "value":"0x0" + }] + } + } + }, + "version":"2.1.0", + "currentBlock":11020164, + "lastValidatorChange":0, + "lastNodeList":11019726, + "execTime":136, + "rpcTime":60, + "rpcCount":1 + } +}] + +:: result +0 diff --git a/c/test/util/junit.c b/c/test/util/junit.c index b6b8c0595..36bda45e8 100644 --- a/c/test/util/junit.c +++ b/c/test/util/junit.c @@ -262,7 +262,7 @@ int main(int argc, char* argv[]) { escape(&last_suite->props, out + 14); sb_add_chars(&last_suite->props, "\"/>\n"); } - else { + else { if (last_suite->out.len) sb_add_char(&last_suite->out, '\n'); escape(&last_suite->out, out); diff --git a/dotnet/ci.yml b/dotnet/ci.yml index 248953e81..9ec971008 100644 --- a/dotnet/ci.yml +++ b/dotnet/ci.yml @@ -96,7 +96,7 @@ release_nuget: - cd dotnet - export NUGET_VERSION=$(echo "$CI_COMMIT_TAG" | cut -c 2-) - dotnet pack -c Release -p:version=${NUGET_VERSION} - - dotnet nuget push In3/bin/Release/Blockchains.In3.${NUGET_VERSION}.nupkg -k {NUGET_GALLERY_API_KEY} -s https://api.nuget.org/v3/index.json + - dotnet nuget push In3/bin/Release/Blockchains.In3.${NUGET_VERSION}.nupkg -k ${NUGET_GALLERY_API_KEY} -s https://api.nuget.org/v3/index.json artifacts: paths: - dotnet/In3/bin/Release/Blockchains.In3.${NUGET_VERSION}.nupkg diff --git a/dotnet/docs/api-dotnet.md b/dotnet/docs/api-dotnet.md index 56833199c..f6ba16b45 100644 --- a/dotnet/docs/api-dotnet.md +++ b/dotnet/docs/api-dotnet.md @@ -25,3 +25,4135 @@ For more information, see [Rid Catalog](https://docs.microsoft.com/en-us/dotnet/ dotnet add package Blockchains.In3 ``` +## Examples + +### CallSmartContractFunction + +source : [in3-c/dotnet/Examples/CallSmartContractFunction//CallSmartContractFunction](https://github.com/slockit/in3-c/blob/master/dotnet/Examples/CallSmartContractFunction//CallSmartContractFunction/Program.cs) + + + +```c# +using System; +using System.Numerics; +using System.Threading.Tasks; +using In3; +using In3.Configuration; +using In3.Eth1; +using In3.Utils; + +namespace CallSmartContractFunction +{ + public class Program + { + public static async Task Main() + { + // Set it to mainnet + IN3 mainnetClient = IN3.ForChain(Chain.Mainnet); + ClientConfiguration cfg = mainnetClient.Configuration; + cfg.Proof = Proof.Standard; + + string contractAddress = "0x2736D225f85740f42D17987100dc8d58e9e16252"; + + // Create the query transaction + TransactionRequest serverCountQuery = new TransactionRequest(); + serverCountQuery.To = contractAddress; + + // Define the function and the parameters to query the total in3 servers + serverCountQuery.Function = "totalServers():uint256"; + serverCountQuery.Params = new object[0]; + + string[] serverCountResult = (string[])await mainnetClient.Eth1.Call(serverCountQuery, BlockParameter.Latest); + BigInteger servers = DataTypeConverter.HexStringToBigint(serverCountResult[0]); + + for (int i = 0; i < servers; i++) + { + TransactionRequest serverDetailQuery = new TransactionRequest(); + serverDetailQuery.To = contractAddress; + + // Define the function and the parameters to query the in3 servers detail + serverDetailQuery.Function = "servers(uint256):(string,address,uint32,uint256,uint256,address)"; + serverDetailQuery.Params = new object[] { i }; // index of the server (uint256) as per solidity function signature + + string[] serverDetailResult = (string[])await mainnetClient.Eth1.Call(serverDetailQuery, BlockParameter.Latest); + Console.Out.WriteLine($"Server url: {serverDetailResult[0]}"); + } + } + } +} + +``` + +### ConnectToEthereum + +source : [in3-c/dotnet/Examples/ConnectToEthereum//ConnectToEthereum](https://github.com/slockit/in3-c/blob/master/dotnet/Examples/ConnectToEthereum//ConnectToEthereum/Program.cs) + + + +```c# +using System; +using System.Numerics; +using System.Threading.Tasks; +using In3; + +namespace ConnectToEthereum +{ + class Program + { + static async Task Main() + { + Console.Out.WriteLine("Ethereum Main Network"); + IN3 mainnetClient = IN3.ForChain(Chain.Mainnet); + BigInteger mainnetLatest = await mainnetClient.Eth1.BlockNumber(); + BigInteger mainnetCurrentGasPrice = await mainnetClient.Eth1.GetGasPrice(); + Console.Out.WriteLine($"Latest Block Number: {mainnetLatest}"); + Console.Out.WriteLine($"Gas Price: {mainnetCurrentGasPrice} Wei"); + + Console.Out.WriteLine("Ethereum Goerli Test Network"); + IN3 goerliClient = IN3.ForChain(Chain.Goerli); + BigInteger goerliLatest = await goerliClient.Eth1.BlockNumber(); + BigInteger clientCurrentGasPrice = await goerliClient.Eth1.GetGasPrice(); + Console.Out.WriteLine($"Latest Block Number: {goerliLatest}"); + Console.Out.WriteLine($"Gas Price: {clientCurrentGasPrice} Wei"); + } + } +} +``` + +### EnsResolver + +source : [in3-c/dotnet/Examples/EnsResolver//EnsResolver](https://github.com/slockit/in3-c/blob/master/dotnet/Examples/EnsResolver//EnsResolver/Program.cs) + + + +```c# +using System; +using System.Threading.Tasks; +using In3; + +namespace EnsResolver +{ + public class Program + { + static async Task Main() + { + IN3 in3 = IN3.ForChain(Chain.Mainnet); + + string cryptoKittiesDomain = "cryptokitties.eth"; + string resolver = await in3.Eth1.Ens(cryptoKittiesDomain, ENSParameter.Resolver); + string owner = await in3.Eth1.Ens(cryptoKittiesDomain, ENSParameter.Owner); + + Console.Out.WriteLine($"The owner of {cryptoKittiesDomain} is {owner}, resolver is {resolver}."); + } + } +} +``` + +### Ipfs + +source : [in3-c/dotnet/Examples/Ipfs//Ipfs](https://github.com/slockit/in3-c/blob/master/dotnet/Examples/Ipfs//Ipfs/Program.cs) + + + +```c# +using System; +using System.Text; +using System.Threading.Tasks; +using In3; + +namespace Ipfs +{ + class Program + { + static async Task Main() + { + // Content to be stored + string toStore = "LOREM_IPSUM"; + + // Connect to ipfs. + IN3 ipfsClient = IN3.ForChain(Chain.Ipfs); + + // Store the hash since it will be needed to fetch the content back. + string hash = await ipfsClient.Ipfs.Put(toStore); + + // + byte[] storedBytes = await ipfsClient.Ipfs.Get(hash); + string storedStging = Encoding.UTF8.GetString(storedBytes, 0, storedBytes.Length); + Console.Out.WriteLine($"The stored string is: {storedStging}"); + } + } +} + +``` + +### Logs + +source : [in3-c/dotnet/Examples/Logs//Logs](https://github.com/slockit/in3-c/blob/master/dotnet/Examples/Logs//Logs/Program.cs) + + + +```c# +using System; +using System.Threading; +using System.Threading.Tasks; +using In3; +using In3.Eth1; + +namespace Logs +{ + class Program + { + static async Task Main() + { + // Define an upper limit for poll since we dont want our application potentially running forever. + int maxIterations = 500; + int oneSecond = 1000; // in ms + + // Connect to mainnet. + IN3 mainnetClient = IN3.ForChain(Chain.Mainnet); + + // Create a filter object pointing, in this case, to an "eventful" contract address. + LogFilter tetherUsFilter = new LogFilter {Address = "0xdAC17F958D2ee523a2206206994597C13D831ec7"}; + + // Create the filter to be polled for logs. + long filterId = await mainnetClient.Eth1.NewLogFilter(tetherUsFilter); + + // Loop to initiate the poll for the logs. + for (int i = 0; i < maxIterations; i++) + { + // Query for the log events since the creation of the filter or the previous poll (this method in NOT idempotent as it retrieves a diff). + Log[] tetherLogs = await mainnetClient.Eth1.GetFilterChangesFromLogs(filterId); + if (tetherLogs.Length > 0) + { + Console.Out.WriteLine("Logs found: " + tetherLogs.Length); + break; + } + + // Wait before next query. + Thread.Sleep(oneSecond); + } + } + } +} + +``` + +### SendTransaction + +source : [in3-c/dotnet/Examples/SendTransaction//SendTransaction](https://github.com/slockit/in3-c/blob/master/dotnet/Examples/SendTransaction//SendTransaction/Program.cs) + + + +```c# +using System; +using System.Threading; +using System.Threading.Tasks; +using In3; +using In3.Crypto; +using In3.Eth1; + +namespace SendTransaction +{ + public class Program + { + static async Task Main() + { + IN3 goerliClient = IN3.ForChain(Chain.Goerli); + + string myPrivateKey = "0x0829B3C639A3A8F2226C8057F100128D4F7AE8102C92048BA6DE38CF4D3BC6F1"; + string receivingAddress = "0x6FA33809667A99A805b610C49EE2042863b1bb83"; + + // Get the wallet, which is the default signer. + SimpleWallet myAccountWallet = (SimpleWallet)goerliClient.Signer; + + string myAccount = myAccountWallet.AddRawKey(myPrivateKey); + + // Create the transaction request + TransactionRequest transferWei = new TransactionRequest(); + transferWei.To = receivingAddress; + transferWei.From = myAccount; + transferWei.Value = 300; + + // Get the current gas prices + long currentGasPrice = await goerliClient.Eth1.GetGasPrice(); + transferWei.GasPrice = currentGasPrice; + + long estimatedSpentGas = await goerliClient.Eth1.EstimateGas(transferWei, BlockParameter.Latest); + Console.Out.WriteLine($"Estimated gas to spend: {estimatedSpentGas}"); + + string transactionHash = await goerliClient.Eth1.SendTransaction(transferWei); + Console.Out.WriteLine($"Transaction {transactionHash} sent."); + Thread.Sleep(30000); + + TransactionReceipt receipt = await goerliClient.Eth1.GetTransactionReceipt(transactionHash); + Console.Out.WriteLine($"Transaction {transactionHash} mined on block {receipt.BlockNumber}."); + } + } +} +``` + +### Build Examples + + +To setup and run the example projects, simply run on the respective project folder: + +```sh +dotnet run +``` + +To build all of them, on the solution folder, run: + +```sh +dotnet build +``` + +\n## Index\n + +- [Account](#T-In3-Crypto-Account 'In3.Crypto.Account') + - [Address](#P-In3-Crypto-Account-Address 'In3.Crypto.Account.Address') + - [PublicKey](#P-In3-Crypto-Account-PublicKey 'In3.Crypto.Account.PublicKey') +- [Api](#T-In3-Btc-Api 'In3.Btc.Api') +- [Api](#T-In3-Crypto-Api 'In3.Crypto.Api') +- [Api](#T-In3-Eth1-Api 'In3.Eth1.Api') +- [Api](#T-In3-Ipfs-Api 'In3.Ipfs.Api') + - [GetBlockBytes(blockHash)](#M-In3-Btc-Api-GetBlockBytes-System-String- 'In3.Btc.Api.GetBlockBytes(System.String)') + - [GetBlockHeader(blockHash)](#M-In3-Btc-Api-GetBlockHeader-System-String- 'In3.Btc.Api.GetBlockHeader(System.String)') + - [GetBlockHeaderBytes(blockHash)](#M-In3-Btc-Api-GetBlockHeaderBytes-System-String- 'In3.Btc.Api.GetBlockHeaderBytes(System.String)') + - [GetBlockWithTxData(blockHash)](#M-In3-Btc-Api-GetBlockWithTxData-System-String- 'In3.Btc.Api.GetBlockWithTxData(System.String)') + - [GetBlockWithTxIds(blockHash)](#M-In3-Btc-Api-GetBlockWithTxIds-System-String- 'In3.Btc.Api.GetBlockWithTxIds(System.String)') + - [GetTransaction(txid)](#M-In3-Btc-Api-GetTransaction-System-String- 'In3.Btc.Api.GetTransaction(System.String)') + - [GetTransactionBytes(txid)](#M-In3-Btc-Api-GetTransactionBytes-System-String- 'In3.Btc.Api.GetTransactionBytes(System.String)') + - [DecryptKey(pk,passphrase)](#M-In3-Crypto-Api-DecryptKey-System-String,System-String- 'In3.Crypto.Api.DecryptKey(System.String,System.String)') + - [EcRecover(signedData,signature,signatureType)](#M-In3-Crypto-Api-EcRecover-System-String,System-String,In3-Crypto-SignatureType- 'In3.Crypto.Api.EcRecover(System.String,System.String,In3.Crypto.SignatureType)') + - [Pk2Address(pk)](#M-In3-Crypto-Api-Pk2Address-System-String- 'In3.Crypto.Api.Pk2Address(System.String)') + - [Pk2Public(pk)](#M-In3-Crypto-Api-Pk2Public-System-String- 'In3.Crypto.Api.Pk2Public(System.String)') + - [Sha3(data)](#M-In3-Crypto-Api-Sha3-System-String- 'In3.Crypto.Api.Sha3(System.String)') + - [SignData(msg,pk,sigType)](#M-In3-Crypto-Api-SignData-System-String,System-String,In3-Crypto-SignatureType- 'In3.Crypto.Api.SignData(System.String,System.String,In3.Crypto.SignatureType)') + - [AbiDecode(signature,encodedData)](#M-In3-Eth1-Api-AbiDecode-System-String,System-String- 'In3.Eth1.Api.AbiDecode(System.String,System.String)') + - [AbiEncode(signature,args)](#M-In3-Eth1-Api-AbiEncode-System-String,System-Object[]- 'In3.Eth1.Api.AbiEncode(System.String,System.Object[])') + - [BlockNumber()](#M-In3-Eth1-Api-BlockNumber 'In3.Eth1.Api.BlockNumber') + - [Call(request,blockNumber)](#M-In3-Eth1-Api-Call-In3-Eth1-TransactionRequest,System-Numerics-BigInteger- 'In3.Eth1.Api.Call(In3.Eth1.TransactionRequest,System.Numerics.BigInteger)') + - [ChecksumAddress(address,shouldUseChainId)](#M-In3-Eth1-Api-ChecksumAddress-System-String,System-Nullable{System-Boolean}- 'In3.Eth1.Api.ChecksumAddress(System.String,System.Nullable{System.Boolean})') + - [Ens(name,type)](#M-In3-Eth1-Api-Ens-System-String,In3-ENSParameter- 'In3.Eth1.Api.Ens(System.String,In3.ENSParameter)') + - [EstimateGas(request,blockNumber)](#M-In3-Eth1-Api-EstimateGas-In3-Eth1-TransactionRequest,System-Numerics-BigInteger- 'In3.Eth1.Api.EstimateGas(In3.Eth1.TransactionRequest,System.Numerics.BigInteger)') + - [GetBalance(address,blockNumber)](#M-In3-Eth1-Api-GetBalance-System-String,System-Numerics-BigInteger- 'In3.Eth1.Api.GetBalance(System.String,System.Numerics.BigInteger)') + - [GetBlockByHash(blockHash,shouldIncludeTransactions)](#M-In3-Eth1-Api-GetBlockByHash-System-String,System-Boolean- 'In3.Eth1.Api.GetBlockByHash(System.String,System.Boolean)') + - [GetBlockByNumber(blockNumber,shouldIncludeTransactions)](#M-In3-Eth1-Api-GetBlockByNumber-System-Numerics-BigInteger,System-Boolean- 'In3.Eth1.Api.GetBlockByNumber(System.Numerics.BigInteger,System.Boolean)') + - [GetBlockTransactionCountByHash(blockHash)](#M-In3-Eth1-Api-GetBlockTransactionCountByHash-System-String- 'In3.Eth1.Api.GetBlockTransactionCountByHash(System.String)') + - [GetBlockTransactionCountByNumber(blockNumber)](#M-In3-Eth1-Api-GetBlockTransactionCountByNumber-System-Numerics-BigInteger- 'In3.Eth1.Api.GetBlockTransactionCountByNumber(System.Numerics.BigInteger)') + - [GetChainId()](#M-In3-Eth1-Api-GetChainId 'In3.Eth1.Api.GetChainId') + - [GetCode(address,blockNumber)](#M-In3-Eth1-Api-GetCode-System-String,System-Numerics-BigInteger- 'In3.Eth1.Api.GetCode(System.String,System.Numerics.BigInteger)') + - [GetFilterChangesFromLogs(filterId)](#M-In3-Eth1-Api-GetFilterChangesFromLogs-System-Int64- 'In3.Eth1.Api.GetFilterChangesFromLogs(System.Int64)') + - [GetFilterLogs(filterId)](#M-In3-Eth1-Api-GetFilterLogs-System-Int64- 'In3.Eth1.Api.GetFilterLogs(System.Int64)') + - [GetGasPrice()](#M-In3-Eth1-Api-GetGasPrice 'In3.Eth1.Api.GetGasPrice') + - [GetLogs(filter)](#M-In3-Eth1-Api-GetLogs-In3-Eth1-LogFilter- 'In3.Eth1.Api.GetLogs(In3.Eth1.LogFilter)') + - [GetStorageAt(address,position,blockNumber)](#M-In3-Eth1-Api-GetStorageAt-System-String,System-Numerics-BigInteger,System-Numerics-BigInteger- 'In3.Eth1.Api.GetStorageAt(System.String,System.Numerics.BigInteger,System.Numerics.BigInteger)') + - [GetTransactionByBlockHashAndIndex(blockHash,index)](#M-In3-Eth1-Api-GetTransactionByBlockHashAndIndex-System-String,System-Int32- 'In3.Eth1.Api.GetTransactionByBlockHashAndIndex(System.String,System.Int32)') + - [GetTransactionByBlockNumberAndIndex(blockNumber,index)](#M-In3-Eth1-Api-GetTransactionByBlockNumberAndIndex-System-Numerics-BigInteger,System-Int32- 'In3.Eth1.Api.GetTransactionByBlockNumberAndIndex(System.Numerics.BigInteger,System.Int32)') + - [GetTransactionByHash(transactionHash)](#M-In3-Eth1-Api-GetTransactionByHash-System-String- 'In3.Eth1.Api.GetTransactionByHash(System.String)') + - [GetTransactionCount(address,blockNumber)](#M-In3-Eth1-Api-GetTransactionCount-System-String,System-Numerics-BigInteger- 'In3.Eth1.Api.GetTransactionCount(System.String,System.Numerics.BigInteger)') + - [GetTransactionReceipt(transactionHash)](#M-In3-Eth1-Api-GetTransactionReceipt-System-String- 'In3.Eth1.Api.GetTransactionReceipt(System.String)') + - [GetUncleByBlockNumberAndIndex(blockNumber,position)](#M-In3-Eth1-Api-GetUncleByBlockNumberAndIndex-System-Numerics-BigInteger,System-Int32- 'In3.Eth1.Api.GetUncleByBlockNumberAndIndex(System.Numerics.BigInteger,System.Int32)') + - [GetUncleCountByBlockHash(blockHash)](#M-In3-Eth1-Api-GetUncleCountByBlockHash-System-String- 'In3.Eth1.Api.GetUncleCountByBlockHash(System.String)') + - [GetUncleCountByBlockNumber(blockNumber)](#M-In3-Eth1-Api-GetUncleCountByBlockNumber-System-Numerics-BigInteger- 'In3.Eth1.Api.GetUncleCountByBlockNumber(System.Numerics.BigInteger)') + - [NewBlockFilter()](#M-In3-Eth1-Api-NewBlockFilter 'In3.Eth1.Api.NewBlockFilter') + - [NewLogFilter(filter)](#M-In3-Eth1-Api-NewLogFilter-In3-Eth1-LogFilter- 'In3.Eth1.Api.NewLogFilter(In3.Eth1.LogFilter)') + - [SendRawTransaction(transactionData)](#M-In3-Eth1-Api-SendRawTransaction-System-String- 'In3.Eth1.Api.SendRawTransaction(System.String)') + - [SendTransaction(tx)](#M-In3-Eth1-Api-SendTransaction-In3-Eth1-TransactionRequest- 'In3.Eth1.Api.SendTransaction(In3.Eth1.TransactionRequest)') + - [SendTransactionAndWait(tx)](#M-In3-Eth1-Api-SendTransactionAndWait-In3-Eth1-TransactionRequest- 'In3.Eth1.Api.SendTransactionAndWait(In3.Eth1.TransactionRequest)') + - [UninstallFilter(filterId)](#M-In3-Eth1-Api-UninstallFilter-System-Int64- 'In3.Eth1.Api.UninstallFilter(System.Int64)') + - [Get(multihash)](#M-In3-Ipfs-Api-Get-System-String- 'In3.Ipfs.Api.Get(System.String)') + - [Put(content)](#M-In3-Ipfs-Api-Put-System-String- 'In3.Ipfs.Api.Put(System.String)') + - [Put(content)](#M-In3-Ipfs-Api-Put-System-Byte[]- 'In3.Ipfs.Api.Put(System.Byte[])') +- [BaseConfiguration](#T-In3-Configuration-BaseConfiguration 'In3.Configuration.BaseConfiguration') +- [Block](#T-In3-Eth1-Block 'In3.Eth1.Block') + - [Author](#P-In3-Eth1-Block-Author 'In3.Eth1.Block.Author') + - [Difficulty](#P-In3-Eth1-Block-Difficulty 'In3.Eth1.Block.Difficulty') + - [ExtraData](#P-In3-Eth1-Block-ExtraData 'In3.Eth1.Block.ExtraData') + - [GasLimit](#P-In3-Eth1-Block-GasLimit 'In3.Eth1.Block.GasLimit') + - [Hash](#P-In3-Eth1-Block-Hash 'In3.Eth1.Block.Hash') + - [LogsBloom](#P-In3-Eth1-Block-LogsBloom 'In3.Eth1.Block.LogsBloom') + - [MixHash](#P-In3-Eth1-Block-MixHash 'In3.Eth1.Block.MixHash') + - [Nonce](#P-In3-Eth1-Block-Nonce 'In3.Eth1.Block.Nonce') + - [Number](#P-In3-Eth1-Block-Number 'In3.Eth1.Block.Number') + - [ParentHash](#P-In3-Eth1-Block-ParentHash 'In3.Eth1.Block.ParentHash') + - [ReceiptsRoot](#P-In3-Eth1-Block-ReceiptsRoot 'In3.Eth1.Block.ReceiptsRoot') + - [Sha3Uncles](#P-In3-Eth1-Block-Sha3Uncles 'In3.Eth1.Block.Sha3Uncles') + - [Size](#P-In3-Eth1-Block-Size 'In3.Eth1.Block.Size') + - [StateRoot](#P-In3-Eth1-Block-StateRoot 'In3.Eth1.Block.StateRoot') + - [Timestamp](#P-In3-Eth1-Block-Timestamp 'In3.Eth1.Block.Timestamp') + - [TotalDifficulty](#P-In3-Eth1-Block-TotalDifficulty 'In3.Eth1.Block.TotalDifficulty') + - [TransactionsRoot](#P-In3-Eth1-Block-TransactionsRoot 'In3.Eth1.Block.TransactionsRoot') + - [Uncles](#P-In3-Eth1-Block-Uncles 'In3.Eth1.Block.Uncles') +- [BlockHeader](#T-In3-Btc-BlockHeader 'In3.Btc.BlockHeader') + - [Bits](#P-In3-Btc-BlockHeader-Bits 'In3.Btc.BlockHeader.Bits') + - [Chainwork](#P-In3-Btc-BlockHeader-Chainwork 'In3.Btc.BlockHeader.Chainwork') + - [Confirmations](#P-In3-Btc-BlockHeader-Confirmations 'In3.Btc.BlockHeader.Confirmations') + - [Difficulty](#P-In3-Btc-BlockHeader-Difficulty 'In3.Btc.BlockHeader.Difficulty') + - [Hash](#P-In3-Btc-BlockHeader-Hash 'In3.Btc.BlockHeader.Hash') + - [Height](#P-In3-Btc-BlockHeader-Height 'In3.Btc.BlockHeader.Height') + - [Mediantime](#P-In3-Btc-BlockHeader-Mediantime 'In3.Btc.BlockHeader.Mediantime') + - [Merkleroot](#P-In3-Btc-BlockHeader-Merkleroot 'In3.Btc.BlockHeader.Merkleroot') + - [NTx](#P-In3-Btc-BlockHeader-NTx 'In3.Btc.BlockHeader.NTx') + - [Nextblockhash](#P-In3-Btc-BlockHeader-Nextblockhash 'In3.Btc.BlockHeader.Nextblockhash') + - [Nonce](#P-In3-Btc-BlockHeader-Nonce 'In3.Btc.BlockHeader.Nonce') + - [Previousblockhash](#P-In3-Btc-BlockHeader-Previousblockhash 'In3.Btc.BlockHeader.Previousblockhash') + - [Time](#P-In3-Btc-BlockHeader-Time 'In3.Btc.BlockHeader.Time') + - [Version](#P-In3-Btc-BlockHeader-Version 'In3.Btc.BlockHeader.Version') + - [VersionHex](#P-In3-Btc-BlockHeader-VersionHex 'In3.Btc.BlockHeader.VersionHex') +- [BlockParameter](#T-In3-BlockParameter 'In3.BlockParameter') + - [Earliest](#P-In3-BlockParameter-Earliest 'In3.BlockParameter.Earliest') + - [Latest](#P-In3-BlockParameter-Latest 'In3.BlockParameter.Latest') +- [Block\`1](#T-In3-Btc-Block`1 'In3.Btc.Block`1') + - [Size](#P-In3-Btc-Block`1-Size 'In3.Btc.Block`1.Size') + - [Tx](#P-In3-Btc-Block`1-Tx 'In3.Btc.Block`1.Tx') + - [Weight](#P-In3-Btc-Block`1-Weight 'In3.Btc.Block`1.Weight') +- [Chain](#T-In3-Chain 'In3.Chain') + - [Btc](#F-In3-Chain-Btc 'In3.Chain.Btc') + - [Evan](#F-In3-Chain-Evan 'In3.Chain.Evan') + - [Ewc](#F-In3-Chain-Ewc 'In3.Chain.Ewc') + - [Goerli](#F-In3-Chain-Goerli 'In3.Chain.Goerli') + - [Ipfs](#F-In3-Chain-Ipfs 'In3.Chain.Ipfs') + - [Local](#F-In3-Chain-Local 'In3.Chain.Local') + - [Mainnet](#F-In3-Chain-Mainnet 'In3.Chain.Mainnet') + - [Multichain](#F-In3-Chain-Multichain 'In3.Chain.Multichain') + - [Tobalaba](#F-In3-Chain-Tobalaba 'In3.Chain.Tobalaba') + - [Volta](#F-In3-Chain-Volta 'In3.Chain.Volta') +- [ChainConfiguration](#T-In3-Configuration-ChainConfiguration 'In3.Configuration.ChainConfiguration') + - [#ctor(chain,clientConfiguration)](#M-In3-Configuration-ChainConfiguration-#ctor-In3-Chain,In3-Configuration-ClientConfiguration- 'In3.Configuration.ChainConfiguration.#ctor(In3.Chain,In3.Configuration.ClientConfiguration)') + - [Contract](#P-In3-Configuration-ChainConfiguration-Contract 'In3.Configuration.ChainConfiguration.Contract') + - [NeedsUpdate](#P-In3-Configuration-ChainConfiguration-NeedsUpdate 'In3.Configuration.ChainConfiguration.NeedsUpdate') + - [NodesConfiguration](#P-In3-Configuration-ChainConfiguration-NodesConfiguration 'In3.Configuration.ChainConfiguration.NodesConfiguration') + - [RegistryId](#P-In3-Configuration-ChainConfiguration-RegistryId 'In3.Configuration.ChainConfiguration.RegistryId') + - [WhiteList](#P-In3-Configuration-ChainConfiguration-WhiteList 'In3.Configuration.ChainConfiguration.WhiteList') + - [WhiteListContract](#P-In3-Configuration-ChainConfiguration-WhiteListContract 'In3.Configuration.ChainConfiguration.WhiteListContract') +- [ClientConfiguration](#T-In3-Configuration-ClientConfiguration 'In3.Configuration.ClientConfiguration') + - [AutoUpdateList](#P-In3-Configuration-ClientConfiguration-AutoUpdateList 'In3.Configuration.ClientConfiguration.AutoUpdateList') + - [BootWeights](#P-In3-Configuration-ClientConfiguration-BootWeights 'In3.Configuration.ClientConfiguration.BootWeights') + - [ChainsConfiguration](#P-In3-Configuration-ClientConfiguration-ChainsConfiguration 'In3.Configuration.ClientConfiguration.ChainsConfiguration') + - [Finality](#P-In3-Configuration-ClientConfiguration-Finality 'In3.Configuration.ClientConfiguration.Finality') + - [IncludeCode](#P-In3-Configuration-ClientConfiguration-IncludeCode 'In3.Configuration.ClientConfiguration.IncludeCode') + - [KeepIn3](#P-In3-Configuration-ClientConfiguration-KeepIn3 'In3.Configuration.ClientConfiguration.KeepIn3') + - [MaxAttempts](#P-In3-Configuration-ClientConfiguration-MaxAttempts 'In3.Configuration.ClientConfiguration.MaxAttempts') + - [MinDeposit](#P-In3-Configuration-ClientConfiguration-MinDeposit 'In3.Configuration.ClientConfiguration.MinDeposit') + - [NodeLimit](#P-In3-Configuration-ClientConfiguration-NodeLimit 'In3.Configuration.ClientConfiguration.NodeLimit') + - [NodeProps](#P-In3-Configuration-ClientConfiguration-NodeProps 'In3.Configuration.ClientConfiguration.NodeProps') + - [Proof](#P-In3-Configuration-ClientConfiguration-Proof 'In3.Configuration.ClientConfiguration.Proof') + - [ReplaceLatestBlock](#P-In3-Configuration-ClientConfiguration-ReplaceLatestBlock 'In3.Configuration.ClientConfiguration.ReplaceLatestBlock') + - [RequestCount](#P-In3-Configuration-ClientConfiguration-RequestCount 'In3.Configuration.ClientConfiguration.RequestCount') + - [Rpc](#P-In3-Configuration-ClientConfiguration-Rpc 'In3.Configuration.ClientConfiguration.Rpc') + - [SignatureCount](#P-In3-Configuration-ClientConfiguration-SignatureCount 'In3.Configuration.ClientConfiguration.SignatureCount') + - [Timeout](#P-In3-Configuration-ClientConfiguration-Timeout 'In3.Configuration.ClientConfiguration.Timeout') + - [UseHttp](#P-In3-Configuration-ClientConfiguration-UseHttp 'In3.Configuration.ClientConfiguration.UseHttp') +- [Context](#T-In3-Context-Context 'In3.Context.Context') + - [#ctor(ctx,nativeClient)](#M-In3-Context-Context-#ctor-System-IntPtr,In3-Native-NativeClient- 'In3.Context.Context.#ctor(System.IntPtr,In3.Native.NativeClient)') + - [CreateNativeCtx(nativeIn3Ptr,rpc)](#M-In3-Context-Context-CreateNativeCtx-System-IntPtr,System-String- 'In3.Context.Context.CreateNativeCtx(System.IntPtr,System.String)') + - [Dispose()](#M-In3-Context-Context-Dispose 'In3.Context.Context.Dispose') + - [Execute()](#M-In3-Context-Context-Execute 'In3.Context.Context.Execute') + - [FromRpc(wrapper,rpc)](#M-In3-Context-Context-FromRpc-In3-Native-NativeClient,System-String- 'In3.Context.Context.FromRpc(In3.Native.NativeClient,System.String)') + - [GetErrorMessage()](#M-In3-Context-Context-GetErrorMessage 'In3.Context.Context.GetErrorMessage') + - [GetLastWaiting()](#M-In3-Context-Context-GetLastWaiting 'In3.Context.Context.GetLastWaiting') + - [GetResponse()](#M-In3-Context-Context-GetResponse 'In3.Context.Context.GetResponse') + - [GetType()](#M-In3-Context-Context-GetType 'In3.Context.Context.GetType') + - [HandleRequest()](#M-In3-Context-Context-HandleRequest 'In3.Context.Context.HandleRequest') + - [HandleSign()](#M-In3-Context-Context-HandleSign 'In3.Context.Context.HandleSign') + - [IsValid()](#M-In3-Context-Context-IsValid 'In3.Context.Context.IsValid') + - [ReportError()](#M-In3-Context-Context-ReportError-System-String- 'In3.Context.Context.ReportError(System.String)') +- [ContextException](#T-In3-Error-ContextException 'In3.Error.ContextException') +- [DataTypeConverter](#T-In3-Utils-DataTypeConverter 'In3.Utils.DataTypeConverter') + - [HexStringToBigint(source)](#M-In3-Utils-DataTypeConverter-HexStringToBigint-System-String- 'In3.Utils.DataTypeConverter.HexStringToBigint(System.String)') +- [DefaultTransport](#T-In3-Transport-DefaultTransport 'In3.Transport.DefaultTransport') + - [#ctor()](#M-In3-Transport-DefaultTransport-#ctor 'In3.Transport.DefaultTransport.#ctor') + - [Handle(url,payload)](#M-In3-Transport-DefaultTransport-Handle-System-String,System-String- 'In3.Transport.DefaultTransport.Handle(System.String,System.String)') +- [ENSParameter](#T-In3-ENSParameter 'In3.ENSParameter') + - [Addr](#P-In3-ENSParameter-Addr 'In3.ENSParameter.Addr') + - [Hash](#P-In3-ENSParameter-Hash 'In3.ENSParameter.Hash') + - [Owner](#P-In3-ENSParameter-Owner 'In3.ENSParameter.Owner') + - [Resolver](#P-In3-ENSParameter-Resolver 'In3.ENSParameter.Resolver') +- [IN3](#T-In3-IN3 'In3.IN3') + - [#ctor(chainId)](#M-In3-IN3-#ctor-In3-Chain- 'In3.IN3.#ctor(In3.Chain)') + - [Btc](#P-In3-IN3-Btc 'In3.IN3.Btc') + - [Configuration](#P-In3-IN3-Configuration 'In3.IN3.Configuration') + - [Crypto](#P-In3-IN3-Crypto 'In3.IN3.Crypto') + - [Eth1](#P-In3-IN3-Eth1 'In3.IN3.Eth1') + - [Ipfs](#P-In3-IN3-Ipfs 'In3.IN3.Ipfs') + - [Signer](#P-In3-IN3-Signer 'In3.IN3.Signer') + - [Storage](#P-In3-IN3-Storage 'In3.IN3.Storage') + - [Transport](#P-In3-IN3-Transport 'In3.IN3.Transport') + - [Finalize()](#M-In3-IN3-Finalize 'In3.IN3.Finalize') + - [ForChain(chain)](#M-In3-IN3-ForChain-In3-Chain- 'In3.IN3.ForChain(In3.Chain)') + - [SendRpc(method,args,in3)](#M-In3-IN3-SendRpc-System-String,System-Object[],System-Collections-Generic-Dictionary{System-String,System-Object}- 'In3.IN3.SendRpc(System.String,System.Object[],System.Collections.Generic.Dictionary{System.String,System.Object})') +- [In3Exception](#T-In3-Error-In3Exception 'In3.Error.In3Exception') +- [InMemoryStorage](#T-In3-Storage-InMemoryStorage 'In3.Storage.InMemoryStorage') + - [#ctor()](#M-In3-Storage-InMemoryStorage-#ctor 'In3.Storage.InMemoryStorage.#ctor') + - [Clear()](#M-In3-Storage-InMemoryStorage-Clear 'In3.Storage.InMemoryStorage.Clear') + - [GetItem(key)](#M-In3-Storage-InMemoryStorage-GetItem-System-String- 'In3.Storage.InMemoryStorage.GetItem(System.String)') + - [SetItem(key,content)](#M-In3-Storage-InMemoryStorage-SetItem-System-String,System-Byte[]- 'In3.Storage.InMemoryStorage.SetItem(System.String,System.Byte[])') +- [InvalidSignerException](#T-In3-Error-InvalidSignerException 'In3.Error.InvalidSignerException') +- [InvalidTransactionRequestException](#T-In3-Error-InvalidTransactionRequestException 'In3.Error.InvalidTransactionRequestException') +- [Log](#T-In3-Eth1-Log 'In3.Eth1.Log') + - [Address](#P-In3-Eth1-Log-Address 'In3.Eth1.Log.Address') + - [BlockHash](#P-In3-Eth1-Log-BlockHash 'In3.Eth1.Log.BlockHash') + - [BlockNumber](#P-In3-Eth1-Log-BlockNumber 'In3.Eth1.Log.BlockNumber') + - [Data](#P-In3-Eth1-Log-Data 'In3.Eth1.Log.Data') + - [LogIndex](#P-In3-Eth1-Log-LogIndex 'In3.Eth1.Log.LogIndex') + - [Removed](#P-In3-Eth1-Log-Removed 'In3.Eth1.Log.Removed') + - [Topics](#P-In3-Eth1-Log-Topics 'In3.Eth1.Log.Topics') + - [TransactionHash](#P-In3-Eth1-Log-TransactionHash 'In3.Eth1.Log.TransactionHash') + - [TransactionIndex](#P-In3-Eth1-Log-TransactionIndex 'In3.Eth1.Log.TransactionIndex') + - [Type](#P-In3-Eth1-Log-Type 'In3.Eth1.Log.Type') +- [LogFilter](#T-In3-Eth1-LogFilter 'In3.Eth1.LogFilter') + - [#ctor()](#M-In3-Eth1-LogFilter-#ctor 'In3.Eth1.LogFilter.#ctor') + - [Address](#P-In3-Eth1-LogFilter-Address 'In3.Eth1.LogFilter.Address') + - [BlockHash](#P-In3-Eth1-LogFilter-BlockHash 'In3.Eth1.LogFilter.BlockHash') + - [FromBlock](#P-In3-Eth1-LogFilter-FromBlock 'In3.Eth1.LogFilter.FromBlock') + - [ToBlock](#P-In3-Eth1-LogFilter-ToBlock 'In3.Eth1.LogFilter.ToBlock') + - [Topics](#P-In3-Eth1-LogFilter-Topics 'In3.Eth1.LogFilter.Topics') +- [NodeConfiguration](#T-In3-Configuration-NodeConfiguration 'In3.Configuration.NodeConfiguration') + - [#ctor(config)](#M-In3-Configuration-NodeConfiguration-#ctor-In3-Configuration-ChainConfiguration- 'In3.Configuration.NodeConfiguration.#ctor(In3.Configuration.ChainConfiguration)') + - [Address](#P-In3-Configuration-NodeConfiguration-Address 'In3.Configuration.NodeConfiguration.Address') + - [Props](#P-In3-Configuration-NodeConfiguration-Props 'In3.Configuration.NodeConfiguration.Props') + - [Url](#P-In3-Configuration-NodeConfiguration-Url 'In3.Configuration.NodeConfiguration.Url') +- [Proof](#T-In3-Configuration-Proof 'In3.Configuration.Proof') + - [Full](#P-In3-Configuration-Proof-Full 'In3.Configuration.Proof.Full') + - [None](#P-In3-Configuration-Proof-None 'In3.Configuration.Proof.None') + - [Standard](#P-In3-Configuration-Proof-Standard 'In3.Configuration.Proof.Standard') +- [Props](#T-In3-Configuration-Props 'In3.Configuration.Props') + - [NodePropArchive](#F-In3-Configuration-Props-NodePropArchive 'In3.Configuration.Props.NodePropArchive') + - [NodePropBinary](#F-In3-Configuration-Props-NodePropBinary 'In3.Configuration.Props.NodePropBinary') + - [NodePropData](#F-In3-Configuration-Props-NodePropData 'In3.Configuration.Props.NodePropData') + - [NodePropHttp](#F-In3-Configuration-Props-NodePropHttp 'In3.Configuration.Props.NodePropHttp') + - [NodePropMinblockheight](#F-In3-Configuration-Props-NodePropMinblockheight 'In3.Configuration.Props.NodePropMinblockheight') + - [NodePropMultichain](#F-In3-Configuration-Props-NodePropMultichain 'In3.Configuration.Props.NodePropMultichain') + - [NodePropOnion](#F-In3-Configuration-Props-NodePropOnion 'In3.Configuration.Props.NodePropOnion') + - [NodePropProof](#F-In3-Configuration-Props-NodePropProof 'In3.Configuration.Props.NodePropProof') + - [NodePropSigner](#F-In3-Configuration-Props-NodePropSigner 'In3.Configuration.Props.NodePropSigner') + - [NodePropStats](#F-In3-Configuration-Props-NodePropStats 'In3.Configuration.Props.NodePropStats') +- [RpcException](#T-In3-Error-RpcException 'In3.Error.RpcException') + - [Code](#P-In3-Error-RpcException-Code 'In3.Error.RpcException.Code') +- [ScriptPubKey](#T-In3-Btc-ScriptPubKey 'In3.Btc.ScriptPubKey') + - [Addresses](#P-In3-Btc-ScriptPubKey-Addresses 'In3.Btc.ScriptPubKey.Addresses') + - [Asm](#P-In3-Btc-ScriptPubKey-Asm 'In3.Btc.ScriptPubKey.Asm') + - [Hex](#P-In3-Btc-ScriptPubKey-Hex 'In3.Btc.ScriptPubKey.Hex') + - [ReqSigs](#P-In3-Btc-ScriptPubKey-ReqSigs 'In3.Btc.ScriptPubKey.ReqSigs') + - [Type](#P-In3-Btc-ScriptPubKey-Type 'In3.Btc.ScriptPubKey.Type') +- [ScriptSig](#T-In3-Btc-ScriptSig 'In3.Btc.ScriptSig') + - [Asm](#P-In3-Btc-ScriptSig-Asm 'In3.Btc.ScriptSig.Asm') + - [Hex](#P-In3-Btc-ScriptSig-Hex 'In3.Btc.ScriptSig.Hex') +- [SignatureType](#T-In3-Crypto-SignatureType 'In3.Crypto.SignatureType') + - [EthSign](#P-In3-Crypto-SignatureType-EthSign 'In3.Crypto.SignatureType.EthSign') + - [Hash](#P-In3-Crypto-SignatureType-Hash 'In3.Crypto.SignatureType.Hash') + - [Raw](#P-In3-Crypto-SignatureType-Raw 'In3.Crypto.SignatureType.Raw') +- [SignedData](#T-In3-Crypto-SignedData 'In3.Crypto.SignedData') + - [Message](#P-In3-Crypto-SignedData-Message 'In3.Crypto.SignedData.Message') + - [MessageHash](#P-In3-Crypto-SignedData-MessageHash 'In3.Crypto.SignedData.MessageHash') + - [R](#P-In3-Crypto-SignedData-R 'In3.Crypto.SignedData.R') + - [S](#P-In3-Crypto-SignedData-S 'In3.Crypto.SignedData.S') + - [Signature](#P-In3-Crypto-SignedData-Signature 'In3.Crypto.SignedData.Signature') + - [V](#P-In3-Crypto-SignedData-V 'In3.Crypto.SignedData.V') +- [Signer](#T-In3-Crypto-Signer 'In3.Crypto.Signer') + - [CanSign(account)](#M-In3-Crypto-Signer-CanSign-System-String- 'In3.Crypto.Signer.CanSign(System.String)') + - [PrepareTransaction()](#M-In3-Crypto-Signer-PrepareTransaction-In3-Eth1-TransactionRequest- 'In3.Crypto.Signer.PrepareTransaction(In3.Eth1.TransactionRequest)') + - [Sign(data,account)](#M-In3-Crypto-Signer-Sign-System-String,System-String- 'In3.Crypto.Signer.Sign(System.String,System.String)') +- [SimpleWallet](#T-In3-Crypto-SimpleWallet 'In3.Crypto.SimpleWallet') + - [#ctor(in3)](#M-In3-Crypto-SimpleWallet-#ctor-In3-IN3- 'In3.Crypto.SimpleWallet.#ctor(In3.IN3)') + - [AddRawKey(privateKey)](#M-In3-Crypto-SimpleWallet-AddRawKey-System-String- 'In3.Crypto.SimpleWallet.AddRawKey(System.String)') + - [CanSign(address)](#M-In3-Crypto-SimpleWallet-CanSign-System-String- 'In3.Crypto.SimpleWallet.CanSign(System.String)') + - [PrepareTransaction(tx)](#M-In3-Crypto-SimpleWallet-PrepareTransaction-In3-Eth1-TransactionRequest- 'In3.Crypto.SimpleWallet.PrepareTransaction(In3.Eth1.TransactionRequest)') + - [Sign(data,address)](#M-In3-Crypto-SimpleWallet-Sign-System-String,System-String- 'In3.Crypto.SimpleWallet.Sign(System.String,System.String)') +- [Storage](#T-In3-Storage-Storage 'In3.Storage.Storage') + - [Clear()](#M-In3-Storage-Storage-Clear 'In3.Storage.Storage.Clear') + - [GetItem(key)](#M-In3-Storage-Storage-GetItem-System-String- 'In3.Storage.Storage.GetItem(System.String)') + - [SetItem(key,content)](#M-In3-Storage-Storage-SetItem-System-String,System-Byte[]- 'In3.Storage.Storage.SetItem(System.String,System.Byte[])') +- [Transaction](#T-In3-Btc-Transaction 'In3.Btc.Transaction') +- [Transaction](#T-In3-Eth1-Transaction 'In3.Eth1.Transaction') + - [Blockhash](#P-In3-Btc-Transaction-Blockhash 'In3.Btc.Transaction.Blockhash') + - [Blocktime](#P-In3-Btc-Transaction-Blocktime 'In3.Btc.Transaction.Blocktime') + - [Confirmations](#P-In3-Btc-Transaction-Confirmations 'In3.Btc.Transaction.Confirmations') + - [Hash](#P-In3-Btc-Transaction-Hash 'In3.Btc.Transaction.Hash') + - [Hex](#P-In3-Btc-Transaction-Hex 'In3.Btc.Transaction.Hex') + - [Locktime](#P-In3-Btc-Transaction-Locktime 'In3.Btc.Transaction.Locktime') + - [Size](#P-In3-Btc-Transaction-Size 'In3.Btc.Transaction.Size') + - [Time](#P-In3-Btc-Transaction-Time 'In3.Btc.Transaction.Time') + - [Txid](#P-In3-Btc-Transaction-Txid 'In3.Btc.Transaction.Txid') + - [Version](#P-In3-Btc-Transaction-Version 'In3.Btc.Transaction.Version') + - [Vin](#P-In3-Btc-Transaction-Vin 'In3.Btc.Transaction.Vin') + - [Vout](#P-In3-Btc-Transaction-Vout 'In3.Btc.Transaction.Vout') + - [Vsize](#P-In3-Btc-Transaction-Vsize 'In3.Btc.Transaction.Vsize') + - [Weight](#P-In3-Btc-Transaction-Weight 'In3.Btc.Transaction.Weight') + - [BlockHash](#P-In3-Eth1-Transaction-BlockHash 'In3.Eth1.Transaction.BlockHash') + - [BlockNumber](#P-In3-Eth1-Transaction-BlockNumber 'In3.Eth1.Transaction.BlockNumber') + - [ChainId](#P-In3-Eth1-Transaction-ChainId 'In3.Eth1.Transaction.ChainId') + - [Creates](#P-In3-Eth1-Transaction-Creates 'In3.Eth1.Transaction.Creates') + - [From](#P-In3-Eth1-Transaction-From 'In3.Eth1.Transaction.From') + - [Gas](#P-In3-Eth1-Transaction-Gas 'In3.Eth1.Transaction.Gas') + - [GasPrice](#P-In3-Eth1-Transaction-GasPrice 'In3.Eth1.Transaction.GasPrice') + - [Hash](#P-In3-Eth1-Transaction-Hash 'In3.Eth1.Transaction.Hash') + - [Input](#P-In3-Eth1-Transaction-Input 'In3.Eth1.Transaction.Input') + - [Nonce](#P-In3-Eth1-Transaction-Nonce 'In3.Eth1.Transaction.Nonce') + - [PublicKey](#P-In3-Eth1-Transaction-PublicKey 'In3.Eth1.Transaction.PublicKey') + - [R](#P-In3-Eth1-Transaction-R 'In3.Eth1.Transaction.R') + - [Raw](#P-In3-Eth1-Transaction-Raw 'In3.Eth1.Transaction.Raw') + - [S](#P-In3-Eth1-Transaction-S 'In3.Eth1.Transaction.S') + - [StandardV](#P-In3-Eth1-Transaction-StandardV 'In3.Eth1.Transaction.StandardV') + - [To](#P-In3-Eth1-Transaction-To 'In3.Eth1.Transaction.To') + - [TransactionIndex](#P-In3-Eth1-Transaction-TransactionIndex 'In3.Eth1.Transaction.TransactionIndex') + - [V](#P-In3-Eth1-Transaction-V 'In3.Eth1.Transaction.V') + - [Value](#P-In3-Eth1-Transaction-Value 'In3.Eth1.Transaction.Value') +- [TransactionBlock](#T-In3-Eth1-TransactionBlock 'In3.Eth1.TransactionBlock') + - [Transactions](#P-In3-Eth1-TransactionBlock-Transactions 'In3.Eth1.TransactionBlock.Transactions') +- [TransactionHashBlock](#T-In3-Eth1-TransactionHashBlock 'In3.Eth1.TransactionHashBlock') + - [Transactions](#P-In3-Eth1-TransactionHashBlock-Transactions 'In3.Eth1.TransactionHashBlock.Transactions') +- [TransactionInput](#T-In3-Btc-TransactionInput 'In3.Btc.TransactionInput') + - [ScriptSig](#P-In3-Btc-TransactionInput-ScriptSig 'In3.Btc.TransactionInput.ScriptSig') + - [Sequence](#P-In3-Btc-TransactionInput-Sequence 'In3.Btc.TransactionInput.Sequence') + - [Txid](#P-In3-Btc-TransactionInput-Txid 'In3.Btc.TransactionInput.Txid') + - [Txinwitness](#P-In3-Btc-TransactionInput-Txinwitness 'In3.Btc.TransactionInput.Txinwitness') + - [Yout](#P-In3-Btc-TransactionInput-Yout 'In3.Btc.TransactionInput.Yout') +- [TransactionOutput](#T-In3-Btc-TransactionOutput 'In3.Btc.TransactionOutput') + - [N](#P-In3-Btc-TransactionOutput-N 'In3.Btc.TransactionOutput.N') + - [ScriptPubKey](#P-In3-Btc-TransactionOutput-ScriptPubKey 'In3.Btc.TransactionOutput.ScriptPubKey') + - [Value](#P-In3-Btc-TransactionOutput-Value 'In3.Btc.TransactionOutput.Value') +- [TransactionReceipt](#T-In3-Eth1-TransactionReceipt 'In3.Eth1.TransactionReceipt') + - [BlockHash](#P-In3-Eth1-TransactionReceipt-BlockHash 'In3.Eth1.TransactionReceipt.BlockHash') + - [BlockNumber](#P-In3-Eth1-TransactionReceipt-BlockNumber 'In3.Eth1.TransactionReceipt.BlockNumber') + - [ContractAddress](#P-In3-Eth1-TransactionReceipt-ContractAddress 'In3.Eth1.TransactionReceipt.ContractAddress') + - [From](#P-In3-Eth1-TransactionReceipt-From 'In3.Eth1.TransactionReceipt.From') + - [GasUsed](#P-In3-Eth1-TransactionReceipt-GasUsed 'In3.Eth1.TransactionReceipt.GasUsed') + - [Logs](#P-In3-Eth1-TransactionReceipt-Logs 'In3.Eth1.TransactionReceipt.Logs') + - [LogsBloom](#P-In3-Eth1-TransactionReceipt-LogsBloom 'In3.Eth1.TransactionReceipt.LogsBloom') + - [Root](#P-In3-Eth1-TransactionReceipt-Root 'In3.Eth1.TransactionReceipt.Root') + - [Status](#P-In3-Eth1-TransactionReceipt-Status 'In3.Eth1.TransactionReceipt.Status') + - [To](#P-In3-Eth1-TransactionReceipt-To 'In3.Eth1.TransactionReceipt.To') + - [TransactionHash](#P-In3-Eth1-TransactionReceipt-TransactionHash 'In3.Eth1.TransactionReceipt.TransactionHash') + - [TransactionIndex](#P-In3-Eth1-TransactionReceipt-TransactionIndex 'In3.Eth1.TransactionReceipt.TransactionIndex') +- [TransactionRequest](#T-In3-Eth1-TransactionRequest 'In3.Eth1.TransactionRequest') + - [Data](#P-In3-Eth1-TransactionRequest-Data 'In3.Eth1.TransactionRequest.Data') + - [From](#P-In3-Eth1-TransactionRequest-From 'In3.Eth1.TransactionRequest.From') + - [Function](#P-In3-Eth1-TransactionRequest-Function 'In3.Eth1.TransactionRequest.Function') + - [Gas](#P-In3-Eth1-TransactionRequest-Gas 'In3.Eth1.TransactionRequest.Gas') + - [GasPrice](#P-In3-Eth1-TransactionRequest-GasPrice 'In3.Eth1.TransactionRequest.GasPrice') + - [Nonce](#P-In3-Eth1-TransactionRequest-Nonce 'In3.Eth1.TransactionRequest.Nonce') + - [Params](#P-In3-Eth1-TransactionRequest-Params 'In3.Eth1.TransactionRequest.Params') + - [To](#P-In3-Eth1-TransactionRequest-To 'In3.Eth1.TransactionRequest.To') + - [Value](#P-In3-Eth1-TransactionRequest-Value 'In3.Eth1.TransactionRequest.Value') +- [Transport](#T-In3-Transport-Transport 'In3.Transport.Transport') + - [Handle(url,payload)](#M-In3-Transport-Transport-Handle-System-String,System-String- 'In3.Transport.Transport.Handle(System.String,System.String)') + + +### Account `type` + + + +In3.Crypto + + + +Composite entity that holds address and public key. It represents and Ethereum acount. Entity returned from [EcRecover](#M-In3-Crypto-Api-EcRecover-System-String,System-String,In3-Crypto-SignatureType- 'In3.Crypto.Api.EcRecover(System.String,System.String,In3.Crypto.SignatureType)'). + + +#### Address `property` + + + +The address. + + +#### PublicKey `property` + + + +The public key. + + +### Api `type` + + + +In3.Btc + + + +API for handling BitCoin data. Use it when connected to [Btc](#F-In3-Chain-Btc 'In3.Chain.Btc'). + + +### Api `type` + + + +In3.Crypto + + + +Class that exposes utility methods for cryptographic utilities. Relies on [IN3](#T-In3-IN3 'In3.IN3') functionality. + + +### Api `type` + + + +In3.Eth1 + + + +Module based on Ethereum's api and web3. Works as a general parent for all Ethereum-specific operations. + + +### Api `type` + + + +In3.Ipfs + + + +API for ipfs realted methods. To be used along with [Ipfs](#F-In3-Chain-Ipfs 'In3.Chain.Ipfs') on [IN3](#T-In3-IN3 'In3.IN3'). Ipfs stands for and is a peer-to-peer hypermedia protocol designed to make the web faster, safer, and more open. + + +#### GetBlockBytes(blockHash) `method` + + + +Retrieves the serialized block in bytes. + +###### Returns + +The bytes of the block. + +###### Parameters + + + +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **blockHash** - The hash of the Block. + +###### Example + +``` +byte[] blockBytes = in3.Btc.GetBlockBytes("000000000000000000064ba7512ecc70cabd7ed17e31c06f2205d5ecdadd6d22"); +``` + + +#### GetBlockHeader(blockHash) `method` + + + +Retrieves the blockheader. + +###### Returns + +The Block header. + +###### Parameters + + + +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **blockHash** - The hash of the Block. + +###### Example + +``` +BlockHeader header = in3.Btc.GetBlockHeader("0000000000000000000cd3c5d7638014e78a5fba33be5fa5cb10ef9f03d99e60"); +``` + + +#### GetBlockHeaderBytes(blockHash) `method` + + + +Retrieves the byte array representing teh serialized blockheader data. + +###### Returns + +The Block header in bytes. + +###### Parameters + + + +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **blockHash** - The hash of the Block. + +###### Example + +``` +byte[] header = in3.Btc.GetBlockHeaderBytes("0000000000000000000cd3c5d7638014e78a5fba33be5fa5cb10ef9f03d99e60"); +``` + + +#### GetBlockWithTxData(blockHash) `method` + + + +Retrieves the block including the full transaction data. Use [GetBlockWithTxIds](#M-In3-Btc-Api-GetBlockWithTxIds-System-String- 'In3.Btc.Api.GetBlockWithTxIds(System.String)') for only the transaction ids. + +###### Returns + +The block of type [Block\`1](#T-In3-Btc-Block`1 'In3.Btc.Block`1'). + +###### Parameters + + + +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **blockHash** - The hash of the Block. + +###### Example + +``` +Block{Transaction} block = in3.Btc.GetBlockWithTxData("000000000000000000064ba7512ecc70cabd7ed17e31c06f2205d5ecdadd6d22"); +Transaction t1 = block.Tx[0]; +``` + + +#### GetBlockWithTxIds(blockHash) `method` + + + +Retrieves the block including only transaction ids. Use [GetBlockWithTxData](#M-In3-Btc-Api-GetBlockWithTxData-System-String- 'In3.Btc.Api.GetBlockWithTxData(System.String)') for the full transaction data. + +###### Returns + +The block of type [Block\`1](#T-In3-Btc-Block`1 'In3.Btc.Block`1'). + +###### Parameters + + + +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **blockHash** - The hash of the Block. + +###### Example + +``` +Block{string} block = in3.Btc.GetBlockWithTxIds("000000000000000000064ba7512ecc70cabd7ed17e31c06f2205d5ecdadd6d22"); +string t1 = block.Tx[0]; +``` + + +#### GetTransaction(txid) `method` + + + +Retrieves the transaction and returns the data as json. + +###### Returns + +The transaction object. + +###### Parameters + + + +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **txid** - The transaction Id. + +###### Example + +``` +Transaction desiredTransaction = in3.Btc.GetTransaction("1427c7d1698e61afe061950226f1c149990b8c1e1b157320b0c4acf7d6b5605d"); +``` + + +#### GetTransactionBytes(txid) `method` + + + +Retrieves the serialized transaction (bytes). + +###### Returns + +The byte array for the Transaction. + +###### Parameters + + + +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **txid** - The transaction Id. + +###### Example + +``` +byte[] serializedTransaction = in3.Btc.GetTransactionBytes("1427c7d1698e61afe061950226f1c149990b8c1e1b157320b0c4acf7d6b5605d"); +``` + + +#### DecryptKey(pk,passphrase) `method` + + + +Decryot an encrypted private key. + +###### Returns + +Decrypted key. + +###### Parameters + + + +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **pk** - Private key. +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **passphrase** - Passphrase whose `pk`. + + +#### EcRecover(signedData,signature,signatureType) `method` + + + +Recovers the account associated with the signed data. + +###### Returns + +The account. + +###### Parameters + + + +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **signedData** - Data that was signed with. +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **signature** - The signature. +- [In3.Crypto.SignatureType](#T-In3-Crypto-SignatureType 'In3.Crypto.SignatureType') **signatureType** - One of [SignatureType](#T-In3-Crypto-SignatureType 'In3.Crypto.SignatureType'). + + +#### Pk2Address(pk) `method` + + + +Derives an address from the given private (`pk`) key using SHA-3 algorithm. + +###### Returns + +The address. + +###### Parameters + + + +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **pk** - Private key. + + +#### Pk2Public(pk) `method` + + + +Derives public key from the given private (`pk`) key using SHA-3 algorithm. + +###### Returns + +The public key. + +###### Parameters + + + +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **pk** - Private key. + + +#### Sha3(data) `method` + + + +Hash the input data using sha3 algorithm. + +###### Returns + +Hashed output. + +###### Parameters + + + +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **data** - Content to be hashed. + + +#### SignData(msg,pk,sigType) `method` + + + +Signs the data `msg` with a given private key. Refer to [SignedData](#T-In3-Crypto-SignedData 'In3.Crypto.SignedData') for more information. + +###### Returns + +The signed data. + +###### Parameters + + + +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **msg** - Data to be signed. +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **pk** - Private key. +- [In3.Crypto.SignatureType](#T-In3-Crypto-SignatureType 'In3.Crypto.SignatureType') **sigType** - Type of signature, one of [SignatureType](#T-In3-Crypto-SignatureType 'In3.Crypto.SignatureType'). + + +#### AbiDecode(signature,encodedData) `method` + + + +ABI decoder. Used to parse rpc responses from the EVM. +Based on the Solidity specification . + +###### Returns + +The decoded argugments for the function call given the encded data. + +###### Parameters + + + +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **signature** - Function signature i.e. or . In case of the latter, the function signature will be ignored and only the return types will be parsed. +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **encodedData** - Abi encoded values. Usually the string returned from a rpc to the EVM. + + +#### AbiEncode(signature,args) `method` + + + +ABI encoder. Used to serialize a rpc to the EVM. +Based on the Solidity specification . +Note: Parameters refers to the list of variables in a method declaration. +Arguments are the actual values that are passed in when the method is invoked. +When you invoke a method, the arguments used must match the declaration's parameters in type and order. + +###### Returns + +The encoded data. + +###### Parameters + + + +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **signature** - Function signature, with parameters. i.e. , can contain the return types but will be ignored. +- [System.Object[]](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Object[] 'System.Object[]') **args** - Function parameters, in the same order as in passed on to . + + +#### BlockNumber() `method` + + + +Returns the number of the most recent block the in3 network can collect signatures to verify. +Can be changed by [ReplaceLatestBlock](#P-In3-Configuration-ClientConfiguration-ReplaceLatestBlock 'In3.Configuration.ClientConfiguration.ReplaceLatestBlock'). +If you need the very latest block, change [SignatureCount](#P-In3-Configuration-ClientConfiguration-SignatureCount 'In3.Configuration.ClientConfiguration.SignatureCount') to `0`. + +###### Returns + +The number of the block. + +###### Parameters + +This method has no parameters. + + +#### Call(request,blockNumber) `method` + + + +Calls a smart-contract method. Will be executed locally by Incubed's EVM or signed and sent over to save the state changes. +Check https://ethereum.stackexchange.com/questions/3514/how-to-call-a-contract-method-using-the-eth-call-json-rpc-api for more. + +###### Returns + +Ddecoded result. If only one return value is expected the Object will be returned, if not an array of objects will be the result. + +###### Parameters + + + +- [In3.Eth1.TransactionRequest](#T-In3-Eth1-TransactionRequest 'In3.Eth1.TransactionRequest') **request** - The transaction request to be processed. +- [System.Numerics.BigInteger](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Numerics.BigInteger 'System.Numerics.BigInteger') **blockNumber** - Block number or [Latest](#P-In3-BlockParameter-Latest 'In3.BlockParameter.Latest') or [Earliest](#P-In3-BlockParameter-Earliest 'In3.BlockParameter.Earliest'). + + +#### ChecksumAddress(address,shouldUseChainId) `method` + + + +Will convert an upper or lowercase Ethereum `address` to a checksum address, that uses case to encode values. +See [EIP55](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-55.md). + +###### Returns + +EIP-55 compliant, mixed-case address. + +###### Parameters + + + +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **address** - Ethereum address. +- [System.Nullable{System.Boolean}](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Nullable 'System.Nullable{System.Boolean}') **shouldUseChainId** - If `true`, the chain id is integrated as well. Default being `false`. + + +#### Ens(name,type) `method` + + + +Resolves ENS domain name. + +###### Returns + +The resolved entity for the domain. + +###### Parameters + + + +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **name** - ENS domain name. +- [In3.ENSParameter](#T-In3-ENSParameter 'In3.ENSParameter') **type** - One of [ENSParameter](#T-In3-ENSParameter 'In3.ENSParameter'). + +###### Remarks + +The actual semantics of the returning value changes according to `type`. + + +#### EstimateGas(request,blockNumber) `method` + + + +Gas estimation for transaction. Used to fill transaction.gas field. Check RawTransaction docs for more on gas. + +###### Returns + +Estimated gas in Wei. + +###### Parameters + + + +- [In3.Eth1.TransactionRequest](#T-In3-Eth1-TransactionRequest 'In3.Eth1.TransactionRequest') **request** - The transaction request whose cost will be estimated. +- [System.Numerics.BigInteger](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Numerics.BigInteger 'System.Numerics.BigInteger') **blockNumber** - Block number or [Latest](#P-In3-BlockParameter-Latest 'In3.BlockParameter.Latest') or [Earliest](#P-In3-BlockParameter-Earliest 'In3.BlockParameter.Earliest'). + + +#### GetBalance(address,blockNumber) `method` + + + +Returns the balance of the account of given `address`. + +###### Returns + +The current balance in wei. + +###### Parameters + + + +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **address** - Address to check for balance. +- [System.Numerics.BigInteger](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Numerics.BigInteger 'System.Numerics.BigInteger') **blockNumber** - Block number or [Latest](#P-In3-BlockParameter-Latest 'In3.BlockParameter.Latest') or [Earliest](#P-In3-BlockParameter-Earliest 'In3.BlockParameter.Earliest'). + + +#### GetBlockByHash(blockHash,shouldIncludeTransactions) `method` + + + +Blocks can be identified by root hash of the block merkle tree (this), or sequential number in which it was mined [GetBlockByNumber](#M-In3-Eth1-Api-GetBlockByNumber-System-Numerics-BigInteger,System-Boolean- 'In3.Eth1.Api.GetBlockByNumber(System.Numerics.BigInteger,System.Boolean)'). + +###### Returns + +The [Block](#T-In3-Eth1-Block 'In3.Eth1.Block') of the requested (if exists). + +###### Parameters + + + +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **blockHash** - Desired block hash. +- [System.Boolean](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Boolean 'System.Boolean') **shouldIncludeTransactions** - If true, returns the full transaction objects, otherwise only its hashes. The default value is `false`. + +###### Remarks + +Returning [Block](#T-In3-Eth1-Block 'In3.Eth1.Block') must be cast to [TransactionBlock](#T-In3-Eth1-TransactionBlock 'In3.Eth1.TransactionBlock') or [TransactionHashBlock](#T-In3-Eth1-TransactionHashBlock 'In3.Eth1.TransactionHashBlock') to access the transaction data. + + +#### GetBlockByNumber(blockNumber,shouldIncludeTransactions) `method` + + + +Blocks can be identified by sequential number in which it was mined, or root hash of the block merkle tree [GetBlockByHash](#M-In3-Eth1-Api-GetBlockByHash-System-String,System-Boolean- 'In3.Eth1.Api.GetBlockByHash(System.String,System.Boolean)'). + +###### Returns + +The [Block](#T-In3-Eth1-Block 'In3.Eth1.Block') of the requested (if exists). + +###### Parameters + + + +- [System.Numerics.BigInteger](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Numerics.BigInteger 'System.Numerics.BigInteger') **blockNumber** - Desired block number or [Latest](#P-In3-BlockParameter-Latest 'In3.BlockParameter.Latest') or [Earliest](#P-In3-BlockParameter-Earliest 'In3.BlockParameter.Earliest'). +- [System.Boolean](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Boolean 'System.Boolean') **shouldIncludeTransactions** - If `true`, returns the full transaction objects, otherwise only its hashes. The default value is `true`. + +###### Example + +``` +TransactionBlock latest = (TransactionBlock) _client.Eth1.GetBlockByNumber(BlockParameter.Latest, true); +TransactionHashBlock earliest = (TransactionHashBlock) _client.Eth1.GetBlockByNumber(BlockParameter.Earliest, false); +``` + +###### Remarks + +Returning [Block](#T-In3-Eth1-Block 'In3.Eth1.Block') must be cast to [TransactionBlock](#T-In3-Eth1-TransactionBlock 'In3.Eth1.TransactionBlock') or [TransactionHashBlock](#T-In3-Eth1-TransactionHashBlock 'In3.Eth1.TransactionHashBlock') to access the transaction data. + + +#### GetBlockTransactionCountByHash(blockHash) `method` + + + +The total transactions on a block. See also [GetBlockTransactionCountByNumber](#M-In3-Eth1-Api-GetBlockTransactionCountByNumber-System-Numerics-BigInteger- 'In3.Eth1.Api.GetBlockTransactionCountByNumber(System.Numerics.BigInteger)'). + +###### Returns + +The number (count) of [Transaction](#T-In3-Eth1-Transaction 'In3.Eth1.Transaction'). + +###### Parameters + + + +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **blockHash** - Desired block hash. + + +#### GetBlockTransactionCountByNumber(blockNumber) `method` + + + +The total transactions on a block. See also [GetBlockTransactionCountByHash](#M-In3-Eth1-Api-GetBlockTransactionCountByHash-System-String- 'In3.Eth1.Api.GetBlockTransactionCountByHash(System.String)'). + +###### Returns + +The number (count) of [Transaction](#T-In3-Eth1-Transaction 'In3.Eth1.Transaction'). + +###### Parameters + + + +- [System.Numerics.BigInteger](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Numerics.BigInteger 'System.Numerics.BigInteger') **blockNumber** - Block number or [Latest](#P-In3-BlockParameter-Latest 'In3.BlockParameter.Latest') or [Earliest](#P-In3-BlockParameter-Earliest 'In3.BlockParameter.Earliest'). + + +#### GetChainId() `method` + + + +Get the [Chain](#T-In3-Chain 'In3.Chain') which the client is currently connected to. + +###### Returns + +The [Chain](#T-In3-Chain 'In3.Chain'). + +###### Parameters + +This method has no parameters. + + +#### GetCode(address,blockNumber) `method` + + + +Smart-Contract bytecode in hexadecimal. If the account is a simple wallet the function will return '0x'. + +###### Returns + +Smart-Contract bytecode in hexadecimal. + +###### Parameters + + + +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **address** - Ethereum address. +- [System.Numerics.BigInteger](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Numerics.BigInteger 'System.Numerics.BigInteger') **blockNumber** - Block number or [Latest](#P-In3-BlockParameter-Latest 'In3.BlockParameter.Latest') or [Earliest](#P-In3-BlockParameter-Earliest 'In3.BlockParameter.Earliest'). + + +#### GetFilterChangesFromLogs(filterId) `method` + + + +Retrieve the logs for a certain filter. Logs marks changes of state on the chan for events. Equivalent to [GetFilterLogs](#M-In3-Eth1-Api-GetFilterLogs-System-Int64- 'In3.Eth1.Api.GetFilterLogs(System.Int64)'). + +###### Returns + +Array of logs which occurred since last poll. + +###### Parameters + + + +- [System.Int64](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Int64 'System.Int64') **filterId** - Id returned during the filter creation. + +###### Remarks + +Since the return is the since last poll, executing this multiple times changes the state making this a "non-idempotent" getter. + + +#### GetFilterLogs(filterId) `method` + + + +Retrieve the logs for a certain filter. Logs marks changes of state on the blockchain for events. Equivalent to [GetFilterChangesFromLogs](#M-In3-Eth1-Api-GetFilterChangesFromLogs-System-Int64- 'In3.Eth1.Api.GetFilterChangesFromLogs(System.Int64)'). + +###### Returns + +Array of logs which occurred since last poll. + +###### Parameters + + + +- [System.Int64](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Int64 'System.Int64') **filterId** - Id returned during the filter creation. + +###### Remarks + +Since the return is the `Log[]` since last poll, executing this multiple times changes the state making this a "non-idempotent" getter. + + +#### GetGasPrice() `method` + + + +The current gas price in Wei (1 ETH equals 1000000000000000000 Wei ). + +###### Returns + +The gas price. + +###### Parameters + +This method has no parameters. + + +#### GetLogs(filter) `method` + + + +Retrieve the logs for a certain filter. Logs marks changes of state on the blockchain for events. Unlike [GetFilterChangesFromLogs](#M-In3-Eth1-Api-GetFilterChangesFromLogs-System-Int64- 'In3.Eth1.Api.GetFilterChangesFromLogs(System.Int64)') or [GetFilterLogs](#M-In3-Eth1-Api-GetFilterLogs-System-Int64- 'In3.Eth1.Api.GetFilterLogs(System.Int64)') this is made to be used in a non-incremental manner (aka no poll) and will return the Logs that satisfy the filter condition. + +###### Returns + +Logs that satisfy the `filter`. + +###### Parameters + + + +- [In3.Eth1.LogFilter](#T-In3-Eth1-LogFilter 'In3.Eth1.LogFilter') **filter** - Filter conditions. + + +#### GetStorageAt(address,position,blockNumber) `method` + + + +Stored value in designed position at a given `address`. Storage can be used to store a smart contract state, constructor or just any data. +Each contract consists of a EVM bytecode handling the execution and a storage to save the state of the contract. + +###### Returns + +Stored value in designed position. + +###### Parameters + + + +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **address** - Ethereum account address. +- [System.Numerics.BigInteger](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Numerics.BigInteger 'System.Numerics.BigInteger') **position** - Position index, 0x0 up to 100. +- [System.Numerics.BigInteger](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Numerics.BigInteger 'System.Numerics.BigInteger') **blockNumber** - Block number or [Latest](#P-In3-BlockParameter-Latest 'In3.BlockParameter.Latest') or [Earliest](#P-In3-BlockParameter-Earliest 'In3.BlockParameter.Earliest'). + + +#### GetTransactionByBlockHashAndIndex(blockHash,index) `method` + + + +Transactions can be identified by root hash of the transaction merkle tree (this) or by its position in the block transactions merkle tree. +Every transaction hash is unique for the whole chain. Collision could in theory happen, chances are 67148E-63%. +See also [GetTransactionByBlockNumberAndIndex](#M-In3-Eth1-Api-GetTransactionByBlockNumberAndIndex-System-Numerics-BigInteger,System-Int32- 'In3.Eth1.Api.GetTransactionByBlockNumberAndIndex(System.Numerics.BigInteger,System.Int32)'). + +###### Returns + +The [Transaction](#T-In3-Eth1-Transaction 'In3.Eth1.Transaction') (if it exists). + +###### Parameters + + + +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **blockHash** - Desired block hash. +- [System.Int32](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Int32 'System.Int32') **index** - The index of the [Transaction](#T-In3-Eth1-Transaction 'In3.Eth1.Transaction') in a [Block](#T-In3-Eth1-Block 'In3.Eth1.Block') + + +#### GetTransactionByBlockNumberAndIndex(blockNumber,index) `method` + + + +Transactions can be identified by root hash of the transaction merkle tree (this) or by its position in the block transactions merkle tree. +Every transaction hash is unique for the whole chain. Collision could in theory happen, chances are 67148E-63%. + +###### Returns + +The [Transaction](#T-In3-Eth1-Transaction 'In3.Eth1.Transaction') (if it exists). + +###### Parameters + + + +- [System.Numerics.BigInteger](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Numerics.BigInteger 'System.Numerics.BigInteger') **blockNumber** - Block number or [Latest](#P-In3-BlockParameter-Latest 'In3.BlockParameter.Latest') or [Earliest](#P-In3-BlockParameter-Earliest 'In3.BlockParameter.Earliest'). +- [System.Int32](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Int32 'System.Int32') **index** - The index of the [Transaction](#T-In3-Eth1-Transaction 'In3.Eth1.Transaction') in a [Block](#T-In3-Eth1-Block 'In3.Eth1.Block') + + +#### GetTransactionByHash(transactionHash) `method` + + + +Transactions can be identified by root hash of the transaction merkle tree (this) or by its position in the block transactions merkle tree. +Every transaction hash is unique for the whole chain. Collision could in theory happen, chances are 67148E-63%. + +###### Returns + +The [Transaction](#T-In3-Eth1-Transaction 'In3.Eth1.Transaction') (if it exists). + +###### Parameters + + + +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **transactionHash** - Desired transaction hash. + + +#### GetTransactionCount(address,blockNumber) `method` + + + +Number of transactions mined from this `address`. Used to set transaction nonce. +Nonce is a value that will make a transaction fail in case it is different from (transaction count + 1). +It exists to mitigate replay attacks. + +###### Returns + +Number of transactions mined from this address. + +###### Parameters + + + +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **address** - Ethereum account address. +- [System.Numerics.BigInteger](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Numerics.BigInteger 'System.Numerics.BigInteger') **blockNumber** - Block number or [Latest](#P-In3-BlockParameter-Latest 'In3.BlockParameter.Latest') or [Earliest](#P-In3-BlockParameter-Earliest 'In3.BlockParameter.Earliest'). + + +#### GetTransactionReceipt(transactionHash) `method` + + + +After a transaction is received the by the client, it returns the transaction hash. With it, it is possible to gather the receipt, once a miner has mined and it is part of an acknowledged block. Because how it is possible, in distributed systems, that data is asymmetric in different parts of the system, the transaction is only "final" once a certain number of blocks was mined after it, and still it can be possible that the transaction is discarded after some time. But, in general terms, it is accepted that after 6 to 8 blocks from latest, that it is very likely that the transaction will stay in the chain. + +###### Returns + +The mined transaction data including event logs. + +###### Parameters + + + +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **transactionHash** - Desired transaction hash. + + +#### GetUncleByBlockNumberAndIndex(blockNumber,position) `method` + + + +Retrieve the of uncle of a block for the given `blockNumber` and a position. Uncle blocks are valid blocks and are mined in a genuine manner, but get rejected from the main blockchain. + +###### Returns + +The uncle block. + +###### Parameters + + + +- [System.Numerics.BigInteger](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Numerics.BigInteger 'System.Numerics.BigInteger') **blockNumber** - Block number or [Latest](#P-In3-BlockParameter-Latest 'In3.BlockParameter.Latest') or [Earliest](#P-In3-BlockParameter-Earliest 'In3.BlockParameter.Earliest'). +- [System.Int32](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Int32 'System.Int32') **position** - Position of the block. + + +#### GetUncleCountByBlockHash(blockHash) `method` + + + +Retrieve the total of uncles of a block for the given `blockHash`. Uncle blocks are valid blocks and are mined in a genuine manner, but get rejected from the main blockchain. +See [GetUncleCountByBlockNumber](#M-In3-Eth1-Api-GetUncleCountByBlockNumber-System-Numerics-BigInteger- 'In3.Eth1.Api.GetUncleCountByBlockNumber(System.Numerics.BigInteger)'). + +###### Returns + +The number of uncles in a block. + +###### Parameters + + + +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **blockHash** - Desired block hash. + + +#### GetUncleCountByBlockNumber(blockNumber) `method` + + + +Retrieve the total of uncles of a block for the given `blockNumber`. Uncle blocks are valid and are mined in a genuine manner, but get rejected from the main blockchain. +See [GetUncleCountByBlockHash](#M-In3-Eth1-Api-GetUncleCountByBlockHash-System-String- 'In3.Eth1.Api.GetUncleCountByBlockHash(System.String)'). + +###### Returns + +The number of uncles in a block. + +###### Parameters + + + +- [System.Numerics.BigInteger](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Numerics.BigInteger 'System.Numerics.BigInteger') **blockNumber** - Block number or [Latest](#P-In3-BlockParameter-Latest 'In3.BlockParameter.Latest') or [Earliest](#P-In3-BlockParameter-Earliest 'In3.BlockParameter.Earliest'). + + +#### NewBlockFilter() `method` + + + +Creates a filter in the node, to notify when a new block arrives. To check if the state has changed, call [GetFilterChangesFromLogs](#M-In3-Eth1-Api-GetFilterChangesFromLogs-System-Int64- 'In3.Eth1.Api.GetFilterChangesFromLogs(System.Int64)'). +Filters are event catchers running on the Ethereum Client. Incubed has a client-side implementation. +An event will be stored in case it is within to and from blocks, or in the block of blockhash, contains a +transaction to the designed address, and has a word listed on topics. + +###### Returns + +The filter id. + +###### Parameters + +This method has no parameters. + +###### Remarks + +Use the returned filter id to perform other filter operations. + + +#### NewLogFilter(filter) `method` + + + +Creates a filter object, based on filter options, to notify when the state changes (logs). To check if the state has changed, call [GetFilterChangesFromLogs](#M-In3-Eth1-Api-GetFilterChangesFromLogs-System-Int64- 'In3.Eth1.Api.GetFilterChangesFromLogs(System.Int64)'). +Filters are event catchers running on the Ethereum Client. Incubed has a client-side implementation. +An event will be stored in case it is within to and from blocks, or in the block of blockhash, contains a +transaction to the designed address, and has a word listed on topics. + +###### Returns + +The filter id. + +###### Parameters + + + +- [In3.Eth1.LogFilter](#T-In3-Eth1-LogFilter 'In3.Eth1.LogFilter') **filter** - Model that holds the data for the filter creation. + +###### Remarks + +Use the returned filter id to perform other filter operations. + + +#### SendRawTransaction(transactionData) `method` + + + +Sends a signed and encoded transaction. + +###### Returns + +Transaction hash, used to get the receipt and check if the transaction was mined. + +###### Parameters + + + +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **transactionData** - Signed keccak hash of the serialized transaction. + +###### Remarks + +Client will add the other required fields, gas and chaind id. + + +#### SendTransaction(tx) `method` + + + +Signs and sends the assigned transaction. The [Signer](#T-In3-Crypto-Signer 'In3.Crypto.Signer') used to sign the transaction is the one set by [Signer](#P-In3-IN3-Signer 'In3.IN3.Signer'). +Transactions change the state of an account, just the balance, or additionally, the storage and the code. +Every transaction has a cost, gas, paid in Wei. The transaction gas is calculated over estimated gas times the gas cost, plus an additional miner fee, if the sender wants to be sure that the transaction will be mined in the latest block. +See [SendTransactionAndWait](#M-In3-Eth1-Api-SendTransactionAndWait-In3-Eth1-TransactionRequest- 'In3.Eth1.Api.SendTransactionAndWait(In3.Eth1.TransactionRequest)') to wait for the [TransactionReceipt](#T-In3-Eth1-TransactionReceipt 'In3.Eth1.TransactionReceipt') in the same call. + +###### Returns + +Transaction hash, used to get the receipt and check if the transaction was mined. + +###### Parameters + + + +- [In3.Eth1.TransactionRequest](#T-In3-Eth1-TransactionRequest 'In3.Eth1.TransactionRequest') **tx** - All information needed to perform a transaction. + +###### Example + +``` + SimpleWallet wallet = (SimpleWallet) client.Signer; + TransactionRequest tx = new TransactionRequest(); + tx.From = wallet.AddRawKey(pk);; + tx.To = "0x3940256B93c4BE0B1d5931A6A036608c25706B0c"; + tx.Gas = 21000; + tx.Value = 100000000; + client.Eth1.SendTransaction(tx); +``` + + +#### SendTransactionAndWait(tx) `method` + + + +Signs and sends the assigned transaction. The [Signer](#T-In3-Crypto-Signer 'In3.Crypto.Signer') used to sign the transaction is the one set by [Signer](#P-In3-IN3-Signer 'In3.IN3.Signer'). +Transactions change the state of an account, just the balance, or additionally, the storage and the code. +Every transaction has a cost, gas, paid in Wei. The transaction gas is calculated over estimated gas times the gas cost, plus an additional miner fee, if the sender wants to be sure that the transaction will be mined in the latest block. +In this particular case, the transaction will wait the receipt. See [SendTransaction](#M-In3-Eth1-Api-SendTransaction-In3-Eth1-TransactionRequest- 'In3.Eth1.Api.SendTransaction(In3.Eth1.TransactionRequest)') if that is not desirable. + +###### Returns + +The receipt associated with the performed transaction. + +###### Parameters + + + +- [In3.Eth1.TransactionRequest](#T-In3-Eth1-TransactionRequest 'In3.Eth1.TransactionRequest') **tx** - All information needed to perform a transaction. + +###### Example + +``` + SimpleWallet wallet = (SimpleWallet) client.Signer; + TransactionRequest tx = new TransactionRequest(); + tx.From = wallet.AddRawKey(pk);; + tx.To = "0x3940256B93c4BE0B1d5931A6A036608c25706B0c"; + tx.Gas = 21000; + tx.Value = 100000000; + client.Eth1.SendTransactionAndWait(tx); +``` + + +#### UninstallFilter(filterId) `method` + + + +Uninstalls a previously created filter. + +###### Returns + +The result of the operation, `true` on success or `false` on failure. + +###### Parameters + + + +- [System.Int64](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Int64 'System.Int64') **filterId** - The filter id returned by [NewBlockFilter](#M-In3-Eth1-Api-NewBlockFilter 'In3.Eth1.Api.NewBlockFilter'). + + +#### Get(multihash) `method` + + + +Returns the content associated with specified multihash on success OR on error. + +###### Returns + +The content that was stored by [Put](#M-In3-Ipfs-Api-Put-System-Byte[]- 'In3.Ipfs.Api.Put(System.Byte[])') or [Put](#M-In3-Ipfs-Api-Put-System-String- 'In3.Ipfs.Api.Put(System.String)'). + +###### Parameters + + + +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **multihash** - The multihash. + + +#### Put(content) `method` + + + +Stores content on ipfs. + +###### Returns + +The multihash. + +###### Parameters + + + +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **content** - The content that will be stored via ipfs. + + +#### Put(content) `method` + + + +Stores content on ipfs. The content is encoded as base64 before storing. + +###### Returns + +The multihash. + +###### Parameters + + + +- [System.Byte[]](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Byte[] 'System.Byte[]') **content** - The content that will be stored via ipfs. + + +### BaseConfiguration `type` + + + +In3.Configuration + + + +Base class for all configuration classes. + + +### Block `type` + + + +In3.Eth1 + + + +Class that represents as Ethereum block. + + +#### Author `property` + + + +The miner of the block. + + +#### Difficulty `property` + + + +Dificulty of the block. + + +#### ExtraData `property` + + + +Extra data. + + +#### GasLimit `property` + + + +Gas limit. + + +#### Hash `property` + + + +The block hash. + + +#### LogsBloom `property` + + + +The logsBloom data of the block. + + +#### MixHash `property` + + + +The mix hash of the block. (only valid of proof of work). + + +#### Nonce `property` + + + +The nonce. + + +#### Number `property` + + + +The index of the block. + + +#### ParentHash `property` + + + +The parent block\`s hash. + + +#### ReceiptsRoot `property` + + + +The roothash of the merkletree containing all transaction receipts of the block. + + +#### Sha3Uncles `property` + + + +The roothash of the merkletree containing all uncles of the block. + + +#### Size `property` + + + +Size of the block. + + +#### StateRoot `property` + + + +The roothash of the merkletree containing the complete state. + + +#### Timestamp `property` + + + +Epoch timestamp when the block was created. + + +#### TotalDifficulty `property` + + + +Total Difficulty as a sum of all difficulties starting from genesis. + + +#### TransactionsRoot `property` + + + +The roothash of the merkletree containing all transaction of the block. + + +#### Uncles `property` + + + +List of uncle hashes. + + +### BlockHeader `type` + + + +In3.Btc + + + +A Block header. + + +#### Bits `property` + + + +Bits (target) for the block as hex. + + +#### Chainwork `property` + + + +Total amount of work since genesis. + + +#### Confirmations `property` + + + +Number of confirmations or blocks mined on top of the containing block. + + +#### Difficulty `property` + + + +Difficulty of the block. + + +#### Hash `property` + + + +The hash of the blockheader. + + +#### Height `property` + + + +Block number. + + +#### Mediantime `property` + + + +Unix timestamp in seconds since 1970. + + +#### Merkleroot `property` + + + +Merkle root of the trie of all transactions in the block. + + +#### NTx `property` + + + +Number of transactions in the block. + + +#### Nextblockhash `property` + + + +Hash of the next blockheader. + + +#### Nonce `property` + + + +Nonce-field of the block. + + +#### Previousblockhash `property` + + + +Hash of the parent blockheader. + + +#### Time `property` + + + +Unix timestamp in seconds since 1970. + + +#### Version `property` + + + +Used version. + + +#### VersionHex `property` + + + +Version as hex. + + +### BlockParameter `type` + + + +In3 + + + +Enum-like class that defines constants to be used with [Api](#T-In3-Eth1-Api 'In3.Eth1.Api'). + + +#### Earliest `property` + + + +Genesis block. + + +#### Latest `property` + + + +Constant associated with the latest mined block in the chain. + +###### Remarks + +While the parameter itself is constant the current "latest" block changes everytime a new block is mined. The result of the operations are also related to `ReplaceLatestBlock` on [ClientConfiguration](#T-In3-Configuration-ClientConfiguration 'In3.Configuration.ClientConfiguration'). + + +### Block\`1 `type` + + + +In3.Btc + + + +A Block. + + +#### Size `property` + + + +Size of this block in bytes. + + +#### Tx `property` + + + +Transactions or Transaction ids of a block. [GetBlockWithTxData](#M-In3-Btc-Api-GetBlockWithTxData-System-String- 'In3.Btc.Api.GetBlockWithTxData(System.String)') or [GetBlockWithTxIds](#M-In3-Btc-Api-GetBlockWithTxIds-System-String- 'In3.Btc.Api.GetBlockWithTxIds(System.String)'). + + +#### Weight `property` + + + +Weight of this block in bytes. + + +### Chain `type` + + + +In3 + + + +Represents the multiple chains supported by Incubed. + + +#### Btc `constants` + + + +Bitcoin chain. + + +#### Evan `constants` + + + +Evan testnet. + + +#### Ewc `constants` + + + +Ewf chain. + + +#### Goerli `constants` + + + +Goerli testnet. + + +#### Ipfs `constants` + + + +Ipfs (InterPlanetary File System). + + +#### Local `constants` + + + +Local client. + + +#### Mainnet `constants` + + + +Ethereum mainnet. + + +#### Multichain `constants` + + + +Support for multiple chains, a client can then switch between different chains (but consumes more memory). + + +#### Tobalaba `constants` + + + +Tobalaba testnet. + + +#### Volta `constants` + + + +Volta testnet. + + +### ChainConfiguration `type` + + + +In3.Configuration + + + +Class that represents part of the configuration to be applied on the [IN3](#T-In3-IN3 'In3.IN3') (in particular to each chain). +This is a child of [ClientConfiguration](#T-In3-Configuration-ClientConfiguration 'In3.Configuration.ClientConfiguration') and have many [NodeConfiguration](#T-In3-Configuration-NodeConfiguration 'In3.Configuration.NodeConfiguration'). + + +#### #ctor(chain,clientConfiguration) `constructor` + + + +Constructor. + +###### Parameters + + + +- [In3.Chain](#T-In3-Chain 'In3.Chain') **chain** - One of [Chain](#T-In3-Chain 'In3.Chain'). The chain that this configuration is related to. +- [In3.Configuration.ClientConfiguration](#T-In3-Configuration-ClientConfiguration 'In3.Configuration.ClientConfiguration') **clientConfiguration** - The configuration for the client whose the chain configuration belongs to. + +###### Example + +``` +ChainConfiguration goerliConfiguration = new ChainConfiguration(Chain.Goerli, in3Client.Configuration); +``` + + +#### Contract `property` + + + +Incubed registry contract from which the list was taken. + + +#### NeedsUpdate `property` + + + +Preemptively update the node list. + + +#### NodesConfiguration `property` + + + +Getter for the list of elements that represent the configuration for each node. + +###### Remarks + +This is a read-only property. To add configuration for nodes, Use [NodeConfiguration](#T-In3-Configuration-NodeConfiguration 'In3.Configuration.NodeConfiguration') constructor. + + +#### RegistryId `property` + + + +Uuid of this incubed network. one chain could contain more than one incubed networks. + + +#### WhiteList `property` + + + +Node addresses that constitute the white list of nodes. + + +#### WhiteListContract `property` + + + +Address of whiteList contract. + + +### ClientConfiguration `type` + + + +In3.Configuration + + + +Class that represents the configuration to be applied on [IN3](#T-In3-IN3 'In3.IN3'). +Due to the 1-to-1 relationship with the client, this class should never be instantiated. To obtain a reference of the client configuration use [Configuration](#P-In3-IN3-Configuration 'In3.IN3.Configuration') instead. + +###### Remarks + +Use in conjunction with [ChainConfiguration](#T-In3-Configuration-ChainConfiguration 'In3.Configuration.ChainConfiguration') and [NodeConfiguration](#T-In3-Configuration-NodeConfiguration 'In3.Configuration.NodeConfiguration'). + + +#### AutoUpdateList `property` + + + +If `true` the nodelist will be automatically updated. False may compromise data security. + + +#### BootWeights `property` + + + +if true, the first request (updating the nodelist) will also fetch the current health status + and use it for blacklisting unhealthy nodes. This is used only if no nodelist is availabkle from cache. + + +#### ChainsConfiguration `property` + + + +Configuration for the chains. Read-only attribute. + + +#### Finality `property` + +###### Remarks + +Beware that the semantics of the values change greatly from chain to chain. The value of `8` would mean 8 blocks mined on top of the requested one while with the POW algorithm while, for POA, it would mean 8% of validators. + + +#### IncludeCode `property` + + + +Code is included when sending eth_call-requests. + + +#### KeepIn3 `property` + + + +Tthe in3-section (custom node on the RPC call) with the proof will also returned. + + +#### MaxAttempts `property` + + + +Maximum times the client will retry to contact a certain node. + + +#### MinDeposit `property` + + + +Only nodes owning at least this amount will be chosen to sign responses to your requests. + + +#### NodeLimit `property` + + + +Limit nodes stored in the client. + + +#### NodeProps `property` + + + +Props define the capabilities of the nodes. Accepts a combination of values. + +###### Example + +``` +clientConfiguration.NodeProps = Props.NodePropProof | Props.NodePropArchive; +``` + + +#### Proof `property` + + + +One of [Proof](#P-In3-Configuration-ClientConfiguration-Proof 'In3.Configuration.ClientConfiguration.Proof'). [Full](#P-In3-Configuration-Proof-Full 'In3.Configuration.Proof.Full') gets the whole block Patricia-Merkle-Tree, [Standard](#P-In3-Configuration-Proof-Standard 'In3.Configuration.Proof.Standard') only verifies the specific tree branch concerning the request, [None](#P-In3-Configuration-Proof-None 'In3.Configuration.Proof.None') only verifies the root hashes, like a light-client does. + + +#### ReplaceLatestBlock `property` + + + +Distance considered safe, consensus wise, from the very latest block. Higher values exponentially increases state finality, and therefore data security, as well guaranteeded responses from in3 nodes. + + +#### RequestCount `property` + + + +Useful when [SignatureCount](#P-In3-Configuration-ClientConfiguration-SignatureCount 'In3.Configuration.ClientConfiguration.SignatureCount') is less then `1`. The client will check for consensus in responses. + + +#### Rpc `property` + + + +Setup an custom rpc source for requests by setting chain to [Local](#F-In3-Chain-Local 'In3.Chain.Local') and proof to [None](#P-In3-Configuration-Proof-None 'In3.Configuration.Proof.None'). + + +#### SignatureCount `property` + + + +Node signatures attesting the response to your request. Will send a separate request for each. + +###### Example + +When set to `3`, 3 nodes will have to sign the response. + + +#### Timeout `property` + + + +Milliseconds before a request times out. + + +#### UseHttp `property` + + + +Disable ssl on the Http connection. + + +### Context `type` + + + +In3.Context + + + +Acts as the main orchestrator for the execution of an rpc. Holds a reference to the native context (ctx) and wraps behavior around it. + + +#### #ctor(ctx,nativeClient) `constructor` + + + +Standard constructor, private so people use [FromRpc](#M-In3-Context-Context-FromRpc-In3-Native-NativeClient,System-String- 'In3.Context.Context.FromRpc(In3.Native.NativeClient,System.String)'). + +###### Parameters + + + +- [System.IntPtr](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.IntPtr 'System.IntPtr') **ctx** - The native rpc context. +- [In3.Native.NativeClient](#T-In3-Native-NativeClient 'In3.Native.NativeClient') **nativeClient** - Object that encapsulates the native client. + + +#### CreateNativeCtx(nativeIn3Ptr,rpc) `method` + + + +Method to manage the creation of the native ctx request. + +###### Returns + +Native rpc pointer + +###### Parameters + + + +- [System.IntPtr](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.IntPtr 'System.IntPtr') **nativeIn3Ptr** - Native client pointer. +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **rpc** - The rpc request + +###### Exceptions + +| Name | Description | + +| [In3.Error.ContextException](#T-In3-Error-ContextException 'In3.Error.ContextException') | | + + +#### Dispose() `method` + + + +Destructor method for the native ctx encapsulated by the [Context](#T-In3-Context-Context 'In3.Context.Context') object. + +###### Parameters + +This method has no parameters. + + +#### Execute() `method` + + + +Proxy to in3_ctx_execute, every invocation generates a new state. + +###### Returns + +The state as computed by in3_ctx_execute. + +###### Parameters + +This method has no parameters. + + +#### FromRpc(wrapper,rpc) `method` + + + +Factory-like method to build a Context object from an rpc request. + +###### Returns + +An instance of context. + +###### Parameters + + + +- [In3.Native.NativeClient](#T-In3-Native-NativeClient 'In3.Native.NativeClient') **wrapper** - The object that encapsulates the native client pointer. +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **rpc** - The rpc request + + +#### GetErrorMessage() `method` + + + +Retrieve the error result on the context. + +###### Returns + +A string describing the encountered error. + +###### Parameters + +This method has no parameters. + + +#### GetLastWaiting() `method` + + + +Method responsible to fetch the pending context references in the current context. + +###### Returns + +A context object. + +###### Parameters + +This method has no parameters. + + +#### GetResponse() `method` + + + +Method to get the consolidated response of a request. + +###### Returns + +The final result. + +###### Parameters + +This method has no parameters. + + +#### GetType() `method` + + + +Method to get the consolidated response of a request. + +###### Returns + +The final result. + +###### Parameters + +This method has no parameters. + + +#### HandleRequest() `method` + + + +Handle rpc request in an asynchronous manner. + +###### Parameters + +This method has no parameters. + + +#### HandleSign() `method` + + + +Handle signing request in an asynchronous manner. + +###### Parameters + +This method has no parameters. + + +#### IsValid() `method` + + + +Conditional to verify if the encapsulated pointer actually points to something. + +###### Returns + +if its valid, `false` if it is not. + +###### Parameters + +This method has no parameters. + + +#### ReportError() `method` + + + +Setter for the error on the current context. Proxies it to the native context. + +###### Parameters + +This method has no parameters. + + +### ContextException `type` + + + +In3.Error + + + +Exception thrown when there is an issue with the Context engine. + + +### DataTypeConverter `type` + + + +In3.Utils + + + +General util class for conversion between blockchain types. + + +#### HexStringToBigint(source) `method` + + + +Converts a zero-prefixed hex (e.g.: 0x05) to [BigInteger](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Numerics.BigInteger 'System.Numerics.BigInteger') + +###### Returns + +The number representation of `source`. + +###### Parameters + + + +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **source** - The hex number string. + + +### DefaultTransport `type` + + + +In3.Transport + + + +Basic implementation for synchronous http transport for Incubed client. + + +#### #ctor() `constructor` + + + +Standard construction. + +###### Parameters + +This constructor has no parameters. + + +#### Handle(url,payload) `method` + + + +Method that handles, sychronously the http requests. + +###### Returns + +The http json response. + +###### Parameters + + + +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **url** - The url of the node. +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **payload** - Json for the body of the POST request to the node. + + +### ENSParameter `type` + + + +In3 + + + +Defines the kind of entity associated with the ENS Resolved. Used along with [Ens](#M-In3-Eth1-Api-Ens-System-String,In3-ENSParameter- 'In3.Eth1.Api.Ens(System.String,In3.ENSParameter)'). + + +#### Addr `property` + + + +Address. + + +#### Hash `property` + + + +Hash. + + +#### Owner `property` + + + +Owner. + + +#### Resolver `property` + + + +Resolver. + + +### IN3 `type` + + + +In3 + + + +Incubed network client. Connect to the blockchain via a list of bootnodes, then gets the latest list of nodes in +the network and ask a certain number of the to sign the block header of given list, putting their deposit at stake. +Once with the latest list at hand, the client can request any other on-chain information using the same scheme. + + +#### #ctor(chainId) `constructor` + + + +Standard constructor, use [ForChain](#M-In3-IN3-ForChain-In3-Chain- 'In3.IN3.ForChain(In3.Chain)') instead. + +###### Parameters + + + +- [In3.Chain](#T-In3-Chain 'In3.Chain') **chainId** - The chainId to connect to. + + +#### Btc `property` + + + +Gets [Api](#T-In3-Btc-Api 'In3.Btc.Api') object. + + +#### Configuration `property` + + + +Gets [ClientConfiguration](#T-In3-Configuration-ClientConfiguration 'In3.Configuration.ClientConfiguration') object. Any changes in the object will be automaticaly applied to the client before each method invocation. + + +#### Crypto `property` + + + +Gets [Api](#T-In3-Crypto-Api 'In3.Crypto.Api') object. + + +#### Eth1 `property` + + + +Gets [Api](#T-In3-Eth1-Api 'In3.Eth1.Api') object. + + +#### Ipfs `property` + + + +Gets [Api](#T-In3-Ipfs-Api 'In3.Ipfs.Api') object. + + +#### Signer `property` + + + +Get or Sets [Signer](#P-In3-IN3-Signer 'In3.IN3.Signer') object. If not set [SimpleWallet](#T-In3-Crypto-SimpleWallet 'In3.Crypto.SimpleWallet') will be used. + + +#### Storage `property` + + + +Get or Sets [Storage](#T-In3-Storage-Storage 'In3.Storage.Storage') object. If not set [InMemoryStorage](#T-In3-Storage-InMemoryStorage 'In3.Storage.InMemoryStorage') will be used. + + +#### Transport `property` + + + +Gets or sets [Transport](#T-In3-Transport-Transport 'In3.Transport.Transport') object. If not set [DefaultTransport](#T-In3-Transport-DefaultTransport 'In3.Transport.DefaultTransport') will be used. + + +#### Finalize() `method` + + + +Finalizer for the client. + +###### Parameters + +This method has no parameters. + + +#### ForChain(chain) `method` + + + +Creates a new instance of `IN3`. + +###### Returns + +An Incubed instance. + +###### Parameters + + + +- [In3.Chain](#T-In3-Chain 'In3.Chain') **chain** - [Chain](#T-In3-Chain 'In3.Chain') that Incubed will connect to. + +###### Example + +``` +IN3 client = IN3.ForChain(Chain.Mainnet); +``` + + +#### SendRpc(method,args,in3) `method` + + + +Method used to communicate with the client. In general, its preferably to use the API. + +###### Returns + +The result of the Rpc operation as JSON. + +###### Parameters + + + +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **method** - Rpc method. +- [System.Object[]](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Object[] 'System.Object[]') **args** - Arguments to the operation. +- [System.Collections.Generic.Dictionary{System.String,System.Object}](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Collections.Generic.Dictionary 'System.Collections.Generic.Dictionary{System.String,System.Object}') **in3** - Internal parameters to be repassed to the server or to change the client behavior. + + +### In3Exception `type` + + + +In3.Error + + + +General purpose, all-encompassing, Incubed specific Exception class. + + +### InMemoryStorage `type` + + + +In3.Storage + + + +Default implementation of [Storage](#T-In3-Storage-Storage 'In3.Storage.Storage'). It caches all cacheable data in memory. + + +#### #ctor() `constructor` + + + +Standard constructor. + +###### Parameters + +This constructor has no parameters. + + +#### Clear() `method` + + + +Empty the in-memory cache. + +###### Returns + +Result for the clear operation. + +###### Parameters + +This method has no parameters. + + +#### GetItem(key) `method` + + + +Fetches the data from memory. + +###### Returns + +The cached value as a `byte[]`. + +###### Parameters + + + +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **key** - Key + + +#### SetItem(key,content) `method` + + + +Stores a value in memory for a given key. + +###### Parameters + + + +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **key** - A unique identifier for the data that is being cached. +- [System.Byte[]](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Byte[] 'System.Byte[]') **content** - The value that is being cached. + + +### InvalidSignerException `type` + + + +In3.Error + + + +Exception thrown when there is no available [Signer](#T-In3-Crypto-Signer 'In3.Crypto.Signer') to sign. + + +### InvalidTransactionRequestException `type` + + + +In3.Error + + + +Exception thrown when the state of [TransactionRequest](#T-In3-Eth1-TransactionRequest 'In3.Eth1.TransactionRequest') is invalid. + + +### Log `type` + + + +In3.Eth1 + + + +Logs marks changes of state on the blockchain for events. The [Log](#T-In3-Eth1-Log 'In3.Eth1.Log') is a data object with information from logs. + + +#### Address `property` + + + +Address from which this log originated. + + +#### BlockHash `property` + + + +Hash of the block this log was in. null when its pending log. + + +#### BlockNumber `property` + + + +Number of the block this log was in. + + +#### Data `property` + + + +Data associated with the log. + + +#### LogIndex `property` + + + +Index position in the block. + + +#### Removed `property` + + + +Flags log removal (due to chain reorganization). + + +#### Topics `property` + + + +Array of 0 to 4 32 Bytes DATA of indexed log arguments. (In solidity: The first topic is the hash of the signature of the event (e.g. Deposit(address,bytes32,uint256)), except you declared the event with the anonymous specifier). + + +#### TransactionHash `property` + + + +Hash of the transactions this log was created from. null when its pending log. + + +#### TransactionIndex `property` + + + +index position log was created from. + + +#### Type `property` + + + +Address from which this log originated. + + +### LogFilter `type` + + + +In3.Eth1 + + + +Filter configuration for search logs. To be used along with the [Api](#T-In3-Eth1-Api 'In3.Eth1.Api') filter and methods. + + +#### #ctor() `constructor` + + + +Standard constructor. + +###### Parameters + +This constructor has no parameters. + + +#### Address `property` + + + +Address for the filter. + + +#### BlockHash `property` + + + +Blcok hash of the filtered blocks. + +###### Remarks + +If present, [FromBlock](#P-In3-Eth1-LogFilter-FromBlock 'In3.Eth1.LogFilter.FromBlock') and [ToBlock](#P-In3-Eth1-LogFilter-ToBlock 'In3.Eth1.LogFilter.ToBlock') will be ignored. + + +#### FromBlock `property` + + + +Starting block for the filter. + + +#### ToBlock `property` + + + +End block for the filter. + + +#### Topics `property` + + + +Array of 32 Bytes Data topics. Topics are order-dependent. It's possible to pass in null to match any topic, or a subarray of multiple topics of which one should be matching. + + +### NodeConfiguration `type` + + + +In3.Configuration + + + +Class that represents part of the configuration to be applied on the [IN3](#T-In3-IN3 'In3.IN3') (in particular to each boot node). +This is a child of [ChainConfiguration](#T-In3-Configuration-ChainConfiguration 'In3.Configuration.ChainConfiguration'). + + +#### #ctor(config) `constructor` + + + +Constructor for the node configuration. + +###### Parameters + + + +- [In3.Configuration.ChainConfiguration](#T-In3-Configuration-ChainConfiguration 'In3.Configuration.ChainConfiguration') **config** - The [ChainConfiguration](#T-In3-Configuration-ChainConfiguration 'In3.Configuration.ChainConfiguration') of which this node belongs to. + +###### Example + +``` +NodeConfiguration myDeployedNode = new NodeConfiguration(mainnetChainConfiguration); +``` + + +#### Address `property` + + + +Address of the node, which is the public address it is signing with. + + +#### Props `property` + + + +Props define the capabilities of the node. Accepts a combination of values. + +###### Example + +``` +nodeConfiguration.Props = Props.NodePropProof | Props.NodePropArchive; +``` + + +#### Url `property` + + + +Url of the bootnode which the client can connect to. + + +### Proof `type` + + + +In3.Configuration + + + +Alias for verification levels. Verification is done by calculating Ethereum Trie states requested by the Incubed network ans signed as proofs of a certain state. + + +#### Full `property` + + + +All fields will be validated (including uncles). + + +#### None `property` + + + +No Verification. + + +#### Standard `property` + + + +Standard Verification of the important properties. + + +### Props `type` + + + +In3.Configuration + + + +`Enum` that defines the capabilities an incubed node. + + +#### NodePropArchive `constants` + + + +filter out non-archive supporting nodes. + + +#### NodePropBinary `constants` + + + +filter out nodes that don't support binary encoding. + + +#### NodePropData `constants` + + + +filter out non-data provider nodes. + + +#### NodePropHttp `constants` + + + +filter out non-http nodes. + + +#### NodePropMinblockheight `constants` + + + +filter out nodes that will sign blocks with lower min block height than specified. + + +#### NodePropMultichain `constants` + + + +filter out nodes other then which have capability of the same RPC endpoint may also accept requests for different chains. + + +#### NodePropOnion `constants` + + + +filter out non-onion nodes. + + +#### NodePropProof `constants` + + + +filter out nodes which are providing no proof. + + +#### NodePropSigner `constants` + + + +filter out non-signer nodes. + + +#### NodePropStats `constants` + + + +filter out nodes that do not provide stats. + + +### RpcException `type` + + + +In3.Error + + + +Custom Exception to be thrown in case of Rpc errors. + + +#### Code `property` + + + +Json-rpc code for the error. + + +### ScriptPubKey `type` + + + +In3.Btc + + + +Script on a transaction output. + + +#### Addresses `property` + + + +List of addresses. + + +#### Asm `property` + + + +The asm data, + + +#### Hex `property` + + + +The raw hex data. + + +#### ReqSigs `property` + + + +The required sigs. + + +#### Type `property` + + + +The type. + +###### Example + +pubkeyhash + + +### ScriptSig `type` + + + +In3.Btc + + + +Script on a transaction input. + + +#### Asm `property` + + + +The asm data. + + +#### Hex `property` + + + +The raw hex data. + + +### SignatureType `type` + + + +In3.Crypto + + + +Group of constants to be used along with the methods of [Api](#T-In3-Crypto-Api 'In3.Crypto.Api'). + + +#### EthSign `property` + + + +For hashes of the RLP prefixed. + + +#### Hash `property` + + + +For data that was hashed and then signed. + + +#### Raw `property` + + + +For data that was signed directly. + + +### SignedData `type` + + + +In3.Crypto + + + +Output of [SignData](#M-In3-Crypto-Api-SignData-System-String,System-String,In3-Crypto-SignatureType- 'In3.Crypto.Api.SignData(System.String,System.String,In3.Crypto.SignatureType)'). + + +#### Message `property` + + + +Signed message. + + +#### MessageHash `property` + + + +Hash of ([Message](#P-In3-Crypto-SignedData-Message 'In3.Crypto.SignedData.Message'). + + +#### R `property` + + + +Part of the ECDSA signature. + + +#### S `property` + + + +Part of the ECDSA signature. + + +#### Signature `property` + + + +ECDSA calculated r, s, and parity v, concatenated. + + +#### V `property` + + + +27 + ([R](#P-In3-Crypto-SignedData-R 'In3.Crypto.SignedData.R') % 2). + + +### Signer `type` + + + +In3.Crypto + + + +Minimum interface to be implemented by a kind of signer. Used by [SendTransaction](#M-In3-Eth1-Api-SendTransaction-In3-Eth1-TransactionRequest- 'In3.Eth1.Api.SendTransaction(In3.Eth1.TransactionRequest)'). Set it with [Signer](#P-In3-IN3-Signer 'In3.IN3.Signer'). + + +#### CanSign(account) `method` + + + +Queries the Signer if it can sign for a certain key. + +###### Returns + +`true` if it can sign, `false` if it cant. + +###### Parameters + + + +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **account** - The account derived from the private key used to sign transactions. + +###### Remarks + +This method is invoked internaly by [SendTransaction](#M-In3-Eth1-Api-SendTransaction-In3-Eth1-TransactionRequest- 'In3.Eth1.Api.SendTransaction(In3.Eth1.TransactionRequest)') using [From](#P-In3-Eth1-TransactionRequest-From 'In3.Eth1.TransactionRequest.From') and will throw a `SystemException` in case `false` is returned. + + +#### PrepareTransaction() `method` + + + +Optional method which allows to change the transaction-data before sending it. This can be used for redirecting it through a multisig. Invoked just before sending a transaction through [SendTransaction](#M-In3-Eth1-Api-SendTransaction-In3-Eth1-TransactionRequest- 'In3.Eth1.Api.SendTransaction(In3.Eth1.TransactionRequest)'). + +###### Returns + +Modified transaction request. + +###### Parameters + +This method has no parameters. + + +#### Sign(data,account) `method` + + + +Signs the transaction data with the private key associated with the invoked account. Both arguments are automaticaly passed by Incubed client base on [TransactionRequest](#T-In3-Eth1-TransactionRequest 'In3.Eth1.TransactionRequest') data during a [SendTransaction](#M-In3-Eth1-Api-SendTransaction-In3-Eth1-TransactionRequest- 'In3.Eth1.Api.SendTransaction(In3.Eth1.TransactionRequest)'). + +###### Returns + +The signed transaction data. + +###### Parameters + + + +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **data** - Data to be signed. +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **account** - The account that will sign the transaction. + + +### SimpleWallet `type` + + + +In3.Crypto + + + +Default implementation of the [Signer](#T-In3-Crypto-Signer 'In3.Crypto.Signer'). Works as an orchestration of the [](#N-In3-Crypto 'In3.Crypto') in order to manage multiple accounts. + + +#### #ctor(in3) `constructor` + + + +Basic constructor. + +###### Parameters + + + +- [In3.IN3](#T-In3-IN3 'In3.IN3') **in3** - A client instance. + + +#### AddRawKey(privateKey) `method` + + + +Adds a private key to be managed by the wallet and sign transactions. + +###### Returns + +The address derived from the `privateKey` + +###### Parameters + + + +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **privateKey** - The private key to be stored by the wallet. + + +#### CanSign(address) `method` + + + +Check if this address is managed by this wallet. + +###### Returns + +`true` if the address is managed by this wallter, `false` if not. + +###### Parameters + + + +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **address** - The address. Value returned by [AddRawKey](#M-In3-Crypto-SimpleWallet-AddRawKey-System-String- 'In3.Crypto.SimpleWallet.AddRawKey(System.String)'). + + +#### PrepareTransaction(tx) `method` + + + +Identity function-like method. + +###### Returns + +`tx` + +###### Parameters + + + +- [In3.Eth1.TransactionRequest](#T-In3-Eth1-TransactionRequest 'In3.Eth1.TransactionRequest') **tx** - A transaction object. + + +#### Sign(data,address) `method` + + + +Signs the transaction data by invoking [SignData](#M-In3-Crypto-Api-SignData-System-String,System-String,In3-Crypto-SignatureType- 'In3.Crypto.Api.SignData(System.String,System.String,In3.Crypto.SignatureType)'). + +###### Returns + +Signed transaction data. + +###### Parameters + + + +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **data** - Data to be signed. +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **address** - Address managed by the wallet, see [AddRawKey](#M-In3-Crypto-SimpleWallet-AddRawKey-System-String- 'In3.Crypto.SimpleWallet.AddRawKey(System.String)') + + +### Storage `type` + + + +In3.Storage + + + +Provider methods to cache data. +These data could be nodelists, contract codes or validator changes. +Any form of cache should implement [Storage](#T-In3-Storage-Storage 'In3.Storage.Storage') and be set with [Storage](#P-In3-IN3-Storage 'In3.IN3.Storage'). + + +#### Clear() `method` + + + +Clear the cache. + +###### Returns + +The result of the operation: `true` for success and `false` for failure. + +###### Parameters + +This method has no parameters. + + +#### GetItem(key) `method` + + + +returns a item from cache. + +###### Returns + +The bytes or `null` if not found. + +###### Parameters + + + +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **key** - The key for the item. + + +#### SetItem(key,content) `method` + + + +Stores an item to cache. + +###### Parameters + + + +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **key** - The key for the item. +- [System.Byte[]](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Byte[] 'System.Byte[]') **content** - The value to store. + + +### Transaction `type` + + + +In3.Btc + + + +A BitCoin Transaction. + + +### Transaction `type` + + + +In3.Eth1 + + + +Class representing a transaction that was accepted by the Ethereum chain. + + +#### Blockhash `property` + + + +The block hash of the block containing this transaction. + + +#### Blocktime `property` + + + +The block time in seconds since epoch (Jan 1 1970 GMT). + + +#### Confirmations `property` + + + +The confirmations. + + +#### Hash `property` + + + +The transaction hash (differs from txid for witness transactions). + + +#### Hex `property` + + + +The hex representation of raw data. + + +#### Locktime `property` + + + +The locktime. + + +#### Size `property` + + + +The serialized transaction size. + + +#### Time `property` + + + +The transaction time in seconds since epoch (Jan 1 1970 GMT). + + +#### Txid `property` + + + +Transaction Id. + + +#### Version `property` + + + +The version. + + +#### Vin `property` + + + +The transaction inputs. + + +#### Vout `property` + + + +The transaction outputs. + + +#### Vsize `property` + + + +The virtual transaction size (differs from size for witness transactions). + + +#### Weight `property` + + + +The transaction’s weight (between vsize4-3 and vsize4). + + +#### BlockHash `property` + + + +Hash of the block that this transaction belongs to. + + +#### BlockNumber `property` + + + +Number of the block that this transaction belongs to. + + +#### ChainId `property` + + + +Chain id that this transaction belongs to. + + +#### Creates `property` + + + +Address of the deployed contract (if successfull). + + +#### From `property` + + + +Address whose private key signed this transaction with. + + +#### Gas `property` + + + +Gas for the transaction. + + +#### GasPrice `property` + + + +Gas price (in wei) for each unit of gas. + + +#### Hash `property` + + + +Transaction hash. + + +#### Input `property` + + + +Transaction data. + + +#### Nonce `property` + + + +Nonce for this transaction. + + +#### PublicKey `property` + + + +Public key. + + +#### R `property` + + + +Part of the transaction signature. + + +#### Raw `property` + + + +Transaction as rlp encoded data. + + +#### S `property` + + + +Part of the transaction signature. + + +#### StandardV `property` + + + +Part of the transaction signature. V is parity set by v = 27 + (r % 2). + + +#### To `property` + + + +To address of the transaction. + + +#### TransactionIndex `property` + + + +Transaction index. + + +#### V `property` + + + +The [StandardV](#P-In3-Eth1-Transaction-StandardV 'In3.Eth1.Transaction.StandardV') plus the chain. + + +#### Value `property` + + + +Value of the transaction. + + +### TransactionBlock `type` + + + +In3.Eth1 + + + +Class that holds a block with its full transaction array: [Transaction](#T-In3-Eth1-Transaction 'In3.Eth1.Transaction'). + + +#### Transactions `property` + + + +Array with the full transactions containing on this block. + +###### Remarks + +Returned when `shouldIncludeTransactions` on [Api](#T-In3-Eth1-Api 'In3.Eth1.Api') get block methods are set to `true`. + + +### TransactionHashBlock `type` + + + +In3.Eth1 + + + +Class that holds a block with its transaction hash array. + + +#### Transactions `property` + + + +Array with the full transactions containing on this block. + +###### Remarks + +Returned when `shouldIncludeTransactions` on [Api](#T-In3-Eth1-Api 'In3.Eth1.Api') get block methods are set to `false`. + + +### TransactionInput `type` + + + +In3.Btc + + + +Input of a transaction. + + +#### ScriptSig `property` + + + +The script. + + +#### Sequence `property` + + + +The script sequence number. + + +#### Txid `property` + + + +The transaction id. + + +#### Txinwitness `property` + + + +Hex-encoded witness data (if any). + + +#### Yout `property` + + + +The index of the transactionoutput. + + +### TransactionOutput `type` + + + +In3.Btc + + + +Output of a transaction. + + +#### N `property` + + + +The index in the transaction. + + +#### ScriptPubKey `property` + + + +The script of the transaction. + + +#### Value `property` + + + +The value in bitcoins. + + +### TransactionReceipt `type` + + + +In3.Eth1 + + + +Class that represents a transaction receipt. See [GetTransactionReceipt](#M-In3-Eth1-Api-GetTransactionReceipt-System-String- 'In3.Eth1.Api.GetTransactionReceipt(System.String)'). + + +#### BlockHash `property` + + + +Hash of the block with the transaction which this receipt is associated with. + + +#### BlockNumber `property` + + + +Number of the block with the transaction which this receipt is associated with. + + +#### ContractAddress `property` + + + +Address of the smart contract invoked in the transaction (if any). + + +#### From `property` + + + +Address of the account that signed the transaction. + + +#### GasUsed `property` + + + +Gas used on this transaction. + + +#### Logs `property` + + + +Logs/events for this transaction. + + +#### LogsBloom `property` + + + +A bloom filter of logs/events generated by contracts during transaction execution. Used to efficiently rule out transactions without expected logs. + + +#### Root `property` + + + +Merkle root of the state trie after the transaction has been executed (optional after Byzantium hard fork EIP609). + + +#### Status `property` + + + +Status of the transaction. + + +#### To `property` + + + +Address whose value will be transfered to. + + +#### TransactionHash `property` + + + +Hash of the transaction. + + +#### TransactionIndex `property` + + + +Number of the transaction on the block. + + +### TransactionRequest `type` + + + +In3.Eth1 + + + +Class that holds the state for the transaction request to be submited via [SendTransaction](#M-In3-Eth1-Api-SendTransaction-In3-Eth1-TransactionRequest- 'In3.Eth1.Api.SendTransaction(In3.Eth1.TransactionRequest)'). + + +#### Data `property` + + + +Data of the transaction (in the case of a smart contract deployment for exemple). + + +#### From `property` + + + +Address derivated from the private key that will sign the transaction. See [Signer](#T-In3-Crypto-Signer 'In3.Crypto.Signer'). + + +#### Function `property` + + + +Function of the smart contract to be invoked. + + +#### Gas `property` + + + +Gas cost for the transaction. Can be estimated via [EstimateGas](#M-In3-Eth1-Api-EstimateGas-In3-Eth1-TransactionRequest,System-Numerics-BigInteger- 'In3.Eth1.Api.EstimateGas(In3.Eth1.TransactionRequest,System.Numerics.BigInteger)'). + + +#### GasPrice `property` + + + +Gas price (in wei). Can be obtained via [GetGasPrice](#M-In3-Eth1-Api-GetGasPrice 'In3.Eth1.Api.GetGasPrice'). + + +#### Nonce `property` + + + +Nonce of the transaction. + + +#### Params `property` + + + +Array of parameters for the function (in the same order of its signature), see [Function](#P-In3-Eth1-TransactionRequest-Function 'In3.Eth1.TransactionRequest.Function') + + +#### To `property` + + + +Address to whom the transaction value will be transfered to or the smart contract address whose function will be invoked. + + +#### Value `property` + + + +Value of the transaction. + + +### Transport `type` + + + +In3.Transport + + + +Minimum interface for a custom transport. Transport is a mean of communication with the Incubed server. + + +#### Handle(url,payload) `method` + + + +Method to be implemented that will handle the requests to the server. This method may be called once for each url on each batch of requests. + +###### Returns + +The rpc response. + +###### Parameters + + + +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **url** - Url of the node. +- [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') **payload** - Content for the RPC request. diff --git a/scripts/build.sh b/scripts/build.sh index 9a06be16a..fa6d7dd8a 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -13,7 +13,7 @@ if [ "$CONTAINER" = "sentry" ]; then BUILDTYPE=debug CONTAINER="" TEST=true - OPTS="-DLOGGING=true -DRECORDER=true -DSENTRY=true -DJAVA=false -DSENTRY_BACKEND=inproc -DBUILD_SHARED_LIBS=false" + OPTS="-DLOGGING=true -DRECORDER=true -DSENTRY=true -DJAVA=false -DSENTRY_BACKEND=crashpad -DBUILD_SHARED_LIBS=false" fi if [ "$CONTAINER" = "release" ]; then BUILDTYPE=release diff --git a/scripts/cmake_flags.sh b/scripts/cmake_flags.sh new file mode 100755 index 000000000..17a9a264f --- /dev/null +++ b/scripts/cmake_flags.sh @@ -0,0 +1,61 @@ +#!/bin/bash +opt=$1 +#cmd args +enable_make=0 +case $opt in + -m|--make) + enable_make=1 + ;; + -h|--help) + echo 'Usage: %s ... + -m, --make enable make compiling of the cmake project, (this will take a long time 2 days aprox) + -h, --help test common in3 cmake definitions combinations. current flags: -DLOGGING -DUSE_CURL -DJAVA -DEVM_GAS -DTEST -DZKSYNC -DIN3API -DIN3_LIB -DCMD"' + exit 0 + ;; +esac + +opts=( "-DLOGGING" "-DUSE_CURL" "-DJAVA" "-DEVM_GAS" "-DTEST" "-DZKSYNC" "-DIN3API" "-DIN3_LIB" "-DCMD" ) +len=$((${#opts[@]})) +max=$((1<0)); + then + opt_str="${opt_str} ${opts[i]}=true" + else + opt_str="${opt_str} ${opts[i]}=false" + fi + done + opt_str="${opt_str} -DCMAKE_BUILD_TYPE=${types[t]}" + cd .. + mkdir build || echo "using existng build-folder ..." + rm -rf build/* + cd build + log_out="${types[t]}_${mask}_cmake_test.txt" + echo "Current mask: " $mask "Current cmake definitions state: " ${opt_str} + cmake ${opt_str} .. 2>>../$log_out + # if cmake fails record the error to a file + if [ $? -eq 1 ] + then + echo "cmake failed ${opt_str}" + echo "test: ${mask} ${opt_str}">../"err_$log_out" + fi + if [ $enable_make -eq 1 ] + then + make -j 8 + fi + + done +done +) + + + diff --git a/wasm/src/build_js.sh b/wasm/src/build_js.sh index 0a5195ec2..29b592f51 100755 --- a/wasm/src/build_js.sh +++ b/wasm/src/build_js.sh @@ -9,7 +9,7 @@ TARGET_JS="in3.js" # wrap code in a function in order to not polute the global namespace. printf "const IN3=(function(){\nvar in3w = {};\n" > $TARGET_JS # add emscripten gluecode -cat in3w.js | sed "s/uncaughtException/ue/g" >> $TARGET_JS +cat in3w.js | sed "s/(document/(typeof document!=\"undefined\"\&\&document/g" | sed "s/uncaughtException/ue/g" >> $TARGET_JS # add custom code the defines the public export. This code will have access to all the internal functions of the gluecode! # it should also overwrite the module.exports to use the wrapper-class. cat "$1/in3.js" >> $TARGET_JS diff --git a/wasm/src/in3.js b/wasm/src/in3.js index 1c3a7dd02..8c5ffb6cc 100644 --- a/wasm/src/in3.js +++ b/wasm/src/in3.js @@ -32,10 +32,13 @@ * with this program. If not, see . *******************************************************************************/ +const isBrowserEnvironment = (function () { + return (typeof window !== "undefined") && (this === window); +}).call(); + // implement the transport and storage handlers /* istanbul ignore next */ -if (typeof fetch === 'function') { - +if (isBrowserEnvironment) { // for browsers in3w.in3_cache = { get: key => window.localStorage.getItem('in3.' + key), @@ -244,7 +247,7 @@ class IN3 { this.plugins.push(plgn) } - if (this.ptr) + if (this.ptr) in3w.ccall('wasm_register_plugin', 'number', ['number', 'number', 'number'], [this.ptr, action, index]); } @@ -497,7 +500,7 @@ IN3.setConvertBuffer = function (fn) { convertBuffer = fn } -// change the Buffer +// change the BigInt IN3.setConvertBigInt = function (fn) { convertBigInt = fn } diff --git a/wasm/src/in3_util.js b/wasm/src/in3_util.js index dd7183fcd..f0f2a6421 100644 --- a/wasm/src/in3_util.js +++ b/wasm/src/in3_util.js @@ -154,7 +154,7 @@ function abiEncode(sig, ...params) { function ecSign(pk, data, hashMessage = true, adjustV = true) { data = toUint8Array(data) pk = toUint8Array(pk) - return call_buffer('ec_sign', 65, pk, hashMessage ? 1 : 0, data, data.byteLength, adjustV ? 1 : 0) + return toBuffer(call_buffer('ec_sign', 65, pk, hashMessage ? 1 : 0, data, data.byteLength, adjustV ? 1 : 0)) } function abiDecode(sig, data) { @@ -264,7 +264,7 @@ function toHex(val, bytes) { return undefined; let hex = '' if (typeof val === 'string') - hex = val.startsWith('0x') + hex = (val.startsWith('0x') || val.startsWith('0X')) ? val.substr(2) : (!isNaN(parseInt(val[val[0] == '-' ? 1 : 0])) ? convertInt2Hex(val) : convertUTF82Hex(val)) else if (typeof val === 'boolean') diff --git a/wasm/src/index.d.ts b/wasm/src/index.d.ts index a961f056a..e39203f21 100644 --- a/wasm/src/index.d.ts +++ b/wasm/src/index.d.ts @@ -379,7 +379,7 @@ export declare interface RPCResponse { /** * in case of an error this needs to be set */ - error?: string + error?: string | { message: string, code: number, data?: any } /** * the params * example: 0xa35bc @@ -397,13 +397,19 @@ interface IN3Plugin { * this is called when the client is cleaned up. * @param client the client object */ - term?(client: IN3Generic) + term?(client: IN3Generic): void /** * returns address * @param client */ - getAccount?(client: IN3Generic) + getAccount?(client: IN3Generic): string + + /** + * returns list of addresses + * @param client + */ + getAccounts?(client: IN3Generic): Address[] /** * called for each request. @@ -461,7 +467,7 @@ export default class IN3Generic { /** * disposes the Client. This must be called in order to free allocated memory! */ - public free(); + public free(): void; /** * returns a Object, which can be used as Web3Provider. @@ -531,9 +537,16 @@ export default class IN3Generic { */ public static util: Utils - public static setConvertBigInt(convert: (any) => any) - public static setConvertBuffer(convert: (any) => any) - // public static setConvertBuffer(val: any, len?: number) : BufferType + /** sets the convert-function, which converts any kind of type to Type defined for BigInt-operation. + * if not set the default type would be bigint. + */ + public static setConvertBigInt(convert: (val: any) => any): void + + + /** sets the convert-function, which converts any kind of type to Type defined for Buffer or Bytes-operation. + * if not set the default type would be UInt8Array. + */ + public static setConvertBuffer(convert: (val: any) => any): void /** supporting both ES6 and UMD usage */ public static default: typeof IN3Generic @@ -553,8 +566,16 @@ export class IN3 extends IN3Generic { public constructor(config?: Partial); - public static setConvertBigInt(convert: (any) => any) - public static setConvertBuffer(convert: (any) => any) + /** sets the convert-function, which converts any kind of type to Type defined for BigInt-operation. + * if not set the default type would be bigint. + */ + public static setConvertBigInt(convert: (val: any) => any): void + + + /** sets the convert-function, which converts any kind of type to Type defined for Buffer or Bytes-operation. + * if not set the default type would be UInt8Array. + */ + public static setConvertBuffer(convert: (val: any) => any): void } @@ -658,7 +679,7 @@ export declare class SimpleSigner implements Signer, tx: Transaction) => Promise @@ -791,6 +812,4 @@ export declare interface Utils { * @param pk the private key. */ private2address(pk: Hex | BufferType): Address - } - diff --git a/wasm/src/modules/eth.d.ts b/wasm/src/modules/eth.d.ts index d41bb81fc..6fbb49917 100644 --- a/wasm/src/modules/eth.d.ts +++ b/wasm/src/modules/eth.d.ts @@ -312,7 +312,7 @@ export interface EthAPI { */ accounts: AccountAPI; - constructor(client: IN3Generic); + constructor(client: IN3Generic): EthAPI; /** * Returns the number of most recent block. (as number) */ diff --git a/wasm/src/modules/eth.js b/wasm/src/modules/eth.js index ea5a7d191..f55dd5c1b 100644 --- a/wasm/src/modules/eth.js +++ b/wasm/src/modules/eth.js @@ -3,7 +3,7 @@ class AccountAPI { constructor(client) { this.client = client } add(pk) { - return this.client.sendRPC("in3_addRawKey", [toHex(pk)]) + return this.client.sendRPC("in3_addRawKey", [toHex(pk)]).then(toChecksumAddress) } } class EthAPI { diff --git a/wasm/test/package.json b/wasm/test/package.json index 04de7a072..e4f2f5e33 100644 --- a/wasm/test/package.json +++ b/wasm/test/package.json @@ -47,6 +47,7 @@ }, "dependencies": { "axios": "^0.19.2", + "bn": "^1.0.5", "bn.js": "^5.0.0", "buffer": "^5.2.1", "eth-lib": "^0.2.8", @@ -62,4 +63,4 @@ "client", "jsonrpc" ] -} \ No newline at end of file +} diff --git a/wasm/test/testEthApi.js b/wasm/test/testEthApi.js index b83dbd887..1b339426d 100644 --- a/wasm/test/testEthApi.js +++ b/wasm/test/testEthApi.js @@ -62,8 +62,6 @@ describe('EthAPI-Tests', () => { mockResponse('eth_getCode', 'WETH') res = await c.eth.callFn('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', 'totalSupply():uint') assert.equal(2156081965638983079156868n, res) - - }) it('eth.sendTransaction()', async () => { @@ -86,7 +84,6 @@ describe('EthAPI-Tests', () => { }) assert.equal(hash, '0xd5651b7c0b396c16ad9dc44ef0770aa215ca795702158395713facfbc9b55f38') - }) it('plugin._handlRPC', async () => { @@ -122,7 +119,6 @@ describe('EthAPI-Tests', () => { const address = IN3.util.private2address(pk) assert.equal(address, '0x082977959d0C5A1bA627720ac753Ec2ADB5Bd7d0') - const c = createClient() assert.isTrue(await c.eth.sign(address, msg).then(_ => false, _ => true), 'must throw since we don not have a signer set') @@ -134,7 +130,6 @@ describe('EthAPI-Tests', () => { assert.equal(sig.r, '0x5782d5df271b9a0890f89868de73b7a206f2eb988346bc3df2c0a475d60b068a') assert.equal(sig.s, '0x30760b12fd8cf88cd10a31dea71d9309d5b7b2f7bb49e36f69fcdbdfe480f129') assert.equal(sig.v, 28) - }) it('eth.blockNumber()', async () => { diff --git a/wasm/test/testUtil.js b/wasm/test/testUtil.js index 13f921bb1..6c3eb2607 100644 --- a/wasm/test/testUtil.js +++ b/wasm/test/testUtil.js @@ -34,13 +34,13 @@ require('mocha') const { assert } = require('chai') -const { IN3, beforeTest } = require('./util/mocker') +const { IN3, beforeTest, createClient } = require('./util/mocker') const convertArray2Hex = a => Array.isArray(a) ? a.map(convertArray2Hex) : IN3.util.toHex(a) +const BN = require('bn.js'); describe('Util-Tests', () => { beforeEach(beforeTest) - afterEach(IN3.freeAll) it('abi encode decode', async () => { @@ -55,13 +55,10 @@ describe('Util-Tests', () => { ) } - check("transfer(address,uint256,string)", "0x56b8c724000000000000000000000000965d1c9987bd2c34e151e63d60aff8e9db6b15610000000000000000000000000000000000000000000000000000000000001c4200000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000007496e637562656400000000000000000000000000000000000000000000000000", "0x965D1C9987BD2c34e151E63d60AFf8E9dB6b1561", 7234, "Incubed" ) - - check( "transfer(bytes,string)", "0x8fa7e45f000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000014965d1c9987bd2c34e151e63d60aff8e9db6b15610000000000000000000000000000000000000000000000000000000000000000000000000000000000000007496e637562656400000000000000000000000000000000000000000000000000", @@ -77,11 +74,9 @@ describe('Util-Tests', () => { "0x360a10540000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000034", [0x12, 0x34] ) - }) it('splitSignature', async () => { - let res = IN3.util.splitSignature("0xf596af3336ac65b01ff4b9c632bc8af8043f8c11ae4de626c74d834412cb5a234783c14807e20a9e665b3118dec54838bd78488307d9175dd1ff13eeb67e05941c" , "0x9fa034abf05bd334e60d92da257eb3d66dd3767bba9a1d7a7575533eb0977465") @@ -89,7 +84,6 @@ describe('Util-Tests', () => { assert.equal(res.s, "0x4783c14807e20a9e665b3118dec54838bd78488307d9175dd1ff13eeb67e0594") assert.equal(res.v, 28) assert.equal(res.messageHash, "0xee966c673733bc2c23275a45f712006c0fecc62eba3660574ac738cc31c7c8b8") - }) it('randomBytes', async () => { @@ -98,7 +92,6 @@ describe('Util-Tests', () => { }) it('soliditySha3', async () => { - assert.equal(IN3.util.soliditySha3('Hello!%'), "0x661136a4267dba9ccdf6bfddb7c00e714de936674c4bdb065a531cf1cb15c7fc") assert.equal(IN3.util.soliditySha3('234'), "0x61c831beab28d67d1bb40b5ae1a11e2757fa842f031a2d0bc94a7867bc5d26c2") assert.equal(IN3.util.soliditySha3(0xea), "0x61c831beab28d67d1bb40b5ae1a11e2757fa842f031a2d0bc94a7867bc5d26c2") @@ -133,8 +126,6 @@ describe('Util-Tests', () => { it('getAddress', async () => { assert.equal(IN3.util.private2address("0x3f64dd6972bda1e7611dc38a294d7e3404d51c4aff4b09534675ecd43f66d659"), "0xeebCfd8F610e497748989B7cbAF0633E644512E6") - - }) it('toMinHex', async () => { @@ -166,7 +157,6 @@ describe('Util-Tests', () => { }) - it('toNumber', async () => { assert.equal(1, IN3.util.toNumber(1)) assert.equal(1, IN3.util.toNumber(true)) @@ -201,5 +191,75 @@ describe('Util-Tests', () => { assert.equal(IN3.util.toChecksumAddress('0xbc0ea09c1651a3d5d40bacb4356fb59159a99564'), '0xBc0ea09C1651A3D5D40Bacb4356FB59159A99564') }) - + describe('setConvertBuffer', () => { + it('overrides buffer type', () => { + // Overrides the default function to return a buffer instead of a Uint8Array + IN3.setConvertBuffer(val => { + if (val === undefined || val === null || Buffer.isBuffer(val)) { + return val; + } + if (val instanceof Uint8Array) { + return Buffer.from(val); + } + if (BN.isBN(val)) { + return Buffer.from(val.toString(16), 'hex'); + } + if (typeof val !== 'string') { + val = IN3.util.toHex(val); + } + return val.startsWith('0x') ? Buffer.from(val.substr(2), 'hex') : Buffer.from(val, 'utf8'); + }); + + let toBeSigned = "some_data" + + const pk = "0x889dbed9450f7a4b68e0732ccb7cd016dab158e6946d16158f2736fda1143ca6" + const c = createClient() + c.signer = new IN3.SimpleSigner() + let address = c.signer.addAccount(pk) + c.signer.sign(toBeSigned, address).then(signedData => { + assert.equal(Buffer.isBuffer(signedData), true) + }) + }) + + it('eth.sign()', async () => { + // Overrides the default function to return a buffer instead of a Uint8Array + IN3.setConvertBuffer(val => { + if (val === undefined || val === null || Buffer.isBuffer(val)) { + return val; + } + if (val instanceof Uint8Array) { + return Buffer.from(val); + } + if (BN.isBN(val)) { + return Buffer.from(val.toString(16), 'hex'); + } + if (typeof val !== 'string') { + val = IN3.util.toHex(val); + } + return val.startsWith('0x') ? Buffer.from(val.substr(2), 'hex') : Buffer.from(val, 'utf8'); + }); + + const pk = '0x889dbed9450f7a4b68e0732ccb7cd016dab158e6946d16158f2736fda1143ca6' + const msg = '0x9fa034abf05bd334e60d92da257eb3d66dd3767bba9a1d7a7575533eb0977465' + assert.equal(IN3.util.toHex(IN3.util.ecSign(pk, msg, false)) + , '0xf596af3336ac65b01ff4b9c632bc8af8043f8c11ae4de626c74d834412cb5a234783c14807e20a9e665b3118dec54838bd78488307d9175dd1ff13eeb67e05941c') + assert.equal(IN3.util.toHex(IN3.util.ecSign(pk, msg, true)) + , '0x349338b22f8c19d4c8d257595493450a88bb51cc0df48bb9b0077d1d86df3643513e0ab305ffc3d4f9a0f300d501d16556f9fb43efd1a224d6316012bb5effc71c') + + const address = IN3.util.private2address(pk) + assert.equal(address, '0x082977959d0C5A1bA627720ac753Ec2ADB5Bd7d0') + + const c = createClient() + assert.isTrue(await c.eth.sign(address, msg).then(_ => false, _ => true), 'must throw since we don not have a signer set') + + c.signer = new IN3.SimpleSigner(pk) + const sig = await c.eth.sign(address, msg) + assert.equal(sig.message, '0x19457468657265756d205369676e6564204d6573736167653a0a33329fa034abf05bd334e60d92da257eb3d66dd3767bba9a1d7a7575533eb0977465') + assert.equal(sig.messageHash, IN3.util.toHex(IN3.util.keccak(sig.message))) + assert.equal(sig.signature, '0x5782d5df271b9a0890f89868de73b7a206f2eb988346bc3df2c0a475d60b068a30760b12fd8cf88cd10a31dea71d9309d5b7b2f7bb49e36f69fcdbdfe480f1291c') + assert.equal(sig.r, '0x5782d5df271b9a0890f89868de73b7a206f2eb988346bc3df2c0a475d60b068a') + assert.equal(sig.s, '0x30760b12fd8cf88cd10a31dea71d9309d5b7b2f7bb49e36f69fcdbdfe480f129') + assert.equal(sig.v, 28) + }) + }) })