dsh-remote 0.8.50 → 0.8.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/README.en.md +8 -0
  2. package/README.md +22 -0
  3. package/lib/client.js +15 -3
  4. package/lib/index.js +269 -8
  5. package/lib/instructions.js +288 -0
  6. package/lib/openssh.js +10 -1
  7. package/lib/pool.js +29 -1
  8. package/lib/remote-fs.js +26 -1
  9. package/lib/sftp-surface.js +46 -3
  10. package/lib/sshconfig.js +13 -3
  11. package/node_modules/buildcheck/.eslintrc.js +5 -0
  12. package/node_modules/buildcheck/.github/workflows/ci.yml +88 -0
  13. package/node_modules/buildcheck/.github/workflows/lint.yml +27 -0
  14. package/node_modules/buildcheck/.npmignore +3 -0
  15. package/node_modules/buildcheck/LICENSE +19 -0
  16. package/node_modules/buildcheck/README.md +106 -0
  17. package/node_modules/buildcheck/deps/Find-VisualStudio.cs +250 -0
  18. package/node_modules/buildcheck/lib/findvs.js +361 -0
  19. package/node_modules/buildcheck/lib/index.js +738 -0
  20. package/node_modules/buildcheck/package.json +36 -0
  21. package/node_modules/buildcheck/test/test.js +8 -0
  22. package/node_modules/cpu-features/.eslintrc.js +5 -0
  23. package/node_modules/cpu-features/.github/workflows/ci.yml +74 -0
  24. package/node_modules/cpu-features/.github/workflows/lint.yml +27 -0
  25. package/node_modules/cpu-features/LICENSE +19 -0
  26. package/node_modules/cpu-features/README.md +59 -0
  27. package/node_modules/cpu-features/binding.gyp +16 -0
  28. package/node_modules/cpu-features/buildcheck.js +32 -0
  29. package/node_modules/cpu-features/deps/cpu_features/.clang-format +4 -0
  30. package/node_modules/cpu-features/deps/cpu_features/.dockerignore +31 -0
  31. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/Dockerfile +5 -0
  32. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/aarch64_linux_cmake.yml +30 -0
  33. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/amd64_freebsd_cmake.yml +22 -0
  34. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/amd64_linux_bazel.yml +26 -0
  35. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/amd64_linux_cmake.yml +31 -0
  36. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/amd64_macos_cmake.yml +43 -0
  37. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/amd64_windows_cmake.yml +25 -0
  38. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/arm_linux_cmake.yml +31 -0
  39. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/clang_format.yml +24 -0
  40. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/mips_linux_cmake.yml +30 -0
  41. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/power_linux_cmake.yml +29 -0
  42. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/riscv_linux_cmake.yml +28 -0
  43. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/s390x_linux_cmake.yml +27 -0
  44. package/node_modules/cpu-features/deps/cpu_features/.grenrc.yml +21 -0
  45. package/node_modules/cpu-features/deps/cpu_features/BUILD.bazel +329 -0
  46. package/node_modules/cpu-features/deps/cpu_features/CMakeLists.txt +261 -0
  47. package/node_modules/cpu-features/deps/cpu_features/CONTRIBUTING.md +23 -0
  48. package/node_modules/cpu-features/deps/cpu_features/LICENSE +230 -0
  49. package/node_modules/cpu-features/deps/cpu_features/README.md +272 -0
  50. package/node_modules/cpu-features/deps/cpu_features/WORKSPACE +19 -0
  51. package/node_modules/cpu-features/deps/cpu_features/bazel/ci/README.md +5 -0
  52. package/node_modules/cpu-features/deps/cpu_features/bazel/platforms.bzl +11 -0
  53. package/node_modules/cpu-features/deps/cpu_features/cmake/CpuFeaturesConfig.cmake.in +3 -0
  54. package/node_modules/cpu-features/deps/cpu_features/cmake/CpuFeaturesNdkCompatConfig.cmake.in +3 -0
  55. package/node_modules/cpu-features/deps/cpu_features/cmake/README.md +30 -0
  56. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/Makefile +252 -0
  57. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/README.md +40 -0
  58. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/doc/docker.dot +64 -0
  59. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/doc/docker.svg +312 -0
  60. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/doc/generate_image.sh +7 -0
  61. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/docker/amd64/Dockerfile +48 -0
  62. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/docker/toolchain/Dockerfile +34 -0
  63. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/sample/CMakeLists.txt +22 -0
  64. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/sample/main.cpp +11 -0
  65. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/vagrant/freebsd/Vagrantfile +107 -0
  66. package/node_modules/cpu-features/deps/cpu_features/cmake/googletest.CMakeLists.txt.in +15 -0
  67. package/node_modules/cpu-features/deps/cpu_features/cpu_features.gyp +105 -0
  68. package/node_modules/cpu-features/deps/cpu_features/include/cpu_features_cache_info.h +54 -0
  69. package/node_modules/cpu-features/deps/cpu_features/include/cpu_features_macros.h +384 -0
  70. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_aarch64.h +259 -0
  71. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_arm.h +121 -0
  72. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_mips.h +74 -0
  73. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_ppc.h +149 -0
  74. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_riscv.h +72 -0
  75. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_s390x.h +108 -0
  76. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_x86.h +288 -0
  77. package/node_modules/cpu-features/deps/cpu_features/include/internal/bit_utils.h +40 -0
  78. package/node_modules/cpu-features/deps/cpu_features/include/internal/cpuid_x86.h +37 -0
  79. package/node_modules/cpu-features/deps/cpu_features/include/internal/filesystem.h +39 -0
  80. package/node_modules/cpu-features/deps/cpu_features/include/internal/hwcaps.h +240 -0
  81. package/node_modules/cpu-features/deps/cpu_features/include/internal/stack_line_reader.h +49 -0
  82. package/node_modules/cpu-features/deps/cpu_features/include/internal/string_view.h +110 -0
  83. package/node_modules/cpu-features/deps/cpu_features/include/internal/windows_utils.h +70 -0
  84. package/node_modules/cpu-features/deps/cpu_features/ndk_compat/CMakeLists.txt +60 -0
  85. package/node_modules/cpu-features/deps/cpu_features/ndk_compat/README.md +4 -0
  86. package/node_modules/cpu-features/deps/cpu_features/ndk_compat/cpu-features.c +205 -0
  87. package/node_modules/cpu-features/deps/cpu_features/ndk_compat/cpu-features.h +320 -0
  88. package/node_modules/cpu-features/deps/cpu_features/ndk_compat/ndk-compat-test.c +12 -0
  89. package/node_modules/cpu-features/deps/cpu_features/patches/0001-Add-Apple-Silicon-Support.patch +456 -0
  90. package/node_modules/cpu-features/deps/cpu_features/scripts/generate_badges.d +165 -0
  91. package/node_modules/cpu-features/deps/cpu_features/scripts/make_release.sh +75 -0
  92. package/node_modules/cpu-features/deps/cpu_features/scripts/run_integration.sh +490 -0
  93. package/node_modules/cpu-features/deps/cpu_features/scripts/test_integration.sh +79 -0
  94. package/node_modules/cpu-features/deps/cpu_features/src/copy.inl +19 -0
  95. package/node_modules/cpu-features/deps/cpu_features/src/define_introspection.inl +86 -0
  96. package/node_modules/cpu-features/deps/cpu_features/src/define_introspection_and_hwcaps.inl +26 -0
  97. package/node_modules/cpu-features/deps/cpu_features/src/equals.inl +22 -0
  98. package/node_modules/cpu-features/deps/cpu_features/src/filesystem.c +62 -0
  99. package/node_modules/cpu-features/deps/cpu_features/src/hwcaps.c +169 -0
  100. package/node_modules/cpu-features/deps/cpu_features/src/impl_aarch64__base_implementation.inl +88 -0
  101. package/node_modules/cpu-features/deps/cpu_features/src/impl_aarch64_linux_or_android.c +79 -0
  102. package/node_modules/cpu-features/deps/cpu_features/src/impl_aarch64_macos_or_iphone.c +82 -0
  103. package/node_modules/cpu-features/deps/cpu_features/src/impl_aarch64_windows.c +138 -0
  104. package/node_modules/cpu-features/deps/cpu_features/src/impl_arm_linux_or_android.c +212 -0
  105. package/node_modules/cpu-features/deps/cpu_features/src/impl_mips_linux_or_android.c +93 -0
  106. package/node_modules/cpu-features/deps/cpu_features/src/impl_ppc_linux.c +163 -0
  107. package/node_modules/cpu-features/deps/cpu_features/src/impl_riscv_linux.c +111 -0
  108. package/node_modules/cpu-features/deps/cpu_features/src/impl_s390x_linux.c +120 -0
  109. package/node_modules/cpu-features/deps/cpu_features/src/impl_x86__base_implementation.inl +2055 -0
  110. package/node_modules/cpu-features/deps/cpu_features/src/impl_x86_freebsd.c +68 -0
  111. package/node_modules/cpu-features/deps/cpu_features/src/impl_x86_linux_or_android.c +58 -0
  112. package/node_modules/cpu-features/deps/cpu_features/src/impl_x86_macos.c +57 -0
  113. package/node_modules/cpu-features/deps/cpu_features/src/impl_x86_windows.c +58 -0
  114. package/node_modules/cpu-features/deps/cpu_features/src/stack_line_reader.c +132 -0
  115. package/node_modules/cpu-features/deps/cpu_features/src/string_view.c +192 -0
  116. package/node_modules/cpu-features/deps/cpu_features/src/utils/list_cpu_features.c +461 -0
  117. package/node_modules/cpu-features/deps/cpu_features/test/CMakeLists.txt +114 -0
  118. package/node_modules/cpu-features/deps/cpu_features/test/bit_utils_test.cc +53 -0
  119. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_aarch64_test.cc +396 -0
  120. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_arm_test.cc +384 -0
  121. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_mips_test.cc +176 -0
  122. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_ppc_test.cc +131 -0
  123. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_riscv_test.cc +180 -0
  124. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_s390x_test.cc +82 -0
  125. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_x86_test.cc +1729 -0
  126. package/node_modules/cpu-features/deps/cpu_features/test/filesystem_for_testing.cc +103 -0
  127. package/node_modules/cpu-features/deps/cpu_features/test/filesystem_for_testing.h +61 -0
  128. package/node_modules/cpu-features/deps/cpu_features/test/hwcaps_for_testing.cc +52 -0
  129. package/node_modules/cpu-features/deps/cpu_features/test/hwcaps_for_testing.h +31 -0
  130. package/node_modules/cpu-features/deps/cpu_features/test/stack_line_reader_test.cc +132 -0
  131. package/node_modules/cpu-features/deps/cpu_features/test/string_view_test.cc +202 -0
  132. package/node_modules/cpu-features/lib/index.js +5 -0
  133. package/node_modules/cpu-features/package.json +40 -0
  134. package/node_modules/cpu-features/src/binding.cc +151 -0
  135. package/node_modules/cpu-features/test/test.js +12 -0
  136. package/package.json +1 -1
