Update code
This commit is contained in:
19
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/copy.inl
generated
vendored
Normal file
19
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/copy.inl
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
static void copy(char *__restrict dst, const char *src, size_t count) {
|
||||
for (size_t i = 0; i < count; ++i) dst[i] = src[i];
|
||||
}
|
||||
86
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/define_introspection.inl
generated
vendored
Normal file
86
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/define_introspection.inl
generated
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
// Copyright 2017 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef INTROSPECTION_PREFIX
|
||||
#error "missing INTROSPECTION_PREFIX"
|
||||
#endif
|
||||
#ifndef INTROSPECTION_ENUM_PREFIX
|
||||
#error "missing INTROSPECTION_ENUM_PREFIX"
|
||||
#endif
|
||||
#ifndef INTROSPECTION_TABLE
|
||||
#error "missing INTROSPECTION_TABLE"
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#define STRINGIZE_(s) #s
|
||||
#define STRINGIZE(s) STRINGIZE_(s)
|
||||
|
||||
#define FEAT_TYPE_NAME__(X) X##Features
|
||||
#define FEAT_TYPE_NAME_(X) FEAT_TYPE_NAME__(X)
|
||||
#define FEAT_TYPE_NAME FEAT_TYPE_NAME_(INTROSPECTION_PREFIX)
|
||||
|
||||
#define FEAT_ENUM_NAME__(X) X##FeaturesEnum
|
||||
#define FEAT_ENUM_NAME_(X) FEAT_ENUM_NAME__(X)
|
||||
#define FEAT_ENUM_NAME FEAT_ENUM_NAME_(INTROSPECTION_PREFIX)
|
||||
|
||||
#define GET_FEAT_ENUM_VALUE__(X) Get##X##FeaturesEnumValue
|
||||
#define GET_FEAT_ENUM_VALUE_(X) GET_FEAT_ENUM_VALUE__(X)
|
||||
#define GET_FEAT_ENUM_VALUE GET_FEAT_ENUM_VALUE_(INTROSPECTION_PREFIX)
|
||||
|
||||
#define GET_FEAT_ENUM_NAME__(X) Get##X##FeaturesEnumName
|
||||
#define GET_FEAT_ENUM_NAME_(X) GET_FEAT_ENUM_NAME__(X)
|
||||
#define GET_FEAT_ENUM_NAME GET_FEAT_ENUM_NAME_(INTROSPECTION_PREFIX)
|
||||
|
||||
#define FEAT_ENUM_LAST__(X) X##_LAST_
|
||||
#define FEAT_ENUM_LAST_(X) FEAT_ENUM_LAST__(X)
|
||||
#define FEAT_ENUM_LAST FEAT_ENUM_LAST_(INTROSPECTION_ENUM_PREFIX)
|
||||
|
||||
// Generate individual getters and setters.
|
||||
#define LINE(ENUM, NAME, A, B, C) \
|
||||
static void set_##ENUM(FEAT_TYPE_NAME* features, bool value) { \
|
||||
features->NAME = value; \
|
||||
} \
|
||||
static int get_##ENUM(const FEAT_TYPE_NAME* features) { \
|
||||
return features->NAME; \
|
||||
}
|
||||
INTROSPECTION_TABLE
|
||||
#undef LINE
|
||||
|
||||
// Generate getters table
|
||||
#define LINE(ENUM, NAME, A, B, C) [ENUM] = get_##ENUM,
|
||||
static int (*const kGetters[])(const FEAT_TYPE_NAME*) = {INTROSPECTION_TABLE};
|
||||
#undef LINE
|
||||
|
||||
// Generate setters table
|
||||
#define LINE(ENUM, NAME, A, B, C) [ENUM] = set_##ENUM,
|
||||
static void (*const kSetters[])(FEAT_TYPE_NAME*, bool) = {INTROSPECTION_TABLE};
|
||||
#undef LINE
|
||||
|
||||
// Implements the `GetXXXFeaturesEnumValue` API.
|
||||
int GET_FEAT_ENUM_VALUE(const FEAT_TYPE_NAME* features, FEAT_ENUM_NAME value) {
|
||||
if (value >= FEAT_ENUM_LAST) return false;
|
||||
return kGetters[value](features);
|
||||
}
|
||||
|
||||
// Generate feature name table.
|
||||
#define LINE(ENUM, NAME, A, B, C) [ENUM] = STRINGIZE(NAME),
|
||||
static const char* kFeatureNames[] = {INTROSPECTION_TABLE};
|
||||
#undef LINE
|
||||
|
||||
// Implements the `GetXXXFeaturesEnumName` API.
|
||||
const char* GET_FEAT_ENUM_NAME(FEAT_ENUM_NAME value) {
|
||||
if (value >= FEAT_ENUM_LAST) return "unknown_feature";
|
||||
return kFeatureNames[value];
|
||||
}
|
||||
26
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/define_introspection_and_hwcaps.inl
generated
vendored
Normal file
26
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/define_introspection_and_hwcaps.inl
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
// Copyright 2017 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "define_introspection.inl"
|
||||
#include "internal/hwcaps.h"
|
||||
|
||||
#define LINE(ENUM, NAME, CPUINFO_FLAG, HWCAP, HWCAP2) \
|
||||
[ENUM] = (HardwareCapabilities){HWCAP, HWCAP2},
|
||||
static const HardwareCapabilities kHardwareCapabilities[] = {
|
||||
INTROSPECTION_TABLE};
|
||||
#undef LINE
|
||||
|
||||
#define LINE(ENUM, NAME, CPUINFO_FLAG, HWCAP, HWCAP2) [ENUM] = CPUINFO_FLAG,
|
||||
static const char* kCpuInfoFlags[] = {INTROSPECTION_TABLE};
|
||||
#undef LINE
|
||||
22
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/equals.inl
generated
vendored
Normal file
22
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/equals.inl
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
static bool equals(const char *lhs, const char *rhs, size_t count) {
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
if (lhs[i] != rhs[i]) return false;
|
||||
return true;
|
||||
}
|
||||
62
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/filesystem.c
generated
vendored
Normal file
62
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/filesystem.c
generated
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
// Copyright 2017 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "internal/filesystem.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#if defined(CPU_FEATURES_MOCK_FILESYSTEM)
|
||||
// Implementation will be provided by test/filesystem_for_testing.cc.
|
||||
#elif defined(_MSC_VER)
|
||||
#include <io.h>
|
||||
int CpuFeatures_OpenFile(const char* filename) {
|
||||
int fd = -1;
|
||||
_sopen_s(&fd, filename, _O_RDONLY, _SH_DENYWR, _S_IREAD);
|
||||
return fd;
|
||||
}
|
||||
|
||||
void CpuFeatures_CloseFile(int file_descriptor) { _close(file_descriptor); }
|
||||
|
||||
int CpuFeatures_ReadFile(int file_descriptor, void* buffer,
|
||||
size_t buffer_size) {
|
||||
return _read(file_descriptor, buffer, (unsigned int)buffer_size);
|
||||
}
|
||||
|
||||
#else
|
||||
#include <unistd.h>
|
||||
|
||||
int CpuFeatures_OpenFile(const char* filename) {
|
||||
int result;
|
||||
do {
|
||||
result = open(filename, O_RDONLY);
|
||||
} while (result == -1L && errno == EINTR);
|
||||
return result;
|
||||
}
|
||||
|
||||
void CpuFeatures_CloseFile(int file_descriptor) { close(file_descriptor); }
|
||||
|
||||
int CpuFeatures_ReadFile(int file_descriptor, void* buffer,
|
||||
size_t buffer_size) {
|
||||
int result;
|
||||
do {
|
||||
result = read(file_descriptor, buffer, buffer_size);
|
||||
} while (result == -1L && errno == EINTR);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
||||
169
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/hwcaps.c
generated
vendored
Normal file
169
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/hwcaps.c
generated
vendored
Normal file
@@ -0,0 +1,169 @@
|
||||
// Copyright 2017 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "internal/hwcaps.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "cpu_features_macros.h"
|
||||
#include "internal/filesystem.h"
|
||||
#include "internal/string_view.h"
|
||||
|
||||
static bool IsSet(const uint32_t mask, const uint32_t value) {
|
||||
if (mask == 0) return false;
|
||||
return (value & mask) == mask;
|
||||
}
|
||||
|
||||
bool CpuFeatures_IsHwCapsSet(const HardwareCapabilities hwcaps_mask,
|
||||
const HardwareCapabilities hwcaps) {
|
||||
return IsSet(hwcaps_mask.hwcaps, hwcaps.hwcaps) ||
|
||||
IsSet(hwcaps_mask.hwcaps2, hwcaps.hwcaps2);
|
||||
}
|
||||
|
||||
#ifdef CPU_FEATURES_TEST
|
||||
// In test mode, hwcaps_for_testing will define the following functions.
|
||||
HardwareCapabilities CpuFeatures_GetHardwareCapabilities(void);
|
||||
const char* CpuFeatures_GetPlatformPointer(void);
|
||||
const char* CpuFeatures_GetBasePlatformPointer(void);
|
||||
#else
|
||||
|
||||
// Debug facilities
|
||||
#if defined(NDEBUG)
|
||||
#define D(...)
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#define D(...) \
|
||||
do { \
|
||||
printf(__VA_ARGS__); \
|
||||
fflush(stdout); \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Implementation of GetElfHwcapFromGetauxval
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define AT_HWCAP 16
|
||||
#define AT_HWCAP2 26
|
||||
#define AT_PLATFORM 15
|
||||
#define AT_BASE_PLATFORM 24
|
||||
|
||||
#if defined(HAVE_STRONG_GETAUXVAL)
|
||||
#include <sys/auxv.h>
|
||||
static unsigned long GetElfHwcapFromGetauxval(uint32_t hwcap_type) {
|
||||
return getauxval(hwcap_type);
|
||||
}
|
||||
#elif defined(HAVE_DLFCN_H)
|
||||
// On Android we probe the system's C library for a 'getauxval' function and
|
||||
// call it if it exits, or return 0 for failure. This function is available
|
||||
// since API level 18.
|
||||
//
|
||||
// Note that getauxval() can't really be re-implemented here, because its
|
||||
// implementation does not parse /proc/self/auxv. Instead it depends on values
|
||||
// that are passed by the kernel at process-init time to the C runtime
|
||||
// initialization layer.
|
||||
|
||||
#include <dlfcn.h>
|
||||
|
||||
typedef unsigned long getauxval_func_t(unsigned long);
|
||||
|
||||
static uint32_t GetElfHwcapFromGetauxval(uint32_t hwcap_type) {
|
||||
uint32_t ret = 0;
|
||||
void *libc_handle = NULL;
|
||||
getauxval_func_t *func = NULL;
|
||||
|
||||
dlerror(); // Cleaning error state before calling dlopen.
|
||||
libc_handle = dlopen("libc.so", RTLD_NOW);
|
||||
if (!libc_handle) {
|
||||
D("Could not dlopen() C library: %s\n", dlerror());
|
||||
return 0;
|
||||
}
|
||||
func = (getauxval_func_t *)dlsym(libc_handle, "getauxval");
|
||||
if (!func) {
|
||||
D("Could not find getauxval() in C library\n");
|
||||
} else {
|
||||
// Note: getauxval() returns 0 on failure. Doesn't touch errno.
|
||||
ret = (uint32_t)(*func)(hwcap_type);
|
||||
}
|
||||
dlclose(libc_handle);
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
#error "This platform does not provide hardware capabilities."
|
||||
#endif
|
||||
|
||||
// Implementation of GetHardwareCapabilities for OS that provide
|
||||
// GetElfHwcapFromGetauxval().
|
||||
|
||||
// Fallback when getauxval is not available, retrieves hwcaps from
|
||||
// "/proc/self/auxv".
|
||||
static uint32_t GetElfHwcapFromProcSelfAuxv(uint32_t hwcap_type) {
|
||||
struct {
|
||||
uint32_t tag;
|
||||
uint32_t value;
|
||||
} entry;
|
||||
uint32_t result = 0;
|
||||
const char filepath[] = "/proc/self/auxv";
|
||||
const int fd = CpuFeatures_OpenFile(filepath);
|
||||
if (fd < 0) {
|
||||
D("Could not open %s\n", filepath);
|
||||
return 0;
|
||||
}
|
||||
for (;;) {
|
||||
const int ret = CpuFeatures_ReadFile(fd, (char *)&entry, sizeof entry);
|
||||
if (ret < 0) {
|
||||
D("Error while reading %s\n", filepath);
|
||||
break;
|
||||
}
|
||||
// Detect end of list.
|
||||
if (ret == 0 || (entry.tag == 0 && entry.value == 0)) {
|
||||
break;
|
||||
}
|
||||
if (entry.tag == hwcap_type) {
|
||||
result = entry.value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
CpuFeatures_CloseFile(fd);
|
||||
return result;
|
||||
}
|
||||
|
||||
// Retrieves hardware capabilities by first trying to call getauxval, if not
|
||||
// available falls back to reading "/proc/self/auxv".
|
||||
static unsigned long GetHardwareCapabilitiesFor(uint32_t type) {
|
||||
unsigned long hwcaps = GetElfHwcapFromGetauxval(type);
|
||||
if (!hwcaps) {
|
||||
D("Parsing /proc/self/auxv to extract ELF hwcaps!\n");
|
||||
hwcaps = GetElfHwcapFromProcSelfAuxv(type);
|
||||
}
|
||||
return hwcaps;
|
||||
}
|
||||
|
||||
HardwareCapabilities CpuFeatures_GetHardwareCapabilities(void) {
|
||||
HardwareCapabilities capabilities;
|
||||
capabilities.hwcaps = GetHardwareCapabilitiesFor(AT_HWCAP);
|
||||
capabilities.hwcaps2 = GetHardwareCapabilitiesFor(AT_HWCAP2);
|
||||
return capabilities;
|
||||
}
|
||||
|
||||
const char *CpuFeatures_GetPlatformPointer(void) {
|
||||
return (const char *)GetHardwareCapabilitiesFor(AT_PLATFORM);
|
||||
}
|
||||
|
||||
const char *CpuFeatures_GetBasePlatformPointer(void) {
|
||||
return (const char *)GetHardwareCapabilitiesFor(AT_BASE_PLATFORM);
|
||||
}
|
||||
|
||||
#endif // CPU_FEATURES_TEST
|
||||
88
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/impl_aarch64__base_implementation.inl
generated
vendored
Normal file
88
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/impl_aarch64__base_implementation.inl
generated
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "cpuinfo_aarch64.h"
|
||||
#include "internal/bit_utils.h"
|
||||
#include "internal/filesystem.h"
|
||||
#include "internal/stack_line_reader.h"
|
||||
#include "internal/string_view.h"
|
||||
|
||||
#if !defined(CPU_FEATURES_ARCH_AARCH64)
|
||||
#error "Cannot compile aarch64_base on a non aarch64 platform."
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Definitions for introspection.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#define INTROSPECTION_TABLE \
|
||||
LINE(AARCH64_FP, fp, "fp", AARCH64_HWCAP_FP, 0) \
|
||||
LINE(AARCH64_ASIMD, asimd, "asimd", AARCH64_HWCAP_ASIMD, 0) \
|
||||
LINE(AARCH64_EVTSTRM, evtstrm, "evtstrm", AARCH64_HWCAP_EVTSTRM, 0) \
|
||||
LINE(AARCH64_AES, aes, "aes", AARCH64_HWCAP_AES, 0) \
|
||||
LINE(AARCH64_PMULL, pmull, "pmull", AARCH64_HWCAP_PMULL, 0) \
|
||||
LINE(AARCH64_SHA1, sha1, "sha1", AARCH64_HWCAP_SHA1, 0) \
|
||||
LINE(AARCH64_SHA2, sha2, "sha2", AARCH64_HWCAP_SHA2, 0) \
|
||||
LINE(AARCH64_CRC32, crc32, "crc32", AARCH64_HWCAP_CRC32, 0) \
|
||||
LINE(AARCH64_ATOMICS, atomics, "atomics", AARCH64_HWCAP_ATOMICS, 0) \
|
||||
LINE(AARCH64_FPHP, fphp, "fphp", AARCH64_HWCAP_FPHP, 0) \
|
||||
LINE(AARCH64_ASIMDHP, asimdhp, "asimdhp", AARCH64_HWCAP_ASIMDHP, 0) \
|
||||
LINE(AARCH64_CPUID, cpuid, "cpuid", AARCH64_HWCAP_CPUID, 0) \
|
||||
LINE(AARCH64_ASIMDRDM, asimdrdm, "asimdrdm", AARCH64_HWCAP_ASIMDRDM, 0) \
|
||||
LINE(AARCH64_JSCVT, jscvt, "jscvt", AARCH64_HWCAP_JSCVT, 0) \
|
||||
LINE(AARCH64_FCMA, fcma, "fcma", AARCH64_HWCAP_FCMA, 0) \
|
||||
LINE(AARCH64_LRCPC, lrcpc, "lrcpc", AARCH64_HWCAP_LRCPC, 0) \
|
||||
LINE(AARCH64_DCPOP, dcpop, "dcpop", AARCH64_HWCAP_DCPOP, 0) \
|
||||
LINE(AARCH64_SHA3, sha3, "sha3", AARCH64_HWCAP_SHA3, 0) \
|
||||
LINE(AARCH64_SM3, sm3, "sm3", AARCH64_HWCAP_SM3, 0) \
|
||||
LINE(AARCH64_SM4, sm4, "sm4", AARCH64_HWCAP_SM4, 0) \
|
||||
LINE(AARCH64_ASIMDDP, asimddp, "asimddp", AARCH64_HWCAP_ASIMDDP, 0) \
|
||||
LINE(AARCH64_SHA512, sha512, "sha512", AARCH64_HWCAP_SHA512, 0) \
|
||||
LINE(AARCH64_SVE, sve, "sve", AARCH64_HWCAP_SVE, 0) \
|
||||
LINE(AARCH64_ASIMDFHM, asimdfhm, "asimdfhm", AARCH64_HWCAP_ASIMDFHM, 0) \
|
||||
LINE(AARCH64_DIT, dit, "dit", AARCH64_HWCAP_DIT, 0) \
|
||||
LINE(AARCH64_USCAT, uscat, "uscat", AARCH64_HWCAP_USCAT, 0) \
|
||||
LINE(AARCH64_ILRCPC, ilrcpc, "ilrcpc", AARCH64_HWCAP_ILRCPC, 0) \
|
||||
LINE(AARCH64_FLAGM, flagm, "flagm", AARCH64_HWCAP_FLAGM, 0) \
|
||||
LINE(AARCH64_SSBS, ssbs, "ssbs", AARCH64_HWCAP_SSBS, 0) \
|
||||
LINE(AARCH64_SB, sb, "sb", AARCH64_HWCAP_SB, 0) \
|
||||
LINE(AARCH64_PACA, paca, "paca", AARCH64_HWCAP_PACA, 0) \
|
||||
LINE(AARCH64_PACG, pacg, "pacg", AARCH64_HWCAP_PACG, 0) \
|
||||
LINE(AARCH64_DCPODP, dcpodp, "dcpodp", 0, AARCH64_HWCAP2_DCPODP) \
|
||||
LINE(AARCH64_SVE2, sve2, "sve2", 0, AARCH64_HWCAP2_SVE2) \
|
||||
LINE(AARCH64_SVEAES, sveaes, "sveaes", 0, AARCH64_HWCAP2_SVEAES) \
|
||||
LINE(AARCH64_SVEPMULL, svepmull, "svepmull", 0, AARCH64_HWCAP2_SVEPMULL) \
|
||||
LINE(AARCH64_SVEBITPERM, svebitperm, "svebitperm", 0, \
|
||||
AARCH64_HWCAP2_SVEBITPERM) \
|
||||
LINE(AARCH64_SVESHA3, svesha3, "svesha3", 0, AARCH64_HWCAP2_SVESHA3) \
|
||||
LINE(AARCH64_SVESM4, svesm4, "svesm4", 0, AARCH64_HWCAP2_SVESM4) \
|
||||
LINE(AARCH64_FLAGM2, flagm2, "flagm2", 0, AARCH64_HWCAP2_FLAGM2) \
|
||||
LINE(AARCH64_FRINT, frint, "frint", 0, AARCH64_HWCAP2_FRINT) \
|
||||
LINE(AARCH64_SVEI8MM, svei8mm, "svei8mm", 0, AARCH64_HWCAP2_SVEI8MM) \
|
||||
LINE(AARCH64_SVEF32MM, svef32mm, "svef32mm", 0, AARCH64_HWCAP2_SVEF32MM) \
|
||||
LINE(AARCH64_SVEF64MM, svef64mm, "svef64mm", 0, AARCH64_HWCAP2_SVEF64MM) \
|
||||
LINE(AARCH64_SVEBF16, svebf16, "svebf16", 0, AARCH64_HWCAP2_SVEBF16) \
|
||||
LINE(AARCH64_I8MM, i8mm, "i8mm", 0, AARCH64_HWCAP2_I8MM) \
|
||||
LINE(AARCH64_BF16, bf16, "bf16", 0, AARCH64_HWCAP2_BF16) \
|
||||
LINE(AARCH64_DGH, dgh, "dgh", 0, AARCH64_HWCAP2_DGH) \
|
||||
LINE(AARCH64_RNG, rng, "rng", 0, AARCH64_HWCAP2_RNG) \
|
||||
LINE(AARCH64_BTI, bti, "bti", 0, AARCH64_HWCAP2_BTI) \
|
||||
LINE(AARCH64_MTE, mte, "mte", 0, AARCH64_HWCAP2_MTE) \
|
||||
LINE(AARCH64_ECV, ecv, "ecv", 0, AARCH64_HWCAP2_ECV) \
|
||||
LINE(AARCH64_AFP, afp, "afp", 0, AARCH64_HWCAP2_AFP) \
|
||||
LINE(AARCH64_RPRES, rpres, "rpres", 0, AARCH64_HWCAP2_RPRES)
|
||||
#define INTROSPECTION_PREFIX Aarch64
|
||||
#define INTROSPECTION_ENUM_PREFIX AARCH64
|
||||
#include "define_introspection_and_hwcaps.inl"
|
||||
79
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/impl_aarch64_linux_or_android.c
generated
vendored
Normal file
79
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/impl_aarch64_linux_or_android.c
generated
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
// Copyright 2017 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "cpu_features_macros.h"
|
||||
|
||||
#ifdef CPU_FEATURES_ARCH_AARCH64
|
||||
#if defined(CPU_FEATURES_OS_LINUX) || defined(CPU_FEATURES_OS_ANDROID)
|
||||
|
||||
#include "impl_aarch64__base_implementation.inl"
|
||||
|
||||
static bool HandleAarch64Line(const LineResult result,
|
||||
Aarch64Info* const info) {
|
||||
StringView line = result.line;
|
||||
StringView key, value;
|
||||
if (CpuFeatures_StringView_GetAttributeKeyValue(line, &key, &value)) {
|
||||
if (CpuFeatures_StringView_IsEquals(key, str("Features"))) {
|
||||
for (size_t i = 0; i < AARCH64_LAST_; ++i) {
|
||||
kSetters[i](&info->features, CpuFeatures_StringView_HasWord(
|
||||
value, kCpuInfoFlags[i], ' '));
|
||||
}
|
||||
} else if (CpuFeatures_StringView_IsEquals(key, str("CPU implementer"))) {
|
||||
info->implementer = CpuFeatures_StringView_ParsePositiveNumber(value);
|
||||
} else if (CpuFeatures_StringView_IsEquals(key, str("CPU variant"))) {
|
||||
info->variant = CpuFeatures_StringView_ParsePositiveNumber(value);
|
||||
} else if (CpuFeatures_StringView_IsEquals(key, str("CPU part"))) {
|
||||
info->part = CpuFeatures_StringView_ParsePositiveNumber(value);
|
||||
} else if (CpuFeatures_StringView_IsEquals(key, str("CPU revision"))) {
|
||||
info->revision = CpuFeatures_StringView_ParsePositiveNumber(value);
|
||||
}
|
||||
}
|
||||
return !result.eof;
|
||||
}
|
||||
|
||||
static void FillProcCpuInfoData(Aarch64Info* const info) {
|
||||
const int fd = CpuFeatures_OpenFile("/proc/cpuinfo");
|
||||
if (fd >= 0) {
|
||||
StackLineReader reader;
|
||||
StackLineReader_Initialize(&reader, fd);
|
||||
for (;;) {
|
||||
if (!HandleAarch64Line(StackLineReader_NextLine(&reader), info)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
CpuFeatures_CloseFile(fd);
|
||||
}
|
||||
}
|
||||
|
||||
static const Aarch64Info kEmptyAarch64Info;
|
||||
|
||||
Aarch64Info GetAarch64Info(void) {
|
||||
// capabilities are fetched from both getauxval and /proc/cpuinfo so we can
|
||||
// have some information if the executable is sandboxed (aka no access to
|
||||
// /proc/cpuinfo).
|
||||
Aarch64Info info = kEmptyAarch64Info;
|
||||
|
||||
FillProcCpuInfoData(&info);
|
||||
const HardwareCapabilities hwcaps = CpuFeatures_GetHardwareCapabilities();
|
||||
for (size_t i = 0; i < AARCH64_LAST_; ++i) {
|
||||
if (CpuFeatures_IsHwCapsSet(kHardwareCapabilities[i], hwcaps)) {
|
||||
kSetters[i](&info.features, true);
|
||||
}
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
#endif // defined(CPU_FEATURES_OS_LINUX) || defined(CPU_FEATURES_OS_ANDROID)
|
||||
#endif // CPU_FEATURES_ARCH_AARCH64
|
||||
82
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/impl_aarch64_macos_or_iphone.c
generated
vendored
Normal file
82
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/impl_aarch64_macos_or_iphone.c
generated
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "cpu_features_macros.h"
|
||||
|
||||
#ifdef CPU_FEATURES_ARCH_AARCH64
|
||||
#if defined(CPU_FEATURES_OS_MACOS) || defined(CPU_FEATURES_OS_IPHONE)
|
||||
|
||||
#include "impl_aarch64__base_implementation.inl"
|
||||
|
||||
#if !defined(HAVE_SYSCTLBYNAME)
|
||||
#error "Darwin needs support for sysctlbyname"
|
||||
#endif
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
#if defined(CPU_FEATURES_MOCK_SYSCTL_AARCH64)
|
||||
extern bool GetDarwinSysCtlByName(const char*);
|
||||
extern int GetDarwinSysCtlByNameValue(const char* name);
|
||||
#else
|
||||
static int GetDarwinSysCtlByNameValue(const char* name) {
|
||||
int enabled;
|
||||
size_t enabled_len = sizeof(enabled);
|
||||
const int failure = sysctlbyname(name, &enabled, &enabled_len, NULL, 0);
|
||||
return failure ? 0 : enabled;
|
||||
}
|
||||
|
||||
static bool GetDarwinSysCtlByName(const char* name) {
|
||||
return GetDarwinSysCtlByNameValue(name) != 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static const Aarch64Info kEmptyAarch64Info;
|
||||
|
||||
Aarch64Info GetAarch64Info(void) {
|
||||
Aarch64Info info = kEmptyAarch64Info;
|
||||
|
||||
// Handling Darwin platform through sysctlbyname.
|
||||
info.implementer = GetDarwinSysCtlByNameValue("hw.cputype");
|
||||
info.variant = GetDarwinSysCtlByNameValue("hw.cpusubtype");
|
||||
info.part = GetDarwinSysCtlByNameValue("hw.cpufamily");
|
||||
info.revision = GetDarwinSysCtlByNameValue("hw.cpusubfamily");
|
||||
|
||||
info.features.fp = GetDarwinSysCtlByName("hw.optional.floatingpoint");
|
||||
info.features.asimd = GetDarwinSysCtlByName("hw.optional.AdvSIMD");
|
||||
info.features.aes = GetDarwinSysCtlByName("hw.optional.arm.FEAT_AES");
|
||||
info.features.pmull = GetDarwinSysCtlByName("hw.optional.arm.FEAT_PMULL");
|
||||
info.features.sha1 = GetDarwinSysCtlByName("hw.optional.arm.FEAT_SHA1");
|
||||
info.features.sha2 = GetDarwinSysCtlByName("hw.optional.arm.FEAT_SHA2");
|
||||
info.features.crc32 = GetDarwinSysCtlByName("hw.optional.armv8_crc32");
|
||||
info.features.atomics = GetDarwinSysCtlByName("hw.optional.armv8_1_atomics");
|
||||
info.features.fphp = GetDarwinSysCtlByName("hw.optional.neon_hpfp");
|
||||
info.features.jscvt = GetDarwinSysCtlByName("hw.optional.arm.FEAT_JSCVT");
|
||||
info.features.fcma = GetDarwinSysCtlByName("hw.optional.arm.FEAT_FCMA");
|
||||
info.features.lrcpc = GetDarwinSysCtlByName("hw.optional.arm.FEAT_LRCPC");
|
||||
info.features.sha3 = GetDarwinSysCtlByName("hw.optional.armv8_2_sha3");
|
||||
info.features.sha512 = GetDarwinSysCtlByName("hw.optional.armv8_2_sha512");
|
||||
info.features.asimdfhm = GetDarwinSysCtlByName("hw.optional.armv8_2_fhm");
|
||||
info.features.flagm = GetDarwinSysCtlByName("hw.optional.arm.FEAT_FLAGM");
|
||||
info.features.flagm2 = GetDarwinSysCtlByName("hw.optional.arm.FEAT_FLAGM2");
|
||||
info.features.ssbs = GetDarwinSysCtlByName("hw.optional.arm.FEAT_SSBS");
|
||||
info.features.sb = GetDarwinSysCtlByName("hw.optional.arm.FEAT_SB");
|
||||
info.features.i8mm = GetDarwinSysCtlByName("hw.optional.arm.FEAT_I8MM");
|
||||
info.features.bf16 = GetDarwinSysCtlByName("hw.optional.arm.FEAT_BF16");
|
||||
info.features.bti = GetDarwinSysCtlByName("hw.optional.arm.FEAT_BTI");
|
||||
info.features.ecv = GetDarwinSysCtlByName("hw.optional.arm.FEAT_ECV");
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
#endif // defined(CPU_FEATURES_OS_MACOS) || defined(CPU_FEATURES_OS_IPHONE)
|
||||
#endif // CPU_FEATURES_ARCH_AARCH64
|
||||
138
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/impl_aarch64_windows.c
generated
vendored
Normal file
138
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/impl_aarch64_windows.c
generated
vendored
Normal file
@@ -0,0 +1,138 @@
|
||||
// Copyright 2023 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "cpu_features_macros.h"
|
||||
|
||||
#ifdef CPU_FEATURES_ARCH_AARCH64
|
||||
#ifdef CPU_FEATURES_OS_WINDOWS
|
||||
|
||||
#include "cpuinfo_aarch64.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Definitions for introspection.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#define INTROSPECTION_TABLE \
|
||||
LINE(AARCH64_FP, fp, , , ) \
|
||||
LINE(AARCH64_ASIMD, asimd, , , ) \
|
||||
LINE(AARCH64_EVTSTRM, evtstrm, , , ) \
|
||||
LINE(AARCH64_AES, aes, , , ) \
|
||||
LINE(AARCH64_PMULL, pmull, , , ) \
|
||||
LINE(AARCH64_SHA1, sha1, , , ) \
|
||||
LINE(AARCH64_SHA2, sha2, , , ) \
|
||||
LINE(AARCH64_CRC32, crc32, , , ) \
|
||||
LINE(AARCH64_ATOMICS, atomics, , , ) \
|
||||
LINE(AARCH64_FPHP, fphp, , , ) \
|
||||
LINE(AARCH64_ASIMDHP, asimdhp, , , ) \
|
||||
LINE(AARCH64_CPUID, cpuid, , , ) \
|
||||
LINE(AARCH64_ASIMDRDM, asimdrdm, , , ) \
|
||||
LINE(AARCH64_JSCVT, jscvt, , , ) \
|
||||
LINE(AARCH64_FCMA, fcma, , , ) \
|
||||
LINE(AARCH64_LRCPC, lrcpc, , , ) \
|
||||
LINE(AARCH64_DCPOP, dcpop, , , ) \
|
||||
LINE(AARCH64_SHA3, sha3, , , ) \
|
||||
LINE(AARCH64_SM3, sm3, , , ) \
|
||||
LINE(AARCH64_SM4, sm4, , , ) \
|
||||
LINE(AARCH64_ASIMDDP, asimddp, , , ) \
|
||||
LINE(AARCH64_SHA512, sha512, , , ) \
|
||||
LINE(AARCH64_SVE, sve, , , ) \
|
||||
LINE(AARCH64_ASIMDFHM, asimdfhm, , , ) \
|
||||
LINE(AARCH64_DIT, dit, , , ) \
|
||||
LINE(AARCH64_USCAT, uscat, , , ) \
|
||||
LINE(AARCH64_ILRCPC, ilrcpc, , , ) \
|
||||
LINE(AARCH64_FLAGM, flagm, , , ) \
|
||||
LINE(AARCH64_SSBS, ssbs, , , ) \
|
||||
LINE(AARCH64_SB, sb, , , ) \
|
||||
LINE(AARCH64_PACA, paca, , , ) \
|
||||
LINE(AARCH64_PACG, pacg, , , ) \
|
||||
LINE(AARCH64_DCPODP, dcpodp, , , ) \
|
||||
LINE(AARCH64_SVE2, sve2, , , ) \
|
||||
LINE(AARCH64_SVEAES, sveaes, , , ) \
|
||||
LINE(AARCH64_SVEPMULL, svepmull, , , ) \
|
||||
LINE(AARCH64_SVEBITPERM, svebitperm, , , ) \
|
||||
LINE(AARCH64_SVESHA3, svesha3, , , ) \
|
||||
LINE(AARCH64_SVESM4, svesm4, , , ) \
|
||||
LINE(AARCH64_FLAGM2, flagm2, , , ) \
|
||||
LINE(AARCH64_FRINT, frint, , , ) \
|
||||
LINE(AARCH64_SVEI8MM, svei8mm, , , ) \
|
||||
LINE(AARCH64_SVEF32MM, svef32mm, , , ) \
|
||||
LINE(AARCH64_SVEF64MM, svef64mm, , , ) \
|
||||
LINE(AARCH64_SVEBF16, svebf16, , , ) \
|
||||
LINE(AARCH64_I8MM, i8mm, , , ) \
|
||||
LINE(AARCH64_BF16, bf16, , , ) \
|
||||
LINE(AARCH64_DGH, dgh, , , ) \
|
||||
LINE(AARCH64_RNG, rng, , , ) \
|
||||
LINE(AARCH64_BTI, bti, , , ) \
|
||||
LINE(AARCH64_MTE, mte, , , ) \
|
||||
LINE(AARCH64_ECV, ecv, , , ) \
|
||||
LINE(AARCH64_AFP, afp, , , ) \
|
||||
LINE(AARCH64_RPRES, rpres, , , )
|
||||
#define INTROSPECTION_PREFIX Aarch64
|
||||
#define INTROSPECTION_ENUM_PREFIX AARCH64
|
||||
#include "define_introspection.inl"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Implementation.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "internal/windows_utils.h"
|
||||
|
||||
#ifdef CPU_FEATURES_MOCK_CPUID_AARCH64
|
||||
extern bool GetWindowsIsProcessorFeaturePresent(DWORD);
|
||||
extern WORD GetWindowsNativeSystemInfoProcessorRevision();
|
||||
#else // CPU_FEATURES_MOCK_CPUID_AARCH64
|
||||
static bool GetWindowsIsProcessorFeaturePresent(DWORD dwProcessorFeature) {
|
||||
return IsProcessorFeaturePresent(dwProcessorFeature);
|
||||
}
|
||||
|
||||
static WORD GetWindowsNativeSystemInfoProcessorRevision() {
|
||||
SYSTEM_INFO system_info;
|
||||
GetNativeSystemInfo(&system_info);
|
||||
return system_info.wProcessorRevision;
|
||||
}
|
||||
#endif
|
||||
|
||||
static const Aarch64Info kEmptyAarch64Info;
|
||||
|
||||
Aarch64Info GetAarch64Info(void) {
|
||||
Aarch64Info info = kEmptyAarch64Info;
|
||||
info.revision = GetWindowsNativeSystemInfoProcessorRevision();
|
||||
info.features.fp =
|
||||
GetWindowsIsProcessorFeaturePresent(PF_ARM_VFP_32_REGISTERS_AVAILABLE);
|
||||
info.features.asimd =
|
||||
GetWindowsIsProcessorFeaturePresent(PF_ARM_NEON_INSTRUCTIONS_AVAILABLE);
|
||||
info.features.crc32 = GetWindowsIsProcessorFeaturePresent(
|
||||
PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE);
|
||||
info.features.asimddp =
|
||||
GetWindowsIsProcessorFeaturePresent(PF_ARM_V82_DP_INSTRUCTIONS_AVAILABLE);
|
||||
info.features.jscvt = GetWindowsIsProcessorFeaturePresent(
|
||||
PF_ARM_V83_JSCVT_INSTRUCTIONS_AVAILABLE);
|
||||
info.features.lrcpc = GetWindowsIsProcessorFeaturePresent(
|
||||
PF_ARM_V83_LRCPC_INSTRUCTIONS_AVAILABLE);
|
||||
info.features.atomics = GetWindowsIsProcessorFeaturePresent(
|
||||
PF_ARM_V81_ATOMIC_INSTRUCTIONS_AVAILABLE);
|
||||
|
||||
|
||||
bool is_crypto_available = GetWindowsIsProcessorFeaturePresent(
|
||||
PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE);
|
||||
info.features.aes = is_crypto_available;
|
||||
info.features.sha1 = is_crypto_available;
|
||||
info.features.sha2 = is_crypto_available;
|
||||
info.features.pmull = is_crypto_available;
|
||||
return info;
|
||||
}
|
||||
|
||||
#endif // CPU_FEATURES_OS_WINDOWS
|
||||
#endif // CPU_FEATURES_ARCH_AARCH64
|
||||
212
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/impl_arm_linux_or_android.c
generated
vendored
Normal file
212
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/impl_arm_linux_or_android.c
generated
vendored
Normal file
@@ -0,0 +1,212 @@
|
||||
// Copyright 2017 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "cpu_features_macros.h"
|
||||
|
||||
#ifdef CPU_FEATURES_ARCH_ARM
|
||||
#if defined(CPU_FEATURES_OS_LINUX) || defined(CPU_FEATURES_OS_ANDROID)
|
||||
|
||||
#include "cpuinfo_arm.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Definitions for introspection.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#define INTROSPECTION_TABLE \
|
||||
LINE(ARM_SWP, swp, "swp", ARM_HWCAP_SWP, 0) \
|
||||
LINE(ARM_HALF, half, "half", ARM_HWCAP_HALF, 0) \
|
||||
LINE(ARM_THUMB, thumb, "thumb", ARM_HWCAP_THUMB, 0) \
|
||||
LINE(ARM_26BIT, _26bit, "26bit", ARM_HWCAP_26BIT, 0) \
|
||||
LINE(ARM_FASTMULT, fastmult, "fastmult", ARM_HWCAP_FAST_MULT, 0) \
|
||||
LINE(ARM_FPA, fpa, "fpa", ARM_HWCAP_FPA, 0) \
|
||||
LINE(ARM_VFP, vfp, "vfp", ARM_HWCAP_VFP, 0) \
|
||||
LINE(ARM_EDSP, edsp, "edsp", ARM_HWCAP_EDSP, 0) \
|
||||
LINE(ARM_JAVA, java, "java", ARM_HWCAP_JAVA, 0) \
|
||||
LINE(ARM_IWMMXT, iwmmxt, "iwmmxt", ARM_HWCAP_IWMMXT, 0) \
|
||||
LINE(ARM_CRUNCH, crunch, "crunch", ARM_HWCAP_CRUNCH, 0) \
|
||||
LINE(ARM_THUMBEE, thumbee, "thumbee", ARM_HWCAP_THUMBEE, 0) \
|
||||
LINE(ARM_NEON, neon, "neon", ARM_HWCAP_NEON, 0) \
|
||||
LINE(ARM_VFPV3, vfpv3, "vfpv3", ARM_HWCAP_VFPV3, 0) \
|
||||
LINE(ARM_VFPV3D16, vfpv3d16, "vfpv3d16", ARM_HWCAP_VFPV3D16, 0) \
|
||||
LINE(ARM_TLS, tls, "tls", ARM_HWCAP_TLS, 0) \
|
||||
LINE(ARM_VFPV4, vfpv4, "vfpv4", ARM_HWCAP_VFPV4, 0) \
|
||||
LINE(ARM_IDIVA, idiva, "idiva", ARM_HWCAP_IDIVA, 0) \
|
||||
LINE(ARM_IDIVT, idivt, "idivt", ARM_HWCAP_IDIVT, 0) \
|
||||
LINE(ARM_VFPD32, vfpd32, "vfpd32", ARM_HWCAP_VFPD32, 0) \
|
||||
LINE(ARM_LPAE, lpae, "lpae", ARM_HWCAP_LPAE, 0) \
|
||||
LINE(ARM_EVTSTRM, evtstrm, "evtstrm", ARM_HWCAP_EVTSTRM, 0) \
|
||||
LINE(ARM_AES, aes, "aes", 0, ARM_HWCAP2_AES) \
|
||||
LINE(ARM_PMULL, pmull, "pmull", 0, ARM_HWCAP2_PMULL) \
|
||||
LINE(ARM_SHA1, sha1, "sha1", 0, ARM_HWCAP2_SHA1) \
|
||||
LINE(ARM_SHA2, sha2, "sha2", 0, ARM_HWCAP2_SHA2) \
|
||||
LINE(ARM_CRC32, crc32, "crc32", 0, ARM_HWCAP2_CRC32)
|
||||
#define INTROSPECTION_PREFIX Arm
|
||||
#define INTROSPECTION_ENUM_PREFIX ARM
|
||||
#include "define_introspection_and_hwcaps.inl"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Implementation.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "internal/bit_utils.h"
|
||||
#include "internal/filesystem.h"
|
||||
#include "internal/stack_line_reader.h"
|
||||
#include "internal/string_view.h"
|
||||
|
||||
typedef struct {
|
||||
bool processor_reports_armv6;
|
||||
bool hardware_reports_goldfish;
|
||||
} ProcCpuInfoData;
|
||||
|
||||
static int IndexOfNonDigit(StringView str) {
|
||||
size_t index = 0;
|
||||
while (str.size && isdigit(CpuFeatures_StringView_Front(str))) {
|
||||
str = CpuFeatures_StringView_PopFront(str, 1);
|
||||
++index;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
static bool HandleArmLine(const LineResult result, ArmInfo* const info,
|
||||
ProcCpuInfoData* const proc_info) {
|
||||
StringView line = result.line;
|
||||
StringView key, value;
|
||||
if (CpuFeatures_StringView_GetAttributeKeyValue(line, &key, &value)) {
|
||||
if (CpuFeatures_StringView_IsEquals(key, str("Features"))) {
|
||||
for (size_t i = 0; i < ARM_LAST_; ++i) {
|
||||
kSetters[i](&info->features, CpuFeatures_StringView_HasWord(
|
||||
value, kCpuInfoFlags[i], ' '));
|
||||
}
|
||||
} else if (CpuFeatures_StringView_IsEquals(key, str("CPU implementer"))) {
|
||||
info->implementer = CpuFeatures_StringView_ParsePositiveNumber(value);
|
||||
} else if (CpuFeatures_StringView_IsEquals(key, str("CPU variant"))) {
|
||||
info->variant = CpuFeatures_StringView_ParsePositiveNumber(value);
|
||||
} else if (CpuFeatures_StringView_IsEquals(key, str("CPU part"))) {
|
||||
info->part = CpuFeatures_StringView_ParsePositiveNumber(value);
|
||||
} else if (CpuFeatures_StringView_IsEquals(key, str("CPU revision"))) {
|
||||
info->revision = CpuFeatures_StringView_ParsePositiveNumber(value);
|
||||
} else if (CpuFeatures_StringView_IsEquals(key, str("CPU architecture"))) {
|
||||
// CPU architecture is a number that may be followed by letters. e.g.
|
||||
// "6TEJ", "7".
|
||||
const StringView digits =
|
||||
CpuFeatures_StringView_KeepFront(value, IndexOfNonDigit(value));
|
||||
info->architecture = CpuFeatures_StringView_ParsePositiveNumber(digits);
|
||||
} else if (CpuFeatures_StringView_IsEquals(key, str("Processor")) ||
|
||||
CpuFeatures_StringView_IsEquals(key, str("model name"))) {
|
||||
// Android reports this in a non-Linux standard "Processor" but sometimes
|
||||
// also in "model name", Linux reports it only in "model name"
|
||||
// see RaspberryPiZero (Linux) vs InvalidArmv7 (Android) test-cases
|
||||
proc_info->processor_reports_armv6 =
|
||||
CpuFeatures_StringView_IndexOf(value, str("(v6l)")) >= 0;
|
||||
} else if (CpuFeatures_StringView_IsEquals(key, str("Hardware"))) {
|
||||
proc_info->hardware_reports_goldfish =
|
||||
CpuFeatures_StringView_IsEquals(value, str("Goldfish"));
|
||||
}
|
||||
}
|
||||
return !result.eof;
|
||||
}
|
||||
|
||||
uint32_t GetArmCpuId(const ArmInfo* const info) {
|
||||
return (ExtractBitRange(info->implementer, 7, 0) << 24) |
|
||||
(ExtractBitRange(info->variant, 3, 0) << 20) |
|
||||
(ExtractBitRange(info->part, 11, 0) << 4) |
|
||||
(ExtractBitRange(info->revision, 3, 0) << 0);
|
||||
}
|
||||
|
||||
static void FixErrors(ArmInfo* const info,
|
||||
ProcCpuInfoData* const proc_cpu_info_data) {
|
||||
// Fixing Samsung kernel reporting invalid cpu architecture.
|
||||
// http://code.google.com/p/android/issues/detail?id=10812
|
||||
if (proc_cpu_info_data->processor_reports_armv6 && info->architecture >= 7) {
|
||||
info->architecture = 6;
|
||||
}
|
||||
|
||||
// Handle kernel configuration bugs that prevent the correct reporting of CPU
|
||||
// features.
|
||||
switch (GetArmCpuId(info)) {
|
||||
case 0x4100C080:
|
||||
// Special case: The emulator-specific Android 4.2 kernel fails to report
|
||||
// support for the 32-bit ARM IDIV instruction. Technically, this is a
|
||||
// feature of the virtual CPU implemented by the emulator. Note that it
|
||||
// could also support Thumb IDIV in the future, and this will have to be
|
||||
// slightly updated.
|
||||
if (info->architecture >= 7 &&
|
||||
proc_cpu_info_data->hardware_reports_goldfish) {
|
||||
info->features.idiva = true;
|
||||
}
|
||||
break;
|
||||
case 0x511004D0:
|
||||
// https://crbug.com/341598.
|
||||
info->features.neon = false;
|
||||
break;
|
||||
}
|
||||
|
||||
// Some Qualcomm Krait kernels forget to report IDIV support.
|
||||
// https://github.com/torvalds/linux/commit/120ecfafabec382c4feb79ff159ef42a39b6d33b
|
||||
if (info->implementer == 0x51 && info->architecture == 7 &&
|
||||
(info->part == 0x4d || info->part == 0x6f)) {
|
||||
info->features.idiva = true;
|
||||
info->features.idivt = true;
|
||||
}
|
||||
|
||||
// Propagate cpu features.
|
||||
if (info->features.vfpv4) info->features.vfpv3 = true;
|
||||
if (info->features.neon) info->features.vfpv3 = true;
|
||||
if (info->features.vfpv3) info->features.vfp = true;
|
||||
}
|
||||
|
||||
static void FillProcCpuInfoData(ArmInfo* const info,
|
||||
ProcCpuInfoData* proc_cpu_info_data) {
|
||||
const int fd = CpuFeatures_OpenFile("/proc/cpuinfo");
|
||||
if (fd >= 0) {
|
||||
StackLineReader reader;
|
||||
StackLineReader_Initialize(&reader, fd);
|
||||
for (;;) {
|
||||
if (!HandleArmLine(StackLineReader_NextLine(&reader), info,
|
||||
proc_cpu_info_data)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
CpuFeatures_CloseFile(fd);
|
||||
}
|
||||
}
|
||||
|
||||
static const ArmInfo kEmptyArmInfo;
|
||||
|
||||
static const ProcCpuInfoData kEmptyProcCpuInfoData;
|
||||
|
||||
ArmInfo GetArmInfo(void) {
|
||||
// capabilities are fetched from both getauxval and /proc/cpuinfo so we can
|
||||
// have some information if the executable is sandboxed (aka no access to
|
||||
// /proc/cpuinfo).
|
||||
ArmInfo info = kEmptyArmInfo;
|
||||
ProcCpuInfoData proc_cpu_info_data = kEmptyProcCpuInfoData;
|
||||
|
||||
FillProcCpuInfoData(&info, &proc_cpu_info_data);
|
||||
const HardwareCapabilities hwcaps = CpuFeatures_GetHardwareCapabilities();
|
||||
for (size_t i = 0; i < ARM_LAST_; ++i) {
|
||||
if (CpuFeatures_IsHwCapsSet(kHardwareCapabilities[i], hwcaps)) {
|
||||
kSetters[i](&info.features, true);
|
||||
}
|
||||
}
|
||||
|
||||
FixErrors(&info, &proc_cpu_info_data);
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
#endif // defined(CPU_FEATURES_OS_LINUX) || defined(CPU_FEATURES_OS_ANDROID)
|
||||
#endif // CPU_FEATURES_ARCH_ARM
|
||||
93
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/impl_mips_linux_or_android.c
generated
vendored
Normal file
93
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/impl_mips_linux_or_android.c
generated
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "cpu_features_macros.h"
|
||||
|
||||
#ifdef CPU_FEATURES_ARCH_MIPS
|
||||
#if defined(CPU_FEATURES_OS_LINUX) || defined(CPU_FEATURES_OS_ANDROID)
|
||||
|
||||
#include "cpuinfo_mips.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Definitions for introspection.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#define INTROSPECTION_TABLE \
|
||||
LINE(MIPS_MSA, msa, "msa", MIPS_HWCAP_MSA, 0) \
|
||||
LINE(MIPS_EVA, eva, "eva", 0, 0) \
|
||||
LINE(MIPS_R6, r6, "r6", MIPS_HWCAP_R6, 0) \
|
||||
LINE(MIPS_MIPS16, mips16, "mips16", MIPS_HWCAP_MIPS16, 0) \
|
||||
LINE(MIPS_MDMX, mdmx, "mdmx", MIPS_HWCAP_MDMX, 0) \
|
||||
LINE(MIPS_MIPS3D, mips3d, "mips3d", MIPS_HWCAP_MIPS3D, 0) \
|
||||
LINE(MIPS_SMART, smart, "smartmips", MIPS_HWCAP_SMARTMIPS, 0) \
|
||||
LINE(MIPS_DSP, dsp, "dsp", MIPS_HWCAP_DSP, 0)
|
||||
#define INTROSPECTION_PREFIX Mips
|
||||
#define INTROSPECTION_ENUM_PREFIX MIPS
|
||||
#include "define_introspection_and_hwcaps.inl"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Implementation.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "internal/filesystem.h"
|
||||
#include "internal/hwcaps.h"
|
||||
#include "internal/stack_line_reader.h"
|
||||
#include "internal/string_view.h"
|
||||
|
||||
static bool HandleMipsLine(const LineResult result,
|
||||
MipsFeatures* const features) {
|
||||
StringView key, value;
|
||||
// See tests for an example.
|
||||
if (CpuFeatures_StringView_GetAttributeKeyValue(result.line, &key, &value)) {
|
||||
if (CpuFeatures_StringView_IsEquals(key, str("ASEs implemented"))) {
|
||||
for (size_t i = 0; i < MIPS_LAST_; ++i) {
|
||||
kSetters[i](features, CpuFeatures_StringView_HasWord(
|
||||
value, kCpuInfoFlags[i], ' '));
|
||||
}
|
||||
}
|
||||
}
|
||||
return !result.eof;
|
||||
}
|
||||
|
||||
static void FillProcCpuInfoData(MipsFeatures* const features) {
|
||||
const int fd = CpuFeatures_OpenFile("/proc/cpuinfo");
|
||||
if (fd >= 0) {
|
||||
StackLineReader reader;
|
||||
StackLineReader_Initialize(&reader, fd);
|
||||
for (;;) {
|
||||
if (!HandleMipsLine(StackLineReader_NextLine(&reader), features)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
CpuFeatures_CloseFile(fd);
|
||||
}
|
||||
}
|
||||
|
||||
static const MipsInfo kEmptyMipsInfo;
|
||||
|
||||
MipsInfo GetMipsInfo(void) {
|
||||
// capabilities are fetched from both getauxval and /proc/cpuinfo so we can
|
||||
// have some information if the executable is sandboxed (aka no access to
|
||||
// /proc/cpuinfo).
|
||||
MipsInfo info = kEmptyMipsInfo;
|
||||
|
||||
FillProcCpuInfoData(&info.features);
|
||||
const HardwareCapabilities hwcaps = CpuFeatures_GetHardwareCapabilities();
|
||||
for (size_t i = 0; i < MIPS_LAST_; ++i) {
|
||||
if (CpuFeatures_IsHwCapsSet(kHardwareCapabilities[i], hwcaps)) {
|
||||
kSetters[i](&info.features, true);
|
||||
}
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
#endif // defined(CPU_FEATURES_OS_LINUX) || defined(CPU_FEATURES_OS_ANDROID)
|
||||
#endif // CPU_FEATURES_ARCH_MIPS
|
||||
163
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/impl_ppc_linux.c
generated
vendored
Normal file
163
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/impl_ppc_linux.c
generated
vendored
Normal file
@@ -0,0 +1,163 @@
|
||||
// Copyright 2018 IBM.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "cpu_features_macros.h"
|
||||
|
||||
#ifdef CPU_FEATURES_ARCH_PPC
|
||||
#ifdef CPU_FEATURES_OS_LINUX
|
||||
|
||||
#include "cpuinfo_ppc.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Definitions for introspection.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#define INTROSPECTION_TABLE \
|
||||
LINE(PPC_32, ppc32, "ppc32", PPC_FEATURE_32, 0) \
|
||||
LINE(PPC_64, ppc64, "ppc64", PPC_FEATURE_64, 0) \
|
||||
LINE(PPC_601_INSTR, ppc601, "ppc601", PPC_FEATURE_601_INSTR, 0) \
|
||||
LINE(PPC_HAS_ALTIVEC, altivec, "altivec", PPC_FEATURE_HAS_ALTIVEC, 0) \
|
||||
LINE(PPC_HAS_FPU, fpu, "fpu", PPC_FEATURE_HAS_FPU, 0) \
|
||||
LINE(PPC_HAS_MMU, mmu, "mmu", PPC_FEATURE_HAS_MMU, 0) \
|
||||
LINE(PPC_HAS_4xxMAC, mac_4xx, "4xxmac", PPC_FEATURE_HAS_4xxMAC, 0) \
|
||||
LINE(PPC_UNIFIED_CACHE, unifiedcache, "ucache", PPC_FEATURE_UNIFIED_CACHE, \
|
||||
0) \
|
||||
LINE(PPC_HAS_SPE, spe, "spe", PPC_FEATURE_HAS_SPE, 0) \
|
||||
LINE(PPC_HAS_EFP_SINGLE, efpsingle, "efpsingle", PPC_FEATURE_HAS_EFP_SINGLE, \
|
||||
0) \
|
||||
LINE(PPC_HAS_EFP_DOUBLE, efpdouble, "efpdouble", PPC_FEATURE_HAS_EFP_DOUBLE, \
|
||||
0) \
|
||||
LINE(PPC_NO_TB, no_tb, "notb", PPC_FEATURE_NO_TB, 0) \
|
||||
LINE(PPC_POWER4, power4, "power4", PPC_FEATURE_POWER4, 0) \
|
||||
LINE(PPC_POWER5, power5, "power5", PPC_FEATURE_POWER5, 0) \
|
||||
LINE(PPC_POWER5_PLUS, power5plus, "power5+", PPC_FEATURE_POWER5_PLUS, 0) \
|
||||
LINE(PPC_CELL, cell, "cellbe", PPC_FEATURE_CELL, 0) \
|
||||
LINE(PPC_BOOKE, booke, "booke", PPC_FEATURE_BOOKE, 0) \
|
||||
LINE(PPC_SMT, smt, "smt", PPC_FEATURE_SMT, 0) \
|
||||
LINE(PPC_ICACHE_SNOOP, icachesnoop, "ic_snoop", PPC_FEATURE_ICACHE_SNOOP, 0) \
|
||||
LINE(PPC_ARCH_2_05, arch205, "arch_2_05", PPC_FEATURE_ARCH_2_05, 0) \
|
||||
LINE(PPC_PA6T, pa6t, "pa6t", PPC_FEATURE_PA6T, 0) \
|
||||
LINE(PPC_HAS_DFP, dfp, "dfp", PPC_FEATURE_HAS_DFP, 0) \
|
||||
LINE(PPC_POWER6_EXT, power6ext, "power6x", PPC_FEATURE_POWER6_EXT, 0) \
|
||||
LINE(PPC_ARCH_2_06, arch206, "arch_2_06", PPC_FEATURE_ARCH_2_06, 0) \
|
||||
LINE(PPC_HAS_VSX, vsx, "vsx", PPC_FEATURE_HAS_VSX, 0) \
|
||||
LINE(PPC_PSERIES_PERFMON_COMPAT, pseries_perfmon_compat, "archpmu", \
|
||||
PPC_FEATURE_PSERIES_PERFMON_COMPAT, 0) \
|
||||
LINE(PPC_TRUE_LE, truele, "true_le", PPC_FEATURE_TRUE_LE, 0) \
|
||||
LINE(PPC_PPC_LE, ppcle, "ppcle", PPC_FEATURE_PPC_LE, 0) \
|
||||
LINE(PPC_ARCH_2_07, arch207, "arch_2_07", 0, PPC_FEATURE2_ARCH_2_07) \
|
||||
LINE(PPC_HTM, htm, "htm", 0, PPC_FEATURE2_HTM) \
|
||||
LINE(PPC_DSCR, dscr, "dscr", 0, PPC_FEATURE2_DSCR) \
|
||||
LINE(PPC_EBB, ebb, "ebb", 0, PPC_FEATURE2_EBB) \
|
||||
LINE(PPC_ISEL, isel, "isel", 0, PPC_FEATURE2_ISEL) \
|
||||
LINE(PPC_TAR, tar, "tar", 0, PPC_FEATURE2_TAR) \
|
||||
LINE(PPC_VEC_CRYPTO, vcrypto, "vcrypto", 0, PPC_FEATURE2_VEC_CRYPTO) \
|
||||
LINE(PPC_HTM_NOSC, htm_nosc, "htm-nosc", 0, PPC_FEATURE2_HTM_NOSC) \
|
||||
LINE(PPC_ARCH_3_00, arch300, "arch_3_00", 0, PPC_FEATURE2_ARCH_3_00) \
|
||||
LINE(PPC_HAS_IEEE128, ieee128, "ieee128", 0, PPC_FEATURE2_HAS_IEEE128) \
|
||||
LINE(PPC_DARN, darn, "darn", 0, PPC_FEATURE2_DARN) \
|
||||
LINE(PPC_SCV, scv, "scv", 0, PPC_FEATURE2_SCV) \
|
||||
LINE(PPC_HTM_NO_SUSPEND, htm_no_suspend, "htm-no-suspend", 0, \
|
||||
PPC_FEATURE2_HTM_NO_SUSPEND)
|
||||
#undef PPC // Remove conflict with compiler generated preprocessor
|
||||
#define INTROSPECTION_PREFIX PPC
|
||||
#define INTROSPECTION_ENUM_PREFIX PPC
|
||||
#include "define_introspection_and_hwcaps.inl"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Implementation.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "internal/bit_utils.h"
|
||||
#include "internal/filesystem.h"
|
||||
#include "internal/hwcaps.h"
|
||||
#include "internal/stack_line_reader.h"
|
||||
#include "internal/string_view.h"
|
||||
|
||||
static bool HandlePPCLine(const LineResult result,
|
||||
PPCPlatformStrings* const strings) {
|
||||
StringView line = result.line;
|
||||
StringView key, value;
|
||||
if (CpuFeatures_StringView_GetAttributeKeyValue(line, &key, &value)) {
|
||||
if (CpuFeatures_StringView_HasWord(key, "platform", ' ')) {
|
||||
CpuFeatures_StringView_CopyString(value, strings->platform,
|
||||
sizeof(strings->platform));
|
||||
} else if (CpuFeatures_StringView_IsEquals(key, str("model"))) {
|
||||
CpuFeatures_StringView_CopyString(value, strings->model,
|
||||
sizeof(strings->platform));
|
||||
} else if (CpuFeatures_StringView_IsEquals(key, str("machine"))) {
|
||||
CpuFeatures_StringView_CopyString(value, strings->machine,
|
||||
sizeof(strings->platform));
|
||||
} else if (CpuFeatures_StringView_IsEquals(key, str("cpu"))) {
|
||||
CpuFeatures_StringView_CopyString(value, strings->cpu,
|
||||
sizeof(strings->platform));
|
||||
}
|
||||
}
|
||||
return !result.eof;
|
||||
}
|
||||
|
||||
static void FillProcCpuInfoData(PPCPlatformStrings* const strings) {
|
||||
const int fd = CpuFeatures_OpenFile("/proc/cpuinfo");
|
||||
if (fd >= 0) {
|
||||
StackLineReader reader;
|
||||
StackLineReader_Initialize(&reader, fd);
|
||||
for (;;) {
|
||||
if (!HandlePPCLine(StackLineReader_NextLine(&reader), strings)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
CpuFeatures_CloseFile(fd);
|
||||
}
|
||||
}
|
||||
|
||||
static const PPCInfo kEmptyPPCInfo;
|
||||
|
||||
PPCInfo GetPPCInfo(void) {
|
||||
/*
|
||||
* On Power feature flags aren't currently in cpuinfo so we only look at
|
||||
* the auxilary vector.
|
||||
*/
|
||||
PPCInfo info = kEmptyPPCInfo;
|
||||
const HardwareCapabilities hwcaps = CpuFeatures_GetHardwareCapabilities();
|
||||
for (size_t i = 0; i < PPC_LAST_; ++i) {
|
||||
if (CpuFeatures_IsHwCapsSet(kHardwareCapabilities[i], hwcaps)) {
|
||||
kSetters[i](&info.features, true);
|
||||
}
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
static const PPCPlatformStrings kEmptyPPCPlatformStrings;
|
||||
|
||||
PPCPlatformStrings GetPPCPlatformStrings(void) {
|
||||
PPCPlatformStrings strings = kEmptyPPCPlatformStrings;
|
||||
const char* platform = CpuFeatures_GetPlatformPointer();
|
||||
const char* base_platform = CpuFeatures_GetBasePlatformPointer();
|
||||
|
||||
FillProcCpuInfoData(&strings);
|
||||
|
||||
if (platform != NULL)
|
||||
CpuFeatures_StringView_CopyString(str(platform), strings.type.platform,
|
||||
sizeof(strings.type.platform));
|
||||
if (base_platform != NULL)
|
||||
CpuFeatures_StringView_CopyString(str(base_platform),
|
||||
strings.type.base_platform,
|
||||
sizeof(strings.type.base_platform));
|
||||
|
||||
return strings;
|
||||
}
|
||||
|
||||
#endif // CPU_FEATURES_OS_LINUX
|
||||
#endif // CPU_FEATURES_ARCH_PPC
|
||||
111
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/impl_riscv_linux.c
generated
vendored
Normal file
111
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/impl_riscv_linux.c
generated
vendored
Normal file
@@ -0,0 +1,111 @@
|
||||
// Copyright 2022 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "cpu_features_macros.h"
|
||||
|
||||
#ifdef CPU_FEATURES_ARCH_RISCV
|
||||
#if defined(CPU_FEATURES_OS_LINUX)
|
||||
|
||||
#include "cpuinfo_riscv.h"
|
||||
|
||||
// According to
|
||||
// https://elixir.bootlin.com/linux/latest/source/Documentation/devicetree/bindings/riscv/cpus.yaml
|
||||
// isa string should match the following regex
|
||||
// ^rv(?:64|32)imaf?d?q?c?b?v?k?h?(?:_[hsxz](?:[a-z])+)*$
|
||||
//
|
||||
// This means we can test for features in this exact order except for Z
|
||||
// extensions.
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Definitions for introspection.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#define INTROSPECTION_TABLE \
|
||||
LINE(RISCV_RV32I, RV32I, "rv32i", RISCV_HWCAP_32, 0) \
|
||||
LINE(RISCV_RV64I, RV64I, "rv64i", RISCV_HWCAP_64, 0) \
|
||||
LINE(RISCV_M, M, "m", RISCV_HWCAP_M, 0) \
|
||||
LINE(RISCV_A, A, "a", RISCV_HWCAP_A, 0) \
|
||||
LINE(RISCV_F, F, "f", RISCV_HWCAP_F, 0) \
|
||||
LINE(RISCV_D, D, "d", RISCV_HWCAP_D, 0) \
|
||||
LINE(RISCV_Q, Q, "q", RISCV_HWCAP_Q, 0) \
|
||||
LINE(RISCV_C, C, "c", RISCV_HWCAP_C, 0) \
|
||||
LINE(RISCV_V, V, "v", RISCV_HWCAP_V, 0) \
|
||||
LINE(RISCV_Zicsr, Zicsr, "_zicsr", 0, 0) \
|
||||
LINE(RISCV_Zifencei, Zifencei, "_zifencei", 0, 0)
|
||||
#define INTROSPECTION_PREFIX Riscv
|
||||
#define INTROSPECTION_ENUM_PREFIX RISCV
|
||||
#include "define_introspection_and_hwcaps.inl"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Implementation.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "internal/filesystem.h"
|
||||
#include "internal/stack_line_reader.h"
|
||||
|
||||
static const RiscvInfo kEmptyRiscvInfo;
|
||||
|
||||
static void HandleRiscVIsaLine(StringView line, RiscvFeatures* const features) {
|
||||
for (size_t i = 0; i < RISCV_LAST_; ++i) {
|
||||
StringView flag = str(kCpuInfoFlags[i]);
|
||||
int index_of_flag = CpuFeatures_StringView_IndexOf(line, flag);
|
||||
bool is_set = index_of_flag != -1;
|
||||
kSetters[i](features, is_set);
|
||||
if (is_set)
|
||||
line = CpuFeatures_StringView_PopFront(line, index_of_flag + flag.size);
|
||||
}
|
||||
}
|
||||
|
||||
static bool HandleRiscVLine(const LineResult result, RiscvInfo* const info) {
|
||||
StringView line = result.line;
|
||||
StringView key, value;
|
||||
if (CpuFeatures_StringView_GetAttributeKeyValue(line, &key, &value)) {
|
||||
if (CpuFeatures_StringView_IsEquals(key, str("isa"))) {
|
||||
HandleRiscVIsaLine(value, &info->features);
|
||||
} else if (CpuFeatures_StringView_IsEquals(key, str("uarch"))) {
|
||||
int index = CpuFeatures_StringView_IndexOfChar(value, ',');
|
||||
if (index == -1) return true;
|
||||
StringView vendor = CpuFeatures_StringView_KeepFront(value, index);
|
||||
StringView uarch = CpuFeatures_StringView_PopFront(value, index + 1);
|
||||
CpuFeatures_StringView_CopyString(vendor, info->vendor,
|
||||
sizeof(info->vendor));
|
||||
CpuFeatures_StringView_CopyString(uarch, info->uarch,
|
||||
sizeof(info->uarch));
|
||||
}
|
||||
}
|
||||
return !result.eof;
|
||||
}
|
||||
|
||||
static void FillProcCpuInfoData(RiscvInfo* const info) {
|
||||
const int fd = CpuFeatures_OpenFile("/proc/cpuinfo");
|
||||
if (fd >= 0) {
|
||||
StackLineReader reader;
|
||||
StackLineReader_Initialize(&reader, fd);
|
||||
for (;;) {
|
||||
if (!HandleRiscVLine(StackLineReader_NextLine(&reader), info)) break;
|
||||
}
|
||||
CpuFeatures_CloseFile(fd);
|
||||
}
|
||||
}
|
||||
|
||||
RiscvInfo GetRiscvInfo(void) {
|
||||
RiscvInfo info = kEmptyRiscvInfo;
|
||||
FillProcCpuInfoData(&info);
|
||||
return info;
|
||||
}
|
||||
|
||||
#endif // defined(CPU_FEATURES_OS_LINUX) || defined(CPU_FEATURES_OS_ANDROID)
|
||||
#endif // CPU_FEATURES_ARCH_RISCV
|
||||
120
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/impl_s390x_linux.c
generated
vendored
Normal file
120
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/impl_s390x_linux.c
generated
vendored
Normal file
@@ -0,0 +1,120 @@
|
||||
// Copyright 2022 IBM.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "cpu_features_macros.h"
|
||||
|
||||
#ifdef CPU_FEATURES_ARCH_S390X
|
||||
#ifdef CPU_FEATURES_OS_LINUX
|
||||
|
||||
#include "cpuinfo_s390x.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Definitions for introspection.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#define INTROSPECTION_TABLE \
|
||||
LINE(S390_ESAN3, esan3, "esan3", HWCAP_S390_ESAN3, 0) \
|
||||
LINE(S390_ZARCH, zarch, "zarch", HWCAP_S390_ZARCH, 0) \
|
||||
LINE(S390_STFLE, stfle, "stfle", HWCAP_S390_STFLE, 0) \
|
||||
LINE(S390_MSA, msa, "msa", HWCAP_S390_MSA, 0) \
|
||||
LINE(S390_LDISP, ldisp, "ldisp", HWCAP_S390_LDISP, 0) \
|
||||
LINE(S390_EIMM, eimm, "eimm", HWCAP_S390_EIMM, 0) \
|
||||
LINE(S390_DFP, dfp, "dfp", HWCAP_S390_DFP, 0) \
|
||||
LINE(S390_EDAT, edat, "edat", HWCAP_S390_HPAGE, 0) \
|
||||
LINE(S390_ETF3EH, etf3eh, "etf3eh", HWCAP_S390_ETF3EH, 0) \
|
||||
LINE(S390_HIGHGPRS, highgprs, "highgprs", HWCAP_S390_HIGH_GPRS, 0) \
|
||||
LINE(S390_TE, te, "te", HWCAP_S390_TE, 0) \
|
||||
LINE(S390_VX, vx, "vx", HWCAP_S390_VXRS, 0) \
|
||||
LINE(S390_VXD, vxd, "vxd", HWCAP_S390_VXRS_BCD, 0) \
|
||||
LINE(S390_VXE, vxe, "vxe", HWCAP_S390_VXRS_EXT, 0) \
|
||||
LINE(S390_GS, gs, "gs", HWCAP_S390_GS, 0) \
|
||||
LINE(S390_VXE2, vxe2, "vxe2", HWCAP_S390_VXRS_EXT2, 0) \
|
||||
LINE(S390_VXP, vxp, "vxp", HWCAP_S390_VXRS_PDE, 0) \
|
||||
LINE(S390_SORT, sort, "sort", HWCAP_S390_SORT, 0) \
|
||||
LINE(S390_DFLT, dflt, "dflt", HWCAP_S390_DFLT, 0) \
|
||||
LINE(S390_VXP2, vxp2, "vxp2", HWCAP_S390_VXRS_PDE2, 0) \
|
||||
LINE(S390_NNPA, nnpa, "nnpa", HWCAP_S390_NNPA, 0) \
|
||||
LINE(S390_PCIMIO, pcimio, "pcimio", HWCAP_S390_PCI_MIO, 0) \
|
||||
LINE(S390_SIE, sie, "sie", HWCAP_S390_SIE, 0)
|
||||
#define INTROSPECTION_PREFIX S390X
|
||||
#define INTROSPECTION_ENUM_PREFIX S390X
|
||||
#include "define_introspection_and_hwcaps.inl"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Implementation.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "internal/bit_utils.h"
|
||||
#include "internal/filesystem.h"
|
||||
#include "internal/hwcaps.h"
|
||||
#include "internal/stack_line_reader.h"
|
||||
#include "internal/string_view.h"
|
||||
|
||||
static bool HandleS390XLine(const LineResult result,
|
||||
S390XPlatformStrings* const strings) {
|
||||
StringView line = result.line;
|
||||
StringView key, value;
|
||||
if (CpuFeatures_StringView_GetAttributeKeyValue(line, &key, &value)) {
|
||||
if (CpuFeatures_StringView_IsEquals(key, str("# processors"))) {
|
||||
strings->num_processors = CpuFeatures_StringView_ParsePositiveNumber(value);
|
||||
}
|
||||
}
|
||||
return !result.eof;
|
||||
}
|
||||
|
||||
static void FillProcCpuInfoData(S390XPlatformStrings* const strings) {
|
||||
const int fd = CpuFeatures_OpenFile("/proc/cpuinfo");
|
||||
if (fd >= 0) {
|
||||
StackLineReader reader;
|
||||
StackLineReader_Initialize(&reader, fd);
|
||||
for (;;) {
|
||||
if (!HandleS390XLine(StackLineReader_NextLine(&reader), strings)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
CpuFeatures_CloseFile(fd);
|
||||
}
|
||||
}
|
||||
|
||||
static const S390XInfo kEmptyS390XInfo;
|
||||
|
||||
S390XInfo GetS390XInfo(void) {
|
||||
S390XInfo info = kEmptyS390XInfo;
|
||||
const HardwareCapabilities hwcaps = CpuFeatures_GetHardwareCapabilities();
|
||||
for (size_t i = 0; i < S390X_LAST_; ++i) {
|
||||
if (CpuFeatures_IsHwCapsSet(kHardwareCapabilities[i], hwcaps)) {
|
||||
kSetters[i](&info.features, true);
|
||||
}
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
static const S390XPlatformStrings kEmptyS390XPlatformStrings;
|
||||
|
||||
S390XPlatformStrings GetS390XPlatformStrings(void) {
|
||||
S390XPlatformStrings strings = kEmptyS390XPlatformStrings;
|
||||
const char* platform = CpuFeatures_GetPlatformPointer();
|
||||
|
||||
FillProcCpuInfoData(&strings);
|
||||
|
||||
if (platform != NULL)
|
||||
CpuFeatures_StringView_CopyString(str(platform), strings.type.platform,
|
||||
sizeof(strings.type.platform));
|
||||
|
||||
return strings;
|
||||
}
|
||||
|
||||
#endif // CPU_FEATURES_OS_LINUX
|
||||
#endif // CPU_FEATURES_ARCH_S390X
|
||||
2055
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/impl_x86__base_implementation.inl
generated
vendored
Normal file
2055
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/impl_x86__base_implementation.inl
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
68
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/impl_x86_freebsd.c
generated
vendored
Normal file
68
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/impl_x86_freebsd.c
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
// Copyright 2017 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "cpu_features_macros.h"
|
||||
|
||||
#ifdef CPU_FEATURES_ARCH_X86
|
||||
#ifdef CPU_FEATURES_OS_FREEBSD
|
||||
|
||||
#include "impl_x86__base_implementation.inl"
|
||||
|
||||
static void OverrideOsPreserves(OsPreserves* os_preserves) {
|
||||
(void)os_preserves;
|
||||
// No override
|
||||
}
|
||||
|
||||
#include "internal/filesystem.h"
|
||||
#include "internal/stack_line_reader.h"
|
||||
#include "internal/string_view.h"
|
||||
|
||||
static void DetectFeaturesFromOs(X86Info* info, X86Features* features) {
|
||||
(void)info;
|
||||
// Handling FreeBSD platform through parsing /var/run/dmesg.boot.
|
||||
const int fd = CpuFeatures_OpenFile("/var/run/dmesg.boot");
|
||||
if (fd >= 0) {
|
||||
StackLineReader reader;
|
||||
StackLineReader_Initialize(&reader, fd);
|
||||
for (bool stop = false; !stop;) {
|
||||
const LineResult result = StackLineReader_NextLine(&reader);
|
||||
if (result.eof) stop = true;
|
||||
const StringView line = result.line;
|
||||
if (!CpuFeatures_StringView_StartsWith(line, str(" Features"))) continue;
|
||||
// Lines of interests are of the following form:
|
||||
// " Features=0x1783fbff<PSE36,MMX,FXSR,SSE,SSE2,HTT>"
|
||||
// We first extract the comma separated values between angle brackets.
|
||||
StringView csv = result.line;
|
||||
int index = CpuFeatures_StringView_IndexOfChar(csv, '<');
|
||||
if (index >= 0) csv = CpuFeatures_StringView_PopFront(csv, index + 1);
|
||||
if (csv.size > 0 && CpuFeatures_StringView_Back(csv) == '>')
|
||||
csv = CpuFeatures_StringView_PopBack(csv, 1);
|
||||
if (CpuFeatures_StringView_HasWord(csv, "SSE", ',')) features->sse = true;
|
||||
if (CpuFeatures_StringView_HasWord(csv, "SSE2", ','))
|
||||
features->sse2 = true;
|
||||
if (CpuFeatures_StringView_HasWord(csv, "SSE3", ','))
|
||||
features->sse3 = true;
|
||||
if (CpuFeatures_StringView_HasWord(csv, "SSSE3", ','))
|
||||
features->ssse3 = true;
|
||||
if (CpuFeatures_StringView_HasWord(csv, "SSE4.1", ','))
|
||||
features->sse4_1 = true;
|
||||
if (CpuFeatures_StringView_HasWord(csv, "SSE4.2", ','))
|
||||
features->sse4_2 = true;
|
||||
}
|
||||
CpuFeatures_CloseFile(fd);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // CPU_FEATURES_OS_FREEBSD
|
||||
#endif // CPU_FEATURES_ARCH_X86
|
||||
58
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/impl_x86_linux_or_android.c
generated
vendored
Normal file
58
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/impl_x86_linux_or_android.c
generated
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
// Copyright 2017 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "cpu_features_macros.h"
|
||||
|
||||
#ifdef CPU_FEATURES_ARCH_X86
|
||||
#if defined(CPU_FEATURES_OS_LINUX) || defined(CPU_FEATURES_OS_ANDROID)
|
||||
|
||||
#include "impl_x86__base_implementation.inl"
|
||||
|
||||
static void OverrideOsPreserves(OsPreserves* os_preserves) {
|
||||
(void)os_preserves;
|
||||
// No override
|
||||
}
|
||||
|
||||
#include "internal/filesystem.h"
|
||||
#include "internal/stack_line_reader.h"
|
||||
#include "internal/string_view.h"
|
||||
static void DetectFeaturesFromOs(X86Info* info, X86Features* features) {
|
||||
(void)info;
|
||||
// Handling Linux platform through /proc/cpuinfo.
|
||||
const int fd = CpuFeatures_OpenFile("/proc/cpuinfo");
|
||||
if (fd >= 0) {
|
||||
StackLineReader reader;
|
||||
StackLineReader_Initialize(&reader, fd);
|
||||
for (bool stop = false; !stop;) {
|
||||
const LineResult result = StackLineReader_NextLine(&reader);
|
||||
if (result.eof) stop = true;
|
||||
const StringView line = result.line;
|
||||
StringView key, value;
|
||||
if (!CpuFeatures_StringView_GetAttributeKeyValue(line, &key, &value))
|
||||
continue;
|
||||
if (!CpuFeatures_StringView_IsEquals(key, str("flags"))) continue;
|
||||
features->sse = CpuFeatures_StringView_HasWord(value, "sse", ' ');
|
||||
features->sse2 = CpuFeatures_StringView_HasWord(value, "sse2", ' ');
|
||||
features->sse3 = CpuFeatures_StringView_HasWord(value, "pni", ' ');
|
||||
features->ssse3 = CpuFeatures_StringView_HasWord(value, "ssse3", ' ');
|
||||
features->sse4_1 = CpuFeatures_StringView_HasWord(value, "sse4_1", ' ');
|
||||
features->sse4_2 = CpuFeatures_StringView_HasWord(value, "sse4_2", ' ');
|
||||
break;
|
||||
}
|
||||
CpuFeatures_CloseFile(fd);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // defined(CPU_FEATURES_OS_LINUX) || defined(CPU_FEATURES_OS_ANDROID)
|
||||
#endif // CPU_FEATURES_ARCH_X86
|
||||
57
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/impl_x86_macos.c
generated
vendored
Normal file
57
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/impl_x86_macos.c
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
// Copyright 2017 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "cpu_features_macros.h"
|
||||
|
||||
#ifdef CPU_FEATURES_ARCH_X86
|
||||
#ifdef CPU_FEATURES_OS_MACOS
|
||||
|
||||
#include "impl_x86__base_implementation.inl"
|
||||
|
||||
#if !defined(HAVE_SYSCTLBYNAME)
|
||||
#error "Darwin needs support for sysctlbyname"
|
||||
#endif
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
#if defined(CPU_FEATURES_MOCK_CPUID_X86)
|
||||
extern bool GetDarwinSysCtlByName(const char*);
|
||||
#else // CPU_FEATURES_MOCK_CPUID_X86
|
||||
static bool GetDarwinSysCtlByName(const char* name) {
|
||||
int enabled;
|
||||
size_t enabled_len = sizeof(enabled);
|
||||
const int failure = sysctlbyname(name, &enabled, &enabled_len, NULL, 0);
|
||||
return failure ? false : enabled;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void OverrideOsPreserves(OsPreserves* os_preserves) {
|
||||
// On Darwin AVX512 support is On-demand.
|
||||
// We have to query the OS instead of querying the Zmm save/restore state.
|
||||
// https://github.com/apple/darwin-xnu/blob/8f02f2a044b9bb1ad951987ef5bab20ec9486310/osfmk/i386/fpu.c#L173-L199
|
||||
os_preserves->avx512_registers = GetDarwinSysCtlByName("hw.optional.avx512f");
|
||||
}
|
||||
|
||||
static void DetectFeaturesFromOs(X86Info* info, X86Features* features) {
|
||||
(void)info;
|
||||
// Handling Darwin platform through sysctlbyname.
|
||||
features->sse = GetDarwinSysCtlByName("hw.optional.sse");
|
||||
features->sse2 = GetDarwinSysCtlByName("hw.optional.sse2");
|
||||
features->sse3 = GetDarwinSysCtlByName("hw.optional.sse3");
|
||||
features->ssse3 = GetDarwinSysCtlByName("hw.optional.supplementalsse3");
|
||||
features->sse4_1 = GetDarwinSysCtlByName("hw.optional.sse4_1");
|
||||
features->sse4_2 = GetDarwinSysCtlByName("hw.optional.sse4_2");
|
||||
}
|
||||
|
||||
#endif // CPU_FEATURES_OS_MACOS
|
||||
#endif // CPU_FEATURES_ARCH_X86
|
||||
58
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/impl_x86_windows.c
generated
vendored
Normal file
58
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/impl_x86_windows.c
generated
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
// Copyright 2017 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "cpu_features_macros.h"
|
||||
|
||||
#ifdef CPU_FEATURES_ARCH_X86
|
||||
#ifdef CPU_FEATURES_OS_WINDOWS
|
||||
|
||||
#include "impl_x86__base_implementation.inl"
|
||||
|
||||
static void OverrideOsPreserves(OsPreserves* os_preserves) {
|
||||
(void)os_preserves;
|
||||
// No override
|
||||
}
|
||||
|
||||
#include "internal/windows_utils.h"
|
||||
|
||||
#if defined(CPU_FEATURES_MOCK_CPUID_X86)
|
||||
extern bool GetWindowsIsProcessorFeaturePresent(DWORD);
|
||||
#else // CPU_FEATURES_MOCK_CPUID_X86
|
||||
static bool GetWindowsIsProcessorFeaturePresent(DWORD ProcessorFeature) {
|
||||
return IsProcessorFeaturePresent(ProcessorFeature);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void DetectFeaturesFromOs(X86Info* info, X86Features* features) {
|
||||
// Handling Windows platform through IsProcessorFeaturePresent.
|
||||
// https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-isprocessorfeaturepresent
|
||||
features->sse =
|
||||
GetWindowsIsProcessorFeaturePresent(PF_XMMI_INSTRUCTIONS_AVAILABLE);
|
||||
features->sse2 =
|
||||
GetWindowsIsProcessorFeaturePresent(PF_XMMI64_INSTRUCTIONS_AVAILABLE);
|
||||
features->sse3 =
|
||||
GetWindowsIsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE);
|
||||
features->ssse3 =
|
||||
GetWindowsIsProcessorFeaturePresent(PF_SSSE3_INSTRUCTIONS_AVAILABLE);
|
||||
features->sse4_1 =
|
||||
GetWindowsIsProcessorFeaturePresent(PF_SSE4_1_INSTRUCTIONS_AVAILABLE);
|
||||
features->sse4_2 =
|
||||
GetWindowsIsProcessorFeaturePresent(PF_SSE4_2_INSTRUCTIONS_AVAILABLE);
|
||||
|
||||
// do not bother checking PF_AVX*
|
||||
// cause AVX enabled processor will have XCR0 be exposed and this function will be skipped at all
|
||||
}
|
||||
|
||||
#endif // CPU_FEATURES_OS_WINDOWS
|
||||
#endif // CPU_FEATURES_ARCH_X86
|
||||
132
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/stack_line_reader.c
generated
vendored
Normal file
132
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/stack_line_reader.c
generated
vendored
Normal file
@@ -0,0 +1,132 @@
|
||||
// Copyright 2017 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "internal/stack_line_reader.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "internal/filesystem.h"
|
||||
|
||||
void StackLineReader_Initialize(StackLineReader* reader, int fd) {
|
||||
reader->view.ptr = reader->buffer;
|
||||
reader->view.size = 0;
|
||||
reader->skip_mode = false;
|
||||
reader->fd = fd;
|
||||
}
|
||||
|
||||
// Replaces the content of buffer with bytes from the file.
|
||||
static int LoadFullBuffer(StackLineReader* reader) {
|
||||
const int read = CpuFeatures_ReadFile(reader->fd, reader->buffer,
|
||||
STACK_LINE_READER_BUFFER_SIZE);
|
||||
assert(read >= 0);
|
||||
reader->view.ptr = reader->buffer;
|
||||
reader->view.size = read;
|
||||
return read;
|
||||
}
|
||||
|
||||
// Appends with bytes from the file to buffer, filling the remaining space.
|
||||
static int LoadMore(StackLineReader* reader) {
|
||||
char* const ptr = reader->buffer + reader->view.size;
|
||||
const size_t size_to_read = STACK_LINE_READER_BUFFER_SIZE - reader->view.size;
|
||||
const int read = CpuFeatures_ReadFile(reader->fd, ptr, size_to_read);
|
||||
assert(read >= 0);
|
||||
assert(read <= (int)size_to_read);
|
||||
reader->view.size += read;
|
||||
return read;
|
||||
}
|
||||
|
||||
static int IndexOfEol(StackLineReader* reader) {
|
||||
return CpuFeatures_StringView_IndexOfChar(reader->view, '\n');
|
||||
}
|
||||
|
||||
// Relocate buffer's pending bytes at the beginning of the array and fills the
|
||||
// remaining space with bytes from the file.
|
||||
static int BringToFrontAndLoadMore(StackLineReader* reader) {
|
||||
if (reader->view.size && reader->view.ptr != reader->buffer) {
|
||||
memmove(reader->buffer, reader->view.ptr, reader->view.size);
|
||||
}
|
||||
reader->view.ptr = reader->buffer;
|
||||
return LoadMore(reader);
|
||||
}
|
||||
|
||||
// Loads chunks of buffer size from disks until it contains a newline character
|
||||
// or end of file.
|
||||
static void SkipToNextLine(StackLineReader* reader) {
|
||||
for (;;) {
|
||||
const int read = LoadFullBuffer(reader);
|
||||
if (read == 0) {
|
||||
break;
|
||||
} else {
|
||||
const int eol_index = IndexOfEol(reader);
|
||||
if (eol_index >= 0) {
|
||||
reader->view =
|
||||
CpuFeatures_StringView_PopFront(reader->view, eol_index + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static LineResult CreateLineResult(bool eof, bool full_line, StringView view) {
|
||||
LineResult result;
|
||||
result.eof = eof;
|
||||
result.full_line = full_line;
|
||||
result.line = view;
|
||||
return result;
|
||||
}
|
||||
|
||||
// Helper methods to provide clearer semantic in StackLineReader_NextLine.
|
||||
static LineResult CreateEOFLineResult(StringView view) {
|
||||
return CreateLineResult(true, true, view);
|
||||
}
|
||||
|
||||
static LineResult CreateTruncatedLineResult(StringView view) {
|
||||
return CreateLineResult(false, false, view);
|
||||
}
|
||||
|
||||
static LineResult CreateValidLineResult(StringView view) {
|
||||
return CreateLineResult(false, true, view);
|
||||
}
|
||||
|
||||
LineResult StackLineReader_NextLine(StackLineReader* reader) {
|
||||
if (reader->skip_mode) {
|
||||
SkipToNextLine(reader);
|
||||
reader->skip_mode = false;
|
||||
}
|
||||
{
|
||||
const bool can_load_more =
|
||||
reader->view.size < STACK_LINE_READER_BUFFER_SIZE;
|
||||
int eol_index = IndexOfEol(reader);
|
||||
if (eol_index < 0 && can_load_more) {
|
||||
const int read = BringToFrontAndLoadMore(reader);
|
||||
if (read == 0) {
|
||||
return CreateEOFLineResult(reader->view);
|
||||
}
|
||||
eol_index = IndexOfEol(reader);
|
||||
}
|
||||
if (eol_index < 0) {
|
||||
reader->skip_mode = true;
|
||||
return CreateTruncatedLineResult(reader->view);
|
||||
}
|
||||
{
|
||||
StringView line =
|
||||
CpuFeatures_StringView_KeepFront(reader->view, eol_index);
|
||||
reader->view =
|
||||
CpuFeatures_StringView_PopFront(reader->view, eol_index + 1);
|
||||
return CreateValidLineResult(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
192
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/string_view.c
generated
vendored
Normal file
192
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/string_view.c
generated
vendored
Normal file
@@ -0,0 +1,192 @@
|
||||
// Copyright 2017 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "internal/string_view.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "copy.inl"
|
||||
#include "equals.inl"
|
||||
|
||||
static const char* CpuFeatures_memchr(const char* const ptr, const size_t size,
|
||||
const char c) {
|
||||
for (size_t i = 0; ptr && ptr[i] != '\0' && i < size; ++i)
|
||||
if (ptr[i] == c) return ptr + i;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int CpuFeatures_StringView_IndexOfChar(const StringView view, char c) {
|
||||
if (view.ptr && view.size) {
|
||||
const char* const found = CpuFeatures_memchr(view.ptr, view.size, c);
|
||||
if (found) {
|
||||
return (int)(found - view.ptr);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int CpuFeatures_StringView_IndexOf(const StringView view,
|
||||
const StringView sub_view) {
|
||||
if (sub_view.size) {
|
||||
StringView remainder = view;
|
||||
while (remainder.size >= sub_view.size) {
|
||||
const int found_index =
|
||||
CpuFeatures_StringView_IndexOfChar(remainder, sub_view.ptr[0]);
|
||||
if (found_index < 0) break;
|
||||
remainder = CpuFeatures_StringView_PopFront(remainder, found_index);
|
||||
if (CpuFeatures_StringView_StartsWith(remainder, sub_view)) {
|
||||
return (int)(remainder.ptr - view.ptr);
|
||||
}
|
||||
remainder = CpuFeatures_StringView_PopFront(remainder, 1);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool CpuFeatures_StringView_IsEquals(const StringView a, const StringView b) {
|
||||
if (a.size == b.size) {
|
||||
return a.ptr == b.ptr || equals(a.ptr, b.ptr, b.size);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CpuFeatures_StringView_StartsWith(const StringView a, const StringView b) {
|
||||
return a.ptr && b.ptr && b.size && a.size >= b.size
|
||||
? equals(a.ptr, b.ptr, b.size)
|
||||
: false;
|
||||
}
|
||||
|
||||
StringView CpuFeatures_StringView_PopFront(const StringView str_view,
|
||||
size_t count) {
|
||||
if (count > str_view.size) {
|
||||
return kEmptyStringView;
|
||||
}
|
||||
return view(str_view.ptr + count, str_view.size - count);
|
||||
}
|
||||
|
||||
StringView CpuFeatures_StringView_PopBack(const StringView str_view,
|
||||
size_t count) {
|
||||
if (count > str_view.size) {
|
||||
return kEmptyStringView;
|
||||
}
|
||||
return view(str_view.ptr, str_view.size - count);
|
||||
}
|
||||
|
||||
StringView CpuFeatures_StringView_KeepFront(const StringView str_view,
|
||||
size_t count) {
|
||||
return count <= str_view.size ? view(str_view.ptr, count) : str_view;
|
||||
}
|
||||
|
||||
char CpuFeatures_StringView_Front(const StringView view) {
|
||||
assert(view.size);
|
||||
assert(view.ptr);
|
||||
return view.ptr[0];
|
||||
}
|
||||
|
||||
char CpuFeatures_StringView_Back(const StringView view) {
|
||||
assert(view.size);
|
||||
return view.ptr[view.size - 1];
|
||||
}
|
||||
|
||||
StringView CpuFeatures_StringView_TrimWhitespace(StringView view) {
|
||||
while (view.size && isspace(CpuFeatures_StringView_Front(view)))
|
||||
view = CpuFeatures_StringView_PopFront(view, 1);
|
||||
while (view.size && isspace(CpuFeatures_StringView_Back(view)))
|
||||
view = CpuFeatures_StringView_PopBack(view, 1);
|
||||
return view;
|
||||
}
|
||||
|
||||
static int HexValue(const char c) {
|
||||
if (c >= '0' && c <= '9') return c - '0';
|
||||
if (c >= 'a' && c <= 'f') return c - 'a' + 10;
|
||||
if (c >= 'A' && c <= 'F') return c - 'A' + 10;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Returns -1 if view contains non digits.
|
||||
static int ParsePositiveNumberWithBase(const StringView view, int base) {
|
||||
int result = 0;
|
||||
StringView remainder = view;
|
||||
for (; remainder.size;
|
||||
remainder = CpuFeatures_StringView_PopFront(remainder, 1)) {
|
||||
const int value = HexValue(CpuFeatures_StringView_Front(remainder));
|
||||
if (value < 0 || value >= base) return -1;
|
||||
result = (result * base) + value;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int CpuFeatures_StringView_ParsePositiveNumber(const StringView view) {
|
||||
if (view.size) {
|
||||
const StringView hex_prefix = str("0x");
|
||||
if (CpuFeatures_StringView_StartsWith(view, hex_prefix)) {
|
||||
const StringView span_no_prefix =
|
||||
CpuFeatures_StringView_PopFront(view, hex_prefix.size);
|
||||
return ParsePositiveNumberWithBase(span_no_prefix, 16);
|
||||
}
|
||||
return ParsePositiveNumberWithBase(view, 10);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void CpuFeatures_StringView_CopyString(const StringView src, char* dst,
|
||||
size_t dst_size) {
|
||||
if (dst_size > 0) {
|
||||
const size_t max_copy_size = dst_size - 1;
|
||||
const size_t copy_size =
|
||||
src.size > max_copy_size ? max_copy_size : src.size;
|
||||
copy(dst, src.ptr, copy_size);
|
||||
dst[copy_size] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
bool CpuFeatures_StringView_HasWord(const StringView line,
|
||||
const char* const word_str,
|
||||
const char separator) {
|
||||
const StringView word = str(word_str);
|
||||
StringView remainder = line;
|
||||
for (;;) {
|
||||
const int index_of_word = CpuFeatures_StringView_IndexOf(remainder, word);
|
||||
if (index_of_word < 0) {
|
||||
return false;
|
||||
} else {
|
||||
const StringView before =
|
||||
CpuFeatures_StringView_KeepFront(line, index_of_word);
|
||||
const StringView after =
|
||||
CpuFeatures_StringView_PopFront(line, index_of_word + word.size);
|
||||
const bool valid_before =
|
||||
before.size == 0 || CpuFeatures_StringView_Back(before) == separator;
|
||||
const bool valid_after =
|
||||
after.size == 0 || CpuFeatures_StringView_Front(after) == separator;
|
||||
if (valid_before && valid_after) return true;
|
||||
remainder =
|
||||
CpuFeatures_StringView_PopFront(remainder, index_of_word + word.size);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CpuFeatures_StringView_GetAttributeKeyValue(const StringView line,
|
||||
StringView* key,
|
||||
StringView* value) {
|
||||
const StringView sep = str(": ");
|
||||
const int index_of_separator = CpuFeatures_StringView_IndexOf(line, sep);
|
||||
if (index_of_separator < 0) return false;
|
||||
*value = CpuFeatures_StringView_TrimWhitespace(
|
||||
CpuFeatures_StringView_PopFront(line, index_of_separator + sep.size));
|
||||
*key = CpuFeatures_StringView_TrimWhitespace(
|
||||
CpuFeatures_StringView_KeepFront(line, index_of_separator));
|
||||
return true;
|
||||
}
|
||||
461
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/utils/list_cpu_features.c
generated
vendored
Normal file
461
mcp-server-ssh/node_modules/cpu-features/deps/cpu_features/src/utils/list_cpu_features.c
generated
vendored
Normal file
@@ -0,0 +1,461 @@
|
||||
// Copyright 2017 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// This program dumps current host data to the standard output.
|
||||
// Output can be text or json if the `--json` flag is passed.
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "cpu_features_macros.h"
|
||||
|
||||
#if defined(CPU_FEATURES_ARCH_X86)
|
||||
#include "cpuinfo_x86.h"
|
||||
#elif defined(CPU_FEATURES_ARCH_ARM)
|
||||
#include "cpuinfo_arm.h"
|
||||
#elif defined(CPU_FEATURES_ARCH_AARCH64)
|
||||
#include "cpuinfo_aarch64.h"
|
||||
#elif defined(CPU_FEATURES_ARCH_MIPS)
|
||||
#include "cpuinfo_mips.h"
|
||||
#elif defined(CPU_FEATURES_ARCH_PPC)
|
||||
#include "cpuinfo_ppc.h"
|
||||
#elif defined(CPU_FEATURES_ARCH_S390X)
|
||||
#include "cpuinfo_s390x.h"
|
||||
#elif defined(CPU_FEATURES_ARCH_RISCV)
|
||||
#include "cpuinfo_riscv.h"
|
||||
#endif
|
||||
|
||||
// Design principles
|
||||
// -----------------
|
||||
// We build a tree structure containing all the data to be displayed.
|
||||
// Then depending on the output type (text or json) we walk the tree and display
|
||||
// the data accordingly.
|
||||
|
||||
// We use a bump allocator to allocate strings and nodes of the tree,
|
||||
// Memory is not intended to be reclaimed.
|
||||
typedef struct {
|
||||
char* ptr;
|
||||
size_t size;
|
||||
} BumpAllocator;
|
||||
|
||||
char gGlobalBuffer[64 * 1024];
|
||||
BumpAllocator gBumpAllocator = {.ptr = gGlobalBuffer,
|
||||
.size = sizeof(gGlobalBuffer)};
|
||||
|
||||
static void internal_error(void) {
|
||||
fputs("internal error\n", stderr);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
#define ALIGN 8
|
||||
|
||||
static void assertAligned(void) {
|
||||
if ((uintptr_t)(gBumpAllocator.ptr) % ALIGN) internal_error();
|
||||
}
|
||||
|
||||
static void BA_Align(void) {
|
||||
while (gBumpAllocator.size && (uintptr_t)(gBumpAllocator.ptr) % ALIGN) {
|
||||
--gBumpAllocator.size;
|
||||
++gBumpAllocator.ptr;
|
||||
}
|
||||
assertAligned();
|
||||
}
|
||||
|
||||
// Update the available memory left in the BumpAllocator.
|
||||
static void* BA_Bump(size_t size) {
|
||||
assertAligned();
|
||||
// Align size to next 8B boundary.
|
||||
size = (size + ALIGN - 1) / ALIGN * ALIGN;
|
||||
if (gBumpAllocator.size < size) internal_error();
|
||||
void* ptr = gBumpAllocator.ptr;
|
||||
gBumpAllocator.size -= size;
|
||||
gBumpAllocator.ptr += size;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
// The type of the nodes in the tree.
|
||||
typedef enum {
|
||||
NT_INVALID,
|
||||
NT_INT,
|
||||
NT_MAP,
|
||||
NT_MAP_ENTRY,
|
||||
NT_ARRAY,
|
||||
NT_ARRAY_ELEMENT,
|
||||
NT_STRING,
|
||||
} NodeType;
|
||||
|
||||
// The node in the tree.
|
||||
typedef struct Node {
|
||||
NodeType type;
|
||||
unsigned integer;
|
||||
const char* string;
|
||||
struct Node* value;
|
||||
struct Node* next;
|
||||
} Node;
|
||||
|
||||
// Creates an initialized Node.
|
||||
static Node* BA_CreateNode(NodeType type) {
|
||||
Node* tv = (Node*)BA_Bump(sizeof(Node));
|
||||
assert(tv);
|
||||
*tv = (Node){.type = type};
|
||||
return tv;
|
||||
}
|
||||
|
||||
// Adds an integer node.
|
||||
static Node* CreateInt(int value) {
|
||||
Node* tv = BA_CreateNode(NT_INT);
|
||||
tv->integer = value;
|
||||
return tv;
|
||||
}
|
||||
|
||||
// Adds a string node.
|
||||
// `value` must outlive the tree.
|
||||
static Node* CreateConstantString(const char* value) {
|
||||
Node* tv = BA_CreateNode(NT_STRING);
|
||||
tv->string = value;
|
||||
return tv;
|
||||
}
|
||||
|
||||
// Adds a map node.
|
||||
static Node* CreateMap(void) { return BA_CreateNode(NT_MAP); }
|
||||
|
||||
// Adds an array node.
|
||||
static Node* CreateArray(void) { return BA_CreateNode(NT_ARRAY); }
|
||||
|
||||
// Adds a formatted string node.
|
||||
static Node* CreatePrintfString(const char* format, ...) {
|
||||
va_list arglist;
|
||||
va_start(arglist, format);
|
||||
char* const ptr = gBumpAllocator.ptr;
|
||||
const int written = vsnprintf(ptr, gBumpAllocator.size, format, arglist);
|
||||
va_end(arglist);
|
||||
if (written < 0 || written >= (int)gBumpAllocator.size) internal_error();
|
||||
return CreateConstantString((char*)BA_Bump(written));
|
||||
}
|
||||
|
||||
// Adds a string node.
|
||||
static Node* CreateString(const char* value) {
|
||||
return CreatePrintfString("%s", value);
|
||||
}
|
||||
|
||||
// Adds a map entry node.
|
||||
static void AddMapEntry(Node* map, const char* key, Node* value) {
|
||||
assert(map && map->type == NT_MAP);
|
||||
Node* current = map;
|
||||
while (current->next) current = current->next;
|
||||
current->next = (Node*)BA_Bump(sizeof(Node));
|
||||
*current->next = (Node){.type = NT_MAP_ENTRY, .string = key, .value = value};
|
||||
}
|
||||
|
||||
// Adds an array element node.
|
||||
static void AddArrayElement(Node* array, Node* value) {
|
||||
assert(array && array->type == NT_ARRAY);
|
||||
Node* current = array;
|
||||
while (current->next) current = current->next;
|
||||
current->next = (Node*)BA_Bump(sizeof(Node));
|
||||
*current->next = (Node){.type = NT_ARRAY_ELEMENT, .value = value};
|
||||
}
|
||||
|
||||
static int cmp(const void* p1, const void* p2) {
|
||||
return strcmp(*(const char* const*)p1, *(const char* const*)p2);
|
||||
}
|
||||
|
||||
#define DEFINE_ADD_FLAGS(HasFeature, FeatureName, FeatureType, LastEnum) \
|
||||
static void AddFlags(Node* map, const FeatureType* features) { \
|
||||
size_t i; \
|
||||
const char* ptrs[LastEnum] = {0}; \
|
||||
size_t count = 0; \
|
||||
for (i = 0; i < LastEnum; ++i) { \
|
||||
if (HasFeature(features, i)) { \
|
||||
ptrs[count] = FeatureName(i); \
|
||||
++count; \
|
||||
} \
|
||||
} \
|
||||
qsort((void*)ptrs, count, sizeof(char*), cmp); \
|
||||
Node* const array = CreateArray(); \
|
||||
for (i = 0; i < count; ++i) \
|
||||
AddArrayElement(array, CreateConstantString(ptrs[i])); \
|
||||
AddMapEntry(map, "flags", array); \
|
||||
}
|
||||
|
||||
#if defined(CPU_FEATURES_ARCH_X86)
|
||||
DEFINE_ADD_FLAGS(GetX86FeaturesEnumValue, GetX86FeaturesEnumName, X86Features,
|
||||
X86_LAST_)
|
||||
#elif defined(CPU_FEATURES_ARCH_ARM)
|
||||
DEFINE_ADD_FLAGS(GetArmFeaturesEnumValue, GetArmFeaturesEnumName, ArmFeatures,
|
||||
ARM_LAST_)
|
||||
#elif defined(CPU_FEATURES_ARCH_AARCH64)
|
||||
DEFINE_ADD_FLAGS(GetAarch64FeaturesEnumValue, GetAarch64FeaturesEnumName,
|
||||
Aarch64Features, AARCH64_LAST_)
|
||||
#elif defined(CPU_FEATURES_ARCH_MIPS)
|
||||
DEFINE_ADD_FLAGS(GetMipsFeaturesEnumValue, GetMipsFeaturesEnumName,
|
||||
MipsFeatures, MIPS_LAST_)
|
||||
#elif defined(CPU_FEATURES_ARCH_PPC)
|
||||
DEFINE_ADD_FLAGS(GetPPCFeaturesEnumValue, GetPPCFeaturesEnumName, PPCFeatures,
|
||||
PPC_LAST_)
|
||||
#elif defined(CPU_FEATURES_ARCH_S390X)
|
||||
DEFINE_ADD_FLAGS(GetS390XFeaturesEnumValue, GetS390XFeaturesEnumName, S390XFeatures,
|
||||
S390X_LAST_)
|
||||
#elif defined(CPU_FEATURES_ARCH_RISCV)
|
||||
DEFINE_ADD_FLAGS(GetRiscvFeaturesEnumValue, GetRiscvFeaturesEnumName, RiscvFeatures,
|
||||
RISCV_LAST_)
|
||||
#endif
|
||||
|
||||
// Prints a json string with characters escaping.
|
||||
static void printJsonString(const char* str) {
|
||||
putchar('"');
|
||||
for (; str && *str; ++str) {
|
||||
switch (*str) {
|
||||
case '\"':
|
||||
case '\\':
|
||||
case '/':
|
||||
case '\b':
|
||||
case '\f':
|
||||
case '\n':
|
||||
case '\r':
|
||||
case '\t':
|
||||
putchar('\\');
|
||||
}
|
||||
putchar(*str);
|
||||
}
|
||||
putchar('"');
|
||||
}
|
||||
|
||||
// Walks a Node and print it as json.
|
||||
static void printJson(const Node* current) {
|
||||
assert(current);
|
||||
switch (current->type) {
|
||||
case NT_INVALID:
|
||||
break;
|
||||
case NT_INT:
|
||||
printf("%d", current->integer);
|
||||
break;
|
||||
case NT_STRING:
|
||||
printJsonString(current->string);
|
||||
break;
|
||||
case NT_ARRAY:
|
||||
putchar('[');
|
||||
if (current->next) printJson(current->next);
|
||||
putchar(']');
|
||||
break;
|
||||
case NT_MAP:
|
||||
putchar('{');
|
||||
if (current->next) printJson(current->next);
|
||||
putchar('}');
|
||||
break;
|
||||
case NT_MAP_ENTRY:
|
||||
printf("\"%s\":", current->string);
|
||||
printJson(current->value);
|
||||
if (current->next) {
|
||||
putchar(',');
|
||||
printJson(current->next);
|
||||
}
|
||||
break;
|
||||
case NT_ARRAY_ELEMENT:
|
||||
printJson(current->value);
|
||||
if (current->next) {
|
||||
putchar(',');
|
||||
printJson(current->next);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Walks a Node and print it as text.
|
||||
static void printTextField(const Node* current) {
|
||||
switch (current->type) {
|
||||
case NT_INVALID:
|
||||
break;
|
||||
case NT_INT:
|
||||
printf("%3d (0x%02X)", current->integer, current->integer);
|
||||
break;
|
||||
case NT_STRING:
|
||||
fputs(current->string, stdout);
|
||||
break;
|
||||
case NT_ARRAY:
|
||||
if (current->next) printTextField(current->next);
|
||||
break;
|
||||
case NT_MAP:
|
||||
if (current->next) {
|
||||
printf("{");
|
||||
printJson(current->next);
|
||||
printf("}");
|
||||
}
|
||||
break;
|
||||
case NT_MAP_ENTRY:
|
||||
printf("%-15s : ", current->string);
|
||||
printTextField(current->value);
|
||||
if (current->next) {
|
||||
putchar('\n');
|
||||
printTextField(current->next);
|
||||
}
|
||||
break;
|
||||
case NT_ARRAY_ELEMENT:
|
||||
printTextField(current->value);
|
||||
if (current->next) {
|
||||
putchar(',');
|
||||
printTextField(current->next);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void printTextRoot(const Node* current) {
|
||||
if (current->type == NT_MAP && current->next) printTextField(current->next);
|
||||
}
|
||||
|
||||
static void showUsage(const char* name) {
|
||||
printf(
|
||||
"\n"
|
||||
"Usage: %s [options]\n"
|
||||
" Options:\n"
|
||||
" -h | --help Show help message.\n"
|
||||
" -j | --json Format output as json instead of plain text.\n"
|
||||
"\n",
|
||||
name);
|
||||
}
|
||||
|
||||
static Node* GetCacheTypeString(CacheType cache_type) {
|
||||
switch (cache_type) {
|
||||
case CPU_FEATURE_CACHE_NULL:
|
||||
return CreateConstantString("null");
|
||||
case CPU_FEATURE_CACHE_DATA:
|
||||
return CreateConstantString("data");
|
||||
case CPU_FEATURE_CACHE_INSTRUCTION:
|
||||
return CreateConstantString("instruction");
|
||||
case CPU_FEATURE_CACHE_UNIFIED:
|
||||
return CreateConstantString("unified");
|
||||
case CPU_FEATURE_CACHE_TLB:
|
||||
return CreateConstantString("tlb");
|
||||
case CPU_FEATURE_CACHE_DTLB:
|
||||
return CreateConstantString("dtlb");
|
||||
case CPU_FEATURE_CACHE_STLB:
|
||||
return CreateConstantString("stlb");
|
||||
case CPU_FEATURE_CACHE_PREFETCH:
|
||||
return CreateConstantString("prefetch");
|
||||
}
|
||||
CPU_FEATURES_UNREACHABLE();
|
||||
}
|
||||
|
||||
static void AddCacheInfo(Node* root, const CacheInfo* cache_info) {
|
||||
Node* array = CreateArray();
|
||||
for (int i = 0; i < cache_info->size; ++i) {
|
||||
CacheLevelInfo info = cache_info->levels[i];
|
||||
Node* map = CreateMap();
|
||||
AddMapEntry(map, "level", CreateInt(info.level));
|
||||
AddMapEntry(map, "cache_type", GetCacheTypeString(info.cache_type));
|
||||
AddMapEntry(map, "cache_size", CreateInt(info.cache_size));
|
||||
AddMapEntry(map, "ways", CreateInt(info.ways));
|
||||
AddMapEntry(map, "line_size", CreateInt(info.line_size));
|
||||
AddMapEntry(map, "tlb_entries", CreateInt(info.tlb_entries));
|
||||
AddMapEntry(map, "partitioning", CreateInt(info.partitioning));
|
||||
AddArrayElement(array, map);
|
||||
}
|
||||
AddMapEntry(root, "cache_info", array);
|
||||
}
|
||||
|
||||
static Node* CreateTree(void) {
|
||||
Node* root = CreateMap();
|
||||
#if defined(CPU_FEATURES_ARCH_X86)
|
||||
const X86Info info = GetX86Info();
|
||||
const CacheInfo cache_info = GetX86CacheInfo();
|
||||
AddMapEntry(root, "arch", CreateString("x86"));
|
||||
AddMapEntry(root, "brand", CreateString(info.brand_string));
|
||||
AddMapEntry(root, "family", CreateInt(info.family));
|
||||
AddMapEntry(root, "model", CreateInt(info.model));
|
||||
AddMapEntry(root, "stepping", CreateInt(info.stepping));
|
||||
AddMapEntry(root, "uarch",
|
||||
CreateString(
|
||||
GetX86MicroarchitectureName(GetX86Microarchitecture(&info))));
|
||||
AddFlags(root, &info.features);
|
||||
AddCacheInfo(root, &cache_info);
|
||||
#elif defined(CPU_FEATURES_ARCH_ARM)
|
||||
const ArmInfo info = GetArmInfo();
|
||||
AddMapEntry(root, "arch", CreateString("ARM"));
|
||||
AddMapEntry(root, "implementer", CreateInt(info.implementer));
|
||||
AddMapEntry(root, "architecture", CreateInt(info.architecture));
|
||||
AddMapEntry(root, "variant", CreateInt(info.variant));
|
||||
AddMapEntry(root, "part", CreateInt(info.part));
|
||||
AddMapEntry(root, "revision", CreateInt(info.revision));
|
||||
AddFlags(root, &info.features);
|
||||
#elif defined(CPU_FEATURES_ARCH_AARCH64)
|
||||
const Aarch64Info info = GetAarch64Info();
|
||||
AddMapEntry(root, "arch", CreateString("aarch64"));
|
||||
AddMapEntry(root, "implementer", CreateInt(info.implementer));
|
||||
AddMapEntry(root, "variant", CreateInt(info.variant));
|
||||
AddMapEntry(root, "part", CreateInt(info.part));
|
||||
AddMapEntry(root, "revision", CreateInt(info.revision));
|
||||
AddFlags(root, &info.features);
|
||||
#elif defined(CPU_FEATURES_ARCH_MIPS)
|
||||
const MipsInfo info = GetMipsInfo();
|
||||
AddMapEntry(root, "arch", CreateString("mips"));
|
||||
AddFlags(root, &info.features);
|
||||
#elif defined(CPU_FEATURES_ARCH_PPC)
|
||||
const PPCInfo info = GetPPCInfo();
|
||||
const PPCPlatformStrings strings = GetPPCPlatformStrings();
|
||||
AddMapEntry(root, "arch", CreateString("ppc"));
|
||||
AddMapEntry(root, "platform", CreateString(strings.platform));
|
||||
AddMapEntry(root, "model", CreateString(strings.model));
|
||||
AddMapEntry(root, "machine", CreateString(strings.machine));
|
||||
AddMapEntry(root, "cpu", CreateString(strings.cpu));
|
||||
AddMapEntry(root, "instruction", CreateString(strings.type.platform));
|
||||
AddMapEntry(root, "microarchitecture",
|
||||
CreateString(strings.type.base_platform));
|
||||
AddFlags(root, &info.features);
|
||||
#elif defined(CPU_FEATURES_ARCH_S390X)
|
||||
const S390XInfo info = GetS390XInfo();
|
||||
const S390XPlatformStrings strings = GetS390XPlatformStrings();
|
||||
AddMapEntry(root, "arch", CreateString("s390x"));
|
||||
AddMapEntry(root, "platform", CreateString("zSeries"));
|
||||
AddMapEntry(root, "model", CreateString(strings.type.platform));
|
||||
AddMapEntry(root, "# processors", CreateInt(strings.num_processors));
|
||||
AddFlags(root, &info.features);
|
||||
#elif defined(CPU_FEATURES_ARCH_RISCV)
|
||||
const RiscvInfo info = GetRiscvInfo();
|
||||
AddMapEntry(root, "arch", CreateString("risc-v"));
|
||||
AddMapEntry(root, "vendor", CreateString(info.vendor));
|
||||
AddMapEntry(root, "microarchitecture", CreateString(info.uarch));
|
||||
AddFlags(root, &info.features);
|
||||
#endif
|
||||
return root;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
BA_Align();
|
||||
const Node* const root = CreateTree();
|
||||
bool outputJson = false;
|
||||
int i = 1;
|
||||
for (; i < argc; ++i) {
|
||||
const char* arg = argv[i];
|
||||
if (strcmp(arg, "-j") == 0 || strcmp(arg, "--json") == 0) {
|
||||
outputJson = true;
|
||||
} else {
|
||||
showUsage(argv[0]);
|
||||
if (strcmp(arg, "-h") == 0 || strcmp(arg, "--help") == 0)
|
||||
return EXIT_SUCCESS;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
if (outputJson)
|
||||
printJson(root);
|
||||
else
|
||||
printTextRoot(root);
|
||||
putchar('\n');
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Reference in New Issue
Block a user