diff --git a/README.md b/README.md index 4a15571419..021fed17b3 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,7 @@ DroidDeck is [GPL-3.0](LICENSE). Steam and Proton belong to Valve Corporation. V - Runtime, shim, input and controller work build on WinNative and Bannerlator by maxjivi05. - mmap ring buffer controller input by ribbit384 ([WinNative #345](https://github.com/WinNative-Emu/WinNative/pull/345)). - [FEX](https://github.com/FEX-Emu/FEX) (MIT) runs x86 code. DroidDeck's build puts the platform name under `AT_PLATFORM` so [sharun](https://github.com/VHSgunzo/sharun) AppImages by VHSgunzo (MIT) start through its [userland-execve](https://crates.io/crates/userland-execve) loader (MIT), and its GL thunk hands X errors to the program's own error handler. FEX's code disk cache was checked in its source. The fix for host stack left behind when a program leaves a signal handler without returning follows the approach suggested in [FEX-Emu/FEX#2487](https://github.com/FEX-Emu/FEX/issues/2487). The host stack fix for system calls that end a block is a backport of Ryan Houdek's [FEX-Emu/FEX#6122](https://github.com/FEX-Emu/FEX/pull/6122). +- Anti-cheat support under FEX is the work of [StonkGuy](https://github.com/StonkGuy): the x86-64 ptrace, seccomp and `/proc` emulation from his [FEX fork](https://github.com/StonkGuy/FEX) (`eac-2611` branch, MIT) is carried as build patch 0021 with his authorship, patches 0022 to 0029 build on it, and his `eac-tests` regression suite verifies them. - x86-64 programs on Wayland reach the GPU through FEX's Wayland client, wayland-egl and EGL thunks. The guest `wl_list` and `wl_array` helpers follow [libwayland](https://gitlab.freedesktop.org/wayland/wayland)'s `src/wayland-util.c` (MIT). The EGL extension table comes from the [Khronos EGL registry](https://github.com/KhronosGroup/EGL-Registry) (Apache-2.0) and Mesa's `egl_other.xml` (MIT). - x86 AppImages, and arm64 ones whose runtime can't unpack on Android, are unpacked with [uruntime](https://github.com/VHSgunzo/uruntime) by VHSgunzo (MIT), shipped unmodified with its licence. - DwarFS AppImages are unpacked without proot by `dwarfsextract` from [DwarFS](https://github.com/mhx/dwarfs) by Marcus Holland-Moritz (MIT), the release binary uruntime embeds, taken out of its self-extracting wrapper and shipped with its licence. diff --git a/app/src/main/cpp/fakeinput_steam.cpp b/app/src/main/cpp/fakeinput_steam.cpp index 856501cb3c..4c592ded09 100644 --- a/app/src/main/cpp/fakeinput_steam.cpp +++ b/app/src/main/cpp/fakeinput_steam.cpp @@ -329,16 +329,28 @@ static constexpr int kWatchedFds = 1 << 16; static constexpr int kWatchedBits = sizeof(unsigned long) * 8; static std::atomic watched_fds[kWatchedFds / kWatchedBits]; static std::atomic watched_beyond{false}; +static std::atomic watched_count{0}; static void watch_fd(int fd) { if (fd < 0) return; - if (fd >= kWatchedFds) watched_beyond.store(true, std::memory_order_release); - else watched_fds[fd / kWatchedBits].fetch_or(1UL << (fd % kWatchedBits), std::memory_order_release); + if (fd >= kWatchedFds) { + watched_beyond.store(true, std::memory_order_release); + return; + } + const unsigned long bit = 1UL << (fd % kWatchedBits); + if (!(watched_fds[fd / kWatchedBits].fetch_or(bit, std::memory_order_acq_rel) & bit)) + watched_count.fetch_add(1, std::memory_order_acq_rel); } static void unwatch_fd(int fd) { - if (fd >= 0 && fd < kWatchedFds) - watched_fds[fd / kWatchedBits].fetch_and(~(1UL << (fd % kWatchedBits)), std::memory_order_release); + if (fd < 0 || fd >= kWatchedFds) return; + const unsigned long bit = 1UL << (fd % kWatchedBits); + if (watched_fds[fd / kWatchedBits].fetch_and(~bit, std::memory_order_acq_rel) & bit) + watched_count.fetch_sub(1, std::memory_order_acq_rel); +} + +static bool any_watched() { + return watched_count.load(std::memory_order_acquire) > 0 || watched_beyond.load(std::memory_order_acquire); } static bool watched(int fd) { @@ -4269,7 +4281,7 @@ static int poll_fake(struct pollfd *fds, nfds_t nfds, int timeout, const auto my_poll = next_symbol(Next::poll); const auto my_ppoll = next_symbol(Next::ppoll); - nfds_t first = 0; + nfds_t first = any_watched() ? 0 : nfds; while (first < nfds && !watched(fds[first].fd)) first++; bool has_fake_fds = false; std::vector real_fds; @@ -4372,12 +4384,12 @@ EXPORT int poll(struct pollfd *fds, nfds_t nfds, int timeout) { EXPORT int ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout, const sigset_t *sigmask) { const auto my_ppoll = next_symbol(Next::ppoll); - if (timeout && (timeout->tv_sec < 0 || timeout->tv_nsec < 0 || timeout->tv_nsec >= 1000000000L)) { - errno = EINVAL; - return -1; - } - for (nfds_t i = 0; i < nfds; ++i) { + for (nfds_t i = 0; any_watched() && i < nfds; ++i) { if (!is_fake_input_fd(fds[i].fd)) continue; + if (timeout && (timeout->tv_sec < 0 || timeout->tv_nsec < 0 || timeout->tv_nsec >= 1000000000L)) { + errno = EINVAL; + return -1; + } if (!sigmask) return poll_fake(fds, nfds, static_cast(timespec_to_ms(timeout)), nullptr); sigset_t all_signals, original_mask; @@ -4410,6 +4422,8 @@ EXPORT int __ppoll_chk(struct pollfd *fds, nfds_t nfds, const struct timespec *t EXPORT int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) { const auto my_select = next_symbol(Next::select); + if (!any_watched()) + return my_select ? my_select(nfds, readfds, writefds, exceptfds, timeout) : -1; fd_set original_readfds; fd_set original_writefds; diff --git a/app/src/main/cpp/shaders/SMAA.hlsl b/app/src/main/cpp/shaders/SMAA.hlsl new file mode 100644 index 0000000000..d955d52401 --- /dev/null +++ b/app/src/main/cpp/shaders/SMAA.hlsl @@ -0,0 +1,1361 @@ +/** + * Copyright (C) 2013 Jorge Jimenez (jorge@iryoku.com) + * Copyright (C) 2013 Jose I. Echevarria (joseignacioechevarria@gmail.com) + * Copyright (C) 2013 Belen Masia (bmasia@unizar.es) + * Copyright (C) 2013 Fernando Navarro (fernandn@microsoft.com) + * Copyright (C) 2013 Diego Gutierrez (diegog@unizar.es) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to + * do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. As clarification, there + * is no requirement that the copyright notice and permission be included in + * binary distributions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + + +/** + * _______ ___ ___ ___ ___ + * / || \/ | / \ / \ + * | (---- | \ / | / ^ \ / ^ \ + * \ \ | |\/| | / /_\ \ / /_\ \ + * ----) | | | | | / _____ \ / _____ \ + * |_______/ |__| |__| /__/ \__\ /__/ \__\ + * + * E N H A N C E D + * S U B P I X E L M O R P H O L O G I C A L A N T I A L I A S I N G + * + * http://www.iryoku.com/smaa/ + * + * Hi, welcome aboard! + * + * Here you'll find instructions to get the shader up and running as fast as + * possible. + * + * IMPORTANTE NOTICE: when updating, remember to update both this file and the + * precomputed textures! They may change from version to version. + * + * The shader has three passes, chained together as follows: + * + * |input|------------------· + * v | + * [ SMAA*EdgeDetection ] | + * v | + * |edgesTex| | + * v | + * [ SMAABlendingWeightCalculation ] | + * v | + * |blendTex| | + * v | + * [ SMAANeighborhoodBlending ] <------· + * v + * |output| + * + * Note that each [pass] has its own vertex and pixel shader. Remember to use + * oversized triangles instead of quads to avoid overshading along the + * diagonal. + * + * You've three edge detection methods to choose from: luma, color or depth. + * They represent different quality/performance and anti-aliasing/sharpness + * tradeoffs, so our recommendation is for you to choose the one that best + * suits your particular scenario: + * + * - Depth edge detection is usually the fastest but it may miss some edges. + * + * - Luma edge detection is usually more expensive than depth edge detection, + * but catches visible edges that depth edge detection can miss. + * + * - Color edge detection is usually the most expensive one but catches + * chroma-only edges. + * + * For quickstarters: just use luma edge detection. + * + * The general advice is to not rush the integration process and ensure each + * step is done correctly (don't try to integrate SMAA T2x with predicated edge + * detection from the start!). Ok then, let's go! + * + * 1. The first step is to create two RGBA temporal render targets for holding + * |edgesTex| and |blendTex|. + * + * In DX10 or DX11, you can use a RG render target for the edges texture. + * In the case of NVIDIA GPUs, using RG render targets seems to actually be + * slower. + * + * On the Xbox 360, you can use the same render target for resolving both + * |edgesTex| and |blendTex|, as they aren't needed simultaneously. + * + * 2. Both temporal render targets |edgesTex| and |blendTex| must be cleared + * each frame. Do not forget to clear the alpha channel! + * + * 3. The next step is loading the two supporting precalculated textures, + * 'areaTex' and 'searchTex'. You'll find them in the 'Textures' folder as + * C++ headers, and also as regular DDS files. They'll be needed for the + * 'SMAABlendingWeightCalculation' pass. + * + * If you use the C++ headers, be sure to load them in the format specified + * inside of them. + * + * You can also compress 'areaTex' and 'searchTex' using BC5 and BC4 + * respectively, if you have that option in your content processor pipeline. + * When compressing then, you get a non-perceptible quality decrease, and a + * marginal performance increase. + * + * 4. All samplers must be set to linear filtering and clamp. + * + * After you get the technique working, remember that 64-bit inputs have + * half-rate linear filtering on GCN. + * + * If SMAA is applied to 64-bit color buffers, switching to point filtering + * when accesing them will increase the performance. Search for + * 'SMAASamplePoint' to see which textures may benefit from point + * filtering, and where (which is basically the color input in the edge + * detection and resolve passes). + * + * 5. All texture reads and buffer writes must be non-sRGB, with the exception + * of the input read and the output write in + * 'SMAANeighborhoodBlending' (and only in this pass!). If sRGB reads in + * this last pass are not possible, the technique will work anyway, but + * will perform antialiasing in gamma space. + * + * IMPORTANT: for best results the input read for the color/luma edge + * detection should *NOT* be sRGB. + * + * 6. Before including SMAA.h you'll have to setup the render target metrics, + * the target and any optional configuration defines. Optionally you can + * use a preset. + * + * You have the following targets available: + * SMAA_HLSL_3 + * SMAA_HLSL_4 + * SMAA_HLSL_4_1 + * SMAA_GLSL_3 * + * SMAA_GLSL_4 * + * + * * (See SMAA_INCLUDE_VS and SMAA_INCLUDE_PS below). + * + * And four presets: + * SMAA_PRESET_LOW (%60 of the quality) + * SMAA_PRESET_MEDIUM (%80 of the quality) + * SMAA_PRESET_HIGH (%95 of the quality) + * SMAA_PRESET_ULTRA (%99 of the quality) + * + * For example: + * #define SMAA_RT_METRICS float4(1.0 / 1280.0, 1.0 / 720.0, 1280.0, 720.0) + * #define SMAA_HLSL_4 + * #define SMAA_PRESET_HIGH + * #include "SMAA.h" + * + * Note that SMAA_RT_METRICS doesn't need to be a macro, it can be a + * uniform variable. The code is designed to minimize the impact of not + * using a constant value, but it is still better to hardcode it. + * + * Depending on how you encoded 'areaTex' and 'searchTex', you may have to + * add (and customize) the following defines before including SMAA.h: + * #define SMAA_AREATEX_SELECT(sample) sample.rg + * #define SMAA_SEARCHTEX_SELECT(sample) sample.r + * + * If your engine is already using porting macros, you can define + * SMAA_CUSTOM_SL, and define the porting functions by yourself. + * + * 7. Then, you'll have to setup the passes as indicated in the scheme above. + * You can take a look into SMAA.fx, to see how we did it for our demo. + * Checkout the function wrappers, you may want to copy-paste them! + * + * 8. It's recommended to validate the produced |edgesTex| and |blendTex|. + * You can use a screenshot from your engine to compare the |edgesTex| + * and |blendTex| produced inside of the engine with the results obtained + * with the reference demo. + * + * 9. After you get the last pass to work, it's time to optimize. You'll have + * to initialize a stencil buffer in the first pass (discard is already in + * the code), then mask execution by using it the second pass. The last + * pass should be executed in all pixels. + * + * + * After this point you can choose to enable predicated thresholding, + * temporal supersampling and motion blur integration: + * + * a) If you want to use predicated thresholding, take a look into + * SMAA_PREDICATION; you'll need to pass an extra texture in the edge + * detection pass. + * + * b) If you want to enable temporal supersampling (SMAA T2x): + * + * 1. The first step is to render using subpixel jitters. I won't go into + * detail, but it's as simple as moving each vertex position in the + * vertex shader, you can check how we do it in our DX10 demo. + * + * 2. Then, you must setup the temporal resolve. You may want to take a look + * into SMAAResolve for resolving 2x modes. After you get it working, you'll + * probably see ghosting everywhere. But fear not, you can enable the + * CryENGINE temporal reprojection by setting the SMAA_REPROJECTION macro. + * Check out SMAA_DECODE_VELOCITY if your velocity buffer is encoded. + * + * 3. The next step is to apply SMAA to each subpixel jittered frame, just as + * done for 1x. + * + * 4. At this point you should already have something usable, but for best + * results the proper area textures must be set depending on current jitter. + * For this, the parameter 'subsampleIndices' of + * 'SMAABlendingWeightCalculationPS' must be set as follows, for our T2x + * mode: + * + * @SUBSAMPLE_INDICES + * + * | S# | Camera Jitter | subsampleIndices | + * +----+------------------+---------------------+ + * | 0 | ( 0.25, -0.25) | float4(1, 1, 1, 0) | + * | 1 | (-0.25, 0.25) | float4(2, 2, 2, 0) | + * + * These jitter positions assume a bottom-to-top y axis. S# stands for the + * sample number. + * + * More information about temporal supersampling here: + * http://iryoku.com/aacourse/downloads/13-Anti-Aliasing-Methods-in-CryENGINE-3.pdf + * + * c) If you want to enable spatial multisampling (SMAA S2x): + * + * 1. The scene must be rendered using MSAA 2x. The MSAA 2x buffer must be + * created with: + * - DX10: see below (*) + * - DX10.1: D3D10_STANDARD_MULTISAMPLE_PATTERN or + * - DX11: D3D11_STANDARD_MULTISAMPLE_PATTERN + * + * This allows to ensure that the subsample order matches the table in + * @SUBSAMPLE_INDICES. + * + * (*) In the case of DX10, we refer the reader to: + * - SMAA::detectMSAAOrder and + * - SMAA::msaaReorder + * + * These functions allow to match the standard multisample patterns by + * detecting the subsample order for a specific GPU, and reordering + * them appropriately. + * + * 2. A shader must be run to output each subsample into a separate buffer + * (DX10 is required). You can use SMAASeparate for this purpose, or just do + * it in an existing pass (for example, in the tone mapping pass, which has + * the advantage of feeding tone mapped subsamples to SMAA, which will yield + * better results). + * + * 3. The full SMAA 1x pipeline must be run for each separated buffer, storing + * the results in the final buffer. The second run should alpha blend with + * the existing final buffer using a blending factor of 0.5. + * 'subsampleIndices' must be adjusted as in the SMAA T2x case (see point + * b). + * + * d) If you want to enable temporal supersampling on top of SMAA S2x + * (which actually is SMAA 4x): + * + * 1. SMAA 4x consists on temporally jittering SMAA S2x, so the first step is + * to calculate SMAA S2x for current frame. In this case, 'subsampleIndices' + * must be set as follows: + * + * | F# | S# | Camera Jitter | Net Jitter | subsampleIndices | + * +----+----+--------------------+-------------------+----------------------+ + * | 0 | 0 | ( 0.125, 0.125) | ( 0.375, -0.125) | float4(5, 3, 1, 3) | + * | 0 | 1 | ( 0.125, 0.125) | (-0.125, 0.375) | float4(4, 6, 2, 3) | + * +----+----+--------------------+-------------------+----------------------+ + * | 1 | 2 | (-0.125, -0.125) | ( 0.125, -0.375) | float4(3, 5, 1, 4) | + * | 1 | 3 | (-0.125, -0.125) | (-0.375, 0.125) | float4(6, 4, 2, 4) | + * + * These jitter positions assume a bottom-to-top y axis. F# stands for the + * frame number. S# stands for the sample number. + * + * 2. After calculating SMAA S2x for current frame (with the new subsample + * indices), previous frame must be reprojected as in SMAA T2x mode (see + * point b). + * + * e) If motion blur is used, you may want to do the edge detection pass + * together with motion blur. This has two advantages: + * + * 1. Pixels under heavy motion can be omitted from the edge detection process. + * For these pixels we can just store "no edge", as motion blur will take + * care of them. + * 2. The center pixel tap is reused. + * + * Note that in this case depth testing should be used instead of stenciling, + * as we have to write all the pixels in the motion blur pass. + * + * That's it! + */ + +//----------------------------------------------------------------------------- +// SMAA Presets + +/** + * Note that if you use one of these presets, the following configuration + * macros will be ignored if set in the "Configurable Defines" section. + */ + +#if defined(SMAA_PRESET_LOW) +#define SMAA_THRESHOLD 0.15 +#define SMAA_MAX_SEARCH_STEPS 4 +#define SMAA_DISABLE_DIAG_DETECTION +#define SMAA_DISABLE_CORNER_DETECTION +#elif defined(SMAA_PRESET_MEDIUM) +#define SMAA_THRESHOLD 0.1 +#define SMAA_MAX_SEARCH_STEPS 8 +#define SMAA_DISABLE_DIAG_DETECTION +#define SMAA_DISABLE_CORNER_DETECTION +#elif defined(SMAA_PRESET_HIGH) +#define SMAA_THRESHOLD 0.1 +#define SMAA_MAX_SEARCH_STEPS 16 +#define SMAA_MAX_SEARCH_STEPS_DIAG 8 +#define SMAA_CORNER_ROUNDING 25 +#elif defined(SMAA_PRESET_ULTRA) +#define SMAA_THRESHOLD 0.05 +#define SMAA_MAX_SEARCH_STEPS 32 +#define SMAA_MAX_SEARCH_STEPS_DIAG 16 +#define SMAA_CORNER_ROUNDING 25 +#endif + +//----------------------------------------------------------------------------- +// Configurable Defines + +/** + * SMAA_THRESHOLD specifies the threshold or sensitivity to edges. + * Lowering this value you will be able to detect more edges at the expense of + * performance. + * + * Range: [0, 0.5] + * 0.1 is a reasonable value, and allows to catch most visible edges. + * 0.05 is a rather overkill value, that allows to catch 'em all. + * + * If temporal supersampling is used, 0.2 could be a reasonable value, as low + * contrast edges are properly filtered by just 2x. + */ +#ifndef SMAA_THRESHOLD +#define SMAA_THRESHOLD 0.1 +#endif + +/** + * SMAA_DEPTH_THRESHOLD specifies the threshold for depth edge detection. + * + * Range: depends on the depth range of the scene. + */ +#ifndef SMAA_DEPTH_THRESHOLD +#define SMAA_DEPTH_THRESHOLD (0.1 * SMAA_THRESHOLD) +#endif + +/** + * SMAA_MAX_SEARCH_STEPS specifies the maximum steps performed in the + * horizontal/vertical pattern searches, at each side of the pixel. + * + * In number of pixels, it's actually the double. So the maximum line length + * perfectly handled by, for example 16, is 64 (by perfectly, we meant that + * longer lines won't look as good, but still antialiased). + * + * Range: [0, 112] + */ +#ifndef SMAA_MAX_SEARCH_STEPS +#define SMAA_MAX_SEARCH_STEPS 16 +#endif + +/** + * SMAA_MAX_SEARCH_STEPS_DIAG specifies the maximum steps performed in the + * diagonal pattern searches, at each side of the pixel. In this case we jump + * one pixel at time, instead of two. + * + * Range: [0, 20] + * + * On high-end machines it is cheap (between a 0.8x and 0.9x slower for 16 + * steps), but it can have a significant impact on older machines. + * + * Define SMAA_DISABLE_DIAG_DETECTION to disable diagonal processing. + */ +#ifndef SMAA_MAX_SEARCH_STEPS_DIAG +#define SMAA_MAX_SEARCH_STEPS_DIAG 8 +#endif + +/** + * SMAA_CORNER_ROUNDING specifies how much sharp corners will be rounded. + * + * Range: [0, 100] + * + * Define SMAA_DISABLE_CORNER_DETECTION to disable corner processing. + */ +#ifndef SMAA_CORNER_ROUNDING +#define SMAA_CORNER_ROUNDING 25 +#endif + +/** + * If there is an neighbor edge that has SMAA_LOCAL_CONTRAST_FACTOR times + * bigger contrast than current edge, current edge will be discarded. + * + * This allows to eliminate spurious crossing edges, and is based on the fact + * that, if there is too much contrast in a direction, that will hide + * perceptually contrast in the other neighbors. + */ +#ifndef SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR +#define SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR 2.0 +#endif + +/** + * Predicated thresholding allows to better preserve texture details and to + * improve performance, by decreasing the number of detected edges using an + * additional buffer like the light accumulation buffer, object ids or even the + * depth buffer (the depth buffer usage may be limited to indoor or short range + * scenes). + * + * It locally decreases the luma or color threshold if an edge is found in an + * additional buffer (so the global threshold can be higher). + * + * This method was developed by Playstation EDGE MLAA team, and used in + * Killzone 3, by using the light accumulation buffer. More information here: + * http://iryoku.com/aacourse/downloads/06-MLAA-on-PS3.pptx + */ +#ifndef SMAA_PREDICATION +#define SMAA_PREDICATION 0 +#endif + +/** + * Threshold to be used in the additional predication buffer. + * + * Range: depends on the input, so you'll have to find the magic number that + * works for you. + */ +#ifndef SMAA_PREDICATION_THRESHOLD +#define SMAA_PREDICATION_THRESHOLD 0.01 +#endif + +/** + * How much to scale the global threshold used for luma or color edge + * detection when using predication. + * + * Range: [1, 5] + */ +#ifndef SMAA_PREDICATION_SCALE +#define SMAA_PREDICATION_SCALE 2.0 +#endif + +/** + * How much to locally decrease the threshold. + * + * Range: [0, 1] + */ +#ifndef SMAA_PREDICATION_STRENGTH +#define SMAA_PREDICATION_STRENGTH 0.4 +#endif + +/** + * Temporal reprojection allows to remove ghosting artifacts when using + * temporal supersampling. We use the CryEngine 3 method which also introduces + * velocity weighting. This feature is of extreme importance for totally + * removing ghosting. More information here: + * http://iryoku.com/aacourse/downloads/13-Anti-Aliasing-Methods-in-CryENGINE-3.pdf + * + * Note that you'll need to setup a velocity buffer for enabling reprojection. + * For static geometry, saving the previous depth buffer is a viable + * alternative. + */ +#ifndef SMAA_REPROJECTION +#define SMAA_REPROJECTION 0 +#endif + +/** + * SMAA_REPROJECTION_WEIGHT_SCALE controls the velocity weighting. It allows to + * remove ghosting trails behind the moving object, which are not removed by + * just using reprojection. Using low values will exhibit ghosting, while using + * high values will disable temporal supersampling under motion. + * + * Behind the scenes, velocity weighting removes temporal supersampling when + * the velocity of the subsamples differs (meaning they are different objects). + * + * Range: [0, 80] + */ +#ifndef SMAA_REPROJECTION_WEIGHT_SCALE +#define SMAA_REPROJECTION_WEIGHT_SCALE 30.0 +#endif + +/** + * On some compilers, discard cannot be used in vertex shaders. Thus, they need + * to be compiled separately. + */ +#ifndef SMAA_INCLUDE_VS +#define SMAA_INCLUDE_VS 1 +#endif +#ifndef SMAA_INCLUDE_PS +#define SMAA_INCLUDE_PS 1 +#endif + +//----------------------------------------------------------------------------- +// Texture Access Defines + +#ifndef SMAA_AREATEX_SELECT +#if defined(SMAA_HLSL_3) +#define SMAA_AREATEX_SELECT(sample) sample.ra +#else +#define SMAA_AREATEX_SELECT(sample) sample.rg +#endif +#endif + +#ifndef SMAA_SEARCHTEX_SELECT +#define SMAA_SEARCHTEX_SELECT(sample) sample.r +#endif + +#ifndef SMAA_DECODE_VELOCITY +#define SMAA_DECODE_VELOCITY(sample) sample.rg +#endif + +//----------------------------------------------------------------------------- +// Non-Configurable Defines + +#define SMAA_AREATEX_MAX_DISTANCE 16 +#define SMAA_AREATEX_MAX_DISTANCE_DIAG 20 +#define SMAA_AREATEX_PIXEL_SIZE (1.0 / float2(160.0, 560.0)) +#define SMAA_AREATEX_SUBTEX_SIZE (1.0 / 7.0) +#define SMAA_SEARCHTEX_SIZE float2(66.0, 33.0) +#define SMAA_SEARCHTEX_PACKED_SIZE float2(64.0, 16.0) +#define SMAA_CORNER_ROUNDING_NORM (float(SMAA_CORNER_ROUNDING) / 100.0) + +//----------------------------------------------------------------------------- +// Porting Functions + +#if defined(SMAA_HLSL_3) +#define SMAATexture2D(tex) sampler2D tex +#define SMAATexturePass2D(tex) tex +#define SMAASampleLevelZero(tex, coord) tex2Dlod(tex, float4(coord, 0.0, 0.0)) +#define SMAASampleLevelZeroPoint(tex, coord) tex2Dlod(tex, float4(coord, 0.0, 0.0)) +#define SMAASampleLevelZeroOffset(tex, coord, offset) tex2Dlod(tex, float4(coord + offset * SMAA_RT_METRICS.xy, 0.0, 0.0)) +#define SMAASample(tex, coord) tex2D(tex, coord) +#define SMAASamplePoint(tex, coord) tex2D(tex, coord) +#define SMAASampleOffset(tex, coord, offset) tex2D(tex, coord + offset * SMAA_RT_METRICS.xy) +#define SMAA_FLATTEN [flatten] +#define SMAA_BRANCH [branch] +#endif +#if defined(SMAA_HLSL_4) || defined(SMAA_HLSL_4_1) +SamplerState LinearSampler { Filter = MIN_MAG_LINEAR_MIP_POINT; AddressU = Clamp; AddressV = Clamp; }; +SamplerState PointSampler { Filter = MIN_MAG_MIP_POINT; AddressU = Clamp; AddressV = Clamp; }; +#define SMAATexture2D(tex) Texture2D tex +#define SMAATexturePass2D(tex) tex +#define SMAASampleLevelZero(tex, coord) tex.SampleLevel(LinearSampler, coord, 0) +#define SMAASampleLevelZeroPoint(tex, coord) tex.SampleLevel(PointSampler, coord, 0) +#define SMAASampleLevelZeroOffset(tex, coord, offset) tex.SampleLevel(LinearSampler, coord, 0, offset) +#define SMAASample(tex, coord) tex.Sample(LinearSampler, coord) +#define SMAASamplePoint(tex, coord) tex.Sample(PointSampler, coord) +#define SMAASampleOffset(tex, coord, offset) tex.Sample(LinearSampler, coord, offset) +#define SMAA_FLATTEN [flatten] +#define SMAA_BRANCH [branch] +#define SMAATexture2DMS2(tex) Texture2DMS tex +#define SMAALoad(tex, pos, sample) tex.Load(pos, sample) +#if defined(SMAA_HLSL_4_1) +#define SMAAGather(tex, coord) tex.Gather(LinearSampler, coord, 0) +#endif +#endif +#if defined(SMAA_GLSL_3) || defined(SMAA_GLSL_4) +#define SMAATexture2D(tex) sampler2D tex +#define SMAATexturePass2D(tex) tex +#define SMAASampleLevelZero(tex, coord) textureLod(tex, coord, 0.0) +#define SMAASampleLevelZeroPoint(tex, coord) textureLod(tex, coord, 0.0) +#define SMAASampleLevelZeroOffset(tex, coord, offset) textureLodOffset(tex, coord, 0.0, offset) +#define SMAASample(tex, coord) texture(tex, coord) +#define SMAASamplePoint(tex, coord) texture(tex, coord) +#define SMAASampleOffset(tex, coord, offset) texture(tex, coord, offset) +#define SMAA_FLATTEN +#define SMAA_BRANCH +#define lerp(a, b, t) mix(a, b, t) +#define saturate(a) clamp(a, 0.0, 1.0) +#if defined(SMAA_GLSL_4) +#define mad(a, b, c) fma(a, b, c) +#define SMAAGather(tex, coord) textureGather(tex, coord) +#else +#define mad(a, b, c) (a * b + c) +#endif +#define float2 vec2 +#define float3 vec3 +#define float4 vec4 +#define int2 ivec2 +#define int3 ivec3 +#define int4 ivec4 +#define bool2 bvec2 +#define bool3 bvec3 +#define bool4 bvec4 +#endif + +#if !defined(SMAA_HLSL_3) && !defined(SMAA_HLSL_4) && !defined(SMAA_HLSL_4_1) && !defined(SMAA_GLSL_3) && !defined(SMAA_GLSL_4) && !defined(SMAA_CUSTOM_SL) +#error you must define the shading language: SMAA_HLSL_*, SMAA_GLSL_* or SMAA_CUSTOM_SL +#endif + +//----------------------------------------------------------------------------- +// Misc functions + +/** + * Gathers current pixel, and the top-left neighbors. + */ +float3 SMAAGatherNeighbours(float2 texcoord, + float4 offset[3], + SMAATexture2D(tex)) { + #ifdef SMAAGather + return SMAAGather(tex, texcoord + SMAA_RT_METRICS.xy * float2(-0.5, -0.5)).grb; + #else + float P = SMAASamplePoint(tex, texcoord).r; + float Pleft = SMAASamplePoint(tex, offset[0].xy).r; + float Ptop = SMAASamplePoint(tex, offset[0].zw).r; + return float3(P, Pleft, Ptop); + #endif +} + +/** + * Adjusts the threshold by means of predication. + */ +float2 SMAACalculatePredicatedThreshold(float2 texcoord, + float4 offset[3], + SMAATexture2D(predicationTex)) { + float3 neighbours = SMAAGatherNeighbours(texcoord, offset, SMAATexturePass2D(predicationTex)); + float2 delta = abs(neighbours.xx - neighbours.yz); + float2 edges = step(SMAA_PREDICATION_THRESHOLD, delta); + return SMAA_PREDICATION_SCALE * SMAA_THRESHOLD * (1.0 - SMAA_PREDICATION_STRENGTH * edges); +} + +/** + * Conditional move: + */ +void SMAAMovc(bool2 cond, inout float2 variable, float2 value) { + SMAA_FLATTEN if (cond.x) variable.x = value.x; + SMAA_FLATTEN if (cond.y) variable.y = value.y; +} + +void SMAAMovc(bool4 cond, inout float4 variable, float4 value) { + SMAAMovc(cond.xy, variable.xy, value.xy); + SMAAMovc(cond.zw, variable.zw, value.zw); +} + + +#if SMAA_INCLUDE_VS +//----------------------------------------------------------------------------- +// Vertex Shaders + +/** + * Edge Detection Vertex Shader + */ +void SMAAEdgeDetectionVS(float2 texcoord, + out float4 offset[3]) { + offset[0] = mad(SMAA_RT_METRICS.xyxy, float4(-1.0, 0.0, 0.0, -1.0), texcoord.xyxy); + offset[1] = mad(SMAA_RT_METRICS.xyxy, float4( 1.0, 0.0, 0.0, 1.0), texcoord.xyxy); + offset[2] = mad(SMAA_RT_METRICS.xyxy, float4(-2.0, 0.0, 0.0, -2.0), texcoord.xyxy); +} + +/** + * Blend Weight Calculation Vertex Shader + */ +void SMAABlendingWeightCalculationVS(float2 texcoord, + out float2 pixcoord, + out float4 offset[3]) { + pixcoord = texcoord * SMAA_RT_METRICS.zw; + + // We will use these offsets for the searches later on (see @PSEUDO_GATHER4): + offset[0] = mad(SMAA_RT_METRICS.xyxy, float4(-0.25, -0.125, 1.25, -0.125), texcoord.xyxy); + offset[1] = mad(SMAA_RT_METRICS.xyxy, float4(-0.125, -0.25, -0.125, 1.25), texcoord.xyxy); + + // And these for the searches, they indicate the ends of the loops: + offset[2] = mad(SMAA_RT_METRICS.xxyy, + float4(-2.0, 2.0, -2.0, 2.0) * float(SMAA_MAX_SEARCH_STEPS), + float4(offset[0].xz, offset[1].yw)); +} + +/** + * Neighborhood Blending Vertex Shader + */ +void SMAANeighborhoodBlendingVS(float2 texcoord, + out float4 offset) { + offset = mad(SMAA_RT_METRICS.xyxy, float4( 1.0, 0.0, 0.0, 1.0), texcoord.xyxy); +} +#endif // SMAA_INCLUDE_VS + +#if SMAA_INCLUDE_PS +//----------------------------------------------------------------------------- +// Edge Detection Pixel Shaders (First Pass) + +/** + * Luma Edge Detection + * + * IMPORTANT NOTICE: luma edge detection requires gamma-corrected colors, and + * thus 'colorTex' should be a non-sRGB texture. + */ +float2 SMAALumaEdgeDetectionPS(float2 texcoord, + float4 offset[3], + SMAATexture2D(colorTex) + #if SMAA_PREDICATION + , SMAATexture2D(predicationTex) + #endif + ) { + // Calculate the threshold: + #if SMAA_PREDICATION + float2 threshold = SMAACalculatePredicatedThreshold(texcoord, offset, SMAATexturePass2D(predicationTex)); + #else + float2 threshold = float2(SMAA_THRESHOLD, SMAA_THRESHOLD); + #endif + + // Calculate lumas: + float3 weights = float3(0.2126, 0.7152, 0.0722); + float L = dot(SMAASamplePoint(colorTex, texcoord).rgb, weights); + + float Lleft = dot(SMAASamplePoint(colorTex, offset[0].xy).rgb, weights); + float Ltop = dot(SMAASamplePoint(colorTex, offset[0].zw).rgb, weights); + + // We do the usual threshold: + float4 delta; + delta.xy = abs(L - float2(Lleft, Ltop)); + float2 edges = step(threshold, delta.xy); + + // Then discard if there is no edge: + if (dot(edges, float2(1.0, 1.0)) == 0.0) + discard; + + // Calculate right and bottom deltas: + float Lright = dot(SMAASamplePoint(colorTex, offset[1].xy).rgb, weights); + float Lbottom = dot(SMAASamplePoint(colorTex, offset[1].zw).rgb, weights); + delta.zw = abs(L - float2(Lright, Lbottom)); + + // Calculate the maximum delta in the direct neighborhood: + float2 maxDelta = max(delta.xy, delta.zw); + + // Calculate left-left and top-top deltas: + float Lleftleft = dot(SMAASamplePoint(colorTex, offset[2].xy).rgb, weights); + float Ltoptop = dot(SMAASamplePoint(colorTex, offset[2].zw).rgb, weights); + delta.zw = abs(float2(Lleft, Ltop) - float2(Lleftleft, Ltoptop)); + + // Calculate the final maximum delta: + maxDelta = max(maxDelta.xy, delta.zw); + float finalDelta = max(maxDelta.x, maxDelta.y); + + // Local contrast adaptation: + edges.xy *= step(finalDelta, SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR * delta.xy); + + return edges; +} + +/** + * Color Edge Detection + * + * IMPORTANT NOTICE: color edge detection requires gamma-corrected colors, and + * thus 'colorTex' should be a non-sRGB texture. + */ +float2 SMAAColorEdgeDetectionPS(float2 texcoord, + float4 offset[3], + SMAATexture2D(colorTex) + #if SMAA_PREDICATION + , SMAATexture2D(predicationTex) + #endif + ) { + // Calculate the threshold: + #if SMAA_PREDICATION + float2 threshold = SMAACalculatePredicatedThreshold(texcoord, offset, predicationTex); + #else + float2 threshold = float2(SMAA_THRESHOLD, SMAA_THRESHOLD); + #endif + + // Calculate color deltas: + float4 delta; + float3 C = SMAASamplePoint(colorTex, texcoord).rgb; + + float3 Cleft = SMAASamplePoint(colorTex, offset[0].xy).rgb; + float3 t = abs(C - Cleft); + delta.x = max(max(t.r, t.g), t.b); + + float3 Ctop = SMAASamplePoint(colorTex, offset[0].zw).rgb; + t = abs(C - Ctop); + delta.y = max(max(t.r, t.g), t.b); + + // We do the usual threshold: + float2 edges = step(threshold, delta.xy); + + // Then discard if there is no edge: + if (dot(edges, float2(1.0, 1.0)) == 0.0) + discard; + + // Calculate right and bottom deltas: + float3 Cright = SMAASamplePoint(colorTex, offset[1].xy).rgb; + t = abs(C - Cright); + delta.z = max(max(t.r, t.g), t.b); + + float3 Cbottom = SMAASamplePoint(colorTex, offset[1].zw).rgb; + t = abs(C - Cbottom); + delta.w = max(max(t.r, t.g), t.b); + + // Calculate the maximum delta in the direct neighborhood: + float2 maxDelta = max(delta.xy, delta.zw); + + // Calculate left-left and top-top deltas: + float3 Cleftleft = SMAASamplePoint(colorTex, offset[2].xy).rgb; + t = abs(C - Cleftleft); + delta.z = max(max(t.r, t.g), t.b); + + float3 Ctoptop = SMAASamplePoint(colorTex, offset[2].zw).rgb; + t = abs(C - Ctoptop); + delta.w = max(max(t.r, t.g), t.b); + + // Calculate the final maximum delta: + maxDelta = max(maxDelta.xy, delta.zw); + float finalDelta = max(maxDelta.x, maxDelta.y); + + // Local contrast adaptation: + edges.xy *= step(finalDelta, SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR * delta.xy); + + return edges; +} + +/** + * Depth Edge Detection + */ +float2 SMAADepthEdgeDetectionPS(float2 texcoord, + float4 offset[3], + SMAATexture2D(depthTex)) { + float3 neighbours = SMAAGatherNeighbours(texcoord, offset, SMAATexturePass2D(depthTex)); + float2 delta = abs(neighbours.xx - float2(neighbours.y, neighbours.z)); + float2 edges = step(SMAA_DEPTH_THRESHOLD, delta); + + if (dot(edges, float2(1.0, 1.0)) == 0.0) + discard; + + return edges; +} + +//----------------------------------------------------------------------------- +// Diagonal Search Functions + +#if !defined(SMAA_DISABLE_DIAG_DETECTION) + +/** + * Allows to decode two binary values from a bilinear-filtered access. + */ +float2 SMAADecodeDiagBilinearAccess(float2 e) { + // Bilinear access for fetching 'e' have a 0.25 offset, and we are + // interested in the R and G edges: + // + // +---G---+-------+ + // | x o R x | + // +-------+-------+ + // + // Then, if one of these edge is enabled: + // Red: (0.75 * X + 0.25 * 1) => 0.25 or 1.0 + // Green: (0.75 * 1 + 0.25 * X) => 0.75 or 1.0 + // + // This function will unpack the values (mad + mul + round): + // wolframalpha.com: round(x * abs(5 * x - 5 * 0.75)) plot 0 to 1 + e.r = e.r * abs(5.0 * e.r - 5.0 * 0.75); + return round(e); +} + +float4 SMAADecodeDiagBilinearAccess(float4 e) { + e.rb = e.rb * abs(5.0 * e.rb - 5.0 * 0.75); + return round(e); +} + +/** + * These functions allows to perform diagonal pattern searches. + */ +float2 SMAASearchDiag1(SMAATexture2D(edgesTex), float2 texcoord, float2 dir, out float2 e) { + float4 coord = float4(texcoord, -1.0, 1.0); + float3 t = float3(SMAA_RT_METRICS.xy, 1.0); + while (coord.z < float(SMAA_MAX_SEARCH_STEPS_DIAG - 1) && + coord.w > 0.9) { + coord.xyz = mad(t, float3(dir, 1.0), coord.xyz); + e = SMAASampleLevelZero(edgesTex, coord.xy).rg; + coord.w = dot(e, float2(0.5, 0.5)); + } + return coord.zw; +} + +float2 SMAASearchDiag2(SMAATexture2D(edgesTex), float2 texcoord, float2 dir, out float2 e) { + float4 coord = float4(texcoord, -1.0, 1.0); + coord.x += 0.25 * SMAA_RT_METRICS.x; // See @SearchDiag2Optimization + float3 t = float3(SMAA_RT_METRICS.xy, 1.0); + while (coord.z < float(SMAA_MAX_SEARCH_STEPS_DIAG - 1) && + coord.w > 0.9) { + coord.xyz = mad(t, float3(dir, 1.0), coord.xyz); + + // @SearchDiag2Optimization + // Fetch both edges at once using bilinear filtering: + e = SMAASampleLevelZero(edgesTex, coord.xy).rg; + e = SMAADecodeDiagBilinearAccess(e); + + // Non-optimized version: + // e.g = SMAASampleLevelZero(edgesTex, coord.xy).g; + // e.r = SMAASampleLevelZeroOffset(edgesTex, coord.xy, int2(1, 0)).r; + + coord.w = dot(e, float2(0.5, 0.5)); + } + return coord.zw; +} + +/** + * Similar to SMAAArea, this calculates the area corresponding to a certain + * diagonal distance and crossing edges 'e'. + */ +float2 SMAAAreaDiag(SMAATexture2D(areaTex), float2 dist, float2 e, float offset) { + float2 texcoord = mad(float2(SMAA_AREATEX_MAX_DISTANCE_DIAG, SMAA_AREATEX_MAX_DISTANCE_DIAG), e, dist); + + // We do a scale and bias for mapping to texel space: + texcoord = mad(SMAA_AREATEX_PIXEL_SIZE, texcoord, 0.5 * SMAA_AREATEX_PIXEL_SIZE); + + // Diagonal areas are on the second half of the texture: + texcoord.x += 0.5; + + // Move to proper place, according to the subpixel offset: + texcoord.y += SMAA_AREATEX_SUBTEX_SIZE * offset; + + // Do it! + return SMAA_AREATEX_SELECT(SMAASampleLevelZero(areaTex, texcoord)); +} + +/** + * This searches for diagonal patterns and returns the corresponding weights. + */ +float2 SMAACalculateDiagWeights(SMAATexture2D(edgesTex), SMAATexture2D(areaTex), float2 texcoord, float2 e, float4 subsampleIndices) { + float2 weights = float2(0.0, 0.0); + + // Search for the line ends: + float4 d; + float2 end; + if (e.r > 0.0) { + d.xz = SMAASearchDiag1(SMAATexturePass2D(edgesTex), texcoord, float2(-1.0, 1.0), end); + d.x += float(end.y > 0.9); + } else + d.xz = float2(0.0, 0.0); + d.yw = SMAASearchDiag1(SMAATexturePass2D(edgesTex), texcoord, float2(1.0, -1.0), end); + + SMAA_BRANCH + if (d.x + d.y > 2.0) { // d.x + d.y + 1 > 3 + // Fetch the crossing edges: + float4 coords = mad(float4(-d.x + 0.25, d.x, d.y, -d.y - 0.25), SMAA_RT_METRICS.xyxy, texcoord.xyxy); + float4 c; + c.xy = SMAASampleLevelZeroOffset(edgesTex, coords.xy, int2(-1, 0)).rg; + c.zw = SMAASampleLevelZeroOffset(edgesTex, coords.zw, int2( 1, 0)).rg; + c.yxwz = SMAADecodeDiagBilinearAccess(c.xyzw); + + // Non-optimized version: + // float4 coords = mad(float4(-d.x, d.x, d.y, -d.y), SMAA_RT_METRICS.xyxy, texcoord.xyxy); + // float4 c; + // c.x = SMAASampleLevelZeroOffset(edgesTex, coords.xy, int2(-1, 0)).g; + // c.y = SMAASampleLevelZeroOffset(edgesTex, coords.xy, int2( 0, 0)).r; + // c.z = SMAASampleLevelZeroOffset(edgesTex, coords.zw, int2( 1, 0)).g; + // c.w = SMAASampleLevelZeroOffset(edgesTex, coords.zw, int2( 1, -1)).r; + + // Merge crossing edges at each side into a single value: + float2 cc = mad(float2(2.0, 2.0), c.xz, c.yw); + + // Remove the crossing edge if we didn't found the end of the line: + SMAAMovc(bool2(step(0.9, d.zw)), cc, float2(0.0, 0.0)); + + // Fetch the areas for this line: + weights += SMAAAreaDiag(SMAATexturePass2D(areaTex), d.xy, cc, subsampleIndices.z); + } + + // Search for the line ends: + d.xz = SMAASearchDiag2(SMAATexturePass2D(edgesTex), texcoord, float2(-1.0, -1.0), end); + if (SMAASampleLevelZeroOffset(edgesTex, texcoord, int2(1, 0)).r > 0.0) { + d.yw = SMAASearchDiag2(SMAATexturePass2D(edgesTex), texcoord, float2(1.0, 1.0), end); + d.y += float(end.y > 0.9); + } else + d.yw = float2(0.0, 0.0); + + SMAA_BRANCH + if (d.x + d.y > 2.0) { // d.x + d.y + 1 > 3 + // Fetch the crossing edges: + float4 coords = mad(float4(-d.x, -d.x, d.y, d.y), SMAA_RT_METRICS.xyxy, texcoord.xyxy); + float4 c; + c.x = SMAASampleLevelZeroOffset(edgesTex, coords.xy, int2(-1, 0)).g; + c.y = SMAASampleLevelZeroOffset(edgesTex, coords.xy, int2( 0, -1)).r; + c.zw = SMAASampleLevelZeroOffset(edgesTex, coords.zw, int2( 1, 0)).gr; + float2 cc = mad(float2(2.0, 2.0), c.xz, c.yw); + + // Remove the crossing edge if we didn't found the end of the line: + SMAAMovc(bool2(step(0.9, d.zw)), cc, float2(0.0, 0.0)); + + // Fetch the areas for this line: + weights += SMAAAreaDiag(SMAATexturePass2D(areaTex), d.xy, cc, subsampleIndices.w).gr; + } + + return weights; +} +#endif + +//----------------------------------------------------------------------------- +// Horizontal/Vertical Search Functions + +/** + * This allows to determine how much length should we add in the last step + * of the searches. It takes the bilinearly interpolated edge (see + * @PSEUDO_GATHER4), and adds 0, 1 or 2, depending on which edges and + * crossing edges are active. + */ +float SMAASearchLength(SMAATexture2D(searchTex), float2 e, float offset) { + // The texture is flipped vertically, with left and right cases taking half + // of the space horizontally: + float2 scale = SMAA_SEARCHTEX_SIZE * float2(0.5, -1.0); + float2 bias = SMAA_SEARCHTEX_SIZE * float2(offset, 1.0); + + // Scale and bias to access texel centers: + scale += float2(-1.0, 1.0); + bias += float2( 0.5, -0.5); + + // Convert from pixel coordinates to texcoords: + // (We use SMAA_SEARCHTEX_PACKED_SIZE because the texture is cropped) + scale *= 1.0 / SMAA_SEARCHTEX_PACKED_SIZE; + bias *= 1.0 / SMAA_SEARCHTEX_PACKED_SIZE; + + // Lookup the search texture: + return SMAA_SEARCHTEX_SELECT(SMAASampleLevelZero(searchTex, mad(scale, e, bias))); +} + +/** + * Horizontal/vertical search functions for the 2nd pass. + */ +float SMAASearchXLeft(SMAATexture2D(edgesTex), SMAATexture2D(searchTex), float2 texcoord, float end) { + /** + * @PSEUDO_GATHER4 + * This texcoord has been offset by (-0.25, -0.125) in the vertex shader to + * sample between edge, thus fetching four edges in a row. + * Sampling with different offsets in each direction allows to disambiguate + * which edges are active from the four fetched ones. + */ + float2 e = float2(0.0, 1.0); + while (texcoord.x > end && + e.g > 0.8281 && // Is there some edge not activated? + e.r == 0.0) { // Or is there a crossing edge that breaks the line? + e = SMAASampleLevelZero(edgesTex, texcoord).rg; + texcoord = mad(-float2(2.0, 0.0), SMAA_RT_METRICS.xy, texcoord); + } + + float offset = mad(-(255.0 / 127.0), SMAASearchLength(SMAATexturePass2D(searchTex), e, 0.0), 3.25); + return mad(SMAA_RT_METRICS.x, offset, texcoord.x); + + // Non-optimized version: + // We correct the previous (-0.25, -0.125) offset we applied: + // texcoord.x += 0.25 * SMAA_RT_METRICS.x; + + // The searches are bias by 1, so adjust the coords accordingly: + // texcoord.x += SMAA_RT_METRICS.x; + + // Disambiguate the length added by the last step: + // texcoord.x += 2.0 * SMAA_RT_METRICS.x; // Undo last step + // texcoord.x -= SMAA_RT_METRICS.x * (255.0 / 127.0) * SMAASearchLength(SMAATexturePass2D(searchTex), e, 0.0); + // return mad(SMAA_RT_METRICS.x, offset, texcoord.x); +} + +float SMAASearchXRight(SMAATexture2D(edgesTex), SMAATexture2D(searchTex), float2 texcoord, float end) { + float2 e = float2(0.0, 1.0); + while (texcoord.x < end && + e.g > 0.8281 && // Is there some edge not activated? + e.r == 0.0) { // Or is there a crossing edge that breaks the line? + e = SMAASampleLevelZero(edgesTex, texcoord).rg; + texcoord = mad(float2(2.0, 0.0), SMAA_RT_METRICS.xy, texcoord); + } + float offset = mad(-(255.0 / 127.0), SMAASearchLength(SMAATexturePass2D(searchTex), e, 0.5), 3.25); + return mad(-SMAA_RT_METRICS.x, offset, texcoord.x); +} + +float SMAASearchYUp(SMAATexture2D(edgesTex), SMAATexture2D(searchTex), float2 texcoord, float end) { + float2 e = float2(1.0, 0.0); + while (texcoord.y > end && + e.r > 0.8281 && // Is there some edge not activated? + e.g == 0.0) { // Or is there a crossing edge that breaks the line? + e = SMAASampleLevelZero(edgesTex, texcoord).rg; + texcoord = mad(-float2(0.0, 2.0), SMAA_RT_METRICS.xy, texcoord); + } + float offset = mad(-(255.0 / 127.0), SMAASearchLength(SMAATexturePass2D(searchTex), e.gr, 0.0), 3.25); + return mad(SMAA_RT_METRICS.y, offset, texcoord.y); +} + +float SMAASearchYDown(SMAATexture2D(edgesTex), SMAATexture2D(searchTex), float2 texcoord, float end) { + float2 e = float2(1.0, 0.0); + while (texcoord.y < end && + e.r > 0.8281 && // Is there some edge not activated? + e.g == 0.0) { // Or is there a crossing edge that breaks the line? + e = SMAASampleLevelZero(edgesTex, texcoord).rg; + texcoord = mad(float2(0.0, 2.0), SMAA_RT_METRICS.xy, texcoord); + } + float offset = mad(-(255.0 / 127.0), SMAASearchLength(SMAATexturePass2D(searchTex), e.gr, 0.5), 3.25); + return mad(-SMAA_RT_METRICS.y, offset, texcoord.y); +} + +/** + * Ok, we have the distance and both crossing edges. So, what are the areas + * at each side of current edge? + */ +float2 SMAAArea(SMAATexture2D(areaTex), float2 dist, float e1, float e2, float offset) { + // Rounding prevents precision errors of bilinear filtering: + float2 texcoord = mad(float2(SMAA_AREATEX_MAX_DISTANCE, SMAA_AREATEX_MAX_DISTANCE), round(4.0 * float2(e1, e2)), dist); + + // We do a scale and bias for mapping to texel space: + texcoord = mad(SMAA_AREATEX_PIXEL_SIZE, texcoord, 0.5 * SMAA_AREATEX_PIXEL_SIZE); + + // Move to proper place, according to the subpixel offset: + texcoord.y = mad(SMAA_AREATEX_SUBTEX_SIZE, offset, texcoord.y); + + // Do it! + return SMAA_AREATEX_SELECT(SMAASampleLevelZero(areaTex, texcoord)); +} + +//----------------------------------------------------------------------------- +// Corner Detection Functions + +void SMAADetectHorizontalCornerPattern(SMAATexture2D(edgesTex), inout float2 weights, float4 texcoord, float2 d) { + #if !defined(SMAA_DISABLE_CORNER_DETECTION) + float2 leftRight = step(d.xy, d.yx); + float2 rounding = (1.0 - SMAA_CORNER_ROUNDING_NORM) * leftRight; + + rounding /= leftRight.x + leftRight.y; // Reduce blending for pixels in the center of a line. + + float2 factor = float2(1.0, 1.0); + factor.x -= rounding.x * SMAASampleLevelZeroOffset(edgesTex, texcoord.xy, int2(0, 1)).r; + factor.x -= rounding.y * SMAASampleLevelZeroOffset(edgesTex, texcoord.zw, int2(1, 1)).r; + factor.y -= rounding.x * SMAASampleLevelZeroOffset(edgesTex, texcoord.xy, int2(0, -2)).r; + factor.y -= rounding.y * SMAASampleLevelZeroOffset(edgesTex, texcoord.zw, int2(1, -2)).r; + + weights *= saturate(factor); + #endif +} + +void SMAADetectVerticalCornerPattern(SMAATexture2D(edgesTex), inout float2 weights, float4 texcoord, float2 d) { + #if !defined(SMAA_DISABLE_CORNER_DETECTION) + float2 leftRight = step(d.xy, d.yx); + float2 rounding = (1.0 - SMAA_CORNER_ROUNDING_NORM) * leftRight; + + rounding /= leftRight.x + leftRight.y; + + float2 factor = float2(1.0, 1.0); + factor.x -= rounding.x * SMAASampleLevelZeroOffset(edgesTex, texcoord.xy, int2( 1, 0)).g; + factor.x -= rounding.y * SMAASampleLevelZeroOffset(edgesTex, texcoord.zw, int2( 1, 1)).g; + factor.y -= rounding.x * SMAASampleLevelZeroOffset(edgesTex, texcoord.xy, int2(-2, 0)).g; + factor.y -= rounding.y * SMAASampleLevelZeroOffset(edgesTex, texcoord.zw, int2(-2, 1)).g; + + weights *= saturate(factor); + #endif +} + +//----------------------------------------------------------------------------- +// Blending Weight Calculation Pixel Shader (Second Pass) + +float4 SMAABlendingWeightCalculationPS(float2 texcoord, + float2 pixcoord, + float4 offset[3], + SMAATexture2D(edgesTex), + SMAATexture2D(areaTex), + SMAATexture2D(searchTex), + float4 subsampleIndices) { // Just pass zero for SMAA 1x, see @SUBSAMPLE_INDICES. + float4 weights = float4(0.0, 0.0, 0.0, 0.0); + + float2 e = SMAASample(edgesTex, texcoord).rg; + + SMAA_BRANCH + if (e.g > 0.0) { // Edge at north + #if !defined(SMAA_DISABLE_DIAG_DETECTION) + // Diagonals have both north and west edges, so searching for them in + // one of the boundaries is enough. + weights.rg = SMAACalculateDiagWeights(SMAATexturePass2D(edgesTex), SMAATexturePass2D(areaTex), texcoord, e, subsampleIndices); + + // We give priority to diagonals, so if we find a diagonal we skip + // horizontal/vertical processing. + SMAA_BRANCH + if (weights.r == -weights.g) { // weights.r + weights.g == 0.0 + #endif + + float2 d; + + // Find the distance to the left: + float3 coords; + coords.x = SMAASearchXLeft(SMAATexturePass2D(edgesTex), SMAATexturePass2D(searchTex), offset[0].xy, offset[2].x); + coords.y = offset[1].y; // offset[1].y = texcoord.y - 0.25 * SMAA_RT_METRICS.y (@CROSSING_OFFSET) + d.x = coords.x; + + // Now fetch the left crossing edges, two at a time using bilinear + // filtering. Sampling at -0.25 (see @CROSSING_OFFSET) enables to + // discern what value each edge has: + float e1 = SMAASampleLevelZero(edgesTex, coords.xy).r; + + // Find the distance to the right: + coords.z = SMAASearchXRight(SMAATexturePass2D(edgesTex), SMAATexturePass2D(searchTex), offset[0].zw, offset[2].y); + d.y = coords.z; + + // We want the distances to be in pixel units (doing this here allow to + // better interleave arithmetic and memory accesses): + d = abs(round(mad(SMAA_RT_METRICS.zz, d, -pixcoord.xx))); + + // SMAAArea below needs a sqrt, as the areas texture is compressed + // quadratically: + float2 sqrt_d = sqrt(d); + + // Fetch the right crossing edges: + float e2 = SMAASampleLevelZeroOffset(edgesTex, coords.zy, int2(1, 0)).r; + + // Ok, we know how this pattern looks like, now it is time for getting + // the actual area: + weights.rg = SMAAArea(SMAATexturePass2D(areaTex), sqrt_d, e1, e2, subsampleIndices.y); + + // Fix corners: + coords.y = texcoord.y; + SMAADetectHorizontalCornerPattern(SMAATexturePass2D(edgesTex), weights.rg, coords.xyzy, d); + + #if !defined(SMAA_DISABLE_DIAG_DETECTION) + } else + e.r = 0.0; // Skip vertical processing. + #endif + } + + SMAA_BRANCH + if (e.r > 0.0) { // Edge at west + float2 d; + + // Find the distance to the top: + float3 coords; + coords.y = SMAASearchYUp(SMAATexturePass2D(edgesTex), SMAATexturePass2D(searchTex), offset[1].xy, offset[2].z); + coords.x = offset[0].x; // offset[1].x = texcoord.x - 0.25 * SMAA_RT_METRICS.x; + d.x = coords.y; + + // Fetch the top crossing edges: + float e1 = SMAASampleLevelZero(edgesTex, coords.xy).g; + + // Find the distance to the bottom: + coords.z = SMAASearchYDown(SMAATexturePass2D(edgesTex), SMAATexturePass2D(searchTex), offset[1].zw, offset[2].w); + d.y = coords.z; + + // We want the distances to be in pixel units: + d = abs(round(mad(SMAA_RT_METRICS.ww, d, -pixcoord.yy))); + + // SMAAArea below needs a sqrt, as the areas texture is compressed + // quadratically: + float2 sqrt_d = sqrt(d); + + // Fetch the bottom crossing edges: + float e2 = SMAASampleLevelZeroOffset(edgesTex, coords.xz, int2(0, 1)).g; + + // Get the area for this direction: + weights.ba = SMAAArea(SMAATexturePass2D(areaTex), sqrt_d, e1, e2, subsampleIndices.x); + + // Fix corners: + coords.x = texcoord.x; + SMAADetectVerticalCornerPattern(SMAATexturePass2D(edgesTex), weights.ba, coords.xyxz, d); + } + + return weights; +} + +//----------------------------------------------------------------------------- +// Neighborhood Blending Pixel Shader (Third Pass) + +float4 SMAANeighborhoodBlendingPS(float2 texcoord, + float4 offset, + SMAATexture2D(colorTex), + SMAATexture2D(blendTex) + #if SMAA_REPROJECTION + , SMAATexture2D(velocityTex) + #endif + ) { + // Fetch the blending weights for current pixel: + float4 a; + a.x = SMAASample(blendTex, offset.xy).a; // Right + a.y = SMAASample(blendTex, offset.zw).g; // Top + a.wz = SMAASample(blendTex, texcoord).xz; // Bottom / Left + + // Is there any blending weight with a value greater than 0.0? + SMAA_BRANCH + if (dot(a, float4(1.0, 1.0, 1.0, 1.0)) < 1e-5) { + float4 color = SMAASampleLevelZero(colorTex, texcoord); + + #if SMAA_REPROJECTION + float2 velocity = SMAA_DECODE_VELOCITY(SMAASampleLevelZero(velocityTex, texcoord)); + + // Pack velocity into the alpha channel: + color.a = sqrt(5.0 * length(velocity)); + #endif + + return color; + } else { + bool h = max(a.x, a.z) > max(a.y, a.w); // max(horizontal) > max(vertical) + + // Calculate the blending offsets: + float4 blendingOffset = float4(0.0, a.y, 0.0, a.w); + float2 blendingWeight = a.yw; + SMAAMovc(bool4(h, h, h, h), blendingOffset, float4(a.x, 0.0, a.z, 0.0)); + SMAAMovc(bool2(h, h), blendingWeight, a.xz); + blendingWeight /= dot(blendingWeight, float2(1.0, 1.0)); + + // Calculate the texture coordinates: + float4 blendingCoord = mad(blendingOffset, float4(SMAA_RT_METRICS.xy, -SMAA_RT_METRICS.xy), texcoord.xyxy); + + // We exploit bilinear filtering to mix current pixel with the chosen + // neighbor: + float4 color = blendingWeight.x * SMAASampleLevelZero(colorTex, blendingCoord.xy); + color += blendingWeight.y * SMAASampleLevelZero(colorTex, blendingCoord.zw); + + #if SMAA_REPROJECTION + // Antialias velocity for proper reprojection in a later stage: + float2 velocity = blendingWeight.x * SMAA_DECODE_VELOCITY(SMAASampleLevelZero(velocityTex, blendingCoord.xy)); + velocity += blendingWeight.y * SMAA_DECODE_VELOCITY(SMAASampleLevelZero(velocityTex, blendingCoord.zw)); + + // Pack velocity into the alpha channel: + color.a = sqrt(5.0 * length(velocity)); + #endif + + return color; + } +} + +//----------------------------------------------------------------------------- +// Temporal Resolve Pixel Shader (Optional Pass) + +float4 SMAAResolvePS(float2 texcoord, + SMAATexture2D(currentColorTex), + SMAATexture2D(previousColorTex) + #if SMAA_REPROJECTION + , SMAATexture2D(velocityTex) + #endif + ) { + #if SMAA_REPROJECTION + // Velocity is assumed to be calculated for motion blur, so we need to + // inverse it for reprojection: + float2 velocity = -SMAA_DECODE_VELOCITY(SMAASamplePoint(velocityTex, texcoord).rg); + + // Fetch current pixel: + float4 current = SMAASamplePoint(currentColorTex, texcoord); + + // Reproject current coordinates and fetch previous pixel: + float4 previous = SMAASamplePoint(previousColorTex, texcoord + velocity); + + // Attenuate the previous pixel if the velocity is different: + float delta = abs(current.a * current.a - previous.a * previous.a) / 5.0; + float weight = 0.5 * saturate(1.0 - sqrt(delta) * SMAA_REPROJECTION_WEIGHT_SCALE); + + // Blend the pixels according to the calculated weight: + return lerp(current, previous, weight); + #else + // Just blend the pixels: + float4 current = SMAASamplePoint(currentColorTex, texcoord); + float4 previous = SMAASamplePoint(previousColorTex, texcoord); + return lerp(current, previous, 0.5); + #endif +} + +//----------------------------------------------------------------------------- +// Separate Multisamples Pixel Shader (Optional Pass) + +#ifdef SMAALoad +void SMAASeparatePS(float4 position, + float2 texcoord, + out float4 target0, + out float4 target1, + SMAATexture2DMS2(colorTexMS)) { + int2 pos = int2(position.xy); + target0 = SMAALoad(colorTexMS, pos, 0); + target1 = SMAALoad(colorTexMS, pos, 1); +} +#endif + +//----------------------------------------------------------------------------- +#endif // SMAA_INCLUDE_PS diff --git a/app/src/main/cpp/shaders/THIRD_PARTY_NOTICES.txt b/app/src/main/cpp/shaders/THIRD_PARTY_NOTICES.txt index 761743c464..ffbc6b370b 100644 --- a/app/src/main/cpp/shaders/THIRD_PARTY_NOTICES.txt +++ b/app/src/main/cpp/shaders/THIRD_PARTY_NOTICES.txt @@ -124,3 +124,33 @@ 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. + +SMAA (Enhanced Subpixel Morphological Antialiasing) +--------------------------------------------------- +SMAA.hlsl and the lookup tables in smaa_tables.h are from the authors' reference +implementation (github.com/iryoku/smaa). + +Copyright (C) 2013 Jorge Jimenez (jorge@iryoku.com) +Copyright (C) 2013 Jose I. Echevarria (joseignacioechevarria@gmail.com) +Copyright (C) 2013 Belen Masia (bmasia@unizar.es) +Copyright (C) 2013 Fernando Navarro (fernandn@microsoft.com) +Copyright (C) 2013 Diego Gutierrez (diegog@unizar.es) + +Permission is hereby granted, free of charge, to any person obtaining a copy +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. As clarification, there is no +requirement that the copyright notice and permission be included in binary +distributions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/app/src/main/cpp/shaders/smaa_blend.frag b/app/src/main/cpp/shaders/smaa_blend.frag index cf4a2302a6..cd36894637 100644 --- a/app/src/main/cpp/shaders/smaa_blend.frag +++ b/app/src/main/cpp/shaders/smaa_blend.frag @@ -1,4 +1,5 @@ #version 450 +#extension GL_GOOGLE_include_directive : require layout(location = 0) in vec2 fragTexCoord; layout(location = 0) out vec4 outColor; @@ -6,25 +7,16 @@ layout(set = 0, binding = 0) uniform sampler2D InputTexture; layout(set = 1, binding = 0) uniform sampler2D WeightTexture; layout(push_constant) uniform Constants { vec4 ndc; - vec2 resolution; - float extra; - float pad; + vec4 metrics; // 1/width, 1/height, width, height } pc; +#define SMAA_RT_METRICS pc.metrics +#define SMAA_GLSL_4 +#define SMAA_PRESET_HIGH +#include "SMAA.hlsl" + void main() { - vec2 px = 1.0 / max(pc.resolution, vec2(1.0)); - vec2 uv = clamp(fragTexCoord, px * 0.5, vec2(1.0) - px * 0.5); - vec4 center = texture(InputTexture, uv); - vec4 weights = texture(WeightTexture, uv); - float weight = clamp(weights.r, 0.0, 0.42); - - if (weight <= 0.001) { - outColor = center; - return; - } - - vec2 normal = weights.gb * 2.0 - 1.0; - vec2 acrossUv = clamp(uv + normal * px, px * 0.5, vec2(1.0) - px * 0.5); - vec3 across = texture(InputTexture, acrossUv).rgb; - outColor = vec4(mix(center.rgb, across, weight), center.a); + vec4 offset; + SMAANeighborhoodBlendingVS(fragTexCoord, offset); + outColor = SMAANeighborhoodBlendingPS(fragTexCoord, offset, InputTexture, WeightTexture); } diff --git a/app/src/main/cpp/shaders/smaa_blend_frag.h b/app/src/main/cpp/shaders/smaa_blend_frag.h index bcb4749618..55ca213931 100644 --- a/app/src/main/cpp/shaders/smaa_blend_frag.h +++ b/app/src/main/cpp/shaders/smaa_blend_frag.h @@ -1,88 +1,204 @@ - // 1116.3.0 + // 1116.6.0 #pragma once const uint32_t smaa_blend_code[] = { - 0x07230203,0x00010000,0x0008000b,0x0000006b,0x00000000,0x00020011,0x00000001,0x0006000b, + 0x07230203,0x00010000,0x0008000b,0x000000f8,0x00000000,0x00020011,0x00000001,0x0006000b, 0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001, - 0x0007000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x0000001a,0x00000041,0x00030010, - 0x00000004,0x00000007,0x00030003,0x00000002,0x000001c2,0x00040005,0x00000004,0x6e69616d, - 0x00000000,0x00030005,0x00000009,0x00007870,0x00050005,0x0000000c,0x736e6f43,0x746e6174, - 0x00000073,0x00040006,0x0000000c,0x00000000,0x0063646e,0x00060006,0x0000000c,0x00000001, - 0x6f736572,0x6974756c,0x00006e6f,0x00050006,0x0000000c,0x00000002,0x72747865,0x00000061, - 0x00040006,0x0000000c,0x00000003,0x00646170,0x00030005,0x0000000e,0x00006370,0x00030005, - 0x00000018,0x00007675,0x00060005,0x0000001a,0x67617266,0x43786554,0x64726f6f,0x00000000, - 0x00040005,0x00000024,0x746e6563,0x00007265,0x00060005,0x00000028,0x75706e49,0x78655474, - 0x65727574,0x00000000,0x00040005,0x0000002c,0x67696577,0x00737468,0x00060005,0x0000002d, - 0x67696557,0x65547468,0x72757478,0x00000065,0x00040005,0x00000032,0x67696577,0x00007468, - 0x00050005,0x00000041,0x4374756f,0x726f6c6f,0x00000000,0x00040005,0x00000044,0x6d726f6e, - 0x00006c61,0x00050005,0x0000004b,0x6f726361,0x76557373,0x00000000,0x00040005,0x00000059, - 0x6f726361,0x00007373,0x00030047,0x0000000c,0x00000002,0x00050048,0x0000000c,0x00000000, - 0x00000023,0x00000000,0x00050048,0x0000000c,0x00000001,0x00000023,0x00000010,0x00050048, - 0x0000000c,0x00000002,0x00000023,0x00000018,0x00050048,0x0000000c,0x00000003,0x00000023, - 0x0000001c,0x00040047,0x0000001a,0x0000001e,0x00000000,0x00040047,0x00000028,0x00000021, - 0x00000000,0x00040047,0x00000028,0x00000022,0x00000000,0x00040047,0x0000002d,0x00000021, - 0x00000000,0x00040047,0x0000002d,0x00000022,0x00000001,0x00040047,0x00000041,0x0000001e, - 0x00000000,0x00020013,0x00000002,0x00030021,0x00000003,0x00000002,0x00030016,0x00000006, - 0x00000020,0x00040017,0x00000007,0x00000006,0x00000002,0x00040020,0x00000008,0x00000007, - 0x00000007,0x0004002b,0x00000006,0x0000000a,0x3f800000,0x00040017,0x0000000b,0x00000006, - 0x00000004,0x0006001e,0x0000000c,0x0000000b,0x00000007,0x00000006,0x00000006,0x00040020, - 0x0000000d,0x00000009,0x0000000c,0x0004003b,0x0000000d,0x0000000e,0x00000009,0x00040015, - 0x0000000f,0x00000020,0x00000001,0x0004002b,0x0000000f,0x00000010,0x00000001,0x00040020, - 0x00000011,0x00000009,0x00000007,0x0005002c,0x00000007,0x00000014,0x0000000a,0x0000000a, - 0x00040020,0x00000019,0x00000001,0x00000007,0x0004003b,0x00000019,0x0000001a,0x00000001, - 0x0004002b,0x00000006,0x0000001d,0x3f000000,0x00040020,0x00000023,0x00000007,0x0000000b, - 0x00090019,0x00000025,0x00000006,0x00000001,0x00000000,0x00000000,0x00000000,0x00000001, - 0x00000000,0x0003001b,0x00000026,0x00000025,0x00040020,0x00000027,0x00000000,0x00000026, - 0x0004003b,0x00000027,0x00000028,0x00000000,0x0004003b,0x00000027,0x0000002d,0x00000000, - 0x00040020,0x00000031,0x00000007,0x00000006,0x00040015,0x00000033,0x00000020,0x00000000, - 0x0004002b,0x00000033,0x00000034,0x00000000,0x0004002b,0x00000006,0x00000037,0x00000000, - 0x0004002b,0x00000006,0x00000038,0x3ed70a3d,0x0004002b,0x00000006,0x0000003b,0x3a83126f, - 0x00020014,0x0000003c,0x00040020,0x00000040,0x00000003,0x0000000b,0x0004003b,0x00000040, - 0x00000041,0x00000003,0x0004002b,0x00000006,0x00000047,0x40000000,0x00040017,0x00000057, - 0x00000006,0x00000003,0x00040020,0x00000058,0x00000007,0x00000057,0x0004002b,0x00000033, - 0x00000064,0x00000003,0x00050036,0x00000002,0x00000004,0x00000000,0x00000003,0x000200f8, - 0x00000005,0x0004003b,0x00000008,0x00000009,0x00000007,0x0004003b,0x00000008,0x00000018, - 0x00000007,0x0004003b,0x00000023,0x00000024,0x00000007,0x0004003b,0x00000023,0x0000002c, - 0x00000007,0x0004003b,0x00000031,0x00000032,0x00000007,0x0004003b,0x00000008,0x00000044, - 0x00000007,0x0004003b,0x00000008,0x0000004b,0x00000007,0x0004003b,0x00000058,0x00000059, - 0x00000007,0x00050041,0x00000011,0x00000012,0x0000000e,0x00000010,0x0004003d,0x00000007, - 0x00000013,0x00000012,0x0007000c,0x00000007,0x00000015,0x00000001,0x00000028,0x00000013, - 0x00000014,0x00050050,0x00000007,0x00000016,0x0000000a,0x0000000a,0x00050088,0x00000007, - 0x00000017,0x00000016,0x00000015,0x0003003e,0x00000009,0x00000017,0x0004003d,0x00000007, - 0x0000001b,0x0000001a,0x0004003d,0x00000007,0x0000001c,0x00000009,0x0005008e,0x00000007, - 0x0000001e,0x0000001c,0x0000001d,0x0004003d,0x00000007,0x0000001f,0x00000009,0x0005008e, - 0x00000007,0x00000020,0x0000001f,0x0000001d,0x00050083,0x00000007,0x00000021,0x00000014, - 0x00000020,0x0008000c,0x00000007,0x00000022,0x00000001,0x0000002b,0x0000001b,0x0000001e, - 0x00000021,0x0003003e,0x00000018,0x00000022,0x0004003d,0x00000026,0x00000029,0x00000028, - 0x0004003d,0x00000007,0x0000002a,0x00000018,0x00050057,0x0000000b,0x0000002b,0x00000029, - 0x0000002a,0x0003003e,0x00000024,0x0000002b,0x0004003d,0x00000026,0x0000002e,0x0000002d, - 0x0004003d,0x00000007,0x0000002f,0x00000018,0x00050057,0x0000000b,0x00000030,0x0000002e, - 0x0000002f,0x0003003e,0x0000002c,0x00000030,0x00050041,0x00000031,0x00000035,0x0000002c, - 0x00000034,0x0004003d,0x00000006,0x00000036,0x00000035,0x0008000c,0x00000006,0x00000039, - 0x00000001,0x0000002b,0x00000036,0x00000037,0x00000038,0x0003003e,0x00000032,0x00000039, - 0x0004003d,0x00000006,0x0000003a,0x00000032,0x000500bc,0x0000003c,0x0000003d,0x0000003a, - 0x0000003b,0x000300f7,0x0000003f,0x00000000,0x000400fa,0x0000003d,0x0000003e,0x0000003f, - 0x000200f8,0x0000003e,0x0004003d,0x0000000b,0x00000042,0x00000024,0x0003003e,0x00000041, - 0x00000042,0x000100fd,0x000200f8,0x0000003f,0x0004003d,0x0000000b,0x00000045,0x0000002c, - 0x0007004f,0x00000007,0x00000046,0x00000045,0x00000045,0x00000001,0x00000002,0x0005008e, - 0x00000007,0x00000048,0x00000046,0x00000047,0x00050050,0x00000007,0x00000049,0x0000000a, - 0x0000000a,0x00050083,0x00000007,0x0000004a,0x00000048,0x00000049,0x0003003e,0x00000044, - 0x0000004a,0x0004003d,0x00000007,0x0000004c,0x00000018,0x0004003d,0x00000007,0x0000004d, - 0x00000044,0x0004003d,0x00000007,0x0000004e,0x00000009,0x00050085,0x00000007,0x0000004f, - 0x0000004d,0x0000004e,0x00050081,0x00000007,0x00000050,0x0000004c,0x0000004f,0x0004003d, - 0x00000007,0x00000051,0x00000009,0x0005008e,0x00000007,0x00000052,0x00000051,0x0000001d, - 0x0004003d,0x00000007,0x00000053,0x00000009,0x0005008e,0x00000007,0x00000054,0x00000053, - 0x0000001d,0x00050083,0x00000007,0x00000055,0x00000014,0x00000054,0x0008000c,0x00000007, - 0x00000056,0x00000001,0x0000002b,0x00000050,0x00000052,0x00000055,0x0003003e,0x0000004b, - 0x00000056,0x0004003d,0x00000026,0x0000005a,0x00000028,0x0004003d,0x00000007,0x0000005b, - 0x0000004b,0x00050057,0x0000000b,0x0000005c,0x0000005a,0x0000005b,0x0008004f,0x00000057, - 0x0000005d,0x0000005c,0x0000005c,0x00000000,0x00000001,0x00000002,0x0003003e,0x00000059, - 0x0000005d,0x0004003d,0x0000000b,0x0000005e,0x00000024,0x0008004f,0x00000057,0x0000005f, - 0x0000005e,0x0000005e,0x00000000,0x00000001,0x00000002,0x0004003d,0x00000057,0x00000060, - 0x00000059,0x0004003d,0x00000006,0x00000061,0x00000032,0x00060050,0x00000057,0x00000062, - 0x00000061,0x00000061,0x00000061,0x0008000c,0x00000057,0x00000063,0x00000001,0x0000002e, - 0x0000005f,0x00000060,0x00000062,0x00050041,0x00000031,0x00000065,0x00000024,0x00000064, - 0x0004003d,0x00000006,0x00000066,0x00000065,0x00050051,0x00000006,0x00000067,0x00000063, - 0x00000000,0x00050051,0x00000006,0x00000068,0x00000063,0x00000001,0x00050051,0x00000006, - 0x00000069,0x00000063,0x00000002,0x00070050,0x0000000b,0x0000006a,0x00000067,0x00000068, - 0x00000069,0x00000066,0x0003003e,0x00000041,0x0000006a,0x000100fd,0x00010038 + 0x0007000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x000000e8,0x000000f0,0x00030010, + 0x00000004,0x00000007,0x00030003,0x00000002,0x000001c2,0x000a0004,0x475f4c47,0x4c474f4f, + 0x70635f45,0x74735f70,0x5f656c79,0x656e696c,0x7269645f,0x69746365,0x00006576,0x00080004, + 0x475f4c47,0x4c474f4f,0x6e695f45,0x64756c63,0x69645f65,0x74636572,0x00657669,0x00040005, + 0x00000004,0x6e69616d,0x00000000,0x00080005,0x00000010,0x41414d53,0x63766f4d,0x32627628, + 0x3266763b,0x3266763b,0x0000003b,0x00040005,0x0000000d,0x646e6f63,0x00000000,0x00050005, + 0x0000000e,0x69726176,0x656c6261,0x00000000,0x00040005,0x0000000f,0x756c6176,0x00000065, + 0x00080005,0x0000001a,0x41414d53,0x63766f4d,0x34627628,0x3466763b,0x3466763b,0x0000003b, + 0x00040005,0x00000017,0x646e6f63,0x00000000,0x00050005,0x00000018,0x69726176,0x656c6261, + 0x00000000,0x00040005,0x00000019,0x756c6176,0x00000065,0x000b0005,0x0000001f,0x41414d53, + 0x6769654e,0x726f6268,0x646f6f68,0x6e656c42,0x676e6964,0x76285356,0x763b3266,0x003b3466, + 0x00050005,0x0000001d,0x63786574,0x64726f6f,0x00000000,0x00040005,0x0000001e,0x7366666f, + 0x00007465,0x000d0005,0x00000029,0x41414d53,0x6769654e,0x726f6268,0x646f6f68,0x6e656c42, + 0x676e6964,0x76285350,0x763b3266,0x733b3466,0x733b3132,0x003b3132,0x00050005,0x00000025, + 0x63786574,0x64726f6f,0x00000000,0x00040005,0x00000026,0x7366666f,0x00007465,0x00050005, + 0x00000027,0x6f6c6f63,0x78655472,0x00000000,0x00050005,0x00000028,0x6e656c62,0x78655464, + 0x00000000,0x00040005,0x0000003e,0x61726170,0x0000006d,0x00040005,0x00000041,0x61726170, + 0x0000006d,0x00040005,0x00000044,0x61726170,0x0000006d,0x00040005,0x0000004d,0x61726170, + 0x0000006d,0x00040005,0x00000050,0x61726170,0x0000006d,0x00040005,0x00000053,0x61726170, + 0x0000006d,0x00050005,0x0000005e,0x736e6f43,0x746e6174,0x00000073,0x00040006,0x0000005e, + 0x00000000,0x0063646e,0x00050006,0x0000005e,0x00000001,0x7274656d,0x00736369,0x00030005, + 0x00000060,0x00006370,0x00030005,0x0000006d,0x00000061,0x00040005,0x00000089,0x6f6c6f63, + 0x00000072,0x00030005,0x00000090,0x00000068,0x00060005,0x0000009c,0x6e656c62,0x676e6964, + 0x7366664f,0x00007465,0x00060005,0x000000a2,0x6e656c62,0x676e6964,0x67696557,0x00007468, + 0x00040005,0x000000ac,0x61726170,0x0000006d,0x00040005,0x000000ad,0x61726170,0x0000006d, + 0x00040005,0x000000af,0x61726170,0x0000006d,0x00040005,0x000000b4,0x61726170,0x0000006d, + 0x00040005,0x000000b5,0x61726170,0x0000006d,0x00040005,0x000000b7,0x61726170,0x0000006d, + 0x00060005,0x000000c2,0x6e656c62,0x676e6964,0x726f6f43,0x00000064,0x00040005,0x000000d3, + 0x6f6c6f63,0x00000072,0x00060005,0x000000e8,0x67617266,0x43786554,0x64726f6f,0x00000000, + 0x00040005,0x000000e9,0x7366666f,0x00007465,0x00040005,0x000000ea,0x61726170,0x0000006d, + 0x00040005,0x000000ec,0x61726170,0x0000006d,0x00050005,0x000000f0,0x4374756f,0x726f6c6f, + 0x00000000,0x00060005,0x000000f1,0x75706e49,0x78655474,0x65727574,0x00000000,0x00060005, + 0x000000f2,0x67696557,0x65547468,0x72757478,0x00000065,0x00040005,0x000000f3,0x61726170, + 0x0000006d,0x00040005,0x000000f5,0x61726170,0x0000006d,0x00030047,0x0000005e,0x00000002, + 0x00050048,0x0000005e,0x00000000,0x00000023,0x00000000,0x00050048,0x0000005e,0x00000001, + 0x00000023,0x00000010,0x00040047,0x000000e8,0x0000001e,0x00000000,0x00040047,0x000000f0, + 0x0000001e,0x00000000,0x00040047,0x000000f1,0x00000021,0x00000000,0x00040047,0x000000f1, + 0x00000022,0x00000000,0x00040047,0x000000f2,0x00000021,0x00000000,0x00040047,0x000000f2, + 0x00000022,0x00000001,0x00020013,0x00000002,0x00030021,0x00000003,0x00000002,0x00020014, + 0x00000006,0x00040017,0x00000007,0x00000006,0x00000002,0x00040020,0x00000008,0x00000007, + 0x00000007,0x00030016,0x00000009,0x00000020,0x00040017,0x0000000a,0x00000009,0x00000002, + 0x00040020,0x0000000b,0x00000007,0x0000000a,0x00060021,0x0000000c,0x00000002,0x00000008, + 0x0000000b,0x0000000b,0x00040017,0x00000012,0x00000006,0x00000004,0x00040020,0x00000013, + 0x00000007,0x00000012,0x00040017,0x00000014,0x00000009,0x00000004,0x00040020,0x00000015, + 0x00000007,0x00000014,0x00060021,0x00000016,0x00000002,0x00000013,0x00000015,0x00000015, + 0x00050021,0x0000001c,0x00000002,0x0000000b,0x00000015,0x00090019,0x00000021,0x00000009, + 0x00000001,0x00000000,0x00000000,0x00000000,0x00000001,0x00000000,0x0003001b,0x00000022, + 0x00000021,0x00040020,0x00000023,0x00000000,0x00000022,0x00070021,0x00000024,0x00000014, + 0x0000000b,0x00000015,0x00000023,0x00000023,0x00040015,0x0000002b,0x00000020,0x00000000, + 0x0004002b,0x0000002b,0x0000002c,0x00000000,0x00040020,0x0000002d,0x00000007,0x00000006, + 0x00040020,0x00000032,0x00000007,0x00000009,0x0004002b,0x0000002b,0x00000036,0x00000001, + 0x0004002b,0x0000002b,0x00000058,0x00000002,0x0004002b,0x0000002b,0x0000005b,0x00000003, + 0x0004001e,0x0000005e,0x00000014,0x00000014,0x00040020,0x0000005f,0x00000009,0x0000005e, + 0x0004003b,0x0000005f,0x00000060,0x00000009,0x00040015,0x00000061,0x00000020,0x00000001, + 0x0004002b,0x00000061,0x00000062,0x00000001,0x00040020,0x00000063,0x00000009,0x00000014, + 0x0004002b,0x00000009,0x00000067,0x3f800000,0x0004002b,0x00000009,0x00000068,0x00000000, + 0x0007002c,0x00000014,0x00000069,0x00000067,0x00000068,0x00000068,0x00000067,0x0007002c, + 0x00000014,0x00000083,0x00000067,0x00000067,0x00000067,0x00000067,0x0004002b,0x00000009, + 0x00000085,0x3727c5ac,0x0005002c,0x0000000a,0x000000bd,0x00000067,0x00000067,0x00040020, + 0x000000e7,0x00000001,0x0000000a,0x0004003b,0x000000e7,0x000000e8,0x00000001,0x00040020, + 0x000000ef,0x00000003,0x00000014,0x0004003b,0x000000ef,0x000000f0,0x00000003,0x0004003b, + 0x00000023,0x000000f1,0x00000000,0x0004003b,0x00000023,0x000000f2,0x00000000,0x00050036, + 0x00000002,0x00000004,0x00000000,0x00000003,0x000200f8,0x00000005,0x0004003b,0x00000015, + 0x000000e9,0x00000007,0x0004003b,0x0000000b,0x000000ea,0x00000007,0x0004003b,0x00000015, + 0x000000ec,0x00000007,0x0004003b,0x0000000b,0x000000f3,0x00000007,0x0004003b,0x00000015, + 0x000000f5,0x00000007,0x0004003d,0x0000000a,0x000000eb,0x000000e8,0x0003003e,0x000000ea, + 0x000000eb,0x00060039,0x00000002,0x000000ed,0x0000001f,0x000000ea,0x000000ec,0x0004003d, + 0x00000014,0x000000ee,0x000000ec,0x0003003e,0x000000e9,0x000000ee,0x0004003d,0x0000000a, + 0x000000f4,0x000000e8,0x0003003e,0x000000f3,0x000000f4,0x0004003d,0x00000014,0x000000f6, + 0x000000e9,0x0003003e,0x000000f5,0x000000f6,0x00080039,0x00000014,0x000000f7,0x00000029, + 0x000000f3,0x000000f5,0x000000f1,0x000000f2,0x0003003e,0x000000f0,0x000000f7,0x000100fd, + 0x00010038,0x00050036,0x00000002,0x00000010,0x00000000,0x0000000c,0x00030037,0x00000008, + 0x0000000d,0x00030037,0x0000000b,0x0000000e,0x00030037,0x0000000b,0x0000000f,0x000200f8, + 0x00000011,0x00050041,0x0000002d,0x0000002e,0x0000000d,0x0000002c,0x0004003d,0x00000006, + 0x0000002f,0x0000002e,0x000300f7,0x00000031,0x00000000,0x000400fa,0x0000002f,0x00000030, + 0x00000031,0x000200f8,0x00000030,0x00050041,0x00000032,0x00000033,0x0000000f,0x0000002c, + 0x0004003d,0x00000009,0x00000034,0x00000033,0x00050041,0x00000032,0x00000035,0x0000000e, + 0x0000002c,0x0003003e,0x00000035,0x00000034,0x000200f9,0x00000031,0x000200f8,0x00000031, + 0x00050041,0x0000002d,0x00000037,0x0000000d,0x00000036,0x0004003d,0x00000006,0x00000038, + 0x00000037,0x000300f7,0x0000003a,0x00000000,0x000400fa,0x00000038,0x00000039,0x0000003a, + 0x000200f8,0x00000039,0x00050041,0x00000032,0x0000003b,0x0000000f,0x00000036,0x0004003d, + 0x00000009,0x0000003c,0x0000003b,0x00050041,0x00000032,0x0000003d,0x0000000e,0x00000036, + 0x0003003e,0x0000003d,0x0000003c,0x000200f9,0x0000003a,0x000200f8,0x0000003a,0x000100fd, + 0x00010038,0x00050036,0x00000002,0x0000001a,0x00000000,0x00000016,0x00030037,0x00000013, + 0x00000017,0x00030037,0x00000015,0x00000018,0x00030037,0x00000015,0x00000019,0x000200f8, + 0x0000001b,0x0004003b,0x00000008,0x0000003e,0x00000007,0x0004003b,0x0000000b,0x00000041, + 0x00000007,0x0004003b,0x0000000b,0x00000044,0x00000007,0x0004003b,0x00000008,0x0000004d, + 0x00000007,0x0004003b,0x0000000b,0x00000050,0x00000007,0x0004003b,0x0000000b,0x00000053, + 0x00000007,0x0004003d,0x00000012,0x0000003f,0x00000017,0x0007004f,0x00000007,0x00000040, + 0x0000003f,0x0000003f,0x00000000,0x00000001,0x0003003e,0x0000003e,0x00000040,0x0004003d, + 0x00000014,0x00000042,0x00000018,0x0007004f,0x0000000a,0x00000043,0x00000042,0x00000042, + 0x00000000,0x00000001,0x0003003e,0x00000041,0x00000043,0x0004003d,0x00000014,0x00000045, + 0x00000019,0x0007004f,0x0000000a,0x00000046,0x00000045,0x00000045,0x00000000,0x00000001, + 0x0003003e,0x00000044,0x00000046,0x00070039,0x00000002,0x00000047,0x00000010,0x0000003e, + 0x00000041,0x00000044,0x0004003d,0x0000000a,0x00000048,0x00000041,0x00050041,0x00000032, + 0x00000049,0x00000018,0x0000002c,0x00050051,0x00000009,0x0000004a,0x00000048,0x00000000, + 0x0003003e,0x00000049,0x0000004a,0x00050041,0x00000032,0x0000004b,0x00000018,0x00000036, + 0x00050051,0x00000009,0x0000004c,0x00000048,0x00000001,0x0003003e,0x0000004b,0x0000004c, + 0x0004003d,0x00000012,0x0000004e,0x00000017,0x0007004f,0x00000007,0x0000004f,0x0000004e, + 0x0000004e,0x00000002,0x00000003,0x0003003e,0x0000004d,0x0000004f,0x0004003d,0x00000014, + 0x00000051,0x00000018,0x0007004f,0x0000000a,0x00000052,0x00000051,0x00000051,0x00000002, + 0x00000003,0x0003003e,0x00000050,0x00000052,0x0004003d,0x00000014,0x00000054,0x00000019, + 0x0007004f,0x0000000a,0x00000055,0x00000054,0x00000054,0x00000002,0x00000003,0x0003003e, + 0x00000053,0x00000055,0x00070039,0x00000002,0x00000056,0x00000010,0x0000004d,0x00000050, + 0x00000053,0x0004003d,0x0000000a,0x00000057,0x00000050,0x00050041,0x00000032,0x00000059, + 0x00000018,0x00000058,0x00050051,0x00000009,0x0000005a,0x00000057,0x00000000,0x0003003e, + 0x00000059,0x0000005a,0x00050041,0x00000032,0x0000005c,0x00000018,0x0000005b,0x00050051, + 0x00000009,0x0000005d,0x00000057,0x00000001,0x0003003e,0x0000005c,0x0000005d,0x000100fd, + 0x00010038,0x00050036,0x00000002,0x0000001f,0x00000000,0x0000001c,0x00030037,0x0000000b, + 0x0000001d,0x00030037,0x00000015,0x0000001e,0x000200f8,0x00000020,0x00050041,0x00000063, + 0x00000064,0x00000060,0x00000062,0x0004003d,0x00000014,0x00000065,0x00000064,0x0009004f, + 0x00000014,0x00000066,0x00000065,0x00000065,0x00000000,0x00000001,0x00000000,0x00000001, + 0x0004003d,0x0000000a,0x0000006a,0x0000001d,0x0009004f,0x00000014,0x0000006b,0x0000006a, + 0x0000006a,0x00000000,0x00000001,0x00000000,0x00000001,0x0008000c,0x00000014,0x0000006c, + 0x00000001,0x00000032,0x00000066,0x00000069,0x0000006b,0x0003003e,0x0000001e,0x0000006c, + 0x000100fd,0x00010038,0x00050036,0x00000014,0x00000029,0x00000000,0x00000024,0x00030037, + 0x0000000b,0x00000025,0x00030037,0x00000015,0x00000026,0x00030037,0x00000023,0x00000027, + 0x00030037,0x00000023,0x00000028,0x000200f8,0x0000002a,0x0004003b,0x00000015,0x0000006d, + 0x00000007,0x0004003b,0x00000015,0x00000089,0x00000007,0x0004003b,0x0000002d,0x00000090, + 0x00000007,0x0004003b,0x00000015,0x0000009c,0x00000007,0x0004003b,0x0000000b,0x000000a2, + 0x00000007,0x0004003b,0x00000013,0x000000ac,0x00000007,0x0004003b,0x00000015,0x000000ad, + 0x00000007,0x0004003b,0x00000015,0x000000af,0x00000007,0x0004003b,0x00000008,0x000000b4, + 0x00000007,0x0004003b,0x0000000b,0x000000b5,0x00000007,0x0004003b,0x0000000b,0x000000b7, + 0x00000007,0x0004003b,0x00000015,0x000000c2,0x00000007,0x0004003b,0x00000015,0x000000d3, + 0x00000007,0x0004003d,0x00000022,0x0000006e,0x00000028,0x0004003d,0x00000014,0x0000006f, + 0x00000026,0x0007004f,0x0000000a,0x00000070,0x0000006f,0x0000006f,0x00000000,0x00000001, + 0x00050057,0x00000014,0x00000071,0x0000006e,0x00000070,0x00050051,0x00000009,0x00000072, + 0x00000071,0x00000003,0x00050041,0x00000032,0x00000073,0x0000006d,0x0000002c,0x0003003e, + 0x00000073,0x00000072,0x0004003d,0x00000022,0x00000074,0x00000028,0x0004003d,0x00000014, + 0x00000075,0x00000026,0x0007004f,0x0000000a,0x00000076,0x00000075,0x00000075,0x00000002, + 0x00000003,0x00050057,0x00000014,0x00000077,0x00000074,0x00000076,0x00050051,0x00000009, + 0x00000078,0x00000077,0x00000001,0x00050041,0x00000032,0x00000079,0x0000006d,0x00000036, + 0x0003003e,0x00000079,0x00000078,0x0004003d,0x00000022,0x0000007a,0x00000028,0x0004003d, + 0x0000000a,0x0000007b,0x00000025,0x00050057,0x00000014,0x0000007c,0x0000007a,0x0000007b, + 0x0007004f,0x0000000a,0x0000007d,0x0000007c,0x0000007c,0x00000000,0x00000002,0x00050041, + 0x00000032,0x0000007e,0x0000006d,0x0000005b,0x00050051,0x00000009,0x0000007f,0x0000007d, + 0x00000000,0x0003003e,0x0000007e,0x0000007f,0x00050041,0x00000032,0x00000080,0x0000006d, + 0x00000058,0x00050051,0x00000009,0x00000081,0x0000007d,0x00000001,0x0003003e,0x00000080, + 0x00000081,0x0004003d,0x00000014,0x00000082,0x0000006d,0x00050094,0x00000009,0x00000084, + 0x00000082,0x00000083,0x000500b8,0x00000006,0x00000086,0x00000084,0x00000085,0x000300f7, + 0x00000088,0x00000000,0x000400fa,0x00000086,0x00000087,0x0000008f,0x000200f8,0x00000087, + 0x0004003d,0x00000022,0x0000008a,0x00000027,0x0004003d,0x0000000a,0x0000008b,0x00000025, + 0x00070058,0x00000014,0x0000008c,0x0000008a,0x0000008b,0x00000002,0x00000068,0x0003003e, + 0x00000089,0x0000008c,0x0004003d,0x00000014,0x0000008d,0x00000089,0x000200fe,0x0000008d, + 0x000200f8,0x0000008f,0x00050041,0x00000032,0x00000091,0x0000006d,0x0000002c,0x0004003d, + 0x00000009,0x00000092,0x00000091,0x00050041,0x00000032,0x00000093,0x0000006d,0x00000058, + 0x0004003d,0x00000009,0x00000094,0x00000093,0x0007000c,0x00000009,0x00000095,0x00000001, + 0x00000028,0x00000092,0x00000094,0x00050041,0x00000032,0x00000096,0x0000006d,0x00000036, + 0x0004003d,0x00000009,0x00000097,0x00000096,0x00050041,0x00000032,0x00000098,0x0000006d, + 0x0000005b,0x0004003d,0x00000009,0x00000099,0x00000098,0x0007000c,0x00000009,0x0000009a, + 0x00000001,0x00000028,0x00000097,0x00000099,0x000500ba,0x00000006,0x0000009b,0x00000095, + 0x0000009a,0x0003003e,0x00000090,0x0000009b,0x00050041,0x00000032,0x0000009d,0x0000006d, + 0x00000036,0x0004003d,0x00000009,0x0000009e,0x0000009d,0x00050041,0x00000032,0x0000009f, + 0x0000006d,0x0000005b,0x0004003d,0x00000009,0x000000a0,0x0000009f,0x00070050,0x00000014, + 0x000000a1,0x00000068,0x0000009e,0x00000068,0x000000a0,0x0003003e,0x0000009c,0x000000a1, + 0x0004003d,0x00000014,0x000000a3,0x0000006d,0x0007004f,0x0000000a,0x000000a4,0x000000a3, + 0x000000a3,0x00000001,0x00000003,0x0003003e,0x000000a2,0x000000a4,0x0004003d,0x00000006, + 0x000000a5,0x00000090,0x00070050,0x00000012,0x000000a6,0x000000a5,0x000000a5,0x000000a5, + 0x000000a5,0x00050041,0x00000032,0x000000a7,0x0000006d,0x0000002c,0x0004003d,0x00000009, + 0x000000a8,0x000000a7,0x00050041,0x00000032,0x000000a9,0x0000006d,0x00000058,0x0004003d, + 0x00000009,0x000000aa,0x000000a9,0x00070050,0x00000014,0x000000ab,0x000000a8,0x00000068, + 0x000000aa,0x00000068,0x0003003e,0x000000ac,0x000000a6,0x0004003d,0x00000014,0x000000ae, + 0x0000009c,0x0003003e,0x000000ad,0x000000ae,0x0003003e,0x000000af,0x000000ab,0x00070039, + 0x00000002,0x000000b0,0x0000001a,0x000000ac,0x000000ad,0x000000af,0x0004003d,0x00000014, + 0x000000b1,0x000000ad,0x0003003e,0x0000009c,0x000000b1,0x0004003d,0x00000006,0x000000b2, + 0x00000090,0x00050050,0x00000007,0x000000b3,0x000000b2,0x000000b2,0x0003003e,0x000000b4, + 0x000000b3,0x0004003d,0x0000000a,0x000000b6,0x000000a2,0x0003003e,0x000000b5,0x000000b6, + 0x0004003d,0x00000014,0x000000b8,0x0000006d,0x0007004f,0x0000000a,0x000000b9,0x000000b8, + 0x000000b8,0x00000000,0x00000002,0x0003003e,0x000000b7,0x000000b9,0x00070039,0x00000002, + 0x000000ba,0x00000010,0x000000b4,0x000000b5,0x000000b7,0x0004003d,0x0000000a,0x000000bb, + 0x000000b5,0x0003003e,0x000000a2,0x000000bb,0x0004003d,0x0000000a,0x000000bc,0x000000a2, + 0x00050094,0x00000009,0x000000be,0x000000bc,0x000000bd,0x0004003d,0x0000000a,0x000000bf, + 0x000000a2,0x00050050,0x0000000a,0x000000c0,0x000000be,0x000000be,0x00050088,0x0000000a, + 0x000000c1,0x000000bf,0x000000c0,0x0003003e,0x000000a2,0x000000c1,0x0004003d,0x00000014, + 0x000000c3,0x0000009c,0x00050041,0x00000063,0x000000c4,0x00000060,0x00000062,0x0004003d, + 0x00000014,0x000000c5,0x000000c4,0x0007004f,0x0000000a,0x000000c6,0x000000c5,0x000000c5, + 0x00000000,0x00000001,0x00050041,0x00000063,0x000000c7,0x00000060,0x00000062,0x0004003d, + 0x00000014,0x000000c8,0x000000c7,0x0007004f,0x0000000a,0x000000c9,0x000000c8,0x000000c8, + 0x00000000,0x00000001,0x0004007f,0x0000000a,0x000000ca,0x000000c9,0x00050051,0x00000009, + 0x000000cb,0x000000c6,0x00000000,0x00050051,0x00000009,0x000000cc,0x000000c6,0x00000001, + 0x00050051,0x00000009,0x000000cd,0x000000ca,0x00000000,0x00050051,0x00000009,0x000000ce, + 0x000000ca,0x00000001,0x00070050,0x00000014,0x000000cf,0x000000cb,0x000000cc,0x000000cd, + 0x000000ce,0x0004003d,0x0000000a,0x000000d0,0x00000025,0x0009004f,0x00000014,0x000000d1, + 0x000000d0,0x000000d0,0x00000000,0x00000001,0x00000000,0x00000001,0x0008000c,0x00000014, + 0x000000d2,0x00000001,0x00000032,0x000000c3,0x000000cf,0x000000d1,0x0003003e,0x000000c2, + 0x000000d2,0x00050041,0x00000032,0x000000d4,0x000000a2,0x0000002c,0x0004003d,0x00000009, + 0x000000d5,0x000000d4,0x0004003d,0x00000022,0x000000d6,0x00000027,0x0004003d,0x00000014, + 0x000000d7,0x000000c2,0x0007004f,0x0000000a,0x000000d8,0x000000d7,0x000000d7,0x00000000, + 0x00000001,0x00070058,0x00000014,0x000000d9,0x000000d6,0x000000d8,0x00000002,0x00000068, + 0x0005008e,0x00000014,0x000000da,0x000000d9,0x000000d5,0x0003003e,0x000000d3,0x000000da, + 0x00050041,0x00000032,0x000000db,0x000000a2,0x00000036,0x0004003d,0x00000009,0x000000dc, + 0x000000db,0x0004003d,0x00000022,0x000000dd,0x00000027,0x0004003d,0x00000014,0x000000de, + 0x000000c2,0x0007004f,0x0000000a,0x000000df,0x000000de,0x000000de,0x00000002,0x00000003, + 0x00070058,0x00000014,0x000000e0,0x000000dd,0x000000df,0x00000002,0x00000068,0x0005008e, + 0x00000014,0x000000e1,0x000000e0,0x000000dc,0x0004003d,0x00000014,0x000000e2,0x000000d3, + 0x00050081,0x00000014,0x000000e3,0x000000e2,0x000000e1,0x0003003e,0x000000d3,0x000000e3, + 0x0004003d,0x00000014,0x000000e4,0x000000d3,0x000200fe,0x000000e4,0x000200f8,0x00000088, + 0x000100ff,0x00010038 }; diff --git a/app/src/main/cpp/shaders/smaa_edge.frag b/app/src/main/cpp/shaders/smaa_edge.frag index 44073b00c4..b4e40a9dad 100644 --- a/app/src/main/cpp/shaders/smaa_edge.frag +++ b/app/src/main/cpp/shaders/smaa_edge.frag @@ -1,29 +1,21 @@ #version 450 +#extension GL_GOOGLE_include_directive : require layout(location = 0) in vec2 fragTexCoord; layout(location = 0) out vec4 outColor; layout(set = 0, binding = 0) uniform sampler2D InputTexture; layout(push_constant) uniform Constants { vec4 ndc; - vec2 resolution; - float extra; - float pad; + vec4 metrics; // 1/width, 1/height, width, height } pc; -float luma(vec3 c) { - return dot(c, vec3(0.2126, 0.7152, 0.0722)); -} +#define SMAA_RT_METRICS pc.metrics +#define SMAA_GLSL_4 +#define SMAA_PRESET_HIGH +#include "SMAA.hlsl" void main() { - vec2 px = 1.0 / max(pc.resolution, vec2(1.0)); - vec2 uv = clamp(fragTexCoord, px * 0.5, vec2(1.0) - px * 0.5); - float center = luma(texture(InputTexture, uv).rgb); - float left = luma(texture(InputTexture, uv - vec2(px.x, 0.0)).rgb); - float right = luma(texture(InputTexture, uv + vec2(px.x, 0.0)).rgb); - float up = luma(texture(InputTexture, uv - vec2(0.0, px.y)).rgb); - float down = luma(texture(InputTexture, uv + vec2(0.0, px.y)).rgb); - - // Store directional edge strengths for the weight pass. - outColor = vec4(abs(center - left), abs(center - right), - abs(center - up), abs(center - down)); + vec4 offset[3]; + SMAAEdgeDetectionVS(fragTexCoord, offset); + outColor = vec4(SMAALumaEdgeDetectionPS(fragTexCoord, offset, InputTexture), 0.0, 0.0); } diff --git a/app/src/main/cpp/shaders/smaa_edge_frag.h b/app/src/main/cpp/shaders/smaa_edge_frag.h index 7d133264c9..300a5ca064 100644 --- a/app/src/main/cpp/shaders/smaa_edge_frag.h +++ b/app/src/main/cpp/shaders/smaa_edge_frag.h @@ -1,102 +1,185 @@ - // 1116.3.0 + // 1116.6.0 #pragma once const uint32_t smaa_edge_code[] = { - 0x07230203,0x00010000,0x0008000b,0x00000080,0x00000000,0x00020011,0x00000001,0x0006000b, + 0x07230203,0x00010000,0x0008000b,0x000000eb,0x00000000,0x00020011,0x00000001,0x0006000b, 0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001, - 0x0007000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x00000028,0x0000006e,0x00030010, - 0x00000004,0x00000007,0x00030003,0x00000002,0x000001c2,0x00040005,0x00000004,0x6e69616d, - 0x00000000,0x00050005,0x0000000b,0x616d756c,0x33667628,0x0000003b,0x00030005,0x0000000a, - 0x00000063,0x00030005,0x00000017,0x00007870,0x00050005,0x0000001a,0x736e6f43,0x746e6174, - 0x00000073,0x00040006,0x0000001a,0x00000000,0x0063646e,0x00060006,0x0000001a,0x00000001, - 0x6f736572,0x6974756c,0x00006e6f,0x00050006,0x0000001a,0x00000002,0x72747865,0x00000061, - 0x00040006,0x0000001a,0x00000003,0x00646170,0x00030005,0x0000001c,0x00006370,0x00030005, - 0x00000026,0x00007675,0x00060005,0x00000028,0x67617266,0x43786554,0x64726f6f,0x00000000, - 0x00040005,0x00000032,0x746e6563,0x00007265,0x00060005,0x00000036,0x75706e49,0x78655474, - 0x65727574,0x00000000,0x00040005,0x0000003a,0x61726170,0x0000006d,0x00040005,0x0000003d, - 0x7466656c,0x00000000,0x00040005,0x00000048,0x61726170,0x0000006d,0x00040005,0x0000004b, - 0x68676972,0x00000074,0x00040005,0x00000053,0x61726170,0x0000006d,0x00030005,0x00000056, - 0x00007075,0x00040005,0x0000005f,0x61726170,0x0000006d,0x00040005,0x00000062,0x6e776f64, - 0x00000000,0x00040005,0x0000006a,0x61726170,0x0000006d,0x00050005,0x0000006e,0x4374756f, - 0x726f6c6f,0x00000000,0x00030047,0x0000001a,0x00000002,0x00050048,0x0000001a,0x00000000, - 0x00000023,0x00000000,0x00050048,0x0000001a,0x00000001,0x00000023,0x00000010,0x00050048, - 0x0000001a,0x00000002,0x00000023,0x00000018,0x00050048,0x0000001a,0x00000003,0x00000023, - 0x0000001c,0x00040047,0x00000028,0x0000001e,0x00000000,0x00040047,0x00000036,0x00000021, - 0x00000000,0x00040047,0x00000036,0x00000022,0x00000000,0x00040047,0x0000006e,0x0000001e, - 0x00000000,0x00020013,0x00000002,0x00030021,0x00000003,0x00000002,0x00030016,0x00000006, - 0x00000020,0x00040017,0x00000007,0x00000006,0x00000003,0x00040020,0x00000008,0x00000007, - 0x00000007,0x00040021,0x00000009,0x00000006,0x00000008,0x0004002b,0x00000006,0x0000000e, - 0x3e59b3d0,0x0004002b,0x00000006,0x0000000f,0x3f371759,0x0004002b,0x00000006,0x00000010, - 0x3d93dd98,0x0006002c,0x00000007,0x00000011,0x0000000e,0x0000000f,0x00000010,0x00040017, - 0x00000015,0x00000006,0x00000002,0x00040020,0x00000016,0x00000007,0x00000015,0x0004002b, - 0x00000006,0x00000018,0x3f800000,0x00040017,0x00000019,0x00000006,0x00000004,0x0006001e, - 0x0000001a,0x00000019,0x00000015,0x00000006,0x00000006,0x00040020,0x0000001b,0x00000009, - 0x0000001a,0x0004003b,0x0000001b,0x0000001c,0x00000009,0x00040015,0x0000001d,0x00000020, - 0x00000001,0x0004002b,0x0000001d,0x0000001e,0x00000001,0x00040020,0x0000001f,0x00000009, - 0x00000015,0x0005002c,0x00000015,0x00000022,0x00000018,0x00000018,0x00040020,0x00000027, - 0x00000001,0x00000015,0x0004003b,0x00000027,0x00000028,0x00000001,0x0004002b,0x00000006, - 0x0000002b,0x3f000000,0x00040020,0x00000031,0x00000007,0x00000006,0x00090019,0x00000033, - 0x00000006,0x00000001,0x00000000,0x00000000,0x00000000,0x00000001,0x00000000,0x0003001b, - 0x00000034,0x00000033,0x00040020,0x00000035,0x00000000,0x00000034,0x0004003b,0x00000035, - 0x00000036,0x00000000,0x00040015,0x00000040,0x00000020,0x00000000,0x0004002b,0x00000040, - 0x00000041,0x00000000,0x0004002b,0x00000006,0x00000044,0x00000000,0x0004002b,0x00000040, - 0x00000059,0x00000001,0x00040020,0x0000006d,0x00000003,0x00000019,0x0004003b,0x0000006d, - 0x0000006e,0x00000003,0x00050036,0x00000002,0x00000004,0x00000000,0x00000003,0x000200f8, - 0x00000005,0x0004003b,0x00000016,0x00000017,0x00000007,0x0004003b,0x00000016,0x00000026, - 0x00000007,0x0004003b,0x00000031,0x00000032,0x00000007,0x0004003b,0x00000008,0x0000003a, - 0x00000007,0x0004003b,0x00000031,0x0000003d,0x00000007,0x0004003b,0x00000008,0x00000048, - 0x00000007,0x0004003b,0x00000031,0x0000004b,0x00000007,0x0004003b,0x00000008,0x00000053, - 0x00000007,0x0004003b,0x00000031,0x00000056,0x00000007,0x0004003b,0x00000008,0x0000005f, - 0x00000007,0x0004003b,0x00000031,0x00000062,0x00000007,0x0004003b,0x00000008,0x0000006a, - 0x00000007,0x00050041,0x0000001f,0x00000020,0x0000001c,0x0000001e,0x0004003d,0x00000015, - 0x00000021,0x00000020,0x0007000c,0x00000015,0x00000023,0x00000001,0x00000028,0x00000021, - 0x00000022,0x00050050,0x00000015,0x00000024,0x00000018,0x00000018,0x00050088,0x00000015, - 0x00000025,0x00000024,0x00000023,0x0003003e,0x00000017,0x00000025,0x0004003d,0x00000015, - 0x00000029,0x00000028,0x0004003d,0x00000015,0x0000002a,0x00000017,0x0005008e,0x00000015, - 0x0000002c,0x0000002a,0x0000002b,0x0004003d,0x00000015,0x0000002d,0x00000017,0x0005008e, - 0x00000015,0x0000002e,0x0000002d,0x0000002b,0x00050083,0x00000015,0x0000002f,0x00000022, - 0x0000002e,0x0008000c,0x00000015,0x00000030,0x00000001,0x0000002b,0x00000029,0x0000002c, - 0x0000002f,0x0003003e,0x00000026,0x00000030,0x0004003d,0x00000034,0x00000037,0x00000036, - 0x0004003d,0x00000015,0x00000038,0x00000026,0x00050057,0x00000019,0x00000039,0x00000037, - 0x00000038,0x0008004f,0x00000007,0x0000003b,0x00000039,0x00000039,0x00000000,0x00000001, - 0x00000002,0x0003003e,0x0000003a,0x0000003b,0x00050039,0x00000006,0x0000003c,0x0000000b, - 0x0000003a,0x0003003e,0x00000032,0x0000003c,0x0004003d,0x00000034,0x0000003e,0x00000036, - 0x0004003d,0x00000015,0x0000003f,0x00000026,0x00050041,0x00000031,0x00000042,0x00000017, - 0x00000041,0x0004003d,0x00000006,0x00000043,0x00000042,0x00050050,0x00000015,0x00000045, - 0x00000043,0x00000044,0x00050083,0x00000015,0x00000046,0x0000003f,0x00000045,0x00050057, - 0x00000019,0x00000047,0x0000003e,0x00000046,0x0008004f,0x00000007,0x00000049,0x00000047, - 0x00000047,0x00000000,0x00000001,0x00000002,0x0003003e,0x00000048,0x00000049,0x00050039, - 0x00000006,0x0000004a,0x0000000b,0x00000048,0x0003003e,0x0000003d,0x0000004a,0x0004003d, - 0x00000034,0x0000004c,0x00000036,0x0004003d,0x00000015,0x0000004d,0x00000026,0x00050041, - 0x00000031,0x0000004e,0x00000017,0x00000041,0x0004003d,0x00000006,0x0000004f,0x0000004e, - 0x00050050,0x00000015,0x00000050,0x0000004f,0x00000044,0x00050081,0x00000015,0x00000051, - 0x0000004d,0x00000050,0x00050057,0x00000019,0x00000052,0x0000004c,0x00000051,0x0008004f, - 0x00000007,0x00000054,0x00000052,0x00000052,0x00000000,0x00000001,0x00000002,0x0003003e, - 0x00000053,0x00000054,0x00050039,0x00000006,0x00000055,0x0000000b,0x00000053,0x0003003e, - 0x0000004b,0x00000055,0x0004003d,0x00000034,0x00000057,0x00000036,0x0004003d,0x00000015, - 0x00000058,0x00000026,0x00050041,0x00000031,0x0000005a,0x00000017,0x00000059,0x0004003d, - 0x00000006,0x0000005b,0x0000005a,0x00050050,0x00000015,0x0000005c,0x00000044,0x0000005b, - 0x00050083,0x00000015,0x0000005d,0x00000058,0x0000005c,0x00050057,0x00000019,0x0000005e, - 0x00000057,0x0000005d,0x0008004f,0x00000007,0x00000060,0x0000005e,0x0000005e,0x00000000, - 0x00000001,0x00000002,0x0003003e,0x0000005f,0x00000060,0x00050039,0x00000006,0x00000061, - 0x0000000b,0x0000005f,0x0003003e,0x00000056,0x00000061,0x0004003d,0x00000034,0x00000063, - 0x00000036,0x0004003d,0x00000015,0x00000064,0x00000026,0x00050041,0x00000031,0x00000065, - 0x00000017,0x00000059,0x0004003d,0x00000006,0x00000066,0x00000065,0x00050050,0x00000015, - 0x00000067,0x00000044,0x00000066,0x00050081,0x00000015,0x00000068,0x00000064,0x00000067, - 0x00050057,0x00000019,0x00000069,0x00000063,0x00000068,0x0008004f,0x00000007,0x0000006b, - 0x00000069,0x00000069,0x00000000,0x00000001,0x00000002,0x0003003e,0x0000006a,0x0000006b, - 0x00050039,0x00000006,0x0000006c,0x0000000b,0x0000006a,0x0003003e,0x00000062,0x0000006c, - 0x0004003d,0x00000006,0x0000006f,0x00000032,0x0004003d,0x00000006,0x00000070,0x0000003d, - 0x00050083,0x00000006,0x00000071,0x0000006f,0x00000070,0x0006000c,0x00000006,0x00000072, - 0x00000001,0x00000004,0x00000071,0x0004003d,0x00000006,0x00000073,0x00000032,0x0004003d, - 0x00000006,0x00000074,0x0000004b,0x00050083,0x00000006,0x00000075,0x00000073,0x00000074, - 0x0006000c,0x00000006,0x00000076,0x00000001,0x00000004,0x00000075,0x0004003d,0x00000006, - 0x00000077,0x00000032,0x0004003d,0x00000006,0x00000078,0x00000056,0x00050083,0x00000006, - 0x00000079,0x00000077,0x00000078,0x0006000c,0x00000006,0x0000007a,0x00000001,0x00000004, - 0x00000079,0x0004003d,0x00000006,0x0000007b,0x00000032,0x0004003d,0x00000006,0x0000007c, - 0x00000062,0x00050083,0x00000006,0x0000007d,0x0000007b,0x0000007c,0x0006000c,0x00000006, - 0x0000007e,0x00000001,0x00000004,0x0000007d,0x00070050,0x00000019,0x0000007f,0x00000072, - 0x00000076,0x0000007a,0x0000007e,0x0003003e,0x0000006e,0x0000007f,0x000100fd,0x00010038, - 0x00050036,0x00000006,0x0000000b,0x00000000,0x00000009,0x00030037,0x00000008,0x0000000a, - 0x000200f8,0x0000000c,0x0004003d,0x00000007,0x0000000d,0x0000000a,0x00050094,0x00000006, - 0x00000012,0x0000000d,0x00000011,0x000200fe,0x00000012,0x00010038 + 0x0007000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x000000d9,0x000000e1,0x00030010, + 0x00000004,0x00000007,0x00030003,0x00000002,0x000001c2,0x000a0004,0x475f4c47,0x4c474f4f, + 0x70635f45,0x74735f70,0x5f656c79,0x656e696c,0x7269645f,0x69746365,0x00006576,0x00080004, + 0x475f4c47,0x4c474f4f,0x6e695f45,0x64756c63,0x69645f65,0x74636572,0x00657669,0x00040005, + 0x00000004,0x6e69616d,0x00000000,0x000a0005,0x00000011,0x41414d53,0x65676445,0x65746544, + 0x6f697463,0x2853566e,0x3b326676,0x5b346676,0x003b5d33,0x00050005,0x0000000f,0x63786574, + 0x64726f6f,0x00000000,0x00040005,0x00000010,0x7366666f,0x00007465,0x000c0005,0x0000001a, + 0x41414d53,0x616d754c,0x65676445,0x65746544,0x6f697463,0x2853506e,0x3b326676,0x5b346676, + 0x733b5d33,0x003b3132,0x00050005,0x00000017,0x63786574,0x64726f6f,0x00000000,0x00040005, + 0x00000018,0x7366666f,0x00007465,0x00050005,0x00000019,0x6f6c6f63,0x78655472,0x00000000, + 0x00050005,0x0000001e,0x736e6f43,0x746e6174,0x00000073,0x00040006,0x0000001e,0x00000000, + 0x0063646e,0x00050006,0x0000001e,0x00000001,0x7274656d,0x00736369,0x00030005,0x00000020, + 0x00006370,0x00050005,0x00000041,0x65726874,0x6c6f6873,0x00000064,0x00040005,0x00000046, + 0x67696577,0x00737468,0x00030005,0x0000004c,0x0000004c,0x00040005,0x00000053,0x66656c4c, + 0x00000074,0x00040005,0x0000005c,0x706f744c,0x00000000,0x00040005,0x00000065,0x746c6564, + 0x00000061,0x00040005,0x00000073,0x65676465,0x00000073,0x00040005,0x00000080,0x6769724c, + 0x00007468,0x00040005,0x00000089,0x746f624c,0x006d6f74,0x00050005,0x0000009e,0x4478616d, + 0x61746c65,0x00000000,0x00050005,0x000000a4,0x66656c4c,0x66656c74,0x00000074,0x00040005, + 0x000000ad,0x706f744c,0x00706f74,0x00050005,0x000000c6,0x616e6966,0x6c65446c,0x00006174, + 0x00060005,0x000000d9,0x67617266,0x43786554,0x64726f6f,0x00000000,0x00040005,0x000000da, + 0x7366666f,0x00007465,0x00040005,0x000000db,0x61726170,0x0000006d,0x00040005,0x000000dd, + 0x61726170,0x0000006d,0x00050005,0x000000e1,0x4374756f,0x726f6c6f,0x00000000,0x00060005, + 0x000000e2,0x75706e49,0x78655474,0x65727574,0x00000000,0x00040005,0x000000e3,0x61726170, + 0x0000006d,0x00040005,0x000000e5,0x61726170,0x0000006d,0x00030047,0x0000001e,0x00000002, + 0x00050048,0x0000001e,0x00000000,0x00000023,0x00000000,0x00050048,0x0000001e,0x00000001, + 0x00000023,0x00000010,0x00040047,0x000000d9,0x0000001e,0x00000000,0x00040047,0x000000e1, + 0x0000001e,0x00000000,0x00040047,0x000000e2,0x00000021,0x00000000,0x00040047,0x000000e2, + 0x00000022,0x00000000,0x00020013,0x00000002,0x00030021,0x00000003,0x00000002,0x00030016, + 0x00000006,0x00000020,0x00040017,0x00000007,0x00000006,0x00000002,0x00040020,0x00000008, + 0x00000007,0x00000007,0x00040017,0x00000009,0x00000006,0x00000004,0x00040015,0x0000000a, + 0x00000020,0x00000000,0x0004002b,0x0000000a,0x0000000b,0x00000003,0x0004001c,0x0000000c, + 0x00000009,0x0000000b,0x00040020,0x0000000d,0x00000007,0x0000000c,0x00050021,0x0000000e, + 0x00000002,0x00000008,0x0000000d,0x00090019,0x00000013,0x00000006,0x00000001,0x00000000, + 0x00000000,0x00000000,0x00000001,0x00000000,0x0003001b,0x00000014,0x00000013,0x00040020, + 0x00000015,0x00000000,0x00000014,0x00060021,0x00000016,0x00000007,0x00000008,0x0000000d, + 0x00000015,0x00040015,0x0000001c,0x00000020,0x00000001,0x0004002b,0x0000001c,0x0000001d, + 0x00000000,0x0004001e,0x0000001e,0x00000009,0x00000009,0x00040020,0x0000001f,0x00000009, + 0x0000001e,0x0004003b,0x0000001f,0x00000020,0x00000009,0x0004002b,0x0000001c,0x00000021, + 0x00000001,0x00040020,0x00000022,0x00000009,0x00000009,0x0004002b,0x00000006,0x00000026, + 0xbf800000,0x0004002b,0x00000006,0x00000027,0x00000000,0x0007002c,0x00000009,0x00000028, + 0x00000026,0x00000027,0x00000027,0x00000026,0x00040020,0x0000002c,0x00000007,0x00000009, + 0x0004002b,0x00000006,0x00000031,0x3f800000,0x0007002c,0x00000009,0x00000032,0x00000031, + 0x00000027,0x00000027,0x00000031,0x0004002b,0x0000001c,0x00000037,0x00000002,0x0004002b, + 0x00000006,0x0000003b,0xc0000000,0x0007002c,0x00000009,0x0000003c,0x0000003b,0x00000027, + 0x00000027,0x0000003b,0x0004002b,0x00000006,0x00000042,0x3dcccccd,0x0005002c,0x00000007, + 0x00000043,0x00000042,0x00000042,0x00040017,0x00000044,0x00000006,0x00000003,0x00040020, + 0x00000045,0x00000007,0x00000044,0x0004002b,0x00000006,0x00000047,0x3e59b3d0,0x0004002b, + 0x00000006,0x00000048,0x3f371759,0x0004002b,0x00000006,0x00000049,0x3d93dd98,0x0006002c, + 0x00000044,0x0000004a,0x00000047,0x00000048,0x00000049,0x00040020,0x0000004b,0x00000007, + 0x00000006,0x0004002b,0x0000000a,0x0000006d,0x00000000,0x0004002b,0x0000000a,0x00000070, + 0x00000001,0x0005002c,0x00000007,0x00000079,0x00000031,0x00000031,0x00020014,0x0000007b, + 0x0004002b,0x0000000a,0x00000099,0x00000002,0x0004002b,0x00000006,0x000000cd,0x40000000, + 0x00040020,0x000000d8,0x00000001,0x00000007,0x0004003b,0x000000d8,0x000000d9,0x00000001, + 0x00040020,0x000000e0,0x00000003,0x00000009,0x0004003b,0x000000e0,0x000000e1,0x00000003, + 0x0004003b,0x00000015,0x000000e2,0x00000000,0x00050036,0x00000002,0x00000004,0x00000000, + 0x00000003,0x000200f8,0x00000005,0x0004003b,0x0000000d,0x000000da,0x00000007,0x0004003b, + 0x00000008,0x000000db,0x00000007,0x0004003b,0x0000000d,0x000000dd,0x00000007,0x0004003b, + 0x00000008,0x000000e3,0x00000007,0x0004003b,0x0000000d,0x000000e5,0x00000007,0x0004003d, + 0x00000007,0x000000dc,0x000000d9,0x0003003e,0x000000db,0x000000dc,0x00060039,0x00000002, + 0x000000de,0x00000011,0x000000db,0x000000dd,0x0004003d,0x0000000c,0x000000df,0x000000dd, + 0x0003003e,0x000000da,0x000000df,0x0004003d,0x00000007,0x000000e4,0x000000d9,0x0003003e, + 0x000000e3,0x000000e4,0x0004003d,0x0000000c,0x000000e6,0x000000da,0x0003003e,0x000000e5, + 0x000000e6,0x00070039,0x00000007,0x000000e7,0x0000001a,0x000000e3,0x000000e5,0x000000e2, + 0x00050051,0x00000006,0x000000e8,0x000000e7,0x00000000,0x00050051,0x00000006,0x000000e9, + 0x000000e7,0x00000001,0x00070050,0x00000009,0x000000ea,0x000000e8,0x000000e9,0x00000027, + 0x00000027,0x0003003e,0x000000e1,0x000000ea,0x000100fd,0x00010038,0x00050036,0x00000002, + 0x00000011,0x00000000,0x0000000e,0x00030037,0x00000008,0x0000000f,0x00030037,0x0000000d, + 0x00000010,0x000200f8,0x00000012,0x00050041,0x00000022,0x00000023,0x00000020,0x00000021, + 0x0004003d,0x00000009,0x00000024,0x00000023,0x0009004f,0x00000009,0x00000025,0x00000024, + 0x00000024,0x00000000,0x00000001,0x00000000,0x00000001,0x0004003d,0x00000007,0x00000029, + 0x0000000f,0x0009004f,0x00000009,0x0000002a,0x00000029,0x00000029,0x00000000,0x00000001, + 0x00000000,0x00000001,0x0008000c,0x00000009,0x0000002b,0x00000001,0x00000032,0x00000025, + 0x00000028,0x0000002a,0x00050041,0x0000002c,0x0000002d,0x00000010,0x0000001d,0x0003003e, + 0x0000002d,0x0000002b,0x00050041,0x00000022,0x0000002e,0x00000020,0x00000021,0x0004003d, + 0x00000009,0x0000002f,0x0000002e,0x0009004f,0x00000009,0x00000030,0x0000002f,0x0000002f, + 0x00000000,0x00000001,0x00000000,0x00000001,0x0004003d,0x00000007,0x00000033,0x0000000f, + 0x0009004f,0x00000009,0x00000034,0x00000033,0x00000033,0x00000000,0x00000001,0x00000000, + 0x00000001,0x0008000c,0x00000009,0x00000035,0x00000001,0x00000032,0x00000030,0x00000032, + 0x00000034,0x00050041,0x0000002c,0x00000036,0x00000010,0x00000021,0x0003003e,0x00000036, + 0x00000035,0x00050041,0x00000022,0x00000038,0x00000020,0x00000021,0x0004003d,0x00000009, + 0x00000039,0x00000038,0x0009004f,0x00000009,0x0000003a,0x00000039,0x00000039,0x00000000, + 0x00000001,0x00000000,0x00000001,0x0004003d,0x00000007,0x0000003d,0x0000000f,0x0009004f, + 0x00000009,0x0000003e,0x0000003d,0x0000003d,0x00000000,0x00000001,0x00000000,0x00000001, + 0x0008000c,0x00000009,0x0000003f,0x00000001,0x00000032,0x0000003a,0x0000003c,0x0000003e, + 0x00050041,0x0000002c,0x00000040,0x00000010,0x00000037,0x0003003e,0x00000040,0x0000003f, + 0x000100fd,0x00010038,0x00050036,0x00000007,0x0000001a,0x00000000,0x00000016,0x00030037, + 0x00000008,0x00000017,0x00030037,0x0000000d,0x00000018,0x00030037,0x00000015,0x00000019, + 0x000200f8,0x0000001b,0x0004003b,0x00000008,0x00000041,0x00000007,0x0004003b,0x00000045, + 0x00000046,0x00000007,0x0004003b,0x0000004b,0x0000004c,0x00000007,0x0004003b,0x0000004b, + 0x00000053,0x00000007,0x0004003b,0x0000004b,0x0000005c,0x00000007,0x0004003b,0x0000002c, + 0x00000065,0x00000007,0x0004003b,0x00000008,0x00000073,0x00000007,0x0004003b,0x0000004b, + 0x00000080,0x00000007,0x0004003b,0x0000004b,0x00000089,0x00000007,0x0004003b,0x00000008, + 0x0000009e,0x00000007,0x0004003b,0x0000004b,0x000000a4,0x00000007,0x0004003b,0x0000004b, + 0x000000ad,0x00000007,0x0004003b,0x0000004b,0x000000c6,0x00000007,0x0003003e,0x00000041, + 0x00000043,0x0003003e,0x00000046,0x0000004a,0x0004003d,0x00000014,0x0000004d,0x00000019, + 0x0004003d,0x00000007,0x0000004e,0x00000017,0x00050057,0x00000009,0x0000004f,0x0000004d, + 0x0000004e,0x0008004f,0x00000044,0x00000050,0x0000004f,0x0000004f,0x00000000,0x00000001, + 0x00000002,0x0004003d,0x00000044,0x00000051,0x00000046,0x00050094,0x00000006,0x00000052, + 0x00000050,0x00000051,0x0003003e,0x0000004c,0x00000052,0x0004003d,0x00000014,0x00000054, + 0x00000019,0x00050041,0x0000002c,0x00000055,0x00000018,0x0000001d,0x0004003d,0x00000009, + 0x00000056,0x00000055,0x0007004f,0x00000007,0x00000057,0x00000056,0x00000056,0x00000000, + 0x00000001,0x00050057,0x00000009,0x00000058,0x00000054,0x00000057,0x0008004f,0x00000044, + 0x00000059,0x00000058,0x00000058,0x00000000,0x00000001,0x00000002,0x0004003d,0x00000044, + 0x0000005a,0x00000046,0x00050094,0x00000006,0x0000005b,0x00000059,0x0000005a,0x0003003e, + 0x00000053,0x0000005b,0x0004003d,0x00000014,0x0000005d,0x00000019,0x00050041,0x0000002c, + 0x0000005e,0x00000018,0x0000001d,0x0004003d,0x00000009,0x0000005f,0x0000005e,0x0007004f, + 0x00000007,0x00000060,0x0000005f,0x0000005f,0x00000002,0x00000003,0x00050057,0x00000009, + 0x00000061,0x0000005d,0x00000060,0x0008004f,0x00000044,0x00000062,0x00000061,0x00000061, + 0x00000000,0x00000001,0x00000002,0x0004003d,0x00000044,0x00000063,0x00000046,0x00050094, + 0x00000006,0x00000064,0x00000062,0x00000063,0x0003003e,0x0000005c,0x00000064,0x0004003d, + 0x00000006,0x00000066,0x0000004c,0x0004003d,0x00000006,0x00000067,0x00000053,0x0004003d, + 0x00000006,0x00000068,0x0000005c,0x00050050,0x00000007,0x00000069,0x00000067,0x00000068, + 0x00050050,0x00000007,0x0000006a,0x00000066,0x00000066,0x00050083,0x00000007,0x0000006b, + 0x0000006a,0x00000069,0x0006000c,0x00000007,0x0000006c,0x00000001,0x00000004,0x0000006b, + 0x00050041,0x0000004b,0x0000006e,0x00000065,0x0000006d,0x00050051,0x00000006,0x0000006f, + 0x0000006c,0x00000000,0x0003003e,0x0000006e,0x0000006f,0x00050041,0x0000004b,0x00000071, + 0x00000065,0x00000070,0x00050051,0x00000006,0x00000072,0x0000006c,0x00000001,0x0003003e, + 0x00000071,0x00000072,0x0004003d,0x00000007,0x00000074,0x00000041,0x0004003d,0x00000009, + 0x00000075,0x00000065,0x0007004f,0x00000007,0x00000076,0x00000075,0x00000075,0x00000000, + 0x00000001,0x0007000c,0x00000007,0x00000077,0x00000001,0x00000030,0x00000074,0x00000076, + 0x0003003e,0x00000073,0x00000077,0x0004003d,0x00000007,0x00000078,0x00000073,0x00050094, + 0x00000006,0x0000007a,0x00000078,0x00000079,0x000500b4,0x0000007b,0x0000007c,0x0000007a, + 0x00000027,0x000300f7,0x0000007e,0x00000000,0x000400fa,0x0000007c,0x0000007d,0x0000007e, + 0x000200f8,0x0000007d,0x000100fc,0x000200f8,0x0000007e,0x0004003d,0x00000014,0x00000081, + 0x00000019,0x00050041,0x0000002c,0x00000082,0x00000018,0x00000021,0x0004003d,0x00000009, + 0x00000083,0x00000082,0x0007004f,0x00000007,0x00000084,0x00000083,0x00000083,0x00000000, + 0x00000001,0x00050057,0x00000009,0x00000085,0x00000081,0x00000084,0x0008004f,0x00000044, + 0x00000086,0x00000085,0x00000085,0x00000000,0x00000001,0x00000002,0x0004003d,0x00000044, + 0x00000087,0x00000046,0x00050094,0x00000006,0x00000088,0x00000086,0x00000087,0x0003003e, + 0x00000080,0x00000088,0x0004003d,0x00000014,0x0000008a,0x00000019,0x00050041,0x0000002c, + 0x0000008b,0x00000018,0x00000021,0x0004003d,0x00000009,0x0000008c,0x0000008b,0x0007004f, + 0x00000007,0x0000008d,0x0000008c,0x0000008c,0x00000002,0x00000003,0x00050057,0x00000009, + 0x0000008e,0x0000008a,0x0000008d,0x0008004f,0x00000044,0x0000008f,0x0000008e,0x0000008e, + 0x00000000,0x00000001,0x00000002,0x0004003d,0x00000044,0x00000090,0x00000046,0x00050094, + 0x00000006,0x00000091,0x0000008f,0x00000090,0x0003003e,0x00000089,0x00000091,0x0004003d, + 0x00000006,0x00000092,0x0000004c,0x0004003d,0x00000006,0x00000093,0x00000080,0x0004003d, + 0x00000006,0x00000094,0x00000089,0x00050050,0x00000007,0x00000095,0x00000093,0x00000094, + 0x00050050,0x00000007,0x00000096,0x00000092,0x00000092,0x00050083,0x00000007,0x00000097, + 0x00000096,0x00000095,0x0006000c,0x00000007,0x00000098,0x00000001,0x00000004,0x00000097, + 0x00050041,0x0000004b,0x0000009a,0x00000065,0x00000099,0x00050051,0x00000006,0x0000009b, + 0x00000098,0x00000000,0x0003003e,0x0000009a,0x0000009b,0x00050041,0x0000004b,0x0000009c, + 0x00000065,0x0000000b,0x00050051,0x00000006,0x0000009d,0x00000098,0x00000001,0x0003003e, + 0x0000009c,0x0000009d,0x0004003d,0x00000009,0x0000009f,0x00000065,0x0007004f,0x00000007, + 0x000000a0,0x0000009f,0x0000009f,0x00000000,0x00000001,0x0004003d,0x00000009,0x000000a1, + 0x00000065,0x0007004f,0x00000007,0x000000a2,0x000000a1,0x000000a1,0x00000002,0x00000003, + 0x0007000c,0x00000007,0x000000a3,0x00000001,0x00000028,0x000000a0,0x000000a2,0x0003003e, + 0x0000009e,0x000000a3,0x0004003d,0x00000014,0x000000a5,0x00000019,0x00050041,0x0000002c, + 0x000000a6,0x00000018,0x00000037,0x0004003d,0x00000009,0x000000a7,0x000000a6,0x0007004f, + 0x00000007,0x000000a8,0x000000a7,0x000000a7,0x00000000,0x00000001,0x00050057,0x00000009, + 0x000000a9,0x000000a5,0x000000a8,0x0008004f,0x00000044,0x000000aa,0x000000a9,0x000000a9, + 0x00000000,0x00000001,0x00000002,0x0004003d,0x00000044,0x000000ab,0x00000046,0x00050094, + 0x00000006,0x000000ac,0x000000aa,0x000000ab,0x0003003e,0x000000a4,0x000000ac,0x0004003d, + 0x00000014,0x000000ae,0x00000019,0x00050041,0x0000002c,0x000000af,0x00000018,0x00000037, + 0x0004003d,0x00000009,0x000000b0,0x000000af,0x0007004f,0x00000007,0x000000b1,0x000000b0, + 0x000000b0,0x00000002,0x00000003,0x00050057,0x00000009,0x000000b2,0x000000ae,0x000000b1, + 0x0008004f,0x00000044,0x000000b3,0x000000b2,0x000000b2,0x00000000,0x00000001,0x00000002, + 0x0004003d,0x00000044,0x000000b4,0x00000046,0x00050094,0x00000006,0x000000b5,0x000000b3, + 0x000000b4,0x0003003e,0x000000ad,0x000000b5,0x0004003d,0x00000006,0x000000b6,0x00000053, + 0x0004003d,0x00000006,0x000000b7,0x0000005c,0x00050050,0x00000007,0x000000b8,0x000000b6, + 0x000000b7,0x0004003d,0x00000006,0x000000b9,0x000000a4,0x0004003d,0x00000006,0x000000ba, + 0x000000ad,0x00050050,0x00000007,0x000000bb,0x000000b9,0x000000ba,0x00050083,0x00000007, + 0x000000bc,0x000000b8,0x000000bb,0x0006000c,0x00000007,0x000000bd,0x00000001,0x00000004, + 0x000000bc,0x00050041,0x0000004b,0x000000be,0x00000065,0x00000099,0x00050051,0x00000006, + 0x000000bf,0x000000bd,0x00000000,0x0003003e,0x000000be,0x000000bf,0x00050041,0x0000004b, + 0x000000c0,0x00000065,0x0000000b,0x00050051,0x00000006,0x000000c1,0x000000bd,0x00000001, + 0x0003003e,0x000000c0,0x000000c1,0x0004003d,0x00000007,0x000000c2,0x0000009e,0x0004003d, + 0x00000009,0x000000c3,0x00000065,0x0007004f,0x00000007,0x000000c4,0x000000c3,0x000000c3, + 0x00000002,0x00000003,0x0007000c,0x00000007,0x000000c5,0x00000001,0x00000028,0x000000c2, + 0x000000c4,0x0003003e,0x0000009e,0x000000c5,0x00050041,0x0000004b,0x000000c7,0x0000009e, + 0x0000006d,0x0004003d,0x00000006,0x000000c8,0x000000c7,0x00050041,0x0000004b,0x000000c9, + 0x0000009e,0x00000070,0x0004003d,0x00000006,0x000000ca,0x000000c9,0x0007000c,0x00000006, + 0x000000cb,0x00000001,0x00000028,0x000000c8,0x000000ca,0x0003003e,0x000000c6,0x000000cb, + 0x0004003d,0x00000006,0x000000cc,0x000000c6,0x0004003d,0x00000009,0x000000ce,0x00000065, + 0x0007004f,0x00000007,0x000000cf,0x000000ce,0x000000ce,0x00000000,0x00000001,0x0005008e, + 0x00000007,0x000000d0,0x000000cf,0x000000cd,0x00050050,0x00000007,0x000000d1,0x000000cc, + 0x000000cc,0x0007000c,0x00000007,0x000000d2,0x00000001,0x00000030,0x000000d1,0x000000d0, + 0x0004003d,0x00000007,0x000000d3,0x00000073,0x00050085,0x00000007,0x000000d4,0x000000d3, + 0x000000d2,0x0003003e,0x00000073,0x000000d4,0x0004003d,0x00000007,0x000000d5,0x00000073, + 0x000200fe,0x000000d5,0x00010038 }; diff --git a/app/src/main/cpp/shaders/smaa_tables.h b/app/src/main/cpp/shaders/smaa_tables.h new file mode 100644 index 0000000000..ebc28d815b --- /dev/null +++ b/app/src/main/cpp/shaders/smaa_tables.h @@ -0,0 +1,1375 @@ +/** + * Copyright (C) 2013 Jorge Jimenez (jorge@iryoku.com) + * Copyright (C) 2013 Jose I. Echevarria (joseignacioechevarria@gmail.com) + * Copyright (C) 2013 Belen Masia (bmasia@unizar.es) + * Copyright (C) 2013 Fernando Navarro (fernandn@microsoft.com) + * Copyright (C) 2013 Diego Gutierrez (diegog@unizar.es) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to + * do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. As clarification, there + * is no requirement that the copyright notice and permission be included in + * binary distributions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/* SMAA's lookup tables, from Textures/AreaTex.h and Textures/SearchTex.h of github.com/iryoku/smaa. + * SMAA 1x reads only the first 80 of the area table's 560 rows; the other rows are not included. */ +#pragma once + +#define SMAA_AREA_W 160 +#define SMAA_AREA_H 560 +#define SMAA_AREA_ROWS 80 +#define SMAA_SEARCH_W 64 +#define SMAA_SEARCH_H 16 + +static const unsigned char kSmaaArea[SMAA_AREA_W * SMAA_AREA_ROWS * 2] = { + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x40,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x44,0x7b,0x41,0x5d,0x42,0x54,0x41,0x4f,0x42,0x4b,0x42,0x49,0x42,0x48,0x41,0x47,0x42,0x46,0x42,0x45, + 0x42,0x45,0x42,0x44,0x42,0x44,0x42,0x44,0x42,0x43,0x41,0x43,0x42,0x43,0x42,0x43,0x42,0x43,0x42,0x43, + 0x04,0x7f,0x22,0x3d,0x2b,0x3d,0x30,0x3d,0x33,0x3d,0x35,0x3d,0x37,0x3d,0x38,0x3d,0x39,0x3d,0x39,0x3d, + 0x3a,0x3d,0x3a,0x3d,0x3b,0x3d,0x3b,0x3d,0x3b,0x3d,0x3c,0x3d,0x3c,0x3d,0x3c,0x3d,0x3c,0x3d,0x3c,0x3d, + 0x40,0x7f,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3f,0x00,0x0a,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3f,0x00,0x0a,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x62,0x20,0x4d,0x2a,0x48,0x30,0x44,0x33,0x44,0x35,0x44,0x36,0x43,0x37,0x42,0x38,0x43,0x39,0x42,0x39, + 0x42,0x3a,0x42,0x3a,0x42,0x3b,0x42,0x3b,0x42,0x3b,0x41,0x3b,0x42,0x3c,0x42,0x3c,0x42,0x3c,0x42,0x3c, + 0x00,0x5d,0x0c,0x49,0x16,0x43,0x1d,0x41,0x22,0x40,0x26,0x3f,0x29,0x3f,0x2c,0x3f,0x2e,0x3e,0x2f,0x3e, + 0x31,0x3e,0x32,0x3e,0x33,0x3e,0x33,0x3e,0x34,0x3e,0x35,0x3e,0x35,0x3e,0x36,0x3e,0x37,0x3e,0x37,0x3e, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x66,0x00,0x3f,0x00,0x03,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x66,0x00,0x3f,0x00, + 0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x6d,0x0b,0x57,0x16,0x4f,0x1d,0x4a,0x22,0x48,0x26,0x47,0x29,0x46,0x2b,0x44,0x2d,0x44,0x2f,0x44,0x30, + 0x44,0x31,0x44,0x32,0x43,0x33,0x43,0x34,0x43,0x34,0x42,0x35,0x43,0x36,0x42,0x36,0x42,0x37,0x42,0x37, + 0x00,0x68,0x06,0x54,0x0d,0x4b,0x14,0x47,0x19,0x44,0x1d,0x43,0x20,0x41,0x23,0x41,0x26,0x40,0x27,0x40, + 0x29,0x3f,0x2b,0x3f,0x2c,0x3f,0x2d,0x3f,0x2e,0x3f,0x2f,0x3f,0x30,0x3f,0x30,0x3e,0x31,0x3e,0x32,0x3e, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x72,0x00,0x5c,0x00,0x2d,0x00,0x01, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x72,0x00,0x5c,0x00, + 0x2d,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x42,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x72,0x06,0x5f,0x0d,0x56,0x14,0x4f,0x19,0x4d,0x1d,0x4a,0x20,0x49,0x23,0x47,0x25,0x46,0x27,0x46,0x29, + 0x45,0x2a,0x45,0x2c,0x44,0x2d,0x44,0x2e,0x44,0x2f,0x43,0x30,0x44,0x30,0x44,0x31,0x43,0x32,0x43,0x33, + 0x00,0x6d,0x04,0x5b,0x09,0x51,0x0e,0x4c,0x13,0x48,0x17,0x46,0x1a,0x44,0x1d,0x43,0x1f,0x42,0x22,0x42, + 0x24,0x41,0x25,0x41,0x27,0x40,0x28,0x40,0x29,0x40,0x2a,0x3f,0x2b,0x3f,0x2c,0x3f,0x2d,0x3f,0x2e,0x3f, + 0x42,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x78,0x00,0x6a,0x00,0x48,0x00,0x22, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x78,0x00,0x6a,0x00, + 0x48,0x00,0x22,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x75,0x03,0x64,0x09,0x5a,0x0e,0x54,0x13,0x51,0x17,0x4e,0x1a,0x4c,0x1d,0x49,0x1f,0x49,0x22,0x48,0x23, + 0x47,0x25,0x46,0x26,0x46,0x28,0x45,0x29,0x45,0x2a,0x44,0x2b,0x44,0x2c,0x44,0x2d,0x44,0x2e,0x44,0x2e, + 0x00,0x70,0x02,0x60,0x07,0x56,0x0b,0x50,0x0f,0x4c,0x12,0x49,0x16,0x47,0x18,0x46,0x1b,0x45,0x1d,0x44, + 0x1f,0x43,0x21,0x42,0x22,0x42,0x24,0x41,0x25,0x41,0x26,0x40,0x27,0x40,0x28,0x40,0x29,0x40,0x2a,0x3f, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7a,0x00,0x71,0x00,0x59,0x00,0x3a, + 0x00,0x1b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7a,0x00,0x71,0x00, + 0x59,0x00,0x3a,0x00,0x1b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x77,0x02,0x68,0x06,0x5f,0x0b,0x58,0x0f,0x54,0x12,0x51,0x15,0x4f,0x18,0x4c,0x1b,0x4b,0x1d,0x4a,0x1f, + 0x49,0x21,0x48,0x22,0x48,0x23,0x47,0x25,0x46,0x26,0x45,0x27,0x45,0x28,0x45,0x29,0x45,0x2a,0x44,0x2b, + 0x00,0x72,0x02,0x64,0x05,0x5b,0x08,0x54,0x0c,0x50,0x0f,0x4d,0x12,0x4a,0x14,0x48,0x17,0x47,0x19,0x46, + 0x1b,0x45,0x1d,0x44,0x1f,0x44,0x20,0x42,0x21,0x42,0x22,0x42,0x24,0x41,0x25,0x41,0x26,0x41,0x27,0x40, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0x00,0x75,0x00,0x63,0x00,0x4a, + 0x00,0x30,0x00,0x16,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0x00,0x75,0x00, + 0x63,0x00,0x4a,0x00,0x30,0x00,0x16,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x78,0x02,0x6b,0x05,0x62,0x08,0x5b,0x0c,0x57,0x0f,0x54,0x12,0x51,0x14,0x4e,0x17,0x4d,0x19,0x4c,0x1b, + 0x4b,0x1d,0x4a,0x1e,0x49,0x20,0x48,0x21,0x48,0x22,0x46,0x24,0x46,0x25,0x46,0x26,0x46,0x27,0x45,0x27, + 0x00,0x74,0x01,0x66,0x04,0x5e,0x07,0x57,0x0a,0x53,0x0d,0x4f,0x10,0x4d,0x12,0x4b,0x14,0x49,0x16,0x48, + 0x18,0x46,0x1a,0x45,0x1b,0x45,0x1d,0x44,0x1e,0x44,0x20,0x43,0x21,0x42,0x22,0x42,0x23,0x42,0x24,0x41, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0x00,0x78,0x00,0x6a,0x00,0x56, + 0x00,0x3f,0x00,0x28,0x00,0x13,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0x00,0x78,0x00, + 0x6a,0x00,0x56,0x00,0x3f,0x00,0x28,0x00,0x13,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x79,0x01,0x6d,0x04,0x65,0x07,0x5e,0x0a,0x5a,0x0d,0x56,0x0f,0x54,0x12,0x51,0x14,0x4f,0x16,0x4e,0x18, + 0x4c,0x1a,0x4b,0x1b,0x4b,0x1d,0x4a,0x1e,0x49,0x1f,0x48,0x21,0x48,0x22,0x48,0x23,0x47,0x23,0x46,0x25, + 0x00,0x75,0x01,0x69,0x03,0x61,0x06,0x5a,0x08,0x56,0x0b,0x52,0x0d,0x4f,0x10,0x4d,0x12,0x4b,0x14,0x4a, + 0x16,0x48,0x17,0x47,0x19,0x46,0x1a,0x45,0x1c,0x45,0x1d,0x44,0x1e,0x44,0x1f,0x44,0x20,0x43,0x21,0x42, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7d,0x00,0x79,0x00,0x6e,0x00,0x5e, + 0x00,0x4b,0x00,0x37,0x00,0x23,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7d,0x00,0x79,0x00, + 0x6e,0x00,0x5e,0x00,0x4b,0x00,0x37,0x00,0x23,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7a,0x01,0x6f,0x03,0x67,0x06,0x60,0x08,0x5d,0x0b,0x59,0x0d,0x56,0x10,0x53,0x11,0x51,0x14,0x50,0x15, + 0x4e,0x17,0x4d,0x19,0x4c,0x1a,0x4b,0x1b,0x4b,0x1d,0x48,0x1e,0x49,0x1f,0x49,0x20,0x48,0x21,0x48,0x22, + 0x00,0x76,0x01,0x6b,0x03,0x63,0x05,0x5d,0x07,0x58,0x09,0x54,0x0c,0x52,0x0e,0x4f,0x10,0x4d,0x11,0x4c, + 0x13,0x4a,0x15,0x49,0x17,0x48,0x18,0x47,0x19,0x46,0x1b,0x45,0x1c,0x45,0x1d,0x44,0x1e,0x44,0x1f,0x44, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7d,0x00,0x7a,0x00,0x72,0x00,0x64, + 0x00,0x54,0x00,0x42,0x00,0x30,0x00,0x1f,0x00,0x0e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7d,0x00,0x7a,0x00, + 0x72,0x00,0x64,0x00,0x54,0x00,0x42,0x00,0x30,0x00,0x1f,0x00,0x0e,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7b,0x01,0x71,0x02,0x69,0x05,0x63,0x07,0x5f,0x09,0x5b,0x0c,0x58,0x0e,0x55,0x10,0x53,0x11,0x52,0x13, + 0x50,0x15,0x4e,0x16,0x4e,0x18,0x4c,0x19,0x4c,0x1a,0x4a,0x1c,0x4b,0x1d,0x49,0x1e,0x49,0x1f,0x49,0x20, + 0x00,0x77,0x00,0x6c,0x02,0x65,0x04,0x5f,0x06,0x5a,0x08,0x57,0x0a,0x54,0x0c,0x51,0x0e,0x4f,0x10,0x4d, + 0x11,0x4c,0x13,0x4a,0x15,0x49,0x16,0x48,0x18,0x48,0x18,0x46,0x1a,0x46,0x1b,0x45,0x1c,0x45,0x1d,0x45, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7b,0x00,0x74,0x00,0x69, + 0x00,0x5b,0x00,0x4b,0x00,0x3b,0x00,0x2b,0x00,0x1b,0x00,0x0d,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7b,0x00, + 0x74,0x00,0x69,0x00,0x5b,0x00,0x4b,0x00,0x3b,0x00,0x2b,0x00,0x1b,0x00,0x0d,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7b,0x00,0x72,0x02,0x6b,0x04,0x64,0x06,0x61,0x08,0x5d,0x0a,0x5a,0x0c,0x56,0x0e,0x55,0x10,0x53,0x11, + 0x52,0x13,0x50,0x15,0x4f,0x16,0x4e,0x17,0x4d,0x18,0x4b,0x1a,0x4b,0x1a,0x4b,0x1c,0x4b,0x1d,0x49,0x1d, + 0x00,0x77,0x00,0x6e,0x02,0x66,0x04,0x61,0x05,0x5c,0x07,0x59,0x09,0x56,0x0b,0x53,0x0d,0x51,0x0f,0x4f, + 0x10,0x4e,0x11,0x4c,0x13,0x4b,0x14,0x4a,0x15,0x48,0x17,0x48,0x18,0x47,0x19,0x46,0x1b,0x46,0x1b,0x45, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7c,0x00,0x76,0x00,0x6d, + 0x00,0x61,0x00,0x53,0x00,0x44,0x00,0x35,0x00,0x27,0x00,0x19,0x00,0x0c,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7c,0x00, + 0x76,0x00,0x6d,0x00,0x61,0x00,0x53,0x00,0x44,0x00,0x35,0x00,0x27,0x00,0x19,0x00,0x0c,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7c,0x00,0x73,0x02,0x6c,0x03,0x66,0x05,0x63,0x07,0x5e,0x09,0x5c,0x0b,0x58,0x0c,0x57,0x0e,0x55,0x10, + 0x53,0x11,0x52,0x13,0x50,0x14,0x4f,0x15,0x4e,0x17,0x4c,0x18,0x4c,0x19,0x4c,0x1a,0x4b,0x1a,0x4b,0x1c, + 0x00,0x77,0x00,0x6f,0x02,0x68,0x03,0x63,0x05,0x5e,0x06,0x5a,0x08,0x57,0x0a,0x55,0x0b,0x53,0x0d,0x50, + 0x0f,0x4f,0x10,0x4e,0x11,0x4c,0x13,0x4b,0x14,0x4a,0x15,0x49,0x16,0x48,0x18,0x48,0x18,0x46,0x19,0x46, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7c,0x00,0x77,0x00,0x6f, + 0x00,0x65,0x00,0x59,0x00,0x4c,0x00,0x3e,0x00,0x30,0x00,0x23,0x00,0x16,0x00,0x0b,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7c,0x00, + 0x77,0x00,0x6f,0x00,0x65,0x00,0x59,0x00,0x4c,0x00,0x3e,0x00,0x30,0x00,0x23,0x00,0x16,0x00,0x0b,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7c,0x00,0x74,0x02,0x6e,0x03,0x68,0x05,0x64,0x06,0x60,0x08,0x5d,0x0a,0x5a,0x0b,0x58,0x0d,0x56,0x0e, + 0x55,0x10,0x53,0x11,0x52,0x13,0x50,0x14,0x50,0x15,0x4d,0x16,0x4e,0x18,0x4c,0x18,0x4c,0x19,0x4c,0x1a, + 0x00,0x78,0x00,0x70,0x01,0x69,0x03,0x64,0x04,0x60,0x06,0x5c,0x07,0x59,0x09,0x56,0x0b,0x54,0x0c,0x52, + 0x0d,0x50,0x0f,0x4f,0x10,0x4e,0x11,0x4c,0x13,0x4b,0x13,0x4a,0x15,0x4a,0x15,0x48,0x17,0x48,0x18,0x47, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7d,0x00,0x78,0x00,0x71, + 0x00,0x68,0x00,0x5e,0x00,0x52,0x00,0x45,0x00,0x39,0x00,0x2c,0x00,0x20,0x00,0x15,0x00,0x0a,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7d,0x00, + 0x78,0x00,0x71,0x00,0x68,0x00,0x5e,0x00,0x52,0x00,0x45,0x00,0x39,0x00,0x2c,0x00,0x20,0x00,0x15,0x00, + 0x0a,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7d,0x00,0x75,0x01,0x6f,0x02,0x69,0x04,0x65,0x06,0x62,0x07,0x5f,0x09,0x5b,0x0b,0x5a,0x0c,0x58,0x0d, + 0x56,0x0e,0x55,0x10,0x53,0x11,0x52,0x13,0x50,0x13,0x4f,0x15,0x4e,0x15,0x4e,0x17,0x4d,0x18,0x4c,0x18, + 0x00,0x78,0x00,0x71,0x01,0x6a,0x03,0x66,0x04,0x61,0x05,0x5d,0x06,0x5a,0x08,0x58,0x09,0x55,0x0b,0x53, + 0x0d,0x52,0x0e,0x50,0x0f,0x4e,0x10,0x4e,0x11,0x4c,0x13,0x4c,0x13,0x4a,0x15,0x4a,0x15,0x49,0x16,0x48, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7d,0x00,0x79,0x00,0x73, + 0x00,0x6b,0x00,0x62,0x00,0x57,0x00,0x4c,0x00,0x40,0x00,0x34,0x00,0x29,0x00,0x1e,0x00,0x13,0x00,0x09, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7d,0x00, + 0x79,0x00,0x73,0x00,0x6b,0x00,0x62,0x00,0x57,0x00,0x4c,0x00,0x40,0x00,0x34,0x00,0x29,0x00,0x1e,0x00, + 0x13,0x00,0x09,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7d,0x00,0x76,0x01,0x70,0x02,0x6a,0x03,0x67,0x05,0x63,0x06,0x60,0x08,0x5d,0x09,0x5b,0x0b,0x59,0x0c, + 0x57,0x0d,0x55,0x0e,0x55,0x10,0x53,0x11,0x52,0x13,0x4f,0x13,0x50,0x15,0x4f,0x15,0x4e,0x16,0x4e,0x18, + 0x00,0x79,0x00,0x71,0x01,0x6c,0x02,0x66,0x04,0x62,0x05,0x5f,0x06,0x5c,0x07,0x59,0x09,0x57,0x0a,0x55, + 0x0b,0x53,0x0d,0x51,0x0e,0x50,0x0f,0x4e,0x11,0x4e,0x11,0x4c,0x13,0x4c,0x13,0x4b,0x14,0x4a,0x15,0x4a, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7d,0x00,0x7a,0x00,0x75, + 0x00,0x6e,0x00,0x65,0x00,0x5b,0x00,0x51,0x00,0x46,0x00,0x3b,0x00,0x30,0x00,0x26,0x00,0x1b,0x00,0x12, + 0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7d,0x00, + 0x7a,0x00,0x75,0x00,0x6e,0x00,0x65,0x00,0x5b,0x00,0x51,0x00,0x46,0x00,0x3b,0x00,0x30,0x00,0x26,0x00, + 0x1b,0x00,0x12,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7d,0x00,0x76,0x01,0x71,0x02,0x6c,0x03,0x68,0x05,0x64,0x06,0x61,0x07,0x5e,0x09,0x5c,0x0a,0x5a,0x0b, + 0x59,0x0c,0x57,0x0e,0x55,0x0e,0x55,0x11,0x52,0x11,0x51,0x12,0x51,0x13,0x50,0x14,0x4f,0x15,0x4e,0x15, + 0x00,0x79,0x00,0x72,0x01,0x6d,0x02,0x68,0x03,0x63,0x04,0x60,0x06,0x5d,0x07,0x5b,0x08,0x58,0x09,0x56, + 0x0b,0x54,0x0c,0x53,0x0d,0x51,0x0e,0x50,0x0f,0x4e,0x11,0x4e,0x11,0x4c,0x12,0x4c,0x13,0x4b,0x14,0x4a, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x1f,0x00,0x3f,0x00,0x66,0x00,0x72,0x00,0x78,0x00,0x7a,0x00,0x7c,0x00,0x7c,0x00,0x7d,0x00,0x7d, + 0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00,0x7d,0x00,0x58,0x00,0x70,0x00,0x77, + 0x00,0x79,0x00,0x7b,0x00,0x7c,0x00,0x7c,0x00,0x7d,0x00,0x7d,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00,0x7e, + 0x00,0x7e,0x00,0x7e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0x1f,0x00,0x3f, + 0x00,0x66,0x00,0x72,0x00,0x78,0x00,0x7a,0x00,0x7c,0x00,0x7c,0x00,0x7d,0x00,0x7d,0x00,0x7e,0x00,0x7e, + 0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x1f,0x1f,0x00,0x3f,0x00,0x66,0x00,0x72,0x00,0x78,0x00,0x7a, + 0x00,0x7c,0x00,0x7c,0x00,0x7d,0x00,0x7d,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00,0x7e, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7d,0x00,0x77,0x01,0x72,0x02,0x6d,0x03,0x69,0x04,0x66,0x06,0x63,0x07,0x5f,0x08,0x5e,0x09,0x5c,0x0b, + 0x5a,0x0c,0x58,0x0c,0x57,0x0e,0x55,0x0f,0x54,0x11,0x51,0x11,0x52,0x12,0x51,0x13,0x50,0x14,0x50,0x15, + 0x00,0x79,0x00,0x73,0x01,0x6d,0x02,0x69,0x03,0x65,0x04,0x61,0x05,0x5e,0x06,0x5c,0x07,0x59,0x09,0x57, + 0x0a,0x55,0x0b,0x54,0x0d,0x53,0x0d,0x51,0x0f,0x50,0x0f,0x4e,0x11,0x4e,0x11,0x4c,0x12,0x4c,0x13,0x4b, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x0a,0x00,0x3f,0x00,0x5c,0x00,0x6a,0x00,0x71,0x00,0x75,0x00,0x78,0x00,0x79,0x00,0x7a, + 0x00,0x7b,0x00,0x7c,0x00,0x7c,0x00,0x7d,0x00,0x7d,0x00,0x7d,0x00,0x58,0x00,0x44,0x00,0x55,0x00,0x67, + 0x00,0x6e,0x00,0x72,0x00,0x75,0x00,0x78,0x00,0x79,0x00,0x7a,0x00,0x7b,0x00,0x7c,0x00,0x7c,0x00,0x7d, + 0x00,0x7d,0x00,0x7d,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3f,0x00,0x0a,0x0a, + 0x00,0x3f,0x00,0x5c,0x00,0x6a,0x00,0x71,0x00,0x75,0x00,0x78,0x00,0x79,0x00,0x7a,0x00,0x7b,0x00,0x7c, + 0x00,0x7c,0x00,0x7d,0x00,0x7d,0x00,0x7d,0x3f,0x00,0x0a,0x0a,0x00,0x3f,0x00,0x5c,0x00,0x6a,0x00,0x71, + 0x00,0x75,0x00,0x78,0x00,0x79,0x00,0x7a,0x00,0x7b,0x00,0x7c,0x00,0x7c,0x00,0x7d,0x00,0x7d,0x00,0x7d, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7d,0x00,0x78,0x01,0x72,0x02,0x6e,0x02,0x6a,0x03,0x67,0x05,0x64,0x06,0x60,0x07,0x5f,0x09,0x5c,0x0a, + 0x5b,0x0b,0x5a,0x0c,0x57,0x0c,0x56,0x0e,0x55,0x0f,0x53,0x11,0x52,0x11,0x52,0x12,0x51,0x13,0x50,0x13, + 0x00,0x79,0x00,0x73,0x01,0x6e,0x02,0x69,0x03,0x66,0x04,0x62,0x05,0x5f,0x06,0x5d,0x07,0x5b,0x08,0x58, + 0x09,0x56,0x0b,0x55,0x0b,0x53,0x0d,0x52,0x0d,0x50,0x0f,0x50,0x0f,0x4e,0x11,0x4e,0x11,0x4d,0x12,0x4c, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x2d,0x00,0x48,0x00,0x59,0x00,0x63,0x00,0x6a,0x00,0x6e,0x00,0x72, + 0x00,0x74,0x00,0x76,0x00,0x77,0x00,0x78,0x00,0x79,0x00,0x7a,0x00,0x70,0x00,0x55,0x00,0x20,0x00,0x3e, + 0x00,0x50,0x00,0x5a,0x00,0x63,0x00,0x6a,0x00,0x6e,0x00,0x72,0x00,0x74,0x00,0x76,0x00,0x77,0x00,0x78, + 0x00,0x79,0x00,0x7a,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x66,0x00,0x3f,0x00, + 0x03,0x03,0x00,0x2d,0x00,0x48,0x00,0x59,0x00,0x63,0x00,0x6a,0x00,0x6e,0x00,0x72,0x00,0x74,0x00,0x76, + 0x00,0x77,0x00,0x78,0x00,0x79,0x00,0x7a,0x66,0x00,0x3f,0x00,0x03,0x03,0x00,0x2d,0x00,0x48,0x00,0x59, + 0x00,0x63,0x00,0x6a,0x00,0x6e,0x00,0x72,0x00,0x74,0x00,0x76,0x00,0x77,0x00,0x78,0x00,0x79,0x00,0x7a, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7e,0x00,0x78,0x01,0x73,0x02,0x6e,0x02,0x6b,0x03,0x68,0x05,0x65,0x06,0x61,0x07,0x5f,0x07,0x5e,0x09, + 0x5c,0x0b,0x5a,0x0b,0x59,0x0c,0x57,0x0d,0x56,0x0e,0x54,0x0f,0x54,0x11,0x52,0x11,0x52,0x12,0x51,0x13, + 0x00,0x79,0x00,0x74,0x00,0x6f,0x02,0x6a,0x03,0x66,0x04,0x63,0x05,0x60,0x05,0x5e,0x06,0x5b,0x07,0x59, + 0x09,0x58,0x09,0x55,0x0b,0x55,0x0c,0x53,0x0d,0x52,0x0d,0x50,0x0f,0x50,0x0f,0x4e,0x11,0x4e,0x11,0x4d, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x22,0x00,0x3a,0x00,0x4a,0x00,0x56,0x00,0x5e,0x00,0x64, + 0x00,0x69,0x00,0x6d,0x00,0x6f,0x00,0x71,0x00,0x73,0x00,0x75,0x00,0x77,0x00,0x67,0x00,0x3e,0x00,0x0d, + 0x00,0x28,0x00,0x3a,0x00,0x4a,0x00,0x56,0x00,0x5e,0x00,0x64,0x00,0x69,0x00,0x6d,0x00,0x6f,0x00,0x71, + 0x00,0x73,0x00,0x75,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x72,0x00,0x5c,0x00, + 0x2d,0x00,0x01,0x01,0x00,0x22,0x00,0x3a,0x00,0x4a,0x00,0x56,0x00,0x5e,0x00,0x64,0x00,0x69,0x00,0x6d, + 0x00,0x6f,0x00,0x71,0x00,0x73,0x00,0x75,0x72,0x00,0x5c,0x00,0x2d,0x00,0x01,0x01,0x00,0x22,0x00,0x3a, + 0x00,0x4a,0x00,0x56,0x00,0x5e,0x00,0x64,0x00,0x69,0x00,0x6d,0x00,0x6f,0x00,0x71,0x00,0x73,0x00,0x75, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7e,0x00,0x78,0x00,0x74,0x01,0x6f,0x02,0x6c,0x03,0x68,0x04,0x65,0x05,0x62,0x06,0x61,0x07,0x5f,0x09, + 0x5c,0x09,0x5b,0x0b,0x5a,0x0b,0x58,0x0c,0x57,0x0d,0x55,0x0e,0x55,0x0f,0x54,0x11,0x52,0x11,0x52,0x12, + 0x00,0x79,0x00,0x74,0x00,0x70,0x01,0x6b,0x02,0x67,0x03,0x64,0x04,0x61,0x05,0x5f,0x06,0x5d,0x07,0x5b, + 0x08,0x58,0x09,0x57,0x0a,0x55,0x0b,0x54,0x0c,0x53,0x0d,0x51,0x0e,0x50,0x0f,0x50,0x0f,0x4e,0x11,0x4e, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1b,0x00,0x30,0x00,0x3f,0x00,0x4b,0x00,0x54, + 0x00,0x5b,0x00,0x61,0x00,0x65,0x00,0x68,0x00,0x6b,0x00,0x6e,0x00,0x79,0x00,0x6e,0x00,0x50,0x00,0x28, + 0x00,0x01,0x00,0x1b,0x00,0x30,0x00,0x3f,0x00,0x4b,0x00,0x54,0x00,0x5b,0x00,0x61,0x00,0x65,0x00,0x68, + 0x00,0x6b,0x00,0x6e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x78,0x00,0x6a,0x00, + 0x48,0x00,0x22,0x00,0x00,0x00,0x00,0x1b,0x00,0x30,0x00,0x3f,0x00,0x4b,0x00,0x54,0x00,0x5b,0x00,0x61, + 0x00,0x65,0x00,0x68,0x00,0x6b,0x00,0x6e,0x78,0x00,0x6a,0x00,0x48,0x00,0x22,0x00,0x00,0x00,0x00,0x1b, + 0x00,0x30,0x00,0x3f,0x00,0x4b,0x00,0x54,0x00,0x5b,0x00,0x61,0x00,0x65,0x00,0x68,0x00,0x6b,0x00,0x6e, + 0x21,0x5d,0x0c,0x68,0x06,0x6d,0x04,0x71,0x02,0x72,0x02,0x74,0x01,0x75,0x01,0x76,0x01,0x77,0x00,0x77, + 0x00,0x77,0x00,0x78,0x00,0x78,0x00,0x79,0x00,0x79,0x00,0x79,0x00,0x79,0x00,0x79,0x00,0x79,0x00,0x7a, + 0x42,0x40,0x17,0x55,0x0c,0x60,0x08,0x66,0x05,0x6a,0x04,0x6d,0x03,0x6f,0x02,0x71,0x02,0x73,0x01,0x73, + 0x01,0x74,0x01,0x75,0x01,0x76,0x01,0x77,0x00,0x77,0x00,0x77,0x00,0x78,0x00,0x78,0x00,0x78,0x00,0x78, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x21,0x5d,0x0c,0x68,0x06,0x6d,0x04,0x71,0x02,0x72,0x02,0x74,0x01,0x75,0x01,0x76,0x01,0x77,0x00,0x77, + 0x00,0x77,0x00,0x78,0x00,0x78,0x00,0x79,0x00,0x79,0x00,0x79,0x00,0x79,0x00,0x79,0x00,0x79,0x00,0x7a, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x16,0x00,0x28,0x00,0x37,0x00,0x42, + 0x00,0x4b,0x00,0x53,0x00,0x59,0x00,0x5e,0x00,0x62,0x00,0x65,0x00,0x7b,0x00,0x72,0x00,0x5a,0x00,0x3a, + 0x00,0x1b,0x00,0x01,0x00,0x16,0x00,0x28,0x00,0x37,0x00,0x42,0x00,0x4b,0x00,0x53,0x00,0x59,0x00,0x5e, + 0x00,0x62,0x00,0x65,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7a,0x00,0x71,0x00, + 0x59,0x00,0x3a,0x00,0x1b,0x00,0x00,0x00,0x00,0x16,0x00,0x28,0x00,0x37,0x00,0x42,0x00,0x4b,0x00,0x53, + 0x00,0x59,0x00,0x5e,0x00,0x62,0x00,0x65,0x7a,0x00,0x71,0x00,0x59,0x00,0x3a,0x00,0x1b,0x00,0x00,0x00, + 0x00,0x16,0x00,0x28,0x00,0x37,0x00,0x42,0x00,0x4b,0x00,0x53,0x00,0x59,0x00,0x5e,0x00,0x62,0x00,0x65, + 0x2b,0x49,0x16,0x53,0x0d,0x5b,0x09,0x60,0x07,0x64,0x05,0x67,0x04,0x69,0x03,0x6b,0x03,0x6c,0x02,0x6e, + 0x02,0x6f,0x02,0x70,0x01,0x71,0x01,0x71,0x01,0x72,0x01,0x73,0x01,0x73,0x01,0x74,0x00,0x74,0x00,0x75, + 0x57,0x16,0x2d,0x2c,0x1b,0x3b,0x12,0x45,0x0d,0x4d,0x0b,0x53,0x08,0x57,0x07,0x5b,0x05,0x5e,0x05,0x61, + 0x04,0x63,0x04,0x65,0x03,0x67,0x02,0x68,0x02,0x69,0x02,0x6b,0x02,0x6c,0x01,0x6d,0x01,0x6e,0x01,0x6f, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x2b,0x49,0x16,0x53,0x0d,0x5b,0x09,0x60,0x07,0x64,0x05,0x67,0x04,0x69,0x03,0x6b,0x03,0x6c,0x02,0x6e, + 0x02,0x6f,0x02,0x70,0x01,0x71,0x01,0x71,0x01,0x72,0x01,0x73,0x01,0x73,0x01,0x74,0x00,0x74,0x00,0x75, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x13,0x00,0x23,0x00,0x30, + 0x00,0x3b,0x00,0x44,0x00,0x4c,0x00,0x52,0x00,0x57,0x00,0x5b,0x00,0x7c,0x00,0x75,0x00,0x63,0x00,0x4a, + 0x00,0x30,0x00,0x16,0x00,0x00,0x00,0x13,0x00,0x23,0x00,0x30,0x00,0x3b,0x00,0x44,0x00,0x4c,0x00,0x52, + 0x00,0x57,0x00,0x5b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0x00,0x75,0x00, + 0x63,0x00,0x4a,0x00,0x30,0x00,0x16,0x00,0x00,0x00,0x00,0x13,0x00,0x23,0x00,0x30,0x00,0x3b,0x00,0x44, + 0x00,0x4c,0x00,0x52,0x00,0x57,0x00,0x5b,0x7c,0x00,0x75,0x00,0x63,0x00,0x4a,0x00,0x30,0x00,0x16,0x00, + 0x00,0x00,0x00,0x13,0x00,0x23,0x00,0x30,0x00,0x3b,0x00,0x44,0x00,0x4c,0x00,0x52,0x00,0x57,0x00,0x5b, + 0x31,0x43,0x1d,0x4b,0x14,0x51,0x0e,0x56,0x0b,0x5b,0x08,0x5e,0x07,0x61,0x06,0x63,0x05,0x65,0x04,0x67, + 0x04,0x68,0x03,0x69,0x03,0x6a,0x03,0x6c,0x02,0x6d,0x02,0x6d,0x02,0x6e,0x02,0x6f,0x02,0x70,0x01,0x70, + 0x61,0x0c,0x3b,0x1b,0x28,0x28,0x1d,0x32,0x16,0x3a,0x11,0x41,0x0e,0x47,0x0c,0x4b,0x0a,0x4f,0x09,0x53, + 0x07,0x55,0x06,0x58,0x05,0x5a,0x05,0x5c,0x05,0x5e,0x04,0x60,0x04,0x61,0x04,0x63,0x03,0x64,0x02,0x66, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x31,0x43,0x1d,0x4b,0x14,0x51,0x0e,0x56,0x0b,0x5b,0x08,0x5e,0x07,0x61,0x06,0x63,0x05,0x65,0x04,0x67, + 0x04,0x68,0x03,0x69,0x03,0x6a,0x03,0x6c,0x02,0x6d,0x02,0x6d,0x02,0x6e,0x02,0x6f,0x02,0x70,0x01,0x70, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x1f, + 0x00,0x2b,0x00,0x35,0x00,0x3e,0x00,0x45,0x00,0x4c,0x00,0x51,0x00,0x7c,0x00,0x78,0x00,0x6a,0x00,0x56, + 0x00,0x3f,0x00,0x28,0x00,0x13,0x00,0x00,0x00,0x10,0x00,0x1f,0x00,0x2b,0x00,0x35,0x00,0x3e,0x00,0x45, + 0x00,0x4c,0x00,0x51,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0x00,0x78,0x00, + 0x6a,0x00,0x56,0x00,0x3f,0x00,0x28,0x00,0x13,0x00,0x00,0x00,0x00,0x10,0x00,0x1f,0x00,0x2b,0x00,0x35, + 0x00,0x3e,0x00,0x45,0x00,0x4c,0x00,0x51,0x7c,0x00,0x78,0x00,0x6a,0x00,0x56,0x00,0x3f,0x00,0x28,0x00, + 0x13,0x00,0x00,0x00,0x00,0x10,0x00,0x1f,0x00,0x2b,0x00,0x35,0x00,0x3e,0x00,0x45,0x00,0x4c,0x00,0x51, + 0x33,0x41,0x22,0x46,0x19,0x4c,0x13,0x50,0x0f,0x54,0x0c,0x57,0x0a,0x5a,0x08,0x5d,0x07,0x5f,0x06,0x61, + 0x05,0x63,0x05,0x64,0x04,0x66,0x04,0x66,0x04,0x68,0x03,0x69,0x03,0x69,0x03,0x6a,0x03,0x6b,0x02,0x6c, + 0x67,0x07,0x45,0x12,0x32,0x1d,0x26,0x26,0x1e,0x2e,0x18,0x34,0x14,0x3a,0x11,0x3f,0x0f,0x44,0x0c,0x47, + 0x0b,0x4b,0x0a,0x4d,0x09,0x51,0x07,0x52,0x07,0x55,0x06,0x57,0x05,0x58,0x05,0x5a,0x05,0x5c,0x04,0x5d, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x33,0x41,0x22,0x46,0x19,0x4c,0x13,0x50,0x0f,0x54,0x0c,0x57,0x0a,0x5a,0x08,0x5d,0x07,0x5f,0x06,0x61, + 0x05,0x63,0x05,0x64,0x04,0x66,0x04,0x66,0x04,0x68,0x03,0x69,0x03,0x69,0x03,0x6a,0x03,0x6b,0x02,0x6c, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0e, + 0x00,0x1b,0x00,0x27,0x00,0x30,0x00,0x39,0x00,0x40,0x00,0x46,0x00,0x7d,0x00,0x79,0x00,0x6e,0x00,0x5e, + 0x00,0x4b,0x00,0x37,0x00,0x23,0x00,0x10,0x00,0x00,0x00,0x0e,0x00,0x1b,0x00,0x27,0x00,0x30,0x00,0x39, + 0x00,0x40,0x00,0x46,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7d,0x00,0x79,0x00, + 0x6e,0x00,0x5e,0x00,0x4b,0x00,0x37,0x00,0x23,0x00,0x10,0x00,0x00,0x00,0x00,0x0e,0x00,0x1b,0x00,0x27, + 0x00,0x30,0x00,0x39,0x00,0x40,0x00,0x46,0x7d,0x00,0x79,0x00,0x6e,0x00,0x5e,0x00,0x4b,0x00,0x37,0x00, + 0x23,0x00,0x10,0x00,0x00,0x00,0x00,0x0e,0x00,0x1b,0x00,0x27,0x00,0x30,0x00,0x39,0x00,0x40,0x00,0x46, + 0x35,0x40,0x27,0x44,0x1d,0x48,0x17,0x4c,0x12,0x50,0x0f,0x53,0x0d,0x56,0x0b,0x58,0x09,0x5a,0x08,0x5c, + 0x07,0x5e,0x06,0x60,0x06,0x61,0x05,0x62,0x05,0x63,0x04,0x65,0x04,0x66,0x04,0x66,0x04,0x67,0x03,0x68, + 0x6b,0x05,0x4d,0x0d,0x3b,0x16,0x2e,0x1e,0x25,0x25,0x1f,0x2b,0x1a,0x31,0x16,0x36,0x13,0x3a,0x10,0x3e, + 0x0f,0x42,0x0d,0x45,0x0c,0x47,0x0a,0x4a,0x0a,0x4c,0x09,0x4f,0x07,0x51,0x07,0x52,0x07,0x54,0x06,0x56, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x35,0x40,0x27,0x44,0x1d,0x48,0x17,0x4c,0x12,0x50,0x0f,0x53,0x0d,0x56,0x0b,0x58,0x09,0x5a,0x08,0x5c, + 0x07,0x5e,0x06,0x60,0x06,0x61,0x05,0x62,0x05,0x63,0x04,0x65,0x04,0x66,0x04,0x66,0x04,0x67,0x03,0x68, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x0d,0x00,0x19,0x00,0x23,0x00,0x2c,0x00,0x34,0x00,0x3b,0x00,0x7d,0x00,0x7a,0x00,0x72,0x00,0x64, + 0x00,0x54,0x00,0x42,0x00,0x30,0x00,0x1f,0x00,0x0e,0x00,0x00,0x00,0x0d,0x00,0x19,0x00,0x23,0x00,0x2c, + 0x00,0x34,0x00,0x3b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7d,0x00,0x7a,0x00, + 0x72,0x00,0x64,0x00,0x54,0x00,0x42,0x00,0x30,0x00,0x1f,0x00,0x0e,0x00,0x00,0x00,0x00,0x0d,0x00,0x19, + 0x00,0x23,0x00,0x2c,0x00,0x34,0x00,0x3b,0x7d,0x00,0x7a,0x00,0x72,0x00,0x64,0x00,0x54,0x00,0x42,0x00, + 0x30,0x00,0x1f,0x00,0x0e,0x00,0x00,0x00,0x00,0x0d,0x00,0x19,0x00,0x23,0x00,0x2c,0x00,0x34,0x00,0x3b, + 0x37,0x3f,0x29,0x43,0x21,0x46,0x1a,0x49,0x16,0x4d,0x12,0x50,0x10,0x52,0x0d,0x54,0x0c,0x57,0x0a,0x59, + 0x09,0x5a,0x08,0x5c,0x07,0x5d,0x06,0x5f,0x06,0x60,0x06,0x61,0x05,0x62,0x05,0x63,0x04,0x64,0x04,0x65, + 0x6e,0x04,0x53,0x0a,0x41,0x11,0x34,0x18,0x2b,0x1f,0x24,0x24,0x1f,0x29,0x1b,0x2e,0x17,0x33,0x15,0x37, + 0x12,0x3a,0x10,0x3d,0x0f,0x40,0x0d,0x43,0x0c,0x45,0x0c,0x48,0x0a,0x4a,0x0a,0x4c,0x09,0x4e,0x07,0x4f, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x37,0x3f,0x29,0x43,0x21,0x46,0x1a,0x49,0x16,0x4d,0x12,0x50,0x10,0x52,0x0d,0x54,0x0c,0x57,0x0a,0x59, + 0x09,0x5a,0x08,0x5c,0x07,0x5d,0x06,0x5f,0x06,0x60,0x06,0x61,0x05,0x62,0x05,0x63,0x04,0x64,0x04,0x65, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x0c,0x00,0x16,0x00,0x20,0x00,0x29,0x00,0x30,0x00,0x7e,0x00,0x7b,0x00,0x74,0x00,0x69, + 0x00,0x5b,0x00,0x4b,0x00,0x3b,0x00,0x2b,0x00,0x1b,0x00,0x0d,0x00,0x00,0x00,0x0c,0x00,0x16,0x00,0x20, + 0x00,0x29,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7b,0x00, + 0x74,0x00,0x69,0x00,0x5b,0x00,0x4b,0x00,0x3b,0x00,0x2b,0x00,0x1b,0x00,0x0d,0x00,0x00,0x00,0x00,0x0c, + 0x00,0x16,0x00,0x20,0x00,0x29,0x00,0x30,0x7e,0x00,0x7b,0x00,0x74,0x00,0x69,0x00,0x5b,0x00,0x4b,0x00, + 0x3b,0x00,0x2b,0x00,0x1b,0x00,0x0d,0x00,0x00,0x00,0x00,0x0c,0x00,0x16,0x00,0x20,0x00,0x29,0x00,0x30, + 0x38,0x3f,0x2c,0x41,0x23,0x44,0x1d,0x47,0x19,0x4a,0x14,0x4d,0x12,0x4f,0x10,0x52,0x0e,0x54,0x0c,0x56, + 0x0b,0x57,0x0a,0x59,0x09,0x5a,0x08,0x5c,0x07,0x5d,0x07,0x5e,0x06,0x5f,0x06,0x61,0x05,0x61,0x05,0x62, + 0x70,0x03,0x58,0x08,0x47,0x0e,0x3a,0x14,0x31,0x1a,0x29,0x1f,0x24,0x24,0x20,0x28,0x1c,0x2d,0x19,0x31, + 0x16,0x34,0x14,0x37,0x12,0x3a,0x10,0x3d,0x0f,0x3f,0x0e,0x42,0x0c,0x44,0x0c,0x46,0x0b,0x47,0x0a,0x4a, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x38,0x3f,0x2c,0x41,0x23,0x44,0x1d,0x47,0x19,0x4a,0x14,0x4d,0x12,0x4f,0x10,0x52,0x0e,0x54,0x0c,0x56, + 0x0b,0x57,0x0a,0x59,0x09,0x5a,0x08,0x5c,0x07,0x5d,0x07,0x5e,0x06,0x5f,0x06,0x61,0x05,0x61,0x05,0x62, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x0b,0x00,0x15,0x00,0x1e,0x00,0x26,0x00,0x7e,0x00,0x7c,0x00,0x76,0x00,0x6d, + 0x00,0x61,0x00,0x53,0x00,0x44,0x00,0x35,0x00,0x27,0x00,0x19,0x00,0x0c,0x00,0x00,0x00,0x0b,0x00,0x15, + 0x00,0x1e,0x00,0x26,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7c,0x00, + 0x76,0x00,0x6d,0x00,0x61,0x00,0x53,0x00,0x44,0x00,0x35,0x00,0x27,0x00,0x19,0x00,0x0c,0x00,0x00,0x00, + 0x00,0x0b,0x00,0x15,0x00,0x1e,0x00,0x26,0x7e,0x00,0x7c,0x00,0x76,0x00,0x6d,0x00,0x61,0x00,0x53,0x00, + 0x44,0x00,0x35,0x00,0x27,0x00,0x19,0x00,0x0c,0x00,0x00,0x00,0x00,0x0b,0x00,0x15,0x00,0x1e,0x00,0x26, + 0x39,0x3f,0x2e,0x41,0x26,0x43,0x20,0x46,0x1b,0x48,0x17,0x4b,0x14,0x4d,0x12,0x4f,0x10,0x51,0x0e,0x53, + 0x0d,0x55,0x0b,0x56,0x0b,0x58,0x09,0x59,0x09,0x5b,0x08,0x5b,0x07,0x5d,0x07,0x5e,0x06,0x5f,0x06,0x60, + 0x71,0x02,0x5b,0x07,0x4c,0x0c,0x3f,0x11,0x36,0x16,0x2e,0x1b,0x29,0x20,0x24,0x23,0x20,0x28,0x1d,0x2b, + 0x19,0x2f,0x17,0x32,0x16,0x35,0x12,0x37,0x12,0x3a,0x10,0x3c,0x0f,0x3f,0x0e,0x41,0x0c,0x42,0x0c,0x45, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x39,0x3f,0x2e,0x41,0x26,0x43,0x20,0x46,0x1b,0x48,0x17,0x4b,0x14,0x4d,0x12,0x4f,0x10,0x51,0x0e,0x53, + 0x0d,0x55,0x0b,0x56,0x0b,0x58,0x09,0x59,0x09,0x5b,0x08,0x5b,0x07,0x5d,0x07,0x5e,0x06,0x5f,0x06,0x60, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0a,0x00,0x13,0x00,0x1b,0x00,0x7e,0x00,0x7c,0x00,0x77,0x00,0x6f, + 0x00,0x65,0x00,0x59,0x00,0x4c,0x00,0x3e,0x00,0x30,0x00,0x23,0x00,0x16,0x00,0x0b,0x00,0x00,0x00,0x0a, + 0x00,0x13,0x00,0x1b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7c,0x00, + 0x77,0x00,0x6f,0x00,0x65,0x00,0x59,0x00,0x4c,0x00,0x3e,0x00,0x30,0x00,0x23,0x00,0x16,0x00,0x0b,0x00, + 0x00,0x00,0x00,0x0a,0x00,0x13,0x00,0x1b,0x7e,0x00,0x7c,0x00,0x77,0x00,0x6f,0x00,0x65,0x00,0x59,0x00, + 0x4c,0x00,0x3e,0x00,0x30,0x00,0x23,0x00,0x16,0x00,0x0b,0x00,0x00,0x00,0x00,0x0a,0x00,0x13,0x00,0x1b, + 0x39,0x3e,0x2f,0x40,0x28,0x42,0x22,0x45,0x1d,0x47,0x19,0x49,0x16,0x4b,0x14,0x4d,0x11,0x4f,0x10,0x51, + 0x0f,0x53,0x0d,0x54,0x0c,0x55,0x0b,0x57,0x0a,0x58,0x09,0x59,0x09,0x5b,0x08,0x5b,0x07,0x5c,0x07,0x5e, + 0x73,0x02,0x5e,0x05,0x4f,0x0a,0x44,0x0f,0x3a,0x13,0x33,0x18,0x2d,0x1c,0x27,0x20,0x23,0x23,0x20,0x27, + 0x1d,0x2a,0x1a,0x2d,0x18,0x30,0x16,0x33,0x14,0x35,0x12,0x38,0x12,0x3a,0x10,0x3c,0x0f,0x3e,0x0f,0x41, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x39,0x3e,0x2f,0x40,0x28,0x42,0x22,0x45,0x1d,0x47,0x19,0x49,0x16,0x4b,0x14,0x4d,0x11,0x4f,0x10,0x51, + 0x0f,0x53,0x0d,0x54,0x0c,0x55,0x0b,0x57,0x0a,0x58,0x09,0x59,0x09,0x5b,0x08,0x5b,0x07,0x5c,0x07,0x5e, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x09,0x00,0x12,0x00,0x7e,0x00,0x7d,0x00,0x78,0x00,0x71, + 0x00,0x68,0x00,0x5e,0x00,0x52,0x00,0x45,0x00,0x39,0x00,0x2c,0x00,0x20,0x00,0x15,0x00,0x0a,0x00,0x00, + 0x00,0x09,0x00,0x12,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7d,0x00, + 0x78,0x00,0x71,0x00,0x68,0x00,0x5e,0x00,0x52,0x00,0x45,0x00,0x39,0x00,0x2c,0x00,0x20,0x00,0x15,0x00, + 0x0a,0x00,0x00,0x00,0x00,0x09,0x00,0x12,0x7e,0x00,0x7d,0x00,0x78,0x00,0x71,0x00,0x68,0x00,0x5e,0x00, + 0x52,0x00,0x45,0x00,0x39,0x00,0x2c,0x00,0x20,0x00,0x15,0x00,0x0a,0x00,0x00,0x00,0x00,0x09,0x00,0x12, + 0x3a,0x3e,0x31,0x40,0x29,0x42,0x23,0x44,0x1f,0x46,0x1b,0x48,0x18,0x4a,0x15,0x4c,0x13,0x4d,0x11,0x4f, + 0x10,0x50,0x0f,0x52,0x0d,0x53,0x0d,0x55,0x0b,0x56,0x0b,0x57,0x0a,0x58,0x09,0x59,0x09,0x5b,0x08,0x5b, + 0x74,0x01,0x62,0x05,0x53,0x08,0x47,0x0c,0x3e,0x11,0x37,0x15,0x31,0x19,0x2b,0x1d,0x27,0x20,0x23,0x23, + 0x20,0x26,0x1d,0x2a,0x1b,0x2c,0x19,0x2f,0x16,0x31,0x16,0x34,0x13,0x35,0x12,0x38,0x12,0x3b,0x0f,0x3b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x3a,0x3e,0x31,0x40,0x29,0x42,0x23,0x44,0x1f,0x46,0x1b,0x48,0x18,0x4a,0x15,0x4c,0x13,0x4d,0x11,0x4f, + 0x10,0x50,0x0f,0x52,0x0d,0x53,0x0d,0x55,0x0b,0x56,0x0b,0x57,0x0a,0x58,0x09,0x59,0x09,0x5b,0x08,0x5b, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x7e,0x00,0x7d,0x00,0x79,0x00,0x73, + 0x00,0x6b,0x00,0x62,0x00,0x57,0x00,0x4c,0x00,0x40,0x00,0x34,0x00,0x29,0x00,0x1e,0x00,0x13,0x00,0x09, + 0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7d,0x00, + 0x79,0x00,0x73,0x00,0x6b,0x00,0x62,0x00,0x57,0x00,0x4c,0x00,0x40,0x00,0x34,0x00,0x29,0x00,0x1e,0x00, + 0x13,0x00,0x09,0x00,0x00,0x00,0x00,0x08,0x7e,0x00,0x7d,0x00,0x79,0x00,0x73,0x00,0x6b,0x00,0x62,0x00, + 0x57,0x00,0x4c,0x00,0x40,0x00,0x34,0x00,0x29,0x00,0x1e,0x00,0x13,0x00,0x09,0x00,0x00,0x00,0x00,0x08, + 0x3a,0x3e,0x32,0x3f,0x2b,0x41,0x25,0x43,0x21,0x45,0x1d,0x46,0x1a,0x48,0x17,0x4a,0x15,0x4c,0x13,0x4e, + 0x11,0x4f,0x10,0x50,0x0f,0x52,0x0e,0x53,0x0d,0x54,0x0c,0x55,0x0b,0x56,0x0b,0x58,0x09,0x58,0x09,0x59, + 0x75,0x01,0x64,0x04,0x56,0x07,0x4b,0x0b,0x42,0x0f,0x3a,0x12,0x34,0x16,0x2f,0x19,0x2a,0x1d,0x26,0x20, + 0x23,0x23,0x21,0x26,0x1d,0x29,0x1b,0x2b,0x19,0x2e,0x18,0x30,0x16,0x32,0x15,0x35,0x12,0x35,0x12,0x38, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x3a,0x3e,0x32,0x3f,0x2b,0x41,0x25,0x43,0x21,0x45,0x1d,0x46,0x1a,0x48,0x17,0x4a,0x15,0x4c,0x13,0x4e, + 0x11,0x4f,0x10,0x50,0x0f,0x52,0x0e,0x53,0x0d,0x54,0x0c,0x55,0x0b,0x56,0x0b,0x58,0x09,0x58,0x09,0x59, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7d,0x00,0x7a,0x00,0x75, + 0x00,0x6e,0x00,0x65,0x00,0x5b,0x00,0x51,0x00,0x46,0x00,0x3b,0x00,0x30,0x00,0x26,0x00,0x1b,0x00,0x12, + 0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7d,0x00, + 0x7a,0x00,0x75,0x00,0x6e,0x00,0x65,0x00,0x5b,0x00,0x51,0x00,0x46,0x00,0x3b,0x00,0x30,0x00,0x26,0x00, + 0x1b,0x00,0x12,0x00,0x08,0x00,0x00,0x00,0x7e,0x00,0x7d,0x00,0x7a,0x00,0x75,0x00,0x6e,0x00,0x65,0x00, + 0x5b,0x00,0x51,0x00,0x46,0x00,0x3b,0x00,0x30,0x00,0x26,0x00,0x1b,0x00,0x12,0x00,0x08,0x00,0x00,0x00, + 0x3b,0x3e,0x33,0x3f,0x2c,0x41,0x27,0x42,0x22,0x44,0x1f,0x45,0x1c,0x47,0x19,0x49,0x17,0x4a,0x15,0x4c, + 0x13,0x4e,0x11,0x4f,0x10,0x50,0x0f,0x51,0x0e,0x53,0x0d,0x54,0x0c,0x55,0x0b,0x55,0x0b,0x57,0x0a,0x58, + 0x76,0x01,0x66,0x04,0x58,0x06,0x4d,0x0a,0x45,0x0d,0x3e,0x10,0x37,0x14,0x32,0x17,0x2d,0x1a,0x2a,0x1d, + 0x26,0x21,0x22,0x22,0x21,0x26,0x1d,0x28,0x1c,0x2b,0x19,0x2c,0x19,0x30,0x16,0x30,0x16,0x33,0x14,0x35, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x3b,0x3e,0x33,0x3f,0x2c,0x41,0x27,0x42,0x22,0x44,0x1f,0x45,0x1c,0x47,0x19,0x49,0x17,0x4a,0x15,0x4c, + 0x13,0x4e,0x11,0x4f,0x10,0x50,0x0f,0x51,0x0e,0x53,0x0d,0x54,0x0c,0x55,0x0b,0x55,0x0b,0x57,0x0a,0x58, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x3b,0x3e,0x33,0x3f,0x2d,0x40,0x28,0x42,0x24,0x44,0x20,0x45,0x1d,0x46,0x1a,0x48,0x18,0x49,0x16,0x4b, + 0x14,0x4c,0x13,0x4e,0x11,0x4e,0x10,0x50,0x0f,0x51,0x0f,0x53,0x0d,0x53,0x0d,0x55,0x0b,0x55,0x0b,0x56, + 0x77,0x01,0x67,0x03,0x5a,0x05,0x51,0x09,0x48,0x0c,0x40,0x0f,0x3a,0x12,0x35,0x16,0x30,0x18,0x2c,0x1b, + 0x29,0x1d,0x26,0x21,0x22,0x22,0x21,0x26,0x1d,0x27,0x1d,0x2b,0x1a,0x2b,0x19,0x2e,0x17,0x30,0x16,0x31, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x3b,0x3e,0x33,0x3f,0x2d,0x40,0x28,0x42,0x24,0x44,0x20,0x45,0x1d,0x46,0x1a,0x48,0x18,0x49,0x16,0x4b, + 0x14,0x4c,0x13,0x4e,0x11,0x4e,0x10,0x50,0x0f,0x51,0x0f,0x53,0x0d,0x53,0x0d,0x55,0x0b,0x55,0x0b,0x56, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x3b,0x3e,0x34,0x3f,0x2e,0x40,0x29,0x41,0x25,0x43,0x21,0x44,0x1e,0x45,0x1c,0x47,0x19,0x48,0x18,0x4a, + 0x15,0x4b,0x14,0x4c,0x13,0x4e,0x11,0x4e,0x11,0x50,0x0f,0x50,0x0f,0x52,0x0d,0x53,0x0d,0x54,0x0c,0x55, + 0x77,0x01,0x68,0x02,0x5d,0x05,0x52,0x07,0x4a,0x0a,0x43,0x0d,0x3d,0x10,0x38,0x12,0x33,0x16,0x2f,0x19, + 0x2b,0x1b,0x28,0x1d,0x26,0x21,0x22,0x22,0x21,0x26,0x1e,0x26,0x1d,0x2a,0x1a,0x2b,0x19,0x2d,0x18,0x30, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x3b,0x3e,0x34,0x3f,0x2e,0x40,0x29,0x41,0x25,0x43,0x21,0x44,0x1e,0x45,0x1c,0x47,0x19,0x48,0x18,0x4a, + 0x15,0x4b,0x14,0x4c,0x13,0x4e,0x11,0x4e,0x11,0x50,0x0f,0x50,0x0f,0x52,0x0d,0x53,0x0d,0x54,0x0c,0x55, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x3c,0x3e,0x35,0x3f,0x2f,0x40,0x2a,0x41,0x26,0x42,0x22,0x44,0x20,0x45,0x1d,0x46,0x1b,0x48,0x18,0x48, + 0x17,0x4a,0x15,0x4b,0x13,0x4c,0x13,0x4e,0x11,0x4e,0x11,0x50,0x0f,0x50,0x0f,0x52,0x0d,0x53,0x0d,0x53, + 0x77,0x00,0x6a,0x02,0x5e,0x04,0x55,0x07,0x4c,0x0a,0x45,0x0c,0x40,0x0f,0x3a,0x12,0x35,0x14,0x31,0x16, + 0x2e,0x19,0x2b,0x1c,0x27,0x1d,0x26,0x22,0x21,0x22,0x21,0x25,0x1e,0x26,0x1d,0x29,0x1b,0x2b,0x19,0x2b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x3c,0x3e,0x35,0x3f,0x2f,0x40,0x2a,0x41,0x26,0x42,0x22,0x44,0x20,0x45,0x1d,0x46,0x1b,0x48,0x18,0x48, + 0x17,0x4a,0x15,0x4b,0x13,0x4c,0x13,0x4e,0x11,0x4e,0x11,0x50,0x0f,0x50,0x0f,0x52,0x0d,0x53,0x0d,0x53, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x3c,0x3e,0x35,0x3f,0x30,0x3f,0x2b,0x40,0x27,0x42,0x24,0x43,0x21,0x44,0x1e,0x45,0x1c,0x46,0x1a,0x48, + 0x18,0x49,0x16,0x4a,0x15,0x4c,0x13,0x4c,0x13,0x4e,0x11,0x4e,0x11,0x50,0x0f,0x50,0x0f,0x51,0x0e,0x53, + 0x78,0x00,0x6b,0x02,0x60,0x04,0x57,0x06,0x4f,0x09,0x48,0x0c,0x42,0x0e,0x3c,0x10,0x38,0x12,0x34,0x16, + 0x30,0x18,0x2d,0x19,0x2b,0x1d,0x26,0x1e,0x25,0x22,0x21,0x22,0x21,0x25,0x1e,0x26,0x1d,0x28,0x1c,0x2b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x3c,0x3e,0x35,0x3f,0x30,0x3f,0x2b,0x40,0x27,0x42,0x24,0x43,0x21,0x44,0x1e,0x45,0x1c,0x46,0x1a,0x48, + 0x18,0x49,0x16,0x4a,0x15,0x4c,0x13,0x4c,0x13,0x4e,0x11,0x4e,0x11,0x50,0x0f,0x50,0x0f,0x51,0x0e,0x53, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x3c,0x3e,0x36,0x3f,0x30,0x3f,0x2c,0x40,0x28,0x41,0x25,0x42,0x22,0x44,0x1f,0x45,0x1d,0x46,0x1b,0x47, + 0x19,0x48,0x18,0x4a,0x15,0x4a,0x15,0x4c,0x13,0x4c,0x13,0x4e,0x11,0x4e,0x11,0x50,0x0f,0x50,0x0f,0x51, + 0x78,0x00,0x6d,0x02,0x61,0x04,0x58,0x05,0x51,0x07,0x4a,0x0a,0x44,0x0c,0x3f,0x0f,0x3a,0x12,0x35,0x14, + 0x32,0x16,0x30,0x19,0x2b,0x19,0x2a,0x1d,0x26,0x1e,0x25,0x22,0x21,0x22,0x21,0x25,0x1e,0x26,0x1d,0x27, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x3c,0x3e,0x36,0x3f,0x30,0x3f,0x2c,0x40,0x28,0x41,0x25,0x42,0x22,0x44,0x1f,0x45,0x1d,0x46,0x1b,0x47, + 0x19,0x48,0x18,0x4a,0x15,0x4a,0x15,0x4c,0x13,0x4c,0x13,0x4e,0x11,0x4e,0x11,0x50,0x0f,0x50,0x0f,0x51, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x3c,0x3e,0x37,0x3e,0x31,0x3f,0x2d,0x40,0x29,0x41,0x26,0x42,0x23,0x44,0x20,0x45,0x1e,0x45,0x1c,0x46, + 0x1a,0x48,0x18,0x48,0x17,0x4a,0x15,0x4a,0x14,0x4c,0x13,0x4c,0x12,0x4e,0x11,0x4e,0x11,0x50,0x0f,0x50, + 0x78,0x00,0x6d,0x02,0x63,0x04,0x5a,0x05,0x53,0x07,0x4c,0x0a,0x46,0x0c,0x41,0x0f,0x3c,0x0f,0x38,0x12, + 0x35,0x16,0x30,0x16,0x2e,0x19,0x2b,0x1a,0x29,0x1d,0x26,0x1e,0x25,0x22,0x21,0x22,0x21,0x25,0x1f,0x26, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x3c,0x3e,0x37,0x3e,0x31,0x3f,0x2d,0x40,0x29,0x41,0x26,0x42,0x23,0x44,0x20,0x45,0x1e,0x45,0x1c,0x46, + 0x1a,0x48,0x18,0x48,0x17,0x4a,0x15,0x4a,0x14,0x4c,0x13,0x4c,0x12,0x4e,0x11,0x4e,0x11,0x50,0x0f,0x50, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x3c,0x3e,0x37,0x3e,0x32,0x3f,0x2e,0x40,0x2a,0x41,0x27,0x42,0x24,0x43,0x21,0x44,0x1f,0x45,0x1d,0x46, + 0x1b,0x47,0x1a,0x48,0x18,0x49,0x16,0x4a,0x15,0x4b,0x14,0x4c,0x13,0x4d,0x12,0x4e,0x11,0x4e,0x11,0x50, + 0x78,0x00,0x6e,0x01,0x65,0x03,0x5c,0x05,0x54,0x07,0x4e,0x09,0x48,0x0b,0x43,0x0c,0x3e,0x0f,0x3b,0x12, + 0x36,0x12,0x33,0x16,0x30,0x17,0x2d,0x19,0x2b,0x1b,0x28,0x1d,0x26,0x1e,0x25,0x22,0x21,0x22,0x21,0x24, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x3c,0x3e,0x37,0x3e,0x32,0x3f,0x2e,0x40,0x2a,0x41,0x27,0x42,0x24,0x43,0x21,0x44,0x1f,0x45,0x1d,0x46, + 0x1b,0x47,0x1a,0x48,0x18,0x49,0x16,0x4a,0x15,0x4b,0x14,0x4c,0x13,0x4d,0x12,0x4e,0x11,0x4e,0x11,0x50, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x3c,0x3e,0x37,0x3e,0x33,0x3f,0x2e,0x3f,0x2b,0x40,0x28,0x41,0x25,0x42,0x22,0x44,0x20,0x45,0x1e,0x45, + 0x1c,0x46,0x1b,0x48,0x19,0x48,0x18,0x4a,0x16,0x4a,0x15,0x4b,0x13,0x4c,0x13,0x4d,0x12,0x4e,0x11,0x4e, + 0x79,0x00,0x6f,0x01,0x66,0x02,0x5d,0x04,0x56,0x06,0x4f,0x07,0x4a,0x0a,0x45,0x0c,0x41,0x0f,0x3b,0x0f, + 0x38,0x12,0x35,0x14,0x31,0x16,0x30,0x18,0x2b,0x19,0x2b,0x1c,0x27,0x1d,0x26,0x1f,0x24,0x22,0x21,0x22, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b,0x00,0x7b, + 0x3c,0x3e,0x37,0x3e,0x33,0x3f,0x2e,0x3f,0x2b,0x40,0x28,0x41,0x25,0x42,0x22,0x44,0x20,0x45,0x1e,0x45, + 0x1c,0x46,0x1b,0x48,0x19,0x48,0x18,0x4a,0x16,0x4a,0x15,0x4b,0x13,0x4c,0x13,0x4d,0x12,0x4e,0x11,0x4e, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x62,0x00,0x6c,0x00,0x72,0x00,0x74,0x00,0x77,0x00,0x79,0x00,0x79,0x00,0x7a,0x00,0x7b,0x00,0x7b,0x00, + 0x7c,0x00,0x7c,0x00,0x7d,0x00,0x7d,0x00,0x7d,0x00,0x7c,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00, + 0x81,0x00,0x82,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00, + 0x08,0x00,0x44,0x00,0x56,0x00,0x61,0x00,0x67,0x00,0x6b,0x00,0x6e,0x00,0x70,0x00,0x71,0x00,0x73,0x00, + 0x74,0x00,0x75,0x00,0x76,0x00,0x76,0x00,0x77,0x00,0x77,0x00,0x77,0x00,0x78,0x00,0x78,0x00,0x78,0x00, + 0x44,0x00,0x63,0x00,0x6c,0x00,0x71,0x00,0x75,0x00,0x77,0x00,0x79,0x00,0x79,0x00,0x7a,0x00,0x7b,0x00, + 0x7b,0x00,0x7c,0x00,0x7c,0x00,0x7d,0x00,0x7d,0x00,0x7c,0x00,0x7d,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x4c,0x0b,0x57,0x06,0x5f,0x03,0x63,0x02,0x68,0x02,0x6b,0x01,0x6d,0x01,0x6e,0x01,0x71,0x00,0x72,0x00, + 0x73,0x00,0x74,0x00,0x75,0x00,0x76,0x00,0x76,0x00,0x76,0x00,0x78,0x00,0x78,0x00,0x78,0x00,0x79,0x00, + 0x82,0x00,0x82,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00, + 0x00,0x40,0x17,0x17,0x2c,0x0c,0x3b,0x07,0x45,0x05,0x4d,0x04,0x53,0x03,0x57,0x02,0x5c,0x02,0x5e,0x01, + 0x61,0x01,0x63,0x01,0x66,0x01,0x67,0x01,0x68,0x00,0x69,0x00,0x6b,0x00,0x6c,0x00,0x6d,0x00,0x6e,0x00, + 0x41,0x20,0x4d,0x0b,0x58,0x06,0x5e,0x03,0x64,0x02,0x68,0x02,0x6b,0x01,0x6c,0x01,0x6f,0x01,0x71,0x00, + 0x72,0x00,0x73,0x00,0x74,0x00,0x75,0x00,0x76,0x00,0x75,0x00,0x77,0x00,0x78,0x00,0x78,0x00,0x78,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x47,0x15,0x4f,0x0d,0x56,0x09,0x59,0x06,0x5f,0x05,0x62,0x04,0x65,0x03,0x67,0x02,0x69,0x02,0x6b,0x02, + 0x6c,0x02,0x6e,0x01,0x6f,0x01,0x70,0x01,0x71,0x01,0x70,0x01,0x72,0x00,0x73,0x00,0x74,0x00,0x74,0x00, + 0x83,0x00,0x82,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00, + 0x00,0x55,0x0c,0x2c,0x1b,0x1b,0x27,0x12,0x32,0x0d,0x3a,0x0b,0x41,0x08,0x47,0x07,0x4c,0x05,0x4f,0x05, + 0x53,0x04,0x56,0x04,0x58,0x03,0x5a,0x02,0x5d,0x02,0x5e,0x02,0x60,0x02,0x61,0x01,0x63,0x01,0x64,0x01, + 0x41,0x2a,0x47,0x16,0x4f,0x0d,0x54,0x09,0x5b,0x06,0x5f,0x05,0x62,0x04,0x64,0x03,0x67,0x02,0x69,0x02, + 0x6b,0x02,0x6c,0x02,0x6e,0x01,0x6f,0x01,0x70,0x01,0x70,0x01,0x71,0x01,0x72,0x00,0x73,0x00,0x74,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x45,0x1d,0x4a,0x14,0x50,0x0e,0x54,0x0b,0x59,0x08,0x5c,0x07,0x5f,0x06,0x60,0x05,0x64,0x04,0x65,0x03, + 0x67,0x03,0x68,0x02,0x6a,0x02,0x6b,0x02,0x6c,0x02,0x6c,0x02,0x6e,0x02,0x6f,0x01,0x70,0x01,0x70,0x01, + 0x83,0x00,0x82,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00, + 0x00,0x60,0x08,0x3b,0x12,0x28,0x1d,0x1d,0x26,0x16,0x2e,0x11,0x34,0x0e,0x3a,0x0c,0x3f,0x0a,0x44,0x08, + 0x47,0x07,0x4b,0x06,0x4d,0x05,0x51,0x05,0x52,0x04,0x55,0x04,0x57,0x04,0x58,0x04,0x5a,0x03,0x5c,0x02, + 0x42,0x30,0x45,0x1d,0x4b,0x14,0x4f,0x0e,0x55,0x0b,0x59,0x08,0x5c,0x07,0x5e,0x06,0x61,0x05,0x64,0x04, + 0x65,0x03,0x67,0x03,0x68,0x02,0x6a,0x02,0x6b,0x02,0x6b,0x02,0x6d,0x02,0x6e,0x02,0x6f,0x01,0x70,0x01, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x44,0x22,0x48,0x19,0x4d,0x13,0x50,0x0f,0x54,0x0c,0x57,0x0a,0x5a,0x08,0x5c,0x07,0x5f,0x06,0x61,0x05, + 0x63,0x05,0x64,0x04,0x65,0x03,0x67,0x03,0x68,0x03,0x68,0x02,0x6a,0x02,0x6b,0x02,0x6c,0x02,0x6d,0x02, + 0x83,0x00,0x82,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00, + 0x00,0x66,0x05,0x45,0x0d,0x32,0x16,0x26,0x1e,0x1e,0x25,0x18,0x2b,0x14,0x31,0x11,0x36,0x0f,0x3a,0x0c, + 0x3e,0x0b,0x42,0x0a,0x45,0x09,0x47,0x07,0x4a,0x07,0x4c,0x06,0x4f,0x05,0x51,0x05,0x52,0x05,0x54,0x04, + 0x41,0x33,0x44,0x22,0x48,0x19,0x4c,0x13,0x51,0x0f,0x54,0x0c,0x57,0x0a,0x59,0x08,0x5d,0x07,0x5f,0x06, + 0x61,0x05,0x63,0x05,0x64,0x04,0x65,0x03,0x67,0x03,0x67,0x03,0x69,0x02,0x6a,0x02,0x6b,0x02,0x6c,0x02, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x43,0x26,0x47,0x1d,0x4a,0x17,0x4d,0x12,0x51,0x0f,0x54,0x0d,0x56,0x0b,0x58,0x09,0x5b,0x08,0x5d,0x07, + 0x5f,0x06,0x60,0x06,0x62,0x05,0x63,0x05,0x64,0x04,0x65,0x03,0x67,0x03,0x67,0x03,0x68,0x03,0x69,0x02, + 0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00, + 0x00,0x6a,0x04,0x4d,0x0b,0x3a,0x11,0x2e,0x18,0x25,0x1f,0x1f,0x24,0x1a,0x29,0x16,0x2e,0x13,0x33,0x11, + 0x37,0x0f,0x3a,0x0d,0x3d,0x0c,0x40,0x0a,0x43,0x0a,0x45,0x09,0x48,0x07,0x4a,0x07,0x4c,0x07,0x4e,0x06, + 0x41,0x35,0x43,0x26,0x47,0x1d,0x49,0x17,0x4e,0x12,0x51,0x0f,0x54,0x0d,0x55,0x0b,0x59,0x09,0x5b,0x08, + 0x5d,0x07,0x5f,0x06,0x60,0x06,0x62,0x05,0x63,0x05,0x63,0x04,0x65,0x03,0x67,0x03,0x67,0x03,0x68,0x03, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x43,0x29,0x45,0x20,0x49,0x1a,0x4b,0x15,0x4f,0x12,0x51,0x0f,0x54,0x0d,0x55,0x0b,0x58,0x0a,0x5a,0x09, + 0x5b,0x08,0x5d,0x07,0x5f,0x06,0x60,0x06,0x61,0x05,0x62,0x05,0x64,0x05,0x65,0x04,0x65,0x03,0x66,0x03, + 0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00, + 0x00,0x6d,0x03,0x52,0x08,0x41,0x0e,0x34,0x14,0x2b,0x1a,0x24,0x1f,0x1f,0x24,0x1b,0x28,0x17,0x2d,0x15, + 0x31,0x12,0x34,0x10,0x37,0x0f,0x3a,0x0d,0x3d,0x0c,0x40,0x0b,0x42,0x0a,0x44,0x0a,0x46,0x09,0x47,0x07, + 0x41,0x36,0x43,0x29,0x46,0x20,0x48,0x1a,0x4c,0x15,0x4f,0x12,0x51,0x0f,0x53,0x0d,0x56,0x0b,0x58,0x0a, + 0x5a,0x09,0x5b,0x08,0x5d,0x07,0x5f,0x06,0x60,0x06,0x60,0x05,0x62,0x05,0x64,0x05,0x65,0x04,0x65,0x03, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x43,0x2b,0x45,0x23,0x48,0x1d,0x49,0x18,0x4d,0x14,0x4f,0x12,0x51,0x10,0x53,0x0e,0x55,0x0c,0x57,0x0b, + 0x59,0x0a,0x5a,0x09,0x5c,0x08,0x5d,0x07,0x5f,0x07,0x5f,0x06,0x61,0x06,0x62,0x05,0x63,0x05,0x64,0x05, + 0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00, + 0x00,0x6f,0x02,0x57,0x07,0x47,0x0c,0x3a,0x11,0x31,0x16,0x29,0x1b,0x24,0x20,0x20,0x23,0x1c,0x28,0x19, + 0x2b,0x16,0x2f,0x14,0x32,0x12,0x35,0x10,0x38,0x0f,0x3a,0x0e,0x3c,0x0c,0x3f,0x0c,0x41,0x0b,0x42,0x0a, + 0x41,0x37,0x43,0x2b,0x45,0x23,0x47,0x1d,0x4a,0x18,0x4d,0x14,0x4f,0x12,0x51,0x10,0x53,0x0e,0x55,0x0c, + 0x57,0x0b,0x59,0x0a,0x5a,0x09,0x5c,0x08,0x5d,0x07,0x5e,0x07,0x60,0x06,0x61,0x06,0x62,0x05,0x63,0x05, + 0x1f,0x00,0x3f,0x00,0x66,0x00,0x72,0x00,0x78,0x00,0x7a,0x00,0x7c,0x00,0x7c,0x00,0x7d,0x00,0x7d,0x00, + 0x7e,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00,0x1f,0x1f,0x3f,0x00,0x66,0x00,0x72,0x00, + 0x78,0x00,0x7a,0x00,0x7c,0x00,0x7c,0x00,0x7d,0x00,0x7d,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00, + 0x7e,0x00,0x7e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7d,0x00,0x58,0x00, + 0x70,0x00,0x77,0x00,0x79,0x00,0x7b,0x00,0x7c,0x00,0x7c,0x00,0x7d,0x00,0x7d,0x00,0x7e,0x00,0x7e,0x00, + 0x7e,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00,0x1f,0x1f,0x3f,0x00,0x66,0x00,0x72,0x00,0x78,0x00,0x7a,0x00, + 0x7c,0x00,0x7c,0x00,0x7d,0x00,0x7d,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00, + 0x43,0x2d,0x44,0x25,0x46,0x1f,0x48,0x1b,0x4b,0x17,0x4d,0x14,0x50,0x12,0x51,0x10,0x53,0x0e,0x55,0x0c, + 0x57,0x0b,0x58,0x0b,0x5a,0x09,0x5b,0x09,0x5c,0x08,0x5c,0x07,0x5f,0x07,0x60,0x06,0x61,0x06,0x62,0x06, + 0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00, + 0x00,0x71,0x02,0x5b,0x05,0x4b,0x0a,0x3f,0x0f,0x36,0x13,0x2e,0x18,0x29,0x1c,0x23,0x20,0x20,0x23,0x1d, + 0x27,0x19,0x2a,0x17,0x2d,0x16,0x30,0x12,0x33,0x12,0x35,0x10,0x38,0x0f,0x3b,0x0e,0x3c,0x0c,0x3e,0x0c, + 0x41,0x38,0x43,0x2d,0x44,0x25,0x45,0x1f,0x49,0x1b,0x4b,0x17,0x4d,0x14,0x4f,0x11,0x51,0x10,0x53,0x0e, + 0x55,0x0c,0x57,0x0b,0x58,0x0b,0x5a,0x09,0x5b,0x09,0x5b,0x08,0x5e,0x07,0x5f,0x07,0x60,0x06,0x61,0x06, + 0x00,0x00,0x0a,0x00,0x3f,0x00,0x5c,0x00,0x6a,0x00,0x71,0x00,0x75,0x00,0x78,0x00,0x79,0x00,0x7a,0x00, + 0x7b,0x00,0x7c,0x00,0x7c,0x00,0x7d,0x00,0x7d,0x00,0x7d,0x00,0x00,0x3f,0x0a,0x0a,0x3f,0x00,0x5c,0x00, + 0x6a,0x00,0x71,0x00,0x75,0x00,0x78,0x00,0x79,0x00,0x7a,0x00,0x7b,0x00,0x7c,0x00,0x7c,0x00,0x7d,0x00, + 0x7d,0x00,0x7d,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x58,0x00,0x44,0x00, + 0x55,0x00,0x67,0x00,0x6e,0x00,0x72,0x00,0x75,0x00,0x78,0x00,0x79,0x00,0x7a,0x00,0x7b,0x00,0x7c,0x00, + 0x7c,0x00,0x7d,0x00,0x7d,0x00,0x7d,0x00,0x00,0x3f,0x0a,0x0a,0x3f,0x00,0x5c,0x00,0x6a,0x00,0x71,0x00, + 0x75,0x00,0x78,0x00,0x79,0x00,0x7a,0x00,0x7b,0x00,0x7c,0x00,0x7c,0x00,0x7d,0x00,0x7d,0x00,0x7d,0x00, + 0x42,0x2f,0x44,0x27,0x46,0x22,0x47,0x1d,0x4a,0x19,0x4c,0x16,0x4e,0x13,0x4f,0x11,0x52,0x10,0x53,0x0e, + 0x55,0x0d,0x56,0x0c,0x58,0x0b,0x59,0x0a,0x5a,0x09,0x5b,0x09,0x5c,0x07,0x5e,0x07,0x5f,0x07,0x5f,0x06, + 0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00, + 0x00,0x73,0x01,0x5e,0x05,0x4f,0x08,0x44,0x0c,0x3a,0x10,0x33,0x15,0x2d,0x19,0x28,0x1d,0x23,0x20,0x20, + 0x23,0x1d,0x26,0x1a,0x2a,0x18,0x2c,0x16,0x2f,0x14,0x31,0x12,0x34,0x12,0x35,0x0f,0x38,0x0f,0x3b,0x0f, + 0x41,0x39,0x42,0x2f,0x44,0x27,0x45,0x22,0x48,0x1d,0x4a,0x19,0x4c,0x16,0x4d,0x14,0x50,0x11,0x52,0x10, + 0x53,0x0e,0x55,0x0d,0x56,0x0c,0x58,0x0b,0x59,0x0a,0x59,0x09,0x5c,0x09,0x5c,0x07,0x5e,0x07,0x5f,0x07, + 0x00,0x00,0x00,0x00,0x03,0x00,0x2d,0x00,0x48,0x00,0x59,0x00,0x63,0x00,0x6a,0x00,0x6e,0x00,0x72,0x00, + 0x74,0x00,0x76,0x00,0x77,0x00,0x78,0x00,0x79,0x00,0x7a,0x00,0x00,0x66,0x00,0x3f,0x03,0x03,0x2d,0x00, + 0x48,0x00,0x59,0x00,0x63,0x00,0x6a,0x00,0x6e,0x00,0x72,0x00,0x74,0x00,0x76,0x00,0x77,0x00,0x78,0x00, + 0x79,0x00,0x7a,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x55,0x00, + 0x20,0x00,0x3e,0x00,0x50,0x00,0x5a,0x00,0x63,0x00,0x6a,0x00,0x6e,0x00,0x72,0x00,0x74,0x00,0x76,0x00, + 0x77,0x00,0x78,0x00,0x79,0x00,0x7a,0x00,0x00,0x66,0x00,0x3f,0x03,0x03,0x2d,0x00,0x48,0x00,0x59,0x00, + 0x63,0x00,0x6a,0x00,0x6e,0x00,0x72,0x00,0x74,0x00,0x76,0x00,0x77,0x00,0x78,0x00,0x79,0x00,0x7a,0x00, + 0x42,0x30,0x44,0x29,0x45,0x23,0x46,0x1f,0x49,0x1b,0x4b,0x18,0x4c,0x15,0x4d,0x13,0x50,0x11,0x52,0x10, + 0x53,0x0e,0x55,0x0d,0x56,0x0c,0x57,0x0b,0x59,0x0b,0x59,0x09,0x5b,0x09,0x5c,0x09,0x5c,0x07,0x5e,0x07, + 0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00, + 0x00,0x73,0x01,0x61,0x04,0x52,0x07,0x47,0x0b,0x3e,0x0f,0x37,0x12,0x31,0x16,0x2b,0x19,0x27,0x1d,0x23, + 0x20,0x20,0x23,0x1d,0x26,0x1b,0x29,0x19,0x2b,0x16,0x2e,0x16,0x30,0x13,0x32,0x12,0x35,0x12,0x36,0x0f, + 0x41,0x39,0x42,0x30,0x44,0x29,0x44,0x23,0x47,0x1f,0x49,0x1b,0x4b,0x18,0x4c,0x15,0x4e,0x13,0x50,0x11, + 0x52,0x10,0x53,0x0e,0x55,0x0d,0x56,0x0c,0x57,0x0b,0x57,0x0b,0x5a,0x09,0x5b,0x09,0x5c,0x09,0x5c,0x07, + 0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x22,0x00,0x3a,0x00,0x4a,0x00,0x56,0x00,0x5e,0x00,0x64,0x00, + 0x69,0x00,0x6d,0x00,0x6f,0x00,0x71,0x00,0x73,0x00,0x75,0x00,0x00,0x72,0x00,0x5c,0x00,0x2d,0x01,0x01, + 0x22,0x00,0x3a,0x00,0x4a,0x00,0x56,0x00,0x5e,0x00,0x64,0x00,0x69,0x00,0x6d,0x00,0x6f,0x00,0x71,0x00, + 0x73,0x00,0x75,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x77,0x00,0x67,0x00, + 0x3e,0x00,0x0d,0x00,0x28,0x00,0x3a,0x00,0x4a,0x00,0x56,0x00,0x5e,0x00,0x64,0x00,0x69,0x00,0x6d,0x00, + 0x6f,0x00,0x71,0x00,0x73,0x00,0x75,0x00,0x00,0x72,0x00,0x5c,0x00,0x2d,0x01,0x01,0x22,0x00,0x3a,0x00, + 0x4a,0x00,0x56,0x00,0x5e,0x00,0x64,0x00,0x69,0x00,0x6d,0x00,0x6f,0x00,0x71,0x00,0x73,0x00,0x75,0x00, + 0x42,0x32,0x44,0x2a,0x45,0x25,0x46,0x21,0x48,0x1d,0x4a,0x1a,0x4b,0x17,0x4c,0x15,0x4e,0x13,0x50,0x11, + 0x52,0x10,0x53,0x0e,0x55,0x0d,0x55,0x0c,0x57,0x0c,0x57,0x0b,0x5a,0x0a,0x5a,0x09,0x5b,0x09,0x5c,0x09, + 0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00, + 0x00,0x74,0x01,0x64,0x04,0x55,0x06,0x4a,0x0a,0x42,0x0d,0x3a,0x10,0x34,0x14,0x2f,0x17,0x2a,0x1a,0x26, + 0x1d,0x23,0x21,0x21,0x22,0x1d,0x26,0x1b,0x28,0x19,0x2b,0x18,0x2c,0x16,0x30,0x15,0x30,0x12,0x33,0x12, + 0x41,0x3a,0x42,0x32,0x44,0x2a,0x44,0x25,0x46,0x21,0x48,0x1d,0x4a,0x1a,0x4b,0x17,0x4d,0x15,0x4e,0x13, + 0x50,0x11,0x52,0x10,0x53,0x0e,0x55,0x0d,0x55,0x0c,0x56,0x0c,0x58,0x0b,0x5a,0x0a,0x5a,0x09,0x5b,0x09, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1b,0x00,0x30,0x00,0x3f,0x00,0x4b,0x00,0x54,0x00, + 0x5b,0x00,0x61,0x00,0x65,0x00,0x68,0x00,0x6b,0x00,0x6e,0x00,0x00,0x78,0x00,0x6a,0x00,0x48,0x00,0x22, + 0x00,0x00,0x1b,0x00,0x30,0x00,0x3f,0x00,0x4b,0x00,0x54,0x00,0x5b,0x00,0x61,0x00,0x65,0x00,0x68,0x00, + 0x6b,0x00,0x6e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x79,0x00,0x6e,0x00, + 0x50,0x00,0x28,0x00,0x01,0x00,0x1b,0x00,0x30,0x00,0x3f,0x00,0x4b,0x00,0x54,0x00,0x5b,0x00,0x61,0x00, + 0x65,0x00,0x68,0x00,0x6b,0x00,0x6e,0x00,0x00,0x78,0x00,0x6a,0x00,0x48,0x00,0x22,0x00,0x00,0x1b,0x00, + 0x30,0x00,0x3f,0x00,0x4b,0x00,0x54,0x00,0x5b,0x00,0x61,0x00,0x65,0x00,0x68,0x00,0x6b,0x00,0x6e,0x00, + 0x42,0x32,0x43,0x2c,0x44,0x26,0x45,0x22,0x48,0x1f,0x49,0x1b,0x4b,0x19,0x4c,0x16,0x4e,0x15,0x4f,0x13, + 0x50,0x11,0x52,0x10,0x53,0x0e,0x55,0x0e,0x55,0x0c,0x56,0x0c,0x57,0x0b,0x59,0x0b,0x5a,0x0a,0x5a,0x09, + 0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00, + 0x00,0x75,0x01,0x65,0x03,0x58,0x05,0x4d,0x09,0x45,0x0c,0x3e,0x0f,0x37,0x12,0x32,0x16,0x2d,0x18,0x2a, + 0x1b,0x26,0x1d,0x22,0x21,0x21,0x22,0x1d,0x26,0x1c,0x27,0x19,0x2b,0x19,0x2b,0x16,0x2e,0x16,0x30,0x14, + 0x41,0x3a,0x42,0x32,0x43,0x2c,0x44,0x26,0x46,0x22,0x48,0x1f,0x49,0x1b,0x4a,0x19,0x4c,0x16,0x4e,0x15, + 0x4f,0x13,0x50,0x11,0x52,0x10,0x53,0x0e,0x55,0x0e,0x54,0x0c,0x57,0x0c,0x57,0x0b,0x59,0x0b,0x5a,0x0a, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x16,0x00,0x28,0x00,0x37,0x00,0x42,0x00, + 0x4b,0x00,0x53,0x00,0x59,0x00,0x5e,0x00,0x62,0x00,0x65,0x00,0x00,0x7a,0x00,0x71,0x00,0x59,0x00,0x3a, + 0x00,0x1b,0x00,0x00,0x16,0x00,0x28,0x00,0x37,0x00,0x42,0x00,0x4b,0x00,0x53,0x00,0x59,0x00,0x5e,0x00, + 0x62,0x00,0x65,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7b,0x00,0x72,0x00, + 0x5a,0x00,0x3a,0x00,0x1b,0x00,0x01,0x00,0x16,0x00,0x28,0x00,0x37,0x00,0x42,0x00,0x4b,0x00,0x53,0x00, + 0x59,0x00,0x5e,0x00,0x62,0x00,0x65,0x00,0x00,0x7a,0x00,0x71,0x00,0x59,0x00,0x3a,0x00,0x1b,0x00,0x00, + 0x16,0x00,0x28,0x00,0x37,0x00,0x42,0x00,0x4b,0x00,0x53,0x00,0x59,0x00,0x5e,0x00,0x62,0x00,0x65,0x00, + 0x42,0x33,0x43,0x2d,0x44,0x28,0x45,0x23,0x47,0x20,0x48,0x1d,0x4a,0x1a,0x4a,0x18,0x4c,0x16,0x4e,0x14, + 0x4f,0x13,0x50,0x11,0x52,0x10,0x53,0x0e,0x55,0x0e,0x54,0x0d,0x57,0x0c,0x57,0x0b,0x58,0x0b,0x5a,0x0b, + 0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00, + 0x00,0x76,0x01,0x67,0x02,0x5a,0x05,0x50,0x07,0x47,0x0a,0x40,0x0d,0x3a,0x10,0x35,0x12,0x30,0x16,0x2c, + 0x19,0x29,0x1b,0x26,0x1d,0x22,0x21,0x21,0x22,0x1d,0x26,0x1d,0x26,0x1a,0x2a,0x19,0x2b,0x17,0x2d,0x16, + 0x41,0x3b,0x42,0x33,0x43,0x2d,0x44,0x28,0x45,0x23,0x47,0x20,0x48,0x1d,0x49,0x1a,0x4b,0x18,0x4c,0x16, + 0x4e,0x14,0x4f,0x13,0x50,0x11,0x52,0x10,0x53,0x0e,0x54,0x0e,0x55,0x0d,0x57,0x0c,0x57,0x0b,0x58,0x0b, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x13,0x00,0x23,0x00,0x30,0x00, + 0x3b,0x00,0x44,0x00,0x4c,0x00,0x52,0x00,0x57,0x00,0x5b,0x00,0x00,0x7c,0x00,0x75,0x00,0x63,0x00,0x4a, + 0x00,0x30,0x00,0x16,0x00,0x00,0x13,0x00,0x23,0x00,0x30,0x00,0x3b,0x00,0x44,0x00,0x4c,0x00,0x52,0x00, + 0x57,0x00,0x5b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0x00,0x75,0x00, + 0x63,0x00,0x4a,0x00,0x30,0x00,0x16,0x00,0x00,0x00,0x13,0x00,0x23,0x00,0x30,0x00,0x3b,0x00,0x44,0x00, + 0x4c,0x00,0x52,0x00,0x57,0x00,0x5b,0x00,0x00,0x7c,0x00,0x75,0x00,0x63,0x00,0x4a,0x00,0x30,0x00,0x16, + 0x00,0x00,0x13,0x00,0x23,0x00,0x30,0x00,0x3b,0x00,0x44,0x00,0x4c,0x00,0x52,0x00,0x57,0x00,0x5b,0x00, + 0x42,0x34,0x43,0x2e,0x44,0x29,0x45,0x25,0x46,0x21,0x48,0x1e,0x49,0x1b,0x4a,0x19,0x4c,0x17,0x4d,0x15, + 0x4e,0x14,0x50,0x13,0x50,0x11,0x52,0x11,0x52,0x0f,0x53,0x0e,0x55,0x0d,0x56,0x0c,0x57,0x0c,0x57,0x0b, + 0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00, + 0x00,0x77,0x00,0x68,0x02,0x5c,0x05,0x52,0x07,0x4a,0x0a,0x43,0x0c,0x3d,0x0f,0x37,0x12,0x33,0x14,0x2f, + 0x16,0x2b,0x19,0x28,0x1c,0x26,0x1d,0x22,0x21,0x22,0x21,0x1e,0x25,0x1d,0x26,0x1a,0x29,0x19,0x2b,0x18, + 0x41,0x3b,0x42,0x34,0x43,0x2e,0x44,0x29,0x45,0x25,0x46,0x21,0x48,0x1e,0x48,0x1b,0x4b,0x19,0x4c,0x17, + 0x4d,0x15,0x4e,0x14,0x50,0x13,0x50,0x11,0x52,0x11,0x51,0x0f,0x54,0x0e,0x55,0x0d,0x56,0x0c,0x57,0x0c, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x1f,0x00, + 0x2b,0x00,0x35,0x00,0x3e,0x00,0x45,0x00,0x4c,0x00,0x51,0x00,0x00,0x7c,0x00,0x78,0x00,0x6a,0x00,0x56, + 0x00,0x3f,0x00,0x28,0x00,0x13,0x00,0x00,0x10,0x00,0x1f,0x00,0x2b,0x00,0x35,0x00,0x3e,0x00,0x45,0x00, + 0x4c,0x00,0x51,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0x00,0x78,0x00, + 0x6a,0x00,0x56,0x00,0x3f,0x00,0x28,0x00,0x13,0x00,0x00,0x00,0x10,0x00,0x1f,0x00,0x2b,0x00,0x35,0x00, + 0x3e,0x00,0x45,0x00,0x4c,0x00,0x51,0x00,0x00,0x7c,0x00,0x78,0x00,0x6a,0x00,0x56,0x00,0x3f,0x00,0x28, + 0x00,0x13,0x00,0x00,0x10,0x00,0x1f,0x00,0x2b,0x00,0x35,0x00,0x3e,0x00,0x45,0x00,0x4c,0x00,0x51,0x00, + 0x42,0x34,0x43,0x2f,0x44,0x2a,0x44,0x26,0x46,0x22,0x47,0x1f,0x48,0x1d,0x49,0x1a,0x4b,0x18,0x4c,0x17, + 0x4e,0x15,0x4e,0x13,0x50,0x13,0x50,0x11,0x52,0x11,0x51,0x0f,0x54,0x0e,0x55,0x0d,0x56,0x0c,0x57,0x0c, + 0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00, + 0x00,0x77,0x00,0x69,0x02,0x5e,0x04,0x55,0x06,0x4c,0x09,0x45,0x0c,0x3f,0x0e,0x3a,0x10,0x35,0x12,0x31, + 0x16,0x2e,0x18,0x2b,0x19,0x27,0x1d,0x26,0x1e,0x22,0x21,0x22,0x21,0x1e,0x25,0x1d,0x26,0x1b,0x28,0x19, + 0x41,0x3b,0x42,0x34,0x43,0x2f,0x43,0x2a,0x45,0x26,0x46,0x22,0x47,0x1f,0x48,0x1d,0x4a,0x1a,0x4b,0x18, + 0x4c,0x17,0x4e,0x15,0x4e,0x13,0x50,0x13,0x50,0x11,0x51,0x11,0x52,0x0f,0x54,0x0e,0x55,0x0d,0x56,0x0c, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0e,0x00, + 0x1b,0x00,0x27,0x00,0x30,0x00,0x39,0x00,0x40,0x00,0x46,0x00,0x00,0x7d,0x00,0x79,0x00,0x6e,0x00,0x5e, + 0x00,0x4b,0x00,0x37,0x00,0x23,0x00,0x10,0x00,0x00,0x0e,0x00,0x1b,0x00,0x27,0x00,0x30,0x00,0x39,0x00, + 0x40,0x00,0x46,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7d,0x00,0x79,0x00, + 0x6e,0x00,0x5e,0x00,0x4b,0x00,0x37,0x00,0x23,0x00,0x10,0x00,0x00,0x00,0x0e,0x00,0x1b,0x00,0x27,0x00, + 0x30,0x00,0x39,0x00,0x40,0x00,0x46,0x00,0x00,0x7d,0x00,0x79,0x00,0x6e,0x00,0x5e,0x00,0x4b,0x00,0x37, + 0x00,0x23,0x00,0x10,0x00,0x00,0x0e,0x00,0x1b,0x00,0x27,0x00,0x30,0x00,0x39,0x00,0x40,0x00,0x46,0x00, + 0x42,0x35,0x43,0x30,0x44,0x2b,0x44,0x27,0x45,0x24,0x46,0x21,0x48,0x1e,0x48,0x1c,0x4b,0x1a,0x4b,0x18, + 0x4c,0x16,0x4e,0x15,0x4e,0x13,0x50,0x12,0x50,0x11,0x51,0x11,0x52,0x0f,0x54,0x0e,0x55,0x0e,0x55,0x0c, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00, + 0x00,0x77,0x00,0x6b,0x02,0x60,0x04,0x57,0x05,0x4f,0x07,0x48,0x0a,0x42,0x0c,0x3c,0x0f,0x38,0x12,0x34, + 0x14,0x30,0x16,0x2c,0x19,0x2b,0x19,0x26,0x1d,0x25,0x1e,0x22,0x21,0x22,0x21,0x1e,0x25,0x1d,0x26,0x1c, + 0x41,0x3b,0x42,0x35,0x43,0x30,0x43,0x2b,0x44,0x27,0x45,0x24,0x46,0x21,0x47,0x1e,0x49,0x1c,0x4b,0x1a, + 0x4b,0x18,0x4c,0x16,0x4e,0x15,0x4e,0x13,0x50,0x12,0x50,0x11,0x52,0x11,0x52,0x0f,0x54,0x0e,0x55,0x0e, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x0d,0x00,0x19,0x00,0x23,0x00,0x2c,0x00,0x34,0x00,0x3b,0x00,0x00,0x7d,0x00,0x7a,0x00,0x72,0x00,0x64, + 0x00,0x54,0x00,0x42,0x00,0x30,0x00,0x1f,0x00,0x0e,0x00,0x00,0x0d,0x00,0x19,0x00,0x23,0x00,0x2c,0x00, + 0x34,0x00,0x3b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7d,0x00,0x7a,0x00, + 0x72,0x00,0x64,0x00,0x54,0x00,0x42,0x00,0x30,0x00,0x1f,0x00,0x0e,0x00,0x00,0x00,0x0d,0x00,0x19,0x00, + 0x23,0x00,0x2c,0x00,0x34,0x00,0x3b,0x00,0x00,0x7d,0x00,0x7a,0x00,0x72,0x00,0x64,0x00,0x54,0x00,0x42, + 0x00,0x30,0x00,0x1f,0x00,0x0e,0x00,0x00,0x0d,0x00,0x19,0x00,0x23,0x00,0x2c,0x00,0x34,0x00,0x3b,0x00, + 0x42,0x36,0x43,0x30,0x44,0x2c,0x44,0x28,0x45,0x25,0x46,0x22,0x48,0x1f,0x48,0x1d,0x49,0x1a,0x4b,0x19, + 0x4c,0x18,0x4d,0x15,0x4e,0x15,0x4f,0x13,0x50,0x12,0x50,0x11,0x52,0x11,0x52,0x0f,0x54,0x0e,0x55,0x0e, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00, + 0x00,0x77,0x00,0x6c,0x02,0x61,0x04,0x58,0x05,0x51,0x07,0x4a,0x0a,0x44,0x0c,0x3f,0x0f,0x3a,0x10,0x35, + 0x12,0x32,0x16,0x30,0x16,0x2b,0x19,0x2a,0x1a,0x26,0x1d,0x25,0x1e,0x22,0x21,0x22,0x21,0x1e,0x25,0x1d, + 0x41,0x3b,0x42,0x36,0x43,0x30,0x43,0x2c,0x44,0x28,0x45,0x25,0x46,0x22,0x47,0x1f,0x49,0x1d,0x49,0x1a, + 0x4b,0x19,0x4c,0x18,0x4d,0x15,0x4e,0x15,0x4f,0x13,0x4f,0x12,0x51,0x11,0x52,0x11,0x52,0x0f,0x54,0x0e, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x0c,0x00,0x16,0x00,0x20,0x00,0x29,0x00,0x30,0x00,0x00,0x7e,0x00,0x7b,0x00,0x74,0x00,0x69, + 0x00,0x5b,0x00,0x4b,0x00,0x3b,0x00,0x2b,0x00,0x1b,0x00,0x0d,0x00,0x00,0x0c,0x00,0x16,0x00,0x20,0x00, + 0x29,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7b,0x00, + 0x74,0x00,0x69,0x00,0x5b,0x00,0x4b,0x00,0x3b,0x00,0x2b,0x00,0x1b,0x00,0x0d,0x00,0x00,0x00,0x0c,0x00, + 0x16,0x00,0x20,0x00,0x29,0x00,0x30,0x00,0x00,0x7e,0x00,0x7b,0x00,0x74,0x00,0x69,0x00,0x5b,0x00,0x4b, + 0x00,0x3b,0x00,0x2b,0x00,0x1b,0x00,0x0d,0x00,0x00,0x0c,0x00,0x16,0x00,0x20,0x00,0x29,0x00,0x30,0x00, + 0x42,0x36,0x42,0x31,0x43,0x2d,0x44,0x29,0x45,0x26,0x46,0x23,0x47,0x20,0x47,0x1e,0x49,0x1c,0x4b,0x1a, + 0x4b,0x18,0x4c,0x17,0x4d,0x15,0x4e,0x14,0x4f,0x13,0x4f,0x12,0x51,0x11,0x52,0x11,0x52,0x0f,0x54,0x0e, + 0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00, + 0x00,0x78,0x00,0x6d,0x01,0x62,0x03,0x5a,0x05,0x52,0x07,0x4c,0x09,0x46,0x0b,0x41,0x0c,0x3c,0x0f,0x38, + 0x12,0x35,0x12,0x30,0x16,0x2e,0x17,0x2b,0x19,0x29,0x1b,0x26,0x1d,0x25,0x1e,0x22,0x21,0x22,0x21,0x1f, + 0x41,0x3c,0x42,0x36,0x42,0x31,0x43,0x2d,0x44,0x29,0x45,0x26,0x46,0x23,0x46,0x20,0x48,0x1e,0x49,0x1c, + 0x4b,0x1a,0x4b,0x18,0x4c,0x17,0x4d,0x15,0x4e,0x14,0x4e,0x13,0x50,0x12,0x51,0x11,0x52,0x11,0x52,0x0f, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x0b,0x00,0x15,0x00,0x1e,0x00,0x26,0x00,0x00,0x7e,0x00,0x7c,0x00,0x76,0x00,0x6d, + 0x00,0x61,0x00,0x53,0x00,0x44,0x00,0x35,0x00,0x27,0x00,0x19,0x00,0x0c,0x00,0x00,0x0b,0x00,0x15,0x00, + 0x1e,0x00,0x26,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7c,0x00, + 0x76,0x00,0x6d,0x00,0x61,0x00,0x53,0x00,0x44,0x00,0x35,0x00,0x27,0x00,0x19,0x00,0x0c,0x00,0x00,0x00, + 0x0b,0x00,0x15,0x00,0x1e,0x00,0x26,0x00,0x00,0x7e,0x00,0x7c,0x00,0x76,0x00,0x6d,0x00,0x61,0x00,0x53, + 0x00,0x44,0x00,0x35,0x00,0x27,0x00,0x19,0x00,0x0c,0x00,0x00,0x0b,0x00,0x15,0x00,0x1e,0x00,0x26,0x00, + 0x42,0x37,0x42,0x32,0x43,0x2d,0x44,0x2a,0x45,0x27,0x45,0x23,0x46,0x21,0x47,0x1f,0x49,0x1d,0x49,0x1a, + 0x4b,0x19,0x4c,0x18,0x4c,0x16,0x4e,0x15,0x4e,0x14,0x4f,0x13,0x50,0x12,0x51,0x11,0x52,0x11,0x52,0x0f, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x82,0x00,0x83,0x00,0x83,0x00, + 0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x81,0x00,0x83,0x00,0x83,0x00,0x83,0x00,0x83,0x00, + 0x00,0x78,0x00,0x6e,0x01,0x64,0x02,0x5b,0x04,0x54,0x06,0x4e,0x07,0x47,0x0a,0x42,0x0c,0x3e,0x0f,0x3b, + 0x0f,0x35,0x12,0x33,0x14,0x30,0x16,0x2d,0x19,0x2b,0x19,0x28,0x1c,0x26,0x1d,0x25,0x1f,0x22,0x21,0x22, + 0x41,0x3c,0x42,0x37,0x42,0x32,0x43,0x2d,0x44,0x2a,0x45,0x27,0x45,0x23,0x46,0x21,0x48,0x1f,0x49,0x1d, + 0x49,0x1a,0x4b,0x19,0x4c,0x18,0x4c,0x16,0x4e,0x15,0x4d,0x14,0x50,0x13,0x50,0x12,0x51,0x11,0x52,0x11, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x0a,0x00,0x13,0x00,0x1b,0x00,0x00,0x7e,0x00,0x7c,0x00,0x77,0x00,0x6f, + 0x00,0x65,0x00,0x59,0x00,0x4c,0x00,0x3e,0x00,0x30,0x00,0x23,0x00,0x16,0x00,0x0b,0x00,0x00,0x0a,0x00, + 0x13,0x00,0x1b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7c,0x00, + 0x77,0x00,0x6f,0x00,0x65,0x00,0x59,0x00,0x4c,0x00,0x3e,0x00,0x30,0x00,0x23,0x00,0x16,0x00,0x0b,0x00, + 0x00,0x00,0x0a,0x00,0x13,0x00,0x1b,0x00,0x00,0x7e,0x00,0x7c,0x00,0x77,0x00,0x6f,0x00,0x65,0x00,0x59, + 0x00,0x4c,0x00,0x3e,0x00,0x30,0x00,0x23,0x00,0x16,0x00,0x0b,0x00,0x00,0x0a,0x00,0x13,0x00,0x1b,0x00, + 0x40,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x61,0x20,0x4d,0x2a,0x48,0x30,0x44,0x33,0x44,0x35,0x44,0x36,0x43,0x37,0x42,0x38,0x43,0x39,0x42,0x39, + 0x42,0x3a,0x42,0x3a,0x42,0x3b,0x42,0x3b,0x42,0x3b,0x41,0x3b,0x42,0x3c,0x42,0x3c,0x42,0x3c,0x42,0x3c, + 0x04,0x3d,0x22,0x3d,0x2b,0x3d,0x30,0x3d,0x33,0x3d,0x35,0x3d,0x37,0x3d,0x38,0x3d,0x39,0x3d,0x39,0x3d, + 0x3a,0x3d,0x3a,0x3d,0x3b,0x3d,0x3b,0x3d,0x3b,0x3d,0x3c,0x3d,0x3c,0x3d,0x3c,0x3d,0x3c,0x3d,0x3c,0x3d, + 0x40,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x09,0x00,0x12,0x00,0x00,0x7e,0x00,0x7d,0x00,0x78,0x00,0x71, + 0x00,0x68,0x00,0x5e,0x00,0x52,0x00,0x45,0x00,0x39,0x00,0x2c,0x00,0x20,0x00,0x15,0x00,0x0a,0x00,0x00, + 0x09,0x00,0x12,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7d,0x00, + 0x78,0x00,0x71,0x00,0x68,0x00,0x5e,0x00,0x52,0x00,0x45,0x00,0x39,0x00,0x2c,0x00,0x20,0x00,0x15,0x00, + 0x0a,0x00,0x00,0x00,0x09,0x00,0x12,0x00,0x00,0x7e,0x00,0x7d,0x00,0x78,0x00,0x71,0x00,0x68,0x00,0x5e, + 0x00,0x52,0x00,0x45,0x00,0x39,0x00,0x2c,0x00,0x20,0x00,0x15,0x00,0x0a,0x00,0x00,0x09,0x00,0x12,0x00, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x6c,0x0b,0x57,0x16,0x4f,0x1d,0x4a,0x22,0x48,0x26,0x47,0x29,0x46,0x2b,0x44,0x2d,0x44,0x2f,0x44,0x30, + 0x44,0x31,0x44,0x32,0x43,0x33,0x43,0x34,0x43,0x34,0x42,0x35,0x43,0x36,0x42,0x36,0x42,0x37,0x42,0x37, + 0x00,0x5d,0x0c,0x49,0x16,0x43,0x1d,0x41,0x22,0x40,0x26,0x3f,0x29,0x3f,0x2c,0x3f,0x2e,0x3e,0x2f,0x3e, + 0x31,0x3e,0x32,0x3e,0x33,0x3e,0x33,0x3e,0x34,0x3e,0x35,0x3e,0x35,0x3e,0x36,0x3e,0x37,0x3e,0x37,0x3e, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x7e,0x00,0x7d,0x00,0x79,0x00,0x73, + 0x00,0x6b,0x00,0x62,0x00,0x57,0x00,0x4c,0x00,0x40,0x00,0x34,0x00,0x29,0x00,0x1e,0x00,0x13,0x00,0x09, + 0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7d,0x00, + 0x79,0x00,0x73,0x00,0x6b,0x00,0x62,0x00,0x57,0x00,0x4c,0x00,0x40,0x00,0x34,0x00,0x29,0x00,0x1e,0x00, + 0x13,0x00,0x09,0x00,0x00,0x00,0x08,0x00,0x00,0x7e,0x00,0x7d,0x00,0x79,0x00,0x73,0x00,0x6b,0x00,0x62, + 0x00,0x57,0x00,0x4c,0x00,0x40,0x00,0x34,0x00,0x29,0x00,0x1e,0x00,0x13,0x00,0x09,0x00,0x00,0x08,0x00, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x72,0x06,0x5f,0x0d,0x56,0x14,0x4f,0x19,0x4d,0x1d,0x4a,0x20,0x49,0x23,0x47,0x25,0x46,0x27,0x46,0x29, + 0x45,0x2a,0x45,0x2c,0x44,0x2d,0x44,0x2e,0x44,0x2f,0x43,0x30,0x44,0x30,0x44,0x31,0x43,0x32,0x43,0x33, + 0x00,0x68,0x06,0x54,0x0d,0x4b,0x14,0x47,0x19,0x44,0x1d,0x43,0x20,0x41,0x23,0x41,0x26,0x40,0x27,0x40, + 0x29,0x3f,0x2b,0x3f,0x2c,0x3f,0x2d,0x3f,0x2e,0x3f,0x2f,0x3f,0x30,0x3f,0x30,0x3e,0x31,0x3e,0x32,0x3e, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7d,0x00,0x7a,0x00,0x75, + 0x00,0x6e,0x00,0x65,0x00,0x5b,0x00,0x51,0x00,0x46,0x00,0x3b,0x00,0x30,0x00,0x26,0x00,0x1b,0x00,0x12, + 0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7d,0x00, + 0x7a,0x00,0x75,0x00,0x6e,0x00,0x65,0x00,0x5b,0x00,0x51,0x00,0x46,0x00,0x3b,0x00,0x30,0x00,0x26,0x00, + 0x1b,0x00,0x12,0x00,0x08,0x00,0x00,0x00,0x00,0x7e,0x00,0x7d,0x00,0x7a,0x00,0x75,0x00,0x6e,0x00,0x65, + 0x00,0x5b,0x00,0x51,0x00,0x46,0x00,0x3b,0x00,0x30,0x00,0x26,0x00,0x1b,0x00,0x12,0x00,0x08,0x00,0x00, + 0x42,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x75,0x03,0x64,0x09,0x5a,0x0e,0x54,0x13,0x51,0x17,0x4e,0x1a,0x4c,0x1d,0x49,0x1f,0x49,0x22,0x48,0x23, + 0x47,0x25,0x46,0x26,0x46,0x28,0x45,0x29,0x45,0x2a,0x44,0x2b,0x44,0x2c,0x44,0x2d,0x44,0x2e,0x44,0x2e, + 0x00,0x6d,0x04,0x5b,0x09,0x51,0x0e,0x4c,0x13,0x48,0x17,0x46,0x1a,0x44,0x1d,0x43,0x1f,0x42,0x22,0x42, + 0x24,0x41,0x25,0x41,0x27,0x40,0x28,0x40,0x29,0x40,0x2a,0x3f,0x2b,0x3f,0x2c,0x3f,0x2d,0x3f,0x2e,0x3f, + 0x42,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0x1f,0x3f,0x00,0x66,0x00,0x72,0x00, + 0x78,0x00,0x7a,0x00,0x7c,0x00,0x7c,0x00,0x7d,0x00,0x7d,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00, + 0x7e,0x00,0x7e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0x1f,0x00,0x3f, + 0x00,0x66,0x00,0x72,0x00,0x78,0x00,0x7a,0x00,0x7c,0x00,0x7c,0x00,0x7d,0x00,0x7d,0x00,0x7e,0x00,0x7e, + 0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00,0x7e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x77,0x02,0x68,0x06,0x5f,0x0b,0x58,0x0f,0x54,0x12,0x51,0x15,0x4f,0x18,0x4c,0x1b,0x4b,0x1d,0x4a,0x1f, + 0x49,0x21,0x48,0x22,0x48,0x23,0x47,0x25,0x46,0x26,0x45,0x27,0x45,0x28,0x45,0x29,0x45,0x2a,0x44,0x2b, + 0x00,0x70,0x02,0x60,0x07,0x56,0x0b,0x50,0x0f,0x4c,0x12,0x49,0x16,0x47,0x18,0x46,0x1b,0x45,0x1d,0x44, + 0x1f,0x43,0x21,0x42,0x22,0x42,0x24,0x41,0x25,0x41,0x26,0x40,0x27,0x40,0x28,0x40,0x29,0x40,0x2a,0x3f, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3f,0x0a,0x0a,0x3f,0x00,0x5c,0x00, + 0x6a,0x00,0x71,0x00,0x75,0x00,0x78,0x00,0x79,0x00,0x7a,0x00,0x7b,0x00,0x7c,0x00,0x7c,0x00,0x7d,0x00, + 0x7d,0x00,0x7d,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3f,0x00,0x0a,0x0a, + 0x00,0x3f,0x00,0x5c,0x00,0x6a,0x00,0x71,0x00,0x75,0x00,0x78,0x00,0x79,0x00,0x7a,0x00,0x7b,0x00,0x7c, + 0x00,0x7c,0x00,0x7d,0x00,0x7d,0x00,0x7d,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x78,0x02,0x6b,0x05,0x62,0x08,0x5b,0x0c,0x57,0x0f,0x54,0x12,0x51,0x14,0x4e,0x17,0x4d,0x19,0x4c,0x1b, + 0x4b,0x1d,0x4a,0x1e,0x49,0x20,0x48,0x21,0x48,0x22,0x46,0x24,0x46,0x25,0x46,0x26,0x46,0x27,0x45,0x27, + 0x00,0x72,0x02,0x64,0x05,0x5b,0x08,0x54,0x0c,0x50,0x0f,0x4d,0x12,0x4a,0x14,0x48,0x17,0x47,0x19,0x46, + 0x1b,0x45,0x1d,0x44,0x1f,0x44,0x20,0x42,0x21,0x42,0x22,0x42,0x24,0x41,0x25,0x41,0x26,0x41,0x27,0x40, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x66,0x00,0x3f,0x03,0x03,0x2d,0x00, + 0x48,0x00,0x59,0x00,0x63,0x00,0x6a,0x00,0x6e,0x00,0x72,0x00,0x74,0x00,0x76,0x00,0x77,0x00,0x78,0x00, + 0x79,0x00,0x7a,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x66,0x00,0x3f,0x00, + 0x03,0x03,0x00,0x2d,0x00,0x48,0x00,0x59,0x00,0x63,0x00,0x6a,0x00,0x6e,0x00,0x72,0x00,0x74,0x00,0x76, + 0x00,0x77,0x00,0x78,0x00,0x79,0x00,0x7a,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x79,0x01,0x6d,0x04,0x65,0x07,0x5e,0x0a,0x5a,0x0d,0x56,0x0f,0x54,0x12,0x51,0x14,0x4f,0x16,0x4e,0x18, + 0x4c,0x1a,0x4b,0x1b,0x4b,0x1d,0x4a,0x1e,0x49,0x1f,0x48,0x21,0x48,0x22,0x48,0x23,0x47,0x23,0x46,0x25, + 0x00,0x74,0x01,0x66,0x04,0x5e,0x07,0x57,0x0a,0x53,0x0d,0x4f,0x10,0x4d,0x12,0x4b,0x14,0x49,0x16,0x48, + 0x18,0x46,0x1a,0x45,0x1b,0x45,0x1d,0x44,0x1e,0x44,0x20,0x43,0x21,0x42,0x22,0x42,0x23,0x42,0x24,0x41, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x72,0x00,0x5c,0x00,0x2d,0x01,0x01, + 0x22,0x00,0x3a,0x00,0x4a,0x00,0x56,0x00,0x5e,0x00,0x64,0x00,0x69,0x00,0x6d,0x00,0x6f,0x00,0x71,0x00, + 0x73,0x00,0x75,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x72,0x00,0x5c,0x00, + 0x2d,0x00,0x01,0x01,0x00,0x22,0x00,0x3a,0x00,0x4a,0x00,0x56,0x00,0x5e,0x00,0x64,0x00,0x69,0x00,0x6d, + 0x00,0x6f,0x00,0x71,0x00,0x73,0x00,0x75,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7a,0x01,0x6f,0x03,0x67,0x06,0x60,0x08,0x5d,0x0b,0x59,0x0d,0x56,0x10,0x53,0x11,0x51,0x14,0x50,0x15, + 0x4e,0x17,0x4d,0x19,0x4c,0x1a,0x4b,0x1b,0x4b,0x1d,0x48,0x1e,0x49,0x1f,0x49,0x20,0x48,0x21,0x48,0x22, + 0x00,0x75,0x01,0x69,0x03,0x61,0x06,0x5a,0x08,0x56,0x0b,0x52,0x0d,0x4f,0x10,0x4d,0x12,0x4b,0x14,0x4a, + 0x16,0x48,0x17,0x47,0x19,0x46,0x1a,0x45,0x1c,0x45,0x1d,0x44,0x1e,0x44,0x1f,0x44,0x20,0x43,0x21,0x42, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x78,0x00,0x6a,0x00,0x48,0x00,0x22, + 0x00,0x00,0x1b,0x00,0x30,0x00,0x3f,0x00,0x4b,0x00,0x54,0x00,0x5b,0x00,0x61,0x00,0x65,0x00,0x68,0x00, + 0x6b,0x00,0x6e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x78,0x00,0x6a,0x00, + 0x48,0x00,0x22,0x00,0x00,0x00,0x00,0x1b,0x00,0x30,0x00,0x3f,0x00,0x4b,0x00,0x54,0x00,0x5b,0x00,0x61, + 0x00,0x65,0x00,0x68,0x00,0x6b,0x00,0x6e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7b,0x01,0x71,0x02,0x69,0x05,0x62,0x07,0x5f,0x09,0x5b,0x0c,0x58,0x0e,0x55,0x10,0x53,0x11,0x52,0x13, + 0x50,0x15,0x4e,0x16,0x4e,0x18,0x4c,0x19,0x4c,0x1a,0x4a,0x1c,0x4b,0x1d,0x49,0x1e,0x49,0x1f,0x49,0x20, + 0x00,0x76,0x01,0x6b,0x03,0x63,0x05,0x5d,0x07,0x58,0x09,0x54,0x0c,0x52,0x0e,0x4f,0x10,0x4d,0x11,0x4c, + 0x13,0x4a,0x15,0x49,0x17,0x48,0x18,0x47,0x19,0x46,0x1b,0x45,0x1c,0x45,0x1d,0x44,0x1e,0x44,0x1f,0x44, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7a,0x00,0x71,0x00,0x59,0x00,0x3a, + 0x00,0x1b,0x00,0x00,0x16,0x00,0x28,0x00,0x37,0x00,0x42,0x00,0x4b,0x00,0x53,0x00,0x59,0x00,0x5e,0x00, + 0x62,0x00,0x65,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7a,0x00,0x71,0x00, + 0x59,0x00,0x3a,0x00,0x1b,0x00,0x00,0x00,0x00,0x16,0x00,0x28,0x00,0x37,0x00,0x42,0x00,0x4b,0x00,0x53, + 0x00,0x59,0x00,0x5e,0x00,0x62,0x00,0x65,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7b,0x00,0x72,0x02,0x6b,0x04,0x64,0x06,0x61,0x08,0x5d,0x0a,0x5a,0x0c,0x56,0x0e,0x55,0x10,0x53,0x11, + 0x52,0x13,0x50,0x15,0x4f,0x16,0x4e,0x17,0x4d,0x18,0x4b,0x1a,0x4b,0x1a,0x4b,0x1c,0x4b,0x1d,0x49,0x1d, + 0x00,0x77,0x00,0x6c,0x02,0x65,0x04,0x5f,0x06,0x5a,0x08,0x57,0x0a,0x54,0x0c,0x51,0x0e,0x4f,0x10,0x4d, + 0x11,0x4c,0x13,0x4a,0x15,0x49,0x16,0x48,0x18,0x48,0x18,0x46,0x1a,0x46,0x1b,0x45,0x1c,0x45,0x1d,0x45, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0x00,0x75,0x00,0x63,0x00,0x4a, + 0x00,0x30,0x00,0x16,0x00,0x00,0x13,0x00,0x23,0x00,0x30,0x00,0x3b,0x00,0x44,0x00,0x4c,0x00,0x52,0x00, + 0x57,0x00,0x5b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0x00,0x75,0x00, + 0x63,0x00,0x4a,0x00,0x30,0x00,0x16,0x00,0x00,0x00,0x00,0x13,0x00,0x23,0x00,0x30,0x00,0x3b,0x00,0x44, + 0x00,0x4c,0x00,0x52,0x00,0x57,0x00,0x5b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7c,0x00,0x73,0x02,0x6c,0x03,0x66,0x05,0x63,0x07,0x5e,0x09,0x5c,0x0b,0x58,0x0c,0x57,0x0e,0x55,0x10, + 0x53,0x11,0x52,0x13,0x50,0x14,0x4f,0x15,0x4e,0x17,0x4c,0x18,0x4c,0x19,0x4c,0x1a,0x4b,0x1a,0x4b,0x1c, + 0x00,0x77,0x00,0x6e,0x02,0x66,0x04,0x61,0x05,0x5c,0x07,0x59,0x09,0x56,0x0b,0x53,0x0d,0x51,0x0f,0x4f, + 0x10,0x4e,0x11,0x4c,0x13,0x4b,0x14,0x4a,0x15,0x48,0x17,0x48,0x18,0x47,0x19,0x46,0x1b,0x46,0x1b,0x45, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0x00,0x78,0x00,0x6a,0x00,0x56, + 0x00,0x3f,0x00,0x28,0x00,0x13,0x00,0x00,0x10,0x00,0x1f,0x00,0x2b,0x00,0x35,0x00,0x3e,0x00,0x45,0x00, + 0x4c,0x00,0x51,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0x00,0x78,0x00, + 0x6a,0x00,0x56,0x00,0x3f,0x00,0x28,0x00,0x13,0x00,0x00,0x00,0x00,0x10,0x00,0x1f,0x00,0x2b,0x00,0x35, + 0x00,0x3e,0x00,0x45,0x00,0x4c,0x00,0x51,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7c,0x00,0x74,0x02,0x6e,0x03,0x68,0x05,0x64,0x06,0x60,0x08,0x5d,0x0a,0x5a,0x0b,0x58,0x0d,0x56,0x0e, + 0x55,0x10,0x53,0x11,0x52,0x13,0x50,0x14,0x50,0x15,0x4d,0x16,0x4e,0x18,0x4c,0x18,0x4c,0x19,0x4c,0x1a, + 0x00,0x77,0x00,0x6f,0x02,0x68,0x03,0x63,0x05,0x5e,0x06,0x5a,0x08,0x57,0x0a,0x55,0x0b,0x53,0x0d,0x50, + 0x0f,0x4f,0x10,0x4e,0x11,0x4c,0x13,0x4b,0x14,0x4a,0x15,0x49,0x16,0x48,0x18,0x48,0x18,0x46,0x19,0x46, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7d,0x00,0x79,0x00,0x6e,0x00,0x5e, + 0x00,0x4b,0x00,0x37,0x00,0x23,0x00,0x10,0x00,0x00,0x0e,0x00,0x1b,0x00,0x27,0x00,0x30,0x00,0x39,0x00, + 0x40,0x00,0x46,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7d,0x00,0x79,0x00, + 0x6e,0x00,0x5e,0x00,0x4b,0x00,0x37,0x00,0x23,0x00,0x10,0x00,0x00,0x00,0x00,0x0e,0x00,0x1b,0x00,0x27, + 0x00,0x30,0x00,0x39,0x00,0x40,0x00,0x46,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7d,0x00,0x75,0x01,0x6f,0x02,0x69,0x04,0x65,0x06,0x62,0x07,0x5f,0x09,0x5b,0x0b,0x5a,0x0c,0x58,0x0d, + 0x56,0x0e,0x55,0x10,0x53,0x11,0x52,0x13,0x50,0x13,0x4f,0x15,0x4e,0x15,0x4e,0x17,0x4d,0x18,0x4c,0x18, + 0x00,0x78,0x00,0x70,0x01,0x69,0x03,0x64,0x04,0x60,0x06,0x5c,0x07,0x59,0x09,0x56,0x0b,0x54,0x0c,0x52, + 0x0d,0x50,0x0f,0x4f,0x10,0x4e,0x11,0x4c,0x13,0x4b,0x13,0x4a,0x15,0x4a,0x15,0x48,0x17,0x48,0x18,0x47, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7d,0x00,0x7a,0x00,0x72,0x00,0x64, + 0x00,0x54,0x00,0x42,0x00,0x30,0x00,0x1f,0x00,0x0e,0x00,0x00,0x0d,0x00,0x19,0x00,0x23,0x00,0x2c,0x00, + 0x34,0x00,0x3b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7d,0x00,0x7a,0x00, + 0x72,0x00,0x64,0x00,0x54,0x00,0x42,0x00,0x30,0x00,0x1f,0x00,0x0e,0x00,0x00,0x00,0x00,0x0d,0x00,0x19, + 0x00,0x23,0x00,0x2c,0x00,0x34,0x00,0x3b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7d,0x00,0x76,0x01,0x70,0x02,0x6a,0x03,0x67,0x05,0x63,0x06,0x60,0x08,0x5d,0x09,0x5b,0x0b,0x59,0x0c, + 0x57,0x0d,0x55,0x0e,0x55,0x10,0x53,0x11,0x52,0x13,0x4f,0x13,0x50,0x15,0x4f,0x15,0x4e,0x16,0x4e,0x18, + 0x00,0x78,0x00,0x71,0x01,0x6a,0x03,0x66,0x04,0x61,0x05,0x5d,0x06,0x5a,0x08,0x58,0x09,0x55,0x0b,0x53, + 0x0d,0x52,0x0e,0x50,0x0f,0x4e,0x10,0x4e,0x11,0x4c,0x13,0x4c,0x13,0x4a,0x15,0x4a,0x15,0x49,0x16,0x48, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7b,0x00,0x74,0x00,0x69, + 0x00,0x5b,0x00,0x4b,0x00,0x3b,0x00,0x2b,0x00,0x1b,0x00,0x0d,0x00,0x00,0x0c,0x00,0x16,0x00,0x20,0x00, + 0x29,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7b,0x00, + 0x74,0x00,0x69,0x00,0x5b,0x00,0x4b,0x00,0x3b,0x00,0x2b,0x00,0x1b,0x00,0x0d,0x00,0x00,0x00,0x00,0x0c, + 0x00,0x16,0x00,0x20,0x00,0x29,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7d,0x00,0x76,0x01,0x71,0x02,0x6c,0x03,0x68,0x05,0x64,0x06,0x61,0x07,0x5e,0x09,0x5c,0x0a,0x5a,0x0b, + 0x59,0x0c,0x57,0x0e,0x55,0x0e,0x55,0x11,0x52,0x11,0x51,0x12,0x51,0x13,0x50,0x14,0x4f,0x15,0x4e,0x15, + 0x00,0x79,0x00,0x71,0x01,0x6c,0x02,0x66,0x04,0x62,0x05,0x5f,0x06,0x5c,0x07,0x59,0x09,0x57,0x0a,0x55, + 0x0b,0x53,0x0d,0x51,0x0e,0x50,0x0f,0x4e,0x11,0x4e,0x11,0x4c,0x13,0x4c,0x13,0x4b,0x14,0x4a,0x15,0x4a, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7c,0x00,0x76,0x00,0x6d, + 0x00,0x61,0x00,0x53,0x00,0x44,0x00,0x35,0x00,0x27,0x00,0x19,0x00,0x0c,0x00,0x00,0x0b,0x00,0x15,0x00, + 0x1e,0x00,0x26,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7c,0x00, + 0x76,0x00,0x6d,0x00,0x61,0x00,0x53,0x00,0x44,0x00,0x35,0x00,0x27,0x00,0x19,0x00,0x0c,0x00,0x00,0x00, + 0x00,0x0b,0x00,0x15,0x00,0x1e,0x00,0x26,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7d,0x00,0x77,0x01,0x72,0x02,0x6d,0x03,0x69,0x04,0x66,0x06,0x63,0x07,0x5f,0x08,0x5e,0x09,0x5c,0x0b, + 0x5a,0x0c,0x58,0x0c,0x57,0x0e,0x55,0x0f,0x54,0x11,0x51,0x11,0x52,0x12,0x51,0x13,0x50,0x14,0x50,0x15, + 0x00,0x79,0x00,0x72,0x01,0x6d,0x02,0x68,0x03,0x63,0x04,0x60,0x06,0x5d,0x07,0x5b,0x08,0x58,0x09,0x56, + 0x0b,0x54,0x0c,0x53,0x0d,0x51,0x0e,0x50,0x0f,0x4e,0x11,0x4e,0x11,0x4c,0x12,0x4c,0x13,0x4b,0x14,0x4a, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7c,0x00,0x77,0x00,0x6f, + 0x00,0x65,0x00,0x59,0x00,0x4c,0x00,0x3e,0x00,0x30,0x00,0x23,0x00,0x16,0x00,0x0b,0x00,0x00,0x0a,0x00, + 0x13,0x00,0x1b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7c,0x00, + 0x77,0x00,0x6f,0x00,0x65,0x00,0x59,0x00,0x4c,0x00,0x3e,0x00,0x30,0x00,0x23,0x00,0x16,0x00,0x0b,0x00, + 0x00,0x00,0x00,0x0a,0x00,0x13,0x00,0x1b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7d,0x00,0x78,0x01,0x72,0x02,0x6e,0x02,0x6a,0x03,0x67,0x05,0x64,0x06,0x60,0x07,0x5f,0x09,0x5c,0x0a, + 0x5b,0x0b,0x5a,0x0c,0x57,0x0c,0x56,0x0e,0x55,0x0f,0x53,0x11,0x52,0x11,0x52,0x12,0x51,0x13,0x50,0x13, + 0x00,0x79,0x00,0x73,0x01,0x6d,0x02,0x69,0x03,0x65,0x04,0x61,0x05,0x5e,0x06,0x5c,0x07,0x59,0x09,0x57, + 0x0a,0x55,0x0b,0x54,0x0d,0x53,0x0d,0x51,0x0f,0x50,0x0f,0x4e,0x11,0x4e,0x11,0x4c,0x12,0x4c,0x13,0x4b, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7d,0x00,0x78,0x00,0x71, + 0x00,0x68,0x00,0x5e,0x00,0x52,0x00,0x45,0x00,0x39,0x00,0x2c,0x00,0x20,0x00,0x15,0x00,0x0a,0x00,0x00, + 0x09,0x00,0x12,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7d,0x00, + 0x78,0x00,0x71,0x00,0x68,0x00,0x5e,0x00,0x52,0x00,0x45,0x00,0x39,0x00,0x2c,0x00,0x20,0x00,0x15,0x00, + 0x0a,0x00,0x00,0x00,0x00,0x09,0x00,0x12,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7e,0x00,0x78,0x01,0x73,0x02,0x6e,0x02,0x6b,0x03,0x68,0x05,0x65,0x06,0x62,0x07,0x5f,0x07,0x5e,0x09, + 0x5c,0x0b,0x5a,0x0b,0x59,0x0c,0x57,0x0d,0x56,0x0e,0x54,0x0f,0x54,0x11,0x52,0x11,0x52,0x12,0x51,0x13, + 0x00,0x79,0x00,0x73,0x01,0x6e,0x02,0x69,0x03,0x66,0x04,0x62,0x05,0x5f,0x06,0x5d,0x07,0x5b,0x08,0x58, + 0x09,0x56,0x0b,0x55,0x0b,0x53,0x0d,0x52,0x0d,0x50,0x0f,0x50,0x0f,0x4e,0x11,0x4e,0x11,0x4d,0x12,0x4c, + 0x41,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7d,0x00,0x79,0x00,0x73, + 0x00,0x6b,0x00,0x62,0x00,0x57,0x00,0x4c,0x00,0x40,0x00,0x34,0x00,0x29,0x00,0x1e,0x00,0x13,0x00,0x09, + 0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7d,0x00, + 0x79,0x00,0x73,0x00,0x6b,0x00,0x62,0x00,0x57,0x00,0x4c,0x00,0x40,0x00,0x34,0x00,0x29,0x00,0x1e,0x00, + 0x13,0x00,0x09,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7e,0x00,0x78,0x00,0x74,0x01,0x6f,0x02,0x6c,0x03,0x68,0x04,0x65,0x05,0x62,0x06,0x61,0x07,0x5f,0x09, + 0x5c,0x09,0x5b,0x0b,0x5a,0x0b,0x58,0x0c,0x57,0x0d,0x55,0x0e,0x55,0x0f,0x54,0x11,0x52,0x11,0x52,0x12, + 0x00,0x79,0x00,0x74,0x00,0x6f,0x02,0x6a,0x03,0x66,0x04,0x63,0x05,0x60,0x05,0x5e,0x06,0x5b,0x07,0x59, + 0x09,0x58,0x09,0x55,0x0b,0x55,0x0c,0x53,0x0d,0x52,0x0d,0x50,0x0f,0x50,0x0f,0x4e,0x11,0x4e,0x11,0x4d, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7d,0x00,0x7a,0x00,0x75, + 0x00,0x6e,0x00,0x65,0x00,0x5b,0x00,0x51,0x00,0x46,0x00,0x3b,0x00,0x30,0x00,0x26,0x00,0x1b,0x00,0x12, + 0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7d,0x00, + 0x7a,0x00,0x75,0x00,0x6e,0x00,0x65,0x00,0x5b,0x00,0x51,0x00,0x46,0x00,0x3b,0x00,0x30,0x00,0x26,0x00, + 0x1b,0x00,0x12,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, + 0x7e,0x00,0x79,0x00,0x74,0x01,0x70,0x02,0x6c,0x03,0x69,0x03,0x66,0x05,0x63,0x06,0x62,0x07,0x5f,0x07, + 0x5e,0x09,0x5c,0x0a,0x5a,0x0b,0x5a,0x0c,0x57,0x0c,0x56,0x0e,0x55,0x0e,0x55,0x0f,0x54,0x11,0x52,0x11, + 0x00,0x79,0x00,0x74,0x00,0x70,0x01,0x6b,0x02,0x67,0x03,0x64,0x04,0x61,0x05,0x5f,0x06,0x5d,0x07,0x5b, + 0x08,0x58,0x09,0x57,0x0a,0x55,0x0b,0x54,0x0c,0x53,0x0d,0x51,0x0e,0x50,0x0f,0x50,0x0f,0x4e,0x11,0x4e, + 0x41,0x3d,0x41,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d, + 0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x41,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d,0x42,0x3d, +}; + +static const unsigned char kSmaaSearch[SMAA_SEARCH_W * SMAA_SEARCH_H] = { + 0xfe,0xfe,0x00,0x7f,0x7f,0x00,0x00,0xfe,0xfe,0x00,0x7f,0x7f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x7f,0x7f,0x00,0x7f,0x7f,0x00,0x00,0x7f,0x7f,0x00,0x7f,0x7f,0xfe,0x7f,0x00,0x00,0x00,0x00,0x00, + 0x7f,0x7f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0xfe,0xfe,0x00,0x7f,0x7f,0x00,0x00,0xfe,0xfe,0x00,0x7f,0x7f,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x7f,0x7f,0x00,0x7f,0x7f,0x00,0x00,0x7f,0x7f,0x00,0x7f,0x7f,0xfe,0x7f,0x00, + 0x00,0x00,0x00,0x00,0x7f,0x7f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfe,0xfe,0x00,0x7f,0x7f,0x00,0x00,0xfe, + 0xfe,0x00,0x7f,0x7f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7f,0x7f,0x00,0x7f,0x7f,0x00,0x00, + 0x7f,0x7f,0x00,0x7f,0x7f,0xfe,0x7f,0x00,0x00,0x00,0x00,0x00,0x7f,0x7f,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfe,0xfe,0x00,0x7f, + 0x7f,0x00,0x00,0xfe,0xfe,0x00,0x7f,0x7f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7f,0x7f,0x00, + 0x7f,0x7f,0x00,0x00,0x7f,0x7f,0x00,0x7f,0x7f,0xfe,0x7f,0x00,0x00,0x00,0x00,0x00,0x7f,0x7f,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7f,0x7f,0x00,0x7f,0x7f,0x00,0x00,0x7f,0x7f,0x00,0x7f,0x7f, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7f,0x7f,0x00,0x7f,0x7f,0x00,0x00,0x7f,0x7f,0x00,0x7f, + 0x7f,0x7f,0x7f,0x00,0x00,0x00,0x00,0x00,0x7f,0x7f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7f,0x7f,0x00,0x7f,0x7f,0x00,0x00,0x7f, + 0x7f,0x00,0x7f,0x7f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7f,0x7f,0x00,0x7f,0x7f,0x00,0x00, + 0x7f,0x7f,0x00,0x7f,0x7f,0x7f,0x7f,0x00,0x00,0x00,0x00,0x00,0x7f,0x7f,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x7f,0x7f,0x00,0x7f,0x7f,0x00,0x00,0x7f,0x7f,0x00,0x7f,0x7f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x7f,0x7f,0x00,0x7f,0x7f,0x00,0x00,0x7f,0x7f,0x00,0x7f,0x7f,0x7f,0x7f,0x00,0x00,0x00,0x00,0x00, + 0x7f,0x7f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x7f,0x7f,0x00,0x7f,0x7f,0x00,0x00,0x7f,0x7f,0x00,0x7f,0x7f,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x7f,0x7f,0x00,0x7f,0x7f,0x00,0x00,0x7f,0x7f,0x00,0x7f,0x7f,0x7f,0x7f,0x00, + 0x00,0x00,0x00,0x00,0x7f,0x7f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00, +}; diff --git a/app/src/main/cpp/shaders/smaa_weights.frag b/app/src/main/cpp/shaders/smaa_weights.frag index 32e8b404cd..3d6bca5601 100644 --- a/app/src/main/cpp/shaders/smaa_weights.frag +++ b/app/src/main/cpp/shaders/smaa_weights.frag @@ -1,153 +1,25 @@ #version 450 +#extension GL_GOOGLE_include_directive : require layout(location = 0) in vec2 fragTexCoord; layout(location = 0) out vec4 outColor; layout(set = 0, binding = 0) uniform sampler2D EdgeTexture; +layout(set = 1, binding = 0) uniform sampler2D AreaTexture; +layout(set = 2, binding = 0) uniform sampler2D SearchTexture; layout(push_constant) uniform Constants { vec4 ndc; - vec2 resolution; - float extra; - float pad; + vec4 metrics; // 1/width, 1/height, width, height } pc; -vec4 edgeAt(vec2 uv, vec2 px) { - vec2 edgeUV = clamp(uv, px * 0.5, vec2(1.0) - px * 0.5); - vec4 e = textureLod(EdgeTexture, edgeUV, 0.0); - e.a = edgeUV.y >= 1.0 - px.y ? 0.0 : e.a; - return e; -} - -float verticalEdge(vec2 uv, vec2 px) { - vec4 e = edgeAt(uv, px); - return max(e.r, e.g); -} - -float horizontalEdge(vec2 uv, vec2 px) { - vec4 e = edgeAt(uv, px); - return max(e.b, e.a); -} - -float measureRun(vec2 origin, vec2 texel, vec2 tangent, - bool verticalLine, float limit, bool positive) { - float run = 0.0; - for (int i = 1; i <= 6; ++i) { - vec2 probe = origin + tangent * float(i) * (positive ? 1.0 : -1.0); - ivec2 index = ivec2(floor(probe * pc.resolution)); - ivec2 size = ivec2(pc.resolution); - if (any(lessThan(index, ivec2(0))) || - any(greaterThanEqual(index, size))) { - break; - } - float edge = verticalLine - ? verticalEdge(probe, texel) - : horizontalEdge(probe, texel); - if (edge <= limit * 0.65) { - break; - } - run = float(i); - } - return run; -} +#define SMAA_RT_METRICS pc.metrics +#define SMAA_GLSL_4 +#define SMAA_PRESET_HIGH +#include "SMAA.hlsl" void main() { - vec2 px = 1.0 / max(pc.resolution, vec2(1.0)); - vec2 uv = clamp(fragTexCoord, px * 0.5, vec2(1.0) - px * 0.5); - vec4 e = edgeAt(uv, px); - - float dL = e.r; - float dR = e.g; - float dU = e.b; - float dD = e.a; - float vertical = max(dL, dR); - float horizontal = max(dU, dD); - float strongest = max(vertical, horizontal); - float threshold = max(0.045, strongest * 0.12); - - if (strongest <= threshold) { - outColor = vec4(0.0, 0.5, 0.5, 0.0); - return; - } - - bool verticalLine; - float negativeRun = 0.0; - float positiveRun = 0.0; - bool runsMeasured = false; - - if (vertical > horizontal) { - verticalLine = true; - } else if (horizontal > vertical) { - verticalLine = false; - } else { - float vNeg = measureRun(uv, px, vec2(0.0, px.y), true, threshold, false); - float vPos = measureRun(uv, px, vec2(0.0, px.y), true, threshold, true); - float hNeg = measureRun(uv, px, vec2(px.x, 0.0), false, threshold, false); - float hPos = measureRun(uv, px, vec2(px.x, 0.0), false, threshold, true); - verticalLine = (vNeg + vPos) >= (hNeg + hPos); - negativeRun = verticalLine ? vNeg : hNeg; - positiveRun = verticalLine ? vPos : hPos; - runsMeasured = true; - } - - vec2 tangent = verticalLine ? vec2(0.0, px.y) : vec2(px.x, 0.0); - vec2 normal = verticalLine - ? vec2(dL >= dR ? -1.0 : 1.0, 0.0) - : vec2(0.0, dU >= dD ? -1.0 : 1.0); - - if (!runsMeasured) { - negativeRun = measureRun(uv, px, tangent, verticalLine, threshold, false); - positiveRun = measureRun(uv, px, tangent, verticalLine, threshold, true); - } - - float span = negativeRun + positiveRun; - float edgeConfidence = smoothstep(threshold, threshold * 2.5, strongest); - - vec4 nw = edgeAt(uv + vec2(-px.x, -px.y), px); - vec4 ne = edgeAt(uv + vec2(px.x, -px.y), px); - vec4 sw = edgeAt(uv + vec2(-px.x, px.y), px); - vec4 se = edgeAt(uv + vec2(px.x, px.y), px); - - float runEndpointPattern = clamp( - abs(negativeRun - positiveRun) / max(span, 1.0), 0.0, 1.0); - float crossingA = verticalLine - ? abs(nw.a - ne.a) - : abs(nw.g - sw.g); - float crossingB = verticalLine - ? abs(sw.b - se.b) - : abs(ne.r - se.r); - float crossingContrast = abs(crossingA - crossingB); - float crossingPattern = smoothstep(threshold, threshold * 2.5, crossingContrast); - vec4 edgeMin = min(min(nw, ne), min(sw, se)); - vec4 edgeMax = max(max(nw, ne), max(sw, se)); - float edgeVariation = max( - max(edgeMax.r - edgeMin.r, edgeMax.g - edgeMin.g), - max(edgeMax.b - edgeMin.b, edgeMax.a - edgeMin.a)); - float balancedCrossing = edgeVariation > 0.01 - ? smoothstep(threshold, threshold * 2.5, min(crossingA, crossingB)) - : 0.0; - float endpointPattern = runEndpointPattern > 0.01 - ? max(runEndpointPattern, balancedCrossing) - : runEndpointPattern; - float endpointArea = endpointPattern / (1.0 + span * 0.055); - float areaWeight = 0.38 * crossingPattern * clamp(span / 4.0, 0.0, 1.0); - float diagonalContrast = max( - max(max(abs(nw.r - se.r), abs(nw.g - se.g)), - max(abs(nw.b - se.b), abs(nw.a - se.a))), - max(max(abs(ne.r - sw.r), abs(ne.g - sw.g)), - max(abs(ne.b - sw.b), abs(ne.a - sw.a)))); - float cornerFactor = 1.0 - 0.35 * smoothstep(threshold, threshold * 3.0, diagonalContrast); - float baseWeight = areaWeight * endpointArea * edgeConfidence * cornerFactor; - - float diagonalStrength = min(vertical, horizontal); - float diagonalPattern = smoothstep(threshold, threshold * 2.5, diagonalStrength); - float diagonalContinuity = smoothstep(1.0, 3.0, span); - float shortDiagonalFallback = - (span > 0.0 && span <= 1.0 && crossingContrast <= threshold && diagonalStrength > threshold) - ? 1.0 : 0.0; - float diagonalFallback = 0.16 * diagonalPattern * edgeConfidence - * cornerFactor * max( - diagonalContinuity * max(crossingPattern, balancedCrossing), - shortDiagonalFallback); - - float weight = clamp(max(baseWeight, diagonalFallback), 0.0, 0.42); - outColor = vec4(weight, normal.x * 0.5 + 0.5, normal.y * 0.5 + 0.5, 1.0); + vec2 pixcoord; + vec4 offset[3]; + SMAABlendingWeightCalculationVS(fragTexCoord, pixcoord, offset); + outColor = SMAABlendingWeightCalculationPS(fragTexCoord, pixcoord, offset, EdgeTexture, + AreaTexture, SearchTexture, vec4(0.0)); } diff --git a/app/src/main/cpp/shaders/smaa_weights_frag.h b/app/src/main/cpp/shaders/smaa_weights_frag.h index be2681e8a2..5802838e6e 100644 --- a/app/src/main/cpp/shaders/smaa_weights_frag.h +++ b/app/src/main/cpp/shaders/smaa_weights_frag.h @@ -1,567 +1,986 @@ -// SPIR-V gerado -#pragma once + // 1116.6.0 + #pragma once const uint32_t smaa_weights_code[] = { - 0x07230203,0x00010000,0x0008000b,0x000002e6,0x00000000,0x00020011,0x00000001,0x0006000b, + 0x07230203,0x00010000,0x0008000b,0x000004fe,0x00000000,0x00020011,0x00000001,0x0006000b, 0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001, - 0x0007000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x000000cb,0x000000fd,0x00030010, - 0x00000004,0x00000007,0x00030003,0x00000002,0x000001c2,0x00040005,0x00000004,0x6e69616d, - 0x00000000,0x00060005,0x0000000d,0x65676465,0x76287441,0x763b3266,0x003b3266,0x00030005, - 0x0000000b,0x00007675,0x00030005,0x0000000c,0x00007870,0x00080005,0x00000012,0x74726576, - 0x6c616369,0x65676445,0x32667628,0x3266763b,0x0000003b,0x00030005,0x00000010,0x00007675, - 0x00030005,0x00000011,0x00007870,0x00080005,0x00000016,0x69726f68,0x746e6f7a,0x64456c61, - 0x76286567,0x763b3266,0x003b3266,0x00030005,0x00000014,0x00007675,0x00030005,0x00000015, - 0x00007870,0x000b0005,0x00000022,0x7361656d,0x52657275,0x76286e75,0x763b3266,0x763b3266, - 0x623b3266,0x31663b31,0x3b31623b,0x00000000,0x00040005,0x0000001c,0x6769726f,0x00006e69, - 0x00040005,0x0000001d,0x65786574,0x0000006c,0x00040005,0x0000001e,0x676e6174,0x00746e65, - 0x00060005,0x0000001f,0x74726576,0x6c616369,0x656e694c,0x00000000,0x00040005,0x00000020, - 0x696d696c,0x00000074,0x00050005,0x00000021,0x69736f70,0x65766974,0x00000000,0x00040005, - 0x00000024,0x65676465,0x00005655,0x00030005,0x00000030,0x00000065,0x00050005,0x00000034, - 0x65676445,0x74786554,0x00657275,0x00030005,0x0000004d,0x00000065,0x00040005,0x0000004e, - 0x61726170,0x0000006d,0x00040005,0x00000050,0x61726170,0x0000006d,0x00030005,0x0000005b, - 0x00000065,0x00040005,0x0000005c,0x61726170,0x0000006d,0x00040005,0x0000005e,0x61726170, - 0x0000006d,0x00030005,0x00000069,0x006e7572,0x00030005,0x0000006c,0x00000069,0x00040005, - 0x00000076,0x626f7270,0x00000065,0x00040005,0x00000083,0x65646e69,0x00000078,0x00050005, - 0x00000085,0x736e6f43,0x746e6174,0x00000073,0x00040006,0x00000085,0x00000000,0x0063646e, - 0x00060006,0x00000085,0x00000001,0x6f736572,0x6974756c,0x00006e6f,0x00050006,0x00000085, - 0x00000002,0x72747865,0x00000061,0x00040006,0x00000085,0x00000003,0x00646170,0x00030005, - 0x00000087,0x00006370,0x00040005,0x0000008e,0x657a6973,0x00000000,0x00040005,0x000000a3, - 0x65676465,0x00000000,0x00040005,0x000000a8,0x61726170,0x0000006d,0x00040005,0x000000aa, - 0x61726170,0x0000006d,0x00040005,0x000000ae,0x61726170,0x0000006d,0x00040005,0x000000b0, - 0x61726170,0x0000006d,0x00030005,0x000000c3,0x00007870,0x00030005,0x000000c9,0x00007675, - 0x00060005,0x000000cb,0x67617266,0x43786554,0x64726f6f,0x00000000,0x00030005,0x000000d3, - 0x00000065,0x00040005,0x000000d4,0x61726170,0x0000006d,0x00040005,0x000000d6,0x61726170, - 0x0000006d,0x00030005,0x000000d9,0x00004c64,0x00030005,0x000000dc,0x00005264,0x00030005, - 0x000000df,0x00005564,0x00030005,0x000000e2,0x00004464,0x00050005,0x000000e5,0x74726576, - 0x6c616369,0x00000000,0x00050005,0x000000e9,0x69726f68,0x746e6f7a,0x00006c61,0x00050005, - 0x000000ed,0x6f727473,0x7365676e,0x00000074,0x00050005,0x000000f1,0x65726874,0x6c6f6873, - 0x00000064,0x00050005,0x000000fd,0x4374756f,0x726f6c6f,0x00000000,0x00050005,0x00000100, - 0x6167656e,0x65766974,0x006e7552,0x00050005,0x00000101,0x69736f70,0x65766974,0x006e7552, - 0x00060005,0x00000102,0x736e7572,0x7361654d,0x64657275,0x00000000,0x00060005,0x00000109, - 0x74726576,0x6c616369,0x656e694c,0x00000000,0x00040005,0x00000112,0x67654e76,0x00000000, - 0x00040005,0x00000116,0x61726170,0x0000006d,0x00040005,0x00000118,0x61726170,0x0000006d, - 0x00040005,0x0000011a,0x61726170,0x0000006d,0x00040005,0x0000011b,0x61726170,0x0000006d, - 0x00040005,0x0000011c,0x61726170,0x0000006d,0x00040005,0x0000011e,0x61726170,0x0000006d, - 0x00040005,0x00000120,0x736f5076,0x00000000,0x00040005,0x00000124,0x61726170,0x0000006d, - 0x00040005,0x00000126,0x61726170,0x0000006d,0x00040005,0x00000128,0x61726170,0x0000006d, - 0x00040005,0x00000129,0x61726170,0x0000006d,0x00040005,0x0000012a,0x61726170,0x0000006d, - 0x00040005,0x0000012c,0x61726170,0x0000006d,0x00040005,0x0000012e,0x67654e68,0x00000000, - 0x00040005,0x00000132,0x61726170,0x0000006d,0x00040005,0x00000134,0x61726170,0x0000006d, - 0x00040005,0x00000136,0x61726170,0x0000006d,0x00040005,0x00000137,0x61726170,0x0000006d, - 0x00040005,0x00000138,0x61726170,0x0000006d,0x00040005,0x0000013a,0x61726170,0x0000006d, - 0x00040005,0x0000013c,0x736f5068,0x00000000,0x00040005,0x00000140,0x61726170,0x0000006d, - 0x00040005,0x00000142,0x61726170,0x0000006d,0x00040005,0x00000144,0x61726170,0x0000006d, - 0x00040005,0x00000145,0x61726170,0x0000006d,0x00040005,0x00000146,0x61726170,0x0000006d, - 0x00040005,0x00000148,0x61726170,0x0000006d,0x00040005,0x00000159,0x676e6174,0x00746e65, - 0x00040005,0x00000166,0x6d726f6e,0x00006c61,0x00040005,0x0000017b,0x61726170,0x0000006d, - 0x00040005,0x0000017d,0x61726170,0x0000006d,0x00040005,0x0000017f,0x61726170,0x0000006d, - 0x00040005,0x00000181,0x61726170,0x0000006d,0x00040005,0x00000183,0x61726170,0x0000006d, - 0x00040005,0x00000185,0x61726170,0x0000006d,0x00040005,0x00000187,0x61726170,0x0000006d, - 0x00040005,0x00000189,0x61726170,0x0000006d,0x00040005,0x0000018b,0x61726170,0x0000006d, - 0x00040005,0x0000018d,0x61726170,0x0000006d,0x00040005,0x0000018f,0x61726170,0x0000006d, - 0x00040005,0x00000191,0x61726170,0x0000006d,0x00040005,0x00000193,0x6e617073,0x00000000, - 0x00060005,0x00000197,0x65676465,0x666e6f43,0x6e656469,0x00006563,0x00030005,0x0000019e, - 0x0000776e,0x00040005,0x000001a8,0x61726170,0x0000006d,0x00040005,0x000001a9,0x61726170, - 0x0000006d,0x00030005,0x000001ac,0x0000656e,0x00040005,0x000001b5,0x61726170,0x0000006d, - 0x00040005,0x000001b6,0x61726170,0x0000006d,0x00030005,0x000001b9,0x00007773,0x00040005, - 0x000001c2,0x61726170,0x0000006d,0x00040005,0x000001c3,0x61726170,0x0000006d,0x00030005, - 0x000001c6,0x00006573,0x00040005,0x000001ce,0x61726170,0x0000006d,0x00040005,0x000001cf, - 0x61726170,0x0000006d,0x00070005,0x000001d2,0x456e7572,0x6f70646e,0x50746e69,0x65747461, - 0x00006e72,0x00050005,0x000001db,0x736f7263,0x676e6973,0x00000041,0x00050005,0x000001ee, - 0x736f7263,0x676e6973,0x00000042,0x00070005,0x00000201,0x736f7263,0x676e6973,0x746e6f43, - 0x74736172,0x00000000,0x00060005,0x00000206,0x736f7263,0x676e6973,0x74746150,0x006e7265, - 0x00040005,0x0000020c,0x65676465,0x006e694d,0x00040005,0x00000214,0x65676465,0x0078614d, - 0x00060005,0x0000021c,0x65676465,0x69726156,0x6f697461,0x0000006e,0x00070005,0x00000234, - 0x616c6162,0x6465636e,0x736f7243,0x676e6973,0x00000000,0x00060005,0x00000244,0x70646e65, - 0x746e696f,0x74746150,0x006e7265,0x00060005,0x00000250,0x70646e65,0x746e696f,0x61657241, - 0x00000000,0x00050005,0x00000257,0x61657261,0x67696557,0x00007468,0x00070005,0x00000260, - 0x67616964,0x6c616e6f,0x746e6f43,0x74736172,0x00000000,0x00060005,0x00000298,0x6e726f63, - 0x61467265,0x726f7463,0x00000000,0x00050005,0x000002a2,0x65736162,0x67696557,0x00007468, - 0x00070005,0x000002aa,0x67616964,0x6c616e6f,0x65727453,0x6874676e,0x00000000,0x00060005, - 0x000002ae,0x67616964,0x6c616e6f,0x74746150,0x006e7265,0x00070005,0x000002b4,0x67616964, - 0x6c616e6f,0x746e6f43,0x69756e69,0x00007974,0x00080005,0x000002b7,0x726f6873,0x61694474, - 0x616e6f67,0x6c61466c,0x6361626c,0x0000006b,0x00070005,0x000002c6,0x67616964,0x6c616e6f, - 0x6c6c6146,0x6b636162,0x00000000,0x00040005,0x000002d6,0x67696577,0x00007468,0x00040047, - 0x00000034,0x00000021,0x00000000,0x00040047,0x00000034,0x00000022,0x00000000,0x00030047, - 0x00000085,0x00000002,0x00050048,0x00000085,0x00000000,0x00000023,0x00000000,0x00050048, - 0x00000085,0x00000001,0x00000023,0x00000010,0x00050048,0x00000085,0x00000002,0x00000023, - 0x00000018,0x00050048,0x00000085,0x00000003,0x00000023,0x0000001c,0x00040047,0x000000cb, - 0x0000001e,0x00000000,0x00040047,0x000000fd,0x0000001e,0x00000000,0x00020013,0x00000002, - 0x00030021,0x00000003,0x00000002,0x00030016,0x00000006,0x00000020,0x00040017,0x00000007, - 0x00000006,0x00000002,0x00040020,0x00000008,0x00000007,0x00000007,0x00040017,0x00000009, - 0x00000006,0x00000004,0x00050021,0x0000000a,0x00000009,0x00000008,0x00000008,0x00050021, - 0x0000000f,0x00000006,0x00000008,0x00000008,0x00020014,0x00000018,0x00040020,0x00000019, - 0x00000007,0x00000018,0x00040020,0x0000001a,0x00000007,0x00000006,0x00090021,0x0000001b, - 0x00000006,0x00000008,0x00000008,0x00000008,0x00000019,0x0000001a,0x00000019,0x0004002b, - 0x00000006,0x00000027,0x3f000000,0x0004002b,0x00000006,0x00000029,0x3f800000,0x0005002c, - 0x00000007,0x0000002a,0x00000029,0x00000029,0x00040020,0x0000002f,0x00000007,0x00000009, - 0x00090019,0x00000031,0x00000006,0x00000001,0x00000000,0x00000000,0x00000000,0x00000001, - 0x00000000,0x0003001b,0x00000032,0x00000031,0x00040020,0x00000033,0x00000000,0x00000032, - 0x0004003b,0x00000033,0x00000034,0x00000000,0x0004002b,0x00000006,0x00000037,0x00000000, - 0x00040015,0x00000039,0x00000020,0x00000000,0x0004002b,0x00000039,0x0000003a,0x00000001, - 0x0004002b,0x00000039,0x00000045,0x00000003,0x0004002b,0x00000039,0x00000053,0x00000000, - 0x0004002b,0x00000039,0x00000061,0x00000002,0x00040015,0x0000006a,0x00000020,0x00000001, - 0x00040020,0x0000006b,0x00000007,0x0000006a,0x0004002b,0x0000006a,0x0000006d,0x00000001, - 0x0004002b,0x0000006a,0x00000074,0x00000006,0x0004002b,0x00000006,0x0000007d,0xbf800000, - 0x00040017,0x00000081,0x0000006a,0x00000002,0x00040020,0x00000082,0x00000007,0x00000081, - 0x0006001e,0x00000085,0x00000009,0x00000007,0x00000006,0x00000006,0x00040020,0x00000086, - 0x00000009,0x00000085,0x0004003b,0x00000086,0x00000087,0x00000009,0x00040020,0x00000088, - 0x00000009,0x00000007,0x0004002b,0x0000006a,0x00000093,0x00000000,0x0005002c,0x00000081, - 0x00000094,0x00000093,0x00000093,0x00040017,0x00000095,0x00000018,0x00000002,0x0004002b, - 0x00000006,0x000000b6,0x3f266666,0x00040020,0x000000ca,0x00000001,0x00000007,0x0004003b, - 0x000000ca,0x000000cb,0x00000001,0x0004002b,0x00000006,0x000000f2,0x3d3851ec,0x0004002b, - 0x00000006,0x000000f4,0x3df5c28f,0x00040020,0x000000fc,0x00000003,0x00000009,0x0004003b, - 0x000000fc,0x000000fd,0x00000003,0x0007002c,0x00000009,0x000000fe,0x00000037,0x00000027, - 0x00000027,0x00000037,0x0003002a,0x00000018,0x00000103,0x00030029,0x00000018,0x0000010a, - 0x0004002b,0x00000006,0x0000019a,0x40200000,0x0004002b,0x00000006,0x00000236,0x3c23d70a, - 0x0004002b,0x00000006,0x00000253,0x3d6147ae,0x0004002b,0x00000006,0x00000258,0x3ec28f5c, - 0x0004002b,0x00000006,0x0000025c,0x40800000,0x0004002b,0x00000006,0x00000299,0x3eb33333, - 0x0004002b,0x00000006,0x0000029c,0x40400000,0x0004002b,0x00000006,0x000002c7,0x3e23d70a, - 0x0004002b,0x00000006,0x000002da,0x3ed70a3d,0x00050036,0x00000002,0x00000004,0x00000000, - 0x00000003,0x000200f8,0x00000005,0x0004003b,0x00000008,0x000000c3,0x00000007,0x0004003b, - 0x00000008,0x000000c9,0x00000007,0x0004003b,0x0000002f,0x000000d3,0x00000007,0x0004003b, - 0x00000008,0x000000d4,0x00000007,0x0004003b,0x00000008,0x000000d6,0x00000007,0x0004003b, - 0x0000001a,0x000000d9,0x00000007,0x0004003b,0x0000001a,0x000000dc,0x00000007,0x0004003b, - 0x0000001a,0x000000df,0x00000007,0x0004003b,0x0000001a,0x000000e2,0x00000007,0x0004003b, - 0x0000001a,0x000000e5,0x00000007,0x0004003b,0x0000001a,0x000000e9,0x00000007,0x0004003b, - 0x0000001a,0x000000ed,0x00000007,0x0004003b,0x0000001a,0x000000f1,0x00000007,0x0004003b, - 0x0000001a,0x00000100,0x00000007,0x0004003b,0x0000001a,0x00000101,0x00000007,0x0004003b, - 0x00000019,0x00000102,0x00000007,0x0004003b,0x00000019,0x00000109,0x00000007,0x0004003b, - 0x0000001a,0x00000112,0x00000007,0x0004003b,0x00000008,0x00000116,0x00000007,0x0004003b, - 0x00000008,0x00000118,0x00000007,0x0004003b,0x00000008,0x0000011a,0x00000007,0x0004003b, - 0x00000019,0x0000011b,0x00000007,0x0004003b,0x0000001a,0x0000011c,0x00000007,0x0004003b, - 0x00000019,0x0000011e,0x00000007,0x0004003b,0x0000001a,0x00000120,0x00000007,0x0004003b, - 0x00000008,0x00000124,0x00000007,0x0004003b,0x00000008,0x00000126,0x00000007,0x0004003b, - 0x00000008,0x00000128,0x00000007,0x0004003b,0x00000019,0x00000129,0x00000007,0x0004003b, - 0x0000001a,0x0000012a,0x00000007,0x0004003b,0x00000019,0x0000012c,0x00000007,0x0004003b, - 0x0000001a,0x0000012e,0x00000007,0x0004003b,0x00000008,0x00000132,0x00000007,0x0004003b, - 0x00000008,0x00000134,0x00000007,0x0004003b,0x00000008,0x00000136,0x00000007,0x0004003b, - 0x00000019,0x00000137,0x00000007,0x0004003b,0x0000001a,0x00000138,0x00000007,0x0004003b, - 0x00000019,0x0000013a,0x00000007,0x0004003b,0x0000001a,0x0000013c,0x00000007,0x0004003b, - 0x00000008,0x00000140,0x00000007,0x0004003b,0x00000008,0x00000142,0x00000007,0x0004003b, - 0x00000008,0x00000144,0x00000007,0x0004003b,0x00000019,0x00000145,0x00000007,0x0004003b, - 0x0000001a,0x00000146,0x00000007,0x0004003b,0x00000019,0x00000148,0x00000007,0x0004003b, - 0x00000008,0x00000159,0x00000007,0x0004003b,0x00000008,0x0000015b,0x00000007,0x0004003b, - 0x00000008,0x00000166,0x00000007,0x0004003b,0x00000008,0x00000168,0x00000007,0x0004003b, - 0x00000008,0x0000017b,0x00000007,0x0004003b,0x00000008,0x0000017d,0x00000007,0x0004003b, - 0x00000008,0x0000017f,0x00000007,0x0004003b,0x00000019,0x00000181,0x00000007,0x0004003b, - 0x0000001a,0x00000183,0x00000007,0x0004003b,0x00000019,0x00000185,0x00000007,0x0004003b, - 0x00000008,0x00000187,0x00000007,0x0004003b,0x00000008,0x00000189,0x00000007,0x0004003b, - 0x00000008,0x0000018b,0x00000007,0x0004003b,0x00000019,0x0000018d,0x00000007,0x0004003b, - 0x0000001a,0x0000018f,0x00000007,0x0004003b,0x00000019,0x00000191,0x00000007,0x0004003b, - 0x0000001a,0x00000193,0x00000007,0x0004003b,0x0000001a,0x00000197,0x00000007,0x0004003b, - 0x0000002f,0x0000019e,0x00000007,0x0004003b,0x00000008,0x000001a8,0x00000007,0x0004003b, - 0x00000008,0x000001a9,0x00000007,0x0004003b,0x0000002f,0x000001ac,0x00000007,0x0004003b, - 0x00000008,0x000001b5,0x00000007,0x0004003b,0x00000008,0x000001b6,0x00000007,0x0004003b, - 0x0000002f,0x000001b9,0x00000007,0x0004003b,0x00000008,0x000001c2,0x00000007,0x0004003b, - 0x00000008,0x000001c3,0x00000007,0x0004003b,0x0000002f,0x000001c6,0x00000007,0x0004003b, - 0x00000008,0x000001ce,0x00000007,0x0004003b,0x00000008,0x000001cf,0x00000007,0x0004003b, - 0x0000001a,0x000001d2,0x00000007,0x0004003b,0x0000001a,0x000001db,0x00000007,0x0004003b, - 0x0000001a,0x000001dd,0x00000007,0x0004003b,0x0000001a,0x000001ee,0x00000007,0x0004003b, - 0x0000001a,0x000001f0,0x00000007,0x0004003b,0x0000001a,0x00000201,0x00000007,0x0004003b, - 0x0000001a,0x00000206,0x00000007,0x0004003b,0x0000002f,0x0000020c,0x00000007,0x0004003b, - 0x0000002f,0x00000214,0x00000007,0x0004003b,0x0000001a,0x0000021c,0x00000007,0x0004003b, - 0x0000001a,0x00000234,0x00000007,0x0004003b,0x0000001a,0x00000238,0x00000007,0x0004003b, - 0x0000001a,0x00000244,0x00000007,0x0004003b,0x0000001a,0x00000247,0x00000007,0x0004003b, - 0x0000001a,0x00000250,0x00000007,0x0004003b,0x0000001a,0x00000257,0x00000007,0x0004003b, - 0x0000001a,0x00000260,0x00000007,0x0004003b,0x0000001a,0x00000298,0x00000007,0x0004003b, - 0x0000001a,0x000002a2,0x00000007,0x0004003b,0x0000001a,0x000002aa,0x00000007,0x0004003b, - 0x0000001a,0x000002ae,0x00000007,0x0004003b,0x0000001a,0x000002b4,0x00000007,0x0004003b, - 0x0000001a,0x000002b7,0x00000007,0x0004003b,0x0000001a,0x000002c6,0x00000007,0x0004003b, - 0x0000001a,0x000002d6,0x00000007,0x00050041,0x00000088,0x000000c4,0x00000087,0x0000006d, - 0x0004003d,0x00000007,0x000000c5,0x000000c4,0x0007000c,0x00000007,0x000000c6,0x00000001, - 0x00000028,0x000000c5,0x0000002a,0x00050050,0x00000007,0x000000c7,0x00000029,0x00000029, - 0x00050088,0x00000007,0x000000c8,0x000000c7,0x000000c6,0x0003003e,0x000000c3,0x000000c8, - 0x0004003d,0x00000007,0x000000cc,0x000000cb,0x0004003d,0x00000007,0x000000cd,0x000000c3, - 0x0005008e,0x00000007,0x000000ce,0x000000cd,0x00000027,0x0004003d,0x00000007,0x000000cf, - 0x000000c3,0x0005008e,0x00000007,0x000000d0,0x000000cf,0x00000027,0x00050083,0x00000007, - 0x000000d1,0x0000002a,0x000000d0,0x0008000c,0x00000007,0x000000d2,0x00000001,0x0000002b, - 0x000000cc,0x000000ce,0x000000d1,0x0003003e,0x000000c9,0x000000d2,0x0004003d,0x00000007, - 0x000000d5,0x000000c9,0x0003003e,0x000000d4,0x000000d5,0x0004003d,0x00000007,0x000000d7, - 0x000000c3,0x0003003e,0x000000d6,0x000000d7,0x00060039,0x00000009,0x000000d8,0x0000000d, - 0x000000d4,0x000000d6,0x0003003e,0x000000d3,0x000000d8,0x00050041,0x0000001a,0x000000da, - 0x000000d3,0x00000053,0x0004003d,0x00000006,0x000000db,0x000000da,0x0003003e,0x000000d9, - 0x000000db,0x00050041,0x0000001a,0x000000dd,0x000000d3,0x0000003a,0x0004003d,0x00000006, - 0x000000de,0x000000dd,0x0003003e,0x000000dc,0x000000de,0x00050041,0x0000001a,0x000000e0, - 0x000000d3,0x00000061,0x0004003d,0x00000006,0x000000e1,0x000000e0,0x0003003e,0x000000df, - 0x000000e1,0x00050041,0x0000001a,0x000000e3,0x000000d3,0x00000045,0x0004003d,0x00000006, - 0x000000e4,0x000000e3,0x0003003e,0x000000e2,0x000000e4,0x0004003d,0x00000006,0x000000e6, - 0x000000d9,0x0004003d,0x00000006,0x000000e7,0x000000dc,0x0007000c,0x00000006,0x000000e8, - 0x00000001,0x00000028,0x000000e6,0x000000e7,0x0003003e,0x000000e5,0x000000e8,0x0004003d, - 0x00000006,0x000000ea,0x000000df,0x0004003d,0x00000006,0x000000eb,0x000000e2,0x0007000c, - 0x00000006,0x000000ec,0x00000001,0x00000028,0x000000ea,0x000000eb,0x0003003e,0x000000e9, - 0x000000ec,0x0004003d,0x00000006,0x000000ee,0x000000e5,0x0004003d,0x00000006,0x000000ef, - 0x000000e9,0x0007000c,0x00000006,0x000000f0,0x00000001,0x00000028,0x000000ee,0x000000ef, - 0x0003003e,0x000000ed,0x000000f0,0x0004003d,0x00000006,0x000000f3,0x000000ed,0x00050085, - 0x00000006,0x000000f5,0x000000f3,0x000000f4,0x0007000c,0x00000006,0x000000f6,0x00000001, - 0x00000028,0x000000f2,0x000000f5,0x0003003e,0x000000f1,0x000000f6,0x0004003d,0x00000006, - 0x000000f7,0x000000ed,0x0004003d,0x00000006,0x000000f8,0x000000f1,0x000500bc,0x00000018, - 0x000000f9,0x000000f7,0x000000f8,0x000300f7,0x000000fb,0x00000000,0x000400fa,0x000000f9, - 0x000000fa,0x000000fb,0x000200f8,0x000000fa,0x0003003e,0x000000fd,0x000000fe,0x000100fd, - 0x000200f8,0x000000fb,0x0003003e,0x00000100,0x00000037,0x0003003e,0x00000101,0x00000037, - 0x0003003e,0x00000102,0x00000103,0x0004003d,0x00000006,0x00000104,0x000000e5,0x0004003d, - 0x00000006,0x00000105,0x000000e9,0x000500ba,0x00000018,0x00000106,0x00000104,0x00000105, - 0x000300f7,0x00000108,0x00000000,0x000400fa,0x00000106,0x00000107,0x0000010b,0x000200f8, - 0x00000107,0x0003003e,0x00000109,0x0000010a,0x000200f9,0x00000108,0x000200f8,0x0000010b, - 0x0004003d,0x00000006,0x0000010c,0x000000e9,0x0004003d,0x00000006,0x0000010d,0x000000e5, - 0x000500ba,0x00000018,0x0000010e,0x0000010c,0x0000010d,0x000300f7,0x00000110,0x00000000, - 0x000400fa,0x0000010e,0x0000010f,0x00000111,0x000200f8,0x0000010f,0x0003003e,0x00000109, - 0x00000103,0x000200f9,0x00000110,0x000200f8,0x00000111,0x00050041,0x0000001a,0x00000113, - 0x000000c3,0x0000003a,0x0004003d,0x00000006,0x00000114,0x00000113,0x00050050,0x00000007, - 0x00000115,0x00000037,0x00000114,0x0004003d,0x00000007,0x00000117,0x000000c9,0x0003003e, - 0x00000116,0x00000117,0x0004003d,0x00000007,0x00000119,0x000000c3,0x0003003e,0x00000118, - 0x00000119,0x0003003e,0x0000011a,0x00000115,0x0003003e,0x0000011b,0x0000010a,0x0004003d, - 0x00000006,0x0000011d,0x000000f1,0x0003003e,0x0000011c,0x0000011d,0x0003003e,0x0000011e, - 0x00000103,0x000a0039,0x00000006,0x0000011f,0x00000022,0x00000116,0x00000118,0x0000011a, - 0x0000011b,0x0000011c,0x0000011e,0x0003003e,0x00000112,0x0000011f,0x00050041,0x0000001a, - 0x00000121,0x000000c3,0x0000003a,0x0004003d,0x00000006,0x00000122,0x00000121,0x00050050, - 0x00000007,0x00000123,0x00000037,0x00000122,0x0004003d,0x00000007,0x00000125,0x000000c9, - 0x0003003e,0x00000124,0x00000125,0x0004003d,0x00000007,0x00000127,0x000000c3,0x0003003e, - 0x00000126,0x00000127,0x0003003e,0x00000128,0x00000123,0x0003003e,0x00000129,0x0000010a, - 0x0004003d,0x00000006,0x0000012b,0x000000f1,0x0003003e,0x0000012a,0x0000012b,0x0003003e, - 0x0000012c,0x0000010a,0x000a0039,0x00000006,0x0000012d,0x00000022,0x00000124,0x00000126, - 0x00000128,0x00000129,0x0000012a,0x0000012c,0x0003003e,0x00000120,0x0000012d,0x00050041, - 0x0000001a,0x0000012f,0x000000c3,0x00000053,0x0004003d,0x00000006,0x00000130,0x0000012f, - 0x00050050,0x00000007,0x00000131,0x00000130,0x00000037,0x0004003d,0x00000007,0x00000133, - 0x000000c9,0x0003003e,0x00000132,0x00000133,0x0004003d,0x00000007,0x00000135,0x000000c3, - 0x0003003e,0x00000134,0x00000135,0x0003003e,0x00000136,0x00000131,0x0003003e,0x00000137, - 0x00000103,0x0004003d,0x00000006,0x00000139,0x000000f1,0x0003003e,0x00000138,0x00000139, - 0x0003003e,0x0000013a,0x00000103,0x000a0039,0x00000006,0x0000013b,0x00000022,0x00000132, - 0x00000134,0x00000136,0x00000137,0x00000138,0x0000013a,0x0003003e,0x0000012e,0x0000013b, - 0x00050041,0x0000001a,0x0000013d,0x000000c3,0x00000053,0x0004003d,0x00000006,0x0000013e, - 0x0000013d,0x00050050,0x00000007,0x0000013f,0x0000013e,0x00000037,0x0004003d,0x00000007, - 0x00000141,0x000000c9,0x0003003e,0x00000140,0x00000141,0x0004003d,0x00000007,0x00000143, - 0x000000c3,0x0003003e,0x00000142,0x00000143,0x0003003e,0x00000144,0x0000013f,0x0003003e, - 0x00000145,0x00000103,0x0004003d,0x00000006,0x00000147,0x000000f1,0x0003003e,0x00000146, - 0x00000147,0x0003003e,0x00000148,0x0000010a,0x000a0039,0x00000006,0x00000149,0x00000022, - 0x00000140,0x00000142,0x00000144,0x00000145,0x00000146,0x00000148,0x0003003e,0x0000013c, - 0x00000149,0x0004003d,0x00000006,0x0000014a,0x00000112,0x0004003d,0x00000006,0x0000014b, - 0x00000120,0x00050081,0x00000006,0x0000014c,0x0000014a,0x0000014b,0x0004003d,0x00000006, - 0x0000014d,0x0000012e,0x0004003d,0x00000006,0x0000014e,0x0000013c,0x00050081,0x00000006, - 0x0000014f,0x0000014d,0x0000014e,0x000500be,0x00000018,0x00000150,0x0000014c,0x0000014f, - 0x0003003e,0x00000109,0x00000150,0x0004003d,0x00000018,0x00000151,0x00000109,0x0004003d, - 0x00000006,0x00000152,0x00000112,0x0004003d,0x00000006,0x00000153,0x0000012e,0x000600a9, - 0x00000006,0x00000154,0x00000151,0x00000152,0x00000153,0x0003003e,0x00000100,0x00000154, - 0x0004003d,0x00000018,0x00000155,0x00000109,0x0004003d,0x00000006,0x00000156,0x00000120, - 0x0004003d,0x00000006,0x00000157,0x0000013c,0x000600a9,0x00000006,0x00000158,0x00000155, - 0x00000156,0x00000157,0x0003003e,0x00000101,0x00000158,0x0003003e,0x00000102,0x0000010a, - 0x000200f9,0x00000110,0x000200f8,0x00000110,0x000200f9,0x00000108,0x000200f8,0x00000108, - 0x0004003d,0x00000018,0x0000015a,0x00000109,0x000300f7,0x0000015d,0x00000000,0x000400fa, - 0x0000015a,0x0000015c,0x00000161,0x000200f8,0x0000015c,0x00050041,0x0000001a,0x0000015e, - 0x000000c3,0x0000003a,0x0004003d,0x00000006,0x0000015f,0x0000015e,0x00050050,0x00000007, - 0x00000160,0x00000037,0x0000015f,0x0003003e,0x0000015b,0x00000160,0x000200f9,0x0000015d, - 0x000200f8,0x00000161,0x00050041,0x0000001a,0x00000162,0x000000c3,0x00000053,0x0004003d, - 0x00000006,0x00000163,0x00000162,0x00050050,0x00000007,0x00000164,0x00000163,0x00000037, - 0x0003003e,0x0000015b,0x00000164,0x000200f9,0x0000015d,0x000200f8,0x0000015d,0x0004003d, - 0x00000007,0x00000165,0x0000015b,0x0003003e,0x00000159,0x00000165,0x0004003d,0x00000018, - 0x00000167,0x00000109,0x000300f7,0x0000016a,0x00000000,0x000400fa,0x00000167,0x00000169, - 0x00000170,0x000200f8,0x00000169,0x0004003d,0x00000006,0x0000016b,0x000000d9,0x0004003d, - 0x00000006,0x0000016c,0x000000dc,0x000500be,0x00000018,0x0000016d,0x0000016b,0x0000016c, - 0x000600a9,0x00000006,0x0000016e,0x0000016d,0x0000007d,0x00000029,0x00050050,0x00000007, - 0x0000016f,0x0000016e,0x00000037,0x0003003e,0x00000168,0x0000016f,0x000200f9,0x0000016a, - 0x000200f8,0x00000170,0x0004003d,0x00000006,0x00000171,0x000000df,0x0004003d,0x00000006, - 0x00000172,0x000000e2,0x000500be,0x00000018,0x00000173,0x00000171,0x00000172,0x000600a9, - 0x00000006,0x00000174,0x00000173,0x0000007d,0x00000029,0x00050050,0x00000007,0x00000175, - 0x00000037,0x00000174,0x0003003e,0x00000168,0x00000175,0x000200f9,0x0000016a,0x000200f8, - 0x0000016a,0x0004003d,0x00000007,0x00000176,0x00000168,0x0003003e,0x00000166,0x00000176, - 0x0004003d,0x00000018,0x00000177,0x00000102,0x000400a8,0x00000018,0x00000178,0x00000177, - 0x000300f7,0x0000017a,0x00000000,0x000400fa,0x00000178,0x00000179,0x0000017a,0x000200f8, - 0x00000179,0x0004003d,0x00000007,0x0000017c,0x000000c9,0x0003003e,0x0000017b,0x0000017c, - 0x0004003d,0x00000007,0x0000017e,0x000000c3,0x0003003e,0x0000017d,0x0000017e,0x0004003d, - 0x00000007,0x00000180,0x00000159,0x0003003e,0x0000017f,0x00000180,0x0004003d,0x00000018, - 0x00000182,0x00000109,0x0003003e,0x00000181,0x00000182,0x0004003d,0x00000006,0x00000184, - 0x000000f1,0x0003003e,0x00000183,0x00000184,0x0003003e,0x00000185,0x00000103,0x000a0039, - 0x00000006,0x00000186,0x00000022,0x0000017b,0x0000017d,0x0000017f,0x00000181,0x00000183, - 0x00000185,0x0003003e,0x00000100,0x00000186,0x0004003d,0x00000007,0x00000188,0x000000c9, - 0x0003003e,0x00000187,0x00000188,0x0004003d,0x00000007,0x0000018a,0x000000c3,0x0003003e, - 0x00000189,0x0000018a,0x0004003d,0x00000007,0x0000018c,0x00000159,0x0003003e,0x0000018b, - 0x0000018c,0x0004003d,0x00000018,0x0000018e,0x00000109,0x0003003e,0x0000018d,0x0000018e, - 0x0004003d,0x00000006,0x00000190,0x000000f1,0x0003003e,0x0000018f,0x00000190,0x0003003e, - 0x00000191,0x0000010a,0x000a0039,0x00000006,0x00000192,0x00000022,0x00000187,0x00000189, - 0x0000018b,0x0000018d,0x0000018f,0x00000191,0x0003003e,0x00000101,0x00000192,0x000200f9, - 0x0000017a,0x000200f8,0x0000017a,0x0004003d,0x00000006,0x00000194,0x00000100,0x0004003d, - 0x00000006,0x00000195,0x00000101,0x00050081,0x00000006,0x00000196,0x00000194,0x00000195, - 0x0003003e,0x00000193,0x00000196,0x0004003d,0x00000006,0x00000198,0x000000f1,0x0004003d, - 0x00000006,0x00000199,0x000000f1,0x00050085,0x00000006,0x0000019b,0x00000199,0x0000019a, - 0x0004003d,0x00000006,0x0000019c,0x000000ed,0x0008000c,0x00000006,0x0000019d,0x00000001, - 0x00000031,0x00000198,0x0000019b,0x0000019c,0x0003003e,0x00000197,0x0000019d,0x0004003d, - 0x00000007,0x0000019f,0x000000c9,0x00050041,0x0000001a,0x000001a0,0x000000c3,0x00000053, - 0x0004003d,0x00000006,0x000001a1,0x000001a0,0x0004007f,0x00000006,0x000001a2,0x000001a1, - 0x00050041,0x0000001a,0x000001a3,0x000000c3,0x0000003a,0x0004003d,0x00000006,0x000001a4, - 0x000001a3,0x0004007f,0x00000006,0x000001a5,0x000001a4,0x00050050,0x00000007,0x000001a6, - 0x000001a2,0x000001a5,0x00050081,0x00000007,0x000001a7,0x0000019f,0x000001a6,0x0003003e, - 0x000001a8,0x000001a7,0x0004003d,0x00000007,0x000001aa,0x000000c3,0x0003003e,0x000001a9, - 0x000001aa,0x00060039,0x00000009,0x000001ab,0x0000000d,0x000001a8,0x000001a9,0x0003003e, - 0x0000019e,0x000001ab,0x0004003d,0x00000007,0x000001ad,0x000000c9,0x00050041,0x0000001a, - 0x000001ae,0x000000c3,0x00000053,0x0004003d,0x00000006,0x000001af,0x000001ae,0x00050041, - 0x0000001a,0x000001b0,0x000000c3,0x0000003a,0x0004003d,0x00000006,0x000001b1,0x000001b0, - 0x0004007f,0x00000006,0x000001b2,0x000001b1,0x00050050,0x00000007,0x000001b3,0x000001af, - 0x000001b2,0x00050081,0x00000007,0x000001b4,0x000001ad,0x000001b3,0x0003003e,0x000001b5, - 0x000001b4,0x0004003d,0x00000007,0x000001b7,0x000000c3,0x0003003e,0x000001b6,0x000001b7, - 0x00060039,0x00000009,0x000001b8,0x0000000d,0x000001b5,0x000001b6,0x0003003e,0x000001ac, - 0x000001b8,0x0004003d,0x00000007,0x000001ba,0x000000c9,0x00050041,0x0000001a,0x000001bb, - 0x000000c3,0x00000053,0x0004003d,0x00000006,0x000001bc,0x000001bb,0x0004007f,0x00000006, - 0x000001bd,0x000001bc,0x00050041,0x0000001a,0x000001be,0x000000c3,0x0000003a,0x0004003d, - 0x00000006,0x000001bf,0x000001be,0x00050050,0x00000007,0x000001c0,0x000001bd,0x000001bf, - 0x00050081,0x00000007,0x000001c1,0x000001ba,0x000001c0,0x0003003e,0x000001c2,0x000001c1, - 0x0004003d,0x00000007,0x000001c4,0x000000c3,0x0003003e,0x000001c3,0x000001c4,0x00060039, - 0x00000009,0x000001c5,0x0000000d,0x000001c2,0x000001c3,0x0003003e,0x000001b9,0x000001c5, - 0x0004003d,0x00000007,0x000001c7,0x000000c9,0x00050041,0x0000001a,0x000001c8,0x000000c3, - 0x00000053,0x0004003d,0x00000006,0x000001c9,0x000001c8,0x00050041,0x0000001a,0x000001ca, - 0x000000c3,0x0000003a,0x0004003d,0x00000006,0x000001cb,0x000001ca,0x00050050,0x00000007, - 0x000001cc,0x000001c9,0x000001cb,0x00050081,0x00000007,0x000001cd,0x000001c7,0x000001cc, - 0x0003003e,0x000001ce,0x000001cd,0x0004003d,0x00000007,0x000001d0,0x000000c3,0x0003003e, - 0x000001cf,0x000001d0,0x00060039,0x00000009,0x000001d1,0x0000000d,0x000001ce,0x000001cf, - 0x0003003e,0x000001c6,0x000001d1,0x0004003d,0x00000006,0x000001d3,0x00000100,0x0004003d, - 0x00000006,0x000001d4,0x00000101,0x00050083,0x00000006,0x000001d5,0x000001d3,0x000001d4, - 0x0006000c,0x00000006,0x000001d6,0x00000001,0x00000004,0x000001d5,0x0004003d,0x00000006, - 0x000001d7,0x00000193,0x0007000c,0x00000006,0x000001d8,0x00000001,0x00000028,0x000001d7, - 0x00000029,0x00050088,0x00000006,0x000001d9,0x000001d6,0x000001d8,0x0008000c,0x00000006, - 0x000001da,0x00000001,0x0000002b,0x000001d9,0x00000037,0x00000029,0x0003003e,0x000001d2, - 0x000001da,0x0004003d,0x00000018,0x000001dc,0x00000109,0x000300f7,0x000001df,0x00000000, - 0x000400fa,0x000001dc,0x000001de,0x000001e6,0x000200f8,0x000001de,0x00050041,0x0000001a, - 0x000001e0,0x0000019e,0x00000045,0x0004003d,0x00000006,0x000001e1,0x000001e0,0x00050041, - 0x0000001a,0x000001e2,0x000001ac,0x00000045,0x0004003d,0x00000006,0x000001e3,0x000001e2, - 0x00050083,0x00000006,0x000001e4,0x000001e1,0x000001e3,0x0006000c,0x00000006,0x000001e5, - 0x00000001,0x00000004,0x000001e4,0x0003003e,0x000001dd,0x000001e5,0x000200f9,0x000001df, - 0x000200f8,0x000001e6,0x00050041,0x0000001a,0x000001e7,0x0000019e,0x0000003a,0x0004003d, - 0x00000006,0x000001e8,0x000001e7,0x00050041,0x0000001a,0x000001e9,0x000001b9,0x0000003a, - 0x0004003d,0x00000006,0x000001ea,0x000001e9,0x00050083,0x00000006,0x000001eb,0x000001e8, - 0x000001ea,0x0006000c,0x00000006,0x000001ec,0x00000001,0x00000004,0x000001eb,0x0003003e, - 0x000001dd,0x000001ec,0x000200f9,0x000001df,0x000200f8,0x000001df,0x0004003d,0x00000006, - 0x000001ed,0x000001dd,0x0003003e,0x000001db,0x000001ed,0x0004003d,0x00000018,0x000001ef, - 0x00000109,0x000300f7,0x000001f2,0x00000000,0x000400fa,0x000001ef,0x000001f1,0x000001f9, - 0x000200f8,0x000001f1,0x00050041,0x0000001a,0x000001f3,0x000001b9,0x00000061,0x0004003d, - 0x00000006,0x000001f4,0x000001f3,0x00050041,0x0000001a,0x000001f5,0x000001c6,0x00000061, - 0x0004003d,0x00000006,0x000001f6,0x000001f5,0x00050083,0x00000006,0x000001f7,0x000001f4, - 0x000001f6,0x0006000c,0x00000006,0x000001f8,0x00000001,0x00000004,0x000001f7,0x0003003e, - 0x000001f0,0x000001f8,0x000200f9,0x000001f2,0x000200f8,0x000001f9,0x00050041,0x0000001a, - 0x000001fa,0x000001ac,0x00000053,0x0004003d,0x00000006,0x000001fb,0x000001fa,0x00050041, - 0x0000001a,0x000001fc,0x000001c6,0x00000053,0x0004003d,0x00000006,0x000001fd,0x000001fc, - 0x00050083,0x00000006,0x000001fe,0x000001fb,0x000001fd,0x0006000c,0x00000006,0x000001ff, - 0x00000001,0x00000004,0x000001fe,0x0003003e,0x000001f0,0x000001ff,0x000200f9,0x000001f2, - 0x000200f8,0x000001f2,0x0004003d,0x00000006,0x00000200,0x000001f0,0x0003003e,0x000001ee, - 0x00000200,0x0004003d,0x00000006,0x00000202,0x000001db,0x0004003d,0x00000006,0x00000203, - 0x000001ee,0x00050083,0x00000006,0x00000204,0x00000202,0x00000203,0x0006000c,0x00000006, - 0x00000205,0x00000001,0x00000004,0x00000204,0x0003003e,0x00000201,0x00000205,0x0004003d, - 0x00000006,0x00000207,0x000000f1,0x0004003d,0x00000006,0x00000208,0x000000f1,0x00050085, - 0x00000006,0x00000209,0x00000208,0x0000019a,0x0004003d,0x00000006,0x0000020a,0x00000201, - 0x0008000c,0x00000006,0x0000020b,0x00000001,0x00000031,0x00000207,0x00000209,0x0000020a, - 0x0003003e,0x00000206,0x0000020b,0x0004003d,0x00000009,0x0000020d,0x0000019e,0x0004003d, - 0x00000009,0x0000020e,0x000001ac,0x0007000c,0x00000009,0x0000020f,0x00000001,0x00000025, - 0x0000020d,0x0000020e,0x0004003d,0x00000009,0x00000210,0x000001b9,0x0004003d,0x00000009, - 0x00000211,0x000001c6,0x0007000c,0x00000009,0x00000212,0x00000001,0x00000025,0x00000210, - 0x00000211,0x0007000c,0x00000009,0x00000213,0x00000001,0x00000025,0x0000020f,0x00000212, - 0x0003003e,0x0000020c,0x00000213,0x0004003d,0x00000009,0x00000215,0x0000019e,0x0004003d, - 0x00000009,0x00000216,0x000001ac,0x0007000c,0x00000009,0x00000217,0x00000001,0x00000028, - 0x00000215,0x00000216,0x0004003d,0x00000009,0x00000218,0x000001b9,0x0004003d,0x00000009, - 0x00000219,0x000001c6,0x0007000c,0x00000009,0x0000021a,0x00000001,0x00000028,0x00000218, - 0x00000219,0x0007000c,0x00000009,0x0000021b,0x00000001,0x00000028,0x00000217,0x0000021a, - 0x0003003e,0x00000214,0x0000021b,0x00050041,0x0000001a,0x0000021d,0x00000214,0x00000053, - 0x0004003d,0x00000006,0x0000021e,0x0000021d,0x00050041,0x0000001a,0x0000021f,0x0000020c, - 0x00000053,0x0004003d,0x00000006,0x00000220,0x0000021f,0x00050083,0x00000006,0x00000221, - 0x0000021e,0x00000220,0x00050041,0x0000001a,0x00000222,0x00000214,0x0000003a,0x0004003d, - 0x00000006,0x00000223,0x00000222,0x00050041,0x0000001a,0x00000224,0x0000020c,0x0000003a, - 0x0004003d,0x00000006,0x00000225,0x00000224,0x00050083,0x00000006,0x00000226,0x00000223, - 0x00000225,0x0007000c,0x00000006,0x00000227,0x00000001,0x00000028,0x00000221,0x00000226, - 0x00050041,0x0000001a,0x00000228,0x00000214,0x00000061,0x0004003d,0x00000006,0x00000229, - 0x00000228,0x00050041,0x0000001a,0x0000022a,0x0000020c,0x00000061,0x0004003d,0x00000006, - 0x0000022b,0x0000022a,0x00050083,0x00000006,0x0000022c,0x00000229,0x0000022b,0x00050041, - 0x0000001a,0x0000022d,0x00000214,0x00000045,0x0004003d,0x00000006,0x0000022e,0x0000022d, - 0x00050041,0x0000001a,0x0000022f,0x0000020c,0x00000045,0x0004003d,0x00000006,0x00000230, - 0x0000022f,0x00050083,0x00000006,0x00000231,0x0000022e,0x00000230,0x0007000c,0x00000006, - 0x00000232,0x00000001,0x00000028,0x0000022c,0x00000231,0x0007000c,0x00000006,0x00000233, - 0x00000001,0x00000028,0x00000227,0x00000232,0x0003003e,0x0000021c,0x00000233,0x0004003d, - 0x00000006,0x00000235,0x0000021c,0x000500ba,0x00000018,0x00000237,0x00000235,0x00000236, - 0x000300f7,0x0000023a,0x00000000,0x000400fa,0x00000237,0x00000239,0x00000242,0x000200f8, - 0x00000239,0x0004003d,0x00000006,0x0000023b,0x000000f1,0x0004003d,0x00000006,0x0000023c, - 0x000000f1,0x00050085,0x00000006,0x0000023d,0x0000023c,0x0000019a,0x0004003d,0x00000006, - 0x0000023e,0x000001db,0x0004003d,0x00000006,0x0000023f,0x000001ee,0x0007000c,0x00000006, - 0x00000240,0x00000001,0x00000025,0x0000023e,0x0000023f,0x0008000c,0x00000006,0x00000241, - 0x00000001,0x00000031,0x0000023b,0x0000023d,0x00000240,0x0003003e,0x00000238,0x00000241, - 0x000200f9,0x0000023a,0x000200f8,0x00000242,0x0003003e,0x00000238,0x00000037,0x000200f9, - 0x0000023a,0x000200f8,0x0000023a,0x0004003d,0x00000006,0x00000243,0x00000238,0x0003003e, - 0x00000234,0x00000243,0x0004003d,0x00000006,0x00000245,0x000001d2,0x000500ba,0x00000018, - 0x00000246,0x00000245,0x00000236,0x000300f7,0x00000249,0x00000000,0x000400fa,0x00000246, - 0x00000248,0x0000024d,0x000200f8,0x00000248,0x0004003d,0x00000006,0x0000024a,0x000001d2, - 0x0004003d,0x00000006,0x0000024b,0x00000234,0x0007000c,0x00000006,0x0000024c,0x00000001, - 0x00000028,0x0000024a,0x0000024b,0x0003003e,0x00000247,0x0000024c,0x000200f9,0x00000249, - 0x000200f8,0x0000024d,0x0004003d,0x00000006,0x0000024e,0x000001d2,0x0003003e,0x00000247, - 0x0000024e,0x000200f9,0x00000249,0x000200f8,0x00000249,0x0004003d,0x00000006,0x0000024f, - 0x00000247,0x0003003e,0x00000244,0x0000024f,0x0004003d,0x00000006,0x00000251,0x00000244, - 0x0004003d,0x00000006,0x00000252,0x00000193,0x00050085,0x00000006,0x00000254,0x00000252, - 0x00000253,0x00050081,0x00000006,0x00000255,0x00000029,0x00000254,0x00050088,0x00000006, - 0x00000256,0x00000251,0x00000255,0x0003003e,0x00000250,0x00000256,0x0004003d,0x00000006, - 0x00000259,0x00000206,0x00050085,0x00000006,0x0000025a,0x00000258,0x00000259,0x0004003d, - 0x00000006,0x0000025b,0x00000193,0x00050088,0x00000006,0x0000025d,0x0000025b,0x0000025c, - 0x0008000c,0x00000006,0x0000025e,0x00000001,0x0000002b,0x0000025d,0x00000037,0x00000029, - 0x00050085,0x00000006,0x0000025f,0x0000025a,0x0000025e,0x0003003e,0x00000257,0x0000025f, - 0x00050041,0x0000001a,0x00000261,0x0000019e,0x00000053,0x0004003d,0x00000006,0x00000262, - 0x00000261,0x00050041,0x0000001a,0x00000263,0x000001c6,0x00000053,0x0004003d,0x00000006, - 0x00000264,0x00000263,0x00050083,0x00000006,0x00000265,0x00000262,0x00000264,0x0006000c, - 0x00000006,0x00000266,0x00000001,0x00000004,0x00000265,0x00050041,0x0000001a,0x00000267, - 0x0000019e,0x0000003a,0x0004003d,0x00000006,0x00000268,0x00000267,0x00050041,0x0000001a, - 0x00000269,0x000001c6,0x0000003a,0x0004003d,0x00000006,0x0000026a,0x00000269,0x00050083, - 0x00000006,0x0000026b,0x00000268,0x0000026a,0x0006000c,0x00000006,0x0000026c,0x00000001, - 0x00000004,0x0000026b,0x0007000c,0x00000006,0x0000026d,0x00000001,0x00000028,0x00000266, - 0x0000026c,0x00050041,0x0000001a,0x0000026e,0x0000019e,0x00000061,0x0004003d,0x00000006, - 0x0000026f,0x0000026e,0x00050041,0x0000001a,0x00000270,0x000001c6,0x00000061,0x0004003d, - 0x00000006,0x00000271,0x00000270,0x00050083,0x00000006,0x00000272,0x0000026f,0x00000271, - 0x0006000c,0x00000006,0x00000273,0x00000001,0x00000004,0x00000272,0x00050041,0x0000001a, - 0x00000274,0x0000019e,0x00000045,0x0004003d,0x00000006,0x00000275,0x00000274,0x00050041, - 0x0000001a,0x00000276,0x000001c6,0x00000045,0x0004003d,0x00000006,0x00000277,0x00000276, - 0x00050083,0x00000006,0x00000278,0x00000275,0x00000277,0x0006000c,0x00000006,0x00000279, - 0x00000001,0x00000004,0x00000278,0x0007000c,0x00000006,0x0000027a,0x00000001,0x00000028, - 0x00000273,0x00000279,0x0007000c,0x00000006,0x0000027b,0x00000001,0x00000028,0x0000026d, - 0x0000027a,0x00050041,0x0000001a,0x0000027c,0x000001ac,0x00000053,0x0004003d,0x00000006, - 0x0000027d,0x0000027c,0x00050041,0x0000001a,0x0000027e,0x000001b9,0x00000053,0x0004003d, - 0x00000006,0x0000027f,0x0000027e,0x00050083,0x00000006,0x00000280,0x0000027d,0x0000027f, - 0x0006000c,0x00000006,0x00000281,0x00000001,0x00000004,0x00000280,0x00050041,0x0000001a, - 0x00000282,0x000001ac,0x0000003a,0x0004003d,0x00000006,0x00000283,0x00000282,0x00050041, - 0x0000001a,0x00000284,0x000001b9,0x0000003a,0x0004003d,0x00000006,0x00000285,0x00000284, - 0x00050083,0x00000006,0x00000286,0x00000283,0x00000285,0x0006000c,0x00000006,0x00000287, - 0x00000001,0x00000004,0x00000286,0x0007000c,0x00000006,0x00000288,0x00000001,0x00000028, - 0x00000281,0x00000287,0x00050041,0x0000001a,0x00000289,0x000001ac,0x00000061,0x0004003d, - 0x00000006,0x0000028a,0x00000289,0x00050041,0x0000001a,0x0000028b,0x000001b9,0x00000061, - 0x0004003d,0x00000006,0x0000028c,0x0000028b,0x00050083,0x00000006,0x0000028d,0x0000028a, - 0x0000028c,0x0006000c,0x00000006,0x0000028e,0x00000001,0x00000004,0x0000028d,0x00050041, - 0x0000001a,0x0000028f,0x000001ac,0x00000045,0x0004003d,0x00000006,0x00000290,0x0000028f, - 0x00050041,0x0000001a,0x00000291,0x000001b9,0x00000045,0x0004003d,0x00000006,0x00000292, - 0x00000291,0x00050083,0x00000006,0x00000293,0x00000290,0x00000292,0x0006000c,0x00000006, - 0x00000294,0x00000001,0x00000004,0x00000293,0x0007000c,0x00000006,0x00000295,0x00000001, - 0x00000028,0x0000028e,0x00000294,0x0007000c,0x00000006,0x00000296,0x00000001,0x00000028, - 0x00000288,0x00000295,0x0007000c,0x00000006,0x00000297,0x00000001,0x00000028,0x0000027b, - 0x00000296,0x0003003e,0x00000260,0x00000297,0x0004003d,0x00000006,0x0000029a,0x000000f1, - 0x0004003d,0x00000006,0x0000029b,0x000000f1,0x00050085,0x00000006,0x0000029d,0x0000029b, - 0x0000029c,0x0004003d,0x00000006,0x0000029e,0x00000260,0x0008000c,0x00000006,0x0000029f, - 0x00000001,0x00000031,0x0000029a,0x0000029d,0x0000029e,0x00050085,0x00000006,0x000002a0, - 0x00000299,0x0000029f,0x00050083,0x00000006,0x000002a1,0x00000029,0x000002a0,0x0003003e, - 0x00000298,0x000002a1,0x0004003d,0x00000006,0x000002a3,0x00000257,0x0004003d,0x00000006, - 0x000002a4,0x00000250,0x00050085,0x00000006,0x000002a5,0x000002a3,0x000002a4,0x0004003d, - 0x00000006,0x000002a6,0x00000197,0x00050085,0x00000006,0x000002a7,0x000002a5,0x000002a6, - 0x0004003d,0x00000006,0x000002a8,0x00000298,0x00050085,0x00000006,0x000002a9,0x000002a7, - 0x000002a8,0x0003003e,0x000002a2,0x000002a9,0x0004003d,0x00000006,0x000002ab,0x000000e5, - 0x0004003d,0x00000006,0x000002ac,0x000000e9,0x0007000c,0x00000006,0x000002ad,0x00000001, - 0x00000025,0x000002ab,0x000002ac,0x0003003e,0x000002aa,0x000002ad,0x0004003d,0x00000006, - 0x000002af,0x000000f1,0x0004003d,0x00000006,0x000002b0,0x000000f1,0x00050085,0x00000006, - 0x000002b1,0x000002b0,0x0000019a,0x0004003d,0x00000006,0x000002b2,0x000002aa,0x0008000c, - 0x00000006,0x000002b3,0x00000001,0x00000031,0x000002af,0x000002b1,0x000002b2,0x0003003e, - 0x000002ae,0x000002b3,0x0004003d,0x00000006,0x000002b5,0x00000193,0x0008000c,0x00000006, - 0x000002b6,0x00000001,0x00000031,0x00000029,0x0000029c,0x000002b5,0x0003003e,0x000002b4, - 0x000002b6,0x0004003d,0x00000006,0x000002b8,0x00000193,0x000500ba,0x00000018,0x000002b9, - 0x000002b8,0x00000037,0x0004003d,0x00000006,0x000002ba,0x00000193,0x000500bc,0x00000018, - 0x000002bb,0x000002ba,0x00000029,0x000500a7,0x00000018,0x000002bc,0x000002b9,0x000002bb, - 0x0004003d,0x00000006,0x000002bd,0x00000201,0x0004003d,0x00000006,0x000002be,0x000000f1, - 0x000500bc,0x00000018,0x000002bf,0x000002bd,0x000002be,0x000500a7,0x00000018,0x000002c0, - 0x000002bc,0x000002bf,0x0004003d,0x00000006,0x000002c1,0x000002aa,0x0004003d,0x00000006, - 0x000002c2,0x000000f1,0x000500ba,0x00000018,0x000002c3,0x000002c1,0x000002c2,0x000500a7, - 0x00000018,0x000002c4,0x000002c0,0x000002c3,0x000600a9,0x00000006,0x000002c5,0x000002c4, - 0x00000029,0x00000037,0x0003003e,0x000002b7,0x000002c5,0x0004003d,0x00000006,0x000002c8, - 0x000002ae,0x00050085,0x00000006,0x000002c9,0x000002c7,0x000002c8,0x0004003d,0x00000006, - 0x000002ca,0x00000197,0x00050085,0x00000006,0x000002cb,0x000002c9,0x000002ca,0x0004003d, - 0x00000006,0x000002cc,0x00000298,0x00050085,0x00000006,0x000002cd,0x000002cb,0x000002cc, - 0x0004003d,0x00000006,0x000002ce,0x000002b4,0x0004003d,0x00000006,0x000002cf,0x00000206, - 0x0004003d,0x00000006,0x000002d0,0x00000234,0x0007000c,0x00000006,0x000002d1,0x00000001, - 0x00000028,0x000002cf,0x000002d0,0x00050085,0x00000006,0x000002d2,0x000002ce,0x000002d1, - 0x0004003d,0x00000006,0x000002d3,0x000002b7,0x0007000c,0x00000006,0x000002d4,0x00000001, - 0x00000028,0x000002d2,0x000002d3,0x00050085,0x00000006,0x000002d5,0x000002cd,0x000002d4, - 0x0003003e,0x000002c6,0x000002d5,0x0004003d,0x00000006,0x000002d7,0x000002a2,0x0004003d, - 0x00000006,0x000002d8,0x000002c6,0x0007000c,0x00000006,0x000002d9,0x00000001,0x00000028, - 0x000002d7,0x000002d8,0x0008000c,0x00000006,0x000002db,0x00000001,0x0000002b,0x000002d9, - 0x00000037,0x000002da,0x0003003e,0x000002d6,0x000002db,0x0004003d,0x00000006,0x000002dc, - 0x000002d6,0x00050041,0x0000001a,0x000002dd,0x00000166,0x00000053,0x0004003d,0x00000006, - 0x000002de,0x000002dd,0x00050085,0x00000006,0x000002df,0x000002de,0x00000027,0x00050081, - 0x00000006,0x000002e0,0x000002df,0x00000027,0x00050041,0x0000001a,0x000002e1,0x00000166, - 0x0000003a,0x0004003d,0x00000006,0x000002e2,0x000002e1,0x00050085,0x00000006,0x000002e3, - 0x000002e2,0x00000027,0x00050081,0x00000006,0x000002e4,0x000002e3,0x00000027,0x00070050, - 0x00000009,0x000002e5,0x000002dc,0x000002e0,0x000002e4,0x00000029,0x0003003e,0x000000fd, - 0x000002e5,0x000100fd,0x00010038,0x00050036,0x00000009,0x0000000d,0x00000000,0x0000000a, - 0x00030037,0x00000008,0x0000000b,0x00030037,0x00000008,0x0000000c,0x000200f8,0x0000000e, - 0x0004003b,0x00000008,0x00000024,0x00000007,0x0004003b,0x0000002f,0x00000030,0x00000007, - 0x0004003b,0x0000001a,0x00000041,0x00000007,0x0004003d,0x00000007,0x00000025,0x0000000b, - 0x0004003d,0x00000007,0x00000026,0x0000000c,0x0005008e,0x00000007,0x00000028,0x00000026, - 0x00000027,0x0004003d,0x00000007,0x0000002b,0x0000000c,0x0005008e,0x00000007,0x0000002c, - 0x0000002b,0x00000027,0x00050083,0x00000007,0x0000002d,0x0000002a,0x0000002c,0x0008000c, - 0x00000007,0x0000002e,0x00000001,0x0000002b,0x00000025,0x00000028,0x0000002d,0x0003003e, - 0x00000024,0x0000002e,0x0004003d,0x00000032,0x00000035,0x00000034,0x0004003d,0x00000007, - 0x00000036,0x00000024,0x00070058,0x00000009,0x00000038,0x00000035,0x00000036,0x00000002, - 0x00000037,0x0003003e,0x00000030,0x00000038,0x00050041,0x0000001a,0x0000003b,0x00000024, - 0x0000003a,0x0004003d,0x00000006,0x0000003c,0x0000003b,0x00050041,0x0000001a,0x0000003d, - 0x0000000c,0x0000003a,0x0004003d,0x00000006,0x0000003e,0x0000003d,0x00050083,0x00000006, - 0x0000003f,0x00000029,0x0000003e,0x000500be,0x00000018,0x00000040,0x0000003c,0x0000003f, - 0x000300f7,0x00000043,0x00000000,0x000400fa,0x00000040,0x00000042,0x00000044,0x000200f8, - 0x00000042,0x0003003e,0x00000041,0x00000037,0x000200f9,0x00000043,0x000200f8,0x00000044, - 0x00050041,0x0000001a,0x00000046,0x00000030,0x00000045,0x0004003d,0x00000006,0x00000047, - 0x00000046,0x0003003e,0x00000041,0x00000047,0x000200f9,0x00000043,0x000200f8,0x00000043, - 0x0004003d,0x00000006,0x00000048,0x00000041,0x00050041,0x0000001a,0x00000049,0x00000030, - 0x00000045,0x0003003e,0x00000049,0x00000048,0x0004003d,0x00000009,0x0000004a,0x00000030, - 0x000200fe,0x0000004a,0x00010038,0x00050036,0x00000006,0x00000012,0x00000000,0x0000000f, - 0x00030037,0x00000008,0x00000010,0x00030037,0x00000008,0x00000011,0x000200f8,0x00000013, - 0x0004003b,0x0000002f,0x0000004d,0x00000007,0x0004003b,0x00000008,0x0000004e,0x00000007, - 0x0004003b,0x00000008,0x00000050,0x00000007,0x0004003d,0x00000007,0x0000004f,0x00000010, - 0x0003003e,0x0000004e,0x0000004f,0x0004003d,0x00000007,0x00000051,0x00000011,0x0003003e, - 0x00000050,0x00000051,0x00060039,0x00000009,0x00000052,0x0000000d,0x0000004e,0x00000050, - 0x0003003e,0x0000004d,0x00000052,0x00050041,0x0000001a,0x00000054,0x0000004d,0x00000053, - 0x0004003d,0x00000006,0x00000055,0x00000054,0x00050041,0x0000001a,0x00000056,0x0000004d, - 0x0000003a,0x0004003d,0x00000006,0x00000057,0x00000056,0x0007000c,0x00000006,0x00000058, - 0x00000001,0x00000028,0x00000055,0x00000057,0x000200fe,0x00000058,0x00010038,0x00050036, - 0x00000006,0x00000016,0x00000000,0x0000000f,0x00030037,0x00000008,0x00000014,0x00030037, - 0x00000008,0x00000015,0x000200f8,0x00000017,0x0004003b,0x0000002f,0x0000005b,0x00000007, - 0x0004003b,0x00000008,0x0000005c,0x00000007,0x0004003b,0x00000008,0x0000005e,0x00000007, - 0x0004003d,0x00000007,0x0000005d,0x00000014,0x0003003e,0x0000005c,0x0000005d,0x0004003d, - 0x00000007,0x0000005f,0x00000015,0x0003003e,0x0000005e,0x0000005f,0x00060039,0x00000009, - 0x00000060,0x0000000d,0x0000005c,0x0000005e,0x0003003e,0x0000005b,0x00000060,0x00050041, - 0x0000001a,0x00000062,0x0000005b,0x00000061,0x0004003d,0x00000006,0x00000063,0x00000062, - 0x00050041,0x0000001a,0x00000064,0x0000005b,0x00000045,0x0004003d,0x00000006,0x00000065, - 0x00000064,0x0007000c,0x00000006,0x00000066,0x00000001,0x00000028,0x00000063,0x00000065, - 0x000200fe,0x00000066,0x00010038,0x00050036,0x00000006,0x00000022,0x00000000,0x0000001b, - 0x00030037,0x00000008,0x0000001c,0x00030037,0x00000008,0x0000001d,0x00030037,0x00000008, - 0x0000001e,0x00030037,0x00000019,0x0000001f,0x00030037,0x0000001a,0x00000020,0x00030037, - 0x00000019,0x00000021,0x000200f8,0x00000023,0x0004003b,0x0000001a,0x00000069,0x00000007, - 0x0004003b,0x0000006b,0x0000006c,0x00000007,0x0004003b,0x00000008,0x00000076,0x00000007, - 0x0004003b,0x00000082,0x00000083,0x00000007,0x0004003b,0x00000082,0x0000008e,0x00000007, - 0x0004003b,0x0000001a,0x000000a3,0x00000007,0x0004003b,0x0000001a,0x000000a5,0x00000007, - 0x0004003b,0x00000008,0x000000a8,0x00000007,0x0004003b,0x00000008,0x000000aa,0x00000007, - 0x0004003b,0x00000008,0x000000ae,0x00000007,0x0004003b,0x00000008,0x000000b0,0x00000007, - 0x0003003e,0x00000069,0x00000037,0x0003003e,0x0000006c,0x0000006d,0x000200f9,0x0000006e, - 0x000200f8,0x0000006e,0x000400f6,0x00000070,0x00000071,0x00000000,0x000200f9,0x00000072, - 0x000200f8,0x00000072,0x0004003d,0x0000006a,0x00000073,0x0000006c,0x000500b3,0x00000018, - 0x00000075,0x00000073,0x00000074,0x000400fa,0x00000075,0x0000006f,0x00000070,0x000200f8, - 0x0000006f,0x0004003d,0x00000007,0x00000077,0x0000001c,0x0004003d,0x00000007,0x00000078, - 0x0000001e,0x0004003d,0x0000006a,0x00000079,0x0000006c,0x0004006f,0x00000006,0x0000007a, - 0x00000079,0x0005008e,0x00000007,0x0000007b,0x00000078,0x0000007a,0x0004003d,0x00000018, - 0x0000007c,0x00000021,0x000600a9,0x00000006,0x0000007e,0x0000007c,0x00000029,0x0000007d, - 0x0005008e,0x00000007,0x0000007f,0x0000007b,0x0000007e,0x00050081,0x00000007,0x00000080, - 0x00000077,0x0000007f,0x0003003e,0x00000076,0x00000080,0x0004003d,0x00000007,0x00000084, - 0x00000076,0x00050041,0x00000088,0x00000089,0x00000087,0x0000006d,0x0004003d,0x00000007, - 0x0000008a,0x00000089,0x00050085,0x00000007,0x0000008b,0x00000084,0x0000008a,0x0006000c, - 0x00000007,0x0000008c,0x00000001,0x00000008,0x0000008b,0x0004006e,0x00000081,0x0000008d, - 0x0000008c,0x0003003e,0x00000083,0x0000008d,0x00050041,0x00000088,0x0000008f,0x00000087, - 0x0000006d,0x0004003d,0x00000007,0x00000090,0x0000008f,0x0004006e,0x00000081,0x00000091, - 0x00000090,0x0003003e,0x0000008e,0x00000091,0x0004003d,0x00000081,0x00000092,0x00000083, - 0x000500b1,0x00000095,0x00000096,0x00000092,0x00000094,0x0004009a,0x00000018,0x00000097, - 0x00000096,0x000400a8,0x00000018,0x00000098,0x00000097,0x000300f7,0x0000009a,0x00000000, - 0x000400fa,0x00000098,0x00000099,0x0000009a,0x000200f8,0x00000099,0x0004003d,0x00000081, - 0x0000009b,0x00000083,0x0004003d,0x00000081,0x0000009c,0x0000008e,0x000500af,0x00000095, - 0x0000009d,0x0000009b,0x0000009c,0x0004009a,0x00000018,0x0000009e,0x0000009d,0x000200f9, - 0x0000009a,0x000200f8,0x0000009a,0x000700f5,0x00000018,0x0000009f,0x00000097,0x0000006f, - 0x0000009e,0x00000099,0x000300f7,0x000000a1,0x00000000,0x000400fa,0x0000009f,0x000000a0, - 0x000000a1,0x000200f8,0x000000a0,0x000200f9,0x00000070,0x000200f8,0x000000a1,0x0004003d, - 0x00000018,0x000000a4,0x0000001f,0x000300f7,0x000000a7,0x00000000,0x000400fa,0x000000a4, - 0x000000a6,0x000000ad,0x000200f8,0x000000a6,0x0004003d,0x00000007,0x000000a9,0x00000076, - 0x0003003e,0x000000a8,0x000000a9,0x0004003d,0x00000007,0x000000ab,0x0000001d,0x0003003e, - 0x000000aa,0x000000ab,0x00060039,0x00000006,0x000000ac,0x00000012,0x000000a8,0x000000aa, - 0x0003003e,0x000000a5,0x000000ac,0x000200f9,0x000000a7,0x000200f8,0x000000ad,0x0004003d, - 0x00000007,0x000000af,0x00000076,0x0003003e,0x000000ae,0x000000af,0x0004003d,0x00000007, - 0x000000b1,0x0000001d,0x0003003e,0x000000b0,0x000000b1,0x00060039,0x00000006,0x000000b2, - 0x00000016,0x000000ae,0x000000b0,0x0003003e,0x000000a5,0x000000b2,0x000200f9,0x000000a7, - 0x000200f8,0x000000a7,0x0004003d,0x00000006,0x000000b3,0x000000a5,0x0003003e,0x000000a3, - 0x000000b3,0x0004003d,0x00000006,0x000000b4,0x000000a3,0x0004003d,0x00000006,0x000000b5, - 0x00000020,0x00050085,0x00000006,0x000000b7,0x000000b5,0x000000b6,0x000500bc,0x00000018, - 0x000000b8,0x000000b4,0x000000b7,0x000300f7,0x000000ba,0x00000000,0x000400fa,0x000000b8, - 0x000000b9,0x000000ba,0x000200f8,0x000000b9,0x000200f9,0x00000070,0x000200f8,0x000000ba, - 0x0004003d,0x0000006a,0x000000bc,0x0000006c,0x0004006f,0x00000006,0x000000bd,0x000000bc, - 0x0003003e,0x00000069,0x000000bd,0x000200f9,0x00000071,0x000200f8,0x00000071,0x0004003d, - 0x0000006a,0x000000be,0x0000006c,0x00050080,0x0000006a,0x000000bf,0x000000be,0x0000006d, - 0x0003003e,0x0000006c,0x000000bf,0x000200f9,0x0000006e,0x000200f8,0x00000070,0x0004003d, - 0x00000006,0x000000c0,0x00000069,0x000200fe,0x000000c0,0x00010038, + 0x0007000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x000004e7,0x000004f2,0x00030010, + 0x00000004,0x00000007,0x00030003,0x00000002,0x000001c2,0x000a0004,0x475f4c47,0x4c474f4f, + 0x70635f45,0x74735f70,0x5f656c79,0x656e696c,0x7269645f,0x69746365,0x00006576,0x00080004, + 0x475f4c47,0x4c474f4f,0x6e695f45,0x64756c63,0x69645f65,0x74636572,0x00657669,0x00040005, + 0x00000004,0x6e69616d,0x00000000,0x00080005,0x00000010,0x41414d53,0x63766f4d,0x32627628, + 0x3266763b,0x3266763b,0x0000003b,0x00040005,0x0000000d,0x646e6f63,0x00000000,0x00050005, + 0x0000000e,0x69726176,0x656c6261,0x00000000,0x00040005,0x0000000f,0x756c6176,0x00000065, + 0x000e0005,0x0000001b,0x41414d53,0x6e656c42,0x676e6964,0x67696557,0x61437468,0x6c75636c, + 0x6f697461,0x2853566e,0x3b326676,0x3b326676,0x5b346676,0x003b5d33,0x00050005,0x00000018, + 0x63786574,0x64726f6f,0x00000000,0x00050005,0x00000019,0x63786970,0x64726f6f,0x00000000, + 0x00040005,0x0000001a,0x7366666f,0x00007465,0x000b0005,0x0000001f,0x41414d53,0x6f636544, + 0x69446564,0x69426761,0x656e696c,0x63417261,0x73736563,0x32667628,0x0000003b,0x00030005, + 0x0000001e,0x00000065,0x000b0005,0x00000024,0x41414d53,0x6f636544,0x69446564,0x69426761, + 0x656e696c,0x63417261,0x73736563,0x34667628,0x0000003b,0x00030005,0x00000023,0x00000065, + 0x000b0005,0x0000002e,0x41414d53,0x72616553,0x69446863,0x28316761,0x3b313273,0x3b326676, + 0x3b326676,0x3b326676,0x00000000,0x00050005,0x0000002a,0x65676465,0x78655473,0x00000000, + 0x00050005,0x0000002b,0x63786574,0x64726f6f,0x00000000,0x00030005,0x0000002c,0x00726964, + 0x00030005,0x0000002d,0x00000065,0x000b0005,0x00000034,0x41414d53,0x72616553,0x69446863, + 0x28326761,0x3b313273,0x3b326676,0x3b326676,0x3b326676,0x00000000,0x00050005,0x00000030, + 0x65676465,0x78655473,0x00000000,0x00050005,0x00000031,0x63786574,0x64726f6f,0x00000000, + 0x00030005,0x00000032,0x00726964,0x00030005,0x00000033,0x00000065,0x000a0005,0x0000003c, + 0x41414d53,0x61657241,0x67616944,0x31327328,0x3266763b,0x3266763b,0x3b31663b,0x00000000, + 0x00040005,0x00000038,0x61657261,0x00786554,0x00040005,0x00000039,0x74736964,0x00000000, + 0x00030005,0x0000003a,0x00000065,0x00040005,0x0000003b,0x7366666f,0x00007465,0x000e0005, + 0x00000044,0x41414d53,0x636c6143,0x74616c75,0x61694465,0x69655767,0x73746867,0x31327328, + 0x3132733b,0x3266763b,0x3266763b,0x3466763b,0x0000003b,0x00050005,0x0000003f,0x65676465, + 0x78655473,0x00000000,0x00040005,0x00000040,0x61657261,0x00786554,0x00050005,0x00000041, + 0x63786574,0x64726f6f,0x00000000,0x00030005,0x00000042,0x00000065,0x00070005,0x00000043, + 0x73627573,0x6c706d61,0x646e4965,0x73656369,0x00000000,0x000a0005,0x0000004a,0x41414d53, + 0x72616553,0x654c6863,0x6874676e,0x31327328,0x3266763b,0x3b31663b,0x00000000,0x00050005, + 0x00000047,0x72616573,0x65546863,0x00000078,0x00030005,0x00000048,0x00000065,0x00040005, + 0x00000049,0x7366666f,0x00007465,0x000a0005,0x00000051,0x41414d53,0x72616553,0x4c586863, + 0x28746665,0x3b313273,0x3b313273,0x3b326676,0x003b3166,0x00050005,0x0000004d,0x65676465, + 0x78655473,0x00000000,0x00050005,0x0000004e,0x72616573,0x65546863,0x00000078,0x00050005, + 0x0000004f,0x63786574,0x64726f6f,0x00000000,0x00030005,0x00000050,0x00646e65,0x000b0005, + 0x00000057,0x41414d53,0x72616553,0x52586863,0x74686769,0x31327328,0x3132733b,0x3266763b, + 0x3b31663b,0x00000000,0x00050005,0x00000053,0x65676465,0x78655473,0x00000000,0x00050005, + 0x00000054,0x72616573,0x65546863,0x00000078,0x00050005,0x00000055,0x63786574,0x64726f6f, + 0x00000000,0x00030005,0x00000056,0x00646e65,0x000a0005,0x0000005d,0x41414d53,0x72616553, + 0x55596863,0x32732870,0x32733b31,0x66763b31,0x31663b32,0x0000003b,0x00050005,0x00000059, + 0x65676465,0x78655473,0x00000000,0x00050005,0x0000005a,0x72616573,0x65546863,0x00000078, + 0x00050005,0x0000005b,0x63786574,0x64726f6f,0x00000000,0x00030005,0x0000005c,0x00646e65, + 0x000a0005,0x00000063,0x41414d53,0x72616553,0x44596863,0x286e776f,0x3b313273,0x3b313273, + 0x3b326676,0x003b3166,0x00050005,0x0000005f,0x65676465,0x78655473,0x00000000,0x00050005, + 0x00000060,0x72616573,0x65546863,0x00000078,0x00050005,0x00000061,0x63786574,0x64726f6f, + 0x00000000,0x00030005,0x00000062,0x00646e65,0x00090005,0x0000006b,0x41414d53,0x61657241, + 0x31327328,0x3266763b,0x3b31663b,0x663b3166,0x00003b31,0x00040005,0x00000066,0x61657261, + 0x00786554,0x00040005,0x00000067,0x74736964,0x00000000,0x00030005,0x00000068,0x00003165, + 0x00030005,0x00000069,0x00003265,0x00040005,0x0000006a,0x7366666f,0x00007465,0x000f0005, + 0x00000072,0x41414d53,0x65746544,0x6f487463,0x6f7a6972,0x6c61746e,0x6e726f43,0x61507265, + 0x72657474,0x3273286e,0x66763b31,0x66763b32,0x66763b34,0x00003b32,0x00050005,0x0000006e, + 0x65676465,0x78655473,0x00000000,0x00040005,0x0000006f,0x67696577,0x00737468,0x00050005, + 0x00000070,0x63786574,0x64726f6f,0x00000000,0x00030005,0x00000071,0x00000064,0x000f0005, + 0x00000078,0x41414d53,0x65746544,0x65567463,0x63697472,0x6f436c61,0x72656e72,0x74746150, + 0x286e7265,0x3b313273,0x3b326676,0x3b346676,0x3b326676,0x00000000,0x00050005,0x00000074, + 0x65676465,0x78655473,0x00000000,0x00040005,0x00000075,0x67696577,0x00737468,0x00050005, + 0x00000076,0x63786574,0x64726f6f,0x00000000,0x00030005,0x00000077,0x00000064,0x00120005, + 0x00000082,0x41414d53,0x6e656c42,0x676e6964,0x67696557,0x61437468,0x6c75636c,0x6f697461, + 0x2853506e,0x3b326676,0x3b326676,0x5b346676,0x733b5d33,0x733b3132,0x733b3132,0x763b3132, + 0x003b3466,0x00050005,0x0000007b,0x63786574,0x64726f6f,0x00000000,0x00050005,0x0000007c, + 0x63786970,0x64726f6f,0x00000000,0x00040005,0x0000007d,0x7366666f,0x00007465,0x00050005, + 0x0000007e,0x65676465,0x78655473,0x00000000,0x00040005,0x0000007f,0x61657261,0x00786554, + 0x00050005,0x00000080,0x72616573,0x65546863,0x00000078,0x00070005,0x00000081,0x73627573, + 0x6c706d61,0x646e4965,0x73656369,0x00000000,0x00050005,0x00000096,0x736e6f43,0x746e6174, + 0x00000073,0x00040006,0x00000096,0x00000000,0x0063646e,0x00050006,0x00000096,0x00000001, + 0x7274656d,0x00736369,0x00030005,0x00000098,0x00006370,0x00040005,0x000000e9,0x726f6f63, + 0x00000064,0x00030005,0x000000f2,0x00000074,0x00040005,0x00000126,0x726f6f63,0x00000064, + 0x00030005,0x00000134,0x00000074,0x00040005,0x0000015c,0x61726170,0x0000006d,0x00050005, + 0x00000166,0x63786574,0x64726f6f,0x00000000,0x00040005,0x00000185,0x67696577,0x00737468, + 0x00030005,0x0000018c,0x00000064,0x00030005,0x0000018e,0x00646e65,0x00040005,0x0000018f, + 0x61726170,0x0000006d,0x00040005,0x00000191,0x61726170,0x0000006d,0x00040005,0x00000192, + 0x61726170,0x0000006d,0x00040005,0x000001a7,0x61726170,0x0000006d,0x00040005,0x000001a9, + 0x61726170,0x0000006d,0x00040005,0x000001aa,0x61726170,0x0000006d,0x00040005,0x000001ba, + 0x726f6f63,0x00007364,0x00030005,0x000001ce,0x00000063,0x00040005,0x000001e5,0x61726170, + 0x0000006d,0x00030005,0x000001ea,0x00006363,0x00040005,0x000001f6,0x61726170,0x0000006d, + 0x00040005,0x000001f7,0x61726170,0x0000006d,0x00040005,0x000001f9,0x61726170,0x0000006d, + 0x00040005,0x000001fc,0x61726170,0x0000006d,0x00040005,0x000001ff,0x61726170,0x0000006d, + 0x00040005,0x00000201,0x61726170,0x0000006d,0x00040005,0x00000208,0x61726170,0x0000006d, + 0x00040005,0x0000020a,0x61726170,0x0000006d,0x00040005,0x0000020b,0x61726170,0x0000006d, + 0x00040005,0x0000021a,0x61726170,0x0000006d,0x00040005,0x0000021c,0x61726170,0x0000006d, + 0x00040005,0x0000021d,0x61726170,0x0000006d,0x00040005,0x00000239,0x726f6f63,0x00007364, + 0x00030005,0x0000024b,0x00000063,0x00030005,0x00000262,0x00006363,0x00040005,0x0000026d, + 0x61726170,0x0000006d,0x00040005,0x0000026e,0x61726170,0x0000006d,0x00040005,0x00000270, + 0x61726170,0x0000006d,0x00040005,0x00000273,0x61726170,0x0000006d,0x00040005,0x00000276, + 0x61726170,0x0000006d,0x00040005,0x00000278,0x61726170,0x0000006d,0x00040005,0x00000282, + 0x6c616373,0x00000065,0x00040005,0x00000286,0x73616962,0x00000000,0x00030005,0x000002a2, + 0x00000065,0x00040005,0x000002c6,0x7366666f,0x00007465,0x00040005,0x000002c8,0x61726170, + 0x0000006d,0x00040005,0x000002ca,0x61726170,0x0000006d,0x00030005,0x000002d6,0x00000065, + 0x00040005,0x000002f6,0x7366666f,0x00007465,0x00040005,0x000002f7,0x61726170,0x0000006d, + 0x00040005,0x000002f9,0x61726170,0x0000006d,0x00030005,0x00000305,0x00000065,0x00040005, + 0x00000326,0x7366666f,0x00007465,0x00040005,0x00000327,0x61726170,0x0000006d,0x00040005, + 0x0000032a,0x61726170,0x0000006d,0x00030005,0x00000335,0x00000065,0x00040005,0x00000355, + 0x7366666f,0x00007465,0x00040005,0x00000356,0x61726170,0x0000006d,0x00040005,0x00000359, + 0x61726170,0x0000006d,0x00050005,0x00000365,0x63786574,0x64726f6f,0x00000000,0x00050005, + 0x0000037d,0x7466656c,0x68676952,0x00000074,0x00050005,0x00000382,0x6e756f72,0x676e6964, + 0x00000000,0x00040005,0x0000038e,0x74636166,0x0000726f,0x00050005,0x000003ca,0x7466656c, + 0x68676952,0x00000074,0x00050005,0x000003cf,0x6e756f72,0x676e6964,0x00000000,0x00040005, + 0x000003da,0x74636166,0x0000726f,0x00040005,0x00000413,0x67696577,0x00737468,0x00030005, + 0x00000415,0x00000065,0x00040005,0x0000041f,0x61726170,0x0000006d,0x00040005,0x00000421, + 0x61726170,0x0000006d,0x00040005,0x00000423,0x61726170,0x0000006d,0x00040005,0x00000432, + 0x726f6f63,0x00007364,0x00040005,0x00000433,0x61726170,0x0000006d,0x00040005,0x00000437, + 0x61726170,0x0000006d,0x00030005,0x0000043f,0x00000064,0x00030005,0x00000443,0x00003165, + 0x00040005,0x00000449,0x61726170,0x0000006d,0x00040005,0x0000044d,0x61726170,0x0000006d, + 0x00040005,0x0000045f,0x74727173,0x0000645f,0x00030005,0x00000462,0x00003265,0x00040005, + 0x00000468,0x61726170,0x0000006d,0x00040005,0x0000046a,0x61726170,0x0000006d,0x00040005, + 0x0000046c,0x61726170,0x0000006d,0x00040005,0x0000046e,0x61726170,0x0000006d,0x00040005, + 0x00000479,0x61726170,0x0000006d,0x00040005,0x0000047c,0x61726170,0x0000006d,0x00040005, + 0x0000047f,0x61726170,0x0000006d,0x00040005,0x0000048e,0x726f6f63,0x00007364,0x00040005, + 0x0000048f,0x61726170,0x0000006d,0x00040005,0x00000493,0x61726170,0x0000006d,0x00030005, + 0x0000049b,0x00000064,0x00030005,0x0000049f,0x00003165,0x00040005,0x000004a5,0x61726170, + 0x0000006d,0x00040005,0x000004a9,0x61726170,0x0000006d,0x00040005,0x000004bb,0x74727173, + 0x0000645f,0x00030005,0x000004be,0x00003265,0x00040005,0x000004c4,0x61726170,0x0000006d, + 0x00040005,0x000004c6,0x61726170,0x0000006d,0x00040005,0x000004c8,0x61726170,0x0000006d, + 0x00040005,0x000004ca,0x61726170,0x0000006d,0x00040005,0x000004d5,0x61726170,0x0000006d, + 0x00040005,0x000004d8,0x61726170,0x0000006d,0x00040005,0x000004db,0x61726170,0x0000006d, + 0x00060005,0x000004e7,0x67617266,0x43786554,0x64726f6f,0x00000000,0x00050005,0x000004e8, + 0x63786970,0x64726f6f,0x00000000,0x00040005,0x000004e9,0x7366666f,0x00007465,0x00040005, + 0x000004ea,0x61726170,0x0000006d,0x00040005,0x000004ec,0x61726170,0x0000006d,0x00040005, + 0x000004ed,0x61726170,0x0000006d,0x00050005,0x000004f2,0x4374756f,0x726f6c6f,0x00000000, + 0x00050005,0x000004f3,0x65676445,0x74786554,0x00657275,0x00050005,0x000004f4,0x61657241, + 0x74786554,0x00657275,0x00060005,0x000004f5,0x72616553,0x65546863,0x72757478,0x00000065, + 0x00040005,0x000004f6,0x61726170,0x0000006d,0x00040005,0x000004f8,0x61726170,0x0000006d, + 0x00040005,0x000004fa,0x61726170,0x0000006d,0x00040005,0x000004fc,0x61726170,0x0000006d, + 0x00030047,0x00000096,0x00000002,0x00050048,0x00000096,0x00000000,0x00000023,0x00000000, + 0x00050048,0x00000096,0x00000001,0x00000023,0x00000010,0x00040047,0x000004e7,0x0000001e, + 0x00000000,0x00040047,0x000004f2,0x0000001e,0x00000000,0x00040047,0x000004f3,0x00000021, + 0x00000000,0x00040047,0x000004f3,0x00000022,0x00000000,0x00040047,0x000004f4,0x00000021, + 0x00000000,0x00040047,0x000004f4,0x00000022,0x00000001,0x00040047,0x000004f5,0x00000021, + 0x00000000,0x00040047,0x000004f5,0x00000022,0x00000002,0x00020013,0x00000002,0x00030021, + 0x00000003,0x00000002,0x00020014,0x00000006,0x00040017,0x00000007,0x00000006,0x00000002, + 0x00040020,0x00000008,0x00000007,0x00000007,0x00030016,0x00000009,0x00000020,0x00040017, + 0x0000000a,0x00000009,0x00000002,0x00040020,0x0000000b,0x00000007,0x0000000a,0x00060021, + 0x0000000c,0x00000002,0x00000008,0x0000000b,0x0000000b,0x00040017,0x00000012,0x00000009, + 0x00000004,0x00040015,0x00000013,0x00000020,0x00000000,0x0004002b,0x00000013,0x00000014, + 0x00000003,0x0004001c,0x00000015,0x00000012,0x00000014,0x00040020,0x00000016,0x00000007, + 0x00000015,0x00060021,0x00000017,0x00000002,0x0000000b,0x0000000b,0x00000016,0x00040021, + 0x0000001d,0x0000000a,0x0000000b,0x00040020,0x00000021,0x00000007,0x00000012,0x00040021, + 0x00000022,0x00000012,0x00000021,0x00090019,0x00000026,0x00000009,0x00000001,0x00000000, + 0x00000000,0x00000000,0x00000001,0x00000000,0x0003001b,0x00000027,0x00000026,0x00040020, + 0x00000028,0x00000000,0x00000027,0x00070021,0x00000029,0x0000000a,0x00000028,0x0000000b, + 0x0000000b,0x0000000b,0x00040020,0x00000036,0x00000007,0x00000009,0x00070021,0x00000037, + 0x0000000a,0x00000028,0x0000000b,0x0000000b,0x00000036,0x00080021,0x0000003e,0x0000000a, + 0x00000028,0x00000028,0x0000000b,0x0000000b,0x00000021,0x00060021,0x00000046,0x00000009, + 0x00000028,0x0000000b,0x00000036,0x00070021,0x0000004c,0x00000009,0x00000028,0x00000028, + 0x0000000b,0x00000036,0x00080021,0x00000065,0x0000000a,0x00000028,0x0000000b,0x00000036, + 0x00000036,0x00000036,0x00070021,0x0000006d,0x00000002,0x00000028,0x0000000b,0x00000021, + 0x0000000b,0x000a0021,0x0000007a,0x00000012,0x0000000b,0x0000000b,0x00000016,0x00000028, + 0x00000028,0x00000028,0x00000021,0x0004002b,0x00000013,0x00000084,0x00000000,0x00040020, + 0x00000085,0x00000007,0x00000006,0x0004002b,0x00000013,0x0000008d,0x00000001,0x0004001e, + 0x00000096,0x00000012,0x00000012,0x00040020,0x00000097,0x00000009,0x00000096,0x0004003b, + 0x00000097,0x00000098,0x00000009,0x00040015,0x00000099,0x00000020,0x00000001,0x0004002b, + 0x00000099,0x0000009a,0x00000001,0x00040020,0x0000009b,0x00000009,0x00000012,0x0004002b, + 0x00000099,0x000000a0,0x00000000,0x0004002b,0x00000009,0x000000a4,0xbe800000,0x0004002b, + 0x00000009,0x000000a5,0xbe000000,0x0004002b,0x00000009,0x000000a6,0x3fa00000,0x0007002c, + 0x00000012,0x000000a7,0x000000a4,0x000000a5,0x000000a6,0x000000a5,0x0007002c,0x00000012, + 0x000000af,0x000000a5,0x000000a4,0x000000a5,0x000000a6,0x0004002b,0x00000099,0x000000b4, + 0x00000002,0x0004002b,0x00000009,0x000000b8,0xc2000000,0x0004002b,0x00000009,0x000000b9, + 0x42000000,0x0007002c,0x00000012,0x000000ba,0x000000b8,0x000000b9,0x000000b8,0x000000b9, + 0x0004002b,0x00000009,0x000000ca,0x40a00000,0x0004002b,0x00000009,0x000000ce,0x40700000, + 0x0004002b,0x00000013,0x000000e2,0x00000002,0x0004002b,0x00000009,0x000000eb,0xbf800000, + 0x0004002b,0x00000009,0x000000ec,0x3f800000,0x00040017,0x000000f0,0x00000009,0x00000003, + 0x00040020,0x000000f1,0x00000007,0x000000f0,0x0004002b,0x00000009,0x00000100,0x40e00000, + 0x0004002b,0x00000009,0x00000106,0x3f666666,0x0004002b,0x00000009,0x0000011a,0x00000000, + 0x0004002b,0x00000009,0x0000011e,0x3f000000,0x0005002c,0x0000000a,0x0000011f,0x0000011e, + 0x0000011e,0x0004002b,0x00000009,0x0000012b,0x3e800000,0x00040020,0x0000012c,0x00000009, + 0x00000009,0x0004002b,0x00000009,0x00000167,0x41a00000,0x0005002c,0x0000000a,0x00000168, + 0x00000167,0x00000167,0x0004002b,0x00000009,0x0000016c,0x3bcccccd,0x0004002b,0x00000009, + 0x0000016d,0x3aea0ea1,0x0005002c,0x0000000a,0x0000016e,0x0000016c,0x0000016d,0x0004002b, + 0x00000009,0x00000170,0x3b4ccccd,0x0004002b,0x00000009,0x00000171,0x3a6a0ea1,0x0005002c, + 0x0000000a,0x00000172,0x00000170,0x00000171,0x0004002b,0x00000009,0x00000178,0x3e124925, + 0x0005002c,0x0000000a,0x00000186,0x0000011a,0x0000011a,0x0005002c,0x0000000a,0x0000018d, + 0x000000eb,0x000000ec,0x0005002c,0x0000000a,0x000001a6,0x000000ec,0x000000eb,0x0004002b, + 0x00000009,0x000001b6,0x40000000,0x00040017,0x000001d2,0x00000099,0x00000002,0x0004002b, + 0x00000099,0x000001d3,0xffffffff,0x0005002c,0x000001d2,0x000001d4,0x000001d3,0x000000a0, + 0x0005002c,0x000001d2,0x000001de,0x0000009a,0x000000a0,0x0005002c,0x0000000a,0x000001eb, + 0x000001b6,0x000001b6,0x0005002c,0x0000000a,0x00000207,0x000000eb,0x000000eb,0x0005002c, + 0x0000000a,0x00000219,0x000000ec,0x000000ec,0x0005002c,0x000001d2,0x00000255,0x000000a0, + 0x000001d3,0x0004002b,0x00000009,0x00000283,0x42040000,0x0004002b,0x00000009,0x00000284, + 0xc2040000,0x0005002c,0x0000000a,0x00000285,0x00000283,0x00000284,0x0004002b,0x00000009, + 0x00000287,0x42840000,0x0005002c,0x0000000a,0x00000288,0x00000287,0x00000283,0x0004002b, + 0x00000009,0x0000028e,0xbf000000,0x0005002c,0x0000000a,0x0000028f,0x0000011e,0x0000028e, + 0x0004002b,0x00000009,0x00000292,0x3c800000,0x0004002b,0x00000009,0x00000293,0x3d800000, + 0x0005002c,0x0000000a,0x00000294,0x00000292,0x00000293,0x0005002c,0x0000000a,0x000002a3, + 0x0000011a,0x000000ec,0x0004002b,0x00000009,0x000002b1,0x3f53fe5d,0x0004002b,0x00000009, + 0x000002be,0xc0000000,0x0004002b,0x00000009,0x000002bf,0x80000000,0x0005002c,0x0000000a, + 0x000002c0,0x000002be,0x000002bf,0x0004002b,0x00000009,0x000002c7,0xc0008102,0x0004002b, + 0x00000009,0x000002cc,0x40500000,0x0005002c,0x0000000a,0x000002f0,0x000001b6,0x0000011a, + 0x0005002c,0x0000000a,0x00000306,0x000000ec,0x0000011a,0x0005002c,0x0000000a,0x00000320, + 0x000002bf,0x000002be,0x0005002c,0x0000000a,0x0000034f,0x0000011a,0x000001b6,0x0004002b, + 0x00000009,0x00000366,0x41800000,0x0005002c,0x0000000a,0x00000367,0x00000366,0x00000366, + 0x0004002b,0x00000009,0x00000368,0x40800000,0x0004002b,0x00000009,0x00000383,0x3f400000, + 0x0005002c,0x000001d2,0x00000394,0x000000a0,0x0000009a,0x0005002c,0x000001d2,0x000003a1, + 0x0000009a,0x0000009a,0x0004002b,0x00000099,0x000003ae,0xfffffffe,0x0005002c,0x000001d2, + 0x000003af,0x000000a0,0x000003ae,0x0005002c,0x000001d2,0x000003bc,0x0000009a,0x000003ae, + 0x0005002c,0x000001d2,0x000003f8,0x000003ae,0x000000a0,0x0005002c,0x000001d2,0x00000405, + 0x000003ae,0x0000009a,0x0007002c,0x00000012,0x00000414,0x0000011a,0x0000011a,0x0000011a, + 0x0000011a,0x00040020,0x000004e6,0x00000001,0x0000000a,0x0004003b,0x000004e6,0x000004e7, + 0x00000001,0x00040020,0x000004f1,0x00000003,0x00000012,0x0004003b,0x000004f1,0x000004f2, + 0x00000003,0x0004003b,0x00000028,0x000004f3,0x00000000,0x0004003b,0x00000028,0x000004f4, + 0x00000000,0x0004003b,0x00000028,0x000004f5,0x00000000,0x00050036,0x00000002,0x00000004, + 0x00000000,0x00000003,0x000200f8,0x00000005,0x0004003b,0x0000000b,0x000004e8,0x00000007, + 0x0004003b,0x00000016,0x000004e9,0x00000007,0x0004003b,0x0000000b,0x000004ea,0x00000007, + 0x0004003b,0x0000000b,0x000004ec,0x00000007,0x0004003b,0x00000016,0x000004ed,0x00000007, + 0x0004003b,0x0000000b,0x000004f6,0x00000007,0x0004003b,0x0000000b,0x000004f8,0x00000007, + 0x0004003b,0x00000016,0x000004fa,0x00000007,0x0004003b,0x00000021,0x000004fc,0x00000007, + 0x0004003d,0x0000000a,0x000004eb,0x000004e7,0x0003003e,0x000004ea,0x000004eb,0x00070039, + 0x00000002,0x000004ee,0x0000001b,0x000004ea,0x000004ec,0x000004ed,0x0004003d,0x0000000a, + 0x000004ef,0x000004ec,0x0003003e,0x000004e8,0x000004ef,0x0004003d,0x00000015,0x000004f0, + 0x000004ed,0x0003003e,0x000004e9,0x000004f0,0x0004003d,0x0000000a,0x000004f7,0x000004e7, + 0x0003003e,0x000004f6,0x000004f7,0x0004003d,0x0000000a,0x000004f9,0x000004e8,0x0003003e, + 0x000004f8,0x000004f9,0x0004003d,0x00000015,0x000004fb,0x000004e9,0x0003003e,0x000004fa, + 0x000004fb,0x0003003e,0x000004fc,0x00000414,0x000b0039,0x00000012,0x000004fd,0x00000082, + 0x000004f6,0x000004f8,0x000004fa,0x000004f3,0x000004f4,0x000004f5,0x000004fc,0x0003003e, + 0x000004f2,0x000004fd,0x000100fd,0x00010038,0x00050036,0x00000002,0x00000010,0x00000000, + 0x0000000c,0x00030037,0x00000008,0x0000000d,0x00030037,0x0000000b,0x0000000e,0x00030037, + 0x0000000b,0x0000000f,0x000200f8,0x00000011,0x00050041,0x00000085,0x00000086,0x0000000d, + 0x00000084,0x0004003d,0x00000006,0x00000087,0x00000086,0x000300f7,0x00000089,0x00000000, + 0x000400fa,0x00000087,0x00000088,0x00000089,0x000200f8,0x00000088,0x00050041,0x00000036, + 0x0000008a,0x0000000f,0x00000084,0x0004003d,0x00000009,0x0000008b,0x0000008a,0x00050041, + 0x00000036,0x0000008c,0x0000000e,0x00000084,0x0003003e,0x0000008c,0x0000008b,0x000200f9, + 0x00000089,0x000200f8,0x00000089,0x00050041,0x00000085,0x0000008e,0x0000000d,0x0000008d, + 0x0004003d,0x00000006,0x0000008f,0x0000008e,0x000300f7,0x00000091,0x00000000,0x000400fa, + 0x0000008f,0x00000090,0x00000091,0x000200f8,0x00000090,0x00050041,0x00000036,0x00000092, + 0x0000000f,0x0000008d,0x0004003d,0x00000009,0x00000093,0x00000092,0x00050041,0x00000036, + 0x00000094,0x0000000e,0x0000008d,0x0003003e,0x00000094,0x00000093,0x000200f9,0x00000091, + 0x000200f8,0x00000091,0x000100fd,0x00010038,0x00050036,0x00000002,0x0000001b,0x00000000, + 0x00000017,0x00030037,0x0000000b,0x00000018,0x00030037,0x0000000b,0x00000019,0x00030037, + 0x00000016,0x0000001a,0x000200f8,0x0000001c,0x0004003d,0x0000000a,0x00000095,0x00000018, + 0x00050041,0x0000009b,0x0000009c,0x00000098,0x0000009a,0x0004003d,0x00000012,0x0000009d, + 0x0000009c,0x0007004f,0x0000000a,0x0000009e,0x0000009d,0x0000009d,0x00000002,0x00000003, + 0x00050085,0x0000000a,0x0000009f,0x00000095,0x0000009e,0x0003003e,0x00000019,0x0000009f, + 0x00050041,0x0000009b,0x000000a1,0x00000098,0x0000009a,0x0004003d,0x00000012,0x000000a2, + 0x000000a1,0x0009004f,0x00000012,0x000000a3,0x000000a2,0x000000a2,0x00000000,0x00000001, + 0x00000000,0x00000001,0x0004003d,0x0000000a,0x000000a8,0x00000018,0x0009004f,0x00000012, + 0x000000a9,0x000000a8,0x000000a8,0x00000000,0x00000001,0x00000000,0x00000001,0x0008000c, + 0x00000012,0x000000aa,0x00000001,0x00000032,0x000000a3,0x000000a7,0x000000a9,0x00050041, + 0x00000021,0x000000ab,0x0000001a,0x000000a0,0x0003003e,0x000000ab,0x000000aa,0x00050041, + 0x0000009b,0x000000ac,0x00000098,0x0000009a,0x0004003d,0x00000012,0x000000ad,0x000000ac, + 0x0009004f,0x00000012,0x000000ae,0x000000ad,0x000000ad,0x00000000,0x00000001,0x00000000, + 0x00000001,0x0004003d,0x0000000a,0x000000b0,0x00000018,0x0009004f,0x00000012,0x000000b1, + 0x000000b0,0x000000b0,0x00000000,0x00000001,0x00000000,0x00000001,0x0008000c,0x00000012, + 0x000000b2,0x00000001,0x00000032,0x000000ae,0x000000af,0x000000b1,0x00050041,0x00000021, + 0x000000b3,0x0000001a,0x0000009a,0x0003003e,0x000000b3,0x000000b2,0x00050041,0x0000009b, + 0x000000b5,0x00000098,0x0000009a,0x0004003d,0x00000012,0x000000b6,0x000000b5,0x0009004f, + 0x00000012,0x000000b7,0x000000b6,0x000000b6,0x00000000,0x00000000,0x00000001,0x00000001, + 0x00050041,0x00000021,0x000000bb,0x0000001a,0x000000a0,0x0004003d,0x00000012,0x000000bc, + 0x000000bb,0x0007004f,0x0000000a,0x000000bd,0x000000bc,0x000000bc,0x00000000,0x00000002, + 0x00050041,0x00000021,0x000000be,0x0000001a,0x0000009a,0x0004003d,0x00000012,0x000000bf, + 0x000000be,0x0007004f,0x0000000a,0x000000c0,0x000000bf,0x000000bf,0x00000001,0x00000003, + 0x00050051,0x00000009,0x000000c1,0x000000bd,0x00000000,0x00050051,0x00000009,0x000000c2, + 0x000000bd,0x00000001,0x00050051,0x00000009,0x000000c3,0x000000c0,0x00000000,0x00050051, + 0x00000009,0x000000c4,0x000000c0,0x00000001,0x00070050,0x00000012,0x000000c5,0x000000c1, + 0x000000c2,0x000000c3,0x000000c4,0x0008000c,0x00000012,0x000000c6,0x00000001,0x00000032, + 0x000000b7,0x000000ba,0x000000c5,0x00050041,0x00000021,0x000000c7,0x0000001a,0x000000b4, + 0x0003003e,0x000000c7,0x000000c6,0x000100fd,0x00010038,0x00050036,0x0000000a,0x0000001f, + 0x00000000,0x0000001d,0x00030037,0x0000000b,0x0000001e,0x000200f8,0x00000020,0x00050041, + 0x00000036,0x000000c8,0x0000001e,0x00000084,0x0004003d,0x00000009,0x000000c9,0x000000c8, + 0x00050041,0x00000036,0x000000cb,0x0000001e,0x00000084,0x0004003d,0x00000009,0x000000cc, + 0x000000cb,0x00050085,0x00000009,0x000000cd,0x000000ca,0x000000cc,0x00050083,0x00000009, + 0x000000cf,0x000000cd,0x000000ce,0x0006000c,0x00000009,0x000000d0,0x00000001,0x00000004, + 0x000000cf,0x00050085,0x00000009,0x000000d1,0x000000c9,0x000000d0,0x00050041,0x00000036, + 0x000000d2,0x0000001e,0x00000084,0x0003003e,0x000000d2,0x000000d1,0x0004003d,0x0000000a, + 0x000000d3,0x0000001e,0x0006000c,0x0000000a,0x000000d4,0x00000001,0x00000001,0x000000d3, + 0x000200fe,0x000000d4,0x00010038,0x00050036,0x00000012,0x00000024,0x00000000,0x00000022, + 0x00030037,0x00000021,0x00000023,0x000200f8,0x00000025,0x0004003d,0x00000012,0x000000d7, + 0x00000023,0x0007004f,0x0000000a,0x000000d8,0x000000d7,0x000000d7,0x00000000,0x00000002, + 0x0004003d,0x00000012,0x000000d9,0x00000023,0x0007004f,0x0000000a,0x000000da,0x000000d9, + 0x000000d9,0x00000000,0x00000002,0x0005008e,0x0000000a,0x000000db,0x000000da,0x000000ca, + 0x00050050,0x0000000a,0x000000dc,0x000000ce,0x000000ce,0x00050083,0x0000000a,0x000000dd, + 0x000000db,0x000000dc,0x0006000c,0x0000000a,0x000000de,0x00000001,0x00000004,0x000000dd, + 0x00050085,0x0000000a,0x000000df,0x000000d8,0x000000de,0x00050041,0x00000036,0x000000e0, + 0x00000023,0x00000084,0x00050051,0x00000009,0x000000e1,0x000000df,0x00000000,0x0003003e, + 0x000000e0,0x000000e1,0x00050041,0x00000036,0x000000e3,0x00000023,0x000000e2,0x00050051, + 0x00000009,0x000000e4,0x000000df,0x00000001,0x0003003e,0x000000e3,0x000000e4,0x0004003d, + 0x00000012,0x000000e5,0x00000023,0x0006000c,0x00000012,0x000000e6,0x00000001,0x00000001, + 0x000000e5,0x000200fe,0x000000e6,0x00010038,0x00050036,0x0000000a,0x0000002e,0x00000000, + 0x00000029,0x00030037,0x00000028,0x0000002a,0x00030037,0x0000000b,0x0000002b,0x00030037, + 0x0000000b,0x0000002c,0x00030037,0x0000000b,0x0000002d,0x000200f8,0x0000002f,0x0004003b, + 0x00000021,0x000000e9,0x00000007,0x0004003b,0x000000f1,0x000000f2,0x00000007,0x0004003d, + 0x0000000a,0x000000ea,0x0000002b,0x00050051,0x00000009,0x000000ed,0x000000ea,0x00000000, + 0x00050051,0x00000009,0x000000ee,0x000000ea,0x00000001,0x00070050,0x00000012,0x000000ef, + 0x000000ed,0x000000ee,0x000000eb,0x000000ec,0x0003003e,0x000000e9,0x000000ef,0x00050041, + 0x0000009b,0x000000f3,0x00000098,0x0000009a,0x0004003d,0x00000012,0x000000f4,0x000000f3, + 0x0007004f,0x0000000a,0x000000f5,0x000000f4,0x000000f4,0x00000000,0x00000001,0x00050051, + 0x00000009,0x000000f6,0x000000f5,0x00000000,0x00050051,0x00000009,0x000000f7,0x000000f5, + 0x00000001,0x00060050,0x000000f0,0x000000f8,0x000000f6,0x000000f7,0x000000ec,0x0003003e, + 0x000000f2,0x000000f8,0x000200f9,0x000000f9,0x000200f8,0x000000f9,0x000400f6,0x000000fb, + 0x000000fc,0x00000000,0x000200f9,0x000000fd,0x000200f8,0x000000fd,0x00050041,0x00000036, + 0x000000fe,0x000000e9,0x000000e2,0x0004003d,0x00000009,0x000000ff,0x000000fe,0x000500b8, + 0x00000006,0x00000101,0x000000ff,0x00000100,0x000300f7,0x00000103,0x00000000,0x000400fa, + 0x00000101,0x00000102,0x00000103,0x000200f8,0x00000102,0x00050041,0x00000036,0x00000104, + 0x000000e9,0x00000014,0x0004003d,0x00000009,0x00000105,0x00000104,0x000500ba,0x00000006, + 0x00000107,0x00000105,0x00000106,0x000200f9,0x00000103,0x000200f8,0x00000103,0x000700f5, + 0x00000006,0x00000108,0x00000101,0x000000fd,0x00000107,0x00000102,0x000400fa,0x00000108, + 0x000000fa,0x000000fb,0x000200f8,0x000000fa,0x0004003d,0x000000f0,0x00000109,0x000000f2, + 0x0004003d,0x0000000a,0x0000010a,0x0000002c,0x00050051,0x00000009,0x0000010b,0x0000010a, + 0x00000000,0x00050051,0x00000009,0x0000010c,0x0000010a,0x00000001,0x00060050,0x000000f0, + 0x0000010d,0x0000010b,0x0000010c,0x000000ec,0x0004003d,0x00000012,0x0000010e,0x000000e9, + 0x0008004f,0x000000f0,0x0000010f,0x0000010e,0x0000010e,0x00000000,0x00000001,0x00000002, + 0x0008000c,0x000000f0,0x00000110,0x00000001,0x00000032,0x00000109,0x0000010d,0x0000010f, + 0x00050041,0x00000036,0x00000111,0x000000e9,0x00000084,0x00050051,0x00000009,0x00000112, + 0x00000110,0x00000000,0x0003003e,0x00000111,0x00000112,0x00050041,0x00000036,0x00000113, + 0x000000e9,0x0000008d,0x00050051,0x00000009,0x00000114,0x00000110,0x00000001,0x0003003e, + 0x00000113,0x00000114,0x00050041,0x00000036,0x00000115,0x000000e9,0x000000e2,0x00050051, + 0x00000009,0x00000116,0x00000110,0x00000002,0x0003003e,0x00000115,0x00000116,0x0004003d, + 0x00000027,0x00000117,0x0000002a,0x0004003d,0x00000012,0x00000118,0x000000e9,0x0007004f, + 0x0000000a,0x00000119,0x00000118,0x00000118,0x00000000,0x00000001,0x00070058,0x00000012, + 0x0000011b,0x00000117,0x00000119,0x00000002,0x0000011a,0x0007004f,0x0000000a,0x0000011c, + 0x0000011b,0x0000011b,0x00000000,0x00000001,0x0003003e,0x0000002d,0x0000011c,0x0004003d, + 0x0000000a,0x0000011d,0x0000002d,0x00050094,0x00000009,0x00000120,0x0000011d,0x0000011f, + 0x00050041,0x00000036,0x00000121,0x000000e9,0x00000014,0x0003003e,0x00000121,0x00000120, + 0x000200f9,0x000000fc,0x000200f8,0x000000fc,0x000200f9,0x000000f9,0x000200f8,0x000000fb, + 0x0004003d,0x00000012,0x00000122,0x000000e9,0x0007004f,0x0000000a,0x00000123,0x00000122, + 0x00000122,0x00000002,0x00000003,0x000200fe,0x00000123,0x00010038,0x00050036,0x0000000a, + 0x00000034,0x00000000,0x00000029,0x00030037,0x00000028,0x00000030,0x00030037,0x0000000b, + 0x00000031,0x00030037,0x0000000b,0x00000032,0x00030037,0x0000000b,0x00000033,0x000200f8, + 0x00000035,0x0004003b,0x00000021,0x00000126,0x00000007,0x0004003b,0x000000f1,0x00000134, + 0x00000007,0x0004003b,0x0000000b,0x0000015c,0x00000007,0x0004003d,0x0000000a,0x00000127, + 0x00000031,0x00050051,0x00000009,0x00000128,0x00000127,0x00000000,0x00050051,0x00000009, + 0x00000129,0x00000127,0x00000001,0x00070050,0x00000012,0x0000012a,0x00000128,0x00000129, + 0x000000eb,0x000000ec,0x0003003e,0x00000126,0x0000012a,0x00060041,0x0000012c,0x0000012d, + 0x00000098,0x0000009a,0x00000084,0x0004003d,0x00000009,0x0000012e,0x0000012d,0x00050085, + 0x00000009,0x0000012f,0x0000012b,0x0000012e,0x00050041,0x00000036,0x00000130,0x00000126, + 0x00000084,0x0004003d,0x00000009,0x00000131,0x00000130,0x00050081,0x00000009,0x00000132, + 0x00000131,0x0000012f,0x00050041,0x00000036,0x00000133,0x00000126,0x00000084,0x0003003e, + 0x00000133,0x00000132,0x00050041,0x0000009b,0x00000135,0x00000098,0x0000009a,0x0004003d, + 0x00000012,0x00000136,0x00000135,0x0007004f,0x0000000a,0x00000137,0x00000136,0x00000136, + 0x00000000,0x00000001,0x00050051,0x00000009,0x00000138,0x00000137,0x00000000,0x00050051, + 0x00000009,0x00000139,0x00000137,0x00000001,0x00060050,0x000000f0,0x0000013a,0x00000138, + 0x00000139,0x000000ec,0x0003003e,0x00000134,0x0000013a,0x000200f9,0x0000013b,0x000200f8, + 0x0000013b,0x000400f6,0x0000013d,0x0000013e,0x00000000,0x000200f9,0x0000013f,0x000200f8, + 0x0000013f,0x00050041,0x00000036,0x00000140,0x00000126,0x000000e2,0x0004003d,0x00000009, + 0x00000141,0x00000140,0x000500b8,0x00000006,0x00000142,0x00000141,0x00000100,0x000300f7, + 0x00000144,0x00000000,0x000400fa,0x00000142,0x00000143,0x00000144,0x000200f8,0x00000143, + 0x00050041,0x00000036,0x00000145,0x00000126,0x00000014,0x0004003d,0x00000009,0x00000146, + 0x00000145,0x000500ba,0x00000006,0x00000147,0x00000146,0x00000106,0x000200f9,0x00000144, + 0x000200f8,0x00000144,0x000700f5,0x00000006,0x00000148,0x00000142,0x0000013f,0x00000147, + 0x00000143,0x000400fa,0x00000148,0x0000013c,0x0000013d,0x000200f8,0x0000013c,0x0004003d, + 0x000000f0,0x00000149,0x00000134,0x0004003d,0x0000000a,0x0000014a,0x00000032,0x00050051, + 0x00000009,0x0000014b,0x0000014a,0x00000000,0x00050051,0x00000009,0x0000014c,0x0000014a, + 0x00000001,0x00060050,0x000000f0,0x0000014d,0x0000014b,0x0000014c,0x000000ec,0x0004003d, + 0x00000012,0x0000014e,0x00000126,0x0008004f,0x000000f0,0x0000014f,0x0000014e,0x0000014e, + 0x00000000,0x00000001,0x00000002,0x0008000c,0x000000f0,0x00000150,0x00000001,0x00000032, + 0x00000149,0x0000014d,0x0000014f,0x00050041,0x00000036,0x00000151,0x00000126,0x00000084, + 0x00050051,0x00000009,0x00000152,0x00000150,0x00000000,0x0003003e,0x00000151,0x00000152, + 0x00050041,0x00000036,0x00000153,0x00000126,0x0000008d,0x00050051,0x00000009,0x00000154, + 0x00000150,0x00000001,0x0003003e,0x00000153,0x00000154,0x00050041,0x00000036,0x00000155, + 0x00000126,0x000000e2,0x00050051,0x00000009,0x00000156,0x00000150,0x00000002,0x0003003e, + 0x00000155,0x00000156,0x0004003d,0x00000027,0x00000157,0x00000030,0x0004003d,0x00000012, + 0x00000158,0x00000126,0x0007004f,0x0000000a,0x00000159,0x00000158,0x00000158,0x00000000, + 0x00000001,0x00070058,0x00000012,0x0000015a,0x00000157,0x00000159,0x00000002,0x0000011a, + 0x0007004f,0x0000000a,0x0000015b,0x0000015a,0x0000015a,0x00000000,0x00000001,0x0003003e, + 0x00000033,0x0000015b,0x0004003d,0x0000000a,0x0000015d,0x00000033,0x0003003e,0x0000015c, + 0x0000015d,0x00050039,0x0000000a,0x0000015e,0x0000001f,0x0000015c,0x0003003e,0x00000033, + 0x0000015e,0x0004003d,0x0000000a,0x0000015f,0x00000033,0x00050094,0x00000009,0x00000160, + 0x0000015f,0x0000011f,0x00050041,0x00000036,0x00000161,0x00000126,0x00000014,0x0003003e, + 0x00000161,0x00000160,0x000200f9,0x0000013e,0x000200f8,0x0000013e,0x000200f9,0x0000013b, + 0x000200f8,0x0000013d,0x0004003d,0x00000012,0x00000162,0x00000126,0x0007004f,0x0000000a, + 0x00000163,0x00000162,0x00000162,0x00000002,0x00000003,0x000200fe,0x00000163,0x00010038, + 0x00050036,0x0000000a,0x0000003c,0x00000000,0x00000037,0x00030037,0x00000028,0x00000038, + 0x00030037,0x0000000b,0x00000039,0x00030037,0x0000000b,0x0000003a,0x00030037,0x00000036, + 0x0000003b,0x000200f8,0x0000003d,0x0004003b,0x0000000b,0x00000166,0x00000007,0x0004003d, + 0x0000000a,0x00000169,0x0000003a,0x0004003d,0x0000000a,0x0000016a,0x00000039,0x0008000c, + 0x0000000a,0x0000016b,0x00000001,0x00000032,0x00000168,0x00000169,0x0000016a,0x0003003e, + 0x00000166,0x0000016b,0x0004003d,0x0000000a,0x0000016f,0x00000166,0x0008000c,0x0000000a, + 0x00000173,0x00000001,0x00000032,0x0000016e,0x0000016f,0x00000172,0x0003003e,0x00000166, + 0x00000173,0x00050041,0x00000036,0x00000174,0x00000166,0x00000084,0x0004003d,0x00000009, + 0x00000175,0x00000174,0x00050081,0x00000009,0x00000176,0x00000175,0x0000011e,0x00050041, + 0x00000036,0x00000177,0x00000166,0x00000084,0x0003003e,0x00000177,0x00000176,0x0004003d, + 0x00000009,0x00000179,0x0000003b,0x00050085,0x00000009,0x0000017a,0x00000178,0x00000179, + 0x00050041,0x00000036,0x0000017b,0x00000166,0x0000008d,0x0004003d,0x00000009,0x0000017c, + 0x0000017b,0x00050081,0x00000009,0x0000017d,0x0000017c,0x0000017a,0x00050041,0x00000036, + 0x0000017e,0x00000166,0x0000008d,0x0003003e,0x0000017e,0x0000017d,0x0004003d,0x00000027, + 0x0000017f,0x00000038,0x0004003d,0x0000000a,0x00000180,0x00000166,0x00070058,0x00000012, + 0x00000181,0x0000017f,0x00000180,0x00000002,0x0000011a,0x0007004f,0x0000000a,0x00000182, + 0x00000181,0x00000181,0x00000000,0x00000001,0x000200fe,0x00000182,0x00010038,0x00050036, + 0x0000000a,0x00000044,0x00000000,0x0000003e,0x00030037,0x00000028,0x0000003f,0x00030037, + 0x00000028,0x00000040,0x00030037,0x0000000b,0x00000041,0x00030037,0x0000000b,0x00000042, + 0x00030037,0x00000021,0x00000043,0x000200f8,0x00000045,0x0004003b,0x0000000b,0x00000185, + 0x00000007,0x0004003b,0x00000021,0x0000018c,0x00000007,0x0004003b,0x0000000b,0x0000018e, + 0x00000007,0x0004003b,0x0000000b,0x0000018f,0x00000007,0x0004003b,0x0000000b,0x00000191, + 0x00000007,0x0004003b,0x0000000b,0x00000192,0x00000007,0x0004003b,0x0000000b,0x000001a7, + 0x00000007,0x0004003b,0x0000000b,0x000001a9,0x00000007,0x0004003b,0x0000000b,0x000001aa, + 0x00000007,0x0004003b,0x00000021,0x000001ba,0x00000007,0x0004003b,0x00000021,0x000001ce, + 0x00000007,0x0004003b,0x00000021,0x000001e5,0x00000007,0x0004003b,0x0000000b,0x000001ea, + 0x00000007,0x0004003b,0x00000008,0x000001f6,0x00000007,0x0004003b,0x0000000b,0x000001f7, + 0x00000007,0x0004003b,0x0000000b,0x000001f9,0x00000007,0x0004003b,0x0000000b,0x000001fc, + 0x00000007,0x0004003b,0x0000000b,0x000001ff,0x00000007,0x0004003b,0x00000036,0x00000201, + 0x00000007,0x0004003b,0x0000000b,0x00000208,0x00000007,0x0004003b,0x0000000b,0x0000020a, + 0x00000007,0x0004003b,0x0000000b,0x0000020b,0x00000007,0x0004003b,0x0000000b,0x0000021a, + 0x00000007,0x0004003b,0x0000000b,0x0000021c,0x00000007,0x0004003b,0x0000000b,0x0000021d, + 0x00000007,0x0004003b,0x00000021,0x00000239,0x00000007,0x0004003b,0x00000021,0x0000024b, + 0x00000007,0x0004003b,0x0000000b,0x00000262,0x00000007,0x0004003b,0x00000008,0x0000026d, + 0x00000007,0x0004003b,0x0000000b,0x0000026e,0x00000007,0x0004003b,0x0000000b,0x00000270, + 0x00000007,0x0004003b,0x0000000b,0x00000273,0x00000007,0x0004003b,0x0000000b,0x00000276, + 0x00000007,0x0004003b,0x00000036,0x00000278,0x00000007,0x0003003e,0x00000185,0x00000186, + 0x00050041,0x00000036,0x00000187,0x00000042,0x00000084,0x0004003d,0x00000009,0x00000188, + 0x00000187,0x000500ba,0x00000006,0x00000189,0x00000188,0x0000011a,0x000300f7,0x0000018b, + 0x00000000,0x000400fa,0x00000189,0x0000018a,0x000001a1,0x000200f8,0x0000018a,0x0004003d, + 0x0000000a,0x00000190,0x00000041,0x0003003e,0x0000018f,0x00000190,0x0003003e,0x00000191, + 0x0000018d,0x00080039,0x0000000a,0x00000193,0x0000002e,0x0000003f,0x0000018f,0x00000191, + 0x00000192,0x0004003d,0x0000000a,0x00000194,0x00000192,0x0003003e,0x0000018e,0x00000194, + 0x00050041,0x00000036,0x00000195,0x0000018c,0x00000084,0x00050051,0x00000009,0x00000196, + 0x00000193,0x00000000,0x0003003e,0x00000195,0x00000196,0x00050041,0x00000036,0x00000197, + 0x0000018c,0x000000e2,0x00050051,0x00000009,0x00000198,0x00000193,0x00000001,0x0003003e, + 0x00000197,0x00000198,0x00050041,0x00000036,0x00000199,0x0000018e,0x0000008d,0x0004003d, + 0x00000009,0x0000019a,0x00000199,0x000500ba,0x00000006,0x0000019b,0x0000019a,0x00000106, + 0x000600a9,0x00000009,0x0000019c,0x0000019b,0x000000ec,0x0000011a,0x00050041,0x00000036, + 0x0000019d,0x0000018c,0x00000084,0x0004003d,0x00000009,0x0000019e,0x0000019d,0x00050081, + 0x00000009,0x0000019f,0x0000019e,0x0000019c,0x00050041,0x00000036,0x000001a0,0x0000018c, + 0x00000084,0x0003003e,0x000001a0,0x0000019f,0x000200f9,0x0000018b,0x000200f8,0x000001a1, + 0x00050041,0x00000036,0x000001a2,0x0000018c,0x00000084,0x00050051,0x00000009,0x000001a3, + 0x00000186,0x00000000,0x0003003e,0x000001a2,0x000001a3,0x00050041,0x00000036,0x000001a4, + 0x0000018c,0x000000e2,0x00050051,0x00000009,0x000001a5,0x00000186,0x00000001,0x0003003e, + 0x000001a4,0x000001a5,0x000200f9,0x0000018b,0x000200f8,0x0000018b,0x0004003d,0x0000000a, + 0x000001a8,0x00000041,0x0003003e,0x000001a7,0x000001a8,0x0003003e,0x000001a9,0x000001a6, + 0x00080039,0x0000000a,0x000001ab,0x0000002e,0x0000003f,0x000001a7,0x000001a9,0x000001aa, + 0x0004003d,0x0000000a,0x000001ac,0x000001aa,0x0003003e,0x0000018e,0x000001ac,0x00050041, + 0x00000036,0x000001ad,0x0000018c,0x0000008d,0x00050051,0x00000009,0x000001ae,0x000001ab, + 0x00000000,0x0003003e,0x000001ad,0x000001ae,0x00050041,0x00000036,0x000001af,0x0000018c, + 0x00000014,0x00050051,0x00000009,0x000001b0,0x000001ab,0x00000001,0x0003003e,0x000001af, + 0x000001b0,0x00050041,0x00000036,0x000001b1,0x0000018c,0x00000084,0x0004003d,0x00000009, + 0x000001b2,0x000001b1,0x00050041,0x00000036,0x000001b3,0x0000018c,0x0000008d,0x0004003d, + 0x00000009,0x000001b4,0x000001b3,0x00050081,0x00000009,0x000001b5,0x000001b2,0x000001b4, + 0x000500ba,0x00000006,0x000001b7,0x000001b5,0x000001b6,0x000300f7,0x000001b9,0x00000000, + 0x000400fa,0x000001b7,0x000001b8,0x000001b9,0x000200f8,0x000001b8,0x00050041,0x00000036, + 0x000001bb,0x0000018c,0x00000084,0x0004003d,0x00000009,0x000001bc,0x000001bb,0x0004007f, + 0x00000009,0x000001bd,0x000001bc,0x00050081,0x00000009,0x000001be,0x000001bd,0x0000012b, + 0x00050041,0x00000036,0x000001bf,0x0000018c,0x00000084,0x0004003d,0x00000009,0x000001c0, + 0x000001bf,0x00050041,0x00000036,0x000001c1,0x0000018c,0x0000008d,0x0004003d,0x00000009, + 0x000001c2,0x000001c1,0x00050041,0x00000036,0x000001c3,0x0000018c,0x0000008d,0x0004003d, + 0x00000009,0x000001c4,0x000001c3,0x0004007f,0x00000009,0x000001c5,0x000001c4,0x00050083, + 0x00000009,0x000001c6,0x000001c5,0x0000012b,0x00070050,0x00000012,0x000001c7,0x000001be, + 0x000001c0,0x000001c2,0x000001c6,0x00050041,0x0000009b,0x000001c8,0x00000098,0x0000009a, + 0x0004003d,0x00000012,0x000001c9,0x000001c8,0x0009004f,0x00000012,0x000001ca,0x000001c9, + 0x000001c9,0x00000000,0x00000001,0x00000000,0x00000001,0x0004003d,0x0000000a,0x000001cb, + 0x00000041,0x0009004f,0x00000012,0x000001cc,0x000001cb,0x000001cb,0x00000000,0x00000001, + 0x00000000,0x00000001,0x0008000c,0x00000012,0x000001cd,0x00000001,0x00000032,0x000001c7, + 0x000001ca,0x000001cc,0x0003003e,0x000001ba,0x000001cd,0x0004003d,0x00000027,0x000001cf, + 0x0000003f,0x0004003d,0x00000012,0x000001d0,0x000001ba,0x0007004f,0x0000000a,0x000001d1, + 0x000001d0,0x000001d0,0x00000000,0x00000001,0x00080058,0x00000012,0x000001d5,0x000001cf, + 0x000001d1,0x0000000a,0x0000011a,0x000001d4,0x0007004f,0x0000000a,0x000001d6,0x000001d5, + 0x000001d5,0x00000000,0x00000001,0x00050041,0x00000036,0x000001d7,0x000001ce,0x00000084, + 0x00050051,0x00000009,0x000001d8,0x000001d6,0x00000000,0x0003003e,0x000001d7,0x000001d8, + 0x00050041,0x00000036,0x000001d9,0x000001ce,0x0000008d,0x00050051,0x00000009,0x000001da, + 0x000001d6,0x00000001,0x0003003e,0x000001d9,0x000001da,0x0004003d,0x00000027,0x000001db, + 0x0000003f,0x0004003d,0x00000012,0x000001dc,0x000001ba,0x0007004f,0x0000000a,0x000001dd, + 0x000001dc,0x000001dc,0x00000002,0x00000003,0x00080058,0x00000012,0x000001df,0x000001db, + 0x000001dd,0x0000000a,0x0000011a,0x000001de,0x0007004f,0x0000000a,0x000001e0,0x000001df, + 0x000001df,0x00000000,0x00000001,0x00050041,0x00000036,0x000001e1,0x000001ce,0x000000e2, + 0x00050051,0x00000009,0x000001e2,0x000001e0,0x00000000,0x0003003e,0x000001e1,0x000001e2, + 0x00050041,0x00000036,0x000001e3,0x000001ce,0x00000014,0x00050051,0x00000009,0x000001e4, + 0x000001e0,0x00000001,0x0003003e,0x000001e3,0x000001e4,0x0004003d,0x00000012,0x000001e6, + 0x000001ce,0x0003003e,0x000001e5,0x000001e6,0x00050039,0x00000012,0x000001e7,0x00000024, + 0x000001e5,0x0004003d,0x00000012,0x000001e8,0x000001ce,0x0009004f,0x00000012,0x000001e9, + 0x000001e8,0x000001e7,0x00000005,0x00000004,0x00000007,0x00000006,0x0003003e,0x000001ce, + 0x000001e9,0x0004003d,0x00000012,0x000001ec,0x000001ce,0x0007004f,0x0000000a,0x000001ed, + 0x000001ec,0x000001ec,0x00000000,0x00000002,0x0004003d,0x00000012,0x000001ee,0x000001ce, + 0x0007004f,0x0000000a,0x000001ef,0x000001ee,0x000001ee,0x00000001,0x00000003,0x0008000c, + 0x0000000a,0x000001f0,0x00000001,0x00000032,0x000001eb,0x000001ed,0x000001ef,0x0003003e, + 0x000001ea,0x000001f0,0x0004003d,0x00000012,0x000001f1,0x0000018c,0x0007004f,0x0000000a, + 0x000001f2,0x000001f1,0x000001f1,0x00000002,0x00000003,0x00050050,0x0000000a,0x000001f3, + 0x00000106,0x00000106,0x0007000c,0x0000000a,0x000001f4,0x00000001,0x00000030,0x000001f3, + 0x000001f2,0x000500b7,0x00000007,0x000001f5,0x000001f4,0x00000186,0x0003003e,0x000001f6, + 0x000001f5,0x0004003d,0x0000000a,0x000001f8,0x000001ea,0x0003003e,0x000001f7,0x000001f8, + 0x0003003e,0x000001f9,0x00000186,0x00070039,0x00000002,0x000001fa,0x00000010,0x000001f6, + 0x000001f7,0x000001f9,0x0004003d,0x0000000a,0x000001fb,0x000001f7,0x0003003e,0x000001ea, + 0x000001fb,0x0004003d,0x00000012,0x000001fd,0x0000018c,0x0007004f,0x0000000a,0x000001fe, + 0x000001fd,0x000001fd,0x00000000,0x00000001,0x0003003e,0x000001fc,0x000001fe,0x0004003d, + 0x0000000a,0x00000200,0x000001ea,0x0003003e,0x000001ff,0x00000200,0x00050041,0x00000036, + 0x00000202,0x00000043,0x000000e2,0x0004003d,0x00000009,0x00000203,0x00000202,0x0003003e, + 0x00000201,0x00000203,0x00080039,0x0000000a,0x00000204,0x0000003c,0x00000040,0x000001fc, + 0x000001ff,0x00000201,0x0004003d,0x0000000a,0x00000205,0x00000185,0x00050081,0x0000000a, + 0x00000206,0x00000205,0x00000204,0x0003003e,0x00000185,0x00000206,0x000200f9,0x000001b9, + 0x000200f8,0x000001b9,0x0004003d,0x0000000a,0x00000209,0x00000041,0x0003003e,0x00000208, + 0x00000209,0x0003003e,0x0000020a,0x00000207,0x00080039,0x0000000a,0x0000020c,0x00000034, + 0x0000003f,0x00000208,0x0000020a,0x0000020b,0x0004003d,0x0000000a,0x0000020d,0x0000020b, + 0x0003003e,0x0000018e,0x0000020d,0x00050041,0x00000036,0x0000020e,0x0000018c,0x00000084, + 0x00050051,0x00000009,0x0000020f,0x0000020c,0x00000000,0x0003003e,0x0000020e,0x0000020f, + 0x00050041,0x00000036,0x00000210,0x0000018c,0x000000e2,0x00050051,0x00000009,0x00000211, + 0x0000020c,0x00000001,0x0003003e,0x00000210,0x00000211,0x0004003d,0x00000027,0x00000212, + 0x0000003f,0x0004003d,0x0000000a,0x00000213,0x00000041,0x00080058,0x00000012,0x00000214, + 0x00000212,0x00000213,0x0000000a,0x0000011a,0x000001de,0x00050051,0x00000009,0x00000215, + 0x00000214,0x00000000,0x000500ba,0x00000006,0x00000216,0x00000215,0x0000011a,0x000300f7, + 0x00000218,0x00000000,0x000400fa,0x00000216,0x00000217,0x0000022c,0x000200f8,0x00000217, + 0x0004003d,0x0000000a,0x0000021b,0x00000041,0x0003003e,0x0000021a,0x0000021b,0x0003003e, + 0x0000021c,0x00000219,0x00080039,0x0000000a,0x0000021e,0x00000034,0x0000003f,0x0000021a, + 0x0000021c,0x0000021d,0x0004003d,0x0000000a,0x0000021f,0x0000021d,0x0003003e,0x0000018e, + 0x0000021f,0x00050041,0x00000036,0x00000220,0x0000018c,0x0000008d,0x00050051,0x00000009, + 0x00000221,0x0000021e,0x00000000,0x0003003e,0x00000220,0x00000221,0x00050041,0x00000036, + 0x00000222,0x0000018c,0x00000014,0x00050051,0x00000009,0x00000223,0x0000021e,0x00000001, + 0x0003003e,0x00000222,0x00000223,0x00050041,0x00000036,0x00000224,0x0000018e,0x0000008d, + 0x0004003d,0x00000009,0x00000225,0x00000224,0x000500ba,0x00000006,0x00000226,0x00000225, + 0x00000106,0x000600a9,0x00000009,0x00000227,0x00000226,0x000000ec,0x0000011a,0x00050041, + 0x00000036,0x00000228,0x0000018c,0x0000008d,0x0004003d,0x00000009,0x00000229,0x00000228, + 0x00050081,0x00000009,0x0000022a,0x00000229,0x00000227,0x00050041,0x00000036,0x0000022b, + 0x0000018c,0x0000008d,0x0003003e,0x0000022b,0x0000022a,0x000200f9,0x00000218,0x000200f8, + 0x0000022c,0x00050041,0x00000036,0x0000022d,0x0000018c,0x0000008d,0x00050051,0x00000009, + 0x0000022e,0x00000186,0x00000000,0x0003003e,0x0000022d,0x0000022e,0x00050041,0x00000036, + 0x0000022f,0x0000018c,0x00000014,0x00050051,0x00000009,0x00000230,0x00000186,0x00000001, + 0x0003003e,0x0000022f,0x00000230,0x000200f9,0x00000218,0x000200f8,0x00000218,0x00050041, + 0x00000036,0x00000231,0x0000018c,0x00000084,0x0004003d,0x00000009,0x00000232,0x00000231, + 0x00050041,0x00000036,0x00000233,0x0000018c,0x0000008d,0x0004003d,0x00000009,0x00000234, + 0x00000233,0x00050081,0x00000009,0x00000235,0x00000232,0x00000234,0x000500ba,0x00000006, + 0x00000236,0x00000235,0x000001b6,0x000300f7,0x00000238,0x00000000,0x000400fa,0x00000236, + 0x00000237,0x00000238,0x000200f8,0x00000237,0x00050041,0x00000036,0x0000023a,0x0000018c, + 0x00000084,0x0004003d,0x00000009,0x0000023b,0x0000023a,0x0004007f,0x00000009,0x0000023c, + 0x0000023b,0x00050041,0x00000036,0x0000023d,0x0000018c,0x00000084,0x0004003d,0x00000009, + 0x0000023e,0x0000023d,0x0004007f,0x00000009,0x0000023f,0x0000023e,0x00050041,0x00000036, + 0x00000240,0x0000018c,0x0000008d,0x0004003d,0x00000009,0x00000241,0x00000240,0x00050041, + 0x00000036,0x00000242,0x0000018c,0x0000008d,0x0004003d,0x00000009,0x00000243,0x00000242, + 0x00070050,0x00000012,0x00000244,0x0000023c,0x0000023f,0x00000241,0x00000243,0x00050041, + 0x0000009b,0x00000245,0x00000098,0x0000009a,0x0004003d,0x00000012,0x00000246,0x00000245, + 0x0009004f,0x00000012,0x00000247,0x00000246,0x00000246,0x00000000,0x00000001,0x00000000, + 0x00000001,0x0004003d,0x0000000a,0x00000248,0x00000041,0x0009004f,0x00000012,0x00000249, + 0x00000248,0x00000248,0x00000000,0x00000001,0x00000000,0x00000001,0x0008000c,0x00000012, + 0x0000024a,0x00000001,0x00000032,0x00000244,0x00000247,0x00000249,0x0003003e,0x00000239, + 0x0000024a,0x0004003d,0x00000027,0x0000024c,0x0000003f,0x0004003d,0x00000012,0x0000024d, + 0x00000239,0x0007004f,0x0000000a,0x0000024e,0x0000024d,0x0000024d,0x00000000,0x00000001, + 0x00080058,0x00000012,0x0000024f,0x0000024c,0x0000024e,0x0000000a,0x0000011a,0x000001d4, + 0x00050051,0x00000009,0x00000250,0x0000024f,0x00000001,0x00050041,0x00000036,0x00000251, + 0x0000024b,0x00000084,0x0003003e,0x00000251,0x00000250,0x0004003d,0x00000027,0x00000252, + 0x0000003f,0x0004003d,0x00000012,0x00000253,0x00000239,0x0007004f,0x0000000a,0x00000254, + 0x00000253,0x00000253,0x00000000,0x00000001,0x00080058,0x00000012,0x00000256,0x00000252, + 0x00000254,0x0000000a,0x0000011a,0x00000255,0x00050051,0x00000009,0x00000257,0x00000256, + 0x00000000,0x00050041,0x00000036,0x00000258,0x0000024b,0x0000008d,0x0003003e,0x00000258, + 0x00000257,0x0004003d,0x00000027,0x00000259,0x0000003f,0x0004003d,0x00000012,0x0000025a, + 0x00000239,0x0007004f,0x0000000a,0x0000025b,0x0000025a,0x0000025a,0x00000002,0x00000003, + 0x00080058,0x00000012,0x0000025c,0x00000259,0x0000025b,0x0000000a,0x0000011a,0x000001de, + 0x0007004f,0x0000000a,0x0000025d,0x0000025c,0x0000025c,0x00000001,0x00000000,0x00050041, + 0x00000036,0x0000025e,0x0000024b,0x000000e2,0x00050051,0x00000009,0x0000025f,0x0000025d, + 0x00000000,0x0003003e,0x0000025e,0x0000025f,0x00050041,0x00000036,0x00000260,0x0000024b, + 0x00000014,0x00050051,0x00000009,0x00000261,0x0000025d,0x00000001,0x0003003e,0x00000260, + 0x00000261,0x0004003d,0x00000012,0x00000263,0x0000024b,0x0007004f,0x0000000a,0x00000264, + 0x00000263,0x00000263,0x00000000,0x00000002,0x0004003d,0x00000012,0x00000265,0x0000024b, + 0x0007004f,0x0000000a,0x00000266,0x00000265,0x00000265,0x00000001,0x00000003,0x0008000c, + 0x0000000a,0x00000267,0x00000001,0x00000032,0x000001eb,0x00000264,0x00000266,0x0003003e, + 0x00000262,0x00000267,0x0004003d,0x00000012,0x00000268,0x0000018c,0x0007004f,0x0000000a, + 0x00000269,0x00000268,0x00000268,0x00000002,0x00000003,0x00050050,0x0000000a,0x0000026a, + 0x00000106,0x00000106,0x0007000c,0x0000000a,0x0000026b,0x00000001,0x00000030,0x0000026a, + 0x00000269,0x000500b7,0x00000007,0x0000026c,0x0000026b,0x00000186,0x0003003e,0x0000026d, + 0x0000026c,0x0004003d,0x0000000a,0x0000026f,0x00000262,0x0003003e,0x0000026e,0x0000026f, + 0x0003003e,0x00000270,0x00000186,0x00070039,0x00000002,0x00000271,0x00000010,0x0000026d, + 0x0000026e,0x00000270,0x0004003d,0x0000000a,0x00000272,0x0000026e,0x0003003e,0x00000262, + 0x00000272,0x0004003d,0x00000012,0x00000274,0x0000018c,0x0007004f,0x0000000a,0x00000275, + 0x00000274,0x00000274,0x00000000,0x00000001,0x0003003e,0x00000273,0x00000275,0x0004003d, + 0x0000000a,0x00000277,0x00000262,0x0003003e,0x00000276,0x00000277,0x00050041,0x00000036, + 0x00000279,0x00000043,0x00000014,0x0004003d,0x00000009,0x0000027a,0x00000279,0x0003003e, + 0x00000278,0x0000027a,0x00080039,0x0000000a,0x0000027b,0x0000003c,0x00000040,0x00000273, + 0x00000276,0x00000278,0x0007004f,0x0000000a,0x0000027c,0x0000027b,0x0000027b,0x00000001, + 0x00000000,0x0004003d,0x0000000a,0x0000027d,0x00000185,0x00050081,0x0000000a,0x0000027e, + 0x0000027d,0x0000027c,0x0003003e,0x00000185,0x0000027e,0x000200f9,0x00000238,0x000200f8, + 0x00000238,0x0004003d,0x0000000a,0x0000027f,0x00000185,0x000200fe,0x0000027f,0x00010038, + 0x00050036,0x00000009,0x0000004a,0x00000000,0x00000046,0x00030037,0x00000028,0x00000047, + 0x00030037,0x0000000b,0x00000048,0x00030037,0x00000036,0x00000049,0x000200f8,0x0000004b, + 0x0004003b,0x0000000b,0x00000282,0x00000007,0x0004003b,0x0000000b,0x00000286,0x00000007, + 0x0003003e,0x00000282,0x00000285,0x0004003d,0x00000009,0x00000289,0x00000049,0x00050050, + 0x0000000a,0x0000028a,0x00000289,0x000000ec,0x00050085,0x0000000a,0x0000028b,0x00000288, + 0x0000028a,0x0003003e,0x00000286,0x0000028b,0x0004003d,0x0000000a,0x0000028c,0x00000282, + 0x00050081,0x0000000a,0x0000028d,0x0000028c,0x0000018d,0x0003003e,0x00000282,0x0000028d, + 0x0004003d,0x0000000a,0x00000290,0x00000286,0x00050081,0x0000000a,0x00000291,0x00000290, + 0x0000028f,0x0003003e,0x00000286,0x00000291,0x0004003d,0x0000000a,0x00000295,0x00000282, + 0x00050085,0x0000000a,0x00000296,0x00000295,0x00000294,0x0003003e,0x00000282,0x00000296, + 0x0004003d,0x0000000a,0x00000297,0x00000286,0x00050085,0x0000000a,0x00000298,0x00000297, + 0x00000294,0x0003003e,0x00000286,0x00000298,0x0004003d,0x00000027,0x00000299,0x00000047, + 0x0004003d,0x0000000a,0x0000029a,0x00000282,0x0004003d,0x0000000a,0x0000029b,0x00000048, + 0x0004003d,0x0000000a,0x0000029c,0x00000286,0x0008000c,0x0000000a,0x0000029d,0x00000001, + 0x00000032,0x0000029a,0x0000029b,0x0000029c,0x00070058,0x00000012,0x0000029e,0x00000299, + 0x0000029d,0x00000002,0x0000011a,0x00050051,0x00000009,0x0000029f,0x0000029e,0x00000000, + 0x000200fe,0x0000029f,0x00010038,0x00050036,0x00000009,0x00000051,0x00000000,0x0000004c, + 0x00030037,0x00000028,0x0000004d,0x00030037,0x00000028,0x0000004e,0x00030037,0x0000000b, + 0x0000004f,0x00030037,0x00000036,0x00000050,0x000200f8,0x00000052,0x0004003b,0x0000000b, + 0x000002a2,0x00000007,0x0004003b,0x00000036,0x000002c6,0x00000007,0x0004003b,0x0000000b, + 0x000002c8,0x00000007,0x0004003b,0x00000036,0x000002ca,0x00000007,0x0003003e,0x000002a2, + 0x000002a3,0x000200f9,0x000002a4,0x000200f8,0x000002a4,0x000400f6,0x000002a6,0x000002a7, + 0x00000000,0x000200f9,0x000002a8,0x000200f8,0x000002a8,0x00050041,0x00000036,0x000002a9, + 0x0000004f,0x00000084,0x0004003d,0x00000009,0x000002aa,0x000002a9,0x0004003d,0x00000009, + 0x000002ab,0x00000050,0x000500ba,0x00000006,0x000002ac,0x000002aa,0x000002ab,0x000300f7, + 0x000002ae,0x00000000,0x000400fa,0x000002ac,0x000002ad,0x000002ae,0x000200f8,0x000002ad, + 0x00050041,0x00000036,0x000002af,0x000002a2,0x0000008d,0x0004003d,0x00000009,0x000002b0, + 0x000002af,0x000500ba,0x00000006,0x000002b2,0x000002b0,0x000002b1,0x000200f9,0x000002ae, + 0x000200f8,0x000002ae,0x000700f5,0x00000006,0x000002b3,0x000002ac,0x000002a8,0x000002b2, + 0x000002ad,0x000300f7,0x000002b5,0x00000000,0x000400fa,0x000002b3,0x000002b4,0x000002b5, + 0x000200f8,0x000002b4,0x00050041,0x00000036,0x000002b6,0x000002a2,0x00000084,0x0004003d, + 0x00000009,0x000002b7,0x000002b6,0x000500b4,0x00000006,0x000002b8,0x000002b7,0x0000011a, + 0x000200f9,0x000002b5,0x000200f8,0x000002b5,0x000700f5,0x00000006,0x000002b9,0x000002b3, + 0x000002ae,0x000002b8,0x000002b4,0x000400fa,0x000002b9,0x000002a5,0x000002a6,0x000200f8, + 0x000002a5,0x0004003d,0x00000027,0x000002ba,0x0000004d,0x0004003d,0x0000000a,0x000002bb, + 0x0000004f,0x00070058,0x00000012,0x000002bc,0x000002ba,0x000002bb,0x00000002,0x0000011a, + 0x0007004f,0x0000000a,0x000002bd,0x000002bc,0x000002bc,0x00000000,0x00000001,0x0003003e, + 0x000002a2,0x000002bd,0x00050041,0x0000009b,0x000002c1,0x00000098,0x0000009a,0x0004003d, + 0x00000012,0x000002c2,0x000002c1,0x0007004f,0x0000000a,0x000002c3,0x000002c2,0x000002c2, + 0x00000000,0x00000001,0x0004003d,0x0000000a,0x000002c4,0x0000004f,0x0008000c,0x0000000a, + 0x000002c5,0x00000001,0x00000032,0x000002c0,0x000002c3,0x000002c4,0x0003003e,0x0000004f, + 0x000002c5,0x000200f9,0x000002a7,0x000200f8,0x000002a7,0x000200f9,0x000002a4,0x000200f8, + 0x000002a6,0x0004003d,0x0000000a,0x000002c9,0x000002a2,0x0003003e,0x000002c8,0x000002c9, + 0x0003003e,0x000002ca,0x0000011a,0x00070039,0x00000009,0x000002cb,0x0000004a,0x0000004e, + 0x000002c8,0x000002ca,0x0008000c,0x00000009,0x000002cd,0x00000001,0x00000032,0x000002c7, + 0x000002cb,0x000002cc,0x0003003e,0x000002c6,0x000002cd,0x00060041,0x0000012c,0x000002ce, + 0x00000098,0x0000009a,0x00000084,0x0004003d,0x00000009,0x000002cf,0x000002ce,0x0004003d, + 0x00000009,0x000002d0,0x000002c6,0x00050041,0x00000036,0x000002d1,0x0000004f,0x00000084, + 0x0004003d,0x00000009,0x000002d2,0x000002d1,0x0008000c,0x00000009,0x000002d3,0x00000001, + 0x00000032,0x000002cf,0x000002d0,0x000002d2,0x000200fe,0x000002d3,0x00010038,0x00050036, + 0x00000009,0x00000057,0x00000000,0x0000004c,0x00030037,0x00000028,0x00000053,0x00030037, + 0x00000028,0x00000054,0x00030037,0x0000000b,0x00000055,0x00030037,0x00000036,0x00000056, + 0x000200f8,0x00000058,0x0004003b,0x0000000b,0x000002d6,0x00000007,0x0004003b,0x00000036, + 0x000002f6,0x00000007,0x0004003b,0x0000000b,0x000002f7,0x00000007,0x0004003b,0x00000036, + 0x000002f9,0x00000007,0x0003003e,0x000002d6,0x000002a3,0x000200f9,0x000002d7,0x000200f8, + 0x000002d7,0x000400f6,0x000002d9,0x000002da,0x00000000,0x000200f9,0x000002db,0x000200f8, + 0x000002db,0x00050041,0x00000036,0x000002dc,0x00000055,0x00000084,0x0004003d,0x00000009, + 0x000002dd,0x000002dc,0x0004003d,0x00000009,0x000002de,0x00000056,0x000500b8,0x00000006, + 0x000002df,0x000002dd,0x000002de,0x000300f7,0x000002e1,0x00000000,0x000400fa,0x000002df, + 0x000002e0,0x000002e1,0x000200f8,0x000002e0,0x00050041,0x00000036,0x000002e2,0x000002d6, + 0x0000008d,0x0004003d,0x00000009,0x000002e3,0x000002e2,0x000500ba,0x00000006,0x000002e4, + 0x000002e3,0x000002b1,0x000200f9,0x000002e1,0x000200f8,0x000002e1,0x000700f5,0x00000006, + 0x000002e5,0x000002df,0x000002db,0x000002e4,0x000002e0,0x000300f7,0x000002e7,0x00000000, + 0x000400fa,0x000002e5,0x000002e6,0x000002e7,0x000200f8,0x000002e6,0x00050041,0x00000036, + 0x000002e8,0x000002d6,0x00000084,0x0004003d,0x00000009,0x000002e9,0x000002e8,0x000500b4, + 0x00000006,0x000002ea,0x000002e9,0x0000011a,0x000200f9,0x000002e7,0x000200f8,0x000002e7, + 0x000700f5,0x00000006,0x000002eb,0x000002e5,0x000002e1,0x000002ea,0x000002e6,0x000400fa, + 0x000002eb,0x000002d8,0x000002d9,0x000200f8,0x000002d8,0x0004003d,0x00000027,0x000002ec, + 0x00000053,0x0004003d,0x0000000a,0x000002ed,0x00000055,0x00070058,0x00000012,0x000002ee, + 0x000002ec,0x000002ed,0x00000002,0x0000011a,0x0007004f,0x0000000a,0x000002ef,0x000002ee, + 0x000002ee,0x00000000,0x00000001,0x0003003e,0x000002d6,0x000002ef,0x00050041,0x0000009b, + 0x000002f1,0x00000098,0x0000009a,0x0004003d,0x00000012,0x000002f2,0x000002f1,0x0007004f, + 0x0000000a,0x000002f3,0x000002f2,0x000002f2,0x00000000,0x00000001,0x0004003d,0x0000000a, + 0x000002f4,0x00000055,0x0008000c,0x0000000a,0x000002f5,0x00000001,0x00000032,0x000002f0, + 0x000002f3,0x000002f4,0x0003003e,0x00000055,0x000002f5,0x000200f9,0x000002da,0x000200f8, + 0x000002da,0x000200f9,0x000002d7,0x000200f8,0x000002d9,0x0004003d,0x0000000a,0x000002f8, + 0x000002d6,0x0003003e,0x000002f7,0x000002f8,0x0003003e,0x000002f9,0x0000011e,0x00070039, + 0x00000009,0x000002fa,0x0000004a,0x00000054,0x000002f7,0x000002f9,0x0008000c,0x00000009, + 0x000002fb,0x00000001,0x00000032,0x000002c7,0x000002fa,0x000002cc,0x0003003e,0x000002f6, + 0x000002fb,0x00060041,0x0000012c,0x000002fc,0x00000098,0x0000009a,0x00000084,0x0004003d, + 0x00000009,0x000002fd,0x000002fc,0x0004007f,0x00000009,0x000002fe,0x000002fd,0x0004003d, + 0x00000009,0x000002ff,0x000002f6,0x00050041,0x00000036,0x00000300,0x00000055,0x00000084, + 0x0004003d,0x00000009,0x00000301,0x00000300,0x0008000c,0x00000009,0x00000302,0x00000001, + 0x00000032,0x000002fe,0x000002ff,0x00000301,0x000200fe,0x00000302,0x00010038,0x00050036, + 0x00000009,0x0000005d,0x00000000,0x0000004c,0x00030037,0x00000028,0x00000059,0x00030037, + 0x00000028,0x0000005a,0x00030037,0x0000000b,0x0000005b,0x00030037,0x00000036,0x0000005c, + 0x000200f8,0x0000005e,0x0004003b,0x0000000b,0x00000305,0x00000007,0x0004003b,0x00000036, + 0x00000326,0x00000007,0x0004003b,0x0000000b,0x00000327,0x00000007,0x0004003b,0x00000036, + 0x0000032a,0x00000007,0x0003003e,0x00000305,0x00000306,0x000200f9,0x00000307,0x000200f8, + 0x00000307,0x000400f6,0x00000309,0x0000030a,0x00000000,0x000200f9,0x0000030b,0x000200f8, + 0x0000030b,0x00050041,0x00000036,0x0000030c,0x0000005b,0x0000008d,0x0004003d,0x00000009, + 0x0000030d,0x0000030c,0x0004003d,0x00000009,0x0000030e,0x0000005c,0x000500ba,0x00000006, + 0x0000030f,0x0000030d,0x0000030e,0x000300f7,0x00000311,0x00000000,0x000400fa,0x0000030f, + 0x00000310,0x00000311,0x000200f8,0x00000310,0x00050041,0x00000036,0x00000312,0x00000305, + 0x00000084,0x0004003d,0x00000009,0x00000313,0x00000312,0x000500ba,0x00000006,0x00000314, + 0x00000313,0x000002b1,0x000200f9,0x00000311,0x000200f8,0x00000311,0x000700f5,0x00000006, + 0x00000315,0x0000030f,0x0000030b,0x00000314,0x00000310,0x000300f7,0x00000317,0x00000000, + 0x000400fa,0x00000315,0x00000316,0x00000317,0x000200f8,0x00000316,0x00050041,0x00000036, + 0x00000318,0x00000305,0x0000008d,0x0004003d,0x00000009,0x00000319,0x00000318,0x000500b4, + 0x00000006,0x0000031a,0x00000319,0x0000011a,0x000200f9,0x00000317,0x000200f8,0x00000317, + 0x000700f5,0x00000006,0x0000031b,0x00000315,0x00000311,0x0000031a,0x00000316,0x000400fa, + 0x0000031b,0x00000308,0x00000309,0x000200f8,0x00000308,0x0004003d,0x00000027,0x0000031c, + 0x00000059,0x0004003d,0x0000000a,0x0000031d,0x0000005b,0x00070058,0x00000012,0x0000031e, + 0x0000031c,0x0000031d,0x00000002,0x0000011a,0x0007004f,0x0000000a,0x0000031f,0x0000031e, + 0x0000031e,0x00000000,0x00000001,0x0003003e,0x00000305,0x0000031f,0x00050041,0x0000009b, + 0x00000321,0x00000098,0x0000009a,0x0004003d,0x00000012,0x00000322,0x00000321,0x0007004f, + 0x0000000a,0x00000323,0x00000322,0x00000322,0x00000000,0x00000001,0x0004003d,0x0000000a, + 0x00000324,0x0000005b,0x0008000c,0x0000000a,0x00000325,0x00000001,0x00000032,0x00000320, + 0x00000323,0x00000324,0x0003003e,0x0000005b,0x00000325,0x000200f9,0x0000030a,0x000200f8, + 0x0000030a,0x000200f9,0x00000307,0x000200f8,0x00000309,0x0004003d,0x0000000a,0x00000328, + 0x00000305,0x0007004f,0x0000000a,0x00000329,0x00000328,0x00000328,0x00000001,0x00000000, + 0x0003003e,0x00000327,0x00000329,0x0003003e,0x0000032a,0x0000011a,0x00070039,0x00000009, + 0x0000032b,0x0000004a,0x0000005a,0x00000327,0x0000032a,0x0008000c,0x00000009,0x0000032c, + 0x00000001,0x00000032,0x000002c7,0x0000032b,0x000002cc,0x0003003e,0x00000326,0x0000032c, + 0x00060041,0x0000012c,0x0000032d,0x00000098,0x0000009a,0x0000008d,0x0004003d,0x00000009, + 0x0000032e,0x0000032d,0x0004003d,0x00000009,0x0000032f,0x00000326,0x00050041,0x00000036, + 0x00000330,0x0000005b,0x0000008d,0x0004003d,0x00000009,0x00000331,0x00000330,0x0008000c, + 0x00000009,0x00000332,0x00000001,0x00000032,0x0000032e,0x0000032f,0x00000331,0x000200fe, + 0x00000332,0x00010038,0x00050036,0x00000009,0x00000063,0x00000000,0x0000004c,0x00030037, + 0x00000028,0x0000005f,0x00030037,0x00000028,0x00000060,0x00030037,0x0000000b,0x00000061, + 0x00030037,0x00000036,0x00000062,0x000200f8,0x00000064,0x0004003b,0x0000000b,0x00000335, + 0x00000007,0x0004003b,0x00000036,0x00000355,0x00000007,0x0004003b,0x0000000b,0x00000356, + 0x00000007,0x0004003b,0x00000036,0x00000359,0x00000007,0x0003003e,0x00000335,0x00000306, + 0x000200f9,0x00000336,0x000200f8,0x00000336,0x000400f6,0x00000338,0x00000339,0x00000000, + 0x000200f9,0x0000033a,0x000200f8,0x0000033a,0x00050041,0x00000036,0x0000033b,0x00000061, + 0x0000008d,0x0004003d,0x00000009,0x0000033c,0x0000033b,0x0004003d,0x00000009,0x0000033d, + 0x00000062,0x000500b8,0x00000006,0x0000033e,0x0000033c,0x0000033d,0x000300f7,0x00000340, + 0x00000000,0x000400fa,0x0000033e,0x0000033f,0x00000340,0x000200f8,0x0000033f,0x00050041, + 0x00000036,0x00000341,0x00000335,0x00000084,0x0004003d,0x00000009,0x00000342,0x00000341, + 0x000500ba,0x00000006,0x00000343,0x00000342,0x000002b1,0x000200f9,0x00000340,0x000200f8, + 0x00000340,0x000700f5,0x00000006,0x00000344,0x0000033e,0x0000033a,0x00000343,0x0000033f, + 0x000300f7,0x00000346,0x00000000,0x000400fa,0x00000344,0x00000345,0x00000346,0x000200f8, + 0x00000345,0x00050041,0x00000036,0x00000347,0x00000335,0x0000008d,0x0004003d,0x00000009, + 0x00000348,0x00000347,0x000500b4,0x00000006,0x00000349,0x00000348,0x0000011a,0x000200f9, + 0x00000346,0x000200f8,0x00000346,0x000700f5,0x00000006,0x0000034a,0x00000344,0x00000340, + 0x00000349,0x00000345,0x000400fa,0x0000034a,0x00000337,0x00000338,0x000200f8,0x00000337, + 0x0004003d,0x00000027,0x0000034b,0x0000005f,0x0004003d,0x0000000a,0x0000034c,0x00000061, + 0x00070058,0x00000012,0x0000034d,0x0000034b,0x0000034c,0x00000002,0x0000011a,0x0007004f, + 0x0000000a,0x0000034e,0x0000034d,0x0000034d,0x00000000,0x00000001,0x0003003e,0x00000335, + 0x0000034e,0x00050041,0x0000009b,0x00000350,0x00000098,0x0000009a,0x0004003d,0x00000012, + 0x00000351,0x00000350,0x0007004f,0x0000000a,0x00000352,0x00000351,0x00000351,0x00000000, + 0x00000001,0x0004003d,0x0000000a,0x00000353,0x00000061,0x0008000c,0x0000000a,0x00000354, + 0x00000001,0x00000032,0x0000034f,0x00000352,0x00000353,0x0003003e,0x00000061,0x00000354, + 0x000200f9,0x00000339,0x000200f8,0x00000339,0x000200f9,0x00000336,0x000200f8,0x00000338, + 0x0004003d,0x0000000a,0x00000357,0x00000335,0x0007004f,0x0000000a,0x00000358,0x00000357, + 0x00000357,0x00000001,0x00000000,0x0003003e,0x00000356,0x00000358,0x0003003e,0x00000359, + 0x0000011e,0x00070039,0x00000009,0x0000035a,0x0000004a,0x00000060,0x00000356,0x00000359, + 0x0008000c,0x00000009,0x0000035b,0x00000001,0x00000032,0x000002c7,0x0000035a,0x000002cc, + 0x0003003e,0x00000355,0x0000035b,0x00060041,0x0000012c,0x0000035c,0x00000098,0x0000009a, + 0x0000008d,0x0004003d,0x00000009,0x0000035d,0x0000035c,0x0004007f,0x00000009,0x0000035e, + 0x0000035d,0x0004003d,0x00000009,0x0000035f,0x00000355,0x00050041,0x00000036,0x00000360, + 0x00000061,0x0000008d,0x0004003d,0x00000009,0x00000361,0x00000360,0x0008000c,0x00000009, + 0x00000362,0x00000001,0x00000032,0x0000035e,0x0000035f,0x00000361,0x000200fe,0x00000362, + 0x00010038,0x00050036,0x0000000a,0x0000006b,0x00000000,0x00000065,0x00030037,0x00000028, + 0x00000066,0x00030037,0x0000000b,0x00000067,0x00030037,0x00000036,0x00000068,0x00030037, + 0x00000036,0x00000069,0x00030037,0x00000036,0x0000006a,0x000200f8,0x0000006c,0x0004003b, + 0x0000000b,0x00000365,0x00000007,0x0004003d,0x00000009,0x00000369,0x00000068,0x0004003d, + 0x00000009,0x0000036a,0x00000069,0x00050050,0x0000000a,0x0000036b,0x00000369,0x0000036a, + 0x0005008e,0x0000000a,0x0000036c,0x0000036b,0x00000368,0x0006000c,0x0000000a,0x0000036d, + 0x00000001,0x00000001,0x0000036c,0x0004003d,0x0000000a,0x0000036e,0x00000067,0x0008000c, + 0x0000000a,0x0000036f,0x00000001,0x00000032,0x00000367,0x0000036d,0x0000036e,0x0003003e, + 0x00000365,0x0000036f,0x0004003d,0x0000000a,0x00000370,0x00000365,0x0008000c,0x0000000a, + 0x00000371,0x00000001,0x00000032,0x0000016e,0x00000370,0x00000172,0x0003003e,0x00000365, + 0x00000371,0x0004003d,0x00000009,0x00000372,0x0000006a,0x00050041,0x00000036,0x00000373, + 0x00000365,0x0000008d,0x0004003d,0x00000009,0x00000374,0x00000373,0x0008000c,0x00000009, + 0x00000375,0x00000001,0x00000032,0x00000178,0x00000372,0x00000374,0x00050041,0x00000036, + 0x00000376,0x00000365,0x0000008d,0x0003003e,0x00000376,0x00000375,0x0004003d,0x00000027, + 0x00000377,0x00000066,0x0004003d,0x0000000a,0x00000378,0x00000365,0x00070058,0x00000012, + 0x00000379,0x00000377,0x00000378,0x00000002,0x0000011a,0x0007004f,0x0000000a,0x0000037a, + 0x00000379,0x00000379,0x00000000,0x00000001,0x000200fe,0x0000037a,0x00010038,0x00050036, + 0x00000002,0x00000072,0x00000000,0x0000006d,0x00030037,0x00000028,0x0000006e,0x00030037, + 0x0000000b,0x0000006f,0x00030037,0x00000021,0x00000070,0x00030037,0x0000000b,0x00000071, + 0x000200f8,0x00000073,0x0004003b,0x0000000b,0x0000037d,0x00000007,0x0004003b,0x0000000b, + 0x00000382,0x00000007,0x0004003b,0x0000000b,0x0000038e,0x00000007,0x0004003d,0x0000000a, + 0x0000037e,0x00000071,0x0004003d,0x0000000a,0x0000037f,0x00000071,0x0007004f,0x0000000a, + 0x00000380,0x0000037f,0x0000037f,0x00000001,0x00000000,0x0007000c,0x0000000a,0x00000381, + 0x00000001,0x00000030,0x0000037e,0x00000380,0x0003003e,0x0000037d,0x00000381,0x0004003d, + 0x0000000a,0x00000384,0x0000037d,0x0005008e,0x0000000a,0x00000385,0x00000384,0x00000383, + 0x0003003e,0x00000382,0x00000385,0x00050041,0x00000036,0x00000386,0x0000037d,0x00000084, + 0x0004003d,0x00000009,0x00000387,0x00000386,0x00050041,0x00000036,0x00000388,0x0000037d, + 0x0000008d,0x0004003d,0x00000009,0x00000389,0x00000388,0x00050081,0x00000009,0x0000038a, + 0x00000387,0x00000389,0x0004003d,0x0000000a,0x0000038b,0x00000382,0x00050050,0x0000000a, + 0x0000038c,0x0000038a,0x0000038a,0x00050088,0x0000000a,0x0000038d,0x0000038b,0x0000038c, + 0x0003003e,0x00000382,0x0000038d,0x0003003e,0x0000038e,0x00000219,0x00050041,0x00000036, + 0x0000038f,0x00000382,0x00000084,0x0004003d,0x00000009,0x00000390,0x0000038f,0x0004003d, + 0x00000027,0x00000391,0x0000006e,0x0004003d,0x00000012,0x00000392,0x00000070,0x0007004f, + 0x0000000a,0x00000393,0x00000392,0x00000392,0x00000000,0x00000001,0x00080058,0x00000012, + 0x00000395,0x00000391,0x00000393,0x0000000a,0x0000011a,0x00000394,0x00050051,0x00000009, + 0x00000396,0x00000395,0x00000000,0x00050085,0x00000009,0x00000397,0x00000390,0x00000396, + 0x00050041,0x00000036,0x00000398,0x0000038e,0x00000084,0x0004003d,0x00000009,0x00000399, + 0x00000398,0x00050083,0x00000009,0x0000039a,0x00000399,0x00000397,0x00050041,0x00000036, + 0x0000039b,0x0000038e,0x00000084,0x0003003e,0x0000039b,0x0000039a,0x00050041,0x00000036, + 0x0000039c,0x00000382,0x0000008d,0x0004003d,0x00000009,0x0000039d,0x0000039c,0x0004003d, + 0x00000027,0x0000039e,0x0000006e,0x0004003d,0x00000012,0x0000039f,0x00000070,0x0007004f, + 0x0000000a,0x000003a0,0x0000039f,0x0000039f,0x00000002,0x00000003,0x00080058,0x00000012, + 0x000003a2,0x0000039e,0x000003a0,0x0000000a,0x0000011a,0x000003a1,0x00050051,0x00000009, + 0x000003a3,0x000003a2,0x00000000,0x00050085,0x00000009,0x000003a4,0x0000039d,0x000003a3, + 0x00050041,0x00000036,0x000003a5,0x0000038e,0x00000084,0x0004003d,0x00000009,0x000003a6, + 0x000003a5,0x00050083,0x00000009,0x000003a7,0x000003a6,0x000003a4,0x00050041,0x00000036, + 0x000003a8,0x0000038e,0x00000084,0x0003003e,0x000003a8,0x000003a7,0x00050041,0x00000036, + 0x000003a9,0x00000382,0x00000084,0x0004003d,0x00000009,0x000003aa,0x000003a9,0x0004003d, + 0x00000027,0x000003ab,0x0000006e,0x0004003d,0x00000012,0x000003ac,0x00000070,0x0007004f, + 0x0000000a,0x000003ad,0x000003ac,0x000003ac,0x00000000,0x00000001,0x00080058,0x00000012, + 0x000003b0,0x000003ab,0x000003ad,0x0000000a,0x0000011a,0x000003af,0x00050051,0x00000009, + 0x000003b1,0x000003b0,0x00000000,0x00050085,0x00000009,0x000003b2,0x000003aa,0x000003b1, + 0x00050041,0x00000036,0x000003b3,0x0000038e,0x0000008d,0x0004003d,0x00000009,0x000003b4, + 0x000003b3,0x00050083,0x00000009,0x000003b5,0x000003b4,0x000003b2,0x00050041,0x00000036, + 0x000003b6,0x0000038e,0x0000008d,0x0003003e,0x000003b6,0x000003b5,0x00050041,0x00000036, + 0x000003b7,0x00000382,0x0000008d,0x0004003d,0x00000009,0x000003b8,0x000003b7,0x0004003d, + 0x00000027,0x000003b9,0x0000006e,0x0004003d,0x00000012,0x000003ba,0x00000070,0x0007004f, + 0x0000000a,0x000003bb,0x000003ba,0x000003ba,0x00000002,0x00000003,0x00080058,0x00000012, + 0x000003bd,0x000003b9,0x000003bb,0x0000000a,0x0000011a,0x000003bc,0x00050051,0x00000009, + 0x000003be,0x000003bd,0x00000000,0x00050085,0x00000009,0x000003bf,0x000003b8,0x000003be, + 0x00050041,0x00000036,0x000003c0,0x0000038e,0x0000008d,0x0004003d,0x00000009,0x000003c1, + 0x000003c0,0x00050083,0x00000009,0x000003c2,0x000003c1,0x000003bf,0x00050041,0x00000036, + 0x000003c3,0x0000038e,0x0000008d,0x0003003e,0x000003c3,0x000003c2,0x0004003d,0x0000000a, + 0x000003c4,0x0000038e,0x00050050,0x0000000a,0x000003c5,0x0000011a,0x0000011a,0x00050050, + 0x0000000a,0x000003c6,0x000000ec,0x000000ec,0x0008000c,0x0000000a,0x000003c7,0x00000001, + 0x0000002b,0x000003c4,0x000003c5,0x000003c6,0x0004003d,0x0000000a,0x000003c8,0x0000006f, + 0x00050085,0x0000000a,0x000003c9,0x000003c8,0x000003c7,0x0003003e,0x0000006f,0x000003c9, + 0x000100fd,0x00010038,0x00050036,0x00000002,0x00000078,0x00000000,0x0000006d,0x00030037, + 0x00000028,0x00000074,0x00030037,0x0000000b,0x00000075,0x00030037,0x00000021,0x00000076, + 0x00030037,0x0000000b,0x00000077,0x000200f8,0x00000079,0x0004003b,0x0000000b,0x000003ca, + 0x00000007,0x0004003b,0x0000000b,0x000003cf,0x00000007,0x0004003b,0x0000000b,0x000003da, + 0x00000007,0x0004003d,0x0000000a,0x000003cb,0x00000077,0x0004003d,0x0000000a,0x000003cc, + 0x00000077,0x0007004f,0x0000000a,0x000003cd,0x000003cc,0x000003cc,0x00000001,0x00000000, + 0x0007000c,0x0000000a,0x000003ce,0x00000001,0x00000030,0x000003cb,0x000003cd,0x0003003e, + 0x000003ca,0x000003ce,0x0004003d,0x0000000a,0x000003d0,0x000003ca,0x0005008e,0x0000000a, + 0x000003d1,0x000003d0,0x00000383,0x0003003e,0x000003cf,0x000003d1,0x00050041,0x00000036, + 0x000003d2,0x000003ca,0x00000084,0x0004003d,0x00000009,0x000003d3,0x000003d2,0x00050041, + 0x00000036,0x000003d4,0x000003ca,0x0000008d,0x0004003d,0x00000009,0x000003d5,0x000003d4, + 0x00050081,0x00000009,0x000003d6,0x000003d3,0x000003d5,0x0004003d,0x0000000a,0x000003d7, + 0x000003cf,0x00050050,0x0000000a,0x000003d8,0x000003d6,0x000003d6,0x00050088,0x0000000a, + 0x000003d9,0x000003d7,0x000003d8,0x0003003e,0x000003cf,0x000003d9,0x0003003e,0x000003da, + 0x00000219,0x00050041,0x00000036,0x000003db,0x000003cf,0x00000084,0x0004003d,0x00000009, + 0x000003dc,0x000003db,0x0004003d,0x00000027,0x000003dd,0x00000074,0x0004003d,0x00000012, + 0x000003de,0x00000076,0x0007004f,0x0000000a,0x000003df,0x000003de,0x000003de,0x00000000, + 0x00000001,0x00080058,0x00000012,0x000003e0,0x000003dd,0x000003df,0x0000000a,0x0000011a, + 0x000001de,0x00050051,0x00000009,0x000003e1,0x000003e0,0x00000001,0x00050085,0x00000009, + 0x000003e2,0x000003dc,0x000003e1,0x00050041,0x00000036,0x000003e3,0x000003da,0x00000084, + 0x0004003d,0x00000009,0x000003e4,0x000003e3,0x00050083,0x00000009,0x000003e5,0x000003e4, + 0x000003e2,0x00050041,0x00000036,0x000003e6,0x000003da,0x00000084,0x0003003e,0x000003e6, + 0x000003e5,0x00050041,0x00000036,0x000003e7,0x000003cf,0x0000008d,0x0004003d,0x00000009, + 0x000003e8,0x000003e7,0x0004003d,0x00000027,0x000003e9,0x00000074,0x0004003d,0x00000012, + 0x000003ea,0x00000076,0x0007004f,0x0000000a,0x000003eb,0x000003ea,0x000003ea,0x00000002, + 0x00000003,0x00080058,0x00000012,0x000003ec,0x000003e9,0x000003eb,0x0000000a,0x0000011a, + 0x000003a1,0x00050051,0x00000009,0x000003ed,0x000003ec,0x00000001,0x00050085,0x00000009, + 0x000003ee,0x000003e8,0x000003ed,0x00050041,0x00000036,0x000003ef,0x000003da,0x00000084, + 0x0004003d,0x00000009,0x000003f0,0x000003ef,0x00050083,0x00000009,0x000003f1,0x000003f0, + 0x000003ee,0x00050041,0x00000036,0x000003f2,0x000003da,0x00000084,0x0003003e,0x000003f2, + 0x000003f1,0x00050041,0x00000036,0x000003f3,0x000003cf,0x00000084,0x0004003d,0x00000009, + 0x000003f4,0x000003f3,0x0004003d,0x00000027,0x000003f5,0x00000074,0x0004003d,0x00000012, + 0x000003f6,0x00000076,0x0007004f,0x0000000a,0x000003f7,0x000003f6,0x000003f6,0x00000000, + 0x00000001,0x00080058,0x00000012,0x000003f9,0x000003f5,0x000003f7,0x0000000a,0x0000011a, + 0x000003f8,0x00050051,0x00000009,0x000003fa,0x000003f9,0x00000001,0x00050085,0x00000009, + 0x000003fb,0x000003f4,0x000003fa,0x00050041,0x00000036,0x000003fc,0x000003da,0x0000008d, + 0x0004003d,0x00000009,0x000003fd,0x000003fc,0x00050083,0x00000009,0x000003fe,0x000003fd, + 0x000003fb,0x00050041,0x00000036,0x000003ff,0x000003da,0x0000008d,0x0003003e,0x000003ff, + 0x000003fe,0x00050041,0x00000036,0x00000400,0x000003cf,0x0000008d,0x0004003d,0x00000009, + 0x00000401,0x00000400,0x0004003d,0x00000027,0x00000402,0x00000074,0x0004003d,0x00000012, + 0x00000403,0x00000076,0x0007004f,0x0000000a,0x00000404,0x00000403,0x00000403,0x00000002, + 0x00000003,0x00080058,0x00000012,0x00000406,0x00000402,0x00000404,0x0000000a,0x0000011a, + 0x00000405,0x00050051,0x00000009,0x00000407,0x00000406,0x00000001,0x00050085,0x00000009, + 0x00000408,0x00000401,0x00000407,0x00050041,0x00000036,0x00000409,0x000003da,0x0000008d, + 0x0004003d,0x00000009,0x0000040a,0x00000409,0x00050083,0x00000009,0x0000040b,0x0000040a, + 0x00000408,0x00050041,0x00000036,0x0000040c,0x000003da,0x0000008d,0x0003003e,0x0000040c, + 0x0000040b,0x0004003d,0x0000000a,0x0000040d,0x000003da,0x00050050,0x0000000a,0x0000040e, + 0x0000011a,0x0000011a,0x00050050,0x0000000a,0x0000040f,0x000000ec,0x000000ec,0x0008000c, + 0x0000000a,0x00000410,0x00000001,0x0000002b,0x0000040d,0x0000040e,0x0000040f,0x0004003d, + 0x0000000a,0x00000411,0x00000075,0x00050085,0x0000000a,0x00000412,0x00000411,0x00000410, + 0x0003003e,0x00000075,0x00000412,0x000100fd,0x00010038,0x00050036,0x00000012,0x00000082, + 0x00000000,0x0000007a,0x00030037,0x0000000b,0x0000007b,0x00030037,0x0000000b,0x0000007c, + 0x00030037,0x00000016,0x0000007d,0x00030037,0x00000028,0x0000007e,0x00030037,0x00000028, + 0x0000007f,0x00030037,0x00000028,0x00000080,0x00030037,0x00000021,0x00000081,0x000200f8, + 0x00000083,0x0004003b,0x00000021,0x00000413,0x00000007,0x0004003b,0x0000000b,0x00000415, + 0x00000007,0x0004003b,0x0000000b,0x0000041f,0x00000007,0x0004003b,0x0000000b,0x00000421, + 0x00000007,0x0004003b,0x00000021,0x00000423,0x00000007,0x0004003b,0x000000f1,0x00000432, + 0x00000007,0x0004003b,0x0000000b,0x00000433,0x00000007,0x0004003b,0x00000036,0x00000437, + 0x00000007,0x0004003b,0x0000000b,0x0000043f,0x00000007,0x0004003b,0x00000036,0x00000443, + 0x00000007,0x0004003b,0x0000000b,0x00000449,0x00000007,0x0004003b,0x00000036,0x0000044d, + 0x00000007,0x0004003b,0x0000000b,0x0000045f,0x00000007,0x0004003b,0x00000036,0x00000462, + 0x00000007,0x0004003b,0x0000000b,0x00000468,0x00000007,0x0004003b,0x00000036,0x0000046a, + 0x00000007,0x0004003b,0x00000036,0x0000046c,0x00000007,0x0004003b,0x00000036,0x0000046e, + 0x00000007,0x0004003b,0x0000000b,0x00000479,0x00000007,0x0004003b,0x00000021,0x0000047c, + 0x00000007,0x0004003b,0x0000000b,0x0000047f,0x00000007,0x0004003b,0x000000f1,0x0000048e, + 0x00000007,0x0004003b,0x0000000b,0x0000048f,0x00000007,0x0004003b,0x00000036,0x00000493, + 0x00000007,0x0004003b,0x0000000b,0x0000049b,0x00000007,0x0004003b,0x00000036,0x0000049f, + 0x00000007,0x0004003b,0x0000000b,0x000004a5,0x00000007,0x0004003b,0x00000036,0x000004a9, + 0x00000007,0x0004003b,0x0000000b,0x000004bb,0x00000007,0x0004003b,0x00000036,0x000004be, + 0x00000007,0x0004003b,0x0000000b,0x000004c4,0x00000007,0x0004003b,0x00000036,0x000004c6, + 0x00000007,0x0004003b,0x00000036,0x000004c8,0x00000007,0x0004003b,0x00000036,0x000004ca, + 0x00000007,0x0004003b,0x0000000b,0x000004d5,0x00000007,0x0004003b,0x00000021,0x000004d8, + 0x00000007,0x0004003b,0x0000000b,0x000004db,0x00000007,0x0003003e,0x00000413,0x00000414, + 0x0004003d,0x00000027,0x00000416,0x0000007e,0x0004003d,0x0000000a,0x00000417,0x0000007b, + 0x00050057,0x00000012,0x00000418,0x00000416,0x00000417,0x0007004f,0x0000000a,0x00000419, + 0x00000418,0x00000418,0x00000000,0x00000001,0x0003003e,0x00000415,0x00000419,0x00050041, + 0x00000036,0x0000041a,0x00000415,0x0000008d,0x0004003d,0x00000009,0x0000041b,0x0000041a, + 0x000500ba,0x00000006,0x0000041c,0x0000041b,0x0000011a,0x000300f7,0x0000041e,0x00000000, + 0x000400fa,0x0000041c,0x0000041d,0x0000041e,0x000200f8,0x0000041d,0x0004003d,0x0000000a, + 0x00000420,0x0000007b,0x0003003e,0x0000041f,0x00000420,0x0004003d,0x0000000a,0x00000422, + 0x00000415,0x0003003e,0x00000421,0x00000422,0x0004003d,0x00000012,0x00000424,0x00000081, + 0x0003003e,0x00000423,0x00000424,0x00090039,0x0000000a,0x00000425,0x00000044,0x0000007e, + 0x0000007f,0x0000041f,0x00000421,0x00000423,0x00050041,0x00000036,0x00000426,0x00000413, + 0x00000084,0x00050051,0x00000009,0x00000427,0x00000425,0x00000000,0x0003003e,0x00000426, + 0x00000427,0x00050041,0x00000036,0x00000428,0x00000413,0x0000008d,0x00050051,0x00000009, + 0x00000429,0x00000425,0x00000001,0x0003003e,0x00000428,0x00000429,0x00050041,0x00000036, + 0x0000042a,0x00000413,0x00000084,0x0004003d,0x00000009,0x0000042b,0x0000042a,0x00050041, + 0x00000036,0x0000042c,0x00000413,0x0000008d,0x0004003d,0x00000009,0x0000042d,0x0000042c, + 0x0004007f,0x00000009,0x0000042e,0x0000042d,0x000500b4,0x00000006,0x0000042f,0x0000042b, + 0x0000042e,0x000300f7,0x00000431,0x00000000,0x000400fa,0x0000042f,0x00000430,0x00000487, + 0x000200f8,0x00000430,0x00050041,0x00000021,0x00000434,0x0000007d,0x000000a0,0x0004003d, + 0x00000012,0x00000435,0x00000434,0x0007004f,0x0000000a,0x00000436,0x00000435,0x00000435, + 0x00000000,0x00000001,0x0003003e,0x00000433,0x00000436,0x00060041,0x00000036,0x00000438, + 0x0000007d,0x000000b4,0x00000084,0x0004003d,0x00000009,0x00000439,0x00000438,0x0003003e, + 0x00000437,0x00000439,0x00080039,0x00000009,0x0000043a,0x00000051,0x0000007e,0x00000080, + 0x00000433,0x00000437,0x00050041,0x00000036,0x0000043b,0x00000432,0x00000084,0x0003003e, + 0x0000043b,0x0000043a,0x00060041,0x00000036,0x0000043c,0x0000007d,0x0000009a,0x0000008d, + 0x0004003d,0x00000009,0x0000043d,0x0000043c,0x00050041,0x00000036,0x0000043e,0x00000432, + 0x0000008d,0x0003003e,0x0000043e,0x0000043d,0x00050041,0x00000036,0x00000440,0x00000432, + 0x00000084,0x0004003d,0x00000009,0x00000441,0x00000440,0x00050041,0x00000036,0x00000442, + 0x0000043f,0x00000084,0x0003003e,0x00000442,0x00000441,0x0004003d,0x00000027,0x00000444, + 0x0000007e,0x0004003d,0x000000f0,0x00000445,0x00000432,0x0007004f,0x0000000a,0x00000446, + 0x00000445,0x00000445,0x00000000,0x00000001,0x00070058,0x00000012,0x00000447,0x00000444, + 0x00000446,0x00000002,0x0000011a,0x00050051,0x00000009,0x00000448,0x00000447,0x00000000, + 0x0003003e,0x00000443,0x00000448,0x00050041,0x00000021,0x0000044a,0x0000007d,0x000000a0, + 0x0004003d,0x00000012,0x0000044b,0x0000044a,0x0007004f,0x0000000a,0x0000044c,0x0000044b, + 0x0000044b,0x00000002,0x00000003,0x0003003e,0x00000449,0x0000044c,0x00060041,0x00000036, + 0x0000044e,0x0000007d,0x000000b4,0x0000008d,0x0004003d,0x00000009,0x0000044f,0x0000044e, + 0x0003003e,0x0000044d,0x0000044f,0x00080039,0x00000009,0x00000450,0x00000057,0x0000007e, + 0x00000080,0x00000449,0x0000044d,0x00050041,0x00000036,0x00000451,0x00000432,0x000000e2, + 0x0003003e,0x00000451,0x00000450,0x00050041,0x00000036,0x00000452,0x00000432,0x000000e2, + 0x0004003d,0x00000009,0x00000453,0x00000452,0x00050041,0x00000036,0x00000454,0x0000043f, + 0x0000008d,0x0003003e,0x00000454,0x00000453,0x00050041,0x0000009b,0x00000455,0x00000098, + 0x0000009a,0x0004003d,0x00000012,0x00000456,0x00000455,0x0007004f,0x0000000a,0x00000457, + 0x00000456,0x00000456,0x00000002,0x00000002,0x0004003d,0x0000000a,0x00000458,0x0000043f, + 0x0004003d,0x0000000a,0x00000459,0x0000007c,0x0007004f,0x0000000a,0x0000045a,0x00000459, + 0x00000459,0x00000000,0x00000000,0x0004007f,0x0000000a,0x0000045b,0x0000045a,0x0008000c, + 0x0000000a,0x0000045c,0x00000001,0x00000032,0x00000457,0x00000458,0x0000045b,0x0006000c, + 0x0000000a,0x0000045d,0x00000001,0x00000001,0x0000045c,0x0006000c,0x0000000a,0x0000045e, + 0x00000001,0x00000004,0x0000045d,0x0003003e,0x0000043f,0x0000045e,0x0004003d,0x0000000a, + 0x00000460,0x0000043f,0x0006000c,0x0000000a,0x00000461,0x00000001,0x0000001f,0x00000460, + 0x0003003e,0x0000045f,0x00000461,0x0004003d,0x00000027,0x00000463,0x0000007e,0x0004003d, + 0x000000f0,0x00000464,0x00000432,0x0007004f,0x0000000a,0x00000465,0x00000464,0x00000464, + 0x00000002,0x00000001,0x00080058,0x00000012,0x00000466,0x00000463,0x00000465,0x0000000a, + 0x0000011a,0x000001de,0x00050051,0x00000009,0x00000467,0x00000466,0x00000000,0x0003003e, + 0x00000462,0x00000467,0x0004003d,0x0000000a,0x00000469,0x0000045f,0x0003003e,0x00000468, + 0x00000469,0x0004003d,0x00000009,0x0000046b,0x00000443,0x0003003e,0x0000046a,0x0000046b, + 0x0004003d,0x00000009,0x0000046d,0x00000462,0x0003003e,0x0000046c,0x0000046d,0x00050041, + 0x00000036,0x0000046f,0x00000081,0x0000008d,0x0004003d,0x00000009,0x00000470,0x0000046f, + 0x0003003e,0x0000046e,0x00000470,0x00090039,0x0000000a,0x00000471,0x0000006b,0x0000007f, + 0x00000468,0x0000046a,0x0000046c,0x0000046e,0x00050041,0x00000036,0x00000472,0x00000413, + 0x00000084,0x00050051,0x00000009,0x00000473,0x00000471,0x00000000,0x0003003e,0x00000472, + 0x00000473,0x00050041,0x00000036,0x00000474,0x00000413,0x0000008d,0x00050051,0x00000009, + 0x00000475,0x00000471,0x00000001,0x0003003e,0x00000474,0x00000475,0x00050041,0x00000036, + 0x00000476,0x0000007b,0x0000008d,0x0004003d,0x00000009,0x00000477,0x00000476,0x00050041, + 0x00000036,0x00000478,0x00000432,0x0000008d,0x0003003e,0x00000478,0x00000477,0x0004003d, + 0x00000012,0x0000047a,0x00000413,0x0007004f,0x0000000a,0x0000047b,0x0000047a,0x0000047a, + 0x00000000,0x00000001,0x0003003e,0x00000479,0x0000047b,0x0004003d,0x000000f0,0x0000047d, + 0x00000432,0x0009004f,0x00000012,0x0000047e,0x0000047d,0x0000047d,0x00000000,0x00000001, + 0x00000002,0x00000001,0x0003003e,0x0000047c,0x0000047e,0x0004003d,0x0000000a,0x00000480, + 0x0000043f,0x0003003e,0x0000047f,0x00000480,0x00080039,0x00000002,0x00000481,0x00000072, + 0x0000007e,0x00000479,0x0000047c,0x0000047f,0x0004003d,0x0000000a,0x00000482,0x00000479, + 0x00050041,0x00000036,0x00000483,0x00000413,0x00000084,0x00050051,0x00000009,0x00000484, + 0x00000482,0x00000000,0x0003003e,0x00000483,0x00000484,0x00050041,0x00000036,0x00000485, + 0x00000413,0x0000008d,0x00050051,0x00000009,0x00000486,0x00000482,0x00000001,0x0003003e, + 0x00000485,0x00000486,0x000200f9,0x00000431,0x000200f8,0x00000487,0x00050041,0x00000036, + 0x00000488,0x00000415,0x00000084,0x0003003e,0x00000488,0x0000011a,0x000200f9,0x00000431, + 0x000200f8,0x00000431,0x000200f9,0x0000041e,0x000200f8,0x0000041e,0x00050041,0x00000036, + 0x00000489,0x00000415,0x00000084,0x0004003d,0x00000009,0x0000048a,0x00000489,0x000500ba, + 0x00000006,0x0000048b,0x0000048a,0x0000011a,0x000300f7,0x0000048d,0x00000000,0x000400fa, + 0x0000048b,0x0000048c,0x0000048d,0x000200f8,0x0000048c,0x00050041,0x00000021,0x00000490, + 0x0000007d,0x0000009a,0x0004003d,0x00000012,0x00000491,0x00000490,0x0007004f,0x0000000a, + 0x00000492,0x00000491,0x00000491,0x00000000,0x00000001,0x0003003e,0x0000048f,0x00000492, + 0x00060041,0x00000036,0x00000494,0x0000007d,0x000000b4,0x000000e2,0x0004003d,0x00000009, + 0x00000495,0x00000494,0x0003003e,0x00000493,0x00000495,0x00080039,0x00000009,0x00000496, + 0x0000005d,0x0000007e,0x00000080,0x0000048f,0x00000493,0x00050041,0x00000036,0x00000497, + 0x0000048e,0x0000008d,0x0003003e,0x00000497,0x00000496,0x00060041,0x00000036,0x00000498, + 0x0000007d,0x000000a0,0x00000084,0x0004003d,0x00000009,0x00000499,0x00000498,0x00050041, + 0x00000036,0x0000049a,0x0000048e,0x00000084,0x0003003e,0x0000049a,0x00000499,0x00050041, + 0x00000036,0x0000049c,0x0000048e,0x0000008d,0x0004003d,0x00000009,0x0000049d,0x0000049c, + 0x00050041,0x00000036,0x0000049e,0x0000049b,0x00000084,0x0003003e,0x0000049e,0x0000049d, + 0x0004003d,0x00000027,0x000004a0,0x0000007e,0x0004003d,0x000000f0,0x000004a1,0x0000048e, + 0x0007004f,0x0000000a,0x000004a2,0x000004a1,0x000004a1,0x00000000,0x00000001,0x00070058, + 0x00000012,0x000004a3,0x000004a0,0x000004a2,0x00000002,0x0000011a,0x00050051,0x00000009, + 0x000004a4,0x000004a3,0x00000001,0x0003003e,0x0000049f,0x000004a4,0x00050041,0x00000021, + 0x000004a6,0x0000007d,0x0000009a,0x0004003d,0x00000012,0x000004a7,0x000004a6,0x0007004f, + 0x0000000a,0x000004a8,0x000004a7,0x000004a7,0x00000002,0x00000003,0x0003003e,0x000004a5, + 0x000004a8,0x00060041,0x00000036,0x000004aa,0x0000007d,0x000000b4,0x00000014,0x0004003d, + 0x00000009,0x000004ab,0x000004aa,0x0003003e,0x000004a9,0x000004ab,0x00080039,0x00000009, + 0x000004ac,0x00000063,0x0000007e,0x00000080,0x000004a5,0x000004a9,0x00050041,0x00000036, + 0x000004ad,0x0000048e,0x000000e2,0x0003003e,0x000004ad,0x000004ac,0x00050041,0x00000036, + 0x000004ae,0x0000048e,0x000000e2,0x0004003d,0x00000009,0x000004af,0x000004ae,0x00050041, + 0x00000036,0x000004b0,0x0000049b,0x0000008d,0x0003003e,0x000004b0,0x000004af,0x00050041, + 0x0000009b,0x000004b1,0x00000098,0x0000009a,0x0004003d,0x00000012,0x000004b2,0x000004b1, + 0x0007004f,0x0000000a,0x000004b3,0x000004b2,0x000004b2,0x00000003,0x00000003,0x0004003d, + 0x0000000a,0x000004b4,0x0000049b,0x0004003d,0x0000000a,0x000004b5,0x0000007c,0x0007004f, + 0x0000000a,0x000004b6,0x000004b5,0x000004b5,0x00000001,0x00000001,0x0004007f,0x0000000a, + 0x000004b7,0x000004b6,0x0008000c,0x0000000a,0x000004b8,0x00000001,0x00000032,0x000004b3, + 0x000004b4,0x000004b7,0x0006000c,0x0000000a,0x000004b9,0x00000001,0x00000001,0x000004b8, + 0x0006000c,0x0000000a,0x000004ba,0x00000001,0x00000004,0x000004b9,0x0003003e,0x0000049b, + 0x000004ba,0x0004003d,0x0000000a,0x000004bc,0x0000049b,0x0006000c,0x0000000a,0x000004bd, + 0x00000001,0x0000001f,0x000004bc,0x0003003e,0x000004bb,0x000004bd,0x0004003d,0x00000027, + 0x000004bf,0x0000007e,0x0004003d,0x000000f0,0x000004c0,0x0000048e,0x0007004f,0x0000000a, + 0x000004c1,0x000004c0,0x000004c0,0x00000000,0x00000002,0x00080058,0x00000012,0x000004c2, + 0x000004bf,0x000004c1,0x0000000a,0x0000011a,0x00000394,0x00050051,0x00000009,0x000004c3, + 0x000004c2,0x00000001,0x0003003e,0x000004be,0x000004c3,0x0004003d,0x0000000a,0x000004c5, + 0x000004bb,0x0003003e,0x000004c4,0x000004c5,0x0004003d,0x00000009,0x000004c7,0x0000049f, + 0x0003003e,0x000004c6,0x000004c7,0x0004003d,0x00000009,0x000004c9,0x000004be,0x0003003e, + 0x000004c8,0x000004c9,0x00050041,0x00000036,0x000004cb,0x00000081,0x00000084,0x0004003d, + 0x00000009,0x000004cc,0x000004cb,0x0003003e,0x000004ca,0x000004cc,0x00090039,0x0000000a, + 0x000004cd,0x0000006b,0x0000007f,0x000004c4,0x000004c6,0x000004c8,0x000004ca,0x00050041, + 0x00000036,0x000004ce,0x00000413,0x000000e2,0x00050051,0x00000009,0x000004cf,0x000004cd, + 0x00000000,0x0003003e,0x000004ce,0x000004cf,0x00050041,0x00000036,0x000004d0,0x00000413, + 0x00000014,0x00050051,0x00000009,0x000004d1,0x000004cd,0x00000001,0x0003003e,0x000004d0, + 0x000004d1,0x00050041,0x00000036,0x000004d2,0x0000007b,0x00000084,0x0004003d,0x00000009, + 0x000004d3,0x000004d2,0x00050041,0x00000036,0x000004d4,0x0000048e,0x00000084,0x0003003e, + 0x000004d4,0x000004d3,0x0004003d,0x00000012,0x000004d6,0x00000413,0x0007004f,0x0000000a, + 0x000004d7,0x000004d6,0x000004d6,0x00000002,0x00000003,0x0003003e,0x000004d5,0x000004d7, + 0x0004003d,0x000000f0,0x000004d9,0x0000048e,0x0009004f,0x00000012,0x000004da,0x000004d9, + 0x000004d9,0x00000000,0x00000001,0x00000000,0x00000002,0x0003003e,0x000004d8,0x000004da, + 0x0004003d,0x0000000a,0x000004dc,0x0000049b,0x0003003e,0x000004db,0x000004dc,0x00080039, + 0x00000002,0x000004dd,0x00000078,0x0000007e,0x000004d5,0x000004d8,0x000004db,0x0004003d, + 0x0000000a,0x000004de,0x000004d5,0x00050041,0x00000036,0x000004df,0x00000413,0x000000e2, + 0x00050051,0x00000009,0x000004e0,0x000004de,0x00000000,0x0003003e,0x000004df,0x000004e0, + 0x00050041,0x00000036,0x000004e1,0x00000413,0x00000014,0x00050051,0x00000009,0x000004e2, + 0x000004de,0x00000001,0x0003003e,0x000004e1,0x000004e2,0x000200f9,0x0000048d,0x000200f8, + 0x0000048d,0x0004003d,0x00000012,0x000004e3,0x00000413,0x000200fe,0x000004e3,0x00010038 }; diff --git a/app/src/main/cpp/waylandcomp/src/effects_chain.c b/app/src/main/cpp/waylandcomp/src/effects_chain.c index 6d307dcd7d..90423d2441 100644 --- a/app/src/main/cpp/waylandcomp/src/effects_chain.c +++ b/app/src/main/cpp/waylandcomp/src/effects_chain.c @@ -22,6 +22,7 @@ #include "smaa_edge_frag.h" #include "smaa_weights_frag.h" #include "smaa_blend_frag.h" +#include "smaa_tables.h" #include "toon_frag.h" #include "toon_color_frag.h" #include "hdr_frag.h" @@ -196,6 +197,7 @@ struct pc_sgsr { float ndc[4]; float vp[4]; float edge; }; struct pc_easu { float ndc[4]; uint32_t con0[4], con1[4], con2[4], con3[4]; float outW, outH; }; struct pc_rcas { float ndc[4]; uint32_t con[4]; float outW, outH; }; struct pc_res { float ndc[4]; float res[2]; float extra; float pad; }; +struct pc_smaa { float ndc[4]; float metrics[4]; }; struct pc_color { float ndc[4]; float b, c, g, s; }; struct pc_toon_color { float ndc[4]; float res[2]; float b, c, g, s; @@ -230,7 +232,7 @@ static VkDevice g_dev; static VkPhysicalDevice g_pd; static VkPhysicalDeviceMemoryProperties g_mp; static int g_ready; -static VkRenderPass g_rp, g_smaa_rp; +static VkRenderPass g_rp, g_smaa_edge_rp, g_smaa_weights_rp; static VkDescriptorSetLayout g_dsl; static VkPipelineLayout g_pl; static VkDescriptorPool g_dpool; @@ -247,7 +249,9 @@ static int g_context; #define g_t (g_contexts[g_context].targets) #define g_mid (g_contexts[g_context].mid) #define g_nissrc (g_contexts[g_context].nissrc) -static struct fx_target g_smaa_edges, g_smaa_weights; +static struct fx_target g_smaa_edges, g_smaa_weights, g_smaa_area, g_smaa_search; +static VkBuffer g_smaa_buf; +static VkDeviceMemory g_smaa_mem; /* Half set: NIS = nis_luma prepass (scene rgb + luma in alpha, scene size) into g_nissrc, then * nis3 gathers its luma from that alpha, its coefficient banks (nis_coef.h) in a uniform buffer * at descriptor set 1 (g_pl_nis = {g_dsl, g_coef_dsl}, same push-constant range as g_pl). @@ -311,6 +315,7 @@ static void target_destroy(struct fx_target *t) { #define FX_TARGET_USAGE (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | \ VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT) #define FX_SCRATCH_USAGE (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT) +#define SMAA_EDGE_FORMAT VK_FORMAT_R8G8_UNORM static int target_ensure_format(struct fx_target *t, int w, int h, VkImageUsageFlags usage, const char *what, @@ -318,8 +323,9 @@ static int target_ensure_format(struct fx_target *t, int w, int h, if (t->img && t->w == w && t->h == h) return 0; target_destroy(t); VkImageCreateInfo ii = {.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, - .flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT, .imageType = VK_IMAGE_TYPE_2D, - .format = format, .extent = {(uint32_t)w, (uint32_t)h, 1}, .mipLevels = 1, + /* SMAA's own images need no views in other formats, and the GPU is faster without the flag. */ + .flags = render_pass == g_rp ? VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT : 0, + .imageType = VK_IMAGE_TYPE_2D, .format = format, .extent = {(uint32_t)w, (uint32_t)h, 1}, .mipLevels = 1, .arrayLayers = 1, .samples = VK_SAMPLE_COUNT_1_BIT, .tiling = VK_IMAGE_TILING_OPTIMAL, .usage = usage, .sharingMode = VK_SHARING_MODE_EXCLUSIVE, .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED}; @@ -337,12 +343,16 @@ static int target_ensure_format(struct fx_target *t, int w, int h, (unsigned long long)req.size, (int)r); target_destroy(t); return -1; } - g_vk.BindImageMemory(g_dev, t->img, t->mem, 0); + r = g_vk.BindImageMemory(g_dev, t->img, t->mem, 0); + if (r != VK_SUCCESS) { + droiddeck_log("error", "effects: %s image %dx%d: vkBindImageMemory %d", what, w, h, (int)r); + target_destroy(t); return -1; + } if (!(t->view = make_view(t->img, format))) { target_destroy(t); return -1; } VkFramebufferCreateInfo fi = {.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, .renderPass = render_pass, .attachmentCount = 1, .pAttachments = &t->view, .width = (uint32_t)w, .height = (uint32_t)h, .layers = 1}; - if (g_vk.CreateFramebuffer(g_dev, &fi, NULL, &t->fb) != VK_SUCCESS) { target_destroy(t); return -1; } + if (render_pass && g_vk.CreateFramebuffer(g_dev, &fi, NULL, &t->fb) != VK_SUCCESS) { target_destroy(t); return -1; } if (!(t->ds = alloc_ds(t->view))) { target_destroy(t); return -1; } t->w = w; t->h = h; return 0; @@ -461,6 +471,22 @@ static VkPipeline post_pipeline_for_renderpass(VkShaderModule vert, return p; } +/* The mapped memory of a new host-visible buffer. On failure: NULL, and the caller frees what there is. */ +static void *host_buffer(VkDeviceSize size, VkBufferUsageFlags usage, VkBuffer *buf, VkDeviceMemory *mem) { + VkBufferCreateInfo bci = {.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, .size = size, + .usage = usage, .sharingMode = VK_SHARING_MODE_EXCLUSIVE}; + if (g_vk.CreateBuffer(g_dev, &bci, NULL, buf) != VK_SUCCESS) return NULL; + VkMemoryRequirements req; + g_vk.GetBufferMemoryRequirements(g_dev, *buf, &req); + int idx = memtype(req.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); + if (idx < 0) return NULL; + VkMemoryAllocateInfo mai = {.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, .allocationSize = req.size, .memoryTypeIndex = (uint32_t)idx}; + if (g_vk.AllocateMemory(g_dev, &mai, NULL, mem) != VK_SUCCESS) return NULL; + if (g_vk.BindBufferMemory(g_dev, *buf, *mem, 0) != VK_SUCCESS) return NULL; + void *p = NULL; + return g_vk.MapMemory(g_dev, *mem, 0, size, 0, &p) == VK_SUCCESS ? p : NULL; +} + static void coef_destroy(void) { if (g_coef_pool) g_vk.DestroyDescriptorPool(g_dev, g_coef_pool, NULL); /* frees g_coef_ds */ if (g_coef_buf) g_vk.DestroyBuffer(g_dev, g_coef_buf, NULL); @@ -482,18 +508,8 @@ static int coef_create(void) { VkPipelineLayoutCreateInfo pli = {.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, .setLayoutCount = 2, .pSetLayouts = sets, .pushConstantRangeCount = 1, .pPushConstantRanges = &pcr}; if (g_vk.CreatePipelineLayout(g_dev, &pli, NULL, &g_pl_nis) != VK_SUCCESS) goto fail; - VkBufferCreateInfo bci = {.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, .size = 4096, - .usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, .sharingMode = VK_SHARING_MODE_EXCLUSIVE}; - if (g_vk.CreateBuffer(g_dev, &bci, NULL, &g_coef_buf) != VK_SUCCESS) goto fail; - VkMemoryRequirements req; - g_vk.GetBufferMemoryRequirements(g_dev, g_coef_buf, &req); - int idx = memtype(req.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); - if (idx < 0) goto fail; - VkMemoryAllocateInfo mai = {.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, .allocationSize = req.size, .memoryTypeIndex = (uint32_t)idx}; - if (g_vk.AllocateMemory(g_dev, &mai, NULL, &g_coef_mem) != VK_SUCCESS) goto fail; - if (g_vk.BindBufferMemory(g_dev, g_coef_buf, g_coef_mem, 0) != VK_SUCCESS) goto fail; - void *p = NULL; - if (g_vk.MapMemory(g_dev, g_coef_mem, 0, 4096, 0, &p) != VK_SUCCESS || !p) goto fail; + void *p = host_buffer(4096, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, &g_coef_buf, &g_coef_mem); + if (!p) goto fail; memcpy(p, kNisCoefScale, sizeof(kNisCoefScale)); memcpy((char *)p + sizeof(kNisCoefScale), kNisCoefUsm, sizeof(kNisCoefUsm)); g_vk.UnmapMemory(g_dev, g_coef_mem); @@ -513,6 +529,29 @@ fail: return -1; } +static void smaa_tables_destroy(void) { + target_destroy(&g_smaa_area); target_destroy(&g_smaa_search); + if (g_smaa_buf) g_vk.DestroyBuffer(g_dev, g_smaa_buf, NULL); + if (g_smaa_mem) g_vk.FreeMemory(g_dev, g_smaa_mem, NULL); + g_smaa_buf = VK_NULL_HANDLE; g_smaa_mem = VK_NULL_HANDLE; +} + +static int smaa_tables_ensure(void) { + if (g_smaa_buf) return 0; + const VkImageUsageFlags usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT; + unsigned char *p = NULL; + if (target_ensure_format(&g_smaa_area, SMAA_AREA_W, SMAA_AREA_H, usage, "SMAA area table", + VK_FORMAT_R8G8_UNORM, VK_NULL_HANDLE) == 0 && + target_ensure_format(&g_smaa_search, SMAA_SEARCH_W, SMAA_SEARCH_H, usage, "SMAA search table", + VK_FORMAT_R8_UNORM, VK_NULL_HANDLE) == 0) + p = host_buffer(sizeof(kSmaaArea) + sizeof(kSmaaSearch), VK_BUFFER_USAGE_TRANSFER_SRC_BIT, &g_smaa_buf, &g_smaa_mem); + if (!p) { smaa_tables_destroy(); return -1; } + memcpy(p, kSmaaArea, sizeof(kSmaaArea)); + memcpy(p + sizeof(kSmaaArea), kSmaaSearch, sizeof(kSmaaSearch)); + g_vk.UnmapMemory(g_dev, g_smaa_mem); + return 0; +} + /* nis_luma keeps luma in the target's alpha: only formats with at least 8 alpha bits (not the * 2-bit alpha of the 10-bit HDR composition format) can hold it. */ static int fx_alpha_holds_luma(VkFormat f) { @@ -540,16 +579,19 @@ static void objects_destroy(void) { } g_context = saved; target_destroy(&g_smaa_edges); target_destroy(&g_smaa_weights); + smaa_tables_destroy(); for (int i = 0; i < P_COUNT; i++) { if (g_pipe[i]) g_vk.DestroyPipeline(g_dev, g_pipe[i], NULL); g_pipe[i] = VK_NULL_HANDLE; } if (g_dpool) g_vk.DestroyDescriptorPool(g_dev, g_dpool, NULL); if (g_pl) g_vk.DestroyPipelineLayout(g_dev, g_pl, NULL); coef_destroy(); if (g_dsl) g_vk.DestroyDescriptorSetLayout(g_dev, g_dsl, NULL); if (g_sampler) g_vk.DestroySampler(g_dev, g_sampler, NULL); - if (g_smaa_rp) g_vk.DestroyRenderPass(g_dev, g_smaa_rp, NULL); + if (g_smaa_edge_rp) g_vk.DestroyRenderPass(g_dev, g_smaa_edge_rp, NULL); + if (g_smaa_weights_rp) g_vk.DestroyRenderPass(g_dev, g_smaa_weights_rp, NULL); if (g_rp) g_vk.DestroyRenderPass(g_dev, g_rp, NULL); g_dpool = VK_NULL_HANDLE; g_pl = VK_NULL_HANDLE; g_dsl = VK_NULL_HANDLE; - g_sampler = VK_NULL_HANDLE; g_rp = VK_NULL_HANDLE; g_smaa_rp = VK_NULL_HANDLE; + g_sampler = VK_NULL_HANDLE; g_rp = VK_NULL_HANDLE; + g_smaa_edge_rp = VK_NULL_HANDLE; g_smaa_weights_rp = VK_NULL_HANDLE; g_nis_fast = 0; g_nis_attempted = 0; g_upscale_half = 0; g_ready = 0; } @@ -603,9 +645,12 @@ static int objects_ensure(void) { VkAttachmentDescription smaa_att = att; smaa_att.format = FX_FORMAT; + smaa_att.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; /* SMAA.hlsl discards pixels without an edge */ VkRenderPassCreateInfo smaa_rci = rci; smaa_rci.pAttachments = &smaa_att; - if (g_vk.CreateRenderPass(g_dev, &smaa_rci, NULL, &g_smaa_rp) != VK_SUCCESS) goto fail; + if (g_vk.CreateRenderPass(g_dev, &smaa_rci, NULL, &g_smaa_weights_rp) != VK_SUCCESS) goto fail; + smaa_att.format = SMAA_EDGE_FORMAT; + if (g_vk.CreateRenderPass(g_dev, &smaa_rci, NULL, &g_smaa_edge_rp) != VK_SUCCESS) goto fail; VkSamplerCreateInfo sci = {.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, .magFilter = VK_FILTER_LINEAR, .minFilter = VK_FILTER_LINEAR, .mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST, @@ -619,13 +664,13 @@ static int objects_ensure(void) { VkDescriptorSetLayoutCreateInfo dli = {.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, .bindingCount = 1, .pBindings = &b}; if (g_vk.CreateDescriptorSetLayout(g_dev, &dli, NULL, &g_dsl) != VK_SUCCESS) goto fail; VkPushConstantRange pcr = {.stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, .offset = 0, .size = PC_MAX_SIZE}; - VkDescriptorSetLayout set_layouts[2] = {g_dsl, g_dsl}; - VkPipelineLayoutCreateInfo pli = {.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, .setLayoutCount = 2, .pSetLayouts = set_layouts, + VkDescriptorSetLayout set_layouts[3] = {g_dsl, g_dsl, g_dsl}; + VkPipelineLayoutCreateInfo pli = {.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, .setLayoutCount = 3, .pSetLayouts = set_layouts, .pushConstantRangeCount = 1, .pPushConstantRanges = &pcr}; if (g_vk.CreatePipelineLayout(g_dev, &pli, NULL, &g_pl) != VK_SUCCESS) goto fail; - VkDescriptorPoolSize ps = {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, FX_CONTEXTS * 5 + 2}; + VkDescriptorPoolSize ps = {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, FX_CONTEXTS * 5 + 4}; VkDescriptorPoolCreateInfo dpi = {.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO, - .flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, .maxSets = FX_CONTEXTS * 5 + 2, + .flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, .maxSets = FX_CONTEXTS * 5 + 4, .poolSizeCount = 1, .pPoolSizes = &ps}; if (g_vk.CreateDescriptorPool(g_dev, &dpi, NULL, &g_dpool) != VK_SUCCESS) goto fail; @@ -712,8 +757,8 @@ static int pipelines_ensure(int spatial, const struct fx_settings *s) { if (s->color_on && !(s->toon && g_fx_fmt == FX_FORMAT)) MK(1, P_COLOR, color_code, "color"); if (s->aa_mode == 1 || s->aa_mode == 2) MK(1, P_FXAA, fxaa_code, "fxaa"); if (s->aa_mode == 2) { - MKL(1, P_SMAA_EDGE, smaa_edge_code, "smaa_edge", g_smaa_rp, g_pl); - MKL(1, P_SMAA_WEIGHTS, smaa_weights_code, "smaa_weights", g_smaa_rp, g_pl); + MKL(1, P_SMAA_EDGE, smaa_edge_code, "smaa_edge", g_smaa_edge_rp, g_pl); + MKL(1, P_SMAA_WEIGHTS, smaa_weights_code, "smaa_weights", g_smaa_weights_rp, g_pl); MK(1, P_SMAA_BLEND, smaa_blend_code, "smaa_blend"); } if (s->toon && s->color_on && g_fx_fmt == FX_FORMAT) MK(1, P_TOON_COLOR, toon_color_code, "toon_color"); @@ -742,14 +787,32 @@ static void barrier(VkCommandBuffer cmd, VkImage img, VkImageLayout from, VkImag g_vk.CmdPipelineBarrier(cmd, src_stage, dst_stage, 0, 0, NULL, 0, NULL, 1, &b); } -static void pass_renderpass(VkCommandBuffer cmd, VkRenderPass render_pass, - VkPipeline p, struct fx_target *dst, VkDescriptorSet src, - const void *pc, uint32_t pcsz) { +/* The tables are copied into place in every frame: a recorded frame can be dropped before it is submitted. */ +static void smaa_tables_copy(VkCommandBuffer cmd) { + const VkBufferImageCopy area = {.imageSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}, + .imageExtent = {SMAA_AREA_W, SMAA_AREA_ROWS, 1}}; + const VkBufferImageCopy search = {.bufferOffset = sizeof(kSmaaArea), .imageSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}, + .imageExtent = {SMAA_SEARCH_W, SMAA_SEARCH_H, 1}}; + const struct { VkImage img; const VkBufferImageCopy *copy; } t[2] = {{g_smaa_area.img, &area}, {g_smaa_search.img, &search}}; + for (int i = 0; i < 2; i++) { + barrier(cmd, t[i].img, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT); + g_vk.CmdCopyBufferToImage(cmd, g_smaa_buf, t[i].img, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, t[i].copy); + barrier(cmd, t[i].img, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, + VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT, + VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_ACCESS_SHADER_READ_BIT); + } +} + +static void pass_sets(VkCommandBuffer cmd, VkRenderPass render_pass, VkPipeline p, struct fx_target *dst, + const VkDescriptorSet *src, uint32_t count, const void *pc, uint32_t pcsz) { + const VkClearValue clear = {0}; VkRenderPassBeginInfo rpi = {.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, .renderPass = render_pass, .framebuffer = dst->fb, - .renderArea = {{0, 0}, {(uint32_t)dst->w, (uint32_t)dst->h}}}; + .renderArea = {{0, 0}, {(uint32_t)dst->w, (uint32_t)dst->h}}, + .clearValueCount = 1, .pClearValues = &clear}; g_vk.CmdBeginRenderPass(cmd, &rpi, VK_SUBPASS_CONTENTS_INLINE); g_vk.CmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, p); - g_vk.CmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, g_pl, 0, 1, &src, 0, NULL); + g_vk.CmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, g_pl, 0, count, src, 0, NULL); if (g_nis_fast && p == g_pipe[P_NIS] && g_coef_ds) /* nis3: coefficient banks at set 1 */ g_vk.CmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, g_pl_nis, 1, 1, &g_coef_ds, 0, NULL); g_vk.CmdPushConstants(cmd, g_pl, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, pcsz, pc); @@ -759,21 +822,7 @@ static void pass_renderpass(VkCommandBuffer cmd, VkRenderPass render_pass, static void pass(VkCommandBuffer cmd, VkPipeline p, struct fx_target *dst, VkDescriptorSet src, const void *pc, uint32_t pcsz) { - pass_renderpass(cmd, g_rp, p, dst, src, pc, pcsz); -} - -static void pass_dual(VkCommandBuffer cmd, VkPipeline p, struct fx_target *dst, - VkDescriptorSet src, VkDescriptorSet second, - const void *pc, uint32_t pcsz) { - VkRenderPassBeginInfo rpi = {.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, .renderPass = g_rp, .framebuffer = dst->fb, - .renderArea = {{0, 0}, {(uint32_t)dst->w, (uint32_t)dst->h}}}; - VkDescriptorSet sets[2] = {src, second}; - g_vk.CmdBeginRenderPass(cmd, &rpi, VK_SUBPASS_CONTENTS_INLINE); - g_vk.CmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, p); - g_vk.CmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, g_pl, 0, 2, sets, 0, NULL); - g_vk.CmdPushConstants(cmd, g_pl, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, pcsz, pc); - g_vk.CmdDraw(cmd, 4, 1, 0, 0); - g_vk.CmdEndRenderPass(cmd); + pass_sets(cmd, g_rp, p, dst, &src, 1, pc, pcsz); } static const float FULL_NDC[4] = {-1.0f, -1.0f, 1.0f, 1.0f}; @@ -785,6 +834,12 @@ struct fx_source_state { VkAccessFlags access; }; +/* NIS here is the SDR implementation and is documented for <=2x upscales: other outputs run FSR instead. */ +static int nis_falls_back(int scene_w, int scene_h, int cw, int ch) { + return g_scene_is_pq || cw < scene_w || ch < scene_h || (double)cw > (double)scene_w * 2.0 || + (double)ch > (double)scene_h * 2.0; +} + static VkImage effects_run(VkCommandBuffer cmd, VkImage scene, int scene_w, int scene_h, int out_w, int out_h, int *res_w, int *res_h, VkImageLayout input_layout, const struct fx_settings *frozen, @@ -810,11 +865,7 @@ static VkImage effects_run(VkCommandBuffer cmd, VkImage scene, int scene_w, int const int upscaling = cw > scene_w || ch > scene_h; int spatial = 0; if (spatial_mode(s->scaling) && (s->scaling == 6 || upscaling)) spatial = s->scaling; - /* NIS here is the SDR implementation and is documented for <=2x upscales. */ - const int nis_fallback = spatial == 7 && - (g_scene_is_pq || cw < scene_w || ch < scene_h || - (double)cw > (double)scene_w * 2.0 || - (double)ch > (double)scene_h * 2.0); + const int nis_fallback = spatial == 7 && nis_falls_back(scene_w, scene_h, cw, ch); static int last_nis_fallback = 0; const int was_nis_fallback = __atomic_exchange_n(&last_nis_fallback, nis_fallback, __ATOMIC_RELAXED); @@ -839,9 +890,10 @@ static VkImage effects_run(VkCommandBuffer cmd, VkImage scene, int scene_w, int target_ensure(&g_mid, cw, ch, FX_SCRATCH_USAGE, "EASU") == 0)) { if (s->aa_mode == 2 && (target_ensure_format(&g_smaa_edges, cw, ch, FX_SCRATCH_USAGE, - "SMAA edges", FX_FORMAT, g_smaa_rp) != 0 || + "SMAA edges", SMAA_EDGE_FORMAT, g_smaa_edge_rp) != 0 || target_ensure_format(&g_smaa_weights, cw, ch, FX_SCRATCH_USAGE, - "SMAA weights", FX_FORMAT, g_smaa_rp) != 0)) { + "SMAA weights", FX_FORMAT, g_smaa_weights_rp) != 0 || + smaa_tables_ensure() != 0)) { droiddeck_log("error", "effects: SMAA scratch allocation failed; falling back to FXAA"); snapshot.aa_mode = 1; s = &snapshot; @@ -969,14 +1021,17 @@ static VkImage effects_run(VkCommandBuffer cmd, VkImage scene, int scene_w, int switch (order[i]) { case FX_FXAA: pass(cmd, g_pipe[P_FXAA], dst, cur_ds, &pr, sizeof(pr)); break; case FX_FXAA_TOON: pass(cmd, g_pipe[P_FXAA_TOON], dst, cur_ds, &pr, sizeof(pr)); break; - case FX_SMAA: - pass_renderpass(cmd, g_smaa_rp, g_pipe[P_SMAA_EDGE], - &g_smaa_edges, cur_ds, &pr, sizeof(pr)); - pass_renderpass(cmd, g_smaa_rp, g_pipe[P_SMAA_WEIGHTS], - &g_smaa_weights, g_smaa_edges.ds, &pr, sizeof(pr)); - pass_dual(cmd, g_pipe[P_SMAA_BLEND], dst, cur_ds, - g_smaa_weights.ds, &pr, sizeof(pr)); + case FX_SMAA: { + struct pc_smaa pc = {.metrics = {1.0f / (float)cw, 1.0f / (float)ch, (float)cw, (float)ch}}; + const VkDescriptorSet weigh[3] = {g_smaa_edges.ds, g_smaa_area.ds, g_smaa_search.ds}; + const VkDescriptorSet blend[2] = {cur_ds, g_smaa_weights.ds}; + SET_NDC(pc); + smaa_tables_copy(cmd); + pass_sets(cmd, g_smaa_edge_rp, g_pipe[P_SMAA_EDGE], &g_smaa_edges, &cur_ds, 1, &pc, sizeof(pc)); + pass_sets(cmd, g_smaa_weights_rp, g_pipe[P_SMAA_WEIGHTS], &g_smaa_weights, weigh, 3, &pc, sizeof(pc)); + pass_sets(cmd, g_rp, g_pipe[P_SMAA_BLEND], dst, blend, 2, &pc, sizeof(pc)); break; + } case FX_TOON: pass(cmd, g_pipe[P_TOON], dst, cur_ds, &pr, sizeof(pr)); break; case FX_TOON_COLOR: { struct pc_toon_color pc = {0}; @@ -1037,13 +1092,23 @@ VkImage vkp_effects_run(VkCommandBuffer cmd, VkImage scene, int scene_w, int sce VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, NULL, NULL); } -int vkp_effects_prepare_generated(void) { +int vkp_effects_prepare_generated(int in_w, int in_h, int out_w, int out_h) { vkp_effects_sync(); pthread_mutex_lock(&g_lock); g_generated_settings = g_cur; pthread_mutex_unlock(&g_lock); - return spatial_mode(g_generated_settings.scaling) && g_generated_settings.scaling != 6 && - effect_count(&g_generated_settings) == 0; + int spatial = g_generated_settings.scaling; + if (!spatial_mode(spatial) || spatial == 6 || effect_count(&g_generated_settings) != 0) return 0; + /* Build the spatial filter's pipelines now, before frame generation records commands that sample the + * chain's views: one failing later in the same pass would tear the chain down (chain_failed) under a + * recorded command buffer. Build only what effects_run will use for this output, as it decides it: + * NIS on an output it hands to FSR builds FSR, so a NIS that cannot build here costs nothing. */ + int cw = out_w > FX_MAX_DIM ? FX_MAX_DIM : out_w < 1 ? 1 : out_w; + int ch = out_h > FX_MAX_DIM ? FX_MAX_DIM : out_h < 1 ? 1 : out_h; + if (cw <= in_w && ch <= in_h) return 1; /* clamped, it no longer upscales: effects_run builds no filter */ + if (spatial == 7 && nis_falls_back(in_w, in_h, cw, ch)) spatial = 4; + if (objects_ensure() != 0 || pipelines_ensure(spatial, &g_generated_settings) != 0) return 0; + return 1; } VkImage vkp_effects_run_before_generated(VkCommandBuffer cmd, VkImage scene, int w, int h, diff --git a/app/src/main/cpp/waylandcomp/src/effects_chain.h b/app/src/main/cpp/waylandcomp/src/effects_chain.h index a0aba31138..b85becc0a5 100644 --- a/app/src/main/cpp/waylandcomp/src/effects_chain.h +++ b/app/src/main/cpp/waylandcomp/src/effects_chain.h @@ -18,7 +18,7 @@ VkFilter vkp_effects_blit_filter(void); VkImage vkp_effects_run(VkCommandBuffer cmd, VkImage scene, int scene_w, int scene_h, int out_w, int out_h, int *res_w, int *res_h); -int vkp_effects_prepare_generated(void); +int vkp_effects_prepare_generated(int in_w, int in_h, int out_w, int out_h); void vkp_effects_release_generated_sources(void); VkImage vkp_effects_run_before_generated(VkCommandBuffer cmd, VkImage scene, int w, int h, int *res_w, int *res_h); diff --git a/app/src/main/cpp/waylandcomp/src/framegen_bridge.c b/app/src/main/cpp/waylandcomp/src/framegen_bridge.c index b3badeea27..b402dc0a8a 100644 --- a/app/src/main/cpp/waylandcomp/src/framegen_bridge.c +++ b/app/src/main/cpp/waylandcomp/src/framegen_bridge.c @@ -113,6 +113,7 @@ static int g_layer_path; static int g_out_gens; static int64_t g_out_planned[VKP_FG_MAX_GENERATIONS + 1]; static int64_t g_completion_issue; +static int g_paced_route = 1; void vkp_framegen_set_pacer(int on) { if (atomic_exchange(&g_pacer_on, on ? 1 : 0) != (on ? 1 : 0)) { @@ -178,6 +179,17 @@ void vkp_framegen_set_layer_timing(int layer) { fge_set_layer_timing(layer); } +void vkp_framegen_set_paced_route(int composed) { + composed = composed != 0; + if (composed == g_paced_route) return; + g_paced_route = composed; + if (atomic_load(&g_pacer_on)) { + fge_pacer_reset(); + FGLOG("ZeroPacer %s", composed ? "times the layer's frames again (composed route)" + : "waits: the direct route presents the real frame on its own timing"); + } +} + void vkp_framegen_set_tuning(float flow_scale, float refresh_hz) { if (flow_scale < 0.25f) flow_scale = 0.25f; if (flow_scale > 1.0f) flow_scale = 1.0f; @@ -517,7 +529,7 @@ int vkp_framegen_run(VkCommandBuffer cmd, VkImage scene, VkImageView scene_view, } } fge_set_phases(NULL, 0); - if (kind == VKP_FG_ENGINE_ZEROFG && pacer_wanted() && g_layer_path) { + if (kind == VKP_FG_ENGINE_ZEROFG && pacer_wanted() && g_layer_path && g_paced_route) { int64_t vsync = 0, period = 0; sc_layer_timeline(&vsync, &period); int64_t planned[VKP_FG_MAX_GENERATIONS + 1]; diff --git a/app/src/main/cpp/waylandcomp/src/framegen_bridge.h b/app/src/main/cpp/waylandcomp/src/framegen_bridge.h index 3412eda7f1..4b7e215446 100644 --- a/app/src/main/cpp/waylandcomp/src/framegen_bridge.h +++ b/app/src/main/cpp/waylandcomp/src/framegen_bridge.h @@ -30,6 +30,9 @@ int vkp_framegen_extra_images(void); void vkp_framegen_set_layer_timing(int layer); /* ZeroFG's pacer (include/zerofg/inline_pacer.h) times the layer's frames instead of the layer's own spacing. */ void vkp_framegen_set_pacer(int on); +/* 1 when the layer pass presents the real frame itself after its generated frames (the composed route): only + * then can the pacer time the whole group. The direct route keeps the layer's own timing. */ +void vkp_framegen_set_paced_route(int composed); /* Reset pacing history when a planned real-frame pair is aborted before presentation. */ void vkp_framegen_pacer_abort(void); /* Refresh planned for output k of the last run (k == gens: its real frame; 0: use layer timing). */ diff --git a/app/src/main/cpp/waylandcomp/src/framegen_zerofg.cpp b/app/src/main/cpp/waylandcomp/src/framegen_zerofg.cpp index 786c830964..b0da6b2af1 100644 --- a/app/src/main/cpp/waylandcomp/src/framegen_zerofg.cpp +++ b/app/src/main/cpp/waylandcomp/src/framegen_zerofg.cpp @@ -55,6 +55,15 @@ VkImage g_current = VK_NULL_HANDLE; VkImageView g_current_view = VK_NULL_HANDLE; uint64_t g_current_sequence = 0; bool g_pair_pending = false; +// The interpolator keeps per-pair work and the prepared Real by sequence. A pass dropped after recording +// Interpolate never ran on the GPU, so the next pair's A gets a fresh identity no record has seen: nothing the +// dropped pass would have prepared is reused, nor its flow start. The identity is stable for the whole pair, so +// its phases still share their work (and ReallyZero sees one pair, not a first picture per phase). +bool g_interpolate_uncommitted = false; +bool g_record_stale = false; +uint64_t g_pair_anonymous = 0; // the recovery pair's A identity, 0 for an ordinary pair +uint64_t g_anonymous_count = 0; +constexpr uint64_t kAnonymousSequence = 1ull << 63; // above any frame sequence the compositor hands out // Pacing. The compositor presents a pair's generated frames and its real frame back to back in FIFO, // so they reach the panel on consecutive refreshes right after the tick that drew them. @@ -475,6 +484,9 @@ int zfg_prepare(uint32_t width, uint32_t height, VkFormat format) { return 0; } if (g_width == width && g_height == height && g_format == format && g_history) return 1; + // ReallyZero's Resize accepts 64..16384 per side: refuse this frame only, before touching the + // engine's state, so a supported size later still generates. + if (width < 64 || height < 64 || width > 16384 || height > 16384) return 0; if (g_DeviceWaitIdle) g_DeviceWaitIdle(g_device); destroy_history(); const zerofg::Status resized = g_interpolator->Resize(width, height, format, format); @@ -540,6 +552,8 @@ void zfg_process(VkCommandBuffer cmd, VkImage source, VkImageView source_view, g_current_view = source_view; g_current_sequence = sequence; g_pair_pending = true; + g_pair_anonymous = g_record_stale ? (kAnonymousSequence | ++g_anonymous_count) : 0; + g_record_stale = false; } void zfg_generate(VkCommandBuffer cmd, uint32_t index, uint32_t count, @@ -564,6 +578,8 @@ void zfg_generate(VkCommandBuffer cmd, uint32_t index, uint32_t count, result.width = width; result.height = height; result.usage = VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT; + if (g_pair_anonymous) previous.sequence = g_pair_anonymous; + g_interpolate_uncommitted = true; const zerofg::Status status = g_interpolator->Interpolate(cmd, index, previous, current, phase, result); @@ -579,6 +595,7 @@ void zfg_generate(VkCommandBuffer cmd, uint32_t index, uint32_t count, } void zfg_commit_history_update(void) { + g_interpolate_uncommitted = false; if (!g_history_recorded_pending) return; g_history_layout_defined = true; g_history_valid = true; @@ -589,10 +606,15 @@ void zfg_commit_history_update(void) { void zfg_discard_history_update(void) { g_history_recorded_pending = false; g_history_recorded_sequence = 0; + if (g_interpolate_uncommitted) g_record_stale = true; + g_interpolate_uncommitted = false; + g_pair_pending = false; } void zfg_forget_targets(void) { g_pair_pending = false; + if (g_interpolate_uncommitted) g_record_stale = true; + g_interpolate_uncommitted = false; g_history_recorded_pending = false; g_history_recorded_sequence = 0; g_history_valid = false; diff --git a/app/src/main/cpp/waylandcomp/src/sc_layer.c b/app/src/main/cpp/waylandcomp/src/sc_layer.c index d38cc7ede5..fb93305e4b 100644 --- a/app/src/main/cpp/waylandcomp/src/sc_layer.c +++ b/app/src/main/cpp/waylandcomp/src/sc_layer.c @@ -1138,6 +1138,7 @@ int sc_layer_present_generated(const struct vkp_draw *draws, int n_draws, const if (vkp_update_map(scene_w, scene_h) != 0) return -1; const int deep = hf && !hf->tonemap; if (hf) composed = 1; + vkp_framegen_set_paced_route(composed); if (hf && hf->tonemap) color = NULL; int n = vkp_pass_begin_generate(scene_w, scene_h, draws, n_draws, hf, &rw, &rh); if (n < 0) return -1; diff --git a/app/src/main/cpp/waylandcomp/src/vk_present.c b/app/src/main/cpp/waylandcomp/src/vk_present.c index ab0d50bea6..8801c87286 100644 --- a/app/src/main/cpp/waylandcomp/src/vk_present.c +++ b/app/src/main/cpp/waylandcomp/src/vk_present.c @@ -2769,8 +2769,8 @@ static int render_impl(int scene_w, int scene_h, const struct vkp_draw *draws, i const int upscale_w = (int)(scene_w * g_map.kx + 0.5f); const int upscale_h = (int)(scene_h * g_map.ky + 0.5f); const int post_upscale = fx && fg && !hf && !cb && vkp_effects_upscaling() && - vkp_effects_prepare_generated() && - (upscale_w > input_w || upscale_h > input_h); + (upscale_w > input_w || upscale_h > input_h) && + vkp_effects_prepare_generated(input_w, input_h, upscale_w, upscale_h); if (post_upscale) { static int last_input_w, last_input_h, last_output_w, last_output_h; if (input_w != last_input_w || input_h != last_input_h || @@ -3545,7 +3545,8 @@ static int pass_begin_impl(int scene_w, int scene_h, const struct vkp_draw *draw int mapped_w = (int)(scene_w * g_map.kx + 0.5f), mapped_h = (int)(scene_h * g_map.ky + 0.5f); g_pass.post_upscale = generate && !hf && vkp_effects_active() && vkp_effects_upscaling() && - vkp_effects_prepare_generated() && (mapped_w > input_w || mapped_h > input_h); + (mapped_w > input_w || mapped_h > input_h) && + vkp_effects_prepare_generated(input_w, input_h, mapped_w, mapped_h); if (g_pass.post_upscale) { static int last_input_w, last_input_h, last_output_w, last_output_h; if (input_w != last_input_w || input_h != last_input_h || mapped_w != last_output_w || mapped_h != last_output_h) { diff --git a/app/src/main/java/com/droiddeck/launcher/ProtonMenu.kt b/app/src/main/java/com/droiddeck/launcher/ProtonMenu.kt index 385081cc7d..b6799bd315 100644 --- a/app/src/main/java/com/droiddeck/launcher/ProtonMenu.kt +++ b/app/src/main/java/com/droiddeck/launcher/ProtonMenu.kt @@ -45,6 +45,7 @@ internal class ProtonMenu( var experimentalReleases by Operation.experimentalReleases companion object { const val EXPERIMENTAL = "experimental" + private val REMEMBERED = setOf(ProtonExtras.OWN, ProtonExtras.ANTICHEAT) } @VisibleForTesting internal var latestCheck: (Boolean) -> Boolean = { force -> ProtonExtras.checkLatest(activity, force) } @VisibleForTesting internal var experimentalRefresh: () -> List? = { ExperimentalProtons.refresh(activity) } @@ -66,7 +67,7 @@ internal class ProtonMenu( ui.post { protonStage = label; protonPercent = value } } }.getOrElse { it.message ?: it.javaClass.simpleName } - if (problem == null && !automatic && tool.id == ProtonExtras.OWN) ProtonExtras.setDeclined(activity, false) + if (problem == null && !automatic && tool.id in REMEMBERED) ProtonExtras.setDeclined(activity, false, tool.id) if (tool.id == ProtonExtras.OWN) { if (problem == null) Onboarding.finish(Onboarding.Step.PROTON) else Onboarding.fail(Onboarding.Step.PROTON, problem) Onboarding.recheck(activity) @@ -96,7 +97,7 @@ internal class ProtonMenu( protonPercent = -1 Thread({ if (older) ProtonExtras.removeOlder(activity, tool) else ProtonExtras.remove(activity, tool, dir) - if (tool.id == ProtonExtras.OWN && ProtonExtras.installedAll(activity, tool).isEmpty()) ProtonExtras.setDeclined(activity, true) + if (tool.id in REMEMBERED && ProtonExtras.installedAll(activity, tool).isEmpty()) ProtonExtras.setDeclined(activity, true, tool.id) ui.post { protonBusyId = null protonStage = null @@ -158,7 +159,7 @@ internal class ProtonMenu( refreshExperimental() protonRows = ProtonExtras.offered(activity).map { val all = ProtonExtras.installedAll(activity, it) - ProtonRow(it.id, it.name, all.lastOrNull(), ProtonExtras.queued(activity, it), all, ProtonExtras.update(activity, it)) + ProtonRow(it.id, if (it.label != 0) activity.getString(it.label) else it.name, all.lastOrNull(), ProtonExtras.queued(activity, it), all, ProtonExtras.update(activity, it)) } } diff --git a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt index 26aa65af74..5c9adddabf 100644 --- a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt @@ -100,6 +100,12 @@ import com.droiddeck.launcher.input.SteamControllerBle import com.droiddeck.launcher.input.DirectTouchHold import com.droiddeck.launcher.input.GestureTouchStreamGate import com.droiddeck.launcher.input.PenRouter +import com.droiddeck.launcher.input.AirTrigger +import com.droiddeck.launcher.input.AirTriggerButtons +import com.droiddeck.launcher.input.AirTriggerInput +import com.droiddeck.launcher.input.AirTriggerPrefs +import com.droiddeck.launcher.input.AirTriggerSetup +import com.droiddeck.launcher.input.RedMagicAirTriggers import com.droiddeck.launcher.input.PenStream import com.droiddeck.launcher.input.PointerGestures import com.droiddeck.launcher.input.PointerSpace @@ -241,6 +247,10 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde private lateinit var sessionRoot: FrameLayout private var inputRouter: InputRouter? = null private var physicalInputBindings: com.droiddeck.launcher.input.PhysicalInputBindings? = null + private var airTriggerInput: AirTriggerInput? = null + private var airTriggersOpen = false + private var airTriggerMenu by mutableStateOf(null) + private var airTriggerGlow: com.droiddeck.launcher.ui.AirTriggerGlow? = null private var inputSettingsOpen by mutableStateOf(false) /** Which editor the input window shows; none means the full controller settings. */ private var inputEditor by mutableStateOf(null) @@ -663,6 +673,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde private var effects by mutableStateOf(ScreenEffects.OFF) private var observedScreenEffectsProfileId by mutableStateOf(null) private var screenEffectsTarget by mutableStateOf(SCREEN_EFFECTS_TARGET_AUTO) + private var screenEffectsProfileRevision by mutableIntStateOf(0) private var cardboard by mutableStateOf(Cardboard.OFF) private var headTracker: HeadTracker? = null private var steamVrStatus by mutableStateOf(null) @@ -976,6 +987,10 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde bridge.setBuiltinPad(SessionState.mode != SessionService.MODE_STEAM || SessionPrefs.builtinPad(this)) padBridge = bridge inputRouter = InputRouter(inputOutput).also { bridge.setInputRouter(it); DeckControls.setRouter(it); physicalInputBindings = com.droiddeck.launcher.input.PhysicalInputBindings(it) } + if (RedMagicAirTriggers.supported(this)) { + airTriggerInput = AirTriggerInput(bridge, ::holdOnScreen, ::airTriggerTouched) + RedMagicAirTriggers.restore(this) + } refreshInputProfile() bridge.setOnChordInput(backQamInput::onChordInput) SessionState.padBridge = bridge @@ -1101,6 +1116,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde override fun onResolvePointerIcon(event: MotionEvent, pointerIndex: Int): android.view.PointerIcon? = if (platformPointerShown == true) super.onResolvePointerIcon(event, pointerIndex) else null }.apply { addView(sessionOverlay) }) + if (airTriggerInput != null) airTriggerGlow = com.droiddeck.launcher.ui.AirTriggerGlow(this).also { root.addView(it) } setContentView(root) glassesScope.launch { Glasses.state.collect { glasses = it @@ -1388,6 +1404,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde } LaunchedEffect(drawerOpen, menuOwnsController, pcKeyboardOpen, achievementsOpen, gestureSettingsOpen, inputSettingsOpen, pipUi, SessionState.suspended, resumed, appTextFocus) { updateOnScreenControls() + refreshAirTriggers() padBridge?.setInputEnabled(resumed && !menuOwnsController && !pcKeyboardOpen && !achievementsOpen && !gestureSettingsOpen && !inputSettingsOpen && !pipUi && !appTextFocus && !SessionState.suspended) if (!drawerOpen && backTapOpenedDrawer) { backTaps.cancel() @@ -1651,8 +1668,11 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde effects = effects, screenEffectsTarget = screenEffectsTarget, screenEffectsTargets = screenEffectsTargetOptions(), - screenEffectsCanDelete = screenEffectsProfileIdForTarget(screenEffectsTarget)?.let { - SessionPrefs.hasScreenEffectsOverride(this@SessionActivity, it) + screenEffectsCanDelete = screenEffectsProfileRevision.let { + screenEffectsProfileIdForTarget(screenEffectsTarget)?.let { + SessionPrefs.hasScreenEffectsOverride(this@SessionActivity, it) || + SessionPrefs.hasScreenEffectsUpscalerOverride(this@SessionActivity, it) + } } == true, cardboard = cardboard, cardboardSensor = hasRotationSensor, @@ -1758,6 +1778,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde } else { val profileId = screenEffectsProfileIdForTarget(target) SessionPrefs.setScreenEffectsUpscaler(this@SessionActivity, profileId, m) + screenEffectsProfileRevision++ if (target == screenEffectsTarget) { upscaler = m @@ -1793,6 +1814,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde } else { val profileId = screenEffectsProfileIdForTarget(target) SessionPrefs.setScreenEffectsUpscaler(this@SessionActivity, profileId, m) + screenEffectsProfileRevision++ if (target == screenEffectsTarget) { upscaler = m if (screenEffectsUpscalerTargetAppliesToLiveOutput(target)) { @@ -1839,7 +1861,22 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde val profileId = screenEffectsProfileIdForTarget(editorTarget) SessionPrefs.setScreenEffects(this@SessionActivity, profileId, e) effects = e - if (screenEffectsTargetAppliesToLiveOutput(editorTarget)) e.push(upscaler) + if (screenEffectsTargetAppliesToLiveOutput(editorTarget)) { + val upscalerAppliesToLiveOutput = + screenEffectsUpscalerTargetAppliesToLiveOutput(editorTarget) + val liveUpscaler = if (upscalerAppliesToLiveOutput) { + SessionPrefs.screenEffectsUpscaler( + this@SessionActivity, + screenEffectsProfileIdForTarget(editorTarget) + ) + } else { + SessionPrefs.screenEffectsUpscaler( + this@SessionActivity, + currentScreenEffectsProfileId() + ) + } + e.push(liveUpscaler) + } } } }, @@ -1896,7 +1933,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde onBlackFrameInsertion = { on -> SessionPrefs.setBlackFrameInsertion(this@SessionActivity, on) blackFrameInsertion = on - CompositorHost.setBlackFrameInsertion(on, refreshHz(), compositorFpsLimit()) + CompositorHost.setBlackFrameInsertion(on, refreshHz(), compositorFpsLimit(), outputFpsLimit()) }, hdr = hdrWanted, hdrAvailable = hdrAvailable, @@ -1925,6 +1962,27 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde wowChat = wowChat.remembered, onWowChat = wowChat::choose, controller = controllerSettings, + airTriggers = airTriggerMenu, + onAirTriggers = { on -> AirTriggerPrefs.setEnabled(this@SessionActivity, on); refreshAirTriggers() }, + onAirTriggerButton = { trigger, id -> + AirTriggerPrefs.setButton(this@SessionActivity, primaryInputLayout?.id.orEmpty(), trigger, id) + refreshAirTriggers() + }, + onAirTriggerAction = { trigger, action -> + AirTriggerPrefs.setAction(this@SessionActivity, primaryInputLayout?.id.orEmpty(), trigger, action) + refreshAirTriggers() + }, + onAirTriggerRate = { trigger, rate -> + AirTriggerPrefs.setRate(this@SessionActivity, primaryInputLayout?.id.orEmpty(), trigger, rate) + refreshAirTriggers() + }, + onAirTriggerVibration = { on -> AirTriggerPrefs.setVibration(this@SessionActivity, on); refreshAirTriggers() }, + onAirTriggerScreenLight = { on -> AirTriggerPrefs.setScreenLight(this@SessionActivity, on); refreshAirTriggers() }, + onAirTriggerLed = { led -> + AirTriggerPrefs.setLed(this@SessionActivity, led) + if (airTriggersOpen) RedMagicAirTriggers.open(this@SessionActivity) + refreshAirTriggers() + }, onControllerSize = { percent -> updateControllerPrefs { ControllerPrefs.setSize(this@SessionActivity, percent) } }, onControllerOpacity = { percent -> ControllerPrefs.setOnScreenOpacity(this@SessionActivity, percent) @@ -2662,10 +2720,21 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde val targetUpscaler = SessionPrefs.screenEffectsUpscaler(this, profileId) effects = targetEffects upscaler = targetUpscaler + val upscalerAppliesToLiveOutput = screenEffectsUpscalerTargetAppliesToLiveOutput(target) + val liveUpscaler = if (upscalerAppliesToLiveOutput) { + targetUpscaler + } else { + SessionPrefs.screenEffectsUpscaler(this, currentScreenEffectsProfileId()) + } + if (upscalerAppliesToLiveOutput) { + WaylandCompositor.nativeSetUpscaler(liveUpscaler) + } if (screenEffectsTargetAppliesToLiveOutput(target)) { - WaylandCompositor.nativeSetUpscaler(targetUpscaler) - WaylandCompositor.nativeSetLookName(ScreenEffectLooks.match(targetEffects, targetUpscaler)?.name) - targetEffects.push(targetUpscaler) + WaylandCompositor.nativeSetLookName(ScreenEffectLooks.match(targetEffects, liveUpscaler)?.name) + targetEffects.push(liveUpscaler) + } else if (upscalerAppliesToLiveOutput) { + val liveEffects = SessionPrefs.screenEffects(this, currentScreenEffectsProfileId()) + WaylandCompositor.nativeSetLookName(ScreenEffectLooks.match(liveEffects, liveUpscaler)?.name) } } @@ -2678,6 +2747,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde private fun resetScreenEffectsTarget(target: String) { if (target != screenEffectsTarget) return SessionPrefs.resetScreenEffectsProfile(this, screenEffectsProfileIdForTarget(target)) + screenEffectsProfileRevision++ syncScreenEffectsTarget(target) } @@ -2685,6 +2755,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde if (target != screenEffectsTarget) return val profileId = screenEffectsProfileIdForTarget(target) ?: return SessionPrefs.deleteScreenEffectsProfile(this, profileId) + screenEffectsProfileRevision++ syncScreenEffectsTarget(target) } @@ -3137,7 +3208,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde CompositorHost.startOrAttach( this, holder.surface, runtimeDir.path, driverId?.let { turnip.driverPath(it) }, driverId?.let { turnip.libraryName(it) }, - applicationInfo.nativeLibraryDir, size.first, size.second, refreshHz(holder), compositorFpsLimit(), + applicationInfo.nativeLibraryDir, size.first, size.second, refreshHz(holder), compositorFpsLimit(), outputFpsLimit(), ) onOutputAttached(holder) if (SessionState.running && size != previous) { @@ -3412,7 +3483,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde ) val hz = refreshHz() val changed = kotlin.math.abs(SessionState.refreshHz - hz) > 0.1f - CompositorHost.updatePacing(hz, compositorFpsLimit()) + CompositorHost.updatePacing(hz, compositorFpsLimit(), outputFpsLimit()) pushCardboard(activeCardboard) if (changed && ::surfaceView.isInitialized) applyFrameGen() } @@ -3660,6 +3731,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde private fun onSessionEnded(status: Int) { ended = true + runOnUiThread { refreshAirTriggers() } ++steamVrRequestGeneration if (isInPictureInPictureMode) { runOnUiThread { finish() } @@ -3717,6 +3789,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde private fun releasePads(keepBackTap: Boolean = false) { inputMotion.stop() physicalInputBindings?.release() + airTriggerInput?.release() com.droiddeck.launcher.input.HomeButtonShortcuts.cancel(this) backQamInput.cancel(keepTap = keepBackTap) padBridge?.releaseAll() @@ -3849,6 +3922,9 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde return dispatchSessionKeyEvent(normalized, orderedImeKey) } + private fun physicalInputAccepted() = resumed && !menuOwnsController && !pcKeyboardOpen && !achievementsOpen && + !inputSettingsOpen && !gestureSettingsOpen && !SessionState.suspended && !loading.visible + private fun dispatchSessionKeyEvent(event: KeyEvent, orderedImeKey: Boolean): Boolean { if (com.droiddeck.launcher.ui.AgentPet.handleBack(this, event)) return true when (event.keyCode) { @@ -3868,10 +3944,10 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde } } if (penStream.holdsKey(event) || (penSettings.mode != SessionPrefs.PEN_TOUCH && PenStream.isPenKey(event))) return penStream.onKey(event) + if (airTriggerInput?.onKey(event) { physicalInputAccepted() && !pipUi && !appTextFocus } == true) return true if (appTextFocus) return super.dispatchKeyEvent(event) if (!pipUi) { - if (physicalInputBindings?.onKey(event, resumed && !menuOwnsController && !pcKeyboardOpen && !achievementsOpen && - !inputSettingsOpen && !gestureSettingsOpen && !SessionState.suspended && !loading.visible) == true) return true + if (physicalInputBindings?.onKey(event, physicalInputAccepted()) == true) return true if (physicalShortcuts.onKey( event, enabled = resumed && SessionState.running && !SessionState.suspended && @@ -5143,6 +5219,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde || inputProfile.keys.any { it.action is InputAction.MouseButton } physicalInputBindings?.configure(inputProfile.keys) padBridge?.setInputProfile(inputProfile) + refreshAirTriggers() DeckControls.refresh() onScreenControls?.updateLayout(primaryInputLayout) bottomInputControls?.updateLayout(primaryInputLayout) @@ -5153,6 +5230,32 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde secondScreenPresentation?.refreshControls() } + private fun refreshAirTriggers() { + val input = airTriggerInput ?: return + val layout = primaryInputLayout + val layoutId = layout?.id.orEmpty() + val enabled = AirTriggerPrefs.enabled(this) + val chosen = AirTrigger.entries.associateWith { + AirTriggerSetup(AirTriggerButtons.resolve(layout, it, AirTriggerPrefs.button(this, layoutId, it)), + AirTriggerPrefs.action(this, layoutId, it), AirTriggerPrefs.rate(this, layoutId, it)) + } + val active = enabled && resumed && !ended && !SessionState.suspended + input.configure(if (active) chosen else emptyMap()) + if (active != airTriggersOpen) { + airTriggersOpen = active + if (active) RedMagicAirTriggers.open(this) else RedMagicAirTriggers.restore(this) + } + airTriggerMenu = com.droiddeck.launcher.ui.AirTriggerMenu(enabled, chosen.mapValues { it.value.element.id }, + AirTriggerButtons.options(layout).map { it.id to it.name }, AirTriggerPrefs.vibration(this), AirTriggerPrefs.screenLight(this), + AirTriggerPrefs.led(this), chosen.mapValues { it.value.action }, chosen.mapValues { it.value.rate }) + } + + private fun airTriggerTouched(trigger: AirTrigger, down: Boolean) { + RedMagicAirTriggers.light(if (down) trigger.pressLight else trigger.releaseLight) + if (down && AirTriggerPrefs.vibration(this)) com.droiddeck.launcher.ui.ControllerHaptics.click(this) + airTriggerGlow?.show(trigger, down && AirTriggerPrefs.screenLight(this)) + } + private fun tapQam() { if (SessionState.mode == SessionService.MODE_STEAM) padBridge?.triggerQam() } @@ -5609,10 +5712,20 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde private var sessionTouchDown = false private var screenTapsClick = true - private fun onScreenLeftMouseButtonShown(): Boolean = listOfNotNull( + private fun inputSurfaces() = listOfNotNull( onScreenControls?.inputSurface, bottomInputControls?.inputSurface, unfoldedPanel?.inputSurface, unfoldedDeckSurface, secondScreenPresentation?.controlsView, swappedInputSurface, - ).any { it.isShown && inputProfile.showsLeftMouseButton(it.inputRole, it.shownElements, stockInputProfile) } + ) + + private fun onScreenLeftMouseButtonShown(): Boolean = + inputSurfaces().any { it.isShown && inputProfile.showsLeftMouseButton(it.inputRole, it.shownElements, stockInputProfile) } + + private fun holdOnScreen(elementId: String, trigger: AirTrigger, held: Boolean, cancelled: Boolean): Boolean { + val surfaces = inputSurfaces().filter { it.inputRole == InputRole.PRIMARY } + if (held) return surfaces.any { it.isShown && it.hold(elementId, trigger.ordinal, true) } + surfaces.forEach { it.hold(elementId, trigger.ordinal, false, cancelled) } + return true + } override fun onTouchEvent(event: MotionEvent): Boolean = inSurfaceSpace(event) { handleTouch(event) } @@ -6730,6 +6843,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde if (::scrollTouch.isInitialized) scrollTouch.cancel() if (::padMouse.isInitialized) padMouse.reset() resumed = false + refreshAirTriggers() boostGpuClock(false) updateKeyboardRoute() updatePointerCapture() @@ -7323,7 +7437,10 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde if (!hasFocus) { cancelTouchGestures() releaseHeldGuestInput() + airTriggerInput?.release() } + // Game Space clears the distribute state when the launcher or Game Space itself comes to the front. + if (hasFocus && airTriggersOpen) RedMagicAirTriggers.open(this) if (hasFocus && !pipUi) { retryFieldKeyboard(true) goFullscreen() @@ -7411,6 +7528,9 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde inputMotion.stop() padBridge?.setInputEnabled(false) physicalInputBindings?.close() + airTriggerInput?.close() + airTriggerInput = null + if (airTriggersOpen) RedMagicAirTriggers.restore(this) padBridge?.stop() DeckControls.clearRouter(inputRouter) inputRouter = null diff --git a/app/src/main/java/com/droiddeck/launcher/core/DeviceReport.kt b/app/src/main/java/com/droiddeck/launcher/core/DeviceReport.kt index db8ab970a2..d94fbbb587 100644 --- a/app/src/main/java/com/droiddeck/launcher/core/DeviceReport.kt +++ b/app/src/main/java/com/droiddeck/launcher/core/DeviceReport.kt @@ -27,6 +27,7 @@ import java.io.File import java.text.SimpleDateFormat import java.util.Date import java.util.Locale +import java.util.TimeZone object DeviceReport { private const val TAG = "DeviceReport" @@ -36,6 +37,10 @@ object DeviceReport { .map { it.substringAfter(':').trim().split(Regex("\\s+")).filter(String::isNotEmpty).joinToString(" ") } .filter(String::isNotEmpty).distinct().joinToString(" | ").ifEmpty { "not reported" } + internal fun buildDate(millis: Long): String? = millis.takeIf { it > 0 }?.let { + SimpleDateFormat("yyyy-MM-dd HH:mm 'UTC'", Locale.US).apply { timeZone = TimeZone.getTimeZone("UTC") }.format(Date(it)) + } + fun write(context: Context, target: File, mode: String) { try { target.writeText(build(context, mode)) @@ -129,6 +134,7 @@ object DeviceReport { k("Android", "${Build.VERSION.RELEASE} (API ${Build.VERSION.SDK_INT})") k("Security patch", Build.VERSION.SECURITY_PATCH) k("Build", Build.DISPLAY) + k("Build date", buildDate(Build.TIME)) k("Fingerprint", Build.FINGERPRINT) k("Kernel", System.getProperty("os.version")) k("ABIs", Build.SUPPORTED_ABIS.joinToString(", ")) diff --git a/app/src/main/java/com/droiddeck/launcher/input/RedMagicAirTriggers.kt b/app/src/main/java/com/droiddeck/launcher/input/RedMagicAirTriggers.kt new file mode 100644 index 0000000000..051e745945 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/input/RedMagicAirTriggers.kt @@ -0,0 +1,324 @@ +package com.droiddeck.launcher.input + +import android.content.Context +import android.content.SharedPreferences +import android.net.Uri +import android.os.Build +import android.os.Handler +import android.os.IBinder +import android.os.Looper +import android.os.Parcel +import android.provider.Settings +import android.util.Log +import android.view.InputDevice +import android.view.KeyEvent +import java.util.EnumMap +import java.util.EnumSet +import java.util.concurrent.Executor +import java.util.concurrent.LinkedBlockingQueue +import java.util.concurrent.ThreadPoolExecutor +import java.util.concurrent.TimeUnit +import org.json.JSONObject + +enum class AirTrigger(val keyCode: Int, val control: InputControl, val pressLight: Int, val releaseLight: Int) { + LEFT(KeyEvent.KEYCODE_F7, InputControl.LT, 106, 107), RIGHT(KeyEvent.KEYCODE_F8, InputControl.RT, 108, 109); + + companion object { + private const val DEVICE_PREFIX = "nubia_tgk" + + internal fun isTriggerDevice(device: InputDevice?): Boolean { + if (device == null) return false + if (device.name.startsWith(DEVICE_PREFIX)) return true + // Some RedMagic firmware merges the trigger sensors with an unnamed built-in keyboard. + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && + device.name.isEmpty() && !device.isVirtual && !device.isExternal && + device.supportsSource(InputDevice.SOURCE_KEYBOARD) && + device.hasKeys(LEFT.keyCode, RIGHT.keyCode).all { it } + } + + internal fun of(keyCode: Int, device: InputDevice?): AirTrigger? = + entries.firstOrNull { it.keyCode == keyCode }?.takeIf { isTriggerDevice(device) } + } +} + +/** Game Space's single tap holds the button while the trigger is touched; its long press latches it until the next touch. */ +enum class AirTriggerAction { TAP, LATCH, RAPID } + +/** Game Space's rapid fire counts for its low, normal and high click frequency. */ +enum class RapidFireRate(val clicksPerSecond: Int) { LOW(2), NORMAL(5), HIGH(10) } + +/** Game Space's touch atmosphere lamp cases, by their name in RedMagic's shoulder light settings. */ +enum class AirTriggerLed(val effect: String, val fallback: String) { + OFF("close", "02000000"), STEADY("steady", "02101000"), PULSE("pulse", "02102000") +} + +data class AirTriggerSetup( + val element: InputSurfaceElement, + val action: AirTriggerAction = AirTriggerAction.TAP, + val rate: RapidFireRate = RapidFireRate.NORMAL, +) { + /** Long press and rapid fire decide when the button is let go, so they press a toggle button as a plain one. */ + internal val target get() = if (action != AirTriggerAction.TAP && element.toggle) element.copy(toggle = false) else element +} + +object AirTriggerButtons { + fun options(layout: SavedInputLayout?): List { + val placed = layout?.let { (it.elements + it.rotated).distinctBy { element -> element.id } }.orEmpty() + .filter { it.kind == InputElementKind.BUTTON || it.kind == InputElementKind.TRIGGER } + return placed + AirTrigger.entries.filter { trigger -> placed.none { it.control == trigger.control } } + .map { InputSurfaceElement(it.control, 0f, 0f, 0f, 0f) } + } + + fun resolve(layout: SavedInputLayout?, trigger: AirTrigger, chosen: String?): InputSurfaceElement { + val options = options(layout) + return chosen?.let { id -> options.firstOrNull { it.id == id } } ?: options.first { it.control == trigger.control } + } +} + +object AirTriggerPrefs { + private const val FILE = "redmagic-air-triggers" + private const val ENABLED = "enabled" + private const val VIBRATION = "vibration" + private const val SCREEN_LIGHT = "screen-light" + private const val LED = "led" + internal const val OWNED = "distribute-owned" + + fun prefs(context: Context): SharedPreferences = context.getSharedPreferences(FILE, Context.MODE_PRIVATE) + fun enabled(context: Context) = prefs(context).getBoolean(ENABLED, false) + fun setEnabled(context: Context, on: Boolean) = prefs(context).edit().putBoolean(ENABLED, on).apply() + fun button(context: Context, layoutId: String, trigger: AirTrigger): String? = prefs(context).getString(key(layoutId, trigger), null) + fun setButton(context: Context, layoutId: String, trigger: AirTrigger, elementId: String) = + prefs(context).edit().putString(key(layoutId, trigger), elementId).apply() + fun action(context: Context, layoutId: String, trigger: AirTrigger) = read(context, key(layoutId, trigger, "action"), AirTriggerAction.TAP) + fun setAction(context: Context, layoutId: String, trigger: AirTrigger, action: AirTriggerAction) = + prefs(context).edit().putString(key(layoutId, trigger, "action"), action.name).apply() + fun rate(context: Context, layoutId: String, trigger: AirTrigger) = read(context, key(layoutId, trigger, "rate"), RapidFireRate.NORMAL) + fun setRate(context: Context, layoutId: String, trigger: AirTrigger, rate: RapidFireRate) = + prefs(context).edit().putString(key(layoutId, trigger, "rate"), rate.name).apply() + fun vibration(context: Context) = prefs(context).getBoolean(VIBRATION, false) + fun setVibration(context: Context, on: Boolean) = prefs(context).edit().putBoolean(VIBRATION, on).apply() + fun screenLight(context: Context) = prefs(context).getBoolean(SCREEN_LIGHT, false) + fun setScreenLight(context: Context, on: Boolean) = prefs(context).edit().putBoolean(SCREEN_LIGHT, on).apply() + fun led(context: Context) = read(context, LED, AirTriggerLed.STEADY) + fun setLed(context: Context, led: AirTriggerLed) = prefs(context).edit().putString(LED, led.name).apply() + + private inline fun > read(context: Context, key: String, default: E): E = + prefs(context).getString(key, null)?.let { name -> enumValues().firstOrNull { it.name == name } } ?: default + + private fun key(layoutId: String, trigger: AirTrigger, setting: String? = null) = + listOfNotNull(trigger.name.lowercase(), setting).joinToString("-") + ".$layoutId" +} + +/** Game Space's exported provider switches the triggers to plain F7/F8 keys without its panel, and needs no permission. */ +object RedMagicAirTriggers { + private const val TAG = "AirTriggers" + private const val AUTHORITY = "cn.nubia.tgk.data.TgkDataProvider" + private val URI = Uri.parse("content://$AUTHORITY") + private const val OPEN = "openTouchGameKeyDistribute" + private const val CLOSE = "closeTouchGameKeyDistribute" + private const val SHOULDER_LIGHT_ON = 110 + private const val SHOULDER_LIGHT_OFF = 111 + private const val SHOULDER_SETTINGS = "lighting_shoulder_config_json" + private val REAPPLY_MS = longArrayOf(1_000, 5_000) + internal var worker: Executor = ThreadPoolExecutor(0, 1, 10, TimeUnit.SECONDS, LinkedBlockingQueue()) { Thread(it, "air-triggers") } + internal var lights: TriggerLights = ColorfulLights + private val main = Handler(Looper.getMainLooper()) + private var reapply: Runnable? = null + + @Suppress("DEPRECATION") + fun supported(context: Context) = context.packageManager.resolveContentProvider(AUTHORITY, 0) != null && + InputDevice.getDeviceIds().any { AirTrigger.isTriggerDevice(InputDevice.getDevice(it)) } + + /** Call on the main thread. */ + fun open(context: Context) { + val app = context.applicationContext + cancelReapply() + worker.execute { apply(app) } + // Game Space runs its own trigger setup for the app that comes to the front, which switches the trigger keys and lights off again. + val again = Runnable { worker.execute { apply(app) } } + reapply = again + REAPPLY_MS.forEach { main.postDelayed(again, it) } + } + + private fun apply(app: Context) { + val prefs = AirTriggerPrefs.prefs(app) + if (!prefs.getBoolean(AirTriggerPrefs.OWNED, false) && Settings.Global.getInt(app.contentResolver, OPEN, 0) != 1) + prefs.edit().putBoolean(AirTriggerPrefs.OWNED, true).commit() + call(app, OPEN) + if (!prefs.getBoolean(AirTriggerPrefs.OWNED, false)) return + lights.request(SHOULDER_LIGHT_ON) + // The light service drops every trigger light until an effect is set, which Game Space only does from its own view. + lights.setEffect(shoulderEffect(Settings.Global.getString(app.contentResolver, SHOULDER_SETTINGS), AirTriggerPrefs.led(app))) + // Entering the scene turns the lights off; the release actions show the idle light picked in RedMagic's lighting settings. + AirTrigger.entries.forEach { lights.request(it.releaseLight) } + } + + /** The code RedMagic's shoulder light settings give the effect, such as "02101000" for steady. */ + internal fun shoulderEffect(settings: String?, led: AirTriggerLed): String = settings + ?.let { runCatching { JSONObject(it).optJSONObject("shoulder_effects")?.optString(led.effect) }.getOrNull() } + ?.takeIf { it.length == 8 } ?: led.fallback + + /** Closes only what this app opened, so a distribute another app turned on stays on. Call on the main thread. */ + fun restore(context: Context) { + val app = context.applicationContext + cancelReapply() + worker.execute { + val prefs = AirTriggerPrefs.prefs(app) + if (!prefs.getBoolean(AirTriggerPrefs.OWNED, false)) return@execute + lights.request(SHOULDER_LIGHT_OFF) + if (call(app, CLOSE)) prefs.edit().remove(AirTriggerPrefs.OWNED).commit() + } + } + + fun light(code: Int) = worker.execute { lights.request(code) } + + private fun cancelReapply() { + reapply?.let(main::removeCallbacks) + reapply = null + } + + private fun call(context: Context, method: String) = runCatching { context.contentResolver.call(URI, method, null, null) != null } + .onFailure { Log.w(TAG, "$method failed", it) }.getOrDefault(false) +} + +internal interface TriggerLights { + fun request(action: Int) + fun setEffect(effect: String) +} + +private object ColorfulLights : TriggerLights { + private const val TAG = "AirTriggers" + private const val SERVICE = "ColorfulLightService" + private const val INTERFACE = "com.zte.hardware.IColorfulLightManager" + // IColorfulLightManager transaction codes; its ColorfulLightManager wrapper is a blocked hidden API. + private const val REQUEST_LIGHT = IBinder.FIRST_CALL_TRANSACTION + private const val SET_SHOULDER_EFFECT = IBinder.FIRST_CALL_TRANSACTION + 2 + private val binder: IBinder? by lazy { + runCatching { Class.forName("android.os.ServiceManager").getMethod("getService", String::class.java).invoke(null, SERVICE) as IBinder? } + .getOrNull()?.takeIf { runCatching { it.interfaceDescriptor }.getOrNull() == INTERFACE } + } + + override fun request(action: Int) = transact(REQUEST_LIGHT) { writeInt(action) } + override fun setEffect(effect: String) = transact(SET_SHOULDER_EFFECT) { writeString(effect) } + + private fun transact(code: Int, write: Parcel.() -> Unit) { + val binder = binder ?: return + val data = Parcel.obtain() + val reply = Parcel.obtain() + try { + data.writeInterfaceToken(INTERFACE) + data.write() + binder.transact(code, data, reply, 0) + reply.readException() + } catch (e: Exception) { + Log.w(TAG, "light call $code failed", e) + } finally { + data.recycle() + reply.recycle() + } + } +} + +/** Presses the chosen button on screen when it is shown, so it animates and keeps one toggle state; otherwise uses a source of its own. */ +class AirTriggerInput( + private val pad: PadBridge, + private val onScreen: (elementId: String, trigger: AirTrigger, held: Boolean, cancelled: Boolean) -> Boolean = { _, _, _, _ -> false }, + private val touched: (AirTrigger, Boolean) -> Unit = { _, _ -> }, + private val handler: Handler = Handler(Looper.getMainLooper()), +) { + private val sources = EnumMap(AirTrigger::class.java) + private val setups = EnumMap(AirTrigger::class.java) + private val held = EnumSet.noneOf(AirTrigger::class.java) + private val pressed = EnumSet.noneOf(AirTrigger::class.java) + private val heldOnScreen = EnumMap(AirTrigger::class.java) + private val timers = EnumMap(AirTrigger::class.java) + + fun configure(setups: Map) { + for (trigger in AirTrigger.entries) { + val setup = setups[trigger] + if (this.setups[trigger] == setup) continue + stop(trigger) + if (sources[trigger]?.element != setup?.target) { + pressed.remove(trigger) + heldOnScreen.remove(trigger)?.let { onScreen(it, trigger, false, true) } + sources.remove(trigger)?.close() + if (setup != null) sources[trigger] = InputSurfaceSource(pad, InputRole.PRIMARY, setup.target) + } else if (trigger in pressed) unpress(trigger, cancelled = true) + if (setup != null) this.setups[trigger] = setup else this.setups.remove(trigger) + } + } + + fun onKey(event: KeyEvent, enabled: () -> Boolean): Boolean { + if (event.keyCode != AirTrigger.LEFT.keyCode && event.keyCode != AirTrigger.RIGHT.keyCode) return false + val trigger = AirTrigger.of(event.keyCode, event.device) ?: return false + return onKey(trigger, event.action, event.repeatCount, event.action == KeyEvent.ACTION_DOWN && enabled()) + } + + fun onKey(trigger: AirTrigger, action: Int, repeatCount: Int, enabled: Boolean): Boolean { + val source = sources[trigger] + when (action) { + KeyEvent.ACTION_DOWN -> if (source != null && enabled && repeatCount == 0 && held.add(trigger)) { + touched(trigger, true) + val setup = setups[trigger] + if (setup?.action == AirTriggerAction.LATCH && trigger in pressed) unpress(trigger, cancelled = false) + else if (trigger !in pressed) { + press(trigger, source) + if (setup?.action == AirTriggerAction.RAPID) rapid(trigger, 500L / setup.rate.clicksPerSecond) + } + } + KeyEvent.ACTION_UP -> if (held.remove(trigger)) { + touched(trigger, false) + if (setups[trigger]?.action != AirTriggerAction.LATCH) { + stop(trigger) + if (trigger in pressed) unpress(trigger, cancelled = false) + } + return true + } + } + return source != null + } + + private fun rapid(trigger: AirTrigger, halfPeriod: Long) { + val tick = object : Runnable { + override fun run() { + if (trigger in pressed) unpress(trigger, cancelled = false) else sources[trigger]?.let { press(trigger, it) } + handler.postDelayed(this, halfPeriod) + } + } + timers[trigger] = tick + handler.postDelayed(tick, halfPeriod) + } + + private fun stop(trigger: AirTrigger) { + timers.remove(trigger)?.let(handler::removeCallbacks) + } + + private fun press(trigger: AirTrigger, source: InputSurfaceSource) { + pressed += trigger + if (source.element == setups[trigger]?.element && onScreen(source.element.id, trigger, true, false)) { + heldOnScreen[trigger] = source.element.id + // The router counts held keys, so a toggle latched while its button was hidden is released before the button takes over. + if (source.latched) source.release() + } else source.update(1f) + } + + private fun unpress(trigger: AirTrigger, cancelled: Boolean) { + pressed -= trigger + heldOnScreen.remove(trigger)?.let { onScreen(it, trigger, false, cancelled) } + ?: sources[trigger]?.let { if (cancelled) it.cancel() else it.update(0f) } + } + + fun release() { + AirTrigger.entries.forEach(::stop) + held.toList().forEach { held.remove(it); touched(it, false) } + pressed.toList().forEach { unpress(it, cancelled = true) } + sources.values.forEach { it.release() } + } + + fun close() { + release() + sources.values.forEach { it.close() } + sources.clear() + setups.clear() + } +} diff --git a/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt b/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt index c9c55f9c27..566f2bf20f 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt @@ -268,7 +268,7 @@ internal object EnhancedSessionLogShare { val out = outputDirectory.apply { deleteRecursively(); mkdirs() } val redactionLearningComplete = LogRedactor.learnFromRuntime(LinuxRuntime.rootDir(context)) val discovery = collect(context, folder, limits.maxDiscoveredFiles, legacy = true) - val candidates = discovery.candidates.filter { it.linePrefix == null } + val candidates = discovery.candidates.filter { it.linePrefix == null }.sortedBy(::sharePriority) if (candidates.isEmpty()) { out.deleteRecursively() return null @@ -697,15 +697,6 @@ internal object EnhancedSessionLogShare { Category.GAMES, "DROIDDECK_DIAGNOSTICS event=game_", ) } - if (SessionPaths.current()?.canonicalFile == folder.canonicalFile && !File(folder, "steam").exists()) { - val steam = File(SessionPrefs.activeSteamRoot(context), "logs") - val scan = directFiles(steam, remaining(maxFiles, out.size)) - truncated = truncated || scan.truncated - partial = partial || scan.partial - scan.files.forEach { - add(it, steam, "${folder.name}/steam/${it.name}", "live-steam") - } - } val logs = LinuxRuntime.logDir(context) for ((name, root) in listOf(SessionLogShare.STORES_DIR to File(logs, SessionLogShare.STORES_DIR), SessionPaths.TOOLS_DIR to File(logs, SessionPaths.TOOLS_DIR))) { val scan = directFiles(root, STORE_LOG_SCAN) @@ -742,9 +733,24 @@ internal object EnhancedSessionLogShare { if (relative == EnhancedDiagnostics.MANIFEST_FILE) return@forEach add(file, folder, "${folder.name}/$relative", "session") } + if (SessionPaths.current()?.canonicalFile == folder.canonicalFile && !File(folder, "steam").exists()) { + val steam = File(SessionPrefs.activeSteamRoot(context), "logs") + val scan = directFiles(steam, remaining(maxFiles, out.size)) + truncated = truncated || scan.truncated + partial = partial || scan.partial + scan.files.forEach { + add(it, steam, "${folder.name}/steam/${it.name}", "live-steam") + } + } return CollectionResult(out.values.toList(), truncated, partial) } + private fun sharePriority(candidate: Candidate): Int = when { + candidate.origin == "session-critical" -> 0 + candidate.origin == "session" && candidate.category == Category.GAMES -> 1 + else -> 2 + } + private fun remaining(maxFiles: Int, found: Int): Int = (maxFiles - found + 1).coerceAtLeast(0) private fun walk(root: File, limit: Int): ScanResult { diff --git a/app/src/main/java/com/droiddeck/launcher/session/ProtonExtras.kt b/app/src/main/java/com/droiddeck/launcher/session/ProtonExtras.kt index 412fc79627..756a721a7a 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/ProtonExtras.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/ProtonExtras.kt @@ -9,6 +9,8 @@ import com.droiddeck.launcher.core.Downloader import com.droiddeck.launcher.core.FileUtils import com.droiddeck.launcher.runtime.LinuxRuntime import com.droiddeck.launcher.runtime.NativeGuest +import com.droiddeck.launcher.storage.SteamStorage +import com.droiddeck.launcher.stores.steam.SteamClient import java.io.File import java.util.Locale import org.json.JSONArray @@ -34,7 +36,9 @@ object ProtonExtras { private var replacing = false class Tool(val id: String, val name: String, val prefix: String, val repo: String, val assetPattern: Regex, - val prereleases: Boolean = false) + val prereleases: Boolean = false, val x86_64: Boolean = false, val label: Int = 0) { + val arch: String get() = if (x86_64) "x86-64" else "ARM64" + } internal data class Asset(val tag: String, val name: String, val url: String, val sha512: String?, val size: Long, val sha256: String? = null, val releaseName: String = tag) @@ -42,11 +46,13 @@ object ProtonExtras { const val OWN = "droiddeck" const val BIONIC = "bionic" + const val ANTICHEAT = "anticheat" val tools = listOf( Tool("ge", "GE-Proton", "GE-Proton", "GloriousEggroll/proton-ge-custom", Regex("aarch64\\.tar\\.(gz|xz)$")), Tool("cachyos", "proton-cachyos", "proton-cachyos", "CachyOS/proton-cachyos", Regex("arm64\\.tar\\.(gz|xz)$")), Tool("droiddeck", "DroidDeck-Proton", "DroidDeck-Proton", "Droid-Deck/DroidDeck-Proton", Regex("^DroidDeck-Proton-.*aarch64\\.tar\\.(gz|xz)$")), + Tool(ANTICHEAT, "DroidDeck-Proton x86-64", "DroidDeck-Proton", "Droid-Deck/DroidDeck-Proton", Regex("^DroidDeck-Proton-.*x86_64\\.tar\\.(gz|xz)$"), x86_64 = true, label = R.string.pextra_anticheat), // Bionic (Android libc) Proton started outside the Linux userland; test builds are prereleases. No-proot only. Tool(BIONIC, "DroidDeck-Bionic", "DroidDeck-Bionic", "Droid-Deck/DroidDeck-Proton", Regex("^DroidDeck-Bionic-.*aarch64\\.tar\\.(gz|xz)$"), prereleases = true), ) @@ -66,11 +72,14 @@ object ProtonExtras { internal fun installedIn(dir: File, tool: Tool): List = dir.listFiles() - ?.filter { it.isDirectory && it.name.startsWith(tool.prefix) && usable(it) } + ?.filter { it.isDirectory && it.name.startsWith(tool.prefix) && x86_64Build(it) == tool.x86_64 && usable(it) } ?.map { it.name } ?.sortedWith { a, b -> compareVersions(a, b) } ?: emptyList() + internal fun x86_64Build(dir: File): Boolean = + File(dir, "files/lib/wine/x86_64-unix").isDirectory && !File(dir, "files/bin-arm64").isDirectory + private fun usable(dir: File): Boolean { val manifest = runCatching { File(dir, "toolmanifest.vdf").readText() }.getOrNull() ?: return false val command = Regex("\\\"commandline\\\"\\s+\\\"/?([^\\\" ]+)").find(manifest)?.groupValues?.getOrNull(1) ?: return false @@ -108,15 +117,31 @@ object ProtonExtras { fun update(context: Context, tool: Tool): String? = updateFor(installedTags(context, tool), cachedLatest(context, tool)) - fun missing(context: Context, tool: Tool): String? = - if (tool.id == OWN && !declined(context) && installedAll(context, tool).isEmpty()) cachedLatest(context, tool) else null + fun missing(context: Context, tool: Tool): String? = missing(context, tool) { antiCheatRuntimeInstalled(context) } + + internal fun missing(context: Context, tool: Tool, antiCheat: () -> Boolean): String? = when { + declined(context, tool.id) || installedAll(context, tool).isNotEmpty() -> null + tool.id == OWN || tool.id == ANTICHEAT && antiCheat() -> cachedLatest(context, tool) + else -> null + } + + private fun antiCheatRuntimeInstalled(context: Context): Boolean = + antiCheatRuntimeIn(listOf("arm64", SteamClient.X86_64).flatMap { arch -> + runCatching { SteamClient.libraries(context, arch).map { it.host } }.getOrDefault(emptyList()) + } + listOfNotNull(GameStorage.effective(context)?.let { File(it.path) }, GameStorage.x64CardLibrary(context))) + + internal fun antiCheatRuntimeIn(libraries: List): Boolean = libraries.any { library -> + ANTICHEAT_RUNTIMES.any { File(library, "steamapps/appmanifest_$it.acf").isFile } + } + + private val ANTICHEAT_RUNTIMES = listOf(SteamStorage.EAC_RUNTIME, SteamStorage.BATTLEYE_RUNTIME) private fun choices(context: Context) = context.getSharedPreferences("proton-auto-updates", Context.MODE_PRIVATE) - fun declined(context: Context): Boolean = choices(context).getBoolean("$OWN.declined", false) + fun declined(context: Context, id: String = OWN): Boolean = choices(context).getBoolean("$id.declined", false) - fun setDeclined(context: Context, declined: Boolean) { - choices(context).edit().putBoolean("$OWN.declined", declined).apply() + fun setDeclined(context: Context, declined: Boolean, id: String = OWN) { + choices(context).edit().putBoolean("$id.declined", declined).apply() } fun cachedLatest(context: Context, tool: Tool): String? = @@ -220,8 +245,8 @@ object ProtonExtras { if (runCatching { ComponentsManager.carryOver(context, old, newest) }.onFailure { Log.w(TAG, "components of $old", it) }.isFailure) continue if (runCatching { keepUserSettings(context, old, newest) }.onFailure { Log.w(TAG, "user settings of $old", it) }.isFailure) continue if (runCatching { ProtonDefault.moveGames(context, setOf(old), newest) }.onFailure { Log.w(TAG, "per-game picks of $old", it) }.isFailure) continue - // DroidDeck-Bionic only: the guest finds no default for a deleted Bionic build and falls back to DroidDeck-Proton - if (tool.id == BIONIC && runCatching { ProtonDefault.moveDefault(context, setOf(old), newest) }.onFailure { Log.w(TAG, "default pick of $old", it) }.isFailure) continue + // DroidDeck-Bionic and the x86-64 build: the guest finds no default for a deleted build and falls back to DroidDeck-Proton + if ((tool.id == BIONIC || tool.id == ANTICHEAT) && runCatching { ProtonDefault.moveDefault(context, setOf(old), newest) }.onFailure { Log.w(TAG, "default pick of $old", it) }.isFailure) continue if (deleteTool(context, old)) ComponentsManager.forgetProton(context, old) else Log.w(TAG, "could not remove $old") } @@ -288,7 +313,7 @@ object ProtonExtras { } private fun prefetchNow(context: Context, tool: Tool, onProgress: (String, Int) -> Unit): String? { - val asset = releases(tool)?.let { pickAsset(tool, it) } ?: return context.getString(R.string.pextra_no_release, tool.name) + val asset = releases(tool)?.let { pickAsset(tool, it) } ?: return context.getString(R.string.pextra_no_release, tool.name, tool.arch) val downloads = File(context.filesDir, "proton-downloads").apply { mkdirs() } val archive = File(downloads, "${tool.id}-${asset.name}") if (asset.size > 0 && archive.length() > asset.size) archive.delete() @@ -305,7 +330,7 @@ object ProtonExtras { if (SessionState.running) return context.getString(R.string.pextra_stop_session) if (!LinuxRuntime.isInstalled(context)) return context.getString(R.string.user_apps_runtime_required) - val asset = releases(tool)?.let { pickAsset(tool, it) } ?: return context.getString(R.string.pextra_no_release, tool.name) + val asset = releases(tool)?.let { pickAsset(tool, it) } ?: return context.getString(R.string.pextra_no_release, tool.name, tool.arch) val downloads = File(context.filesDir, "proton-downloads").apply { mkdirs() } val archive = File(downloads, "${tool.id}-${asset.name}") if (asset.size > 0 && archive.length() > asset.size) archive.delete() @@ -374,7 +399,7 @@ object ProtonExtras { archive.delete() unqueue(context, tool) record(context, tool, placed, asset.tag) - if (tool.id == OWN || tool.id == BIONIC) replaceOlder(context, tool) + if (tool.id == OWN || tool.id == BIONIC || tool.id == ANTICHEAT) replaceOlder(context, tool) if (EsyncPacks.enabled(context)) { onProgress(context.getString(R.string.esync_fetching), -1) try { diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt index f74b122855..e274182222 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt @@ -1913,6 +1913,9 @@ object SessionPrefs { return if (pip && mirrorRefreshLimit <= 0 && (limit <= 0 || limit > PIP_FPS)) PIP_FPS else limit } + fun layerFrameRate(ownLimit: Int, refreshHz: Float, blackFrameInsertion: Boolean): Float = + if (ownLimit > 0 && !blackFrameInsertion) ownLimit.toFloat() else refreshHz + /** The per-app rate Android holds this window to (Game Mode's FPS override), or 0 when the panel's rate applies. */ fun hostFrameCap(overrideHz: Float, panelHz: Float): Int = if (overrideHz > 1f && panelHz - overrideHz > 1f) Math.round(overrideHz) else 0 @@ -2012,24 +2015,84 @@ object SessionPrefs { sessionPrefs.edit().putString(SCREEN_EFFECTS_PROFILES_KEY, profiles.toString()).apply() } + private const val GAME_UPSCALER_OVERRIDES_KEY = "upscaler.gameOverrides" + + private fun gameUpscalerOverrides(context: Context): JSONObject = runCatching { + JSONObject(prefs(context).getString(GAME_UPSCALER_OVERRIDES_KEY, null) ?: "{}") + }.getOrDefault(JSONObject()) + + private fun legacyScreenEffectsUpscaler(context: Context, profileId: String): Int? = + runCatching { + val profiles = JSONObject(prefs(context).getString(SCREEN_EFFECTS_PROFILES_KEY, null) ?: "{}") + val profile = profiles.optJSONObject(profileId) + if (profile?.has(SCREEN_EFFECTS_PROFILE_UPSCALER_KEY) == true) { + profile.optInt(SCREEN_EFFECTS_PROFILE_UPSCALER_KEY, -1).takeIf { it >= 0 } + } else null + }.getOrNull()?.let(::canonicalUpscaler) + + private fun clearLegacyScreenEffectsUpscaler(context: Context, profileId: String) { + val sessionPrefs = prefs(context) + val profiles = runCatching { + JSONObject(sessionPrefs.getString(SCREEN_EFFECTS_PROFILES_KEY, null) ?: "{}") + }.getOrNull() ?: return + val profile = profiles.optJSONObject(profileId) ?: return + if (!profile.has(SCREEN_EFFECTS_PROFILE_UPSCALER_KEY)) return + profile.remove(SCREEN_EFFECTS_PROFILE_UPSCALER_KEY) + if (profile.length() == 0) profiles.remove(profileId) + sessionPrefs.edit().apply { + if (profiles.length() == 0) remove(SCREEN_EFFECTS_PROFILES_KEY) + else putString(SCREEN_EFFECTS_PROFILES_KEY, profiles.toString()) + }.apply() + } + + fun hasGameUpscalerOverride(context: Context, gameId: String): Boolean { + if (gameId.isBlank()) return false + val stored = gameUpscalerOverrides(context) + return (stored.has(gameId) && stored.optInt(gameId, -1) >= 0) || + legacyScreenEffectsUpscaler(context, "game:$gameId") != null + } + + fun setGameUpscaler(context: Context, gameId: String, mode: Int) { + if (gameId.isBlank()) return + val overrides = gameUpscalerOverrides(context) + overrides.put(gameId, canonicalUpscaler(mode)) + prefs(context).edit().putString(GAME_UPSCALER_OVERRIDES_KEY, overrides.toString()).apply() + clearLegacyScreenEffectsUpscaler(context, "game:$gameId") + } + + fun clearGameUpscaler(context: Context, gameId: String) { + if (gameId.isBlank()) return + val sessionPrefs = prefs(context) + val overrides = gameUpscalerOverrides(context) + if (overrides.has(gameId)) { + overrides.remove(gameId) + sessionPrefs.edit().apply { + if (overrides.length() == 0) remove(GAME_UPSCALER_OVERRIDES_KEY) + else putString(GAME_UPSCALER_OVERRIDES_KEY, overrides.toString()) + }.apply() + } + clearLegacyScreenEffectsUpscaler(context, "game:$gameId") + } + fun hasScreenEffectsUpscalerOverride(context: Context, profileId: String?): Boolean { if (profileId.isNullOrBlank()) return false - return runCatching { - val profiles = JSONObject(prefs(context).getString(SCREEN_EFFECTS_PROFILES_KEY, null) ?: "{}") - profiles.optJSONObject(profileId)?.has(SCREEN_EFFECTS_PROFILE_UPSCALER_KEY) == true - }.getOrDefault(false) + if (profileId.startsWith("game:")) { + return hasGameUpscalerOverride(context, profileId.removePrefix("game:")) + } + return legacyScreenEffectsUpscaler(context, profileId) != null } fun screenEffectsUpscaler(context: Context, profileId: String?): Int { if (profileId.isNullOrBlank()) return upscaler(context) - val stored = runCatching { - val profiles = JSONObject(prefs(context).getString(SCREEN_EFFECTS_PROFILES_KEY, null) ?: "{}") - val profile = profiles.optJSONObject(profileId) - if (profile?.has(SCREEN_EFFECTS_PROFILE_UPSCALER_KEY) == true) { - profile.optInt(SCREEN_EFFECTS_PROFILE_UPSCALER_KEY, -1) - } else -1 - }.getOrDefault(-1) - return if (stored >= 0) canonicalUpscaler(stored) else upscaler(context) + if (profileId.startsWith("game:")) { + val gameId = profileId.removePrefix("game:") + val overrides = gameUpscalerOverrides(context) + if (overrides.has(gameId)) { + val stored = overrides.optInt(gameId, -1) + if (stored >= 0) return canonicalUpscaler(stored) + } + } + return legacyScreenEffectsUpscaler(context, profileId) ?: upscaler(context) } fun setScreenEffectsUpscaler(context: Context, profileId: String?, mode: Int) { @@ -2037,6 +2100,10 @@ object SessionPrefs { setUpscaler(context, mode) return } + if (profileId.startsWith("game:")) { + setGameUpscaler(context, profileId.removePrefix("game:"), mode) + return + } val sessionPrefs = prefs(context) val profiles = runCatching { JSONObject(sessionPrefs.getString(SCREEN_EFFECTS_PROFILES_KEY, null) ?: "{}") @@ -2073,6 +2140,7 @@ object SessionPrefs { val profiles = runCatching { JSONObject(sessionPrefs.getString(SCREEN_EFFECTS_PROFILES_KEY, null) ?: "{}") }.getOrElse { JSONObject() } + if (profileId.startsWith("game:")) clearGameUpscaler(context, profileId.removePrefix("game:")) if (!profiles.has(profileId)) return profiles.remove(profileId) sessionPrefs.edit().apply { diff --git a/app/src/main/java/com/droiddeck/launcher/ui/AirTriggerGlow.kt b/app/src/main/java/com/droiddeck/launcher/ui/AirTriggerGlow.kt new file mode 100644 index 0000000000..d4d734fa02 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/ui/AirTriggerGlow.kt @@ -0,0 +1,62 @@ +package com.droiddeck.launcher.ui + +import android.annotation.SuppressLint +import android.content.Context +import android.graphics.Canvas +import android.graphics.Color +import android.graphics.LinearGradient +import android.graphics.Paint +import android.graphics.Shader +import android.view.View +import android.widget.FrameLayout +import com.droiddeck.launcher.input.AirTrigger +import java.util.EnumMap +import java.util.EnumSet + +@SuppressLint("ViewConstructor") +class AirTriggerGlow(context: Context) : View(context) { + private val lit = EnumSet.noneOf(AirTrigger::class.java) + private val density = resources.displayMetrics.density + private val paints = EnumMap(AirTrigger::class.java) + + init { + isClickable = false + isFocusable = false + importantForAccessibility = IMPORTANT_FOR_ACCESSIBILITY_NO + layoutParams = FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT) + val top = TOP_DP * density + for ((trigger, look) in mapOf(AirTrigger.LEFT to LEFT, AirTrigger.RIGHT to RIGHT)) { + val (color, fade) = look + paints[trigger] = Paint().apply { + shader = LinearGradient(0f, top, 0f, top + HEIGHT_DP * density, + fade.map { Color.argb(it, Color.red(color), Color.green(color), Color.blue(color)) }.toIntArray(), + STOPS, Shader.TileMode.CLAMP) + } + } + } + + fun show(trigger: AirTrigger, on: Boolean) { + if (if (on) lit.add(trigger) else lit.remove(trigger)) invalidate() + } + + override fun onDraw(canvas: Canvas) { + val width = WIDTH_DP * density + val margin = SIDE_DP * density + val top = TOP_DP * density + for (trigger in lit) { + val left = if (trigger == AirTrigger.LEFT) margin else this.width - margin - width + canvas.drawRect(left, top, left + width, top + HEIGHT_DP * density, paints.getValue(trigger)) + } + } + + private companion object { + // Game Space's tgk_*_top_pressed images and their landscape placement on a 2688 x 1216 RedMagic screen. + const val WIDTH_DP = 78f + const val HEIGHT_DP = 33f + const val SIDE_DP = 37f + const val TOP_DP = 2f + val STOPS = floatArrayOf(0f, 0.04f, 0.05f, 0.2f, 0.4f, 0.6f, 0.8f, 1f) + val LEFT = Color.rgb(230, 23, 57) to listOf(255, 255, 150, 102, 55, 36, 18, 0) + val RIGHT = Color.rgb(23, 91, 230) to listOf(255, 255, 151, 94, 41, 27, 14, 0) + } +} diff --git a/app/src/main/java/com/droiddeck/launcher/ui/ControllerHaptics.kt b/app/src/main/java/com/droiddeck/launcher/ui/ControllerHaptics.kt index da1d8d4bb4..b954512fff 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/ControllerHaptics.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/ControllerHaptics.kt @@ -24,7 +24,11 @@ object ControllerHaptics { tick(context) } - fun tick(context: Context) { + fun tick(context: Context) = vibrate(context, VibrationEffect.EFFECT_TICK, 10) + + fun click(context: Context) = vibrate(context, VibrationEffect.EFFECT_CLICK, 20) + + private fun vibrate(context: Context, predefined: Int, fallbackMs: Long) { val vibrator = if (Build.VERSION.SDK_INT >= 31) { context.getSystemService(VibratorManager::class.java)?.defaultVibrator } else { @@ -32,11 +36,11 @@ object ControllerHaptics { } ?: return if (!vibrator.hasVibrator()) return if (Build.VERSION.SDK_INT >= 29) { - vibrator.vibrate(VibrationEffect.createPredefined(VibrationEffect.EFFECT_TICK)) + vibrator.vibrate(VibrationEffect.createPredefined(predefined)) } else if (Build.VERSION.SDK_INT >= 26) { - vibrator.vibrate(VibrationEffect.createOneShot(10, VibrationEffect.DEFAULT_AMPLITUDE)) + vibrator.vibrate(VibrationEffect.createOneShot(fallbackMs, VibrationEffect.DEFAULT_AMPLITUDE)) } else { - @Suppress("DEPRECATION") vibrator.vibrate(10) + @Suppress("DEPRECATION") vibrator.vibrate(fallbackMs) } } } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt index 3bec0c50aa..4047781350 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt @@ -881,6 +881,28 @@ internal fun LaunchSettings(s: FrontEndState, a: FrontEndActions, host: MenuHost com.droiddeck.launcher.gpu.FrameGen.hasGameOverride(context, it) } ?: false) } + val scalingFilterChoices = SessionPrefs.upscalerChoices(context) + var gameUpscaler by remember(frameGenProfileKey) { + mutableStateOf(frameGenProfileKey?.let { + SessionPrefs.screenEffectsUpscaler(context, "game:$it") + } ?: SessionPrefs.upscaler(context)) + } + var gameUpscalerOverride by remember(frameGenProfileKey) { + mutableStateOf(frameGenProfileKey?.let { SessionPrefs.hasGameUpscalerOverride(context, it) } ?: false) + } + val lifecycleOwner = LocalLifecycleOwner.current + DisposableEffect(lifecycleOwner, frameGenProfileKey) { + val observer = LifecycleEventObserver { _, event -> + if (event == Lifecycle.Event.ON_RESUME) { + frameGenProfileKey?.let { key -> + gameUpscaler = SessionPrefs.screenEffectsUpscaler(context, "game:$key") + gameUpscalerOverride = SessionPrefs.hasGameUpscalerOverride(context, key) + } + } + } + lifecycleOwner.lifecycle.addObserver(observer) + onDispose { lifecycleOwner.lifecycle.removeObserver(observer) } + } var wincompOpen by remember(wincompKey) { mutableStateOf(null) } val wincompPicks = remember(wincompKey, wincompOpen) { wincompKey?.let { com.droiddeck.launcher.session.WinComponents.picks(context, it) }.orEmpty() } val steamScope = game?.let { com.droiddeck.launcher.session.NoSteamLaunch.scope(it) } @@ -914,6 +936,25 @@ internal fun LaunchSettings(s: FrontEndState, a: FrontEndActions, host: MenuHost }, ) } + val scalingFilterMenuContent: @Composable () -> Unit = { + val key = frameGenProfileKey + if (key != null) ScalingFilterMenu( + mode = gameUpscaler, + options = scalingFilterChoices, + hasGameOverride = gameUpscalerOverride, + onPick = { mode -> + SessionPrefs.setGameUpscaler(context, key, mode) + gameUpscaler = SessionPrefs.screenEffectsUpscaler(context, "game:$key") + gameUpscalerOverride = SessionPrefs.hasGameUpscalerOverride(context, key) + }, + onResetGame = { + SessionPrefs.clearGameUpscaler(context, key) + gameUpscaler = SessionPrefs.upscaler(context) + gameUpscalerOverride = false + }, + gameName = game?.name, + ) + } val cards = if (game?.library == com.droiddeck.launcher.frontend.Library.EPIC_LAUNCHER) listOfNotNull(steamCard) else buildList<@Composable (Modifier) -> Unit> { add { m -> val back = stringResource(R.string.hop_from_games) @@ -938,6 +979,17 @@ internal fun LaunchSettings(s: FrontEndState, a: FrontEndActions, host: MenuHost } } + if (frameGenProfileKey != null) add { m -> + Box(m) { + SettingCard( + stringResource(R.string.display_filter), + scalingFilterChoices.firstOrNull { it.first == gameUpscaler }?.second ?: scalingFilterChoices.first().second, + "card:scaling-filter", Modifier.fillMaxSize(), + ) { + host.open = if (host.open == "scaling-filter") null else "scaling-filter" + } + } + } if (controller != null) add { m -> SettingCard(stringResource(R.string.setup_card_controls), stringResource(R.string.setup_card_controls_hint), "card:controls", m, controller.onMapping) } if (steamCard != null) add(steamCard) val cardStore = com.droiddeck.launcher.stores.Store.byId(game?.source.orEmpty())?.takeIf { it == com.droiddeck.launcher.stores.Store.EPIC || it == com.droiddeck.launcher.stores.Store.GOG } @@ -972,6 +1024,11 @@ internal fun LaunchSettings(s: FrontEndState, a: FrontEndActions, host: MenuHost frameGenMenuContent() } } + if (host.open == "scaling-filter") { + Box(Modifier.fillMaxWidth().padding(top = 4.dp)) { + scalingFilterMenuContent() + } + } } } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/InputSurfaceView.kt b/app/src/main/java/com/droiddeck/launcher/ui/InputSurfaceView.kt index e0d0207ff3..b57dddc10d 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/InputSurfaceView.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/InputSurfaceView.kt @@ -137,7 +137,7 @@ class InputSurfaceView( val views = owners.values.distinct() owners.clear() for (view in views) { - if (view is HoldButton) { view.cancel(); continue } + if (view is HoldButton) { view.cancelTouches(); continue } val cancel = MotionEvent.obtain(event.downTime, event.eventTime, MotionEvent.ACTION_CANCEL, 0f, 0f, 0) try { view.dispatchTouchEvent(cancel) } finally { cancel.recycle() } } @@ -176,10 +176,23 @@ class InputSurfaceView( val now = android.os.SystemClock.uptimeMillis() val cancel = MotionEvent.obtain(now, now, MotionEvent.ACTION_CANCEL, 0f, 0f, 0) try { cancelOwners(cancel) } finally { cancel.recycle() } + customCanvas?.let { canvas -> for (i in 0 until canvas.childCount) (canvas.getChildAt(i) as? HoldButton)?.cancel() } forwardedPointers = 0 elementSources.forEach { it.release() } } + /** Presses a button as a finger would, for input from outside the screen; [holder] tells holds apart. */ + fun hold(elementId: String, holder: Int, held: Boolean, cancelled: Boolean = false): Boolean { + val canvas = customCanvas ?: return false + for (i in 0 until canvas.childCount) { + val button = canvas.getChildAt(i) as? HoldButton ?: continue + if ((button.tag as? InputSurfaceElement)?.id != elementId) continue + button.press(-1 - holder, held, cancelled) + return true + } + return false + } + override fun onVisibilityChanged(changedView: View, visibility: Int) { super.onVisibilityChanged(changedView, visibility) if (visibility != VISIBLE) releaseInputs() @@ -482,17 +495,22 @@ class InputSurfaceView( fun press(pointer: Int, pressed: Boolean, cancelled: Boolean = false) { if (pressed) pointers.add(pointer) else pointers.remove(pointer) - set(pointers.isNotEmpty(), cancelled) + set(pointers.isNotEmpty(), cancelled, touch = pointer >= 0) } fun cancel() { pointers.clear(); set(false, cancelled = true); source?.release() } + fun cancelTouches() { + pointers.removeAll { it >= 0 } + if (pointers.isEmpty()) cancel() + } + override fun onDetachedFromWindow() { cancel(); super.onDetachedFromWindow() } - private fun set(pressed: Boolean, cancelled: Boolean = false) { + private fun set(pressed: Boolean, cancelled: Boolean = false, touch: Boolean = true) { if (down == pressed) return down = pressed - if (pressed) feedback(this, HapticFeedbackConstants.VIRTUAL_KEY) + if (pressed && touch) feedback(this, HapticFeedbackConstants.VIRTUAL_KEY) if (!pressed && cancelled) source?.cancel() else source?.update(if (pressed) 1f else 0f) invalidate() if (artwork != null && this in artworkDpad) customCanvas?.invalidate() diff --git a/app/src/main/java/com/droiddeck/launcher/ui/ScalingFilterMenu.kt b/app/src/main/java/com/droiddeck/launcher/ui/ScalingFilterMenu.kt new file mode 100644 index 0000000000..b012bb1292 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/ui/ScalingFilterMenu.kt @@ -0,0 +1,69 @@ +package com.droiddeck.launcher.ui + +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.ButtonDefaults +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.OutlinedButton +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp +import com.droiddeck.launcher.R + +@Composable +internal fun ScalingFilterMenu( + mode: Int, + options: List>, + hasGameOverride: Boolean, + onPick: (Int) -> Unit, + onResetGame: () -> Unit, + gameName: String? = null, +) { + val colors = MaterialTheme.colorScheme + Column(Modifier.fillMaxWidth().padding(start = 10.dp, end = 10.dp, bottom = 8.dp)) { + val selectedLabel = options.firstOrNull { it.first == mode }?.second ?: mode.toString() + Text( + stringResource( + if (hasGameOverride) R.string.display_filter_game_profile else R.string.display_filter_default_profile, + if (hasGameOverride) gameName.orEmpty() else selectedLabel, + selectedLabel, + ), + color = colors.onSurfaceVariant, + style = MaterialTheme.typography.bodySmall, + modifier = Modifier.padding(bottom = 6.dp), + ) + options.forEachIndexed { index, (option, label) -> + val selected = mode == option + val pick = { onPick(option) } + OutlinedButton( + onClick = pick, + modifier = Modifier.fillMaxWidth() + .padding(top = if (index == 0) 0.dp else 6.dp) + .controllerConfirm(onClick = pick), + contentPadding = PaddingValues(horizontal = 12.dp, vertical = 8.dp), + colors = ButtonDefaults.outlinedButtonColors( + containerColor = if (selected) colors.primary.copy(alpha = 0.16f) else colors.surface, + contentColor = if (selected) colors.primary else colors.onSurface, + ), + ) { Text(label) } + } + Text( + stringResource(R.string.display_filter_note), + color = colors.onSurfaceVariant, + style = MaterialTheme.typography.bodySmall, + modifier = Modifier.padding(top = 6.dp), + ) + OutlinedButton( + onClick = onResetGame, + modifier = Modifier.fillMaxWidth().padding(top = 6.dp) + .controllerConfirm(onClick = onResetGame), + contentPadding = PaddingValues(horizontal = 12.dp, vertical = 8.dp), + ) { + Text(stringResource(R.string.comp_game_use_general) + if (hasGameOverride) "" else " ✓") + } + } +} diff --git a/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt b/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt index 4bed33e789..a36fa56ed4 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt @@ -116,6 +116,10 @@ import androidx.compose.foundation.shape.CircleShape import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.droiddeck.launcher.HomeApp +import com.droiddeck.launcher.input.AirTrigger +import com.droiddeck.launcher.input.AirTriggerAction +import com.droiddeck.launcher.input.AirTriggerLed +import com.droiddeck.launcher.input.RapidFireRate import com.droiddeck.launcher.input.ControllerPrefs import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.animateColorAsState @@ -238,6 +242,12 @@ private class DrawerFocus { fun forget(page: SessionDrawerPage) { last.remove(page) } } +data class AirTriggerMenu( + val enabled: Boolean, val selected: Map, val buttons: List>, + val vibration: Boolean = false, val screenLight: Boolean = false, val led: AirTriggerLed = AirTriggerLed.STEADY, + val actions: Map = emptyMap(), val rates: Map = emptyMap(), +) + class DrawerActions( val steam: Boolean, val desktop: Boolean, @@ -342,6 +352,14 @@ class DrawerActions( val onControllerSize: (Int) -> Unit = {}, val onControllerOpacity: (Int) -> Unit = {}, val onRumble: (Boolean) -> Unit = {}, + val airTriggers: AirTriggerMenu? = null, + val onAirTriggers: (Boolean) -> Unit = {}, + val onAirTriggerButton: (AirTrigger, String) -> Unit = { _, _ -> }, + val onAirTriggerAction: (AirTrigger, AirTriggerAction) -> Unit = { _, _ -> }, + val onAirTriggerRate: (AirTrigger, RapidFireRate) -> Unit = { _, _ -> }, + val onAirTriggerVibration: (Boolean) -> Unit = {}, + val onAirTriggerScreenLight: (Boolean) -> Unit = {}, + val onAirTriggerLed: (AirTriggerLed) -> Unit = {}, val onSuspendPolicy: (String) -> Unit, val onSteamDownloadsInBackground: (Boolean) -> Unit = {}, val onBackActionsInverted: (Boolean) -> Unit, @@ -459,6 +477,7 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont remember { DrawerSectionState.load(drawerContext) } var appToChooseDisplay by remember { mutableStateOf(null) } var confirmStop by remember { mutableStateOf(false) } + var airTriggersShown by remember { mutableStateOf(false) } var sheetCoords by remember { mutableStateOf(null) } val widthContext = LocalContext.current var savedWidth by remember { mutableStateOf(SessionPrefs.drawerWidthDp(widthContext)) } @@ -470,15 +489,17 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont val focusManager = LocalFocusManager.current // A page kept inside More is one step deeper than the strip: back returns to More before it closes the menu. val insideMore = page in pages.inMore() + val airPanel = airTriggersShown && page == SessionDrawerPage.CONTROLLER && a.airTriggers != null BackHandler(enabled = open) { when { host.open != null -> host.open = null + airPanel -> airTriggersShown = false insideMore -> onPageChange(SessionDrawerPage.MORE) else -> a.onClose() } } BackHandler(enabled = open && confirmStop) { confirmStop = false } - val layerOpen = open && (host.open != null || appToChooseDisplay != null || confirmStop || insideMore) + val layerOpen = open && (host.open != null || appToChooseDisplay != null || confirmStop || insideMore || airPanel) LaunchedEffect(layerOpen) { onLayerChange(layerOpen) } var seenBackRequest by remember { mutableStateOf(backRequest) } LaunchedEffect(backRequest) { @@ -488,10 +509,23 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont confirmStop -> confirmStop = false appToChooseDisplay != null -> appToChooseDisplay = null host.open != null -> host.open = null + airPanel -> airTriggersShown = false insideMore -> onPageChange(SessionDrawerPage.MORE) } } - LaunchedEffect(page) { host.open = null; appToChooseDisplay = null; managing = false } + LaunchedEffect(page) { host.open = null; appToChooseDisplay = null; managing = false; airTriggersShown = false } + var airPanelFocused by remember { mutableStateOf(airPanel) } + LaunchedEffect(airPanel) { + val moved = airPanel != airPanelFocused + airPanelFocused = airPanel + if (!moved || !open || !controllerActive) return@LaunchedEffect + val target = if (airPanel) "air-triggers-toggle" else "air-triggers" + repeat(24) { + androidx.compose.runtime.withFrameNanos { } + focus.request(target) + if (focus.focused == target) return@LaunchedEffect + } + } LaunchedEffect(host.open) { if (host.open == "frame-generation") repeat(24) { androidx.compose.runtime.withFrameNanos { } @@ -577,6 +611,7 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont .controllerBack { when { host.open != null -> host.open = null + airPanel -> airTriggersShown = false managing -> DrawerPages.heldFrom?.let { held -> DrawerPages.rearrange(drawerContext, held) releaseSignal++ @@ -653,7 +688,9 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont host.open = null; onPageChange(pages.strip().step(pages.tabFor(page), 1)) } } - if (insideMore && !managing) DrawerMoreBack(stringResource(page.title), focus.track(page, "more-back")) { host.open = null; onPageChange(SessionDrawerPage.MORE) } + if (insideMore && !managing && !airPanel) DrawerMoreBack(stringResource(page.title), focus.track(page, "more-back")) { host.open = null; onPageChange(SessionDrawerPage.MORE) } + if (airPanel && !managing) DrawerMoreBack(stringResource(R.string.air_triggers_title), focus.track(page, "air-triggers-back"), + parent = stringResource(page.title)) { host.open = null; airTriggersShown = false } if (managing) ManageDrawerPages( offeredDrawerPages(a.achievementsGame != null), Modifier.weight(1f).fillMaxWidth().padding(top = 8.dp, start = 14.dp, end = 14.dp), @@ -674,7 +711,11 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont CompositionLocalProvider(LocalChipMinWidth provides 96.dp, LocalCompactSettings provides true, LocalDrawerSections provides sections) { DrawerColumns(two = sheetWidth >= DRAWER_TWO_COLUMN_WIDTH && page.inColumns) { when (page) { - SessionDrawerPage.CONTROLLER -> DrawerControllerPage(host, a, a.controllerConnected || controllerActive, track) + SessionDrawerPage.CONTROLLER -> { + val airTriggers = a.airTriggers + if (airPanel && airTriggers != null) AirTriggersPanel(host, airTriggers, a, track) + else DrawerControllerPage(host, a, a.controllerConnected || controllerActive, track) { host.open = null; airTriggersShown = true } + } SessionDrawerPage.HUD -> DrawerPerformancePage(host, a, track) SessionDrawerPage.FRAMEGEN -> DrawerFrameGenPage(host, a, track) SessionDrawerPage.DISPLAY -> DrawerDisplayPage(host, a, track) @@ -734,7 +775,7 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont } @Composable -private fun DrawerControllerPage(host: MenuHost, a: DrawerActions, padConnected: Boolean, track: (String) -> Modifier) { +private fun DrawerControllerPage(host: MenuHost, a: DrawerActions, padConnected: Boolean, track: (String) -> Modifier, onAirTriggers: () -> Unit) { val on = stringResource(R.string.widgets_on) val off = stringResource(R.string.widgets_off) val padTag = if (padConnected) stringResource(R.string.drawer_tag_controller) else null @@ -747,9 +788,12 @@ private fun DrawerControllerPage(host: MenuHost, a: DrawerActions, padConnected: SessionPrefs.CONTROLLER_DUALSENSE to stringResource(R.string.mode_controller_dualsense), SessionPrefs.CONTROLLER_XBOX360 to stringResource(R.string.mode_controller_x360)) val rumbleLabel = stringResource(R.string.ctrl_rumble) - if (a.padType != null || c != null) SettingsGroup( + val airTriggers = a.airTriggers + val airTriggersLabel = stringResource(R.string.air_triggers_title) + if (a.padType != null || c != null || airTriggers != null) SettingsGroup( stringResource(R.string.input_device_settings), key = "controller-pad", tag = padTag, - detail = summary(a.padType?.let { padTypes.labelOf(it) }, c?.let { "$rumbleLabel ${if (it.rumble) on else off}" }), + detail = summary(a.padType?.let { padTypes.labelOf(it) }, c?.let { "$rumbleLabel ${if (it.rumble) on else off}" }, + airTriggers?.let { "$airTriggersLabel ${if (it.enabled) on else off}" }), ) { a.padType?.let { type -> ChoiceRow(host, "pad-type", stringResource(R.string.input_virtual_controller), stringResource(R.string.input_virtual_controller_hint), @@ -758,6 +802,10 @@ private fun DrawerControllerPage(host: MenuHost, a: DrawerActions, padConnected: c?.let { ToggleRow(host, "rumble", rumbleLabel, null, it.rumble, chipModifier = track("rumble"), onChange = a.onRumble) } + airTriggers?.let { + ActionRow(airTriggersLabel, if (it.enabled) on else off, stringResource(R.string.air_triggers_open), onAirTriggers, + modifier = track("air-triggers")) + } } val oscValue = if (!a.steam && a.oscMode == SessionPrefs.OSC_STEAM_TOUCH) SessionPrefs.OSC_AUTO else a.oscMode val source = touchSource(oscValue) @@ -1340,15 +1388,15 @@ private fun DrawerPageTabs(page: SessionDrawerPage, pages: List Unit) { +private fun DrawerMoreBack(title: String, modifier: Modifier, parent: String = stringResource(R.string.drawer_page_more), onBack: () -> Unit) { val colors = MaterialTheme.colorScheme val pal = LocalPalette.current val source = remember { MutableInteractionSource() } val hot = source.collectIsFocusedAsState().value || source.collectIsHoveredAsState().value val shape = RoundedCornerShape(12.dp) - val label = stringResource(R.string.drawer_more_back, stringResource(R.string.drawer_page_more)) + val label = stringResource(R.string.drawer_more_back, parent) Row( verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp), modifier = modifier.padding(top = 8.dp, start = 14.dp, end = 14.dp).fillMaxWidth().heightIn(min = 44.dp).clip(shape) @@ -1362,12 +1410,105 @@ private fun DrawerMoreBack(title: String, modifier: Modifier, onBack: () -> Unit .padding(horizontal = 8.dp), ) { Icon(Icons.AutoMirrored.Outlined.ArrowBack, null, tint = colors.onSurfaceVariant, modifier = Modifier.size(22.dp)) - Text(stringResource(R.string.drawer_page_more), fontSize = 13.sp, color = colors.onSurfaceVariant) + Text(parent, fontSize = 13.sp, color = colors.onSurfaceVariant) Text("·", fontSize = 13.sp, color = colors.onSurfaceVariant) Text(title, fontSize = 15.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground, maxLines = 1) } } +@Composable +private fun AirTriggersPanel(host: MenuHost, t: AirTriggerMenu, a: DrawerActions, track: (String) -> Modifier) { + CompositionLocalProvider(LocalDrawerSections provides null) { SettingsGroup(stringResource(R.string.air_triggers_title)) { + ToggleRow(host, "air-triggers-toggle", stringResource(R.string.air_triggers_use), stringResource(R.string.air_triggers_use_hint), t.enabled, + chipModifier = track("air-triggers-toggle"), onChange = a.onAirTriggers) + ToggleRow(host, "air-triggers-vibration", stringResource(R.string.air_triggers_vibration), stringResource(R.string.air_triggers_vibration_hint), + t.vibration, enabled = t.enabled, chipModifier = track("air-triggers-vibration"), onChange = a.onAirTriggerVibration) + ToggleRow(host, "air-triggers-screen-light", stringResource(R.string.air_triggers_screen_light), stringResource(R.string.air_triggers_screen_light_hint), + t.screenLight, enabled = t.enabled, chipModifier = track("air-triggers-screen-light"), onChange = a.onAirTriggerScreenLight) + val leds = listOf(AirTriggerLed.OFF to R.string.air_triggers_led_off, AirTriggerLed.STEADY to R.string.air_triggers_led_steady, + AirTriggerLed.PULSE to R.string.air_triggers_led_pulse).map { (led, text) -> led to stringResource(text) } + ChoiceRow(host, "air-triggers-led", stringResource(R.string.air_triggers_led), null, leds, t.led, + enabled = t.enabled, chipModifier = track("air-triggers-led"), onPick = a.onAirTriggerLed) + for (trigger in AirTrigger.entries) { + val key = "air-trigger-${trigger.name.lowercase()}" + val left = trigger == AirTrigger.LEFT + val label = stringResource(if (left) R.string.air_trigger_left else R.string.air_trigger_right) + ChoiceRow(host, key, label, stringResource(R.string.air_trigger_button_hint), t.buttons, t.selected.getValue(trigger), + enabled = t.enabled, chipModifier = track(key)) { a.onAirTriggerButton(trigger, it) } + AirTriggerActionRow(host, "$key-action", stringResource(if (left) R.string.air_trigger_left_action else R.string.air_trigger_right_action), + t.actions[trigger] ?: AirTriggerAction.TAP, t.rates[trigger] ?: RapidFireRate.NORMAL, t.enabled, track("$key-action"), + onAction = { a.onAirTriggerAction(trigger, it) }, onRate = { a.onAirTriggerRate(trigger, it) }) + } + } } +} + +@Composable +private fun AirTriggerActionRow( + host: MenuHost, key: String, label: String, action: AirTriggerAction, rate: RapidFireRate, enabled: Boolean, chipModifier: Modifier, + onAction: (AirTriggerAction) -> Unit, onRate: (RapidFireRate) -> Unit, +) { + val open = host.open == key + var rateOpen by remember { mutableStateOf(false) } + LaunchedEffect(open) { if (!open) rateOpen = false } + val actions = listOf(AirTriggerAction.TAP to R.string.air_trigger_action_tap, AirTriggerAction.LATCH to R.string.air_trigger_action_hold, + AirTriggerAction.RAPID to R.string.air_trigger_action_rapid).map { (value, text) -> value to stringResource(text) } + val rates = listOf(R.string.air_trigger_rate_low, R.string.air_trigger_rate_normal, R.string.air_trigger_rate_high).map { stringResource(it) } + val rapidLabel = actions.last().second + val frequency = stringResource(R.string.air_trigger_rapid_frequency) + SettingsRow(label, null, highlighted = open) { Box { + ValueChip(actions.first { it.first == action }.second, open, enabled, modifier = chipModifier.testTag("setting-$key")) { + host.open = if (open) null else key + } + AnchoredMenu(open, onDismiss = { if (host.open == key) host.open = null }, title = if (rateOpen) null else label) { first -> + val arrowFocus = remember { FocusRequester() } + val keyboard = LocalInputModeManager.current.inputMode == InputMode.Keyboard + var shown by remember { mutableStateOf(rateOpen) } + LaunchedEffect(rateOpen) { + if (shown == rateOpen) return@LaunchedEffect + shown = rateOpen + withFrameNanos { } + if (keyboard) runCatching { (if (rateOpen) first else arrowFocus).requestFocus() } + } + if (rateOpen) { + Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth().padding(start = 10.dp)) { + Text(rapidLabel.uppercase(), fontSize = 12.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 1.5.sp, + color = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.weight(1f)) + MenuGlyphButton("✕", stringResource(R.string.common_close), Modifier.testTag("$key-rate-close")) { rateOpen = false } + } + ValueSlider(rate.ordinal, 0..RapidFireRate.entries.lastIndex, 1, true, frequency, { rates[it] }, + modifier = Modifier.focusRequester(first).testTag("$key-rate")) { if (it != rate.ordinal) onRate(RapidFireRate.entries[it]) } + } else actions.forEachIndexed { index, (value, text) -> + val pick = { onAction(value); host.open = null } + if (value != AirTriggerAction.RAPID) MenuItem(text, checked = value == action, focusRequester = if (index == 0) first else null, onClick = pick) + else Row(verticalAlignment = Alignment.CenterVertically) { + MenuItem(text, checked = value == action, modifier = Modifier.weight(1f), onClick = pick) + MenuGlyphButton("›", stringResource(R.string.air_trigger_rapid_settings), + Modifier.focusRequester(arrowFocus).testTag("$key-rate-open")) { rateOpen = true } + } + } + } + } } +} + +@Composable +private fun MenuGlyphButton(glyph: String, description: String, modifier: Modifier = Modifier, onClick: () -> Unit) { + val pal = LocalPalette.current + val src = remember { MutableInteractionSource() } + val hot = src.collectIsFocusedAsState().value || src.collectIsHoveredAsState().value + val shape = RoundedCornerShape(8.dp) + Box( + contentAlignment = Alignment.Center, + modifier = modifier.size(40.dp).clip(shape) + .background(if (hot) Color.White.copy(alpha = 0.07f) else Color.Transparent) + .glideBorder(hot, shape, pal.signal) + .hoverable(src).clickable(interactionSource = src, indication = LocalIndication.current, role = Role.Button, onClick = onClick) + .controllerConfirm(onClick = onClick) + .semantics { contentDescription = description }, + ) { + Text(glyph, fontSize = 18.sp, fontWeight = FontWeight.SemiBold, color = MaterialTheme.colorScheme.onBackground) + } +} + /** The pages kept inside More, and the way into arranging which pages sit on the strip and which here. */ @Composable private fun DrawerMorePage(host: MenuHost, pages: List, a: DrawerActions, onOpen: (SessionDrawerPage) -> Unit, onEdit: () -> Unit, track: (String) -> Modifier) { diff --git a/app/src/main/java/com/droiddeck/launcher/ui/SettingsWidgets.kt b/app/src/main/java/com/droiddeck/launcher/ui/SettingsWidgets.kt index 52ba78a7d6..53a617b31b 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/SettingsWidgets.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/SettingsWidgets.kt @@ -456,12 +456,13 @@ fun MenuItem( .padding(horizontal = 10.dp, vertical = 9.dp), ) { Text("✓", fontSize = 12.sp, color = pal.signal, modifier = Modifier.width(18.dp).alpha(if (checked) 1f else 0f).clearAndSetSemantics {}) + val ink = if (checked) pal.signal else colors.onBackground if (leading != null) { - leading() + androidx.compose.runtime.CompositionLocalProvider(androidx.compose.material3.LocalContentColor provides ink) { leading() } Spacer(Modifier.width(8.dp)) } Column(modifier = Modifier.weight(1f)) { - Text(label, fontSize = 13.5.sp, color = if (checked) pal.signal else colors.onBackground, maxLines = 2, overflow = TextOverflow.Ellipsis) + Text(label, fontSize = 13.5.sp, color = ink, maxLines = 2, overflow = TextOverflow.Ellipsis) if (detail != null) Text(detail, fontSize = 12.sp, color = colors.onSurfaceVariant, maxLines = 2, overflow = TextOverflow.Ellipsis) } if (trailing != null) { Spacer(Modifier.width(8.dp)); trailing() } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/TabMenu.kt b/app/src/main/java/com/droiddeck/launcher/ui/TabMenu.kt index c5c31a203c..1a05328069 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/TabMenu.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/TabMenu.kt @@ -88,7 +88,9 @@ internal fun TabMenu( .controllerConfirm(onClick = toggle) .padding(start = 14.dp, end = 10.dp), ) { - if (selected in labels.indices) leading?.invoke(selected, false) + if (selected in labels.indices) androidx.compose.runtime.CompositionLocalProvider(androidx.compose.material3.LocalContentColor provides colors.onBackground) { + leading?.invoke(selected, false) + } Text(label, fontSize = 14.sp, fontWeight = FontWeight.Bold, color = colors.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f, fill = false)) Icon(if (open) Icons.Outlined.ExpandLess else Icons.Outlined.ExpandMore, contentDescription = null, diff --git a/app/src/main/java/com/droiddeck/launcher/wayland/CompositorHost.kt b/app/src/main/java/com/droiddeck/launcher/wayland/CompositorHost.kt index d9d2eb111f..d193c2b025 100644 --- a/app/src/main/java/com/droiddeck/launcher/wayland/CompositorHost.kt +++ b/app/src/main/java/com/droiddeck/launcher/wayland/CompositorHost.kt @@ -67,13 +67,14 @@ object CompositorHost { outputHeight: Int, refreshHz: Float, fpsLimit: Int, + layerFpsLimit: Int = fpsLimit, ): Boolean { WaylandCompositor.nativeSetClockControl(java.io.File(context.filesDir, "${com.droiddeck.launcher.runtime.LinuxRuntime.DIR}/tmp/.dd-clock").path) ownVsyncThread = SessionPrefs.vsyncThread(context) WaylandCompositor.nativeSetRenderOnCommit(SessionPrefs.renderOnCommit(context)) blackFrameInsertion = SessionPrefs.blackFrameInsertion(context) WaylandCompositor.nativeSetBlackFrameInsertion(blackFrameInsertion) - pace(refreshHz, fpsLimit) + pace(refreshHz, fpsLimit, layerFpsLimit) if (!SessionState.running) WaylandCompositor.nativeSetOutputSize(outputWidth, outputHeight) if (started) { attached = surface @@ -95,23 +96,23 @@ object CompositorHost { private var blackFrameInsertion = false private var pictureHolds = 0 - private fun pace(refreshHz: Float, fpsLimit: Int) { + private fun pace(refreshHz: Float, fpsLimit: Int, layerFpsLimit: Int) { WaylandCompositor.nativeSetFpsLimit(fpsLimit) - WaylandCompositor.nativeSetLayerFrameRate(if (fpsLimit > 0 && !blackFrameInsertion) fpsLimit.toFloat() else refreshHz) + WaylandCompositor.nativeSetLayerFrameRate(SessionPrefs.layerFrameRate(layerFpsLimit, refreshHz, blackFrameInsertion)) WaylandCompositor.nativeSetOutputRefreshRate(refreshHz) SessionState.refreshHz = refreshHz } @Synchronized - fun updatePacing(refreshHz: Float, fpsLimit: Int) { - if (started) pace(refreshHz, fpsLimit) + fun updatePacing(refreshHz: Float, fpsLimit: Int, layerFpsLimit: Int = fpsLimit) { + if (started) pace(refreshHz, fpsLimit, layerFpsLimit) } @Synchronized - fun setBlackFrameInsertion(on: Boolean, refreshHz: Float, fpsLimit: Int) { + fun setBlackFrameInsertion(on: Boolean, refreshHz: Float, fpsLimit: Int, layerFpsLimit: Int = fpsLimit) { blackFrameInsertion = on WaylandCompositor.nativeSetBlackFrameInsertion(on) - if (started) pace(refreshHz, fpsLimit) + if (started) pace(refreshHz, fpsLimit, layerFpsLimit) } /** Presents only pictures until the matching release; false when nothing is strobing. */ diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml index 194f286552..2cfdc6ebef 100644 --- a/app/src/main/res/values-ar/strings.xml +++ b/app/src/main/res/values-ar/strings.xml @@ -1336,6 +1336,31 @@ حجم الأزرار عصي تكيّفية اهتزاز اللعبة + Redmagic Air Triggers + فتح + استخدام Air Triggers + يشغّل أزرار الكتف دون لوحة الأزرار أو العلامات من RedMagic، وتضغط بدلاً من ذلك أزرار تخطيط اللمس. + Air Trigger الأيسر + Air Trigger الأيمن + محفوظ لهذا التخطيط + الاهتزاز + يهتز عند لمس Air Trigger + تأثير الإضاءة على الشاشة + يضيء حافة الشاشة أسفل Air Trigger عند لمسه + تأثيرات إضاءة LED عند اللمس + إيقاف + ثابت + نبض + إجراء Air Trigger الأيسر + إجراء Air Trigger الأيمن + نقرة واحدة + ضغط مطوّل + إطلاق سريع + إعدادات الإطلاق السريع + معدل النقر + منخفض + عادي + مرتفع المنطقة الميتة لعصا التحكم زر Steam زر QAM @@ -2420,7 +2445,8 @@ جارٍ تنزيل عميل Steam · %1$s يوجد تثبيت لأداة توافق قيد التنفيذ بالفعل أوقِف الجلسة النشطة قبل تثبيت أدوات التوافق - تعذّر العثور على إصدار ARM64 لـ %1$s + تعذّر العثور على إصدار %2$s لـ %1$s + مكافحة الغش يلزم توفُّر 4 GB على الأقل بالإضافة إلى حجم التنزيل لتثبيت %1$s جارٍ تنزيل %1$s %2$s جارٍ إعادة محاولة التنزيل · المحاولة %1$d من %2$d @@ -4329,4 +4355,6 @@ اختصار داخل اللعبة إظهار اختصار النظارات الذكية إظهار زر النظارات الذكية العائم فوق اللعبة. + استخدام ملف تعريف %1$s: %2$s + استخدام الملف التعريفي الافتراضي: %1$s diff --git a/app/src/main/res/values-b+es+419/strings.xml b/app/src/main/res/values-b+es+419/strings.xml index cb6929d345..89152e4080 100644 --- a/app/src/main/res/values-b+es+419/strings.xml +++ b/app/src/main/res/values-b+es+419/strings.xml @@ -1342,6 +1342,31 @@ Tamaño de botones Sticks adaptables Vibración en juegos + Redmagic Air Triggers + Abrir + Usar los Air Triggers + Activa los gatillos de hombro sin el panel ni los marcadores de RedMagic. En su lugar, presionan botones de la disposición táctil. + Air Trigger izquierdo + Air Trigger derecho + Se guarda para esta disposición + Vibración + Vibra al tocar un Air Trigger + Efecto de luz en pantalla + Ilumina el borde de la pantalla debajo de un Air Trigger al tocarlo + Efectos LED de ambiente al tocar + Apagado + Fijo + Pulso + Acción del Air Trigger izquierdo + Acción del Air Trigger derecho + Toque único + Mantener presionado + Disparo rápido + Configuración de disparo rápido + Frecuencia de clics + Baja + Normal + Alta Zona muerta de la palanca Botón Steam Botón QAM @@ -2412,7 +2437,8 @@ Descargando el cliente de Steam · %1$s Ya se está instalando una herramienta de compatibilidad Detén la sesión activa antes de instalar herramientas de compatibilidad - No se encontró una versión ARM64 de %1$s + No se encontró una versión %2$s de %1$s + Antitrampas Para instalar %1$s se necesitan al menos 4 GB libres más el tamaño de la descarga Descargando %1$s %2$s Reintentando la descarga · intento %1$d de %2$d @@ -4207,4 +4233,6 @@ Acceso directo en el juego Mostrar acceso directo de Smart Glasses Mostrar el botón flotante de Smart Glasses sobre el juego. + Usando el perfil %1$s: %2$s + Usando el perfil predeterminado: %1$s diff --git a/app/src/main/res/values-bg/strings.xml b/app/src/main/res/values-bg/strings.xml index 1b5432d315..dcfa33ab4c 100644 --- a/app/src/main/res/values-bg/strings.xml +++ b/app/src/main/res/values-bg/strings.xml @@ -1308,6 +1308,31 @@ Размер на бутоните Адаптивни стикове Вибрация от играта + Redmagic Air Triggers + Отвори + Използвай Air Triggers + Включва раменните спусъци без панела и маркерите на RedMagic. Вместо това те натискат бутони от сензорното разположение. + Ляв Air Trigger + Десен Air Trigger + Запазва се за това разположение + Вибрация + Вибрира при докосване на Air Trigger + Светлинен ефект на екрана + Осветява ръба на екрана под Air Trigger при докосване + LED ефекти на атмосферата при докосване + Изключено + Постоянно + Пулсиране + Действие на левия Air Trigger + Действие на десния Air Trigger + Еднократно докосване + Продължително натискане + Бърза стрелба + Настройки за бърза стрелба + Честота на щракване + Ниска + Нормална + Висока Мъртва зона на стика Бутон Steam Бутон QAM @@ -2316,7 +2341,8 @@ Изтегляне на клиента на Steam · %1$s Вече тече инсталация на инструмент за съвместимост Спри активната сесия, преди да инсталираш инструменти за съвместимост - Не беше намерена ARM64 версия на %1$s + Не беше намерена %2$s версия на %1$s + Анти-чийт За инсталирането на %1$s са необходими поне 4 GB свободно място плюс размера на изтеглянето Изтегляне на %1$s %2$s Повторен опит за изтегляне · опит %1$d от %2$d @@ -4169,4 +4195,6 @@ Пряк път в играта Показване на прекия път за Smart Glasses Показва плаващия бутон за Smart Glasses върху играта. + Използва се профил %1$s: %2$s + Използва се профилът по подразбиране: %1$s diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index 502b628f3c..acb07bd432 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -1322,6 +1322,31 @@ Velikost tlačítek Adaptivní páčky Vibrace ve hře + Redmagic Air Triggers + Otevřít + Používat Air Triggers + Zapne ramenní triggery bez panelu a značek RedMagic. Místo toho mačkají tlačítka dotykového rozložení. + Levý Air Trigger + Pravý Air Trigger + Uloženo pro toto rozložení + Vibrace + Při dotyku Air Triggeru zavibruje + Světelný efekt na obrazovce + Při dotyku rozsvítí okraj obrazovky pod Air Triggerem + LED efekty atmosféry při dotyku + Vypnuto + Stálé + Pulzování + Akce levého Air Triggeru + Akce pravého Air Triggeru + Jedno klepnutí + Dlouhé stisknutí + Rychlá palba + Nastavení rychlé palby + Frekvence kliknutí + Nízká + Normální + Vysoká Mrtvá zóna páčky Tlačítko Steam Tlačítko QAM @@ -2368,7 +2393,8 @@ Stahování klienta Steam · %1$s Instalace nástroje kompatibility už běží Před instalací nástrojů kompatibility zastavte aktivní relaci - Nepodařilo se najít vydání ARM64 pro %1$s + Nepodařilo se najít vydání %2$s pro %1$s + Anti-cheat Pro instalaci %1$s je potřeba alespoň 4 GB volného místa navíc k velikosti stahování Stahování %1$s %2$s Opakování stahování · pokus %1$d z %2$d @@ -4249,4 +4275,6 @@ Zkratka ve hře Zobrazit zkratku Smart Glasses Zobrazit plovoucí tlačítko Smart Glasses nad hrou. + Používá se profil %1$s: %2$s + Používá se výchozí profil: %1$s diff --git a/app/src/main/res/values-da/strings.xml b/app/src/main/res/values-da/strings.xml index 2ebba4ebd9..d8a910077c 100644 --- a/app/src/main/res/values-da/strings.xml +++ b/app/src/main/res/values-da/strings.xml @@ -1308,6 +1308,31 @@ Knapstørrelse Adaptive styrepinde Spilvibration + Redmagic Air Triggers + Åbn + Brug Air Triggers + Tænder skuldertriggerne uden RedMagics triggerpanel eller markører. De trykker i stedet på knapper i touch-layoutet. + Venstre Air Trigger + Højre Air Trigger + Gemt for dette layout + Vibration + Vibrerer, når en Air Trigger berøres + Lyseffekt på skærmen + Lyser skærmkanten op under en Air Trigger, når den berøres + LED-stemningseffekter ved berøring + Fra + Konstant + Puls + Handling for venstre Air Trigger + Handling for højre Air Trigger + Enkelt tryk + Langt tryk + Hurtig affyring + Indstillinger for hurtig affyring + Klikfrekvens + Lav + Normal + Høj Dødzone for styrepind Steam-knap QAM-knap @@ -2316,7 +2341,8 @@ Downloader Steam-klienten · %1$s En installation af et kompatibilitetsværktøj er allerede i gang Stop den aktive session, før du installerer kompatibilitetsværktøjer - Kunne ikke finde en ARM64-udgivelse af %1$s + Kunne ikke finde en %2$s-udgivelse af %1$s + Anti-cheat Mindst 4 GB ledig plads plus downloadets størrelse er nødvendig for at installere %1$s Downloader %1$s %2$s Forsøger download igen · forsøg %1$d af %2$d @@ -4169,4 +4195,6 @@ Genvej i spillet Vis Smart Glasses-genvej Vis den flydende Smart Glasses-knap oven på spillet. + Bruger profilen %1$s: %2$s + Bruger standardprofilen: %1$s diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 6a88fa913e..b00c57281c 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -1300,6 +1300,31 @@ Tastengröße Adaptive Sticks Spielvibration + Redmagic Air Triggers + Öffnen + Air Triggers verwenden + Schaltet die Schultertrigger ohne das Trigger-Panel und die Markierungen von RedMagic ein. Sie drücken stattdessen Tasten des Touch-Layouts. + Linker Air Trigger + Rechter Air Trigger + Für dieses Layout gespeichert + Vibration + Vibriert, wenn ein Air Trigger berührt wird + Lichteffekt auf dem Bildschirm + Lässt den Bildschirmrand unter einem Air Trigger aufleuchten, wenn er berührt wird + LED-Atmosphäreneffekte bei Berührung + Aus + Dauerhaft + Pulsieren + Aktion des linken Air Triggers + Aktion des rechten Air Triggers + Einmal tippen + Lange drücken + Dauerfeuer + Dauerfeuer-Einstellungen + Klickfrequenz + Niedrig + Normal + Hoch Stick-Totzone Steam-Taste QAM-Taste @@ -2308,7 +2333,8 @@ Steam-Client wird heruntergeladen · %1$s Es läuft bereits die Installation eines Kompatibilitätstools Beende die aktive Sitzung, bevor du Kompatibilitätstools installierst - Kein ARM64-Release für %1$s gefunden + Kein %2$s-Release für %1$s gefunden + Anti-Cheat Zum Installieren von %1$s werden mindestens 4 GB freier Speicherplatz plus die Downloadgröße benötigt %1$s %2$s wird heruntergeladen Download wird wiederholt · Versuch %1$d von %2$d @@ -4169,4 +4195,6 @@ Ingame-Verknüpfung Smart-Glasses-Verknüpfung anzeigen Die schwebende Smart-Glasses-Schaltfläche über dem Spiel anzeigen. + Profil %1$s wird verwendet: %2$s + Standardprofil wird verwendet: %1$s diff --git a/app/src/main/res/values-el/strings.xml b/app/src/main/res/values-el/strings.xml index 3b132d95b8..335f821866 100644 --- a/app/src/main/res/values-el/strings.xml +++ b/app/src/main/res/values-el/strings.xml @@ -1308,6 +1308,31 @@ Μέγεθος κουμπιών Προσαρμοστικοί μοχλοί Κραδασμός παιχνιδιού + Redmagic Air Triggers + Άνοιγμα + Χρήση Air Triggers + Ενεργοποιεί τις σκανδάλες ώμου χωρίς τον πίνακα ή τους δείκτες του RedMagic. Αντί γι\' αυτό πατούν κουμπιά της διάταξης αφής. + Αριστερό Air Trigger + Δεξί Air Trigger + Αποθηκεύεται για αυτή τη διάταξη + Δόνηση + Δονείται όταν αγγίζετε ένα Air Trigger + Εφέ φωτισμού οθόνης + Φωτίζει την άκρη της οθόνης κάτω από ένα Air Trigger όταν το αγγίζετε + Εφέ ατμόσφαιρας LED με την αφή + Ανενεργό + Σταθερό + Παλμός + Ενέργεια αριστερού Air Trigger + Ενέργεια δεξιού Air Trigger + Μονό πάτημα + Παρατεταμένο πάτημα + Ταχεία βολή + Ρυθμίσεις ταχείας βολής + Συχνότητα κλικ + Χαμηλή + Κανονική + Υψηλή Νεκρή ζώνη μοχλού Κουμπί Steam Κουμπί QAM @@ -2316,7 +2341,8 @@ Λήψη του πελάτη Steam · %1$s Μια εγκατάσταση εργαλείου συμβατότητας εκτελείται ήδη Διακόψτε την ενεργή συνεδρία πριν εγκαταστήσετε εργαλεία συμβατότητας - Δεν βρέθηκε κυκλοφορία ARM64 για το %1$s + Δεν βρέθηκε κυκλοφορία %2$s για το %1$s + Anti-cheat Απαιτούνται τουλάχιστον 4 GB ελεύθερα συν το μέγεθος της λήψης για να εγκατασταθεί το %1$s Λήψη %1$s %2$s Επανάληψη λήψης · προσπάθεια %1$d από %2$d @@ -4169,4 +4195,6 @@ Συντόμευση μέσα στο παιχνίδι Εμφάνιση συντόμευσης Smart Glasses Εμφάνιση του αιωρούμενου κουμπιού Smart Glasses πάνω από το παιχνίδι. + Χρήση προφίλ %1$s: %2$s + Χρήση προεπιλεγμένου προφίλ: %1$s diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 3c77647f0e..23a39655a0 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -1315,6 +1315,31 @@ Tamaño de botones Sticks adaptables Vibración en juegos + Redmagic Air Triggers + Abrir + Usar los Air Triggers + Activa los gatillos de hombro sin el panel ni los marcadores de RedMagic. En su lugar, pulsan botones de la disposición táctil. + Air Trigger izquierdo + Air Trigger derecho + Se guarda para esta disposición + Vibración + Vibra al tocar un Air Trigger + Efecto de luz en pantalla + Ilumina el borde de la pantalla debajo de un Air Trigger al tocarlo + Efectos LED de ambiente al tocar + Apagado + Fijo + Pulso + Acción del Air Trigger izquierdo + Acción del Air Trigger derecho + Toque único + Mantener pulsado + Disparo rápido + Ajustes de disparo rápido + Frecuencia de clics + Baja + Normal + Alta Zona muerta de la palanca Botón Steam Botón QAM @@ -2342,7 +2367,8 @@ Descargando el cliente de Steam · %1$s Ya se está instalando una herramienta de compatibilidad Detén la sesión activa antes de instalar herramientas de compatibilidad - No se encontró una versión ARM64 de %1$s + No se encontró una versión %2$s de %1$s + Antitrampas Para instalar %1$s se necesitan al menos 4 GB libres más el tamaño de la descarga Descargando %1$s %2$s Reintentando la descarga · intento %1$d de %2$d @@ -4209,4 +4235,6 @@ Acceso directo en el juego Mostrar acceso directo de Smart Glasses Mostrar el botón flotante de Smart Glasses sobre el juego. + Usando el perfil %1$s: %2$s + Usando el perfil predeterminado: %1$s diff --git a/app/src/main/res/values-fi/strings.xml b/app/src/main/res/values-fi/strings.xml index 9d9141dfe4..0c92d3dd14 100644 --- a/app/src/main/res/values-fi/strings.xml +++ b/app/src/main/res/values-fi/strings.xml @@ -1308,6 +1308,31 @@ Painikkeiden koko Mukautuvat sauvat Pelin tärinä + Redmagic Air Triggers + Avaa + Käytä Air Triggereitä + Ottaa olkaliipaisimet käyttöön ilman RedMagicin liipaisinpaneelia tai merkkejä. Ne painavat sen sijaan kosketusasettelun painikkeita. + Vasen Air Trigger + Oikea Air Trigger + Tallennetaan tälle asettelulle + Värinä + Värisee, kun Air Triggeriä kosketetaan + Näytön valoefekti + Valaisee näytön reunan Air Triggerin alla, kun sitä kosketetaan + Kosketuksen tunnelma-LED-efektit + Pois + Tasainen + Sykkivä + Vasemman Air Triggerin toiminto + Oikean Air Triggerin toiminto + Yksi napautus + Pitkä painallus + Sarjatuli + Sarjatulen asetukset + Napsautustiheys + Matala + Normaali + Korkea Ohjaussauvan kuollut alue Steam-painike QAM-painike @@ -2316,7 +2341,8 @@ Ladataan Steam-asiakasohjelmaa · %1$s Yhteensopivuustyökalun asennus on jo käynnissä Pysäytä käynnissä oleva istunto ennen yhteensopivuustyökalujen asentamista - ARM64-julkaisua kohteelle %1$s ei löytynyt + %2$s-julkaisua kohteelle %1$s ei löytynyt + Huijauksenesto Kohteen %1$s asentaminen vaatii vähintään 4 GB vapaata tilaa latauksen koon lisäksi Ladataan %1$s %2$s Yritetään latausta uudelleen · yritys %1$d/%2$d @@ -4169,4 +4195,6 @@ Pelin aikainen pikakuvake Näytä Smart Glasses -pikakuvake Näytä pelin päällä kelluva Smart Glasses -painike. + Käytössä profiili %1$s: %2$s + Käytössä oletusprofiili: %1$s diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 488fb23c77..33952230d3 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -1314,6 +1314,31 @@ Taille des boutons Joystick adaptatif Vibration du jeu + Redmagic Air Triggers + Ouvrir + Utiliser les Air Triggers + Active les gâchettes d\'épaule sans le panneau ni les repères de RedMagic. Elles appuient à la place sur des boutons de la disposition tactile. + Air Trigger gauche + Air Trigger droit + Enregistré pour cette disposition + Vibration + Vibre quand un Air Trigger est touché + Effet lumineux à l\'écran + Illumine le bord de l\'écran sous un Air Trigger quand il est touché + Effets LED d\'ambiance au toucher + Désactivé + Fixe + Pulsation + Action de l\'Air Trigger gauche + Action de l\'Air Trigger droit + Appui simple + Appui long + Tir rapide + Réglages du tir rapide + Fréquence des clics + Faible + Normale + Élevée Zone morte du stick Bouton Steam Bouton QAM @@ -2341,7 +2366,8 @@ Téléchargement du client Steam · %1$s Une installation d\'outil de compatibilité est déjà en cours Arrêtez la session en cours avant d\'installer des outils de compatibilité - Aucune version ARM64 trouvée pour %1$s + Aucune version %2$s trouvée pour %1$s + Anti-triche Au moins 4 Go libres, plus la taille du téléchargement, sont nécessaires pour installer %1$s Téléchargement de %1$s %2$s Nouvelle tentative de téléchargement · essai %1$d sur %2$d @@ -4208,4 +4234,6 @@ Raccourci en jeu Afficher le raccourci Smart Glasses Afficher le bouton flottant Smart Glasses par-dessus le jeu. + Profil %1$s utilisé : %2$s + Profil par défaut utilisé : %1$s diff --git a/app/src/main/res/values-hi/strings.xml b/app/src/main/res/values-hi/strings.xml index 2d13d432b2..857f6ed048 100644 --- a/app/src/main/res/values-hi/strings.xml +++ b/app/src/main/res/values-hi/strings.xml @@ -1308,6 +1308,31 @@ बटन का आकार एडैप्टिव स्टिक गेम वाइब्रेशन + Redmagic Air Triggers + खोलें + Air Triggers इस्तेमाल करें + RedMagic के ट्रिगर पैनल या मार्कर के बिना शोल्डर ट्रिगर चालू करता है। इसके बजाय वे टच लेआउट के बटन दबाते हैं। + लेफ़्ट Air Trigger + राइट Air Trigger + इस लेआउट के लिए सहेजा गया + वाइब्रेशन + Air Trigger छूने पर वाइब्रेट करता है + स्क्रीन लाइट इफ़ेक्ट + Air Trigger छूने पर उसके नीचे स्क्रीन का किनारा रोशन करता है + टच एटमॉस्फ़ियर LED इफ़ेक्ट + बंद + स्थिर + पल्स + लेफ़्ट Air Trigger का ऐक्शन + राइट Air Trigger का ऐक्शन + सिंगल टैप + लॉन्ग प्रेस + रैपिड फ़ायर + रैपिड फ़ायर सेटिंग + क्लिक फ़्रीक्वेंसी + कम + सामान्य + ज़्यादा स्टिक का डेड ज़ोन Steam बटन QAM बटन @@ -2316,7 +2341,8 @@ Steam क्लाइंट डाउनलोड हो रहा है · %1$s एक कम्पैटिबिलिटी टूल इंस्टॉल पहले से चल रहा है कम्पैटिबिलिटी टूल इंस्टॉल करने से पहले चल रहा सेशन बंद करें - %1$s के लिए कोई ARM64 रिलीज़ नहीं मिली + %1$s के लिए कोई %2$s रिलीज़ नहीं मिली + एंटी-चीट %1$s इंस्टॉल करने के लिए कम से कम 4 GB खाली जगह और डाउनलोड आकार चाहिए %1$s %2$s डाउनलोड हो रहा है डाउनलोड फिर से कोशिश हो रहा है · %2$d में से %1$d प्रयास @@ -4169,4 +4195,6 @@ गेम में शॉर्टकट Smart Glasses शॉर्टकट दिखाएँ गेम के ऊपर तैरता हुआ Smart Glasses बटन दिखाएँ। + %1$s प्रोफ़ाइल का उपयोग: %2$s + डिफ़ॉल्ट प्रोफ़ाइल का उपयोग: %1$s diff --git a/app/src/main/res/values-hu/strings.xml b/app/src/main/res/values-hu/strings.xml index f2c49ad811..2717d7cecc 100644 --- a/app/src/main/res/values-hu/strings.xml +++ b/app/src/main/res/values-hu/strings.xml @@ -1308,6 +1308,31 @@ Gombméret Adaptív karok Játékvibráció + Redmagic Air Triggers + Megnyitás + Air Triggers használata + Bekapcsolja a vállravaszokat a RedMagic ravaszpanelje és jelölői nélkül. Helyettük az érintéses elrendezés gombjait nyomják meg. + Bal Air Trigger + Jobb Air Trigger + Ehhez az elrendezéshez mentve + Rezgés + Rezeg, amikor megérint egy Air Triggert + Fényeffektus a képernyőn + Érintéskor megvilágítja a képernyő szélét az Air Trigger alatt + Érintési hangulat-LED-effektusok + Ki + Folyamatos + Pulzálás + Bal Air Trigger művelete + Jobb Air Trigger művelete + Egy koppintás + Hosszú nyomás + Gyorstüzelés + Gyorstüzelés beállításai + Kattintási gyakoriság + Alacsony + Normál + Magas Kar holtzónája Steam gomb QAM gomb @@ -2316,7 +2341,8 @@ A Steam-kliens letöltése · %1$s Már fut egy kompatibilitási eszköz telepítése Állítsa le az aktív munkamenetet a kompatibilitási eszközök telepítése előtt - Nem található ARM64-es kiadás a %1$s-hez + Nem található %2$s-es kiadás a %1$s-hez + Csalás elleni védelem Legalább 4 GB szabad hely, plusz a letöltés mérete szükséges a %1$s telepítéséhez %1$s %2$s letöltése A letöltés újrapróbálása · %1$d. próbálkozás a %2$d-ből @@ -4169,4 +4195,6 @@ Játékon belüli parancsikon Smart Glasses parancsikon megjelenítése A játék fölött lebegő Smart Glasses gomb megjelenítése. + Használt profil: %1$s – %2$s + Alapértelmezett profil használata: %1$s diff --git a/app/src/main/res/values-in/strings.xml b/app/src/main/res/values-in/strings.xml index 0c331b58ad..bba6153f6d 100644 --- a/app/src/main/res/values-in/strings.xml +++ b/app/src/main/res/values-in/strings.xml @@ -1302,6 +1302,31 @@ Ukuran tombol Stik adaptif Getaran gim + Redmagic Air Triggers + Buka + Gunakan Air Triggers + Menyalakan trigger bahu tanpa panel atau penanda trigger RedMagic. Sebagai gantinya, trigger menekan tombol tata letak sentuh. + Air Trigger kiri + Air Trigger kanan + Disimpan untuk tata letak ini + Getaran + Bergetar saat Air Trigger disentuh + Efek cahaya layar + Menerangi tepi layar di bawah Air Trigger saat disentuh + Efek LED suasana saat disentuh + Mati + Tetap + Denyut + Aksi Air Trigger kiri + Aksi Air Trigger kanan + Ketuk sekali + Tekan lama + Tembak cepat + Setelan tembak cepat + Frekuensi klik + Rendah + Normal + Tinggi Zona mati stik Tombol Steam Tombol QAM @@ -2291,7 +2316,8 @@ Mengunduh klien Steam · %1$s Instalasi alat kompatibilitas sedang berjalan Hentikan sesi aktif sebelum menginstal alat kompatibilitas - Tidak dapat menemukan rilis ARM64 untuk %1$s + Tidak dapat menemukan rilis %2$s untuk %1$s + Anti-cheat Setidaknya 4 GB ruang kosong ditambah ukuran unduhan diperlukan untuk menginstal %1$s Mengunduh %1$s %2$s Mencoba lagi unduhan · percobaan %1$d dari %2$d @@ -4139,4 +4165,6 @@ Pintasan dalam game Tampilkan pintasan Smart Glasses Tampilkan tombol Smart Glasses mengambang di atas game. + Menggunakan profil %1$s: %2$s + Menggunakan profil default: %1$s diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 7b5f250e9b..761a467af9 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -1306,6 +1306,31 @@ Dimensione dei tasti Levette adattive Vibrazione di gioco + Redmagic Air Triggers + Apri + Usa gli Air Triggers + Attiva i grilletti dorsali senza il pannello né gli indicatori di RedMagic. Premono invece i pulsanti del layout touch. + Air Trigger sinistro + Air Trigger destro + Salvato per questo layout + Vibrazione + Vibra quando tocchi un Air Trigger + Effetto luce sullo schermo + Illumina il bordo dello schermo sotto un Air Trigger quando lo tocchi + Effetti LED d\'atmosfera al tocco + Spento + Fisso + Pulsante + Azione dell\'Air Trigger sinistro + Azione dell\'Air Trigger destro + Tocco singolo + Pressione prolungata + Fuoco rapido + Impostazioni fuoco rapido + Frequenza dei clic + Bassa + Normale + Alta Zona morta dello stick Tasto Steam Tasto QAM @@ -2333,7 +2358,8 @@ Download del client Steam · %1$s È già in corso l\'installazione di uno strumento di compatibilità Interrompi la sessione attiva prima di installare strumenti di compatibilità - Impossibile trovare una release ARM64 per %1$s + Impossibile trovare una release %2$s per %1$s + Anti-cheat Per installare %1$s servono almeno 4 GB liberi più la dimensione del download Download di %1$s %2$s Nuovo tentativo di download · tentativo %1$d di %2$d @@ -4208,4 +4234,6 @@ Scorciatoia nel gioco Mostra scorciatoia Smart Glasses Mostra il pulsante mobile Smart Glasses sopra il gioco. + Profilo %1$s in uso: %2$s + Profilo predefinito in uso: %1$s diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index d321979308..09fad4f590 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -1302,6 +1302,31 @@ ボタンのサイズ アダプティブスティック ゲームの振動 + Redmagic エアトリガー + 開く + エアトリガーを使う + RedMagic のトリガーパネルやマーカーを出さずにショルダートリガーをオンにし、タッチレイアウトのボタンを押します。 + 左エアトリガー + 右エアトリガー + このレイアウトに保存されます + バイブレーション + エアトリガーに触れると振動します + 画面のライト効果 + エアトリガーに触れると、その下の画面の端が光ります + タッチ時のアンビエントLED効果 + オフ + 常時点灯 + パルス + 左エアトリガーの動作 + 右エアトリガーの動作 + シングルタップ + 長押し + 連射 + 連射の設定 + クリック頻度 + 低 + 標準 + 高 スティックのデッドゾーン Steamボタン QAMボタン @@ -2291,7 +2316,8 @@ Steamクライアントをダウンロード中 · %1$s 互換性ツールのインストールはすでに実行中です 互換性ツールをインストールする前に、実行中のセッションを停止してください - %1$sのARM64リリースが見つかりませんでした + %1$sの%2$sリリースが見つかりませんでした + アンチチート %1$sのインストールには、ダウンロードサイズに加えて4GB以上の空き容量が必要です %1$s %2$sをダウンロード中 ダウンロードを再試行中 · %1$d / %2$d回目 @@ -4139,4 +4165,6 @@ ゲーム内ショートカット Smart Glasses のショートカットを表示 ゲーム画面上に Smart Glasses のフローティングボタンを表示します。 + %1$s プロファイルを使用中: %2$s + デフォルトプロファイルを使用中: %1$s diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml index 0f1dfea3e9..66dfdcb34a 100644 --- a/app/src/main/res/values-ko/strings.xml +++ b/app/src/main/res/values-ko/strings.xml @@ -1302,6 +1302,31 @@ 버튼 크기 적응형 스틱 게임 진동 + Redmagic 에어 트리거 + 열기 + 에어 트리거 사용 + RedMagic 트리거 패널이나 표시 없이 숄더 트리거를 켜고, 대신 터치 레이아웃의 버튼을 누릅니다. + 왼쪽 에어 트리거 + 오른쪽 에어 트리거 + 이 레이아웃에 저장됨 + 진동 + 에어 트리거를 터치하면 진동합니다 + 화면 조명 효과 + 에어 트리거를 터치하면 그 아래 화면 가장자리가 밝아집니다 + 터치 분위기 LED 효과 + 끄기 + 상시 점등 + 펄스 + 왼쪽 에어 트리거 동작 + 오른쪽 에어 트리거 동작 + 한 번 탭 + 길게 누르기 + 연사 + 연사 설정 + 클릭 빈도 + 낮음 + 보통 + 높음 스틱 데드존 Steam 버튼 QAM 버튼 @@ -2291,7 +2316,8 @@ Steam 클라이언트 다운로드 중 · %1$s 호환성 도구를 이미 설치하고 있습니다 호환성 도구를 설치하기 전에 실행 중인 세션을 중지하세요 - %1$s의 ARM64 릴리스를 찾을 수 없습니다 + %1$s의 %2$s 릴리스를 찾을 수 없습니다 + 안티 치트 %1$s을(를) 설치하려면 다운로드 크기에 더해 최소 4GB의 여유 공간이 필요합니다 %1$s %2$s 다운로드 중 다운로드 재시도 중 · %2$d회 중 %1$d번째 @@ -4139,4 +4165,6 @@ 게임 내 바로가기 Smart Glasses 바로가기 표시 게임 위에 떠 있는 Smart Glasses 버튼을 표시합니다. + %1$s 프로필 사용 중: %2$s + 기본 프로필 사용 중: %1$s diff --git a/app/src/main/res/values-ms/strings.xml b/app/src/main/res/values-ms/strings.xml index 11dcd92779..bb8bc88dba 100644 --- a/app/src/main/res/values-ms/strings.xml +++ b/app/src/main/res/values-ms/strings.xml @@ -1302,6 +1302,31 @@ Saiz butang Stik adaptif Getaran permainan + Redmagic Air Triggers + Buka + Guna Air Triggers + Menghidupkan pencetus bahu tanpa panel atau penanda pencetus RedMagic. Sebaliknya, ia menekan butang susun atur sentuh. + Air Trigger kiri + Air Trigger kanan + Disimpan untuk susun atur ini + Getaran + Bergetar apabila Air Trigger disentuh + Kesan cahaya skrin + Menyalakan tepi skrin di bawah Air Trigger apabila ia disentuh + Kesan LED suasana sentuhan + Mati + Tetap + Denyut + Tindakan Air Trigger kiri + Tindakan Air Trigger kanan + Ketik sekali + Tekan lama + Tembakan pantas + Tetapan tembakan pantas + Kekerapan klik + Rendah + Biasa + Tinggi Zon mati kayu bedik Butang Steam Butang QAM @@ -2291,7 +2316,8 @@ Memuat turun klien Steam · %1$s Pemasangan alat keserasian sudah berjalan Hentikan sesi aktif sebelum memasang alat keserasian - Tidak dapat mencari keluaran ARM64 untuk %1$s + Tidak dapat mencari keluaran %2$s untuk %1$s + Anti-cheat Sekurang-kurangnya 4 GB bebas tambah saiz muat turun diperlukan untuk memasang %1$s Memuat turun %1$s %2$s Mencuba semula muat turun · percubaan %1$d daripada %2$d @@ -4139,4 +4165,6 @@ Pintasan dalam permainan Tunjukkan pintasan Smart Glasses Tunjukkan butang Smart Glasses terapung di atas permainan. + Menggunakan profil %1$s: %2$s + Menggunakan profil lalai: %1$s diff --git a/app/src/main/res/values-nb/strings.xml b/app/src/main/res/values-nb/strings.xml index c24cf07a2f..c8e2060cca 100644 --- a/app/src/main/res/values-nb/strings.xml +++ b/app/src/main/res/values-nb/strings.xml @@ -1308,6 +1308,31 @@ Knappestørrelse Adaptive stikker Spillvibrasjon + Redmagic Air Triggers + Åpne + Bruk Air Triggers + Slår på skuldertriggerne uten RedMagics triggerpanel eller markører. De trykker i stedet på knapper i berøringsoppsettet. + Venstre Air Trigger + Høyre Air Trigger + Lagret for dette oppsettet + Vibrering + Vibrerer når en Air Trigger berøres + Lyseffekt på skjermen + Lyser opp skjermkanten under en Air Trigger når den berøres + LED-stemningseffekter ved berøring + Av + Konstant + Puls + Handling for venstre Air Trigger + Handling for høyre Air Trigger + Enkelt trykk + Langt trykk + Hurtigskyting + Innstillinger for hurtigskyting + Klikkfrekvens + Lav + Normal + Høy Dødsone for styrespak Steam-knapp QAM-knapp @@ -2316,7 +2341,8 @@ Laster ned Steam-klienten · %1$s En installasjon av et kompatibilitetsverktøy kjører allerede Avslutt den aktive sesjonen før du installerer kompatibilitetsverktøy - Fant ingen ARM64-utgivelse for %1$s + Fant ingen %2$s-utgivelse for %1$s + Anti-juks Minst 4 GB ledig pluss nedlastingens størrelse er nødvendig for å installere %1$s Laster ned %1$s %2$s Prøver nedlastingen igjen · forsøk %1$d av %2$d @@ -4169,4 +4195,6 @@ Snarvei i spillet Vis Smart Glasses-snarvei Vis den flytende Smart Glasses-knappen over spillet. + Bruker profilen %1$s: %2$s + Bruker standardprofilen: %1$s diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index 9be1ed4dd3..7cdb2915c4 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -1308,6 +1308,31 @@ Knopgrootte Adaptieve sticks Trillen in games + Redmagic Air Triggers + Openen + Air Triggers gebruiken + Zet de schoudertriggers aan zonder het triggerpaneel of de markeringen van RedMagic. Ze drukken in plaats daarvan knoppen van de aanraakindeling in. + Linker Air Trigger + Rechter Air Trigger + Opgeslagen voor deze indeling + Trillen + Trilt wanneer je een Air Trigger aanraakt + Lichteffect op het scherm + Laat de schermrand onder een Air Trigger oplichten wanneer je die aanraakt + Sfeer-ledeffecten bij aanraken + Uit + Constant + Pulseren + Actie van linker Air Trigger + Actie van rechter Air Trigger + Eén keer tikken + Lang indrukken + Snelvuur + Instellingen voor snelvuur + Klikfrequentie + Laag + Normaal + Hoog Dode zone van stick Steam-knop QAM-knop @@ -2316,7 +2341,8 @@ Steam-client downloaden · %1$s Er wordt al een compatibiliteitstool geïnstalleerd Stop de actieve sessie voordat je compatibiliteitstools installeert - Kan geen ARM64-release vinden voor %1$s + Kan geen %2$s-release vinden voor %1$s + Anti-cheat Om %1$s te installeren is minstens 4 GB vrije ruimte nodig, plus de downloadgrootte %1$s %2$s downloaden Download opnieuw proberen · poging %1$d van %2$d @@ -4169,4 +4195,6 @@ Snelkoppeling in game Smart Glasses-snelkoppeling tonen Toon de zwevende Smart Glasses-knop boven het spel. + Profiel %1$s in gebruik: %2$s + Standaardprofiel in gebruik: %1$s diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index f9d480d75b..93a04f4e7e 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -1322,6 +1322,31 @@ Rozmiar przycisków Adaptacyjne gałki Wibracje gry + Redmagic Air Triggers + Otwórz + Używaj Air Triggers + Włącza spusty naramienne bez panelu i znaczników RedMagic. Zamiast tego naciskają przyciski układu dotykowego. + Lewy Air Trigger + Prawy Air Trigger + Zapisane dla tego układu + Wibracje + Wibruje po dotknięciu Air Triggera + Efekt świetlny na ekranie + Podświetla krawędź ekranu pod Air Triggerem po jego dotknięciu + Efekty LED nastroju przy dotyku + Wyłączone + Stałe + Pulsowanie + Działanie lewego Air Triggera + Działanie prawego Air Triggera + Pojedyncze dotknięcie + Długie naciśnięcie + Szybki ogień + Ustawienia szybkiego ognia + Częstotliwość kliknięć + Niska + Normalna + Wysoka Martwa strefa drążka Przycisk Steam Przycisk QAM @@ -2368,7 +2393,8 @@ Pobieranie klienta Steam · %1$s Instalacja narzędzia zgodności już trwa Zatrzymaj aktywną sesję przed instalacją narzędzi zgodności - Nie znaleziono wydania ARM64 dla %1$s + Nie znaleziono wydania %2$s dla %1$s + Antycheat Do instalacji %1$s potrzeba co najmniej 4 GB wolnego miejsca plus rozmiar pobierania Pobieranie %1$s %2$s Ponawianie pobierania · próba %1$d z %2$d @@ -4249,4 +4275,6 @@ Skrót w grze Pokaż skrót Smart Glasses Pokaż pływający przycisk Smart Glasses nad grą. + Używany profil %1$s: %2$s + Używany profil domyślny: %1$s diff --git a/app/src/main/res/values-pt-rPT/strings.xml b/app/src/main/res/values-pt-rPT/strings.xml index bc4cd0deab..eb9740fe73 100644 --- a/app/src/main/res/values-pt-rPT/strings.xml +++ b/app/src/main/res/values-pt-rPT/strings.xml @@ -1306,6 +1306,31 @@ Tamanho dos botões Analógicos adaptáveis Vibração do jogo + Redmagic Air Triggers + Abrir + Utilizar os Air Triggers + Liga os gatilhos de ombro sem o painel nem os marcadores da RedMagic. Em vez disso, premem botões do esquema tátil. + Air Trigger esquerdo + Air Trigger direito + Guardado para este esquema + Vibração + Vibra quando toca num Air Trigger + Efeito de luz no ecrã + Ilumina a margem do ecrã por baixo de um Air Trigger quando é tocado + Efeitos LED de ambiente ao toque + Desligado + Fixo + Pulsar + Ação do Air Trigger esquerdo + Ação do Air Trigger direito + Toque único + Premir prolongadamente + Disparo rápido + Definições de disparo rápido + Frequência de cliques + Baixa + Normal + Alta Zona morta do manípulo Botão Steam Botão QAM @@ -2348,7 +2373,8 @@ A transferir o cliente Steam · %1$s Já está em curso a instalação de uma ferramenta de compatibilidade Pare a sessão ativa antes de instalar ferramentas de compatibilidade - Não foi possível encontrar uma versão ARM64 de %1$s + Não foi possível encontrar uma versão %2$s de %1$s + Anti-cheat São necessários pelo menos 4 GB livres, mais o tamanho da transferência, para instalar %1$s A transferir %1$s %2$s A repetir a transferência · tentativa %1$d de %2$d @@ -4208,4 +4234,6 @@ Atalho no jogo Mostrar atalho do Smart Glasses Mostrar o botão flutuante do Smart Glasses sobre o jogo. + Perfil %1$s em utilização: %2$s + Perfil predefinido em utilização: %1$s diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index ad2936097b..0f1ed13964 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -1314,6 +1314,31 @@ Tamanho dos botões Analógicos adaptáveis Vibração do jogo + Redmagic Air Triggers + Abrir + Usar os Air Triggers + Liga os gatilhos de ombro sem o painel nem os marcadores da RedMagic. Em vez disso, eles apertam botões do layout de toque. + Air Trigger esquerdo + Air Trigger direito + Salvo para este layout + Vibração + Vibra quando um Air Trigger é tocado + Efeito de luz na tela + Ilumina a borda da tela embaixo de um Air Trigger quando ele é tocado + Efeitos de LED de ambiente ao toque + Desligado + Fixo + Pulsar + Ação do Air Trigger esquerdo + Ação do Air Trigger direito + Toque único + Toque longo + Disparo rápido + Configurações de disparo rápido + Frequência de cliques + Baixa + Normal + Alta Zona morta do analógico Botão Steam Botão QAM @@ -2356,7 +2381,8 @@ Baixando o cliente Steam · %1$s Já há uma instalação de ferramenta de compatibilidade em andamento Pare a sessão ativa antes de instalar ferramentas de compatibilidade - Não foi possível encontrar uma versão ARM64 de %1$s + Não foi possível encontrar uma versão %2$s de %1$s + Anti-cheat É preciso ter pelo menos 4 GB livres, além do tamanho do download, para instalar %1$s Baixando %1$s %2$s Tentando baixar de novo · tentativa %1$d de %2$d @@ -4216,4 +4242,6 @@ Atalho durante o jogo Mostrar atalho do Smart Glasses Mostrar o botão flutuante do Smart Glasses sobre o jogo. + Perfil %1$s em uso: %2$s + Perfil predefinido em uso: %1$s diff --git a/app/src/main/res/values-ro/strings.xml b/app/src/main/res/values-ro/strings.xml index bcfea395b0..dda5fbd7a4 100644 --- a/app/src/main/res/values-ro/strings.xml +++ b/app/src/main/res/values-ro/strings.xml @@ -1315,6 +1315,31 @@ Dimensiunea butoanelor Manșe adaptive Vibrații de joc + Redmagic Air Triggers + Deschide + Folosește Air Triggers + Pornește triggerele de umăr fără panoul sau marcajele RedMagic. În schimb, ele apasă butoane din aranjamentul tactil. + Air Trigger stâng + Air Trigger drept + Salvat pentru acest aranjament + Vibrație + Vibrează când atingi un Air Trigger + Efect de lumină pe ecran + Luminează marginea ecranului de sub un Air Trigger când îl atingi + Efecte LED de atmosferă la atingere + Oprit + Constant + Puls + Acțiunea Air Trigger-ului stâng + Acțiunea Air Trigger-ului drept + Atingere simplă + Apăsare lungă + Foc rapid + Setări foc rapid + Frecvența clicurilor + Scăzută + Normală + Ridicată Zonă moartă a manetei Butonul Steam Butonul QAM @@ -2342,7 +2367,8 @@ Se descarcă clientul Steam · %1$s O instalare a unui instrument de compatibilitate este deja în curs Oprește sesiunea activă înainte de a instala instrumente de compatibilitate - Nu s-a găsit o versiune ARM64 pentru %1$s + Nu s-a găsit o versiune %2$s pentru %1$s + Anti-cheat Este necesar cel puțin 4 GB liber, plus dimensiunea descărcării, pentru a instala %1$s Se descarcă %1$s %2$s Se reîncearcă descărcarea · tentativa %1$d din %2$d @@ -4209,4 +4235,6 @@ Comandă rapidă în joc Afișează comanda rapidă Smart Glasses Afișează butonul plutitor Smart Glasses peste joc. + Se folosește profilul %1$s: %2$s + Se folosește profilul implicit: %1$s diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 4c248f3b94..69debd8ba3 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -1322,6 +1322,31 @@ Размер кнопок Адаптивные стики Вибрация в играх + Redmagic Air Triggers + Открыть + Использовать Air Triggers + Включает плечевые триггеры без панели и меток RedMagic. Вместо этого они нажимают кнопки сенсорной раскладки. + Левый Air Trigger + Правый Air Trigger + Сохраняется для этой раскладки + Вибрация + Вибрирует при касании Air Trigger + Световой эффект на экране + Подсвечивает край экрана под Air Trigger при касании + LED-эффекты атмосферы при касании + Выкл. + Постоянный + Пульсация + Действие левого Air Trigger + Действие правого Air Trigger + Одно нажатие + Долгое нажатие + Быстрая стрельба + Настройки быстрой стрельбы + Частота нажатий + Низкая + Обычная + Высокая Мёртвая зона стика Кнопка Steam Кнопка QAM @@ -2369,7 +2394,8 @@ Загрузка клиента Steam · %1$s Инструмент совместимости уже устанавливается Остановите текущую сессию перед установкой инструментов совместимости - Не найден выпуск %1$s для ARM64 + Не найден выпуск %1$s для %2$s + Античит Для установки %1$s нужно не менее 4 ГБ свободного места плюс размер загрузки Загрузка %1$s %2$s Повторная загрузка · попытка %1$d из %2$d @@ -4250,4 +4276,6 @@ Ярлык в игре Показывать ярлык Smart Glasses Показывать плавающую кнопку Smart Glasses поверх игры. + Используется профиль %1$s: %2$s + Используется профиль по умолчанию: %1$s diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index ec6a0ab304..23c54d1caf 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -1308,6 +1308,31 @@ Knappstorlek Adaptiva spakar Spelvibration + Redmagic Air Triggers + Öppna + Använd Air Triggers + Slår på axelavtryckarna utan RedMagics avtryckarpanel eller markeringar. De trycker i stället på knappar i pekskärmslayouten. + Vänster Air Trigger + Höger Air Trigger + Sparas för den här layouten + Vibration + Vibrerar när en Air Trigger vidrörs + Ljuseffekt på skärmen + Lyser upp skärmkanten under en Air Trigger när den vidrörs + LED-stämningseffekter vid beröring + Av + Fast + Puls + Åtgärd för vänster Air Trigger + Åtgärd för höger Air Trigger + Enkeltryck + Långt tryck + Snabbeld + Inställningar för snabbeld + Klickfrekvens + Låg + Normal + Hög Styrspakens dödzon Steam-knappen QAM-knappen @@ -2316,7 +2341,8 @@ Laddar ned Steam-klienten · %1$s En installation av ett kompatibilitetsverktyg pågår redan Stoppa den aktiva sessionen innan du installerar kompatibilitetsverktyg - Kunde inte hitta en ARM64-utgåva av %1$s + Kunde inte hitta en %2$s-utgåva av %1$s + Anti-cheat Minst 4 GB ledigt utrymme plus nedladdningens storlek krävs för att installera %1$s Laddar ned %1$s %2$s Försöker ladda ned igen · försök %1$d av %2$d @@ -4169,4 +4195,6 @@ Genväg i spelet Visa Smart Glasses-genväg Visa den flytande Smart Glasses-knappen ovanpå spelet. + Använder profilen %1$s: %2$s + Använder standardprofilen: %1$s diff --git a/app/src/main/res/values-th/strings.xml b/app/src/main/res/values-th/strings.xml index 1527735d34..d96c1b03d0 100644 --- a/app/src/main/res/values-th/strings.xml +++ b/app/src/main/res/values-th/strings.xml @@ -1302,6 +1302,31 @@ ขนาดปุ่ม สติ๊กแบบปรับอัตโนมัติ การสั่นของเกม + Redmagic Air Triggers + เปิด + ใช้ Air Triggers + เปิดทริกเกอร์ไหล่โดยไม่แสดงแผงทริกเกอร์หรือเครื่องหมายของ RedMagic และให้กดปุ่มในการจัดวางแบบสัมผัสแทน + Air Trigger ซ้าย + Air Trigger ขวา + บันทึกไว้สำหรับการจัดวางนี้ + การสั่น + สั่นเมื่อแตะ Air Trigger + เอฟเฟกต์แสงบนหน้าจอ + ทำให้ขอบหน้าจอใต้ Air Trigger สว่างขึ้นเมื่อแตะ + เอฟเฟกต์ไฟ LED บรรยากาศเมื่อแตะ + ปิด + ติดค้าง + กะพริบเป็นจังหวะ + การทำงานของ Air Trigger ซ้าย + การทำงานของ Air Trigger ขวา + แตะครั้งเดียว + กดค้าง + ยิงรัว + การตั้งค่ายิงรัว + ความถี่ในการคลิก + ต่ำ + ปกติ + สูง เดดโซนของแอนะล็อกสติ๊ก ปุ่ม Steam ปุ่ม QAM @@ -2291,7 +2316,8 @@ กำลังดาวน์โหลดไคลเอนต์ Steam · %1$s มีการติดตั้งเครื่องมือความเข้ากันได้อื่นกำลังทำงานอยู่แล้ว หยุดเซสชันที่กำลังทำงานก่อนติดตั้งเครื่องมือความเข้ากันได้ - ไม่พบรุ่นที่เผยแพร่แบบ ARM64 สำหรับ %1$s + ไม่พบรุ่นที่เผยแพร่แบบ %2$s สำหรับ %1$s + ระบบป้องกันการโกง ต้องมีพื้นที่ว่างอย่างน้อย 4 GB รวมกับขนาดดาวน์โหลดเพื่อติดตั้ง %1$s กำลังดาวน์โหลด %1$s %2$s กำลังลองดาวน์โหลดใหม่ · ครั้งที่ %1$d จาก %2$d @@ -4139,4 +4165,6 @@ ทางลัดในเกม แสดงทางลัด Smart Glasses แสดงปุ่ม Smart Glasses แบบลอยทับบนเกม + ใช้โปรไฟล์ %1$s: %2$s + ใช้โปรไฟล์เริ่มต้น: %1$s diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index af33426288..0bb3223f55 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -1300,6 +1300,31 @@ Düğme boyutu Uyarlanabilir çubuklar Oyun titreşimi + Redmagic Air Triggers + Aç + Air Triggers kullan + Omuz tetiklerini RedMagic tetik paneli veya işaretleri olmadan açar. Bunun yerine dokunmatik düzenin düğmelerine basarlar. + Sol Air Trigger + Sağ Air Trigger + Bu düzen için kaydedilir + Titreşim + Bir Air Trigger\'a dokunulduğunda titrer + Ekran ışık efekti + Bir Air Trigger\'a dokunulduğunda altındaki ekran kenarını aydınlatır + Dokunma atmosfer LED efektleri + Kapalı + Sabit + Nabız + Sol Air Trigger işlemi + Sağ Air Trigger işlemi + Tek dokunma + Uzun basma + Hızlı ateş + Hızlı ateş ayarları + Tıklama sıklığı + Düşük + Normal + Yüksek Çubuk ölü bölgesi Steam düğmesi QAM düğmesi @@ -2308,7 +2333,8 @@ Steam istemcisi indiriliyor · %1$s Zaten çalışan bir uyumluluk aracı yüklemesi var Uyumluluk araçlarını yüklemeden önce etkin oturumu durdurun - %1$s için bir ARM64 yayını bulunamadı + %1$s için bir %2$s yayını bulunamadı + Anti-cheat %1$s\'i yüklemek için indirme boyutuna ek olarak en az 4 GB boş alan gerekir %1$s %2$s indiriliyor İndirme yeniden deneniyor · %2$d denemenin %1$d\'i @@ -4169,4 +4195,6 @@ Oyun içi kısayol Smart Glasses kısayolunu göster Oyun üzerinde yüzen Smart Glasses düğmesini göster. + %1$s profili kullanılıyor: %2$s + Varsayılan profil kullanılıyor: %1$s diff --git a/app/src/main/res/values-uk/strings.xml b/app/src/main/res/values-uk/strings.xml index 8e1b604f7f..04d1a13a99 100644 --- a/app/src/main/res/values-uk/strings.xml +++ b/app/src/main/res/values-uk/strings.xml @@ -1322,6 +1322,31 @@ Розмір кнопок Адаптивні стики Вібрація гри + Redmagic Air Triggers + Відкрити + Використовувати Air Triggers + Вмикає плечові тригери без панелі та міток RedMagic. Натомість вони натискають кнопки сенсорної розкладки. + Лівий Air Trigger + Правий Air Trigger + Зберігається для цієї розкладки + Вібрація + Вібрує під час дотику до Air Trigger + Світловий ефект на екрані + Підсвічує край екрана під Air Trigger під час дотику + LED-ефекти атмосфери під час дотику + Вимк. + Постійно + Пульсація + Дія лівого Air Trigger + Дія правого Air Trigger + Одне торкання + Довге натискання + Швидка стрільба + Налаштування швидкої стрільби + Частота натискань + Низька + Звичайна + Висока Мертва зона стіка Кнопка Steam Кнопка QAM @@ -2368,7 +2393,8 @@ Завантаження клієнта Steam · %1$s Встановлення інструмента сумісності вже триває Зупиніть активний сеанс, перш ніж встановлювати інструменти сумісності - Не вдалося знайти випуск ARM64 для %1$s + Не вдалося знайти випуск %2$s для %1$s + Античит Щоб встановити %1$s, потрібно щонайменше 4 GB вільного місця плюс розмір завантаження Завантаження %1$s %2$s Повтор завантаження · спроба %1$d з %2$d @@ -4249,4 +4275,6 @@ Ярлик у грі Показувати ярлик Smart Glasses Показувати плаваючу кнопку Smart Glasses поверх гри. + Використовується профіль %1$s: %2$s + Використовується профіль за замовчуванням: %1$s diff --git a/app/src/main/res/values-vi/strings.xml b/app/src/main/res/values-vi/strings.xml index 1f7dd4b72d..93d36887cb 100644 --- a/app/src/main/res/values-vi/strings.xml +++ b/app/src/main/res/values-vi/strings.xml @@ -1302,6 +1302,31 @@ Kích thước nút Cần thích ứng Rung khi chơi game + Redmagic Air Triggers + Mở + Dùng Air Triggers + Bật trigger vai mà không hiện bảng trigger hay điểm đánh dấu của RedMagic. Thay vào đó, chúng nhấn các nút của bố cục cảm ứng. + Air Trigger trái + Air Trigger phải + Được lưu cho bố cục này + Rung + Rung khi chạm vào Air Trigger + Hiệu ứng ánh sáng trên màn hình + Làm sáng cạnh màn hình bên dưới Air Trigger khi chạm vào + Hiệu ứng đèn LED không khí khi chạm + Tắt + Sáng liên tục + Nhấp nháy theo nhịp + Thao tác của Air Trigger trái + Thao tác của Air Trigger phải + Chạm một lần + Nhấn giữ + Bắn nhanh + Cài đặt bắn nhanh + Tần suất nhấp + Thấp + Bình thường + Cao Vùng chết của cần điều khiển Nút Steam Nút QAM @@ -2291,7 +2316,8 @@ Đang tải client Steam · %1$s Một lượt cài công cụ tương thích đang chạy Dừng phiên đang hoạt động trước khi cài công cụ tương thích - Không tìm thấy bản phát hành ARM64 cho %1$s + Không tìm thấy bản phát hành %2$s cho %1$s + Anti-cheat Cần ít nhất 4 GB trống cộng với kích thước tải xuống để cài %1$s Đang tải %1$s %2$s Đang thử lại tải · lần %1$d trong %2$d @@ -4139,4 +4165,6 @@ Lối tắt trong trò chơi Hiển thị lối tắt Smart Glasses Hiển thị nút Smart Glasses nổi phía trên trò chơi. + Đang dùng hồ sơ %1$s: %2$s + Đang dùng hồ sơ mặc định: %1$s diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index cee25f085c..f9cd8737ab 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -1385,6 +1385,31 @@ 按钮大小 自适应摇杆 游戏震动 + 红魔肩键 + 打开 + 使用肩键 + 开启肩键,但不显示红魔的肩键面板和屏幕标记。肩键改为按下触控布局中的按钮。 + 左肩键 + 右肩键 + 按此布局保存 + 振动 + 触摸肩键时振动 + 屏幕灯效 + 触摸肩键时点亮其下方的屏幕边缘 + 触控氛围灯效 + 关闭 + 常亮 + 脉冲 + 左肩键动作 + 右肩键动作 + 单击 + 长按 + 连发 + 连发设置 + 点击频率 + 低 + 正常 + 高 摇杆死区 Steam 按钮 QAM 按钮 @@ -2368,7 +2393,8 @@ 正在下载 Steam 客户端 · %1$s 已有兼容性工具正在安装 安装兼容性工具前请先停止当前会话 - 找不到 %1$s 的 ARM64 发布版本 + 找不到 %1$s 的 %2$s 发布版本 + 反作弊 安装 %1$s 需要至少 4 GB 可用空间外加下载大小 正在下载 %1$s %2$s 正在重试下载 · 第 %1$d 次,共 %2$d 次 @@ -4137,4 +4163,6 @@ 游戏内快捷方式 显示 Smart Glasses 快捷方式 在游戏画面上显示悬浮的 Smart Glasses 按钮。 + 正在使用 %1$s 配置:%2$s + 正在使用默认配置:%1$s diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 145acdff55..99cb9a8689 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -1301,6 +1301,31 @@ 按鍵大小 自動調整搖桿 遊戲震動 + 紅魔肩鍵 + 開啟 + 使用肩鍵 + 開啟肩鍵,但不顯示紅魔的肩鍵面板和螢幕標記。肩鍵改為按下觸控佈局中的按鈕。 + 左肩鍵 + 右肩鍵 + 按此佈局儲存 + 震動 + 觸摸肩鍵時震動 + 螢幕燈效 + 觸摸肩鍵時點亮其下方的螢幕邊緣 + 觸控氛圍燈效 + 關閉 + 常亮 + 脈衝 + 左肩鍵動作 + 右肩鍵動作 + 單擊 + 長按 + 連發 + 連發設定 + 點擊頻率 + 低 + 正常 + 高 搖桿死區 Steam 按鈕 QAM 按鈕 @@ -2290,7 +2315,8 @@ 正在下載 Steam 用戶端 · %1$s 已有兼容性工具正在安裝 請先停止目前的會話,再安裝兼容性工具 - 找不到 %1$s 的 ARM64 發佈版本 + 找不到 %1$s 的 %2$s 發佈版本 + 防作弊 安裝 %1$s 需要至少 4 GB 可用空間,另加下載大小 正在下載 %1$s %2$s 正在重試下載 · 第 %1$d 次,共 %2$d 次 @@ -4137,4 +4163,6 @@ 遊戲內捷徑 顯示 Smart Glasses 捷徑 在遊戲畫面上顯示浮動的 Smart Glasses 按鈕。 + 正在使用 %1$s 設定檔:%2$s + 正在使用預設設定檔:%1$s diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index c733c5f9eb..3896bd271d 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -1301,6 +1301,31 @@ 按鍵大小 自適應搖桿 遊戲震動 + 紅魔肩鍵 + 開啟 + 使用肩鍵 + 開啟肩鍵,但不顯示紅魔的肩鍵面板和螢幕標記。肩鍵改為按下觸控版面配置中的按鈕。 + 左肩鍵 + 右肩鍵 + 依此版面配置儲存 + 震動 + 觸碰肩鍵時震動 + 螢幕燈效 + 觸碰肩鍵時點亮其下方的螢幕邊緣 + 觸控氛圍燈效 + 關閉 + 恆亮 + 脈衝 + 左肩鍵動作 + 右肩鍵動作 + 單擊 + 長按 + 連發 + 連發設定 + 點擊頻率 + 低 + 正常 + 高 搖桿死區 Steam 按鈕 QAM 按鈕 @@ -2290,7 +2315,8 @@ 正在下載 Steam 用戶端 · %1$s 已有相容性工具正在安裝 安裝相容性工具前,請先停止執行中的工作階段 - 找不到 %1$s 的 ARM64 發行版本 + 找不到 %1$s 的 %2$s 發行版本 + 反作弊 安裝 %1$s 需要至少 4 GB 可用空間,再加上下載大小 正在下載 %1$s %2$s 正在重試下載 · 第 %1$d 次,共 %2$d 次 @@ -4137,4 +4163,6 @@ 遊戲內捷徑 顯示 Smart Glasses 捷徑 在遊戲畫面上顯示浮動的 Smart Glasses 按鈕。 + 正在使用 %1$s 設定檔:%2$s + 正在使用預設設定檔:%1$s diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 87379f4344..0088baafb1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1498,6 +1498,31 @@ Button size Adaptive sticks Game vibration + Redmagic Air Triggers + Open + Use Air Triggers + Turns on the shoulder triggers without RedMagic\'s trigger panel or markers. They press buttons of the touch layout instead. + Left Air Trigger + Right Air Trigger + Saved for this layout + Vibration + Vibrates when an Air Trigger is touched + Screen light effect + Lights up the screen edge under an Air Trigger when it is touched + Touch atmosphere LED effects + Off + Steady + Pulse + Left Air Trigger action + Right Air Trigger action + Single tap + Long press + Rapid fire + Rapid fire settings + Click frequency + Low + Normal + High Stick dead zone Steam button QAM button @@ -2643,7 +2668,8 @@ A compatibility tool install is already running Stop the active session before installing compatibility tools - Could not find an ARM64 release for %1$s + Could not find an %2$s release for %1$s + Anti-Cheat At least 4 GB free plus the download size is required to install %1$s Downloading %1$s %2$s Retrying download · attempt %1$d of %2$d @@ -2856,6 +2882,8 @@ Shared by Steam and Desktop. Applies live. Shared by Steam and Desktop. FSR, GSR and NIS apply when enlarging the session image. Sharpen only also works without enlargement. + Using %1$s profile: %2$s + Using Default profile: %1$s Filter sharpness %1$s Sets scaling to %2$s. Match screen (%1$d×%2$d) diff --git a/app/src/test/java/com/droiddeck/launcher/core/DeviceReportBuildDateTest.kt b/app/src/test/java/com/droiddeck/launcher/core/DeviceReportBuildDateTest.kt new file mode 100644 index 0000000000..21e4ad4206 --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/core/DeviceReportBuildDateTest.kt @@ -0,0 +1,16 @@ +package com.droiddeck.launcher.core + +import org.junit.Assert.assertEquals +import org.junit.Assert.assertNull +import org.junit.Test + +class DeviceReportBuildDateTest { + @Test fun theFirmwareBuildTimeIsShownInUtc() { + assertEquals("2024-11-08 17:47 UTC", DeviceReport.buildDate(1_731_088_027_000L)) + } + + @Test fun anUnsetBuildTimeIsUnknown() { + assertNull(DeviceReport.buildDate(0L)) + assertNull(DeviceReport.buildDate(-1L)) + } +} diff --git a/app/src/test/java/com/droiddeck/launcher/input/RedMagicAirTriggersTest.kt b/app/src/test/java/com/droiddeck/launcher/input/RedMagicAirTriggersTest.kt new file mode 100644 index 0000000000..83c75a2970 --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/input/RedMagicAirTriggersTest.kt @@ -0,0 +1,358 @@ +package com.droiddeck.launcher.input + +import android.hardware.input.InputManager +import android.os.Looper +import android.provider.Settings +import android.view.InputDevice +import android.view.KeyCharacterMap +import android.view.KeyEvent +import java.io.File +import java.time.Duration +import java.util.concurrent.Executor +import org.junit.After +import org.junit.Assert.* +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.RuntimeEnvironment +import org.robolectric.Shadows.shadowOf +import org.robolectric.annotation.Config +import org.robolectric.shadows.InputDeviceBuilder + +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [34], manifest = Config.NONE, shadows = [JoyConPadTest.RecordingWriter::class]) +class RedMagicAirTriggersTest { + private val events = mutableListOf() + private val router = InputRouter(object : InputOutput { + override fun key(code: Int, down: Boolean) { events += "key:$code:$down" } + override fun button(code: Int, down: Boolean) { events += "button:$code:$down" } + override fun pointer(dx: Float, dy: Float) {} + override fun scroll(steps: Int) {} + override fun command(command: InputCommand) { events += command.name } + override fun command(command: InputCommand, role: InputRole) { events += "${command.name}:$role" } + override fun requestMotion() {} + }) + private val context = RuntimeEnvironment.getApplication() + private val bridge = PadBridge(File(context.cacheDir, "air-trigger-input")) + private val input = AirTriggerInput(bridge) + private val lt = InputSurfaceElement(InputControl.LT, .1f, .1f, .1f, .1f) + private val rt = InputSurfaceElement(InputControl.RT, .8f, .1f, .1f, .1f) + private val jump = InputSurfaceElement(InputControl.A, .8f, .8f, .1f, .1f, id = "custom:jump", name = "Jump") + private val stick = InputSurfaceElement(InputControl.LS, .1f, .7f, .2f, .2f) + private val layout = SavedInputLayout("pad", "Pad", listOf(lt, rt, jump, stick)) + + @Before fun setup() { bridge.setInputRouter(router); DeckControls.setRouter(router) } + @After fun close() { input.close(); bridge.stop(); DeckControls.setRouter(null); DeckControls.releaseAll() } + + private fun bind(vararg actions: Pair) { + bridge.setInputProfile(InputProfile("test", elements = mapOf(InputRole.PRIMARY to mapOf(*actions)))) + } + private fun setups(vararg chosen: Pair) = chosen.associate { (trigger, element) -> trigger to AirTriggerSetup(element) } + private fun down(trigger: AirTrigger, enabled: Boolean = true, repeat: Int = 0) = input.onKey(trigger, KeyEvent.ACTION_DOWN, repeat, enabled) + private fun up(trigger: AirTrigger) = input.onKey(trigger, KeyEvent.ACTION_UP, 0, true) + private fun idle(ms: Long) = shadowOf(Looper.getMainLooper()).idleFor(Duration.ofMillis(ms)) + + private fun keyboard(id: Int, name: String, vararg keys: Int, external: Boolean = false): InputDevice { + val device = InputDeviceBuilder.newBuilder().setId(id).setName(name).setDescriptor("keyboard-$id") + .setExternal(external).setSources(InputDevice.SOURCE_KEYBOARD) + .setKeyCharacterMap(KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD)).build() + val manager = shadowOf(context.getSystemService(InputManager::class.java)) + manager.addInputDevice(device) + manager.addInputDeviceKeys(id, keys) + return device + } + + @Test fun onlyTheTriggerDeviceKeysAreAirTriggers() { + val triggers = keyboard(10, "nubia_tgk_aw_sar0_ch0") + val externalKeyboard = keyboard(11, "Keychron K2", KeyEvent.KEYCODE_F7, KeyEvent.KEYCODE_F8, external = true) + assertEquals(AirTrigger.LEFT, AirTrigger.of(KeyEvent.KEYCODE_F7, triggers)) + assertEquals(AirTrigger.RIGHT, AirTrigger.of(KeyEvent.KEYCODE_F8, triggers)) + assertNull(AirTrigger.of(KeyEvent.KEYCODE_F7, externalKeyboard)) + assertNull(AirTrigger.of(KeyEvent.KEYCODE_F8, null)) + assertNull(AirTrigger.of(KeyEvent.KEYCODE_VOLUME_DOWN, triggers)) + } + + @Test fun theUnnamedInternalKeyboardCanContainBothTriggers() { + val left = KeyEvent.KEYCODE_F7 + val right = KeyEvent.KEYCODE_F8 + val merged = keyboard(10, "", left, right, KeyEvent.KEYCODE_POWER) + assertEquals(AirTrigger.LEFT, AirTrigger.of(left, merged)) + assertEquals(AirTrigger.RIGHT, AirTrigger.of(right, merged)) + assertNull(AirTrigger.of(left, keyboard(11, "", left, right, external = true))) + assertNull(AirTrigger.of(left, keyboard(12, "", left))) + assertNull(AirTrigger.of(left, keyboard(-1, "", left, right))) + } + + @Test fun theTriggerLightUsesTheCodeRedMagicsSettingsGiveTheChosenEffect() { + val settings = """{"version":1,"shoulder_effects":{"close":"02000000","steady":"02101009","pulse":"021"},"selection":"02101000"}""" + assertEquals("02101009", RedMagicAirTriggers.shoulderEffect(settings, AirTriggerLed.STEADY)) + assertEquals("02000000", RedMagicAirTriggers.shoulderEffect(settings, AirTriggerLed.OFF)) + assertEquals("02102000", RedMagicAirTriggers.shoulderEffect(settings, AirTriggerLed.PULSE)) + assertEquals("02101000", RedMagicAirTriggers.shoulderEffect(null, AirTriggerLed.STEADY)) + assertEquals("02102000", RedMagicAirTriggers.shoulderEffect("not json", AirTriggerLed.PULSE)) + } + + @Test fun openingShowsTheIdleLightAndAppliesAgainAfterGameSpacesOwnSetup() { + val calls = mutableListOf() + val worker = RedMagicAirTriggers.worker + val lights = RedMagicAirTriggers.lights + RedMagicAirTriggers.worker = Executor { it.run() } + RedMagicAirTriggers.lights = object : TriggerLights { + override fun request(action: Int) { calls += "$action" } + override fun setEffect(effect: String) { calls += effect } + } + Settings.Global.putString(context.contentResolver, "lighting_shoulder_config_json", """{"shoulder_effects":{"pulse":"02102000"}}""") + AirTriggerPrefs.setLed(context, AirTriggerLed.PULSE) + try { + val opened = listOf("110", "02102000", "107", "109") + RedMagicAirTriggers.open(context) + assertEquals(opened, calls) + shadowOf(Looper.getMainLooper()).idleFor(Duration.ofSeconds(1)) + assertEquals(opened + opened, calls) + RedMagicAirTriggers.restore(context) + shadowOf(Looper.getMainLooper()).idleFor(Duration.ofSeconds(10)) + assertEquals(opened + opened + "111", calls) + } finally { + RedMagicAirTriggers.worker = worker + RedMagicAirTriggers.lights = lights + } + } + + @Test fun triggersDefaultToTheLayoutTriggersAndFollowAChoiceThatStillExists() { + assertEquals(lt, AirTriggerButtons.resolve(layout, AirTrigger.LEFT, null)) + assertEquals(rt, AirTriggerButtons.resolve(layout, AirTrigger.RIGHT, null)) + assertEquals(jump, AirTriggerButtons.resolve(layout, AirTrigger.LEFT, "custom:jump")) + assertEquals(lt, AirTriggerButtons.resolve(layout, AirTrigger.LEFT, "custom:removed")) + assertEquals(listOf(lt, rt, jump), AirTriggerButtons.options(layout)) + } + + @Test fun aLayoutWithoutTriggersStillOffersTheControllerTriggers() { + val buttons = SavedInputLayout("buttons", "Buttons", listOf(jump)) + assertEquals(listOf("custom:jump", "legacy:lt", "legacy:rt"), AirTriggerButtons.options(buttons).map { it.id }) + assertEquals("legacy:rt", AirTriggerButtons.resolve(buttons, AirTrigger.RIGHT, null).id) + assertEquals("legacy:lt", AirTriggerButtons.resolve(null, AirTrigger.LEFT, null).id) + } + + @Test fun touchFeedbackStartsOffWithASteadyLight() { + assertFalse(AirTriggerPrefs.vibration(context)) + assertFalse(AirTriggerPrefs.screenLight(context)) + assertEquals(AirTriggerLed.STEADY, AirTriggerPrefs.led(context)) + AirTriggerPrefs.setVibration(context, true) + AirTriggerPrefs.setScreenLight(context, true) + AirTriggerPrefs.setLed(context, AirTriggerLed.OFF) + assertTrue(AirTriggerPrefs.vibration(context)) + assertTrue(AirTriggerPrefs.screenLight(context)) + assertEquals(AirTriggerLed.OFF, AirTriggerPrefs.led(context)) + } + + @Test fun actionsAndRatesAreSavedPerLayoutBesideTheButton() { + assertEquals(AirTriggerAction.TAP, AirTriggerPrefs.action(context, "pad", AirTrigger.LEFT)) + assertEquals(RapidFireRate.NORMAL, AirTriggerPrefs.rate(context, "pad", AirTrigger.LEFT)) + AirTriggerPrefs.setButton(context, "pad", AirTrigger.LEFT, "custom:jump") + AirTriggerPrefs.setAction(context, "pad", AirTrigger.LEFT, AirTriggerAction.RAPID) + AirTriggerPrefs.setRate(context, "pad", AirTrigger.LEFT, RapidFireRate.HIGH) + assertEquals("custom:jump", AirTriggerPrefs.button(context, "pad", AirTrigger.LEFT)) + assertEquals(AirTriggerAction.RAPID, AirTriggerPrefs.action(context, "pad", AirTrigger.LEFT)) + assertEquals(RapidFireRate.HIGH, AirTriggerPrefs.rate(context, "pad", AirTrigger.LEFT)) + assertEquals(AirTriggerAction.TAP, AirTriggerPrefs.action(context, "pad", AirTrigger.RIGHT)) + assertEquals(AirTriggerAction.TAP, AirTriggerPrefs.action(context, "other", AirTrigger.LEFT)) + } + + @Test fun aLongPressLatchesTheButtonUntilTheNextTouch() { + val touches = mutableListOf() + val latch = AirTriggerInput(bridge, touched = { trigger, down -> touches += "$trigger:$down" }) + bind("legacy:lt" to InputAction.Keys(listOf(42))) + latch.configure(mapOf(AirTrigger.LEFT to AirTriggerSetup(lt, AirTriggerAction.LATCH))) + latch.onKey(AirTrigger.LEFT, KeyEvent.ACTION_DOWN, 0, true) + assertTrue(latch.onKey(AirTrigger.LEFT, KeyEvent.ACTION_UP, 0, true)) + idle(1_000) + assertEquals(listOf("key:42:true"), events) + latch.onKey(AirTrigger.LEFT, KeyEvent.ACTION_DOWN, 0, true) + assertEquals(listOf("key:42:true", "key:42:false"), events) + latch.onKey(AirTrigger.LEFT, KeyEvent.ACTION_UP, 0, true) + latch.close() + assertEquals(listOf("key:42:true", "key:42:false"), events) + assertEquals(listOf("LEFT:true", "LEFT:false", "LEFT:true", "LEFT:false"), touches) + } + + @Test fun aLongPressOnAToggleButtonLetsGoOnTheNextTouch() { + val screen = mutableListOf() + val latch = AirTriggerInput(bridge, { id, _, held, _ -> screen += "$id:$held"; true }) + bind("custom:jump" to InputAction.Keys(listOf(57))) + latch.configure(mapOf(AirTrigger.LEFT to AirTriggerSetup(jump.copy(toggle = true), AirTriggerAction.LATCH))) + latch.onKey(AirTrigger.LEFT, KeyEvent.ACTION_DOWN, 0, true); latch.onKey(AirTrigger.LEFT, KeyEvent.ACTION_UP, 0, true) + latch.onKey(AirTrigger.LEFT, KeyEvent.ACTION_DOWN, 0, true); latch.onKey(AirTrigger.LEFT, KeyEvent.ACTION_UP, 0, true) + latch.close() + assertEquals(listOf("key:57:true", "key:57:false"), events) + assertEquals(emptyList(), screen) + } + + @Test fun aSingleTapHoldsTheButtonWhileTheTriggerIsTouched() { + bind("legacy:lt" to InputAction.Keys(listOf(42))) + input.configure(mapOf(AirTrigger.LEFT to AirTriggerSetup(lt, AirTriggerAction.TAP))) + down(AirTrigger.LEFT) + idle(1_000) + assertEquals(listOf("key:42:true"), events) + up(AirTrigger.LEFT) + assertEquals(listOf("key:42:true", "key:42:false"), events) + } + + @Test fun rapidFireClicksAtTheChosenRateWhileHeld() { + val rapid = AirTriggerInput(bridge) + bind("legacy:lt" to InputAction.Keys(listOf(42))) + rapid.configure(mapOf(AirTrigger.LEFT to AirTriggerSetup(lt, AirTriggerAction.RAPID, RapidFireRate.NORMAL))) + rapid.onKey(AirTrigger.LEFT, KeyEvent.ACTION_DOWN, 0, true) + idle(950) + assertEquals(10, events.size) + assertEquals("key:42:true", events.first()) + assertEquals(5, events.count { it == "key:42:true" }) + rapid.onKey(AirTrigger.LEFT, KeyEvent.ACTION_UP, 0, true) + idle(1_000) + rapid.close() + assertEquals(10, events.size) + assertEquals("key:42:false", events.last()) + } + + @Test fun liftingTheTriggerMidClickEndsRapidFireReleased() { + val rapid = AirTriggerInput(bridge) + bind("legacy:lt" to InputAction.Keys(listOf(42))) + rapid.configure(mapOf(AirTrigger.LEFT to AirTriggerSetup(lt, AirTriggerAction.RAPID, RapidFireRate.HIGH))) + rapid.onKey(AirTrigger.LEFT, KeyEvent.ACTION_DOWN, 0, true) + idle(120) + rapid.onKey(AirTrigger.LEFT, KeyEvent.ACTION_UP, 0, true) + idle(500) + rapid.close() + assertEquals(listOf("key:42:true", "key:42:false", "key:42:true", "key:42:false"), events) + } + + @Test fun rapidFireClicksAToggleButtonAsAPlainOneThatEndsReleased() { + val screen = mutableListOf() + val rapid = AirTriggerInput(bridge, { id, _, held, _ -> screen += "$id:$held"; true }) + bind("custom:jump" to InputAction.Keys(listOf(57))) + rapid.configure(mapOf(AirTrigger.LEFT to AirTriggerSetup(jump.copy(toggle = true), AirTriggerAction.RAPID))) + rapid.onKey(AirTrigger.LEFT, KeyEvent.ACTION_DOWN, 0, true) + idle(250) + rapid.onKey(AirTrigger.LEFT, KeyEvent.ACTION_UP, 0, true) + rapid.close() + assertEquals(listOf("key:57:true", "key:57:false", "key:57:true", "key:57:false"), events) + assertEquals(emptyList(), screen) + } + + @Test fun changingTheActionMidPressLetsGoOfTheButtonUntilTheNextTouch() { + bind("legacy:lt" to InputAction.Keys(listOf(42))) + input.configure(setups(AirTrigger.LEFT to lt)) + down(AirTrigger.LEFT) + input.configure(mapOf(AirTrigger.LEFT to AirTriggerSetup(lt, AirTriggerAction.RAPID))) + idle(500) + assertTrue(up(AirTrigger.LEFT)) + assertEquals(listOf("key:42:true", "key:42:false"), events) + down(AirTrigger.LEFT) + idle(250) + up(AirTrigger.LEFT) + assertEquals(listOf("key:42:true", "key:42:false", "key:42:true", "key:42:false", "key:42:true", "key:42:false"), events) + } + + @Test fun choicesAreSavedPerLayoutAndTheToggleStartsOff() { + assertFalse(AirTriggerPrefs.enabled(context)) + AirTriggerPrefs.setEnabled(context, true) + AirTriggerPrefs.setButton(context, "pad", AirTrigger.LEFT, "custom:jump") + assertTrue(AirTriggerPrefs.enabled(context)) + assertEquals("custom:jump", AirTriggerPrefs.button(context, "pad", AirTrigger.LEFT)) + assertNull(AirTriggerPrefs.button(context, "pad", AirTrigger.RIGHT)) + assertNull(AirTriggerPrefs.button(context, "other", AirTrigger.LEFT)) + } + + @Test fun aTriggerPressesTheChosenLayoutButton() { + bind("legacy:lt" to InputAction.Keys(listOf(42)), "custom:jump" to InputAction.Keys(listOf(57))) + input.configure(setups(AirTrigger.LEFT to lt, AirTrigger.RIGHT to jump)) + assertTrue(down(AirTrigger.LEFT)); assertTrue(down(AirTrigger.RIGHT)) + assertTrue(up(AirTrigger.RIGHT)); assertTrue(up(AirTrigger.LEFT)) + assertEquals(listOf("key:42:true", "key:57:true", "key:57:false", "key:42:false"), events) + } + + @Test fun keyRepeatsAndPressesWhileInputIsBlockedAreSwallowed() { + bind("legacy:lt" to InputAction.Keys(listOf(42))) + input.configure(setups(AirTrigger.LEFT to lt)) + assertTrue(down(AirTrigger.LEFT, enabled = false)) + assertTrue(up(AirTrigger.LEFT)) + assertTrue(down(AirTrigger.LEFT)); assertTrue(down(AirTrigger.LEFT, repeat = 1)) + assertTrue(up(AirTrigger.LEFT)) + assertEquals(listOf("key:42:true", "key:42:false"), events) + } + + @Test fun switchingOffReleasesAHeldButtonAndLetsTheKeysThrough() { + bind("legacy:lt" to InputAction.Keys(listOf(42))) + input.configure(setups(AirTrigger.LEFT to lt)) + assertFalse(down(AirTrigger.RIGHT)) + down(AirTrigger.LEFT) + input.configure(emptyMap()) + assertEquals(listOf("key:42:true", "key:42:false"), events) + assertTrue(up(AirTrigger.LEFT)) + assertFalse(down(AirTrigger.LEFT)) + assertEquals(2, events.size) + } + + @Test fun aButtonShownOnScreenTakesThePressAndTheTriggersLight() { + val screen = mutableListOf() + val lights = mutableListOf() + val onScreen = AirTriggerInput(bridge, { id, trigger, held, cancelled -> screen += "$id:$trigger:$held:$cancelled"; id == "custom:jump" }, + { trigger, down -> lights += if (down) trigger.pressLight else trigger.releaseLight }) + bind("legacy:lt" to InputAction.Keys(listOf(42)), "custom:jump" to InputAction.Keys(listOf(57))) + onScreen.configure(setups(AirTrigger.LEFT to lt, AirTrigger.RIGHT to jump)) + onScreen.onKey(AirTrigger.RIGHT, KeyEvent.ACTION_DOWN, 0, true); onScreen.onKey(AirTrigger.LEFT, KeyEvent.ACTION_DOWN, 0, true) + onScreen.onKey(AirTrigger.RIGHT, KeyEvent.ACTION_UP, 0, true); onScreen.onKey(AirTrigger.LEFT, KeyEvent.ACTION_UP, 0, true) + onScreen.onKey(AirTrigger.LEFT, KeyEvent.ACTION_DOWN, 0, false); onScreen.onKey(AirTrigger.LEFT, KeyEvent.ACTION_UP, 0, true) + onScreen.close() + assertEquals(listOf("custom:jump:RIGHT:true:false", "legacy:lt:LEFT:true:false", "custom:jump:RIGHT:false:false"), screen) + assertEquals(listOf("key:42:true", "key:42:false"), events) + assertEquals(listOf(108, 106, 109, 107), lights) + } + + @Test fun switchingOffLetsGoOfTheOnScreenButton() { + val screen = mutableListOf() + val onScreen = AirTriggerInput(bridge, { id, trigger, held, cancelled -> screen += "$id:$trigger:$held:$cancelled"; true }) + onScreen.configure(setups(AirTrigger.LEFT to jump)) + onScreen.onKey(AirTrigger.LEFT, KeyEvent.ACTION_DOWN, 0, true) + onScreen.configure(emptyMap()) + assertTrue(onScreen.onKey(AirTrigger.LEFT, KeyEvent.ACTION_UP, 0, true)) + assertEquals(listOf("custom:jump:LEFT:true:false", "custom:jump:LEFT:false:true"), screen) + } + + @Test fun aForcedReleaseDoesNotRunACommandButtonButAKeyUpDoes() { + bind("custom:jump" to InputAction.Command(InputCommand.KEYBOARD)) + input.configure(setups(AirTrigger.LEFT to jump)) + down(AirTrigger.LEFT) + input.release() + up(AirTrigger.LEFT) + assertEquals(emptyList(), events) + down(AirTrigger.LEFT); up(AirTrigger.LEFT) + assertEquals(listOf("KEYBOARD:PRIMARY"), events) + } + + @Test fun aToggleLatchedWhileItsButtonWasHiddenIsHandedToTheShownButton() { + var shown = false + val screen = mutableListOf() + val onScreen = AirTriggerInput(bridge, { id, _, held, _ -> screen += "$id:$held"; shown }) + bind("custom:jump" to InputAction.Keys(listOf(57))) + onScreen.configure(setups(AirTrigger.LEFT to jump.copy(toggle = true))) + onScreen.onKey(AirTrigger.LEFT, KeyEvent.ACTION_DOWN, 0, true); onScreen.onKey(AirTrigger.LEFT, KeyEvent.ACTION_UP, 0, true) + assertEquals(listOf("key:57:true"), events) + shown = true + onScreen.onKey(AirTrigger.LEFT, KeyEvent.ACTION_DOWN, 0, true) + assertEquals(listOf("key:57:true", "key:57:false"), events) + onScreen.onKey(AirTrigger.LEFT, KeyEvent.ACTION_UP, 0, true) + onScreen.close() + assertEquals(listOf("custom:jump:true", "custom:jump:true", "custom:jump:false"), screen) + } + + @Test fun choosingAnotherButtonMovesTheTriggerWithoutLeavingTheOldOneHeld() { + bind("legacy:lt" to InputAction.Keys(listOf(42)), "custom:jump" to InputAction.Keys(listOf(57))) + input.configure(setups(AirTrigger.LEFT to lt)) + down(AirTrigger.LEFT) + input.configure(setups(AirTrigger.LEFT to jump)) + up(AirTrigger.LEFT) + down(AirTrigger.LEFT); up(AirTrigger.LEFT) + assertEquals(listOf("key:42:true", "key:42:false", "key:57:true", "key:57:false"), events) + } +} diff --git a/app/src/test/java/com/droiddeck/launcher/session/EnhancedSessionLogShareTest.kt b/app/src/test/java/com/droiddeck/launcher/session/EnhancedSessionLogShareTest.kt index e02523e97f..e6dd6163d6 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/EnhancedSessionLogShareTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/EnhancedSessionLogShareTest.kt @@ -14,6 +14,7 @@ import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner import org.robolectric.RuntimeEnvironment import org.robolectric.annotation.Config +import java.io.File import java.io.IOException import java.io.RandomAccessFile import java.nio.ByteBuffer @@ -436,6 +437,53 @@ class EnhancedSessionLogShareTest { SessionLogShare.clear(app) } + @Test fun theRunningSessionsGameLogIsSharedBeforeSteamsWholeClientLogs() { + val previousLogsEnabled = SessionPrefs.logsEnabled(app) + val steamLog = File(SessionPrefs.activeSteamRoot(app), "logs/console_log.txt") + var started: File? = null + try { + SessionPrefs.setLogsEnabled(app, true) + val session = SessionPaths.beginOrCurrent(app, "live-steam").also { started = it } + session.resolve("session.log").writeText("session\n") + session.resolve("steam-239250.log").writeText("wine: game log\n") + steamLog.apply { parentFile!!.mkdirs(); writeText("steam client history\n".repeat(400)) } + val limits = EnhancedShareLimits(maxFilesPerArchive = 16, maxBytesPerFile = 8192, maxBytesTotal = 4096) + + val zip = EnhancedSessionLogShare.createLegacy(app, session, limits = limits)!! + + ZipFile(zip).use { archive -> + assertEquals( + "wine: game log\n", + archive.getInputStream(archive.getEntry("${session.name}/steam-239250.log")).bufferedReader().readText(), + ) + val manifest = JSONObject(archive.getInputStream(archive.getEntry("diagnostics-manifest.json")) + .bufferedReader().readText()) + val entries = manifest.getJSONArray("entries") + val records = (0 until entries.length()).map { entries.getJSONObject(it) } + assertEquals("captured", records.single { it.optString("entry") == "${session.name}/steam-239250.log" }.getString("status")) + val steam = records.single { it.optString("entry") == "${session.name}/steam/console_log.txt" } + assertEquals("live-steam", steam.getString("origin")) + assertEquals("truncated", steam.getString("status")) + assertTrue(archive.getEntry("${session.name}/steam/console_log.txt") != null) + } + + val roomy = EnhancedSessionLogShare.createLegacy(app, session)!! + + ZipFile(roomy).use { archive -> + assertEquals( + "steam client history\n".repeat(400), + archive.getInputStream(archive.getEntry("${session.name}/steam/console_log.txt")).bufferedReader().readText(), + ) + } + } finally { + SessionPaths.take()?.let { SessionPaths.release(app, it) } + started?.deleteRecursively() + steamLog.delete() + SessionPrefs.setLogsEnabled(app, previousLogsEnabled) + SessionLogShare.clear(app) + } + } + @Test fun unreadableDiscoverySubtreeKeepsOtherLogsAndMarksTheManifestPartial() { assumeFilePermissionsEnforced() assumeFalse(System.getProperty("os.name").startsWith("Windows")) diff --git a/app/src/test/java/com/droiddeck/launcher/session/OutputPacingTest.kt b/app/src/test/java/com/droiddeck/launcher/session/OutputPacingTest.kt index 03b7e14f3d..aed120c6f6 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/OutputPacingTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/OutputPacingTest.kt @@ -42,4 +42,24 @@ class OutputPacingTest { assertEquals(45, SessionPrefs.compositorFpsLimit(0, 45, hostCap = 60)) assertEquals(SessionPrefs.PIP_FPS, SessionPrefs.compositorFpsLimit(0, 0, pip = true, hostCap = 60)) } + + @Test fun afterPictureInPictureTheLayerStopsVotingThirtyWhileItsOwnOverrideIsStillReported() { + val staleOverride = SessionPrefs.hostFrameCap(30f, 120f) + assertEquals(SessionPrefs.PIP_FPS, staleOverride) + val own = SessionPrefs.compositorFpsLimit(0, 0, pip = false) + assertEquals(120f, SessionPrefs.layerFrameRate(own, 120f, false), 0f) + assertEquals(staleOverride, SessionPrefs.compositorFpsLimit(0, 0, pip = false, hostCap = staleOverride)) + assertEquals(SessionPrefs.FPS_UNPACED, SessionPrefs.compositorFpsLimit(0, 0, pip = false, hostCap = SessionPrefs.hostFrameCap(120f, 120f))) + } + + @Test fun theLayerVotesOnlyTheSessionsOwnLimits() { + assertEquals(SessionPrefs.PIP_FPS.toFloat(), SessionPrefs.layerFrameRate(SessionPrefs.compositorFpsLimit(0, pip = true), 120f, false), 0f) + assertEquals(45f, SessionPrefs.layerFrameRate(SessionPrefs.compositorFpsLimit(0, 45), 120f, false), 0f) + assertEquals(60f, SessionPrefs.layerFrameRate(SessionPrefs.compositorFpsLimit(60), 120f, false), 0f) + assertEquals(120f, SessionPrefs.layerFrameRate(SessionPrefs.FPS_UNPACED, 120f, false), 0f) + } + + @Test fun blackFrameInsertionKeepsThePanelRate() { + assertEquals(120f, SessionPrefs.layerFrameRate(45, 120f, true), 0f) + } } diff --git a/app/src/test/java/com/droiddeck/launcher/session/ProtonExtrasTest.kt b/app/src/test/java/com/droiddeck/launcher/session/ProtonExtrasTest.kt index d975b6b756..33542f0f0e 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/ProtonExtrasTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/ProtonExtrasTest.kt @@ -78,7 +78,7 @@ class ProtonExtrasTest { @Test fun theSourcesInOrder() { - assertEquals(listOf("ge", "cachyos", "droiddeck", "bionic"), ProtonExtras.tools.map { it.id }) + assertEquals(listOf("ge", "cachyos", "droiddeck", "anticheat", "bionic"), ProtonExtras.tools.map { it.id }) val droiddeck = tool("droiddeck") assertEquals("DroidDeck-Proton", droiddeck.name) assertEquals("DroidDeck-Proton", droiddeck.prefix) @@ -88,6 +88,13 @@ class ProtonExtrasTest { assertFalse(droiddeck.assetPattern.containsMatchIn("DroidDeck-Proton-11-7.5-aarch64.sha512sum")) assertFalse(droiddeck.assetPattern.containsMatchIn("DroidDeck-Proton-11-7.5-aarch64.build-info.json")) assertFalse(tool("cachyos").assetPattern.containsMatchIn("proton-cachyos-11.0-20261005-slr-x86_64.tar.xz")) + val antiCheat = tool("anticheat") + assertEquals("Droid-Deck/DroidDeck-Proton", antiCheat.repo) + assertEquals("DroidDeck-Proton", antiCheat.prefix) + assertTrue(antiCheat.assetPattern.containsMatchIn("DroidDeck-Proton-11-14.3-x86_64.tar.gz")) + assertFalse(antiCheat.assetPattern.containsMatchIn("DroidDeck-Proton-11-14.3-x86_64.sha512sum")) + assertFalse(antiCheat.assetPattern.containsMatchIn("DroidDeck-Proton-11-14.3-aarch64.tar.gz")) + assertFalse(droiddeck.assetPattern.containsMatchIn("DroidDeck-Proton-11-14.3-x86_64.tar.gz")) } @Test @@ -181,6 +188,55 @@ class ProtonExtrasTest { assertEquals(emptyList(), ProtonExtras.installedIn(File(tools, "missing"), tool("ge"))) } + @Test + fun x86_64BuildsAreNotTakenForTheArm64Tool() { + val tools = temp.newFolder("compatibilitytools.d") + for (name in listOf("DroidDeck-Proton 11-7.5", "DroidDeck-Proton-11-14.2-x86_64")) installTool(tools, name) + File(tools, "DroidDeck-Proton-11-14.2-x86_64/files/lib/wine/x86_64-unix").mkdirs() + File(tools, "DroidDeck-Proton 11-7.5/files/lib/wine/x86_64-unix").mkdirs() + File(tools, "DroidDeck-Proton 11-7.5/files/bin-arm64").mkdirs() + assertEquals(listOf("DroidDeck-Proton 11-7.5"), ProtonExtras.installedIn(tools, tool("droiddeck"))) + assertTrue(ProtonExtras.x86_64Build(File(tools, "DroidDeck-Proton-11-14.2-x86_64"))) + assertEquals(listOf("DroidDeck-Proton-11-14.2-x86_64"), ProtonExtras.installedIn(tools, tool("anticheat"))) + } + + @Test + fun theX86_64BuildIsFetchedOnlyForAnInstalledAntiCheatRuntimeUnlessTheUserRemovedIt() { + val context = RuntimeEnvironment.getApplication() + val tools = File(LinuxRuntime.rootDir(context), "root/.local/share/Steam/compatibilitytools.d") + tools.deleteRecursively() + File(context.filesDir, "proton-latest.json").writeText( + """{"anticheat":{"tag":"DroidDeck-Proton-11-14.3","at":1}}""") + val antiCheat = tool("anticheat") + ProtonExtras.setDeclined(context, false, "anticheat") + assertNull(ProtonExtras.missing(context, antiCheat) { false }) + assertEquals("DroidDeck-Proton-11-14.3", ProtonExtras.missing(context, antiCheat) { true }) + ProtonExtras.setDeclined(context, true, "anticheat") + assertNull(ProtonExtras.missing(context, antiCheat) { true }) + assertFalse(ProtonExtras.declined(context)) + ProtonExtras.setDeclined(context, false, "anticheat") + installTool(tools, "DroidDeck-Proton 11-14.2") + File(tools, "DroidDeck-Proton 11-14.2/files/bin-arm64").mkdirs() + assertEquals("DroidDeck-Proton-11-14.3", ProtonExtras.missing(context, antiCheat) { true }) + installTool(tools, "DroidDeck-Proton-11-14.2-x86_64") + File(tools, "DroidDeck-Proton-11-14.2-x86_64/files/lib/wine/x86_64-unix").mkdirs() + assertNull(ProtonExtras.missing(context, antiCheat) { true }) + } + + @Test + fun anAntiCheatRuntimeInAnyLibraryCounts() { + val first = temp.newFolder("library-a") + val second = temp.newFolder("library-b") + File(second, "steamapps").mkdirs() + assertFalse(ProtonExtras.antiCheatRuntimeIn(listOf(first, second))) + File(second, "steamapps/appmanifest_1161040.acf").writeText("") + assertTrue(ProtonExtras.antiCheatRuntimeIn(listOf(first, second))) + assertFalse(ProtonExtras.antiCheatRuntimeIn(listOf(first))) + File(first, "steamapps").mkdirs() + File(first, "steamapps/appmanifest_1826330.acf").writeText("") + assertTrue(ProtonExtras.antiCheatRuntimeIn(listOf(first))) + } + @Test fun interruptedBuildsAreNotReportedAsInstalled() { val tools = temp.newFolder("compatibilitytools.d") @@ -218,6 +274,7 @@ class ProtonExtrasTest { .put("ge", JSONObject().put("tag", "GE-Proton11-7").put("at", now - 60_000)) .put("cachyos", JSONObject().put("tag", "cachyos-11.0-20261005-slr").put("at", now - 60_000)) .put("droiddeck", JSONObject().put("tag", "DroidDeck-Proton-11-7.6").put("at", now - ProtonExtras.CHECK_EVERY_MS + 60_000)) + .put("anticheat", JSONObject().put("tag", "DroidDeck-Proton-11-7.6").put("at", now - 60_000)) File(context.filesDir, "proton-latest.json").writeText(latest.toString()) assertFalse(ProtonExtras.checkLatest(context, now = now)) assertEquals("DroidDeck-Proton-11-7.6", ProtonExtras.update(context, tool("droiddeck"))) diff --git a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt index 087c1a9980..94537df59b 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt @@ -10,6 +10,7 @@ import java.util.concurrent.TimeUnit import java.util.zip.ZipFile import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse +import org.junit.Assert.assertNotNull import org.junit.Assert.assertTrue import org.junit.After import org.junit.Before @@ -116,6 +117,33 @@ class SessionLogShareZipTest { } } + @Test fun theSessionsGameLogsAreSharedBeforeBulkySteamClientLogsUseTheBudget() { + val session = File(LinuxRuntime.logDir(app), "2026-12-05-08-steam").apply { mkdirs() } + val out = File(app.getExternalFilesDir(null), "agent-logs/budget") + try { + File(session, "session.log").writeText("booted\n") + val steam = File(session, "steam").apply { mkdirs() } + listOf("console_log.txt", "webhelper_js.txt", "cef_log.txt").forEach { + File(steam, it).writeText("client line\n".repeat(600)) + } + File(session, "steam-1568590.log").writeText("Proton: x86-64\nerr:module:load\n") + File(session, "games").apply { mkdirs() }.resolve("dxvk.log").writeText("info: DXVK\n") + val limits = EnhancedShareLimits(maxFilesPerArchive = 512, maxBytesPerFile = 8192, maxBytesTotal = 6000) + + val zip = EnhancedSessionLogShare.createLegacy(app, session, outputDirectory = out, limits = limits)!! + ZipFile(zip).use { archive -> + assertNotNull(archive.getEntry("${session.name}/session.log")) + val proton = archive.getEntry("${session.name}/steam-1568590.log")!! + assertTrue(archive.getInputStream(proton).bufferedReader().readText().contains("err:module:load")) + assertTrue(archive.entries().toList().any { it.name.startsWith("${session.name}/games/") }) + assertTrue(archive.entries().toList().count { it.name.startsWith("${session.name}/steam/") } < 3) + } + } finally { + out.deleteRecursively() + session.deleteRecursively() + } + } + @Test fun everyTextFileInTheZipIsScrubbedAndTheStoresAndToolsLogsComeAlong() { val logs = LinuxRuntime.logDir(app) val session = File(logs, "2026-10-08-01-steam").apply { mkdirs() } diff --git a/app/src/test/java/com/droiddeck/launcher/session/SessionPrefsUpscalerTest.kt b/app/src/test/java/com/droiddeck/launcher/session/SessionPrefsUpscalerTest.kt new file mode 100644 index 0000000000..36708bc145 --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/session/SessionPrefsUpscalerTest.kt @@ -0,0 +1,79 @@ +package com.droiddeck.launcher.session + +import android.content.Context +import org.json.JSONObject +import org.junit.Assert.assertEquals +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.RuntimeEnvironment +import org.robolectric.annotation.Config + +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [28], manifest = Config.NONE) +class SessionPrefsUpscalerTest { + private lateinit var context: Context + + @Before fun setUp() { + context = RuntimeEnvironment.getApplication() + context.getSharedPreferences("session", Context.MODE_PRIVATE).edit().clear().commit() + } + + @Test fun gameOverridesAreIsolatedAndFallBackToTheGlobalFilter() { + SessionPrefs.setUpscaler(context, 4) + SessionPrefs.setGameUpscaler(context, "12345", 7) + + assertEquals(4, SessionPrefs.upscaler(context)) + assertEquals(7, SessionPrefs.screenEffectsUpscaler(context, "game:12345")) + assertEquals(4, SessionPrefs.screenEffectsUpscaler(context, "game:54321")) + assertTrue(SessionPrefs.hasGameUpscalerOverride(context, "12345")) + assertFalse(SessionPrefs.hasGameUpscalerOverride(context, "54321")) + assertFalse(SessionPrefs.hasScreenEffectsOverride(context, "game:12345")) + } + + @Test fun resettingGameOverrideRestoresTheGlobalFilter() { + SessionPrefs.setUpscaler(context, 3) + SessionPrefs.setGameUpscaler(context, "12345", 6) + + SessionPrefs.clearGameUpscaler(context, "12345") + + assertFalse(SessionPrefs.hasGameUpscalerOverride(context, "12345")) + assertEquals(3, SessionPrefs.screenEffectsUpscaler(context, "game:12345")) + } + + @Test fun screenEffectsUpscalerApiKeepsGameFiltersSeparateFromScreenEffects() { + SessionPrefs.setUpscaler(context, 4) + SessionPrefs.setScreenEffectsUpscaler(context, "game:12345", 8) + + assertEquals(8, SessionPrefs.screenEffectsUpscaler(context, "game:12345")) + assertFalse(SessionPrefs.hasScreenEffectsOverride(context, "game:12345")) + } + + @Test fun legacyGameFilterOverridesRemainReadableAndCanBeReset() { + val profile = JSONObject().put("upscaler", 6) + val profiles = JSONObject().put("game:12345", profile) + context.getSharedPreferences("session", Context.MODE_PRIVATE).edit() + .putString("screenEffects.profiles", profiles.toString()).commit() + + assertTrue(SessionPrefs.hasGameUpscalerOverride(context, "12345")) + assertEquals(6, SessionPrefs.screenEffectsUpscaler(context, "game:12345")) + + SessionPrefs.clearGameUpscaler(context, "12345") + + assertFalse(SessionPrefs.hasGameUpscalerOverride(context, "12345")) + assertEquals(2, SessionPrefs.screenEffectsUpscaler(context, "game:12345")) + assertFalse(SessionPrefs.hasScreenEffectsOverride(context, "game:12345")) + } + + @Test fun deletingGameScreenEffectsProfileClearsUpscalerOverrideEvenWithoutEffectsProfile() { + SessionPrefs.setGameUpscaler(context, "12345", 6) + + SessionPrefs.deleteScreenEffectsProfile(context, "game:12345") + + assertFalse(SessionPrefs.hasGameUpscalerOverride(context, "12345")) + assertEquals(SessionPrefs.upscaler(context), SessionPrefs.screenEffectsUpscaler(context, "game:12345")) + } +} diff --git a/app/src/test/java/com/droiddeck/launcher/ui/InputSurfaceTouchTest.kt b/app/src/test/java/com/droiddeck/launcher/ui/InputSurfaceTouchTest.kt index a42a0bf76c..786ee5203a 100644 --- a/app/src/test/java/com/droiddeck/launcher/ui/InputSurfaceTouchTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/ui/InputSurfaceTouchTest.kt @@ -77,6 +77,59 @@ class InputSurfaceTouchTest { assertFalse(state().isDown(PadState.A)) } + @Test fun anOutsideHoldPressesAndLightsTheButtonAlongsideAFinger() { + val surface = view.inputSurface + val button = (surface.javaClass.getDeclaredField("customCanvas").also { it.isAccessible = true }.get(surface) as ViewGroup).getChildAt(0) + fun lit() = button.javaClass.getDeclaredMethod("getHighlighted").also { it.isAccessible = true }.invoke(button) as Boolean + + assertTrue(surface.hold(a.id, 0, true)) + assertTrue(state().isDown(PadState.A)) + assertTrue(lit()) + touch(MotionEvent.ACTION_DOWN, 1 to (800f to 240f)) + touch(MotionEvent.ACTION_UP, 1 to (800f to 240f)) + assertTrue(state().isDown(PadState.A)) + assertTrue(surface.hold(a.id, 0, false)) + assertFalse(state().isDown(PadState.A)) + assertFalse(lit()) + assertFalse(surface.hold("custom:missing", 0, true)) + } + + @Test fun aCancelledTouchLeavesAnOutsideHoldOnTheButton() { + val surface = view.inputSurface + assertTrue(surface.hold(a.id, 0, true)) + touch(MotionEvent.ACTION_DOWN, 1 to (800f to 240f)) + touch(MotionEvent.ACTION_CANCEL, 1 to (800f to 240f)) + assertTrue(state().isDown(PadState.A)) + assertTrue(surface.hold(a.id, 0, false)) + assertFalse(state().isDown(PadState.A)) + } + + @Test fun releasingAllInputLetsGoOfAnOutsideHold() { + val surface = view.inputSurface + val button = (surface.javaClass.getDeclaredField("customCanvas").also { it.isAccessible = true }.get(surface) as ViewGroup).getChildAt(0) + fun lit() = button.javaClass.getDeclaredMethod("getHighlighted").also { it.isAccessible = true }.invoke(button) as Boolean + + assertTrue(surface.hold(a.id, 0, true)) + view.releaseAll() + assertFalse(state().isDown(PadState.A)) + assertFalse(lit()) + touch(MotionEvent.ACTION_DOWN, 1 to (800f to 240f)) + assertTrue(state().isDown(PadState.A)) + touch(MotionEvent.ACTION_UP, 1 to (800f to 240f)) + assertTrue(surface.hold(a.id, 0, false)) + assertFalse(state().isDown(PadState.A)) + } + + @Test fun aCancelledOutsideHoldDoesNotRunTheButtonsCommand() { + val surface = view.inputSurface + assertTrue(surface.hold(keyboard.id, 0, true)) + assertTrue(surface.hold(keyboard.id, 0, false, cancelled = true)) + assertEquals(emptyList(), events) + assertTrue(surface.hold(keyboard.id, 0, true)) + assertTrue(surface.hold(keyboard.id, 0, false)) + assertEquals(listOf("KEYBOARD:PRIMARY"), events) + } + @Test fun steamDeckStylingKeepsTheHeldButtonAndItsHitArea() { val button = a.copy(buttonShape = InputButtonShape.CIRCLE) show(button) diff --git a/docs/development/anti-cheat.md b/docs/development/anti-cheat.md new file mode 100644 index 0000000000..d287aea85e --- /dev/null +++ b/docs/development/anti-cheat.md @@ -0,0 +1,54 @@ +# Easy Anti-Cheat and BattlEye + +On a Steam Deck, Proton loads Valve's anti-cheat runtimes (Proton EasyAntiCheat Runtime, app 1826330, and +Proton BattlEye Runtime, app 1161040). Their bridge libraries are x86 only, so the ARM64 DroidDeck-Proton +cannot load them. Games that need them run an x86-64 DroidDeck-Proton under FEX instead. + +## Routing + +The Proton launchers (`steam-compatibility`: the built-in DroidDeck-Proton launcher and the wrapper put around +every tool in `compatibilitytools.d`) check each `run` and `waitforexitandrun` before any ARM64 setup: + +- **Condition.** The game folder (`STEAM_COMPAT_INSTALL_PATH`, three levels deep) holds one of + `EasyAntiCheat/Settings.json`, `easyanticheat_x64.so`, `BEClient_x64.so` or `BEService_x64.exe`. No + title, app ID or device list is involved. +- **Chosen tool.** Only launches through DroidDeck's own Proton (the built-in launcher or a `DroidDeck-Proton*` + folder) are moved. A game set to any other tool, such as GE-Proton, Bionic or Valve's Proton, in DroidDeck or + in Steam's Properties, runs on that tool and the launcher logs that it was chosen. +- **Tool.** The newest `compatibilitytools.d/DroidDeck-Proton*` whose layout is x86-64 + (`files/lib/wine/x86_64-unix`, no `files/bin-arm64`). +- **Runtime.** `PROTON_EAC_RUNTIME` or `PROTON_BATTLEYE_RUNTIME` when it already points at a folder with the + bridge libraries, otherwise the runtime's folder in any Steam library. +- **Launch.** `droiddeck-fex proton /proton `: FEX with the Steam Linux Runtime rootfs, + keeping the game's own `STEAM_COMPAT_DATA_PATH` prefix. + +Without the x86-64 tool or the runtime files the launch stays on ARM64 and the launcher logs why. +`DROIDDECK_ANTICHEAT=off` in the game's launch options keeps it on ARM64. Picking the x86-64 tool for a +game in Steam always runs it under FEX. + +## Why the x86-64 build needs its own Wine patches + +Android kernels use 39-bit user address spaces. Easy Anti-Cheat's launcher maps fixed memory at +`0x7001_0000_0000`, which FEX serves from emulated guest pages (`tools/fex/patches/0027`). Exclusive load and store pairs on that +memory are emulated as a compare-and-swap, so hosts without LSE atomics work too. `tools/fex/probes/guest-high-memory.c` +checks loads, stores, atomics, iovec system calls, `madvise` and code written through a high alias. The x86-64 Wine +in DroidDeck-Proton carries `ntdll-fixed-allocations-above-host-address-limit.patch` (fixed mappings above +the host limit go to the emulator) and `ntdll-keep-libc-in-native-syscall-dispatch-range.patch` (the +re-armed syscall user dispatch range keeps libc native). Stock x86-64 Proton stops after "Hack native +syscalls" on the same game. + +Easy Anti-Cheat's launcher attaches to the game with ptrace, stops it on a `rt_sigprocmask` call, runs its +own loader and restores the registers it saved at the stop. The call then returns `ENOSYS` without writing +the old mask, as it does on a desktop kernel. `ntdll-retry-blocking-signals-dropped-by-a-tracer.patch` +retries the block once when it fails, so Wine never restores an uninitialised mask that blocks `SIGSYS`. + +## The container's procfs + +Android mounts `/proc` with `hidepid=invisible,gid=3009`, and Easy Anti-Cheat refuses that mount with +launch error 261. Without root, user namespaces or PID namespaces, no procfs instance without those options +can be mounted. Every program in the container runs as the app's user and already sees all of the +container's processes, as it would in a PID-namespaced sandbox on a desktop, so FEX's emulated +`/proc//mounts` and `/proc//mountinfo` show the proc mount without `hidepid=`, `gid=` and +`subset=` (`tools/fex/patches/0029`). Only x86 programs under FEX see this view; every other line of the +table is the host's. Processes of other Android users stay hidden, as host processes do from a desktop +sandbox. diff --git a/docs/development/game-environment.md b/docs/development/game-environment.md index 6036cc3a7a..8fe41b0a61 100644 --- a/docs/development/game-environment.md +++ b/docs/development/game-environment.md @@ -117,7 +117,7 @@ the UI shows a restart reminder instead of enabling logs that would be discarded | `PROTON_LOG` | `1` | | `PROTON_LOG_DIR`, `PROTON_CRASH_REPORT_DIR`, `DXVK_LOG_PATH` | The actual session log directory | | `DXVK_LOG_LEVEL` | `debug` | -| `VKD3D_DEBUG` | `info` | +| `VKD3D_DEBUG`, `VKD3D_SHADER_DEBUG` | `warn` | | `WINEDEBUG` | Valid custom channels plus Proton's standard diagnostic channels | Diagnostics take precedence over conflicting inherited, shared, or per-game log @@ -193,6 +193,14 @@ A Unity game under FEX (`UnityPlayer.dll` for Windows builds under Proton, turns it off: without TSO such games can deadlock or crash (seen with Megabonk and Crab Game). A FEX preset chosen for the game itself still applies. +A game that ships the PlayStation PC SDK runtime installer +(`install_pspc_sdk_runtime.bat`, `PsPcSdkRuntimeInstaller.msi` or +`PsPcSdkRuntimeManager.msi`, next to the executable, one folder below, or in an +Unreal launcher's `/Binaries/Win64`) gets FEX's full x87 precision. +The SDK's obfuscated x87 code depends on full precision; with reduced precision +the game crashes or hangs at startup (FEX-Emu/FEX#4556, FEX-Emu/FEX#5988). A +FEX preset or value chosen for the game itself still applies. + An Inno Setup installer added as a game runs with the Stability preset's FEX settings (full TSO, full x87 precision, no multiblock). Under the default Performance + TSO preset the 32-bit setup stub corrupts its own paths and stops diff --git a/docs/development/x86-64-steam-client.md b/docs/development/x86-64-steam-client.md index ced25e4c70..d4d67c7687 100644 --- a/docs/development/x86-64-steam-client.md +++ b/docs/development/x86-64-steam-client.md @@ -216,9 +216,10 @@ alone would then read as an installed client. NullReferenceException, internal CLR errors). A writable mapping or mprotect now write-protects the overlapping part of any alias that is already executable, so the first write faults and invalidates. `FEX_SMCCHECKS=full` was the only workaround; no setting is needed with the patch. - - `0007-cmake-install-code-without-depends`: CMake 4.5 rejects the `DEPENDS` argument FEX passes to - `install(CODE ...)` for the guest thunk libraries, so builds with host thunks stopped at configure. - The guest libraries are external projects in the default build, which `install` already follows. + - `0007-cmake-install-code-without-depends` (`Fixed-upstream: FEX-2612`): CMake 4.5 rejects the + `DEPENDS` argument FEX passes to `install(CODE ...)` for the guest thunk libraries, so builds with + host thunks stopped at configure. The guest libraries are external projects in the default build, + which `install` already follows. - `0008-signal-return-restores-syscall-state`: a guest `rt_sigreturn` is a system call, so FEX's syscall stub marks every static register as spilled (`InSyscallInfo = 0xFFFF`). When the handler left RIP alone, the return resumed the interrupted JIT code without passing the stub's reset, and diff --git a/tools/droiddeckctl b/tools/droiddeckctl index 831f5fbf89..fd9931a9cd 100755 --- a/tools/droiddeckctl +++ b/tools/droiddeckctl @@ -108,7 +108,8 @@ def receiver_call(adb: str, serial: str, method: str, arg: str | None, request: raise ControlError(f"{PACKAGE} is not running and this shell has no `content` command to start it; open DroidDeck once", "APP_NOT_RUNNING") call_id = uuid.uuid4().hex[:16] remote = f"/sdcard/Android/data/{PACKAGE}/files/agent-calls/{call_id}.json" - command = ["shell", "am", "broadcast", "-a", f"{PACKAGE}.AGENT_CALL", "-p", PACKAGE, + # By component: release variants rename the package but not the receiver's intent action. + command = ["shell", "am", "broadcast", "-n", f"{PACKAGE}/com.droiddeck.launcher.agent.AgentCallReceiver", "--es", "method", method, "--es", "id", call_id] if arg is not None: command += ["--es", "arg", shlex.quote(arg)] diff --git a/tools/fex/build-in-arch.sh b/tools/fex/build-in-arch.sh index dccb24f882..9adc7e93e5 100755 --- a/tools/fex/build-in-arch.sh +++ b/tools/fex/build-in-arch.sh @@ -63,6 +63,11 @@ cmake -S fex-src -B fex-build -G Ninja \ ${FEX_EXTRA_CXXFLAGS:+-DCMAKE_CXX_FLAGS="$FEX_EXTRA_CXXFLAGS"} ninja -C fex-build DESTDIR="$WORK/out" ninja -C fex-build install +mkdir -p out/usr/local/share/fex-emu +for p in tools/fex/patches/*.patch; do + p=$(basename "$p" .patch) + echo "${p#*-}" +done > out/usr/local/share/fex-emu/.droiddeck-patches install -Dm755 /usr/bin/unsquashfs out/usr/local/bin/unsquashfs install -Dm644 "$(readlink -f /usr/lib/libxxhash.so.0)" out/usr/local/lib/libxxhash.so.0 bundled=$(cd out/usr/local/lib && ls -- *.so* | sort -u) diff --git a/tools/fex/patches/0007-cmake-install-code-without-depends.patch b/tools/fex/patches/0007-cmake-install-code-without-depends.patch index 6752b40280..83c0e1fb82 100644 --- a/tools/fex/patches/0007-cmake-install-code-without-depends.patch +++ b/tools/fex/patches/0007-cmake-install-code-without-depends.patch @@ -1,3 +1,4 @@ +Fixed-upstream: FEX-2612 diff --git a/CMakeLists.txt b/CMakeLists.txt index 8976588..3ae54f4 100644 --- a/CMakeLists.txt diff --git a/tools/fex/patches/0008-signal-return-restores-syscall-state.patch b/tools/fex/patches/0008-signal-return-restores-syscall-state.patch index 6592a94550..327fe76a85 100644 --- a/tools/fex/patches/0008-signal-return-restores-syscall-state.patch +++ b/tools/fex/patches/0008-signal-return-restores-syscall-state.patch @@ -1,8 +1,8 @@ diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp -index b4c7b24..643185d 100644 +index 345f4d834..085ff00a2 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp -@@ -264,12 +264,13 @@ void SignalDelegator::RestoreThreadState(FEXCore::Core::InternalThreadState* Thr +@@ -283,12 +283,13 @@ void SignalDelegator::RestoreThreadState(FEXCore::Core::InternalThreadState* Thr auto Frame = Thread->CurrentFrame; if (Context->Flags & ArchHelpers::Context::ContextFlags::CONTEXT_FLAG_INJIT) { diff --git a/tools/fex/patches/0009-signal-handler-escape-frees-host-stack.patch b/tools/fex/patches/0009-signal-handler-escape-frees-host-stack.patch index fbeec5ec96..6af2b7eb33 100644 --- a/tools/fex/patches/0009-signal-handler-escape-frees-host-stack.patch +++ b/tools/fex/patches/0009-signal-handler-escape-frees-host-stack.patch @@ -1,5 +1,5 @@ diff --git a/Source/Tools/LinuxEmulation/ArchHelpers/MContext.h b/Source/Tools/LinuxEmulation/ArchHelpers/MContext.h -index 02bb6bf..2e72492 100644 +index 02bb6bfef..2e724929f 100644 --- a/Source/Tools/LinuxEmulation/ArchHelpers/MContext.h +++ b/Source/Tools/LinuxEmulation/ArchHelpers/MContext.h @@ -49,6 +49,11 @@ struct X86ContextBackup { @@ -27,10 +27,10 @@ index 02bb6bf..2e72492 100644 // Arm64 doesn't have a red zone diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp -index 643185d..53179c4 100644 +index 085ff00a2..5c79d1092 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp -@@ -136,6 +136,31 @@ void SignalDelegator::SpillSRA(FEXCore::Core::InternalThreadState* Thread, void* +@@ -155,6 +155,31 @@ void SignalDelegator::SpillSRA(FEXCore::Core::InternalThreadState* Thread, void* #endif } @@ -62,7 +62,7 @@ index 643185d..53179c4 100644 ArchHelpers::Context::ContextBackup* SignalDelegator::StoreThreadState(FEXCore::Core::InternalThreadState* Thread, int Signal, void* ucontext) { // We can end up getting a signal at any point in our host state // Jump to a handler that saves all state so we can safely return -@@ -249,6 +274,19 @@ void SignalDelegator::RestoreThreadState(FEXCore::Core::InternalThreadState* Thr +@@ -268,6 +293,19 @@ void SignalDelegator::RestoreThreadState(FEXCore::Core::InternalThreadState* Thr } OldSP = *reinterpret_cast(GuestSP); @@ -82,7 +82,7 @@ index 643185d..53179c4 100644 } uintptr_t NewSP = OldSP; -@@ -287,6 +325,7 @@ bool SignalDelegator::HandleDispatcherGuestSignal(FEXCore::Core::InternalThreadS +@@ -306,6 +344,7 @@ bool SignalDelegator::HandleDispatcherGuestSignal(FEXCore::Core::InternalThreadS auto ContextBackup = StoreThreadState(Thread, Signal, ucontext); auto Frame = Thread->CurrentFrame; @@ -90,7 +90,7 @@ index 643185d..53179c4 100644 // Ref count our faults // We use this to track if it is safe to clear cache -@@ -336,6 +375,8 @@ bool SignalDelegator::HandleDispatcherGuestSignal(FEXCore::Core::InternalThreadS +@@ -355,6 +394,8 @@ bool SignalDelegator::HandleDispatcherGuestSignal(FEXCore::Core::InternalThreadS uint64_t OldGuestSP = Frame->State.gregs[FEXCore::X86State::REG_RSP]; uint64_t NewGuestSP = OldGuestSP; @@ -99,7 +99,7 @@ index 643185d..53179c4 100644 // altstack is only used if the signal handler was setup with SA_ONSTACK if (GuestAction->sa_flags & SA_ONSTACK) { -@@ -345,6 +386,8 @@ bool SignalDelegator::HandleDispatcherGuestSignal(FEXCore::Core::InternalThreadS +@@ -364,6 +405,8 @@ bool SignalDelegator::HandleDispatcherGuestSignal(FEXCore::Core::InternalThreadS // Then that means we are hitting recursive signals and we need to walk back the stack correctly uint64_t AltStackBase = reinterpret_cast(GuestStack->ss_sp); uint64_t AltStackEnd = AltStackBase + GuestStack->ss_size; @@ -108,7 +108,7 @@ index 643185d..53179c4 100644 if (OldGuestSP >= AltStackBase && OldGuestSP <= AltStackEnd) { // We are already in the alt stack, the rest of the code will handle adjusting this } else { -@@ -353,6 +396,40 @@ bool SignalDelegator::HandleDispatcherGuestSignal(FEXCore::Core::InternalThreadS +@@ -372,6 +415,40 @@ bool SignalDelegator::HandleDispatcherGuestSignal(FEXCore::Core::InternalThreadS } } @@ -149,7 +149,7 @@ index 643185d..53179c4 100644 // siginfo_t siginfo_t* HostSigInfo = reinterpret_cast(info); -@@ -491,6 +568,8 @@ bool SignalDelegator::HandleSignalPause(FEXCore::Core::InternalThreadState* Thre +@@ -510,6 +587,8 @@ bool SignalDelegator::HandleSignalPause(FEXCore::Core::InternalThreadState* Thre // Our ref counting doesn't matter anymore Thread->CurrentFrame->SignalHandlerRefCounter = 0; @@ -159,7 +159,7 @@ index 643185d..53179c4 100644 // Set the new PC if (CTX->IsAddressInCodeBuffer(Thread, ArchHelpers::Context::GetPc(ucontext))) { diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.h b/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.h -index dfcd4b0..e4a86a9 100644 +index 0f45cf68d..408cddf71 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.h +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.h @@ -83,6 +83,9 @@ struct ThreadStateObject : public FEXCore::Allocator::FEXAllocOperators { diff --git a/tools/fex/patches/0011-thunk-calls-mark-spilled-state.patch b/tools/fex/patches/0011-thunk-calls-mark-spilled-state.patch index 626c726b59..cebe184aa2 100644 --- a/tools/fex/patches/0011-thunk-calls-mark-spilled-state.patch +++ b/tools/fex/patches/0011-thunk-calls-mark-spilled-state.patch @@ -1,7 +1,8 @@ diff --git a/FEXCore/Source/Interface/Core/Core.cpp b/FEXCore/Source/Interface/Core/Core.cpp +index 1946dc946..9f04358c5 100644 --- a/FEXCore/Source/Interface/Core/Core.cpp +++ b/FEXCore/Source/Interface/Core/Core.cpp -@@ -383,7 +383,11 @@ +@@ -383,7 +383,11 @@ bool ContextImpl::InitCore() { } void ContextImpl::HandleCallback(FEXCore::Core::InternalThreadState* Thread, uint64_t RIP) { @@ -15,9 +16,10 @@ diff --git a/FEXCore/Source/Interface/Core/Core.cpp b/FEXCore/Source/Interface/C void ContextImpl::ExecuteThread(FEXCore::Core::InternalThreadState* Thread) { diff --git a/FEXCore/Source/Interface/Core/JIT/BranchOps.cpp b/FEXCore/Source/Interface/Core/JIT/BranchOps.cpp +index ae3ed51e4..c5e656d2c 100644 --- a/FEXCore/Source/Interface/Core/JIT/BranchOps.cpp +++ b/FEXCore/Source/Interface/Core/JIT/BranchOps.cpp -@@ -305,6 +305,9 @@ +@@ -306,6 +306,9 @@ DEF_OP(Thunk) { PushDynamicRegs(TMP1); @@ -27,7 +29,7 @@ diff --git a/FEXCore/Source/Interface/Core/JIT/BranchOps.cpp b/FEXCore/Source/In mov(ARMEmitter::Size::i64Bit, ARMEmitter::Reg::r0, GetReg(Op->ArgPtr)); InsertNamedThunkRelocation(ARMEmitter::Reg::r2, Op->ThunkNameHash); -@@ -320,6 +323,8 @@ +@@ -321,6 +324,8 @@ DEF_OP(Thunk) { FillStaticRegs({ .NZCV = false, }); @@ -37,9 +39,10 @@ diff --git a/FEXCore/Source/Interface/Core/JIT/BranchOps.cpp b/FEXCore/Source/In DEF_OP(ValidateCode) { diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp +index 5c79d1092..e8e04b056 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp -@@ -107,6 +107,10 @@ +@@ -126,6 +126,10 @@ void SignalDelegator::SpillSRA(FEXCore::Core::InternalThreadState* Thread, void* #ifdef ARCHITECTURE_arm64 Thread->CurrentFrame->State.rip = CTX->RestoreRIPFromHostPC(Thread, ArchHelpers::Context::GetPc(ucontext)); @@ -50,7 +53,7 @@ diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp b/Sou for (size_t i = 0; i < Config.SRAGPRCount; i++) { const uint8_t SRAIdxMap = Config.SRAGPRMapping[i]; if (IgnoreMask & (1U << SRAIdxMap)) { -@@ -301,12 +305,10 @@ +@@ -320,12 +324,10 @@ void SignalDelegator::RestoreThreadState(FEXCore::Core::InternalThreadState* Thr if (Context->UContextLocation) { auto Frame = Thread->CurrentFrame; @@ -67,7 +70,7 @@ diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp b/Sou if (Is64BitMode) { RestoreFrame_x64(Thread, Context, Frame, ucontext); -@@ -361,6 +363,9 @@ +@@ -380,6 +382,9 @@ bool SignalDelegator::HandleDispatcherGuestSignal(FEXCore::Core::InternalThreadS ContextBackup->InSyscallInfo = Thread->CurrentFrame->InSyscallInfo; Thread->CurrentFrame->InSyscallInfo = 0; } else { @@ -78,9 +81,10 @@ diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp b/Sou // This is likely to cause issues but in some cases it isn't fatal // This can also happen if we have put a signal on hold, then we just reenabled the signal diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator/GuestFramesManagement.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator/GuestFramesManagement.cpp +index fa6260954..e5d92e7c5 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator/GuestFramesManagement.cpp +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator/GuestFramesManagement.cpp -@@ -131,7 +131,7 @@ +@@ -131,7 +131,7 @@ void SignalDelegator::RestoreFrame_x64(FEXCore::Core::InternalThreadState* Threa if (Context->OriginalRIP != guest_uctx->uc_mcontext.gregs[FEXCore::x86_64::FEX_REG_RIP] || Context->FaultToTopAndGeneratedException) { // Restore previous `InSyscallInfo` structure. @@ -89,7 +93,7 @@ diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator/GuestFram // Hack! Go back to the top of the dispatcher top // This is only safe inside the JIT rather than anything outside of it -@@ -211,7 +211,7 @@ +@@ -211,7 +211,7 @@ void SignalDelegator::RestoreFrame_ia32(FEXCore::Core::InternalThreadState* Thre // If the guest modified the RIP then we need to take special precautions here if (Context->OriginalRIP != guest_uctx->sc.ip || Context->FaultToTopAndGeneratedException) { // Restore previous `InSyscallInfo` structure. @@ -98,7 +102,7 @@ diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator/GuestFram // Hack! Go back to the top of the dispatcher top // This is only safe inside the JIT rather than anything outside of it -@@ -290,7 +290,7 @@ +@@ -290,7 +290,7 @@ void SignalDelegator::RestoreRTFrame_ia32(FEXCore::Core::InternalThreadState* Th if (Context->OriginalRIP != guest_uctx->uc.uc_mcontext.gregs[FEXCore::x86::FEX_REG_EIP] || Context->FaultToTopAndGeneratedException) { // Restore previous `InSyscallInfo` structure. diff --git a/tools/fex/patches/0012-signal-return-applies-guest-registers.patch b/tools/fex/patches/0012-signal-return-applies-guest-registers.patch index d97a75bee3..09c8398310 100644 --- a/tools/fex/patches/0012-signal-return-applies-guest-registers.patch +++ b/tools/fex/patches/0012-signal-return-applies-guest-registers.patch @@ -1,7 +1,8 @@ diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.h b/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.h +index 9e6820bf6..43898e700 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.h +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.h -@@ -263,6 +263,8 @@ +@@ -266,6 +266,8 @@ private: FEXCore::Core::CpuStateFrame* Frame, void* ucontext); void RestoreRTFrame_ia32(FEXCore::Core::InternalThreadState* Thread, ArchHelpers::Context::ContextBackup* Context, FEXCore::Core::CpuStateFrame* Frame, void* ucontext); @@ -11,9 +12,10 @@ diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.h b/Sourc ///< Setup the signal frame for x64. uint64_t SetupFrame_x64(FEXCore::Core::InternalThreadState* Thread, ArchHelpers::Context::ContextBackup* ContextBackup, diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator/GuestFramesManagement.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator/GuestFramesManagement.cpp +index e5d92e7c5..38dc524f1 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator/GuestFramesManagement.cpp +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator/GuestFramesManagement.cpp -@@ -122,6 +122,32 @@ +@@ -122,6 +122,32 @@ static void SetXStateInfo(T* xstate, bool is_avx_enabled) { } } @@ -46,7 +48,7 @@ diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator/GuestFram void SignalDelegator::RestoreFrame_x64(FEXCore::Core::InternalThreadState* Thread, ArchHelpers::Context::ContextBackup* Context, FEXCore::Core::CpuStateFrame* Frame, void* ucontext) { auto* guest_uctx = reinterpret_cast(Context->UContextLocation); -@@ -202,6 +228,27 @@ +@@ -202,6 +228,27 @@ void SignalDelegator::RestoreFrame_x64(FEXCore::Core::InternalThreadState* Threa const auto modulo_i = (i + CurrentOffset) % 8; memcpy(&Frame->State.mm[modulo_i], &fpstate->_st[i], sizeof(Frame->State.mm[0])); } @@ -74,7 +76,7 @@ diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator/GuestFram } } -@@ -280,6 +327,17 @@ +@@ -280,6 +327,17 @@ void SignalDelegator::RestoreFrame_ia32(FEXCore::Core::InternalThreadState* Thre const auto modulo_i = (i + CurrentOffset) % 8; memcpy(&Frame->State.mm[modulo_i], &fpstate->_st[i], 10); } @@ -92,7 +94,7 @@ diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator/GuestFram } } -@@ -359,6 +417,17 @@ +@@ -359,6 +417,17 @@ void SignalDelegator::RestoreRTFrame_ia32(FEXCore::Core::InternalThreadState* Th const auto modulo_i = (i + CurrentOffset) % 8; memcpy(&Frame->State.mm[modulo_i], &fpstate->_st[i], 10); } diff --git a/tools/fex/patches/0017-fd-exec-keeps-argv0-and-path.patch b/tools/fex/patches/0017-fd-exec-keeps-argv0-and-path.patch index 2192b9b0af..9bdad1cebd 100644 --- a/tools/fex/patches/0017-fd-exec-keeps-argv0-and-path.patch +++ b/tools/fex/patches/0017-fd-exec-keeps-argv0-and-path.patch @@ -1,8 +1,8 @@ diff --git a/Source/Tools/FEXInterpreter/FEXInterpreter.cpp b/Source/Tools/FEXInterpreter/FEXInterpreter.cpp -index 2881ad9..abc84f3 100644 +index dd2c18303..e7e88f8f2 100644 --- a/Source/Tools/FEXInterpreter/FEXInterpreter.cpp +++ b/Source/Tools/FEXInterpreter/FEXInterpreter.cpp -@@ -518,7 +518,7 @@ int main(int argc, char** argv, char** const envp) { +@@ -524,7 +524,7 @@ int main(int argc, char** argv, char** const envp) { FEXCore::Config::Set(FEXCore::Config::CONFIG_APP_CONFIG_NAME, Program.ProgramName); } else { // Anonymous program. @@ -12,7 +12,7 @@ index 2881ad9..abc84f3 100644 } } else { diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls.cpp -index a7a432b..4a77d87 100644 +index a7a432bbd..4a77d8716 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls.cpp +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls.cpp @@ -441,7 +441,7 @@ uint64_t ExecveHandler(FEXCore::Core::CpuStateFrame* Frame, const char* pathname diff --git a/tools/fex/patches/0021-anticheat-ptrace-seccomp-and-proc-emulation.patch b/tools/fex/patches/0021-anticheat-ptrace-seccomp-and-proc-emulation.patch new file mode 100644 index 0000000000..b070802512 --- /dev/null +++ b/tools/fex/patches/0021-anticheat-ptrace-seccomp-and-proc-emulation.patch @@ -0,0 +1,5015 @@ +From: StonkGuy <68372320+StonkGuy@users.noreply.github.com> +Subject: [PATCH] x86-64 ptrace, seccomp and /proc emulation for anti-cheat launchers + +Author: StonkGuy (https://github.com/StonkGuy/FEX) +Source: https://github.com/StonkGuy/FEX branch eac-2611 (tag eac-2611.1) +Copyright (c) StonkGuy and FEX contributors, MIT licence + +diff --git a/FEXCore/Source/CMakeLists.txt b/FEXCore/Source/CMakeLists.txt +index 61385d2c3..b515a4a02 100644 +--- a/FEXCore/Source/CMakeLists.txt ++++ b/FEXCore/Source/CMakeLists.txt +@@ -4,6 +4,7 @@ set(FEXCORE_BASE_SRCS + Interface/Config/Config.cpp + Utils/Allocator.cpp + Utils/FileLoading.cpp ++ Utils/FaultSafeRead.cpp + Utils/FileUtils.cpp + Utils/ForcedAssert.cpp + Utils/LogManager.cpp +diff --git a/FEXCore/Source/Interface/Config/Config.json.in b/FEXCore/Source/Interface/Config/Config.json.in +index 6bd89a1e5..860bd4429 100644 +--- a/FEXCore/Source/Interface/Config/Config.json.in ++++ b/FEXCore/Source/Interface/Config/Config.json.in +@@ -604,6 +604,62 @@ + "\tfull: Validate code before every run (slow)" + ] + }, ++ "ProfileSampleHz": { ++ "Type": "uint32", ++ "Default": "0", ++ "AffectsCodeGen": "false", ++ "Desc": [ ++ "Samples the host PC of the main guest thread this many times per second into /dev/shm/fex--samples (in-process; no ptrace).", ++ "Use with LibraryJITNaming to attribute samples to guest libraries. 0 disables." ++ ] ++ }, ++ "ProfileSampleMinThreads": { ++ "Type": "uint32", ++ "Default": "100", ++ "AffectsCodeGen": "false", ++ "Desc": [ ++ "ProfileSampleHz starts the sampler in the process that reaches this many guest threads (default 100: the application,", ++ "not the hundreds of helper processes of a Steam/Wine session). 1 samples every process from its first thread.", ++ "0: no sampler thread; each SIGPROF sent from outside stores a snapshot record of the receiving thread (ring in fex--snap)." ++ ] ++ }, ++ "ProfileSampleAllThreads": { ++ "Type": "bool", ++ "Default": "false", ++ "AffectsCodeGen": "false", ++ "Desc": [ ++ "ProfileSampleHz samples every guest thread instead of only the main one." ++ ] ++ }, ++ "SignalTrace": { ++ "Type": "bool", ++ "Default": "false", ++ "AffectsCodeGen": "false", ++ "Desc": [ ++ "Records guest signal handling events (host signal arrival, masking decisions, delivery, rt_sigreturn, sigprocmask, kill/tgkill)", ++ "into a ring buffer in /dev/shm/fex--sigtrace. For diagnosing lost signals; decode with tools/harness/sigtrace.py." ++ ] ++ }, ++ "SignalMaskFix": { ++ "Type": "bool", ++ "Default": "true", ++ "AffectsCodeGen": "false", ++ "Desc": [ ++ "Run guest signal handlers with the signal mask Linux gives them (the interrupted mask plus sa_mask and the signal)", ++ "and restore the interrupted mask at rt_sigreturn. With false FEX blocks only sa_mask and the signal during the handler and keeps", ++ "a stale view of the mask afterwards, so a signal handler that restores its saved mask can unblock the signal it is running for." ++ ] ++ }, ++ "SMCHotPageFaults": { ++ "Type": "uint32", ++ "Default": "32", ++ "AffectsCodeGen": "true", ++ "Desc": [ ++ "Number of self-modifying-code write faults a guest page may take before FEX stops write-protecting it.", ++ "Instead the JIT verifies the code of every instruction it translates from such a page (like SMCChecks=full, but only for that page).", ++ "Only used with SMCChecks=mtrack. 0 disables the demotion (pages stay write-protected and keep faulting)." ++ ] ++ }, + "TSOEnabled": { + "Type": "bool", + "Default": "true", +@@ -691,6 +747,16 @@ + "Should only be used for applications that have issues with this set." + ] + }, ++ "EnableCPUIDFaulting": { ++ "Type": "bool", ++ "Default": "false", ++ "AffectsCodeGen": "false", ++ "Desc": [ ++ "Honour ARCH_SET_CPUID. When a guest thread calls arch_prctl(ARCH_SET_CPUID, 0), CPUID from that", ++ "thread raises a #GP (SIGSEGV, si_code SI_KERNEL) like Linux with a CPUID-faulting CPU, instead of", ++ "executing transparently. Off by default, so a guest that never asks for it is unaffected." ++ ] ++ }, + "StartupSleep": { + "Type": "uint32", + "Default": "0", +diff --git a/FEXCore/Source/Interface/Context/Context.h b/FEXCore/Source/Interface/Context/Context.h +index cce4d5113..24118405d 100644 +--- a/FEXCore/Source/Interface/Context/Context.h ++++ b/FEXCore/Source/Interface/Context/Context.h +@@ -224,8 +224,12 @@ public: + + void OnCodeBufferAllocated(const std::shared_ptr&) override; + void ClearCodeCache(FEXCore::Core::InternalThreadState* Thread, bool NewCodeBuffer = true) override; +- void InvalidateCodeBuffersCodeRange(uint64_t Start, uint64_t Length) override; +- void InvalidateThreadCachedCodeRange(FEXCore::Core::InternalThreadState* Thread, uint64_t Start, uint64_t Length) override; ++ void InvalidateExecutableRangeCaches() override { ++ ExecutableRangeEpoch.fetch_add(1, std::memory_order_acq_rel); ++ } ++ bool InvalidateCodeBuffersCodeRange(uint64_t Start, uint64_t Length) override; ++ std::atomic ExecutableRangeEpoch {}; ++ void InvalidateThreadCachedCodeRange(FEXCore::Core::InternalThreadState* Thread, uint64_t Start, uint64_t Length, bool CodeMayBeCached) override; + FEXCore::Utils::WritePriorityMutex::Mutex& GetCodeInvalidationMutex() override { + return CodeInvalidationMutex; + } +diff --git a/FEXCore/Source/Interface/Core/Core.cpp b/FEXCore/Source/Interface/Core/Core.cpp +index 9f04358c5..02d9a280a 100644 +--- a/FEXCore/Source/Interface/Core/Core.cpp ++++ b/FEXCore/Source/Interface/Core/Core.cpp +@@ -31,6 +31,7 @@ $end_info$ + #include "Utils/Allocator.h" + #include "Utils/Allocator/HostAllocator.h" + #include "Utils/crc32.h" ++#include + #include + #include "Utils/variable_length_integer.h" + +@@ -201,8 +202,11 @@ uint32_t ContextImpl::ReconstructCompactedEFLAGS(FEXCore::Core::InternalThreadSt + case X86State::RFLAG_SF_RAW_LOC: + case X86State::RFLAG_OF_RAW_LOC: + case X86State::RFLAG_DF_RAW_LOC: ++ case X86State::RFLAG_NZCV_LOC: ++ case X86State::RFLAG_NZCV_1_LOC: ++ case X86State::RFLAG_NZCV_2_LOC: ++ case X86State::RFLAG_NZCV_3_LOC: + // Intentionally do nothing. +- // These contain multiple bits which can corrupt other members when compacted. + break; + default: EFLAGS |= uint32_t {Frame->State.flags[i]} << i; break; + } +@@ -645,11 +649,13 @@ ContextImpl::GenerateIR(FEXCore::Core::InternalThreadState* Thread, uint64_t Gue + Thread->OpDispatcher->_GuestOpcode(InstAddress - GuestRIP); + } + +- if (Config.SMCChecks == FEXCore::Config::CONFIG_SMC_FULL || Block.ForceFullSMCDetection) { ++ if (Config.SMCChecks == FEXCore::Config::CONFIG_SMC_FULL || Block.ForceFullSMCDetection || SyscallHandler->IsSMCHotPage(InstAddress)) { + auto ExistingCodePtr = reinterpret_cast(Block.Entry + BlockInstructionsLength); + auto InstAddressReg = Thread->OpDispatcher->_EntrypointOffset(GPRSize, InstAddress - GuestRIP); + +- auto Value = FEXCore::Utils::crc32(ExistingCodePtr, DecodedInfo->InstSize); ++ uint8_t InstBytes[16]; ++ const bool Readable = FEXCore::Utils::FaultSafeRead::Copy(InstBytes, ExistingCodePtr, DecodedInfo->InstSize); ++ auto Value = Readable ? FEXCore::Utils::crc32(InstBytes, DecodedInfo->InstSize) : ~0U; + auto CRC = WantsDiskCachePatching ? + Thread->OpDispatcher->_PatchableGuestCRC(IR::OpSize::i64Bit, Value, (int64_t)ExistingCodePtr, DecodedInfo->InstSize) : + Thread->OpDispatcher->Constant(Value); +@@ -730,6 +736,8 @@ ContextImpl::GenerateIR(FEXCore::Core::InternalThreadState* Thread, uint64_t Gue + Thread->OpDispatcher->InvalidOp(DecodedInfo); + } else if (Block.BlockStatus == Frontend::Decoder::DecodedBlockStatus::UNIMPLEMENTED_INST) { + Thread->OpDispatcher->UnimplementedOp(DecodedInfo); ++ } else if (Block.BlockStatus == Frontend::Decoder::DecodedBlockStatus::TOO_LONG_INST) { ++ Thread->OpDispatcher->PermissionRestrictedOp(DecodedInfo); + } else { + Thread->OpDispatcher->NoExecOrPartialOp(DecodedInfo); + } +@@ -897,9 +905,10 @@ uintptr_t ContextImpl::CompileBlock(FEXCore::Core::CpuStateFrame* Frame, uint64_ + auto LoadedCode = Thread->CPUBackend->LoadCachedCode(Hit->HostCode); + if (LoadedCode.BlockBegin) { + for (auto& CodePage : Hit->GuestPages) { +- if (Thread->LookupCache->AddBlockExecutableRange(Thread, Hit->EntryPointRIPs, CodePage, FEXCore::Utils::FEX_PAGE_SIZE)) { ++ if (!Thread->LookupCache->HasBlockExecutableRange(CodePage)) { + SyscallHandler->MarkGuestExecutableRange(Thread, CodePage, FEXCore::Utils::FEX_PAGE_SIZE); + } ++ Thread->LookupCache->AddBlockExecutableRange(Thread, Hit->EntryPointRIPs, CodePage, FEXCore::Utils::FEX_PAGE_SIZE); + } + + LOGMAN_THROW_A_FMT(Hit->EntryPointRIPs.size() == Hit->EntryPointHostOffsets.size(), "Mismatched Disk Cache entrypoint pairs!"); +@@ -993,9 +1002,10 @@ uintptr_t ContextImpl::CompileBlock(FEXCore::Core::CpuStateFrame* Frame, uint64_ + CodePages.reserve(BlockInfo->CodePages.size()); + CodePages.insert(CodePages.end(), BlockInfo->CodePages.begin(), BlockInfo->CodePages.end()); + for (auto CodePage : BlockInfo->CodePages) { +- if (Thread->LookupCache->AddBlockExecutableRange(Thread, BlockInfo->EntryPoints, CodePage, FEXCore::Utils::FEX_PAGE_SIZE)) { ++ if (!Thread->LookupCache->HasBlockExecutableRange(CodePage)) { + SyscallHandler->MarkGuestExecutableRange(Thread, CodePage, FEXCore::Utils::FEX_PAGE_SIZE); + } ++ Thread->LookupCache->AddBlockExecutableRange(Thread, BlockInfo->EntryPoints, CodePage, FEXCore::Utils::FEX_PAGE_SIZE); + } + } + +@@ -1006,10 +1016,13 @@ uintptr_t ContextImpl::CompileBlock(FEXCore::Core::CpuStateFrame* Frame, uint64_ + if (DebugData && DebugData->Relocations) { + Relocations = *DebugData->Relocations; + } +- std::span GuestCode = {reinterpret_cast(StartAddr), Length}; +- const Frontend::Decoder::DecodedBlockInformation* BlockInfo = +- NeedsAddGuestCodeRanges ? Thread->FrontendDecoder->GetDecodedBlockInfo() : nullptr; +- DiskCache.Store(Thread, Region, GuestRIP, *DiskCacheGuestCodeKey, GuestCode, CompiledCode, Relocations, BlockInfo); ++ fextl::vector GuestCodeCopy(Length); ++ if (FEXCore::Utils::FaultSafeRead::Copy(GuestCodeCopy.data(), reinterpret_cast(StartAddr), Length)) { ++ std::span GuestCode = GuestCodeCopy; ++ const Frontend::Decoder::DecodedBlockInformation* BlockInfo = ++ NeedsAddGuestCodeRanges ? Thread->FrontendDecoder->GetDecodedBlockInfo() : nullptr; ++ DiskCache.Store(Thread, Region, GuestRIP, *DiskCacheGuestCodeKey, GuestCode, CompiledCode, Relocations, BlockInfo); ++ } + } + + if (CodeMapWriter && Region && Region->FileStartVA != 0) { +@@ -1055,31 +1068,38 @@ uintptr_t ContextImpl::CompileSingleStep(FEXCore::Core::CpuStateFrame* Frame, ui + return (uintptr_t)CodePtr; + } + +-void ContextImpl::InvalidateCodeBuffersCodeRange(uint64_t Start, uint64_t Length) { ++bool ContextImpl::InvalidateCodeBuffersCodeRange(uint64_t Start, uint64_t Length) { + FEXCORE_PROFILE_SCOPED("InvalidateCodeBuffersCodeRange"); + + LOGMAN_THROW_A_FMT(CodeInvalidationMutex.try_lock() == false, "CodeInvalidationMutex needs to be unique_locked here"); + std::scoped_lock lk {CodeBufferListLock}; ++ bool Found = false; + auto it = CodeBufferList.begin(); + while (it != CodeBufferList.end()) { + if (auto Strong = it->lock()) { +- Strong->LookupCache->InvalidateRange(Start, Length); ++ Found |= Strong->LookupCache->InvalidateRange(Start, Length); + it++; + } else { + it = CodeBufferList.erase(it); + } + } ++ return Found; + } + +-void ContextImpl::InvalidateThreadCachedCodeRange(FEXCore::Core::InternalThreadState* Thread, uint64_t Start, uint64_t Length) { ++void ContextImpl::InvalidateThreadCachedCodeRange(FEXCore::Core::InternalThreadState* Thread, uint64_t Start, uint64_t Length, bool CodeMayBeCached) { + LOGMAN_THROW_A_FMT(CodeInvalidationMutex.try_lock() == false, "CodeInvalidationMutex needs to be unique_locked here"); + + // Ensures now-modified mappings aren't cached as being in their previous non-executable state. + // Accessing FrontendDecoder is safe as the thread's code invalidation mutex must be locked here. + Thread->FrontendDecoder->ResetExecutableRangeCache(); + ++ if (!CodeMayBeCached) { ++ return; ++ } ++ + if (Thread->LookupCache->InvalidateCacheRange(Start, Length)) { + FEXCORE_PROFILE_SCOPED("InvalidateCallRet"); ++ FEXCORE_PROFILE_INSTANT_INCREMENT(Thread, AccumulatedCallRetFlushCount, 1); + + // This may cause access violations in the thread on Windows as zeroing is not atomic, this is handled by the frontend + Allocator::VirtualDontNeed(Thread->CallRetStackBase, FEXCore::Core::InternalThreadState::CALLRET_STACK_SIZE); +diff --git a/FEXCore/Source/Interface/Core/DiskCache.cpp b/FEXCore/Source/Interface/Core/DiskCache.cpp +index 3c78b22da..d903216c1 100644 +--- a/FEXCore/Source/Interface/Core/DiskCache.cpp ++++ b/FEXCore/Source/Interface/Core/DiskCache.cpp +@@ -11,6 +11,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -22,6 +23,23 @@ + #include + #include + ++namespace { ++template ++bool HashGuestMemory(UpdateFn&& Update, uint64_t Address, uint64_t Size) { ++ uint8_t Buffer[256]; ++ while (Size) { ++ const uint64_t Chunk = std::min(Size, sizeof(Buffer)); ++ if (!FEXCore::Utils::FaultSafeRead::Copy(Buffer, reinterpret_cast(Address), Chunk)) { ++ return false; ++ } ++ Update(Buffer, Chunk); ++ Address += Chunk; ++ Size -= Chunk; ++ } ++ return true; ++} ++} ++ + namespace FEXCore { + + namespace DiskCache { +@@ -576,12 +594,18 @@ namespace DiskCache { + } + uint64_t HashStart = SubBlock.Entry; + // skip over masked in-block data and data/etc gaps between blocks ++ auto Update = [&](const uint8_t* Bytes, uint64_t Size) { ++ XXH3_64bits_update(&HashState, Bytes, Size); ++ }; + for (auto& DataMask : SubBlock.DataMasks) { +- XXH3_64bits_update(&HashState, reinterpret_cast(HashStart), DataMask.FieldAddress - HashStart); ++ if (!HashGuestMemory(Update, HashStart, DataMask.FieldAddress - HashStart)) { ++ return std::nullopt; ++ } + HashStart = DataMask.FieldAddress + DataMask.ValueSize; + } +- if (HashStart != SubBlock.Entry + SubBlock.Size) { +- XXH3_64bits_update(&HashState, reinterpret_cast(HashStart), SubBlock.Size - (HashStart - SubBlock.Entry)); ++ if (HashStart != SubBlock.Entry + SubBlock.Size && ++ !HashGuestMemory(Update, HashStart, SubBlock.Size - (HashStart - SubBlock.Entry))) { ++ return std::nullopt; + } + } + GuestCodeKey = XXH3_64bits_digest(&HashState); +@@ -704,8 +728,13 @@ namespace DiskCache { + if (FirstHash || LastFootprintHashed != CurrentFootprint) { + XXH3_state_t HashState; + XXH3_128bits_reset(&HashState); ++ auto Update = [&](const uint8_t* Bytes, uint64_t Size) { ++ XXH3_128bits_update(&HashState, Bytes, Size); ++ }; + for (uint32_t i = 0; i < Entry.GuestExtents.size(); i += 2) { +- XXH3_128bits_update(&HashState, reinterpret_cast(GuestRIP) + Entry.GuestExtents[i], Entry.GuestExtents[i + 1]); ++ if (!HashGuestMemory(Update, GuestRIP + Entry.GuestExtents[i], Entry.GuestExtents[i + 1])) { ++ return std::nullopt; ++ } + } + LiveGuestHash = XXH3_128bits_digest(&HashState); + LastFootprintHashed = CurrentFootprint; +diff --git a/FEXCore/Source/Interface/Core/DiskCache.h b/FEXCore/Source/Interface/Core/DiskCache.h +index 0bd3c21e4..0f1490cba 100644 +--- a/FEXCore/Source/Interface/Core/DiskCache.h ++++ b/FEXCore/Source/Interface/Core/DiskCache.h +@@ -249,7 +249,7 @@ namespace DiskCache { + // The current version of the diskcache. + // This must be changed any time codegen changes occur! + // Be aware of the impact of changing this frequently! +- static constexpr uint16_t FormatVersion = 52; ++ static constexpr uint16_t FormatVersion = 0x8000 | (1 << 8) | 52; + + static constexpr uint32_t LOOKUP_KEY_MAX_BUCKET_DEPTH = 500; + +diff --git a/FEXCore/Source/Interface/Core/Frontend.cpp b/FEXCore/Source/Interface/Core/Frontend.cpp +index 94e4ac522..18cda8889 100644 +--- a/FEXCore/Source/Interface/Core/Frontend.cpp ++++ b/FEXCore/Source/Interface/Core/Frontend.cpp +@@ -19,6 +19,7 @@ $end_info$ + #include + #include + #include ++#include + #include + #include + #include +@@ -108,6 +109,11 @@ int32_t Decoder::CheckRangeExecutable(uint64_t Address, uint64_t Size) { + } + } + ++ if (const auto Epoch = CTX->ExecutableRangeEpoch.load(std::memory_order_acquire); Epoch != ExecutableRangeEpochSeen) { ++ ExecutableRangeEpochSeen = Epoch; ++ ResetExecutableRangeCache(); ++ } ++ + uint64_t RemainingSize = Size; + while (Address < ExecutableRangeBase || Address + RemainingSize > ExecutableRangeEnd) { + auto RangeInfo = CTX->SyscallHandler->QueryGuestExecutableRange(Thread, Address); +@@ -132,8 +138,13 @@ int32_t Decoder::CheckRangeExecutable(uint64_t Address, uint64_t Size) { + } + + uint8_t Decoder::ReadByte() { ++ if (InstructionSize >= MAX_INST_SIZE) { ++ HitInstructionLengthLimit = true; ++ return 0; ++ } ++ + std::optional Byte = PeekByte(0); +- if (!Byte || InstructionSize == MAX_INST_SIZE) { ++ if (!Byte) { + HitNonExecutableRange = true; + // Pretend we read 0, the main decode loop will see HitNonExecutableRange and rollback the instruction. + return 0; +@@ -146,8 +157,10 @@ uint8_t Decoder::ReadByte() { + + std::optional Decoder::PeekByte(uint8_t Offset) { + uint64_t ByteAddress = reinterpret_cast(InstStream.InstStream + InstructionSize + Offset); +- if (CheckRangeExecutable(ByteAddress, 1) == 1) { +- return InstStream.AdjustedInstStream[InstructionSize + Offset]; ++ uint8_t Byte; ++ if (CheckRangeExecutable(ByteAddress, 1) == 1 && ++ FEXCore::Utils::FaultSafeRead::Copy(&Byte, &InstStream.AdjustedInstStream[InstructionSize + Offset], 1)) { ++ return Byte; + } else { + return std::nullopt; + } +@@ -160,13 +173,24 @@ std::pair Decoder::ReadData(uint8_t Size) { + uint64_t Address = reinterpret_cast(InstStream.InstStream + InstructionSize); + LastFieldReadOffset = (uint8_t)InstructionSize; + LastFieldReadSize = Size; +- auto ReadableSize = CheckRangeExecutable(Address, Size); +- if (ReadableSize == Size) { +- std::memcpy(&Res, &InstStream.AdjustedInstStream[InstructionSize], Size); +- } else { +- HitNonExecutableRange = true; +- // See PeekByte, this specific case may cause some executable memory to read as 0 but it doesn't matter as the entire instruction will be rolled back anyway. ++ int32_t ReadableSize {}; ++ if (InstructionSize + Size > MAX_INST_SIZE) [[unlikely]] { ++ const int32_t FetchableSize = InstructionSize < MAX_INST_SIZE ? MAX_INST_SIZE - InstructionSize : 0; ++ ReadableSize = FetchableSize ? CheckRangeExecutable(Address, FetchableSize) : 0; ++ if (ReadableSize != FetchableSize) { ++ HitNonExecutableRange = true; ++ } ++ HitInstructionLengthLimit = true; + Res = 0; ++ } else { ++ ReadableSize = CheckRangeExecutable(Address, Size); ++ if (ReadableSize == Size && !FEXCore::Utils::FaultSafeRead::Copy(&Res, &InstStream.AdjustedInstStream[InstructionSize], Size)) { ++ ReadableSize = 0; ++ } ++ if (ReadableSize != Size) { ++ HitNonExecutableRange = true; ++ Res = 0; ++ } + } + + // Skip the number of decoded bytes regardless to get instruction size. +@@ -881,7 +905,7 @@ Decoder::DecodedBlockStatus Decoder::DecodeInstructionImpl(uint64_t PC) { + + for (;;) { + if (InstructionSize >= MAX_INST_SIZE) { +- return DecodedBlockStatus::INVALID_INST; ++ return DecodedBlockStatus::TOO_LONG_INST; + } + uint8_t Op = ReadByte(); + switch (Op) { +@@ -1108,11 +1132,12 @@ void Decoder::DecodeREXIfValid(int8_t ExpectedOffset) { + Decoder::DecodedBlockStatus Decoder::DecodeInstruction(uint64_t PC) { + // Will be set if DecodeInstructionImpl tries to read non-executable memory + HitNonExecutableRange = false; ++ HitInstructionLengthLimit = false; + HitBadRelocation = false; + HitBreakpoint = ~0U; + auto ErrorDuringDecoding = DecodeInstructionImpl(PC); + +- if (ErrorDuringDecoding != DecodedBlockStatus::SUCCESS || HitNonExecutableRange || HitBadRelocation) [[unlikely]] { ++ if (ErrorDuringDecoding != DecodedBlockStatus::SUCCESS || HitNonExecutableRange || HitInstructionLengthLimit || HitBadRelocation) [[unlikely]] { + // Put an invalid instruction in the stream so the core can raise SIGILL if hit + // Error while decoding instruction. We don't know the table or instruction size + DecodeInst->TableInfo = nullptr; +@@ -1134,6 +1159,10 @@ Decoder::DecodedBlockStatus Decoder::DecodeInstruction(uint64_t PC) { + return DecodedBlockStatus::BAD_RELOCATION; + } + ++ if (HitInstructionLengthLimit) { ++ return DecodedBlockStatus::TOO_LONG_INST; ++ } ++ + return ErrorDuringDecoding; + } else if (!DecodeInst->TableInfo || (DecodeInst->TableInfo->Type == TYPE_INST && !DecodeInst->TableInfo->OpcodeDispatcher.OpDispatch)) { + // If there wasn't an error during decoding but we have no dispatcher for the instruction then claim invalid instruction. +@@ -1693,6 +1722,7 @@ void Decoder::DecodeLoop(const uint8_t* _InstStream, uint64_t GuestSizePause) { + BlockIt->BlockStatus == DecodedBlockStatus::BREAKPOINT_3 ? "Breakpoint" : + BlockIt->BlockStatus == DecodedBlockStatus::INVALID_INST ? "Invalid" : + BlockIt->BlockStatus == DecodedBlockStatus::NOEXEC_INST ? "NoExec" : ++ BlockIt->BlockStatus == DecodedBlockStatus::TOO_LONG_INST ? "TooLong" : + BlockIt->BlockStatus == DecodedBlockStatus::BAD_RELOCATION ? "BadRelocation" : + BlockIt->BlockStatus == DecodedBlockStatus::UNIMPLEMENTED_INST ? "Unimplemented" : + "PartialDecode", +diff --git a/FEXCore/Source/Interface/Core/Frontend.h b/FEXCore/Source/Interface/Core/Frontend.h +index ade14bc44..6d279b22c 100644 +--- a/FEXCore/Source/Interface/Core/Frontend.h ++++ b/FEXCore/Source/Interface/Core/Frontend.h +@@ -28,6 +28,7 @@ public: + INVALID_INST, + NOEXEC_INST, + PARTIAL_DECODE_INST, ++ TOO_LONG_INST, + BAD_RELOCATION, + UNIMPLEMENTED_INST, + BREAKPOINT_0, +@@ -93,6 +94,8 @@ public: + ExecutableRangeBase = ExecutableRangeEnd = 0; + } + ++ uint64_t ExecutableRangeEpochSeen {}; ++ + private: + // To pass any information from instruction prefixes + // down into the actual instruction handling machinery. +@@ -159,6 +162,7 @@ private: + uint64_t ExecutableRangeEnd {}; + bool ExecutableRangeWritable {}; + bool HitNonExecutableRange {}; ++ bool HitInstructionLengthLimit {}; + bool HitBadRelocation {}; + uint32_t HitBreakpoint {~0U}; + +diff --git a/FEXCore/Source/Interface/Core/JIT/BranchOps.cpp b/FEXCore/Source/Interface/Core/JIT/BranchOps.cpp +index c5e656d2c..7b9c15b61 100644 +--- a/FEXCore/Source/Interface/Core/JIT/BranchOps.cpp ++++ b/FEXCore/Source/Interface/Core/JIT/BranchOps.cpp +@@ -195,6 +195,21 @@ DEF_OP(ExitFunction) { + ARMEmitter::ForwardLabel SkipFullLookup; + auto RipReg = GetReg(Op->NewRIP); + ++ if (Op->Hint == IR::BranchHint::CheckTF || CompilingWithTF) { ++ ARMEmitter::ForwardLabel TFUnset; ++ ldrb(TMP1, STATE_PTR(CpuStateFrame, State.flags[X86State::RFLAG_TF_RAW_LOC])); ++ (void)cbz(ARMEmitter::Size::i32Bit, TMP1, &TFUnset); ++ if (Op->Hint == IR::BranchHint::Return) { ++ add(ARMEmitter::Size::i64Bit, REG_CALLRET_SP, REG_CALLRET_SP, 0x10); ++ } else if (Op->Hint == IR::BranchHint::Call) { ++ stp(ARMEmitter::XReg::zr, ARMEmitter::XReg::zr, REG_CALLRET_SP, -0x10); ++ } ++ str(RipReg.X(), STATE, offsetof(FEXCore::Core::CpuStateFrame, State.rip)); ++ ldr(TMP2, STATE, offsetof(FEXCore::Core::CpuStateFrame, Pointers.DispatcherLoopTop)); ++ br(TMP2); ++ (void)Bind(&TFUnset); ++ } ++ + if (Op->Hint == IR::BranchHint::Return) { + // First try to pop from the call-ret stack, otherwise follow the normal path (but ending in a ret) + ldp(TMP1, TMP2, REG_CALLRET_SP, 0x10); +diff --git a/FEXCore/Source/Interface/Core/JIT/JIT.cpp b/FEXCore/Source/Interface/Core/JIT/JIT.cpp +index fa9c8c880..777b4b51d 100644 +--- a/FEXCore/Source/Interface/Core/JIT/JIT.cpp ++++ b/FEXCore/Source/Interface/Core/JIT/JIT.cpp +@@ -862,6 +862,7 @@ CPUBackend::CompiledCode Arm64JITCore::EmitJITCode(uint64_t Entry, uint64_t Size + this->DebugData = DebugData; + this->IR = IR; + RequiresFarARM64Jumps = false; ++ CompilingWithTF = CheckTF; + SSANodeMultiplier = 24; + + // Prepare restart via long jump in case branch encoding fails. +diff --git a/FEXCore/Source/Interface/Core/JIT/JITClass.h b/FEXCore/Source/Interface/Core/JIT/JITClass.h +index 55286855f..684ac9d9d 100644 +--- a/FEXCore/Source/Interface/Core/JIT/JITClass.h ++++ b/FEXCore/Source/Interface/Core/JIT/JITClass.h +@@ -86,6 +86,7 @@ private: + // In the rare case when those assumptions are broken, FEX needs to safely restart the JIT. + RestartOptions RestartControl {}; + bool RequiresFarARM64Jumps {}; ++ bool CompilingWithTF {}; + // Default to 6 instructions per SSA node. + uint32_t SSANodeMultiplier {24}; + +diff --git a/FEXCore/Source/Interface/Core/JIT/MiscOps.cpp b/FEXCore/Source/Interface/Core/JIT/MiscOps.cpp +index d15ef9aee..bc1fb9c19 100644 +--- a/FEXCore/Source/Interface/Core/JIT/MiscOps.cpp ++++ b/FEXCore/Source/Interface/Core/JIT/MiscOps.cpp +@@ -86,6 +86,34 @@ DEF_OP(Break) { + br(TMP1); + } + ++DEF_OP(BreakErrorCode) { ++ auto Op = IROp->C(); ++ ++ uxth(ARMEmitter::Size::i64Bit, TMP2, GetReg(Op->ErrorCode)); ++ ResetStack(); ++ ++ Core::CpuStateFrame::SynchronousFaultDataStruct State = { ++ .FaultToTopAndGeneratedException = 1, ++ .Signal = Op->Reason.Signal, ++ .TrapNo = Op->Reason.TrapNumber, ++ .si_code = Op->Reason.si_code, ++ .err_code = 0, ++ .FaultAddress = 0, ++ }; ++ static_assert(offsetof(Core::CpuStateFrame::SynchronousFaultDataStruct, err_code) == 4, "err_code is bits 32-47"); ++ ++ uint64_t Constant {}; ++ memcpy(&Constant, &State, sizeof(uint64_t)); ++ ++ LoadConstant(ARMEmitter::Size::i64Bit, TMP1, static_cast(Constant)); ++ bfi(ARMEmitter::Size::i64Bit, TMP1, TMP2, 32, 16); ++ str(TMP1, STATE, offsetof(FEXCore::Core::CpuStateFrame, SynchronousFaultData)); ++ str(ARMEmitter::XReg::zr, STATE, offsetof(FEXCore::Core::CpuStateFrame, SynchronousFaultData) + 8); ++ ++ ldr(TMP1, STATE, offsetof(FEXCore::Core::CpuStateFrame, Pointers.GuestSignal_SynchronousFault)); ++ br(TMP1); ++} ++ + DEF_OP(GetRoundingMode) { + auto Dst = GetReg(Node); + mrs(Dst, ARMEmitter::SystemRegister::FPCR); +diff --git a/FEXCore/Source/Interface/Core/LookupCache.h b/FEXCore/Source/Interface/Core/LookupCache.h +index 391d48560..228d03969 100644 +--- a/FEXCore/Source/Interface/Core/LookupCache.h ++++ b/FEXCore/Source/Interface/Core/LookupCache.h +@@ -125,7 +125,7 @@ struct GuestToHostMap { + return BlockList.erase(Address) != 0; + } + +- void InvalidateRange(uint64_t Start, uint64_t Length) { ++ bool InvalidateRange(uint64_t Start, uint64_t Length) { + auto lk = AcquireWriteLock(); + + auto lower = CodePages.lower_bound(Start >> 12); +@@ -136,7 +136,9 @@ struct GuestToHostMap { + Erase(Entry, lk); + } + } ++ const bool Found = lower != upper; + CodePages.erase(lower, upper); ++ return Found; + } + + void AddBlockLink(uint64_t GuestDestination, FEXCore::Context::ExitFunctionLinkData* HostLink, +@@ -144,6 +146,11 @@ struct GuestToHostMap { + BlockLinks->insert({{GuestDestination, HostLink}, delinker}); + } + ++ bool HasBlockExecutableRange(uint64_t Page, const LookupCacheReadLockToken&) const { ++ auto it = CodePages.find(Page >> 12); ++ return it != CodePages.end() && !it->second.empty(); ++ } ++ + bool AddBlockExecutableRange(const std::ranges::input_range auto& Addresses, uint64_t Start, uint64_t Length, const LookupCacheWriteLockToken&) { + bool rv = false; + +@@ -282,6 +289,11 @@ public: + + GuestToHostMap* Shared = nullptr; + ++ bool HasBlockExecutableRange(uint64_t Page) { ++ auto lk = Shared->AcquireReadLock(); ++ return Shared->HasBlockExecutableRange(Page, lk); ++ } ++ + // Appends a list of Block {Address} to CodePages [Start, Start + Length) + // Returns true if new pages are marked as containing code + bool AddBlockExecutableRange(FEXCore::Core::InternalThreadState* Thread, auto& Addresses, uint64_t Start, uint64_t Length) { +diff --git a/FEXCore/Source/Interface/Core/OpcodeDispatcher.cpp b/FEXCore/Source/Interface/Core/OpcodeDispatcher.cpp +index 356fc3bb1..27491cea4 100644 +--- a/FEXCore/Source/Interface/Core/OpcodeDispatcher.cpp ++++ b/FEXCore/Source/Interface/Core/OpcodeDispatcher.cpp +@@ -138,6 +138,31 @@ void OpDispatchBuilder::IRETOp(OpcodeArgs) { + + const auto GPRSize = GetGPROpSize(); + ++ { ++ auto FaultBlock = CreateNewCodeBlockAfter(GetCurrentBlock()); ++ auto ContinueBlock = CreateNewCodeBlockAfter(FaultBlock); ++ ++ auto CondJump_ = CondJump(GetRFLAG(FEXCore::X86State::RFLAG_NT_LOC), CondClass::EQ); ++ SetTrueJumpTarget(CondJump_, ContinueBlock); ++ SetFalseJumpTarget(CondJump_, FaultBlock); ++ ++ SetCurrentCodeBlock(FaultBlock); ++ StartNewBlock(); ++ ++ _StoreContextGPR(GPRSize, GetRelocatedPC(Op, -Op->InstSize), offsetof(FEXCore::Core::CPUState, rip)); ++ ++ IR::BreakDefinition Reason {}; ++ Reason.ErrorRegister = 0; ++ Reason.Signal = Core::FAULT_SIGSEGV; ++ Reason.TrapNumber = X86State::X86_TRAPNO_GP; ++ Reason.si_code = 0x80; ++ BlockSetRIP = true; ++ Break(Reason); ++ ++ SetCurrentCodeBlock(ContinueBlock); ++ StartNewBlock(); ++ } ++ + Ref SP = _RMWHandle(LoadGPRRegister(X86State::REG_RSP)); + + // RIP (64/32/16 bits) +@@ -164,7 +189,7 @@ void OpDispatchBuilder::IRETOp(OpcodeArgs) { + StoreGPRRegister(X86State::REG_RSP, SP); + } + +- ExitFunction(NewRIP); ++ ExitFunction(NewRIP, BranchHint::CheckTF); + BlockSetRIP = true; + } + +@@ -1230,6 +1255,36 @@ void OpDispatchBuilder::FLAGControlOp(OpcodeArgs) { + } + + ++void OpDispatchBuilder::MOVSegFSGS64(OpcodeArgs, Ref Selector, uint32_t IndexOffset, uint32_t BaseOffset) { ++ Ref Index = _Bfe(OpSize::i32Bit, 13, 3, Selector); ++ Ref TI = _Bfe(OpSize::i32Bit, 1, 2, Selector); ++ Ref Allowed = _And(OpSize::i32Bit, _Lshr(OpSize::i32Bit, Constant(0x8071), Index), Constant(1)); ++ Allowed = _Select(OpSize::i32Bit, OpSize::i32Bit, CondClass::ULT, Index, Constant(16), Allowed, Constant(0)); ++ Allowed = _Select(OpSize::i32Bit, OpSize::i32Bit, CondClass::EQ, TI, Constant(0), Allowed, Constant(0)); ++ ++ auto FaultBlock = CreateNewCodeBlockAfter(GetCurrentBlock()); ++ auto ContinueBlock = CreateNewCodeBlockAfter(FaultBlock); ++ auto CondJump_ = CondJump(Allowed, CondClass::NEQ); ++ SetTrueJumpTarget(CondJump_, ContinueBlock); ++ SetFalseJumpTarget(CondJump_, FaultBlock); ++ ++ SetCurrentCodeBlock(FaultBlock); ++ StartNewBlock(); ++ Ref FaultSelector = LoadSourceGPR_WithOpSize(Op, Op->Src[0], OpSize::i16Bit, Op->Flags); ++ _StoreContextGPR(GetGPROpSize(), GetRelocatedPC(Op, -Op->InstSize), offsetof(FEXCore::Core::CPUState, rip)); ++ IR::BreakDefinition Reason {}; ++ Reason.Signal = Core::FAULT_SIGSEGV; ++ Reason.TrapNumber = X86State::X86_TRAPNO_GP; ++ Reason.si_code = 0x80; ++ BlockSetRIP = true; ++ BreakErrorCode(_And(OpSize::i32Bit, FaultSelector, Constant(0xfffc)), Reason); ++ ++ SetCurrentCodeBlock(ContinueBlock); ++ StartNewBlock(); ++ _StoreContextGPR(OpSize::i16Bit, LoadSourceGPR_WithOpSize(Op, Op->Src[0], OpSize::i16Bit, Op->Flags), IndexOffset); ++ _StoreContextGPR(OpSize::i64Bit, Constant(0), BaseOffset); ++} ++ + void OpDispatchBuilder::MOVSegOp(OpcodeArgs, bool ToSeg) { + // In x86-64 mode the accesses to the segment registers end up being constant zero moves + // Aside from FS/GS +@@ -1243,7 +1298,6 @@ void OpDispatchBuilder::MOVSegOp(OpcodeArgs, bool ToSeg) { + // selected for the registers + // This statement is actually untrue, the instructions will /actually/ load 16bits in to the selector portion of the register! + // Tested on a Zen+ CPU, the selector is the portion that is modified! +- // We don't currently support FS/GS selector modifying, so this needs to be asserted out + // The loads here also load the selector, NOT the base + + if (ToSeg) { +@@ -1283,8 +1337,7 @@ void OpDispatchBuilder::MOVSegOp(OpcodeArgs, bool ToSeg) { + _StoreContextGPR(OpSize::i16Bit, Src, offsetof(FEXCore::Core::CPUState, gs_idx)); + UpdatePrefixFromSegment(Src, FEXCore::X86Tables::DecodeFlags::FLAG_GS_PREFIX); + } else { +- LogMan::Msg::EFmt("We don't support modifying GS selector in 64bit mode!"); +- DecodeFailure = true; ++ MOVSegFSGS64(Op, Src, offsetof(FEXCore::Core::CPUState, gs_idx), offsetof(FEXCore::Core::CPUState, gs_cached)); + } + break; + case FEXCore::X86State::REG_RSP: // FS +@@ -1293,8 +1346,7 @@ void OpDispatchBuilder::MOVSegOp(OpcodeArgs, bool ToSeg) { + _StoreContextGPR(OpSize::i16Bit, Src, offsetof(FEXCore::Core::CPUState, fs_idx)); + UpdatePrefixFromSegment(Src, FEXCore::X86Tables::DecodeFlags::FLAG_FS_PREFIX); + } else { +- LogMan::Msg::EFmt("We don't support modifying FS selector in 64bit mode!"); +- DecodeFailure = true; ++ MOVSegFSGS64(Op, Src, offsetof(FEXCore::Core::CPUState, fs_idx), offsetof(FEXCore::Core::CPUState, fs_cached)); + } + break; + default: UnimplementedOp(Op); return; +@@ -1321,19 +1373,11 @@ void OpDispatchBuilder::MOVSegOp(OpcodeArgs, bool ToSeg) { + break; + case FEXCore::X86State::REG_RBP: // GS + case FEXCore::X86State::REG_R13: // GS +- if (Is64BitMode) { +- Segment = Constant(0); +- } else { +- Segment = _LoadContextGPR(OpSize::i16Bit, offsetof(FEXCore::Core::CPUState, gs_idx)); +- } ++ Segment = _LoadContextGPR(OpSize::i16Bit, offsetof(FEXCore::Core::CPUState, gs_idx)); + break; + case FEXCore::X86State::REG_RSP: // FS + case FEXCore::X86State::REG_R12: // FS +- if (Is64BitMode) { +- Segment = Constant(0); +- } else { +- Segment = _LoadContextGPR(OpSize::i16Bit, offsetof(FEXCore::Core::CPUState, fs_idx)); +- } ++ Segment = _LoadContextGPR(OpSize::i16Bit, offsetof(FEXCore::Core::CPUState, fs_idx)); + break; + default: UnimplementedOp(Op); return; + } +diff --git a/FEXCore/Source/Interface/Core/OpcodeDispatcher.h b/FEXCore/Source/Interface/Core/OpcodeDispatcher.h +index d3e523d9b..601db6009 100644 +--- a/FEXCore/Source/Interface/Core/OpcodeDispatcher.h ++++ b/FEXCore/Source/Interface/Core/OpcodeDispatcher.h +@@ -216,6 +216,10 @@ public: + } + return _Break(Reason, RelocatedPC); + } ++ IRPair BreakErrorCode(Ref ErrorCode, BreakDefinition Reason) { ++ FlushRegisterCache(); ++ return _BreakErrorCode(ErrorCode, Reason); ++ } + IRPair Thunk(Ref ArgPtr, SHA256Sum ThunkNameHash) { + FlushRegisterCache(); + return _Thunk(ArgPtr, ThunkNameHash); +@@ -417,6 +421,7 @@ public: + void XCHGRAXOp(OpcodeArgs); + void SAHFOp(OpcodeArgs); + void LAHFOp(OpcodeArgs); ++ void MOVSegFSGS64(OpcodeArgs, Ref Selector, uint32_t IndexOffset, uint32_t BaseOffset); + void MOVSegOp(OpcodeArgs, bool ToSeg); + void FLAGControlOp(OpcodeArgs); + void MOVOffsetOp(OpcodeArgs); +@@ -1974,8 +1979,8 @@ private: + // An exception should still be raised after an instruction that unsets TF, leave the unblocked bit set but unset + // the TF bit to cause such behaviour. The handling code at the start of the next block will then unset the + // unblocked bit before raising the exception. +- auto NewPackedTF = +- _Select(OpSize::i64Bit, OpSize::i64Bit, CondClass::EQ, Value, Constant(0), _And(OpSize::i32Bit, PackedTF, Constant(~1)), Constant(1)); ++ auto NewPackedTF = _Select(OpSize::i64Bit, OpSize::i64Bit, CondClass::EQ, Value, Constant(0), _And(OpSize::i32Bit, PackedTF, Constant(~1)), ++ _Select(OpSize::i64Bit, OpSize::i64Bit, CondClass::EQ, PackedTF, Constant(3), Constant(3), Constant(1))); + _StoreContextGPR(OpSize::i8Bit, NewPackedTF, ARRAY_OFFSETOF(FEXCore::Core::CPUState, flags, BitOffset)); + } else { + _StoreContextGPR(OpSize::i8Bit, Value, ARRAY_OFFSETOF(FEXCore::Core::CPUState, flags, BitOffset)); +diff --git a/FEXCore/Source/Interface/IR/IR.json b/FEXCore/Source/Interface/IR/IR.json +index 4b79cf35c..0c01f580d 100644 +--- a/FEXCore/Source/Interface/IR/IR.json ++++ b/FEXCore/Source/Interface/IR/IR.json +@@ -324,6 +324,12 @@ + "Break BreakDefinition:$Reason, GPR:$FaultAddress": { + "HasSideEffects": true + }, ++ "BreakErrorCode GPR:$ErrorCode, BreakDefinition:$Reason": { ++ "HasSideEffects": true, ++ "Desc": ["Break whose fault error code is the low 16 bits of $ErrorCode, known only at run time", ++ "(a #GP with a selector as its error code); Reason.ErrorRegister is not used" ++ ] ++ }, + "CallbackReturn": { + "HasSideEffects": true + }, +diff --git a/FEXCore/Source/Interface/IR/IREmitter.cpp b/FEXCore/Source/Interface/IR/IREmitter.cpp +index 6c8ed5d11..d8fd1431e 100644 +--- a/FEXCore/Source/Interface/IR/IREmitter.cpp ++++ b/FEXCore/Source/Interface/IR/IREmitter.cpp +@@ -23,7 +23,8 @@ static bool IsFragmentExit(FEXCore::IR::IROps Op) { + case OP_SYSCALL: + case OP_CPUID: + case OP_EXITFUNCTION: +- case OP_BREAK: return true; ++ case OP_BREAK: ++ case OP_BREAKERRORCODE: return true; + default: return false; + } + } +diff --git a/FEXCore/Source/Utils/FaultSafeRead.cpp b/FEXCore/Source/Utils/FaultSafeRead.cpp +new file mode 100644 +index 000000000..aaa7a80cf +--- /dev/null ++++ b/FEXCore/Source/Utils/FaultSafeRead.cpp +@@ -0,0 +1,46 @@ ++// SPDX-License-Identifier: MIT ++#include ++ ++#include ++ ++namespace FEXCore::Utils::FaultSafeRead { ++#if defined(ARCHITECTURE_arm64) && !defined(_WIN32) ++__attribute__((naked)) static size_t CopyImpl(void* Dest, const void* Src, size_t Size) { ++ __asm volatile(R"( ++ // Early exit if a copy of size zero. ++ cbz x2, 2f; ++ ++ 1: ++ .globl FEXCore_FaultSafeRead_FaultInst ++ FEXCore_FaultSafeRead_FaultInst: ++ ldrb w3, [x1], 1; // <- This line can fault. ++ strb w3, [x0], 1; ++ sub x2, x2, 1; ++ cbnz x2, 1b; ++2: ++ mov x0, 0; ++ ret; ++ )" :: ++ : "memory"); ++} ++ ++extern "C" uint64_t FEXCore_FaultSafeRead_FaultInst; ++ ++bool Copy(void* Dest, const void* Src, size_t Size) { ++ return CopyImpl(Dest, Src, Size) == 0; ++} ++ ++bool IsFaultLocation(uint64_t PC) { ++ return reinterpret_cast(PC) == &FEXCore_FaultSafeRead_FaultInst; ++} ++#else ++bool Copy(void* Dest, const void* Src, size_t Size) { ++ memcpy(Dest, Src, Size); ++ return true; ++} ++ ++bool IsFaultLocation(uint64_t PC) { ++ return false; ++} ++#endif ++} +diff --git a/FEXCore/include/FEXCore/Core/Context.h b/FEXCore/include/FEXCore/Core/Context.h +index 7e1d30770..854c5ce1c 100644 +--- a/FEXCore/include/FEXCore/Core/Context.h ++++ b/FEXCore/include/FEXCore/Core/Context.h +@@ -141,9 +141,11 @@ public: + virtual void FlushAndCloseCodeMap() = 0; + + FEX_DEFAULT_VISIBILITY virtual void ClearCodeCache(FEXCore::Core::InternalThreadState* Thread, bool NewCodeBuffer = true) = 0; +- FEX_DEFAULT_VISIBILITY virtual void InvalidateCodeBuffersCodeRange(uint64_t Start, uint64_t Length) = 0; ++ FEX_DEFAULT_VISIBILITY virtual void InvalidateExecutableRangeCaches() = 0; ++ ++ FEX_DEFAULT_VISIBILITY virtual bool InvalidateCodeBuffersCodeRange(uint64_t Start, uint64_t Length) = 0; + FEX_DEFAULT_VISIBILITY virtual void +- InvalidateThreadCachedCodeRange(FEXCore::Core::InternalThreadState* Thread, uint64_t Start, uint64_t Length) = 0; ++ InvalidateThreadCachedCodeRange(FEXCore::Core::InternalThreadState* Thread, uint64_t Start, uint64_t Length, bool CodeMayBeCached = true) = 0; + FEX_DEFAULT_VISIBILITY virtual FEXCore::Utils::WritePriorityMutex::Mutex& GetCodeInvalidationMutex() = 0; + + FEX_DEFAULT_VISIBILITY virtual void +diff --git a/FEXCore/include/FEXCore/Core/CoreState.h b/FEXCore/include/FEXCore/Core/CoreState.h +index 7c02605f5..98ba8e150 100644 +--- a/FEXCore/include/FEXCore/Core/CoreState.h ++++ b/FEXCore/include/FEXCore/Core/CoreState.h +@@ -282,6 +282,11 @@ struct alignas(64) CPUState { + + // TODO: This should be moved to the frontend. + constexpr static uint32_t DEFAULT_USER_CS = 6; ++ constexpr static uint32_t DEFAULT_USER_DS = 5; ++ ++ constexpr static uint32_t DEFAULT_USER_CS_SEL = (DEFAULT_USER_CS << 3) | 3; ++ constexpr static uint32_t DEFAULT_USER_DS_SEL = (DEFAULT_USER_DS << 3) | 3; ++ constexpr static uint32_t DEFAULT_USER32_CS_SEL = 0x23; + + // Follows encoding of the TI bit in segment selector encoding. + constexpr static uint32_t SEGMENT_ARRAY_INDEX_GDT = 0; +diff --git a/FEXCore/include/FEXCore/HLE/SyscallHandler.h b/FEXCore/include/FEXCore/HLE/SyscallHandler.h +index 0ba0218e3..89e36d52e 100644 +--- a/FEXCore/include/FEXCore/HLE/SyscallHandler.h ++++ b/FEXCore/include/FEXCore/HLE/SyscallHandler.h +@@ -33,6 +33,10 @@ public: + virtual void HandleSyscall(FEXCore::Core::CpuStateFrame* Frame) = 0; + + virtual void MarkGuestExecutableRange(FEXCore::Core::InternalThreadState* Thread, uint64_t Start, uint64_t Length) {} ++ ++ virtual bool IsSMCHotPage(uint64_t Address) { ++ return false; ++ } + virtual void InvalidateGuestCodeRange(FEXCore::Core::InternalThreadState* Thread, uint64_t Start, uint64_t Length) {} + virtual void MarkOvercommitRange(uint64_t Start, uint64_t Length) {} + virtual void UnmarkOvercommitRange(uint64_t Start, uint64_t Length) {} +diff --git a/FEXCore/include/FEXCore/Utils/FaultSafeRead.h b/FEXCore/include/FEXCore/Utils/FaultSafeRead.h +new file mode 100644 +index 000000000..1fc7213b5 +--- /dev/null ++++ b/FEXCore/include/FEXCore/Utils/FaultSafeRead.h +@@ -0,0 +1,12 @@ ++// SPDX-License-Identifier: MIT ++#pragma once ++#include ++ ++#include ++#include ++ ++namespace FEXCore::Utils::FaultSafeRead { ++FEX_DEFAULT_VISIBILITY bool Copy(void* Dest, const void* Src, size_t Size); ++ ++FEX_DEFAULT_VISIBILITY bool IsFaultLocation(uint64_t PC); ++} +diff --git a/FEXCore/include/FEXCore/Utils/SHMStats.h b/FEXCore/include/FEXCore/Utils/SHMStats.h +index c5844fe10..d646c6a2f 100644 +--- a/FEXCore/include/FEXCore/Utils/SHMStats.h ++++ b/FEXCore/include/FEXCore/Utils/SHMStats.h +@@ -74,7 +74,10 @@ struct ThreadStats { + uint64_t AccumulatedDiskCacheHitCount; + uint64_t AccumulatedDiskCacheMissCount; + uint64_t AccumulatedDiskCacheLookupTime; +- uint64_t Padding; ++ ++ uint64_t AccumulatedInvalidationCount; ++ uint64_t AccumulatedInvalidationTime; ++ uint64_t AccumulatedCallRetFlushCount; + }; + + // Ensure 16-byte alignment to take advantage of ARM single-copy atomicity. +diff --git a/Source/Tools/FEXInterpreter/FEXInterpreter.cpp b/Source/Tools/FEXInterpreter/FEXInterpreter.cpp +index e7e88f8f2..26b8186c8 100644 +--- a/Source/Tools/FEXInterpreter/FEXInterpreter.cpp ++++ b/Source/Tools/FEXInterpreter/FEXInterpreter.cpp +@@ -602,8 +602,7 @@ int main(int argc, char** argv, char** const envp) { + // Create a thread without a RIP or stack pointer setup initially. + auto ParentThread = SyscallHandler->TM.CreateThread(); + SyscallHandler->TM.TrackThread(ParentThread); +- SignalDelegation->RegisterTLSState(ParentThread); +- ThunkHandler->RegisterTLSState(ParentThread); ++ SyscallHandler->RegisterTLSState(ParentThread); + + SyscallHandler->DeserializeSeccompFD(ParentThread, FEXSeccompFD); + +diff --git a/Source/Tools/LinuxEmulation/ArchHelpers/MContext.h b/Source/Tools/LinuxEmulation/ArchHelpers/MContext.h +index 2e724929f..62135b824 100644 +--- a/Source/Tools/LinuxEmulation/ArchHelpers/MContext.h ++++ b/Source/Tools/LinuxEmulation/ArchHelpers/MContext.h +@@ -20,6 +20,7 @@ namespace FEX::ArchHelpers::Context { + + enum ContextFlags : uint32_t { + CONTEXT_FLAG_INJIT = (1U << 0), ++ CONTEXT_FLAG_SYSCALLINFO_CLEARED = (1U << 1), + }; + + #if defined(ASSERTIONS_ENABLED) && ASSERTIONS_ENABLED +@@ -40,7 +41,11 @@ struct X86ContextBackup { + FEXCore::x86_64::_libc_fpstate FPRState; + uint64_t sa_mask; + uint16_t InSyscallInfo; ++ uint16_t ClearedSyscallInfo; + bool FaultToTopAndGeneratedException; ++ uint64_t GuestSignalMask; ++ uint64_t SeccompTrapRIP; ++ uint64_t SavedJITStackSP; + + // Guest state + int Signal; +@@ -72,7 +77,11 @@ struct ArmContextBackup { + __uint128_t FPRs[32]; + uint64_t sa_mask; + uint16_t InSyscallInfo; ++ uint16_t ClearedSyscallInfo; + bool FaultToTopAndGeneratedException; ++ uint64_t GuestSignalMask; ++ uint64_t SeccompTrapRIP; ++ uint64_t SavedJITStackSP; + + // Guest state + int Signal; +@@ -92,6 +101,11 @@ struct ArmContextBackup { + static constexpr int RedZoneSize = 0; + }; + ++template ++static inline uint16_t SavedSyscallInfo(const Backup* Context) { ++ return (Context->Flags & CONTEXT_FLAG_SYSCALLINFO_CLEARED) ? Context->ClearedSyscallInfo : Context->InSyscallInfo; ++} ++ + static inline ucontext_t* GetUContext(void* ucontext) { + ucontext_t* _context = (ucontext_t*)ucontext; + return _context; +diff --git a/Source/Tools/LinuxEmulation/CMakeLists.txt b/Source/Tools/LinuxEmulation/CMakeLists.txt +index 715a8f132..3f02104ea 100644 +--- a/Source/Tools/LinuxEmulation/CMakeLists.txt ++++ b/Source/Tools/LinuxEmulation/CMakeLists.txt +@@ -10,6 +10,9 @@ add_library(LinuxEmulation STATIC + LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp + LinuxSyscalls/FaultSafeUserMemAccess.cpp + LinuxSyscalls/FileManagement.cpp ++ LinuxSyscalls/PtraceEmu.cpp ++ LinuxSyscalls/SamplingProfiler.cpp ++ LinuxSyscalls/SignalTrace.cpp + LinuxSyscalls/LinuxAllocator.cpp + LinuxSyscalls/Seccomp/SeccompEmulator.cpp + LinuxSyscalls/Seccomp/BPFEmitter.cpp +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp +index 2095d4dc5..eb12945e4 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp +@@ -10,6 +10,7 @@ $end_info$ + + #include "Common/CPUInfo.h" + #include "Common/FDUtils.h" ++#include "LinuxSyscalls/PtraceEmu.h" + #include "LinuxSyscalls/Syscalls.h" + #include "LinuxSyscalls/EmulatedFiles/EmulatedFiles.h" + +@@ -24,6 +25,8 @@ $end_info$ + + #include + ++#include ++#include + #include + #include + #include +@@ -593,6 +596,10 @@ EmulatedFDManager::EmulatedFDManager(FEXCore::Context::Context* ctx) + FDReadCreators[procAuxv] = &EmulatedFDManager::ProcAuxv; + FDReadCreators["/proc/self/auxv"] = &EmulatedFDManager::ProcAuxv; + ++ fextl::string procStatus = fextl::fmt::format("/proc/{}/status", getpid()); ++ FDReadCreators[procStatus] = &EmulatedFDManager::ProcStatus; ++ FDReadCreators["/proc/self/status"] = &EmulatedFDManager::ProcStatus; ++ + if (ThreadsConfig > 1) { + cpus_online = fextl::fmt::format("0-{}", ThreadsConfig - 1); + } else { +@@ -602,6 +609,20 @@ EmulatedFDManager::EmulatedFDManager(FEXCore::Context::Context* ctx) + + EmulatedFDManager::~EmulatedFDManager() {} + ++static bool IsProcMapsPath(const char* Path) { ++ if (strncmp(Path, "/proc/", 6) != 0) { ++ return false; ++ } ++ const char* P = Path + 6; ++ if (!isdigit(*P)) { ++ return strcmp(P, "self/maps") == 0; ++ } ++ while (isdigit(*P)) { ++ ++P; ++ } ++ return strcmp(P, "/maps") == 0; ++} ++ + int32_t EmulatedFDManager::Open(const char* pathname, int flags, uint32_t mode) { + auto Creator = FDReadCreators.end(); + if (pathname) { +@@ -609,12 +630,148 @@ int32_t EmulatedFDManager::Open(const char* pathname, int flags, uint32_t mode) + } + + if (Creator == FDReadCreators.end()) { ++ if (pathname && IsProcMapsPath(pathname)) { ++ return ProcMaps(CTX, AT_FDCWD, pathname, flags, mode); ++ } + return -1; + } + + return Creator->second(CTX, AT_FDCWD, pathname, flags, mode); + } + ++int32_t EmulatedFDManager::ProcMaps(FEXCore::Context::Context* ctx, int32_t fd, const char* pathname, int32_t flags, mode_t mode) { ++ int HostFD = ::open(pathname, O_RDONLY | O_CLOEXEC); ++ if (HostFD < 0) { ++ return -1; ++ } ++ fextl::string In; ++ char Buf[65536]; ++ for (;;) { ++ const ssize_t Len = ::read(HostFD, Buf, sizeof(Buf)); ++ if (Len > 0) { ++ In.append(Buf, Len); ++ } else if (Len == 0) { ++ break; ++ } else if (errno != EINTR) { ++ LogMan::Msg::EFmt("ProcMaps: reading {} failed: {}", pathname, errno); ++ ::close(HostFD); ++ return -1; ++ } ++ } ++ ::close(HostFD); ++ ++ constexpr uint64_t X86_64TaskSizeMax = (1ULL << 47) - 4096; ++ fextl::string Out; ++ Out.reserve(In.size()); ++ size_t Pos = 0; ++ while (Pos < In.size()) { ++ size_t Eol = In.find('\n', Pos); ++ const size_t End = Eol == fextl::string::npos ? In.size() : Eol + 1; ++ const uint64_t Start = strtoull(In.c_str() + Pos, nullptr, 16); ++ if (Start < X86_64TaskSizeMax) { ++ Out.append(In, Pos, End - Pos); ++ } ++ Pos = End; ++ } ++ ++ int NewFD = GenTmpFD(pathname, flags); ++ if (NewFD < 0) { ++ LogMan::Msg::EFmt("ProcMaps: memfd_create failed: {}", errno); ++ return -1; ++ } ++ for (size_t Done = 0; Done < Out.size();) { ++ const ssize_t Wrote = ::write(NewFD, Out.data() + Done, Out.size() - Done); ++ if (Wrote > 0) { ++ Done += Wrote; ++ } else if (Wrote < 0 && errno == EINTR) { ++ continue; ++ } else { ++ LogMan::Msg::EFmt("ProcMaps: writing the synthesized file failed: {}", errno); ++ ::close(NewFD); ++ return -1; ++ } ++ } ++ if (::lseek(NewFD, 0, SEEK_SET) != 0) { ++ LogMan::Msg::EFmt("ProcMaps: lseek failed: {}", errno); ++ ::close(NewFD); ++ return -1; ++ } ++ SealTmpFD(NewFD); ++ return NewFD; ++} ++ ++int32_t EmulatedFDManager::ProcStatus(FEXCore::Context::Context* ctx, int32_t fd, const char* pathname, int32_t flags, mode_t mode) { ++ char Buf[8192]; ++ ssize_t Len = 0; ++ { ++ int HostFD = ::open("/proc/self/status", O_RDONLY | O_CLOEXEC); ++ if (HostFD >= 0) { ++ Len = ::read(HostFD, Buf, sizeof(Buf) - 1); ++ ::close(HostFD); ++ } ++ } ++ if (Len < 0) { ++ Len = 0; ++ } ++ Buf[Len] = '\0'; ++ ++ uint32_t SeccompMode = SECCOMP_MODE_DISABLED; ++ if (auto* Thread = FEX::HLE::ThreadManager::GetCurrentThreadObject()) { ++ SeccompMode = Thread->SeccompMode; ++ } ++ ++ fextl::string Out; ++ Out.reserve(Len + 64); ++ const char* Cursor = Buf; ++ while (*Cursor) { ++ const char* Eol = strchr(Cursor, '\n'); ++ const size_t LineLen = Eol ? static_cast(Eol - Cursor) + 1 : strlen(Cursor); ++ if (strncmp(Cursor, "Seccomp:", 8) == 0) { ++ Out += fextl::fmt::format("Seccomp:\t{}\n", SeccompMode); ++ } else if (strncmp(Cursor, "TracerPid:", 10) == 0) { ++ if (FEX::HLE::PtraceEmu::IsAttached()) { ++ Out.append(Cursor, LineLen); ++ } else { ++ Out += "TracerPid:\t0\n"; ++ } ++ } else { ++ Out.append(Cursor, LineLen); ++ if (!Eol) { ++ break; ++ } ++ } ++ if (!Eol) { ++ break; ++ } ++ Cursor = Eol + 1; ++ } ++ ++ int NewFD = GenTmpFD(pathname, flags); ++ if (NewFD < 0) { ++ LogMan::Msg::EFmt("ProcMaps: memfd_create failed: {}", errno); ++ return -1; ++ } ++ for (size_t Done = 0; Done < Out.size();) { ++ const ssize_t Wrote = ::write(NewFD, Out.data() + Done, Out.size() - Done); ++ if (Wrote > 0) { ++ Done += Wrote; ++ } else if (Wrote < 0 && errno == EINTR) { ++ continue; ++ } else { ++ LogMan::Msg::EFmt("ProcMaps: writing the synthesized file failed: {}", errno); ++ ::close(NewFD); ++ return -1; ++ } ++ } ++ if (::lseek(NewFD, 0, SEEK_SET) != 0) { ++ LogMan::Msg::EFmt("ProcMaps: lseek failed: {}", errno); ++ ::close(NewFD); ++ return -1; ++ } ++ SealTmpFD(NewFD); ++ return NewFD; ++} ++ + int32_t EmulatedFDManager::ProcAuxv(FEXCore::Context::Context* ctx, int32_t fd, const char* pathname, int32_t flags, mode_t mode) { + const auto [auxvBase, auxvSize] = FEX::HLE::_SyscallHandler->GetCodeLoader()->GetAuxv(); + if (auxvBase == 0) { +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.h b/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.h +index 854232341..b98ef4bda 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.h ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.h +@@ -34,6 +34,8 @@ private: + fextl::unordered_map FDReadCreators; + + static int32_t ProcAuxv(FEXCore::Context::Context* ctx, int32_t fd, const char* pathname, int32_t flags, mode_t mode); ++ static int32_t ProcMaps(FEXCore::Context::Context* ctx, int32_t fd, const char* pathname, int32_t flags, mode_t mode); ++ static int32_t ProcStatus(FEXCore::Context::Context* ctx, int32_t fd, const char* pathname, int32_t flags, mode_t mode); + const uint32_t ThreadsConfig; + }; + } // namespace FEX::EmulatedFile +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/FaultSafeUserMemAccess.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/FaultSafeUserMemAccess.cpp +index 6471e6483..7a7e068e2 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/FaultSafeUserMemAccess.cpp ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/FaultSafeUserMemAccess.cpp +@@ -1,6 +1,8 @@ + // SPDX-License-Identifier: MIT + #include "LinuxSyscalls/Syscalls.h" + ++#include ++ + namespace FEX::HLE::FaultSafeUserMemAccess { + #ifdef ARCHITECTURE_arm64 + __attribute__((naked)) size_t CopyFromUser(void* Dest, const void* Src, size_t Size) { +@@ -41,6 +43,26 @@ __attribute__((naked)) size_t CopyToUser(void* Dest, const void* Src, size_t Siz + : "memory"); + } + ++__attribute__((naked)) static size_t StringReadableImpl(const char* Src) { ++ __asm volatile(R"( ++ 1: ++ .globl StringReadable_FaultInst ++ StringReadable_FaultInst: ++ ldrb w1, [x0], 1; // <- This line can fault. ++ cbnz w1, 1b; ++ mov x0, 0; ++ ret; ++ )" :: ++ : "memory"); ++} ++ ++bool IsStringReadable(const char* Src) { ++ return Src == nullptr || StringReadableImpl(Src) == 0; ++} ++ ++extern "C" uint64_t StringReadable_FaultInst; ++void* const StringReadable_FaultLocation = &StringReadable_FaultInst; ++ + extern "C" uint64_t CopyFromUser_FaultInst; + void* const CopyFromUser_FaultLocation = &CopyFromUser_FaultInst; + +@@ -157,6 +179,8 @@ bool IsFaultLocation(uint64_t PC) { + bool IsMemcpyFault = false; + IsMemcpyFault |= reinterpret_cast(PC) == CopyToUser_FaultLocation; + IsMemcpyFault |= reinterpret_cast(PC) == CopyFromUser_FaultLocation; ++ IsMemcpyFault |= reinterpret_cast(PC) == StringReadable_FaultLocation; ++ IsMemcpyFault |= FEXCore::Utils::FaultSafeRead::IsFaultLocation(PC); + #if defined(ASSERTIONS_ENABLED) && ASSERTIONS_ENABLED && defined(ARCHITECTURE_arm64) + IsMemcpyFault |= reinterpret_cast(PC) == UserReadable_FaultLocation; + IsMemcpyFault |= reinterpret_cast(PC) == UserWritable_FaultLocation; +@@ -176,6 +200,10 @@ size_t CopyToUser(void* Dest, const void* Src, size_t Size) { + return Size; + } + ++bool IsStringReadable(const char* Src) { ++ return true; ++} ++ + bool IsFaultLocation(uint64_t PC) { + return false; + } +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/FileManagement.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/FileManagement.cpp +index 2210e4508..62b6a2d27 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/FileManagement.cpp ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/FileManagement.cpp +@@ -13,6 +13,7 @@ $end_info$ + #include "FEXCore/Config/Config.h" + #include "LinuxSyscalls/FileManagement.h" + #include "LinuxSyscalls/EmulatedFiles/EmulatedFiles.h" ++#include "LinuxSyscalls/PtraceEmu.h" + #include "LinuxSyscalls/Syscalls.h" + #include "LinuxSyscalls/x64/Syscalls.h" + +@@ -954,6 +955,27 @@ uint64_t FileManager::FAccessat2(int dirfd, const char* pathname, int mode, int + return ::syscall(SYSCALL_DEF(faccessat2), dirfd, SelfPath, mode, flags); + } + ++static std::optional ReadlinkTraceeExe(const char* Path, char* Buf, size_t BufSize) { ++ if (!Path || strncmp(Path, "/proc/", 6) != 0) { ++ return std::nullopt; ++ } ++ char* End = nullptr; ++ const long Pid = strtol(Path + 6, &End, 10); ++ if (End == Path + 6 || strcmp(End, "/exe") != 0) { ++ return std::nullopt; ++ } ++ const auto Exe = PtraceEmu::TraceeExePath(static_cast(Pid)); ++ if (!Exe) { ++ return std::nullopt; ++ } ++ const size_t Len = std::min(BufSize, Exe->size()); ++ if (FaultSafeUserMemAccess::CopyToUser(Buf, Exe->data(), Len)) { ++ errno = EFAULT; ++ return -1; ++ } ++ return Len; ++} ++ + uint64_t FileManager::Readlink(const char* pathname, char* buf, size_t bufsiz) { + // calculate the non-self link to exe + // Some executables do getpid, stat("/proc/$pid/exe") +@@ -962,8 +984,16 @@ uint64_t FileManager::Readlink(const char* pathname, char* buf, size_t bufsiz) { + + if (strcmp(pathname, "/proc/self/exe") == 0 || strcmp(pathname, "/proc/thread-self/exe") == 0 || strcmp(pathname, PidSelfPath) == 0) { + const auto& App = Filename(); +- strncpy(buf, App.c_str(), bufsiz); +- return std::min(bufsiz, App.size()); ++ const size_t Len = std::min(bufsiz, App.size()); ++ if (FaultSafeUserMemAccess::CopyToUser(buf, App.c_str(), Len)) { ++ errno = EFAULT; ++ return -1; ++ } ++ return Len; ++ } ++ ++ if (auto Traced = ReadlinkTraceeExe(pathname, buf, bufsiz)) { ++ return *Traced; + } + + FDPathTmpData TmpFilename; +@@ -1039,8 +1069,18 @@ uint64_t FileManager::Readlinkat(int dirfd, const char* pathname, char* buf, siz + + if (Path == "/proc/self/exe" || Path == "/proc/thread-self/exe" || Path == PidSelfPath) { + const auto& App = Filename(); +- strncpy(buf, App.c_str(), bufsiz); +- return std::min(bufsiz, App.size()); ++ const size_t Len = std::min(bufsiz, App.size()); ++ if (FaultSafeUserMemAccess::CopyToUser(buf, App.c_str(), Len)) { ++ errno = EFAULT; ++ return -1; ++ } ++ return Len; ++ } ++ ++ if (!Path.empty() && Path[0] == '/') { ++ if (auto Traced = ReadlinkTraceeExe(Path.c_str(), buf, bufsiz)) { ++ return *Traced; ++ } + } + + FDPathTmpData TmpFilename; +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/LinuxAllocator.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/LinuxAllocator.cpp +index 7ae8236b3..3be10d097 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/LinuxAllocator.cpp ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/LinuxAllocator.cpp +@@ -50,6 +50,7 @@ public: + + void* Mmap(void* addr, size_t length, int prot, int flags, int fd, off_t offset) override; + int Munmap(void* addr, size_t length) override; ++ void TrackUnmapped(void* addr, size_t length) override; + void* Mremap(void* old_address, size_t old_size, size_t new_size, int flags, void* new_address) override; + uint64_t Shmat(int shmid, const void* shmaddr, int shmflg, uint32_t* ResultAddress) override; + uint64_t Shmdt(const void* shmaddr) override; +@@ -333,6 +334,17 @@ int MemAllocator32Bit::Munmap(void* addr, size_t length) { + return 0; + } + ++void MemAllocator32Bit::TrackUnmapped(void* addr, size_t length) { ++ std::scoped_lock lk {AllocMutex}; ++ ++ const uint64_t Addr = reinterpret_cast(addr); ++ const uint64_t PageAddr = std::max(Addr >> FEXCore::Utils::FEX_PAGE_SHIFT, BASE_KEY); ++ const uint64_t PageEnd = std::min(FEXCore::AlignUp(Addr + length, FEXCore::Utils::FEX_PAGE_SIZE) >> FEXCore::Utils::FEX_PAGE_SHIFT, TOP_KEY); ++ if (PageAddr < PageEnd) { ++ SetFreePages(PageAddr, PageEnd - PageAddr); ++ } ++} ++ + void* MemAllocator32Bit::Mremap(void* old_address, size_t old_size, size_t new_size, int flags, void* new_address) { + size_t OldPagesLength = FEXCore::AlignUp(old_size, FEXCore::Utils::FEX_PAGE_SIZE) >> FEXCore::Utils::FEX_PAGE_SHIFT; + size_t NewPagesLength = FEXCore::AlignUp(new_size, FEXCore::Utils::FEX_PAGE_SIZE) >> FEXCore::Utils::FEX_PAGE_SHIFT; +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/LinuxAllocator.h b/Source/Tools/LinuxEmulation/LinuxSyscalls/LinuxAllocator.h +index dd6ae074f..c84f85b4a 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/LinuxAllocator.h ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/LinuxAllocator.h +@@ -14,6 +14,7 @@ public: + virtual ~MemAllocator() = default; + virtual void* Mmap(void* addr, size_t length, int prot, int flags, int fd, off_t offset) = 0; + virtual int Munmap(void* addr, size_t length) = 0; ++ virtual void TrackUnmapped(void* addr, size_t length) {} + virtual void* Mremap(void* old_address, size_t old_size, size_t new_size, int flags, void* new_address) = 0; + virtual uint64_t Shmat(int shmid, const void* shmaddr, int shmflg, uint32_t* ResultAddress) = 0; + virtual uint64_t Shmdt(const void* shmaddr) = 0; +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/PtraceEmu.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/PtraceEmu.cpp +new file mode 100644 +index 000000000..ca4c86063 +--- /dev/null ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/PtraceEmu.cpp +@@ -0,0 +1,838 @@ ++// SPDX-License-Identifier: MIT ++ ++#include "LinuxSyscalls/PtraceEmu.h" ++#include "LinuxSyscalls/Syscalls.h" ++ ++#include ++#include ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++namespace FEX::HLE::PtraceEmu { ++namespace { ++#ifndef NT_X86_XSTATE ++ constexpr uintptr_t NT_X86_XSTATE = 0x202; ++#endif ++ ++ enum UserReg : unsigned { ++ R15, R14, R13, R12, Rbp, Rbx, R11, R10, R9, R8, Rax, Rcx, Rdx, Rsi, Rdi, OrigRax, Rip, Cs, Eflags, Rsp, Ss, FsBase, GsBase, Ds, Es, Fs, Gs, ++ }; ++ static_assert(Gs + 1 == NumUserRegs); ++ ++ constexpr uintptr_t UserDebugRegByteOffset = 848; ++ constexpr uintptr_t UserDebugRegByteEnd = UserDebugRegByteOffset + 8 * sizeof(uint64_t); ++ constexpr uintptr_t UserStructSize = 928; ++ ++ constexpr uint64_t UserTaskSizeMax = 0x00007ffffffff000ULL; ++ ++ bool DrFieldValid(uint64_t Field, uint64_t* AlignMask) { ++ const uint64_t Len = Field & 0xC; ++ switch (Field & 0x3) { ++ case 0x0: ++ if (Len != 0x0) { ++ return false; ++ } ++ *AlignMask = 0; ++ return true; ++ case 0x1: ++ case 0x3: ++ switch (Len) { ++ case 0x0: *AlignMask = 0; return true; ++ case 0x4: *AlignMask = 1; return true; ++ case 0xC: *AlignMask = 3; return true; ++ case 0x8: *AlignMask = 7; return true; ++ default: return false; ++ } ++ default: ++ return false; ++ } ++ } ++ ++ constexpr unsigned DrEnableShift(unsigned N) { return N * 2; } ++ constexpr unsigned DrFieldShift(unsigned N) { return 16 + N * 4; } ++ ++ bool DrAddressValid(uint64_t Addr, uint64_t AlignMask) { ++ return Addr < UserTaskSizeMax && (Addr & AlignMask) == 0; ++ } ++ ++ bool Dr7Valid(const uint64_t Dr[8], uint64_t NewDr7) { ++ for (unsigned N = 0; N < 4; ++N) { ++ const bool Enabled = (NewDr7 >> DrEnableShift(N)) & 0x3; ++ const bool Registered = Dr[N] != 0; ++ if (!Enabled && !Registered) { ++ continue; ++ } ++ const uint64_t Field = (NewDr7 >> DrFieldShift(N)) & 0xF; ++ uint64_t AlignMask = 0; ++ if (!DrFieldValid(Field, &AlignMask) || !DrAddressValid(Dr[N], AlignMask)) { ++ return false; ++ } ++ } ++ return true; ++ } ++ ++ constexpr uint16_t UserCodeSegment = 0x33; ++ constexpr uint16_t UserStackSegment = 0x2b; ++ constexpr uint64_t UserFlags = 0x246; ++ constexpr uint64_t NoOverride = ~0ULL; ++ ++ constexpr int X86_PTRACE_GETREGS = 12; ++ constexpr int X86_PTRACE_SETREGS = 13; ++ constexpr int X86_PTRACE_EVENT_EXEC = 4; ++ ++ SharedState StaticState {SharedState::MagicValue}; ++ SharedState* Current = &StaticState; ++ thread_local uint64_t PendingRip = 0; ++ ++ struct OpenSyscall { ++ bool Open = false; ++ uint64_t Nr {}; ++ uint64_t Args[6] {}; ++ } Previous; ++ ++ constexpr const char* SidecarDirs[] = {"/dev/shm", "/tmp"}; ++ ++ std::string SidecarPath(const char* Dir, const char* Kind, pid_t Pid) { ++ return std::string(Dir) + "/fex-ptrace-" + Kind + "-" + std::to_string(Pid); ++ } ++ ++ int OpenSidecar(const char* Kind, pid_t Pid, int Flags) { ++ for (const char* Dir : SidecarDirs) { ++ const int fd = ::open(SidecarPath(Dir, Kind, Pid).c_str(), Flags | O_CLOEXEC, 0600); ++ if (fd >= 0) { ++ return fd; ++ } ++ } ++ return -1; ++ } ++ ++ void RemoveSidecar(const char* Kind, pid_t Pid) { ++ for (const char* Dir : SidecarDirs) { ++ ::unlink(SidecarPath(Dir, Kind, Pid).c_str()); ++ } ++ } ++ ++ bool IsMainThread() { ++ return ::syscall(SYS_gettid) == ::getpid(); ++ } ++ ++ bool HasHostTracer() { ++ const int fd = ::open("/proc/self/status", O_RDONLY | O_CLOEXEC); ++ if (fd < 0) { ++ return true; ++ } ++ char Buf[2048]; ++ const ssize_t n = ::read(fd, Buf, sizeof(Buf) - 1); ++ ::close(fd); ++ if (n <= 0) { ++ return true; ++ } ++ Buf[n] = 0; ++ const char* Tag = strstr(Buf, "TracerPid:"); ++ return !Tag || atoi(Tag + sizeof("TracerPid:") - 1) != 0; ++ } ++ ++ ++ void BuildRegs(const FEXCore::Core::CpuStateFrame* Frame, uint64_t Nr, bool Entry, uint64_t Ret, uint64_t* X) { ++ using namespace FEXCore::X86State; ++ const auto& S = Frame->State; ++ X[R15] = S.gregs[REG_R15]; ++ X[R14] = S.gregs[REG_R14]; ++ X[R13] = S.gregs[REG_R13]; ++ X[R12] = S.gregs[REG_R12]; ++ X[Rbp] = S.gregs[REG_RBP]; ++ X[Rbx] = S.gregs[REG_RBX]; ++ X[R11] = UserFlags; ++ X[R10] = S.gregs[REG_R10]; ++ X[R9] = S.gregs[REG_R9]; ++ X[R8] = S.gregs[REG_R8]; ++ X[Rax] = Entry ? static_cast(-ENOSYS) : Ret; ++ X[Rcx] = S.gregs[REG_RCX]; ++ X[Rdx] = S.gregs[REG_RDX]; ++ X[Rsi] = S.gregs[REG_RSI]; ++ X[Rdi] = S.gregs[REG_RDI]; ++ X[OrigRax] = Nr; ++ X[Rip] = S.gregs[REG_RCX] ? S.gregs[REG_RCX] : S.rip; ++ X[Cs] = UserCodeSegment; ++ X[Eflags] = UserFlags; ++ X[Rsp] = S.gregs[REG_RSP]; ++ X[Ss] = UserStackSegment; ++ X[FsBase] = S.fs_cached; ++ X[GsBase] = S.gs_cached; ++ X[Ds] = X[Es] = X[Fs] = X[Gs] = 0; ++ } ++ ++ void Stop(uint64_t Nr, const uint64_t Args[6], bool Entry, uint64_t Ret, const uint64_t* Regs) { ++ SharedState& S = *Current; ++ if (!HasHostTracer()) { ++ S.SyscallStops = 0; ++ S.Attached = 0; ++ return; ++ } ++ for (unsigned i = 0; i < NumUserRegs; ++i) { ++ S.Regs[i] = Regs[i]; ++ } ++ S.PendingNr = Nr; ++ for (unsigned i = 0; i < 6; ++i) { ++ S.PendingArgs[i] = Args[i]; ++ } ++ S.PendingRet = Ret; ++ S.PendingIsEntry = Entry ? 1 : 0; ++ S.Pending = 1; ++ ::syscall(SYS_tgkill, ::getpid(), ::syscall(SYS_gettid), SIGSTOP); ++ S.Pending = 0; ++ } ++ ++ uint64_t ApplyTracerWrites(FEXCore::Core::CpuStateFrame* Frame, bool Entry) { ++ using namespace FEXCore::X86State; ++ SharedState& S = *Current; ++ ++ if (S.FlushLen) { ++ const uint64_t Addr = S.FlushAddr; ++ const uint64_t Len = S.FlushLen; ++ S.FlushLen = 0; ++ FEX::HLE::_SyscallHandler->InvalidateGuestCodeRange(Frame->Thread, Addr, Len); ++ } ++ ++ const uint64_t Dirty = S.DirtyMask; ++ if (!Dirty) { ++ return NoOverride; ++ } ++ ++ static constexpr int Map[15] = {REG_R15, REG_R14, REG_R13, REG_R12, REG_RBP, REG_RBX, -1, REG_R10, REG_R9, REG_R8, -1, REG_RCX, REG_RDX, REG_RSI, REG_RDI}; ++ auto& State = Frame->State; ++ uint64_t Override = NoOverride; ++ for (unsigned i = 0; i < NumUserRegs; ++i) { ++ if (!(Dirty & (1ULL << i))) { ++ continue; ++ } ++ const uint64_t V = S.Regs[i]; ++ if (i < 15) { ++ if (Map[i] >= 0) { ++ State.gregs[Map[i]] = V; ++ } ++ } else if (i == Rip) { ++ PendingRip = V; ++ } else if (i == Rsp) { ++ State.gregs[REG_RSP] = V; ++ } else if (i == FsBase) { ++ State.fs_cached = V; ++ } else if (i == GsBase) { ++ State.gs_cached = V; ++ } ++ if (i == Rax && !Entry) { ++ Override = V; ++ } ++ } ++ if (Entry && (Dirty & (1ULL << OrigRax))) { ++ State.gregs[REG_RAX] = S.Regs[OrigRax]; ++ } ++ S.DirtyMask = 0; ++ return Override; ++ } ++ ++ void PublishSharedPage() { ++ if (Current != &StaticState) { ++ return; ++ } ++ const int fd = OpenSidecar("state", ::getpid(), O_RDWR | O_CREAT | O_TRUNC); ++ if (fd < 0) { ++ return; ++ } ++ if (::ftruncate(fd, 4096) == 0) { ++ void* Page = ::mmap(nullptr, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); ++ if (Page != MAP_FAILED) { ++ std::memcpy(Page, &StaticState, sizeof(SharedState)); ++ Current = static_cast(Page); ++ } ++ } ++ ::close(fd); ++ } ++ ++ struct Remote { ++ uint8_t* Mapped = nullptr; ++ uintptr_t StaticAddr = 0; ++ std::array FpRegs {}; ++ bool FpValid = false; ++ std::array XState {}; ++ bool XStateValid = false; ++ }; ++ std::mutex RemotesLock; ++ std::unordered_map Remotes; ++ std::unordered_map ExePaths; ++ ++ uintptr_t FindFexImageBase(pid_t Pid) { ++ static const std::string SelfExe = []() { ++ char Buf[512]; ++ const ssize_t n = ::readlink("/proc/self/exe", Buf, sizeof(Buf) - 1); ++ return n > 0 ? std::string(Buf, n) : std::string(); ++ }(); ++ if (SelfExe.empty()) { ++ return 0; ++ } ++ const std::string Maps = Pid ? "/proc/" + std::to_string(Pid) + "/maps" : "/proc/self/maps"; ++ FILE* F = fopen(Maps.c_str(), "r"); ++ if (!F) { ++ return 0; ++ } ++ char Line[1024]; ++ uintptr_t Lowest = 0; ++ while (fgets(Line, sizeof(Line), F)) { ++ if (!strstr(Line, SelfExe.c_str())) { ++ continue; ++ } ++ unsigned long long Start = 0, End = 0, Offset = 0; ++ if (sscanf(Line, "%llx-%llx %*s %llx", &Start, &End, &Offset) == 3 && Offset == 0 && (!Lowest || Start < Lowest)) { ++ Lowest = Start; ++ } ++ } ++ fclose(F); ++ return Lowest; ++ } ++ ++ Remote* Lookup(pid_t Pid) { ++ auto It = Remotes.find(Pid); ++ if (It != Remotes.end()) { ++ return &It->second; ++ } ++ Remote R; ++ const int fd = OpenSidecar("state", Pid, O_RDWR); ++ if (fd >= 0) { ++ void* Page = ::mmap(nullptr, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); ++ ::close(fd); ++ if (Page != MAP_FAILED) { ++ R.Mapped = static_cast(Page); ++ } ++ } ++ if (!R.Mapped) { ++ static const uintptr_t SelfBase = FindFexImageBase(0); ++ const uintptr_t TraceeBase = FindFexImageBase(Pid); ++ if (!SelfBase || !TraceeBase) { ++ return nullptr; ++ } ++ R.StaticAddr = TraceeBase + (reinterpret_cast(&StaticState) - SelfBase); ++ } ++ return &Remotes.emplace(Pid, std::move(R)).first->second; ++ } ++ ++ void Forget(pid_t Pid, bool Exited) { ++ std::lock_guard lk(RemotesLock); ++ auto It = Remotes.find(Pid); ++ if (It != Remotes.end()) { ++ if (It->second.Mapped) { ++ ::munmap(It->second.Mapped, 4096); ++ } ++ Remotes.erase(It); ++ } ++ RemoveSidecar("state", Pid); ++ if (Exited) { ++ ExePaths.erase(Pid); ++ } ++ } ++ ++ void CaptureExecPath(pid_t Pid) { ++ std::lock_guard lk(RemotesLock); ++ Remote* R = Lookup(Pid); ++ if (R && R->Mapped) { ++ auto* S = reinterpret_cast(R->Mapped); ++ if (S->Magic == SharedState::MagicValue && S->ExePath[0]) { ++ ExePaths[Pid] = std::string(S->ExePath, strnlen(S->ExePath, sizeof(S->ExePath))); ++ } ++ } ++ } ++ ++ uint64_t HostPtrace(int Request, pid_t Pid, void* Addr, void* Data) { ++ const long R = ::syscall(SYS_ptrace, Request, Pid, Addr, Data); ++ return R == -1 ? static_cast(-errno) : static_cast(R); ++ } ++ ++ bool ReadWord(pid_t Pid, size_t Offset, uint64_t* Out) { ++ std::lock_guard lk(RemotesLock); ++ Remote* R = Lookup(Pid); ++ if (!R) { ++ return false; ++ } ++ if (R->Mapped) { ++ *Out = *reinterpret_cast(R->Mapped + Offset); ++ return true; ++ } ++ return ::syscall(SYS_ptrace, PTRACE_PEEKDATA, Pid, R->StaticAddr + Offset, Out) == 0; ++ } ++ ++ bool WriteWord(pid_t Pid, size_t Offset, uint64_t Value) { ++ std::lock_guard lk(RemotesLock); ++ Remote* R = Lookup(Pid); ++ if (!R) { ++ return false; ++ } ++ if (R->Mapped) { ++ *reinterpret_cast(R->Mapped + Offset) = Value; ++ return true; ++ } ++ return ::syscall(SYS_ptrace, PTRACE_POKEDATA, Pid, R->StaticAddr + Offset, Value) == 0; ++ } ++ ++ bool IsFexTracee(pid_t Pid) { ++ uint64_t Magic = 0; ++ return ReadWord(Pid, offsetof(SharedState, Magic), &Magic) && Magic == SharedState::MagicValue; ++ } ++ ++ bool ReadSlot(pid_t Pid, size_t Offset, uint64_t* Out) { ++ return ReadWord(Pid, Offset, Out); ++ } ++ ++ void MarkDirty(pid_t Pid, uint64_t Mask) { ++ uint64_t Dirty = 0; ++ ReadWord(Pid, offsetof(SharedState, DirtyMask), &Dirty); ++ WriteWord(Pid, offsetof(SharedState, DirtyMask), Dirty | Mask); ++ } ++ ++ constexpr size_t RegOffset(unsigned Index) { ++ return offsetof(SharedState, Regs) + Index * sizeof(uint64_t); ++ } ++ ++ bool ReadDebugReg(pid_t Pid, unsigned N, uint64_t* Out) { ++ if (N == 4 || N == 5) { ++ *Out = 0; ++ return true; ++ } ++ if (N > 7) { ++ return false; ++ } ++ return ReadWord(Pid, offsetof(SharedState, DebugRegs) + N * sizeof(uint64_t), Out); ++ } ++ ++ int WriteDebugReg(pid_t Pid, unsigned N, uint64_t Value) { ++ if (N == 4 || N == 5) { ++ return -EIO; ++ } ++ if (N <= 3) { ++ if (!DrAddressValid(Value, 0)) { ++ return -EINVAL; ++ } ++ return WriteWord(Pid, offsetof(SharedState, DebugRegs) + N * sizeof(uint64_t), Value) ? 0 : -ESRCH; ++ } ++ if (N == 6) { ++ return WriteWord(Pid, offsetof(SharedState, DebugRegs) + 6 * sizeof(uint64_t), Value) ? 0 : -ESRCH; ++ } ++ uint64_t Dr[8] {}; ++ for (unsigned I = 0; I < 8; ++I) { ++ if (!ReadWord(Pid, offsetof(SharedState, DebugRegs) + I * sizeof(uint64_t), &Dr[I])) { ++ return -ESRCH; ++ } ++ } ++ if (!Dr7Valid(Dr, Value)) { ++ return -EINVAL; ++ } ++ return WriteWord(Pid, offsetof(SharedState, DebugRegs) + 7 * sizeof(uint64_t), Value) ? 0 : -ESRCH; ++ } ++ ++ Remote* XStateState(pid_t Pid) { ++ std::lock_guard lk(RemotesLock); ++ Remote* R = Lookup(Pid); ++ if (R && !R->XStateValid) { ++ R->XStateValid = true; ++ } ++ return R; ++ } ++ ++ Remote* FpState(pid_t Pid) { ++ std::lock_guard lk(RemotesLock); ++ Remote* R = Lookup(Pid); ++ if (R && !R->FpValid) { ++ const uint16_t Fcw = 0x37f; ++ const uint32_t Mxcsr = 0x1f80, MxcsrMask = 0xffff; ++ std::memcpy(&R->FpRegs[0], &Fcw, sizeof(Fcw)); ++ std::memcpy(&R->FpRegs[24], &Mxcsr, sizeof(Mxcsr)); ++ std::memcpy(&R->FpRegs[28], &MxcsrMask, sizeof(MxcsrMask)); ++ R->FpValid = true; ++ } ++ return R; ++ } ++} ++ ++ ++bool IsAttached() { ++ return Current->Attached != 0; ++} ++ ++bool WantsSyscallStops() { ++ return Current->SyscallStops && IsMainThread(); ++} ++ ++uint64_t SyscallEntryStop(FEXCore::Core::CpuStateFrame* Frame, uint64_t Nr, const uint64_t Args[6]) { ++ uint64_t Regs[NumUserRegs]; ++ if (Previous.Open) { ++ BuildRegs(Frame, Previous.Nr, false, 0, Regs); ++ Stop(Previous.Nr, Previous.Args, false, 0, Regs); ++ } ++ BuildRegs(Frame, Nr, true, 0, Regs); ++ Stop(Nr, Args, true, 0, Regs); ++ ApplyTracerWrites(Frame, true); ++ ++ const uint64_t NewNr = Frame->State.gregs[FEXCore::X86State::REG_RAX]; ++ Previous.Open = Current->SyscallStops != 0; ++ Previous.Nr = NewNr; ++ std::copy(Args, Args + 6, Previous.Args); ++ return NewNr; ++} ++ ++uint64_t SyscallExitStop(FEXCore::Core::CpuStateFrame* Frame, uint64_t Nr, const uint64_t Args[6], uint64_t Result) { ++ uint64_t Regs[NumUserRegs]; ++ BuildRegs(Frame, Nr, false, Result, Regs); ++ Stop(Nr, Args, false, Result, Regs); ++ const uint64_t Override = ApplyTracerWrites(Frame, false); ++ Previous.Open = false; ++ return Override != NoOverride ? Override : Result; ++} ++ ++void OnForkedChild(bool SharesAddressSpace) { ++ if (SharesAddressSpace) { ++ return; ++ } ++ Current = &StaticState; ++ StaticState.SyscallStops = 0; ++ StaticState.Attached = 0; ++ StaticState.Pending = 0; ++ Previous.Open = false; ++} ++ ++void ApplyPendingFlush(FEXCore::Core::CpuStateFrame* Frame) { ++ SharedState& S = *Current; ++ if (S.FlushLen) { ++ const uint64_t Addr = S.FlushAddr; ++ const uint64_t Len = S.FlushLen; ++ S.FlushLen = 0; ++ FEX::HLE::_SyscallHandler->InvalidateGuestCodeRange(Frame->Thread, Addr, Len); ++ } ++} ++ ++uint64_t TakePendingRip() { ++ const uint64_t Rip = PendingRip; ++ PendingRip = 0; ++ return Rip; ++} ++ ++bool TryGuestSignalStop(FEXCore::Core::CpuStateFrame* Frame, int Signal) { ++ if (Signal != SIGTRAP && Signal != SIGSEGV) { ++ return false; ++ } ++ if (!Frame->SynchronousFaultData.FaultToTopAndGeneratedException || !Current->Attached || !IsMainThread()) { ++ return false; ++ } ++ ++ uint64_t Regs[NumUserRegs]; ++ const uint64_t NoArgs[6] {}; ++ BuildRegs(Frame, ~0ULL, false, Frame->State.gregs[FEXCore::X86State::REG_RAX], Regs); ++ Regs[Rip] = Frame->State.rip; ++ ++ Current->SignalNumber = static_cast(Signal); ++ Stop(~0ULL, NoArgs, false, 0, Regs); ++ Current->SignalNumber = 0; ++ ++ const uint64_t Override = ApplyTracerWrites(Frame, false); ++ if (Override != NoOverride) { ++ Frame->State.gregs[FEXCore::X86State::REG_RAX] = Override; ++ } ++ if (const uint64_t NewRip = TakePendingRip()) { ++ Frame->State.rip = NewRip; ++ } ++ return true; ++} ++ ++void RecordExecPath(const std::string& GuestPath) { ++ if (!Current->Attached) { ++ return; ++ } ++ const size_t Len = std::min(GuestPath.size(), sizeof(Current->ExePath) - 1); ++ std::memcpy(Current->ExePath, GuestPath.data(), Len); ++ Current->ExePath[Len] = 0; ++} ++ ++ ++std::optional TraceeExePath(pid_t Pid) { ++ if (Pid <= 0 || Pid == ::getpid()) { ++ return std::nullopt; ++ } ++ std::lock_guard lk(RemotesLock); ++ auto It = ExePaths.find(Pid); ++ return It != ExePaths.end() ? std::optional(It->second) : std::nullopt; ++} ++ ++bool FixupWaitStatus(pid_t Pid, int* Status) { ++ if (!Status || Pid <= 0) { ++ return false; ++ } ++ const int St = *Status; ++ ++ if (WIFEXITED(St) || WIFSIGNALED(St)) { ++ Forget(Pid, true); ++ return false; ++ } ++ if (!WIFSTOPPED(St)) { ++ return false; ++ } ++ ++ if ((St >> 16) == 0 && (WSTOPSIG(St) == SIGTRAP || WSTOPSIG(St) == SIGSEGV) && IsFexTracee(Pid)) { ++ HostPtrace(PTRACE_CONT, Pid, nullptr, reinterpret_cast(static_cast(WSTOPSIG(St)))); ++ return true; ++ } ++ ++ if ((St >> 16) == 0 && WSTOPSIG(St) == SIGBUS && IsFexTracee(Pid)) { ++ siginfo_t Info {}; ++ if (HostPtrace(PTRACE_GETSIGINFO, Pid, nullptr, &Info) == 0 && Info.si_code == BUS_ADRALN) { ++ HostPtrace(PTRACE_CONT, Pid, nullptr, reinterpret_cast(static_cast(SIGBUS))); ++ return true; ++ } ++ } ++ ++ if ((St >> 16) == 0 && WSTOPSIG(St) == SIGPROF && IsFexTracee(Pid)) { ++ HostPtrace(PTRACE_CONT, Pid, nullptr, nullptr); ++ return true; ++ } ++ ++ if ((St >> 16) == X86_PTRACE_EVENT_EXEC) { ++ CaptureExecPath(Pid); ++ Forget(Pid, false); ++ } ++ ++ if (WSTOPSIG(St) == SIGSTOP) { ++ uint64_t Pending = 0; ++ if (ReadWord(Pid, offsetof(SharedState, Pending), &Pending) && Pending) { ++ uint64_t Signal = 0; ++ ReadWord(Pid, offsetof(SharedState, SignalNumber), &Signal); ++ *Status = (St & ~0xff00) | (static_cast(Signal ? Signal : (SIGTRAP | 0x80)) << 8); ++ } ++ } ++ return false; ++} ++ ++bool HandleRequest(int Request, pid_t Pid, void* Addr, void* Data, uint64_t* Result) { ++ switch (Request) { ++ case PTRACE_TRACEME: ++ *Result = HostPtrace(Request, Pid, Addr, Data); ++ if (*Result == 0) { ++ PublishSharedPage(); ++ Current->Attached = 1; ++ } ++ return true; ++ ++ case PTRACE_KILL: ++ case PTRACE_SEIZE: ++ case PTRACE_INTERRUPT: ++ case PTRACE_SETOPTIONS: ++ case PTRACE_GETEVENTMSG: ++ case PTRACE_SINGLESTEP: ++ case PTRACE_GETSIGINFO: *Result = HostPtrace(Request, Pid, Addr, Data); return true; ++ ++ case PTRACE_POKETEXT: ++ case PTRACE_POKEDATA: { ++ *Result = HostPtrace(Request, Pid, Addr, Data); ++ if (*Result == 0 && IsFexTracee(Pid)) { ++ const uint64_t Lo = reinterpret_cast(Addr) & ~0xfffULL; ++ const uint64_t Hi = Lo + 0x2000; ++ uint64_t OldAddr = 0, OldLen = 0; ++ ReadWord(Pid, offsetof(SharedState, FlushAddr), &OldAddr); ++ ReadWord(Pid, offsetof(SharedState, FlushLen), &OldLen); ++ uint64_t NewLo = Lo, NewHi = Hi; ++ if (OldLen) { ++ NewLo = std::min(OldAddr, Lo); ++ NewHi = std::max(OldAddr + OldLen, Hi); ++ } ++ WriteWord(Pid, offsetof(SharedState, FlushAddr), NewLo); ++ WriteWord(Pid, offsetof(SharedState, FlushLen), NewHi - NewLo); ++ } ++ return true; ++ } ++ ++ case PTRACE_CONT: ++ case PTRACE_SYSCALL: { ++ uint64_t Magic = 0; ++ if (ReadWord(Pid, offsetof(SharedState, Magic), &Magic) && Magic == SharedState::MagicValue) { ++ WriteWord(Pid, offsetof(SharedState, SyscallStops), Request == PTRACE_SYSCALL ? 1 : 0); ++ WriteWord(Pid, offsetof(SharedState, Attached), 1); ++ } ++ *Result = HostPtrace(PTRACE_CONT, Pid, Addr, Data); ++ return true; ++ } ++ ++ case PTRACE_DETACH: { ++ if (IsFexTracee(Pid)) { ++ WriteWord(Pid, offsetof(SharedState, SyscallStops), 0); ++ WriteWord(Pid, offsetof(SharedState, Attached), 0); ++ } ++ *Result = HostPtrace(Request, Pid, Addr, Data); ++ Forget(Pid, false); ++ return true; ++ } ++ ++ case PTRACE_PEEKUSER: { ++ const uintptr_t Off = reinterpret_cast(Addr); ++ if ((Off % sizeof(uint64_t)) != 0 || Off >= UserStructSize) { ++ *Result = static_cast(-EIO); ++ return true; ++ } ++ uint64_t V = 0; ++ if (Off < NumUserRegs * sizeof(uint64_t)) { ++ if (!ReadSlot(Pid, RegOffset(Off / 8), &V)) { ++ *Result = static_cast(-ESRCH); ++ return true; ++ } ++ } else if (Off >= UserDebugRegByteOffset && Off < UserDebugRegByteEnd) { ++ if (!ReadDebugReg(Pid, static_cast((Off - UserDebugRegByteOffset) / sizeof(uint64_t)), &V)) { ++ *Result = static_cast(-ESRCH); ++ return true; ++ } ++ } ++ *static_cast(Data) = V; ++ *Result = 0; ++ return true; ++ } ++ ++ case PTRACE_POKEUSER: { ++ const uintptr_t Off = reinterpret_cast(Addr); ++ if ((Off % sizeof(uint64_t)) != 0 || Off >= UserStructSize) { ++ *Result = static_cast(-EIO); ++ return true; ++ } ++ if (Off < NumUserRegs * sizeof(uint64_t)) { ++ if (!WriteWord(Pid, RegOffset(Off / 8), reinterpret_cast(Data))) { ++ *Result = static_cast(-ESRCH); ++ return true; ++ } ++ MarkDirty(Pid, 1ULL << (Off / 8)); ++ *Result = 0; ++ return true; ++ } ++ if (Off >= UserDebugRegByteOffset && Off < UserDebugRegByteEnd) { ++ *Result = static_cast(WriteDebugReg(Pid, static_cast((Off - UserDebugRegByteOffset) / sizeof(uint64_t)), reinterpret_cast(Data))); ++ return true; ++ } ++ *Result = static_cast(-EIO); ++ return true; ++ } ++ ++ case X86_PTRACE_GETREGS: { ++ for (unsigned i = 0; i < NumUserRegs; ++i) { ++ uint64_t V = 0; ++ if (!ReadSlot(Pid, RegOffset(i), &V)) { ++ *Result = static_cast(-ESRCH); ++ return true; ++ } ++ static_cast(Data)[i] = V; ++ } ++ *Result = 0; ++ return true; ++ } ++ ++ case X86_PTRACE_SETREGS: { ++ uint64_t Mask = 0; ++ for (unsigned i = 0; i < NumUserRegs; ++i) { ++ if (!WriteWord(Pid, RegOffset(i), static_cast(Data)[i])) { ++ *Result = static_cast(-ESRCH); ++ return true; ++ } ++ Mask |= 1ULL << i; ++ } ++ MarkDirty(Pid, Mask); ++ *Result = 0; ++ return true; ++ } ++ ++ case PTRACE_GETREGSET: ++ case PTRACE_SETREGSET: { ++ const auto NtType = reinterpret_cast(Addr); ++ auto* Iov = static_cast(Data); ++ if (!Iov) { ++ return false; ++ } ++ const bool Get = Request == PTRACE_GETREGSET; ++ ++ if (NtType == NT_PRSTATUS) { ++ if (Get) { ++ uint64_t Image[NumUserRegs]; ++ for (unsigned i = 0; i < NumUserRegs; ++i) { ++ if (!ReadSlot(Pid, RegOffset(i), &Image[i])) { ++ *Result = static_cast(-ESRCH); ++ return true; ++ } ++ } ++ const size_t Len = std::min(Iov->iov_len, sizeof(Image)); ++ std::memcpy(Iov->iov_base, Image, Len); ++ Iov->iov_len = Len; ++ } else { ++ const size_t Slots = std::min(Iov->iov_len / sizeof(uint64_t), NumUserRegs); ++ uint64_t Mask = 0; ++ for (size_t i = 0; i < Slots; ++i) { ++ if (!WriteWord(Pid, RegOffset(i), static_cast(Iov->iov_base)[i])) { ++ *Result = static_cast(-ESRCH); ++ return true; ++ } ++ Mask |= 1ULL << i; ++ } ++ MarkDirty(Pid, Mask); ++ Iov->iov_len = NumUserRegs * sizeof(uint64_t); ++ } ++ *Result = 0; ++ return true; ++ } ++ ++ if (NtType == NT_PRFPREG) { ++ Remote* R = FpState(Pid); ++ if (!R) { ++ *Result = static_cast(-ESRCH); ++ return true; ++ } ++ const size_t Len = std::min(Iov->iov_len, R->FpRegs.size()); ++ if (Get) { ++ std::memcpy(Iov->iov_base, R->FpRegs.data(), Len); ++ } else { ++ std::memcpy(R->FpRegs.data(), Iov->iov_base, Len); ++ } ++ Iov->iov_len = Len; ++ *Result = 0; ++ return true; ++ } ++ ++ if (NtType == NT_X86_XSTATE) { ++ Remote* R = XStateState(Pid); ++ if (!R) { ++ *Result = static_cast(-ESRCH); ++ return true; ++ } ++ const size_t Len = std::min(Iov->iov_len, R->XState.size()); ++ if (Get) { ++ std::memcpy(Iov->iov_base, R->XState.data(), Len); ++ } else { ++ std::memcpy(R->XState.data(), Iov->iov_base, Len); ++ } ++ Iov->iov_len = Len; ++ *Result = 0; ++ return true; ++ } ++ ++ *Result = static_cast(-EINVAL); ++ return true; ++ } ++ ++ default: return false; ++ } ++} ++ ++} +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/PtraceEmu.h b/Source/Tools/LinuxEmulation/LinuxSyscalls/PtraceEmu.h +new file mode 100644 +index 000000000..59194979a +--- /dev/null ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/PtraceEmu.h +@@ -0,0 +1,63 @@ ++// SPDX-License-Identifier: MIT ++#pragma once ++ ++#include ++#include ++#include ++#include ++ ++namespace FEXCore::Core { ++struct CpuStateFrame; ++} ++ ++namespace FEX::HLE::PtraceEmu { ++ ++constexpr unsigned NumUserRegs = 27; ++ ++struct SharedState { ++ static constexpr uint64_t MagicValue = 0xFE8E5E57CAFE0001ULL; ++ ++ volatile uint64_t Magic; ++ volatile uint64_t SyscallStops; ++ volatile uint64_t Attached; ++ volatile uint64_t Pending; ++ volatile uint64_t PendingIsEntry; ++ volatile uint64_t PendingNr; ++ volatile uint64_t PendingArgs[6]; ++ volatile uint64_t PendingRet; ++ volatile uint64_t Regs[NumUserRegs]; ++ volatile uint64_t DebugRegs[8]; ++ volatile uint64_t DirtyMask; ++ volatile uint64_t SignalNumber; ++ volatile uint64_t FlushAddr; ++ volatile uint64_t FlushLen; ++ char ExePath[1024]; ++}; ++ ++ ++bool WantsSyscallStops(); ++ ++uint64_t SyscallEntryStop(FEXCore::Core::CpuStateFrame* Frame, uint64_t Nr, const uint64_t Args[6]); ++ ++uint64_t SyscallExitStop(FEXCore::Core::CpuStateFrame* Frame, uint64_t Nr, const uint64_t Args[6], uint64_t Result); ++ ++void OnForkedChild(bool SharesAddressSpace); ++ ++void ApplyPendingFlush(FEXCore::Core::CpuStateFrame* Frame); ++ ++uint64_t TakePendingRip(); ++ ++bool TryGuestSignalStop(FEXCore::Core::CpuStateFrame* Frame, int Signal); ++ ++void RecordExecPath(const std::string& GuestPath); ++ ++bool IsAttached(); ++ ++ ++bool HandleRequest(int Request, pid_t Pid, void* Addr, void* Data, uint64_t* Result); ++ ++bool FixupWaitStatus(pid_t Pid, int* Status); ++ ++std::optional TraceeExePath(pid_t Pid); ++ ++} +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SMCHotPages.h b/Source/Tools/LinuxEmulation/LinuxSyscalls/SMCHotPages.h +new file mode 100644 +index 000000000..3f36e79fd +--- /dev/null ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/SMCHotPages.h +@@ -0,0 +1,90 @@ ++// SPDX-License-Identifier: MIT ++#pragma once ++ ++#include ++#include ++#include ++#include ++ ++namespace FEX::HLE { ++ ++class SMCHotPageTracker final { ++public: ++ static constexpr uint64_t PageShift = 12; ++ ++ bool RecordFault(uint64_t Address, uint32_t FaultThreshold) { ++ if (!FaultThreshold) { ++ return false; ++ } ++ const uint64_t Page = Address >> PageShift; ++ auto& Slot = Counters[Hash(Page) & (CounterSlots - 1)]; ++ ++ uint64_t Old = Slot.load(std::memory_order_relaxed); ++ uint64_t New; ++ do { ++ const uint64_t Count = (Old >> CountBits) == Page ? (Old & CountMask) + 1 : 1; ++ New = (Page << CountBits) | (Count < CountMask ? Count : CountMask); ++ } while (!Slot.compare_exchange_weak(Old, New, std::memory_order_relaxed)); ++ ++ return (New & CountMask) == FaultThreshold && MakeHot(Page); ++ } ++ ++ bool MarkHot(uint64_t Address) { ++ return MakeHot(Address >> PageShift); ++ } ++ ++ bool IsHot(uint64_t Address) const { ++ if (HotCount.load(std::memory_order_relaxed) == 0) { ++ return false; ++ } ++ ++ const uint64_t Key = (Address >> PageShift) + 1; ++ for (size_t i = 0, Idx = Hash(Key - 1); i < HotSlots; ++i, ++Idx) { ++ const uint64_t Entry = Hot[Idx & (HotSlots - 1)].load(std::memory_order_relaxed); ++ if (Entry == Key) { ++ return true; ++ } ++ if (Entry == 0) { ++ return false; ++ } ++ } ++ return false; ++ } ++ ++private: ++ static constexpr size_t CounterSlots = 4096; ++ static constexpr size_t HotSlots = 2048; ++ static constexpr unsigned CountBits = 20; ++ static constexpr uint64_t CountMask = (1ULL << CountBits) - 1; ++ static_assert((CounterSlots & (CounterSlots - 1)) == 0 && (HotSlots & (HotSlots - 1)) == 0); ++ ++ static size_t Hash(uint64_t Page) { ++ return static_cast((Page * 0x9E3779B97F4A7C15ULL) >> 40); ++ } ++ ++ bool MakeHot(uint64_t Page) { ++ if (HotCount.load(std::memory_order_relaxed) >= HotSlots / 4 * 3) { ++ return false; ++ } ++ ++ const uint64_t Key = Page + 1; ++ for (size_t i = 0, Idx = Hash(Page); i < HotSlots; ++i, ++Idx) { ++ auto& Entry = Hot[Idx & (HotSlots - 1)]; ++ uint64_t Expected = 0; ++ if (Entry.compare_exchange_strong(Expected, Key, std::memory_order_relaxed)) { ++ HotCount.fetch_add(1, std::memory_order_relaxed); ++ return true; ++ } ++ if (Expected == Key) { ++ return false; ++ } ++ } ++ return false; ++ } ++ ++ std::array, CounterSlots> Counters {}; ++ std::array, HotSlots> Hot {}; ++ std::atomic HotCount {}; ++}; ++ ++} +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SamplingProfiler.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/SamplingProfiler.cpp +new file mode 100644 +index 000000000..abc3284a3 +--- /dev/null ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/SamplingProfiler.cpp +@@ -0,0 +1,278 @@ ++// SPDX-License-Identifier: MIT ++#include "LinuxSyscalls/SamplingProfiler.h" ++#include "LinuxSyscalls/SignalDelegator.h" ++#include "LinuxSyscalls/PtraceEmu.h" ++#include "ArchHelpers/MContext.h" ++ ++#include ++#include ++#include ++#include ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++namespace FEX::HLE { ++namespace { ++ struct Sample { ++ uint64_t HostPC; ++ uint64_t Info; ++ }; ++ constexpr size_t MaxSamples = 1 << 18; ++ std::atomic RecordsPtr {nullptr}; ++ Sample* Records = nullptr; ++ std::atomic Count {0}; ++ ++ struct SnapRecord { ++ uint64_t Tid; ++ uint64_t HostPC; ++ uint64_t Rip; ++ uint64_t FutexWord; ++ uint64_t FutexExpected; ++ uint64_t FutexAddr; ++ uint64_t Gregs[16]; ++ uint64_t Stack[138]; ++ }; ++ static_assert(sizeof(SnapRecord) == 160 * 8); ++ constexpr size_t MaxSnaps = 1024; ++ SnapRecord* Snaps = nullptr; ++ std::atomic SnapCount {0}; ++ std::atomic SnapMode {false}; ++ bool ExternalMode = false; ++ FEX::HLE::SignalDelegator* Delegator = nullptr; ++ std::atomic ExternalOpen {false}; ++ ++ void OpenExternalSnaps() { ++ if (ExternalOpen.exchange(true)) { ++ return; ++ } ++ char Path[64]; ++ snprintf(Path, sizeof(Path), "/dev/shm/fex-%d-snap", static_cast(getpid())); ++ const int fd = open(Path, O_RDWR | O_CREAT | O_TRUNC | O_CLOEXEC, 0600); ++ if (fd < 0 || ftruncate(fd, sizeof(SnapRecord) * MaxSnaps) != 0) { ++ return; ++ } ++ void* Map = mmap(nullptr, sizeof(SnapRecord) * MaxSnaps, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); ++ close(fd); ++ if (Map != MAP_FAILED) { ++ Snaps = static_cast(Map); ++ } ++ } ++ ++ bool IsInteresting(pid_t Tid) { ++ static thread_local std::unordered_map Last; ++ char Path[64]; ++ snprintf(Path, sizeof(Path), "/proc/self/task/%d/stat", Tid); ++ FILE* F = fopen(Path, "r"); ++ if (!F) { ++ return false; ++ } ++ char Buf[512]; ++ const bool Ok = fgets(Buf, sizeof(Buf), F) != nullptr; ++ fclose(F); ++ if (!Ok) { ++ return false; ++ } ++ const char* P = strrchr(Buf, ')'); ++ unsigned long Ut = 0, St = 0; ++ if (!P || sscanf(P + 2, "%*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %lu %lu", &Ut, &St) != 2) { ++ return false; ++ } ++ auto& L = Last[Tid]; ++ const bool Busy = (Ut + St) > L; ++ L = Ut + St; ++ return Busy; ++ } ++ ++ bool OpenRecords(pid_t Pid) { ++ if (Records) { ++ return true; ++ } ++ const std::string Path = "/dev/shm/fex-" + std::to_string(Pid) + "-samples"; ++ const int fd = open(Path.c_str(), O_RDWR | O_CREAT | O_TRUNC | O_CLOEXEC, 0600); ++ if (fd < 0 || ftruncate(fd, sizeof(Sample) * MaxSamples) != 0) { ++ return false; ++ } ++ void* Map = mmap(nullptr, sizeof(Sample) * MaxSamples, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); ++ close(fd); ++ if (Map == MAP_FAILED) { ++ return false; ++ } ++ Records = static_cast(Map); ++ return true; ++ } ++ ++ void TakeSnapshot(pid_t Pid) { ++ if (!Snaps) { ++ const std::string Path = "/dev/shm/fex-" + std::to_string(Pid) + "-snap"; ++ const int fd = open(Path.c_str(), O_RDWR | O_CREAT | O_TRUNC | O_CLOEXEC, 0600); ++ if (fd < 0 || ftruncate(fd, sizeof(SnapRecord) * MaxSnaps) != 0) { ++ return; ++ } ++ void* Map = mmap(nullptr, sizeof(SnapRecord) * MaxSnaps, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); ++ close(fd); ++ if (Map == MAP_FAILED) { ++ return; ++ } ++ Snaps = static_cast(Map); ++ } ++ memset(Snaps, 0, sizeof(SnapRecord) * MaxSnaps); ++ SnapCount = 0; ++ SnapMode = true; ++ if (DIR* D = opendir("/proc/self/task")) { ++ while (auto* E = readdir(D)) { ++ const pid_t Tid = atoi(E->d_name); ++ if (Tid > 0 && Tid != static_cast(syscall(SYS_gettid))) { ++ syscall(SYS_tgkill, Pid, Tid, SIGPROF); ++ } ++ } ++ closedir(D); ++ } ++ usleep(700000); ++ SnapMode = false; ++ } ++ ++ void* SamplerThread(void* Arg) { ++ const uint32_t Hz = static_cast(reinterpret_cast(Arg) & 0xffff); ++ const bool All = (reinterpret_cast(Arg) >> 16) != 0; ++ const pid_t Pid = getpid(); ++ const std::string Trigger = "/dev/shm/fex-" + std::to_string(Pid) + "-sample-on"; ++ const std::string SnapTrigger = "/dev/shm/fex-" + std::to_string(Pid) + "-snapshot"; ++ for (;;) { ++ if (access(SnapTrigger.c_str(), F_OK) == 0) { ++ unlink(SnapTrigger.c_str()); ++ TakeSnapshot(Pid); ++ continue; ++ } ++ if (access(Trigger.c_str(), F_OK) != 0) { ++ usleep(100000); ++ continue; ++ } ++ if (!OpenRecords(Pid)) { ++ usleep(100000); ++ continue; ++ } ++ usleep(1000000 / Hz); ++ if (FEX::HLE::PtraceEmu::IsAttached()) { ++ continue; ++ } ++ if (All) { ++ if (DIR* D = opendir("/proc/self/task")) { ++ while (auto* E = readdir(D)) { ++ const pid_t Tid = atoi(E->d_name); ++ if (Tid > 0 && Tid != static_cast(syscall(SYS_gettid)) && IsInteresting(Tid)) { ++ syscall(SYS_tgkill, Pid, Tid, SIGPROF); ++ } ++ } ++ closedir(D); ++ } ++ } else { ++ syscall(SYS_tgkill, Pid, Pid, SIGPROF); ++ } ++ } ++ return nullptr; ++ } ++} ++ ++void StartSamplingProfiler(FEX::HLE::SignalDelegator* Signals, uint32_t Hz, bool AllThreads, bool External) { ++ if (!Hz) { ++ return; ++ } ++ ExternalMode = External; ++ Delegator = Signals; ++ Signals->RegisterHostSignalHandler( ++ SIGPROF, ++ [](FEXCore::Core::InternalThreadState* Thread, int, void*, void* UContext) { ++ if (ExternalMode) { ++ OpenExternalSnaps(); ++ } ++ if (ExternalMode || SnapMode.load(std::memory_order_relaxed)) { ++ uint32_t SIdx = SnapCount.fetch_add(1, std::memory_order_relaxed); ++ const uint32_t Seq = SIdx; ++ if (ExternalMode) { ++ SIdx %= MaxSnaps; ++ } ++ if (Snaps && SIdx < MaxSnaps) { ++ SnapRecord& R = Snaps[SIdx]; ++ R.Tid = static_cast(syscall(SYS_gettid)); ++ R.HostPC = ArchHelpers::Context::GetPc(UContext); ++ if (Thread) { ++ const auto& St = Thread->CurrentFrame->State; ++ R.Rip = St.rip; ++ for (unsigned i = 0; i < 16; ++i) { ++ R.Gregs[i] = St.gregs[i]; ++ } ++ iovec Local {R.Stack, sizeof(R.Stack)}; ++ iovec Remote {reinterpret_cast(St.gregs[FEXCore::X86State::REG_RSP]), sizeof(R.Stack)}; ++ process_vm_readv(getpid(), &Local, 1, &Remote, 1, 0); ++ ++ const uint64_t Nr = St.gregs[FEXCore::X86State::REG_RAX]; ++ if (Nr == 202 || Nr == 449) { ++ uint64_t Addr = St.gregs[FEXCore::X86State::REG_RDI]; ++ uint64_t Expected = St.gregs[FEXCore::X86State::REG_RDX]; ++ if (Nr == 449) { ++ uint64_t Waiter[3] {}; ++ iovec WL {Waiter, sizeof(Waiter)}; ++ iovec WR {reinterpret_cast(Addr), sizeof(Waiter)}; ++ Addr = process_vm_readv(getpid(), &WL, 1, &WR, 1, 0) == static_cast(sizeof(Waiter)) ? Waiter[1] : 0; ++ Expected = Waiter[0]; ++ } ++ uint32_t Word = 0; ++ iovec FL {&Word, sizeof(Word)}; ++ iovec FR {reinterpret_cast(Addr), sizeof(Word)}; ++ if (Addr && process_vm_readv(getpid(), &FL, 1, &FR, 1, 0) == static_cast(sizeof(Word))) { ++ R.FutexWord = (1ULL << 63) | Word; ++ R.FutexExpected = Expected; ++ R.FutexAddr = Addr; ++ } ++ } ++ } ++ if (ExternalMode) { ++ R.FutexWord = 0; ++ R.FutexExpected = Seq; ++ R.FutexAddr = ArchHelpers::Context::GetSp(UContext); ++ if (Thread && Thread->CTX->IsAddressInCodeBuffer(Thread, R.HostPC)) { ++ R.FutexWord = 1; ++ R.Rip = Thread->CTX->RestoreRIPFromHostPC(Thread, R.HostPC); ++ const auto& Cfg = Delegator->GetConfig(); ++ for (size_t i = 0; i < Cfg.SRAGPRCount && i < 16; ++i) { ++ R.Gregs[i] = ArchHelpers::Context::GetArmReg(UContext, Cfg.SRAGPRMapping[i]); ++ } ++ iovec Local {R.Stack, sizeof(R.Stack)}; ++ iovec Remote {reinterpret_cast(R.Gregs[FEXCore::X86State::REG_RSP]), sizeof(R.Stack)}; ++ process_vm_readv(getpid(), &Local, 1, &Remote, 1, 0); ++ } ++ } ++ } ++ return true; ++ } ++ const uint32_t Idx = Count.fetch_add(1, std::memory_order_relaxed); ++ if (Records && Idx < MaxSamples) { ++ Records[Idx] = {ArchHelpers::Context::GetPc(UContext), ++ static_cast(static_cast(syscall(SYS_gettid))) | (Thread ? (Thread->CurrentFrame->State.rip << 32) : 0)}; ++ } ++ return true; ++ }, ++ true); ++ ++ if (External) { ++ return; ++ } ++ pthread_t T; ++ pthread_attr_t Attr; ++ pthread_attr_init(&Attr); ++ pthread_attr_setdetachstate(&Attr, PTHREAD_CREATE_DETACHED); ++ pthread_create(&T, &Attr, SamplerThread, reinterpret_cast(static_cast(Hz | (AllThreads ? 0x10000 : 0)))); ++} ++} +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SamplingProfiler.h b/Source/Tools/LinuxEmulation/LinuxSyscalls/SamplingProfiler.h +new file mode 100644 +index 000000000..b6b433eca +--- /dev/null ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/SamplingProfiler.h +@@ -0,0 +1,13 @@ ++// SPDX-License-Identifier: MIT ++#pragma once ++ ++#include ++ ++namespace FEXCore::Core { ++struct InternalThreadState; ++} ++namespace FEX::HLE { ++class SignalDelegator; ++ ++void StartSamplingProfiler(FEX::HLE::SignalDelegator* Signals, uint32_t Hz, bool AllThreads, bool External = false); ++} +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/Seccomp/SeccompEmulator.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/Seccomp/SeccompEmulator.cpp +index a7dcd128d..830ae3721 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/Seccomp/SeccompEmulator.cpp ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/Seccomp/SeccompEmulator.cpp +@@ -119,6 +119,16 @@ $end_info$ + // TRACE_syscall + // - ptrace unsupported + ++#ifndef PR_SET_SYSCALL_USER_DISPATCH ++#define PR_SET_SYSCALL_USER_DISPATCH 59 ++#define PR_SYS_DISPATCH_OFF 0 ++#define PR_SYS_DISPATCH_ON 1 ++#endif ++#ifndef SYSCALL_DISPATCH_FILTER_ALLOW ++#define SYSCALL_DISPATCH_FILTER_ALLOW 0 ++#define SYSCALL_DISPATCH_FILTER_BLOCK 1 ++#endif ++ + namespace FEX::HLE { + uint64_t SeccompEmulator::Handle(FEXCore::Core::CpuStateFrame* Frame, uint32_t Op, uint32_t flags, void* arg) { + // If seccomp isn't enabled then say so. +@@ -314,6 +324,60 @@ void SeccompEmulator::DeserializeFilters(FEXCore::Core::CpuStateFrame* Frame, in + close(FD); + } + ++void SeccompEmulator::QueueTrapSignal(FEX::HLE::ThreadStateObject* Thread, int Code, uint32_t Errno, uint64_t PostSyscallRIP, ++ uint64_t SyscallNumber, uint32_t Arch) { ++ siginfo_t Info { ++ .si_signo = SIGSYS, ++ .si_errno = static_cast(Errno), ++ .si_code = Code, ++ }; ++ ++ Info.si_call_addr = reinterpret_cast(PostSyscallRIP); ++ Info.si_syscall = SyscallNumber; ++ Info.si_arch = Arch; ++ ++ Thread->SeccompTrapRIP = PostSyscallRIP; ++ ++ SignalDelegation->PrepareForcedGuestSignal(Thread, SIGSYS); ++ SignalDelegation->QueueSignal(::getpid(), ::gettid(), SIGSYS, &Info, true); ++} ++ ++void SeccompEmulator::ForceExitSignal(FEX::HLE::ThreadStateObject* Thread, int Signal) { ++ uint64_t Mask = 1ULL << (Signal - 1); ++ SignalDelegation->GuestSigProcMask(Thread, SIG_UNBLOCK, &Mask, nullptr); ++ SignalDelegation->UninstallHostHandler(Signal); ++ FHU::Syscalls::tgkill(::getpid(), ::gettid(), Signal); ++} ++ ++SeccompEmulator::ExecuteFilterResult ++SeccompEmulator::ExecuteSyscallUserDispatch(FEXCore::Core::CpuStateFrame* Frame, uint64_t JITPC, uint64_t SyscallNumber) { ++ auto Thread = FEX::HLE::ThreadManager::GetStateObjectFromCPUState(Frame); ++ const auto& SUD = Thread->SyscallUserDispatch; ++ const uint64_t PostSyscallRIP = Thread->Thread->CTX->RestoreRIPFromHostPC(Frame->Thread, JITPC) + 2; ++ ++ if (PostSyscallRIP - SUD.Offset < SUD.Length) { ++ return {false, 0}; ++ } ++ ++ if (SUD.Selector) { ++ uint8_t State {}; ++ if (FaultSafeUserMemAccess::CopyFromUser(&State, reinterpret_cast(SUD.Selector), sizeof(State))) { ++ ForceExitSignal(Thread, SIGSEGV); ++ return {true, SyscallNumber}; ++ } ++ if (State == SYSCALL_DISPATCH_FILTER_ALLOW) { ++ return {false, 0}; ++ } ++ if (State != SYSCALL_DISPATCH_FILTER_BLOCK) { ++ ForceExitSignal(Thread, SIGSYS); ++ return {true, SyscallNumber}; ++ } ++ } ++ ++ QueueTrapSignal(Thread, 2 , 0, PostSyscallRIP, SyscallNumber, Is64BitMode() ? AUDIT_ARCH_X86_64 : AUDIT_ARCH_I386); ++ return {true, SyscallNumber}; ++} ++ + SeccompEmulator::ExecuteFilterResult + SeccompEmulator::ExecuteFilter(FEXCore::Core::CpuStateFrame* Frame, uint64_t JITPC, FEX::HLE::SyscallArguments* Args) { + if (!HasFilter(Frame)) { +@@ -330,6 +394,8 @@ SeccompEmulator::ExecuteFilter(FEXCore::Core::CpuStateFrame* Frame, uint64_t JIT + ::prctl(PR_SET_NO_NEW_PRIVS, 1L, 0, 0, 0); + } + ++ const uint64_t PostSyscallRIP = RIP + 2; ++ + const auto Arch = Is64BitMode() ? AUDIT_ARCH_X86_64 : AUDIT_ARCH_I386; + bool ShouldLog {}; + uint32_t SeccompResult {}; +@@ -425,18 +491,9 @@ SeccompEmulator::ExecuteFilter(FEXCore::Core::CpuStateFrame* Frame, uint64_t JIT + break; + } + case SECCOMP_RET_TRAP: { +- siginfo_t Info { +- .si_signo = SIGSYS, +- .si_errno = static_cast(DataMasked), +- .si_code = 1, // SYS_SECCOMP +- }; +- +- Info.si_call_addr = reinterpret_cast(RIP); +- Info.si_syscall = Args->Argument[0]; +- Info.si_arch = Arch; ++ QueueTrapSignal(Thread, 1 , DataMasked, PostSyscallRIP, Args->Argument[0], Arch); + +- SignalDelegation->QueueSignal(::getpid(), ::gettid(), SIGSYS, &Info, true); +- break; ++ return {true, Args->Argument[0]}; + } + case SECCOMP_RET_ERRNO: { + // errno return is clamped. +@@ -671,7 +728,8 @@ uint64_t SeccompEmulator::SetModeFilter(FEXCore::Core::CpuStateFrame* Frame, uin + return -EINVAL; + } + +- if (!prog) { ++ sock_fprog UserProg; ++ if (FaultSafeUserMemAccess::CopyFromUser(&UserProg, prog, sizeof(UserProg))) { + return -EFAULT; + } + +@@ -680,12 +738,22 @@ uint64_t SeccompEmulator::SetModeFilter(FEXCore::Core::CpuStateFrame* Frame, uin + return -EACCES; + } + +- if (prog->len > BPF_MAXINSNS || prog->len == 0) { ++ if (UserProg.len > BPF_MAXINSNS || UserProg.len == 0) { + // operation specified SECCOMP_SET_MODE_FILTER, but the filter program pointed to by args was not valid or the length of the filter + // program was zero or exceeded BPF_MAXINSNS (4096) instructions. + return -EINVAL; + } + ++ fextl::vector Instructions(UserProg.len); ++ if (FaultSafeUserMemAccess::CopyFromUser(Instructions.data(), UserProg.filter, UserProg.len * sizeof(sock_filter))) { ++ return -EFAULT; ++ } ++ const sock_fprog LocalProg { ++ .len = UserProg.len, ++ .filter = Instructions.data(), ++ }; ++ prog = &LocalProg; ++ + // Don't interrupt me while I'm jitting. + auto lk = FEXCore::MaskSignalsAndLockMutex(FilterMutex); + +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/Seccomp/SeccompEmulator.h b/Source/Tools/LinuxEmulation/LinuxSyscalls/Seccomp/SeccompEmulator.h +index a4c7b70e0..31b489216 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/Seccomp/SeccompEmulator.h ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/Seccomp/SeccompEmulator.h +@@ -61,6 +61,8 @@ public: + }; + ExecuteFilterResult ExecuteFilter(FEXCore::Core::CpuStateFrame* Frame, uint64_t JITPC, FEX::HLE::SyscallArguments* Args); + ++ ExecuteFilterResult ExecuteSyscallUserDispatch(FEXCore::Core::CpuStateFrame* Frame, uint64_t JITPC, uint64_t SyscallNumber); ++ + bool HasFilter(FEXCore::Core::CpuStateFrame* Frame) const { + auto Thread = FEX::HLE::ThreadManager::GetStateObjectFromCPUState(Frame); + return !Thread->Filters.empty(); +@@ -101,6 +103,9 @@ private: + const sock_fprog* GetStrictModeFilter() const; + void KillProcess(ThreadStateObject* Thread); + void KillThread(FEXCore::Core::CpuStateFrame* Thread); ++ void QueueTrapSignal(FEX::HLE::ThreadStateObject* Thread, int Code, uint32_t Errno, uint64_t PostSyscallRIP, uint64_t SyscallNumber, ++ uint32_t Arch); ++ void ForceExitSignal(FEX::HLE::ThreadStateObject* Thread, int Signal); + + // Multiple filter instruction count penalty. + // When multiple filters are installed there is a penalty per filter counted towards the maximum number of instructions. +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp +index e8e04b056..87b890e19 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp +@@ -8,6 +8,8 @@ $end_info$ + + #include "LinuxSyscalls/SignalDelegator.h" + #include "LinuxSyscalls/Syscalls.h" ++#include "LinuxSyscalls/PtraceEmu.h" ++#include "LinuxSyscalls/SignalTrace.h" + + #include + #include +@@ -219,6 +221,10 @@ ArchHelpers::Context::ContextBackup* SignalDelegator::StoreThreadState(FEXCore:: + Context->UContextLocation = 0; + Context->SigInfoLocation = 0; + Context->InSyscallInfo = 0; ++ Context->ClearedSyscallInfo = 0; ++ Context->GuestSignalMask = 0; ++ Context->SeccompTrapRIP = 0; ++ Context->SavedJITStackSP = 0; + + // Store fault to top status and then reset it + Context->FaultToTopAndGeneratedException = Thread->CurrentFrame->SynchronousFaultData.FaultToTopAndGeneratedException; +@@ -227,6 +233,8 @@ ArchHelpers::Context::ContextBackup* SignalDelegator::StoreThreadState(FEXCore:: + return Context; + } + ++static void CheckForPendingSignals(const FEX::HLE::ThreadStateObject* Thread); ++ + void SignalDelegator::RestoreThreadState(FEXCore::Core::InternalThreadState* Thread, void* ucontext, RestoreType Type) { + uint64_t OldSP {}; + if (Type == RestoreType::TYPE_PAUSE) [[unlikely]] { +@@ -315,8 +323,36 @@ void SignalDelegator::RestoreThreadState(FEXCore::Core::InternalThreadState* Thr + uintptr_t NewSP = OldSP; + auto Context = reinterpret_cast(NewSP); + ++ if (Type != RestoreType::TYPE_PAUSE) { ++ auto ThreadObject = FEX::HLE::ThreadManager::GetStateObjectFromFEXCoreThread(Thread); ++ for (size_t i = ThreadObject->TrapSignalFrameCount; i > 0; --i) { ++ if (ThreadObject->TrapSignalFrames[i - 1].ContextBackup == NewSP) { ++ ThreadObject->TrapSignalFrameCount = i - 1; ++ break; ++ } ++ } ++ } ++ + // Restore host state + ArchHelpers::Context::RestoreContext(ucontext, Context); ++ Thread->CurrentFrame->InSyscallInfo = ArchHelpers::Context::SavedSyscallInfo(Context); ++ ++ { ++ auto ThreadObject = FEX::HLE::ThreadManager::GetStateObjectFromFEXCoreThread(Thread); ++ SigTrace::Log(ThreadObject->ThreadInfo.TID, SigTrace::SigReturn, 0, Thread->CurrentFrame->State.gregs[FEXCore::X86State::REG_RSP], ++ Context->GuestSignalMask); ++ if (Type != RestoreType::TYPE_PAUSE && SignalMaskFix()) { ++ uint64_t NewGuestMask = Context->GuestSignalMask; ++ if (Is64BitMode && Context->UContextLocation) { ++ auto* GuestUContext = reinterpret_cast(Context->UContextLocation); ++ NewGuestMask = GuestUContext->uc_sigmask.val[0] & ~((1ULL << (SIGKILL - 1)) | (1ULL << (SIGSTOP - 1))); ++ } ++ ThreadObject->SignalInfo.CurrentSignalMask.Val = NewGuestMask; ++ CheckForPendingSignals(ThreadObject); ++ } ++ } ++ ++ FEX::HLE::ThreadManager::GetStateObjectFromFEXCoreThread(Thread)->JITStackSP = Context->SavedJITStackSP; + + // Reset the guest state + memcpy(&Thread->CurrentFrame->State, &Context->GuestState, sizeof(FEXCore::Core::CPUState)); +@@ -327,7 +363,7 @@ void SignalDelegator::RestoreThreadState(FEXCore::Core::InternalThreadState* Thr + // XXX: Unsupported since it needs state reconstruction + // If we are in the JIT then SRA might need to be restored to values from the context + // We can't currently support this since it might result in tearing without real state reconstruction +- Frame->InSyscallInfo = Context->InSyscallInfo; ++ Frame->InSyscallInfo = ArchHelpers::Context::SavedSyscallInfo(Context); + + if (Is64BitMode) { + RestoreFrame_x64(Thread, Context, Frame, ucontext); +@@ -343,7 +379,36 @@ void SignalDelegator::RestoreThreadState(FEXCore::Core::InternalThreadState* Thr + + bool SignalDelegator::HandleDispatcherGuestSignal(FEXCore::Core::InternalThreadState* Thread, int Signal, void* info, void* ucontext, + GuestSigAction* GuestAction, stack_t* GuestStack) { ++ auto ThreadObject = FEX::HLE::ThreadManager::GetStateObjectFromFEXCoreThread(Thread); ++ ++ const int SigSysCode = Signal == SIGSYS ? static_cast(info)->si_code : 0; ++ const bool IsTrapSignal = (SigSysCode == 1 || SigSysCode == 2 ) && ThreadObject->SeccompTrapRIP && ++ !CTX->IsAddressInCodeBuffer(Thread, ArchHelpers::Context::GetPc(ucontext)); ++ if (IsTrapSignal) { ++ const uint64_t GuestRSP = Thread->CurrentFrame->State.gregs[FEXCore::X86State::REG_RSP]; ++ while (ThreadObject->TrapSignalFrameCount) { ++ const auto& Abandoned = ThreadObject->TrapSignalFrames[ThreadObject->TrapSignalFrameCount - 1]; ++ if (GuestRSP <= Abandoned.GuestFrame || GuestRSP < Abandoned.GuestRSP) { ++ break; ++ } ++ ThreadObject->JITStackSP = Abandoned.JITStackSP; ++ --ThreadObject->TrapSignalFrameCount; ++ --Thread->CurrentFrame->SignalHandlerRefCounter; ++ } ++ const uint64_t Level = ThreadObject->JITStackSP ? ThreadObject->JITStackSP : Thread->CurrentFrame->ReturningStackLocation; ++ if (Level > ArchHelpers::Context::GetSp(ucontext)) { ++ ArchHelpers::Context::SetSp(ucontext, Level); ++ } ++ } ++ + auto ContextBackup = StoreThreadState(Thread, Signal, ucontext); ++ ContextBackup->GuestSignalMask = ThreadObject->SignalInfo.CurrentSignalMask.Val; ++ ++ if (SigSysCode == 1 || SigSysCode == 2 ) { ++ ContextBackup->SeccompTrapRIP = ThreadObject->SeccompTrapRIP; ++ ThreadObject->SeccompTrapRIP = 0; ++ } ++ ContextBackup->SavedJITStackSP = ThreadObject->JITStackSP; + + auto Frame = Thread->CurrentFrame; + auto& SignalInfo = FEX::HLE::ThreadManager::GetStateObjectFromFEXCoreThread(Thread)->SignalInfo; +@@ -382,8 +447,13 @@ bool SignalDelegator::HandleDispatcherGuestSignal(FEXCore::Core::InternalThreadS + ContextBackup->InSyscallInfo = Thread->CurrentFrame->InSyscallInfo; + Thread->CurrentFrame->InSyscallInfo = 0; + } else { +- ContextBackup->InSyscallInfo = Frame->InSyscallInfo; +- Frame->InSyscallInfo = 0; ++ ThreadObject->JITStackSP = ArchHelpers::Context::GetSp(ucontext); ++ ++ if (Thread->CurrentFrame->InSyscallInfo != 0) { ++ ContextBackup->ClearedSyscallInfo = Thread->CurrentFrame->InSyscallInfo; ++ ContextBackup->Flags |= ArchHelpers::Context::ContextFlags::CONTEXT_FLAG_SYSCALLINFO_CLEARED; ++ Thread->CurrentFrame->InSyscallInfo = 0; ++ } + + if (!IsAddressInDispatcher(OldPC)) { + // This is likely to cause issues but in some cases it isn't fatal +@@ -462,6 +532,14 @@ bool SignalDelegator::HandleDispatcherGuestSignal(FEXCore::Core::InternalThreadS + + if (Is64BitMode) { + NewGuestSP = SetupFrame_x64(Thread, ContextBackup, Frame, Signal, HostSigInfo, ucontext, GuestAction, GuestStack, NewGuestSP, eflags); ++ if (IsTrapSignal && ThreadObject->TrapSignalFrameCount < ThreadObject->MaxTrapSignalFrames) { ++ ThreadObject->TrapSignalFrames[ThreadObject->TrapSignalFrameCount++] = { ++ .GuestFrame = NewGuestSP, ++ .GuestRSP = OldGuestSP, ++ .JITStackSP = ContextBackup->SavedJITStackSP, ++ .ContextBackup = reinterpret_cast(ContextBackup), ++ }; ++ } + } else { + const bool SigInfoFrame = (GuestAction->sa_flags & SA_SIGINFO) == SA_SIGINFO; + if (SigInfoFrame) { +@@ -483,8 +561,8 @@ bool SignalDelegator::HandleDispatcherGuestSignal(FEXCore::Core::InternalThreadS + // This way signal handlers always go back to their original operating mode. + // Doesn't matter for 32-bit processes as they can only be 32-bit, but does + // matter for 64-bit processes as they could have potentially installed a 32-bit code segment. +- Frame->State.cs_idx = FEXCore::Core::CPUState::DEFAULT_USER_CS << 3; +- Frame->State.ss_idx = 0; ++ Frame->State.cs_idx = Is64BitMode ? FEXCore::Core::CPUState::DEFAULT_USER_CS_SEL : FEXCore::Core::CPUState::DEFAULT_USER32_CS_SEL; ++ Frame->State.ss_idx = FEXCore::Core::CPUState::DEFAULT_USER_DS_SEL; + Frame->State.cs_cached = Frame->State.CalculateGDTBase(*Frame->State.GetSegmentFromIndex(Frame->State, Frame->State.cs_idx)); + Frame->State.ss_cached = Frame->State.CalculateGDTBase(*Frame->State.GetSegmentFromIndex(Frame->State, Frame->State.ss_idx)); + +@@ -690,7 +768,7 @@ bool SignalDelegator::HandleFrontendSIGSEGV(FEXCore::Core::InternalThreadState* + auto SigInfo = *static_cast(Info); + + if (FaultSafeUserMemAccess::TryHandleSafeFault(Signal, SigInfo, UContext)) { +- ERROR_AND_DIE_FMT("Received invalid data to syscall. Crashing now!"); ++ return true; + } + + #ifdef ARCHITECTURE_arm64 +@@ -714,10 +792,21 @@ bool SignalDelegator::HandleFrontendSIGSEGV(FEXCore::Core::InternalThreadState* + + void SignalDelegator::HandleGuestSignal(FEX::HLE::ThreadStateObject* ThreadObject, int Signal, void* Info, void* UContext) { + auto Thread = ThreadObject->Thread; ++ ++ if (PtraceEmu::TryGuestSignalStop(Thread->CurrentFrame, Signal)) { ++ Thread->CurrentFrame->SynchronousFaultData.FaultToTopAndGeneratedException = false; ++ ArchHelpers::Context::SetPc(UContext, Config.AbsoluteLoopTopAddressFillSRA); ++ ArchHelpers::Context::SetFillSRASingleInst(UContext, false); ++ ArchHelpers::Context::SetState(UContext, reinterpret_cast(Thread->CurrentFrame)); ++ return; ++ } ++ + ucontext_t* _context = (ucontext_t*)UContext; + auto SigInfo = *static_cast(Info); + + auto MustDeferSignal = (Thread->CurrentFrame->State.DeferredSignalRefCount.Load() != 0); ++ SigTrace::Log(ThreadObject->ThreadInfo.TID, SigTrace::HostArrive, Signal, ThreadObject->SignalInfo.CurrentSignalMask.Val, ++ (static_cast(MustDeferSignal) << 32) | static_cast(SigInfo.si_code)); + if (Signal == SIGSEGV && SigInfo.si_code == SEGV_ACCERR && SigInfo.si_addr == reinterpret_cast(&Thread->InterruptFaultPage)) { + if (!MustDeferSignal) { + // We just reached the end of the outermost signal-deferring section and faulted to check for pending signals. +@@ -781,6 +870,8 @@ void SignalDelegator::HandleGuestSignal(FEX::HLE::ThreadStateObject* ThreadObjec + // This allows us to maintain the expected signal mask through the guest signal handling and then all the way back again + sigmask_val[0] = GetNewSigMask(Signal); + ++ SigTrace::Log(ThreadObject->ThreadInfo.TID, SigTrace::Deferred, Signal, 0, 0); ++ + // Now update the faulting page permissions so it will fault on write. + mprotect(reinterpret_cast(&Thread->InterruptFaultPage), sizeof(Thread->InterruptFaultPage), PROT_NONE); + +@@ -793,6 +884,7 @@ void SignalDelegator::HandleGuestSignal(FEX::HLE::ThreadStateObject* ThreadObjec + // This signal is masked, must defer until the guest updates the signal mask. + // Add it to the pending signal list + ThreadObject->SignalInfo.PendingSignals |= 1ULL << (Signal - 1); ++ SigTrace::Log(ThreadObject->ThreadInfo.TID, SigTrace::Masked, Signal, ThreadObject->SignalInfo.CurrentSignalMask.Val, ThreadObject->SignalInfo.PendingSignals); + return; + } + +@@ -814,6 +906,21 @@ void SignalDelegator::HandleGuestSignal(FEX::HLE::ThreadStateObject* ThreadObjec + if (Handler.GuestHandler && + Handler.GuestHandler(Thread, Signal, &SigInfo, UContext, &Handler.GuestAction, &ThreadObject->SignalInfo.GuestAltStack)) { + uint64_t NewMask = GetNewSigMask(Signal); ++ if (SignalMaskFix()) { ++ uint64_t GuestNew = ThreadObject->SignalInfo.CurrentSignalMask.Val | Handler.GuestAction.sa_mask.Val; ++ if (!(Handler.GuestAction.sa_flags & SA_NODEFER)) { ++ GuestNew |= 1ULL << (Signal - 1); ++ } ++ GuestNew &= ~((1ULL << (SIGKILL - 1)) | (1ULL << (SIGSTOP - 1))); ++ ThreadObject->SignalInfo.CurrentSignalMask.Val = GuestNew; ++ NewMask = GuestNew; ++ for (size_t i = 0; i < MAX_SIGNALS; ++i) { ++ if (HostHandlers[i + 1].Required.load(std::memory_order_relaxed)) { ++ NewMask &= ~(1ULL << i); ++ } ++ } ++ } ++ SigTrace::Log(ThreadObject->ThreadInfo.TID, SigTrace::Delivered, Signal, reinterpret_cast(Handler.GuestAction.sigaction_handler.sigaction), NewMask); + + // Update our host signal mask so we don't hit race conditions with signals + // This allows us to maintain the expected signal mask through the guest signal handling and then all the way back again +@@ -961,6 +1068,30 @@ void SignalDelegator::UninstallHostHandler(int Signal) { + ::syscall(SYS_rt_sigaction, Signal, &SignalHandler.OldAction, nullptr, 8); + } + ++void SignalDelegator::ForceGuestSigSegv(uint64_t BadSP) { ++ static std::atomic Logged {false}; ++ if (!Logged.exchange(true, std::memory_order_relaxed)) { ++ LogMan::Msg::EFmt("Cannot write the guest signal frame at stack pointer 0x{:x}; forcing SIGSEGV " ++ "(Linux force_sigsegv). The guest stack pointer is not a live, writable mapping.", ++ BadSP); ++ } ++ ++ SignalHandler& Handler = HostHandlers[SIGSEGV]; ++ Handler.GuestAction.sigaction_handler.handler = SIG_DFL; ++ Handler.OldAction.handler = SIG_DFL; ++ ::signal(SIGSEGV, SIG_DFL); ++ ++ CTX->FlushAndCloseCodeMap(); ++ FEX::HLE::_SyscallHandler->TM.CleanupForExit(); ++ ++ uint64_t SegvMask = 1ULL << (SIGSEGV - 1); ++ ::syscall(SYS_rt_sigprocmask, SIG_UNBLOCK, &SegvMask, nullptr, 8); ++ ::raise(SIGSEGV); ++ ++ ::syscall(SYS_exit, 128 + SIGSEGV); ++ FEX_UNREACHABLE; ++} ++ + void SignalDelegator::QueueSignal(pid_t tgid, pid_t tid, int Signal, siginfo_t* info, bool IgnoreMask) { + bool WasIgnored {}; + bool WasMasked {}; +@@ -995,11 +1126,34 @@ void SignalDelegator::QueueSignal(pid_t tgid, pid_t tid, int Signal, siginfo_t* + } + } + ++void SignalDelegator::PrepareForcedGuestSignal(FEX::HLE::ThreadStateObject* Thread, int Signal) { ++ const uint64_t SignalMask = 1ULL << (Signal - 1); ++ const bool Blocked = Thread->SignalInfo.CurrentSignalMask.Val & SignalMask; ++ ++ GuestSigAction Action {}; ++ RegisterGuestSignalHandler(Signal, nullptr, &Action); ++ const bool Ignored = Action.sigaction_handler.handler == SIG_IGN; ++ ++ if (!Blocked && !Ignored) { ++ return; ++ } ++ ++ Action.sigaction_handler.handler = SIG_DFL; ++ RegisterGuestSignalHandler(Signal, &Action, nullptr); ++ if (Blocked) { ++ GuestSigProcMask(Thread, SIG_UNBLOCK, &SignalMask, nullptr); ++ } ++} ++ + SignalDelegator::SignalDelegator(FEXCore::Context::Context* _CTX, const std::string_view ApplicationName, bool SupportsAVX, bool SupportsSVE256) + : CTX {_CTX} + , ApplicationName {ApplicationName} + , SupportsAVX {SupportsAVX} + , SupportsSVE256 {SupportsSVE256} { ++ if (SignalTrace()) { ++ SigTrace::Init(); ++ } ++ + // Signal zero isn't real + HostHandlers[0].Installed = true; + +@@ -1162,23 +1316,36 @@ void SignalDelegator::RegisterTLSState(FEX::HLE::ThreadStateObject* Thread) { + } + } + +-void SignalDelegator::UninstallTLSState(FEX::HLE::ThreadStateObject* Thread) { +- FEXCore::Allocator::munmap(Thread->SignalInfo.AltStackPtr, SIGSTKSZ * 16); +- +- Thread->SignalInfo.AltStackPtr = nullptr; +- ++void SignalDelegator::ReleaseAltStack(FEX::HLE::ThreadStateObject* Thread) { + stack_t altstack {}; + altstack.ss_flags = SS_DISABLE; +- +- // Uninstall the alt stack + const int Result = sigaltstack(&altstack, nullptr); + if (Result == -1) { + LogMan::Msg::EFmt("Failed to uninstall alternative signal stack {}", strerror(errno)); + } + ++ FEXCore::Allocator::munmap(Thread->SignalInfo.AltStackPtr, SIGSTKSZ * 16); ++ Thread->SignalInfo.AltStackPtr = nullptr; ++ Thread->SignalInfo.AltStackReleaseDeferred = false; ++} ++ ++void SignalDelegator::UninstallTLSState(FEX::HLE::ThreadStateObject* Thread) { ++ stack_t Current {}; ++ if (sigaltstack(nullptr, &Current) == 0 && (Current.ss_flags & SS_ONSTACK)) { ++ Thread->SignalInfo.AltStackReleaseDeferred = true; ++ } else { ++ ReleaseAltStack(Thread); ++ } ++ + FEXCore::Allocator::UninstallTLSData(Thread->Thread); + } + ++void SignalDelegator::ReleaseDeferredTLSState(FEX::HLE::ThreadStateObject* Thread) { ++ if (Thread->SignalInfo.AltStackReleaseDeferred) { ++ ReleaseAltStack(Thread); ++ } ++} ++ + void SignalDelegator::FrontendRegisterHostSignalHandler(int Signal, bool Required) { + // Linux signal handlers are per-process rather than per thread + // Multiple threads could be calling in to this +@@ -1321,6 +1488,7 @@ static void CheckForPendingSignals(const FEX::HLE::ThreadStateObject* Thread) { + if (PendingSignals != 0) { + for (int i = 0; i < 64; ++i) { + if (PendingSignals & (1ULL << i)) { ++ SigTrace::Log(Thread->ThreadInfo.TID, SigTrace::Reraise, i + 1, Thread->SignalInfo.CurrentSignalMask.Val, Thread->SignalInfo.PendingSignals); + FHU::Syscalls::tgkill(Thread->ThreadInfo.PID, Thread->ThreadInfo.TID, i + 1); + // We might not even return here which is spooky + } +@@ -1361,6 +1529,9 @@ uint64_t SignalDelegator::GuestSigProcMask(FEX::HLE::ThreadStateObject* Thread, + } + + ::syscall(SYS_rt_sigprocmask, SIG_SETMASK, &HostMask, nullptr, 8); ++ if (Thread->Thread->CurrentFrame->SignalHandlerRefCounter != 0) { ++ SigTrace::Log(Thread->ThreadInfo.TID, SigTrace::ProcMask, how, *set, Thread->SignalInfo.CurrentSignalMask.Val); ++ } + } + + if (oldset) { +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.h b/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.h +index 43898e700..0d5b5597d 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.h ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.h +@@ -65,6 +65,8 @@ public: + + void RegisterTLSState(FEX::HLE::ThreadStateObject* Thread); + void UninstallTLSState(FEX::HLE::ThreadStateObject* Thread); ++ void ReleaseDeferredTLSState(FEX::HLE::ThreadStateObject* Thread); ++ void ReleaseAltStack(FEX::HLE::ThreadStateObject* Thread); + + /** + * @brief Registers a signal handler for the host to handle a signal +@@ -109,6 +111,10 @@ public: + void UninstallHostHandler(int Signal); + void QueueSignal(pid_t tgid, pid_t tid, int Signal, siginfo_t* info, bool IgnoreMask); + ++ void PrepareForcedGuestSignal(FEX::HLE::ThreadStateObject* Thread, int Signal); ++ ++ [[noreturn]] void ForceGuestSigSegv(uint64_t BadSP); ++ + void SetVDSOSymbols() { + // Get symbols from VDSO. + VDSOPointers = FEX::VDSO::GetVDSOSymbols(); +@@ -187,6 +193,8 @@ private: + FEXCore::Context::Context* CTX; + + FEX_CONFIG_OPT(Is64BitMode, IS64BIT_MODE); ++ FEX_CONFIG_OPT(SignalMaskFix, SIGNALMASKFIX); ++ FEX_CONFIG_OPT(SignalTrace, SIGNALTRACE); + const fextl::string ApplicationName; + FEX_CONFIG_OPT(HalfBarrierTSOEnabled, HALFBARRIERTSOENABLED); + +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator/GuestFramesManagement.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator/GuestFramesManagement.cpp +index 38dc524f1..d0bcdbecb 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator/GuestFramesManagement.cpp ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator/GuestFramesManagement.cpp +@@ -7,6 +7,7 @@ $end_info$ + */ + + #include "LinuxSyscalls/SignalDelegator.h" ++#include "LinuxSyscalls/Syscalls.h" + + #include + #include +@@ -14,11 +15,15 @@ $end_info$ + #include + #include + #include ++#include + ++#include + #include + #include + #include + #include ++#include ++#include + + namespace FEX::HLE { + constexpr uint32_t X86_SA_RESTORER = 0x04000000; +@@ -106,26 +111,42 @@ template + static void SetXStateInfo(T* xstate, bool is_avx_enabled) { + auto* fpstate = &xstate->fpstate; + +- fpstate->sw_reserved.magic1 = is_avx_enabled ? FEXCore::x86_64::fpx_sw_bytes::FP_XSTATE_MAGIC_1 : 0; +- fpstate->sw_reserved.extended_size = is_avx_enabled ? sizeof(T) : 0; ++ fpstate->sw_reserved.magic1 = FEXCore::x86_64::fpx_sw_bytes::FP_XSTATE_MAGIC_1; + + fpstate->sw_reserved.xfeatures |= FEXCore::x86_64::fpx_sw_bytes::FEATURE_FP | FEXCore::x86_64::fpx_sw_bytes::FEATURE_SSE; + if (is_avx_enabled) { + fpstate->sw_reserved.xfeatures |= FEXCore::x86_64::fpx_sw_bytes::FEATURE_YMM; + } + +- fpstate->sw_reserved.xstate_size = fpstate->sw_reserved.extended_size; ++ if constexpr (std::is_same_v) { ++ if (!is_avx_enabled) { ++ fpstate->sw_reserved.xstate_size = sizeof(FEXCore::x86_64::_libc_fpstate); ++ fpstate->sw_reserved.extended_size = sizeof(FEXCore::x86_64::_libc_fpstate) + sizeof(uint32_t); ++ return; ++ } + +- if (is_avx_enabled) { +- xstate->xstate_hdr.xfeatures = 0; +- xstate->magic2.magic = FEXCore::x86_64::fpx_sw_bytes::FP_XSTATE_MAGIC_2; ++ const uint32_t UserSize = offsetof(FEXCore::x86_64::xstate, ymmh) + sizeof(FEXCore::x86_64::ymmh_state); ++ fpstate->sw_reserved.xstate_size = UserSize; ++ fpstate->sw_reserved.extended_size = UserSize + sizeof(uint32_t); ++ ++ xstate->xstate_hdr.xfeatures = fpstate->sw_reserved.xfeatures; ++ ++ *reinterpret_cast(reinterpret_cast(fpstate) + UserSize) = ++ FEXCore::x86_64::fpx_sw_bytes::FP_XSTATE_MAGIC_2; ++ } else { ++ fpstate->sw_reserved.extended_size = is_avx_enabled ? sizeof(T) : 0; ++ fpstate->sw_reserved.xstate_size = fpstate->sw_reserved.extended_size; ++ if (is_avx_enabled) { ++ xstate->xstate_hdr.xfeatures = 0; ++ xstate->magic2.magic = FEXCore::x86_64::fpx_sw_bytes::FP_XSTATE_MAGIC_2; ++ } + } + } + + void SignalDelegator::ResumeWithGuestGPRs(ArchHelpers::Context::ContextBackup* Context, FEXCore::Core::CpuStateFrame* Frame, void* ucontext, + const uint64_t* GuestGPRs, size_t Count, uint64_t Mask) { + #ifdef ARCHITECTURE_arm64 +- const uint32_t Spilled = Context->InSyscallInfo & 0xFFFF; ++ const uint32_t Spilled = ArchHelpers::Context::SavedSyscallInfo(Context) & 0xFFFF; + const bool AllSpilled = Spilled == 0xFFFF; + if (!AllSpilled && !(Context->Flags & ArchHelpers::Context::ContextFlags::CONTEXT_FLAG_INJIT)) { + return; +@@ -153,14 +174,19 @@ void SignalDelegator::RestoreFrame_x64(FEXCore::Core::InternalThreadState* Threa + auto* guest_uctx = reinterpret_cast(Context->UContextLocation); + [[maybe_unused]] auto* guest_siginfo = reinterpret_cast(Context->SigInfoLocation); + +- // If the guest modified the RIP then we need to take special precautions here +- if (Context->OriginalRIP != guest_uctx->uc_mcontext.gregs[FEXCore::x86_64::FEX_REG_RIP] || Context->FaultToTopAndGeneratedException) { ++ CTX->SetFlagsFromCompactedEFLAGS(Thread, guest_uctx->uc_mcontext.gregs[FEXCore::x86_64::FEX_REG_EFL]); ++ ++ if (Context->OriginalRIP != guest_uctx->uc_mcontext.gregs[FEXCore::x86_64::FEX_REG_RIP] || Context->FaultToTopAndGeneratedException || ++ Context->SeccompTrapRIP) { + + // Restore previous `InSyscallInfo` structure. + Frame->InSyscallInfo = 0; + + // Hack! Go back to the top of the dispatcher top + // This is only safe inside the JIT rather than anything outside of it ++ if (!(Context->Flags & ArchHelpers::Context::ContextFlags::CONTEXT_FLAG_INJIT)) { ++ ArchHelpers::Context::SetSp(ucontext, Context->SavedJITStackSP ? Context->SavedJITStackSP : Frame->ReturningStackLocation); ++ } + ArchHelpers::Context::SetPc(ucontext, Config.AbsoluteLoopTopAddressFillSRA); + ArchHelpers::Context::SetFillSRASingleInst(ucontext, false); + // Set our state register to point to our guest thread data +@@ -176,9 +202,6 @@ void SignalDelegator::RestoreFrame_x64(FEXCore::Core::InternalThreadState* Threa + Frame->State.cs_cached = Frame->State.CalculateGDTBase(*Frame->State.GetSegmentFromIndex(Frame->State, Frame->State.cs_idx)); + Frame->State.ss_cached = Frame->State.CalculateGDTBase(*Frame->State.GetSegmentFromIndex(Frame->State, Frame->State.ss_idx)); + +- // XXX: Full context setting +- CTX->SetFlagsFromCompactedEFLAGS(Thread, guest_uctx->uc_mcontext.gregs[FEXCore::x86_64::FEX_REG_EFL]); +- + #define COPY_REG(x) Frame->State.gregs[FEXCore::X86State::REG_##x] = guest_uctx->uc_mcontext.gregs[FEXCore::x86_64::FEX_REG_##x]; + COPY_REG(R8); + COPY_REG(R9); +@@ -256,12 +279,15 @@ void SignalDelegator::RestoreFrame_ia32(FEXCore::Core::InternalThreadState* Thre + FEXCore::Core::CpuStateFrame* Frame, void* ucontext) { + SigFrame_i32* guest_uctx = reinterpret_cast(Context->UContextLocation); + // If the guest modified the RIP then we need to take special precautions here +- if (Context->OriginalRIP != guest_uctx->sc.ip || Context->FaultToTopAndGeneratedException) { ++ if (Context->OriginalRIP != guest_uctx->sc.ip || Context->FaultToTopAndGeneratedException || Context->SeccompTrapRIP) { + // Restore previous `InSyscallInfo` structure. + Frame->InSyscallInfo = 0; + + // Hack! Go back to the top of the dispatcher top + // This is only safe inside the JIT rather than anything outside of it ++ if (!(Context->Flags & ArchHelpers::Context::ContextFlags::CONTEXT_FLAG_INJIT)) { ++ ArchHelpers::Context::SetSp(ucontext, Context->SavedJITStackSP ? Context->SavedJITStackSP : Frame->ReturningStackLocation); ++ } + ArchHelpers::Context::SetPc(ucontext, Config.AbsoluteLoopTopAddressFillSRA); + ArchHelpers::Context::SetFillSRASingleInst(ucontext, false); + // Set our state register to point to our guest thread data +@@ -345,13 +371,17 @@ void SignalDelegator::RestoreRTFrame_ia32(FEXCore::Core::InternalThreadState* Th + FEXCore::Core::CpuStateFrame* Frame, void* ucontext) { + RTSigFrame_i32* guest_uctx = reinterpret_cast(Context->UContextLocation); + // If the guest modified the RIP then we need to take special precautions here +- if (Context->OriginalRIP != guest_uctx->uc.uc_mcontext.gregs[FEXCore::x86::FEX_REG_EIP] || Context->FaultToTopAndGeneratedException) { ++ if (Context->OriginalRIP != guest_uctx->uc.uc_mcontext.gregs[FEXCore::x86::FEX_REG_EIP] || Context->FaultToTopAndGeneratedException || ++ Context->SeccompTrapRIP) { + + // Restore previous `InSyscallInfo` structure. + Frame->InSyscallInfo = 0; + + // Hack! Go back to the top of the dispatcher top + // This is only safe inside the JIT rather than anything outside of it ++ if (!(Context->Flags & ArchHelpers::Context::ContextFlags::CONTEXT_FLAG_INJIT)) { ++ ArchHelpers::Context::SetSp(ucontext, Context->SavedJITStackSP ? Context->SavedJITStackSP : Frame->ReturningStackLocation); ++ } + ArchHelpers::Context::SetPc(ucontext, Config.AbsoluteLoopTopAddressFillSRA); + ArchHelpers::Context::SetFillSRASingleInst(ucontext, false); + // Set our state register to point to our guest thread data +@@ -431,9 +461,42 @@ void SignalDelegator::RestoreRTFrame_ia32(FEXCore::Core::InternalThreadState* Th + } + } + ++static bool GuestFrameWritable(uint64_t Begin, uint64_t End) { ++ if (End < Begin) { ++ return false; ++ } ++ ++ auto& VMATracking = FEX::HLE::_SyscallHandler->VMATracking; ++ ++ constexpr uint64_t PageSize = 4096; ++ constexpr uint64_t MaxPages = 4096; ++ const uint64_t FirstPage = Begin & ~(PageSize - 1); ++ const uint64_t LastPage = End & ~(PageSize - 1); ++ ++ auto lk = FEXCore::MaskSignalsAndLockMutex(VMATracking.Mutex); ++ ++ for (uint64_t Page = FirstPage, PageCount = 0; Page <= LastPage; Page += PageSize, ++PageCount) { ++ if (PageCount >= MaxPages) { ++ return false; ++ } ++ ++ const auto Entry = VMATracking.FindVMAEntry(Page); ++ if (Entry == VMATracking.VMAs.end()) { ++ return false; ++ } ++ ++ if (!Entry->second.Prot.Writable || (Entry->first + Entry->second.Length) < (Page + PageSize)) { ++ return false; ++ } ++ } ++ ++ return true; ++} ++ + uint64_t SignalDelegator::SetupFrame_x64(FEXCore::Core::InternalThreadState* Thread, ArchHelpers::Context::ContextBackup* ContextBackup, + FEXCore::Core::CpuStateFrame* Frame, int Signal, siginfo_t* HostSigInfo, void* ucontext, + GuestSigAction* GuestAction, stack_t* GuestStack, uint64_t NewGuestSP, const uint32_t eflags) { ++ const uint64_t RequestedGuestSP = NewGuestSP; + + // Back up past the redzone, which is 128bytes + // 32-bit doesn't have a redzone +@@ -475,6 +538,16 @@ uint64_t SignalDelegator::SetupFrame_x64(FEXCore::Core::InternalThreadState* Thr + ContextBackup->UContextLocation = UContextLocation; + ContextBackup->SigInfoLocation = SigInfoLocation; + ++ const uint64_t UContextEnd = UContextLocation + sizeof(FEXCore::x86_64::ucontext_t); ++ const uint64_t FPStateEnd = ++ FPStateLocation + (SupportsAVX ? sizeof(FEXCore::x86_64::xstate) : sizeof(FEXCore::x86_64::_libc_fpstate)); ++ const uint64_t HostStackEnd = HostStackLocation + sizeof(uint64_t); ++ const uint64_t FrameEnd = std::max({UContextEnd, FPStateEnd, HostStackEnd}); ++ ++ if (!GuestFrameWritable(UContextLocation, FrameEnd)) { ++ ForceGuestSigSegv(RequestedGuestSP); ++ } ++ + FEXCore::x86_64::ucontext_t* guest_uctx = reinterpret_cast(UContextLocation); + siginfo_t* guest_siginfo = reinterpret_cast(SigInfoLocation); + // Store where the host context lives in the guest stack. +@@ -488,7 +561,8 @@ uint64_t SignalDelegator::SetupFrame_x64(FEXCore::Core::InternalThreadState* Thr + auto* xstate = reinterpret_cast(FPStateLocation); + SetXStateInfo(xstate, SupportsAVX); + +- guest_uctx->uc_mcontext.gregs[FEXCore::x86_64::FEX_REG_RIP] = ContextBackup->OriginalRIP; ++ guest_uctx->uc_mcontext.gregs[FEXCore::x86_64::FEX_REG_RIP] = ++ ContextBackup->SeccompTrapRIP ? ContextBackup->SeccompTrapRIP : ContextBackup->OriginalRIP; + guest_uctx->uc_mcontext.gregs[FEXCore::x86_64::FEX_REG_EFL] = eflags; + // This stores the CS/GS/FS selectors. It ALSO stores the SS selector in the top 16 bits...For some reason. + // Despite the naming, the endianness is swapped from what you'd expect. +@@ -568,6 +642,9 @@ uint64_t SignalDelegator::SetupFrame_x64(FEXCore::Core::InternalThreadState* Thr + guest_uctx->uc_stack.ss_sp = GuestStack->ss_sp; + guest_uctx->uc_stack.ss_size = GuestStack->ss_size; + ++ memset(guest_uctx->uc_sigmask.val, 0, sizeof(guest_uctx->uc_sigmask.val)); ++ guest_uctx->uc_sigmask.val[0] = ContextBackup->GuestSignalMask; ++ + // Apparently RAX is always set to zero in case of badly misbehaving C applications and variadics. + Frame->State.gregs[FEXCore::X86State::REG_RAX] = 0; + Frame->State.gregs[FEXCore::X86State::REG_RDI] = Signal; +@@ -643,7 +720,7 @@ uint64_t SignalDelegator::SetupFrame_ia32(FEXCore::Core::InternalThreadState* Th + guest_uctx->sc.err = ConvertSignalToError(ucontext, Signal, HostSigInfo); + } + +- guest_uctx->sc.ip = ContextBackup->OriginalRIP; ++ guest_uctx->sc.ip = ContextBackup->SeccompTrapRIP ? ContextBackup->SeccompTrapRIP : ContextBackup->OriginalRIP; + guest_uctx->sc.flags = eflags; + guest_uctx->sc.sp_at_signal = 0; + +@@ -779,7 +856,8 @@ uint64_t SignalDelegator::SetupRTFrame_ia32(FEXCore::Core::InternalThreadState* + guest_uctx->uc.uc_mcontext.gregs[FEXCore::x86::FEX_REG_ERR] = ConvertSignalToError(ucontext, Signal, HostSigInfo); + } + +- guest_uctx->uc.uc_mcontext.gregs[FEXCore::x86::FEX_REG_EIP] = ContextBackup->OriginalRIP; ++ guest_uctx->uc.uc_mcontext.gregs[FEXCore::x86::FEX_REG_EIP] = ++ ContextBackup->SeccompTrapRIP ? ContextBackup->SeccompTrapRIP : ContextBackup->OriginalRIP; + guest_uctx->uc.uc_mcontext.gregs[FEXCore::x86::FEX_REG_EFL] = eflags; + guest_uctx->uc.uc_mcontext.gregs[FEXCore::x86::FEX_REG_UESP] = Frame->State.gregs[FEXCore::X86State::REG_RSP]; + guest_uctx->uc.uc_mcontext.cr2 = 0; +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalTrace.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalTrace.cpp +new file mode 100644 +index 000000000..5db61d312 +--- /dev/null ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalTrace.cpp +@@ -0,0 +1,45 @@ ++// SPDX-License-Identifier: MIT ++#include "LinuxSyscalls/SignalTrace.h" ++ ++#include ++#include ++#include ++#include ++ ++namespace FEX::HLE::SigTrace { ++Rec* Buf = nullptr; ++std::atomic Idx {0}; ++ ++namespace { ++ std::string PathFor(pid_t Pid) { ++ return "/dev/shm/fex-" + std::to_string(Pid) + "-sigtrace"; ++ } ++} ++ ++void Init() { ++ if (Buf) { ++ return; ++ } ++ const std::string Path = PathFor(getpid()); ++ const int fd = open(Path.c_str(), O_RDWR | O_CREAT | O_TRUNC | O_CLOEXEC, 0600); ++ if (fd < 0) { ++ return; ++ } ++ if (ftruncate(fd, sizeof(Rec) * Recs) != 0) { ++ close(fd); ++ return; ++ } ++ void* Map = mmap(nullptr, sizeof(Rec) * Recs, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); ++ close(fd); ++ if (Map != MAP_FAILED) { ++ Buf = static_cast(Map); ++ } ++} ++ ++void CleanupForExit() { ++ if (!Buf) { ++ return; ++ } ++ unlink(PathFor(getpid()).c_str()); ++} ++} +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalTrace.h b/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalTrace.h +new file mode 100644 +index 000000000..d1a1bb8a6 +--- /dev/null ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalTrace.h +@@ -0,0 +1,54 @@ ++// SPDX-License-Identifier: MIT ++#pragma once ++ ++#include ++#include ++ ++namespace FEX::HLE::SigTrace { ++enum Event : uint16_t { ++ HostArrive = 1, ++ Masked = 2, ++ Deferred = 3, ++ Delivered = 4, ++ SigReturn = 5, ++ ProcMask = 6, ++ Reraise = 7, ++ Kill = 8, ++ Read16 = 9, ++ Write16 = 10, ++ EpollCtl = 11, ++}; ++ ++struct Rec { ++ uint64_t Tsc; ++ uint32_t Tid; ++ uint16_t Ev; ++ uint16_t Sig; ++ uint64_t A; ++ uint64_t B; ++}; ++ ++constexpr uint32_t Recs = 1u << 19; ++extern Rec* Buf; ++extern std::atomic Idx; ++ ++void Init(); ++ ++void CleanupForExit(); ++ ++inline bool Enabled() { ++ return Buf != nullptr; ++} ++ ++inline void Log(uint32_t Tid, uint16_t Ev, uint16_t Sig, uint64_t A, uint64_t B) { ++ if (!Buf) { ++ return; ++ } ++ uint64_t Tsc = 0; ++#if defined(__aarch64__) ++ asm volatile("mrs %0, cntvct_el0" : "=r"(Tsc)); ++#endif ++ Rec& R = Buf[Idx.fetch_add(1, std::memory_order_relaxed) & (Recs - 1)]; ++ R = {Tsc, Tid, Ev, Sig, A, B}; ++} ++} +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls.cpp +index 4a77d8716..607ab0b97 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls.cpp ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls.cpp +@@ -15,6 +15,8 @@ $end_info$ + + #include "LinuxSyscalls/LinuxAllocator.h" + #include "LinuxSyscalls/SignalDelegator.h" ++#include "LinuxSyscalls/PtraceEmu.h" ++#include + #include "LinuxSyscalls/Syscalls.h" + #include "LinuxSyscalls/Syscalls/Thread.h" + #include "LinuxSyscalls/Utils/Threads.h" +@@ -235,6 +237,11 @@ uint64_t ExecveHandler(FEXCore::Core::CpuStateFrame* Frame, const char* pathname + return -ENOENT; + } + ++ if (PtraceEmu::IsAttached()) { ++ char Resolved[PATH_MAX]; ++ PtraceEmu::RecordExecPath(pathname[0] == '/' ? std::string(pathname) : std::string(realpath(Filename.c_str(), Resolved) ? Resolved : pathname)); ++ } ++ + int pid = getpid(); + + char PidSelfPath[50]; +@@ -332,7 +339,8 @@ uint64_t ExecveHandler(FEXCore::Core::CpuStateFrame* Frame, const char* pathname + // - seccomp inheritance + // - FEXServer FD inheritance (unshare(CLONE_NEWNET)) + // - FD_CLOEXEC set on FD on anonymous file FD. +- const bool NeedsEnvpCopy = (IsFDExec && !(IsBinfmtCompatible || IsOtherELF)) || HasSeccomp || NeedsFDCopy || NeedsLoaderFD; ++ const bool NeedsExecveFD = (IsFDExec && !(IsBinfmtCompatible || IsOtherELF)) || NeedsFDCopy || NeedsLoaderFD; ++ const bool NeedsEnvpCopy = NeedsExecveFD || HasSeccomp; + + // We are trying to execute a shebang handled by a different architecture interpreter (e.g. /usr/bin/python from the host FS). + // In this case we just defer to the kernel. +@@ -348,7 +356,7 @@ uint64_t ExecveHandler(FEXCore::Core::CpuStateFrame* Frame, const char* pathname + } + } + +- if (!IsBinfmtCompatible || NeedsFDCopy) { ++ if (NeedsExecveFD) { + if (NeedsFDCopy) { + // FEX needs the FD to live past execve when binfmt_misc isn't used, + // so duplicate the FD if FD_CLOEXEC is set, which removes the FD_CLOEXEC flag. +@@ -439,9 +447,7 @@ uint64_t ExecveHandler(FEXCore::Core::CpuStateFrame* Frame, const char* pathname + + // It is valid to provide nullptr first argument. + if (*OldArgv) { +- // The direct fallback uses the executable path as argv[0]. An FD-backed load uses the +- // binfmt preserve-argv0 layout, so the caller-supplied argv[0] has to stay in the vector. +- if (!NeedsLoaderFD && !IsFDExec) { ++ if (!IsFDExec && !NeedsLoaderFD) { + ++OldArgv; + } + while (*OldArgv) { +@@ -814,6 +820,9 @@ SyscallHandler::SyscallHandler(FEXCore::Context::Context* _CTX, FEX::HLE::Signal + + SignalDelegation->RegisterHostSignalHandler(SIGSEGV, HandleSegfault, true); + ++ SignalDelegation->RegisterHostSignalHandler( ++ SIGTRAP, [](FEXCore::Core::InternalThreadState*, int, void*, void*) { return false; }, true); ++ + ExtendedMetaData = FEX::VolatileMetadata::ParseExtendedVolatileMetadata(FEXCore::Config::Get_EXTENDEDVOLATILEMETADATA()()); + } + +@@ -835,6 +844,14 @@ void SyscallHandler::HandleSyscallImpl(FEXCore::Core::CpuStateFrame* Frame, uint + Thread->Thread->CurrentFrame->State.gregs[FEXCore::X86State::REG_RAX] = Result & Mask; + }; + ++ if (FEX::HLE::ThreadManager::GetStateObjectFromCPUState(Frame)->SyscallUserDispatch.Enabled) [[unlikely]] { ++ const auto Result = SeccompEmulator.ExecuteSyscallUserDispatch(Frame, JITPC, GetArg(Is64Bit, Frame, 0)); ++ if (Result.EarlyReturn) { ++ SetResult(Frame, Result.Result); ++ return; ++ } ++ } ++ + if (SeccompEmulator.HasFilter(Frame)) { + FEX::HLE::SyscallArguments Args { + .Argument = +@@ -856,9 +873,23 @@ void SyscallHandler::HandleSyscallImpl(FEXCore::Core::CpuStateFrame* Frame, uint + } + } + +- const auto SyscallNum = GetArg(Is64Bit, Frame, 0); ++ auto SyscallNum = GetArg(Is64Bit, Frame, 0); ++ ++ uint64_t TraceArgs[6] {}; ++ const bool ReportStops = Is64Bit && PtraceEmu::WantsSyscallStops(); ++ if (ReportStops) { ++ for (unsigned i = 0; i < 6; ++i) { ++ TraceArgs[i] = GetArg(Is64Bit, Frame, i + 1); ++ } ++ SyscallNum = PtraceEmu::SyscallEntryStop(Frame, SyscallNum, TraceArgs); ++ } ++ + if (SyscallNum >= Definitions.size()) { +- SetResult(Frame, -ENOSYS); ++ uint64_t Result = -ENOSYS; ++ if (ReportStops && PtraceEmu::WantsSyscallStops()) { ++ Result = PtraceEmu::SyscallExitStop(Frame, SyscallNum, TraceArgs, Result); ++ } ++ SetResult(Frame, Result); + return; + } + +@@ -891,6 +922,23 @@ void SyscallHandler::HandleSyscallImpl(FEXCore::Core::CpuStateFrame* Frame, uint + #ifdef DEBUG_STRACE + Strace(Frame, Result); + #endif ++ ++ if constexpr (Is64Bit) { ++ PtraceEmu::ApplyPendingFlush(Frame); ++ if (Result == 0 && (SyscallNum == 56 || SyscallNum == 57 || SyscallNum == 58 || SyscallNum == 435)) { ++ constexpr uint64_t CloneVM = 0x100; ++ uint64_t Flags = 0; ++ if (SyscallNum == 56) { ++ Flags = GetArg(Is64Bit, Frame, 1); ++ } else if (SyscallNum == 435) { ++ Flags = *reinterpret_cast(GetArg(Is64Bit, Frame, 1)); ++ } ++ PtraceEmu::OnForkedChild((Flags & CloneVM) != 0); ++ } ++ if (ReportStops && PtraceEmu::WantsSyscallStops()) { ++ Result = PtraceEmu::SyscallExitStop(Frame, SyscallNum, TraceArgs, Result); ++ } ++ } + SetResult(Frame, Result); + } + +@@ -906,9 +954,12 @@ void SyscallHandler::HandleSyscall(FEXCore::Core::CpuStateFrame* Frame) { + HandleSyscallImpl(Frame, JITPC); + } + +- // Skip past the `syscall` or `int 0x80` instruction. Both of which are 2-bytes. + auto Thread = FEX::HLE::ThreadManager::GetStateObjectFromCPUState(Frame); +- Thread->Thread->CurrentFrame->State.rip += 2; ++ if (const uint64_t NewRip = PtraceEmu::TakePendingRip()) { ++ Thread->Thread->CurrentFrame->State.rip = NewRip; ++ } else { ++ Thread->Thread->CurrentFrame->State.rip += 2; ++ } + } + + #ifdef DEBUG_STRACE +@@ -969,6 +1020,8 @@ void SyscallHandler::UnlockAfterFork(FEXCore::Core::InternalThreadState* LiveThr + // Code maps are closed upon fork in the child + FM.SetProtectedCodeMapFD(-1); + ++ FEX::HLE::ThreadManager::GetStateObjectFromFEXCoreThread(LiveThread)->SyscallUserDispatch = {}; ++ + VMATracking.Mutex.StealAndDropActiveLocks(); + CodeCachePatchingMutex.StealAndDropActiveLocks(); + } else { +@@ -985,10 +1038,16 @@ void SyscallHandler::UnlockAfterFork(FEXCore::Core::InternalThreadState* LiveThr + void SyscallHandler::RegisterTLSState(FEX::HLE::ThreadStateObject* Thread) { + SignalDelegation->RegisterTLSState(Thread); + ThunkHandler->RegisterTLSState(Thread); ++ FEX::HLE::ThreadManager::SetCurrentThreadObject(Thread); + } + + void SyscallHandler::UninstallTLSState(FEX::HLE::ThreadStateObject* Thread) { + SignalDelegation->UninstallTLSState(Thread); ++ FEX::HLE::ThreadManager::SetCurrentThreadObject(nullptr); ++} ++ ++void SyscallHandler::ReleaseDeferredTLSState(FEX::HLE::ThreadStateObject* Thread) { ++ SignalDelegation->ReleaseDeferredTLSState(Thread); + } + + static bool isHEX(char c) { +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls.h b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls.h +index f55bce4fc..d643b4975 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls.h ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls.h +@@ -14,6 +14,7 @@ $end_info$ + #include "LinuxSyscalls/LinuxAllocator.h" + #include "LinuxSyscalls/ThreadManager.h" + #include "LinuxSyscalls/Seccomp/SeccompEmulator.h" ++#include "LinuxSyscalls/SMCHotPages.h" + #include "LinuxSyscalls/SyscallsVMATracking.h" + #include "ArchHelpers/MContext.h" + +@@ -203,6 +204,7 @@ public: + FEX_CONFIG_OPT(RootFSPath, ROOTFS); + FEX_CONFIG_OPT(Is64BitMode, IS64BIT_MODE); + FEX_CONFIG_OPT(SMCChecks, SMCCHECKS); ++ FEX_CONFIG_OPT(SMCHotPageFaults, SMCHOTPAGEFAULTS); + FEX_CONFIG_OPT(NeedsSeccomp, NEEDSSECCOMP); + FEX_CONFIG_OPT(EnableCodeCaching, ENABLECODECACHINGWIP); + FEX_CONFIG_OPT(EnableDiskCache, DISKCACHE); +@@ -287,8 +289,13 @@ public: + + ///// VMA (Virtual Memory Area) tracking ///// + static bool HandleSegfault(FEXCore::Core::InternalThreadState* Thread, int Signal, void* info, void* ucontext); ++ static void InvalidateWrittenCodePage(FEXCore::Core::InternalThreadState* Thread, uint64_t FaultBase, uint64_t EntryBase, ++ const FEX::HLE::VMATracking::VMAEntry& Mapping); + void MarkGuestExecutableRange(FEXCore::Core::InternalThreadState* Thread, uint64_t Start, uint64_t Length) override; + void ProtectWritableAliasOfCode(uint64_t Base, uint64_t Length); ++ bool IsSMCHotPage(uint64_t Address) override; ++ ++ void PrepareGuestBufferForKernelWrite(FEXCore::Core::InternalThreadState* Thread, const void* Buf, size_t Length); + void InvalidateGuestCodeRange(FEXCore::Core::InternalThreadState* Thread, uint64_t Start, uint64_t Length) override; + std::optional + LookupExecutableFileSection(FEXCore::Core::InternalThreadState* Thread, uint64_t GuestAddr) final override; +@@ -304,6 +311,7 @@ public: + + void RegisterTLSState(FEX::HLE::ThreadStateObject* Thread); + void UninstallTLSState(FEX::HLE::ThreadStateObject* Thread); ++ void ReleaseDeferredTLSState(FEX::HLE::ThreadStateObject* Thread); + + SourcecodeResolver* GetSourcecodeResolver() override { + return this; +@@ -363,6 +371,8 @@ private: + // std::mutex CodeCachePatchingMutex; + FEXCore::ForkableUniqueMutex CodeCachePatchingMutex; + ++ SMCHotPageTracker SMCHotPages; ++ + FEX::CodeLoader* LocalLoader {}; + bool NeedToCheckXID {true}; + +@@ -607,11 +617,13 @@ uint64_t GetDentsEmulation(int fd, T* dirp, uint32_t count); + namespace FaultSafeUserMemAccess { + // These are little helper functions for cases when FEX needs to copy data to or from the application in a robust fashion. + // CopyFromUser and CopyToUser are memcpy routines that expect to safely SIGSEGV when reading or writing application memory respectively. +- // Returns zero if the memcpy completed, or crashes with SIGABRT and a log message if it faults. + [[nodiscard]] + size_t CopyFromUser(void* Dest, const void* Src, size_t Size); + [[nodiscard]] + size_t CopyToUser(void* Dest, const void* Src, size_t Size); ++ ++ [[nodiscard]] ++ bool IsStringReadable(const char* Src); + #if defined(ASSERTIONS_ENABLED) && ASSERTIONS_ENABLED && defined(ARCHITECTURE_arm64) + // These helpers just check if the user pointer is readable and writable. + // This is useful in an assert build that can be safely sprinkled through the syscall handler without overhead in release builds. +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/FD.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/FD.cpp +index 9acf01ff5..1601de1ef 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/FD.cpp ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/FD.cpp +@@ -38,6 +38,9 @@ void RegisterFD(FEX::HLE::SyscallHandler* Handler) { + }); + + REGISTER_SYSCALL_IMPL(open, [](FEXCore::Core::CpuStateFrame* Frame, const char* pathname, int flags, uint32_t mode) -> uint64_t { ++ if (!FaultSafeUserMemAccess::IsStringReadable(pathname)) { ++ return -EFAULT; ++ } + flags = FEX::HLE::RemapFromX86Flags(flags); + uint64_t Result = FEX::HLE::_SyscallHandler->FM.Open(pathname, flags, mode); + SYSCALL_ERRNO(); +@@ -59,6 +62,9 @@ void RegisterFD(FEX::HLE::SyscallHandler* Handler) { + }); + + REGISTER_SYSCALL_IMPL(access, [](FEXCore::Core::CpuStateFrame* Frame, const char* pathname, int mode) -> uint64_t { ++ if (!FaultSafeUserMemAccess::IsStringReadable(pathname)) { ++ return -EFAULT; ++ } + uint64_t Result = FEX::HLE::_SyscallHandler->FM.Access(pathname, mode); + SYSCALL_ERRNO(); + }); +@@ -80,22 +86,34 @@ void RegisterFD(FEX::HLE::SyscallHandler* Handler) { + }); + + REGISTER_SYSCALL_IMPL(openat, [](FEXCore::Core::CpuStateFrame* Frame, int dirfs, const char* pathname, int flags, uint32_t mode) -> uint64_t { ++ if (!FaultSafeUserMemAccess::IsStringReadable(pathname)) { ++ return -EFAULT; ++ } + flags = FEX::HLE::RemapFromX86Flags(flags); + uint64_t Result = FEX::HLE::_SyscallHandler->FM.Openat(dirfs, pathname, flags, mode); + SYSCALL_ERRNO(); + }); + + REGISTER_SYSCALL_IMPL(readlinkat, [](FEXCore::Core::CpuStateFrame* Frame, int dirfd, const char* pathname, char* buf, size_t bufsiz) -> uint64_t { ++ if (!FaultSafeUserMemAccess::IsStringReadable(pathname)) { ++ return -EFAULT; ++ } + uint64_t Result = FEX::HLE::_SyscallHandler->FM.Readlinkat(dirfd, pathname, buf, bufsiz); + SYSCALL_ERRNO(); + }); + + REGISTER_SYSCALL_IMPL(faccessat, [](FEXCore::Core::CpuStateFrame* Frame, int dirfd, const char* pathname, int mode) -> uint64_t { ++ if (!FaultSafeUserMemAccess::IsStringReadable(pathname)) { ++ return -EFAULT; ++ } + uint64_t Result = FEX::HLE::_SyscallHandler->FM.FAccessat(dirfd, pathname, mode); + SYSCALL_ERRNO(); + }); + + REGISTER_SYSCALL_IMPL(faccessat2, [](FEXCore::Core::CpuStateFrame* Frame, int dirfd, const char* pathname, int mode, int flags) -> uint64_t { ++ if (!FaultSafeUserMemAccess::IsStringReadable(pathname)) { ++ return -EFAULT; ++ } + uint64_t Result = FEX::HLE::_SyscallHandler->FM.FAccessat2(dirfd, pathname, mode, flags); + SYSCALL_ERRNO(); + }); +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/FS.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/FS.cpp +index 64c9aae22..9eee296ec 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/FS.cpp ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/FS.cpp +@@ -52,6 +52,9 @@ void RegisterFS(FEX::HLE::SyscallHandler* Handler) { + }); + + REGISTER_SYSCALL_IMPL(readlink, [](FEXCore::Core::CpuStateFrame* Frame, const char* pathname, char* buf, size_t bufsiz) -> uint64_t { ++ if (!FaultSafeUserMemAccess::IsStringReadable(pathname)) { ++ return -EFAULT; ++ } + uint64_t Result = FEX::HLE::_SyscallHandler->FM.Readlink(pathname, buf, bufsiz); + SYSCALL_ERRNO(); + }); +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Info.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Info.cpp +index 1b61282d3..f83006c0a 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Info.cpp ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Info.cpp +@@ -6,6 +6,7 @@ $end_info$ + */ + + #include "LinuxSyscalls/Syscalls.h" ++#include "LinuxSyscalls/PtraceEmu.h" + #include "LinuxSyscalls/x64/Syscalls.h" + #include "LinuxSyscalls/x32/Syscalls.h" + +@@ -34,9 +35,11 @@ using cap_user_header_t = void*; + using cap_user_data_t = void*; + + void RegisterInfo(FEX::HLE::SyscallHandler* Handler) { +- REGISTER_SYSCALL_IMPL(uname, [](FEXCore::Core::CpuStateFrame* Frame, struct utsname* buf) -> uint64_t { ++ REGISTER_SYSCALL_IMPL(uname, [](FEXCore::Core::CpuStateFrame* Frame, struct utsname* ubuf) -> uint64_t { + auto Thread = FEX::HLE::ThreadManager::GetStateObjectFromCPUState(Frame); + ++ struct utsname Out {}; ++ auto buf = &Out; + struct utsname Local {}; + if (::uname(&Local) == 0) { + memcpy(buf->nodename, Local.nodename, sizeof(Local.nodename)); +@@ -66,6 +69,9 @@ void RegisterInfo(FEX::HLE::SyscallHandler* Handler) { + // Tell the guest that we are a 64bit kernel + strcpy(buf->machine, "x86_64"); + } ++ if (FaultSafeUserMemAccess::CopyToUser(ubuf, &Out, sizeof(Out))) { ++ return -EFAULT; ++ } + return 0; + }); + +@@ -97,13 +103,14 @@ void RegisterInfo(FEX::HLE::SyscallHandler* Handler) { + ptrace, [](FEXCore::Core::CpuStateFrame* Frame, int /*enum __ptrace_request*/ request, pid_t pid, void* addr, void* data) -> uint64_t { + uint64_t Result {}; + ++ if (PtraceEmu::HandleRequest(request, pid, addr, data, &Result)) { ++ return Result; ++ } ++ + switch (request) { + case PTRACE_PEEKTEXT: + case PTRACE_PEEKDATA: +- case PTRACE_POKETEXT: +- case PTRACE_POKEDATA: + case PTRACE_ATTACH: +- case PTRACE_DETACH: + // Passthrough these requests. Allows Wine to run the Ubisoft launcher. + Result = ::syscall(SYSCALL_DEF(ptrace), request, pid, addr, data); + SYSCALL_ERRNO(); +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Passthrough.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Passthrough.cpp +index 21816674e..602e17570 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Passthrough.cpp ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Passthrough.cpp +@@ -9,6 +9,13 @@ $end_info$ + #include "LinuxSyscalls/Syscalls.h" + #include "LinuxSyscalls/x64/Syscalls.h" + #include "LinuxSyscalls/x32/Syscalls.h" ++#include "LinuxSyscalls/PtraceEmu.h" ++#include "LinuxSyscalls/SignalTrace.h" ++ ++#include ++#include ++#include ++#include + + #include + #include +@@ -252,8 +259,23 @@ uint64_t SyscallPathPassthrough5(FEXCore::Core::CpuStateFrame* Frame, uint64_t a + } + + static void RegisterCommon(FEX::HLE::SyscallHandler* Handler) { +- REGISTER_SYSCALL_IMPL(read, SyscallPassthrough3); +- REGISTER_SYSCALL_IMPL(write, SyscallPassthrough3); ++ REGISTER_SYSCALL_IMPL(read, [](FEXCore::Core::CpuStateFrame* Frame, int fd, void* buf, size_t count) -> uint64_t { ++ FEX::HLE::_SyscallHandler->PrepareGuestBufferForKernelWrite(Frame->Thread, buf, count); ++ uint64_t Result = ::syscall(SYSCALL_DEF(read), fd, buf, count); ++ if (count == 16 && SigTrace::Enabled()) { ++ const int Errno = errno; ++ SigTrace::Log(::syscall(SYS_gettid), SigTrace::Read16, fd, Result, Result == 16 ? *static_cast(buf) : (1ULL << 63) | Errno); ++ } ++ SYSCALL_ERRNO(); ++ }); ++ REGISTER_SYSCALL_IMPL(write, [](FEXCore::Core::CpuStateFrame* Frame, int fd, const void* buf, size_t count) -> uint64_t { ++ uint64_t Result = ::syscall(SYSCALL_DEF(write), fd, buf, count); ++ if (count == 16 && SigTrace::Enabled()) { ++ const int Errno = errno; ++ SigTrace::Log(::syscall(SYS_gettid), SigTrace::Write16, fd, Result, Result == 16 ? *static_cast(buf) : (1ULL << 63) | Errno); ++ } ++ SYSCALL_ERRNO(); ++ }); + REGISTER_SYSCALL_IMPL(lseek, SyscallPassthrough3); + REGISTER_SYSCALL_IMPL(sched_yield, SyscallPassthrough0); + REGISTER_SYSCALL_IMPL(msync, SyscallPassthrough3); +@@ -264,14 +286,26 @@ static void RegisterCommon(FEX::HLE::SyscallHandler* Handler) { + REGISTER_SYSCALL_IMPL(socket, SyscallPassthrough3); + REGISTER_SYSCALL_IMPL(connect, SyscallPathPassthrough3); + REGISTER_SYSCALL_IMPL(sendto, SyscallPassthrough6); +- REGISTER_SYSCALL_IMPL(recvfrom, SyscallPassthrough6); ++ REGISTER_SYSCALL_IMPL(recvfrom, ++ [](FEXCore::Core::CpuStateFrame* Frame, int sockfd, void* buf, size_t len, int flags, struct sockaddr* src_addr, ++ socklen_t* addrlen) -> uint64_t { ++ FEX::HLE::_SyscallHandler->PrepareGuestBufferForKernelWrite(Frame->Thread, buf, len); ++ uint64_t Result = ::syscall(SYSCALL_DEF(recvfrom), sockfd, buf, len, flags, src_addr, addrlen); ++ SYSCALL_ERRNO(); ++ }); + REGISTER_SYSCALL_IMPL(shutdown, SyscallPassthrough2); + REGISTER_SYSCALL_IMPL(bind, SyscallPathPassthrough3); + REGISTER_SYSCALL_IMPL(listen, SyscallPassthrough2); + REGISTER_SYSCALL_IMPL(getsockname, SyscallPassthrough3); + REGISTER_SYSCALL_IMPL(getpeername, SyscallPassthrough3); + REGISTER_SYSCALL_IMPL(socketpair, SyscallPassthrough4); +- REGISTER_SYSCALL_IMPL(kill, SyscallPassthrough2); ++ REGISTER_SYSCALL_IMPL(kill, [](FEXCore::Core::CpuStateFrame* Frame, pid_t pid, int sig) -> uint64_t { ++ if (SigTrace::Enabled()) { ++ SigTrace::Log(::syscall(SYS_gettid), SigTrace::Kill, sig, pid, 0); ++ } ++ uint64_t Result = ::syscall(SYSCALL_DEF(kill), pid, sig); ++ SYSCALL_ERRNO(); ++ }); + REGISTER_SYSCALL_IMPL(semget, SyscallPassthrough3); + REGISTER_SYSCALL_IMPL(msgget, SyscallPassthrough2); + REGISTER_SYSCALL_IMPL(msgsnd, SyscallPassthrough4); +@@ -334,7 +368,13 @@ static void RegisterCommon(FEX::HLE::SyscallHandler* Handler) { + REGISTER_SYSCALL_IMPL(fgetxattr, SyscallPassthrough4); + REGISTER_SYSCALL_IMPL(flistxattr, SyscallPassthrough3); + REGISTER_SYSCALL_IMPL(fremovexattr, SyscallPassthrough2); +- REGISTER_SYSCALL_IMPL(tkill, SyscallPassthrough2); ++ REGISTER_SYSCALL_IMPL(tkill, [](FEXCore::Core::CpuStateFrame* Frame, pid_t tid, int sig) -> uint64_t { ++ if (SigTrace::Enabled()) { ++ SigTrace::Log(::syscall(SYS_gettid), SigTrace::Kill, sig, tid, 0); ++ } ++ uint64_t Result = ::syscall(SYSCALL_DEF(tkill), tid, sig); ++ SYSCALL_ERRNO(); ++ }); + REGISTER_SYSCALL_IMPL(sched_setaffinity, SyscallPassthrough3); + REGISTER_SYSCALL_IMPL(sched_getaffinity, SyscallPassthrough3); + REGISTER_SYSCALL_IMPL(io_setup, SyscallPassthrough2); +@@ -344,7 +384,13 @@ static void RegisterCommon(FEX::HLE::SyscallHandler* Handler) { + REGISTER_SYSCALL_IMPL(remap_file_pages, SyscallPassthrough5); + REGISTER_SYSCALL_IMPL(timer_getoverrun, SyscallPassthrough1); + REGISTER_SYSCALL_IMPL(timer_delete, SyscallPassthrough1); +- REGISTER_SYSCALL_IMPL(tgkill, SyscallPassthrough3); ++ REGISTER_SYSCALL_IMPL(tgkill, [](FEXCore::Core::CpuStateFrame* Frame, pid_t tgid, pid_t tid, int sig) -> uint64_t { ++ if (SigTrace::Enabled()) { ++ SigTrace::Log(::syscall(SYS_gettid), SigTrace::Kill, sig, tid, tgid); ++ } ++ uint64_t Result = ::syscall(SYSCALL_DEF(tgkill), tgid, tid, sig); ++ SYSCALL_ERRNO(); ++ }); + REGISTER_SYSCALL_IMPL(mbind, SyscallPassthrough6); + REGISTER_SYSCALL_IMPL(set_mempolicy, SyscallPassthrough3); + REGISTER_SYSCALL_IMPL(get_mempolicy, SyscallPassthrough5); +@@ -459,7 +505,11 @@ namespace x64 { + RegisterCommon(Handler); + REGISTER_SYSCALL_IMPL_X64(ftruncate, SyscallPassthrough2); + REGISTER_SYSCALL_IMPL_X64(ioctl, SyscallPassthrough3); +- REGISTER_SYSCALL_IMPL_X64(pread_64, SyscallPassthrough4); ++ REGISTER_SYSCALL_IMPL_X64(pread_64, [](FEXCore::Core::CpuStateFrame* Frame, int fd, void* buf, size_t count, off_t offset) -> uint64_t { ++ FEX::HLE::_SyscallHandler->PrepareGuestBufferForKernelWrite(Frame->Thread, buf, count); ++ uint64_t Result = ::syscall(SYSCALL_DEF(pread_64), fd, buf, count, offset); ++ SYSCALL_ERRNO(); ++ }); + REGISTER_SYSCALL_IMPL_X64(pwrite_64, SyscallPassthrough4); + REGISTER_SYSCALL_IMPL_X64(readv, SyscallPassthrough3); + REGISTER_SYSCALL_IMPL_X64(writev, SyscallPassthrough3); +@@ -473,7 +523,14 @@ namespace x64 { + REGISTER_SYSCALL_IMPL_X64(recvmsg, SyscallPathPassthrough3); + REGISTER_SYSCALL_IMPL_X64(setsockopt, SyscallPassthrough5); + REGISTER_SYSCALL_IMPL_X64(getsockopt, SyscallPathPassthrough5); +- REGISTER_SYSCALL_IMPL_X64(wait4, SyscallPassthrough4); ++ REGISTER_SYSCALL_IMPL_X64(wait4, [](FEXCore::Core::CpuStateFrame* Frame, pid_t pid, int* status, int options, struct rusage* ru) -> uint64_t { ++ uint64_t Result; ++ do { ++ Result = ::syscall(SYSCALL_DEF(wait4), pid, status, options, ru); ++ Result = Result == -1 ? -errno : Result; ++ } while (static_cast(Result) > 0 && PtraceEmu::FixupWaitStatus(static_cast(Result), status)); ++ SYSCALL_ERRNO(); ++ }); + REGISTER_SYSCALL_IMPL_X64(semop, SyscallPassthrough3); + REGISTER_SYSCALL_IMPL_X64(getrlimit, SyscallPassthrough2); + REGISTER_SYSCALL_IMPL_X64(getrusage, SyscallPassthrough2); +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Signals.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Signals.cpp +index 8723026ef..1956b0d52 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Signals.cpp ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Signals.cpp +@@ -25,13 +25,27 @@ struct GuestSigAction; + namespace FEX::HLE { + void RegisterSignals(FEX::HLE::SyscallHandler* Handler) { + REGISTER_SYSCALL_IMPL(rt_sigprocmask, [](FEXCore::Core::CpuStateFrame* Frame, int how, const uint64_t* set, uint64_t* oldset) -> uint64_t { +- return FEX::HLE::_SyscallHandler->GetSignalDelegator()->GuestSigProcMask(FEX::HLE::ThreadManager::GetStateObjectFromCPUState(Frame), +- how, set, oldset); ++ uint64_t NewSet; ++ uint64_t OldSet; ++ if (set && FaultSafeUserMemAccess::CopyFromUser(&NewSet, set, sizeof(NewSet))) { ++ return -EFAULT; ++ } ++ uint64_t Result = FEX::HLE::_SyscallHandler->GetSignalDelegator()->GuestSigProcMask( ++ FEX::HLE::ThreadManager::GetStateObjectFromCPUState(Frame), how, set ? &NewSet : nullptr, oldset ? &OldSet : nullptr); ++ if (Result == 0 && oldset && FaultSafeUserMemAccess::CopyToUser(oldset, &OldSet, sizeof(OldSet))) { ++ return -EFAULT; ++ } ++ return Result; + }); + + REGISTER_SYSCALL_IMPL(rt_sigpending, [](FEXCore::Core::CpuStateFrame* Frame, uint64_t* set, size_t sigsetsize) -> uint64_t { +- return FEX::HLE::_SyscallHandler->GetSignalDelegator()->GuestSigPending(FEX::HLE::ThreadManager::GetStateObjectFromCPUState(Frame), set, +- sigsetsize); ++ uint64_t Pending {}; ++ uint64_t Result = FEX::HLE::_SyscallHandler->GetSignalDelegator()->GuestSigPending( ++ FEX::HLE::ThreadManager::GetStateObjectFromCPUState(Frame), &Pending, sigsetsize); ++ if (Result == 0 && FaultSafeUserMemAccess::CopyToUser(set, &Pending, std::min(sigsetsize, sizeof(Pending)))) { ++ return -EFAULT; ++ } ++ return Result; + }); + + REGISTER_SYSCALL_IMPL(rt_sigsuspend, [](FEXCore::Core::CpuStateFrame* Frame, uint64_t* unewset, size_t sigsetsize) -> uint64_t { +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Stubs.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Stubs.cpp +index 2c3edeef1..5ce7ee8bd 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Stubs.cpp ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Stubs.cpp +@@ -27,7 +27,9 @@ struct CpuStateFrame; + + namespace FEX::HLE { + void RegisterStubs(FEX::HLE::SyscallHandler* Handler) { +- REGISTER_SYSCALL_IMPL(restart_syscall, [](FEXCore::Core::CpuStateFrame* Frame) -> uint64_t { SYSCALL_STUB(restart_syscall); }); ++ REGISTER_SYSCALL_IMPL(restart_syscall, [](FEXCore::Core::CpuStateFrame* Frame) -> uint64_t { ++ return -EINTR; ++ }); + + REGISTER_SYSCALL_IMPL(rseq, [](FEXCore::Core::CpuStateFrame* Frame, struct rseq* rseq, uint32_t rseq_len, int flags, uint32_t sig) -> uint64_t { + // We don't support this +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Thread.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Thread.cpp +index 068fee23e..5f4a60480 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Thread.cpp ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Thread.cpp +@@ -8,6 +8,7 @@ $end_info$ + #include "CodeLoader.h" + + #include "LinuxSyscalls/SignalDelegator.h" ++#include "LinuxSyscalls/SignalTrace.h" + #include "LinuxSyscalls/Syscalls.h" + #include "LinuxSyscalls/Syscalls/Thread.h" + #include "LinuxSyscalls/x64/Syscalls.h" +@@ -43,6 +44,12 @@ $end_info$ + #include + #include + ++#ifndef PR_SET_SYSCALL_USER_DISPATCH ++#define PR_SET_SYSCALL_USER_DISPATCH 59 ++#define PR_SYS_DISPATCH_OFF 0 ++#define PR_SYS_DISPATCH_ON 1 ++#endif ++ + ARG_TO_STR(idtype_t, "%u") + + namespace FEX::HLE { +@@ -500,6 +507,30 @@ void RegisterThread(FEX::HLE::SyscallHandler* Handler) { + return FEX::HLE::_SyscallHandler->SeccompEmulator.Handle(Frame, Operation, 0, reinterpret_cast(arg3)); + } + case PR_GET_SECCOMP: return FEX::HLE::_SyscallHandler->SeccompEmulator.GetSeccomp(Frame); ++ case PR_SET_SYSCALL_USER_DISPATCH: { ++ auto& SUD = FEX::HLE::ThreadManager::GetStateObjectFromCPUState(Frame)->SyscallUserDispatch; ++ switch (arg2) { ++ case PR_SYS_DISPATCH_OFF: ++ if (arg3 || arg4 || arg5) { ++ return -EINVAL; ++ } ++ SUD = {}; ++ return 0; ++ case PR_SYS_DISPATCH_ON: ++ if (arg3 && arg3 + arg4 <= arg3) { ++ return -EINVAL; ++ } ++ if (arg5 && arg5 >= SyscallHandler::TASK_MAX_64BIT) { ++ return -EFAULT; ++ } ++ SUD.Offset = arg3; ++ SUD.Length = arg4; ++ SUD.Selector = arg5; ++ SUD.Enabled = true; ++ return 0; ++ default: return -EINVAL; ++ } ++ } + case PR_GET_AUXV: { + if (arg4 || arg5) { + return -EINVAL; +@@ -532,6 +563,7 @@ void RegisterThread(FEX::HLE::SyscallHandler* Handler) { + return -EPERM; + } + Frame->State.gs_cached = addr; ++ Frame->State.gs_idx = 0; + Result = 0; + break; + case 0x1002: // ARCH_SET_FS +@@ -540,22 +572,27 @@ void RegisterThread(FEX::HLE::SyscallHandler* Handler) { + return -EPERM; + } + Frame->State.fs_cached = addr; ++ Frame->State.fs_idx = 0; + Result = 0; + break; + case 0x1003: // ARCH_GET_FS +- *reinterpret_cast(addr) = Frame->State.fs_cached; +- Result = 0; ++ Result = FaultSafeUserMemAccess::CopyToUser(reinterpret_cast(addr), &Frame->State.fs_cached, sizeof(uint64_t)) ? -EFAULT : 0; + break; + case 0x1004: // ARCH_GET_GS +- *reinterpret_cast(addr) = Frame->State.gs_cached; +- Result = 0; ++ Result = FaultSafeUserMemAccess::CopyToUser(reinterpret_cast(addr), &Frame->State.gs_cached, sizeof(uint64_t)) ? -EFAULT : 0; + break; + case 0x3001: // ARCH_CET_STATUS + Result = -EINVAL; // We don't support CET, return EINVAL + break; + case 0x1011: // ARCH_GET_CPUID ++ if (!FEX::HLE::_SyscallHandler->TM.EnableCPUIDFaulting()) { ++ return 1; ++ } + return (Frame->State.CoreFlags & FEXCore::Core::CoreFlagsEnum::CPUID_ENABLED) == FEXCore::Core::CoreFlagsEnum::CPUID_ENABLED ? 1 : 0; + case 0x1012: // ARCH_SET_CPUID ++ if (!FEX::HLE::_SyscallHandler->TM.EnableCPUIDFaulting()) { ++ return -ENODEV; ++ } + if (addr == 0) { + // Disable CPUID (thus enabling CPUID faulting) + Frame->State.CoreFlags = Frame->State.CoreFlags & ~FEXCore::Core::CoreFlagsEnum::CPUID_ENABLED; +@@ -584,6 +621,7 @@ void RegisterThread(FEX::HLE::SyscallHandler* Handler) { + // Save telemetry if we're exiting. + FEX::HLE::_SyscallHandler->GetSignalDelegator()->SaveTelemetry(); + FEX::HLE::_SyscallHandler->TM.CleanupForExit(); ++ FEX::HLE::SigTrace::CleanupForExit(); + + syscall(SYSCALL_DEF(exit_group), status); + // This will never be reached +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SyscallsSMCTracking.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/SyscallsSMCTracking.cpp +index 5d6c850d8..f9e85a26f 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/SyscallsSMCTracking.cpp ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/SyscallsSMCTracking.cpp +@@ -42,6 +42,40 @@ static void HandleSegfaultForCodeCacheFinalization(FEXCore::Core::InternalThread + } + } + ++void SyscallHandler::InvalidateWrittenCodePage(FEXCore::Core::InternalThreadState* Thread, uint64_t FaultBase, uint64_t EntryBase, ++ const FEX::HLE::VMATracking::VMAEntry& Mapping) { ++ auto UnprotectRegionCallback = [](uintptr_t Start, uintptr_t Length) { ++ auto rv = mprotect((void*)Start, Length, PROT_READ | PROT_WRITE); ++ LogMan::Throw::AFmt(rv == 0, "mprotect({}, {}) failed", Start, Length); ++ }; ++ ++ if (Mapping.Flags.Shared) { ++ LOGMAN_THROW_A_FMT(Mapping.Resource, "VMA tracking error"); ++ ++ auto Offset = FaultBase - EntryBase + Mapping.Offset; ++ ++ auto VMA = Mapping.Resource->FirstVMA; ++ LOGMAN_THROW_A_FMT(VMA, "VMA tracking error"); ++ ++ do { ++ if (VMA->Offset <= Offset && (VMA->Offset + VMA->Length) > Offset) { ++ auto FaultBaseMirrored = Offset - VMA->Offset + VMA->Base; ++ ++ if (VMA->Prot.Writable) { ++ _SyscallHandler->TM.InvalidateGuestCodeRange(Thread, FaultBaseMirrored, FEXCore::Utils::FEX_PAGE_SIZE, UnprotectRegionCallback); ++ } else { ++ _SyscallHandler->TM.InvalidateGuestCodeRange(Thread, FaultBaseMirrored, FEXCore::Utils::FEX_PAGE_SIZE); ++ } ++ ++ _SyscallHandler->SMCHotPages.RecordFault(FaultBaseMirrored, _SyscallHandler->SMCHotPageFaults()); ++ } ++ } while ((VMA = VMA->ResourceNextVMA)); ++ } else { ++ _SyscallHandler->TM.InvalidateGuestCodeRange(Thread, FaultBase, FEXCore::Utils::FEX_PAGE_SIZE, UnprotectRegionCallback); ++ _SyscallHandler->SMCHotPages.RecordFault(FaultBase, _SyscallHandler->SMCHotPageFaults()); ++ } ++} ++ + // Handles segfaults from: + // - call-ret shadow stack overflow + // - guest-side self-modifying code (SMC) +@@ -52,9 +86,11 @@ bool SyscallHandler::HandleSegfault(FEXCore::Core::InternalThreadState* Thread, + auto ThreadObject = FEX::HLE::ThreadManager::GetStateObjectFromFEXCoreThread(Thread); + auto CallRetStackInfo = ThreadObject->GetCallRetStackInfo(); + if (FaultAddress >= CallRetStackInfo.AllocationBase && FaultAddress < CallRetStackInfo.AllocationEnd) { +- // Reset REG_CALLRET_SP to the default location to allow for underflows/overflows +- ArchHelpers::Context::SetArmReg(ucontext, 25, CallRetStackInfo.DefaultLocation); +- return true; ++ const uint64_t CallRetSP = ArchHelpers::Context::GetArmReg(ucontext, 25); ++ if (FaultAddress - (CallRetSP - 16) < 32) { ++ ArchHelpers::Context::SetArmReg(ucontext, 25, CallRetStackInfo.DefaultLocation); ++ return true; ++ } + } + + { +@@ -84,41 +120,16 @@ bool SyscallHandler::HandleSegfault(FEXCore::Core::InternalThreadState* Thread, + } + + auto FaultBase = FEXCore::AlignDown(FaultAddress, FEXCore::Utils::FEX_PAGE_SIZE); +- +- auto UnprotectRegionCallback = [](uintptr_t Start, uintptr_t Length) { +- auto rv = mprotect((void*)Start, Length, PROT_READ | PROT_WRITE); +- LogMan::Throw::AFmt(rv == 0, "mprotect({}, {}) failed", Start, Length); +- }; +- +- if (Entry->second.Flags.Shared) { +- LOGMAN_THROW_A_FMT(Entry->second.Resource, "VMA tracking error"); +- +- auto Offset = FaultBase - Entry->first + Entry->second.Offset; +- +- auto VMA = Entry->second.Resource->FirstVMA; +- LOGMAN_THROW_A_FMT(VMA, "VMA tracking error"); +- +- // Flush all mirrors, remap the page writable as needed +- do { +- if (VMA->Offset <= Offset && (VMA->Offset + VMA->Length) > Offset) { +- auto FaultBaseMirrored = Offset - VMA->Offset + VMA->Base; +- +- if (VMA->Prot.Writable) { +- _SyscallHandler->TM.InvalidateGuestCodeRange(Thread, FaultBaseMirrored, FEXCore::Utils::FEX_PAGE_SIZE, UnprotectRegionCallback); +- } else { +- _SyscallHandler->TM.InvalidateGuestCodeRange(Thread, FaultBaseMirrored, FEXCore::Utils::FEX_PAGE_SIZE); +- } +- } +- } while ((VMA = VMA->ResourceNextVMA)); +- } else { +- _SyscallHandler->TM.InvalidateGuestCodeRange(Thread, FaultBase, FEXCore::Utils::FEX_PAGE_SIZE, UnprotectRegionCallback); +- } ++ InvalidateWrittenCodePage(Thread, FaultBase, Entry->first, Entry->second); + + FEXCORE_PROFILE_INSTANT_INCREMENT(Thread, AccumulatedSMCCount, 1); + ++ constexpr uint64_t MaxStoreSize = 64; ++ const uint64_t StoreWindowStart = FaultAddress > MaxStoreSize ? FaultAddress - MaxStoreSize : 0; ++ + auto CTX = Thread->CTX; + if (CTX->IsAddressInCodeBuffer(Thread, ArchHelpers::Context::GetPc(ucontext)) && !CTX->IsCurrentBlockSingleInst(Thread) && +- CTX->IsAddressInCurrentBlock(Thread, FaultAddress & FEXCore::Utils::FEX_PAGE_MASK, FEXCore::Utils::FEX_PAGE_SIZE)) { ++ CTX->IsAddressInCurrentBlock(Thread, StoreWindowStart, 2 * MaxStoreSize)) { + // If we are not in a single-instruction block, and the SMC write address could intersect with the current block, + // reconstruct the context and repeat the faulting instruction as a single-instruction block so any SMC it performs + // is immediately picked up. +@@ -134,6 +145,48 @@ bool SyscallHandler::HandleSegfault(FEXCore::Core::InternalThreadState* Thread, + } + } + ++void SyscallHandler::PrepareGuestBufferForKernelWrite(FEXCore::Core::InternalThreadState* Thread, const void* Buf, size_t Length) { ++ if (SMCChecks != FEXCore::Config::CONFIG_SMC_MTRACK || Length == 0) [[likely]] { ++ return; ++ } ++ ++ const uint64_t Start = FEXCore::AlignDown(reinterpret_cast(Buf), FEXCore::Utils::FEX_PAGE_SIZE); ++ const uint64_t Last = reinterpret_cast(Buf) + Length - 1 < reinterpret_cast(Buf) ? ++ UINT64_MAX : ++ reinterpret_cast(Buf) + Length - 1; ++ const uint64_t End = FEXCore::AlignDown(Last, FEXCore::Utils::FEX_PAGE_SIZE) + (Last >= UINT64_MAX - FEXCore::Utils::FEX_PAGE_SIZE ? 0 : FEXCore::Utils::FEX_PAGE_SIZE); ++ ++ auto lk = FEXCore::GuardSignalDeferringSection(VMATracking.Mutex, Thread); ++ ++ auto Entry = VMATracking.VMAs.upper_bound(Start); ++ if (Entry != VMATracking.VMAs.begin() && std::prev(Entry)->first + std::prev(Entry)->second.Length > Start) { ++ --Entry; ++ } ++ ++ for (; Entry != VMATracking.VMAs.end() && Entry->first < End; ++Entry) { ++ const auto& Mapping = Entry->second; ++ if (!Mapping.Prot.Writable || !(Mapping.Prot.Executable || Mapping.Flags.Shared)) [[likely]] { ++ continue; ++ } ++ const uint64_t From = std::max(Start, Entry->first); ++ const uint64_t To = std::min(End, Entry->first + Mapping.Length); ++ if (Mapping.Flags.Shared) { ++ for (uint64_t Page = From; Page < To; Page += FEXCore::Utils::FEX_PAGE_SIZE) { ++ InvalidateWrittenCodePage(Thread, Page, Entry->first, Mapping); ++ } ++ } else { ++ TM.InvalidateGuestCodeRange(Thread, From, To - From, [](uintptr_t Start, uintptr_t Length) { ++ auto rv = mprotect(reinterpret_cast(Start), Length, PROT_READ | PROT_WRITE); ++ LogMan::Throw::AFmt(rv == 0, "mprotect({}, {}) failed", Start, Length); ++ }); ++ } ++ } ++} ++ ++bool SyscallHandler::IsSMCHotPage(uint64_t Address) { ++ return SMCHotPages.IsHot(Address); ++} ++ + void SyscallHandler::MarkGuestExecutableRange(FEXCore::Core::InternalThreadState* Thread, uint64_t Start, uint64_t Length) { + const auto Base = Start & FEXCore::Utils::FEX_PAGE_MASK; + const auto Top = FEXCore::AlignUp(Start + Length, FEXCore::Utils::FEX_PAGE_SIZE); +@@ -143,6 +196,18 @@ void SyscallHandler::MarkGuestExecutableRange(FEXCore::Core::InternalThreadState + return; + } + ++ for (auto Page = Base; Page < Top; Page += FEXCore::Utils::FEX_PAGE_SIZE) { ++ if (SMCHotPages.IsHot(Page)) { ++ if (Page > Base) { ++ MarkGuestExecutableRange(Thread, Base, Page - Base); ++ } ++ if (Page + FEXCore::Utils::FEX_PAGE_SIZE < Top) { ++ MarkGuestExecutableRange(Thread, Page + FEXCore::Utils::FEX_PAGE_SIZE, Top - (Page + FEXCore::Utils::FEX_PAGE_SIZE)); ++ } ++ return; ++ } ++ } ++ + auto lk = FEXCore::GuardSignalDeferringSection(VMATracking.Mutex, Thread); + + // Find the first mapping at or after the range ends, or ::end(). +@@ -407,16 +472,24 @@ uint64_t SyscallHandler::GuestMunmap(bool Is64Bit, FEXCore::Core::InternalThread + // To be more optimal the frontend should provide this code with a valid Thread object earlier. + auto lk = FEXCore::GuardSignalDeferringSectionWithFallback(VMATracking.Mutex, Thread); + +- if (reinterpret_cast(addr) < 0x1'0000'0000ULL) { ++ if (!Is64Bit) { + Result = Get32BitAllocator()->Munmap(addr, length); + if (FEX::HLE::HasSyscallError(Result)) { + return Result; + } + } else { ++ constexpr uint64_t X86_64TaskSizeMax = (1ULL << 47) - FEXCore::Utils::FEX_PAGE_SIZE; ++ const uint64_t Addr = reinterpret_cast(addr); ++ if (Addr > X86_64TaskSizeMax || Size > X86_64TaskSizeMax - Addr || (length != 0 && Size == 0)) { ++ return -EINVAL; ++ } + Result = ::munmap(addr, length); + if (Result == -1) { + return -errno; + } ++ if (reinterpret_cast(addr) < 0x1'0000'0000ULL) { ++ Get32BitAllocator()->TrackUnmapped(addr, length); ++ } + } + TrackMunmap(Thread, addr, length); + PendingResourceDeletion = VMATracking.HasPendingResourceDeletions(); +@@ -514,6 +587,21 @@ uint64_t SyscallHandler::GuestMprotect(FEXCore::Core::InternalThreadState* Threa + + { + auto lk = FEXCore::GuardSignalDeferringSection(VMATracking.Mutex, Thread); ++ ++ fextl::vector UnlockedCode; ++ constexpr uint64_t MaxUnlockedCodePages = 64; ++ const auto Base = reinterpret_cast(addr) & FEXCore::Utils::FEX_PAGE_MASK; ++ const auto Top = FEXCore::AlignUp(reinterpret_cast(addr) + len, FEXCore::Utils::FEX_PAGE_SIZE); ++ if (SMCChecks == FEXCore::Config::CONFIG_SMC_MTRACK && SMCHotPageFaults() && (prot & PROT_WRITE) && (prot & PROT_EXEC) && ++ Top > Base && (Top - Base) / FEXCore::Utils::FEX_PAGE_SIZE <= MaxUnlockedCodePages) { ++ for (auto Page = Base; Page < Top; Page += FEXCore::Utils::FEX_PAGE_SIZE) { ++ auto Entry = VMATracking.FindVMAEntry(Page); ++ if (Entry != VMATracking.VMAs.end() && Entry->second.Prot.Executable && !Entry->second.Prot.Writable) { ++ UnlockedCode.push_back(Page); ++ } ++ } ++ } ++ + Result = ::mprotect(addr, len, prot); + if (Result == -1) { + return -errno; +@@ -523,6 +611,10 @@ uint64_t SyscallHandler::GuestMprotect(FEXCore::Core::InternalThreadState* Threa + if (prot & PROT_WRITE) { + ProtectWritableAliasOfCode(reinterpret_cast(addr), FEXCore::AlignUp(len, FEXCore::Utils::FEX_PAGE_SIZE)); + } ++ ++ for (auto Page : UnlockedCode) { ++ SMCHotPages.MarkHot(Page); ++ } + } + + InvalidateCodeRangeIfNecessary(Thread, reinterpret_cast(addr), len, false); +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.cpp +index 8e7d466ed..2e59f2fb5 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.cpp ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.cpp +@@ -1,6 +1,7 @@ + // SPDX-License-Identifier: MIT + + #include "LinuxSyscalls/ThreadManager.h" ++#include "LinuxSyscalls/SamplingProfiler.h" + + #include "LinuxSyscalls/Syscalls.h" + #include "LinuxSyscalls/SignalDelegator.h" +@@ -158,6 +159,16 @@ void ThreadManager::StatAlloc::UnlockAfterFork(FEXCore::Core::InternalThreadStat + ThreadObject->Thread->ThreadStats = AllocateSlot(ThreadObject->ThreadInfo.TID); + } + ++static thread_local FEX::HLE::ThreadStateObject* CurrentThreadObject {}; ++ ++FEX::HLE::ThreadStateObject* ThreadManager::GetCurrentThreadObject() { ++ return CurrentThreadObject; ++} ++ ++void ThreadManager::SetCurrentThreadObject(FEX::HLE::ThreadStateObject* Thread) { ++ CurrentThreadObject = Thread; ++} ++ + uint64_t ThreadManager::SetSignalMask(uint64_t Mask) { + ::syscall(SYSCALL_DEF(rt_sigprocmask), SIG_SETMASK, &Mask, &Mask, 8); + return Mask; +@@ -197,6 +208,16 @@ ThreadManager::CreateThread(const FEXCore::Core::CPUState* NewThreadState, uint6 + Frame->State.callret_sp = ThreadStateObject->GetCallRetStackInfo().DefaultLocation; + + ThreadStateObject->Thread->FrontendPtr = ThreadStateObject; ++ ++ { ++ static std::atomic ThreadCount {0}; ++ FEX_CONFIG_OPT(ProfileSampleHz, PROFILESAMPLEHZ); ++ FEX_CONFIG_OPT(ProfileSampleAllThreads, PROFILESAMPLEALLTHREADS); ++ FEX_CONFIG_OPT(ProfileSampleMinThreads, PROFILESAMPLEMINTHREADS); ++ if (ProfileSampleHz() && ThreadCount.fetch_add(1) + 1 == std::max(ProfileSampleMinThreads(), 1)) { ++ StartSamplingProfiler(SignalDelegation, ProfileSampleHz(), ProfileSampleAllThreads(), ProfileSampleMinThreads() == 0); ++ } ++ } + if (ProfileStats()) { + ThreadStateObject->Thread->ThreadStats = Stat.AllocateSlot(ThreadStateObject->ThreadInfo.TID); + } +@@ -222,8 +243,8 @@ ThreadManager::CreateThread(const FEXCore::Core::CPUState* NewThreadState, uint6 + } + } else { + // Without any thread data to inherit, setup the default gdt. +- // Default code segment indexes match the numbers that the Linux kernel uses. +- Frame->State.cs_idx = FEXCore::Core::CPUState::DEFAULT_USER_CS << 3; ++ Frame->State.cs_idx = ++ Is64BitMode() ? FEXCore::Core::CPUState::DEFAULT_USER_CS_SEL : FEXCore::Core::CPUState::DEFAULT_USER32_CS_SEL; + auto GDT = FEXCore::Core::CPUState::GetSegmentFromIndex(Frame->State, Frame->State.cs_idx); + FEXCore::Core::CPUState::SetGDTBase(GDT, 0); + FEXCore::Core::CPUState::SetGDTLimit(GDT, 0xF'FFFFU); +@@ -237,6 +258,14 @@ ThreadManager::CreateThread(const FEXCore::Core::CPUState* NewThreadState, uint6 + GDT->L = 0; // L = Long Mode = 32-bit + GDT->D = 1; // D = Default Operand Size = 32-bit + } ++ ++ Frame->State.ss_idx = FEXCore::Core::CPUState::DEFAULT_USER_DS_SEL; ++ auto SSGDT = FEXCore::Core::CPUState::GetSegmentFromIndex(Frame->State, Frame->State.ss_idx); ++ FEXCore::Core::CPUState::SetGDTBase(SSGDT, 0); ++ FEXCore::Core::CPUState::SetGDTLimit(SSGDT, 0xF'FFFFU); ++ SSGDT->L = 0; ++ SSGDT->D = 1; ++ Frame->State.ss_cached = FEXCore::Core::CPUState::CalculateGDTBase(*SSGDT); + } + + if (InheritThread) { +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.h b/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.h +index 408cddf71..0a46703ca 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.h ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.h +@@ -15,6 +15,7 @@ $end_info$ + + #include + #include ++#include + #include + #include + #include +@@ -68,6 +69,7 @@ struct ThreadStateObject : public FEXCore::Allocator::FEXAllocOperators { + SignalDelegator* Delegator {}; + + void* AltStackPtr {}; ++ bool AltStackReleaseDeferred {}; + stack_t GuestAltStack { + .ss_sp = nullptr, + .ss_flags = SS_DISABLE, // By default the guest alt stack is disabled +@@ -93,6 +95,27 @@ struct ThreadStateObject : public FEXCore::Allocator::FEXAllocOperators { + fextl::vector Filters {}; + std::atomic PrctlSetPending {false}; + ++ uint64_t SeccompTrapRIP {}; ++ ++ struct { ++ uint64_t Offset; ++ uint64_t Length; ++ uint64_t Selector; ++ bool Enabled; ++ } SyscallUserDispatch {}; ++ ++ uint64_t JITStackSP {}; ++ ++ struct TrapSignalFrame { ++ uint64_t GuestFrame; ++ uint64_t GuestRSP; ++ uint64_t JITStackSP; ++ uint64_t ContextBackup; ++ }; ++ static constexpr size_t MaxTrapSignalFrames = 16; ++ TrapSignalFrame TrapSignalFrames[MaxTrapSignalFrames] {}; ++ size_t TrapSignalFrameCount {}; ++ + // personality emulation. + uint32_t persona {}; + +@@ -190,6 +213,11 @@ public: + return static_cast(Thread->FrontendPtr); + } + ++ static FEX::HLE::ThreadStateObject* GetCurrentThreadObject(); ++ static void SetCurrentThreadObject(FEX::HLE::ThreadStateObject* Thread); ++ ++ FEX_CONFIG_OPT(EnableCPUIDFaulting, ENABLECPUIDFAULTING); ++ + FEX::HLE::ThreadStateObject* CreateThread(const FEXCore::Core::CPUState* NewThreadState = nullptr, uint64_t ParentTID = 0, + FEX::HLE::ThreadStateObject* InheritThread = nullptr); + void TrackThread(FEX::HLE::ThreadStateObject* Thread) { +@@ -220,29 +248,38 @@ public: + } + + void InvalidateGuestCodeRange(FEXCore::Core::InternalThreadState* CallingThread, uint64_t Start, uint64_t Length) { ++ InvalidationStats Stats(CallingThread); + std::lock_guard lk(ThreadCreationMutex); + + // Potential deferred since Thread might not be valid. + // Thread object isn't valid very early in frontend's initialization. + // To be more optimal the frontend should provide this code with a valid Thread object earlier. + auto CodeInvalidationlk = FEXCore::GuardSignalDeferringSectionWithFallback(CTX->GetCodeInvalidationMutex(), CallingThread); +- CTX->InvalidateCodeBuffersCodeRange(Start, Length); +- for (auto& Thread : Threads) { +- CTX->InvalidateThreadCachedCodeRange(Thread->Thread, Start, Length); ++ const bool HadCode = CTX->InvalidateCodeBuffersCodeRange(Start, Length); ++ if (HadCode) { ++ for (auto& Thread : Threads) { ++ CTX->InvalidateThreadCachedCodeRange(Thread->Thread, Start, Length, true); ++ } ++ } else { ++ CTX->InvalidateExecutableRangeCaches(); + } + } + + void InvalidateGuestCodeRange(FEXCore::Core::InternalThreadState* CallingThread, uint64_t Start, uint64_t Length, + FEXCore::Context::CodeRangeInvalidationFn after_callback) { ++ InvalidationStats Stats(CallingThread); + std::lock_guard lk(ThreadCreationMutex); + + // Potential deferred since Thread might not be valid. + // Thread object isn't valid very early in frontend's initialization. + // To be more optimal the frontend should provide this code with a valid Thread object earlier. + auto CodeInvalidationlk = FEXCore::GuardSignalDeferringSectionWithFallback(CTX->GetCodeInvalidationMutex(), CallingThread); +- CTX->InvalidateCodeBuffersCodeRange(Start, Length); +- for (auto& Thread : Threads) { +- CTX->InvalidateThreadCachedCodeRange(Thread->Thread, Start, Length); ++ if (CTX->InvalidateCodeBuffersCodeRange(Start, Length)) { ++ for (auto& Thread : Threads) { ++ CTX->InvalidateThreadCachedCodeRange(Thread->Thread, Start, Length, true); ++ } ++ } else { ++ CTX->InvalidateExecutableRangeCaches(); + } + + // Callback while holding the locks. +@@ -254,6 +291,20 @@ public: + } + + private: ++ struct InvalidationStats { ++ explicit InvalidationStats(FEXCore::Core::InternalThreadState* Thread) ++ : Thread {Thread} ++ , Begin {Thread && Thread->ThreadStats ? FEXCore::SHMStats::GetCycleCounter() : 0} {} ++ ~InvalidationStats() { ++ if (Thread && Thread->ThreadStats) { ++ Thread->ThreadStats->AccumulatedInvalidationCount += 1; ++ Thread->ThreadStats->AccumulatedInvalidationTime += FEXCore::SHMStats::GetCycleCounter() - Begin; ++ } ++ } ++ FEXCore::Core::InternalThreadState* Thread; ++ uint64_t Begin; ++ }; ++ + StatAlloc Stat; + FEXCore::Context::Context* CTX; + FEX::HLE::SignalDelegator* SignalDelegation; +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/Utils/Threads.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/Utils/Threads.cpp +index 8b9c25948..3b37e4a3e 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/Utils/Threads.cpp ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/Utils/Threads.cpp +@@ -347,6 +347,7 @@ namespace PThreads { + Thread->detach(); + + if (LongJumpExit) { ++ FEX::HLE::_SyscallHandler->ReleaseDeferredTLSState(ThreadObject); + // We have ownership of the thread object. Make sure to clean it up to prevent memory leaks. + FEX::HLE::_SyscallHandler->TM.DestroyThread(ThreadObject, true); + if (Status == 0) { +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/x32/FD.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/x32/FD.cpp +index 361bfbec1..25b3b0742 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/x32/FD.cpp ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/x32/FD.cpp +@@ -802,6 +802,7 @@ void RegisterFD(FEX::HLE::SyscallHandler* Handler) { + REGISTER_SYSCALL_IMPL_X32( + pread_64, [](FEXCore::Core::CpuStateFrame* Frame, int fd, void* buf, uint32_t count, uint32_t offset_low, uint32_t offset_high) -> uint64_t { + uint64_t Offset = (uint64_t(offset_high) << 32) | offset_low; ++ FEX::HLE::_SyscallHandler->PrepareGuestBufferForKernelWrite(Frame->Thread, buf, count); + uint64_t Result = ::pread64(fd, buf, count, Offset); + SYSCALL_ERRNO(); + }); +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/x64/EPoll.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/x64/EPoll.cpp +index d1ab9cdf8..84c612940 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/x64/EPoll.cpp ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/x64/EPoll.cpp +@@ -6,6 +6,7 @@ tags: LinuxSyscalls|syscalls-x86-64 + $end_info$ + */ + ++#include "LinuxSyscalls/SignalTrace.h" + #include "LinuxSyscalls/Syscalls.h" + #include "LinuxSyscalls/Types.h" + #include "LinuxSyscalls/x64/Syscalls.h" +@@ -14,6 +15,7 @@ $end_info$ + #include + + #include ++#include + #include + #include + #include +@@ -50,6 +52,9 @@ void RegisterEpoll(FEX::HLE::SyscallHandler* Handler) { + EventPtr = &Event; + } + uint64_t Result = ::syscall(SYSCALL_DEF(epoll_ctl), epfd, op, fd, EventPtr); ++ if (SigTrace::Enabled()) { ++ SigTrace::Log(::syscall(SYS_gettid), SigTrace::EpollCtl, op, fd, (EventPtr ? EventPtr->events : 0) | (Result << 32)); ++ } + if (Result != -1 && event) { + FaultSafeUserMemAccess::VerifyIsWritable(event, sizeof(FEX::HLE::epoll_event_x86)); + *event = Event; +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/x64/FD.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/x64/FD.cpp +index 91b5a103d..4eab76a59 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/x64/FD.cpp ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/x64/FD.cpp +@@ -63,14 +63,16 @@ void RegisterFD(FEX::HLE::SyscallHandler* Handler) { + }); + + REGISTER_SYSCALL_IMPL_X64(stat, [](FEXCore::Core::CpuStateFrame* Frame, const char* pathname, FEX::HLE::x64::guest_stat* buf) -> uint64_t { +- SYSCALL_EFAULT_IF_NULL(pathname); +- FaultSafeUserMemAccess::VerifyIsStringReadableMaxSize(pathname, PATH_MAX); ++ if (!FaultSafeUserMemAccess::IsStringReadable(pathname)) { ++ return -EFAULT; ++ } + struct stat host_stat; + uint64_t Result = FEX::HLE::_SyscallHandler->FM.Stat(pathname, &host_stat); + if (Result != -1) { +- SYSCALL_EFAULT_IF_NULL(buf); +- FaultSafeUserMemAccess::VerifyIsWritable(buf, sizeof(*buf)); +- *buf = host_stat; ++ FEX::HLE::x64::guest_stat guest = host_stat; ++ if (FaultSafeUserMemAccess::CopyToUser(buf, &guest, sizeof(guest))) { ++ return -EFAULT; ++ } + } + SYSCALL_ERRNO(); + }); +@@ -79,36 +81,41 @@ void RegisterFD(FEX::HLE::SyscallHandler* Handler) { + struct stat host_stat; + uint64_t Result = ::fstat(fd, &host_stat); + if (Result != -1) { +- SYSCALL_EFAULT_IF_NULL(buf); +- FaultSafeUserMemAccess::VerifyIsWritable(buf, sizeof(*buf)); +- *buf = host_stat; ++ FEX::HLE::x64::guest_stat guest = host_stat; ++ if (FaultSafeUserMemAccess::CopyToUser(buf, &guest, sizeof(guest))) { ++ return -EFAULT; ++ } + } + SYSCALL_ERRNO(); + }); + + REGISTER_SYSCALL_IMPL_X64(lstat, [](FEXCore::Core::CpuStateFrame* Frame, const char* path, FEX::HLE::x64::guest_stat* buf) -> uint64_t { +- SYSCALL_EFAULT_IF_NULL(path); +- FaultSafeUserMemAccess::VerifyIsStringReadableMaxSize(path, PATH_MAX); ++ if (!FaultSafeUserMemAccess::IsStringReadable(path)) { ++ return -EFAULT; ++ } + struct stat host_stat; + uint64_t Result = FEX::HLE::_SyscallHandler->FM.Lstat(path, &host_stat); + if (Result != -1) { +- SYSCALL_EFAULT_IF_NULL(buf); +- FaultSafeUserMemAccess::VerifyIsWritable(buf, sizeof(*buf)); +- *buf = host_stat; ++ FEX::HLE::x64::guest_stat guest = host_stat; ++ if (FaultSafeUserMemAccess::CopyToUser(buf, &guest, sizeof(guest))) { ++ return -EFAULT; ++ } + } + SYSCALL_ERRNO(); + }); + + REGISTER_SYSCALL_IMPL_X64( + newfstatat, [](FEXCore::Core::CpuStateFrame* Frame, int dirfd, const char* pathname, FEX::HLE::x64::guest_stat* buf, int flag) -> uint64_t { +- SYSCALL_EFAULT_IF_NULL(pathname); +- FaultSafeUserMemAccess::VerifyIsStringReadableMaxSize(pathname, PATH_MAX); ++ if (!FaultSafeUserMemAccess::IsStringReadable(pathname)) { ++ return -EFAULT; ++ } + struct stat host_stat; + uint64_t Result = FEX::HLE::_SyscallHandler->FM.NewFSStatAt(dirfd, pathname, &host_stat, flag); + if (Result != -1) { +- SYSCALL_EFAULT_IF_NULL(buf); +- FaultSafeUserMemAccess::VerifyIsWritable(buf, sizeof(*buf)); +- *buf = host_stat; ++ FEX::HLE::x64::guest_stat guest = host_stat; ++ if (FaultSafeUserMemAccess::CopyToUser(buf, &guest, sizeof(guest))) { ++ return -EFAULT; ++ } + } + SYSCALL_ERRNO(); + }); +@@ -140,8 +147,9 @@ void RegisterFD(FEX::HLE::SyscallHandler* Handler) { + }); + + REGISTER_SYSCALL_IMPL_X64(statfs, [](FEXCore::Core::CpuStateFrame* Frame, const char* path, struct statfs* buf) -> uint64_t { +- SYSCALL_EFAULT_IF_NULL(path); +- FaultSafeUserMemAccess::VerifyIsStringReadableMaxSize(path, PATH_MAX); ++ if (!FaultSafeUserMemAccess::IsStringReadable(path)) { ++ return -EFAULT; ++ } + uint64_t Result = FEX::HLE::_SyscallHandler->FM.Statfs(path, buf); + SYSCALL_ERRNO(); + }); +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/x64/Signals.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/x64/Signals.cpp +index 36726ece6..c7b39bb46 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/x64/Signals.cpp ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/x64/Signals.cpp +@@ -25,10 +25,18 @@ void RegisterSignals(FEX::HLE::SyscallHandler* Handler) { + if (sigsetsize != 8) { + return -EINVAL; + } +- FaultSafeUserMemAccess::VerifyIsReadableOrNull(act, sizeof(GuestSigAction)); +- FaultSafeUserMemAccess::VerifyIsWritableOrNull(oldact, sizeof(GuestSigAction)); ++ GuestSigAction NewAct; ++ GuestSigAction OldAct; ++ if (act && FaultSafeUserMemAccess::CopyFromUser(&NewAct, act, sizeof(NewAct))) { ++ return -EFAULT; ++ } + +- return FEX::HLE::_SyscallHandler->GetSignalDelegator()->RegisterGuestSignalHandler(signum, act, oldact); ++ uint64_t Result = FEX::HLE::_SyscallHandler->GetSignalDelegator()->RegisterGuestSignalHandler(signum, act ? &NewAct : nullptr, ++ oldact ? &OldAct : nullptr); ++ if (Result == 0 && oldact && FaultSafeUserMemAccess::CopyToUser(oldact, &OldAct, sizeof(OldAct))) { ++ return -EFAULT; ++ } ++ return Result; + }); + + REGISTER_SYSCALL_IMPL_X64( +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/x64/Thread.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/x64/Thread.cpp +index c25ff5b94..0ec2933bc 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/x64/Thread.cpp ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/x64/Thread.cpp +@@ -233,6 +233,22 @@ enum Modify_ldt_func : int32_t { + LDT_WRITE = 0x11, + }; + ++static bool GatherStringArray(char* const* User, fextl::vector& Out) { ++ for (size_t i = 0;; ++i) { ++ const char* Str; ++ if (FaultSafeUserMemAccess::CopyFromUser(&Str, &User[i], sizeof(Str))) { ++ return false; ++ } ++ Out.push_back(Str); ++ if (!Str) { ++ return true; ++ } ++ if (!FaultSafeUserMemAccess::IsStringReadable(Str)) { ++ return false; ++ } ++ } ++} ++ + void RegisterThread(FEX::HLE::SyscallHandler* Handler) { + REGISTER_SYSCALL_IMPL_X64(modify_ldt, [](FEXCore::Core::CpuStateFrame* Frame, int func, void* ptr, unsigned long bytecount) -> uint64_t { + switch (func) { +@@ -278,10 +294,17 @@ void RegisterThread(FEX::HLE::SyscallHandler* Handler) { + })); + + REGISTER_SYSCALL_IMPL_X64(sigaltstack, [](FEXCore::Core::CpuStateFrame* Frame, const stack_t* ss, stack_t* old_ss) -> uint64_t { +- FaultSafeUserMemAccess::VerifyIsReadableOrNull(ss, sizeof(*ss)); +- FaultSafeUserMemAccess::VerifyIsWritableOrNull(old_ss, sizeof(*old_ss)); +- return FEX::HLE::_SyscallHandler->GetSignalDelegator()->RegisterGuestSigAltStack( +- FEX::HLE::ThreadManager::GetStateObjectFromCPUState(Frame), ss, old_ss); ++ stack_t NewStack; ++ stack_t OldStack; ++ if (ss && FaultSafeUserMemAccess::CopyFromUser(&NewStack, ss, sizeof(NewStack))) { ++ return -EFAULT; ++ } ++ uint64_t Result = FEX::HLE::_SyscallHandler->GetSignalDelegator()->RegisterGuestSigAltStack( ++ FEX::HLE::ThreadManager::GetStateObjectFromCPUState(Frame), ss ? &NewStack : nullptr, old_ss ? &OldStack : nullptr); ++ if (Result == 0 && old_ss && FaultSafeUserMemAccess::CopyToUser(old_ss, &OldStack, sizeof(OldStack))) { ++ return -EFAULT; ++ } ++ return Result; + }); + + // launch a new process under fex +@@ -290,20 +313,9 @@ void RegisterThread(FEX::HLE::SyscallHandler* Handler) { + fextl::vector Args; + fextl::vector Envp; + +- if (argv) { +- for (int i = 0; argv[i]; i++) { +- Args.push_back(argv[i]); +- } +- +- Args.push_back(nullptr); +- } +- +- if (envp) { +- for (int i = 0; envp[i]; i++) { +- Envp.push_back(envp[i]); +- } +- +- Envp.push_back(nullptr); ++ if (!FaultSafeUserMemAccess::IsStringReadable(pathname) || (argv && !GatherStringArray(argv, Args)) || ++ (envp && !GatherStringArray(envp, Envp))) { ++ return -EFAULT; + } + + auto* const* ArgsPtr = argv ? const_cast(Args.data()) : nullptr; +@@ -319,20 +331,9 @@ void RegisterThread(FEX::HLE::SyscallHandler* Handler) { + fextl::vector Args; + fextl::vector Envp; + +- if (argv) { +- for (int i = 0; argv[i]; i++) { +- Args.push_back(argv[i]); +- } +- +- Args.push_back(nullptr); +- } +- +- if (envp) { +- for (int i = 0; envp[i]; i++) { +- Envp.push_back(envp[i]); +- } +- +- Envp.push_back(nullptr); ++ if (!FaultSafeUserMemAccess::IsStringReadable(pathname) || (argv && !GatherStringArray(argv, Args)) || ++ (envp && !GatherStringArray(envp, Envp))) { ++ return -EFAULT; + } + + FEX::HLE::ExecveAtArgs AtArgs { diff --git a/tools/fex/patches/0022-proc-maps-guest-only-on-small-address-space-hosts.patch b/tools/fex/patches/0022-proc-maps-guest-only-on-small-address-space-hosts.patch new file mode 100644 index 0000000000..0d62f092d4 --- /dev/null +++ b/tools/fex/patches/0022-proc-maps-guest-only-on-small-address-space-hosts.patch @@ -0,0 +1,132 @@ +From: maxjivi05 +Subject: [PATCH] List only guest mappings in /proc//maps on hosts below 47 address bits + +Builds on StonkGuy's /proc emulation from https://github.com/StonkGuy/FEX (eac-2611, MIT). + +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp +index eb12945e4..65b0521c9 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp +@@ -17,7 +17,11 @@ $end_info$ + #include + #include + #include ++#include + #include ++#include ++#include ++#include + #include + #include + #include +@@ -25,9 +29,13 @@ $end_info$ + + #include + ++#include + #include + #include + #include ++#include ++#include ++#include + #include + #include + #include +@@ -609,6 +617,37 @@ EmulatedFDManager::EmulatedFDManager(FEXCore::Context::Context* ctx) + + EmulatedFDManager::~EmulatedFDManager() {} + ++static bool IsSelfProcPath(const char* Path) { ++ const char* P = Path + 6; ++ if (!isdigit(*P)) { ++ return true; ++ } ++ return strtol(P, nullptr, 10) == ::getpid(); ++} ++ ++static bool IsHostArchModule(const char* Path, fextl::unordered_map& Seen) { ++ auto Known = Seen.find(Path); ++ if (Known != Seen.end()) { ++ return Known->second; ++ } ++ bool Host = false; ++ int FD = ::open(Path, O_RDONLY | O_CLOEXEC); ++ if (FD >= 0) { ++ Elf64_Ehdr Header {}; ++ if (::pread(FD, &Header, sizeof(Header), 0) >= static_cast(offsetof(Elf64_Ehdr, e_version)) && ++ memcmp(Header.e_ident, ELFMAG, SELFMAG) == 0) { ++#if defined(__aarch64__) ++ Host = Header.e_machine == EM_AARCH64; ++#else ++ Host = Header.e_machine != EM_X86_64 && Header.e_machine != EM_386; ++#endif ++ } ++ ::close(FD); ++ } ++ Seen.emplace(Path, Host); ++ return Host; ++} ++ + static bool IsProcMapsPath(const char* Path) { + if (strncmp(Path, "/proc/", 6) != 0) { + return false; +@@ -661,14 +700,56 @@ int32_t EmulatedFDManager::ProcMaps(FEXCore::Context::Context* ctx, int32_t fd, + ::close(HostFD); + + constexpr uint64_t X86_64TaskSizeMax = (1ULL << 47) - 4096; ++ const bool HostSharesGuestRange = FEXCore::Allocator::GetHostVABits() < 47; ++ const bool Self = IsSelfProcPath(pathname); ++ fextl::vector> GuestRanges; ++ if (HostSharesGuestRange && Self && FEX::HLE::_SyscallHandler) { ++ auto lk = FEXCore::MaskSignalsAndLockMutex(FEX::HLE::_SyscallHandler->VMATracking.Mutex); ++ GuestRanges.reserve(FEX::HLE::_SyscallHandler->VMATracking.VMAs.size()); ++ for (const auto& [Base, VMA] : FEX::HLE::_SyscallHandler->VMATracking.VMAs) { ++ if (!GuestRanges.empty() && GuestRanges.back().second >= Base) { ++ GuestRanges.back().second = std::max(GuestRanges.back().second, Base + VMA.Length); ++ } else { ++ GuestRanges.emplace_back(Base, Base + VMA.Length); ++ } ++ } ++ } ++ auto IsGuestRange = [&GuestRanges](uint64_t Start, uint64_t End) { ++ auto It = std::upper_bound(GuestRanges.begin(), GuestRanges.end(), Start, ++ [](uint64_t Value, const std::pair& Range) { return Value < Range.first; }); ++ if (It != GuestRanges.begin() && std::prev(It)->second > Start) { ++ return true; ++ } ++ return It != GuestRanges.end() && It->first < End; ++ }; ++ fextl::unordered_map ModuleArch; + fextl::string Out; + Out.reserve(In.size()); + size_t Pos = 0; + while (Pos < In.size()) { + size_t Eol = In.find('\n', Pos); + const size_t End = Eol == fextl::string::npos ? In.size() : Eol + 1; +- const uint64_t Start = strtoull(In.c_str() + Pos, nullptr, 16); +- if (Start < X86_64TaskSizeMax) { ++ char* Cursor {}; ++ const uint64_t Start = strtoull(In.c_str() + Pos, &Cursor, 16); ++ const uint64_t Stop = *Cursor == '-' ? strtoull(Cursor + 1, nullptr, 16) : Start; ++ bool Keep = Start < X86_64TaskSizeMax; ++ if (Keep && HostSharesGuestRange) { ++ if (Self) { ++ Keep = IsGuestRange(Start, Stop); ++ } else { ++ const size_t LineEnd = Eol == fextl::string::npos ? In.size() : Eol; ++ size_t Name = In.find_first_of("/[", Pos); ++ if (Name != fextl::string::npos && Name < LineEnd) { ++ fextl::string Path(In, Name, LineEnd - Name); ++ if (Path.starts_with("[anon:FEX")) { ++ Keep = false; ++ } else if (Path[0] == '/') { ++ Keep = !IsHostArchModule(Path.c_str(), ModuleArch); ++ } ++ } ++ } ++ } ++ if (Keep) { + Out.append(In, Pos, End - Pos); + } + Pos = End; diff --git a/tools/fex/patches/0023-proc-status-seccomp-of-calling-thread.patch b/tools/fex/patches/0023-proc-status-seccomp-of-calling-thread.patch new file mode 100644 index 0000000000..d0550e8db0 --- /dev/null +++ b/tools/fex/patches/0023-proc-status-seccomp-of-calling-thread.patch @@ -0,0 +1,53 @@ +From 597bfab6ff068e0f6c08f63d6940486446967b0d Mon Sep 17 00:00:00 2001 +From: maxjivi05 +Date: Wed, 2 Dec 2026 18:21:23 -0500 +Subject: [PATCH] Report the calling thread's seccomp mode in /proc/self/status + +Builds on StonkGuy's anti-cheat emulation from https://github.com/StonkGuy/FEX (eac-2611, MIT). + +--- + .../LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp | 6 +++++- + .../Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.h | 10 ++++++++++ + 2 files changed, 15 insertions(+), 1 deletion(-) + +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp +index 65b0521c9..ce36b988b 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp +@@ -797,7 +797,11 @@ int32_t EmulatedFDManager::ProcStatus(FEXCore::Context::Context* ctx, int32_t fd + Buf[Len] = '\0'; + + uint32_t SeccompMode = SECCOMP_MODE_DISABLED; +- if (auto* Thread = FEX::HLE::ThreadManager::GetCurrentThreadObject()) { ++ auto* Thread = FEX::HLE::_SyscallHandler ? FEX::HLE::_SyscallHandler->TM.FindThreadByTID(::gettid()) : nullptr; ++ if (!Thread) { ++ Thread = FEX::HLE::ThreadManager::GetCurrentThreadObject(); ++ } ++ if (Thread) { + SeccompMode = Thread->SeccompMode; + } + +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.h b/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.h +index 0a46703ca..9c5f9f1c2 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.h ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.h +@@ -290,6 +290,16 @@ public: + return &Threads; + } + ++ FEX::HLE::ThreadStateObject* FindThreadByTID(uint32_t TID) { ++ std::lock_guard lk(ThreadCreationMutex); ++ for (auto* Thread : Threads) { ++ if (Thread->ThreadInfo.TID == TID) { ++ return Thread; ++ } ++ } ++ return nullptr; ++ } ++ + private: + struct InvalidationStats { + explicit InvalidationStats(FEXCore::Core::InternalThreadState* Thread) +-- +2.43.0 + diff --git a/tools/fex/patches/0024-read-host-status-directly.patch b/tools/fex/patches/0024-read-host-status-directly.patch new file mode 100644 index 0000000000..8a5268c7e7 --- /dev/null +++ b/tools/fex/patches/0024-read-host-status-directly.patch @@ -0,0 +1,105 @@ +From ab6a01db9e93e7f143b9a3da5b40dcb160b960f3 Mon Sep 17 00:00:00 2001 +From: maxjivi05 +Date: Wed, 2 Dec 2026 18:25:20 -0500 +Subject: [PATCH] Read FEX's own /proc/self/status with a direct openat system + call + +Builds on StonkGuy's anti-cheat emulation from https://github.com/StonkGuy/FEX (eac-2611, MIT). + +--- + FEXHeaderUtils/FEXHeaderUtils/Syscalls.h | 30 +++++++++++++++++++ + .../EmulatedFiles/EmulatedFiles.cpp | 3 +- + .../LinuxSyscalls/PtraceEmu.cpp | 3 +- + 3 files changed, 34 insertions(+), 2 deletions(-) + +diff --git a/FEXHeaderUtils/FEXHeaderUtils/Syscalls.h b/FEXHeaderUtils/FEXHeaderUtils/Syscalls.h +index dae3d3bcc..c0f3eb3ed 100644 +--- a/FEXHeaderUtils/FEXHeaderUtils/Syscalls.h ++++ b/FEXHeaderUtils/FEXHeaderUtils/Syscalls.h +@@ -4,6 +4,7 @@ + #include + + #include ++#include + #include + #include + #include +@@ -123,4 +124,33 @@ inline int32_t gettid() { + + #endif + ++#ifndef _WIN32 ++inline int32_t openat_kernel(int dirfd, const char* pathname, int flags) { ++#if defined(__aarch64__) ++ register long x0 asm("x0") = dirfd; ++ register long x1 asm("x1") = reinterpret_cast(pathname); ++ register long x2 asm("x2") = flags; ++ register long x3 asm("x3") = 0; ++ register long x8 asm("x8") = SYS_openat; ++ asm volatile("svc #0" : "+r"(x0) : "r"(x1), "r"(x2), "r"(x3), "r"(x8) : "memory"); ++ if (x0 < 0) { ++ errno = static_cast(-x0); ++ return -1; ++ } ++ return static_cast(x0); ++#elif defined(__x86_64__) ++ long ret; ++ register long r10 asm("r10") = 0; ++ asm volatile("syscall" : "=a"(ret) : "a"(SYS_openat), "D"(dirfd), "S"(pathname), "d"(flags), "r"(r10) : "rcx", "r11", "memory"); ++ if (ret < 0) { ++ errno = static_cast(-ret); ++ return -1; ++ } ++ return static_cast(ret); ++#else ++ return static_cast(::syscall(SYS_openat, dirfd, pathname, flags)); ++#endif ++} ++#endif ++ + } // namespace FHU::Syscalls +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp +index ce36b988b..19bfc814f 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp +@@ -14,6 +14,7 @@ $end_info$ + #include "LinuxSyscalls/Syscalls.h" + #include "LinuxSyscalls/EmulatedFiles/EmulatedFiles.h" + ++#include + #include + #include + #include +@@ -785,7 +786,7 @@ int32_t EmulatedFDManager::ProcStatus(FEXCore::Context::Context* ctx, int32_t fd + char Buf[8192]; + ssize_t Len = 0; + { +- int HostFD = ::open("/proc/self/status", O_RDONLY | O_CLOEXEC); ++ int HostFD = FHU::Syscalls::openat_kernel(AT_FDCWD, "/proc/self/status", O_RDONLY | O_CLOEXEC); + if (HostFD >= 0) { + Len = ::read(HostFD, Buf, sizeof(Buf) - 1); + ::close(HostFD); +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/PtraceEmu.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/PtraceEmu.cpp +index ca4c86063..49ece24a3 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/PtraceEmu.cpp ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/PtraceEmu.cpp +@@ -3,6 +3,7 @@ + #include "LinuxSyscalls/PtraceEmu.h" + #include "LinuxSyscalls/Syscalls.h" + ++#include + #include + #include + +@@ -133,7 +134,7 @@ namespace { + } + + bool HasHostTracer() { +- const int fd = ::open("/proc/self/status", O_RDONLY | O_CLOEXEC); ++ const int fd = FHU::Syscalls::openat_kernel(AT_FDCWD, "/proc/self/status", O_RDONLY | O_CLOEXEC); + if (fd < 0) { + return true; + } +-- +2.43.0 + diff --git a/tools/fex/patches/0025-ptrace-state-across-exec.patch b/tools/fex/patches/0025-ptrace-state-across-exec.patch new file mode 100644 index 0000000000..6c1bcc618f --- /dev/null +++ b/tools/fex/patches/0025-ptrace-state-across-exec.patch @@ -0,0 +1,104 @@ +From 38ee3ef08d9bfd8312fccff688290572da82ef2a Mon Sep 17 00:00:00 2001 +From: maxjivi05 +Date: Wed, 2 Dec 2026 18:41:52 -0500 +Subject: [PATCH] Hand the tracee's ptrace state across exec + +Builds on StonkGuy's anti-cheat emulation from https://github.com/StonkGuy/FEX (eac-2611, MIT). + +--- + .../LinuxSyscalls/PtraceEmu.cpp | 54 ++++++++++++++++++- + 1 file changed, 53 insertions(+), 1 deletion(-) + +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/PtraceEmu.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/PtraceEmu.cpp +index 49ece24a3..62acdb0da 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/PtraceEmu.cpp ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/PtraceEmu.cpp +@@ -266,6 +266,38 @@ namespace { + ::close(fd); + } + ++ bool AdoptionTried = false; ++ ++ void AdoptSharedPage() { ++ if (AdoptionTried || Current != &StaticState || !IsMainThread()) { ++ return; ++ } ++ AdoptionTried = true; ++ const int fd = OpenSidecar("state", ::getpid(), O_RDWR); ++ if (fd < 0) { ++ return; ++ } ++ if (!HasHostTracer()) { ++ ::close(fd); ++ return; ++ } ++ void* Page = ::mmap(nullptr, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); ++ ::close(fd); ++ if (Page == MAP_FAILED) { ++ return; ++ } ++ auto* S = static_cast(Page); ++ if (S->Magic != SharedState::MagicValue) { ++ ::munmap(Page, 4096); ++ return; ++ } ++ S->Pending = 0; ++ S->DirtyMask = 0; ++ S->SignalNumber = 0; ++ S->FlushLen = 0; ++ Current = S; ++ } ++ + struct Remote { + uint8_t* Mapped = nullptr; + uintptr_t StaticAddr = 0; +@@ -332,6 +364,22 @@ namespace { + return &Remotes.emplace(Pid, std::move(R)).first->second; + } + ++ bool KeepAcrossExec(pid_t Pid) { ++ { ++ std::lock_guard lk(RemotesLock); ++ auto It = Remotes.find(Pid); ++ if (It != Remotes.end()) { ++ return It->second.Mapped != nullptr; ++ } ++ } ++ const int fd = OpenSidecar("state", Pid, O_RDONLY); ++ if (fd < 0) { ++ return false; ++ } ++ ::close(fd); ++ return true; ++ } ++ + void Forget(pid_t Pid, bool Exited) { + std::lock_guard lk(RemotesLock); + auto It = Remotes.find(Pid); +@@ -470,10 +518,12 @@ namespace { + + + bool IsAttached() { ++ AdoptSharedPage(); + return Current->Attached != 0; + } + + bool WantsSyscallStops() { ++ AdoptSharedPage(); + return Current->SyscallStops && IsMainThread(); + } + +@@ -610,7 +660,9 @@ bool FixupWaitStatus(pid_t Pid, int* Status) { + + if ((St >> 16) == X86_PTRACE_EVENT_EXEC) { + CaptureExecPath(Pid); +- Forget(Pid, false); ++ if (!KeepAcrossExec(Pid)) { ++ Forget(Pid, false); ++ } + } + + if (WSTOPSIG(St) == SIGSTOP) { +-- +2.43.0 + diff --git a/tools/fex/patches/0026-emulated-proc-files-behind-host-memfd.patch b/tools/fex/patches/0026-emulated-proc-files-behind-host-memfd.patch new file mode 100644 index 0000000000..0ebaff5209 --- /dev/null +++ b/tools/fex/patches/0026-emulated-proc-files-behind-host-memfd.patch @@ -0,0 +1,78 @@ +From 834075bdee10fb0a1c7a7f499a0bb97162370b5d Mon Sep 17 00:00:00 2001 +From: maxjivi05 +Date: Wed, 2 Dec 2026 18:58:13 -0500 +Subject: [PATCH] Serve emulated proc files by the requested path when the host + returns a memfd + +Builds on StonkGuy's anti-cheat emulation from https://github.com/StonkGuy/FEX (eac-2611, MIT). +--- + .../LinuxEmulation/LinuxSyscalls/FileManagement.cpp | 11 +++++++---- + .../LinuxEmulation/LinuxSyscalls/FileManagement.h | 2 +- + 2 files changed, 8 insertions(+), 5 deletions(-) + +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/FileManagement.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/FileManagement.cpp +index 62b6a2d27..b76e96e58 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/FileManagement.cpp ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/FileManagement.cpp +@@ -785,7 +785,7 @@ static int OpenatWithoutOpenat2(int DirFD, const char* Pathname, int Flags, uint + return ::syscall(SYSCALL_DEF(openat), DirFD, Resolved, Flags, Mode); + } + +-bool FileManager::ReplaceEmuFd(int fd, int flags, uint32_t mode) { ++bool FileManager::ReplaceEmuFd(int fd, int flags, uint32_t mode, const char* RequestedPath) { + char Tmp[PATH_MAX + 1]; + + if (fd < 0) { +@@ -801,6 +801,9 @@ bool FileManager::ReplaceEmuFd(int fd, int flags, uint32_t mode) { + + // And try to open via EmuFD + auto EmuFd = EmuFD.Open(Tmp, flags, mode); ++ if (EmuFd == -1 && RequestedPath && RequestedPath[0] == '/' && strncmp(Tmp, "/memfd:", 7) == 0) { ++ EmuFd = EmuFD.Open(RequestedPath, flags, mode); ++ } + if (EmuFd == -1) { + return false; + } +@@ -841,7 +844,7 @@ uint64_t FileManager::Open(const char* pathname, int flags, uint32_t mode) { + fd = ::open(SelfPath, flags, mode); + } + +- ReplaceEmuFd(fd, flags, mode); ++ ReplaceEmuFd(fd, flags, mode, SelfPath); + } else { + fd = ::open(SelfPath, flags, mode); + } +@@ -1135,7 +1138,7 @@ uint64_t FileManager::Openat([[maybe_unused]] int dirfs, const char* pathname, i + fd = ::syscall(SYSCALL_DEF(openat), dirfs, SelfPath, flags, mode); + } + +- ReplaceEmuFd(fd, flags, mode); ++ ReplaceEmuFd(fd, flags, mode, SelfPath); + } else { + fd = ::syscall(SYSCALL_DEF(openat), dirfs, SelfPath, flags, mode); + } +@@ -1173,7 +1176,7 @@ uint64_t FileManager::Openat2(int dirfs, const char* pathname, FEX::HLE::open_ho + fd = ::syscall(SYSCALL_DEF(openat2), dirfs, SelfPath, how, usize); + } + +- ReplaceEmuFd(fd, how->flags, how->mode); ++ ReplaceEmuFd(fd, how->flags, how->mode, SelfPath); + } else { + fd = ::syscall(SYSCALL_DEF(openat2), dirfs, SelfPath, how, usize); + } +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/FileManagement.h b/Source/Tools/LinuxEmulation/LinuxSyscalls/FileManagement.h +index b11f096f7..a86539972 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/FileManagement.h ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/FileManagement.h +@@ -102,7 +102,7 @@ public: + fextl::string GetEmulatedPath(const char* pathname, bool FollowSymlink = false) const; + fextl::string GetHostPath(fextl::string& Path, bool AliasedOnly) const; + +- bool ReplaceEmuFd(int fd, int flags, uint32_t mode); ++ bool ReplaceEmuFd(int fd, int flags, uint32_t mode, const char* RequestedPath); + + #if defined(ASSERTIONS_ENABLED) && ASSERTIONS_ENABLED + void TrackFEXFD(int FD) noexcept { +-- +2.43.0 + diff --git a/tools/fex/patches/0027-fixed-guest-memory-above-host-address-limit.patch b/tools/fex/patches/0027-fixed-guest-memory-above-host-address-limit.patch new file mode 100644 index 0000000000..b19386b095 --- /dev/null +++ b/tools/fex/patches/0027-fixed-guest-memory-above-host-address-limit.patch @@ -0,0 +1,3258 @@ +From 4e237204720bf57c8e4b7dae1ff74b5e341763e6 Mon Sep 17 00:00:00 2001 +From: maxjivi05 +Date: Wed, 2 Dec 2026 20:01:44 -0500 +Subject: [PATCH] Map fixed guest memory above a small host address space + +Hosts with 39-bit or 42-bit user address spaces cannot place x86-64 +mappings that ask for a fixed address above that limit. Such mappings +are now backed by host memory at any address, and guest accesses to +them are redirected through a per-thread single-instruction trampoline. +Syscall arguments that point into these mappings are translated, and +writes to code in them invalidate translated blocks. + +Builds on StonkGuy's anti-cheat emulation from https://github.com/StonkGuy/FEX (eac-2611, MIT). +--- + Source/Tools/LinuxEmulation/CMakeLists.txt | 1 + + .../LinuxSyscalls/GuestHighMemory.cpp | 2754 +++++++++++++++++ + .../LinuxSyscalls/GuestHighMemory.h | 74 + + .../LinuxSyscalls/SignalDelegator.cpp | 5 + + .../LinuxEmulation/LinuxSyscalls/Syscalls.cpp | 53 +- + .../LinuxSyscalls/Syscalls/Memory.cpp | 30 + + .../LinuxSyscalls/SyscallsSMCTracking.cpp | 61 +- + .../LinuxSyscalls/ThreadManager.cpp | 2 + + .../LinuxSyscalls/ThreadManager.h | 34 + + 9 files changed, 2984 insertions(+), 30 deletions(-) + create mode 100644 Source/Tools/LinuxEmulation/LinuxSyscalls/GuestHighMemory.cpp + create mode 100644 Source/Tools/LinuxEmulation/LinuxSyscalls/GuestHighMemory.h + +diff --git a/Source/Tools/LinuxEmulation/CMakeLists.txt b/Source/Tools/LinuxEmulation/CMakeLists.txt +index 3f02104..acf4c4c 100644 +--- a/Source/Tools/LinuxEmulation/CMakeLists.txt ++++ b/Source/Tools/LinuxEmulation/CMakeLists.txt +@@ -18,6 +18,7 @@ add_library(LinuxEmulation STATIC + LinuxSyscalls/Seccomp/BPFEmitter.cpp + LinuxSyscalls/Seccomp/Dumper.cpp + LinuxSyscalls/SignalDelegator.cpp ++ LinuxSyscalls/GuestHighMemory.cpp + LinuxSyscalls/Syscalls.cpp + LinuxSyscalls/SyscallsSMCTracking.cpp + LinuxSyscalls/SyscallsVMATracking.cpp +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/GuestHighMemory.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/GuestHighMemory.cpp +new file mode 100644 +index 0000000..4483499 +--- /dev/null ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/GuestHighMemory.cpp +@@ -0,0 +1,2754 @@ ++#include "LinuxSyscalls/GuestHighMemory.h" ++#include "LinuxSyscalls/Syscalls.h" ++#include "LinuxSyscalls/SignalDelegator.h" ++#include "LinuxSyscalls/ThreadManager.h" ++#include "LinuxSyscalls/x64/SyscallsEnum.h" ++#include "ArchHelpers/MContext.h" ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++namespace FEX::HLE::GuestHighMemory { ++namespace { ++ constexpr uint64_t TaskTop = (1ULL << 47) - FEXCore::Utils::FEX_PAGE_SIZE; ++ constexpr uint32_t MaxRegions = 1024; ++ ++ struct Region { ++ std::atomic Guest; ++ std::atomic Size; ++ std::atomic Host; ++ std::atomic Code; ++ std::atomic Prot; ++ }; ++ ++ struct RegionView { ++ uint64_t Guest; ++ uint64_t Size; ++ uint64_t Host; ++ uint32_t Index; ++ bool Code; ++ uint8_t Prot; ++ }; ++ ++ struct HostRange { ++ uint64_t Start; ++ uint64_t Size; ++ }; ++ ++ constexpr uint32_t MaxAccessPieces = 2; ++ ++ struct AccessPiece { ++ uint64_t Guest; ++ uint64_t Host; ++ uint64_t Size; ++ uint8_t Prot; ++ bool Code; ++ }; ++ ++ Region Regions[MaxRegions]; ++ std::atomic Count {0}; ++ HostRange Retired[MaxRegions]; ++ uint32_t RetiredCount {}; ++ std::atomic Sequence {0}; ++ ++ uint64_t HostLimit() { ++ static const uint64_t Limit = [] { ++ const auto Bits = FEXCore::Allocator::GetHostVABits(); ++ return Bits >= 47 ? TaskTop : (1ULL << Bits); ++ }(); ++ return Limit; ++ } ++ ++ void BeginWrite() { ++ Sequence.fetch_add(1, std::memory_order_acq_rel); ++ } ++ ++ void EndWrite() { ++ Sequence.fetch_add(1, std::memory_order_release); ++ } ++ ++ bool FindLocked(uint64_t Address, RegionView* Out) { ++ const auto Entries = Count.load(std::memory_order_acquire); ++ for (uint32_t i = 0; i < Entries; ++i) { ++ const auto Guest = Regions[i].Guest.load(std::memory_order_relaxed); ++ const auto Size = Regions[i].Size.load(std::memory_order_relaxed); ++ if (Address >= Guest && Address - Guest < Size) { ++ Out->Guest = Guest; ++ Out->Size = Size; ++ Out->Host = Regions[i].Host.load(std::memory_order_relaxed); ++ Out->Code = Regions[i].Code.load(std::memory_order_relaxed); ++ Out->Prot = Regions[i].Prot.load(std::memory_order_relaxed); ++ Out->Index = i; ++ return true; ++ } ++ } ++ return false; ++ } ++ ++ template ++ auto ReadConsistent(Fn&& Body) { ++ for (;;) { ++ const auto Before = Sequence.load(std::memory_order_acquire); ++ if (Before & 1) { ++ continue; ++ } ++ const auto Result = Body(); ++ std::atomic_thread_fence(std::memory_order_acquire); ++ if (Sequence.load(std::memory_order_relaxed) == Before) { ++ return Result; ++ } ++ } ++ } ++ ++ bool SpanLocked(uint64_t Address, uint64_t Length, uint64_t* Host) { ++ RegionView View; ++ if (!FindLocked(Address, &View)) { ++ *Host = Address; ++ return true; ++ } ++ *Host = View.Host + (Address - View.Guest); ++ if (Length > TaskTop - Address) { ++ return false; ++ } ++ const auto End = Address + Length; ++ auto GuestEnd = View.Guest + View.Size; ++ auto HostEnd = View.Host + View.Size; ++ while (End > GuestEnd) { ++ if (!FindLocked(GuestEnd, &View) || View.Host != HostEnd) { ++ return false; ++ } ++ GuestEnd += View.Size; ++ HostEnd += View.Size; ++ } ++ return true; ++ } ++ ++ uint32_t PlanAccessLocked(uint64_t Address, uint64_t Size, AccessPiece* Pieces) { ++ uint32_t Parts = 0; ++ uint64_t Done = 0; ++ while (Done < Size) { ++ RegionView View; ++ if (Parts == MaxAccessPieces || !FindLocked(Address + Done, &View)) { ++ return 0; ++ } ++ const auto Offset = Address + Done - View.Guest; ++ const auto Length = std::min(Size - Done, View.Size - Offset); ++ Pieces[Parts++] = {Address + Done, View.Host + Offset, Length, View.Prot, View.Code}; ++ Done += Length; ++ } ++ return Parts; ++ } ++ ++ template ++ uint64_t ApplyToRegionsLocked(uint64_t Address, uint64_t Length, uint64_t WrapError, Fn&& Apply) { ++ if (Address & (FEXCore::Utils::FEX_PAGE_SIZE - 1)) { ++ return -EINVAL; ++ } ++ if (Length == 0) { ++ return 0; ++ } ++ const auto Size = FEXCore::AlignUp(Length, FEXCore::Utils::FEX_PAGE_SIZE); ++ if (Size == 0 || Size > UINT64_MAX - Address) { ++ return WrapError; ++ } ++ const auto End = Address + std::min(Size, TaskTop - Address); ++ uint64_t Covered = 0; ++ const auto Entries = Count.load(std::memory_order_acquire); ++ for (uint32_t i = 0; i < Entries; ++i) { ++ const auto Guest = Regions[i].Guest.load(std::memory_order_relaxed); ++ const auto RegionEnd = Guest + Regions[i].Size.load(std::memory_order_relaxed); ++ if (RegionEnd <= Address || Guest >= End) { ++ continue; ++ } ++ const auto OverlapStart = std::max(Guest, Address); ++ const auto OverlapEnd = std::min(RegionEnd, End); ++ const auto Host = Regions[i].Host.load(std::memory_order_relaxed) + (OverlapStart - Guest); ++ if (Apply(reinterpret_cast(Host), OverlapEnd - OverlapStart, i) != 0) { ++ return -errno; ++ } ++ Covered += OverlapEnd - OverlapStart; ++ } ++ return Covered == Size ? 0 : -ENOMEM; ++ } ++ ++ uint64_t NeighbourHint(uint64_t Address, uint64_t Size) { ++ const auto Entries = Count.load(std::memory_order_relaxed); ++ for (uint32_t i = 0; i < Entries; ++i) { ++ const auto Guest = Regions[i].Guest.load(std::memory_order_relaxed); ++ const auto RegionSize = Regions[i].Size.load(std::memory_order_relaxed); ++ const auto Host = Regions[i].Host.load(std::memory_order_relaxed); ++ if (Guest + RegionSize == Address) { ++ return Host + RegionSize; ++ } ++ if (Guest == Address + Size && Host >= Size) { ++ return Host - Size; ++ } ++ } ++ return 0; ++ } ++ ++ void SetEntry(uint32_t i, uint64_t Guest, uint64_t Size, uint64_t Host, bool Code, uint8_t Prot) { ++ Regions[i].Guest.store(Guest, std::memory_order_relaxed); ++ Regions[i].Size.store(Size, std::memory_order_relaxed); ++ Regions[i].Host.store(Host, std::memory_order_relaxed); ++ Regions[i].Code.store(Code, std::memory_order_relaxed); ++ Regions[i].Prot.store(Prot, std::memory_order_relaxed); ++ } ++ ++ void RemoveEntry(uint32_t i) { ++ const auto Last = Count.load(std::memory_order_relaxed) - 1; ++ if (i != Last) { ++ SetEntry(i, Regions[Last].Guest.load(std::memory_order_relaxed), Regions[Last].Size.load(std::memory_order_relaxed), ++ Regions[Last].Host.load(std::memory_order_relaxed), Regions[Last].Code.load(std::memory_order_relaxed), ++ Regions[Last].Prot.load(std::memory_order_relaxed)); ++ } ++ Count.store(Last, std::memory_order_release); ++ } ++ ++ bool AddEntry(uint64_t Guest, uint64_t Size, uint64_t Host, bool Code, uint8_t Prot) { ++ const auto Entries = Count.load(std::memory_order_relaxed); ++ if (Entries >= MaxRegions) { ++ return false; ++ } ++ SetEntry(Entries, Guest, Size, Host, Code, Prot); ++ Count.store(Entries + 1, std::memory_order_release); ++ return true; ++ } ++ ++ bool HasRoomLocked(uint64_t Address, uint64_t Length, uint32_t Added) { ++ const auto End = Address + Length; ++ const auto Entries = Count.load(std::memory_order_relaxed); ++ uint64_t After = Entries + Added; ++ for (uint32_t i = 0; i < Entries; ++i) { ++ const auto Guest = Regions[i].Guest.load(std::memory_order_relaxed); ++ const auto RegionEnd = Guest + Regions[i].Size.load(std::memory_order_relaxed); ++ if (RegionEnd <= Address || Guest >= End) { ++ continue; ++ } ++ if (Guest >= Address && RegionEnd <= End) { ++ --After; ++ } else if (Guest < Address && RegionEnd > End) { ++ ++After; ++ } ++ } ++ return After <= MaxRegions; ++ } ++ ++ void ReleaseRetiredLocked() { ++ uint32_t i = 0; ++ while (i < RetiredCount) { ++ if (::munmap(reinterpret_cast(Retired[i].Start), Retired[i].Size) == 0) { ++ Retired[i] = Retired[--RetiredCount]; ++ } else { ++ ++i; ++ } ++ } ++ } ++ ++ void UnmapHost(uint64_t Start, uint64_t Size) { ++ if (::munmap(reinterpret_cast(Start), Size) == 0) { ++ return; ++ } ++ ::madvise(reinterpret_cast(Start), Size, MADV_DONTNEED); ++ for (uint32_t i = 0; i < RetiredCount; ++i) { ++ if (Retired[i].Start + Retired[i].Size == Start) { ++ Retired[i].Size += Size; ++ return; ++ } ++ if (Start + Size == Retired[i].Start) { ++ Retired[i] = {Start, Retired[i].Size + Size}; ++ return; ++ } ++ } ++ if (RetiredCount < MaxRegions) { ++ Retired[RetiredCount++] = {Start, Size}; ++ } ++ } ++ ++ int UnmapLocked(uint64_t Address, uint64_t Length) { ++ ReleaseRetiredLocked(); ++ if (!HasRoomLocked(Address, Length, 0)) { ++ return -ENOMEM; ++ } ++ const auto End = Address + Length; ++ uint32_t Overlapping = 0; ++ for (uint32_t i = 0; i < Count.load(std::memory_order_relaxed); ++i) { ++ const auto Guest = Regions[i].Guest.load(std::memory_order_relaxed); ++ if (Guest < End && Guest + Regions[i].Size.load(std::memory_order_relaxed) > Address) { ++ ++Overlapping; ++ } ++ } ++ if (RetiredCount + Overlapping > MaxRegions) { ++ return -ENOMEM; ++ } ++ uint32_t i = 0; ++ while (i < Count.load(std::memory_order_relaxed)) { ++ const auto Guest = Regions[i].Guest.load(std::memory_order_relaxed); ++ const auto Size = Regions[i].Size.load(std::memory_order_relaxed); ++ const auto Host = Regions[i].Host.load(std::memory_order_relaxed); ++ const auto Code = Regions[i].Code.load(std::memory_order_relaxed); ++ const auto Prot = Regions[i].Prot.load(std::memory_order_relaxed); ++ const auto RegionEnd = Guest + Size; ++ if (RegionEnd <= Address || Guest >= End) { ++ ++i; ++ continue; ++ } ++ const auto OverlapStart = std::max(Guest, Address); ++ const auto OverlapEnd = std::min(RegionEnd, End); ++ UnmapHost(Host + (OverlapStart - Guest), OverlapEnd - OverlapStart); ++ ++ if (OverlapStart == Guest && OverlapEnd == RegionEnd) { ++ RemoveEntry(i); ++ continue; ++ } ++ if (OverlapStart == Guest) { ++ SetEntry(i, OverlapEnd, RegionEnd - OverlapEnd, Host + (OverlapEnd - Guest), Code, Prot); ++ } else if (OverlapEnd == RegionEnd) { ++ SetEntry(i, Guest, OverlapStart - Guest, Host, Code, Prot); ++ } else { ++ if (!AddEntry(OverlapEnd, RegionEnd - OverlapEnd, Host + (OverlapEnd - Guest), Code, Prot)) { ++ return -ENOMEM; ++ } ++ SetEntry(i, Guest, OverlapStart - Guest, Host, Code, Prot); ++ } ++ ++i; ++ } ++ return 0; ++ } ++ ++ constexpr uint8_t TrackedProt(int Prot) { ++ return Prot & (PROT_READ | PROT_WRITE | PROT_EXEC); ++ } ++ ++ int SplitLocked(uint64_t Address, uint64_t Length) { ++ const auto Size = FEXCore::AlignUp(Length, FEXCore::Utils::FEX_PAGE_SIZE); ++ if (Size == 0) { ++ return 0; ++ } ++ const uint64_t Boundaries[] = {Address, Address + std::min(Size, TaskTop - Address)}; ++ uint32_t Needed = 0; ++ const auto Entries = Count.load(std::memory_order_relaxed); ++ for (const auto Boundary : Boundaries) { ++ for (uint32_t i = 0; i < Entries; ++i) { ++ const auto Guest = Regions[i].Guest.load(std::memory_order_relaxed); ++ if (Boundary > Guest && Boundary - Guest < Regions[i].Size.load(std::memory_order_relaxed)) { ++ ++Needed; ++ } ++ } ++ } ++ if (Entries + Needed > MaxRegions) { ++ return -ENOMEM; ++ } ++ for (const auto Boundary : Boundaries) { ++ for (uint32_t i = 0; i < Count.load(std::memory_order_relaxed); ++i) { ++ const auto Guest = Regions[i].Guest.load(std::memory_order_relaxed); ++ const auto RegionSize = Regions[i].Size.load(std::memory_order_relaxed); ++ if (Boundary <= Guest || Boundary - Guest >= RegionSize) { ++ continue; ++ } ++ const auto Host = Regions[i].Host.load(std::memory_order_relaxed); ++ const auto Code = Regions[i].Code.load(std::memory_order_relaxed); ++ const auto Prot = Regions[i].Prot.load(std::memory_order_relaxed); ++ AddEntry(Boundary, Guest + RegionSize - Boundary, Host + (Boundary - Guest), Code, Prot); ++ SetEntry(i, Guest, Boundary - Guest, Host, Code, Prot); ++ break; ++ } ++ } ++ return 0; ++ } ++ ++ void CoalesceLocked(uint64_t Address, uint64_t End) { ++ uint32_t i = 0; ++ while (i < Count.load(std::memory_order_relaxed)) { ++ const auto Entries = Count.load(std::memory_order_relaxed); ++ const auto Size = Regions[i].Size.load(std::memory_order_relaxed); ++ const auto RegionEnd = Regions[i].Guest.load(std::memory_order_relaxed) + Size; ++ const auto HostEnd = Regions[i].Host.load(std::memory_order_relaxed) + Size; ++ const auto Code = Regions[i].Code.load(std::memory_order_relaxed); ++ const auto Prot = Regions[i].Prot.load(std::memory_order_relaxed); ++ uint32_t Next = Entries; ++ if (RegionEnd >= Address && RegionEnd <= End) { ++ for (uint32_t j = 0; j < Entries; ++j) { ++ if (Regions[j].Guest.load(std::memory_order_relaxed) == RegionEnd && Regions[j].Host.load(std::memory_order_relaxed) == HostEnd && ++ Regions[j].Code.load(std::memory_order_relaxed) == Code && Regions[j].Prot.load(std::memory_order_relaxed) == Prot) { ++ Next = j; ++ break; ++ } ++ } ++ } ++ if (Next == Entries) { ++ ++i; ++ continue; ++ } ++ Regions[i].Size.store(Size + Regions[Next].Size.load(std::memory_order_relaxed), std::memory_order_relaxed); ++ RemoveEntry(Next); ++ if (i == Entries - 1 || Next < i) { ++ i = Next; ++ } ++ } ++ } ++ ++ constexpr uint32_t RtField(uint32_t Insn) { ++ return Insn & 0x1f; ++ } ++ ++ constexpr uint32_t RnField(uint32_t Insn) { ++ return (Insn >> 5) & 0x1f; ++ } ++ ++ constexpr uint32_t Rt2Field(uint32_t Insn) { ++ return (Insn >> 10) & 0x1f; ++ } ++ ++ constexpr uint32_t RsField(uint32_t Insn) { ++ return (Insn >> 16) & 0x1f; ++ } ++ ++ constexpr bool IsLoadStore(uint32_t Insn) { ++ return (Insn & 0x0a000000) == 0x08000000; ++ } ++ ++ constexpr bool IsLiteralLoad(uint32_t Insn) { ++ return (Insn & 0x3b000000) == 0x18000000; ++ } ++ ++ constexpr bool IsExclusive(uint32_t Insn) { ++ if ((Insn & 0x3f800000) != 0x08000000) { ++ return false; ++ } ++ return (Insn & (1U << 21)) == 0 || (Insn & (1U << 31)) != 0; ++ } ++ ++ constexpr bool IsSingleRegister(uint32_t Insn) { ++ return (Insn & 0x3a000000) == 0x38000000 || (Insn & 0x3f200c00) == 0x19000000; ++ } ++ ++ constexpr bool IsWrite(uint32_t Insn) { ++ if ((Insn & 0x3b200c00) == 0x38200000) { ++ return ((Insn >> 12) & 0xf) != 0xc; ++ } ++ if ((Insn & 0x3f200000) == 0x08200000 && Rt2Field(Insn) == 0x1f) { ++ return true; ++ } ++ if (IsSingleRegister(Insn)) { ++ const auto Opc = (Insn >> 22) & 3; ++ return ((Insn >> 26) & 1) ? (Opc & 1) == 0 : Opc == 0; ++ } ++ return (Insn & (1U << 22)) == 0; ++ } ++ ++ constexpr bool IsOrderedAccess(uint32_t Insn) { ++ if ((Insn & 0x3f200c00) == 0x19000000) { ++ const auto Opc = (Insn >> 22) & 3; ++ const auto SizeBits = Insn >> 30; ++ return Opc < 2 || (Opc == 2 && SizeBits < 3) || (Opc == 3 && SizeBits < 2); ++ } ++ return (Insn & 0x3fbf7c00) == 0x089f7c00 || (Insn & 0x3ffffc00) == 0x38bfc000; ++ } ++ ++ constexpr uint64_t ExtendOrdered(uint32_t Insn, uint64_t Value) { ++ const auto Bits = 8U << (Insn >> 30); ++ const auto Opc = (Insn >> 22) & 3; ++ if ((Insn & 0x3f200c00) != 0x19000000 || Bits == 64 || Opc < 2) { ++ return Value; ++ } ++ const auto Signed = static_cast(static_cast(Value << (64 - Bits)) >> (64 - Bits)); ++ return Opc == 3 ? Signed & 0xffffffffULL : Signed; ++ } ++ ++ constexpr uint32_t ProbeInstruction(uint32_t Scratch) { ++ return 0x39400000 | (Scratch << 5) | Scratch; ++ } ++ ++ constexpr bool IsExclusiveLoad(uint32_t Insn) { ++ return (Insn & (1U << 22)) != 0; ++ } ++ ++ constexpr bool IsExclusivePair(uint32_t Insn) { ++ return (Insn & (1U << 21)) != 0; ++ } ++ ++ constexpr bool ExclusiveReachable(uint32_t Insn, uint8_t Prot) { ++ if (IsExclusiveLoad(Insn)) { ++ return (Prot & (PROT_READ | PROT_WRITE)) != 0; ++ } ++ return (Prot & PROT_WRITE) != 0; ++ } ++ ++ constexpr uint32_t ExclusiveElementSize(uint32_t Insn) { ++ return 1U << (Insn >> 30); ++ } ++ ++ uint64_t ReadReg(void* UContext, uint32_t Reg) { ++ return Reg == 31 ? 0 : ArchHelpers::Context::GetArmReg(UContext, Reg); ++ } ++ ++ void WriteReg(void* UContext, uint32_t Reg, uint64_t Value) { ++ if (Reg != 31) { ++ ArchHelpers::Context::SetArmReg(UContext, Reg, Value); ++ } ++ } ++ ++ uint64_t ElementMask(uint32_t Size) { ++ return Size == 8 ? ~0ULL : (1ULL << (Size * 8)) - 1; ++ } ++ ++ uint64_t LoadElement(uint64_t Host, uint32_t Size) { ++ switch (Size) { ++ case 1: return __atomic_load_n(reinterpret_cast(Host), __ATOMIC_SEQ_CST); ++ case 2: return __atomic_load_n(reinterpret_cast(Host), __ATOMIC_SEQ_CST); ++ case 4: return __atomic_load_n(reinterpret_cast(Host), __ATOMIC_SEQ_CST); ++ default: return __atomic_load_n(reinterpret_cast(Host), __ATOMIC_SEQ_CST); ++ } ++ } ++ ++ bool CompareExchange(uint64_t Host, uint32_t Size, uint64_t ExpectedLow, uint64_t ExpectedHigh, uint64_t Low, uint64_t High) { ++ switch (Size) { ++ case 1: { ++ auto Expected = static_cast(ExpectedLow); ++ return __atomic_compare_exchange_n(reinterpret_cast(Host), &Expected, static_cast(Low), false, ++ __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); ++ } ++ case 2: { ++ auto Expected = static_cast(ExpectedLow); ++ return __atomic_compare_exchange_n(reinterpret_cast(Host), &Expected, static_cast(Low), false, ++ __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); ++ } ++ case 4: { ++ auto Expected = static_cast(ExpectedLow); ++ return __atomic_compare_exchange_n(reinterpret_cast(Host), &Expected, static_cast(Low), false, ++ __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); ++ } ++ case 8: { ++ auto Expected = ExpectedLow; ++ return __atomic_compare_exchange_n(reinterpret_cast(Host), &Expected, Low, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); ++ } ++ default: { ++ auto Expected = (static_cast(ExpectedHigh) << 64) | ExpectedLow; ++ const auto Desired = (static_cast(High) << 64) | Low; ++ return __atomic_compare_exchange_n(reinterpret_cast(Host), &Expected, Desired, false, __ATOMIC_SEQ_CST, ++ __ATOMIC_SEQ_CST); ++ } ++ } ++ } ++ ++ template ++ bool EmulateExclusive(MonitorType& Monitor, uint32_t Insn, uint64_t Host, void* UContext) { ++ const auto Element = ExclusiveElementSize(Insn); ++ const bool Pair = IsExclusivePair(Insn); ++ const auto Size = Pair ? Element * 2 : Element; ++ if (Host & (Size - 1)) { ++ return false; ++ } ++ ++ if (IsExclusiveLoad(Insn)) { ++ uint64_t Low {}; ++ uint64_t High {}; ++ if (Pair && Element == 8) { ++ Low = LoadElement(Host, 8); ++ High = LoadElement(Host + 8, 8); ++ WriteReg(UContext, RtField(Insn), Low); ++ WriteReg(UContext, Rt2Field(Insn), High); ++ } else if (Pair) { ++ Low = LoadElement(Host, 8); ++ WriteReg(UContext, RtField(Insn), Low & 0xffffffffULL); ++ WriteReg(UContext, Rt2Field(Insn), Low >> 32); ++ } else { ++ Low = LoadElement(Host, Element); ++ WriteReg(UContext, RtField(Insn), Low); ++ } ++ Monitor.Host = Host; ++ Monitor.Size = Size; ++ Monitor.Low = Low; ++ Monitor.High = High; ++ Monitor.Valid = true; ++ return true; ++ } ++ ++ uint64_t Low {}; ++ uint64_t High {}; ++ if (Pair && Element == 8) { ++ Low = ReadReg(UContext, RtField(Insn)); ++ High = ReadReg(UContext, Rt2Field(Insn)); ++ } else if (Pair) { ++ Low = (ReadReg(UContext, RtField(Insn)) & 0xffffffffULL) | (ReadReg(UContext, Rt2Field(Insn)) << 32); ++ } else { ++ Low = ReadReg(UContext, RtField(Insn)) & ElementMask(Element); ++ } ++ const bool Stored = Monitor.Valid && Monitor.Host == Host && Monitor.Size == Size && ++ CompareExchange(Host, Size, Monitor.Low, Monitor.High, Low, High); ++ Monitor.Valid = false; ++ WriteReg(UContext, RsField(Insn), Stored ? 0 : 1); ++ return true; ++ } ++ ++ int64_t SignedField(uint32_t Insn, uint32_t Shift, uint32_t Bits) { ++ return static_cast(static_cast(Insn >> Shift) << (64 - Bits)) >> (64 - Bits); ++ } ++ ++ bool DecodeAccess(uint32_t Insn, void* UContext, uint64_t* Address, uint32_t* Size, bool* Plain) { ++ const auto Base = ArchHelpers::Context::GetArmReg(UContext, RnField(Insn)); ++ const auto SizeBits = Insn >> 30; ++ const bool Vector = (Insn >> 26) & 1; ++ const auto Scale = Vector && ((Insn >> 23) & 1) && SizeBits == 0 ? 4U : SizeBits; ++ *Address = Base; ++ *Plain = false; ++ if ((Insn & 0x3f000000) == 0x08000000) { ++ const bool Pair = (Insn & (1U << 21)) && !(Insn & (1U << 23)); ++ *Size = Pair ? 8U << (SizeBits & 1) : 1U << SizeBits; ++ return true; ++ } ++ if ((Insn & 0x3f200c00) == 0x19000000) { ++ *Address = Base + SignedField(Insn, 12, 9); ++ *Size = 1U << SizeBits; ++ return true; ++ } ++ if ((Insn & 0x3b200c00) == 0x38200000) { ++ *Size = 1U << SizeBits; ++ return !Vector; ++ } ++ *Plain = true; ++ if ((Insn & 0x3b000000) == 0x39000000) { ++ *Address = Base + (static_cast((Insn >> 10) & 0xfff) << Scale); ++ *Size = 1U << Scale; ++ return true; ++ } ++ if ((Insn & 0x3b200000) == 0x38000000) { ++ *Address = ((Insn >> 10) & 3) == 1 ? Base : Base + SignedField(Insn, 12, 9); ++ *Size = 1U << Scale; ++ return true; ++ } ++ if ((Insn & 0x3b200c00) == 0x38200800) { ++ const auto Option = (Insn >> 13) & 7; ++ if ((Option & 2) == 0) { ++ return false; ++ } ++ auto Offset = ReadReg(UContext, RsField(Insn)); ++ if ((Option & 1) == 0) { ++ Offset = (Option & 4) ? static_cast(static_cast(static_cast(Offset))) : static_cast(Offset); ++ } ++ *Address = Base + (Offset << (((Insn >> 12) & 1) ? Scale : 0)); ++ *Size = 1U << Scale; ++ return true; ++ } ++ if ((Insn & 0x3a000000) == 0x28000000) { ++ if (SizeBits == 3) { ++ return false; ++ } ++ const auto Element = Vector ? 4U << SizeBits : (SizeBits == 2 ? 8U : 4U); ++ *Address = ((Insn >> 23) & 3) == 1 ? Base : Base + SignedField(Insn, 15, 7) * static_cast(Element); ++ *Size = 2 * Element; ++ return true; ++ } ++ if ((Insn & 0xbfbf0000) == 0x0c000000 || (Insn & 0xbfa00000) == 0x0c800000) { ++ uint32_t Registers = 0; ++ switch ((Insn >> 12) & 0xf) { ++ case 0x0: ++ case 0x2: Registers = 4; break; ++ case 0x4: ++ case 0x6: Registers = 3; break; ++ case 0x7: Registers = 1; break; ++ case 0x8: ++ case 0xa: Registers = 2; break; ++ default: return false; ++ } ++ *Size = Registers * ((Insn & (1U << 30)) ? 16U : 8U); ++ return true; ++ } ++ if ((Insn & 0xbf9f0000) == 0x0d000000 || (Insn & 0xbf800000) == 0x0d800000) { ++ const auto Opcode = (Insn >> 13) & 7; ++ const auto Elements = (((Opcode & 1) << 1) | ((Insn >> 21) & 1)) + 1; ++ const auto Bits = (Insn >> 10) & 3; ++ uint32_t Element = 0; ++ switch (Opcode >> 1) { ++ case 0: Element = 1; break; ++ case 1: Element = (Bits & 1) ? 0 : 2; break; ++ case 2: Element = Bits == 0 ? 4 : (Bits == 1 && !((Insn >> 12) & 1) ? 8 : 0); break; ++ default: Element = 1U << Bits; break; ++ } ++ *Size = Elements * Element; ++ return Element != 0; ++ } ++ return false; ++ } ++ ++ bool HostContiguous(const AccessPiece* Pieces, uint32_t Parts) { ++ for (uint32_t i = 1; i < Parts; ++i) { ++ if (Pieces[i - 1].Host + Pieces[i - 1].Size != Pieces[i].Host) { ++ return false; ++ } ++ } ++ return true; ++ } ++ ++ bool PiecesReachable(const AccessPiece* Pieces, uint32_t Parts, bool Write) { ++ const uint8_t Need = Write ? PROT_WRITE : PROT_READ | PROT_WRITE; ++ for (uint32_t i = 0; i < Parts; ++i) { ++ if ((Pieces[i].Prot & Need) == 0) { ++ return false; ++ } ++ } ++ return true; ++ } ++ ++ template ++ uint32_t CopyPieces(uint8_t* Bounce, const PieceType* Pieces, uint32_t Parts, bool Gather) { ++ uint64_t Offset = 0; ++ for (uint32_t i = 0; i < Parts; ++i) { ++ auto* Host = reinterpret_cast(Pieces[i].Host); ++ const auto Failed = Gather ? FaultSafeUserMemAccess::CopyFromUser(Bounce + Offset, Host, Pieces[i].Size) : ++ FaultSafeUserMemAccess::CopyToUser(Host, Bounce + Offset, Pieces[i].Size); ++ if (Failed != 0) { ++ return i; ++ } ++ Offset += Pieces[i].Size; ++ } ++ return Parts; ++ } ++ ++ template ++ uint32_t EmulateOrdered(uint32_t Insn, const PieceType* Pieces, uint32_t Parts, void* UContext) { ++ const auto Size = 1U << (Insn >> 30); ++ uint8_t Bytes[8] {}; ++ std::atomic_thread_fence(std::memory_order_seq_cst); ++ const auto Gathered = CopyPieces(Bytes, Pieces, Parts, true); ++ if (Gathered != Parts) { ++ return Gathered; ++ } ++ uint64_t Value {}; ++ if (IsWrite(Insn)) { ++ Value = ReadReg(UContext, RtField(Insn)); ++ memcpy(Bytes, &Value, Size); ++ const auto Scattered = CopyPieces(Bytes, Pieces, Parts, false); ++ std::atomic_thread_fence(std::memory_order_seq_cst); ++ return Scattered; ++ } ++ memcpy(&Value, Bytes, Size); ++ std::atomic_thread_fence(std::memory_order_seq_cst); ++ WriteReg(UContext, RtField(Insn), ExtendOrdered(Insn, Value)); ++ return Parts; ++ } ++ ++ constexpr int HeldSignals[] = {SIGSEGV, SIGBUS, SIGTRAP}; ++ ++ constexpr uint64_t HeldSignalMask() { ++ uint64_t Mask = 0; ++ for (int Sig : HeldSignals) { ++ Mask |= 1ULL << (Sig - 1); ++ } ++ return Mask; ++ } ++ ++ constexpr int HeldSignalSlot(int Signal) { ++ for (int Slot = 0; Slot < static_cast(std::size(HeldSignals)); ++Slot) { ++ if (HeldSignals[Slot] == Signal) { ++ return Slot; ++ } ++ } ++ return -1; ++ } ++ ++ template ++ bool DeferWhileHeld(HoldState& Hold, int Signal, const siginfo_t* Info) { ++ const int Slot = HeldSignalSlot(Signal); ++ if (!Hold.Held || Info->si_code > SI_USER || Slot < 0) { ++ return false; ++ } ++ Hold.Deferred |= 1U << Slot; ++ Hold.DeferredInfo[Slot] = *Info; ++ return true; ++ } ++ ++ template ++ uint64_t ReleaseMappings(HoldState& Hold) { ++ if (!Hold.Held) { ++ return 0; ++ } ++ FEX::HLE::_SyscallHandler->VMATracking.Mutex.unlock_shared(); ++ Hold.Held = false; ++ uint64_t Requeued = 0; ++ for (int Slot = 0; Slot < static_cast(std::size(HeldSignals)); ++Slot) { ++ if (Hold.Deferred & (1U << Slot)) { ++ Requeued |= 1ULL << (HeldSignals[Slot] - 1); ++ } ++ } ++ if (Requeued == 0) { ++ return 0; ++ } ++ ::syscall(SYS_rt_sigprocmask, SIG_BLOCK, &Requeued, nullptr, sizeof(Requeued)); ++ const auto Process = ::syscall(SYS_getpid); ++ const auto Self = ::syscall(SYS_gettid); ++ for (int Slot = 0; Slot < static_cast(std::size(HeldSignals)); ++Slot) { ++ if (Hold.Deferred & (1U << Slot)) { ++ ::syscall(SYS_rt_tgsigqueueinfo, Process, Self, HeldSignals[Slot], &Hold.DeferredInfo[Slot]); ++ } ++ } ++ Hold.Deferred = 0; ++ return Requeued; ++ } ++ ++ template ++ class MappingHold final { ++ public: ++ explicit MappingHold(HoldState& Hold, bool Deliver = false) ++ : Hold {Hold} ++ , Deliver {Deliver} { ++ const uint64_t All = ~0ULL; ++ ::syscall(SYS_rt_sigprocmask, SIG_SETMASK, &All, &Mask, sizeof(Mask)); ++ FEX::HLE::_SyscallHandler->VMATracking.Mutex.lock_shared(); ++ Hold.Held = true; ++ const uint64_t Blocked = ~HeldSignalMask(); ++ ::syscall(SYS_rt_sigprocmask, SIG_SETMASK, &Blocked, nullptr, sizeof(Blocked)); ++ } ++ MappingHold(const MappingHold&) = delete; ++ MappingHold& operator=(const MappingHold&) = delete; ++ ~MappingHold() { ++ if (!Kept) { ++ const uint64_t Requeued = ReleaseMappings(Hold); ++ const uint64_t Restored = Deliver ? Mask : Mask | Requeued; ++ ::syscall(SYS_rt_sigprocmask, SIG_SETMASK, &Restored, nullptr, sizeof(Restored)); ++ } ++ } ++ void Keep() { ++ Kept = true; ++ } ++ ++ private: ++ HoldState& Hold; ++ uint64_t Mask {}; ++ bool Deliver {}; ++ bool Kept {}; ++ }; ++ ++ int PickScratch(uint32_t Insn) { ++ constexpr int Candidates[] = {16, 17, 9, 10, 11, 12, 13, 14, 15, 8, 7, 6, 5, 4, 3, 2}; ++ for (auto Reg : Candidates) { ++ const auto R = static_cast(Reg); ++ if (R != RtField(Insn) && R != RnField(Insn) && R != Rt2Field(Insn) && R != RsField(Insn)) { ++ return Reg; ++ } ++ } ++ return -1; ++ } ++ ++ constexpr uint32_t TrapInstruction = 0xd4200000 | (0xf3e << 5); ++ ++ using TrapState = decltype(FEX::HLE::ThreadStateObject::HighMemoryTrap); ++ ++ bool EnsureTrapCode(TrapState& Trap) { ++ if (!Trap.Code) { ++ void* Page = FEXCore::Allocator::VirtualAlloc(FEXCore::Utils::FEX_PAGE_SIZE, true); ++ if (Page == MAP_FAILED || Page == nullptr) { ++ return false; ++ } ++ Trap.Code = static_cast(Page); ++ } ++ return true; ++ } ++ ++ void ArmTrap(TrapState& Trap, void* UContext, uint32_t Instruction, uint64_t ScratchValue, bool Probe) { ++ auto* Code = reinterpret_cast(Trap.Code); ++ Code[0] = Instruction; ++ Code[1] = TrapInstruction; ++ __builtin___clear_cache(reinterpret_cast(Code), reinterpret_cast(Code + 2)); ++ Trap.Probe = Probe; ++ ArchHelpers::Context::SetArmReg(UContext, Trap.Scratch, ScratchValue); ++ ArchHelpers::Context::SetPc(UContext, reinterpret_cast(Code)); ++ Trap.Active = true; ++ } ++ ++ void ArmProbe(TrapState& Trap, void* UContext, uint64_t Guest, uint64_t Host) { ++ Trap.Parts = 0; ++ Trap.Delta = Host - Guest; ++ ArmTrap(Trap, UContext, ProbeInstruction(Trap.Scratch), Host, true); ++ } ++ ++ void LeaveTrap(TrapState& Trap, void* UContext, uint64_t ResumePC) { ++ memcpy(&ArchHelpers::Context::GetUContext(UContext)->uc_sigmask, &Trap.SavedMask, sizeof(Trap.SavedMask)); ++ ArchHelpers::Context::SetPc(UContext, ResumePC); ++ Trap.Parts = 0; ++ Trap.Probe = false; ++ Trap.Active = false; ++ ReleaseMappings(Trap.Mappings); ++ } ++ ++ void RedeliverFromTrap(TrapState& Trap, siginfo_t* SigInfo, void* UContext) { ++ ArchHelpers::Context::SetArmReg(UContext, Trap.Scratch, Trap.SavedScratch); ++ ArchHelpers::Context::SetArmReg(UContext, Trap.Base, Trap.BaseBefore); ++ SigInfo->si_addr = reinterpret_cast(reinterpret_cast(SigInfo->si_addr) - Trap.Delta); ++ LeaveTrap(Trap, UContext, Trap.ResumePC - 4); ++ } ++ ++ constexpr uint64_t MaxIoVectors = 1024; ++ ++ enum class VectorKind : uint8_t { ++ None, ++ Io, ++ SentMessage, ++ ReceivedMessage, ++ SentMessageArray, ++ ReceivedMessageArray, ++ IoSubmit, ++ IoEvents, ++ PageList, ++ FutexWaiters, ++ FutexRequeue, ++ FileControl, ++ Capabilities, ++ PerfAttribute, ++ SchedulerAttribute, ++ HandleAt, ++ OpenHandle, ++ MountRequest, ++ LandlockRule, ++ }; ++ ++ constexpr uint8_t BitmapElements = 0xff; ++ constexpr uint8_t MessageElements = 0xfe; ++ constexpr uint8_t PageElements = 0xfd; ++ ++ struct Layout { ++ uint8_t Pointers; ++ uint64_t Lengths; ++ VectorKind Vector {VectorKind::None}; ++ uint64_t ElementSizes {}; ++ uint64_t FixedSizes {}; ++ uint8_t Strings {}; ++ }; ++ ++ struct LayoutEntry { ++ uint32_t Syscall; ++ Layout Arguments; ++ }; ++ ++ constexpr uint8_t Ptr(uint32_t Arg) { ++ return 1U << Arg; ++ } ++ ++ constexpr uint64_t CountWord = 0x10; ++ constexpr uint64_t CountSigned = 0x20; ++ ++ constexpr uint64_t Sized(uint32_t Pointer, uint32_t Length) { ++ return static_cast(Length + 1) << (Pointer * 8); ++ } ++ ++ constexpr uint64_t IntSized(uint32_t Pointer, uint32_t Length) { ++ return Sized(Pointer, Length) | ((CountWord | CountSigned) << (Pointer * 8)); ++ } ++ ++ constexpr uint64_t UintSized(uint32_t Pointer, uint32_t Length) { ++ return Sized(Pointer, Length) | (CountWord << (Pointer * 8)); ++ } ++ ++ constexpr uint64_t LongSized(uint32_t Pointer, uint32_t Length) { ++ return Sized(Pointer, Length) | (CountSigned << (Pointer * 8)); ++ } ++ ++ constexpr uint64_t Through(uint32_t Pointer, uint32_t Length) { ++ return static_cast(Length + 9) << (Pointer * 8); ++ } ++ ++ constexpr uint32_t LengthArgument(const Layout& Arguments, uint32_t Pointer) { ++ return (Arguments.Lengths >> (Pointer * 8)) & 0x7; ++ } ++ ++ constexpr bool LengthThroughPointer(const Layout& Arguments, uint32_t Pointer) { ++ return (Arguments.Lengths >> (Pointer * 8)) & 0x8; ++ } ++ ++ constexpr uint64_t CountKind(const Layout& Arguments, uint32_t Pointer) { ++ return (Arguments.Lengths >> (Pointer * 8)) & (CountWord | CountSigned); ++ } ++ ++ constexpr uint64_t CountValue(const Layout& Arguments, uint32_t Pointer, uint64_t Raw) { ++ const auto Kind = CountKind(Arguments, Pointer); ++ int64_t Value = static_cast(Raw); ++ if (Kind == (CountWord | CountSigned)) { ++ Value = static_cast(Raw); ++ } else if (Kind == CountWord) { ++ return static_cast(Raw); ++ } else if (Kind == 0) { ++ return Raw; ++ } ++ return Value < 0 ? 0 : static_cast(Value); ++ } ++ ++ constexpr uint64_t Fixed(uint32_t Pointer, uint64_t Bytes) { ++ return Bytes << (Pointer * 10); ++ } ++ ++ constexpr uint64_t FixedSize(const Layout& Arguments, uint32_t Pointer) { ++ return (Arguments.FixedSizes >> (Pointer * 10)) & 0x3ff; ++ } ++ ++ constexpr uint8_t Text(uint32_t Arg) { ++ return 1U << Arg; ++ } ++ ++ constexpr uint64_t Each(uint32_t Pointer, uint8_t Size) { ++ return static_cast(Size) << (Pointer * 8); ++ } ++ ++ constexpr uint8_t ElementSize(const Layout& Arguments, uint32_t Pointer) { ++ return (Arguments.ElementSizes >> (Pointer * 8)) & 0xff; ++ } ++ ++ constexpr uint64_t PollFdSize = 8; ++ constexpr uint64_t EpollEventSize = 12; ++ constexpr uint64_t GroupIdSize = 4; ++ constexpr uint64_t IntSize = 4; ++ constexpr uint64_t PointerSize = 8; ++ constexpr uint64_t SemaphoreOpSize = 6; ++ constexpr uint64_t IoEventSize = 32; ++ constexpr uint64_t FutexWaitSize = 24; ++ constexpr uint64_t StatSize = 144; ++ constexpr uint64_t StatfsSize = 120; ++ constexpr uint64_t StatxSize = 256; ++ constexpr uint64_t TimeSize = 16; ++ constexpr uint64_t TimePairSize = 32; ++ constexpr uint64_t TimezoneSize = 8; ++ constexpr uint64_t LongSize = 8; ++ constexpr uint64_t FdPairSize = 8; ++ constexpr uint64_t UtimbufSize = 16; ++ constexpr uint64_t SigactionSize = 32; ++ constexpr uint64_t SiginfoSize = 128; ++ constexpr uint64_t SigeventSize = 64; ++ constexpr uint64_t StackSize = 24; ++ constexpr uint64_t RlimitSize = 16; ++ constexpr uint64_t RusageSize = 144; ++ constexpr uint64_t SysinfoSize = 112; ++ constexpr uint64_t TmsSize = 32; ++ constexpr uint64_t UtsnameSize = 390; ++ constexpr uint64_t TimexSize = 208; ++ constexpr uint64_t UstatSize = 32; ++ constexpr uint64_t UserDescSize = 16; ++ constexpr uint64_t MqAttrSize = 64; ++ constexpr uint64_t IoControlBlockSize = 64; ++ constexpr uint64_t IoEventObjectOffset = 8; ++ constexpr uint64_t CapHeaderSize = 8; ++ constexpr uint64_t CapDataSize = 12; ++ constexpr uint32_t CapVersion1 = 0x19980330; ++ constexpr uint32_t CapVersion2 = 0x20071026; ++ constexpr uint32_t CapVersion3 = 0x20080522; ++ constexpr uint64_t FileLockSize = 32; ++ constexpr uint64_t IoUringParamsSize = 120; ++ constexpr uint64_t CachestatRangeSize = 16; ++ constexpr uint64_t CachestatSize = 40; ++ constexpr uint64_t LandlockPathRuleSize = 12; ++ constexpr uint64_t LandlockPortRuleSize = 16; ++ constexpr uint64_t KcmpSlotSize = 12; ++ constexpr uint64_t KexecSegmentSize = 32; ++ constexpr uint64_t SigsetArgumentSize = 16; ++ constexpr uint64_t SocketAddressSize = 128; ++ constexpr uint64_t MessageHeaderSize = 8; ++ constexpr uint64_t MaxString = 4096; ++ constexpr uint64_t StringChunk = 256; ++ constexpr uint64_t MaxPageList = 65536; ++ constexpr uint64_t MaxFutexWaiters = 128; ++ constexpr uint64_t MaxElements = 1ULL << 32; ++ ++ bool ByteLength(const Layout& Arguments, uint32_t Pointer, uint64_t Count, uint64_t* Bytes) { ++ const auto Size = ElementSize(Arguments, Pointer); ++ if (Size == 0) { ++ *Bytes = Count; ++ return true; ++ } ++ if (Size == BitmapElements) { ++ const auto Elements = static_cast(Count); ++ *Bytes = (static_cast(Elements) + 63) / 64 * 8; ++ return true; ++ } ++ if (Size == PageElements) { ++ *Bytes = Count / FEXCore::Utils::FEX_PAGE_SIZE + (Count % FEXCore::Utils::FEX_PAGE_SIZE != 0); ++ return true; ++ } ++ if (Count >= MaxElements) { ++ return false; ++ } ++ if (Size == MessageElements) { ++ *Bytes = Count + MessageHeaderSize; ++ return true; ++ } ++ *Bytes = Count * Size; ++ return true; ++ } ++ ++ constexpr LayoutEntry LayoutEntries[] = { ++ {x64::SYSCALL_x64_read, {Ptr(1), Sized(1, 2)}}, ++ {x64::SYSCALL_x64_write, {Ptr(1), Sized(1, 2)}}, ++ {x64::SYSCALL_x64_open, {Ptr(0), 0, VectorKind::None, 0, 0, Text(0)}}, ++ {x64::SYSCALL_x64_stat, {Ptr(0) | Ptr(1), 0, VectorKind::None, 0, Fixed(1, StatSize), Text(0)}}, ++ {x64::SYSCALL_x64_fstat, {Ptr(1), 0, VectorKind::None, 0, Fixed(1, StatSize)}}, ++ {x64::SYSCALL_x64_lstat, {Ptr(0) | Ptr(1), 0, VectorKind::None, 0, Fixed(1, StatSize), Text(0)}}, ++ {x64::SYSCALL_x64_poll, {Ptr(0), UintSized(0, 1), VectorKind::None, Each(0, PollFdSize)}}, ++ {x64::SYSCALL_x64_rt_sigaction, {Ptr(1) | Ptr(2), 0, VectorKind::None, 0, Fixed(1, SigactionSize) | Fixed(2, SigactionSize)}}, ++ {x64::SYSCALL_x64_rt_sigprocmask, {Ptr(1) | Ptr(2), Sized(1, 3) | Sized(2, 3)}}, ++ {x64::SYSCALL_x64_ioctl, {Ptr(2)}}, ++ {x64::SYSCALL_x64_pread_64, {Ptr(1), Sized(1, 2)}}, ++ {x64::SYSCALL_x64_pwrite_64, {Ptr(1), Sized(1, 2)}}, ++ {x64::SYSCALL_x64_readv, {0, 0, VectorKind::Io}}, ++ {x64::SYSCALL_x64_writev, {0, 0, VectorKind::Io}}, ++ {x64::SYSCALL_x64_access, {Ptr(0), 0, VectorKind::None, 0, 0, Text(0)}}, ++ {x64::SYSCALL_x64_pipe, {Ptr(0), 0, VectorKind::None, 0, Fixed(0, FdPairSize)}}, ++ {x64::SYSCALL_x64_select, {Ptr(1) | Ptr(2) | Ptr(3) | Ptr(4), IntSized(1, 0) | IntSized(2, 0) | IntSized(3, 0), VectorKind::None, Each(1, BitmapElements) | Each(2, BitmapElements) | Each(3, BitmapElements), Fixed(4, TimeSize)}}, ++ {x64::SYSCALL_x64_msync, {Ptr(0), Sized(0, 1)}}, ++ {x64::SYSCALL_x64_mincore, {Ptr(0) | Ptr(2), Sized(0, 1) | Sized(2, 1), VectorKind::None, Each(2, PageElements)}}, ++ {x64::SYSCALL_x64_shmctl, {Ptr(2)}}, ++ {x64::SYSCALL_x64_nanosleep, {Ptr(0) | Ptr(1), 0, VectorKind::None, 0, Fixed(0, TimeSize) | Fixed(1, TimeSize)}}, ++ {x64::SYSCALL_x64_getitimer, {Ptr(1), 0, VectorKind::None, 0, Fixed(1, TimePairSize)}}, ++ {x64::SYSCALL_x64_setitimer, {Ptr(1) | Ptr(2), 0, VectorKind::None, 0, Fixed(1, TimePairSize) | Fixed(2, TimePairSize)}}, ++ {x64::SYSCALL_x64_sendfile, {Ptr(2), 0, VectorKind::None, 0, Fixed(2, LongSize)}}, ++ {x64::SYSCALL_x64_connect, {Ptr(1), IntSized(1, 2)}}, ++ {x64::SYSCALL_x64_accept, {Ptr(1) | Ptr(2), Through(1, 2), VectorKind::None, 0, Fixed(1, SocketAddressSize) | Fixed(2, IntSize)}}, ++ {x64::SYSCALL_x64_sendto, {Ptr(1) | Ptr(4), Sized(1, 2) | IntSized(4, 5)}}, ++ {x64::SYSCALL_x64_recvfrom, {Ptr(1) | Ptr(4) | Ptr(5), Sized(1, 2) | Through(4, 5), VectorKind::None, 0, Fixed(4, SocketAddressSize) | Fixed(5, IntSize)}}, ++ {x64::SYSCALL_x64_sendmsg, {0, 0, VectorKind::SentMessage}}, ++ {x64::SYSCALL_x64_recvmsg, {0, 0, VectorKind::ReceivedMessage}}, ++ {x64::SYSCALL_x64_bind, {Ptr(1), IntSized(1, 2)}}, ++ {x64::SYSCALL_x64_getsockname, {Ptr(1) | Ptr(2), Through(1, 2), VectorKind::None, 0, Fixed(1, SocketAddressSize) | Fixed(2, IntSize)}}, ++ {x64::SYSCALL_x64_getpeername, {Ptr(1) | Ptr(2), Through(1, 2), VectorKind::None, 0, Fixed(1, SocketAddressSize) | Fixed(2, IntSize)}}, ++ {x64::SYSCALL_x64_socketpair, {Ptr(3), 0, VectorKind::None, 0, Fixed(3, FdPairSize)}}, ++ {x64::SYSCALL_x64_setsockopt, {Ptr(3), IntSized(3, 4)}}, ++ {x64::SYSCALL_x64_getsockopt, {Ptr(3) | Ptr(4), Through(3, 4), VectorKind::None, 0, Fixed(4, IntSize)}}, ++ {x64::SYSCALL_x64_execve, {Ptr(0) | Ptr(1) | Ptr(2), 0, VectorKind::None, 0, 0, Text(0)}}, ++ {x64::SYSCALL_x64_wait4, {Ptr(1) | Ptr(3), 0, VectorKind::None, 0, Fixed(1, IntSize) | Fixed(3, RusageSize)}}, ++ {x64::SYSCALL_x64_uname, {Ptr(0), 0, VectorKind::None, 0, Fixed(0, UtsnameSize)}}, ++ {x64::SYSCALL_x64_semop, {Ptr(1), UintSized(1, 2), VectorKind::None, Each(1, SemaphoreOpSize)}}, ++ {x64::SYSCALL_x64_semctl, {Ptr(3)}}, ++ {x64::SYSCALL_x64_msgsnd, {Ptr(1), Sized(1, 2), VectorKind::None, Each(1, MessageElements)}}, ++ {x64::SYSCALL_x64_msgrcv, {Ptr(1), Sized(1, 2), VectorKind::None, Each(1, MessageElements)}}, ++ {x64::SYSCALL_x64_msgctl, {Ptr(2)}}, ++ {x64::SYSCALL_x64_fcntl, {0, 0, VectorKind::FileControl}}, ++ {x64::SYSCALL_x64_truncate, {Ptr(0), 0, VectorKind::None, 0, 0, Text(0)}}, ++ {x64::SYSCALL_x64_getdents, {Ptr(1), UintSized(1, 2)}}, ++ {x64::SYSCALL_x64_getcwd, {Ptr(0), Sized(0, 1)}}, ++ {x64::SYSCALL_x64_chdir, {Ptr(0), 0, VectorKind::None, 0, 0, Text(0)}}, ++ {x64::SYSCALL_x64_rename, {Ptr(0) | Ptr(1), 0, VectorKind::None, 0, 0, Text(0) | Text(1)}}, ++ {x64::SYSCALL_x64_mkdir, {Ptr(0), 0, VectorKind::None, 0, 0, Text(0)}}, ++ {x64::SYSCALL_x64_rmdir, {Ptr(0), 0, VectorKind::None, 0, 0, Text(0)}}, ++ {x64::SYSCALL_x64_creat, {Ptr(0), 0, VectorKind::None, 0, 0, Text(0)}}, ++ {x64::SYSCALL_x64_link, {Ptr(0) | Ptr(1), 0, VectorKind::None, 0, 0, Text(0) | Text(1)}}, ++ {x64::SYSCALL_x64_unlink, {Ptr(0), 0, VectorKind::None, 0, 0, Text(0)}}, ++ {x64::SYSCALL_x64_symlink, {Ptr(0) | Ptr(1), 0, VectorKind::None, 0, 0, Text(0) | Text(1)}}, ++ {x64::SYSCALL_x64_readlink, {Ptr(0) | Ptr(1), IntSized(1, 2), VectorKind::None, 0, 0, Text(0)}}, ++ {x64::SYSCALL_x64_chmod, {Ptr(0), 0, VectorKind::None, 0, 0, Text(0)}}, ++ {x64::SYSCALL_x64_chown, {Ptr(0), 0, VectorKind::None, 0, 0, Text(0)}}, ++ {x64::SYSCALL_x64_lchown, {Ptr(0), 0, VectorKind::None, 0, 0, Text(0)}}, ++ {x64::SYSCALL_x64_gettimeofday, {Ptr(0) | Ptr(1), 0, VectorKind::None, 0, Fixed(0, TimeSize) | Fixed(1, TimezoneSize)}}, ++ {x64::SYSCALL_x64_getrlimit, {Ptr(1), 0, VectorKind::None, 0, Fixed(1, RlimitSize)}}, ++ {x64::SYSCALL_x64_getrusage, {Ptr(1), 0, VectorKind::None, 0, Fixed(1, RusageSize)}}, ++ {x64::SYSCALL_x64_sysinfo, {Ptr(0), 0, VectorKind::None, 0, Fixed(0, SysinfoSize)}}, ++ {x64::SYSCALL_x64_times, {Ptr(0), 0, VectorKind::None, 0, Fixed(0, TmsSize)}}, ++ {x64::SYSCALL_x64_syslog, {Ptr(1), IntSized(1, 2)}}, ++ {x64::SYSCALL_x64_getgroups, {Ptr(1), IntSized(1, 0), VectorKind::None, Each(1, GroupIdSize)}}, ++ {x64::SYSCALL_x64_setgroups, {Ptr(1), IntSized(1, 0), VectorKind::None, Each(1, GroupIdSize)}}, ++ {x64::SYSCALL_x64_getresuid, {Ptr(0) | Ptr(1) | Ptr(2), 0, VectorKind::None, 0, Fixed(0, IntSize) | Fixed(1, IntSize) | Fixed(2, IntSize)}}, ++ {x64::SYSCALL_x64_getresgid, {Ptr(0) | Ptr(1) | Ptr(2), 0, VectorKind::None, 0, Fixed(0, IntSize) | Fixed(1, IntSize) | Fixed(2, IntSize)}}, ++ {x64::SYSCALL_x64_capget, {Ptr(0), 0, VectorKind::Capabilities, 0, Fixed(0, CapHeaderSize)}}, ++ {x64::SYSCALL_x64_capset, {Ptr(0), 0, VectorKind::Capabilities, 0, Fixed(0, CapHeaderSize)}}, ++ {x64::SYSCALL_x64_rt_sigpending, {Ptr(0), Sized(0, 1)}}, ++ {x64::SYSCALL_x64_rt_sigtimedwait, {Ptr(0) | Ptr(1) | Ptr(2), Sized(0, 3), VectorKind::None, 0, Fixed(1, SiginfoSize) | Fixed(2, TimeSize)}}, ++ {x64::SYSCALL_x64_rt_sigqueueinfo, {Ptr(2), 0, VectorKind::None, 0, Fixed(2, SiginfoSize)}}, ++ {x64::SYSCALL_x64_rt_sigsuspend, {Ptr(0), Sized(0, 1)}}, ++ {x64::SYSCALL_x64_sigaltstack, {Ptr(0) | Ptr(1), 0, VectorKind::None, 0, Fixed(0, StackSize) | Fixed(1, StackSize)}}, ++ {x64::SYSCALL_x64_utime, {Ptr(0) | Ptr(1), 0, VectorKind::None, 0, Fixed(1, UtimbufSize), Text(0)}}, ++ {x64::SYSCALL_x64_mknod, {Ptr(0), 0, VectorKind::None, 0, 0, Text(0)}}, ++ {x64::SYSCALL_x64_uselib, {Ptr(0), 0, VectorKind::None, 0, 0, Text(0)}}, ++ {x64::SYSCALL_x64_ustat, {Ptr(1), 0, VectorKind::None, 0, Fixed(1, UstatSize)}}, ++ {x64::SYSCALL_x64_statfs, {Ptr(0) | Ptr(1), 0, VectorKind::None, 0, Fixed(1, StatfsSize), Text(0)}}, ++ {x64::SYSCALL_x64_fstatfs, {Ptr(1), 0, VectorKind::None, 0, Fixed(1, StatfsSize)}}, ++ {x64::SYSCALL_x64_sysfs, {Ptr(1) | Ptr(2), 0, VectorKind::None, 0, 0, Text(1)}}, ++ {x64::SYSCALL_x64_sched_setparam, {Ptr(1), 0, VectorKind::None, 0, Fixed(1, IntSize)}}, ++ {x64::SYSCALL_x64_sched_getparam, {Ptr(1), 0, VectorKind::None, 0, Fixed(1, IntSize)}}, ++ {x64::SYSCALL_x64_sched_setscheduler, {Ptr(2), 0, VectorKind::None, 0, Fixed(2, IntSize)}}, ++ {x64::SYSCALL_x64_sched_rr_get_interval, {Ptr(1), 0, VectorKind::None, 0, Fixed(1, TimeSize)}}, ++ {x64::SYSCALL_x64_mlock, {Ptr(0), Sized(0, 1)}}, ++ {x64::SYSCALL_x64_munlock, {Ptr(0), Sized(0, 1)}}, ++ {x64::SYSCALL_x64_modify_ldt, {Ptr(1), Sized(1, 2)}}, ++ {x64::SYSCALL_x64_pivot_root, {Ptr(0) | Ptr(1), 0, VectorKind::None, 0, 0, Text(0) | Text(1)}}, ++ {x64::SYSCALL_x64__sysctl, {Ptr(0)}}, ++ {x64::SYSCALL_x64_adjtimex, {Ptr(0), 0, VectorKind::None, 0, Fixed(0, TimexSize)}}, ++ {x64::SYSCALL_x64_setrlimit, {Ptr(1), 0, VectorKind::None, 0, Fixed(1, RlimitSize)}}, ++ {x64::SYSCALL_x64_chroot, {Ptr(0), 0, VectorKind::None, 0, 0, Text(0)}}, ++ {x64::SYSCALL_x64_acct, {Ptr(0), 0, VectorKind::None, 0, 0, Text(0)}}, ++ {x64::SYSCALL_x64_settimeofday, {Ptr(0) | Ptr(1), 0, VectorKind::None, 0, Fixed(0, TimeSize) | Fixed(1, TimezoneSize)}}, ++ {x64::SYSCALL_x64_mount, {Ptr(0) | Ptr(1) | Ptr(2) | Ptr(4), 0, VectorKind::None, 0, 0, Text(0) | Text(1) | Text(2)}}, ++ {x64::SYSCALL_x64_umount2, {Ptr(0), 0, VectorKind::None, 0, 0, Text(0)}}, ++ {x64::SYSCALL_x64_swapon, {Ptr(0), 0, VectorKind::None, 0, 0, Text(0)}}, ++ {x64::SYSCALL_x64_swapoff, {Ptr(0), 0, VectorKind::None, 0, 0, Text(0)}}, ++ {x64::SYSCALL_x64_reboot, {Ptr(3), 0, VectorKind::None, 0, 0, Text(3)}}, ++ {x64::SYSCALL_x64_sethostname, {Ptr(0), IntSized(0, 1)}}, ++ {x64::SYSCALL_x64_setdomainname, {Ptr(0), IntSized(0, 1)}}, ++ {x64::SYSCALL_x64_create_module, {Ptr(0), 0, VectorKind::None, 0, 0, Text(0)}}, ++ {x64::SYSCALL_x64_init_module, {Ptr(0) | Ptr(2), Sized(0, 1), VectorKind::None, 0, 0, Text(2)}}, ++ {x64::SYSCALL_x64_delete_module, {Ptr(0), 0, VectorKind::None, 0, 0, Text(0)}}, ++ {x64::SYSCALL_x64_get_kernel_syms, {Ptr(0)}}, ++ {x64::SYSCALL_x64_query_module, {Ptr(0) | Ptr(2) | Ptr(4), Sized(2, 3)}}, ++ {x64::SYSCALL_x64_quotactl, {Ptr(1) | Ptr(3), 0, VectorKind::None, 0, 0, Text(1)}}, ++ {x64::SYSCALL_x64_nfsservctl, {Ptr(1) | Ptr(2)}}, ++ {x64::SYSCALL_x64_setxattr, {Ptr(0) | Ptr(1) | Ptr(2), Sized(2, 3), VectorKind::None, 0, 0, Text(0) | Text(1)}}, ++ {x64::SYSCALL_x64_lsetxattr, {Ptr(0) | Ptr(1) | Ptr(2), Sized(2, 3), VectorKind::None, 0, 0, Text(0) | Text(1)}}, ++ {x64::SYSCALL_x64_fsetxattr, {Ptr(1) | Ptr(2), Sized(2, 3), VectorKind::None, 0, 0, Text(1)}}, ++ {x64::SYSCALL_x64_getxattr, {Ptr(0) | Ptr(1) | Ptr(2), Sized(2, 3), VectorKind::None, 0, 0, Text(0) | Text(1)}}, ++ {x64::SYSCALL_x64_lgetxattr, {Ptr(0) | Ptr(1) | Ptr(2), Sized(2, 3), VectorKind::None, 0, 0, Text(0) | Text(1)}}, ++ {x64::SYSCALL_x64_fgetxattr, {Ptr(1) | Ptr(2), Sized(2, 3), VectorKind::None, 0, 0, Text(1)}}, ++ {x64::SYSCALL_x64_listxattr, {Ptr(0) | Ptr(1), Sized(1, 2), VectorKind::None, 0, 0, Text(0)}}, ++ {x64::SYSCALL_x64_llistxattr, {Ptr(0) | Ptr(1), Sized(1, 2), VectorKind::None, 0, 0, Text(0)}}, ++ {x64::SYSCALL_x64_flistxattr, {Ptr(1), Sized(1, 2)}}, ++ {x64::SYSCALL_x64_removexattr, {Ptr(0) | Ptr(1), 0, VectorKind::None, 0, 0, Text(0) | Text(1)}}, ++ {x64::SYSCALL_x64_lremovexattr, {Ptr(0) | Ptr(1), 0, VectorKind::None, 0, 0, Text(0) | Text(1)}}, ++ {x64::SYSCALL_x64_fremovexattr, {Ptr(1), 0, VectorKind::None, 0, 0, Text(1)}}, ++ {x64::SYSCALL_x64_time, {Ptr(0), 0, VectorKind::None, 0, Fixed(0, LongSize)}}, ++ {x64::SYSCALL_x64_futex, {Ptr(0) | Ptr(3) | Ptr(4), 0, VectorKind::None, 0, Fixed(0, IntSize) | Fixed(3, TimeSize) | Fixed(4, IntSize)}}, ++ {x64::SYSCALL_x64_sched_setaffinity, {Ptr(2), UintSized(2, 1)}}, ++ {x64::SYSCALL_x64_sched_getaffinity, {Ptr(2), UintSized(2, 1)}}, ++ {x64::SYSCALL_x64_set_thread_area, {Ptr(0), 0, VectorKind::None, 0, Fixed(0, UserDescSize)}}, ++ {x64::SYSCALL_x64_io_setup, {Ptr(1), 0, VectorKind::None, 0, Fixed(1, LongSize)}}, ++ {x64::SYSCALL_x64_io_getevents, {Ptr(3) | Ptr(4), LongSized(3, 2), VectorKind::IoEvents, Each(3, IoEventSize), Fixed(4, TimeSize)}}, ++ {x64::SYSCALL_x64_io_submit, {Ptr(2), LongSized(2, 1), VectorKind::IoSubmit, Each(2, PointerSize)}}, ++ {x64::SYSCALL_x64_io_cancel, {Ptr(1) | Ptr(2), 0, VectorKind::None, 0, Fixed(1, IoControlBlockSize) | Fixed(2, IoEventSize)}}, ++ {x64::SYSCALL_x64_get_thread_area, {Ptr(0), 0, VectorKind::None, 0, Fixed(0, UserDescSize)}}, ++ {x64::SYSCALL_x64_lookup_dcookie, {Ptr(1), Sized(1, 2)}}, ++ {x64::SYSCALL_x64_remap_file_pages, {Ptr(0), Sized(0, 1)}}, ++ {x64::SYSCALL_x64_getdents64, {Ptr(1), UintSized(1, 2)}}, ++ {x64::SYSCALL_x64_semtimedop, {Ptr(1) | Ptr(3), UintSized(1, 2), VectorKind::None, Each(1, SemaphoreOpSize), Fixed(3, TimeSize)}}, ++ {x64::SYSCALL_x64_timer_create, {Ptr(1) | Ptr(2), 0, VectorKind::None, 0, Fixed(1, SigeventSize) | Fixed(2, IntSize)}}, ++ {x64::SYSCALL_x64_timer_settime, {Ptr(2) | Ptr(3), 0, VectorKind::None, 0, Fixed(2, TimePairSize) | Fixed(3, TimePairSize)}}, ++ {x64::SYSCALL_x64_timer_gettime, {Ptr(1), 0, VectorKind::None, 0, Fixed(1, TimePairSize)}}, ++ {x64::SYSCALL_x64_clock_settime, {Ptr(1), 0, VectorKind::None, 0, Fixed(1, TimeSize)}}, ++ {x64::SYSCALL_x64_clock_gettime, {Ptr(1), 0, VectorKind::None, 0, Fixed(1, TimeSize)}}, ++ {x64::SYSCALL_x64_clock_getres, {Ptr(1), 0, VectorKind::None, 0, Fixed(1, TimeSize)}}, ++ {x64::SYSCALL_x64_clock_nanosleep, {Ptr(2) | Ptr(3), 0, VectorKind::None, 0, Fixed(2, TimeSize) | Fixed(3, TimeSize)}}, ++ {x64::SYSCALL_x64_epoll_wait, {Ptr(1), IntSized(1, 2), VectorKind::None, Each(1, EpollEventSize)}}, ++ {x64::SYSCALL_x64_epoll_ctl, {Ptr(3), 0, VectorKind::None, 0, Fixed(3, EpollEventSize)}}, ++ {x64::SYSCALL_x64_utimes, {Ptr(0) | Ptr(1), 0, VectorKind::None, 0, Fixed(1, TimePairSize), Text(0)}}, ++ {x64::SYSCALL_x64_mbind, {Ptr(0) | Ptr(3), Sized(0, 1)}}, ++ {x64::SYSCALL_x64_set_mempolicy, {Ptr(1)}}, ++ {x64::SYSCALL_x64_get_mempolicy, {Ptr(0) | Ptr(1) | Ptr(3), 0, VectorKind::None, 0, Fixed(0, IntSize)}}, ++ {x64::SYSCALL_x64_mq_open, {Ptr(0) | Ptr(3), 0, VectorKind::None, 0, Fixed(3, MqAttrSize), Text(0)}}, ++ {x64::SYSCALL_x64_mq_unlink, {Ptr(0), 0, VectorKind::None, 0, 0, Text(0)}}, ++ {x64::SYSCALL_x64_mq_timedsend, {Ptr(1) | Ptr(4), Sized(1, 2), VectorKind::None, 0, Fixed(4, TimeSize)}}, ++ {x64::SYSCALL_x64_mq_timedreceive, {Ptr(1) | Ptr(3) | Ptr(4), Sized(1, 2), VectorKind::None, 0, Fixed(3, IntSize) | Fixed(4, TimeSize)}}, ++ {x64::SYSCALL_x64_mq_notify, {Ptr(1), 0, VectorKind::None, 0, Fixed(1, SigeventSize)}}, ++ {x64::SYSCALL_x64_mq_getsetattr, {Ptr(1) | Ptr(2), 0, VectorKind::None, 0, Fixed(1, MqAttrSize) | Fixed(2, MqAttrSize)}}, ++ {x64::SYSCALL_x64_kexec_load, {Ptr(2), Sized(2, 1), VectorKind::None, Each(2, KexecSegmentSize)}}, ++ {x64::SYSCALL_x64_waitid, {Ptr(2) | Ptr(4), 0, VectorKind::None, 0, Fixed(2, SiginfoSize) | Fixed(4, RusageSize)}}, ++ {x64::SYSCALL_x64_add_key, {Ptr(0) | Ptr(1) | Ptr(2), Sized(2, 3), VectorKind::None, 0, 0, Text(0) | Text(1)}}, ++ {x64::SYSCALL_x64_request_key, {Ptr(0) | Ptr(1) | Ptr(2), 0, VectorKind::None, 0, 0, Text(0) | Text(1) | Text(2)}}, ++ {x64::SYSCALL_x64_keyctl, {Ptr(1) | Ptr(2) | Ptr(3) | Ptr(4)}}, ++ {x64::SYSCALL_x64_inotify_add_watch, {Ptr(1), 0, VectorKind::None, 0, 0, Text(1)}}, ++ {x64::SYSCALL_x64_migrate_pages, {Ptr(2) | Ptr(3)}}, ++ {x64::SYSCALL_x64_openat, {Ptr(1), 0, VectorKind::None, 0, 0, Text(1)}}, ++ {x64::SYSCALL_x64_mkdirat, {Ptr(1), 0, VectorKind::None, 0, 0, Text(1)}}, ++ {x64::SYSCALL_x64_mknodat, {Ptr(1), 0, VectorKind::None, 0, 0, Text(1)}}, ++ {x64::SYSCALL_x64_fchownat, {Ptr(1), 0, VectorKind::None, 0, 0, Text(1)}}, ++ {x64::SYSCALL_x64_futimesat, {Ptr(1) | Ptr(2), 0, VectorKind::None, 0, Fixed(2, TimePairSize), Text(1)}}, ++ {x64::SYSCALL_x64_newfstatat, {Ptr(1) | Ptr(2), 0, VectorKind::None, 0, Fixed(2, StatSize), Text(1)}}, ++ {x64::SYSCALL_x64_unlinkat, {Ptr(1), 0, VectorKind::None, 0, 0, Text(1)}}, ++ {x64::SYSCALL_x64_renameat, {Ptr(1) | Ptr(3), 0, VectorKind::None, 0, 0, Text(1) | Text(3)}}, ++ {x64::SYSCALL_x64_linkat, {Ptr(1) | Ptr(3), 0, VectorKind::None, 0, 0, Text(1) | Text(3)}}, ++ {x64::SYSCALL_x64_symlinkat, {Ptr(0) | Ptr(2), 0, VectorKind::None, 0, 0, Text(0) | Text(2)}}, ++ {x64::SYSCALL_x64_readlinkat, {Ptr(1) | Ptr(2), IntSized(2, 3), VectorKind::None, 0, 0, Text(1)}}, ++ {x64::SYSCALL_x64_fchmodat, {Ptr(1), 0, VectorKind::None, 0, 0, Text(1)}}, ++ {x64::SYSCALL_x64_faccessat, {Ptr(1), 0, VectorKind::None, 0, 0, Text(1)}}, ++ {x64::SYSCALL_x64_pselect6, {Ptr(1) | Ptr(2) | Ptr(3) | Ptr(4) | Ptr(5), IntSized(1, 0) | IntSized(2, 0) | IntSized(3, 0), VectorKind::None, Each(1, BitmapElements) | Each(2, BitmapElements) | Each(3, BitmapElements), Fixed(4, TimeSize) | Fixed(5, SigsetArgumentSize)}}, ++ {x64::SYSCALL_x64_ppoll, {Ptr(0) | Ptr(2) | Ptr(3), UintSized(0, 1) | Sized(3, 4), VectorKind::None, Each(0, PollFdSize), Fixed(2, TimeSize)}}, ++ {x64::SYSCALL_x64_get_robust_list, {Ptr(1) | Ptr(2), 0, VectorKind::None, 0, Fixed(1, PointerSize) | Fixed(2, PointerSize)}}, ++ {x64::SYSCALL_x64_splice, {Ptr(1) | Ptr(3), 0, VectorKind::None, 0, Fixed(1, LongSize) | Fixed(3, LongSize)}}, ++ {x64::SYSCALL_x64_vmsplice, {0, 0, VectorKind::Io}}, ++ {x64::SYSCALL_x64_move_pages, {Ptr(2) | Ptr(3) | Ptr(4), Sized(2, 1) | Sized(3, 1) | Sized(4, 1), VectorKind::PageList, Each(2, PointerSize) | Each(3, IntSize) | Each(4, IntSize)}}, ++ {x64::SYSCALL_x64_utimensat, {Ptr(1) | Ptr(2), 0, VectorKind::None, 0, Fixed(2, TimePairSize), Text(1)}}, ++ {x64::SYSCALL_x64_epoll_pwait, {Ptr(1) | Ptr(4), IntSized(1, 2) | Sized(4, 5), VectorKind::None, Each(1, EpollEventSize)}}, ++ {x64::SYSCALL_x64_signalfd, {Ptr(1), Sized(1, 2)}}, ++ {x64::SYSCALL_x64_timerfd_settime, {Ptr(2) | Ptr(3), 0, VectorKind::None, 0, Fixed(2, TimePairSize) | Fixed(3, TimePairSize)}}, ++ {x64::SYSCALL_x64_timerfd_gettime, {Ptr(1), 0, VectorKind::None, 0, Fixed(1, TimePairSize)}}, ++ {x64::SYSCALL_x64_accept4, {Ptr(1) | Ptr(2), Through(1, 2), VectorKind::None, 0, Fixed(1, SocketAddressSize) | Fixed(2, IntSize)}}, ++ {x64::SYSCALL_x64_signalfd4, {Ptr(1), Sized(1, 2)}}, ++ {x64::SYSCALL_x64_pipe2, {Ptr(0), 0, VectorKind::None, 0, Fixed(0, FdPairSize)}}, ++ {x64::SYSCALL_x64_preadv, {0, 0, VectorKind::Io}}, ++ {x64::SYSCALL_x64_pwritev, {0, 0, VectorKind::Io}}, ++ {x64::SYSCALL_x64_rt_tgsigqueueinfo, {Ptr(3), 0, VectorKind::None, 0, Fixed(3, SiginfoSize)}}, ++ {x64::SYSCALL_x64_perf_event_open, {0, 0, VectorKind::PerfAttribute}}, ++ {x64::SYSCALL_x64_recvmmsg, {Ptr(4), 0, VectorKind::ReceivedMessageArray, 0, Fixed(4, TimeSize)}}, ++ {x64::SYSCALL_x64_fanotify_mark, {Ptr(4), 0, VectorKind::None, 0, 0, Text(4)}}, ++ {x64::SYSCALL_x64_prlimit_64, {Ptr(2) | Ptr(3), 0, VectorKind::None, 0, Fixed(2, RlimitSize) | Fixed(3, RlimitSize)}}, ++ {x64::SYSCALL_x64_name_to_handle_at, {Ptr(1) | Ptr(3), 0, VectorKind::HandleAt, 0, Fixed(3, IntSize), Text(1)}}, ++ {x64::SYSCALL_x64_open_by_handle_at, {0, 0, VectorKind::OpenHandle}}, ++ {x64::SYSCALL_x64_clock_adjtime, {Ptr(1), 0, VectorKind::None, 0, Fixed(1, TimexSize)}}, ++ {x64::SYSCALL_x64_sendmmsg, {0, 0, VectorKind::SentMessageArray}}, ++ {x64::SYSCALL_x64_getcpu, {Ptr(0) | Ptr(1), 0, VectorKind::None, 0, Fixed(0, IntSize) | Fixed(1, IntSize)}}, ++ {x64::SYSCALL_x64_kcmp, {Ptr(4), 0, VectorKind::None, 0, Fixed(4, KcmpSlotSize)}}, ++ {x64::SYSCALL_x64_finit_module, {Ptr(1), 0, VectorKind::None, 0, 0, Text(1)}}, ++ {x64::SYSCALL_x64_sched_setattr, {0, 0, VectorKind::SchedulerAttribute}}, ++ {x64::SYSCALL_x64_sched_getattr, {Ptr(1), UintSized(1, 2)}}, ++ {x64::SYSCALL_x64_renameat2, {Ptr(1) | Ptr(3), 0, VectorKind::None, 0, 0, Text(1) | Text(3)}}, ++ {x64::SYSCALL_x64_seccomp, {Ptr(2)}}, ++ {x64::SYSCALL_x64_getrandom, {Ptr(0), Sized(0, 1)}}, ++ {x64::SYSCALL_x64_memfd_create, {Ptr(0), 0, VectorKind::None, 0, 0, Text(0)}}, ++ {x64::SYSCALL_x64_kexec_file_load, {Ptr(3), Sized(3, 2)}}, ++ {x64::SYSCALL_x64_bpf, {Ptr(1), UintSized(1, 2)}}, ++ {x64::SYSCALL_x64_execveat, {Ptr(1) | Ptr(2) | Ptr(3), 0, VectorKind::None, 0, 0, Text(1)}}, ++ {x64::SYSCALL_x64_mlock2, {Ptr(0), Sized(0, 1)}}, ++ {x64::SYSCALL_x64_copy_file_range, {Ptr(1) | Ptr(3), 0, VectorKind::None, 0, Fixed(1, LongSize) | Fixed(3, LongSize)}}, ++ {x64::SYSCALL_x64_preadv2, {0, 0, VectorKind::Io}}, ++ {x64::SYSCALL_x64_pwritev2, {0, 0, VectorKind::Io}}, ++ {x64::SYSCALL_x64_pkey_mprotect, {Ptr(0), Sized(0, 1)}}, ++ {x64::SYSCALL_x64_statx, {Ptr(1) | Ptr(4), 0, VectorKind::None, 0, Fixed(4, StatxSize), Text(1)}}, ++ {x64::SYSCALL_x64_io_pgetevents, {Ptr(3) | Ptr(4) | Ptr(5), LongSized(3, 2), VectorKind::IoEvents, Each(3, IoEventSize), Fixed(4, TimeSize) | Fixed(5, SigsetArgumentSize)}}, ++ {x64::SYSCALL_x64_rseq, {Ptr(0), UintSized(0, 1)}}, ++ {x64::SYSCALL_x64_pidfd_send_signal, {Ptr(2), 0, VectorKind::None, 0, Fixed(2, SiginfoSize)}}, ++ {x64::SYSCALL_x64_io_uring_setup, {Ptr(1), 0, VectorKind::None, 0, Fixed(1, IoUringParamsSize)}}, ++ {x64::SYSCALL_x64_io_uring_enter, {Ptr(4), Sized(4, 5)}}, ++ {x64::SYSCALL_x64_io_uring_register, {Ptr(2)}}, ++ {x64::SYSCALL_x64_open_tree, {Ptr(1), 0, VectorKind::None, 0, 0, Text(1)}}, ++ {x64::SYSCALL_x64_move_mount, {Ptr(1) | Ptr(3), 0, VectorKind::None, 0, 0, Text(1) | Text(3)}}, ++ {x64::SYSCALL_x64_fsopen, {Ptr(0), 0, VectorKind::None, 0, 0, Text(0)}}, ++ {x64::SYSCALL_x64_fsconfig, {Ptr(2) | Ptr(3), 0, VectorKind::None, 0, 0, Text(2)}}, ++ {x64::SYSCALL_x64_fspick, {Ptr(1), 0, VectorKind::None, 0, 0, Text(1)}}, ++ {x64::SYSCALL_x64_openat2, {Ptr(1) | Ptr(2), Sized(2, 3), VectorKind::None, 0, 0, Text(1)}}, ++ {x64::SYSCALL_x64_faccessat2, {Ptr(1), 0, VectorKind::None, 0, 0, Text(1)}}, ++ {x64::SYSCALL_x64_process_madvise, {Ptr(1)}}, ++ {x64::SYSCALL_x64_epoll_pwait2, {Ptr(1) | Ptr(3) | Ptr(4), IntSized(1, 2) | Sized(4, 5), VectorKind::None, Each(1, EpollEventSize), Fixed(3, TimeSize)}}, ++ {x64::SYSCALL_x64_mount_setattr, {Ptr(1) | Ptr(3), Sized(3, 4), VectorKind::None, 0, 0, Text(1)}}, ++ {x64::SYSCALL_x64_quotactl_fd, {Ptr(3)}}, ++ {x64::SYSCALL_x64_landlock_create_ruleset, {Ptr(0), Sized(0, 1)}}, ++ {x64::SYSCALL_x64_landlock_add_rule, {0, 0, VectorKind::LandlockRule}}, ++ {x64::SYSCALL_x64_futex_waitv, {Ptr(0) | Ptr(3), UintSized(0, 1), VectorKind::FutexWaiters, Each(0, FutexWaitSize), Fixed(3, TimeSize)}}, ++ {x64::SYSCALL_x64_set_mempolicy_home_node, {Ptr(0), Sized(0, 1)}}, ++ {x64::SYSCALL_x64_cachestat, {Ptr(1) | Ptr(2), 0, VectorKind::None, 0, Fixed(1, CachestatRangeSize) | Fixed(2, CachestatSize)}}, ++ {x64::SYSCALL_x64_fchmodat2, {Ptr(1), 0, VectorKind::None, 0, 0, Text(1)}}, ++ {x64::SYSCALL_x64_futex_wake, {Ptr(0), 0, VectorKind::None, 0, Fixed(0, IntSize)}}, ++ {x64::SYSCALL_x64_futex_wait, {Ptr(0) | Ptr(4), 0, VectorKind::None, 0, Fixed(0, IntSize) | Fixed(4, TimeSize)}}, ++ {x64::SYSCALL_x64_futex_requeue, {Ptr(0), 0, VectorKind::FutexRequeue, 0, Fixed(0, 2 * FutexWaitSize)}}, ++ {x64::SYSCALL_x64_statmount, {Ptr(1), Sized(1, 2), VectorKind::MountRequest}}, ++ {x64::SYSCALL_x64_listmount, {Ptr(1), Sized(1, 2), VectorKind::MountRequest, Each(1, PointerSize)}}, ++ {x64::SYSCALL_x64_lsm_get_self_attr, {Ptr(1) | Ptr(2), Through(1, 2), VectorKind::None, 0, Fixed(2, IntSize)}}, ++ {x64::SYSCALL_x64_lsm_set_self_attr, {Ptr(1), UintSized(1, 2)}}, ++ {x64::SYSCALL_x64_lsm_list_modules, {Ptr(0) | Ptr(1), Through(0, 1), VectorKind::None, 0, Fixed(1, IntSize)}}, ++ {x64::SYSCALL_x64_mseal, {Ptr(0), Sized(0, 1)}}, ++ {x64::SYSCALL_x64_setxattrat, {Ptr(1) | Ptr(3) | Ptr(4), Sized(4, 5), VectorKind::None, 0, 0, Text(1) | Text(3)}}, ++ {x64::SYSCALL_x64_getxattrat, {Ptr(1) | Ptr(3) | Ptr(4), Sized(4, 5), VectorKind::None, 0, 0, Text(1) | Text(3)}}, ++ {x64::SYSCALL_x64_listxattrat, {Ptr(1) | Ptr(3), Sized(3, 4), VectorKind::None, 0, 0, Text(1)}}, ++ {x64::SYSCALL_x64_removexattrat, {Ptr(1) | Ptr(3), 0, VectorKind::None, 0, 0, Text(1) | Text(3)}}, ++ }; ++ ++ constexpr uint32_t LayoutCount() { ++ uint32_t Max = 0; ++ for (const auto& Entry : LayoutEntries) { ++ Max = std::max(Max, Entry.Syscall); ++ } ++ return Max + 1; ++ } ++ ++ constexpr std::array BuildLayouts() { ++ std::array Table {}; ++ for (const auto& Entry : LayoutEntries) { ++ Table[Entry.Syscall] = Entry.Arguments; ++ } ++ return Table; ++ } ++ ++ constexpr auto Layouts = BuildLayouts(); ++ ++ constexpr bool LayoutsAreConsistent() { ++ for (size_t i = 0; i < std::size(LayoutEntries); ++i) { ++ for (size_t j = i + 1; j < std::size(LayoutEntries); ++j) { ++ if (LayoutEntries[i].Syscall == LayoutEntries[j].Syscall) { ++ return false; ++ } ++ } ++ const auto& Arguments = LayoutEntries[i].Arguments; ++ if ((Arguments.Strings & ~Arguments.Pointers) != 0) { ++ return false; ++ } ++ for (uint32_t Arg = 0; Arg < 6; ++Arg) { ++ const bool Pointer = Arguments.Pointers & Ptr(Arg); ++ const auto Length = LengthArgument(Arguments, Arg); ++ const bool Indirect = LengthThroughPointer(Arguments, Arg); ++ const auto Bytes = FixedSize(Arguments, Arg); ++ const bool String = Arguments.Strings & Ptr(Arg); ++ const bool Elements = ElementSize(Arguments, Arg) != 0; ++ if (CountKind(Arguments, Arg) != 0 && (Length == 0 || Indirect)) { ++ return false; ++ } ++ if (!Pointer && (Length != 0 || Indirect || Bytes != 0 || Elements)) { ++ return false; ++ } ++ if (String && (Length != 0 || Indirect || Bytes != 0)) { ++ return false; ++ } ++ if (Elements && (Length == 0 || Indirect)) { ++ return false; ++ } ++ if (Length == 0) { ++ if (Indirect) { ++ return false; ++ } ++ continue; ++ } ++ if (Length > 6) { ++ return false; ++ } ++ const bool Target = Arguments.Pointers & Ptr(Length - 1); ++ if (Indirect ? !Target : (Target || Bytes != 0)) { ++ return false; ++ } ++ } ++ } ++ return true; ++ } ++ ++ constexpr bool LeavesUntranslated(std::initializer_list Syscalls) { ++ for (const auto Syscall : Syscalls) { ++ if (Syscall < Layouts.size() && (Layouts[Syscall].Pointers != 0 || Layouts[Syscall].Vector != VectorKind::None)) { ++ return false; ++ } ++ } ++ return true; ++ } ++ ++ static_assert(LayoutsAreConsistent()); ++ static_assert(LeavesUntranslated({ ++ x64::SYSCALL_x64_mmap, ++ x64::SYSCALL_x64_mprotect, ++ x64::SYSCALL_x64_munmap, ++ x64::SYSCALL_x64_brk, ++ x64::SYSCALL_x64_rt_sigreturn, ++ x64::SYSCALL_x64_mremap, ++ x64::SYSCALL_x64_madvise, ++ x64::SYSCALL_x64_shmat, ++ x64::SYSCALL_x64_clone, ++ x64::SYSCALL_x64_shmdt, ++ x64::SYSCALL_x64_ptrace, ++ x64::SYSCALL_x64_prctl, ++ x64::SYSCALL_x64_arch_prctl, ++ x64::SYSCALL_x64_set_tid_address, ++ x64::SYSCALL_x64_set_robust_list, ++ x64::SYSCALL_x64_process_vm_readv, ++ x64::SYSCALL_x64_process_vm_writev, ++ x64::SYSCALL_x64_clone3, ++ x64::SYSCALL_x64_map_shadow_stack, ++ })); ++ ++ struct iovec* VectorCopy(ArgumentStorage* Storage, uint64_t Entries) { ++ if (Entries <= std::size(Storage->Inline)) { ++ return Storage->Inline; ++ } ++ Storage->Heap.resize(std::min(Entries, MaxIoVectors)); ++ return Storage->Heap.data(); ++ } ++ ++ uint64_t TranslateIoVector(uint64_t Vector, uint64_t Entries, struct iovec* Copy, uint64_t* Out, bool* Copied = nullptr) { ++ if (Entries == 0 || Entries > MaxIoVectors) { ++ return 0; ++ } ++ const auto Bytes = Entries * sizeof(struct iovec); ++ uint64_t HostVector {}; ++ if (!TranslateRange(Vector, Bytes, &HostVector)) { ++ return -EFAULT; ++ } ++ *Out = HostVector; ++ if (FaultSafeUserMemAccess::CopyFromUser(Copy, reinterpret_cast(HostVector), Bytes) != 0) { ++ return 0; ++ } ++ if (Copied) { ++ *Copied = true; ++ } ++ bool Changed = false; ++ for (uint64_t i = 0; i < Entries; ++i) { ++ const auto Base = reinterpret_cast(Copy[i].iov_base); ++ uint64_t Host {}; ++ if (!TranslateRange(Base, Copy[i].iov_len, &Host)) { ++ return -EFAULT; ++ } ++ if (Host != Base) { ++ Copy[i].iov_base = reinterpret_cast(Host); ++ Changed = true; ++ } ++ } ++ if (Changed) { ++ *Out = reinterpret_cast(Copy); ++ } ++ return 0; ++ } ++ ++ uint64_t TranslateMessageFields(struct msghdr* Message, struct iovec* Copy, bool* Changed, bool* Copied = nullptr) { ++ const auto Name = reinterpret_cast(Message->msg_name); ++ const auto Control = reinterpret_cast(Message->msg_control); ++ const auto Vector = reinterpret_cast(Message->msg_iov); ++ uint64_t HostName {}; ++ uint64_t HostControl {}; ++ uint64_t HostVector = Vector; ++ if (!TranslateRange(Name, Message->msg_namelen, &HostName) || !TranslateRange(Control, Message->msg_controllen, &HostControl)) { ++ return -EFAULT; ++ } ++ if (const auto Result = TranslateIoVector(Vector, Message->msg_iovlen, Copy, &HostVector, Copied); Result != 0) { ++ return Result; ++ } ++ *Changed = HostName != Name || HostControl != Control || HostVector != Vector; ++ Message->msg_name = reinterpret_cast(HostName); ++ Message->msg_control = reinterpret_cast(HostControl); ++ Message->msg_iov = reinterpret_cast(HostVector); ++ return 0; ++ } ++ ++ uint64_t TranslateMessage(uint64_t* Header, bool Received, ArgumentStorage* Storage) { ++ const auto GuestHeader = *Header; ++ uint64_t HostHeader {}; ++ if (!TranslateRange(GuestHeader, sizeof(struct msghdr), &HostHeader)) { ++ return -EFAULT; ++ } ++ *Header = HostHeader; ++ auto* Message = &Storage->Message; ++ if (FaultSafeUserMemAccess::CopyFromUser(Message, reinterpret_cast(HostHeader), sizeof(*Message)) != 0) { ++ return 0; ++ } ++ bool Changed = false; ++ if (const auto Result = TranslateMessageFields(Message, VectorCopy(Storage, Message->msg_iovlen), &Changed); Result != 0 || !Changed) { ++ return Result; ++ } ++ if (Received) { ++ Storage->ReceivedHeader = GuestHeader; ++ } ++ *Header = reinterpret_cast(Message); ++ return 0; ++ } ++ ++ template ++ bool WithStableMapping(uint64_t Address, Fn&& Body) { ++ auto* Thread = Contains(Address) ? FEX::HLE::ThreadManager::GetCurrentThreadObject() : nullptr; ++ if (Thread == nullptr || Thread->HighMemoryTrap.Mappings.Held) { ++ return Body(); ++ } ++ MappingHold Hold {Thread->HighMemoryTrap.Mappings, true}; ++ return Body(); ++ } ++ ++ bool CopyToGuest(uint64_t Address, const void* Value, uint64_t Size) { ++ return WithStableMapping(Address, [&] { ++ uint64_t Host {}; ++ return TranslateRange(Address, Size, &Host) && FaultSafeUserMemAccess::CopyToUser(reinterpret_cast(Host), Value, Size) == 0; ++ }); ++ } ++ ++ uint64_t TranslateMessages(uint64_t* Args, bool Received, ArgumentStorage* Storage) { ++ auto* Array = &Args[1]; ++ auto* Entries = &Args[2]; ++ const uint64_t Messages = std::min(static_cast(*Entries), MaxIoVectors); ++ if (Messages == 0) { ++ return 0; ++ } ++ constexpr uint64_t Size = sizeof(struct mmsghdr); ++ const auto GuestArray = *Array; ++ uint64_t HostArray {}; ++ if (!TranslateRange(GuestArray, Size, &HostArray)) { ++ return -EFAULT; ++ } ++ Storage->Messages.resize(Messages); ++ auto* Copy = Storage->Messages.data(); ++ uint64_t Ready = 0; ++ bool Contiguous = true; ++ uint64_t Whole {}; ++ if (TranslateRange(GuestArray, Messages * Size, &Whole) && ++ FaultSafeUserMemAccess::CopyFromUser(Copy, reinterpret_cast(Whole), Messages * Size) == 0) { ++ Ready = Messages; ++ } else { ++ for (; Ready < Messages; ++Ready) { ++ uint64_t Host {}; ++ if (!TranslateRange(GuestArray + Ready * Size, Size, &Host) || ++ FaultSafeUserMemAccess::CopyFromUser(&Copy[Ready], reinterpret_cast(Host), Size) != 0) { ++ break; ++ } ++ Contiguous = Contiguous && Host == HostArray + Ready * Size; ++ } ++ } ++ if (Ready == 0) { ++ *Array = HostArray; ++ return 0; ++ } ++ uint64_t Vectors = 0; ++ for (uint64_t i = 0; i < Ready; ++i) { ++ if (Copy[i].msg_hdr.msg_iovlen <= MaxIoVectors) { ++ Vectors += Copy[i].msg_hdr.msg_iovlen; ++ } ++ } ++ Storage->Heap.resize(Vectors); ++ Storage->MessageLengths.assign(Ready, 0); ++ bool Changed = !Contiguous; ++ uint64_t Offset = 0; ++ for (uint64_t i = 0; i < Ready; ++i) { ++ const auto Length = Copy[i].msg_hdr.msg_iovlen; ++ auto* Local = Storage->Heap.data() + Offset; ++ bool Translated = false; ++ bool Copied = false; ++ if (const auto Result = TranslateMessageFields(&Copy[i].msg_hdr, Local, &Translated, &Copied); Result != 0) { ++ if (i == 0) { ++ return Result; ++ } ++ Ready = i; ++ break; ++ } ++ if (!Received && Length != 0 && !Copied) { ++ if (i == 0) { ++ *Array = HostArray; ++ return 0; ++ } ++ Ready = i; ++ break; ++ } ++ if (Copied && !Received) { ++ Copy[i].msg_hdr.msg_iov = Local; ++ for (uint64_t j = 0; j < Length; ++j) { ++ Storage->MessageLengths[i] += Local[j].iov_len; ++ } ++ } ++ if (Length <= MaxIoVectors) { ++ Offset += Length; ++ } ++ Changed = Changed || Translated; ++ } ++ Storage->Messages.resize(Ready); ++ Storage->MessageLengths.resize(Ready); ++ if (!Changed) { ++ *Array = HostArray; ++ if (HostArray != GuestArray || Ready < static_cast(*Entries)) { ++ *Entries = Ready; ++ } ++ return 0; ++ } ++ *Array = reinterpret_cast(Copy); ++ *Entries = Received ? Ready : 1; ++ Storage->GuestMessages = GuestArray; ++ Storage->ReceivedMessages = Received; ++ Storage->SendFlags = static_cast(Args[3]); ++ if (!Received && Ready > 1) { ++ Storage->Socket = fcntl(static_cast(Args[0]), F_DUPFD_CLOEXEC, 0); ++ if (Storage->Socket >= 0) { ++ Args[0] = static_cast(Storage->Socket); ++ } ++ } ++ return 0; ++ } ++ ++ bool ReturnMessageFields(uint64_t Guest, const struct msghdr& Message) { ++ return (Message.msg_name == nullptr || ++ CopyToGuest(Guest + offsetof(struct msghdr, msg_namelen), &Message.msg_namelen, sizeof(Message.msg_namelen))) && ++ CopyToGuest(Guest + offsetof(struct msghdr, msg_flags), &Message.msg_flags, sizeof(Message.msg_flags)) && ++ CopyToGuest(Guest + offsetof(struct msghdr, msg_controllen), &Message.msg_controllen, sizeof(Message.msg_controllen)); ++ } ++ ++ uint64_t StringLength(uint64_t Address) { ++ uint64_t Length = 0; ++ while (Length < MaxString) { ++ const auto Here = Address + Length; ++ const auto Chunk = std::min({FEXCore::Utils::FEX_PAGE_SIZE - (Here & (FEXCore::Utils::FEX_PAGE_SIZE - 1)), MaxString - Length, StringChunk}); ++ char Chars[StringChunk]; ++ uint64_t Host {}; ++ if (!TranslateRange(Here, Chunk, &Host) || (Host == Here && Contains(Here)) || ++ FaultSafeUserMemAccess::CopyFromUser(Chars, reinterpret_cast(Host), Chunk) != 0) { ++ return Length + 1; ++ } ++ if (const auto* End = static_cast(memchr(Chars, 0, Chunk)); End != nullptr) { ++ return Length + (End - Chars) + 1; ++ } ++ Length += Chunk; ++ } ++ return MaxString; ++ } ++ ++ bool PointerLength(const Layout& Arguments, uint32_t Pointer, const uint64_t* Args, uint32_t NumArgs, uint64_t* Length) { ++ if (Arguments.Strings & Ptr(Pointer)) { ++ *Length = StringLength(Args[Pointer]); ++ return true; ++ } ++ const auto LengthArg = LengthArgument(Arguments, Pointer); ++ const auto Cap = FixedSize(Arguments, Pointer); ++ if (LengthArg == 0 || LengthArg > NumArgs) { ++ *Length = Cap; ++ return true; ++ } ++ const auto Source = Args[LengthArg - 1]; ++ if (!LengthThroughPointer(Arguments, Pointer)) { ++ return ByteLength(Arguments, Pointer, CountValue(Arguments, Pointer, Source), Length); ++ } ++ *Length = 0; ++ uint32_t Value {}; ++ uint64_t Host {}; ++ if (Source == 0 || !TranslateRange(Source, sizeof(Value), &Host) || ++ FaultSafeUserMemAccess::CopyFromUser(&Value, reinterpret_cast(Host), sizeof(Value)) != 0) { ++ return true; ++ } ++ *Length = Cap != 0 ? std::min(Value, Cap) : Value; ++ return true; ++ } ++ ++ uint64_t FileControlSize(uint64_t Command) { ++ switch (static_cast(Command)) { ++ case F_GETLK: ++ case F_SETLK: ++ case F_SETLKW: ++ case F_OFD_GETLK: ++ case F_OFD_SETLK: ++ case F_OFD_SETLKW: return FileLockSize; ++ case F_GETOWN_EX: ++ case F_SETOWN_EX: ++ case F_GET_RW_HINT: ++ case F_SET_RW_HINT: ++ case F_GET_FILE_RW_HINT: ++ case F_SET_FILE_RW_HINT: return LongSize; ++ default: return 0; ++ } ++ } ++ ++ struct IoControlBlock { ++ uint64_t Data; ++ uint32_t Key; ++ int32_t ReadWriteFlags; ++ uint16_t Opcode; ++ int16_t Priority; ++ uint32_t File; ++ uint64_t Buffer; ++ uint64_t Bytes; ++ int64_t Offset; ++ uint64_t Reserved; ++ uint32_t Flags; ++ uint32_t ResultFile; ++ }; ++ static_assert(sizeof(IoControlBlock) == IoControlBlockSize); ++ ++ constexpr uint16_t IoRead = 0; ++ constexpr uint16_t IoWrite = 1; ++ constexpr uint16_t IoReadVector = 7; ++ constexpr uint16_t IoWriteVector = 8; ++ ++ uint64_t TranslateIoBuffer(const IoControlBlock& Block, struct iovec* Copy, uint64_t* Out) { ++ *Out = Block.Buffer; ++ switch (Block.Opcode) { ++ case IoRead: ++ case IoWrite: return TranslateRange(Block.Buffer, Block.Bytes, Out) ? 0 : -EFAULT; ++ case IoReadVector: ++ case IoWriteVector: return TranslateIoVector(Block.Buffer, Block.Bytes, Copy, Out); ++ default: return 0; ++ } ++ } ++ ++ struct IoCopy { ++ IoControlBlock Block; ++ uint64_t Context; ++ uint64_t Guest; ++ uint64_t Generation; ++ bool Used; ++ }; ++ static_assert(offsetof(IoCopy, Block) == 0); ++ ++ constexpr size_t MaxIoCopies = 1024; ++ std::mutex IoCopyMutex; ++ std::array IoCopies {}; ++ size_t IoCopyNext {}; ++ std::atomic IoCopyCount {0}; ++ ++ struct AioContextState { ++ uint64_t Generation; ++ uint64_t Active; ++ bool Live; ++ fextl::list> Batches; ++ }; ++ ++ using AioContextTable = fextl::unordered_map; ++ ++ AioContextTable& AioContextsLocked() { ++ static auto* Table = fextl::make_unique().release(); ++ return *Table; ++ } ++ ++ uint64_t AioGeneration {}; ++ ++ uint64_t ContextGenerationLocked(uint64_t Context) { ++ const auto& Table = AioContextsLocked(); ++ const auto Found = Table.find(Context); ++ return Found == Table.end() ? AioGeneration : Found->second.Generation; ++ } ++ ++ IoCopy* FindIoCopyLocked(uint64_t Address) { ++ const auto First = reinterpret_cast(IoCopies.data()); ++ if (Address < First || Address - First >= sizeof(IoCopies) || (Address - First) % sizeof(IoCopy) != 0) { ++ return nullptr; ++ } ++ auto* Copy = &IoCopies[(Address - First) / sizeof(IoCopy)]; ++ return Copy->Used ? Copy : nullptr; ++ } ++ ++ void ReleaseIoCopyLocked(IoCopy* Copy) { ++ Copy->Used = false; ++ IoCopyCount.fetch_sub(1, std::memory_order_release); ++ } ++ ++ uint64_t ClaimIoCopy(const IoControlBlock& Block, uint64_t Context, uint64_t Guest) { ++ auto lk = FEXCore::MaskSignalsAndLockMutex(IoCopyMutex, ~HeldSignalMask()); ++ for (size_t Tried = 0; Tried < MaxIoCopies; ++Tried) { ++ auto& Copy = IoCopies[IoCopyNext]; ++ IoCopyNext = (IoCopyNext + 1) % MaxIoCopies; ++ if (!Copy.Used) { ++ Copy = {Block, Context, Guest, ContextGenerationLocked(Context), true}; ++ IoCopyCount.fetch_add(1, std::memory_order_release); ++ return reinterpret_cast(&Copy); ++ } ++ } ++ return 0; ++ } ++ ++ void ReleaseIoCopies(const uint64_t* Copies, uint64_t Entries) { ++ auto lk = FEXCore::MaskSignalsAndLockMutex(IoCopyMutex, ~HeldSignalMask()); ++ for (uint64_t i = 0; i < Entries; ++i) { ++ if (auto* Copy = Copies[i] ? FindIoCopyLocked(Copies[i]) : nullptr) { ++ ReleaseIoCopyLocked(Copy); ++ } ++ } ++ } ++ ++ uint64_t ContextGeneration(uint64_t Context) { ++ auto lk = FEXCore::MaskSignalsAndLockMutex(IoCopyMutex, ~HeldSignalMask()); ++ return ContextGenerationLocked(Context); ++ } ++ ++ void ReleaseContext(uint64_t Context, uint64_t Generation) { ++ auto lk = FEXCore::MaskSignalsAndLockMutex(IoCopyMutex, ~HeldSignalMask()); ++ for (auto& Copy : IoCopies) { ++ if (Copy.Used && Copy.Context == Context && Copy.Generation <= Generation) { ++ ReleaseIoCopyLocked(&Copy); ++ } ++ } ++ auto& Table = AioContextsLocked(); ++ const auto Found = Table.find(Context); ++ if (Found != Table.end() && Found->second.Generation <= Generation) { ++ Table.erase(Found); ++ } ++ } ++ ++ uint64_t BeginContext(uint64_t Context) { ++ auto lk = FEXCore::MaskSignalsAndLockMutex(IoCopyMutex, ~HeldSignalMask()); ++ auto& Table = AioContextsLocked(); ++ Table.erase(Context); ++ Table[Context] = {++AioGeneration, 0, true, {}}; ++ return AioGeneration; ++ } ++ ++ uint64_t ReportedObject(uint64_t Object) { ++ if (IoCopyCount.load(std::memory_order_acquire) != 0) { ++ auto lk = FEXCore::MaskSignalsAndLockMutex(IoCopyMutex, ~HeldSignalMask()); ++ if (auto* Copy = FindIoCopyLocked(Object)) { ++ const auto Guest = Copy->Guest; ++ ReleaseIoCopyLocked(Copy); ++ return Guest; ++ } ++ } ++ return ToGuest(Object); ++ } ++ ++ uint64_t CancelTarget(uint64_t Context, uint64_t Guest, uint64_t Host) { ++ uint32_t Key {}; ++ if (IoCopyCount.load(std::memory_order_acquire) == 0 || ++ FaultSafeUserMemAccess::CopyFromUser(&Key, reinterpret_cast(Host + offsetof(IoControlBlock, Key)), sizeof(Key)) != 0 || ++ Key != 0) { ++ return Host; ++ } ++ auto lk = FEXCore::MaskSignalsAndLockMutex(IoCopyMutex, ~HeldSignalMask()); ++ for (auto& Copy : IoCopies) { ++ if (Copy.Used && Copy.Context == Context && Copy.Guest == Guest) { ++ return reinterpret_cast(&Copy); ++ } ++ } ++ return Host; ++ } ++ ++ constexpr uint64_t MaxIoEvents = 65536; ++ constexpr uint64_t IoEventWords = IoEventSize / sizeof(uint64_t); ++ constexpr uint64_t AioRingMagicOffset = 16; ++ constexpr uint32_t AioRingMagic = 0xa10a10a1; ++ ++ constexpr int64_t NanosPerSecond = 1'000'000'000; ++ constexpr int64_t ReapSlice = 20'000'000; ++ constexpr int64_t MaxWaitSeconds = 1LL << 32; ++ ++ struct StashTicket { ++ uint64_t Taken; ++ uint64_t Generation; ++ }; ++ ++ uint64_t TakeEventsLocked(AioContextState& State, uint64_t* Words, uint64_t Events) { ++ uint64_t Taken = 0; ++ while (Taken < Events && !State.Batches.empty()) { ++ auto& Batch = State.Batches.front(); ++ const auto Count = std::min(Batch.size() / IoEventWords, Events - Taken); ++ std::copy_n(Batch.begin(), Count * IoEventWords, Words + Taken * IoEventWords); ++ Taken += Count; ++ if (Count * IoEventWords == Batch.size()) { ++ State.Batches.pop_front(); ++ } else { ++ Batch.erase(Batch.begin(), Batch.begin() + Count * IoEventWords); ++ } ++ } ++ return Taken; ++ } ++ ++ StashTicket ReserveEvents(uint64_t Context, uint64_t* Words, uint64_t Events, bool Take) { ++ auto lk = FEXCore::MaskSignalsAndLockMutex(IoCopyMutex, ~HeldSignalMask()); ++ auto& State = AioContextsLocked()[Context]; ++ if (State.Generation == 0) { ++ State.Generation = ++AioGeneration; ++ } ++ ++State.Active; ++ return {Take ? TakeEventsLocked(State, Words, Events) : 0, State.Generation}; ++ } ++ ++ uint64_t TopUpEvents(uint64_t Context, uint64_t Generation, uint64_t* Words, uint64_t Events) { ++ auto lk = FEXCore::MaskSignalsAndLockMutex(IoCopyMutex, ~HeldSignalMask()); ++ auto& Table = AioContextsLocked(); ++ const auto Found = Table.find(Context); ++ if (Found == Table.end() || Found->second.Generation != Generation) { ++ return 0; ++ } ++ return TakeEventsLocked(Found->second, Words, Events); ++ } ++ ++ void SettleEvents(uint64_t Context, uint64_t Generation, ArgumentStorage* Storage, uint64_t Kept, bool Forget) { ++ auto lk = FEXCore::MaskSignalsAndLockMutex(IoCopyMutex, ~HeldSignalMask()); ++ auto& Table = AioContextsLocked(); ++ const auto Found = Table.find(Context); ++ if (Found == Table.end() || Found->second.Generation != Generation) { ++ return; ++ } ++ auto& State = Found->second; ++ --State.Active; ++ if (Kept != 0) { ++ auto& Batch = Storage->Recovery.front(); ++ Batch.swap(Storage->EventBuffer); ++ Batch.resize(Kept * IoEventWords); ++ State.Batches.splice(State.Batches.begin(), Storage->Recovery); ++ } ++ if (Forget && !State.Live && State.Active == 0 && State.Batches.empty()) { ++ Table.erase(Found); ++ } ++ } ++ ++ uint64_t WritableEvents(uint64_t Host, uint64_t Events) { ++ Events = std::min(Events, (~0ULL - Host) / IoEventSize); ++ const auto End = Host + Events * IoEventSize; ++ auto Probe = Host; ++ while (Probe < End) { ++ uint8_t Byte {}; ++ if (FaultSafeUserMemAccess::CopyFromUser(&Byte, reinterpret_cast(Probe), sizeof(Byte)) != 0 || ++ FaultSafeUserMemAccess::CopyToUser(reinterpret_cast(Probe), &Byte, sizeof(Byte)) != 0) { ++ break; ++ } ++ Probe = (Probe | (FEXCore::Utils::FEX_PAGE_SIZE - 1)) + 1; ++ } ++ return (std::min(Probe, End) - Host) / IoEventSize; ++ } ++ ++ int64_t MonotonicNanos() { ++ struct timespec Now {}; ++ clock_gettime(CLOCK_MONOTONIC, &Now); ++ return Now.tv_sec * NanosPerSecond + Now.tv_nsec; ++ } ++ ++ void SetWait(ArgumentStorage* Storage, int64_t Left) { ++ const auto Wait = std::clamp(Left, 0, ReapSlice); ++ Storage->Wait[0] = Wait / NanosPerSecond; ++ Storage->Wait[1] = Wait % NanosPerSecond; ++ } ++ ++ bool StartWait(uint64_t Timeout, ArgumentStorage* Storage) { ++ int64_t Given[2] {}; ++ if (Timeout != 0 && (FaultSafeUserMemAccess::CopyFromUser(Given, reinterpret_cast(Timeout), sizeof(Given)) != 0 || ++ Given[0] < 0 || Given[1] < 0 || Given[1] >= NanosPerSecond)) { ++ return false; ++ } ++ const auto Now = MonotonicNanos(); ++ Storage->Deadline = Timeout != 0 && Given[0] < MaxWaitSeconds ? Now + Given[0] * NanosPerSecond + Given[1] : -1; ++ SetWait(Storage, Storage->Deadline < 0 ? ReapSlice : Storage->Deadline - Now); ++ Storage->Blocking = true; ++ return true; ++ } ++ ++ bool ContinueWait(ArgumentStorage* Storage) { ++ if (Storage->Deadline < 0) { ++ SetWait(Storage, ReapSlice); ++ return true; ++ } ++ const auto Left = Storage->Deadline - MonotonicNanos(); ++ SetWait(Storage, Left); ++ return Left > 0; ++ } ++ ++ uint64_t WaitForEvents(ArgumentStorage* Storage, uint64_t* Words, uint64_t Events, uint64_t Reaped) { ++ if (!FEX::HLE::ThreadManager::GetCurrentThreadObject()->SignalInfo.DeferredSignalFrames.empty()) { ++ return -EINTR; ++ } ++ const auto Result = ::syscall(Storage->EventSyscall, Storage->EventContext, Storage->Least - Reaped, Events - Reaped, ++ Words + Reaped * IoEventWords, Storage->Wait, Storage->EventMask); ++ return Result == -1 ? -errno : Result; ++ } ++ ++ uint64_t StartContext(uint64_t ContextPointer, uint64_t Ring) { ++ const auto Generation = BeginContext(Ring); ++ uint32_t Magic {}; ++ if (FaultSafeUserMemAccess::CopyFromUser(&Magic, reinterpret_cast(Ring + AioRingMagicOffset), sizeof(Magic)) == 0 && ++ Magic == AioRingMagic) { ++ Magic = 0; ++ static_cast(FaultSafeUserMemAccess::CopyToUser(reinterpret_cast(Ring + AioRingMagicOffset), &Magic, sizeof(Magic))); ++ } ++ if (CopyToGuest(ContextPointer, &Ring, sizeof(Ring))) { ++ return 0; ++ } ++ static_cast(::syscall(SYS_io_destroy, Ring)); ++ ReleaseContext(Ring, Generation); ++ return -EFAULT; ++ } ++ ++ uint64_t TrackIoCopies(uint64_t Syscall, const uint64_t* Guest, uint64_t* Args, ArgumentStorage* Storage) { ++ switch (Syscall) { ++ case x64::SYSCALL_x64_io_setup: ++ if (FaultSafeUserMemAccess::CopyFromUser(&Storage->SetupId, reinterpret_cast(Args[1]), sizeof(Storage->SetupId)) != 0) { ++ return -EFAULT; ++ } ++ Storage->SetupContext = Guest[1]; ++ Args[1] = reinterpret_cast(&Storage->SetupId); ++ break; ++ case x64::SYSCALL_x64_io_getevents: ++ case x64::SYSCALL_x64_io_pgetevents: { ++ const auto Wanted = static_cast(Args[2]); ++ if (Wanted <= 0 || Guest[3] == 0) { ++ break; ++ } ++ const auto Events = std::max(WritableEvents(Args[3], std::min(Wanted, MaxIoEvents)), 1); ++ if (static_cast(Wanted) > Events) { ++ if (static_cast(Args[1]) > static_cast(Events) && static_cast(Args[1]) <= Wanted) { ++ Args[1] = Events; ++ } ++ Args[2] = Events; ++ } ++ Storage->EventBuffer.resize(Events * IoEventWords); ++ Storage->Recovery.emplace_back(); ++ Storage->Events = Guest[3]; ++ Storage->EventContext = Args[0]; ++ const auto Least = static_cast(Args[1]); ++ const bool Valid = Least >= 0 && Least <= static_cast(Events); ++ const auto Ticket = ReserveEvents(Args[0], Storage->EventBuffer.data(), Events, Valid); ++ Storage->Stashed = Ticket.Taken; ++ Storage->StashGeneration = Ticket.Generation; ++ if (Valid) { ++ Storage->Least = Least; ++ Args[1] = Ticket.Taken >= Storage->Least ? 0 : Storage->Least - Ticket.Taken; ++ if (Args[1] != 0 && StartWait(Args[4], Storage)) { ++ Storage->EventSyscall = Syscall == x64::SYSCALL_x64_io_pgetevents ? SYS_io_pgetevents : SYS_io_getevents; ++ Storage->EventMask = Args[5]; ++ Args[4] = reinterpret_cast(Storage->Wait); ++ } ++ } ++ Args[2] = Events - Ticket.Taken; ++ Args[3] = reinterpret_cast(Storage->EventBuffer.data() + Ticket.Taken * IoEventWords); ++ break; ++ } ++ case x64::SYSCALL_x64_io_cancel: Args[1] = CancelTarget(Args[0], Guest[1], Args[1]); break; ++ case x64::SYSCALL_x64_io_destroy: ++ Storage->DestroyedContext = Args[0]; ++ Storage->DestroyedGeneration = ContextGeneration(Args[0]); ++ Storage->Destroying = true; ++ break; ++ default: break; ++ } ++ return 0; ++ } ++ ++ uint64_t TranslateIoSubmit(uint64_t Context, uint64_t* Entries, uint64_t* Array, ArgumentStorage* Storage) { ++ const auto Requested = static_cast(*Entries); ++ if (Requested <= 0) { ++ return 0; ++ } ++ const auto Blocks = std::min(Requested, MaxIoVectors); ++ Storage->Words.resize(Blocks); ++ auto* List = Storage->Words.data(); ++ if (FaultSafeUserMemAccess::CopyFromUser(List, reinterpret_cast(*Array), Blocks * PointerSize) != 0) { ++ return 0; ++ } ++ Storage->IoCopies.reserve(Blocks); ++ Storage->IoKeys.reserve(Blocks); ++ Storage->IoKeyValues.reserve(Blocks); ++ bool Refused = false; ++ bool Changed = false; ++ uint64_t Vectors = 0; ++ uint64_t Usable = 0; ++ for (; Usable < Blocks; ++Usable) { ++ IoControlBlock Block {}; ++ uint64_t Host {}; ++ if (!TranslateRange(List[Usable], sizeof(Block), &Host) || ++ FaultSafeUserMemAccess::CopyFromUser(&Block, reinterpret_cast(Host), sizeof(Block)) != 0) { ++ break; ++ } ++ const bool Vectored = (Block.Opcode == IoReadVector || Block.Opcode == IoWriteVector) && Block.Bytes <= MaxIoVectors; ++ if (Vectored) { ++ if (Block.Bytes > MaxIoVectors - Vectors) { ++ break; ++ } ++ Storage->Heap.resize(MaxIoVectors); ++ } ++ uint64_t Buffer {}; ++ if (TranslateIoBuffer(Block, Storage->Heap.data() + Vectors, &Buffer) != 0) { ++ break; ++ } ++ uint64_t Submitted = Host; ++ if (Buffer != Block.Buffer) { ++ if (FaultSafeUserMemAccess::CopyToUser(reinterpret_cast(Host + offsetof(IoControlBlock, Key)), &Block.Key, sizeof(Block.Key)) != 0) { ++ Storage->IoCopies.push_back(0); ++ Storage->IoKeys.push_back(0); ++ Storage->IoKeyValues.push_back(Block.Key); ++ Changed = Changed || Host != List[Usable]; ++ List[Usable++] = Host; ++ break; ++ } ++ Block.Buffer = Buffer; ++ Submitted = ClaimIoCopy(Block, Context, List[Usable]); ++ if (Submitted == 0) { ++ Refused = true; ++ break; ++ } ++ } ++ if (Vectored) { ++ Vectors += Block.Bytes; ++ } ++ Storage->IoCopies.push_back(Submitted != Host ? Submitted : 0); ++ Storage->IoKeys.push_back(Submitted != Host ? List[Usable] + offsetof(IoControlBlock, Key) : 0); ++ Storage->IoKeyValues.push_back(Block.Key); ++ Changed = Changed || Submitted != List[Usable]; ++ List[Usable] = Submitted; ++ } ++ if (Usable == 0) { ++ return Refused ? -EAGAIN : -EFAULT; ++ } ++ if (Changed) { ++ *Array = reinterpret_cast(List); ++ } ++ *Entries = Usable; ++ return 0; ++ } ++ ++ uint64_t TranslatePageList(uint64_t* Args, ArgumentStorage* Storage) { ++ const auto Process = static_cast(Args[0]); ++ const auto Pages = Args[1]; ++ if ((Process != 0 && Process != getpid()) || Pages == 0 || Pages > MaxPageList) { ++ return 0; ++ } ++ Storage->Words.resize(Pages); ++ auto* List = Storage->Words.data(); ++ if (FaultSafeUserMemAccess::CopyFromUser(List, reinterpret_cast(Args[2]), Pages * PointerSize) != 0) { ++ return 0; ++ } ++ bool Changed = false; ++ for (uint64_t i = 0; i < Pages; ++i) { ++ uint64_t Host {}; ++ if (!TranslateRange(List[i], 1, &Host)) { ++ return -EFAULT; ++ } ++ Changed = Changed || Host != List[i]; ++ List[i] = Host; ++ } ++ if (Changed) { ++ Args[2] = reinterpret_cast(List); ++ } ++ return 0; ++ } ++ ++ struct EmbeddedSize { ++ uint64_t Offset; ++ uint64_t Header; ++ uint64_t Default; ++ uint64_t Minimum; ++ uint64_t Maximum; ++ }; ++ ++ constexpr EmbeddedSize PerfAttributeSize {4, 0, 64, 64, FEXCore::Utils::FEX_PAGE_SIZE}; ++ constexpr EmbeddedSize SchedulerAttributeSize {0, 0, 48, 48, FEXCore::Utils::FEX_PAGE_SIZE}; ++ constexpr EmbeddedSize FileHandleSize {0, 8, 0, 0, 128}; ++ constexpr EmbeddedSize MountRequestSize {0, 0, 0, 24, FEXCore::Utils::FEX_PAGE_SIZE}; ++ ++ uint64_t TranslateEmbedded(uint64_t* Argument, const EmbeddedSize& Rule) { ++ if (!Contains(*Argument)) { ++ return 0; ++ } ++ const uint64_t Field = Rule.Offset + sizeof(uint32_t); ++ uint64_t Host {}; ++ if (!TranslateRange(*Argument, Field, &Host)) { ++ return -EFAULT; ++ } ++ uint64_t Span = std::max(Field, Rule.Header); ++ uint32_t Raw {}; ++ if (FaultSafeUserMemAccess::CopyFromUser(&Raw, reinterpret_cast(Host + Rule.Offset), sizeof(Raw)) == 0) { ++ const uint64_t Value = Raw == 0 ? Rule.Default : Raw; ++ if (Value >= Rule.Minimum && Value <= Rule.Maximum) { ++ Span = std::max(Field, Rule.Header + Value); ++ } ++ } ++ return TranslateRange(*Argument, Span, Argument) ? 0 : -EFAULT; ++ } ++ ++ uint64_t TranslateCapabilities(uint64_t* Header, uint64_t GuestHeader, uint64_t* Data, ArgumentStorage* Storage) { ++ if (!Contains(*Data)) { ++ return 0; ++ } ++ uint64_t Bytes = 0; ++ auto* Copy = Storage->CapabilityHeader; ++ if (FaultSafeUserMemAccess::CopyFromUser(Copy, reinterpret_cast(*Header), sizeof(Storage->CapabilityHeader)) == 0) { ++ const auto Version = Copy[0]; ++ Bytes = Version == CapVersion1 ? CapDataSize : (Version == CapVersion2 || Version == CapVersion3) ? 2 * CapDataSize : 0; ++ Storage->CapabilityVersion = Version; ++ Storage->GuestCapabilityHeader = GuestHeader; ++ *Header = reinterpret_cast(Copy); ++ } ++ return TranslateRange(*Data, Bytes, Data) ? 0 : -EFAULT; ++ } ++ ++ uint64_t TranslateLandlockRule(uint64_t Type, uint64_t* Rule) { ++ const uint64_t Bytes = Type == 1 ? LandlockPathRuleSize : Type == 2 ? LandlockPortRuleSize : 0; ++ return TranslateRange(*Rule, Bytes, Rule) ? 0 : -EFAULT; ++ } ++ ++ uint64_t TranslateWaiters(uint64_t* Waiters, uint64_t Entries, ArgumentStorage* Storage) { ++ constexpr uint64_t Words = FutexWaitSize / sizeof(uint64_t); ++ if (Entries == 0 || Entries > MaxFutexWaiters) { ++ return 0; ++ } ++ Storage->Words.resize(Entries * Words); ++ auto* Copy = Storage->Words.data(); ++ if (FaultSafeUserMemAccess::CopyFromUser(Copy, reinterpret_cast(*Waiters), Entries * FutexWaitSize) != 0) { ++ return 0; ++ } ++ bool Changed = false; ++ for (uint64_t i = 0; i < Entries; ++i) { ++ auto& Address = Copy[i * Words + 1]; ++ uint64_t Host {}; ++ if (!TranslateRange(Address, 1ULL << (Copy[i * Words + 2] & 3), &Host)) { ++ return -EFAULT; ++ } ++ Changed = Changed || Host != Address; ++ Address = Host; ++ } ++ if (Changed) { ++ *Waiters = reinterpret_cast(Copy); ++ } ++ return 0; ++ } ++} // namespace ++ ++bool Contains(uint64_t Address) { ++ return Address >= HostLimit() && Address < TaskTop; ++} ++ ++bool ClaimsMapping(uint64_t Address, uint64_t Length, int Flags) { ++ if (!(Flags & MAP_FIXED) || (Flags & MAP_FIXED_NOREPLACE) || Length == 0) { ++ return false; ++ } ++ if (Address & (FEXCore::Utils::FEX_PAGE_SIZE - 1)) { ++ return false; ++ } ++ const auto Size = FEXCore::AlignUp(Length, FEXCore::Utils::FEX_PAGE_SIZE); ++ return Contains(Address) && Size <= TaskTop - Address; ++} ++ ++uint64_t Map(uint64_t Address, uint64_t Length, int Prot, int Flags, int FD, off_t Offset) { ++ const auto Size = FEXCore::AlignUp(Length, FEXCore::Utils::FEX_PAGE_SIZE); ++ const int HostFlags = Flags & ~MAP_FIXED; ++ void* Host = MAP_FAILED; ++ if (const auto Hint = NeighbourHint(Address, Size); Hint != 0) { ++ Host = ::mmap(reinterpret_cast(Hint), Size, Prot, HostFlags | MAP_FIXED_NOREPLACE, FD, Offset); ++ } ++ if (Host == MAP_FAILED) { ++ Host = ::mmap(nullptr, Size, Prot, HostFlags, FD, Offset); ++ } ++ if (Host == MAP_FAILED) { ++ return -errno; ++ } ++ ++ BeginWrite(); ++ int Result = 0; ++ if (!HasRoomLocked(Address, Size, 1)) { ++ Result = -ENOMEM; ++ } else { ++ Result = UnmapLocked(Address, Size); ++ } ++ if (Result == 0 && !AddEntry(Address, Size, reinterpret_cast(Host), false, TrackedProt(Prot))) { ++ Result = -ENOMEM; ++ } ++ if (Result == 0) { ++ CoalesceLocked(Address, Address + Size); ++ } ++ EndWrite(); ++ if (Result != 0) { ++ ::munmap(Host, Size); ++ return Result; ++ } ++ return Address; ++} ++ ++uint64_t Unmap(uint64_t Address, uint64_t Length) { ++ if (Address & (FEXCore::Utils::FEX_PAGE_SIZE - 1)) { ++ return -EINVAL; ++ } ++ const auto Size = FEXCore::AlignUp(Length, FEXCore::Utils::FEX_PAGE_SIZE); ++ if (Size == 0 || Size > TaskTop - Address) { ++ return -EINVAL; ++ } ++ BeginWrite(); ++ const int Result = UnmapLocked(Address, Size); ++ EndWrite(); ++ return Result; ++} ++ ++uint64_t Protect(uint64_t Address, uint64_t Length, int Prot) { ++ BeginWrite(); ++ uint64_t Result = ApplyToRegionsLocked(Address, Length, -ENOMEM, [](void*, uint64_t, uint32_t) { return 0; }); ++ if (Result == 0) { ++ Result = SplitLocked(Address, Length); ++ } ++ if (Result == 0) { ++ Result = ApplyToRegionsLocked(Address, Length, -ENOMEM, [Prot](void* Host, uint64_t Size, uint32_t i) { ++ const int Applied = ::mprotect(Host, Size, Prot); ++ if (Applied == 0) { ++ Regions[i].Prot.store(TrackedProt(Prot), std::memory_order_relaxed); ++ } ++ return Applied; ++ }); ++ CoalesceLocked(Address, Address + std::min(FEXCore::AlignUp(Length, FEXCore::Utils::FEX_PAGE_SIZE), TaskTop - Address)); ++ } ++ EndWrite(); ++ return Result; ++} ++ ++uint64_t Advise(uint64_t Address, uint64_t Length, int Advice, bool* Applied) { ++ *Applied = false; ++ return ApplyToRegionsLocked(Address, Length, -EINVAL, [Advice, Applied](void* Host, uint64_t Size, uint32_t) { ++ const int Result = ::madvise(Host, Size, Advice); ++ if (Result == 0) { ++ *Applied = true; ++ } ++ return Result; ++ }); ++} ++ ++bool DiscardsContents(int Advice) { ++ switch (Advice) { ++ case MADV_DONTNEED: ++ case MADV_FREE: ++ case MADV_REMOVE: ++ case MADV_DONTNEED_LOCKED: return true; ++ default: return false; ++ } ++} ++ ++uint64_t ToGuest(uint64_t Address) { ++ if (Count.load(std::memory_order_relaxed) == 0) [[likely]] { ++ return Address; ++ } ++ return ReadConsistent([&] { ++ const auto Entries = Count.load(std::memory_order_acquire); ++ for (uint32_t i = 0; i < Entries; ++i) { ++ const auto Host = Regions[i].Host.load(std::memory_order_relaxed); ++ const auto Size = Regions[i].Size.load(std::memory_order_relaxed); ++ if (Address >= Host && Address - Host < Size) { ++ return Regions[i].Guest.load(std::memory_order_relaxed) + (Address - Host); ++ } ++ } ++ return Address; ++ }); ++} ++ ++bool TranslateRange(uint64_t Address, uint64_t Length, uint64_t* Host) { ++ if (Count.load(std::memory_order_relaxed) == 0 || !Contains(Address)) [[likely]] { ++ *Host = Address; ++ return true; ++ } ++ return ReadConsistent([&] { return SpanLocked(Address, Length, Host); }); ++} ++ ++void MarkCode(uint64_t Address, uint64_t Length) { ++ const auto End = Address + Length; ++ const auto Entries = Count.load(std::memory_order_acquire); ++ for (uint32_t i = 0; i < Entries; ++i) { ++ const auto Guest = Regions[i].Guest.load(std::memory_order_relaxed); ++ const auto RegionEnd = Guest + Regions[i].Size.load(std::memory_order_relaxed); ++ if (RegionEnd > Address && Guest < End) { ++ Regions[i].Code.store(true, std::memory_order_relaxed); ++ } ++ } ++} ++ ++uint64_t TranslateSyscallArguments(uint64_t Syscall, uint64_t* Args, uint32_t NumArgs, ArgumentStorage* Storage) { ++ if (Count.load(std::memory_order_relaxed) == 0) [[likely]] { ++ return TrackIoCopies(Syscall, Args, Args, Storage); ++ } ++ if (Syscall >= Layouts.size()) { ++ return 0; ++ } ++ const auto& Arguments = Layouts[Syscall]; ++ const auto Used = std::min(NumArgs, 6); ++ uint64_t Guest[6] {}; ++ std::copy_n(Args, Used, Guest); ++ uint64_t Lengths[6] {}; ++ for (uint32_t i = 0; i < Used; ++i) { ++ if ((Arguments.Pointers & Ptr(i)) && Contains(Args[i]) && !PointerLength(Arguments, i, Args, Used, &Lengths[i])) { ++ return -EFAULT; ++ } ++ } ++ for (uint32_t i = 0; i < Used; ++i) { ++ if ((Arguments.Pointers & Ptr(i)) && !TranslateRange(Args[i], Lengths[i], &Args[i])) { ++ return -EFAULT; ++ } ++ } ++ if (const auto Failed = TrackIoCopies(Syscall, Guest, Args, Storage); Failed != 0) { ++ return Failed; ++ } ++ if (Used < 6) { ++ return 0; ++ } ++ switch (Arguments.Vector) { ++ case VectorKind::Io: return TranslateIoVector(Args[1], Args[2], VectorCopy(Storage, Args[2]), &Args[1]); ++ case VectorKind::SentMessage: return TranslateMessage(&Args[1], false, Storage); ++ case VectorKind::ReceivedMessage: return TranslateMessage(&Args[1], true, Storage); ++ case VectorKind::SentMessageArray: return TranslateMessages(Args, false, Storage); ++ case VectorKind::ReceivedMessageArray: return TranslateMessages(Args, true, Storage); ++ case VectorKind::IoSubmit: return TranslateIoSubmit(Args[0], &Args[1], &Args[2], Storage); ++ case VectorKind::IoEvents: return 0; ++ case VectorKind::PageList: return TranslatePageList(Args, Storage); ++ case VectorKind::FutexWaiters: return TranslateWaiters(&Args[0], static_cast(Args[1]), Storage); ++ case VectorKind::FutexRequeue: return TranslateWaiters(&Args[0], 2, Storage); ++ case VectorKind::FileControl: return TranslateRange(Args[2], FileControlSize(Args[1]), &Args[2]) ? 0 : -EFAULT; ++ case VectorKind::Capabilities: return TranslateCapabilities(&Args[0], Guest[0], &Args[1], Storage); ++ case VectorKind::PerfAttribute: return TranslateEmbedded(&Args[0], PerfAttributeSize); ++ case VectorKind::SchedulerAttribute: return TranslateEmbedded(&Args[1], SchedulerAttributeSize); ++ case VectorKind::HandleAt: return TranslateEmbedded(&Args[2], FileHandleSize); ++ case VectorKind::OpenHandle: return TranslateEmbedded(&Args[1], FileHandleSize); ++ case VectorKind::MountRequest: return TranslateEmbedded(&Args[0], MountRequestSize); ++ case VectorKind::LandlockRule: return TranslateLandlockRule(static_cast(Args[1]), &Args[2]); ++ case VectorKind::None: break; ++ } ++ return 0; ++} ++ ++bool HoldsMappings(FEXCore::Core::InternalThreadState* Thread) { ++ return FEX::HLE::ThreadManager::GetStateObjectFromFEXCoreThread(Thread)->HighMemoryTrap.Mappings.Held; ++} ++ ++uint64_t FinishSyscallArguments(uint64_t Result, ArgumentStorage* Storage) { ++ struct PinnedSocket { ++ int FD; ++ ~PinnedSocket() { ++ if (FD >= 0) { ++ close(FD); ++ } ++ } ++ } Socket {std::exchange(Storage->Socket, -1)}; ++ if (!Storage->IoCopies.empty()) { ++ const auto Submitted = FEX::HLE::HasSyscallError(Result) ? 0 : std::min(Result, Storage->IoCopies.size()); ++ const auto Examined = std::min(Submitted + 1, Storage->IoCopies.size()); ++ for (uint64_t i = 0; i < Examined; ++i) { ++ if (Storage->IoKeys[i] == 0) { ++ continue; ++ } ++ const uint32_t Key = i < Submitted ? 0 : reinterpret_cast(Storage->IoCopies[i])->Key; ++ if (Key != Storage->IoKeyValues[i]) { ++ static_cast(CopyToGuest(Storage->IoKeys[i], &Key, sizeof(Key))); ++ } ++ } ++ ReleaseIoCopies(Storage->IoCopies.data() + Submitted, Storage->IoCopies.size() - Submitted); ++ } ++ if (Storage->SetupContext != 0 && Result == 0) { ++ Result = StartContext(Storage->SetupContext, Storage->SetupId); ++ } ++ if (Storage->Destroying && Result == 0) { ++ ReleaseContext(Storage->DestroyedContext, Storage->DestroyedGeneration); ++ } ++ if (Storage->GuestCapabilityHeader != 0 && Storage->CapabilityHeader[0] != Storage->CapabilityVersion && ++ !CopyToGuest(Storage->GuestCapabilityHeader, &Storage->CapabilityHeader[0], sizeof(Storage->CapabilityHeader[0]))) { ++ return -EFAULT; ++ } ++ if (Storage->Events != 0) { ++ const auto Taken = Storage->Stashed; ++ auto* Words = Storage->EventBuffer.data(); ++ if (FEX::HLE::HasSyscallError(Result) && (Result != static_cast(-EINTR) || Taken == 0)) { ++ SettleEvents(Storage->EventContext, Storage->StashGeneration, Storage, Taken, Result == static_cast(-EINVAL)); ++ return Result; ++ } ++ const auto Events = Storage->EventBuffer.size() / IoEventWords; ++ auto Reaped = Taken; ++ while (!FEX::HLE::HasSyscallError(Result)) { ++ const auto Fresh = std::min(Result, Events - Reaped); ++ for (uint64_t i = Reaped; i < Reaped + Fresh; ++i) { ++ auto& Object = Words[i * IoEventWords + IoEventObjectOffset / sizeof(uint64_t)]; ++ Object = ReportedObject(Object); ++ } ++ Reaped += Fresh; ++ if (!Storage->Blocking || Reaped >= Storage->Least) { ++ break; ++ } ++ Reaped += TopUpEvents(Storage->EventContext, Storage->StashGeneration, Words + Reaped * IoEventWords, Events - Reaped); ++ if (Reaped >= Storage->Least || !ContinueWait(Storage)) { ++ break; ++ } ++ Result = WaitForEvents(Storage, Words, Events, Reaped); ++ if (FEX::HLE::HasSyscallError(Result) && Reaped == 0) { ++ SettleEvents(Storage->EventContext, Storage->StashGeneration, Storage, 0, Result == static_cast(-EINVAL)); ++ return Result; ++ } ++ } ++ const bool Delivered = Reaped == 0 || CopyToGuest(Storage->Events, Words, Reaped * IoEventSize); ++ SettleEvents(Storage->EventContext, Storage->StashGeneration, Storage, Delivered ? 0 : Reaped, false); ++ if (!Delivered) { ++ return -EFAULT; ++ } ++ Result = Reaped; ++ } ++ if (FEX::HLE::HasSyscallError(Result)) { ++ return Result; ++ } ++ if (Storage->GuestMessages != 0) { ++ const bool FollowUps = !Storage->ReceivedMessages && Socket.FD >= 0; ++ const auto Total = FollowUps ? Storage->Messages.size() : std::min(Result, Storage->Messages.size()); ++ uint64_t Done = 0; ++ for (; Done < Total; ++Done) { ++ auto& Message = Storage->Messages[Done]; ++ if (Done >= Result && ::sendmmsg(Socket.FD, &Message, 1, Storage->SendFlags) != 1) { ++ break; ++ } ++ const auto Guest = Storage->GuestMessages + Done * sizeof(struct mmsghdr); ++ if ((Storage->ReceivedMessages && !ReturnMessageFields(Guest + offsetof(struct mmsghdr, msg_hdr), Message.msg_hdr)) || ++ !CopyToGuest(Guest + offsetof(struct mmsghdr, msg_len), &Message.msg_len, sizeof(Message.msg_len))) { ++ return Done == 0 ? -EFAULT : Done; ++ } ++ if (FollowUps && Message.msg_len < Storage->MessageLengths[Done]) { ++ return Done + 1; ++ } ++ } ++ return Done; ++ } ++ if (Storage->ReceivedHeader != 0 && !ReturnMessageFields(Storage->ReceivedHeader, Storage->Message)) { ++ return -EFAULT; ++ } ++ return Result; ++} ++ ++bool HandleFault(FEXCore::Core::InternalThreadState* Thread, int Signal, void* Info, void* UContext) { ++ auto* SigInfo = static_cast(Info); ++ const auto FaultAddress = reinterpret_cast(SigInfo->si_addr); ++ auto ThreadObject = FEX::HLE::ThreadManager::GetStateObjectFromFEXCoreThread(Thread); ++ auto& Trap = ThreadObject->HighMemoryTrap; ++ const auto PC = ArchHelpers::Context::GetPc(UContext); ++ ++ if (DeferWhileHeld(Trap.Mappings, Signal, SigInfo)) { ++ return true; ++ } ++ if (Trap.Active && PC == reinterpret_cast(Trap.Code)) { ++ RedeliverFromTrap(Trap, SigInfo, UContext); ++ return false; ++ } ++ ++ if (SigInfo->si_code <= SI_USER || !Contains(FaultAddress) || Trap.Active || Trap.Mappings.Held) { ++ return false; ++ } ++ ++ const auto Insn = *reinterpret_cast(PC); ++ if (!IsLoadStore(Insn) || IsLiteralLoad(Insn) || RnField(Insn) == 31) { ++ return false; ++ } ++ ++ uint64_t Address {}; ++ uint32_t Size {}; ++ bool Plain {}; ++ if (!DecodeAccess(Insn, UContext, &Address, &Size, &Plain)) { ++ return false; ++ } ++ ++ MappingHold Hold {Trap.Mappings}; ++ AccessPiece Pieces[MaxAccessPieces] {}; ++ const auto Parts = ReadConsistent([&] { return PlanAccessLocked(Address, Size, Pieces); }); ++ if (Parts == 0) { ++ return false; ++ } ++ ++ const bool Write = IsWrite(Insn); ++ if (Write && std::any_of(Pieces, Pieces + Parts, [](const AccessPiece& Piece) { return Piece.Code; })) { ++ auto& VMATracking = FEX::HLE::_SyscallHandler->VMATracking; ++ for (uint32_t i = 0; i < Parts; ++i) { ++ if (!Pieces[i].Code) { ++ continue; ++ } ++ const auto Last = Pieces[i].Guest + Pieces[i].Size - 1; ++ for (auto FaultBase = FEXCore::AlignDown(Pieces[i].Guest, FEXCore::Utils::FEX_PAGE_SIZE); FaultBase <= Last; ++ FaultBase += FEXCore::Utils::FEX_PAGE_SIZE) { ++ const auto Entry = VMATracking.FindVMAEntry(FaultBase); ++ if (Entry != VMATracking.VMAs.end()) { ++ FEX::HLE::SyscallHandler::InvalidateWrittenCodePage(Thread, FaultBase, Entry->first, Entry->second); ++ } else { ++ FEX::HLE::_SyscallHandler->TM.InvalidateGuestCodeRange(Thread, FaultBase, FEXCore::Utils::FEX_PAGE_SIZE); ++ } ++ } ++ } ++ ++ constexpr uint64_t MaxStoreSize = 64; ++ const uint64_t StoreWindowStart = FaultAddress - MaxStoreSize; ++ auto CTX = Thread->CTX; ++ if (CTX->IsAddressInCodeBuffer(Thread, PC) && !CTX->IsCurrentBlockSingleInst(Thread) && ++ CTX->IsAddressInCurrentBlock(Thread, StoreWindowStart, 2 * MaxStoreSize)) { ++ ThreadObject->SignalInfo.Delegator->SpillSRA(Thread, UContext, Thread->CurrentFrame->InSyscallInfo & 0xFFFF); ++ const auto& Config = ThreadObject->SignalInfo.Delegator->GetConfig(); ++ ArchHelpers::Context::SetPc(UContext, Config.AbsoluteLoopTopAddressFillSRA); ++ ArchHelpers::Context::SetArmReg(UContext, 1, 1); ++ return true; ++ } ++ } ++ ++ if (IsExclusive(Insn)) { ++ if (Parts != 1 || !ExclusiveReachable(Insn, Pieces[0].Prot) || ++ !EmulateExclusive(Trap.Monitor, Insn, Pieces[0].Host, UContext)) { ++ return false; ++ } ++ ArchHelpers::Context::SetPc(UContext, PC + 4); ++ return true; ++ } ++ ++ const bool Bounced = !HostContiguous(Pieces, Parts); ++ if (Bounced && (!PiecesReachable(Pieces, Parts, Write) || (!Plain && !IsOrderedAccess(Insn)))) { ++ return false; ++ } ++ ++ const int Scratch = PickScratch(Insn); ++ if (Scratch < 0 || !EnsureTrapCode(Trap)) { ++ return false; ++ } ++ ++ Trap.Scratch = Scratch; ++ Trap.Base = RnField(Insn); ++ Trap.SavedScratch = ArchHelpers::Context::GetArmReg(UContext, Scratch); ++ Trap.BaseBefore = ArchHelpers::Context::GetArmReg(UContext, Trap.Base); ++ Trap.ResumePC = PC + 4; ++ Trap.Parts = 0; ++ Trap.Delta = Pieces[0].Host - Address; ++ ++ uint32_t Failed = Parts; ++ if (Bounced && !Plain) { ++ Failed = EmulateOrdered(Insn, Pieces, Parts, UContext); ++ if (Failed == Parts) { ++ ArchHelpers::Context::SetPc(UContext, PC + 4); ++ return true; ++ } ++ } else if (Bounced) { ++ Trap.BounceOffset = Address & 15; ++ Trap.Store = Write; ++ Trap.Parts = Parts; ++ for (uint32_t i = 0; i < Parts; ++i) { ++ Trap.Pieces[i].Guest = Pieces[i].Guest; ++ Trap.Pieces[i].Host = Pieces[i].Host; ++ Trap.Pieces[i].Size = Pieces[i].Size; ++ } ++ auto* Window = Trap.Bounce + Trap.BounceOffset; ++ Failed = CopyPieces(Window, Trap.Pieces, Parts, true); ++ Trap.Delta = reinterpret_cast(Window) - Address; ++ } ++ ++ auto* Mask = &ArchHelpers::Context::GetUContext(UContext)->uc_sigmask; ++ memcpy(&Trap.SavedMask, Mask, sizeof(Trap.SavedMask)); ++ const uint64_t Blocked = ~HeldSignalMask(); ++ memcpy(Mask, &Blocked, sizeof(Blocked)); ++ if (Failed != Parts) { ++ ArmProbe(Trap, UContext, Pieces[Failed].Guest, Pieces[Failed].Host); ++ } else { ++ ArmTrap(Trap, UContext, (Insn & ~(0x1fU << 5)) | (static_cast(Scratch) << 5), Trap.BaseBefore + Trap.Delta, false); ++ } ++ Hold.Keep(); ++ return true; ++} ++ ++bool HandleBusFault(FEXCore::Core::InternalThreadState* Thread, int Signal, void* Info, void* UContext) { ++ auto* SigInfo = static_cast(Info); ++ auto& Trap = FEX::HLE::ThreadManager::GetStateObjectFromFEXCoreThread(Thread)->HighMemoryTrap; ++ const auto PC = ArchHelpers::Context::GetPc(UContext); ++ if (DeferWhileHeld(Trap.Mappings, Signal, SigInfo)) { ++ return true; ++ } ++ if (Trap.Active && PC == reinterpret_cast(Trap.Code)) { ++ RedeliverFromTrap(Trap, SigInfo, UContext); ++ return false; ++ } ++ if (SigInfo->si_code <= SI_USER || !FaultSafeUserMemAccess::IsFaultLocation(PC)) { ++ return false; ++ } ++ ArchHelpers::Context::SetArmReg(UContext, 0, EFAULT); ++ ArchHelpers::Context::SetPc(UContext, ArchHelpers::Context::GetArmReg(UContext, 30)); ++ return true; ++} ++ ++bool HandleTrap(FEXCore::Core::InternalThreadState* Thread, int Signal, void* Info, void* UContext) { ++ auto ThreadObject = FEX::HLE::ThreadManager::GetStateObjectFromFEXCoreThread(Thread); ++ auto& Trap = ThreadObject->HighMemoryTrap; ++ auto* SigInfo = static_cast(Info); ++ if (DeferWhileHeld(Trap.Mappings, Signal, SigInfo)) { ++ return true; ++ } ++ if (!Trap.Active || SigInfo->si_code != TRAP_BRKPT || ArchHelpers::Context::GetPc(UContext) != reinterpret_cast(Trap.Code) + 4) { ++ return false; ++ } ++ ++ if (Trap.Probe) { ++ ArchHelpers::Context::SetArmReg(UContext, Trap.Scratch, Trap.SavedScratch); ++ LeaveTrap(Trap, UContext, Trap.ResumePC - 4); ++ return true; ++ } ++ ++ const auto ScratchAfter = ArchHelpers::Context::GetArmReg(UContext, Trap.Scratch); ++ if (ScratchAfter != Trap.BaseBefore + Trap.Delta) { ++ ArchHelpers::Context::SetArmReg(UContext, Trap.Base, ScratchAfter - Trap.Delta); ++ } ++ if (Trap.Parts != 0 && Trap.Store) { ++ const auto Failed = CopyPieces(Trap.Bounce + Trap.BounceOffset, Trap.Pieces, Trap.Parts, false); ++ if (Failed != Trap.Parts) { ++ ArchHelpers::Context::SetArmReg(UContext, Trap.Base, Trap.BaseBefore); ++ ArmProbe(Trap, UContext, Trap.Pieces[Failed].Guest, Trap.Pieces[Failed].Host); ++ return true; ++ } ++ } ++ ArchHelpers::Context::SetArmReg(UContext, Trap.Scratch, Trap.SavedScratch); ++ LeaveTrap(Trap, UContext, Trap.ResumePC); ++ return true; ++} ++ ++void ReleaseThread(FEX::HLE::ThreadStateObject* Thread) { ++ if (Thread->HighMemoryTrap.Code) { ++ FEXCore::Allocator::munmap(Thread->HighMemoryTrap.Code, FEXCore::Utils::FEX_PAGE_SIZE); ++ Thread->HighMemoryTrap.Code = nullptr; ++ } ++} ++} // namespace FEX::HLE::GuestHighMemory +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/GuestHighMemory.h b/Source/Tools/LinuxEmulation/LinuxSyscalls/GuestHighMemory.h +new file mode 100644 +index 0000000..661b200 +--- /dev/null ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/GuestHighMemory.h +@@ -0,0 +1,74 @@ ++#pragma once ++ ++#include ++#include ++ ++#include ++#include ++#include ++#include ++ ++namespace FEXCore::Core { ++struct InternalThreadState; ++} ++ ++namespace FEX::HLE { ++struct ThreadStateObject; ++} ++ ++namespace FEX::HLE::GuestHighMemory { ++struct ArgumentStorage { ++ struct iovec Inline[8]; ++ fextl::vector Heap; ++ struct msghdr Message; ++ uint64_t ReceivedHeader {}; ++ fextl::vector Messages; ++ fextl::vector MessageLengths; ++ uint64_t GuestMessages {}; ++ bool ReceivedMessages {}; ++ int Socket {-1}; ++ int SendFlags {}; ++ uint32_t CapabilityHeader[2] {}; ++ uint32_t CapabilityVersion {}; ++ uint64_t GuestCapabilityHeader {}; ++ fextl::vector Words; ++ fextl::vector IoCopies; ++ fextl::vector IoKeys; ++ fextl::vector IoKeyValues; ++ fextl::vector EventBuffer; ++ fextl::list> Recovery; ++ uint64_t Events {}; ++ uint64_t EventContext {}; ++ uint64_t Stashed {}; ++ uint64_t StashGeneration {}; ++ uint64_t Least {}; ++ int64_t Deadline {}; ++ int64_t Wait[2] {}; ++ long EventSyscall {}; ++ uint64_t EventMask {}; ++ bool Blocking {}; ++ uint64_t SetupContext {}; ++ uint64_t SetupId {}; ++ uint64_t DestroyedContext {}; ++ uint64_t DestroyedGeneration {}; ++ bool Destroying {}; ++}; ++ ++bool Contains(uint64_t Address); ++bool ClaimsMapping(uint64_t Address, uint64_t Length, int Flags); ++uint64_t Map(uint64_t Address, uint64_t Length, int Prot, int Flags, int FD, off_t Offset); ++uint64_t Unmap(uint64_t Address, uint64_t Length); ++uint64_t Protect(uint64_t Address, uint64_t Length, int Prot); ++uint64_t Advise(uint64_t Address, uint64_t Length, int Advice, bool* Applied); ++bool DiscardsContents(int Advice); ++uint64_t ToGuest(uint64_t Address); ++bool TranslateRange(uint64_t Address, uint64_t Length, uint64_t* Host); ++void MarkCode(uint64_t Address, uint64_t Length); ++uint64_t TranslateSyscallArguments(uint64_t Syscall, uint64_t* Args, uint32_t Count, ArgumentStorage* Storage); ++uint64_t FinishSyscallArguments(uint64_t Result, ArgumentStorage* Storage); ++bool HoldsMappings(FEXCore::Core::InternalThreadState* Thread); ++bool HandleFault(FEXCore::Core::InternalThreadState* Thread, int Signal, void* Info, void* UContext); ++bool HandleBusFault(FEXCore::Core::InternalThreadState* Thread, int Signal, void* Info, void* UContext); ++bool HandleTrap(FEXCore::Core::InternalThreadState* Thread, int Signal, void* Info, void* UContext); ++void ReleaseThread(FEX::HLE::ThreadStateObject* Thread); ++} // namespace FEX::HLE::GuestHighMemory +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp +index 87b890e..ababed9 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp +@@ -7,6 +7,7 @@ $end_info$ + */ + + #include "LinuxSyscalls/SignalDelegator.h" ++#include "LinuxSyscalls/GuestHighMemory.h" + #include "LinuxSyscalls/Syscalls.h" + #include "LinuxSyscalls/PtraceEmu.h" + #include "LinuxSyscalls/SignalTrace.h" +@@ -765,6 +766,10 @@ uint64_t SignalDelegator::GetNewSigMask(int Signal) const { + } + + bool SignalDelegator::HandleFrontendSIGSEGV(FEXCore::Core::InternalThreadState* Thread, int Signal, void* Info, void* UContext) { ++ if (FEX::HLE::GuestHighMemory::HandleFault(Thread, Signal, Info, UContext)) { ++ return true; ++ } ++ + auto SigInfo = *static_cast(Info); + + if (FaultSafeUserMemAccess::TryHandleSafeFault(Signal, SigInfo, UContext)) { +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls.cpp +index 607ab0b..5e684c4 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls.cpp ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls.cpp +@@ -16,6 +16,7 @@ $end_info$ + #include "LinuxSyscalls/LinuxAllocator.h" + #include "LinuxSyscalls/SignalDelegator.h" + #include "LinuxSyscalls/PtraceEmu.h" ++#include "LinuxSyscalls/GuestHighMemory.h" + #include + #include "LinuxSyscalls/Syscalls.h" + #include "LinuxSyscalls/Syscalls/Thread.h" +@@ -820,6 +821,8 @@ SyscallHandler::SyscallHandler(FEXCore::Context::Context* _CTX, FEX::HLE::Signal + + SignalDelegation->RegisterHostSignalHandler(SIGSEGV, HandleSegfault, true); + ++ SignalDelegation->RegisterHostSignalHandler(SIGTRAP, FEX::HLE::GuestHighMemory::HandleTrap, true); ++ SignalDelegation->RegisterHostSignalHandler(SIGBUS, FEX::HLE::GuestHighMemory::HandleBusFault, true); + SignalDelegation->RegisterHostSignalHandler( + SIGTRAP, [](FEXCore::Core::InternalThreadState*, int, void*, void*) { return false; }, true); + +@@ -894,30 +897,34 @@ void SyscallHandler::HandleSyscallImpl(FEXCore::Core::CpuStateFrame* Frame, uint + } + + auto& Def = Definitions[SyscallNum]; ++ uint64_t A[7] {}; ++ for (unsigned i = 1; i < 7; ++i) { ++ A[i] = GetArg(Is64Bit, Frame, i); ++ } ++ FEX::HLE::GuestHighMemory::ArgumentStorage HighMemoryArguments; + uint64_t Result {}; +- switch (Def.NumArgs) { +- case 0: Result = std::invoke(Def.Ptr0, Frame); break; +- case 1: Result = std::invoke(Def.Ptr1, Frame, GetArg(Is64Bit, Frame, 1)); break; +- case 2: Result = std::invoke(Def.Ptr2, Frame, GetArg(Is64Bit, Frame, 1), GetArg(Is64Bit, Frame, 2)); break; +- case 3: Result = std::invoke(Def.Ptr3, Frame, GetArg(Is64Bit, Frame, 1), GetArg(Is64Bit, Frame, 2), GetArg(Is64Bit, Frame, 3)); break; +- case 4: +- Result = +- std::invoke(Def.Ptr4, Frame, GetArg(Is64Bit, Frame, 1), GetArg(Is64Bit, Frame, 2), GetArg(Is64Bit, Frame, 3), GetArg(Is64Bit, Frame, 4)); +- break; +- case 5: +- Result = std::invoke(Def.Ptr5, Frame, GetArg(Is64Bit, Frame, 1), GetArg(Is64Bit, Frame, 2), GetArg(Is64Bit, Frame, 3), +- GetArg(Is64Bit, Frame, 4), GetArg(Is64Bit, Frame, 5)); +- break; +- case 6: +- Result = std::invoke(Def.Ptr6, Frame, GetArg(Is64Bit, Frame, 1), GetArg(Is64Bit, Frame, 2), GetArg(Is64Bit, Frame, 3), +- GetArg(Is64Bit, Frame, 4), GetArg(Is64Bit, Frame, 5), GetArg(Is64Bit, Frame, 6)); +- break; +- // for missing syscalls +- case 255: Result = std::invoke(Def.Ptr1, Frame, GetArg(Is64Bit, Frame, 0)); break; +- default: +- LOGMAN_MSG_A_FMT("Unhandled syscall: {}", GetArg(Is64Bit, Frame, 0)); +- Result = -ENOSYS; +- break; ++ if constexpr (Is64Bit) { ++ Result = FEX::HLE::GuestHighMemory::TranslateSyscallArguments(SyscallNum, &A[1], 6, &HighMemoryArguments); ++ } ++ if (!FEX::HLE::HasSyscallError(Result)) { ++ switch (Def.NumArgs) { ++ case 0: Result = std::invoke(Def.Ptr0, Frame); break; ++ case 1: Result = std::invoke(Def.Ptr1, Frame, A[1]); break; ++ case 2: Result = std::invoke(Def.Ptr2, Frame, A[1], A[2]); break; ++ case 3: Result = std::invoke(Def.Ptr3, Frame, A[1], A[2], A[3]); break; ++ case 4: Result = std::invoke(Def.Ptr4, Frame, A[1], A[2], A[3], A[4]); break; ++ case 5: Result = std::invoke(Def.Ptr5, Frame, A[1], A[2], A[3], A[4], A[5]); break; ++ case 6: Result = std::invoke(Def.Ptr6, Frame, A[1], A[2], A[3], A[4], A[5], A[6]); break; ++ // for missing syscalls ++ case 255: Result = std::invoke(Def.Ptr1, Frame, GetArg(Is64Bit, Frame, 0)); break; ++ default: ++ LOGMAN_MSG_A_FMT("Unhandled syscall: {}", GetArg(Is64Bit, Frame, 0)); ++ Result = -ENOSYS; ++ break; ++ } ++ } ++ if constexpr (Is64Bit) { ++ Result = FEX::HLE::GuestHighMemory::FinishSyscallArguments(Result, &HighMemoryArguments); + } + #ifdef DEBUG_STRACE + Strace(Frame, Result); +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Memory.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Memory.cpp +index 9397c9e..6095bf3 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Memory.cpp ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Memory.cpp +@@ -5,12 +5,19 @@ tags: LinuxSyscalls|syscalls-shared + $end_info$ + */ + ++#include "LinuxSyscalls/GuestHighMemory.h" + #include "LinuxSyscalls/Syscalls.h" + #include "LinuxSyscalls/x64/Syscalls.h" + #include "LinuxSyscalls/x32/Syscalls.h" + + #include ++#include ++#include ++#include ++#include + ++#include ++#include + #include + #include + #include +@@ -25,6 +32,29 @@ void RegisterMemory(FEX::HLE::SyscallHandler* Handler) { + }); + + REGISTER_SYSCALL_IMPL(madvise, [](FEXCore::Core::CpuStateFrame* Frame, void* addr, size_t length, int32_t advice) -> uint64_t { ++ if (FEX::HLE::GuestHighMemory::Contains(reinterpret_cast(addr))) { ++ uint64_t Result {}; ++ bool Applied {}; ++ { ++ auto lk = FEXCore::GuardSignalDeferringSection(FEX::HLE::_SyscallHandler->VMATracking.Mutex, Frame->Thread); ++ Result = FEX::HLE::GuestHighMemory::Advise(reinterpret_cast(addr), length, advice, &Applied); ++ } ++ if (Applied && FEX::HLE::GuestHighMemory::DiscardsContents(advice)) { ++ const auto Base = reinterpret_cast(addr); ++ const auto Size = std::min(FEXCore::AlignUp(length, FEXCore::Utils::FEX_PAGE_SIZE), UINT64_MAX - Base); ++ FEX::HLE::_SyscallHandler->TM.InvalidateGuestCodeRange(Frame->Thread, Base, Size, [](uintptr_t Start, uintptr_t Length) { ++ if (FEX::HLE::GuestHighMemory::Contains(Start)) { ++ return; ++ } ++ auto rv = mprotect(reinterpret_cast(Start), Length, PROT_READ | PROT_WRITE); ++ LogMan::Throw::AFmt(rv == 0, "mprotect({}, {}) failed", Start, Length); ++ }); ++ } ++ if (!FEX::HLE::HasSyscallError(Result)) { ++ FEX::HLE::_SyscallHandler->TrackMadvise(Frame->Thread, (uintptr_t)addr, length, advice); ++ } ++ return Result; ++ } + uint64_t Result = ::madvise(addr, length, advice); + + if (Result != -1) { +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SyscallsSMCTracking.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/SyscallsSMCTracking.cpp +index f9e85a2..2dff836 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/SyscallsSMCTracking.cpp ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/SyscallsSMCTracking.cpp +@@ -21,6 +21,7 @@ $end_info$ + + #include "LinuxSyscalls/Syscalls.h" + #include "LinuxSyscalls/SignalDelegator.h" ++#include "LinuxSyscalls/GuestHighMemory.h" + + #include + #include +@@ -45,6 +46,9 @@ static void HandleSegfaultForCodeCacheFinalization(FEXCore::Core::InternalThread + void SyscallHandler::InvalidateWrittenCodePage(FEXCore::Core::InternalThreadState* Thread, uint64_t FaultBase, uint64_t EntryBase, + const FEX::HLE::VMATracking::VMAEntry& Mapping) { + auto UnprotectRegionCallback = [](uintptr_t Start, uintptr_t Length) { ++ if (FEX::HLE::GuestHighMemory::Contains(Start)) { ++ return; ++ } + auto rv = mprotect((void*)Start, Length, PROT_READ | PROT_WRITE); + LogMan::Throw::AFmt(rv == 0, "mprotect({}, {}) failed", Start, Length); + }; +@@ -93,6 +97,10 @@ bool SyscallHandler::HandleSegfault(FEXCore::Core::InternalThreadState* Thread, + } + } + ++ if (FEX::HLE::GuestHighMemory::Contains(FaultAddress) || FEX::HLE::GuestHighMemory::HoldsMappings(Thread)) { ++ return false; ++ } ++ + { + // Can't use the deferred signal lock in the SIGSEGV handler. + auto lk = FEXCore::MaskSignalsAndLockMutex(_SyscallHandler->VMATracking.Mutex); +@@ -150,6 +158,7 @@ void SyscallHandler::PrepareGuestBufferForKernelWrite(FEXCore::Core::InternalThr + return; + } + ++ Buf = reinterpret_cast(FEX::HLE::GuestHighMemory::ToGuest(reinterpret_cast(Buf))); + const uint64_t Start = FEXCore::AlignDown(reinterpret_cast(Buf), FEXCore::Utils::FEX_PAGE_SIZE); + const uint64_t Last = reinterpret_cast(Buf) + Length - 1 < reinterpret_cast(Buf) ? + UINT64_MAX : +@@ -176,6 +185,9 @@ void SyscallHandler::PrepareGuestBufferForKernelWrite(FEXCore::Core::InternalThr + } + } else { + TM.InvalidateGuestCodeRange(Thread, From, To - From, [](uintptr_t Start, uintptr_t Length) { ++ if (FEX::HLE::GuestHighMemory::Contains(Start)) { ++ return; ++ } + auto rv = mprotect(reinterpret_cast(Start), Length, PROT_READ | PROT_WRITE); + LogMan::Throw::AFmt(rv == 0, "mprotect({}, {}) failed", Start, Length); + }); +@@ -227,6 +239,10 @@ void SyscallHandler::MarkGuestExecutableRange(FEXCore::Core::InternalThreadState + const auto ProtectBase = std::max(MapBase, Base); + const auto ProtectSize = std::min(MapTop, Top) - ProtectBase; + ++ const bool HighRange = FEX::HLE::GuestHighMemory::Contains(ProtectBase); ++ if (HighRange) { ++ FEX::HLE::GuestHighMemory::MarkCode(ProtectBase, ProtectSize); ++ } + if (Mapping->second.Flags.Shared) { + LOGMAN_THROW_A_FMT(Mapping->second.Resource, "VMA tracking error"); + +@@ -245,13 +261,17 @@ void SyscallHandler::MarkGuestExecutableRange(FEXCore::Core::InternalThreadState + + const auto MirroredBase = std::max(VMAOffsetBase, OffsetBase); + const auto MirroredSize = std::min(OffsetTop, VMAOffsetTop) - MirroredBase; ++ if (FEX::HLE::GuestHighMemory::Contains(MirroredBase - VMAOffsetBase + VMABase)) { ++ FEX::HLE::GuestHighMemory::MarkCode(MirroredBase - VMAOffsetBase + VMABase, MirroredSize); ++ continue; ++ } + + auto rv = mprotect((void*)(MirroredBase - VMAOffsetBase + VMABase), MirroredSize, PROT_READ); + LogMan::Throw::AFmt(rv == 0, "mprotect({}, {}) failed", MirroredBase, MirroredSize); + } + } while ((VMA = VMA->ResourceNextVMA)); + +- } else if (Mapping->second.Prot.Writable) { ++ } else if (!HighRange && Mapping->second.Prot.Writable) { + int rv = mprotect((void*)ProtectBase, ProtectSize, PROT_READ); + + LogMan::Throw::AFmt(rv == 0, "mprotect({}, {}) failed", ProtectBase, ProtectSize); +@@ -293,6 +313,10 @@ void SyscallHandler::ProtectWritableAliasOfCode(uint64_t Base, uint64_t Length) + + const auto OverlapBase = std::max(VMA->Offset, OffsetBase); + const auto OverlapTop = std::min(VMA->Offset + VMA->Length, OffsetTop); ++ if (FEX::HLE::GuestHighMemory::Contains(MapBase + (OverlapBase - OffsetBase))) { ++ FEX::HLE::GuestHighMemory::MarkCode(MapBase + (OverlapBase - OffsetBase), OverlapTop - OverlapBase); ++ continue; ++ } + auto rv = mprotect((void*)(MapBase + (OverlapBase - OffsetBase)), OverlapTop - OverlapBase, PROT_READ); + LogMan::Throw::AFmt(rv == 0, "mprotect({}, {}) failed", OverlapBase, OverlapTop - OverlapBase); + } +@@ -429,6 +453,11 @@ void* SyscallHandler::GuestMmap(bool Is64Bit, FEXCore::Core::InternalThreadState + return reinterpret_cast(Result); + } + LOGMAN_THROW_A_FMT(Is64Bit || (Result >> 32) == 0 || (Result >> 32) == 0xFFFFFFFF, "values must fit to 32 bits"); ++ } else if (FEX::HLE::GuestHighMemory::ClaimsMapping(reinterpret_cast(addr), length, flags)) { ++ Result = FEX::HLE::GuestHighMemory::Map(reinterpret_cast(addr), length, prot, flags, fd, offset); ++ if (FEX::HLE::HasSyscallError(Result)) { ++ return reinterpret_cast(Result); ++ } + } else { + Result = reinterpret_cast(::mmap(reinterpret_cast(addr), length, prot, flags, fd, offset)); + if (Result == ~0ULL) { +@@ -483,9 +512,16 @@ uint64_t SyscallHandler::GuestMunmap(bool Is64Bit, FEXCore::Core::InternalThread + if (Addr > X86_64TaskSizeMax || Size > X86_64TaskSizeMax - Addr || (length != 0 && Size == 0)) { + return -EINVAL; + } +- Result = ::munmap(addr, length); +- if (Result == -1) { +- return -errno; ++ if (FEX::HLE::GuestHighMemory::Contains(Addr)) { ++ Result = FEX::HLE::GuestHighMemory::Unmap(Addr, length); ++ if (FEX::HLE::HasSyscallError(Result)) { ++ return Result; ++ } ++ } else { ++ Result = ::munmap(addr, length); ++ if (Result == -1) { ++ return -errno; ++ } + } + if (reinterpret_cast(addr) < 0x1'0000'0000ULL) { + Get32BitAllocator()->TrackUnmapped(addr, length); +@@ -511,6 +547,10 @@ uint64_t SyscallHandler::GuestMremap(bool Is64Bit, FEXCore::Core::InternalThread + { + auto lk = FEXCore::GuardSignalDeferringSection(VMATracking.Mutex, Thread); + if (Is64Bit) { ++ if (FEX::HLE::GuestHighMemory::Contains(reinterpret_cast(old_address)) || ++ ((flags & MREMAP_FIXED) && FEX::HLE::GuestHighMemory::Contains(reinterpret_cast(new_address)))) { ++ return -EINVAL; ++ } + Result = reinterpret_cast(::mremap(old_address, old_size, new_size, flags, new_address)); + if (Result == -1) { + return -errno; +@@ -602,9 +642,16 @@ uint64_t SyscallHandler::GuestMprotect(FEXCore::Core::InternalThreadState* Threa + } + } + +- Result = ::mprotect(addr, len, prot); +- if (Result == -1) { +- return -errno; ++ if (FEX::HLE::GuestHighMemory::Contains(reinterpret_cast(addr))) { ++ Result = FEX::HLE::GuestHighMemory::Protect(reinterpret_cast(addr), len, prot); ++ if (FEX::HLE::HasSyscallError(Result)) { ++ return Result; ++ } ++ } else { ++ Result = ::mprotect(addr, len, prot); ++ if (Result == -1) { ++ return -errno; ++ } + } + + TrackMprotect(Thread, addr, len, prot); +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.cpp +index 2e59f2f..ee28680 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.cpp ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.cpp +@@ -1,6 +1,7 @@ + // SPDX-License-Identifier: MIT + + #include "LinuxSyscalls/ThreadManager.h" ++#include "LinuxSyscalls/GuestHighMemory.h" + #include "LinuxSyscalls/SamplingProfiler.h" + + #include "LinuxSyscalls/Syscalls.h" +@@ -330,6 +331,7 @@ void ThreadManager::HandleThreadDeletion(FEX::HLE::ThreadStateObject* Thread, bo + FEXCore::Allocator::munmap(Thread->ldt_entries, Thread->ldt_entry_count * FEX::HLE::SyscallHandler::LDT_ENTRY_SIZE); + } + ++ FEX::HLE::GuestHighMemory::ReleaseThread(Thread); + CTX->DestroyThread(Thread->Thread); + FEX::HLE::_SyscallHandler->SeccompEmulator.FreeSeccompFilters(Thread); + +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.h b/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.h +index 9c5f9f1..e43dfc7 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.h ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.h +@@ -104,6 +104,40 @@ struct ThreadStateObject : public FEXCore::Allocator::FEXAllocOperators { + bool Enabled; + } SyscallUserDispatch {}; + ++ struct { ++ uint8_t* Code; ++ uint64_t ResumePC; ++ uint64_t SavedScratch; ++ uint64_t BaseBefore; ++ uint64_t Delta; ++ uint64_t SavedMask; ++ uint32_t Scratch; ++ uint32_t Base; ++ bool Active; ++ bool Store; ++ bool Probe; ++ struct { ++ bool Held; ++ uint32_t Deferred; ++ siginfo_t DeferredInfo[3]; ++ } Mappings; ++ uint32_t Parts; ++ uint32_t BounceOffset; ++ struct { ++ uint64_t Guest; ++ uint64_t Host; ++ uint64_t Size; ++ } Pieces[2]; ++ alignas(16) uint8_t Bounce[96]; ++ struct { ++ uint64_t Host; ++ uint64_t Low; ++ uint64_t High; ++ uint32_t Size; ++ bool Valid; ++ } Monitor; ++ } HighMemoryTrap {}; ++ + uint64_t JITStackSP {}; + + struct TrapSignalFrame { +-- +2.43.0 + diff --git a/tools/fex/patches/0028-guest-cmdline-without-checkpoint-restore.patch b/tools/fex/patches/0028-guest-cmdline-without-checkpoint-restore.patch new file mode 100644 index 0000000000..899b071568 --- /dev/null +++ b/tools/fex/patches/0028-guest-cmdline-without-checkpoint-restore.patch @@ -0,0 +1,58 @@ +From 0510284085165d39ef0eabb83e7604fe1bb74c76 Mon Sep 17 00:00:00 2001 +From: maxjivi05 +Date: Thu, 3 Dec 2026 03:26:13 -0500 +Subject: [PATCH] Show the guest command line when the argument area cannot be + remapped + +Kernels built without checkpoint/restore support refuse PR_SET_MM_MAP, +so /proc/pid/cmdline kept showing the FEX invocation instead of the +guest program and the argv rewrites it makes. For 64-bit guests whose +arguments fit, the guest argument strings now live in the original +argument area and argv points there, which needs no privilege. +--- + Source/Tools/FEXInterpreter/ELFCodeLoader.h | 23 ++++++++++++++++++++- + 1 file changed, 22 insertions(+), 1 deletion(-) + +diff --git a/Source/Tools/FEXInterpreter/ELFCodeLoader.h b/Source/Tools/FEXInterpreter/ELFCodeLoader.h +index b1a72d227..6d2157365 100644 +--- a/Source/Tools/FEXInterpreter/ELFCodeLoader.h ++++ b/Source/Tools/FEXInterpreter/ELFCodeLoader.h +@@ -874,13 +874,34 @@ public: + + int r = prctl(PR_SET_MM, PR_SET_MM_MAP, &map, sizeof(map), 0L); + if (r != 0) { +- LogMan::Msg::EFmt("Failed to remap /proc/pid/cmdline data (prctl failed: result {}, errno {})", r, errno); ++ int Error = errno; ++ if (Is64BitMode() && MoveArgumentDataToHostArea(NewArgStart, ArgSize)) { ++ return; ++ } ++ LogMan::Msg::EFmt("Failed to remap /proc/pid/cmdline data (prctl failed: result {}, errno {})", r, Error); + } + } else { + LogMan::Msg::EFmt("Failed to remap /proc/pid/cmdline data (GetCurrentMap failed)"); + } + } + ++ bool MoveArgumentDataToHostArea(uintptr_t GuestArgStart, uint64_t ArgSize) { ++ struct prctl_mm_map map {}; ++ if (!GetCurrentMap(map) || map.arg_end <= map.arg_start || ArgSize > map.arg_end - map.arg_start) { ++ return false; ++ } ++ ++ auto HostArgs = reinterpret_cast(map.arg_start); ++ memmove(HostArgs, reinterpret_cast(GuestArgStart), ArgSize); ++ memset(HostArgs + ArgSize, 0, map.arg_end - map.arg_start - ArgSize); ++ ++ auto ArgumentPointers = reinterpret_cast(StackPointer + sizeof(uint64_t)); ++ for (size_t i = 0; i < ApplicationArgs.size(); ++i) { ++ ArgumentPointers[i] = ArgumentPointers[i] - GuestArgStart + map.arg_start; ++ } ++ return true; ++ } ++ + // Setups the stack initial data (argv, envp, auxv) + void SetupStack() { + StackPointer += StackSize(); +-- +2.43.0 + diff --git a/tools/fex/patches/0029-proc-mount-tables-describe-the-container-procfs.patch b/tools/fex/patches/0029-proc-mount-tables-describe-the-container-procfs.patch new file mode 100644 index 0000000000..61cf5004df --- /dev/null +++ b/tools/fex/patches/0029-proc-mount-tables-describe-the-container-procfs.patch @@ -0,0 +1,310 @@ +From fc926d0e9c63a3d5290a5d816029513349de78f6 Mon Sep 17 00:00:00 2001 +From: maxjivi05 +Date: Thu, 3 Dec 2026 08:03:20 -0500 +Subject: [PATCH] Describe the container's procfs in emulated mount tables + +Android mounts /proc with hidepid=invisible,gid=3009 so an app cannot see the +processes of other users. Every process of the container runs as the app's +user, so the container sees all of its own processes, as it would through a +procfs of its own in a PID namespace. The emulated /proc//mounts and +mountinfo now list the proc mount without the host instance's access options +(hidepid, gid, subset). Every other mount is passed through unchanged. +--- + .../EmulatedFiles/EmulatedFiles.cpp | 230 +++++++++++++----- + .../EmulatedFiles/EmulatedFiles.h | 1 + + 2 files changed, 170 insertions(+), 61 deletions(-) + +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp +index 19bfc814f..85f1b3e15 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp +@@ -37,6 +37,7 @@ $end_info$ + #include + #include + #include ++#include + #include + #include + #include +@@ -649,6 +650,149 @@ static bool IsHostArchModule(const char* Path, fextl::unordered_map 0) { ++ Out.append(Buf, Len); ++ } else if (Len == 0) { ++ break; ++ } else if (errno != EINTR) { ++ LogMan::Msg::EFmt("Emulated /proc file: reading {} failed: {}", Path, errno); ++ ::close(HostFD); ++ return false; ++ } ++ } ++ ::close(HostFD); ++ return true; ++} ++ ++static int32_t SealedFileOf(const char* pathname, int32_t flags, const fextl::string& Data) { ++ int NewFD = GenTmpFD(pathname, flags); ++ if (NewFD < 0) { ++ LogMan::Msg::EFmt("Emulated /proc file: memfd_create failed: {}", errno); ++ return -1; ++ } ++ for (size_t Done = 0; Done < Data.size();) { ++ const ssize_t Wrote = ::write(NewFD, Data.data() + Done, Data.size() - Done); ++ if (Wrote > 0) { ++ Done += Wrote; ++ } else if (Wrote < 0 && errno == EINTR) { ++ continue; ++ } else { ++ LogMan::Msg::EFmt("Emulated /proc file: writing the synthesized file failed: {}", errno); ++ ::close(NewFD); ++ return -1; ++ } ++ } ++ if (::lseek(NewFD, 0, SEEK_SET) != 0) { ++ LogMan::Msg::EFmt("Emulated /proc file: lseek failed: {}", errno); ++ ::close(NewFD); ++ return -1; ++ } ++ SealTmpFD(NewFD); ++ return NewFD; ++} ++ ++static const char* ProcFileOfPid(const char* Path) { ++ if (strncmp(Path, "/proc/", 6) != 0) { ++ return nullptr; ++ } ++ const char* P = Path + 6; ++ if (strncmp(P, "self/", 5) == 0) { ++ return P + 5; ++ } ++ if (strncmp(P, "thread-self/", 12) == 0) { ++ return P + 12; ++ } ++ if (!isdigit(*P)) { ++ return P; ++ } ++ while (isdigit(*P)) { ++ ++P; ++ } ++ if (*P++ != '/') { ++ return nullptr; ++ } ++ if (strncmp(P, "task/", 5) == 0) { ++ P += 5; ++ if (!isdigit(*P)) { ++ return nullptr; ++ } ++ while (isdigit(*P)) { ++ ++P; ++ } ++ if (*P++ != '/') { ++ return nullptr; ++ } ++ } ++ return P; ++} ++ ++static bool IsProcMountTablePath(const char* Path) { ++ const char* File = ProcFileOfPid(Path); ++ return File && (strcmp(File, "mounts") == 0 || strcmp(File, "mountinfo") == 0); ++} ++ ++static fextl::string ContainerProcOptions(std::string_view Options) { ++ fextl::string Out; ++ size_t Pos = 0; ++ while (Pos <= Options.size()) { ++ size_t Comma = Options.find(',', Pos); ++ if (Comma == std::string_view::npos) { ++ Comma = Options.size(); ++ } ++ const std::string_view Option = Options.substr(Pos, Comma - Pos); ++ if (!Option.empty() && !Option.starts_with("hidepid=") && !Option.starts_with("gid=") && !Option.starts_with("subset=")) { ++ if (!Out.empty()) { ++ Out += ','; ++ } ++ Out.append(Option); ++ } ++ Pos = Comma + 1; ++ } ++ return Out; ++} ++ ++static fextl::string ContainerMountLine(std::string_view Line, bool MountInfo) { ++ fextl::vector Fields; ++ size_t Pos = 0; ++ while (Pos < Line.size()) { ++ size_t Space = Line.find(' ', Pos); ++ if (Space == std::string_view::npos) { ++ Space = Line.size(); ++ } ++ Fields.push_back(Line.substr(Pos, Space - Pos)); ++ Pos = Space + 1; ++ } ++ size_t Type = 2; ++ if (MountInfo) { ++ auto Dash = std::find(Fields.begin(), Fields.end(), std::string_view("-")); ++ Type = static_cast(Dash - Fields.begin()) + 1; ++ } ++ const size_t Options = MountInfo ? Type + 2 : Type + 1; ++ if (Options >= Fields.size() || Fields[Type] != "proc") { ++ return fextl::string(Line); ++ } ++ fextl::string Out; ++ for (size_t i = 0; i < Fields.size(); ++i) { ++ if (i) { ++ Out += ' '; ++ } ++ if (i == Options) { ++ Out += ContainerProcOptions(Fields[i]); ++ } else { ++ Out.append(Fields[i]); ++ } ++ } ++ return Out; ++} ++ + static bool IsProcMapsPath(const char* Path) { + if (strncmp(Path, "/proc/", 6) != 0) { + return false; +@@ -673,6 +817,9 @@ int32_t EmulatedFDManager::Open(const char* pathname, int flags, uint32_t mode) + if (pathname && IsProcMapsPath(pathname)) { + return ProcMaps(CTX, AT_FDCWD, pathname, flags, mode); + } ++ if (pathname && IsProcMountTablePath(pathname)) { ++ return ProcMounts(CTX, AT_FDCWD, pathname, flags, mode); ++ } + return -1; + } + +@@ -680,25 +827,10 @@ int32_t EmulatedFDManager::Open(const char* pathname, int flags, uint32_t mode) + } + + int32_t EmulatedFDManager::ProcMaps(FEXCore::Context::Context* ctx, int32_t fd, const char* pathname, int32_t flags, mode_t mode) { +- int HostFD = ::open(pathname, O_RDONLY | O_CLOEXEC); +- if (HostFD < 0) { +- return -1; +- } + fextl::string In; +- char Buf[65536]; +- for (;;) { +- const ssize_t Len = ::read(HostFD, Buf, sizeof(Buf)); +- if (Len > 0) { +- In.append(Buf, Len); +- } else if (Len == 0) { +- break; +- } else if (errno != EINTR) { +- LogMan::Msg::EFmt("ProcMaps: reading {} failed: {}", pathname, errno); +- ::close(HostFD); +- return -1; +- } ++ if (!ReadHostFile(pathname, In)) { ++ return -1; + } +- ::close(HostFD); + + constexpr uint64_t X86_64TaskSizeMax = (1ULL << 47) - 4096; + const bool HostSharesGuestRange = FEXCore::Allocator::GetHostVABits() < 47; +@@ -756,30 +888,29 @@ int32_t EmulatedFDManager::ProcMaps(FEXCore::Context::Context* ctx, int32_t fd, + Pos = End; + } + +- int NewFD = GenTmpFD(pathname, flags); +- if (NewFD < 0) { +- LogMan::Msg::EFmt("ProcMaps: memfd_create failed: {}", errno); ++ return SealedFileOf(pathname, flags, Out); ++} ++ ++int32_t EmulatedFDManager::ProcMounts(FEXCore::Context::Context* ctx, int32_t fd, const char* pathname, int32_t flags, mode_t mode) { ++ fextl::string In; ++ if (!ReadHostFile(pathname, In)) { + return -1; + } +- for (size_t Done = 0; Done < Out.size();) { +- const ssize_t Wrote = ::write(NewFD, Out.data() + Done, Out.size() - Done); +- if (Wrote > 0) { +- Done += Wrote; +- } else if (Wrote < 0 && errno == EINTR) { +- continue; +- } else { +- LogMan::Msg::EFmt("ProcMaps: writing the synthesized file failed: {}", errno); +- ::close(NewFD); +- return -1; ++ const char* File = ProcFileOfPid(pathname); ++ const bool MountInfo = File && strcmp(File, "mountinfo") == 0; ++ fextl::string Out; ++ Out.reserve(In.size()); ++ size_t Pos = 0; ++ while (Pos < In.size()) { ++ size_t Eol = In.find('\n', Pos); ++ const size_t LineEnd = Eol == fextl::string::npos ? In.size() : Eol; ++ Out += ContainerMountLine(std::string_view(In).substr(Pos, LineEnd - Pos), MountInfo); ++ if (Eol != fextl::string::npos) { ++ Out += '\n'; + } ++ Pos = LineEnd + 1; + } +- if (::lseek(NewFD, 0, SEEK_SET) != 0) { +- LogMan::Msg::EFmt("ProcMaps: lseek failed: {}", errno); +- ::close(NewFD); +- return -1; +- } +- SealTmpFD(NewFD); +- return NewFD; ++ return SealedFileOf(pathname, flags, Out); + } + + int32_t EmulatedFDManager::ProcStatus(FEXCore::Context::Context* ctx, int32_t fd, const char* pathname, int32_t flags, mode_t mode) { +@@ -832,30 +963,7 @@ int32_t EmulatedFDManager::ProcStatus(FEXCore::Context::Context* ctx, int32_t fd + Cursor = Eol + 1; + } + +- int NewFD = GenTmpFD(pathname, flags); +- if (NewFD < 0) { +- LogMan::Msg::EFmt("ProcMaps: memfd_create failed: {}", errno); +- return -1; +- } +- for (size_t Done = 0; Done < Out.size();) { +- const ssize_t Wrote = ::write(NewFD, Out.data() + Done, Out.size() - Done); +- if (Wrote > 0) { +- Done += Wrote; +- } else if (Wrote < 0 && errno == EINTR) { +- continue; +- } else { +- LogMan::Msg::EFmt("ProcMaps: writing the synthesized file failed: {}", errno); +- ::close(NewFD); +- return -1; +- } +- } +- if (::lseek(NewFD, 0, SEEK_SET) != 0) { +- LogMan::Msg::EFmt("ProcMaps: lseek failed: {}", errno); +- ::close(NewFD); +- return -1; +- } +- SealTmpFD(NewFD); +- return NewFD; ++ return SealedFileOf(pathname, flags, Out); + } + + int32_t EmulatedFDManager::ProcAuxv(FEXCore::Context::Context* ctx, int32_t fd, const char* pathname, int32_t flags, mode_t mode) { +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.h b/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.h +index b98ef4bda..b1ec241a7 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.h ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.h +@@ -35,6 +35,7 @@ private: + + static int32_t ProcAuxv(FEXCore::Context::Context* ctx, int32_t fd, const char* pathname, int32_t flags, mode_t mode); + static int32_t ProcMaps(FEXCore::Context::Context* ctx, int32_t fd, const char* pathname, int32_t flags, mode_t mode); ++ static int32_t ProcMounts(FEXCore::Context::Context* ctx, int32_t fd, const char* pathname, int32_t flags, mode_t mode); + static int32_t ProcStatus(FEXCore::Context::Context* ctx, int32_t fd, const char* pathname, int32_t flags, mode_t mode); + const uint32_t ThreadsConfig; + }; diff --git a/tools/fex/probes/guest-high-memory.c b/tools/fex/probes/guest-high-memory.c new file mode 100644 index 0000000000..fa4450183a --- /dev/null +++ b/tools/fex/probes/guest-high-memory.c @@ -0,0 +1,92 @@ +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include + +#define HIGH ((uintptr_t)0x7e0000000000ULL) +#define ALIAS ((uintptr_t)0x7e0000100000ULL) +#define THREADS 4 +#define ITERS 200000 + +static volatile uint64_t *counter; +static volatile uint64_t *cas; +static int fails; + +static void check(const char *name, int ok) { + printf("%s %s\n", ok ? "PASS" : "FAIL", name); + if (!ok) fails++; +} + +static void *worker(void *arg) { + (void)arg; + for (int i = 0; i < ITERS; i++) { + __atomic_fetch_add(counter, 1, __ATOMIC_SEQ_CST); + uint64_t old = __atomic_load_n(cas, __ATOMIC_RELAXED); + while (!__atomic_compare_exchange_n(cas, &old, old + 1, 0, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED)) { + } + } + return NULL; +} + +int main(void) { + alarm(60); + uint8_t *high = mmap((void *)HIGH, 65536, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0); + if (high == MAP_FAILED) { + printf("NOTCLAIMED errno=%d\n", errno); + return 0; + } + check("fixed-high-map", high == (uint8_t *)HIGH); + memset(high, 0x5a, 65536); + check("load-store", high[100] == 0x5a && high[65535] == 0x5a); + + counter = (uint64_t *)(high + 64); + cas = (uint64_t *)(high + 128); + *counter = 0; + *cas = 0; + pthread_t t[THREADS]; + for (int i = 0; i < THREADS; i++) pthread_create(&t[i], NULL, worker, NULL); + for (int i = 0; i < THREADS; i++) pthread_join(t[i], NULL); + check("atomic-add", *counter == (uint64_t)THREADS * ITERS); + check("atomic-cmpxchg", *cas == (uint64_t)THREADS * ITERS); + + int p[2]; + check("pipe", pipe(p) == 0); + memcpy(high + 4096, "hello ", 6); + memcpy(high + 8192, "world", 5); + struct iovec out[2] = {{high + 4096, 6}, {high + 8192, 5}}; + ssize_t w = writev(p[1], out, 2); + memset(high + 12288, 0, 64); + struct iovec in[2] = {{high + 12288, 3}, {high + 12291, 8}}; + ssize_t r = w == 11 ? readv(p[0], in, 2) : -1; + check("writev-readv", w == 11 && r == 11 && memcmp(high + 12288, "hello world", 11) == 0); + + int wrote = write(p[1], "abcdef", 6) == 6; + check("write", wrote); + check("read", wrote && read(p[0], high + 20000, 6) == 6 && memcmp(high + 20000, "abcdef", 6) == 0); + + high[30000] = 7; + check("madvise-dontneed", madvise(high + 28672, 4096, MADV_DONTNEED) == 0 && high[30000] == 0); + + int fd = memfd_create("code", 0); + check("memfd", fd >= 0 && ftruncate(fd, 4096) == 0); + static const uint8_t code[] = {0xb8, 0x01, 0x00, 0x00, 0x00, 0xc3}; + check("pwrite", pwrite(fd, code, sizeof code, 0) == (ssize_t)sizeof code); + uint8_t *low = mmap(NULL, 4096, PROT_READ | PROT_EXEC, MAP_SHARED, fd, 0); + uint8_t *alias = mmap((void *)ALIAS, 4096, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, fd, 0); + check("alias-map", low != MAP_FAILED && alias == (uint8_t *)ALIAS); + int (*fn)(void) = (int (*)(void))low; + int before = fn(); + alias[1] = 2; + __atomic_thread_fence(__ATOMIC_SEQ_CST); + int after = fn(); + printf("alias before=%d after=%d\n", before, after); + check("smc-through-high-alias", before == 1 && after == 2); + + printf("%s\n", fails ? "RESULT FAIL" : "RESULT PASS"); + return fails != 0; +} diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-fex b/tools/linuxfs/overlay/usr/local/bin/droiddeck-fex index 0b432bb5d3..1f5cc42743 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-fex +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-fex @@ -664,7 +664,7 @@ def data_dir(env): return DATA_DIR -def guest_environment(fex, env): +def guest_environment(fex, env, keep_compat=False): result = dict(env) data = data_dir(env) for directory in (CONFIG_DIR, data, CACHE_DIR): @@ -672,7 +672,7 @@ def guest_environment(fex, env): result["FEX_APP_CONFIG_LOCATION"] = CONFIG_DIR + "/" result["FEX_APP_DATA_LOCATION"] = data + "/" result["FEX_APP_CACHE_LOCATION"] = CACHE_DIR + "/" - if result.get("STEAM_COMPAT_DATA_PATH"): + if result.get("STEAM_COMPAT_DATA_PATH") and not keep_compat: short = data if data != DATA_DIR else "/tmp/fex" os.makedirs(short, exist_ok=True) result["STEAM_COMPAT_DATA_PATH"] = short @@ -750,9 +750,12 @@ def vulkan_thunk_loads(fex, folder): def required_runtime(program): - text = read_text(os.path.join(os.path.dirname(program), "toolmanifest.vdf")) or "" - match = re.search(r'"require_tool_appid"\s+"(\d+)"', text) - return match.group(1) if match and match.group(1) in RUNTIMES else SNIPER_APPID + folder = os.path.dirname(program) + for name in ("toolmanifest.vdf.droiddeck-orig", "toolmanifest.vdf"): + match = re.search(r'"require_tool_appid"\s+"(\d+)"', read_text(os.path.join(folder, name)) or "") + if match and match.group(1) in RUNTIMES: + return match.group(1) + return SNIPER_APPID def resolve(program, env): @@ -761,7 +764,7 @@ def resolve(program, env): return shutil.which(program, path=env.get("PATH")) or program -def launch(command, env, mode, decide=None): +def launch(command, env, mode, decide=None, keep_compat=False): program = resolve(command[0], env) use = mode == "on" or (mode == "auto" and needs_fex(decide or program)) if not use: @@ -769,7 +772,7 @@ def launch(command, env, mode, decide=None): fex = prepare(required_runtime(program)) if fex is None: return 126 - guest = guest_environment(fex, env) + guest = guest_environment(fex, env, keep_compat) x86_64 = elf_arch(program) != "i386" thunks = "on" if "FEX_THUNKCONFIG" in guest else "off" folder = decide if decide and os.path.isdir(decide) else os.path.dirname(program) @@ -781,7 +784,7 @@ def launch(command, env, mode, decide=None): return os.execve(fex["bin"], [fex["bin"], program] + command[1:], guest) -def game_environment(env, command): +def game_environment(env, command, proton=None): try: game_env = runpy.run_path(os.path.join(BIN_DIR, "droiddeck-game-env")) env = game_env["game_gpu"](env) @@ -800,7 +803,14 @@ def game_environment(env, command): config = json.load(source) except FileNotFoundError: config = {"version": 1} - return game_env["apply_config"](env, config, str(app), fixes) + env = game_env["apply_config"](env, config, str(app), fixes) + if proton and len(proton) > 2 and proton[1] == "waitforexitandrun": + logged = game_env["apply_game_debug_logs"](env, config) + if logged is not env: + say("game debug logs enabled for this launch") + env = game_env["game_logs"](proton, logged, str(app)) + game_env["GAME_DEBUG"]["cap_proton_log"](env) + return env except FileNotFoundError: return env except Exception as error: @@ -963,7 +973,7 @@ def parse_run(args): def main(argv): if not argv: - say("usage: droiddeck-fex steam VERB CMD... | run [--mode auto|on|off] [--for PATH] [--] CMD... | needs PATH | extract IMAGE | prepare | status") + say("usage: droiddeck-fex steam VERB CMD... | proton PROTON VERB CMD... | run [--mode auto|on|off] [--for PATH] [--] CMD... | needs PATH | extract IMAGE | prepare | update | status") return 2 action, args = argv[0], list(argv[1:]) if action == "steam": @@ -975,6 +985,10 @@ def main(argv): if not command: return 2 return launch(command, game_environment(dict(os.environ), command), os.environ.get("DROIDDECK_FEX", "auto")) + if action == "proton": + if len(args) < 2: + return 2 + return launch(args, game_environment(dict(os.environ), args[2:] or args, args), "on", keep_compat=True) if action == "run": try: mode, decide, command = parse_run(args) @@ -996,6 +1010,10 @@ def main(argv): return extract(args[0]) if action == "prepare": return 0 if prepare() else 1 + if action == "update": + with locked(): + update_own_fex() + return 0 if action == "status": with locked(): status = describe(fex_install(), runtime_platform(), graphics_platform()) diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-fex-update b/tools/linuxfs/overlay/usr/local/bin/droiddeck-fex-update index 25f445adee..f25d2a3394 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-fex-update +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-fex-update @@ -29,10 +29,14 @@ fex_install() { return 1 fi (cd "$tmp/root" && find . ! -type d) > "$tmp/files" - for d in usr/local/share/fex-emu/GuestThunks usr/local/share/fex-emu/GuestThunks_32 usr/local/lib/fex-emu/HostThunks usr/local/lib/fex-emu/HostThunks_32; do - [ -d "$tmp/root/$d" ] && [ -d "$dst$d" ] || continue - (cd "$dst" && find "$d" ! -type d) | while IFS= read -r f; do grep -qxF "./$f" "$tmp/files" || echo "$f"; done - done > "$tmp/stale" + { + for d in usr/local/share/fex-emu/GuestThunks usr/local/share/fex-emu/GuestThunks_32 usr/local/lib/fex-emu/HostThunks usr/local/lib/fex-emu/HostThunks_32; do + [ -d "$tmp/root/$d" ] && [ -d "$dst$d" ] || continue + (cd "$dst" && find "$d" ! -type d) | while IFS= read -r f; do grep -qxF "./$f" "$tmp/files" || echo "$f"; done + done + f=usr/local/share/fex-emu/.droiddeck-patches + if [ -e "$dst$f" ] && ! grep -qxF "./$f" "$tmp/files"; then echo "$f"; fi + } > "$tmp/stale" mkdir "$tmp/old" while IFS= read -r f; do f=${f#./} diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-debug b/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-debug index 24147636b7..6be7771a39 100644 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-debug +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-debug @@ -69,7 +69,8 @@ def apply_game_debug_logs(env, config=None, debug_dir=None): "PROTON_CRASH_REPORT_DIR": debug_dir, "DXVK_LOG_PATH": debug_dir, "DXVK_LOG_LEVEL": "debug", - "VKD3D_DEBUG": "info", + "VKD3D_DEBUG": "warn", + "VKD3D_SHADER_DEBUG": "warn", "WINEDEBUG": game_debug_channels(env.get("WINEDEBUG"), env.get("PROTON_LOG")), }) return result diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env b/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env index 04992da01b..bc4c7c73c8 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env @@ -91,6 +91,7 @@ XBOX_BACK_COMPAT_ENV = dict( VKD3D_INTEROP_PRESENT="1", VKD3D_PACKED_422="1", ) +PSPC_SDK_FILES = {"install_pspc_sdk_runtime.bat", "pspcsdkruntimeinstaller.msi", "pspcsdkruntimemanager.msi"} # Setup loader offset-table IDs, as innoextract's known_setup_loader_versions lists them. Loaders # from 5.1.5 keep the table in a resource; older ones also put "Inno" at file offset 0x30. INNO_LOADER_IDS = (b"rDlPtS", b"nS5W7dT\x83\xaa\x1b\x0fj") @@ -173,6 +174,15 @@ def game_files(exe): return names +def unreal_binary_files(exe): + project = os.path.splitext(os.path.basename(exe))[0] + try: + with os.scandir(os.path.join(os.path.dirname(exe), project, "Binaries", "Win64")) as folder: + return {entry.name.lower() for entry in folder} + except OSError: + return set() + + def xbox_identity(exe): """The identity name in the MicrosoftGame.config of the Xbox package the executable is in, or "".""" folder = os.path.dirname(exe) @@ -305,6 +315,12 @@ def arkham_city_x87(game): return {"FEX_X87REDUCEDPRECISION": "0"}, [], "Batman: Arkham City: FEX with full x87 precision" +@fix +def playstation_pc_sdk_x87(game): + if PSPC_SDK_FILES & (game.files | unreal_binary_files(game.exe)): + return {"FEX_X87REDUCEDPRECISION": "0"}, [], "PlayStation PC SDK: FEX with full x87 precision" + + @fix def split_second_x87_fip(game): if game.app_id == "297860" or game.stem == "splitsecond": diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-open-url b/tools/linuxfs/overlay/usr/local/bin/droiddeck-open-url index 48154cc849..83c84f885d 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-open-url +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-open-url @@ -3,6 +3,7 @@ import json import os LAUNCH_DIR_FILE = "/tmp/droiddeck-browser/launch-dir" +STEAM = "/usr/local/bin/droiddeck-steam-shim" import sys import time from pathlib import Path @@ -17,6 +18,13 @@ def hand_over(url, launch_dir): os.rename(tmp, req / (rid + ".json")) +def same_file(a, b): + try: + return os.path.samefile(a, b) + except OSError: + return os.path.realpath(a) == os.path.realpath(b) + + def where(url): from urllib.parse import urlsplit try: @@ -40,10 +48,11 @@ def main(argv): if url.startswith(("https://", "http://")) and launch_dir: hand_over(url, launch_dir) return 0 - here = os.path.dirname(os.path.realpath(sys.argv[0])) + if url.startswith("steam://") and os.access(STEAM, os.X_OK): + os.execv(STEAM, [STEAM, url]) for d in os.environ.get("PATH", "").split(os.pathsep): candidate = os.path.join(d, "xdg-open") - if os.access(candidate, os.X_OK) and os.path.realpath(candidate) != os.path.realpath(__file__) and os.path.abspath(d) != here: + if os.access(candidate, os.X_OK) and not same_file(candidate, __file__): os.execv(candidate, [candidate] + argv) return 1 diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-session b/tools/linuxfs/overlay/usr/local/bin/droiddeck-session index cced83f6f6..d82fb99350 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-session +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-session @@ -1560,6 +1560,7 @@ case $mode in decky_exits=0 # The guest has no "deck" user, which Decky otherwise requires at startup. export UNPRIVILEGED_USER=root + export LIVE_RELOAD=0 while :; do if [ "$decky_arch" = x86_64 ]; then /usr/local/bin/droiddeck-fex run --mode on -- "$decky_loader" >>"$HOME/homebrew/services/PluginLoader.log" 2>&1 & else "$decky_loader" >>"$HOME/homebrew/services/PluginLoader.log" 2>&1 & diff --git a/tools/linuxfs/overlay/usr/local/bin/steam-compatibility b/tools/linuxfs/overlay/usr/local/bin/steam-compatibility index 4eb7ba26f7..0f1a29f3ac 100755 --- a/tools/linuxfs/overlay/usr/local/bin/steam-compatibility +++ b/tools/linuxfs/overlay/usr/local/bin/steam-compatibility @@ -318,12 +318,80 @@ dd_vacdiag() { } """ +DD_ANTICHEAT_SETUP = """ +dd_anticheat_runtime() { + local current=$1 name=$2 bridge=$3 library + if [ -n "$current" ] && [ -n "$(find -L "$current" -iname "$bridge" -print -quit 2>/dev/null)" ]; then + printf '%s' "$current"; return 0 + fi + while IFS= read -r library; do + [ -n "$(find "$library/steamapps/common/$name" -iname "$bridge" -print -quit 2>/dev/null)" ] || continue + printf '%s' "$library/steamapps/common/$name"; return 0 + done < <(printf '%s\\n' "$DD_AC_ROOT" /mnt/droiddeck-sd; sed -n 's/^[[:space:]]*"path"[[:space:]]*"\\(.*\\)"[[:space:]]*$/\\1/p' "$DD_AC_ROOT/steamapps/libraryfolders.vdf" 2>/dev/null) + return 1 +} + +dd_x86_64_proton() { + [ -d "$1/files/lib/wine/x86_64-unix" ] && [ ! -d "$1/files/bin-arm64" ] +} + +dd_anticheat() { + case ${verb:-} in waitforexitandrun | run) ;; *) return 0 ;; esac + case ${DROIDDECK_ANTICHEAT:-auto} in off | 0 | false) return 0 ;; esac + local game=${STEAM_COMPAT_INSTALL_PATH:-} found markers eac battleye tool runtime= + [ -d "$game" ] || return 0 + markers=$(find "$game" -maxdepth 5 \\( -ipath '*/easyanticheat/settings.json' -o -iname 'easyanticheat_x64.so' \\ + -o -iname 'beclient_x64.so' -o -iname 'beservice_x64.exe' \\) -print 2>/dev/null) + eac=$(printf '%s\\n' "$markers" | grep -i easyanticheat | head -n 1) + battleye=$(printf '%s\\n' "$markers" | grep -iv easyanticheat | grep . | head -n 1) + found=${eac:-$battleye} + [ -n "$found" ] || return 0 + case ${DD_AC_TOOL:-DroidDeck-Proton} in + DroidDeck-Proton*) ;; + *) + echo "droiddeck-proton: anti-cheat files in ${found#$game/}; ${DD_AC_TOOL} was chosen for this game, so it runs as chosen" >&2 + return 0 + ;; + esac + /usr/local/bin/droiddeck-fex update || true + if ! grep -qx fixed-guest-memory-above-host-address-limit /usr/local/share/fex-emu/.droiddeck-patches 2>/dev/null; then + echo "droiddeck-proton: anti-cheat files in ${found#$game/}; the installed FEX build cannot run anti-cheat, so this launch stays on ARM64" >&2 + return 0 + fi + DD_AC_ROOT=${STEAM_COMPAT_CLIENT_INSTALL_PATH:-${XDG_DATA_HOME:-$HOME/.local/share}/Steam} + tool=$(cd "$DD_AC_ROOT/compatibilitytools.d" 2>/dev/null && for d in DroidDeck-Proton*; do + [ -x "$d/proton" ] && dd_x86_64_proton "$d" && printf '%s/%s\\n' "$PWD" "$d" + done | sort -V | tail -n 1) + if [ -z "$tool" ]; then + echo "droiddeck-proton: anti-cheat files in ${found#$game/}; no x86-64 DroidDeck-Proton is installed, so this launch stays on ARM64" >&2 + return 0 + fi + if [ -n "$eac" ] && runtime=$(dd_anticheat_runtime "${PROTON_EAC_RUNTIME:-}" "Proton EasyAntiCheat Runtime" easyanticheat_x64.so); then + export PROTON_EAC_RUNTIME="$runtime" + found=$eac + elif [ -n "$battleye" ] && runtime=$(dd_anticheat_runtime "${PROTON_BATTLEYE_RUNTIME:-}" "Proton BattlEye Runtime" beclient_x64.so); then + export PROTON_BATTLEYE_RUNTIME="$runtime" + found=$battleye + else + runtime= + fi + if [ -z "$runtime" ]; then + echo "droiddeck-proton: anti-cheat files in ${found#$game/}; its Proton runtime is not installed, so this launch stays on ARM64" >&2 + return 0 + fi + dd_game_cpus + declare -F dd_components >/dev/null && dd_components "$tool" + echo "droiddeck-proton: anti-cheat files in ${found#$game/}; running ${tool##*/} under FEX" >&2 + exec ${DD_TASKSET:-} /usr/local/bin/droiddeck-fex proton "$tool/proton" "$verb" "$@" +} +""" + # DroidDeck-Bionic runs only without proot. With proot on, a launch Steam sends to a DroidDeck-Bionic tool goes to the # newest DroidDeck-Proton's wrapper before anything else runs, as if that Proton had been picked; the picks stay as set. DD_BIONIC_PROOT_FALLBACK = """ if [ -f "$here/bionic/launch.sh" ] && [ -z "${DDNATV_ROOT:-}" ]; then dd_fallback=$(cd "$here/.." 2>/dev/null && for d in DroidDeck-Proton*; do - [ -x "$d/droiddeck-proton-wrap" ] && [ ! -e "$d/bionic/launch.sh" ] || continue + [ -x "$d/droiddeck-proton-wrap" ] && [ ! -e "$d/bionic/launch.sh" ] && ! dd_x86_64_proton "$d" || continue v=${d#DroidDeck-Proton}; printf '%s\\t%s/%s\\n' "${v#[ -]}" "$PWD" "$d" done | sort -V | tail -n 1 | cut -f 2-) if [ -n "$dd_fallback" ]; then @@ -461,6 +529,7 @@ for name in %s; do [ -n "$depot" ] && break done if [ -n "$depot" ]; then + dd_anticheat "$@" dd_components "$depot" dd_directaudio "$depot" "$@" dd_game_cpus @@ -481,7 +550,7 @@ LAUNCHER_TEMPLATE = LAUNCHER_SH def launcher_sh(sources=SOURCES): return (LAUNCHER_TEMPLATE % " ".join('"%s"' % n for n in sources)).replace( "verb=$1; shift", "verb=$1; shift\n" + DD_DRIVER_QUERY_SKIP + DD_DESKTOP_GPU_SETUP + DD_DIRECTAUDIO_SETUP + DD_GAME_CPUS_SETUP + DD_IDTECH3_SETUP - + DD_VACDIAG_SETUP + DD_COMPONENTS_SETUP + DD_LIBPATH_SETUP + DD_STORE_SETUP, 1) + + DD_VACDIAG_SETUP + DD_COMPONENTS_SETUP + DD_LIBPATH_SETUP + DD_STORE_SETUP + DD_ANTICHEAT_SETUP, 1) LAUNCHER_SH = launcher_sh() @@ -516,6 +585,11 @@ if [ -n "${PROOT_FP_KEY:-}" ] && [ -f "$audit" ]; then *) LD_AUDIT="$audit${LD_AUDIT:+:$LD_AUDIT}"; export LD_AUDIT ;; esac fi +if dd_x86_64_proton "$here"; then + dd_game_cpus + exec ${DD_TASKSET:-} /usr/local/bin/droiddeck-fex proton "$here/%s" "$verb" "$@" +fi +DD_AC_TOOL=$(basename "$(cd "$here" && pwd -P)") dd_anticheat "$@" dd_components "$here" dd_directaudio "$here" "$@" dd_game_cpus @@ -530,9 +604,9 @@ dd_run ${DD_TASKSET:-} /usr/local/bin/droiddeck-game-env "$DD_STORE_PROTON" "$ve def extra_wrapper_sh(entry_point): - return (EXTRA_WRAPPER_SH % entry_point).replace( + return (EXTRA_WRAPPER_SH % (entry_point, entry_point)).replace( 'here=$(dirname "$0")', - 'here=$(dirname "$0")\n' + DD_BIONIC_PROOT_FALLBACK + DD_DRIVER_QUERY_SKIP + DD_DESKTOP_GPU_SETUP + DD_DIRECTAUDIO_SETUP + DD_GAME_CPUS_SETUP + 'here=$(dirname "$0")\n' + DD_ANTICHEAT_SETUP + DD_BIONIC_PROOT_FALLBACK + DD_DRIVER_QUERY_SKIP + DD_DESKTOP_GPU_SETUP + DD_DIRECTAUDIO_SETUP + DD_GAME_CPUS_SETUP + DD_IDTECH3_SETUP + DD_VACDIAG_SETUP + DD_COMPONENTS_SETUP + DD_LIBPATH_SETUP + DD_STORE_SETUP, 1) @@ -1332,10 +1406,18 @@ def tool_catalog(steam_root, extras=None): continue extras[first_key(os.path.join(tool_dir, "compatibilitytool.vdf"), ["compatibilitytools", "compat_tools"]) or entry] = entry for name, entry in sorted(extras.items()): - catalog.append(tool_entry(name, display_name(entry), os.path.join(tools, entry), False)) + tool = tool_entry(name, display_name(entry), os.path.join(tools, entry), False) + if x86_64_layout(os.path.join(tools, entry)): + tool["x86_64"] = True + catalog.append(tool) return catalog +def x86_64_layout(path): + return (os.path.isdir(os.path.join(path, "files", "lib", "wine", "x86_64-unix")) and + not os.path.isdir(os.path.join(path, "files", "bin-arm64"))) + + def built_from(name, catalog, runnable=None): depot = VALVE_DEPOTS.get(name) tools = [t["name"] for t in catalog if depot and t["valve"] and t["dir"] == depot and @@ -1474,7 +1556,7 @@ ARCH_WORDS = re.compile(r"(?i)aarch64|arm64|x86_64|x86-64|amd64") def own_builds(tools): return [t for t in tools if isinstance(t, dict) and not t.get("valve") and - isinstance(t.get("dir"), str) and t["dir"].startswith(OWN_PROTON) and t.get("name")] + isinstance(t.get("dir"), str) and t["dir"].startswith(OWN_PROTON) and t.get("name") and not t.get("x86_64")] def build_key(name): @@ -1512,7 +1594,8 @@ def choose_default(steam_default, state, request, catalog, adopt_steam=True, app wanted = requested_tool(request, catalog) state["applied"] = seq if wanted: - if wanted != state.get("default"): + if wanted != state.get("default") or (state.get("source") not in ("app", "steam") and any( + t["name"] == wanted and t.get("x86_64") for t in catalog)): state.update(default=wanted, seq=now or now_ms(), source="app") else: print("steam-compatibility: the app asked for %s, which is not installed; kept %s" % ( @@ -1709,7 +1792,11 @@ def register_default(config_path, apps=(), protect=(), default=None, catalog=Non read_json(state_path("request.json", directory)), catalog) else: default = state.get("default") if state.get("default") in names else TOOL - if settle and newest and default == TOOL and state.get("source") not in ("app", "steam"): + automatic = state.get("source") not in ("app", "steam") + if settle and automatic and default in {t["name"] for t in catalog if t.get("x86_64")}: + default = newest or TOOL + state.update(default=default, seq=now_ms(), source="update") + elif settle and newest and default == TOOL and automatic: default = newest state.update(default=newest, seq=now_ms(), source="update") state.pop("own_proton", None) diff --git a/tools/linuxfs/preload/vdec.c b/tools/linuxfs/preload/vdec.c index 3bd38f3bc9..89e62129cf 100644 --- a/tools/linuxfs/preload/vdec.c +++ b/tools/linuxfs/preload/vdec.c @@ -957,8 +957,9 @@ __attribute__((visibility("hidden"))) void dd_vdec_closed(int fd) { __attribute__((visibility("hidden"))) int dd_vdec_poll(struct pollfd *fds, nfds_t n, int timeout_ms, int (*real)(struct pollfd *, nfds_t, int), int *ret) { - if (n != 1 || vd_find(fds[0].fd) == NULL) return 0; + if (n != 1 || __atomic_load_n(&vd_open_count, __ATOMIC_ACQUIRE) == 0) return 0; struct vdec *v = vd_find(fds[0].fd); + if (v == NULL) return 0; pthread_mutex_lock(&vd_lock); short ready = (v->n_cap_done ? POLLIN | POLLRDNORM : 0) | (v->n_out_done ? POLLOUT | POLLWRNORM : 0); pthread_mutex_unlock(&vd_lock); diff --git a/tools/linuxfs/preload/zram.c b/tools/linuxfs/preload/zram.c index 7fc21d0cab..446996a06e 100644 --- a/tools/linuxfs/preload/zram.c +++ b/tools/linuxfs/preload/zram.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -18,6 +19,9 @@ #include +#ifndef PR_SET_SYSCALL_USER_DISPATCH +#define PR_SET_SYSCALL_USER_DISPATCH 59 +#endif #ifndef MADV_PAGEOUT #define MADV_PAGEOUT 21 #endif @@ -538,13 +542,40 @@ static int zr_start(void) { return 0; } +static __thread volatile unsigned char *zr_dispatch __attribute__((tls_model("initial-exec"))); + +int prctl(int option, ...) { + va_list ap; + va_start(ap, option); + unsigned long arg2 = va_arg(ap, unsigned long); + unsigned long arg3 = va_arg(ap, unsigned long); + unsigned long arg4 = va_arg(ap, unsigned long); + unsigned long arg5 = va_arg(ap, unsigned long); + va_end(ap); + volatile unsigned char *dispatch = zr_dispatch; + unsigned char selector = dispatch != NULL ? *dispatch : 0; + if (selector) *dispatch = 0; + long result = zr_sys(SYS_prctl, option, arg2, arg3, arg4, arg5); + if (selector) *dispatch = selector; + if ((unsigned long)result > -4096UL) { + errno = (int)-result; + return -1; + } + if (option == PR_SET_SYSCALL_USER_DISPATCH) zr_dispatch = arg2 ? (volatile unsigned char *)arg5 : NULL; + return (int)result; +} + static void zr_handler(int sig, siginfo_t *info, void *context) { (void)sig; (void)context; if (info == NULL || info->si_code != SI_USER) return; + volatile unsigned char *dispatch = zr_dispatch; + unsigned char selector = dispatch != NULL ? *dispatch : 0; + if (selector) *dispatch = 0; int saved = errno; if (__atomic_fetch_add(&zr_requests, 1, __ATOMIC_ACQ_REL) == 0 && !zr_start()) zr_drain(0); errno = saved; + if (selector) *dispatch = selector; } static void zr_child(void) { diff --git a/tools/nativeguest/hook/exec.c b/tools/nativeguest/hook/exec.c index db55262540..ede8c4354d 100644 --- a/tools/nativeguest/hook/exec.c +++ b/tools/nativeguest/hook/exec.c @@ -374,6 +374,7 @@ static int ddnatv_execve(const char *filename, char *const argv[], char *const e errno = ENOSYS; return -1; } + if (is_proc_self_exe(filename) && g_real_exe[0] != '\0') filename = g_real_exe; if (depth == 0 && !in_exec_rehearsal()) ddh_try(filename, argv, envp); // Scripts get the path exactly as the caller wrote it ("./x.sh" stays "./x.sh" in $0), diff --git a/tools/nativeguest/hook/fileops.c b/tools/nativeguest/hook/fileops.c index a515e6a248..81a10b89e5 100644 --- a/tools/nativeguest/hook/fileops.c +++ b/tools/nativeguest/hook/fileops.c @@ -422,6 +422,7 @@ static ssize_t copy_readlink_result(char *buf, size_t bufsiz, const char *out, s if (ret <= 0 || out == buf) return ret; size_t n = (size_t)ret < bufsiz ? (size_t)ret : bufsiz; memcpy(buf, out, n); + if (n < bufsiz) buf[n] = '\0'; return (ssize_t)n; } @@ -454,6 +455,7 @@ ssize_t readlink(const char *pathname, char *buf, size_t bufsiz) { ssize_t readlinkat(int dirfd, const char *pathname, char *buf, size_t bufsiz) { static ssize_t (*orig_readlinkat)(int, const char *, char *, size_t) = NULL; if (!orig_readlinkat) orig_readlinkat = (ssize_t (*)(int, const char *, char *, size_t))dlsym(RTLD_NEXT, "readlinkat"); + const char *given = pathname; DDNATV_AT_REMAP(dirfd, pathname); // after the remap: "proc/self/exe" relative to a descriptor for "/" is /proc/self/exe as well { @@ -478,7 +480,7 @@ ssize_t readlinkat(int dirfd, const char *pathname, char *buf, size_t bufsiz) { const char *retry = usrmerge_retry_path(target, alt, sizeof(alt)); if (retry) ret = orig_readlinkat(dirfd, retry, out, outsiz); } - return copy_readlink_result(buf, bufsiz, out, postprocess_readlink(pathname, out, ret, outsiz)); + return copy_readlink_result(buf, bufsiz, out, postprocess_named_readlink(pathname, pathname == given ? pathname : NULL, out, ret, outsiz)); } // Fortified readlink variants used by dpkg / update-alternatives @@ -776,7 +778,7 @@ char *realpath(const char *path, char *resolved_path) { char pbuf[PATH_MAX]; const char *target = rewrite_path(path, pbuf, sizeof(pbuf)); char *res = orig_realpath ? orig_realpath(target, resolved_path) : NULL; - if (res && g_ddnatv_root[0] != '\0') { + if (res && g_ddnatv_root[0] != '\0' && !is_rootfs_real_path(path)) { size_t rlen = g_ddnatv_root_len; if (strncmp(res, g_ddnatv_root, rlen) == 0 && (res[rlen] == '/' || res[rlen] == '\0')) { size_t rem_len = strlen(res + rlen); diff --git a/tools/nativeguest/hook/files.c b/tools/nativeguest/hook/files.c index 318adb79ef..7ea658d006 100644 --- a/tools/nativeguest/hook/files.c +++ b/tools/nativeguest/hook/files.c @@ -197,6 +197,116 @@ static int open_proc_status_at(int dirfd, const char *name, int flags) { return open_proc_status(dir, flags); } +static long call_orig_syscall(long number, unsigned long a1, unsigned long a2, unsigned long a3, unsigned long a4, unsigned long a5, unsigned long a6); + +#ifndef F_SEAL_EXEC +#define F_SEAL_EXEC 0x0020 +#endif +#ifndef MFD_EXEC +#define MFD_EXEC 0x0010U +#endif + +static int own_fd_of_path(const char *path) { + if (!path) return -1; + const char *p; + if (strncmp(path, "/dev/fd/", 8) == 0) { + p = path + 8; + } else { + if (!is_proc_fd_link(path)) return -1; + const char *who = path + 6; + if (*who >= '0' && *who <= '9') { + long pid = 0; + while (*who >= '0' && *who <= '9') pid = pid * 10 + (*who++ - '0'); + if (pid != (long)call_orig_syscall(SYS_getpid, 0, 0, 0, 0, 0, 0)) { + char task[48]; + snprintf(task, sizeof(task), "/proc/self/task/%ld", pid); + if (call_orig_syscall(SYS_faccessat, (unsigned long)AT_FDCWD, (unsigned long)task, F_OK, 0, 0, 0) != 0) return -1; + } + } + p = strstr(path + 6, "/fd/") + 4; + } + if (*p < '0' || *p > '9') return -1; + long fd = 0; + while (*p >= '0' && *p <= '9') { + fd = fd * 10 + (*p++ - '0'); + if (fd > INT_MAX) return -1; + } + return *p == '\0' ? (int)fd : -1; +} + +static int copy_memfd_contents(int from, int to, off_t size) { + char chunk[32768]; + off_t at = 0; + while (at < size) { + size_t want = (size_t)(size - at) < sizeof(chunk) ? (size_t)(size - at) : sizeof(chunk); + long got = call_orig_syscall(SYS_pread64, (unsigned long)from, (unsigned long)chunk, want, (unsigned long)at, 0, 0); + if (got < 0 && errno == EINTR) continue; + if (got <= 0) return -1; + long done = 0; + while (done < got) { + long put = call_orig_syscall(SYS_write, (unsigned long)to, (unsigned long)(chunk + done), (unsigned long)(got - done), 0, 0, 0); + if (put < 0 && errno == EINTR) continue; + if (put <= 0) return -1; + done += put; + } + at += got; + } + return 0; +} + +static int copy_of_memfd(int src, int flags) { + char link[48], target[PATH_MAX]; + snprintf(link, sizeof(link), "/proc/thread-self/fd/%d", src); + long n = call_orig_syscall(SYS_readlinkat, (unsigned long)AT_FDCWD, (unsigned long)link, (unsigned long)target, sizeof(target) - 1, 0, 0); + if (n <= 7 || strncmp(target, "/memfd:", 7) != 0) return -1; + target[n] = '\0'; + char *name = target + 7; + size_t name_len = (size_t)n - 7; + if (name_len >= 10 && strcmp(name + name_len - 10, " (deleted)") == 0) name[name_len -= 10] = '\0'; + if (name_len > 249) name[249] = '\0'; + struct stat st; + if (call_orig_syscall(SYS_fstat, (unsigned long)src, (unsigned long)&st, 0, 0, 0, 0) != 0 || !S_ISREG(st.st_mode)) return -1; + long seals = call_orig_syscall(SYS_fcntl, (unsigned long)src, F_GET_SEALS, 0, 0, 0, 0); + if (seals < 0) return -1; + unsigned long mfd_flags = MFD_ALLOW_SEALING | ((flags & O_CLOEXEC) ? MFD_CLOEXEC : 0); + long copy = -1; + if (st.st_mode & 0111) copy = call_orig_syscall(SYS_memfd_create, (unsigned long)name, mfd_flags | MFD_EXEC, 0, 0, 0, 0); + if (copy < 0) copy = call_orig_syscall(SYS_memfd_create, (unsigned long)name, mfd_flags, 0, 0, 0, 0); + if (copy < 0) return -1; + int ok = copy_memfd_contents(src, (int)copy, st.st_size) == 0 && + call_orig_syscall(SYS_lseek, (unsigned long)copy, 0, SEEK_SET, 0, 0, 0) == 0 && + call_orig_syscall(SYS_fchmod, (unsigned long)copy, st.st_mode & 07777, 0, 0, 0, 0) == 0 && + call_orig_syscall(SYS_fcntl, (unsigned long)copy, F_ADD_SEALS, (unsigned long)(seals | F_SEAL_WRITE | F_SEAL_GROW | F_SEAL_SHRINK), 0, 0, 0) == 0; + if (!ok) { + call_orig_syscall(SYS_close, (unsigned long)copy, 0, 0, 0, 0, 0); + return -1; + } + return (int)copy; +} + +static int reopen_denied_memfd(const char *path, int flags) { + if ((flags & O_ACCMODE) != O_RDONLY || (flags & (O_CREAT | O_TRUNC | O_DIRECTORY | O_PATH))) return -1; + int named = own_fd_of_path(path); + if (named < 0) return -1; + long src = call_orig_syscall(SYS_fcntl, (unsigned long)named, F_DUPFD_CLOEXEC, 0, 0, 0, 0); + if (src < 0) return -1; + struct stat by_path, by_fd; + int same = call_orig_syscall(SYS_newfstatat, (unsigned long)AT_FDCWD, (unsigned long)path, (unsigned long)&by_path, 0, 0, 0) == 0 && + call_orig_syscall(SYS_fstat, (unsigned long)src, (unsigned long)&by_fd, 0, 0, 0, 0) == 0 && + by_path.st_dev == by_fd.st_dev && by_path.st_ino == by_fd.st_ino; + int copy = same ? copy_of_memfd((int)src, flags) : -1; + call_orig_syscall(SYS_close, (unsigned long)src, 0, 0, 0, 0, 0); + return copy; +} + +static int open_or_reopen_memfd(int fd, const char *path, int flags) { + if (fd >= 0 || errno != EACCES) return fd; + int copy = reopen_denied_memfd(path, flags); + if (copy >= 0) return copy; + errno = EACCES; + return -1; +} + // Hook open int open(const char *pathname, int flags, ...) { static int (*orig_open)(const char *, int, ...) = NULL; @@ -225,7 +335,7 @@ int open(const char *pathname, int flags, ...) { forget_proc_root_fd(fd); return fd; } - int fd = orig_open(target, flags); + int fd = open_or_reopen_memfd(orig_open(target, flags), pathname, flags); remember_proc_root_fd(fd, pathname); return fd; } @@ -259,7 +369,7 @@ int openat(int dirfd, const char *pathname, int flags, ...) { forget_proc_root_fd(fd); return fd; } - int fd = orig_openat(dirfd, target, flags); + int fd = open_or_reopen_memfd(orig_openat(dirfd, target, flags), (pathname && pathname[0] == '/') ? pathname : NULL, flags); remember_proc_root_fd(fd, pathname); return fd; } @@ -304,6 +414,11 @@ static long call_orig_syscall(long number, unsigned long a1, unsigned long a2, u return orig_syscall ? orig_syscall(number, a1, a2, a3, a4, a5, a6) : syscall(number, a1, a2, a3, a4, a5, a6); } +static int openat2_or_reopen_memfd(int fd, const char *pathname, const struct ddnatv_open_how *how) { + if (fd >= 0 || errno != EACCES || pathname[0] != '/' || !how || how->resolve) return fd; + return open_or_reopen_memfd(fd, pathname, (int)how->flags); +} + // Hook openat2 (used by GNU tar 1.35+/gnulib for RESOLVE_BENEATH traversal). // Rewrites absolute paths like openat, then delegates; on ENOSYS (kernels // without openat2, e.g. Android < 5.6) emulates with plain openat instead of @@ -334,12 +449,12 @@ int openat2(int dirfd, const char *pathname, struct ddnatv_open_how *how, size_t const char *target = (pathname[0] == '/') ? rewrite_path(pathname, buf, sizeof(buf)) : pathname; if (orig_openat2) { int ret = orig_openat2(dirfd, target, how, usize); - if (ret >= 0 || errno != ENOSYS) return ret; + if (ret >= 0 || errno != ENOSYS) return openat2_or_reopen_memfd(ret, pathname, how); } #ifdef __NR_openat2 long sret = call_orig_syscall(__NR_openat2, (unsigned long)dirfd, (unsigned long)target, (unsigned long)how, (unsigned long)usize, 0, 0); if (sret >= 0 || errno != ENOSYS) { - return (int)sret; + return openat2_or_reopen_memfd((int)sret, pathname, how); } #endif if (!how || usize < 16) { @@ -646,6 +761,7 @@ int lstat(const char *pathname, struct stat *statbuf) { int fstatat(int dirfd, const char *pathname, struct stat *statbuf, int flags) { static int (*orig_fstatat)(int, const char *, struct stat *, int) = NULL; if (!orig_fstatat) orig_fstatat = (int (*)(int, const char *, struct stat *, int))dlsym(RTLD_NEXT, "fstatat"); + const char *given = pathname; DDNATV_AT_REMAP(dirfd, pathname); char buf[PATH_MAX]; const char *target = (pathname && pathname[0] == '/') ? ((flags & AT_SYMLINK_NOFOLLOW) ? rewrite_path : rewrite_path_follow)(pathname, buf, sizeof(buf)) : pathname; @@ -665,7 +781,7 @@ int fstatat(int dirfd, const char *pathname, struct stat *statbuf, int flags) { if (!orig_readlinkat) orig_readlinkat = (ssize_t (*)(int, const char *, char *, size_t))dlsym(RTLD_NEXT, "readlinkat"); ssize_t llen = orig_readlinkat ? orig_readlinkat(dirfd, target, link_buf, sizeof(link_buf) - 1) : -1; if (llen > 0) { - ssize_t post_len = postprocess_readlink(pathname, link_buf, llen, sizeof(link_buf)); + ssize_t post_len = postprocess_named_readlink(pathname, pathname == given ? pathname : NULL, link_buf, llen, sizeof(link_buf)); if (post_len > 0) { statbuf->st_size = post_len; } diff --git a/tools/nativeguest/hook/paths.c b/tools/nativeguest/hook/paths.c index 74983a7552..e8f9060b45 100644 --- a/tools/nativeguest/hook/paths.c +++ b/tools/nativeguest/hook/paths.c @@ -952,6 +952,30 @@ static int is_proc_fd_link(const char *path) { return *p == '\0'; } +static int is_proc_cwd_link(const char *path) { + if (!path || strncmp(path, "/proc/", 6) != 0) return 0; + const char *p = path + 6; + if (strncmp(p, "self/", 5) == 0) { + p += 5; + } else if (strncmp(p, "thread-self/", 12) == 0) { + p += 12; + } else { + if (*p < '0' || *p > '9') return 0; + while (*p >= '0' && *p <= '9') p++; + if (*p != '/') return 0; + p++; + } + return strcmp(p, "cwd") == 0; +} + +static int is_rootfs_real_path(const char *path) { + return path && g_ddnatv_root_len > 0 && is_path_prefix(path, g_ddnatv_root, g_ddnatv_root_len); +} + +static int link_answers_in_kernel_form(const char *linkpath, const char *named) { + return is_proc_fd_link(linkpath) || is_proc_cwd_link(linkpath) || is_rootfs_real_path(named); +} + // The guest path of a folder that a session mount puts outside the rootfs, for what the kernel // reports as its real place (getcwd(), /proc/self/cwd and fd links). Wine found no DOS drive for // Sekiro's folder on the SD card library ("starting in the Windows directory"), and the game quit. @@ -989,7 +1013,7 @@ static char *guest_path_of_allocated_mount_source(char *res) { return grown; } -static ssize_t postprocess_readlink(const char *linkpath, char *buf, ssize_t ret, size_t bufsiz) { +static ssize_t postprocess_named_readlink(const char *linkpath, const char *named, char *buf, ssize_t ret, size_t bufsiz) { if (ret <= 0) return ret; if ((size_t)ret < bufsiz) { buf[ret] = '\0'; @@ -998,7 +1022,7 @@ static ssize_t postprocess_readlink(const char *linkpath, char *buf, ssize_t ret ret = (ssize_t)guest_path_of_mount_source(buf, (size_t)ret, bufsiz, NULL); // 1. Strip g_ddnatv_root if target starts with it - if (g_ddnatv_root_len > 0 && !is_proc_fd_link(linkpath)) { + if (g_ddnatv_root_len > 0 && !link_answers_in_kernel_form(linkpath, named)) { size_t rlen = g_ddnatv_root_len; if ((size_t)ret >= rlen && memcmp(buf, g_ddnatv_root, rlen) == 0 && ((size_t)ret == rlen || buf[rlen] == '/')) { @@ -1053,6 +1077,10 @@ static ssize_t postprocess_readlink(const char *linkpath, char *buf, ssize_t ret return ret; } +static ssize_t postprocess_readlink(const char *linkpath, char *buf, ssize_t ret, size_t bufsiz) { + return postprocess_named_readlink(linkpath, linkpath, buf, ret, bufsiz); +} + // Android's SELinux label, which the xattr hooks keep away from Ubuntu programs. static const char k_selinux_xattr[] = "security.selinux"; diff --git a/tools/nativeguest/hook/privileged.c b/tools/nativeguest/hook/privileged.c index 0ca6f97880..9fd5a8077f 100644 --- a/tools/nativeguest/hook/privileged.c +++ b/tools/nativeguest/hook/privileged.c @@ -668,6 +668,19 @@ long syscall(long number, ...) { } #endif +#ifdef __NR_execve + if (number == __NR_execve) { + return (long)execve((const char *)arg1, (char *const *)arg2, (char *const *)arg3); + } +#endif + +#ifdef __NR_execveat + if (number == __NR_execveat && arg2 && ((const char *)arg2)[0] != '\0' && + (((const char *)arg2)[0] == '/' || (int)arg1 == AT_FDCWD) && (arg5 & ~(unsigned long)AT_EMPTY_PATH) == 0) { + return (long)execve((const char *)arg2, (char *const *)arg3, (char *const *)arg4); + } +#endif + #ifdef __NR_clone3 if (number == __NR_clone3) { errno = ENOSYS; diff --git a/tools/nativeguest/hook/setup.c b/tools/nativeguest/hook/setup.c index 4b7d2bbb0f..d94956af5a 100644 --- a/tools/nativeguest/hook/setup.c +++ b/tools/nativeguest/hook/setup.c @@ -307,6 +307,7 @@ static ssize_t copy_guest_exe(const char *real_exe, char *buf, size_t bufsiz) { size_t len = strlen(out_path); size_t copy_len = (len < bufsiz) ? len : bufsiz; memcpy(buf, out_path, copy_len); + if (copy_len < bufsiz) buf[copy_len] = '\0'; return (ssize_t)copy_len; } diff --git a/tools/nativeguest/hook/signals.c b/tools/nativeguest/hook/signals.c index 4ed9522da4..3d370bae28 100644 --- a/tools/nativeguest/hook/signals.c +++ b/tools/nativeguest/hook/signals.c @@ -10,6 +10,12 @@ #define SYS_SECCOMP 1 #endif +#if defined(__aarch64__) +#define DDNATV_HOST_AUDIT_ARCH 0xC00000B7U +#else +#define DDNATV_HOST_AUDIT_ARCH 0x40000028U +#endif + static int (*get_real_sigaction(void))(int, const struct sigaction *, struct sigaction *); // A program's own SIGSYS handler, for the traps of a seccomp filter it installed itself (Firefox's @@ -57,7 +63,13 @@ static long sigsys_id_change(int nr, const unsigned long long *regs, long ret_va // Intercept SECCOMP blocked syscalls (SIGSYS), resolve sandbox/landlock gracefully, and advance PC static void ddnatv_sigsys_handler(int sig, siginfo_t *info, void *ctx) { if (!ctx || !info) return; - if (info->si_code != SYS_SECCOMP) { + int host_trap = info->si_code == SYS_SECCOMP && info->si_errno == 0 && info->si_arch == DDNATV_HOST_AUDIT_ARCH; + if (!host_trap && g_app_sigsys_set) { + if (g_app_sigsys.sa_flags & SA_SIGINFO) g_app_sigsys.sa_sigaction(sig, info, ctx); + else g_app_sigsys.sa_handler(sig); + return; + } + if (!host_trap) { int (*real_sig)(int, const struct sigaction *, struct sigaction *) = get_real_sigaction(); if (real_sig) { struct sigaction sa_dfl; @@ -69,11 +81,6 @@ static void ddnatv_sigsys_handler(int sig, siginfo_t *info, void *ctx) { raise(sig); return; } - if (info->si_errno != 0 && g_app_sigsys_set) { - if (g_app_sigsys.sa_flags & SA_SIGINFO) g_app_sigsys.sa_sigaction(sig, info, ctx); - else g_app_sigsys.sa_handler(sig); - return; - } ucontext_t *uctx = (ucontext_t *)ctx; int sys_nr = info->si_syscall; diff --git a/tools/tests/effects_source_cache_harness.c b/tools/tests/effects_source_cache_harness.c index da9615d1c6..11cfd85080 100644 --- a/tools/tests/effects_source_cache_harness.c +++ b/tools/tests/effects_source_cache_harness.c @@ -67,7 +67,12 @@ static void VKAPI_CALL pipeline_barrier(VkCommandBuffer cmd, VkPipelineStageFlag static void VKAPI_CALL begin_pass(VkCommandBuffer c, const VkRenderPassBeginInfo *i, VkSubpassContents s) {} static void VKAPI_CALL viewport(VkCommandBuffer c, uint32_t f, uint32_t n, const VkViewport *v) {} static void VKAPI_CALL scissor(VkCommandBuffer c, uint32_t f, uint32_t n, const VkRect2D *v) {} -static void VKAPI_CALL bind_pipeline(VkCommandBuffer c, VkPipelineBindPoint b, VkPipeline p) {} +static unsigned area_copies, search_copies, weight_passes; +static void VKAPI_CALL bind_pipeline(VkCommandBuffer c, VkPipelineBindPoint b, VkPipeline p) { + if (p != g_pipe[P_SMAA_WEIGHTS]) return; + weight_passes++; + assert(area_copies == weight_passes && search_copies == weight_passes); +} static void VKAPI_CALL bind_sets(VkCommandBuffer c, VkPipelineBindPoint b, VkPipelineLayout l, uint32_t f, uint32_t n, const VkDescriptorSet *s, uint32_t nd, const uint32_t *d) {} static void VKAPI_CALL push(VkCommandBuffer c, VkPipelineLayout l, VkShaderStageFlags s, uint32_t o, @@ -77,13 +82,45 @@ static void VKAPI_CALL end_pass(VkCommandBuffer c) {} static void VKAPI_CALL blit(VkCommandBuffer c, VkImage a, VkImageLayout al, VkImage b, VkImageLayout bl, uint32_t n, const VkImageBlit *r, VkFilter f) {} -static void check_generated_settings_and_layout(void) { +static void VKAPI_CALL copy_table(VkCommandBuffer c, VkBuffer b, VkImage i, VkImageLayout l, + uint32_t n, const VkBufferImageCopy *r) { + assert(i == g_smaa_area.img || i == g_smaa_search.img); + if (i == g_smaa_area.img) area_copies++; + else search_copies++; +} + +static void record_into_stubs(void) { g_vk.CmdPipelineBarrier = pipeline_barrier; g_vk.CmdBeginRenderPass = begin_pass; g_vk.CmdSetViewport = viewport; g_vk.CmdSetScissor = scissor; g_vk.CmdBindPipeline = bind_pipeline; g_vk.CmdBindDescriptorSets = bind_sets; g_vk.CmdPushConstants = push; g_vk.CmdDraw = draw; g_vk.CmdEndRenderPass = end_pass; g_vk.CmdBlitImage = blit; + g_vk.CmdCopyBufferToImage = copy_table; +} + +static void check_smaa_tables(void) { + record_into_stubs(); + g_rp = g_smaa_edge_rp = g_smaa_weights_rp = (VkRenderPass)(uintptr_t)5; + for (int k = P_FXAA; k <= P_SMAA_BLEND; k++) g_pipe[k] = (VkPipeline)(uintptr_t)(60 + k); + g_smaa_buf = (VkBuffer)(uintptr_t)7; + g_smaa_area.img = (VkImage)(uintptr_t)40; + g_smaa_search.img = (VkImage)(uintptr_t)41; + g_ready = 1; + struct fx_target *targets[] = {&g_t[0], &g_smaa_edges, &g_smaa_weights}; + for (int k = 0; k < 3; k++) { + targets[k]->img = (VkImage)(uintptr_t)(30 + k); targets[k]->w = 1280; targets[k]->h = 720; + } + vkp_effects_set_screen(0, 0, 1, 100, 2, 0, 0, 0); + for (unsigned frame = 1; frame <= 2; frame++) { + int w, h; + assert(vkp_effects_run(VK_NULL_HANDLE, (VkImage)(uintptr_t)10, 1280, 720, 1280, 720, &w, &h) == g_t[0].img); + assert(weight_passes == frame && area_copies == frame && search_copies == frame); + } +} + +static void check_generated_settings_and_layout(void) { + record_into_stubs(); g_rp = (VkRenderPass)(uintptr_t)5; g_pipe[P_SGSR] = (VkPipeline)(uintptr_t)6; g_pipe[P_COLOR] = (VkPipeline)(uintptr_t)7; @@ -93,7 +130,7 @@ static void check_generated_settings_and_layout(void) { t->img = (VkImage)(uintptr_t)(30 + k); t->w = 1920; t->h = 1080; } vkp_effects_set_scaling(3); - assert(vkp_effects_prepare_generated()); + assert(vkp_effects_prepare_generated(1280, 720, 1920, 1080)); vkp_effects_set_scaling(0); vkp_effects_set_cas(1, 75); vkp_effects_sync(); @@ -153,6 +190,8 @@ int main(int argc, char **argv) { VkImageView original = bound_view; if (!strcmp(argv[1], "generated-layout")) { check_generated_settings_and_layout(); + } else if (!strcmp(argv[1], "smaa-tables")) { + check_smaa_tables(); } else if (!strcmp(argv[1], "generated")) { for (int k = 1; k < FX_CONTEXTS; k++) { g_context = k; diff --git a/tools/tests/test_anticheat_routing.py b/tools/tests/test_anticheat_routing.py new file mode 100644 index 0000000000..6f3666a464 --- /dev/null +++ b/tools/tests/test_anticheat_routing.py @@ -0,0 +1,245 @@ +import json +import os +from pathlib import Path +import runpy +import subprocess +import tempfile +import unittest + + +BIN = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin" +COMPAT = runpy.run_path(str(BIN / "steam-compatibility"), run_name="steam_compatibility") +SETUP = COMPAT["DD_ANTICHEAT_SETUP"] + + +class AntiCheatRoutingTest(unittest.TestCase): + def setUp(self): + temp = tempfile.TemporaryDirectory() + self.addCleanup(temp.cleanup) + self.root = Path(temp.name) + self.steam = self.root / "Steam" + self.common = self.steam / "steamapps" / "common" + self.tools = self.steam / "compatibilitytools.d" + self.game = self.common / "Some Game" + self.game.mkdir(parents=True) + self.tools.mkdir(parents=True) + self.record = self.root / "record.json" + self.fex = self.root / "droiddeck-fex" + self.fex.write_text("#!/bin/bash\nif [ \"$1\" = update ]; then echo \"$1\" >> \"$DD_RECORD.update\"; " + "[ -n \"${DD_UPDATED_PATCHES:-}\" ] && printf '%s\\n' \"$DD_UPDATED_PATCHES\" > \"$DD_PATCHES\"; exit 0; fi\n" + "python3 -c 'import json,os,sys; json.dump({\"argv\": sys.argv[2:], " + "\"eac\": os.environ.get(\"PROTON_EAC_RUNTIME\"), \"be\": os.environ.get(\"PROTON_BATTLEYE_RUNTIME\")}, " + "open(sys.argv[1], \"w\"))' \"$DD_RECORD\" \"$@\"\n") + self.fex.chmod(0o755) + self.patches = self.root / "fex-patches" + self.patches.write_text("openat2-enosys-fallback\nfixed-guest-memory-above-host-address-limit\n") + + def tool(self, name, x86_64=True): + tool = self.tools / name + (tool / "files" / "lib" / "wine" / ("x86_64-unix" if x86_64 else "aarch64-unix")).mkdir(parents=True) + if not x86_64: + (tool / "files" / "bin-arm64").mkdir() + (tool / "proton").write_text("#!/bin/sh\n") + (tool / "proton").chmod(0o755) + return tool + + def runtime(self, name, library): + folder = self.common / name / "v2" / "lib64" + folder.mkdir(parents=True) + (folder / library).write_text("") + return self.common / name + + def file(self, relative): + path = self.game / relative + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text("{}") + + def launch(self, verb="waitforexitandrun", extra=None): + script = SETUP.replace("/usr/local/bin/droiddeck-fex", str(self.fex)).replace( + "/usr/local/share/fex-emu/.droiddeck-patches", str(self.patches)) + ( + "dd_game_cpus() { :; }\n" + "verb=$1; shift\n" + "dd_anticheat \"$@\"\n" + "echo stayed\n") + env = {"PATH": os.environ["PATH"], "HOME": str(self.root), "DD_RECORD": str(self.record), "DD_PATCHES": str(self.patches), + "STEAM_COMPAT_INSTALL_PATH": str(self.game), "STEAM_COMPAT_CLIENT_INSTALL_PATH": str(self.steam)} + env.update(extra or {}) + result = subprocess.run(["bash", "-c", script, "launcher", verb, str(self.game / "game.exe")], + env=env, capture_output=True, text=True, timeout=30) + routed = json.loads(self.record.read_text()) if self.record.exists() else None + return result, routed + + def test_eos_easy_anti_cheat_runs_the_newest_x86_64_build_under_fex(self): + self.file("EasyAntiCheat/Settings.json") + self.tool("DroidDeck-Proton-11.0-1-x86_64") + newest = self.tool("DroidDeck-Proton-11.0-10-x86_64") + self.tool("DroidDeck-Proton-11.0-20", x86_64=False) + runtime = self.runtime("Proton EasyAntiCheat Runtime", "easyanticheat_x64.so") + result, routed = self.launch() + self.assertNotIn("stayed", result.stdout) + self.assertEqual(routed["argv"], ["proton", str(newest / "proton"), "waitforexitandrun", str(self.game / "game.exe")]) + self.assertEqual(routed["eac"], str(runtime)) + self.assertIn("running DroidDeck-Proton-11.0-10-x86_64 under FEX", result.stderr) + + def test_battleye_sets_its_own_runtime(self): + self.file("BattlEye/BEClient_x64.so") + tool = self.tool("DroidDeck-Proton-11.0-1-x86_64") + runtime = self.runtime("Proton BattlEye Runtime", "beclient_x64.so") + _, routed = self.launch() + self.assertEqual((routed["argv"][1], routed["be"], routed["eac"]), (str(tool / "proton"), str(runtime), None)) + + def test_anti_cheat_in_an_unreal_binaries_folder_is_found(self): + for found in ("Project/Binaries/Win64/BattlEye/BEService_x64.exe", "Project/Binaries/Win64/EasyAntiCheat/Settings.json"): + with self.subTest(found=found): + self.setUp() + self.file(found) + tool = self.tool("DroidDeck-Proton-11.0-1-x86_64") + self.runtime("Proton BattlEye Runtime", "beclient_x64.so") + self.runtime("Proton EasyAntiCheat Runtime", "easyanticheat_x64.so") + _, routed = self.launch() + self.assertEqual(routed["argv"][1], str(tool / "proton")) + + def test_a_game_with_both_kinds_uses_whichever_runtime_is_installed(self): + for installed, key in (("Proton BattlEye Runtime", "be"), ("Proton EasyAntiCheat Runtime", "eac")): + with self.subTest(installed=installed): + self.setUp() + self.file("BattlEye/BEService_x64.exe") + self.file("Project/Binaries/Win64/EasyAntiCheat/Settings.json") + tool = self.tool("DroidDeck-Proton-11.0-1-x86_64") + runtime = self.runtime(installed, "beclient_x64.so" if key == "be" else "easyanticheat_x64.so") + _, routed = self.launch() + self.assertEqual((routed["argv"][1], routed[key]), (str(tool / "proton"), str(runtime))) + + def test_a_runtime_already_set_with_files_is_kept(self): + self.file("EasyAntiCheat/Settings.json") + self.tool("DroidDeck-Proton-11.0-1-x86_64") + own = self.root / "own-eac" + (own / "v2").mkdir(parents=True) + (own / "v2" / "easyanticheat_x64.so").write_text("") + _, routed = self.launch(extra={"PROTON_EAC_RUNTIME": str(own)}) + self.assertEqual(routed["eac"], str(own)) + + def test_games_without_anti_cheat_files_stay_on_arm64(self): + self.file("Data/Settings.json") + self.tool("DroidDeck-Proton-11.0-1-x86_64") + self.runtime("Proton EasyAntiCheat Runtime", "easyanticheat_x64.so") + result, routed = self.launch() + self.assertIsNone(routed) + self.assertIn("stayed", result.stdout) + self.assertEqual(result.stderr, "") + + def test_without_an_x86_64_build_the_launch_stays_on_arm64(self): + self.file("EasyAntiCheat/Settings.json") + self.tool("DroidDeck-Proton-11.0-20", x86_64=False) + self.runtime("Proton EasyAntiCheat Runtime", "easyanticheat_x64.so") + result, routed = self.launch() + self.assertIsNone(routed) + self.assertIn("stayed", result.stdout) + self.assertIn("no x86-64 DroidDeck-Proton is installed", result.stderr) + + def test_without_the_runtime_files_the_launch_stays_on_arm64(self): + self.file("EasyAntiCheat/Settings.json") + self.tool("DroidDeck-Proton-11.0-1-x86_64") + (self.common / "Proton EasyAntiCheat Runtime").mkdir(parents=True) + result, routed = self.launch() + self.assertIsNone(routed) + self.assertIn("its Proton runtime is not installed", result.stderr) + + def test_the_user_can_turn_routing_off(self): + self.file("EasyAntiCheat/Settings.json") + self.tool("DroidDeck-Proton-11.0-1-x86_64") + self.runtime("Proton EasyAntiCheat Runtime", "easyanticheat_x64.so") + result, routed = self.launch(extra={"DROIDDECK_ANTICHEAT": "off"}) + self.assertIsNone(routed) + self.assertIn("stayed", result.stdout) + + def test_a_tool_the_user_chose_is_kept(self): + self.file("EasyAntiCheat/Settings.json") + self.tool("DroidDeck-Proton-11.0-1-x86_64") + self.runtime("Proton EasyAntiCheat Runtime", "easyanticheat_x64.so") + for chosen in ("GE-Proton11-15-aarch64", "DroidDeck-Bionic-14.1-r85", "proton_experimental"): + result, routed = self.launch(extra={"DD_AC_TOOL": chosen}) + self.assertIsNone(routed) + self.assertIn("stayed", result.stdout) + self.assertIn("%s was chosen for this game, so it runs as chosen" % chosen, result.stderr) + + def test_droiddeck_proton_builds_still_route(self): + self.file("EasyAntiCheat/Settings.json") + newest = self.tool("DroidDeck-Proton-11.0-1-x86_64") + self.runtime("Proton EasyAntiCheat Runtime", "easyanticheat_x64.so") + for own in ("DroidDeck-Proton 11-14.1", "DroidDeck-Proton-11-14.2"): + self.record.unlink(missing_ok=True) + result, routed = self.launch(extra={"DD_AC_TOOL": own}) + self.assertEqual(routed["argv"][1], str(newest / "proton")) + + def test_a_fex_build_without_high_guest_memory_stays_on_arm64(self): + self.file("EasyAntiCheat/Settings.json") + self.tool("DroidDeck-Proton-11.0-1-x86_64") + self.runtime("Proton EasyAntiCheat Runtime", "easyanticheat_x64.so") + for patches in ("openat2-enosys-fallback\n", None): + if patches is None: + self.patches.unlink() + else: + self.patches.write_text(patches) + result, routed = self.launch() + self.assertIsNone(routed) + self.assertIn("stayed", result.stdout) + self.assertIn("the installed FEX build cannot run anti-cheat", result.stderr) + + def test_an_older_fex_build_is_updated_before_routing(self): + self.file("EasyAntiCheat/Settings.json") + tool = self.tool("DroidDeck-Proton-11.0-1-x86_64") + self.runtime("Proton EasyAntiCheat Runtime", "easyanticheat_x64.so") + self.patches.unlink() + result, routed = self.launch(extra={"DD_UPDATED_PATCHES": "fixed-guest-memory-above-host-address-limit"}) + self.assertEqual(routed["argv"][1], str(tool / "proton")) + self.assertNotIn("cannot run anti-cheat", result.stderr) + self.assertTrue((self.root / "record.json.update").exists()) + + def test_games_without_anti_cheat_files_do_not_update_fex(self): + self.file("Data/Settings.json") + self.launch() + self.assertFalse((self.root / "record.json.update").exists()) + + def test_choices_are_kept_the_same_with_an_older_fex_build(self): + self.file("EasyAntiCheat/Settings.json") + self.tool("DroidDeck-Proton-11.0-1-x86_64") + self.runtime("Proton EasyAntiCheat Runtime", "easyanticheat_x64.so") + self.patches.unlink() + result, routed = self.launch(extra={"DD_AC_TOOL": "GE-Proton11-15-aarch64"}) + self.assertIsNone(routed) + self.assertIn("GE-Proton11-15-aarch64 was chosen for this game, so it runs as chosen", result.stderr) + result, routed = self.launch(extra={"DROIDDECK_ANTICHEAT": "off"}) + self.assertIsNone(routed) + self.assertEqual(result.stderr, "") + + def test_the_fex_build_lists_its_patches(self): + build = (BIN.parents[4] / "fex" / "build-in-arch.sh").read_text() + self.assertIn("> out/usr/local/share/fex-emu/.droiddeck-patches", build) + names = {p.stem.split("-", 1)[1] for p in (BIN.parents[4] / "fex" / "patches").glob("*.patch")} + self.assertIn("fixed-guest-memory-above-host-address-limit", names) + + def test_adopted_tools_pass_their_own_folder_name(self): + wrapper = COMPAT["extra_wrapper_sh"]("proton") + self.assertIn('DD_AC_TOOL=$(basename "$(cd "$here" && pwd -P)") dd_anticheat "$@"', wrapper) + self.assertNotIn("DD_AC_TOOL=", COMPAT["LAUNCHER_SH"]) + + def test_other_verbs_are_left_alone(self): + self.file("EasyAntiCheat/Settings.json") + self.tool("DroidDeck-Proton-11.0-1-x86_64") + self.runtime("Proton EasyAntiCheat Runtime", "easyanticheat_x64.so") + result, routed = self.launch(verb="getcompatpath") + self.assertIsNone(routed) + self.assertIn("stayed", result.stdout) + + def test_launchers_check_before_arm64_setup_and_x86_64_tools_run_under_fex(self): + launcher = COMPAT["LAUNCHER_SH"] + self.assertLess(launcher.index('dd_anticheat "$@"'), launcher.index('dd_components "$depot"')) + wrapper = COMPAT["extra_wrapper_sh"]("proton") + self.assertLess(wrapper.index("dd_x86_64_proton() {"), wrapper.index("dd_fallback=")) + self.assertLess(wrapper.index('droiddeck-fex proton "$here/proton"'), wrapper.index('dd_components "$here"')) + self.assertIn('! dd_x86_64_proton "$d"', wrapper) + + +if __name__ == "__main__": + unittest.main() diff --git a/tools/tests/test_decky_loader_env.py b/tools/tests/test_decky_loader_env.py new file mode 100644 index 0000000000..dbd6c4ec24 --- /dev/null +++ b/tools/tests/test_decky_loader_env.py @@ -0,0 +1,58 @@ +import os +import re +import shlex +import subprocess +import tempfile +import unittest +from pathlib import Path + +SESSION = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin/droiddeck-session" + + +def decky_job(): + match = re.search(r"^ *_dd_job_decky\(\) \{\n.*?^ {8}\}\n", SESSION.read_text(), re.M | re.S) + return match.group(0) if match else None + + +class DeckyLoaderEnvironmentTest(unittest.TestCase): + def setUp(self): + self.temp = tempfile.TemporaryDirectory() + self.addCleanup(self.temp.cleanup) + self.root = Path(self.temp.name) + (self.root / "homebrew/services").mkdir(parents=True) + + def loader_environment(self, inherited=None): + job = decky_job() + self.assertIsNotNone(job, "droiddeck-session has no _dd_job_decky()") + seen = self.root / "seen.env" + loader = self.root / "PluginLoader" + loader.write_text("#!/bin/sh\nenv > %s\nexit 1\n" % shlex.quote(str(seen))) + loader.chmod(0o755) + script = "sleep() { :; }\n" + job + script += "decky_arch=arm64\ndecky_loader=%s\n_dd_job_decky\n" % shlex.quote(str(loader)) + env = {"PATH": os.environ.get("PATH", "/usr/bin:/bin"), "HOME": str(self.root)} + env.update(inherited or {}) + out = subprocess.run(["bash", "-c", script], capture_output=True, text=True, timeout=30, env=env, check=True).stdout + self.assertIn("stopped after 5 loader exits", out) + return dict(line.split("=", 1) for line in seen.read_text().splitlines() if "=" in line) + + def test_the_loader_runs_without_its_file_watcher(self): + self.assertEqual("0", self.loader_environment().get("LIVE_RELOAD")) + + def test_a_live_reload_from_the_session_environment_does_not_reach_the_loader(self): + self.assertEqual("0", self.loader_environment({"LIVE_RELOAD": "1"}).get("LIVE_RELOAD")) + + def test_the_loader_still_runs_as_root_and_keeps_its_plugin_permission_fixes(self): + env = self.loader_environment() + self.assertEqual("root", env.get("UNPRIVILEGED_USER")) + self.assertNotIn("CHOWN_PLUGIN_PATH", env) + + def test_only_the_decky_job_sets_live_reload(self): + text = SESSION.read_text() + job = decky_job() + self.assertEqual(1, text.count("LIVE_RELOAD")) + self.assertIn("export LIVE_RELOAD=0", job) + + +if __name__ == "__main__": + unittest.main() diff --git a/tools/tests/test_droiddeck_fex.py b/tools/tests/test_droiddeck_fex.py index 79f7043cbb..5bd2596b88 100644 --- a/tools/tests/test_droiddeck_fex.py +++ b/tools/tests/test_droiddeck_fex.py @@ -1235,6 +1235,29 @@ class LaunchTest(FexTestCase): self.assertEqual(emulated.call_args[0][2]["FEX_ROOTFS"], str(platform / "files")) self.assertEqual(FEX["required_runtime"](str(self.proton("1391110"))), "1628350") + def test_an_adopted_proton_keeps_the_runtime_of_its_original_manifest(self): + proton = self.proton("4183110") + folder = proton.parent + os.rename(folder / "toolmanifest.vdf", folder / "toolmanifest.vdf.droiddeck-orig") + self.write(folder / "toolmanifest.vdf", '"manifest"\n{\n "commandline" "/droiddeck-proton-wrap %verb%"\n}\n') + self.assertEqual(FEX["required_runtime"](str(proton)), "4183110") + os.unlink(folder / "toolmanifest.vdf.droiddeck-orig") + self.assertEqual(FEX["required_runtime"](str(proton)), "1628350") + + def test_proton_action_keeps_the_prefix_and_runs_under_fex(self): + self.fex_tool() + self.runtime() + proton = self.proton("1628350") + prefix = str(self.tmp / "compatdata" / "730") + env = {"STEAM_COMPAT_DATA_PATH": prefix} + with mock.patch.dict(os.environ, env, clear=False), mock.patch("os.execve") as emulated: + self.quiet(FEX["main"], ["proton", str(proton), "waitforexitandrun", "game.exe"]) + command, guest = emulated.call_args[0][1], emulated.call_args[0][2] + self.assertEqual(command[1:], [str(proton), "waitforexitandrun", "game.exe"]) + self.assertEqual(guest["STEAM_COMPAT_DATA_PATH"], prefix) + self.assertNotEqual(FEX["guest_environment"]({"portable": True}, env)["STEAM_COMPAT_DATA_PATH"], prefix) + self.assertEqual(FEX["main"](["proton", str(proton)]), 2) + def test_native_programs_run_directly(self): program = self.write(self.tmp / "native", elf(183), 0o755) with mock.patch("os.execvpe") as native, mock.patch("os.execve") as emulated: @@ -1351,6 +1374,48 @@ class LaunchTest(FexTestCase): self.assertEqual(started(unity, "10")[:2], ("1", None)) self.assertEqual(started(other, "10")[:2], (None, None)) + def test_x86_64_proton_launches_keep_the_game_debug_and_graphics_logs(self): + config = self.home / ".config/droiddeck/game-environment.json" + session = self.tmp / "session" + session.mkdir() + proton = str(self.tmp / "Proton x86-64/proton") + + def started(verb, debug, extra=None): + self.write(config, json.dumps({"version": 1, "gameDebugLogs": debug, + "games": {"976730": {"DXVK_HUD": "fps"}}})) + env = {"SteamAppId": "976730", "SteamGameId": "976730", "DD_DEBUG_DIR": str(session), **(extra or {})} + with mock.patch.dict(G, {"launch": mock.Mock(return_value=0), "GAME_ENVIRONMENT": str(config)}), \ + mock.patch.dict(os.environ, env, clear=True), mock.patch("subprocess.Popen") as capped: + _, said = self.quiet(FEX["main"], ["proton", proton, verb, "C:/game/game.exe"]) + command, guest, mode = G["launch"].call_args[0] + self.assertEqual((command, mode), ([proton, verb, "C:/game/game.exe"], "on")) + return guest, said, capped + + guest, said, capped = started("waitforexitandrun", True) + self.assertEqual((guest["PROTON_LOG"], guest["PROTON_LOG_DIR"]), ("1", str(session))) + self.assertIn("+seh", guest["WINEDEBUG"]) + self.assertEqual(guest["DXVK_HUD"], "fps") + self.assertIn("game debug logs enabled for this launch", said) + self.assertIn(str(session / "steam-976730.log"), capped.call_args[0][0]) + + guest, said, _ = started("waitforexitandrun", False, {"DD_GAME_LOGS": "1"}) + folder = Path(guest["PROTON_LOG_DIR"]) + self.assertEqual((guest["PROTON_LOG"], folder.parent), ("1", session / "games")) + self.assertTrue(folder.name.endswith("-976730")) + self.assertNotIn("game debug logs enabled", said) + + guest, _, capped = started("waitforexitandrun", False) + self.assertNotIn("PROTON_LOG", guest) + self.assertEqual(guest["DXVK_HUD"], "fps") + capped.assert_not_called() + + guest, _, capped = started("run", True) + self.assertNotIn("PROTON_LOG", guest) + capped.assert_not_called() + + guest, _, _ = started("waitforexitandrun", True, {"PROTON_LOG": "1", "PROTON_LOG_DIR": "/mine"}) + self.assertEqual(guest["PROTON_LOG_DIR"], str(session)) + class AppInfoTest(unittest.TestCase): COMPAT = runpy.run_path(str(BIN / "steam-compatibility")) diff --git a/tools/tests/test_droiddeck_proton_default.py b/tools/tests/test_droiddeck_proton_default.py index 2173a223a1..194bf022c9 100644 --- a/tools/tests/test_droiddeck_proton_default.py +++ b/tools/tests/test_droiddeck_proton_default.py @@ -15,6 +15,8 @@ VALVE_11 = {"name": COMPAT["TOOL_11"], "display": "Proton 11.0 ARM64", "dir": CO GE = {"name": "GE-Proton11-7", "display": "GE-Proton11-7", "dir": "GE-Proton11-7", "valve": False} GE10 = {"name": "GE-Proton10-3", "display": "GE-Proton10-3", "dir": "GE-Proton10-3", "valve": False} NEWER = {"name": "DroidDeck-Proton-11-12.1", "display": "DroidDeck-Proton 11-12.1", "dir": "DroidDeck-Proton 11-12.1", "valve": False} +X86 = {"name": "DroidDeck-Proton-11-14.2-x86_64", "display": "DroidDeck-Proton 11-14.2 x86-64", "dir": "DroidDeck-Proton 11-14.2 x86-64", + "valve": False, "x86_64": True} def config_text(entries): @@ -204,6 +206,50 @@ class DroidDeckProtonDefaultTest(unittest.TestCase): self.assertEqual(newest, "b") self.assertEqual(gone, {OLD["name"]}) + def test_an_x86_64_build_never_becomes_the_automatic_default(self): + default, mapping, state = self.run_default( + {"default": TOOL, "auto": {"42": TOOL}}, [("0", TOOL), ("42", TOOL)], [VALVE, NEW, X86], ["42"]) + self.assertEqual((default, mapping["0"]), (NEW["name"], NEW["name"])) + default, mapping, _ = self.run_default({"default": TOOL}, [("0", TOOL)], [VALVE, X86]) + self.assertEqual((default, mapping), (TOOL, {"0": TOOL})) + + def test_an_automatic_x86_64_default_moves_back_to_arm64(self): + default, mapping, state = self.run_default( + {"default": X86["name"], "written": X86["name"], "source": "update"}, [("0", X86["name"])], [VALVE, NEW, X86]) + self.assertEqual((default, mapping, state["source"]), (NEW["name"], {"0": NEW["name"]}, "update")) + default, mapping, _ = self.run_default( + {"default": X86["name"], "written": X86["name"], "source": "update"}, [("0", X86["name"])], [VALVE, X86]) + self.assertEqual((default, mapping), (TOOL, {"0": TOOL})) + + def test_an_x86_64_default_the_user_picked_is_kept(self): + for source in ("app", "steam"): + default, mapping, _ = self.run_default( + {"default": X86["name"], "written": X86["name"], "source": source}, [("0", X86["name"])], [VALVE, NEW, X86]) + self.assertEqual((default, mapping), (X86["name"], {"0": X86["name"]})) + + def test_a_request_for_the_automatic_x86_64_default_keeps_it(self): + default, mapping, state = self.run_default( + {"default": X86["name"], "written": X86["name"], "source": "update", "applied": 1}, [("0", X86["name"])], + [VALVE, NEW, X86], request={"seq": 2, "name": X86["name"]}) + self.assertEqual((default, mapping, state["source"]), (X86["name"], {"0": X86["name"]}, "app")) + default, mapping, state = self.run_default(state, [("0", X86["name"])], [VALVE, NEW, X86], + request={"seq": 2, "name": X86["name"]}) + self.assertEqual((default, mapping, state["source"]), (X86["name"], {"0": X86["name"]}, "app")) + + def test_x86_64_layouts_are_marked_in_the_catalog(self): + with tempfile.TemporaryDirectory() as tmp: + tools = Path(tmp) / "compatibilitytools.d" + for entry, arm in (("DroidDeck-Proton 11-14.2 x86-64", False), ("DroidDeck-Proton 11-14.2", True)): + (tools / entry / "files" / "lib" / "wine" / ("aarch64-unix" if arm else "x86_64-unix")).mkdir(parents=True) + if arm: + (tools / entry / "files" / "bin-arm64").mkdir() + (tools / entry / COMPAT["EXTRA_WRAPPER"]).write_text("") + catalog = {t["dir"]: t for t in COMPAT["tool_catalog"](tmp) if not t["valve"]} + self.assertTrue(catalog["DroidDeck-Proton 11-14.2 x86-64"].get("x86_64")) + self.assertNotIn("x86_64", catalog["DroidDeck-Proton 11-14.2"]) + newest, _ = COMPAT["own_proton_moves"]({}, list(catalog.values())) + self.assertEqual(newest, catalog["DroidDeck-Proton 11-14.2"]["name"]) + if __name__ == "__main__": unittest.main() diff --git a/tools/tests/test_droiddeckctl.py b/tools/tests/test_droiddeckctl.py index 8a15ec92a3..4873d13ce5 100644 --- a/tools/tests/test_droiddeckctl.py +++ b/tools/tests/test_droiddeckctl.py @@ -522,7 +522,9 @@ class DroiddeckctlTest(FakeAdbTest): answer = ctl.provider_call("adb", "fake-1", "state", arg="a b", request={"x": 1}) self.assertEqual({"ok": True, "command": "state"}, answer) broadcast = next(c for c in calls if c[:2] == ("shell", "am")) - self.assertEqual(("shell", "am", "broadcast", "-a", ctl.PACKAGE + ".AGENT_CALL", "-p", ctl.PACKAGE), broadcast[:7]) + receiver = ctl.PACKAGE + "/com.droiddeck.launcher.agent.AgentCallReceiver" + self.assertEqual(("shell", "am", "broadcast", "-n", receiver), broadcast[:5]) + self.assertNotIn("-a", broadcast) self.assertIn("'a b'", broadcast) self.assertEqual(ctl.encode_request({"x": 1}), broadcast[broadcast.index("request") + 1]) call_id = broadcast[broadcast.index("id") + 1] diff --git a/tools/tests/test_effects_source_cache.py b/tools/tests/test_effects_source_cache.py index 163bef4bb6..ba80771818 100644 --- a/tools/tests/test_effects_source_cache.py +++ b/tools/tests/test_effects_source_cache.py @@ -63,6 +63,9 @@ class EffectsSourceCacheTest(unittest.TestCase): def test_generated_settings_snapshot_and_source_layout_restoration(self): self.check_cache('generated-layout') + def test_every_recorded_frame_fills_the_smaa_tables(self): + self.check_cache('smaa-tables') + if __name__ == '__main__': unittest.main() diff --git a/tools/tests/test_effects_source_resolution.py b/tools/tests/test_effects_source_resolution.py index 38ca6f9f3c..09c9e16f2d 100644 --- a/tools/tests/test_effects_source_resolution.py +++ b/tools/tests/test_effects_source_resolution.py @@ -286,7 +286,8 @@ static VkImage vkp_effects_run(int cmd, int source, int w, int h, int ow, int oh if (fail_effects) { *rw = w; *rh = h; return source; } *rw = ow; *rh = oh; return 4; } -static int vkp_effects_prepare_generated(void) { +static int vkp_effects_prepare_generated(int in_w, int in_h, int out_w, int out_h) { + (void)in_w; (void)in_h; (void)out_w; (void)out_h; return g_cur.scaling >= 3 && g_cur.scaling <= 8 && g_cur.scaling != 6 && !postprocessing; } static VkImage vkp_effects_run_before_generated(int cmd, int source, int w, int h, int *rw, int *rh) { diff --git a/tools/tests/test_fex_guest_high_memory.py b/tools/tests/test_fex_guest_high_memory.py new file mode 100644 index 0000000000..ff21c4adad --- /dev/null +++ b/tools/tests/test_fex_guest_high_memory.py @@ -0,0 +1,3392 @@ +import platform +import re +import shutil +import signal +import subprocess +import tempfile +import unittest +from pathlib import Path + +REPO = Path(__file__).resolve().parents[2] +PATCH = REPO / "tools/fex/patches/0027-fixed-guest-memory-above-host-address-limit.patch" +PROBE = REPO / "tools/fex/probes/guest-high-memory.c" + +SOURCE = "Source/Tools/LinuxEmulation/LinuxSyscalls/GuestHighMemory.cpp" +HEADER = "Source/Tools/LinuxEmulation/LinuxSyscalls/GuestHighMemory.h" + +KERNEL_NAMES = {"pread_64": "pread64", "pwrite_64": "pwrite64", "prlimit_64": "prlimit64"} +NEWER_SYSCALLS = { + "futex_wake": 454, "futex_wait": 455, "futex_requeue": 456, "statmount": 457, "listmount": 458, + "lsm_get_self_attr": 459, "lsm_set_self_attr": 460, "lsm_list_modules": 461, + "mseal": 462, "setxattrat": 463, "getxattrat": 464, "listxattrat": 465, "removexattrat": 466, +} +OLDEST_HEADERS_LAST_SYSCALL = 453 +HARNESS_SECONDS = 120 + +PRELUDE = r""" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +namespace fextl { +template using vector = std::vector; +template using list = std::list; +template using unordered_map = std::unordered_map; +using std::make_unique; +} +namespace FEXCore { +namespace Utils { constexpr uint64_t FEX_PAGE_SIZE = 4096; } +constexpr uint64_t AlignUp(uint64_t V, uint64_t A) { return (V + A - 1) & ~(A - 1); } +namespace Allocator { inline uint64_t GetHostVABits() { return 39; } } +} +""" + +STUBS = r""" +static int MunmapFailures; +static int TestMunmap(void* Address, size_t Size) { + if (MunmapFailures > 0) { + --MunmapFailures; + errno = ENOMEM; + return -1; + } + return munmap(Address, Size); +} +#define munmap TestMunmap +static int SendCalls; +static int SendFailures; +static size_t SendLimit = ~size_t {}; +static int SentSocket = -1; +static size_t SentLengths[8]; +static struct iovec* GrowAfterSend; +static void* UnmapAfterSend; +static bool PassSend; +static int DupFailures; +static int TestSendmmsg(int Socket, struct mmsghdr* Messages, unsigned int Count, int Flags) { + if (PassSend) { + return sendmmsg(Socket, Messages, Count, Flags); + } + SentSocket = Socket; + if (Count != 1 || SendFailures > 0) { + SendFailures -= SendFailures > 0; + errno = EAGAIN; + return -1; + } + size_t Length = 0; + for (size_t i = 0; i < Messages[0].msg_hdr.msg_iovlen; ++i) { + Length += Messages[0].msg_hdr.msg_iov[i].iov_len; + } + Length = std::min(Length, SendLimit); + SentLengths[SendCalls++ & 7] = Length; + Messages[0].msg_len = Length; + if (GrowAfterSend) { + GrowAfterSend->iov_len = 64; + } + if (UnmapAfterSend) { + munmap(UnmapAfterSend, 4096); + UnmapAfterSend = nullptr; + } + return 1; +} +#define sendmmsg TestSendmmsg +static int TestFcntl(int FD, int Command, int Argument = 0) { + if (Command == F_DUPFD_CLOEXEC && DupFailures > 0) { + --DupFailures; + errno = EMFILE; + return -1; + } + return fcntl(FD, Command, Argument); +} +#define fcntl TestFcntl +static int ProtectCalls; +static int TestMprotect(void* Address, size_t Size, int Prot) { + ++ProtectCalls; + return mprotect(Address, Size, Prot); +} +#define mprotect TestMprotect +static uint64_t AioDestroyed; +static std::function AioDestroyHook; +static int AioReaps; +static uint64_t AioReapArgs[7]; +static std::function AioReapHook; +template static uint64_t SyscallWord(T Value) { + if constexpr (std::is_null_pointer_v) { + return 0; + } else if constexpr (std::is_pointer_v) { + return reinterpret_cast(Value); + } else { + return static_cast(Value); + } +} +template static long TestSyscall(long Number, T... Args) { + const uint64_t Words[] = {0, SyscallWord(Args)...}; + if (Number == SYS_io_getevents || Number == SYS_io_pgetevents) { + ++AioReaps; + std::copy_n(Words, std::min(std::size(Words), 7), AioReapArgs); + AioReapArgs[0] = Number; + if (AioReapHook) { + return AioReapHook(Words); + } + errno = EINTR; + return -1; + } + if (Number == SYS_io_destroy) { + AioDestroyed = Words[1]; + if (AioDestroyHook) { + AioDestroyHook(Words[1]); + } + errno = EINVAL; + return -1; + } + return syscall(Number, Args...); +} +#define syscall TestSyscall +namespace FEXCore { +template class LockType = std::unique_lock, typename MutexType> +inline auto MaskSignalsAndLockMutex(MutexType& Mutex, uint64_t = ~0ULL) { return LockType {Mutex}; } +} +namespace ArchHelpers::Context { +inline uint64_t GetArmReg(void* UContext, uint32_t Reg) { return static_cast(UContext)[Reg]; } +inline void SetArmReg(void* UContext, uint32_t Reg, uint64_t Value) { static_cast(UContext)[Reg] = Value; } +} +namespace FEX::HLE { +struct TestVMATracking { std::shared_mutex Mutex; }; +struct TestSyscallHandler { TestVMATracking VMATracking; }; +inline TestSyscallHandler TestHandler; +inline TestSyscallHandler* _SyscallHandler = &TestHandler; +struct TestThreadObject { + struct { + struct { + bool Held; + uint32_t Deferred; + siginfo_t DeferredInfo[3]; + } Mappings; + } HighMemoryTrap; + struct { + std::vector DeferredSignalFrames; + } SignalInfo; +}; +inline TestThreadObject TestThread {}; +struct ThreadManager { + static TestThreadObject* GetCurrentThreadObject() { return &TestThread; } +}; +inline bool HasSyscallError(uint64_t Result) { return Result >= 0xFFFF'FFFF'FFFF'0001ULL; } +namespace FaultSafeUserMemAccess { +inline size_t CopyFromUser(void* Dest, const void* Src, size_t Size) { + struct iovec Local {Dest, Size}; + struct iovec Remote {const_cast(Src), Size}; + return Size == 0 || process_vm_readv(getpid(), &Local, 1, &Remote, 1, 0) == static_cast(Size) ? 0 : Size; +} +inline void (*BeforeUserWrite)() = nullptr; +inline size_t CopyToUser(void* Dest, const void* Src, size_t Size) { + if (auto* Hook = std::exchange(BeforeUserWrite, nullptr)) { + Hook(); + } + struct iovec Local {const_cast(Src), Size}; + struct iovec Remote {Dest, Size}; + return Size == 0 || process_vm_writev(getpid(), &Local, 1, &Remote, 1, 0) == static_cast(Size) ? 0 : Size; +} +} +namespace x64 { +ENUM +} +} +""" + +MAIN = r""" +using namespace FEX::HLE::GuestHighMemory; +namespace Sys = FEX::HLE::x64; +static void Show(const char* Name, uint64_t Value) { std::printf("%s %llx\n", Name, static_cast(Value)); } +struct TestHold { + bool Held; + uint32_t Deferred; + siginfo_t DeferredInfo[3]; +}; +static std::atomic TrapsSeen; +static std::atomic TrapCode; +static std::atomic TrapValue; +static bool ExclusiveFromAnotherThread() { + std::thread Writer([] { std::unique_lock Exclusive {FEX::HLE::_SyscallHandler->VMATracking.Mutex}; }); + Writer.join(); + return true; +} +static void CountTrap(int, siginfo_t* Info, void*) { + ++TrapsSeen; + TrapCode = Info->si_code; + TrapValue = Info->si_value.sival_int; +} +static uint64_t Call(uint32_t Syscall, uint64_t* Args, ArgumentStorage* Storage) { return TranslateSyscallArguments(Syscall, Args, 6, Storage); } +template +static uint64_t FinishResult(uint64_t Result, Arguments* Storage) { + if constexpr (std::is_void_v) { + FinishSyscallArguments(Result, Storage); + return Result; + } else { + return FinishSyscallArguments(Result, Storage); + } +} +int main() { + alarm(HARNESS_SECONDS); + const uint64_t Page = 4096; + static bool FirstHighStoreHeld; + FEX::HLE::FaultSafeUserMemAccess::BeforeUserWrite = [] { FirstHighStoreHeld = FEX::HLE::TestThread.HighMemoryTrap.Mappings.Held; }; + const uint32_t FirstHighValue = 1; + Show("high_store_unmapped_result", CopyToGuest(0x720000000000ULL, &FirstHighValue, sizeof(FirstHighValue))); + Show("high_store_unmapped_held", FirstHighStoreHeld); + Show("high_store_unmapped_released", FEX::HLE::TestThread.HighMemoryTrap.Mappings.Held); + const uint64_t High = TaskTop - Page; + const uint64_t Low = 0x140000000ULL; + Show("contains_last_page", Contains(High)); + Show("contains_task_top", Contains(TaskTop)); + Show("contains_host_limit", Contains(1ULL << 39)); + Show("contains_below_limit", Contains((1ULL << 39) - Page)); + Show("claims_fixed", ClaimsMapping(High, Page, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED)); + Show("claims_noreplace", ClaimsMapping(High, Page, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED_NOREPLACE)); + Show("claims_low", ClaimsMapping(Low, Page, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED)); + Show("claims_hint", ClaimsMapping(High, Page, MAP_PRIVATE | MAP_ANONYMOUS)); + Show("claims_task_top", ClaimsMapping(TaskTop, Page, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED)); + + auto* Backing = static_cast(mmap(nullptr, 8 * Page, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)); + const uint64_t Base = reinterpret_cast(Backing); + const uint64_t Single = 0x7f0000000000ULL; + const uint64_t Split = 0x7e0000000000ULL; + const uint64_t Joined = 0x7d0000000000ULL; + AddEntry(Single, Page, Base, false, PROT_READ | PROT_WRITE); + AddEntry(Split, Page, Base + 2 * Page, false, PROT_READ | PROT_WRITE); + AddEntry(Split + Page, Page, Base + 4 * Page, false, PROT_READ | PROT_WRITE); + AddEntry(Joined, Page, Base + 5 * Page, false, PROT_READ | PROT_WRITE); + AddEntry(Joined + Page, Page, Base + 6 * Page, false, PROT_READ | PROT_WRITE); + ArgumentStorage Storage; + const int Peer = socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0); + + uint64_t Read[6] = {3, Single + 16, 32, 0, 0, 0}; + Show("read_result", Call(Sys::SYSCALL_x64_read, Read, &Storage)); + Show("read_buffer", Read[1] - Base); + + uint64_t Truncate[6] = {3, Single + 16, 0, 0, 0, 0}; + Show("ftruncate_result", Call(Sys::SYSCALL_x64_ftruncate, Truncate, &Storage)); + Show("ftruncate_length", Truncate[1] - Single); + + uint64_t Mapping[6] = {Single, Page, 0, 0, 0, 0}; + Show("mmap_result", Call(Sys::SYSCALL_x64_mmap, Mapping, &Storage)); + Show("mmap_address", Mapping[0] - Single); + + uint64_t Unknown[6] = {Single, Single, Single, Single, Single, Single}; + Show("unknown_result", Call(1000, Unknown, &Storage)); + Show("unknown_args", Unknown[0] - Single + Unknown[5] - Single); + + uint64_t Overrun[6] = {3, Single + Page - 8, 64, 0, 0, 0}; + Show("overrun_result", Call(Sys::SYSCALL_x64_read, Overrun, &Storage)); + + uint64_t Apart[6] = {3, Split + Page - 96, 200, 0, 0, 0}; + Show("split_result", Call(Sys::SYSCALL_x64_read, Apart, &Storage)); + + uint64_t Together[6] = {3, Joined + Page - 96, 200, 0, 0, 0}; + Show("joined_result", Call(Sys::SYSCALL_x64_read, Together, &Storage)); + Show("joined_buffer", Together[1] - Base); + + uint64_t Write[6] = {3, Split + Page - 96, 96, 0, 0, 0}; + Show("fits_result", Call(Sys::SYSCALL_x64_write, Write, &Storage)); + + uint64_t PollApart[6] = {Split + Page - 96, 25, 0, 0, 0, 0}; + Show("poll_split_result", Call(Sys::SYSCALL_x64_poll, PollApart, &Storage)); + uint64_t PollFits[6] = {Split + Page - 96, 12, 0, 0, 0, 0}; + Show("poll_fits_result", Call(Sys::SYSCALL_x64_poll, PollFits, &Storage)); + uint64_t PollJoined[6] = {Joined + Page - 96, 25, 0, 0, 0, 0}; + Show("poll_joined_result", Call(Sys::SYSCALL_x64_poll, PollJoined, &Storage)); + uint64_t PollHuge[6] = {Single, 1ULL << 61, 0, 0, 0, 0}; + Show("poll_huge_result", Call(Sys::SYSCALL_x64_poll, PollHuge, &Storage)); + uint64_t EpollApart[6] = {3, Split + Page - 96, 9, 0, 0, 0}; + Show("epoll_split_result", Call(Sys::SYSCALL_x64_epoll_wait, EpollApart, &Storage)); + uint64_t EpollFits[6] = {3, Split + Page - 96, 8, 0, 0, 0}; + Show("epoll_fits_result", Call(Sys::SYSCALL_x64_epoll_wait, EpollFits, &Storage)); + uint64_t SelectApart[6] = {1024, Split + Page - 64, 0, 0, 0, 0}; + Show("select_split_result", Call(Sys::SYSCALL_x64_select, SelectApart, &Storage)); + uint64_t SelectFits[6] = {512, Split + Page - 64, 0, 0, 0, 0}; + Show("select_fits_result", Call(Sys::SYSCALL_x64_select, SelectFits, &Storage)); + uint64_t SelectWide[6] = {(1ULL << 32) + 1, Single, 0, 0, 0, 0}; + Show("select_wide_result", Call(Sys::SYSCALL_x64_select, SelectWide, &Storage)); + Show("fits_buffer", Write[1] - Base); + + char LowBuffer[16]; + struct iovec Guest[2] = {{reinterpret_cast(Single + 64), 32}, {LowBuffer, sizeof(LowBuffer)}}; + uint64_t Vector[6] = {3, reinterpret_cast(Guest), 2, 0, 0, 0}; + Show("readv_result", Call(Sys::SYSCALL_x64_readv, Vector, &Storage)); + const auto* HostVector = reinterpret_cast(Vector[1]); + Show("readv_copied", HostVector != Guest); + Show("readv_high_base", reinterpret_cast(HostVector[0].iov_base) - Base); + Show("readv_low_base", HostVector[1].iov_base == LowBuffer); + Show("readv_guest_untouched", reinterpret_cast(Guest[0].iov_base) - Single); + + struct iovec LowOnly[1] = {{LowBuffer, sizeof(LowBuffer)}}; + uint64_t Plain[6] = {3, reinterpret_cast(LowOnly), 1, 0, 0, 0}; + Show("writev_result", Call(Sys::SYSCALL_x64_writev, Plain, &Storage)); + Show("writev_untouched", Plain[1] == reinterpret_cast(LowOnly)); + + struct iovec Straddle[1] = {{reinterpret_cast(Split + Page - 8), 16}}; + uint64_t Crossing[6] = {3, reinterpret_cast(Straddle), 1, 0, 0, 0}; + Show("writev_split_result", Call(Sys::SYSCALL_x64_writev, Crossing, &Storage)); + + ArgumentStorage Receive; + struct iovec Incoming[1] = {{reinterpret_cast(Single + 128), 64}}; + struct msghdr Header {}; + Header.msg_iov = Incoming; + Header.msg_iovlen = 1; + uint64_t Message[6] = {3, reinterpret_cast(&Header), 0, 0, 0, 0}; + Show("recvmsg_result", Call(Sys::SYSCALL_x64_recvmsg, Message, &Receive)); + const auto* HostHeader = reinterpret_cast(Message[1]); + Show("recvmsg_copied", HostHeader != &Header); + Show("recvmsg_base", reinterpret_cast(HostHeader->msg_iov[0].iov_base) - Base); + Receive.Message.msg_flags = MSG_TRUNC; + FinishSyscallArguments(64, &Receive); + Show("recvmsg_flags", Header.msg_flags); + Show("recvmsg_guest_iov", Header.msg_iov == Incoming); + + Show("to_guest", ToGuest(Base + 6 * Page + 8) - Joined); + Show("to_guest_low", ToGuest(Low) == Low); + + const uint32_t ExclusiveOps[] = {0xc85f7c20, 0x885ffc20, 0x085ffc20, 0x485f7c20, 0xc8027c20, 0xc802fc20, + 0x0802fc20, 0xc87f0820, 0x887f8820, 0xc8230820, 0xc8238820}; + const uint32_t OtherOps[] = {0xc8dffc20, 0xc89ffc20, 0xc8e0fc41, 0x4860fc82, 0x08207c82, 0xf8e00041, + 0xf8e08041, 0xf9400020, 0xf9000420, 0xa9000440, 0xf8bfc020}; + uint64_t Refused = 0; + for (auto Op : ExclusiveOps) { + Refused += IsExclusive(Op); + } + uint64_t Allowed = 0; + for (auto Op : OtherOps) { + Allowed += !IsExclusive(Op); + } + Show("exclusive_refused", Refused); + Show("others_allowed", Allowed); + + std::vector> Applied; + auto Record = [&](void* Host, uint64_t Size, uint32_t) { + Applied.emplace_back(reinterpret_cast(Host), Size); + return 0; + }; + Show("split_apply_result", ApplyToRegionsLocked(Split, 2 * Page, -EINVAL, Record)); + Show("split_apply_count", Applied.size()); + Show("split_apply_first", Applied[0].first - Base); + Show("split_apply_second", Applied[1].first - Base); + Show("split_apply_sizes", Applied[0].second + Applied[1].second); + Applied.clear(); + Show("gap_apply_result", ApplyToRegionsLocked(Single, 2 * Page, -EINVAL, Record)); + Show("gap_apply_count", Applied.size()); + bool Advised = false; + Show("advise_split", Advise(Split, 2 * Page, MADV_DONTNEED, &Advised)); + Show("advise_split_applied", Advised); + Show("advise_gap", Advise(Single, 2 * Page, MADV_DONTNEED, &Advised)); + Show("advise_gap_applied", Advised); + Show("advise_unaligned", Advise(Single + 8, Page, MADV_DONTNEED, &Advised)); + Show("advise_unaligned_applied", Advised); + Show("advise_zero", Advise(Single, 0, MADV_DONTNEED, &Advised)); + Show("advise_wrap", Advise(Single, UINT64_MAX - 16, MADV_DONTNEED, &Advised)); + Show("advise_wrap_applied", Advised); + Show("protect_split", Protect(Split, 2 * Page, PROT_READ | PROT_WRITE)); + Show("protect_zero", Protect(Single, 0, PROT_READ | PROT_WRITE)); + Show("protect_wrap", Protect(Single, UINT64_MAX - 16, PROT_READ | PROT_WRITE)); + + auto* Guarded = static_cast(mmap(nullptr, 3 * Page, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)); + const uint64_t Guard = 0x7b0000000000ULL; + RegionView Part {}; + AddEntry(Guard, 3 * Page, reinterpret_cast(Guarded), false, PROT_READ | PROT_WRITE); + Show("guard_protect", Protect(Guard + Page, Page, PROT_READ)); + FindLocked(Guard, &Part); + Show("guard_low_size", Part.Size); + Show("guard_low_prot", Part.Prot); + FindLocked(Guard + Page, &Part); + Show("guard_mid_size", Part.Size); + Show("guard_mid_host", Part.Host - reinterpret_cast(Guarded)); + Show("guard_mid_prot", Part.Prot); + FindLocked(Guard + 2 * Page, &Part); + Show("guard_high_size", Part.Size); + Show("guard_high_prot", Part.Prot); + Show("guard_store_readonly", ExclusiveReachable(0xc8027c20, PROT_READ)); + Show("guard_load_readonly", ExclusiveReachable(0xc85f7c20, PROT_READ)); + Show("guard_store_writable", ExclusiveReachable(0xc8027c20, PROT_READ | PROT_WRITE)); + Show("guard_load_none", ExclusiveReachable(0xc85f7c20, PROT_NONE)); + Show("guard_pair_store_readonly", ExclusiveReachable(0xc8220c20, PROT_READ)); + Show("discards", DiscardsContents(MADV_DONTNEED) + DiscardsContents(MADV_FREE) + DiscardsContents(MADV_REMOVE) + + DiscardsContents(MADV_DONTNEED_LOCKED)); + Show("keeps", DiscardsContents(MADV_WILLNEED) + DiscardsContents(MADV_NORMAL) + DiscardsContents(MADV_HUGEPAGE)); + + auto* Spare = static_cast(mmap(nullptr, 2 * Page, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)); + const uint64_t Retire = 0x7c0000000000ULL; + unsigned char Resident = 0; + RegionView View {}; + AddEntry(Retire, 2 * Page, reinterpret_cast(Spare), false, PROT_READ | PROT_WRITE); + MunmapFailures = 1; + Show("retire_unmap", UnmapLocked(Retire, Page)); + Show("retire_pending", RetiredCount); + Show("retire_untracked", !FindLocked(Retire, &View)); + Show("retire_host_held", mincore(Spare, Page, &Resident) == 0); + Show("retire_second", UnmapLocked(Retire + Page, Page)); + Show("retire_released", RetiredCount); + Show("retire_host_gone", mincore(Spare, Page, &Resident) != 0 && errno == ENOMEM); + Show("retire_rest_gone", mincore(Spare + Page, Page, &Resident) != 0 && errno == ENOMEM); + + auto* Kept = static_cast(mmap(nullptr, Page, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)); + const uint64_t Full = 0x7a0000000000ULL; + AddEntry(Full, Page, reinterpret_cast(Kept), false, PROT_READ | PROT_WRITE); + for (uint32_t i = 0; i < MaxRegions; ++i) { + Retired[i] = {0x10000000ULL + i * 2 * Page, Page}; + } + RetiredCount = MaxRegions; + MunmapFailures = MaxRegions + 1; + Show("retire_full_unmap", UnmapLocked(Full, Page)); + Show("retire_full_tracked", FindLocked(Full, &View)); + Show("retire_full_host_held", mincore(Kept, Page, &Resident) == 0); + RetiredCount = 0; + MunmapFailures = 0; + Show("retire_full_after", UnmapLocked(Full, Page)); + Show("retire_full_gone", !FindLocked(Full, &View)); + + struct { + uint64_t Host; + uint64_t Low; + uint64_t High; + uint32_t Size; + bool Valid; + } Monitor {}; + uint64_t Context[32] {}; + alignas(16) uint64_t Cell[2] = {5, 0}; + const auto CellHost = reinterpret_cast(Cell); + EmulateExclusive(Monitor, 0xc85f7c20, CellHost, Context); + Show("ldxr_value", Context[0]); + Context[0] = 9; + EmulateExclusive(Monitor, 0xc8027c20, CellHost, Context); + Show("stxr_status", Context[2]); + Show("stxr_memory", Cell[0]); + EmulateExclusive(Monitor, 0xc85f7c20, CellHost, Context); + Cell[0] = 11; + Context[0] = 12; + EmulateExclusive(Monitor, 0xc8027c20, CellHost, Context); + Show("contended_status", Context[2]); + Show("contended_memory", Cell[0]); + Context[0] = 13; + EmulateExclusive(Monitor, 0xc8027c20, CellHost, Context); + Show("unarmed_status", Context[2]); + Show("unarmed_memory", Cell[0]); + Cell[0] = 1; + Cell[1] = 2; + EmulateExclusive(Monitor, 0xc87f0c20, CellHost, Context); + Show("ldxp_low", Context[0]); + Show("ldxp_high", Context[3]); + Context[0] = 7; + Context[3] = 8; + EmulateExclusive(Monitor, 0xc8220c20, CellHost, Context); + Show("stxp_status", Context[2]); + Show("stxp_memory", Cell[0] * 16 + Cell[1]); + Cell[0] = 0x1122334455667788ULL; + EmulateExclusive(Monitor, 0x085f7c20, CellHost, Context); + Show("ldxrb_value", Context[0]); + Context[0] = 0x1ab; + EmulateExclusive(Monitor, 0x0802fc20, CellHost, Context); + Show("stlxrb_status", Context[2]); + Show("stlxrb_memory", Cell[0]); + Show("misaligned", EmulateExclusive(Monitor, 0xc85f7c20, CellHost + 4, Context)); + + Show("writeonly_load", ExclusiveReachable(0xc85f7c20, PROT_WRITE)); + Show("writeonly_store", ExclusiveReachable(0xc8027c20, PROT_WRITE)); + Show("writeonly_pair_store", ExclusiveReachable(0xc8220c20, PROT_WRITE)); + Show("exec_only_load", ExclusiveReachable(0xc85f7c20, PROT_EXEC)); + + const uint32_t GuardEntries = Count.load(); + Show("guard_restore", Protect(Guard + Page, Page, PROT_READ | PROT_WRITE)); + FindLocked(Guard + Page, &Part); + Show("guard_restored_guest", Part.Guest - Guard); + Show("guard_restored_size", Part.Size); + Show("guard_restored_merged", GuardEntries - Count.load()); + Show("split_hosts_kept_apart", FindLocked(Split + Page, &Part) && Part.Guest == Split + Page && Part.Size == Page); + + const uint64_t Toggles = 1100; + auto* Striped = static_cast(mmap(nullptr, Toggles * Page, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)); + const uint64_t Stripe = 0x790000000000ULL; + AddEntry(Stripe, Toggles * Page, reinterpret_cast(Striped), false, PROT_READ | PROT_WRITE); + const uint32_t StripeEntries = Count.load(); + uint64_t ToggleFailures = 0; + for (uint64_t i = 0; i < Toggles; ++i) { + ToggleFailures += Protect(Stripe + i * Page, Page, PROT_READ) != 0; + ToggleFailures += Protect(Stripe + i * Page, Page, PROT_READ | PROT_WRITE) != 0; + } + Show("toggle_failures", ToggleFailures); + Show("toggle_entries", Count.load() - StripeEntries); + FindLocked(Stripe, &Part); + Show("toggle_pages", Part.Size / Page); + + uint64_t SemApart[6] = {1, Split + Page - 12, 3, 0, 0, 0}; + Show("semop_split_result", Call(Sys::SYSCALL_x64_semop, SemApart, &Storage)); + uint64_t SemFits[6] = {1, Split + Page - 12, 2, 0, 0, 0}; + Show("semop_fits_result", Call(Sys::SYSCALL_x64_semop, SemFits, &Storage)); + uint64_t GroupsApart[6] = {4, Split + Page - 12, 0, 0, 0, 0}; + Show("getgroups_split_result", Call(Sys::SYSCALL_x64_getgroups, GroupsApart, &Storage)); + uint64_t EventsApart[6] = {1, 1, 2, Split + Page - 32, 0, 0}; + Show("io_getevents_split_result", Call(Sys::SYSCALL_x64_io_getevents, EventsApart, &Storage)); + uint64_t EventsFit[6] = {1, 1, 1, Split + Page - 32, 0, 0}; + Show("io_getevents_fits_result", Call(Sys::SYSCALL_x64_io_getevents, EventsFit, &Storage)); + uint64_t PagesApart[6] = {0, 2, Split + Page - 8, 0, 0, 0}; + Show("move_pages_split_result", Call(Sys::SYSCALL_x64_move_pages, PagesApart, &Storage)); + + char BatchLow[16]; + struct iovec SendVectors[2] = {{reinterpret_cast(Single + 256), 32}, {BatchLow, sizeof(BatchLow)}}; + struct mmsghdr Outgoing[2] {}; + Outgoing[0].msg_hdr.msg_iov = &SendVectors[0]; + Outgoing[0].msg_hdr.msg_iovlen = 1; + Outgoing[1].msg_hdr.msg_iov = &SendVectors[1]; + Outgoing[1].msg_hdr.msg_iovlen = 1; + ArgumentStorage SendBatch; + uint64_t Send[6] = {static_cast(Peer), reinterpret_cast(Outgoing), 2, 0, 0, 0}; + Show("sendmmsg_result", Call(Sys::SYSCALL_x64_sendmmsg, Send, &SendBatch)); + auto* HostSend = reinterpret_cast(Send[1]); + Show("sendmmsg_copied", HostSend != Outgoing); + Show("sendmmsg_high_base", reinterpret_cast(HostSend[0].msg_hdr.msg_iov[0].iov_base) - Base); + Show("sendmmsg_low_base", HostSend[1].msg_hdr.msg_iov[0].iov_base == BatchLow); + Show("sendmmsg_guest_untouched", reinterpret_cast(Outgoing[0].msg_hdr.msg_iov[0].iov_base) - Single); + Show("sendmmsg_submitted", Send[2]); + SendCalls = 0; + HostSend[0].msg_len = 32; + Show("sendmmsg_finish", FinishResult(1, &SendBatch)); + Show("sendmmsg_later_sends", SendCalls); + Show("sendmmsg_lengths", Outgoing[0].msg_len * 0x100 + Outgoing[1].msg_len); + Outgoing[0].msg_len = 0; + Outgoing[1].msg_len = 0; + ArgumentStorage DeclinedBatch; + uint64_t Declined[6] = {static_cast(Peer), reinterpret_cast(Outgoing), 2, 0, 0, 0}; + Call(Sys::SYSCALL_x64_sendmmsg, Declined, &DeclinedBatch); + reinterpret_cast(Declined[1])[0].msg_len = 32; + SendFailures = 1; + Show("sendmmsg_refused_finish", FinishResult(1, &DeclinedBatch)); + Show("sendmmsg_refused_lengths", Outgoing[0].msg_len * 0x100 + Outgoing[1].msg_len); + + struct iovec ReceiveVectors[2] = {{reinterpret_cast(Single + 512), 64}, {BatchLow, sizeof(BatchLow)}}; + struct mmsghdr Arriving[2] {}; + Arriving[0].msg_hdr.msg_iov = &ReceiveVectors[0]; + Arriving[0].msg_hdr.msg_iovlen = 1; + Arriving[1].msg_hdr.msg_iov = &ReceiveVectors[1]; + Arriving[1].msg_hdr.msg_iovlen = 1; + ArgumentStorage ReceiveBatch; + uint64_t Batch[6] = {3, reinterpret_cast(Arriving), 2, 0, 0, 0}; + Show("recvmmsg_result", Call(Sys::SYSCALL_x64_recvmmsg, Batch, &ReceiveBatch)); + auto* HostReceive = reinterpret_cast(Batch[1]); + Show("recvmmsg_copied", HostReceive != Arriving); + Show("recvmmsg_base", reinterpret_cast(HostReceive[0].msg_hdr.msg_iov[0].iov_base) - Base); + HostReceive[0].msg_len = 40; + HostReceive[0].msg_hdr.msg_flags = MSG_TRUNC; + HostReceive[1].msg_len = 5; + FinishSyscallArguments(1, &ReceiveBatch); + Show("recvmmsg_first_length", Arriving[0].msg_len); + Show("recvmmsg_first_flags", Arriving[0].msg_hdr.msg_flags); + Show("recvmmsg_second_length", Arriving[1].msg_len); + Show("recvmmsg_guest_iov", Arriving[0].msg_hdr.msg_iov == &ReceiveVectors[0]); + + std::vector Many(1100); + Many[0].msg_hdr.msg_iov = &ReceiveVectors[0]; + Many[0].msg_hdr.msg_iovlen = 1; + ArgumentStorage ManyBatch; + uint64_t Wide[6] = {3, reinterpret_cast(Many.data()), Many.size(), 0, 0, 0}; + Show("recvmmsg_wide_result", Call(Sys::SYSCALL_x64_recvmmsg, Wide, &ManyBatch)); + Show("recvmmsg_wide_count", Wide[2]); + uint64_t BatchApart[6] = {3, Split + Page - 64, 2, 0, 0, 0}; + Show("sendmmsg_split_result", Call(Sys::SYSCALL_x64_sendmmsg, BatchApart, &ManyBatch)); + + ArgumentStorage Sizes; + uint64_t StatSplit[6] = {3, Split + Page - 64, 0, 0, 0, 0}; + Show("fstat_split_result", Call(Sys::SYSCALL_x64_fstat, StatSplit, &Sizes)); + uint64_t StatEdge[6] = {3, Single + Page - 144, 0, 0, 0, 0}; + Show("fstat_edge_result", Call(Sys::SYSCALL_x64_fstat, StatEdge, &Sizes)); + uint64_t NameEdge[6] = {Single + Page - 390, 0, 0, 0, 0, 0}; + Show("uname_edge_result", Call(Sys::SYSCALL_x64_uname, NameEdge, &Sizes)); + uint64_t NameOver[6] = {Single + Page - 389, 0, 0, 0, 0, 0}; + Show("uname_over_result", Call(Sys::SYSCALL_x64_uname, NameOver, &Sizes)); + uint64_t Action[6] = {10, Single + Page - 32, 0, 8, 0, 0}; + Show("sigaction_edge_result", Call(Sys::SYSCALL_x64_rt_sigaction, Action, &Sizes)); + uint64_t ActionOver[6] = {10, Single + Page - 24, 0, 8, 0, 0}; + Show("sigaction_over_result", Call(Sys::SYSCALL_x64_rt_sigaction, ActionOver, &Sizes)); + uint64_t MaskApart[6] = {0, Split + Page - 4, 0, 8, 0, 0}; + Show("sigprocmask_split_result", Call(Sys::SYSCALL_x64_rt_sigprocmask, MaskApart, &Sizes)); + uint64_t MaskFits[6] = {0, Split + Page - 8, 0, 8, 0, 0}; + Show("sigprocmask_fits_result", Call(Sys::SYSCALL_x64_rt_sigprocmask, MaskFits, &Sizes)); + uint64_t Sleep[6] = {Single + Page - 16, 0, 0, 0, 0, 0}; + Show("nanosleep_edge_result", Call(Sys::SYSCALL_x64_nanosleep, Sleep, &Sizes)); + uint64_t SleepOver[6] = {Single + Page - 8, 0, 0, 0, 0, 0}; + Show("nanosleep_over_result", Call(Sys::SYSCALL_x64_nanosleep, SleepOver, &Sizes)); + uint64_t Residency[6] = {Low, 3 * Page, Split + Page - 2, 0, 0, 0}; + Show("mincore_split_result", Call(Sys::SYSCALL_x64_mincore, Residency, &Sizes)); + uint64_t ResidencyFits[6] = {Low, 2 * Page, Split + Page - 2, 0, 0, 0}; + Show("mincore_fits_result", Call(Sys::SYSCALL_x64_mincore, ResidencyFits, &Sizes)); + uint64_t Lock[6] = {3, F_GETLK, Split + Page - 16, 0, 0, 0}; + Show("fcntl_lock_split_result", Call(Sys::SYSCALL_x64_fcntl, Lock, &Sizes)); + uint64_t LockFits[6] = {3, F_GETLK, Single + Page - 32, 0, 0, 0}; + Show("fcntl_lock_fits_result", Call(Sys::SYSCALL_x64_fcntl, LockFits, &Sizes)); + Show("fcntl_lock_fits_buffer", LockFits[2] - Base); + + std::memcpy(Backing + 3 * Page - 2, "ab", 2); + std::memcpy(Backing + 4 * Page, "cd", 3); + uint64_t PathApart[6] = {Split + Page - 2, 0, 0, 0, 0, 0}; + Show("open_split_result", Call(Sys::SYSCALL_x64_open, PathApart, &Sizes)); + std::memcpy(Backing + 6 * Page - 2, "ab", 2); + std::memcpy(Backing + 6 * Page, "cd", 3); + uint64_t PathJoined[6] = {Joined + Page - 2, 0, 0, 0, 0, 0}; + Show("open_joined_result", Call(Sys::SYSCALL_x64_open, PathJoined, &Sizes)); + Show("open_joined_path", PathJoined[0] - Base); + std::memcpy(Backing + 3000, "dir/file", 9); + uint64_t PathInside[6] = {static_cast(AT_FDCWD), Single + 3000, 0, 0, 0, 0}; + Show("openat_inside_result", Call(Sys::SYSCALL_x64_openat, PathInside, &Sizes)); + Show("openat_inside_path", PathInside[1] - Base); + std::memset(Backing + Page - 8, 'x', 8); + uint64_t PathOpen[6] = {Single + Page - 8, 0, 0, 0, 0, 0}; + Show("open_unterminated_result", Call(Sys::SYSCALL_x64_open, PathOpen, &Sizes)); + uint64_t RenameApart[6] = {Single + 3000, Split + Page - 2, 0, 0, 0, 0}; + Show("rename_split_result", Call(Sys::SYSCALL_x64_rename, RenameApart, &Sizes)); + + socklen_t AddressLength = 16; + uint64_t Accept[6] = {3, Split + Page - 16, reinterpret_cast(&AddressLength), 0, 0, 0}; + Show("accept_fits_result", Call(Sys::SYSCALL_x64_accept, Accept, &Sizes)); + AddressLength = 32; + uint64_t AcceptOver[6] = {3, Split + Page - 16, reinterpret_cast(&AddressLength), 0, 0, 0}; + Show("accept_split_result", Call(Sys::SYSCALL_x64_accept, AcceptOver, &Sizes)); + AddressLength = 4096; + uint64_t AcceptCapped[6] = {3, Single + Page - 128, reinterpret_cast(&AddressLength), 0, 0, 0}; + Show("accept_capped_result", Call(Sys::SYSCALL_x64_accept, AcceptCapped, &Sizes)); + const uint32_t HighLength = 32; + std::memcpy(Backing + 40, &HighLength, sizeof(HighLength)); + uint64_t AcceptHigh[6] = {3, Split + Page - 16, Single + 40, 0, 0, 0}; + Show("accept_high_length_result", Call(Sys::SYSCALL_x64_accept, AcceptHigh, &Sizes)); + uint32_t OptionLength = 8; + uint64_t Option[6] = {3, 1, 2, Split + Page - 4, reinterpret_cast(&OptionLength), 0}; + Show("getsockopt_split_result", Call(Sys::SYSCALL_x64_getsockopt, Option, &Sizes)); + OptionLength = 4; + uint64_t OptionFits[6] = {3, 1, 2, Split + Page - 4, reinterpret_cast(&OptionLength), 0}; + Show("getsockopt_fits_result", Call(Sys::SYSCALL_x64_getsockopt, OptionFits, &Sizes)); + + uint64_t QueueFits[6] = {1, Split + Page - 16, 8, 0, 0, 0}; + Show("msgsnd_fits_result", Call(Sys::SYSCALL_x64_msgsnd, QueueFits, &Sizes)); + uint64_t QueueOver[6] = {1, Split + Page - 16, 9, 0, 0, 0}; + Show("msgsnd_split_result", Call(Sys::SYSCALL_x64_msgsnd, QueueOver, &Sizes)); + uint64_t QueueReceive[6] = {1, Split + Page - 16, 9, 0, 0, 0}; + Show("msgrcv_split_result", Call(Sys::SYSCALL_x64_msgrcv, QueueReceive, &Sizes)); + uint64_t QueueHuge[6] = {1, Single, 1ULL << 40, 0, 0, 0}; + Show("msgsnd_huge_result", Call(Sys::SYSCALL_x64_msgsnd, QueueHuge, &Sizes)); + + std::memcpy(Backing + 100, "x", 2); + uint64_t ValidFailures = 0; + uint64_t ValidTranslated = 0; + uint64_t StatValid[6] = {Single + 100, Single + 1024, 0, 0, 0, 0}; + ValidFailures += Call(Sys::SYSCALL_x64_stat, StatValid, &Sizes) != 0; + ValidTranslated += StatValid[0] == Base + 100 && StatValid[1] == Base + 1024; + uint64_t StatxValid[6] = {static_cast(AT_FDCWD), Single + 100, 0, 0x7ff, Single + 1536, 0}; + ValidFailures += Call(Sys::SYSCALL_x64_statx, StatxValid, &Sizes) != 0; + ValidTranslated += StatxValid[1] == Base + 100 && StatxValid[4] == Base + 1536; + uint64_t ClockValid[6] = {1, Single + 2048, 0, 0, 0, 0}; + ValidFailures += Call(Sys::SYSCALL_x64_clock_gettime, ClockValid, &Sizes) != 0; + ValidTranslated += ClockValid[1] == Base + 2048; + uint64_t WaitValid[6] = {static_cast(-1), Single + 64, 0, Single + 512, 0, 0}; + ValidFailures += Call(Sys::SYSCALL_x64_wait4, WaitValid, &Sizes) != 0; + ValidTranslated += WaitValid[1] == Base + 64 && WaitValid[3] == Base + 512; + uint64_t PipeValid[6] = {Single + 8, 0, 0, 0, 0, 0}; + ValidFailures += Call(Sys::SYSCALL_x64_pipe2, PipeValid, &Sizes) != 0; + ValidTranslated += PipeValid[0] == Base + 8; + uint64_t LimitValid[6] = {0, 7, Single + 2560, Single + 2600, 0, 0}; + ValidFailures += Call(Sys::SYSCALL_x64_prlimit_64, LimitValid, &Sizes) != 0; + ValidTranslated += LimitValid[2] == Base + 2560 && LimitValid[3] == Base + 2600; + uint64_t TimerValid[6] = {1, 0, Single + 2304, Single + 2336, 0, 0}; + ValidFailures += Call(Sys::SYSCALL_x64_timer_settime, TimerValid, &Sizes) != 0; + ValidTranslated += TimerValid[2] == Base + 2304 && TimerValid[3] == Base + 2336; + AddressLength = 16; + uint64_t AcceptValid[6] = {3, Single + 256, reinterpret_cast(&AddressLength), 0, 0, 0}; + ValidFailures += Call(Sys::SYSCALL_x64_accept, AcceptValid, &Sizes) != 0; + ValidTranslated += AcceptValid[1] == Base + 256; + uint64_t NameValid[6] = {Single, 0, 0, 0, 0, 0}; + ValidFailures += Call(Sys::SYSCALL_x64_uname, NameValid, &Sizes) != 0; + ValidTranslated += NameValid[0] == Base; + uint64_t SignalValid[6] = {10, Single + 2800, Single + 2900, 8, 0, 0}; + ValidFailures += Call(Sys::SYSCALL_x64_rt_sigaction, SignalValid, &Sizes) != 0; + ValidTranslated += SignalValid[1] == Base + 2800 && SignalValid[2] == Base + 2900; + Show("single_valid_failures", ValidFailures); + Show("single_valid_translated", ValidTranslated); + + struct TestIocb { + uint64_t Data; + uint32_t Key; + int32_t ReadWriteFlags; + uint16_t Opcode; + int16_t Priority; + uint32_t File; + uint64_t Buffer; + uint64_t Bytes; + int64_t Offset; + uint64_t Reserved; + uint32_t Flags; + uint32_t ResultFile; + }; + TestIocb ReadBlock {}; + ReadBlock.Data = 0x77; + ReadBlock.Key = 5; + ReadBlock.Buffer = Single + 768; + ReadBlock.Bytes = 64; + char VectorLow[16]; + struct iovec Scatter[2] = {{reinterpret_cast(Single + 800), 16}, {VectorLow, sizeof(VectorLow)}}; + TestIocb Vectored {}; + Vectored.Opcode = 7; + Vectored.Buffer = reinterpret_cast(Scatter); + Vectored.Bytes = 2; + TestIocb ReadExpected = ReadBlock; + const TestIocb VectoredExpected = Vectored; + auto GuestBlocksUntouched = [&] { + return std::memcmp(&ReadBlock, &ReadExpected, sizeof(TestIocb)) == 0 && std::memcmp(&Vectored, &VectoredExpected, sizeof(TestIocb)) == 0; + }; + struct TestEvent { + uint64_t Data; + uint64_t Object; + int64_t Result; + int64_t Result2; + }; + auto Deliver = [](const uint64_t* Args, const void* Events, size_t Size) { + static_cast(FEX::HLE::FaultSafeUserMemAccess::CopyToUser(reinterpret_cast(Args[3]), Events, Size)); + }; + uint64_t Submitted[2] = {reinterpret_cast(&ReadBlock), reinterpret_cast(&Vectored)}; + ArgumentStorage Submit; + uint64_t SubmitArgs[6] = {1, 2, reinterpret_cast(Submitted), 0, 0, 0}; + const auto CopiesBefore = IoCopyCount.load(); + ProtectCalls = 0; + Show("io_submit_result", Call(Sys::SYSCALL_x64_io_submit, SubmitArgs, &Submit)); + Show("io_submit_count", SubmitArgs[1]); + Show("io_submit_list_copied", SubmitArgs[2] != reinterpret_cast(Submitted)); + const auto* Sent = reinterpret_cast(SubmitArgs[2]); + const auto* SentRead = reinterpret_cast(Sent[0]); + const auto* SentVector = reinterpret_cast(Sent[1]); + Show("io_submit_private_blocks", SentRead != &ReadBlock && SentVector != &Vectored); + Show("io_submit_buffer", SentRead->Buffer - Base); + Show("io_submit_fields_kept", SentRead->Data == 0x77 && SentRead->Bytes == 64 && SentRead->Key == 5); + const auto* HostScatter = reinterpret_cast(SentVector->Buffer); + Show("io_submit_vector_copied", HostScatter != Scatter); + Show("io_submit_vector_base", reinterpret_cast(HostScatter[0].iov_base) - Base); + Show("io_submit_vector_low", HostScatter[1].iov_base == VectorLow); + Show("io_submit_guest_key", ReadBlock.Key); + Show("io_submit_guest_untouched", GuestBlocksUntouched()); + Show("io_submit_copies", IoCopyCount.load() - CopiesBefore); + FinishSyscallArguments(2, &Submit); + Show("io_submit_accepted_key", ReadBlock.Key); + ReadExpected.Key = 0; + Show("io_submit_copies_kept", IoCopyCount.load() - CopiesBefore); + Show("io_submit_finished_untouched", GuestBlocksUntouched()); + + TestEvent CancelEvent {}; + ArgumentStorage Cancel; + uint64_t CancelArgs[6] = {1, reinterpret_cast(&ReadBlock), reinterpret_cast(&CancelEvent), 0, 0, 0}; + Show("io_cancel_result", Call(Sys::SYSCALL_x64_io_cancel, CancelArgs, &Cancel)); + Show("io_cancel_private", CancelArgs[1] == Sent[0]); + ArgumentStorage CancelElsewhere; + uint64_t ElsewhereArgs[6] = {2, reinterpret_cast(&ReadBlock), reinterpret_cast(&CancelEvent), 0, 0, 0}; + Call(Sys::SYSCALL_x64_io_cancel, ElsewhereArgs, &CancelElsewhere); + Show("io_cancel_other_context", ElsewhereArgs[1] == reinterpret_cast(&ReadBlock)); + + TestEvent Reaped[3] = {{0x77, Sent[0], 64, 0}, {0, Sent[1], 16, 0}, {8, Base + 1536, 16, 0}}; + ArgumentStorage ReapCopies; + uint64_t ReapCopiesArgs[6] = {1, 1, 3, reinterpret_cast(Reaped), 0, 0}; + Call(Sys::SYSCALL_x64_io_getevents, ReapCopiesArgs, &ReapCopies); + Show("io_getevents_host_buffer", ReapCopiesArgs[3] == reinterpret_cast(ReapCopies.EventBuffer.data())); + Deliver(ReapCopiesArgs, Reaped, sizeof(Reaped)); + FinishSyscallArguments(3, &ReapCopies); + Show("io_getevents_copy_object", Reaped[0].Object == reinterpret_cast(&ReadBlock)); + Show("io_getevents_vector_object", Reaped[1].Object == reinterpret_cast(&Vectored)); + Show("io_getevents_alias_object", Reaped[2].Object - Single); + Show("io_getevents_copies_freed", IoCopyCount.load() - CopiesBefore); + Show("io_getevents_untouched", GuestBlocksUntouched()); + Show("io_submit_protect_calls", ProtectCalls); + + auto* HighBlock = reinterpret_cast(Backing + 1536); + *HighBlock = {}; + HighBlock->Opcode = 1; + HighBlock->Buffer = reinterpret_cast(LowBuffer); + HighBlock->Bytes = sizeof(LowBuffer); + uint64_t HighList[1] = {Single + 1536}; + ArgumentStorage HighSubmit; + uint64_t HighArgs[6] = {1, 1, reinterpret_cast(HighList), 0, 0, 0}; + Show("io_submit_high_result", Call(Sys::SYSCALL_x64_io_submit, HighArgs, &HighSubmit)); + Show("io_submit_high_copied", HighArgs[2] != reinterpret_cast(HighList)); + Show("io_submit_high_block", reinterpret_cast(HighArgs[2])[0] - Base); + Show("io_submit_high_guest_list", HighList[0] - Single); + Show("io_submit_high_uncopied", IoCopyCount.load() - CopiesBefore); + FinishSyscallArguments(1, &HighSubmit); + + TestIocb BadBlock {}; + BadBlock.Buffer = Split + Page - 8; + BadBlock.Bytes = 16; + uint64_t Mixed[2] = {reinterpret_cast(&ReadBlock), reinterpret_cast(&BadBlock)}; + ArgumentStorage Partial; + uint64_t PartialArgs[6] = {1, 2, reinterpret_cast(Mixed), 0, 0, 0}; + Show("io_submit_partial_result", Call(Sys::SYSCALL_x64_io_submit, PartialArgs, &Partial)); + Show("io_submit_partial_count", PartialArgs[1]); + Show("io_submit_partial_copies", IoCopyCount.load() - CopiesBefore); + FinishSyscallArguments(static_cast(-EFAULT), &Partial); + Show("io_submit_partial_released", IoCopyCount.load() - CopiesBefore); + Show("io_submit_partial_untouched", GuestBlocksUntouched()); + ArgumentStorage Truncated; + uint64_t TruncatedArgs[6] = {1, 2, reinterpret_cast(Submitted), 0, 0, 0}; + Call(Sys::SYSCALL_x64_io_submit, TruncatedArgs, &Truncated); + const uint64_t TruncatedFirst = reinterpret_cast(TruncatedArgs[2])[0]; + FinishSyscallArguments(1, &Truncated); + Show("io_submit_short_kept", IoCopyCount.load() - CopiesBefore); + Show("io_submit_short_first_live", FindIoCopyLocked(TruncatedFirst) != nullptr); + ArgumentStorage OtherContext; + uint64_t OtherContextArgs[6] = {3, 1, reinterpret_cast(Submitted), 0, 0, 0}; + Call(Sys::SYSCALL_x64_io_submit, OtherContextArgs, &OtherContext); + FinishSyscallArguments(1, &OtherContext); + ArgumentStorage Destroy; + uint64_t DestroyArgs[6] = {1, 0, 0, 0, 0, 0}; + Call(Sys::SYSCALL_x64_io_destroy, DestroyArgs, &Destroy); + FinishSyscallArguments(0, &Destroy); + Show("io_destroy_released", IoCopyCount.load() - CopiesBefore); + ArgumentStorage DestroyFailed; + uint64_t DestroyFailedArgs[6] = {3, 0, 0, 0, 0, 0}; + Call(Sys::SYSCALL_x64_io_destroy, DestroyFailedArgs, &DestroyFailed); + FinishSyscallArguments(static_cast(-EINVAL), &DestroyFailed); + Show("io_destroy_failed_kept", IoCopyCount.load() - CopiesBefore); + ArgumentStorage DestroyOther; + uint64_t DestroyOtherArgs[6] = {3, 0, 0, 0, 0, 0}; + Call(Sys::SYSCALL_x64_io_destroy, DestroyOtherArgs, &DestroyOther); + FinishSyscallArguments(0, &DestroyOther); + Show("io_destroy_other_released", IoCopyCount.load() - CopiesBefore); + uint64_t OnlyCrossing[1] = {reinterpret_cast(&BadBlock)}; + ArgumentStorage FirstBad; + uint64_t FirstBadArgs[6] = {1, 1, reinterpret_cast(OnlyCrossing), 0, 0, 0}; + Show("io_submit_first_bad_result", Call(Sys::SYSCALL_x64_io_submit, FirstBadArgs, &FirstBad)); + FinishSyscallArguments(static_cast(-EFAULT), &FirstBad); + Show("io_submit_first_bad_copies", IoCopyCount.load() - CopiesBefore); + TestIocb KeyFirst = ReadBlock; + KeyFirst.Key = 5; + TestIocb KeySecond = ReadBlock; + KeySecond.Key = 6; + uint64_t KeyList[2] = {reinterpret_cast(&KeyFirst), reinterpret_cast(&KeySecond)}; + ArgumentStorage KeySubmit; + uint64_t KeySubmitArgs[6] = {4, 2, reinterpret_cast(KeyList), 0, 0, 0}; + Call(Sys::SYSCALL_x64_io_submit, KeySubmitArgs, &KeySubmit); + const uint64_t KeyFirstSent = reinterpret_cast(KeySubmitArgs[2])[0]; + Show("io_submit_keys_prepared", KeyFirst.Key == 5 && KeySecond.Key == 6); + TestEvent KeyCancelEvent {}; + ArgumentStorage EarlyCancel; + uint64_t EarlyCancelArgs[6] = {4, reinterpret_cast(&KeyFirst), reinterpret_cast(&KeyCancelEvent), 0, 0, 0}; + Call(Sys::SYSCALL_x64_io_cancel, EarlyCancelArgs, &EarlyCancel); + Show("io_cancel_keyed_native", EarlyCancelArgs[1] == reinterpret_cast(&KeyFirst)); + FinishSyscallArguments(1, &KeySubmit); + Show("io_submit_key_accepted", KeyFirst.Key); + Show("io_submit_key_after_rejected", KeySecond.Key); + Show("io_submit_key_rejected_released", IoCopyCount.load() - CopiesBefore); + ArgumentStorage LateCancel; + uint64_t LateCancelArgs[6] = {4, reinterpret_cast(&KeyFirst), reinterpret_cast(&KeyCancelEvent), 0, 0, 0}; + Call(Sys::SYSCALL_x64_io_cancel, LateCancelArgs, &LateCancel); + Show("io_cancel_accepted_private", LateCancelArgs[1] == KeyFirstSent); + TestIocb KeyA = ReadBlock; + KeyA.Key = 7; + TestIocb KeyB = ReadBlock; + KeyB.Key = 8; + TestIocb KeyC = ReadBlock; + KeyC.Key = 9; + uint64_t KeyTriple[3] = {reinterpret_cast(&KeyA), reinterpret_cast(&KeyB), reinterpret_cast(&KeyC)}; + ArgumentStorage RejectSubmit; + uint64_t RejectSubmitArgs[6] = {6, 3, reinterpret_cast(KeyTriple), 0, 0, 0}; + Call(Sys::SYSCALL_x64_io_submit, RejectSubmitArgs, &RejectSubmit); + const auto* RejectSent = reinterpret_cast(RejectSubmitArgs[2]); + reinterpret_cast(RejectSent[0])->Key = 0; + reinterpret_cast(RejectSent[1])->Key = 0; + FinishSyscallArguments(1, &RejectSubmit); + Show("io_submit_rejected_key_cleared", KeyA.Key == 0 && KeyB.Key == 0); + Show("io_submit_unreached_key", KeyC.Key); + TestIocb KeyD = ReadBlock; + KeyD.Key = 3; + uint64_t KeySingle[1] = {reinterpret_cast(&KeyD)}; + ArgumentStorage FirstRejected; + uint64_t FirstRejectedArgs[6] = {6, 1, reinterpret_cast(KeySingle), 0, 0, 0}; + Call(Sys::SYSCALL_x64_io_submit, FirstRejectedArgs, &FirstRejected); + reinterpret_cast(reinterpret_cast(FirstRejectedArgs[2])[0])->Key = 0; + FinishSyscallArguments(static_cast(-EBADF), &FirstRejected); + Show("io_submit_first_rejected_key", KeyD.Key); + ArgumentStorage RejectDestroy; + uint64_t RejectDestroyArgs[6] = {6, 0, 0, 0, 0, 0}; + Call(Sys::SYSCALL_x64_io_destroy, RejectDestroyArgs, &RejectDestroy); + FinishSyscallArguments(0, &RejectDestroy); + Show("io_submit_rejected_released", IoCopyCount.load() - CopiesBefore); + auto* SealedEvents = static_cast(mmap(nullptr, Page, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)); + int64_t NoWait[2] = {0, 0}; + const uint64_t Immediate = reinterpret_cast(NoWait); + ArgumentStorage UnwritableReap; + uint64_t UnwritableReapArgs[6] = {4, 1, 1, reinterpret_cast(SealedEvents), 0, 0}; + Call(Sys::SYSCALL_x64_io_getevents, UnwritableReapArgs, &UnwritableReap); + Show("io_getevents_unwritable_staged", UnwritableReapArgs[3] == reinterpret_cast(UnwritableReap.EventBuffer.data()) && + UnwritableReapArgs[2] == 1 && UnwritableReap.EventBuffer.size() == sizeof(TestEvent) / sizeof(uint64_t)); + Show("io_getevents_unwritable_result", FinishSyscallArguments(static_cast(-EFAULT), &UnwritableReap)); + Show("io_getevents_unwritable_kept", IoCopyCount.load() - CopiesBefore); + mprotect(SealedEvents, Page, PROT_READ | PROT_WRITE); + ArgumentStorage SealedReap; + uint64_t SealedReapArgs[6] = {4, 1, 1, reinterpret_cast(SealedEvents), 0, 0}; + Call(Sys::SYSCALL_x64_io_getevents, SealedReapArgs, &SealedReap); + mprotect(SealedEvents, Page, PROT_READ); + const TestEvent SealedEvent {0x77, KeyFirstSent, 64, 0}; + Deliver(SealedReapArgs, &SealedEvent, sizeof(SealedEvent)); + Show("io_getevents_sealed_result", FinishSyscallArguments(1, &SealedReap)); + Show("io_getevents_sealed_released", IoCopyCount.load() - CopiesBefore); + mprotect(SealedEvents, Page, PROT_READ | PROT_WRITE); + ArgumentStorage StashedReap; + uint64_t StashedReapArgs[6] = {4, 1, 2, reinterpret_cast(SealedEvents), 0, 0}; + Call(Sys::SYSCALL_x64_io_getevents, StashedReapArgs, &StashedReap); + Show("io_getevents_stash_nonblocking", StashedReapArgs[1] == 0 && StashedReapArgs[2] == 1 && + StashedReapArgs[3] == reinterpret_cast(StashedReap.EventBuffer.data() + sizeof(TestEvent) / sizeof(uint64_t))); + Show("io_getevents_stash_result", FinishSyscallArguments(0, &StashedReap)); + Show("io_getevents_stash_event", SealedEvents[0].Object == reinterpret_cast(&KeyFirst) && SealedEvents[0].Data == 0x77); + ArgumentStorage DrainedReap; + uint64_t DrainedReapArgs[6] = {4, 1, 1, reinterpret_cast(SealedEvents), Immediate, 0}; + Call(Sys::SYSCALL_x64_io_getevents, DrainedReapArgs, &DrainedReap); + Show("io_getevents_stash_once", DrainedReapArgs[1] == 1 && DrainedReapArgs[2] == 1 && FinishSyscallArguments(0, &DrainedReap) == 0); + auto FailReap = [&](uint64_t Context, const TestEvent& Event) { + mprotect(SealedEvents, Page, PROT_READ | PROT_WRITE); + ArgumentStorage Failed; + uint64_t FailedArgs[6] = {Context, 1, 1, reinterpret_cast(SealedEvents), 0, 0}; + Call(Sys::SYSCALL_x64_io_getevents, FailedArgs, &Failed); + mprotect(SealedEvents, Page, PROT_READ); + Deliver(FailedArgs, &Event, sizeof(Event)); + const auto Result = FinishSyscallArguments(1, &Failed); + mprotect(SealedEvents, Page, PROT_READ | PROT_WRITE); + return Result; + }; + Show("io_getevents_stash_ready_failed", FailReap(4, {0x57, reinterpret_cast(&KeyD), 1, 0})); + ArgumentStorage ReadyReap; + uint64_t ReadyReapArgs[6] = {4, 1, 2, reinterpret_cast(SealedEvents), 0, 0}; + Call(Sys::SYSCALL_x64_io_getevents, ReadyReapArgs, &ReadyReap); + const TestEvent Ready {0x58, reinterpret_cast(&KeyC), 1, 0}; + Deliver(ReadyReapArgs, &Ready, sizeof(Ready)); + Show("io_getevents_stash_ready_result", FinishSyscallArguments(1, &ReadyReap)); + Show("io_getevents_stash_ready_order", SealedEvents[0].Data == 0x57 && SealedEvents[1].Data == 0x58 && + SealedEvents[1].Object == reinterpret_cast(&KeyC)); + Show("io_getevents_stash_plain_failed", FailReap(4, {0x55, reinterpret_cast(&KeyD), 1, 0})); + ArgumentStorage TopUp; + uint64_t TopUpArgs[6] = {4, 2, 3, reinterpret_cast(SealedEvents), 0, 0}; + Call(Sys::SYSCALL_x64_io_getevents, TopUpArgs, &TopUp); + Show("io_getevents_stash_topup_args", TopUpArgs[1] == 1 && TopUpArgs[2] == 2 && + TopUpArgs[3] == reinterpret_cast(TopUp.EventBuffer.data() + sizeof(TestEvent) / sizeof(uint64_t))); + const TestEvent Fresh {0x66, reinterpret_cast(&KeyA), 2, 0}; + Deliver(TopUpArgs, &Fresh, sizeof(Fresh)); + Show("io_getevents_stash_topup_result", FinishSyscallArguments(1, &TopUp)); + Show("io_getevents_stash_topup_order", SealedEvents[0].Data == 0x55 && SealedEvents[0].Object == reinterpret_cast(&KeyD) && + SealedEvents[1].Data == 0x66 && SealedEvents[1].Object == reinterpret_cast(&KeyA)); + FailReap(4, {0x44, reinterpret_cast(&KeyB), 1, 0}); + ArgumentStorage FaultedRetry; + uint64_t FaultedRetryArgs[6] = {4, 2, 2, reinterpret_cast(SealedEvents), 0, 0}; + Call(Sys::SYSCALL_x64_io_getevents, FaultedRetryArgs, &FaultedRetry); + Show("io_getevents_stash_fault_result", FinishSyscallArguments(static_cast(-EFAULT), &FaultedRetry)); + ArgumentStorage Interrupted; + uint64_t InterruptedArgs[6] = {4, 2, 2, reinterpret_cast(SealedEvents), 0, 0}; + Call(Sys::SYSCALL_x64_io_getevents, InterruptedArgs, &Interrupted); + Show("io_getevents_stash_kept_after_fault", InterruptedArgs[1] == 1 && InterruptedArgs[2] == 1); + Show("io_getevents_stash_interrupted", FinishSyscallArguments(static_cast(-EINTR), &Interrupted)); + Show("io_getevents_stash_interrupted_event", SealedEvents[0].Data == 0x44 && SealedEvents[0].Object == reinterpret_cast(&KeyB)); + FailReap(4, {0x45, reinterpret_cast(&KeyB), 1, 0}); + ArgumentStorage RejectedMask; + uint64_t RejectedMaskArgs[6] = {4, 1, 1, reinterpret_cast(SealedEvents), 0, 0}; + Call(Sys::SYSCALL_x64_io_pgetevents, RejectedMaskArgs, &RejectedMask); + Show("io_getevents_stash_einval_result", FinishSyscallArguments(static_cast(-EINVAL), &RejectedMask)); + ArgumentStorage AfterRejected; + uint64_t AfterRejectedArgs[6] = {4, 1, 1, reinterpret_cast(SealedEvents), 0, 0}; + Call(Sys::SYSCALL_x64_io_getevents, AfterRejectedArgs, &AfterRejected); + Show("io_getevents_stash_einval_kept", FinishSyscallArguments(0, &AfterRejected) == 1 && SealedEvents[0].Data == 0x45); + FailReap(12, {0x46, reinterpret_cast(&KeyB), 1, 0}); + ArgumentStorage InFlight; + uint64_t InFlightArgs[6] = {12, 1, 1, reinterpret_cast(SealedEvents), 0, 0}; + Call(Sys::SYSCALL_x64_io_getevents, InFlightArgs, &InFlight); + ArgumentStorage InFlightDestroy; + uint64_t InFlightDestroyArgs[6] = {12, 0, 0, 0, 0, 0}; + Call(Sys::SYSCALL_x64_io_destroy, InFlightDestroyArgs, &InFlightDestroy); + FinishSyscallArguments(0, &InFlightDestroy); + ArgumentStorage Recreated; + uint64_t RecreatedArgs[6] = {12, 1, 1, reinterpret_cast(SealedEvents), Immediate, 0}; + Call(Sys::SYSCALL_x64_io_getevents, RecreatedArgs, &Recreated); + FinishSyscallArguments(static_cast(-EINVAL), &InFlight); + Show("io_getevents_stash_recreated_result", FinishSyscallArguments(0, &Recreated)); + ArgumentStorage AfterDestroy; + uint64_t AfterDestroyArgs[6] = {12, 1, 1, reinterpret_cast(SealedEvents), Immediate, 0}; + Call(Sys::SYSCALL_x64_io_getevents, AfterDestroyArgs, &AfterDestroy); + Show("io_getevents_stash_destroyed_in_flight", AfterDestroyArgs[1] == 1 && AfterDestroyArgs[2] == 1 && FinishSyscallArguments(0, &AfterDestroy) == 0); + std::vector FullStash(65536); + ArgumentStorage Filling; + uint64_t FillingArgs[6] = {31, 1, FullStash.size(), reinterpret_cast(FullStash.data()), 0, 0}; + Call(Sys::SYSCALL_x64_io_getevents, FillingArgs, &Filling); + ArgumentStorage Contended; + uint64_t ContendedArgs[6] = {31, 1, 1, reinterpret_cast(SealedEvents), 0, 0}; + Call(Sys::SYSCALL_x64_io_getevents, ContendedArgs, &Contended); + Show("io_getevents_stash_blocking_kept", FillingArgs[2] == FullStash.size() && ContendedArgs[1] == 1 && ContendedArgs[2] == 1); + FinishSyscallArguments(0, &Contended); + FinishSyscallArguments(0, &Filling); + ArgumentStorage Uncrowded; + uint64_t UncrowdedArgs[6] = {31, 1, 1, reinterpret_cast(SealedEvents), 0, 0}; + Call(Sys::SYSCALL_x64_io_getevents, UncrowdedArgs, &Uncrowded); + Show("io_getevents_stash_reserve_released", UncrowdedArgs[1] == 1 && UncrowdedArgs[2] == 1); + FinishSyscallArguments(0, &Uncrowded); + mprotect(SealedEvents, Page, PROT_READ | PROT_WRITE); + ArgumentStorage Owned; + uint64_t OwnedArgs[6] = {32, 1, 1, reinterpret_cast(SealedEvents), 0, 0}; + Call(Sys::SYSCALL_x64_io_getevents, OwnedArgs, &Owned); + const auto* OwnedBuffer = Owned.EventBuffer.data(); + const bool OwnedReady = Owned.Recovery.size() == 1; + mprotect(SealedEvents, Page, PROT_READ); + const TestEvent OwnedEvent {0x47, reinterpret_cast(&KeyB), 1, 0}; + Deliver(OwnedArgs, &OwnedEvent, sizeof(OwnedEvent)); + const auto OwnedResult = FinishSyscallArguments(1, &Owned); + mprotect(SealedEvents, Page, PROT_READ | PROT_WRITE); + const auto& OwnedState = AioContextsLocked()[32]; + Show("io_getevents_recovery_preallocated", OwnedReady && OwnedResult == static_cast(-EFAULT) && Owned.Recovery.empty() && + OwnedState.Batches.size() == 1 && OwnedState.Batches.front().data() == OwnedBuffer); + ArgumentStorage OwnedRetry; + uint64_t OwnedRetryArgs[6] = {32, 1, 1, reinterpret_cast(SealedEvents), 0, 0}; + Call(Sys::SYSCALL_x64_io_getevents, OwnedRetryArgs, &OwnedRetry); + Show("io_getevents_recovery_delivered", FinishSyscallArguments(0, &OwnedRetry) == 1 && SealedEvents[0].Data == 0x47); + uint32_t ReplacementRing[8] = {0, 128, 0, 0, 0xa10a10a1, 1, 0, 32}; + const uint64_t Replaced = reinterpret_cast(ReplacementRing); + FailReap(Replaced, {0x48, reinterpret_cast(&KeyB), 1, 0}); + const auto ReplacedCopies = IoCopyCount.load(); + ArgumentStorage OldSubmit; + uint64_t OldSubmitArgs[6] = {Replaced, 1, reinterpret_cast(Submitted), 0, 0, 0}; + Call(Sys::SYSCALL_x64_io_submit, OldSubmitArgs, &OldSubmit); + const auto OldCopy = reinterpret_cast(OldSubmitArgs[2])[0]; + FinishSyscallArguments(1, &OldSubmit); + ArgumentStorage OldDestroy; + uint64_t OldDestroyArgs[6] = {Replaced, 0, 0, 0, 0, 0}; + Call(Sys::SYSCALL_x64_io_destroy, OldDestroyArgs, &OldDestroy); + uint64_t ReplacementContext = Replaced; + ArgumentStorage Replacement; + uint64_t ReplacementArgs[6] = {128, reinterpret_cast(&ReplacementContext), 0, 0, 0, 0}; + Call(Sys::SYSCALL_x64_io_setup, ReplacementArgs, &Replacement); + FinishSyscallArguments(0, &Replacement); + ArgumentStorage NewSubmit; + uint64_t NewSubmitArgs[6] = {Replaced, 1, reinterpret_cast(Submitted), 0, 0, 0}; + Call(Sys::SYSCALL_x64_io_submit, NewSubmitArgs, &NewSubmit); + const auto NewCopy = reinterpret_cast(NewSubmitArgs[2])[0]; + FinishSyscallArguments(1, &NewSubmit); + ArgumentStorage StaleReap; + uint64_t StaleReapArgs[6] = {Replaced, 1, 1, reinterpret_cast(SealedEvents), 0, 0}; + Call(Sys::SYSCALL_x64_io_getevents, StaleReapArgs, &StaleReap); + const bool StaleSkipped = StaleReapArgs[1] == 1 && StaleReapArgs[2] == 1; + FinishSyscallArguments(0, &StaleReap); + FailReap(Replaced, {0x49, reinterpret_cast(&KeyB), 1, 0}); + FinishSyscallArguments(0, &OldDestroy); + Show("io_destroy_replacement_copies_kept", StaleSkipped && IoCopyCount.load() - ReplacedCopies == 1 && OldCopy != NewCopy && + !FindIoCopyLocked(OldCopy) && FindIoCopyLocked(NewCopy)); + ArgumentStorage ReplacementRetry; + uint64_t ReplacementRetryArgs[6] = {Replaced, 1, 1, reinterpret_cast(SealedEvents), 0, 0}; + Call(Sys::SYSCALL_x64_io_getevents, ReplacementRetryArgs, &ReplacementRetry); + Show("io_destroy_replacement_stash_kept", FinishSyscallArguments(0, &ReplacementRetry) == 1 && SealedEvents[0].Data == 0x49); + ArgumentStorage NewDestroy; + uint64_t NewDestroyArgs[6] = {Replaced, 0, 0, 0, 0, 0}; + Call(Sys::SYSCALL_x64_io_destroy, NewDestroyArgs, &NewDestroy); + FinishSyscallArguments(0, &NewDestroy); + Show("io_destroy_replacement_released", IoCopyCount.load() - ReplacedCopies + (FindIoCopyLocked(NewCopy) != nullptr)); + uint32_t WakeRing[8] = {0, 128, 0, 0, 0xa10a10a1, 1, 0, 32}; + const uint64_t Woken = reinterpret_cast(WakeRing); + uint64_t WakeContext = Woken; + ArgumentStorage WakeSetup; + uint64_t WakeSetupArgs[6] = {128, reinterpret_cast(&WakeContext), 0, 0, 0, 0}; + Call(Sys::SYSCALL_x64_io_setup, WakeSetupArgs, &WakeSetup); + const bool SetupPrivate = WakeSetupArgs[1] == reinterpret_cast(&WakeSetup.SetupId); + FinishSyscallArguments(0, &WakeSetup); + const auto WakeGeneration = AioContextsLocked()[Woken].Generation; + ArgumentStorage WakeRejected; + uint64_t WakeRejectedArgs[6] = {Woken, 1, 1, reinterpret_cast(SealedEvents), 0, 0}; + Call(Sys::SYSCALL_x64_io_getevents, WakeRejectedArgs, &WakeRejected); + FinishSyscallArguments(static_cast(-EINVAL), &WakeRejected); + Show("io_setup_generation_kept", SetupPrivate && WakeGeneration != 0 && AioContextsLocked().count(Woken) == 1 && + AioContextsLocked()[Woken].Generation == WakeGeneration && AioContextsLocked()[Woken].Live); + const uint64_t EventWords = sizeof(TestEvent) / sizeof(uint64_t); + const int ReapsBefore = AioReaps; + ArgumentStorage Blocked; + uint64_t BlockedArgs[6] = {Woken, 2, 2, reinterpret_cast(SealedEvents), 0, 0}; + Call(Sys::SYSCALL_x64_io_getevents, BlockedArgs, &Blocked); + Show("io_getevents_blocking_sliced", Blocked.Blocking && BlockedArgs[1] == 2 && BlockedArgs[2] == 2 && + BlockedArgs[4] == reinterpret_cast(Blocked.Wait) && Blocked.Wait[0] == 0 && Blocked.Wait[1] == 20000000 && Blocked.Deadline < 0); + ArgumentStorage StashPair; + uint64_t StashPairArgs[6] = {Woken, 2, 2, reinterpret_cast(SealedEvents), 0, 0}; + Call(Sys::SYSCALL_x64_io_getevents, StashPairArgs, &StashPair); + mprotect(SealedEvents, Page, PROT_READ); + const TestEvent StashPairEvents[2] = {{0x4a, reinterpret_cast(&KeyB), 1, 0}, {0x4b, reinterpret_cast(&KeyC), 1, 0}}; + Deliver(StashPairArgs, StashPairEvents, sizeof(StashPairEvents)); + const auto StashPairResult = FinishSyscallArguments(2, &StashPair); + mprotect(SealedEvents, Page, PROT_READ | PROT_WRITE); + Show("io_getevents_slice_collects_stash", StashPairResult == static_cast(-EFAULT) && FinishSyscallArguments(0, &Blocked) == 2 && + AioReaps == ReapsBefore && SealedEvents[0].Data == 0x4a && SealedEvents[1].Data == 0x4b && + SealedEvents[1].Object == reinterpret_cast(&KeyC)); + ArgumentStorage Waiting; + uint64_t WaitingArgs[6] = {Woken, 1, 1, reinterpret_cast(SealedEvents), 0, 0}; + Call(Sys::SYSCALL_x64_io_getevents, WaitingArgs, &Waiting); + bool SiblingStashed = false; + AioReapHook = [&](const uint64_t* Words) -> long { + SiblingStashed = Words[1] == Woken && Words[2] == 1 && Words[3] == 1 && Words[4] == reinterpret_cast(Waiting.EventBuffer.data()) && + Words[5] == reinterpret_cast(Waiting.Wait) && Waiting.Wait[1] == 20000000 && + FailReap(Woken, {0x4c, reinterpret_cast(&KeyB), 1, 0}) == static_cast(-EFAULT); + return 0; + }; + const auto WaitingResult = FinishSyscallArguments(0, &Waiting); + AioReapHook = nullptr; + Show("io_getevents_slice_without_notification", SiblingStashed && WaitingResult == 1 && AioReaps == ReapsBefore + 1 && + AioReapArgs[0] == SYS_io_getevents && SealedEvents[0].Data == 0x4c); + ArgumentStorage Gathering; + uint64_t GatheringArgs[6] = {Woken, 3, 3, reinterpret_cast(SealedEvents), 0, 0}; + Call(Sys::SYSCALL_x64_io_getevents, GatheringArgs, &Gathering); + const TestEvent Trickle[3] = {{0x51, reinterpret_cast(&KeyA), 1, 0}, {0x52, reinterpret_cast(&KeyB), 1, 0}, + {0x53, reinterpret_cast(&KeyC), 1, 0}}; + Deliver(GatheringArgs, &Trickle[0], sizeof(TestEvent)); + int Waits = 0; + bool Remaining = true; + AioReapHook = [&](const uint64_t* Words) -> long { + ++Waits; + if (Waits == 1) { + Remaining = Remaining && Words[2] == 2 && Words[3] == 2 && Words[4] == reinterpret_cast(Gathering.EventBuffer.data() + EventWords); + return 0; + } + const uint64_t Have = Waits == 2 ? 1 : 2; + Remaining = Remaining && Words[2] == 3 - Have && Words[3] == 3 - Have && + Words[4] == reinterpret_cast(Gathering.EventBuffer.data() + Have * EventWords); + std::memcpy(reinterpret_cast(Words[4]), &Trickle[Have], sizeof(TestEvent)); + return 1; + }; + const auto GatheringResult = FinishSyscallArguments(1, &Gathering); + AioReapHook = nullptr; + Show("io_getevents_slices_accumulate", GatheringResult == 3 && Waits == 3 && Remaining && SealedEvents[0].Data == 0x51 && + SealedEvents[1].Data == 0x52 && SealedEvents[2].Data == 0x53 && SealedEvents[2].Object == reinterpret_cast(&KeyC)); + ArgumentStorage Interrupt; + uint64_t InterruptArgs[6] = {Woken, 1, 1, reinterpret_cast(SealedEvents), 0, 0}; + Call(Sys::SYSCALL_x64_io_getevents, InterruptArgs, &Interrupt); + const int ReapsInterrupt = AioReaps; + Show("io_getevents_slice_host_eintr", FinishSyscallArguments(0, &Interrupt) == static_cast(-EINTR) && AioReaps == ReapsInterrupt + 1); + FEX::HLE::TestThread.SignalInfo.DeferredSignalFrames.push_back(SIGUSR1); + ArgumentStorage Signalled; + uint64_t SignalledArgs[6] = {Woken, 1, 1, reinterpret_cast(SealedEvents), 0, 0}; + Call(Sys::SYSCALL_x64_io_getevents, SignalledArgs, &Signalled); + const int ReapsSignalled = AioReaps; + const auto SignalledResult = FinishSyscallArguments(0, &Signalled); + ArgumentStorage SignalledSome; + uint64_t SignalledSomeArgs[6] = {Woken, 2, 2, reinterpret_cast(SealedEvents), 0, 0}; + Call(Sys::SYSCALL_x64_io_getevents, SignalledSomeArgs, &SignalledSome); + Deliver(SignalledSomeArgs, &Trickle[1], sizeof(TestEvent)); + const auto SignalledSomeResult = FinishSyscallArguments(1, &SignalledSome); + FEX::HLE::TestThread.SignalInfo.DeferredSignalFrames.clear(); + Show("io_getevents_slice_deferred_signal", SignalledResult == static_cast(-EINTR) && SignalledSomeResult == 1 && + AioReaps == ReapsSignalled && SealedEvents[0].Data == 0x52); + ArgumentStorage Polled; + uint64_t PolledArgs[6] = {Woken, 1, 1, reinterpret_cast(SealedEvents), Immediate, 0}; + Call(Sys::SYSCALL_x64_io_getevents, PolledArgs, &Polled); + const int ReapsPolled = AioReaps; + Show("io_getevents_zero_timeout", PolledArgs[4] == reinterpret_cast(Polled.Wait) && Polled.Wait[0] == 0 && Polled.Wait[1] == 0 && + FinishSyscallArguments(0, &Polled) == 0 && AioReaps == ReapsPolled); + int64_t ShortWait[2] = {0, 1000000}; + ArgumentStorage Timed; + uint64_t TimedArgs[6] = {Woken, 1, 1, reinterpret_cast(SealedEvents), reinterpret_cast(ShortWait), 0}; + const auto TimedStart = std::chrono::steady_clock::now(); + Call(Sys::SYSCALL_x64_io_getevents, TimedArgs, &Timed); + const bool TimedFirst = Timed.Wait[0] == 0 && Timed.Wait[1] > 0 && Timed.Wait[1] <= 1000000; + bool TimedBounded = true; + AioReapHook = [&](const uint64_t* Words) -> long { + const auto* Wait = reinterpret_cast(Words[5]); + TimedBounded = TimedBounded && Wait[0] == 0 && Wait[1] > 0 && Wait[1] <= 1000000; + return 0; + }; + const auto TimedResult = FinishSyscallArguments(0, &Timed); + const auto TimedTook = std::chrono::steady_clock::now() - TimedStart; + AioReapHook = nullptr; + Show("io_getevents_timeout_returns_empty", TimedFirst && TimedBounded && TimedResult == 0 && TimedTook >= std::chrono::milliseconds(1) && + ShortWait[0] == 0 && ShortWait[1] == 1000000); + int64_t LongWait[2] = {5, 0}; + uint64_t MaskWords[2] = {0, 8}; + ArgumentStorage Masked; + uint64_t MaskedArgs[6] = {Woken, 1, 1, reinterpret_cast(SealedEvents), reinterpret_cast(LongWait), reinterpret_cast(MaskWords)}; + Call(Sys::SYSCALL_x64_io_pgetevents, MaskedArgs, &Masked); + const bool MaskedSliced = Masked.Wait[0] == 0 && Masked.Wait[1] == 20000000 && Masked.Deadline > 0; + AioReapHook = [&](const uint64_t* Words) -> long { + std::memcpy(reinterpret_cast(Words[4]), &Trickle[2], sizeof(TestEvent)); + return 1; + }; + const auto MaskedResult = FinishSyscallArguments(0, &Masked); + AioReapHook = nullptr; + Show("io_pgetevents_slices_keep_mask", MaskedSliced && MaskedResult == 1 && AioReapArgs[0] == SYS_io_pgetevents && + AioReapArgs[6] == reinterpret_cast(MaskWords) && SealedEvents[0].Data == 0x53); + int64_t BadWait[2] = {0, 2000000000}; + ArgumentStorage Unsliced; + uint64_t UnslicedArgs[6] = {Woken, 1, 1, reinterpret_cast(SealedEvents), reinterpret_cast(BadWait), 0}; + Call(Sys::SYSCALL_x64_io_getevents, UnslicedArgs, &Unsliced); + const int ReapsUnsliced = AioReaps; + Show("io_getevents_odd_timeout_native", !Unsliced.Blocking && UnslicedArgs[1] == 1 && UnslicedArgs[4] == reinterpret_cast(BadWait) && + FinishSyscallArguments(0, &Unsliced) == 0 && AioReaps == ReapsUnsliced); + uint64_t* Published = static_cast(mmap(nullptr, Page, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)); + uint32_t LostRing[8] = {0, 128, 0, 0, 0xa10a10a1, 1, 0, 32}; + *Published = reinterpret_cast(LostRing); + ArgumentStorage Unpublished; + uint64_t UnpublishedArgs[6] = {128, reinterpret_cast(Published), 0, 0, 0, 0}; + Call(Sys::SYSCALL_x64_io_setup, UnpublishedArgs, &Unpublished); + mprotect(Published, Page, PROT_READ); + Show("io_setup_unpublished_result", FinishSyscallArguments(0, &Unpublished)); + Show("io_setup_unpublished_destroyed", AioDestroyed == reinterpret_cast(LostRing) && + AioContextsLocked().count(reinterpret_cast(LostRing)) == 0); + mprotect(Published, Page, PROT_READ | PROT_WRITE); + uint32_t ReusedRing[8] = {0, 128, 0, 0, 0xa10a10a1, 1, 0, 32}; + const uint64_t Reused = reinterpret_cast(ReusedRing); + *Published = Reused; + uint64_t ReusedGeneration = 0; + AioDestroyHook = [&](uint64_t Ring) { ReusedGeneration = BeginContext(Ring); }; + ArgumentStorage ReusedSetup; + uint64_t ReusedSetupArgs[6] = {128, reinterpret_cast(Published), 0, 0, 0, 0}; + Call(Sys::SYSCALL_x64_io_setup, ReusedSetupArgs, &ReusedSetup); + mprotect(Published, Page, PROT_READ); + const auto ReusedResult = FinishSyscallArguments(0, &ReusedSetup); + AioDestroyHook = nullptr; + Show("io_setup_rollback_keeps_reused_context", ReusedResult == static_cast(-EFAULT) && ReusedGeneration != 0 && + AioContextsLocked().count(Reused) == 1 && AioContextsLocked()[Reused].Generation == ReusedGeneration); + ReleaseContext(Reused, ReusedGeneration); + mprotect(Published, Page, PROT_NONE); + ArgumentStorage UnreadableSetup; + uint64_t UnreadableArgs[6] = {128, reinterpret_cast(Published), 0, 0, 0, 0}; + Show("io_setup_unreadable_output_faults", Call(Sys::SYSCALL_x64_io_setup, UnreadableArgs, &UnreadableSetup) == static_cast(-EFAULT) && + UnreadableArgs[1] == reinterpret_cast(Published) && UnreadableSetup.SetupContext == 0 && + FinishSyscallArguments(static_cast(-EFAULT), &UnreadableSetup) == static_cast(-EFAULT)); + munmap(Published, Page); + ArgumentStorage BogusReap; + uint64_t BogusReapArgs[6] = {0x5bad, 1, 1, reinterpret_cast(SealedEvents), 0, 0}; + Call(Sys::SYSCALL_x64_io_getevents, BogusReapArgs, &BogusReap); + FinishSyscallArguments(static_cast(-EINVAL), &BogusReap); + Show("io_getevents_invalid_context_forgotten", AioContextsLocked().count(0x5bad)); + mprotect(SealedEvents, Page, PROT_READ | PROT_WRITE); + ArgumentStorage Pending; + uint64_t PendingArgs[6] = {33, 1, 1, reinterpret_cast(SealedEvents), 0, 0}; + Call(Sys::SYSCALL_x64_io_getevents, PendingArgs, &Pending); + ArgumentStorage Rejected; + uint64_t RejectedArgs[6] = {33, 1, 1, reinterpret_cast(SealedEvents), 0, 0}; + Call(Sys::SYSCALL_x64_io_pgetevents, RejectedArgs, &Rejected); + FinishSyscallArguments(static_cast(-EINVAL), &Rejected); + mprotect(SealedEvents, Page, PROT_READ); + const TestEvent PendingEvent {0x4a, reinterpret_cast(&KeyB), 1, 0}; + Deliver(PendingArgs, &PendingEvent, sizeof(PendingEvent)); + FinishSyscallArguments(1, &Pending); + mprotect(SealedEvents, Page, PROT_READ | PROT_WRITE); + ArgumentStorage PendingRetry; + uint64_t PendingRetryArgs[6] = {33, 1, 1, reinterpret_cast(SealedEvents), 0, 0}; + Call(Sys::SYSCALL_x64_io_getevents, PendingRetryArgs, &PendingRetry); + Show("io_getevents_rejected_sibling_kept", FinishSyscallArguments(0, &PendingRetry) == 1 && SealedEvents[0].Data == 0x4a); + FailReap(10, {0x33, reinterpret_cast(&KeyC), 1, 0}); + ArgumentStorage StashDestroy; + uint64_t StashDestroyArgs[6] = {10, 0, 0, 0, 0, 0}; + Call(Sys::SYSCALL_x64_io_destroy, StashDestroyArgs, &StashDestroy); + FinishSyscallArguments(0, &StashDestroy); + ArgumentStorage DestroyedReap; + uint64_t DestroyedReapArgs[6] = {10, 1, 1, reinterpret_cast(SealedEvents), Immediate, 0}; + Call(Sys::SYSCALL_x64_io_getevents, DestroyedReapArgs, &DestroyedReap); + Show("io_getevents_stash_destroyed", DestroyedReapArgs[2] == 1 && FinishSyscallArguments(0, &DestroyedReap) == 0); + ArgumentStorage TripleFailed; + uint64_t TripleFailedArgs[6] = {4, 3, 3, reinterpret_cast(SealedEvents), 0, 0}; + Call(Sys::SYSCALL_x64_io_getevents, TripleFailedArgs, &TripleFailed); + mprotect(SealedEvents, Page, PROT_READ); + const TestEvent Triple[3] = {{0x31, reinterpret_cast(&KeyA), 1, 0}, {0x32, reinterpret_cast(&KeyB), 1, 0}, + {0x33, reinterpret_cast(&KeyC), 1, 0}}; + Deliver(TripleFailedArgs, Triple, sizeof(Triple)); + Show("io_getevents_stash_triple_failed", FinishSyscallArguments(3, &TripleFailed)); + mprotect(SealedEvents, Page, PROT_READ | PROT_WRITE); + ArgumentStorage SealedRetry; + uint64_t SealedRetryArgs[6] = {4, 1, 1, reinterpret_cast(SealedEvents), 0, 0}; + Call(Sys::SYSCALL_x64_io_getevents, SealedRetryArgs, &SealedRetry); + mprotect(SealedEvents, Page, PROT_READ); + Show("io_getevents_stash_retry_failed", FinishSyscallArguments(0, &SealedRetry)); + mprotect(SealedEvents, Page, PROT_READ | PROT_WRITE); + ArgumentStorage OrderedReap; + uint64_t OrderedReapArgs[6] = {4, 3, 3, reinterpret_cast(SealedEvents), 0, 0}; + Call(Sys::SYSCALL_x64_io_getevents, OrderedReapArgs, &OrderedReap); + Show("io_getevents_stash_ordered_result", FinishSyscallArguments(0, &OrderedReap)); + Show("io_getevents_stash_ordered", SealedEvents[0].Data == 0x31 && SealedEvents[1].Data == 0x32 && SealedEvents[2].Data == 0x33 && + SealedEvents[2].Object == reinterpret_cast(&KeyC)); + static TestEvent ManyEvents[100]; + for (uint64_t i = 0; i < 100; ++i) { + ManyEvents[i] = {0x1000 + i, reinterpret_cast(&KeyA), 1, 0}; + } + ArgumentStorage ManyFailed; + uint64_t ManyFailedArgs[6] = {4, 100, 100, reinterpret_cast(SealedEvents), 0, 0}; + Call(Sys::SYSCALL_x64_io_getevents, ManyFailedArgs, &ManyFailed); + mprotect(SealedEvents, Page, PROT_READ); + Deliver(ManyFailedArgs, ManyEvents, sizeof(ManyEvents)); + Show("io_getevents_stash_many_failed", FinishSyscallArguments(100, &ManyFailed)); + mprotect(SealedEvents, Page, PROT_READ | PROT_WRITE); + ArgumentStorage ManyRetry; + uint64_t ManyRetryArgs[6] = {4, 100, 100, reinterpret_cast(SealedEvents), 0, 0}; + Call(Sys::SYSCALL_x64_io_getevents, ManyRetryArgs, &ManyRetry); + bool ManyOrdered = FinishSyscallArguments(0, &ManyRetry) == 100; + for (uint64_t i = 0; i < 100; ++i) { + ManyOrdered = ManyOrdered && SealedEvents[i].Data == 0x1000 + i; + } + Show("io_getevents_stash_many_kept", ManyOrdered); + for (uint64_t Context = 100; Context < 120; ++Context) { + FailReap(Context, {Context, reinterpret_cast(&KeyA), 1, 0}); + } + bool EveryContext = true; + for (uint64_t Context = 100; Context < 120; ++Context) { + ArgumentStorage ContextRetry; + uint64_t ContextRetryArgs[6] = {Context, 1, 1, reinterpret_cast(SealedEvents), 0, 0}; + Call(Sys::SYSCALL_x64_io_getevents, ContextRetryArgs, &ContextRetry); + EveryContext = EveryContext && FinishSyscallArguments(0, &ContextRetry) == 1 && SealedEvents[0].Data == Context; + } + Show("io_getevents_stash_every_context", EveryContext); + TestIocb DirectBlock = ReadBlock; + uint64_t DirectList[1] = {reinterpret_cast(&DirectBlock)}; + auto SubmitDirect = [&] { + ArgumentStorage DirectSubmit; + uint64_t DirectSubmitArgs[6] = {11, 1, reinterpret_cast(DirectList), 0, 0, 0}; + Call(Sys::SYSCALL_x64_io_submit, DirectSubmitArgs, &DirectSubmit); + const auto Sent = reinterpret_cast(DirectSubmitArgs[2])[0]; + FinishSyscallArguments(1, &DirectSubmit); + return Sent; + }; + const auto DirectBefore = IoCopyCount.load(); + const auto DirectSent = SubmitDirect(); + mprotect(SealedEvents, Page, PROT_READ); + ArgumentStorage DirectReap; + uint64_t DirectReapArgs[6] = {11, 1, 1, reinterpret_cast(SealedEvents), 0, 0}; + Call(Sys::SYSCALL_x64_io_getevents, DirectReapArgs, &DirectReap); + Show("io_getevents_unwritable_first_staged", DirectReapArgs[3] == reinterpret_cast(DirectReap.EventBuffer.data()) && DirectReapArgs[2] == 1); + mprotect(SealedEvents, Page, PROT_READ | PROT_WRITE); + const TestEvent DirectEvent {0x21, DirectSent, 64, 0}; + Deliver(DirectReapArgs, &DirectEvent, sizeof(DirectEvent)); + Show("io_getevents_late_writable_result", FinishSyscallArguments(1, &DirectReap)); + Show("io_getevents_late_writable_object", SealedEvents[0].Object == reinterpret_cast(&DirectBlock)); + Show("io_getevents_late_writable_released", IoCopyCount.load() - DirectBefore); + const auto HiddenSent = SubmitDirect(); + SealedEvents[0] = {}; + mprotect(SealedEvents, Page, PROT_READ); + ArgumentStorage HiddenReap; + uint64_t HiddenReapArgs[6] = {11, 1, 1, reinterpret_cast(SealedEvents), 0, 0}; + Call(Sys::SYSCALL_x64_io_getevents, HiddenReapArgs, &HiddenReap); + mprotect(SealedEvents, Page, PROT_READ | PROT_WRITE); + const TestEvent HiddenEvent {0x22, HiddenSent, 64, 0}; + Deliver(HiddenReapArgs, &HiddenEvent, sizeof(HiddenEvent)); + mprotect(SealedEvents, Page, PROT_NONE); + Show("io_getevents_hidden_result", FinishSyscallArguments(1, &HiddenReap)); + mprotect(SealedEvents, Page, PROT_READ | PROT_WRITE); + Show("io_getevents_hidden_no_private", SealedEvents[0].Object == 0); + Show("io_getevents_hidden_released", IoCopyCount.load() - DirectBefore); + ArgumentStorage HiddenRetry; + uint64_t HiddenRetryArgs[6] = {11, 1, 1, reinterpret_cast(SealedEvents), 0, 0}; + Call(Sys::SYSCALL_x64_io_getevents, HiddenRetryArgs, &HiddenRetry); + Show("io_getevents_hidden_retry", FinishSyscallArguments(0, &HiddenRetry) == 1 && SealedEvents[0].Data == 0x22 && + SealedEvents[0].Object == reinterpret_cast(&DirectBlock)); + ArgumentStorage DirectDestroy; + uint64_t DirectDestroyArgs[6] = {11, 0, 0, 0, 0, 0}; + Call(Sys::SYSCALL_x64_io_destroy, DirectDestroyArgs, &DirectDestroy); + FinishSyscallArguments(0, &DirectDestroy); + munmap(SealedEvents, Page); + munmap(SealedEvents, Page); + ArgumentStorage WrappedReap; + uint64_t WrappedReapArgs[6] = {4, 1, 1024, 0xFFFF'FFFF'FFFF'F000ULL, 0, 0}; + Call(Sys::SYSCALL_x64_io_getevents, WrappedReapArgs, &WrappedReap); + Show("io_getevents_wrapped_staged", WrappedReapArgs[3] == reinterpret_cast(WrappedReap.EventBuffer.data()) && WrappedReapArgs[2] == 1 && + WrappedReap.EventBuffer.size() == sizeof(TestEvent) / sizeof(uint64_t)); + Show("io_getevents_wrapped_result", FinishSyscallArguments(static_cast(-EFAULT), &WrappedReap)); + auto* EdgeEvents = static_cast(mmap(nullptr, 2 * Page, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)); + mprotect(EdgeEvents + Page, Page, PROT_READ); + ArgumentStorage EdgeReap; + uint64_t EdgeReapArgs[6] = {4, 3, 4, reinterpret_cast(EdgeEvents + Page - 2 * sizeof(TestEvent)), 0, 0}; + Call(Sys::SYSCALL_x64_io_getevents, EdgeReapArgs, &EdgeReap); + Show("io_getevents_writable_prefix", EdgeReapArgs[2]); + Show("io_getevents_writable_min", EdgeReapArgs[1]); + Show("io_getevents_writable_buffer", EdgeReap.EventBuffer.size() * sizeof(uint64_t) / sizeof(TestEvent)); + munmap(EdgeEvents, 2 * Page); + uint32_t Ring[8] = {0, 128, 0, 0, 0xa10a10a1, 1, 0, 32}; + uint64_t RingContext = reinterpret_cast(Ring); + ArgumentStorage Setup; + uint64_t SetupArgs[6] = {128, reinterpret_cast(&RingContext), 0, 0, 0, 0}; + Call(Sys::SYSCALL_x64_io_setup, SetupArgs, &Setup); + FinishSyscallArguments(0, &Setup); + Show("io_setup_magic", Ring[4]); + Show("io_setup_header_kept", Ring[0] == 0 && Ring[1] == 128 && Ring[2] == 0 && Ring[3] == 0 && Ring[5] == 1 && Ring[6] == 0 && Ring[7] == 32); + uint32_t KeptRing[8] = {0, 128, 0, 0, 0xa10a10a1, 1, 0, 32}; + uint64_t KeptContext = reinterpret_cast(KeptRing); + ArgumentStorage FailedSetup; + uint64_t FailedSetupArgs[6] = {128, reinterpret_cast(&KeptContext), 0, 0, 0, 0}; + Call(Sys::SYSCALL_x64_io_setup, FailedSetupArgs, &FailedSetup); + FinishSyscallArguments(static_cast(-EINVAL), &FailedSetup); + Show("io_setup_failed_magic", KeptRing[4]); + + TestEvent Completions[2] = {{7, Base + 1536, 16, 0}, {8, Base + 1536, 16, 0}}; + ArgumentStorage Reap; + uint64_t ReapArgs[6] = {1, 1, 2, reinterpret_cast(Completions), 0, 0}; + Show("io_getevents_result", Call(Sys::SYSCALL_x64_io_getevents, ReapArgs, &Reap)); + Deliver(ReapArgs, Completions, sizeof(Completions)); + FinishSyscallArguments(1, &Reap); + Show("io_getevents_object", Completions[0].Object - Single); + Show("io_getevents_unreported", Completions[1].Object - Base); + + uint64_t Pages[2] = {Single + 16, Low}; + int PageStatus[2] = {}; + ArgumentStorage Move; + uint64_t MoveArgs[6] = {0, 2, reinterpret_cast(Pages), 0, reinterpret_cast(PageStatus), 0}; + Show("move_pages_result", Call(Sys::SYSCALL_x64_move_pages, MoveArgs, &Move)); + Show("move_pages_copied", MoveArgs[2] != reinterpret_cast(Pages)); + Show("move_pages_first", reinterpret_cast(MoveArgs[2])[0] - Base); + Show("move_pages_second", reinterpret_cast(MoveArgs[2])[1] == Low); + Show("move_pages_guest_list", Pages[0] - Single); + ArgumentStorage Remote; + uint64_t RemoteArgs[6] = {1, 2, reinterpret_cast(Pages), 0, reinterpret_cast(PageStatus), 0}; + Show("move_pages_remote_result", Call(Sys::SYSCALL_x64_move_pages, RemoteArgs, &Remote)); + Show("move_pages_remote_kept", RemoteArgs[2] == reinterpret_cast(Pages)); + + uint32_t LowWord = 0; + uint64_t Waiters[2][3] = {{0, Single + 64, 2}, {0, reinterpret_cast(&LowWord), 2}}; + ArgumentStorage Wait; + uint64_t WaitArgs[6] = {reinterpret_cast(Waiters), 2, 0, 0, 1, 0}; + Show("futex_waitv_result", Call(Sys::SYSCALL_x64_futex_waitv, WaitArgs, &Wait)); + Show("futex_waitv_copied", WaitArgs[0] != reinterpret_cast(Waiters)); + Show("futex_waitv_first", reinterpret_cast(WaitArgs[0])[1] - Base); + Show("futex_waitv_second", reinterpret_cast(WaitArgs[0])[4] == reinterpret_cast(&LowWord)); + Show("futex_waitv_guest", Waiters[0][1] - Single); + uint64_t Straddling[1][3] = {{0, Split + Page - 2, 2}}; + ArgumentStorage WaitBad; + uint64_t WaitBadArgs[6] = {reinterpret_cast(Straddling), 1, 0, 0, 1, 0}; + Show("futex_waitv_split_result", Call(Sys::SYSCALL_x64_futex_waitv, WaitBadArgs, &WaitBad)); + uint64_t Requeue[2][3] = {{0, Single + 64, 2}, {0, Single + 128, 2}}; + ArgumentStorage RequeueStorage; + uint64_t RequeueArgs[6] = {reinterpret_cast(Requeue), 0, 1, 1, 0, 0}; + Show("futex_requeue_result", Call(Sys::SYSCALL_x64_futex_requeue, RequeueArgs, &RequeueStorage)); + Show("futex_requeue_second", reinterpret_cast(RequeueArgs[0])[4] - Base); + + const uint64_t Mapped = 0x780000000000ULL; + const int Anonymous = MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED; + Show("map_result", Map(Mapped, 2 * Page, PROT_READ | PROT_WRITE, Anonymous, -1, 0) - Mapped); + const uint32_t MappedEntries = Count.load(); + Show("map_unmap", Unmap(Mapped + Page, Page)); + Show("map_again", Map(Mapped + Page, Page, PROT_READ | PROT_WRITE, Anonymous, -1, 0) - Mapped); + FindLocked(Mapped, &Part); + Show("map_merged_size", Part.Size); + Show("map_merged_entries", Count.load() - MappedEntries); + Show("map_unmap_again", Unmap(Mapped + Page, Page)); + Show("map_readonly", Map(Mapped + Page, Page, PROT_READ, Anonymous, -1, 0) - Mapped); + FindLocked(Mapped, &Part); + Show("map_readonly_size", Part.Size); + Show("map_readonly_entries", Count.load() - MappedEntries); + + auto* Order = static_cast(mmap(nullptr, 5 * Page, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)); + const uint64_t OrderHost = reinterpret_cast(Order); + const uint64_t Ordered = 0x770000000000ULL; + const uint32_t OrderEntries = Count.load(); + AddEntry(Ordered + Page, Page, OrderHost + Page, false, PROT_READ); + AddEntry(Ordered + 3 * Page, Page, OrderHost + 4 * Page, false, PROT_READ); + AddEntry(Ordered, Page, OrderHost, false, PROT_READ); + AddEntry(Ordered + 2 * Page, Page, OrderHost + 3 * Page, false, PROT_READ); + Show("slot_order_restore", Protect(Ordered, 4 * Page, PROT_READ | PROT_WRITE)); + Show("slot_order_entries", Count.load() - OrderEntries); + FindLocked(Ordered + 2 * Page, &Part); + Show("slot_order_second_size", Part.Size); + + ArgumentStorage Widths; + uint64_t GroupsWide[6] = {(1ULL << 32) + 1, Single + Page - 4, 0, 0, 0, 0}; + Show("getgroups_wide_result", Call(Sys::SYSCALL_x64_getgroups, GroupsWide, &Widths)); + Show("getgroups_wide_list", GroupsWide[1] - Base); + uint64_t GroupsNegative[6] = {0xffffffffULL, Single + Page - 4, 0, 0, 0, 0}; + Show("getgroups_negative_result", Call(Sys::SYSCALL_x64_getgroups, GroupsNegative, &Widths)); + uint64_t GroupsLarge[6] = {(1ULL << 32) + 2, Single + Page - 4, 0, 0, 0, 0}; + Show("getgroups_large_result", Call(Sys::SYSCALL_x64_getgroups, GroupsLarge, &Widths)); + uint64_t PollWide[6] = {Single + Page - 8, (1ULL << 32) + 1, 0, 0, 0, 0}; + Show("poll_wide_result", Call(Sys::SYSCALL_x64_poll, PollWide, &Widths)); + uint64_t EpollNegative[6] = {3, Single + Page - 12, 0xffffffffULL, 0, 0, 0}; + Show("epoll_negative_result", Call(Sys::SYSCALL_x64_epoll_wait, EpollNegative, &Widths)); + ArgumentStorage NegativeReap; + uint64_t EventsNegative[6] = {1, 1, static_cast(-1), Single, 0, 0}; + Show("io_getevents_negative_result", Call(Sys::SYSCALL_x64_io_getevents, EventsNegative, &NegativeReap)); + + struct iovec PrefixVectors[2] = {{reinterpret_cast(Single + 256), 32}, {reinterpret_cast(Split + Page - 8), 16}}; + struct mmsghdr Prefix[2] {}; + Prefix[0].msg_hdr.msg_iov = &PrefixVectors[0]; + Prefix[0].msg_hdr.msg_iovlen = 1; + Prefix[1].msg_hdr.msg_iov = &PrefixVectors[1]; + Prefix[1].msg_hdr.msg_iovlen = 1; + ArgumentStorage PrefixBatch; + uint64_t PrefixArgs[6] = {3, reinterpret_cast(Prefix), 2, 0, 0, 0}; + Show("sendmmsg_prefix_result", Call(Sys::SYSCALL_x64_sendmmsg, PrefixArgs, &PrefixBatch)); + Show("sendmmsg_prefix_count", PrefixArgs[2]); + ArgumentStorage PrefixBad; + uint64_t PrefixBadArgs[6] = {3, reinterpret_cast(&Prefix[1]), 1, 0, 0, 0}; + Show("sendmmsg_first_bad_result", Call(Sys::SYSCALL_x64_sendmmsg, PrefixBadArgs, &PrefixBad)); + auto* ApartFirst = reinterpret_cast(Backing + 3 * Page - sizeof(struct mmsghdr)); + auto* ApartSecond = reinterpret_cast(Backing + 4 * Page); + char ApartLow[32]; + struct iovec ApartVectors[2] = {{ApartLow, 11}, {ApartLow, 22}}; + *ApartFirst = {}; + ApartFirst->msg_hdr.msg_iov = &ApartVectors[0]; + ApartFirst->msg_hdr.msg_iovlen = 1; + *ApartSecond = {}; + ApartSecond->msg_hdr.msg_iov = &ApartVectors[1]; + ApartSecond->msg_hdr.msg_iovlen = 1; + ArgumentStorage ApartBatch; + uint64_t HeadersApart[6] = {static_cast(Peer), Split + Page - sizeof(struct mmsghdr), 2, 0, 0, 0}; + Show("sendmmsg_headers_apart_result", Call(Sys::SYSCALL_x64_sendmmsg, HeadersApart, &ApartBatch)); + Show("sendmmsg_headers_apart_count", HeadersApart[2]); + auto* ApartHost = reinterpret_cast(HeadersApart[1]); + Show("sendmmsg_headers_apart_first", ApartHost[0].msg_hdr.msg_iov[0].iov_len); + Show("sendmmsg_headers_apart_second", ApartHost[1].msg_hdr.msg_iov[0].iov_len); + SendCalls = 0; + ApartHost[0].msg_len = 11; + Show("sendmmsg_headers_apart_finish", FinishResult(1, &ApartBatch)); + Show("sendmmsg_headers_apart_sent", SentLengths[0]); + Show("sendmmsg_headers_apart_lengths", ApartFirst->msg_len * 0x100 + ApartSecond->msg_len); + + struct iovec MovingVector = {reinterpret_cast(Single + 256), 32}; + const uint64_t Moving = 0x760000000000ULL; + Map(Moving, Page, PROT_READ | PROT_WRITE, Anonymous, -1, 0); + uint64_t OldHost {}; + TranslateRange(Moving, Page, &OldHost); + auto* MovingHeaders = reinterpret_cast(OldHost); + MovingHeaders[0] = {}; + MovingHeaders[0].msg_hdr.msg_iov = &MovingVector; + MovingHeaders[0].msg_hdr.msg_iovlen = 1; + ArgumentStorage MovingBatch; + uint64_t MovingArgs[6] = {3, Moving, 1, 0, 0, 0}; + Show("moved_result", Call(Sys::SYSCALL_x64_sendmmsg, MovingArgs, &MovingBatch)); + reinterpret_cast(MovingArgs[1])[0].msg_len = 32; + Unmap(Moving, Page); + auto* Unrelated = static_cast(mmap(reinterpret_cast(OldHost), Page, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED_NOREPLACE, -1, 0)); + Map(Moving, Page, PROT_READ | PROT_WRITE, Anonymous, -1, 0); + uint64_t NewHost {}; + TranslateRange(Moving, Page, &NewHost); + Show("moved_finish", FinishResult(1, &MovingBatch)); + Show("moved_unrelated_placed", reinterpret_cast(Unrelated) == OldHost && NewHost != OldHost); + Show("moved_unrelated_length", Unrelated[0].msg_len); + Show("moved_new_length", reinterpret_cast(NewHost)[0].msg_len); + + const uint64_t Sealed = 0x750000000000ULL; + Map(Sealed, 2 * Page, PROT_READ | PROT_WRITE, Anonymous, -1, 0); + uint64_t SealedHost {}; + TranslateRange(Sealed, 2 * Page, &SealedHost); + auto* SealedHeaders = reinterpret_cast(SealedHost + Page - sizeof(struct mmsghdr)); + for (int i = 0; i < 3; ++i) { + SealedHeaders[i] = {}; + SealedHeaders[i].msg_hdr.msg_iov = &MovingVector; + SealedHeaders[i].msg_hdr.msg_iovlen = 1; + } + Protect(Sealed + Page, Page, PROT_READ); + ArgumentStorage SealedBatch; + uint64_t SealedArgs[6] = {static_cast(Peer), Sealed + Page - sizeof(struct mmsghdr), 3, 0, 0, 0}; + Show("sealed_result", Call(Sys::SYSCALL_x64_sendmmsg, SealedArgs, &SealedBatch)); + Show("sealed_submitted", SealedArgs[2]); + auto* SealedCopy = reinterpret_cast(SealedArgs[1]); + SealedCopy[0].msg_len = 32; + SendCalls = 0; + Show("sealed_finish", FinishResult(1, &SealedBatch)); + Show("sealed_later_sends", SendCalls); + Show("sealed_first_length", SealedHeaders[0].msg_len); + Show("sealed_second_length", SealedHeaders[1].msg_len); + Show("sealed_third_length", SealedHeaders[2].msg_len); + ArgumentStorage SealedOnly; + uint64_t SealedOnlyArgs[6] = {3, Sealed + Page, 1, 0, 0, 0}; + Show("sealed_only_result", Call(Sys::SYSCALL_x64_sendmmsg, SealedOnlyArgs, &SealedOnly)); + reinterpret_cast(SealedOnlyArgs[1])[0].msg_len = 32; + Show("sealed_only_finish", FinishResult(1, &SealedOnly)); + + ArgumentStorage Embedded; + uint8_t* SplitEnd = Backing + 3 * Page; + const uint32_t Sizes32[] = {64, 0, 72}; + const char* PerfNames[] = {"perf_attr_fits_result", "perf_attr_default_result", "perf_attr_large_result"}; + for (int i = 0; i < 3; ++i) { + std::memcpy(SplitEnd - 64 + 4, &Sizes32[i], 4); + uint64_t PerfArgs[6] = {Split + Page - 64, 0, static_cast(-1), static_cast(-1), 0, 0}; + Show(PerfNames[i], Call(Sys::SYSCALL_x64_perf_event_open, PerfArgs, &Embedded)); + } + const uint32_t SchedSizes[] = {48, 56}; + const char* SchedNames[] = {"sched_attr_fits_result", "sched_attr_large_result"}; + for (int i = 0; i < 2; ++i) { + std::memcpy(SplitEnd - 48, &SchedSizes[i], 4); + uint64_t SchedArgs[6] = {0, Split + Page - 48, 0, 0, 0, 0}; + Show(SchedNames[i], Call(Sys::SYSCALL_x64_sched_setattr, SchedArgs, &Embedded)); + } + const uint32_t CapHeader1[2] = {0x19980330, 0}; + const uint32_t CapHeader3[2] = {0x20080522, 0}; + uint64_t CapV1[6] = {reinterpret_cast(CapHeader1), Split + Page - 12, 0, 0, 0, 0}; + Show("capget_v1_result", Call(Sys::SYSCALL_x64_capget, CapV1, &Embedded)); + Show("capget_v1_data", CapV1[1] - Base); + uint64_t CapV3[6] = {reinterpret_cast(CapHeader3), Split + Page - 12, 0, 0, 0, 0}; + Show("capget_v3_result", Call(Sys::SYSCALL_x64_capget, CapV3, &Embedded)); + uint64_t CapSetV3[6] = {reinterpret_cast(CapHeader3), Split + Page - 12, 0, 0, 0, 0}; + Show("capset_v3_result", Call(Sys::SYSCALL_x64_capset, CapSetV3, &Embedded)); + uint32_t CapGuest[2] = {0x19980330, 0}; + ArgumentStorage CapCopy; + uint64_t CapCopyArgs[6] = {reinterpret_cast(CapGuest), Split + Page - 12, 0, 0, 0, 0}; + Show("capget_copy_result", Call(Sys::SYSCALL_x64_capget, CapCopyArgs, &CapCopy)); + Show("capget_copy_private", CapCopyArgs[0] != reinterpret_cast(CapGuest)); + CapGuest[0] = 0x20080522; + Show("capget_copy_version", reinterpret_cast(CapCopyArgs[0])[0]); + Show("capget_copy_finish", FinishResult(0, &CapCopy)); + Show("capget_copy_guest_version", CapGuest[0]); + uint32_t CapUnknown[2] = {0x1234, 0}; + ArgumentStorage CapInvalid; + uint64_t CapInvalidArgs[6] = {reinterpret_cast(CapUnknown), Single + 64, 0, 0, 0, 0}; + Show("capget_invalid_result", Call(Sys::SYSCALL_x64_capget, CapInvalidArgs, &CapInvalid)); + reinterpret_cast(CapInvalidArgs[0])[0] = 0x20080522; + Show("capget_invalid_finish", FinishResult(static_cast(-EINVAL), &CapInvalid)); + Show("capget_invalid_version", CapUnknown[0]); + const uint32_t HandleBytes[] = {8, 16}; + const char* HandleNames[] = {"name_to_handle_fits_result", "name_to_handle_large_result"}; + const char* OpenNames[] = {"open_by_handle_fits_result", "open_by_handle_large_result"}; + int MountId = 0; + for (int i = 0; i < 2; ++i) { + std::memcpy(SplitEnd - 16, &HandleBytes[i], 4); + uint64_t HandleArgs[6] = {static_cast(AT_FDCWD), reinterpret_cast("x"), Split + Page - 16, reinterpret_cast(&MountId), 0, 0}; + Show(HandleNames[i], Call(Sys::SYSCALL_x64_name_to_handle_at, HandleArgs, &Embedded)); + uint64_t OpenArgs[6] = {3, Split + Page - 16, 0, 0, 0, 0}; + Show(OpenNames[i], Call(Sys::SYSCALL_x64_open_by_handle_at, OpenArgs, &Embedded)); + } + const uint32_t OversizedHandle = 1000; + std::memcpy(SplitEnd - 4, &OversizedHandle, 4); + uint64_t HandleHeaderSplit[6] = {static_cast(AT_FDCWD), reinterpret_cast("x"), Split + Page - 4, reinterpret_cast(&MountId), 0, 0}; + Show("name_to_handle_header_split_result", Call(Sys::SYSCALL_x64_name_to_handle_at, HandleHeaderSplit, &Embedded)); + uint64_t OpenHeaderSplit[6] = {3, Split + Page - 4, 0, 0, 0, 0}; + Show("open_by_handle_header_split_result", Call(Sys::SYSCALL_x64_open_by_handle_at, OpenHeaderSplit, &Embedded)); + std::memcpy(SplitEnd - 8, &OversizedHandle, 4); + uint64_t OpenHeaderFits[6] = {3, Split + Page - 8, 0, 0, 0, 0}; + Show("open_by_handle_header_fits_result", Call(Sys::SYSCALL_x64_open_by_handle_at, OpenHeaderFits, &Embedded)); + const uint32_t RequestSizes[] = {24, 32}; + const char* RequestNames[] = {"statmount_fits_result", "statmount_large_result"}; + for (int i = 0; i < 2; ++i) { + std::memcpy(SplitEnd - 24, &RequestSizes[i], 4); + uint64_t RequestArgs[6] = {Split + Page - 24, 0, 0, 0, 0, 0}; + Show(RequestNames[i], Call(Sys::SYSCALL_x64_statmount, RequestArgs, &Embedded)); + } + uint64_t PathRule[6] = {3, 1, Split + Page - 12, 0, 0, 0}; + Show("landlock_path_result", Call(Sys::SYSCALL_x64_landlock_add_rule, PathRule, &Embedded)); + uint64_t PortRule[6] = {3, 2, Split + Page - 12, 0, 0, 0}; + Show("landlock_port_result", Call(Sys::SYSCALL_x64_landlock_add_rule, PortRule, &Embedded)); + + const uint64_t Nameless = 0x740000000000ULL; + Map(Nameless, 2 * Page, PROT_READ | PROT_WRITE, Anonymous, -1, 0); + uint64_t NamelessHost {}; + TranslateRange(Nameless, 2 * Page, &NamelessHost); + const uint64_t NamelessGuestHeader = Nameless + Page - 16; + auto* NamelessHeader = reinterpret_cast(NamelessHost + Page - 16); + struct iovec NamelessVector = {reinterpret_cast(Single + 128), 64}; + *NamelessHeader = {}; + NamelessHeader->msg_iov = &NamelessVector; + NamelessHeader->msg_iovlen = 1; + Protect(Nameless, Page, PROT_READ); + ArgumentStorage NamelessReceive; + uint64_t NamelessArgs[6] = {3, NamelessGuestHeader, 0, 0, 0, 0}; + Show("recvmsg_nameless_result", Call(Sys::SYSCALL_x64_recvmsg, NamelessArgs, &NamelessReceive)); + NamelessReceive.Message.msg_flags = MSG_TRUNC; + Show("recvmsg_nameless_finish", FinishResult(64, &NamelessReceive)); + Show("recvmsg_nameless_flags", NamelessHeader->msg_flags); + char NameBuffer[16]; + const uint64_t Named = 0x700000000000ULL; + Map(Named, 2 * Page, PROT_READ | PROT_WRITE, Anonymous, -1, 0); + uint64_t NamedHost {}; + TranslateRange(Named, 2 * Page, &NamedHost); + auto* NamedHeader = reinterpret_cast(NamedHost + Page - 16); + *NamedHeader = {}; + NamedHeader->msg_name = NameBuffer; + NamedHeader->msg_namelen = sizeof(NameBuffer); + NamedHeader->msg_iov = &NamelessVector; + NamedHeader->msg_iovlen = 1; + Protect(Named, Page, PROT_READ); + ArgumentStorage NamedReceive; + uint64_t NamedArgs[6] = {3, Named + Page - 16, 0, 0, 0, 0}; + Show("recvmsg_named_result", Call(Sys::SYSCALL_x64_recvmsg, NamedArgs, &NamedReceive)); + Show("recvmsg_named_private", NamedArgs[1] != NamedHost + Page - 16); + Show("recvmsg_named_name_kept", reinterpret_cast(NamedArgs[1])->msg_name == NameBuffer); + Show("recvmsg_named_finish", FinishResult(64, &NamedReceive)); + + const uint64_t Flagged = 0x730000000000ULL; + Map(Flagged, 2 * Page, PROT_READ | PROT_WRITE, Anonymous, -1, 0); + uint64_t FlaggedHost {}; + TranslateRange(Flagged, 2 * Page, &FlaggedHost); + auto* FlaggedHeader = reinterpret_cast(FlaggedHost + Page - offsetof(struct msghdr, msg_flags)); + *FlaggedHeader = {}; + FlaggedHeader->msg_iov = &NamelessVector; + FlaggedHeader->msg_iovlen = 1; + FlaggedHeader->msg_controllen = 99; + Protect(Flagged + Page, Page, PROT_READ); + ArgumentStorage FlaggedReceive; + uint64_t FlaggedArgs[6] = {3, Flagged + Page - offsetof(struct msghdr, msg_flags), 0, 0, 0, 0}; + Show("recvmsg_flags_first_result", Call(Sys::SYSCALL_x64_recvmsg, FlaggedArgs, &FlaggedReceive)); + FlaggedReceive.Message.msg_controllen = 0; + Show("recvmsg_flags_first_finish", FinishResult(64, &FlaggedReceive)); + Show("recvmsg_flags_first_controllen", FlaggedHeader->msg_controllen); + + const uint64_t Blocks = 0x720000000000ULL; + Map(Blocks, Page, PROT_READ | PROT_WRITE, Anonymous, -1, 0); + uint64_t BlocksHost {}; + TranslateRange(Blocks, Page, &BlocksHost); + auto* HighIocb = reinterpret_cast(BlocksHost); + *HighIocb = {}; + HighIocb->Data = 0x99; + HighIocb->Opcode = 7; + HighIocb->Buffer = reinterpret_cast(Scatter); + HighIocb->Bytes = 2; + const TestIocb HighExpected = *HighIocb; + uint64_t HighIocbList[1] = {Blocks}; + ArgumentStorage HighCopy; + uint64_t HighCopyArgs[6] = {1, 1, reinterpret_cast(HighIocbList), 0, 0, 0}; + Show("io_submit_high_copy_result", Call(Sys::SYSCALL_x64_io_submit, HighCopyArgs, &HighCopy)); + const uint64_t HighSent = reinterpret_cast(HighCopyArgs[2])[0]; + Show("io_submit_high_copy_private", HighSent != BlocksHost && FindIoCopyLocked(HighSent) != nullptr); + Show("io_submit_high_copy_vector", reinterpret_cast(reinterpret_cast(HighSent)->Buffer)[0].iov_base == reinterpret_cast(Base + 800)); + Show("io_submit_high_copy_untouched", std::memcmp(HighIocb, &HighExpected, sizeof(TestIocb)) == 0); + ArgumentStorage HighCancel; + uint64_t HighCancelArgs[6] = {1, Blocks, reinterpret_cast(&CancelEvent), 0, 0, 0}; + Call(Sys::SYSCALL_x64_io_cancel, HighCancelArgs, &HighCancel); + Show("io_cancel_high_private", HighCancelArgs[1] == HighSent); + Show("io_submit_high_copy_hidden", Protect(Blocks, Page, PROT_NONE)); + uint64_t SealedProbe = 0; + auto HiddenRead = [&] { return FEX::HLE::FaultSafeUserMemAccess::CopyFromUser(&SealedProbe, &HighIocb->Buffer, sizeof(SealedProbe)) != 0; }; + auto HiddenWrite = [&] { return FEX::HLE::FaultSafeUserMemAccess::CopyToUser(&HighIocb->Buffer, &SealedProbe, sizeof(SealedProbe)) != 0; }; + ProtectCalls = 0; + FinishSyscallArguments(1, &HighCopy); + Show("io_submit_high_copy_sealed", HiddenRead() && HiddenWrite()); + ArgumentStorage HiddenCancel; + uint64_t HiddenCancelArgs[6] = {1, Blocks, reinterpret_cast(&CancelEvent), 0, 0, 0}; + Call(Sys::SYSCALL_x64_io_cancel, HiddenCancelArgs, &HiddenCancel); + Show("io_cancel_hidden_native", HiddenCancelArgs[1] == BlocksHost); + TestEvent HighReaped[1] = {{0x99, HighSent, 16, 0}}; + ArgumentStorage HighReap; + uint64_t HighReapArgs[6] = {1, 1, 1, reinterpret_cast(HighReaped), 0, 0}; + Call(Sys::SYSCALL_x64_io_getevents, HighReapArgs, &HighReap); + Deliver(HighReapArgs, HighReaped, sizeof(HighReaped)); + FinishSyscallArguments(1, &HighReap); + Show("io_getevents_high_object", HighReaped[0].Object - Blocks); + Show("io_getevents_high_sealed", HiddenRead() && HiddenWrite()); + Show("io_getevents_high_protect_calls", ProtectCalls); + Show("io_getevents_high_freed", IoCopyCount.load() - CopiesBefore); + Protect(Blocks, Page, PROT_READ | PROT_WRITE); + Show("io_getevents_high_untouched", std::memcmp(HighIocb, &HighExpected, sizeof(TestIocb)) == 0); + + Protect(Blocks, Page, PROT_READ); + ArgumentStorage SealedSubmit; + uint64_t SealedSubmitArgs[6] = {1, 1, reinterpret_cast(HighIocbList), 0, 0, 0}; + Show("io_submit_read_only_result", Call(Sys::SYSCALL_x64_io_submit, SealedSubmitArgs, &SealedSubmit)); + Show("io_submit_read_only_count", SealedSubmitArgs[1]); + Show("io_submit_read_only_passed", reinterpret_cast(SealedSubmitArgs[2])[0] == BlocksHost); + Show("io_submit_read_only_copies", IoCopyCount.load() - CopiesBefore); + FinishSyscallArguments(static_cast(-EBADF), &SealedSubmit); + TestIocb Leading = ReadBlock; + uint64_t LeadingList[2] = {reinterpret_cast(&Leading), Blocks}; + ArgumentStorage LeadingSubmit; + uint64_t LeadingSubmitArgs[6] = {5, 2, reinterpret_cast(LeadingList), 0, 0, 0}; + Call(Sys::SYSCALL_x64_io_submit, LeadingSubmitArgs, &LeadingSubmit); + const auto* LeadingSent = reinterpret_cast(LeadingSubmitArgs[2]); + Show("io_submit_read_only_after_copy", LeadingSubmitArgs[1] == 2 && FindIoCopyLocked(LeadingSent[0]) != nullptr && LeadingSent[1] == BlocksHost); + FinishSyscallArguments(1, &LeadingSubmit); + ArgumentStorage LeadingDestroy; + uint64_t LeadingDestroyArgs[6] = {5, 0, 0, 0, 0, 0}; + Call(Sys::SYSCALL_x64_io_destroy, LeadingDestroyArgs, &LeadingDestroy); + FinishSyscallArguments(0, &LeadingDestroy); + Show("io_submit_read_only_after_copy_released", IoCopyCount.load() - CopiesBefore); + Show("io_submit_read_only_untouched", std::memcmp(HighIocb, &HighExpected, sizeof(TestIocb)) == 0); + Protect(Blocks, Page, PROT_READ | PROT_WRITE); + HighIocb->Opcode = 1; + HighIocb->Buffer = reinterpret_cast(LowBuffer); + HighIocb->Bytes = sizeof(LowBuffer); + Protect(Blocks, Page, PROT_READ); + ArgumentStorage ReadOnlyNative; + uint64_t ReadOnlyNativeArgs[6] = {1, 1, reinterpret_cast(HighIocbList), 0, 0, 0}; + Show("io_submit_read_only_native_result", Call(Sys::SYSCALL_x64_io_submit, ReadOnlyNativeArgs, &ReadOnlyNative)); + Show("io_submit_read_only_native_block", reinterpret_cast(ReadOnlyNativeArgs[2])[0] == BlocksHost); + Show("io_submit_read_only_native_copies", IoCopyCount.load() - CopiesBefore); + Protect(Blocks, Page, PROT_READ | PROT_WRITE); + HighIocb->Opcode = 7; + HighIocb->Buffer = reinterpret_cast(Scatter); + HighIocb->Bytes = 2; + HighIocb->Key = 4; + ArgumentStorage KeyedHigh; + uint64_t KeyedHighArgs[6] = {7, 1, reinterpret_cast(HighIocbList), 0, 0, 0}; + Call(Sys::SYSCALL_x64_io_submit, KeyedHighArgs, &KeyedHigh); + FinishSyscallArguments(1, &KeyedHigh); + Show("io_submit_high_key_accepted", HighIocb->Key); + HighIocb->Key = 4; + ArgumentStorage MovedHigh; + uint64_t MovedHighArgs[6] = {7, 1, reinterpret_cast(HighIocbList), 0, 0, 0}; + Call(Sys::SYSCALL_x64_io_submit, MovedHighArgs, &MovedHigh); + Unmap(Blocks, Page); + void* ReusedPage = mmap(reinterpret_cast(BlocksHost), Page, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED_NOREPLACE, -1, 0); + Show("io_submit_key_reused_mapped", ReusedPage == reinterpret_cast(BlocksHost)); + if (ReusedPage == reinterpret_cast(BlocksHost)) { + static_cast(ReusedPage)->Key = 4; + FinishSyscallArguments(1, &MovedHigh); + Show("io_submit_key_unmapped_skipped", static_cast(ReusedPage)->Key); + munmap(ReusedPage, Page); + } + Map(Blocks, Page, PROT_READ | PROT_WRITE, Anonymous, -1, 0); + static uint64_t RacedHost; + static uint32_t RacedSeen; + static TestIocb* RacedStandIn; + static std::thread RacedSibling; + static std::atomic RacedAttempted; + static bool RacedBlocked; + TranslateRange(Blocks, Page, &RacedHost); + auto* RacedIocb = reinterpret_cast(RacedHost); + *RacedIocb = {}; + RacedIocb->Opcode = 7; + RacedIocb->Buffer = reinterpret_cast(Scatter); + RacedIocb->Bytes = 2; + RacedIocb->Key = 4; + ArgumentStorage RacedHigh; + uint64_t RacedHighArgs[6] = {7, 1, reinterpret_cast(HighIocbList), 0, 0, 0}; + Call(Sys::SYSCALL_x64_io_submit, RacedHighArgs, &RacedHigh); + FEX::HLE::FaultSafeUserMemAccess::BeforeUserWrite = [] { + RacedSibling = std::thread([] { + std::unique_lock Lock {FEX::HLE::_SyscallHandler->VMATracking.Mutex, std::try_to_lock}; + RacedBlocked = !Lock.owns_lock(); + RacedAttempted = 1; + if (!Lock.owns_lock()) { + Lock.lock(); + } + RacedSeen = reinterpret_cast(RacedHost)->Key; + Unmap(Blocks, Page); + void* StandIn = mmap(reinterpret_cast(RacedHost), Page, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED_NOREPLACE, -1, 0); + if (StandIn == reinterpret_cast(RacedHost)) { + RacedStandIn = static_cast(StandIn); + RacedStandIn->Key = 4; + } + }); + while (RacedAttempted.load() == 0) { + std::this_thread::yield(); + } + }; + FinishSyscallArguments(1, &RacedHigh); + RacedSibling.join(); + Show("io_submit_key_store_blocked_writer", RacedBlocked); + Show("io_submit_key_store_before_unmap", RacedSeen); + Show("io_submit_key_store_stand_in", RacedStandIn != nullptr ? RacedStandIn->Key : 0xff); + Show("io_submit_key_store_released", FEX::HLE::TestThread.HighMemoryTrap.Mappings.Held); + if (RacedStandIn != nullptr) { + munmap(RacedStandIn, Page); + } + ArgumentStorage KeyedDestroy; + uint64_t KeyedDestroyArgs[6] = {7, 0, 0, 0, 0, 0}; + Call(Sys::SYSCALL_x64_io_destroy, KeyedDestroyArgs, &KeyedDestroy); + FinishSyscallArguments(0, &KeyedDestroy); + Show("io_submit_keyed_high_released", IoCopyCount.load() - CopiesBefore); + + auto* LowBlock = static_cast(mmap(nullptr, Page, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)); + *LowBlock = {}; + LowBlock->Opcode = 7; + LowBlock->Buffer = reinterpret_cast(Scatter); + LowBlock->Bytes = 2; + const TestIocb LowExpected = *LowBlock; + uint64_t LowList[1] = {reinterpret_cast(LowBlock)}; + ArgumentStorage LowCopy; + uint64_t LowCopyArgs[6] = {1, 1, reinterpret_cast(LowList), 0, 0, 0}; + Show("low_iocb_result", Call(Sys::SYSCALL_x64_io_submit, LowCopyArgs, &LowCopy)); + const uint64_t LowSent = reinterpret_cast(LowCopyArgs[2])[0]; + Show("low_iocb_private", LowSent != reinterpret_cast(LowBlock) && FindIoCopyLocked(LowSent) != nullptr); + mprotect(LowBlock, Page, PROT_READ); + ProtectCalls = 0; + FinishSyscallArguments(1, &LowCopy); + Show("low_iocb_untouched", std::memcmp(LowBlock, &LowExpected, sizeof(TestIocb)) == 0); + const auto Regions = Count.load(); + Count.store(0); + ArgumentStorage QuietCancel; + uint64_t QuietCancelArgs[6] = {1, reinterpret_cast(LowBlock), 0, 0, 0, 0}; + Call(Sys::SYSCALL_x64_io_cancel, QuietCancelArgs, &QuietCancel); + Show("low_iocb_quiet_cancel", QuietCancelArgs[1] == LowSent); + TestEvent QuietReaped[1] = {{0, LowSent, 16, 0}}; + ArgumentStorage QuietReap; + uint64_t QuietReapArgs[6] = {1, 1, 1, reinterpret_cast(QuietReaped), 0, 0}; + Call(Sys::SYSCALL_x64_io_getevents, QuietReapArgs, &QuietReap); + Show("low_iocb_quiet_host_buffer", QuietReapArgs[3] == reinterpret_cast(QuietReap.EventBuffer.data())); + Deliver(QuietReapArgs, QuietReaped, sizeof(QuietReaped)); + FinishSyscallArguments(1, &QuietReap); + uint32_t QuietRing[8] = {0, 64, 0, 0, 0xa10a10a1, 1, 0, 32}; + uint64_t QuietRingContext = reinterpret_cast(QuietRing); + ArgumentStorage QuietSetup; + uint64_t QuietSetupArgs[6] = {64, reinterpret_cast(&QuietRingContext), 0, 0, 0, 0}; + Call(Sys::SYSCALL_x64_io_setup, QuietSetupArgs, &QuietSetup); + FinishSyscallArguments(0, &QuietSetup); + Show("low_quiet_setup_magic", QuietRing[4]); + Count.store(Regions); + Show("low_iocb_quiet_object", QuietReaped[0].Object == reinterpret_cast(LowBlock)); + Show("low_iocb_quiet_freed", IoCopyCount.load() - CopiesBefore); + Show("low_iocb_protect_calls", ProtectCalls); + Show("low_iocb_reaped_untouched", std::memcmp(LowBlock, &LowExpected, sizeof(TestIocb)) == 0); + munmap(LowBlock, Page); + + for (auto& Copy : IoCopies) { + Copy.Used = true; + } + IoCopyCount = MaxIoCopies; + ArgumentStorage Crowded; + uint64_t CrowdedArgs[6] = {1, 2, reinterpret_cast(Submitted), 0, 0, 0}; + Show("io_submit_crowded_result", Call(Sys::SYSCALL_x64_io_submit, CrowdedArgs, &Crowded)); + Show("io_submit_crowded_untouched", GuestBlocksUntouched()); + IoCopies[5].Used = false; + IoCopyCount = MaxIoCopies - 1; + ArgumentStorage LastCopy; + uint64_t LastCopyArgs[6] = {1, 2, reinterpret_cast(Submitted), 0, 0, 0}; + Show("io_submit_last_copy_result", Call(Sys::SYSCALL_x64_io_submit, LastCopyArgs, &LastCopy)); + Show("io_submit_last_copy_count", LastCopyArgs[1]); + Show("io_submit_last_copy_slot", reinterpret_cast(LastCopyArgs[2])[0] == reinterpret_cast(&IoCopies[5])); + for (auto& Copy : IoCopies) { + Copy.Used = false; + } + IoCopyCount = 0; + + auto* CapPage = static_cast(mmap(nullptr, Page, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)); + CapPage[0] = 0x1234; + ArgumentStorage CapSealed; + uint64_t CapSealedArgs[6] = {reinterpret_cast(CapPage), Single + 64, 0, 0, 0, 0}; + Show("capget_sealed_result", Call(Sys::SYSCALL_x64_capget, CapSealedArgs, &CapSealed)); + reinterpret_cast(CapSealedArgs[0])[0] = 0x20080522; + mprotect(CapPage, Page, PROT_READ); + Show("capget_sealed_finish", FinishResult(static_cast(-EINVAL), &CapSealed)); + Show("capget_sealed_version", CapPage[0]); + + struct iovec ShortVector = {reinterpret_cast(Single + 256), 32}; + struct mmsghdr Shorts[3] {}; + for (auto& Short : Shorts) { + Short.msg_hdr.msg_iov = &ShortVector; + Short.msg_hdr.msg_iovlen = 1; + } + ArgumentStorage ShortFirst; + uint64_t ShortFirstArgs[6] = {static_cast(Peer), reinterpret_cast(Shorts), 3, 0, 0, 0}; + Show("sendmmsg_short_first_result", Call(Sys::SYSCALL_x64_sendmmsg, ShortFirstArgs, &ShortFirst)); + reinterpret_cast(ShortFirstArgs[1])[0].msg_len = 10; + SendCalls = 0; + Show("sendmmsg_short_first_finish", FinishResult(1, &ShortFirst)); + Show("sendmmsg_short_first_sends", SendCalls); + Show("sendmmsg_short_first_lengths", Shorts[0].msg_len * 0x10000 + Shorts[1].msg_len * 0x100 + Shorts[2].msg_len); + for (auto& Short : Shorts) { + Short.msg_len = 0; + } + ArgumentStorage ShortSecond; + uint64_t ShortSecondArgs[6] = {static_cast(Peer), reinterpret_cast(Shorts), 3, 0, 0, 0}; + Show("sendmmsg_short_second_result", Call(Sys::SYSCALL_x64_sendmmsg, ShortSecondArgs, &ShortSecond)); + Show("sendmmsg_short_second_submitted", ShortSecondArgs[2]); + const int Pinned = ShortSecond.Socket; + Show("sendmmsg_pinned_distinct", Pinned >= 0 && Pinned != Peer); + Show("sendmmsg_pinned_dispatched", ShortSecondArgs[0] == static_cast(Pinned)); + reinterpret_cast(ShortSecondArgs[1])[0].msg_len = 32; + SendCalls = 0; + SendLimit = 5; + SentSocket = -1; + Show("sendmmsg_short_second_finish", FinishResult(1, &ShortSecond)); + SendLimit = ~size_t {}; + Show("sendmmsg_short_second_sends", SendCalls); + Show("sendmmsg_short_second_lengths", Shorts[0].msg_len * 0x10000 + Shorts[1].msg_len * 0x100 + Shorts[2].msg_len); + Show("sendmmsg_pinned_used", SentSocket == Pinned); + Show("sendmmsg_pinned_closed", fcntl(Pinned, F_GETFD) == -1 && errno == EBADF && ShortSecond.Socket == -1); + for (auto& Short : Shorts) { + Short.msg_len = 0; + } + ArgumentStorage ShortFailed; + uint64_t ShortFailedArgs[6] = {static_cast(Peer), reinterpret_cast(Shorts), 3, 0, 0, 0}; + Call(Sys::SYSCALL_x64_sendmmsg, ShortFailedArgs, &ShortFailed); + const int FailedPin = ShortFailed.Socket; + Show("sendmmsg_error_finish", FinishResult(static_cast(-EAGAIN), &ShortFailed)); + Show("sendmmsg_error_closed", FailedPin >= 0 && fcntl(FailedPin, F_GETFD) == -1 && errno == EBADF); + int Pair[2]; + if (socketpair(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0, Pair) != 0) { + std::fprintf(stderr, "socketpair: %s\n", std::strerror(errno)); + return 1; + } + struct iovec Payloads[3] = {}; + for (int i = 0; i < 3; ++i) { + std::memset(Backing + 2048 + 16 * i, 'A' + i, 4); + Payloads[i] = {reinterpret_cast(Single + 2048 + 16 * i), 4}; + } + auto Drain = [&] { + uint64_t Packed = 0; + unsigned char Data[16]; + while (recv(Pair[1], Data, sizeof(Data), MSG_DONTWAIT) > 0) { + Packed = Packed * 0x100 + Data[0]; + } + return Packed; + }; + auto Dispatch = [&](uint64_t* Args) { + return static_cast(sendmmsg(static_cast(Args[0]), reinterpret_cast(Args[1]), static_cast(Args[2]), 0)); + }; + auto Lengths = [&](struct mmsghdr* Headers) { + return Headers[0].msg_len * 0x10000 + Headers[1].msg_len * 0x100 + Headers[2].msg_len; + }; + PassSend = true; + + struct mmsghdr Real[3] {}; + for (int i = 0; i < 3; ++i) { + Real[i].msg_hdr.msg_iov = &Payloads[i]; + Real[i].msg_hdr.msg_iovlen = 1; + } + DupFailures = 1; + ArgumentStorage Emfile; + uint64_t EmfileArgs[6] = {static_cast(Pair[0]), reinterpret_cast(Real), 3, 0, 0, 0}; + Show("sendmmsg_emfile_result", Call(Sys::SYSCALL_x64_sendmmsg, EmfileArgs, &Emfile)); + Show("sendmmsg_emfile_submitted", EmfileArgs[2]); + Show("sendmmsg_emfile_original", EmfileArgs[0] == static_cast(Pair[0]) && Emfile.Socket == -1 && DupFailures == 0); + Show("sendmmsg_emfile_first_only", Drain()); + Show("sendmmsg_emfile_finish", FinishResult(Dispatch(EmfileArgs), &Emfile)); + Show("sendmmsg_emfile_received", Drain()); + Show("sendmmsg_emfile_lengths", Lengths(Real)); + + const uint64_t ReadOnly = 0x730000000000ULL; + Map(ReadOnly, 2 * Page, PROT_READ | PROT_WRITE, Anonymous, -1, 0); + uint64_t ReadOnlyHost {}; + TranslateRange(ReadOnly, 2 * Page, &ReadOnlyHost); + auto* ReadOnlyHeaders = reinterpret_cast(ReadOnlyHost + Page - sizeof(struct mmsghdr)); + for (int i = 0; i < 3; ++i) { + ReadOnlyHeaders[i] = {}; + ReadOnlyHeaders[i].msg_hdr.msg_iov = &Payloads[i]; + ReadOnlyHeaders[i].msg_hdr.msg_iovlen = 1; + } + Protect(ReadOnly + Page, Page, PROT_READ); + DupFailures = 1; + ArgumentStorage ReadOnlyBatch; + uint64_t ReadOnlyArgs[6] = {static_cast(Pair[0]), ReadOnly + Page - sizeof(struct mmsghdr), 3, 0, 0, 0}; + Show("sendmmsg_emfile_readonly_result", Call(Sys::SYSCALL_x64_sendmmsg, ReadOnlyArgs, &ReadOnlyBatch)); + Show("sendmmsg_emfile_readonly_submitted", ReadOnlyArgs[2]); + Show("sendmmsg_emfile_readonly_finish", FinishResult(Dispatch(ReadOnlyArgs), &ReadOnlyBatch)); + Show("sendmmsg_emfile_readonly_received", Drain()); + Show("sendmmsg_emfile_readonly_lengths", Lengths(ReadOnlyHeaders)); + + DupFailures = 1; + ArgumentStorage ReadOnlyFirst; + uint64_t ReadOnlyFirstArgs[6] = {static_cast(Pair[0]), ReadOnly + Page, 1, 0, 0, 0}; + Show("sendmmsg_emfile_only_result", Call(Sys::SYSCALL_x64_sendmmsg, ReadOnlyFirstArgs, &ReadOnlyFirst)); + Show("sendmmsg_emfile_only_finish", FinishResult(Dispatch(ReadOnlyFirstArgs), &ReadOnlyFirst)); + Show("sendmmsg_emfile_only_received", Drain()); + DupFailures = 0; + + auto* Unreadable = static_cast(mmap(nullptr, Page, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)); + struct mmsghdr Middle[3] {}; + for (int i = 0; i < 3; ++i) { + Middle[i].msg_hdr.msg_iov = i == 1 ? Unreadable : &Payloads[i]; + Middle[i].msg_hdr.msg_iovlen = 1; + } + ArgumentStorage MiddleBatch; + uint64_t MiddleArgs[6] = {static_cast(Pair[0]), reinterpret_cast(Middle), 3, 0, 0, 0}; + Show("sendmmsg_unreadable_middle_result", Call(Sys::SYSCALL_x64_sendmmsg, MiddleArgs, &MiddleBatch)); + Show("sendmmsg_unreadable_middle_submitted", MiddleArgs[2]); + Show("sendmmsg_unreadable_middle_queued", MiddleBatch.Messages.size()); + Show("sendmmsg_unreadable_middle_finish", FinishResult(Dispatch(MiddleArgs), &MiddleBatch)); + Show("sendmmsg_unreadable_middle_received", Drain()); + Show("sendmmsg_unreadable_middle_lengths", Lengths(Middle)); + + struct mmsghdr Last[3] {}; + for (int i = 0; i < 3; ++i) { + Last[i].msg_hdr.msg_iov = i == 2 ? Unreadable : &Payloads[i]; + Last[i].msg_hdr.msg_iovlen = 1; + } + ArgumentStorage LastBatch; + uint64_t LastArgs[6] = {static_cast(Pair[0]), reinterpret_cast(Last), 3, 0, 0, 0}; + Show("sendmmsg_unreadable_last_result", Call(Sys::SYSCALL_x64_sendmmsg, LastArgs, &LastBatch)); + Show("sendmmsg_unreadable_last_submitted", LastArgs[2]); + Show("sendmmsg_unreadable_last_queued", LastBatch.Messages.size()); + const int LastPin = LastBatch.Socket; + Show("sendmmsg_unreadable_last_pinned", LastPin >= 0 && LastArgs[0] == static_cast(LastPin)); + Show("sendmmsg_unreadable_last_finish", FinishResult(Dispatch(LastArgs), &LastBatch)); + Show("sendmmsg_unreadable_last_received", Drain()); + Show("sendmmsg_unreadable_last_lengths", Lengths(Last)); + + struct mmsghdr First[3] {}; + for (int i = 0; i < 3; ++i) { + First[i].msg_hdr.msg_iov = i == 0 ? Unreadable : &Payloads[i]; + First[i].msg_hdr.msg_iovlen = 1; + } + ArgumentStorage FirstBatch; + uint64_t FirstArgs[6] = {static_cast(Pair[0]), reinterpret_cast(First), 3, 0, 0, 0}; + Show("sendmmsg_unreadable_first_result", Call(Sys::SYSCALL_x64_sendmmsg, FirstArgs, &FirstBatch)); + Show("sendmmsg_unreadable_first_native", FirstArgs[1] == reinterpret_cast(First) && FirstArgs[2] == 3 && FirstBatch.GuestMessages == 0); + Show("sendmmsg_unreadable_first_error", static_cast(sendmmsg(Pair[0], First, 3, 0)) == static_cast(-1) && errno == EFAULT); + Show("sendmmsg_unreadable_first_received", Drain()); + PassSend = false; + + auto* LowVectors = static_cast(mmap(nullptr, Page, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)); + char KeptLow[16]; + LowVectors[0] = {KeptLow, sizeof(KeptLow)}; + struct mmsghdr Growing[3] {}; + Growing[0].msg_hdr.msg_iov = &ShortVector; + Growing[0].msg_hdr.msg_iovlen = 1; + for (int i = 1; i < 3; ++i) { + Growing[i].msg_hdr.msg_iov = LowVectors; + Growing[i].msg_hdr.msg_iovlen = 1; + } + ArgumentStorage Grown; + uint64_t GrownArgs[6] = {static_cast(Peer), reinterpret_cast(Growing), 3, 0, 0, 0}; + Show("sendmmsg_grown_result", Call(Sys::SYSCALL_x64_sendmmsg, GrownArgs, &Grown)); + auto* GrownCopy = reinterpret_cast(GrownArgs[1]); + Show("sendmmsg_grown_private", GrownCopy[1].msg_hdr.msg_iov != LowVectors && GrownCopy[1].msg_hdr.msg_iov[0].iov_base == KeptLow); + GrownCopy[0].msg_len = 32; + SendCalls = 0; + GrowAfterSend = LowVectors; + Show("sendmmsg_grown_finish", FinishResult(1, &Grown)); + GrowAfterSend = nullptr; + Show("sendmmsg_grown_sends", SendCalls); + Show("sendmmsg_grown_lengths", Growing[0].msg_len * 0x10000 + Growing[1].msg_len * 0x100 + Growing[2].msg_len); + for (auto& Message : Growing) { + Message.msg_len = 0; + } + LowVectors[0] = {KeptLow, sizeof(KeptLow)}; + ArgumentStorage Vanished; + uint64_t VanishedArgs[6] = {static_cast(Peer), reinterpret_cast(Growing), 3, 0, 0, 0}; + Show("sendmmsg_vanished_result", Call(Sys::SYSCALL_x64_sendmmsg, VanishedArgs, &Vanished)); + reinterpret_cast(VanishedArgs[1])[0].msg_len = 32; + SendCalls = 0; + SendLimit = 5; + UnmapAfterSend = LowVectors; + Show("sendmmsg_vanished_finish", FinishResult(1, &Vanished)); + SendLimit = ~size_t {}; + Show("sendmmsg_vanished_sends", SendCalls); + Show("sendmmsg_vanished_unmapped", UnmapAfterSend == nullptr && msync(LowVectors, Page, MS_ASYNC) == -1 && errno == ENOMEM); + Show("sendmmsg_vanished_lengths", Growing[0].msg_len * 0x10000 + Growing[1].msg_len * 0x100 + Growing[2].msg_len); + + uint64_t AccessRegs[32] {}; + AccessRegs[0] = 0x10000; + AccessRegs[2] = 0xfffffffeULL; + auto Decode = [&](const char* Name, uint32_t Insn) { + uint64_t Address {}; + uint32_t Size {}; + bool Plain {}; + const bool Known = DecodeAccess(Insn, AccessRegs, &Address, &Size, &Plain); + std::printf("decode_%s_known %x\n", Name, Known); + std::printf("decode_%s_offset %llx\n", Name, static_cast(Address - AccessRegs[0])); + std::printf("decode_%s_size %x\n", Name, Size); + std::printf("decode_%s_plain %x\n", Name, Plain); + }; + Decode("str_x_imm", 0xf9000401); + Decode("ldr_x_pre", 0xf85fcc01); + Decode("ldr_x_post", 0xf8408401); + Decode("stur_x", 0xf81fc001); + Decode("ldr_w_lsl", 0xb8627801); + Decode("ldr_w_sxtw", 0xb862c801); + Decode("ldr_w_uxtw", 0xb8624801); + Decode("ldr_w_reserved", 0xb8620801); + Decode("stp_x", 0xa9010c01); + Decode("ldp_w_negative", 0x297f0c01); + Decode("ldp_q_post", 0xacc10c01); + Decode("str_q", 0x3d800401); + Decode("ld1_four", 0x4c402001); + Decode("st1_post", 0x4c9f7c01); + Decode("ld1_lane", 0x0d409001); + Decode("ld4r", 0x4d60e801); + Decode("ldadd", 0xf8210002); + Decode("ldar", 0xc8dffc01); + Decode("casp", 0x48227c04); + Decode("ldxp", 0xc87f0c01); + Decode("ldapur", 0x995fc001); + Decode("ldraa", 0xf8200400); + + auto* Backings = static_cast(mmap(nullptr, 6 * Page, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)); + const uint64_t Backed = reinterpret_cast(Backings); + const uint64_t SeparateGuest = 0x6f0000000000ULL; + const uint64_t Adjacent = 0x6f0000100000ULL; + AddEntry(SeparateGuest, Page, Backed, false, PROT_READ | PROT_WRITE); + AddEntry(SeparateGuest + Page, Page, Backed + 2 * Page, false, PROT_READ | PROT_WRITE); + AddEntry(Adjacent, Page, Backed + 4 * Page, false, PROT_READ | PROT_WRITE); + AddEntry(Adjacent + Page, Page, Backed + 5 * Page, false, PROT_READ | PROT_WRITE); + std::memset(Backings + Page, 0xee, Page); + uint64_t StoreRegs[32] {}; + StoreRegs[0] = SeparateGuest + Page - 4; + StoreRegs[1] = 0x1122334455667788ULL; + uint64_t SplitAddress {}; + uint32_t SplitSize {}; + bool SplitPlain {}; + DecodeAccess(0xf9000001, StoreRegs, &SplitAddress, &SplitSize, &SplitPlain); + AccessPiece SplitPieces[MaxAccessPieces] {}; + const auto SplitParts = PlanAccessLocked(SplitAddress, SplitSize, SplitPieces); + Show("split_access_parts", SplitParts); + Show("split_access_first", SplitPieces[0].Host - Backed); + Show("split_access_second", SplitPieces[1].Host - Backed); + Show("split_access_sizes", SplitPieces[0].Size * 0x10 + SplitPieces[1].Size); + Show("split_access_guests", (SplitPieces[0].Guest == SeparateGuest + Page - 4) * 0x10 + (SplitPieces[1].Guest == SeparateGuest + Page)); + Show("split_access_contiguous", HostContiguous(SplitPieces, SplitParts)); + Show("split_access_store_reachable", PiecesReachable(SplitPieces, SplitParts, true)); + alignas(16) uint8_t Window[96] {}; + const auto WindowOffset = SplitAddress & 15; + CopyPieces(Window + WindowOffset, SplitPieces, SplitParts, true); + std::memcpy(Window + WindowOffset, &StoreRegs[1], sizeof(StoreRegs[1])); + CopyPieces(Window + WindowOffset, SplitPieces, SplitParts, false); + uint32_t SplitWords[3] {}; + std::memcpy(&SplitWords[0], Backings + Page - 4, 4); + std::memcpy(&SplitWords[1], Backings + 2 * Page, 4); + std::memcpy(&SplitWords[2], Backings + Page, 4); + Show("split_store_low", SplitWords[0]); + Show("split_store_high", SplitWords[1]); + Show("split_store_neighbour", SplitWords[2]); + std::memset(Window, 0, sizeof(Window)); + CopyPieces(Window + WindowOffset, SplitPieces, SplitParts, true); + uint64_t SplitLoaded {}; + std::memcpy(&SplitLoaded, Window + WindowOffset, sizeof(SplitLoaded)); + Show("split_load_value", SplitLoaded); + SplitPieces[1].Prot = PROT_READ; + Show("split_readonly_store", PiecesReachable(SplitPieces, SplitParts, true)); + Show("split_readonly_load", PiecesReachable(SplitPieces, SplitParts, false)); + SplitPieces[1].Prot = PROT_NONE; + Show("split_none_load", PiecesReachable(SplitPieces, SplitParts, false)); + AccessPiece EdgePieces[MaxAccessPieces] {}; + Show("split_unmapped_parts", PlanAccessLocked(SeparateGuest + 2 * Page - 4, 8, EdgePieces)); + Show("split_inside_parts", PlanAccessLocked(SeparateGuest + 16, 64, EdgePieces)); + Show("split_inside_host", EdgePieces[0].Host - Backed); + AccessPiece JoinedPieces[MaxAccessPieces] {}; + const auto JoinedParts = PlanAccessLocked(Adjacent + Page - 4, 8, JoinedPieces); + Show("joined_access_parts", JoinedParts); + Show("joined_access_contiguous", HostContiguous(JoinedPieces, JoinedParts)); + Show("joined_access_delta", JoinedPieces[0].Host - (Adjacent + Page - 4) == Backed + 4 * Page - Adjacent); + + uint64_t OrderedRegs[32] {}; + Show("ordered_load_parts", EmulateOrdered(0xd9400001, SplitPieces, SplitParts, OrderedRegs)); + Show("ordered_load_value", OrderedRegs[1]); + OrderedRegs[1] = 0xa1a2a3a4b5b6b7b8ULL; + Show("ordered_store_parts", EmulateOrdered(0xd9000001, SplitPieces, SplitParts, OrderedRegs)); + uint32_t OrderedWords[2] {}; + std::memcpy(&OrderedWords[0], Backings + Page - 4, 4); + std::memcpy(&OrderedWords[1], Backings + 2 * Page, 4); + Show("ordered_store_low", OrderedWords[0]); + Show("ordered_store_high", OrderedWords[1]); + AccessPiece WordPieces[MaxAccessPieces] {}; + const auto WordParts = PlanAccessLocked(SeparateGuest + Page - 2, 4, WordPieces); + OrderedRegs[1] = 0; + Show("ordered_signed_parts", EmulateOrdered(0x99800001, WordPieces, WordParts, OrderedRegs) == WordParts && WordParts == 2); + Show("ordered_signed_value", OrderedRegs[1]); + mprotect(Backings + 2 * Page, Page, PROT_NONE); + OrderedRegs[1] = 0x77; + Show("ordered_fault_parts", EmulateOrdered(0xd9400001, SplitPieces, SplitParts, OrderedRegs)); + Show("ordered_fault_untouched", OrderedRegs[1]); + Show("gather_fault_piece", CopyPieces(Window + WindowOffset, SplitPieces, SplitParts, true)); + Show("scatter_fault_piece", CopyPieces(Window + WindowOffset, SplitPieces, SplitParts, false)); + mprotect(Backings + 2 * Page, Page, PROT_READ | PROT_WRITE); + Show("gather_whole", CopyPieces(Window + WindowOffset, SplitPieces, SplitParts, true)); + Show("probe_instruction", ProbeInstruction(16)); + Show("probe_instruction_low", ProbeInstruction(2)); + auto OrderedKind = [](uint32_t Insn) { return static_cast(IsOrderedAccess(Insn)); }; + Show("ordered_kinds", OrderedKind(0xd9400001) << 20 | OrderedKind(0x99800001) << 16 | OrderedKind(0xc8dffc01) << 12 | OrderedKind(0xc89ffc01) << 8 | + OrderedKind(0xf8bfc001) << 4 | OrderedKind(0xf9400001)); + Show("ordered_atomics", OrderedKind(0xf8210002) << 8 | OrderedKind(0x48227c04) << 4 | OrderedKind(0xc87f0c01)); + auto WriteKind = [](uint32_t Insn) { return static_cast(IsWrite(Insn)); }; + Show("write_loads", WriteKind(0xb9800001) << 20 | WriteKind(0x99800001) << 16 | WriteKind(0x39c00001) << 12 | WriteKind(0xf9400001) << 8 | + WriteKind(0x3dc00401) << 4 | WriteKind(0xd9400001)); + Show("write_stores", WriteKind(0xf9000001) << 12 | WriteKind(0xd9000001) << 8 | WriteKind(0x3d800401) << 4 | WriteKind(0x39000001)); + Show("extend_signed_half_w", ExtendOrdered(0x59c00001, 0x8001)); + Show("extend_signed_half_x", ExtendOrdered(0x59800001, 0x8001)); + Show("extend_unsigned_byte", ExtendOrdered(0x19400001, 0x80)); + Show("extend_ldar", ExtendOrdered(0x889ffc01 | (1U << 22), 0x80000000)); + + TestHold Held {}; + std::atomic WriterIn {0}; + uint64_t HoldResults[4] {}; + std::thread Holder([&] { + { + MappingHold Hold {Held}; + Hold.Keep(); + } + HoldResults[0] = Held.Held; + std::thread Writer([&] { + std::unique_lock Exclusive {FEX::HLE::_SyscallHandler->VMATracking.Mutex}; + WriterIn = 1; + }); + std::this_thread::sleep_for(std::chrono::milliseconds(50)); + HoldResults[1] = WriterIn.load(); + ReleaseMappings(Held); + Writer.join(); + HoldResults[2] = WriterIn.load() * 0x10 + Held.Held; + { + MappingHold Hold {Held}; + } + HoldResults[3] = ExclusiveFromAnotherThread() * 0x10 + Held.Held; + }); + Holder.join(); + Show("hold_kept_held", HoldResults[0]); + Show("hold_blocks_writer", HoldResults[1]); + Show("hold_released", HoldResults[2]); + Show("hold_scoped", HoldResults[3]); + + struct sigaction TrapAction {}; + TrapAction.sa_sigaction = CountTrap; + TrapAction.sa_flags = SA_SIGINFO; + sigaction(SIGTRAP, &TrapAction, nullptr); + uint64_t DeferResults[12] {}; + std::thread Deferring([&] { + siginfo_t User {}; + User.si_signo = SIGTRAP; + User.si_code = SI_QUEUE; + User.si_pid = getpid(); + User.si_uid = getuid(); + User.si_value.sival_int = 0x1234; + siginfo_t Breakpoint {}; + Breakpoint.si_signo = SIGTRAP; + Breakpoint.si_code = TRAP_BRKPT; + TestHold Deferred {}; + DeferResults[0] = DeferWhileHeld(Deferred, SIGTRAP, &User); + { + MappingHold Hold {Deferred}; + Hold.Keep(); + } + sigset_t Current; + pthread_sigmask(SIG_BLOCK, nullptr, &Current); + DeferResults[1] = sigismember(&Current, SIGTRAP) * 0x100 + sigismember(&Current, SIGSEGV) * 0x10 + sigismember(&Current, SIGILL); + DeferResults[2] = DeferWhileHeld(Deferred, SIGTRAP, &User) * 0x100 + DeferWhileHeld(Deferred, SIGTRAP, &Breakpoint) * 0x10 + + DeferWhileHeld(Deferred, SIGILL, &User); + DeferResults[3] = TrapsSeen.load(); + DeferResults[4] = ReleaseMappings(Deferred); + DeferResults[5] = TrapsSeen.load() * 0x10 + Deferred.Held; + DeferResults[6] = ExclusiveFromAnotherThread(); + sigset_t Trap; + sigemptyset(&Trap); + sigaddset(&Trap, SIGTRAP); + pthread_sigmask(SIG_UNBLOCK, &Trap, nullptr); + DeferResults[7] = TrapsSeen.load(); + DeferResults[8] = static_cast(TrapCode.load()) * 0x10000ULL + static_cast(TrapValue.load()); + { + MappingHold Hold {Deferred}; + User.si_value.sival_int = 0x5678; + DeferWhileHeld(Deferred, SIGTRAP, &User); + } + DeferResults[9] = TrapsSeen.load(); + pthread_sigmask(SIG_BLOCK, nullptr, &Current); + DeferResults[10] = sigismember(&Current, SIGTRAP); + pthread_sigmask(SIG_UNBLOCK, &Trap, nullptr); + DeferResults[11] = TrapsSeen.load() * 0x10000ULL + static_cast(TrapValue.load()); + }); + Deferring.join(); + Show("defer_unheld", DeferResults[0]); + Show("defer_held_mask", DeferResults[1]); + Show("defer_kinds", DeferResults[2]); + Show("defer_not_run_while_held", DeferResults[3]); + Show("defer_requeued", DeferResults[4]); + Show("defer_after_release", DeferResults[5]); + Show("defer_lock_free", DeferResults[6]); + Show("defer_delivered", DeferResults[7]); + Show("defer_info", DeferResults[8]); + Show("defer_scoped_pending", DeferResults[9]); + Show("defer_scoped_blocked", DeferResults[10]); + Show("defer_scoped_delivered", DeferResults[11]); + const uint64_t Delivering = 0x730000000000ULL; + Map(Delivering, Page, PROT_READ | PROT_WRITE, Anonymous, -1, 0); + static int TrapsBefore; + TrapsBefore = TrapsSeen.load(); + FEX::HLE::FaultSafeUserMemAccess::BeforeUserWrite = [] { + siginfo_t User {}; + User.si_signo = SIGTRAP; + User.si_code = SI_QUEUE; + User.si_pid = getpid(); + User.si_uid = getuid(); + DeferWhileHeld(FEX::HLE::TestThread.HighMemoryTrap.Mappings, SIGTRAP, &User); + }; + const uint32_t DeliveringValue = 0x5a; + Show("guest_store_deferred_result", CopyToGuest(Delivering, &DeliveringValue, sizeof(DeliveringValue))); + Show("guest_store_deferred_delivered", TrapsSeen.load() - TrapsBefore); + sigset_t AfterStore; + pthread_sigmask(SIG_BLOCK, nullptr, &AfterStore); + Show("guest_store_deferred_unblocked", !sigismember(&AfterStore, SIGTRAP)); + Unmap(Delivering, Page); + return 0; +} +""" + + +def added_lines(text, path): + lines = [] + inside = False + for line in text.splitlines(): + if line.startswith("diff --git "): + inside = line.endswith(" b/" + path) + continue + if inside and line.startswith("+") and not line.startswith("+++"): + lines.append(line[1:]) + return lines + + +def block(lines, signature): + start = next(i for i, line in enumerate(lines) if line.lstrip().startswith(signature)) + indent = lines[start][: len(lines[start]) - len(lines[start].lstrip())] + if lines[start].rstrip().endswith(";"): + return lines[start] + end = next(i for i in range(start + 1, len(lines)) if lines[i] in (indent + "}", indent + "};")) + return "\n".join(lines[start:end + 1]) + + +def span(lines, first, stop): + start = next(i for i, line in enumerate(lines) if line.startswith(first)) + end = next(i for i in range(start + 1, len(lines)) if lines[i].startswith(stop)) + return "\n".join(lines[start:end]) + + +def syscall_enum(code): + entries = [] + for name in sorted(set(re.findall(r"SYSCALL_x64_(\w+)", code))): + kernel = KERNEL_NAMES.get(name, name) + fallback = NEWER_SYSCALLS.get(name) + if fallback is None: + entries.append(f"SYSCALL_x64_{name} = __NR_{kernel},") + else: + entries.append(f"#ifdef __NR_{kernel}\nSYSCALL_x64_{name} = __NR_{kernel},\n#else\nSYSCALL_x64_{name} = {fallback},\n#endif") + return "enum Syscalls_x64 : int {\n" + "\n".join(entries) + "\n};" + + +def harness(): + text = PATCH.read_text() + source = added_lines(text, SOURCE) + header = [line for line in added_lines(text, HEADER) if not line.startswith(("#pragma", "#include