@@ -0,0 +1,68 @@
1
+ // Copyright 2017 Google LLC
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ #include "cpu_features_macros.h"
16
+
17
+ #ifdef CPU_FEATURES_ARCH_X86
18
+ #ifdef CPU_FEATURES_OS_FREEBSD
19
+
20
+ #include "impl_x86__base_implementation.inl"
21
+
22
+ static void OverrideOsPreserves(OsPreserves* os_preserves) {
23
+ (void)os_preserves;
24
+ // No override
25
+ }
26
+
27
+ #include "internal/filesystem.h"
28
+ #include "internal/stack_line_reader.h"
29
+ #include "internal/string_view.h"
30
+
31
+ static void DetectFeaturesFromOs(X86Info* info, X86Features* features) {
32
+ (void)info;
33
+ // Handling FreeBSD platform through parsing /var/run/dmesg.boot.
34
+ const int fd = CpuFeatures_OpenFile("/var/run/dmesg.boot");
35
+ if (fd >= 0) {
36
+ StackLineReader reader;
37
+ StackLineReader_Initialize(&reader, fd);
38
+ for (bool stop = false; !stop;) {
39
+ const LineResult result = StackLineReader_NextLine(&reader);
40
+ if (result.eof) stop = true;
41
+ const StringView line = result.line;
42
+ if (!CpuFeatures_StringView_StartsWith(line, str(" Features"))) continue;
43
+ // Lines of interests are of the following form:
44
+ // " Features=0x1783fbff<PSE36,MMX,FXSR,SSE,SSE2,HTT>"
45
+ // We first extract the comma separated values between angle brackets.
46
+ StringView csv = result.line;
47
+ int index = CpuFeatures_StringView_IndexOfChar(csv, '<');
48
+ if (index >= 0) csv = CpuFeatures_StringView_PopFront(csv, index + 1);
49
+ if (csv.size > 0 && CpuFeatures_StringView_Back(csv) == '>')
50
+ csv = CpuFeatures_StringView_PopBack(csv, 1);
51
+ if (CpuFeatures_StringView_HasWord(csv, "SSE", ',')) features->sse = true;
52
+ if (CpuFeatures_StringView_HasWord(csv, "SSE2", ','))
53
+ features->sse2 = true;
54
+ if (CpuFeatures_StringView_HasWord(csv, "SSE3", ','))
55
+ features->sse3 = true;
56
+ if (CpuFeatures_StringView_HasWord(csv, "SSSE3", ','))
57
+ features->ssse3 = true;
58
+ if (CpuFeatures_StringView_HasWord(csv, "SSE4.1", ','))
59
+ features->sse4_1 = true;
60
+ if (CpuFeatures_StringView_HasWord(csv, "SSE4.2", ','))
61
+ features->sse4_2 = true;
62
+ }
63
+ CpuFeatures_CloseFile(fd);
64
+ }
65
+ }
66
+
67
+ #endif // CPU_FEATURES_OS_FREEBSD
68
+ #endif // CPU_FEATURES_ARCH_X86
@@ -0,0 +1,58 @@
1
+ // Copyright 2017 Google LLC
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ #include "cpu_features_macros.h"
16
+
17
+ #ifdef CPU_FEATURES_ARCH_X86
18
+ #if defined(CPU_FEATURES_OS_LINUX) || defined(CPU_FEATURES_OS_ANDROID)
19
+
20
+ #include "impl_x86__base_implementation.inl"
21
+
22
+ static void OverrideOsPreserves(OsPreserves* os_preserves) {
23
+ (void)os_preserves;
24
+ // No override
25
+ }
26
+
27
+ #include "internal/filesystem.h"
28
+ #include "internal/stack_line_reader.h"
29
+ #include "internal/string_view.h"
30
+ static void DetectFeaturesFromOs(X86Info* info, X86Features* features) {
31
+ (void)info;
32
+ // Handling Linux platform through /proc/cpuinfo.
33
+ const int fd = CpuFeatures_OpenFile("/proc/cpuinfo");
34
+ if (fd >= 0) {
35
+ StackLineReader reader;
36
+ StackLineReader_Initialize(&reader, fd);
37
+ for (bool stop = false; !stop;) {
38
+ const LineResult result = StackLineReader_NextLine(&reader);
39
+ if (result.eof) stop = true;
40
+ const StringView line = result.line;
41
+ StringView key, value;
42
+ if (!CpuFeatures_StringView_GetAttributeKeyValue(line, &key, &value))
43
+ continue;
44
+ if (!CpuFeatures_StringView_IsEquals(key, str("flags"))) continue;
45
+ features->sse = CpuFeatures_StringView_HasWord(value, "sse", ' ');
46
+ features->sse2 = CpuFeatures_StringView_HasWord(value, "sse2", ' ');
47
+ features->sse3 = CpuFeatures_StringView_HasWord(value, "pni", ' ');
48
+ features->ssse3 = CpuFeatures_StringView_HasWord(value, "ssse3", ' ');
49
+ features->sse4_1 = CpuFeatures_StringView_HasWord(value, "sse4_1", ' ');
50
+ features->sse4_2 = CpuFeatures_StringView_HasWord(value, "sse4_2", ' ');
51
+ break;
52
+ }
53
+ CpuFeatures_CloseFile(fd);
54
+ }
55
+ }
56
+
57
+ #endif // defined(CPU_FEATURES_OS_LINUX) || defined(CPU_FEATURES_OS_ANDROID)
58
+ #endif // CPU_FEATURES_ARCH_X86
@@ -0,0 +1,57 @@
1
+ // Copyright 2017 Google LLC
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ #include "cpu_features_macros.h"
16
+
17
+ #ifdef CPU_FEATURES_ARCH_X86
18
+ #ifdef CPU_FEATURES_OS_MACOS
19
+
20
+ #include "impl_x86__base_implementation.inl"
21
+
22
+ #if !defined(HAVE_SYSCTLBYNAME)
23
+ #error "Darwin needs support for sysctlbyname"
24
+ #endif
25
+ #include <sys/sysctl.h>
26
+
27
+ #if defined(CPU_FEATURES_MOCK_CPUID_X86)
28
+ extern bool GetDarwinSysCtlByName(const char*);
29
+ #else // CPU_FEATURES_MOCK_CPUID_X86
30
+ static bool GetDarwinSysCtlByName(const char* name) {
31
+ int enabled;
32
+ size_t enabled_len = sizeof(enabled);
33
+ const int failure = sysctlbyname(name, &enabled, &enabled_len, NULL, 0);
34
+ return failure ? false : enabled;
35
+ }
36
+ #endif
37
+
38
+ static void OverrideOsPreserves(OsPreserves* os_preserves) {
39
+ // On Darwin AVX512 support is On-demand.
40
+ // We have to query the OS instead of querying the Zmm save/restore state.
41
+ // https://github.com/apple/darwin-xnu/blob/8f02f2a044b9bb1ad951987ef5bab20ec9486310/osfmk/i386/fpu.c#L173-L199
42
+ os_preserves->avx512_registers = GetDarwinSysCtlByName("hw.optional.avx512f");
43
+ }
44
+
45
+ static void DetectFeaturesFromOs(X86Info* info, X86Features* features) {
46
+ (void)info;
47
+ // Handling Darwin platform through sysctlbyname.
48
+ features->sse = GetDarwinSysCtlByName("hw.optional.sse");
49
+ features->sse2 = GetDarwinSysCtlByName("hw.optional.sse2");
50
+ features->sse3 = GetDarwinSysCtlByName("hw.optional.sse3");
51
+ features->ssse3 = GetDarwinSysCtlByName("hw.optional.supplementalsse3");
52
+ features->sse4_1 = GetDarwinSysCtlByName("hw.optional.sse4_1");
53
+ features->sse4_2 = GetDarwinSysCtlByName("hw.optional.sse4_2");
54
+ }
55
+
56
+ #endif // CPU_FEATURES_OS_MACOS
57
+ #endif // CPU_FEATURES_ARCH_X86
@@ -0,0 +1,58 @@
1
+ // Copyright 2017 Google LLC
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ #include "cpu_features_macros.h"
16
+
17
+ #ifdef CPU_FEATURES_ARCH_X86
18
+ #ifdef CPU_FEATURES_OS_WINDOWS
19
+
20
+ #include "impl_x86__base_implementation.inl"
21
+
22
+ static void OverrideOsPreserves(OsPreserves* os_preserves) {
23
+ (void)os_preserves;
24
+ // No override
25
+ }
26
+
27
+ #include "internal/windows_utils.h"
28
+
29
+ #if defined(CPU_FEATURES_MOCK_CPUID_X86)
30
+ extern bool GetWindowsIsProcessorFeaturePresent(DWORD);
31
+ #else // CPU_FEATURES_MOCK_CPUID_X86
32
+ static bool GetWindowsIsProcessorFeaturePresent(DWORD ProcessorFeature) {
33
+ return IsProcessorFeaturePresent(ProcessorFeature);
34
+ }
35
+ #endif
36
+
37
+ static void DetectFeaturesFromOs(X86Info* info, X86Features* features) {
38
+ // Handling Windows platform through IsProcessorFeaturePresent.
39
+ // https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-isprocessorfeaturepresent
40
+ features->sse =
41
+ GetWindowsIsProcessorFeaturePresent(PF_XMMI_INSTRUCTIONS_AVAILABLE);
42
+ features->sse2 =
43
+ GetWindowsIsProcessorFeaturePresent(PF_XMMI64_INSTRUCTIONS_AVAILABLE);
44
+ features->sse3 =
45
+ GetWindowsIsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE);
46
+ features->ssse3 =
47
+ GetWindowsIsProcessorFeaturePresent(PF_SSSE3_INSTRUCTIONS_AVAILABLE);
48
+ features->sse4_1 =
49
+ GetWindowsIsProcessorFeaturePresent(PF_SSE4_1_INSTRUCTIONS_AVAILABLE);
50
+ features->sse4_2 =
51
+ GetWindowsIsProcessorFeaturePresent(PF_SSE4_2_INSTRUCTIONS_AVAILABLE);
52
+
53
+ // do not bother checking PF_AVX*
54
+ // cause AVX enabled processor will have XCR0 be exposed and this function will be skipped at all
55
+ }
56
+
57
+ #endif // CPU_FEATURES_OS_WINDOWS
58
+ #endif // CPU_FEATURES_ARCH_X86
@@ -0,0 +1,132 @@
1
+ // Copyright 2017 Google LLC
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ #include "internal/stack_line_reader.h"
16
+
17
+ #include <assert.h>
18
+ #include <errno.h>
19
+ #include <stdio.h>
20
+
21
+ #include "internal/filesystem.h"
22
+
23
+ void StackLineReader_Initialize(StackLineReader* reader, int fd) {
24
+ reader->view.ptr = reader->buffer;
25
+ reader->view.size = 0;
26
+ reader->skip_mode = false;
27
+ reader->fd = fd;
28
+ }
29
+
30
+ // Replaces the content of buffer with bytes from the file.
31
+ static int LoadFullBuffer(StackLineReader* reader) {
32
+ const int read = CpuFeatures_ReadFile(reader->fd, reader->buffer,
33
+ STACK_LINE_READER_BUFFER_SIZE);
34
+ assert(read >= 0);
35
+ reader->view.ptr = reader->buffer;
36
+ reader->view.size = read;
37
+ return read;
38
+ }
39
+
40
+ // Appends with bytes from the file to buffer, filling the remaining space.
41
+ static int LoadMore(StackLineReader* reader) {
42
+ char* const ptr = reader->buffer + reader->view.size;
43
+ const size_t size_to_read = STACK_LINE_READER_BUFFER_SIZE - reader->view.size;
44
+ const int read = CpuFeatures_ReadFile(reader->fd, ptr, size_to_read);
45
+ assert(read >= 0);
46
+ assert(read <= (int)size_to_read);
47
+ reader->view.size += read;
48
+ return read;
49
+ }
50
+
51
+ static int IndexOfEol(StackLineReader* reader) {
52
+ return CpuFeatures_StringView_IndexOfChar(reader->view, '\n');
53
+ }
54
+
55
+ // Relocate buffer's pending bytes at the beginning of the array and fills the
56
+ // remaining space with bytes from the file.
57
+ static int BringToFrontAndLoadMore(StackLineReader* reader) {
58
+ if (reader->view.size && reader->view.ptr != reader->buffer) {
59
+ memmove(reader->buffer, reader->view.ptr, reader->view.size);
60
+ }
61
+ reader->view.ptr = reader->buffer;
62
+ return LoadMore(reader);
63
+ }
64
+
65
+ // Loads chunks of buffer size from disks until it contains a newline character
66
+ // or end of file.
67
+ static void SkipToNextLine(StackLineReader* reader) {
68
+ for (;;) {
69
+ const int read = LoadFullBuffer(reader);
70
+ if (read == 0) {
71
+ break;
72
+ } else {
73
+ const int eol_index = IndexOfEol(reader);
74
+ if (eol_index >= 0) {
75
+ reader->view =
76
+ CpuFeatures_StringView_PopFront(reader->view, eol_index + 1);
77
+ break;
78
+ }
79
+ }
80
+ }
81
+ }
82
+
83
+ static LineResult CreateLineResult(bool eof, bool full_line, StringView view) {
84
+ LineResult result;
85
+ result.eof = eof;
86
+ result.full_line = full_line;
87
+ result.line = view;
88
+ return result;
89
+ }
90
+
91
+ // Helper methods to provide clearer semantic in StackLineReader_NextLine.
92
+ static LineResult CreateEOFLineResult(StringView view) {
93
+ return CreateLineResult(true, true, view);
94
+ }
95
+
96
+ static LineResult CreateTruncatedLineResult(StringView view) {
97
+ return CreateLineResult(false, false, view);
98
+ }
99
+
100
+ static LineResult CreateValidLineResult(StringView view) {
101
+ return CreateLineResult(false, true, view);
102
+ }
103
+
104
+ LineResult StackLineReader_NextLine(StackLineReader* reader) {
105
+ if (reader->skip_mode) {
106
+ SkipToNextLine(reader);
107
+ reader->skip_mode = false;
108
+ }
109
+ {
110
+ const bool can_load_more =
111
+ reader->view.size < STACK_LINE_READER_BUFFER_SIZE;
112
+ int eol_index = IndexOfEol(reader);
113
+ if (eol_index < 0 && can_load_more) {
114
+ const int read = BringToFrontAndLoadMore(reader);
115
+ if (read == 0) {
116
+ return CreateEOFLineResult(reader->view);
117
+ }
118
+ eol_index = IndexOfEol(reader);
119
+ }
120
+ if (eol_index < 0) {
121
+ reader->skip_mode = true;
122
+ return CreateTruncatedLineResult(reader->view);
123
+ }
124
+ {
125
+ StringView line =
126
+ CpuFeatures_StringView_KeepFront(reader->view, eol_index);
127
+ reader->view =
128
+ CpuFeatures_StringView_PopFront(reader->view, eol_index + 1);
129
+ return CreateValidLineResult(line);
130
+ }
131
+ }
132
+ }
@@ -0,0 +1,192 @@
1
+ // Copyright 2017 Google LLC
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ #include "internal/string_view.h"
16
+
17
+ #include <assert.h>
18
+ #include <ctype.h>
19
+
20
+ #include "copy.inl"
21
+ #include "equals.inl"
22
+
23
+ static const char* CpuFeatures_memchr(const char* const ptr, const size_t size,
24
+ const char c) {
25
+ for (size_t i = 0; ptr && ptr[i] != '\0' && i < size; ++i)
26
+ if (ptr[i] == c) return ptr + i;
27
+ return NULL;
28
+ }
29
+
30
+ int CpuFeatures_StringView_IndexOfChar(const StringView view, char c) {
31
+ if (view.ptr && view.size) {
32
+ const char* const found = CpuFeatures_memchr(view.ptr, view.size, c);
33
+ if (found) {
34
+ return (int)(found - view.ptr);
35
+ }
36
+ }
37
+ return -1;
38
+ }
39
+
40
+ int CpuFeatures_StringView_IndexOf(const StringView view,
41
+ const StringView sub_view) {
42
+ if (sub_view.size) {
43
+ StringView remainder = view;
44
+ while (remainder.size >= sub_view.size) {
45
+ const int found_index =
46
+ CpuFeatures_StringView_IndexOfChar(remainder, sub_view.ptr[0]);
47
+ if (found_index < 0) break;
48
+ remainder = CpuFeatures_StringView_PopFront(remainder, found_index);
49
+ if (CpuFeatures_StringView_StartsWith(remainder, sub_view)) {
50
+ return (int)(remainder.ptr - view.ptr);
51
+ }
52
+ remainder = CpuFeatures_StringView_PopFront(remainder, 1);
53
+ }
54
+ }
55
+ return -1;
56
+ }
57
+
58
+ bool CpuFeatures_StringView_IsEquals(const StringView a, const StringView b) {
59
+ if (a.size == b.size) {
60
+ return a.ptr == b.ptr || equals(a.ptr, b.ptr, b.size);
61
+ }
62
+ return false;
63
+ }
64
+
65
+ bool CpuFeatures_StringView_StartsWith(const StringView a, const StringView b) {
66
+ return a.ptr && b.ptr && b.size && a.size >= b.size
67
+ ? equals(a.ptr, b.ptr, b.size)
68
+ : false;
69
+ }
70
+
71
+ StringView CpuFeatures_StringView_PopFront(const StringView str_view,
72
+ size_t count) {
73
+ if (count > str_view.size) {
74
+ return kEmptyStringView;
75
+ }
76
+ return view(str_view.ptr + count, str_view.size - count);
77
+ }
78
+
79
+ StringView CpuFeatures_StringView_PopBack(const StringView str_view,
80
+ size_t count) {
81
+ if (count > str_view.size) {
82
+ return kEmptyStringView;
83
+ }
84
+ return view(str_view.ptr, str_view.size - count);
85
+ }
86
+
87
+ StringView CpuFeatures_StringView_KeepFront(const StringView str_view,
88
+ size_t count) {
89
+ return count <= str_view.size ? view(str_view.ptr, count) : str_view;
90
+ }
91
+
92
+ char CpuFeatures_StringView_Front(const StringView view) {
93
+ assert(view.size);
94
+ assert(view.ptr);
95
+ return view.ptr[0];
96
+ }
97
+
98
+ char CpuFeatures_StringView_Back(const StringView view) {
99
+ assert(view.size);
100
+ return view.ptr[view.size - 1];
101
+ }
102
+
103
+ StringView CpuFeatures_StringView_TrimWhitespace(StringView view) {
104
+ while (view.size && isspace(CpuFeatures_StringView_Front(view)))
105
+ view = CpuFeatures_StringView_PopFront(view, 1);
106
+ while (view.size && isspace(CpuFeatures_StringView_Back(view)))
107
+ view = CpuFeatures_StringView_PopBack(view, 1);
108
+ return view;
109
+ }
110
+
111
+ static int HexValue(const char c) {
112
+ if (c >= '0' && c <= '9') return c - '0';
113
+ if (c >= 'a' && c <= 'f') return c - 'a' + 10;
114
+ if (c >= 'A' && c <= 'F') return c - 'A' + 10;
115
+ return -1;
116
+ }
117
+
118
+ // Returns -1 if view contains non digits.
119
+ static int ParsePositiveNumberWithBase(const StringView view, int base) {
120
+ int result = 0;
121
+ StringView remainder = view;
122
+ for (; remainder.size;
123
+ remainder = CpuFeatures_StringView_PopFront(remainder, 1)) {
124
+ const int value = HexValue(CpuFeatures_StringView_Front(remainder));
125
+ if (value < 0 || value >= base) return -1;
126
+ result = (result * base) + value;
127
+ }
128
+ return result;
129
+ }
130
+
131
+ int CpuFeatures_StringView_ParsePositiveNumber(const StringView view) {
132
+ if (view.size) {
133
+ const StringView hex_prefix = str("0x");
134
+ if (CpuFeatures_StringView_StartsWith(view, hex_prefix)) {
135
+ const StringView span_no_prefix =
136
+ CpuFeatures_StringView_PopFront(view, hex_prefix.size);
137
+ return ParsePositiveNumberWithBase(span_no_prefix, 16);
138
+ }
139
+ return ParsePositiveNumberWithBase(view, 10);
140
+ }
141
+ return -1;
142
+ }
143
+
144
+ void CpuFeatures_StringView_CopyString(const StringView src, char* dst,
145
+ size_t dst_size) {
146
+ if (dst_size > 0) {
147
+ const size_t max_copy_size = dst_size - 1;
148
+ const size_t copy_size =
149
+ src.size > max_copy_size ? max_copy_size : src.size;
150
+ copy(dst, src.ptr, copy_size);
151
+ dst[copy_size] = '\0';
152
+ }
153
+ }
154
+
155
+ bool CpuFeatures_StringView_HasWord(const StringView line,
156
+ const char* const word_str,
157
+ const char separator) {
158
+ const StringView word = str(word_str);
159
+ StringView remainder = line;
160
+ for (;;) {
161
+ const int index_of_word = CpuFeatures_StringView_IndexOf(remainder, word);
162
+ if (index_of_word < 0) {
163
+ return false;
164
+ } else {
165
+ const StringView before =
166
+ CpuFeatures_StringView_KeepFront(line, index_of_word);
167
+ const StringView after =
168
+ CpuFeatures_StringView_PopFront(line, index_of_word + word.size);
169
+ const bool valid_before =
170
+ before.size == 0 || CpuFeatures_StringView_Back(before) == separator;
171
+ const bool valid_after =
172
+ after.size == 0 || CpuFeatures_StringView_Front(after) == separator;
173
+ if (valid_before && valid_after) return true;
174
+ remainder =
175
+ CpuFeatures_StringView_PopFront(remainder, index_of_word + word.size);
176
+ }
177
+ }
178
+ return false;
179
+ }
180
+
181
+ bool CpuFeatures_StringView_GetAttributeKeyValue(const StringView line,
182
+ StringView* key,
183
+ StringView* value) {
184
+ const StringView sep = str(": ");
185
+ const int index_of_separator = CpuFeatures_StringView_IndexOf(line, sep);
186
+ if (index_of_separator < 0) return false;
187
+ *value = CpuFeatures_StringView_TrimWhitespace(
188
+ CpuFeatures_StringView_PopFront(line, index_of_separator + sep.size));
189
+ *key = CpuFeatures_StringView_TrimWhitespace(
190
+ CpuFeatures_StringView_KeepFront(line, index_of_separator));
191
+ return true;
192
+ }