зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1610991 - Update rlbox_lucet lib to Mac compatible version r=froydnj
Differential Revision: https://phabricator.services.mozilla.com/D61077 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
0cc72577b5
Коммит
4fbd7a0f7c
|
@ -60,12 +60,12 @@ replace-with = "vendored-sources"
|
|||
[source."https://github.com/PLSysSec/rlbox_lucet_sandbox/"]
|
||||
git = "https://github.com/PLSysSec/rlbox_lucet_sandbox/"
|
||||
replace-with = "vendored-sources"
|
||||
rev = "5f8bca975d8206e4837786d6bdb57a5c2fbd4016"
|
||||
rev = "6ddc15b70f0d902241742fd55c689649cad100f8"
|
||||
|
||||
[source."https://github.com/PLSysSec/lucet_sandbox_compiler"]
|
||||
git = "https://github.com/PLSysSec/lucet_sandbox_compiler"
|
||||
replace-with = "vendored-sources"
|
||||
rev = "58498599272e23ef797bb4304d0f181d7455ca57"
|
||||
rev = "a3fd180d53a6f929a7ef47466ffc2e53338ad4f1"
|
||||
|
||||
[source."https://github.com/ChunMinChang/cubeb-coreaudio-rs"]
|
||||
git = "https://github.com/ChunMinChang/cubeb-coreaudio-rs"
|
||||
|
|
|
@ -737,7 +737,7 @@ source = "git+https://github.com/bytecodealliance/cranelift?rev=eb20fcab349ce20a
|
|||
[[package]]
|
||||
name = "cranelift-entity"
|
||||
version = "0.41.0"
|
||||
source = "git+https://github.com/PLSysSec/lucet_sandbox_compiler?rev=58498599272e23ef797bb4304d0f181d7455ca57#58498599272e23ef797bb4304d0f181d7455ca57"
|
||||
source = "git+https://github.com/PLSysSec/lucet_sandbox_compiler?rev=a3fd180d53a6f929a7ef47466ffc2e53338ad4f1#a3fd180d53a6f929a7ef47466ffc2e53338ad4f1"
|
||||
|
||||
[[package]]
|
||||
name = "cranelift-entity"
|
||||
|
@ -2123,7 +2123,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "lucet-module"
|
||||
version = "0.1.1"
|
||||
source = "git+https://github.com/PLSysSec/lucet_sandbox_compiler?rev=58498599272e23ef797bb4304d0f181d7455ca57#58498599272e23ef797bb4304d0f181d7455ca57"
|
||||
source = "git+https://github.com/PLSysSec/lucet_sandbox_compiler?rev=a3fd180d53a6f929a7ef47466ffc2e53338ad4f1#a3fd180d53a6f929a7ef47466ffc2e53338ad4f1"
|
||||
dependencies = [
|
||||
"bincode",
|
||||
"byteorder",
|
||||
|
@ -2139,7 +2139,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "lucet-runtime"
|
||||
version = "0.1.1"
|
||||
source = "git+https://github.com/PLSysSec/lucet_sandbox_compiler?rev=58498599272e23ef797bb4304d0f181d7455ca57#58498599272e23ef797bb4304d0f181d7455ca57"
|
||||
source = "git+https://github.com/PLSysSec/lucet_sandbox_compiler?rev=a3fd180d53a6f929a7ef47466ffc2e53338ad4f1#a3fd180d53a6f929a7ef47466ffc2e53338ad4f1"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
|
@ -2152,7 +2152,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "lucet-runtime-internals"
|
||||
version = "0.1.1"
|
||||
source = "git+https://github.com/PLSysSec/lucet_sandbox_compiler?rev=58498599272e23ef797bb4304d0f181d7455ca57#58498599272e23ef797bb4304d0f181d7455ca57"
|
||||
source = "git+https://github.com/PLSysSec/lucet_sandbox_compiler?rev=a3fd180d53a6f929a7ef47466ffc2e53338ad4f1#a3fd180d53a6f929a7ef47466ffc2e53338ad4f1"
|
||||
dependencies = [
|
||||
"bincode",
|
||||
"bitflags",
|
||||
|
@ -2168,13 +2168,14 @@ dependencies = [
|
|||
"nix",
|
||||
"num-derive",
|
||||
"num-traits",
|
||||
"raw-cpuid",
|
||||
"xfailure",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lucet-wasi"
|
||||
version = "0.1.1"
|
||||
source = "git+https://github.com/PLSysSec/lucet_sandbox_compiler?rev=58498599272e23ef797bb4304d0f181d7455ca57#58498599272e23ef797bb4304d0f181d7455ca57"
|
||||
source = "git+https://github.com/PLSysSec/lucet_sandbox_compiler?rev=a3fd180d53a6f929a7ef47466ffc2e53338ad4f1#a3fd180d53a6f929a7ef47466ffc2e53338ad4f1"
|
||||
dependencies = [
|
||||
"cast",
|
||||
"failure",
|
||||
|
@ -2182,6 +2183,7 @@ dependencies = [
|
|||
"lucet-module",
|
||||
"lucet-runtime",
|
||||
"lucet-runtime-internals",
|
||||
"mach",
|
||||
"nix",
|
||||
"rand",
|
||||
]
|
||||
|
@ -3247,6 +3249,17 @@ version = "0.1.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dd5927936723a9e8b715d37d7e4b390455087c4bdf25b9f702309460577b14f9"
|
||||
|
||||
[[package]]
|
||||
name = "raw-cpuid"
|
||||
version = "7.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b4a349ca83373cfa5d6dbb66fd76e58b2cca08da71a5f6400de0a0a6a9bceeaf"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"cc",
|
||||
"rustc_version",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "raw-window-handle"
|
||||
version = "0.3.0"
|
||||
|
@ -3467,7 +3480,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "rlbox_lucet_sandbox"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/PLSysSec/rlbox_lucet_sandbox/?rev=5f8bca975d8206e4837786d6bdb57a5c2fbd4016#5f8bca975d8206e4837786d6bdb57a5c2fbd4016"
|
||||
source = "git+https://github.com/PLSysSec/rlbox_lucet_sandbox/?rev=6ddc15b70f0d902241742fd55c689649cad100f8#6ddc15b70f0d902241742fd55c689649cad100f8"
|
||||
dependencies = [
|
||||
"failure",
|
||||
"goblin",
|
||||
|
|
|
@ -62,7 +62,7 @@ codegen-units = 1
|
|||
[patch.crates-io]
|
||||
libudev-sys = { path = "dom/webauthn/libudev-sys" }
|
||||
packed_simd = { git = "https://github.com/hsivonen/packed_simd", branch = "rust_1_32" }
|
||||
rlbox_lucet_sandbox = { git = "https://github.com/PLSysSec/rlbox_lucet_sandbox/", rev="5f8bca975d8206e4837786d6bdb57a5c2fbd4016" }
|
||||
rlbox_lucet_sandbox = { git = "https://github.com/PLSysSec/rlbox_lucet_sandbox/", rev="6ddc15b70f0d902241742fd55c689649cad100f8" }
|
||||
nix = { git = "https://github.com/shravanrn/nix/", branch = "r0.13.1", rev="4af6c367603869a30fddb5ffb0aba2b9477ba92e" }
|
||||
spirv_cross = { git = "https://github.com/kvark/spirv_cross", branch = "wgpu", rev = "9cb4de489bf80b2b23efffe5a79afb7db6247ba4" }
|
||||
# failure's backtrace feature might break our builds, see bug 1608157.
|
||||
|
|
|
@ -566,6 +566,7 @@ $(WASM_ARCHIVE): $(CWASMOBJS) $(CPPWASMOBJS) $(STATIC_LIBS) $(EXTRA_DEPS) $(GLOB
|
|||
$(WASM_CXX) $(OUTOPTION)$@ -Wl,--export-all $(WASM_LDFLAGS) $(CWASMOBJS) $(CPPWASMOBJS)
|
||||
|
||||
lucet_options := \
|
||||
--target-cpu baseline \
|
||||
--bindings $(topsrcdir)/third_party/rust/lucet-wasi/bindings.json \
|
||||
--guard-size 4GiB \
|
||||
--min-reserved-size 4GiB \
|
||||
|
|
|
@ -448,7 +448,7 @@ lucetc-source:
|
|||
fetch:
|
||||
type: git
|
||||
repo: https://github.com/PLSysSec/lucet_sandbox_compiler/
|
||||
revision: 5c22392b5b1aaa60e915c75e92b57391e1e61e6d
|
||||
revision: a3fd180d53a6f929a7ef47466ffc2e53338ad4f1
|
||||
|
||||
dump-syms:
|
||||
description: dump_syms source code
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"files":{"Cargo.toml":"541f0b13e6f51d7ce1e61275aaaeeaabd38ae9f3e5b6bb1d5b543be416449546","src/bindings.rs":"bb0bcfb2e328f139d7d34b95d91ac64008c54fbf2748caf818b4a6af6c3bec14","src/error.rs":"1c938dfd33b790eb97e920785aadc7b4a2796d8e2e806b6083593ccf173d43d1","src/functions.rs":"29f4e4bd91986680d7d06ed6f5ccbb8bc734b52316e5bf9ac40ced45cbc8b149","src/globals.rs":"18841f6f5d6163673de5e9dfd641b1c558e9ad984418cbf94691059a1c4ed2a2","src/lib.rs":"9b5ec1e3fd8b0c51e5eceb8ac4930f9d2562cf296cffa102746b794547cbcfbb","src/linear_memory.rs":"aa62a57ad0783508465dc43bd22167c33d15efb32e44b9aeba6ff86ea72051ef","src/module.rs":"56f37d2892fe91d19afc49d2f62b562f0f71a21f21aec205b5368c733329d629","src/module_data.rs":"8059b46aeef038babdedbf3d2de758605f019ba6f2ab8ddc7c132581609a7a78","src/runtime.rs":"0532a55d2649eb6ea486a70c278ccbc243255cdbf5462739c0db6a2e73cb4d1a","src/signature.rs":"c1606419111edec1895762c212c7116a0d39670c8d303b5af0f58295ba15cfc4","src/tables.rs":"efe9aa8ae3602cce8aa093e220d63490b17907be8ed192024939445ff8b8922b","src/traps.rs":"2ff45ff2438f18ca1740182cf9735cbb789125bd57214e5a140b3bcd5295a433","src/types.rs":"d354b3a9f96b768dc7a8885b9fefa2efc1e01bcb66e5028e5f787247d1b2abb2","tests/bindings/bad_bindings.json":"7c5ad85eb0a222985857b6ff35246dccfa2a35de415d57fd712264ca7e078934","tests/bindings/bindings_test.json":"2e3ed6ff5d18da665d5c2fb24e279f009092f21bba6deff221db7a5770a6a3d4","tests/bindings/garbage.json":"f956f64c8c23ecf2aa6226fa7abc5f52eee2fa861e12ceac3bddbdf0602a174b"},"package":null}
|
||||
{"files":{"Cargo.toml":"541f0b13e6f51d7ce1e61275aaaeeaabd38ae9f3e5b6bb1d5b543be416449546","src/bindings.rs":"bb0bcfb2e328f139d7d34b95d91ac64008c54fbf2748caf818b4a6af6c3bec14","src/error.rs":"1c938dfd33b790eb97e920785aadc7b4a2796d8e2e806b6083593ccf173d43d1","src/functions.rs":"29f4e4bd91986680d7d06ed6f5ccbb8bc734b52316e5bf9ac40ced45cbc8b149","src/globals.rs":"18841f6f5d6163673de5e9dfd641b1c558e9ad984418cbf94691059a1c4ed2a2","src/lib.rs":"759adce1db8c138294edcc47610f905e89da2e3ba5e62e3cef769ba1556ae174","src/linear_memory.rs":"aa62a57ad0783508465dc43bd22167c33d15efb32e44b9aeba6ff86ea72051ef","src/module.rs":"56f37d2892fe91d19afc49d2f62b562f0f71a21f21aec205b5368c733329d629","src/module_data.rs":"9e08e44ce8aaa90ae60240eb8feb693d5ca36dc42df55147617f5c3b636b9b8b","src/runtime.rs":"0532a55d2649eb6ea486a70c278ccbc243255cdbf5462739c0db6a2e73cb4d1a","src/signature.rs":"c1606419111edec1895762c212c7116a0d39670c8d303b5af0f58295ba15cfc4","src/tables.rs":"efe9aa8ae3602cce8aa093e220d63490b17907be8ed192024939445ff8b8922b","src/traps.rs":"2ff45ff2438f18ca1740182cf9735cbb789125bd57214e5a140b3bcd5295a433","src/types.rs":"d354b3a9f96b768dc7a8885b9fefa2efc1e01bcb66e5028e5f787247d1b2abb2","tests/bindings/bad_bindings.json":"7c5ad85eb0a222985857b6ff35246dccfa2a35de415d57fd712264ca7e078934","tests/bindings/bindings_test.json":"2e3ed6ff5d18da665d5c2fb24e279f009092f21bba6deff221db7a5770a6a3d4","tests/bindings/garbage.json":"f956f64c8c23ecf2aa6226fa7abc5f52eee2fa861e12ceac3bddbdf0602a174b"},"package":null}
|
|
@ -26,7 +26,7 @@ pub use crate::functions::{
|
|||
pub use crate::globals::{Global, GlobalDef, GlobalSpec, GlobalValue};
|
||||
pub use crate::linear_memory::{HeapSpec, LinearMemorySpec, SparseData};
|
||||
pub use crate::module::{Module, SerializedModule, LUCET_MODULE_SYM};
|
||||
pub use crate::module_data::{ModuleData, MODULE_DATA_SYM};
|
||||
pub use crate::module_data::{ModuleData, ModuleFeatures, MODULE_DATA_SYM};
|
||||
pub use crate::runtime::InstanceRuntimeData;
|
||||
pub use crate::signature::ModuleSignature;
|
||||
#[cfg(feature = "signature_checking")]
|
||||
|
|
|
@ -35,6 +35,38 @@ pub struct ModuleData<'a> {
|
|||
export_functions: Vec<ExportFunction<'a>>,
|
||||
signatures: Vec<Signature>,
|
||||
module_signature: Vec<u8>,
|
||||
features: ModuleFeatures,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
|
||||
pub struct ModuleFeatures {
|
||||
pub sse3: bool,
|
||||
pub ssse3: bool,
|
||||
pub sse41: bool,
|
||||
pub sse42: bool,
|
||||
pub avx: bool,
|
||||
pub bmi1: bool,
|
||||
pub bmi2: bool,
|
||||
pub lzcnt: bool,
|
||||
pub popcnt: bool,
|
||||
_hidden: (),
|
||||
}
|
||||
|
||||
impl ModuleFeatures {
|
||||
pub fn none() -> Self {
|
||||
Self {
|
||||
sse3: false,
|
||||
ssse3: false,
|
||||
sse41: false,
|
||||
sse42: false,
|
||||
avx: false,
|
||||
bmi1: false,
|
||||
bmi2: false,
|
||||
lzcnt: false,
|
||||
popcnt: false,
|
||||
_hidden: (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ModuleData<'a> {
|
||||
|
@ -46,6 +78,7 @@ impl<'a> ModuleData<'a> {
|
|||
import_functions: Vec<ImportFunction<'a>>,
|
||||
export_functions: Vec<ExportFunction<'a>>,
|
||||
signatures: Vec<Signature>,
|
||||
features: ModuleFeatures,
|
||||
) -> Self {
|
||||
let module_signature = vec![0u8; SignatureBones::BYTES];
|
||||
Self {
|
||||
|
@ -56,6 +89,7 @@ impl<'a> ModuleData<'a> {
|
|||
export_functions,
|
||||
signatures,
|
||||
module_signature,
|
||||
features,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,6 +101,7 @@ impl<'a> ModuleData<'a> {
|
|||
import_functions: Vec<ImportFunction<'a>>,
|
||||
export_functions: Vec<ExportFunction<'a>>,
|
||||
signatures: Vec<Signature>,
|
||||
features: ModuleFeatures,
|
||||
) -> Self {
|
||||
let module_signature = vec![0u8; 0];
|
||||
Self {
|
||||
|
@ -77,6 +112,7 @@ impl<'a> ModuleData<'a> {
|
|||
export_functions,
|
||||
signatures,
|
||||
module_signature,
|
||||
features,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -136,6 +172,10 @@ impl<'a> ModuleData<'a> {
|
|||
&self.module_signature
|
||||
}
|
||||
|
||||
pub fn features(&self) -> &ModuleFeatures {
|
||||
&self.features
|
||||
}
|
||||
|
||||
#[cfg(feature = "signature_checking")]
|
||||
pub fn patch_module_signature(
|
||||
module_data_bin: &'a [u8],
|
||||
|
@ -186,6 +226,7 @@ pub struct OwnedModuleData {
|
|||
imports: Vec<OwnedImportFunction>,
|
||||
exports: Vec<OwnedExportFunction>,
|
||||
signatures: Vec<Signature>,
|
||||
features: ModuleFeatures,
|
||||
}
|
||||
|
||||
impl OwnedModuleData {
|
||||
|
@ -196,6 +237,7 @@ impl OwnedModuleData {
|
|||
imports: Vec<OwnedImportFunction>,
|
||||
exports: Vec<OwnedExportFunction>,
|
||||
signatures: Vec<Signature>,
|
||||
features: ModuleFeatures,
|
||||
) -> Self {
|
||||
Self {
|
||||
linear_memory,
|
||||
|
@ -204,6 +246,7 @@ impl OwnedModuleData {
|
|||
imports,
|
||||
exports,
|
||||
signatures,
|
||||
features,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -224,11 +267,20 @@ impl OwnedModuleData {
|
|||
self.imports.iter().map(|imp| imp.to_ref()).collect(),
|
||||
self.exports.iter().map(|exp| exp.to_ref()).collect(),
|
||||
self.signatures.clone(),
|
||||
self.features.clone(),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn empty() -> Self {
|
||||
Self::new(None, vec![], vec![], vec![], vec![], vec![])
|
||||
Self::new(
|
||||
None,
|
||||
vec![],
|
||||
vec![],
|
||||
vec![],
|
||||
vec![],
|
||||
vec![],
|
||||
ModuleFeatures::none(),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn with_heap_spec(mut self, heap_spec: HeapSpec) -> Self {
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"files":{"Cargo.toml":"20c473420bb65fe6f8abb4695359ce4e56a051de9076e960fc831e4445053303","build.rs":"ae539feaad828d15cbe4924e8de5ae38c7d0086200a5c4d494edf8e8e28c074e","src/alloc/mod.rs":"842a9003ab8f89d142e567f62278b8a50ce08be9a1751035d5fdba09286dea75","src/alloc/tests.rs":"d7516622bfa8c96f81b2f6929674eea6b9f368e876ab84bd442de120debda234","src/c_api.rs":"5360954bad8cd332e881e466eb840e50da1984d72c44ccc809a38b7e33633d5a","src/context/context_asm.S":"6b0fe86e5e7f3699482d94819f67ead933aaf91da89f79da0d8a75fa71ba4380","src/context/mod.rs":"98452bfad053d4cd4143afed620233538688cf2bac857b0c4569f42ee8d6d844","src/context/tests/c_child.c":"a9ad91367ac37e7406a587f971858aa7758913f634ea7ae88fccc7f487a3c4fc","src/context/tests/c_child.rs":"33c0472401795d61af2a706cc69d62b69225159a10cfc55e4b0c6e15321f0964","src/context/tests/mod.rs":"5d1bc979aaea2870a8c3a3db66cde21d16d9aab20b898da2c67d6aa1f1f5c292","src/context/tests/rust_child.rs":"ed69940a0b426eef5f9524f06ca215d0952cf4b00d8ebcf8837077849502d075","src/embed_ctx.rs":"57ae60c1a50cf84af23dc529a154db21cbb58c52c8067b9f87069dd600b99473","src/error.rs":"fd09389d5112b04ea76ffed0a7b2a8180c524cded90e33e36399a690c5714e2e","src/hostcall_macros.rs":"b4a2fdd876eee50bec4188f7d9f7c708d71600974cc2b52ff38c7daaa63cb225","src/instance.rs":"04bf1dddd9a980579b3baef77b83f19e8187a085aee6276a0fd4e60af7918e7a","src/instance/siginfo_ext.c":"8ee3a54ef2b93041ca07ecce70ebeb8d421c8ad1257122d9e8ef064d2d45a4a4","src/instance/siginfo_ext.rs":"529b4cc7ce6eea140c17a97477cc862f9d224e40cc24687223a478696d27b971","src/instance/signals.rs":"b890f9f7ca571763c48fa004284aa09b4e80b07ae2f836826aa784fbcace28f1","src/instance/state.rs":"490278c7222fc22248c8f545364a5d522da721c35f5b5e814658dc90e8ed77bd","src/lib.rs":"0c97e40191f17826feccff762898a0f4cafd1ed45cc3e81c07f9f446e263a422","src/module.rs":"29b54cc59cf308d712d9ecf4d595ef10645213e8ea62ec7f3a12adb27089fb47","src/module/dl.rs":"863c487f7494353ca53e0c663dc297e65a4ff5f380cff94c7c760b9509275270","src/module/mock.rs":"12d8eb790de37c3065d7a3029ea5caa4811992dc62054f01737ad7562c7f4c05","src/module/sparse_page_data.rs":"84ef79aa4707e5c84d72a38c5ead18156b16ab29c617540e652e851c744449dc","src/region/mmap.rs":"3ad6dc578f52619300a24db532912fd3ac16ced9de894b9fce8dab4f78b0f04f","src/region/mod.rs":"d2bf8b8c769542299bae9e5ed5d334ca7b431dfd52619ae1487d1494653dfc82","src/sysdeps/linux.rs":"124cc2f0fb0856e23274facdab8ca4631f04cdf8e494d9a4531979efe4ba4ad9","src/sysdeps/macos.rs":"8dc632a9aab98993140a6faefb7c2e313d80e6b9db2e45f54e8d6604cd752a6f","src/sysdeps/mod.rs":"9caed471a08f5f7d39c836a649d0f61d7a84095cee7589cdfc1eafe10eaa866c","src/test_helpers.rs":"72d1aeb9ca9c512aadcecac7ad0869c883c13134fced9f625075dc5e2741c55d","src/val.rs":"503891cd17892349b931d49ed3cdc0c9fc572da47d4c8f8f94fee30f5f4543a6","src/vmctx.rs":"b401df03b483c827d694f5f9024cf54b40987cff025dd8f292137e8396f56e6e"},"package":null}
|
||||
{"files":{"Cargo.toml":"60850f9a0002833508a6c2ecfa7ec8e11c3b5708934a7b74faa93246cd9b75ee","build.rs":"ae539feaad828d15cbe4924e8de5ae38c7d0086200a5c4d494edf8e8e28c074e","src/alloc/mod.rs":"6aac9fa3fd238de17d6270fab6e9677ade40dbbff9d700494f9a78084da1ccd3","src/alloc/tests.rs":"3aada1196dae1b03106e63f6892b9fc019cf9627b99b278765668c56df82bc79","src/c_api.rs":"cb42793d891597ac903636d4726d64a94507a583d44bd350571ce104db4fcc0a","src/context/context_asm.S":"6b0fe86e5e7f3699482d94819f67ead933aaf91da89f79da0d8a75fa71ba4380","src/context/mod.rs":"98452bfad053d4cd4143afed620233538688cf2bac857b0c4569f42ee8d6d844","src/context/tests/c_child.c":"a9ad91367ac37e7406a587f971858aa7758913f634ea7ae88fccc7f487a3c4fc","src/context/tests/c_child.rs":"33c0472401795d61af2a706cc69d62b69225159a10cfc55e4b0c6e15321f0964","src/context/tests/mod.rs":"5d1bc979aaea2870a8c3a3db66cde21d16d9aab20b898da2c67d6aa1f1f5c292","src/context/tests/rust_child.rs":"ed69940a0b426eef5f9524f06ca215d0952cf4b00d8ebcf8837077849502d075","src/embed_ctx.rs":"57ae60c1a50cf84af23dc529a154db21cbb58c52c8067b9f87069dd600b99473","src/error.rs":"fd09389d5112b04ea76ffed0a7b2a8180c524cded90e33e36399a690c5714e2e","src/hostcall_macros.rs":"b4a2fdd876eee50bec4188f7d9f7c708d71600974cc2b52ff38c7daaa63cb225","src/instance.rs":"04bf1dddd9a980579b3baef77b83f19e8187a085aee6276a0fd4e60af7918e7a","src/instance/siginfo_ext.c":"8ee3a54ef2b93041ca07ecce70ebeb8d421c8ad1257122d9e8ef064d2d45a4a4","src/instance/siginfo_ext.rs":"529b4cc7ce6eea140c17a97477cc862f9d224e40cc24687223a478696d27b971","src/instance/signals.rs":"37d7cff815169fdab680d2931f6236d4e912c34621b9c99192b0147450bb6bc1","src/instance/state.rs":"490278c7222fc22248c8f545364a5d522da721c35f5b5e814658dc90e8ed77bd","src/lib.rs":"0c97e40191f17826feccff762898a0f4cafd1ed45cc3e81c07f9f446e263a422","src/module.rs":"29b54cc59cf308d712d9ecf4d595ef10645213e8ea62ec7f3a12adb27089fb47","src/module/dl.rs":"15208d80e918ff59dca78e2168fb7e6799baac28605cc9a318e3cff87bea02fd","src/module/mock.rs":"bf397a32bc1f567a5597f92d017a04f5c480e1b07f21b8843b49b49f6dde111a","src/module/sparse_page_data.rs":"84ef79aa4707e5c84d72a38c5ead18156b16ab29c617540e652e851c744449dc","src/region/mmap.rs":"fd41806035e26320136eb770960d514770eab8a4c933b8f17b4c605d02cf421f","src/region/mod.rs":"d2bf8b8c769542299bae9e5ed5d334ca7b431dfd52619ae1487d1494653dfc82","src/sysdeps/linux.rs":"124cc2f0fb0856e23274facdab8ca4631f04cdf8e494d9a4531979efe4ba4ad9","src/sysdeps/macos.rs":"8dc632a9aab98993140a6faefb7c2e313d80e6b9db2e45f54e8d6604cd752a6f","src/sysdeps/mod.rs":"9caed471a08f5f7d39c836a649d0f61d7a84095cee7589cdfc1eafe10eaa866c","src/test_helpers.rs":"72d1aeb9ca9c512aadcecac7ad0869c883c13134fced9f625075dc5e2741c55d","src/val.rs":"503891cd17892349b931d49ed3cdc0c9fc572da47d4c8f8f94fee30f5f4543a6","src/vmctx.rs":"b401df03b483c827d694f5f9024cf54b40987cff025dd8f292137e8396f56e6e"},"package":null}
|
|
@ -24,6 +24,7 @@ nix = "0.13"
|
|||
num-derive = "0.3"
|
||||
num-traits = "0.2"
|
||||
xfailure = "0.1"
|
||||
raw-cpuid = "7.0.3"
|
||||
|
||||
# This is only a dependency to ensure that other crates don't pick a newer version as a transitive
|
||||
# dependency. `0.1.3 < getrandom <= 0.1.6` cause `lazy_static` to pull in spinlock implementations
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::error::Error;
|
||||
use crate::module::Module;
|
||||
use crate::region::RegionInternal;
|
||||
use libc::{c_void, SIGSTKSZ};
|
||||
use libc::c_void;
|
||||
use lucet_module::GlobalValue;
|
||||
use nix::unistd::{sysconf, SysconfVar};
|
||||
use std::sync::{Arc, Once, Weak};
|
||||
|
@ -113,7 +113,8 @@ impl Drop for Alloc {
|
|||
}
|
||||
|
||||
impl Alloc {
|
||||
pub fn addr_in_heap_guard(&self, addr: *const c_void) -> bool {
|
||||
pub fn addr_in_guard_page(&self, addr: *const c_void) -> bool {
|
||||
let addr = addr as usize;
|
||||
let heap = self.slot().heap as usize;
|
||||
let guard_start = heap + self.heap_accessible_size;
|
||||
let guard_end = heap + self.slot().limits.heap_address_space_size;
|
||||
|
@ -121,7 +122,16 @@ impl Alloc {
|
|||
// "addr = {:p}, guard_start = {:p}, guard_end = {:p}",
|
||||
// addr, guard_start as *mut c_void, guard_end as *mut c_void
|
||||
// );
|
||||
(addr as usize >= guard_start) && ((addr as usize) < guard_end)
|
||||
let stack_guard_end = self.slot().stack as usize;
|
||||
let stack_guard_start = stack_guard_end - host_page_size();
|
||||
// eprintln!(
|
||||
// "addr = {:p}, stack_guard_start = {:p}, stack_guard_end = {:p}",
|
||||
// addr, stack_guard_start as *mut c_void, stack_guard_end as *mut c_void
|
||||
// );
|
||||
let in_heap_guard = (addr >= guard_start) && (addr < guard_end);
|
||||
let in_stack_guard = (addr >= stack_guard_start) && (addr < stack_guard_end);
|
||||
|
||||
in_heap_guard || in_stack_guard
|
||||
}
|
||||
|
||||
pub fn expand_heap(&mut self, expand_bytes: u32, module: &dyn Module) -> Result<u32, Error> {
|
||||
|
@ -308,7 +318,10 @@ impl Alloc {
|
|||
|
||||
/// Return the sigstack as a mutable byte slice.
|
||||
pub unsafe fn sigstack_mut(&mut self) -> &mut [u8] {
|
||||
std::slice::from_raw_parts_mut(self.slot().sigstack as *mut u8, libc::SIGSTKSZ)
|
||||
std::slice::from_raw_parts_mut(
|
||||
self.slot().sigstack as *mut u8,
|
||||
self.slot().limits.signal_stack_size,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn mem_in_heap<T>(&self, ptr: *const T, len: usize) -> bool {
|
||||
|
@ -341,15 +354,30 @@ pub struct Limits {
|
|||
pub stack_size: usize,
|
||||
/// Size of the globals region in bytes; each global uses 8 bytes. (default 4K)
|
||||
pub globals_size: usize,
|
||||
/// Size of the signal stack in bytes. (default SIGSTKSZ for release builds, 12K for debug builds)
|
||||
///
|
||||
/// This difference is to account for the greatly increased stack size usage in the signal
|
||||
/// handler when running without optimizations.
|
||||
///
|
||||
/// Note that debug vs. release mode is determined by `cfg(debug_assertions)`, so if you are
|
||||
/// specifically enabling debug assertions in your release builds, the default signal stack will
|
||||
/// be larger.
|
||||
pub signal_stack_size: usize,
|
||||
}
|
||||
|
||||
impl Default for Limits {
|
||||
fn default() -> Limits {
|
||||
#[cfg(debug_assertions)]
|
||||
pub const DEFAULT_SIGNAL_STACK_SIZE: usize = 12 * 1024;
|
||||
#[cfg(not(debug_assertions))]
|
||||
pub const DEFAULT_SIGNAL_STACK_SIZE: usize = libc::SIGSTKSZ;
|
||||
|
||||
impl Limits {
|
||||
pub const fn default() -> Limits {
|
||||
Limits {
|
||||
heap_memory_size: 16 * 64 * 1024,
|
||||
heap_address_space_size: 0x200000000,
|
||||
stack_size: 128 * 1024,
|
||||
globals_size: 4096,
|
||||
signal_stack_size: DEFAULT_SIGNAL_STACK_SIZE,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -360,19 +388,18 @@ impl Limits {
|
|||
// * the instance (up to instance_heap_offset)
|
||||
// * the heap, followed by guard pages
|
||||
// * the stack (grows towards heap guard pages)
|
||||
// * one guard page (for good luck?)
|
||||
// * globals
|
||||
// * one guard page (to catch signal stack overflow)
|
||||
// * the signal stack (size given by signal.h SIGSTKSZ macro)
|
||||
// * the signal stack
|
||||
|
||||
[
|
||||
instance_heap_offset(),
|
||||
self.heap_address_space_size,
|
||||
self.stack_size,
|
||||
host_page_size(),
|
||||
self.stack_size,
|
||||
self.globals_size,
|
||||
host_page_size(),
|
||||
SIGSTKSZ,
|
||||
self.signal_stack_size,
|
||||
]
|
||||
.iter()
|
||||
.try_fold(0usize, |acc, &x| acc.checked_add(x))
|
||||
|
@ -409,6 +436,11 @@ impl Limits {
|
|||
if self.stack_size <= 0 {
|
||||
return Err(Error::InvalidArgument("stack size must be greater than 0"));
|
||||
}
|
||||
if self.signal_stack_size % host_page_size() != 0 {
|
||||
return Err(Error::InvalidArgument(
|
||||
"signal stack size must be a multiple of host page size",
|
||||
));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ macro_rules! alloc_tests {
|
|||
heap_address_space_size: LIMITS_HEAP_ADDRSPACE_SIZE,
|
||||
stack_size: LIMITS_STACK_SIZE,
|
||||
globals_size: LIMITS_GLOBALS_SIZE,
|
||||
..Limits::default()
|
||||
};
|
||||
|
||||
const SPEC_HEAP_RESERVED_SIZE: u64 = LIMITS_HEAP_ADDRSPACE_SIZE as u64 / 2;
|
||||
|
@ -264,6 +265,7 @@ macro_rules! alloc_tests {
|
|||
heap_address_space_size: LIMITS_HEAP_ADDRSPACE_SIZE,
|
||||
stack_size: LIMITS_STACK_SIZE,
|
||||
globals_size: LIMITS_GLOBALS_SIZE,
|
||||
..Limits::default()
|
||||
};
|
||||
let res = TestRegion::create(10, &LIMITS);
|
||||
assert!(res.is_err(), "region creation fails");
|
||||
|
@ -366,7 +368,7 @@ macro_rules! alloc_tests {
|
|||
}
|
||||
|
||||
let sigstack = unsafe { inst.alloc_mut().sigstack_mut() };
|
||||
assert_eq!(sigstack.len(), libc::SIGSTKSZ);
|
||||
assert_eq!(sigstack.len(), LIMITS.signal_stack_size);
|
||||
|
||||
assert_eq!(sigstack[0], 0);
|
||||
sigstack[0] = 0xFF;
|
||||
|
@ -569,6 +571,7 @@ macro_rules! alloc_tests {
|
|||
heap_address_space_size: 2 * 4096,
|
||||
stack_size: 4096,
|
||||
globals_size: 4096,
|
||||
..Limits::default()
|
||||
};
|
||||
const CONTEXT_TEST_INITIAL_SIZE: u64 = 4096;
|
||||
const CONTEXT_TEST_HEAP: HeapSpec = HeapSpec {
|
||||
|
|
|
@ -140,6 +140,16 @@ pub struct lucet_alloc_limits {
|
|||
pub stack_size: u64,
|
||||
/// Size of the globals region in bytes; each global uses 8 bytes. (default 4K)
|
||||
pub globals_size: u64,
|
||||
/// Size of the signal stack in bytes. (default SIGSTKSZ for Rust release builds, 12K for Rust
|
||||
/// debug builds)
|
||||
///
|
||||
/// This difference is to account for the greatly increased stack size usage in the signal
|
||||
/// handler when running without optimizations.
|
||||
///
|
||||
/// Note that debug vs. release mode is determined by `cfg(debug_assertions)`, so if you are
|
||||
/// specifically enabling Rust debug assertions in your Cargo release builds, the default signal
|
||||
/// stack will be larger.
|
||||
pub signal_stack_size: u64,
|
||||
}
|
||||
|
||||
impl From<Limits> for lucet_alloc_limits {
|
||||
|
@ -155,6 +165,7 @@ impl From<&Limits> for lucet_alloc_limits {
|
|||
heap_address_space_size: limits.heap_address_space_size as u64,
|
||||
stack_size: limits.stack_size as u64,
|
||||
globals_size: limits.globals_size as u64,
|
||||
signal_stack_size: limits.signal_stack_size as u64,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -172,6 +183,7 @@ impl From<&lucet_alloc_limits> for Limits {
|
|||
heap_address_space_size: limits.heap_address_space_size as usize,
|
||||
stack_size: limits.stack_size as usize,
|
||||
globals_size: limits.globals_size as usize,
|
||||
signal_stack_size: limits.signal_stack_size as usize,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ impl Instance {
|
|||
let guest_sigstack = SigStack::new(
|
||||
self.alloc.slot().sigstack,
|
||||
SigStackFlags::empty(),
|
||||
libc::SIGSTKSZ,
|
||||
self.alloc.slot().limits.signal_stack_size,
|
||||
);
|
||||
let previous_sigstack = unsafe { sigaltstack(Some(guest_sigstack)) }
|
||||
.expect("enabling or changing the signal stack succeeds");
|
||||
|
@ -190,7 +190,7 @@ extern "C" fn handle_signal(signum: c_int, siginfo_ptr: *mut siginfo_t, ucontext
|
|||
// If the trap was a segv or bus fault and the addressed memory was outside the
|
||||
// guard pages, it is also a fatal error
|
||||
let outside_guard = (siginfo.si_signo == SIGSEGV || siginfo.si_signo == SIGBUS)
|
||||
&& !inst.alloc.addr_in_heap_guard(siginfo.si_addr_ext());
|
||||
&& !inst.alloc.addr_in_guard_page(siginfo.si_addr_ext());
|
||||
|
||||
// record the fault and jump back to the host context
|
||||
inst.state = State::Faulted {
|
||||
|
|
|
@ -3,8 +3,8 @@ use crate::module::{AddrDetails, GlobalSpec, HeapSpec, Module, ModuleInternal, T
|
|||
use libc::c_void;
|
||||
use libloading::Library;
|
||||
use lucet_module::{
|
||||
FunctionHandle, FunctionIndex, FunctionPointer, FunctionSpec, ModuleData, SerializedModule,
|
||||
Signature, LUCET_MODULE_SYM,
|
||||
FunctionHandle, FunctionIndex, FunctionPointer, FunctionSpec, ModuleData, ModuleFeatures,
|
||||
ModuleSignature, SerializedModule, Signature, LUCET_MODULE_SYM,
|
||||
};
|
||||
#[cfg(feature = "signature_checking")]
|
||||
use lucet_module::{ModuleSignature, PublicKey};
|
||||
|
@ -15,6 +15,65 @@ use std::slice;
|
|||
use std::slice::from_raw_parts;
|
||||
use std::sync::Arc;
|
||||
|
||||
use raw_cpuid::CpuId;
|
||||
|
||||
fn check_feature_support(module_features: &ModuleFeatures) -> Result<(), Error> {
|
||||
let cpuid = CpuId::new();
|
||||
|
||||
fn missing_feature(feature: &str) -> Error {
|
||||
Error::Unsupported(format!(
|
||||
"Module requires feature host does not support: {}",
|
||||
feature
|
||||
))
|
||||
}
|
||||
|
||||
let info = cpuid
|
||||
.get_feature_info()
|
||||
.ok_or_else(|| Error::Unsupported("Unable to obtain host CPU feature info!".to_string()))?;
|
||||
|
||||
if module_features.sse3 && !info.has_sse3() {
|
||||
return Err(missing_feature("SSE3"));
|
||||
}
|
||||
if module_features.ssse3 && !info.has_ssse3() {
|
||||
return Err(missing_feature("SSS3"));
|
||||
}
|
||||
if module_features.sse41 && !info.has_sse41() {
|
||||
return Err(missing_feature("SSE4.1"));
|
||||
}
|
||||
if module_features.sse42 && !info.has_sse42() {
|
||||
return Err(missing_feature("SSE4.2"));
|
||||
}
|
||||
if module_features.avx && !info.has_avx() {
|
||||
return Err(missing_feature("AVX"));
|
||||
}
|
||||
if module_features.popcnt && !info.has_popcnt() {
|
||||
return Err(missing_feature("POPCNT"));
|
||||
}
|
||||
|
||||
let info = cpuid.get_extended_feature_info().ok_or_else(|| {
|
||||
Error::Unsupported("Unable to obtain host CPU extended feature info!".to_string())
|
||||
})?;
|
||||
|
||||
if module_features.bmi1 && !info.has_bmi1() {
|
||||
return Err(missing_feature("BMI1"));
|
||||
}
|
||||
|
||||
if module_features.bmi2 && !info.has_bmi2() {
|
||||
return Err(missing_feature("BMI2"));
|
||||
}
|
||||
|
||||
let info = cpuid.get_extended_function_info().ok_or_else(|| {
|
||||
Error::Unsupported("Unable to obtain host CPU extended function info!".to_string())
|
||||
})?;
|
||||
|
||||
if module_features.lzcnt && !info.has_lzcnt() {
|
||||
return Err(missing_feature("LZCNT"));
|
||||
}
|
||||
|
||||
// Features are fine, we're compatible!
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// A Lucet module backed by a dynamically-loaded shared object.
|
||||
pub struct DlModule {
|
||||
lib: Library,
|
||||
|
@ -83,6 +142,9 @@ impl DlModule {
|
|||
)
|
||||
};
|
||||
let module_data = ModuleData::deserialize(module_data_slice)?;
|
||||
|
||||
check_feature_support(module_data.features())?;
|
||||
|
||||
verifier(&module_data)?;
|
||||
|
||||
let fbase = if let Some(dli) =
|
||||
|
|
|
@ -6,8 +6,8 @@ use lucet_module::owned::{
|
|||
OwnedLinearMemorySpec, OwnedModuleData, OwnedSparseData,
|
||||
};
|
||||
use lucet_module::{
|
||||
FunctionHandle, FunctionIndex, FunctionPointer, FunctionSpec, ModuleData, Signature, TrapSite,
|
||||
UniqueSignatureIndex,
|
||||
FunctionHandle, FunctionIndex, FunctionPointer, FunctionSpec, ModuleData, ModuleFeatures,
|
||||
Signature, TrapSite, UniqueSignatureIndex,
|
||||
};
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
use std::sync::Arc;
|
||||
|
@ -221,6 +221,7 @@ impl MockModuleBuilder {
|
|||
self.imports,
|
||||
self.exports,
|
||||
self.signatures,
|
||||
ModuleFeatures::none(),
|
||||
);
|
||||
let serialized_module_data = owned_module_data
|
||||
.to_ref()
|
||||
|
|
|
@ -4,9 +4,9 @@ use crate::error::Error;
|
|||
use crate::instance::{new_instance_handle, Instance, InstanceHandle};
|
||||
use crate::module::Module;
|
||||
use crate::region::{Region, RegionCreate, RegionInternal};
|
||||
use libc::c_void;
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
use libc::memset;
|
||||
use libc::{c_void, SIGSTKSZ};
|
||||
use nix::sys::mman::{madvise, mmap, munmap, MapFlags, MmapAdvise, ProtFlags};
|
||||
use std::ptr;
|
||||
use std::sync::{Arc, Mutex, Weak};
|
||||
|
@ -39,17 +39,17 @@ use std::sync::{Arc, Mutex, Weak};
|
|||
/// 0xXXXX: ~ .......heap....... ~ // heap size is governed by limits.heap_address_space_size
|
||||
/// 0xXXXX: | |
|
||||
/// 0xN000: +-----------------------| <-- Stack (at heap_start + limits.heap_address_space_size)
|
||||
/// 0xNXXX: --- stack guard page ----
|
||||
/// 0xNXXX: | |
|
||||
/// 0xXXXX: ~ .......stack...... ~ // stack size is governed by limits.stack_size
|
||||
/// 0xXXXX: | |
|
||||
/// 0xXXXx: --- stack guard page ----
|
||||
/// 0xM000: +-----------------------| <-- Globals (at stack_start + limits.stack_size + PAGE_SIZE)
|
||||
/// 0xMXXX: | |
|
||||
/// 0xXXXX: ~ ......globals..... ~
|
||||
/// 0xXXXX: | |
|
||||
/// 0xXXXX --- global guard page ---
|
||||
/// 0xS000: +-----------------------| <-- Sigstack (at globals_start + globals_size + PAGE_SIZE)
|
||||
/// 0xSXXX: | ......sigstack.... | // sigstack is SIGSTKSZ bytes
|
||||
/// 0xSXXX: | ......sigstack.... | // sigstack is governed by limits.signal_stack_size
|
||||
/// 0xSXXX: +-----------------------|
|
||||
/// ```
|
||||
pub struct MmapRegion {
|
||||
|
@ -87,7 +87,7 @@ impl RegionInternal for MmapRegion {
|
|||
// make the globals read/writable
|
||||
(slot.globals, limits.globals_size),
|
||||
// make the sigstack read/writable
|
||||
(slot.sigstack, SIGSTKSZ),
|
||||
(slot.sigstack, limits.signal_stack_size),
|
||||
]
|
||||
.into_iter()
|
||||
{
|
||||
|
@ -136,7 +136,7 @@ impl RegionInternal for MmapRegion {
|
|||
(slot.heap, alloc.heap_accessible_size),
|
||||
(slot.stack, slot.limits.stack_size),
|
||||
(slot.globals, slot.limits.globals_size),
|
||||
(slot.sigstack, SIGSTKSZ),
|
||||
(slot.sigstack, slot.limits.signal_stack_size),
|
||||
]
|
||||
.into_iter()
|
||||
{
|
||||
|
@ -272,10 +272,6 @@ impl MmapRegion {
|
|||
/// The region is returned in an `Arc`, because any instances created from it carry a reference
|
||||
/// back to the region.
|
||||
pub fn create(instance_capacity: usize, limits: &Limits) -> Result<Arc<Self>, Error> {
|
||||
assert!(
|
||||
SIGSTKSZ % host_page_size() == 0,
|
||||
"signal stack size is a multiple of host page size"
|
||||
);
|
||||
limits.validate()?;
|
||||
|
||||
let region = Arc::new(MmapRegion {
|
||||
|
@ -305,10 +301,6 @@ impl MmapRegion {
|
|||
limits: &Limits,
|
||||
heap_alignment: usize,
|
||||
) -> Result<Arc<Self>, Error> {
|
||||
assert!(
|
||||
SIGSTKSZ % host_page_size() == 0,
|
||||
"signal stack size is a multiple of host page size"
|
||||
);
|
||||
limits.validate()?;
|
||||
|
||||
let is_power_of_2 = (heap_alignment & (heap_alignment - 1)) == 0;
|
||||
|
@ -372,9 +364,9 @@ impl MmapRegion {
|
|||
|
||||
// lay out the other sections in memory
|
||||
let heap = mem as usize + instance_heap_offset();
|
||||
let stack = heap + region.limits.heap_address_space_size;
|
||||
let globals = stack + region.limits.stack_size + host_page_size();
|
||||
let sigstack = globals + host_page_size();
|
||||
let stack = heap + region.limits.heap_address_space_size + host_page_size();
|
||||
let globals = stack + region.limits.stack_size;
|
||||
let sigstack = globals + region.limits.globals_size + host_page_size();
|
||||
|
||||
Ok(Slot {
|
||||
start: mem,
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"files":{"Cargo.toml":"32943e73c9f49c3ce3512b312128bed7200631c33297f45a254db416a5a3d4bd","LICENSE":"268872b9816f90fd8e85db5a28d33f8150ebb8dd016653fb39ef1f94f2686bc5","build.rs":"d56fd4e2fe9d0830aee061be443ef0b541ed98dd6a4233220a51745478b3fb77","include/lucet.h":"89ff353483287040e07e3f6eaeed4286cb06f541fb67057f9fdbbf844a7ec928","include/lucet_types.h":"9581effd486709f178f5e45b68eea015b9c5f94f4488bf8e745edd65ea02086d","include/lucet_val.h":"220b862b0280ac4f7962d44520f6cc34a47f3b3a34b8ecf389e6111cd95b8bf0","include/lucet_vmctx.h":"044ca80cf8cca51620de3f113a1c07c00ebecea108a45288f9b87e5e2fbb820c","src/c_api.rs":"97e28537fffeac5d21f09911a3474114997ce0268492edb8010ce8ca178a6c64","src/lib.rs":"48f0ba473b4da3616bddfce3cda00cf836eca3c9e7b055855156c1c167a6f908","tests/c_api.c":"82618645e60d714dd07338f9240eeea54a459e2c6bb6f7e35ee75d6aadd900ae","tests/entrypoint.rs":"1d0080e9f71a16f61e69c21922ac1c2207b2003fb13d3bacafb681be5cceb8b9","tests/globals.rs":"56248c5cefbaad546b08964d9193e5c16a461e974d1c9c520ebba3f1cf32af66","tests/guest_fault.rs":"cb4728d0851148f992c944199f4fc98595070d0879e1ddf5361419e4fc330ad3","tests/guests/null.c":"de2bf0dc98ac1acaef8cb856a300119aa1300d228a1dceb0b7e06b63d3ac712a","tests/guests/yield_resume.c":"b9c19d9c2d540e042d3488f2cea04a7a98cc75910c68faad738ad835b04dde9d","tests/guests/yield_resume_bindings.json":"e124e940038a552d08495d6f99b7dd8495a011e4a082b32ab8d035e40169d663","tests/host.rs":"0cd5f40ed9725c7ef2f497a4e31f09e88833841240dfbfe971d60724075eac00","tests/instruction_counting.rs":"6aa8c2cf4c32adbbb5bf74e8449dd29d4deff77dcb55947a2d15c4eccbb89d6e","tests/instruction_counting/arithmetic_count.wat":"c347c7a78e4159e45aa5ba299f1d03e1efbb7c635f13dd23053907de7f57193b","tests/instruction_counting/br_table_count.wat":"66cdac7595bd69103f5d1b825a58f09a5624db4e35c91e11ae7b30cc2f53eb0c","tests/instruction_counting/calls.wat":"8212736a55a897937c712bab33c22c62ab96f1b32eef44eab1cbee77f34ba641","tests/instruction_counting/count_after_br.wat":"12df2019f3b0c518bd747e485b423f73a82c91571e834bdeed5d7bd6455f84c0","tests/instruction_counting/empty_loop.wat":"3dfa9ab297a7f8fd21bd22db8ded37de0545ac741be132fdcdf1a61c50cf455a","tests/instruction_counting/empty_loop_2.wat":"c65b4516a1a26f9b8b0117bb1f4fe9282e3bc79052b89f834cad6c202a51f68e","tests/instruction_counting/if_count.wat":"620330be046a3b3890646e8fdbbde6d4a8c4763b450d818ee549e103a1c3e3aa","tests/instruction_counting/if_not_taken_count.wat":"12bdc1f0512016e549bd7656386274c7b7b92d32b5d3eeb73b93d6ef18cc4ff2","tests/instruction_counting/indirect_calls.wat":"f56f6a715a733176168a81ca6cbfd22333ab9755029174a3f7950da9b401320e","tests/instruction_counting/loops.wat":"0cd765b1cf694a2c35df69547b30303731512c937cad05e1c052ebcd7840e3b1","tests/instruction_counting/unreachable_call.wat":"c15653c3ff198f321f8b892c363ec7badad75ec703c5b3a215a6dbfb059a15b7","tests/memory.rs":"73b65dc44978181a5d2a3b39a6d0fc60fd6637e16387c2a7b025baedb16a004f","tests/stack.rs":"5e5939991a55c8ecd579d8c509226ed3ac7bae5a847bdcdac4d285df28d54d6b","tests/start.rs":"7b31f8c289c1ad52d05f17c0c46b0856382b0ff85d6e5579c4346c443eb93fb3","tests/strcmp.rs":"7420aa723630af51360a9e9a3763c2fd8d7c57aa8d4011cfd8ca452376036efb","tests/val.rs":"2e38a7aa10bde34d5cf580a958c07eff8593662a86678427a79d8a5f5bc2efac"},"package":null}
|
||||
{"files":{"Cargo.toml":"d5bb2276a7550ff7863e938a82168d721f2eabb917599e953e556f645fe1b6e1","LICENSE":"268872b9816f90fd8e85db5a28d33f8150ebb8dd016653fb39ef1f94f2686bc5","build.rs":"d56fd4e2fe9d0830aee061be443ef0b541ed98dd6a4233220a51745478b3fb77","include/lucet.h":"89ff353483287040e07e3f6eaeed4286cb06f541fb67057f9fdbbf844a7ec928","include/lucet_types.h":"95c7793034c71e123fac04ce61dc89f4930360b6d4af0f40582c84357fd6877d","include/lucet_val.h":"220b862b0280ac4f7962d44520f6cc34a47f3b3a34b8ecf389e6111cd95b8bf0","include/lucet_vmctx.h":"044ca80cf8cca51620de3f113a1c07c00ebecea108a45288f9b87e5e2fbb820c","src/c_api.rs":"97e28537fffeac5d21f09911a3474114997ce0268492edb8010ce8ca178a6c64","src/lib.rs":"48f0ba473b4da3616bddfce3cda00cf836eca3c9e7b055855156c1c167a6f908","tests/c_api.c":"772716a14ceed6913a3670d8ca3fcf0cb0c376493cabae4c8b527fb694554b7b","tests/entrypoint.rs":"1d0080e9f71a16f61e69c21922ac1c2207b2003fb13d3bacafb681be5cceb8b9","tests/globals.rs":"56248c5cefbaad546b08964d9193e5c16a461e974d1c9c520ebba3f1cf32af66","tests/guest_fault.rs":"cb4728d0851148f992c944199f4fc98595070d0879e1ddf5361419e4fc330ad3","tests/guests/null.c":"de2bf0dc98ac1acaef8cb856a300119aa1300d228a1dceb0b7e06b63d3ac712a","tests/guests/yield_resume.c":"b9c19d9c2d540e042d3488f2cea04a7a98cc75910c68faad738ad835b04dde9d","tests/guests/yield_resume_bindings.json":"e124e940038a552d08495d6f99b7dd8495a011e4a082b32ab8d035e40169d663","tests/host.rs":"0cd5f40ed9725c7ef2f497a4e31f09e88833841240dfbfe971d60724075eac00","tests/instruction_counting.rs":"6aa8c2cf4c32adbbb5bf74e8449dd29d4deff77dcb55947a2d15c4eccbb89d6e","tests/instruction_counting/arithmetic_count.wat":"c347c7a78e4159e45aa5ba299f1d03e1efbb7c635f13dd23053907de7f57193b","tests/instruction_counting/br_table_count.wat":"66cdac7595bd69103f5d1b825a58f09a5624db4e35c91e11ae7b30cc2f53eb0c","tests/instruction_counting/calls.wat":"8212736a55a897937c712bab33c22c62ab96f1b32eef44eab1cbee77f34ba641","tests/instruction_counting/count_after_br.wat":"12df2019f3b0c518bd747e485b423f73a82c91571e834bdeed5d7bd6455f84c0","tests/instruction_counting/empty_loop.wat":"3dfa9ab297a7f8fd21bd22db8ded37de0545ac741be132fdcdf1a61c50cf455a","tests/instruction_counting/empty_loop_2.wat":"c65b4516a1a26f9b8b0117bb1f4fe9282e3bc79052b89f834cad6c202a51f68e","tests/instruction_counting/if_count.wat":"620330be046a3b3890646e8fdbbde6d4a8c4763b450d818ee549e103a1c3e3aa","tests/instruction_counting/if_not_taken_count.wat":"12bdc1f0512016e549bd7656386274c7b7b92d32b5d3eeb73b93d6ef18cc4ff2","tests/instruction_counting/indirect_calls.wat":"f56f6a715a733176168a81ca6cbfd22333ab9755029174a3f7950da9b401320e","tests/instruction_counting/loops.wat":"0cd765b1cf694a2c35df69547b30303731512c937cad05e1c052ebcd7840e3b1","tests/instruction_counting/unreachable_call.wat":"c15653c3ff198f321f8b892c363ec7badad75ec703c5b3a215a6dbfb059a15b7","tests/memory.rs":"73b65dc44978181a5d2a3b39a6d0fc60fd6637e16387c2a7b025baedb16a004f","tests/stack.rs":"5e5939991a55c8ecd579d8c509226ed3ac7bae5a847bdcdac4d285df28d54d6b","tests/start.rs":"7b31f8c289c1ad52d05f17c0c46b0856382b0ff85d6e5579c4346c443eb93fb3","tests/strcmp.rs":"7420aa723630af51360a9e9a3763c2fd8d7c57aa8d4011cfd8ca452376036efb","tests/val.rs":"2e38a7aa10bde34d5cf580a958c07eff8593662a86678427a79d8a5f5bc2efac"},"package":null}
|
|
@ -36,7 +36,7 @@ signature_checking = ["lucet-module/signature_checking"]
|
|||
|
||||
[lib]
|
||||
name = "lucet_runtime"
|
||||
crate-type = ["rlib", "staticlib", "cdylib"]
|
||||
crate-type = ["rlib", "staticlib"]
|
||||
|
||||
[package.metadata.deb]
|
||||
name = "fst-lucet-runtime"
|
||||
|
|
|
@ -122,6 +122,13 @@ struct lucet_alloc_limits {
|
|||
* Size of the globals region in bytes; each global uses 8 bytes. (default 4K)
|
||||
*/
|
||||
uint64_t globals_size;
|
||||
/**
|
||||
* Size of the signal stack region in bytes.
|
||||
*
|
||||
* SIGSTKSZ from <signals.h> is a good default when linking against a Rust release build of
|
||||
* lucet-runtime, but 12K or more is recommended when using a Rust debug build.
|
||||
*/
|
||||
uint64_t signal_stack_size;
|
||||
};
|
||||
|
||||
typedef enum lucet_signal_behavior (*lucet_signal_handler)(struct lucet_instance * inst,
|
||||
|
|
|
@ -11,6 +11,7 @@ bool lucet_runtime_test_expand_heap(struct lucet_dl_module *mod)
|
|||
.heap_address_space_size = 8 * 1024 * 1024,
|
||||
.stack_size = 64 * 1024,
|
||||
.globals_size = 4096,
|
||||
.signal_stack_size = 12 * 1024,
|
||||
};
|
||||
|
||||
enum lucet_error err;
|
||||
|
@ -97,6 +98,7 @@ bool lucet_runtime_test_yield_resume(struct lucet_dl_module *mod)
|
|||
.heap_address_space_size = 8 * 1024 * 1024,
|
||||
.stack_size = 64 * 1024,
|
||||
.globals_size = 4096,
|
||||
.signal_stack_size = 12 * 1024,
|
||||
};
|
||||
|
||||
enum lucet_error err;
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"files":{"Cargo.toml":"8874fee1c359b1a1e18014cd0237bb1c54db182216ec4d41ca1bd360eff2573f","LICENSE":"268872b9816f90fd8e85db5a28d33f8150ebb8dd016653fb39ef1f94f2686bc5","LICENSE.cloudabi-utils":"86a34251f0aab76b7dc3daf8d252afbdf481ea94aa5b46d020205178b7e2eac1","LICENSE.wasmtime":"a6c48161a09acc75a0e25503bab66a731eb5fba5392ed4bb4743e4ba5085327a","bindings.json":"fad8362f845e6f7a2af1d7547cee5730894e7b96804f338181fc070ffdcfae1e","build.rs":"593173ad03963afcbef43f1843be6f04cde1df3eae0298ca20bf881019dd350a","examples/.gitignore":"44575cf5b28512d75644bf54a517dcef304ff809fd511747621b4d64f19aac66","examples/Makefile":"d2d2ceeb1bc4435189ea9a2710b6f5f5331ce6aa73ae8a4f4edcca215058a9b4","examples/README.md":"f2a5be6cc88d511c9f4d3bfefdd42dcb2ace813bc23f6a4430b6b543f7373341","examples/hello.c":"9cbc0d3173e02309e15372835fa849d196b2a202d81806fea60378e1878d0c53","examples/pseudoquine.c":"8fd696f8e1b8fb86188564a05f4776875ead31d785a12e3aa4af9d9c1b46d5b5","include/lucet_wasi.h":"497f712c64f753ebdf73ab05b0b340d50094f9c59bb8637ccbf99d895cd20966","src/bindings.rs":"edbeb51d1a93fd31039ee1f1dc7c1b6c0bded2cf5dad10039e8b7da81a4d4a12","src/c_api.rs":"a9c73070a88a461882a28e3e2adfd773f569b964c7ffabde39a3cef907782f71","src/ctx.rs":"578f87c35cce12eaebec95d03e31954c3e6cd0afa214a0fec068f03814eb0cc7","src/fdentry.rs":"94a8480fa587e5586327dfd6b66d8a6a3ef1f8091ba8deb335bf45642f4f98e6","src/host.rs":"6f05f8fea2afed827abfc3c008a5854a8023d91d066580ecfb49e5c8036ef3a3","src/hostcalls/fs.rs":"18102b651f443e37197b2d808450c85535d3b39ff98d52844b4f5fd95e8018e6","src/hostcalls/fs_helpers.rs":"474bce0a1f15fa23b0b0b8aa83143d993dd2cbd7cdfc38c118d452d04e80caea","src/hostcalls/misc.rs":"2cb55f010d661f4e42dffc82d49d0970996de9437b8fd6f8e3b298dd898cd2f9","src/hostcalls/mod.rs":"7ffeb1c08825487d90dd516def21ddc303949d631792ac17a8f57d902993ffd1","src/lib.rs":"5554e1a3f0cd3756173ece6435a0d01b2f520b3401cd5fc33180a04fb9f69bbe","src/memory.rs":"0a09026b15d27f99d74e560cd94795f645cba414a8491bc961987fab9d9da69b","src/wasi_host.rs":"cacbdac28304a837b11e5ad400ae9de3ee79c0284be335e64606ecdfe426ad6e","src/wasm32.rs":"13a5dc6e59784662f1e55eccb457cbbae241a96f70cfa72c41d55858ca05b980","tests/guests/cant_dotdot.c":"609b8cece9443e375a0b38a7e43651b179f66ee9c686edba6696fe1bcd45b111","tests/guests/clock_getres.c":"f5e41c0a2b05a8d7cdb5b4da6c8b6778b858004c1e9d115503c45a1d976be33b","tests/guests/duplicate_import.wat":"4bd8d7a5c1d1597dbe7648300e94e3fab84d7ab068d56cfb656aa1a208026cee","tests/guests/exitcode.c":"b7c5cec3ead0ed82326c568287a1f3398e71ae7e447ce49a3c4c7114c82495af","tests/guests/follow_symlink.c":"de3143ad2bbbfe834c0c32b54c9fcf144ca4eba5cdcf7588929e5f47225ab616","tests/guests/fs.c":"0dca5232ff5da1b7745e3b44bca39333c01a20ba4eae1a6a0a1c492c71ca1efa","tests/guests/getentropy.c":"5d80bcc68dcf3ba91576969055099d61635ae713c057b3cb36afb122a5f26347","tests/guests/getrusage.c":"8114c103b85eb564d9ab43684958bc1939de3794d314b7c121762f3a2f0434a6","tests/guests/gettimeofday.c":"4a57f376b06f4228017b82695448a0bd213fb91455f5301d689cd87fcff01f06","tests/guests/notdir.c":"bd8f8b24360b7cf8d5dced9d9ba4c15843fcbbae89fecc13e3a457c33a275e28","tests/guests/poll.c":"aefaa9b58ce9906dc379e0bd25fa68dfbf8cdffb48cd5ecde1d67708b83b366d","tests/guests/preopen_populates.c":"f186e4eb4aab6a1d9ec7bc5c49eaea6d9d162e0159dfe8f953bb48ade9b58d43","tests/guests/read_file.c":"1aab9393f005f05b69592826d7c4d384a115d5bca42c66f10a901811b4b1dcac","tests/guests/read_file_twice.c":"04a3dad7a43b93e36efd4e2c822c11b3f129429ec799af304d82b358686c578a","tests/guests/stat.c":"02756933ea7d4337b4fa04344b32968851b02f9d0bd5ea1cb0e2f022e8c65ab0","tests/guests/stdin.c":"66efc4b54f68d1138046f1afefae15f7d4555b2904b4a988818e61e67fe8fefb","tests/guests/symlink_escape.c":"686e047b5c986e29c854bcd93996d027dcdc8721219fa9fa532efc98d2798f5c","tests/guests/symlink_loop.c":"2bbddf3a5edfc6e5f3c0fa82cee4ac92b18804810509e263abd17f5240cd37e5","tests/guests/write_file.c":"9e9b14552c2445cfa6d0aa26b334081a59e6e3428dbb17ceca005a9ba59d3220","tests/test_helpers/mod.rs":"bc18194317611fe1be5c439a7a9e0de75399555c3b6de4275af149fb180456c8","tests/tests.rs":"173a7e0f086f6ed46474686cc3413ee68bbd2ff67004f7790e963a1392c7c46e"},"package":null}
|
||||
{"files":{"Cargo.toml":"fea1408a1c1b1e84b06044a0b12cb26c8fd3253ca124debb6cd3e4faab48fcbd","LICENSE":"268872b9816f90fd8e85db5a28d33f8150ebb8dd016653fb39ef1f94f2686bc5","LICENSE.cloudabi-utils":"86a34251f0aab76b7dc3daf8d252afbdf481ea94aa5b46d020205178b7e2eac1","LICENSE.wasmtime":"a6c48161a09acc75a0e25503bab66a731eb5fba5392ed4bb4743e4ba5085327a","bindings.json":"fad8362f845e6f7a2af1d7547cee5730894e7b96804f338181fc070ffdcfae1e","build.rs":"593173ad03963afcbef43f1843be6f04cde1df3eae0298ca20bf881019dd350a","examples/.gitignore":"44575cf5b28512d75644bf54a517dcef304ff809fd511747621b4d64f19aac66","examples/Makefile":"d2d2ceeb1bc4435189ea9a2710b6f5f5331ce6aa73ae8a4f4edcca215058a9b4","examples/README.md":"f2a5be6cc88d511c9f4d3bfefdd42dcb2ace813bc23f6a4430b6b543f7373341","examples/hello.c":"9cbc0d3173e02309e15372835fa849d196b2a202d81806fea60378e1878d0c53","examples/pseudoquine.c":"8fd696f8e1b8fb86188564a05f4776875ead31d785a12e3aa4af9d9c1b46d5b5","include/lucet_wasi.h":"497f712c64f753ebdf73ab05b0b340d50094f9c59bb8637ccbf99d895cd20966","src/bindings.rs":"edbeb51d1a93fd31039ee1f1dc7c1b6c0bded2cf5dad10039e8b7da81a4d4a12","src/c_api.rs":"a9c73070a88a461882a28e3e2adfd773f569b964c7ffabde39a3cef907782f71","src/ctx.rs":"578f87c35cce12eaebec95d03e31954c3e6cd0afa214a0fec068f03814eb0cc7","src/fdentry.rs":"94a8480fa587e5586327dfd6b66d8a6a3ef1f8091ba8deb335bf45642f4f98e6","src/host.rs":"6f05f8fea2afed827abfc3c008a5854a8023d91d066580ecfb49e5c8036ef3a3","src/hostcalls/fs.rs":"4726e6f695f7d1d4e371ec52c57f4e36b0ba0d2302fc008b21a301f5fd7a5c97","src/hostcalls/fs_helpers.rs":"474bce0a1f15fa23b0b0b8aa83143d993dd2cbd7cdfc38c118d452d04e80caea","src/hostcalls/misc.rs":"83d087891d92af08cfa2d2e0c5f41cc47cb8219460f6dbcc8666b418dfef206e","src/hostcalls/mod.rs":"4c5d3f65c69503e11e647770879026c37c0e5e01a99b7116c8fb9411b4797187","src/hostcalls/timers.rs":"e65d6a491256b5d6051b6816f6c5049ba3cdc6142651bac81f34d659c1c2a104","src/lib.rs":"5554e1a3f0cd3756173ece6435a0d01b2f520b3401cd5fc33180a04fb9f69bbe","src/memory.rs":"0a09026b15d27f99d74e560cd94795f645cba414a8491bc961987fab9d9da69b","src/wasi_host.rs":"cacbdac28304a837b11e5ad400ae9de3ee79c0284be335e64606ecdfe426ad6e","src/wasm32.rs":"13a5dc6e59784662f1e55eccb457cbbae241a96f70cfa72c41d55858ca05b980","tests/guests/cant_dotdot.c":"609b8cece9443e375a0b38a7e43651b179f66ee9c686edba6696fe1bcd45b111","tests/guests/clock_getres.c":"f5e41c0a2b05a8d7cdb5b4da6c8b6778b858004c1e9d115503c45a1d976be33b","tests/guests/duplicate_import.wat":"4bd8d7a5c1d1597dbe7648300e94e3fab84d7ab068d56cfb656aa1a208026cee","tests/guests/exitcode.c":"b7c5cec3ead0ed82326c568287a1f3398e71ae7e447ce49a3c4c7114c82495af","tests/guests/follow_symlink.c":"de3143ad2bbbfe834c0c32b54c9fcf144ca4eba5cdcf7588929e5f47225ab616","tests/guests/fs.c":"0dca5232ff5da1b7745e3b44bca39333c01a20ba4eae1a6a0a1c492c71ca1efa","tests/guests/getentropy.c":"5d80bcc68dcf3ba91576969055099d61635ae713c057b3cb36afb122a5f26347","tests/guests/getrusage.c":"8114c103b85eb564d9ab43684958bc1939de3794d314b7c121762f3a2f0434a6","tests/guests/gettimeofday.c":"4a57f376b06f4228017b82695448a0bd213fb91455f5301d689cd87fcff01f06","tests/guests/notdir.c":"bd8f8b24360b7cf8d5dced9d9ba4c15843fcbbae89fecc13e3a457c33a275e28","tests/guests/poll.c":"aefaa9b58ce9906dc379e0bd25fa68dfbf8cdffb48cd5ecde1d67708b83b366d","tests/guests/preopen_populates.c":"f186e4eb4aab6a1d9ec7bc5c49eaea6d9d162e0159dfe8f953bb48ade9b58d43","tests/guests/read_file.c":"1aab9393f005f05b69592826d7c4d384a115d5bca42c66f10a901811b4b1dcac","tests/guests/read_file_twice.c":"04a3dad7a43b93e36efd4e2c822c11b3f129429ec799af304d82b358686c578a","tests/guests/stat.c":"02756933ea7d4337b4fa04344b32968851b02f9d0bd5ea1cb0e2f022e8c65ab0","tests/guests/stdin.c":"66efc4b54f68d1138046f1afefae15f7d4555b2904b4a988818e61e67fe8fefb","tests/guests/symlink_escape.c":"686e047b5c986e29c854bcd93996d027dcdc8721219fa9fa532efc98d2798f5c","tests/guests/symlink_loop.c":"2bbddf3a5edfc6e5f3c0fa82cee4ac92b18804810509e263abd17f5240cd37e5","tests/guests/write_file.c":"9e9b14552c2445cfa6d0aa26b334081a59e6e3428dbb17ceca005a9ba59d3220","tests/test_helpers/mod.rs":"bc18194317611fe1be5c439a7a9e0de75399555c3b6de4275af149fb180456c8","tests/tests.rs":"173a7e0f086f6ed46474686cc3413ee68bbd2ff67004f7790e963a1392c7c46e"},"package":null}
|
|
@ -33,6 +33,9 @@ lucet-module = { path = "../lucet-module", version = "0.1.1" }
|
|||
nix = "0.13"
|
||||
rand = "0.7"
|
||||
|
||||
[target.'cfg(target_os = "macos")'.dependencies]
|
||||
mach = "0.3.2"
|
||||
|
||||
[dev-dependencies]
|
||||
lucet-wasi-sdk = { path = "../lucet-wasi-sdk", version = "0.1.1" }
|
||||
lucetc = { path = "../lucetc", version = "0.1.1" }
|
||||
|
@ -44,7 +47,7 @@ optional = true
|
|||
|
||||
[lib]
|
||||
name = "lucet_wasi"
|
||||
crate-type = ["rlib", "staticlib", "cdylib"]
|
||||
crate-type = ["rlib", "staticlib"]
|
||||
|
||||
[package.metadata.deb]
|
||||
name = "fst-lucet-wasi"
|
||||
|
|
|
@ -7,6 +7,7 @@ use crate::memory::*;
|
|||
use crate::{host, wasm32};
|
||||
|
||||
use super::fs_helpers::*;
|
||||
use super::timers;
|
||||
use lucet_runtime::vmctx::Vmctx;
|
||||
|
||||
use nix::libc::{self, c_long, c_void, off_t};
|
||||
|
@ -821,7 +822,7 @@ pub fn wasi_fd_filestat_set_times(
|
|||
if fst_flags & (host::__WASI_FILESTAT_SET_MTIM_NOW as host::__wasi_fstflags_t) != 0 {
|
||||
let clock_id = libc::CLOCK_REALTIME;
|
||||
let mut timespec = MaybeUninit::<libc::timespec>::uninit();
|
||||
let res = unsafe { libc::clock_gettime(clock_id, timespec.as_mut_ptr()) };
|
||||
let res = unsafe { timers::clock_gettime_helper(clock_id, timespec.as_mut_ptr()) };
|
||||
if res != 0 {
|
||||
return wasm32::errno_from_nix(nix::errno::Errno::last());
|
||||
}
|
||||
|
@ -850,7 +851,7 @@ pub fn wasi_fd_filestat_set_times(
|
|||
};
|
||||
let ts_mtime = *TimeSpec::nanoseconds(st_mtim as i64).as_ref();
|
||||
let times = [ts_atime, ts_mtime];
|
||||
let res = unsafe { libc::futimens(fe.fd_object.rawfd, times.as_ptr()) };
|
||||
let res = unsafe { timers::futimens_helper(fe.fd_object.rawfd, times.as_ptr()) };
|
||||
if res != 0 {
|
||||
return wasm32::errno_from_nix(nix::errno::Errno::last());
|
||||
}
|
||||
|
@ -890,7 +891,7 @@ pub fn wasi_path_filestat_set_times(
|
|||
if fst_flags & (host::__WASI_FILESTAT_SET_MTIM_NOW as host::__wasi_fstflags_t) != 0 {
|
||||
let clock_id = libc::CLOCK_REALTIME;
|
||||
let mut timespec = MaybeUninit::<libc::timespec>::uninit();
|
||||
let res = unsafe { libc::clock_gettime(clock_id, timespec.as_mut_ptr()) };
|
||||
let res = unsafe { timers::clock_gettime_helper(clock_id, timespec.as_mut_ptr()) };
|
||||
if res != 0 {
|
||||
return wasm32::errno_from_nix(nix::errno::Errno::last());
|
||||
}
|
||||
|
@ -923,7 +924,7 @@ pub fn wasi_path_filestat_set_times(
|
|||
Ok(path_cstr) => path_cstr,
|
||||
Err(_) => return wasm32::__WASI_EINVAL,
|
||||
};
|
||||
let res = unsafe { libc::utimensat(dir, path_cstr.as_ptr(), times.as_ptr(), atflags) };
|
||||
let res = unsafe { timers::utimensat_helper(dir, path_cstr.as_ptr(), times.as_ptr(), atflags) };
|
||||
if res != 0 {
|
||||
return wasm32::errno_from_nix(nix::errno::Errno::last());
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@ use crate::ctx::WasiCtx;
|
|||
use crate::memory::*;
|
||||
use crate::{host, wasm32};
|
||||
|
||||
use super::timers;
|
||||
|
||||
use cast::From as _0;
|
||||
use lucet_runtime::lucet_hostcall_terminate;
|
||||
use lucet_runtime::vmctx::Vmctx;
|
||||
|
@ -125,7 +127,7 @@ pub fn wasi_clock_res_get(
|
|||
|
||||
// no `nix` wrapper for clock_getres, so we do it ourselves
|
||||
let mut timespec = MaybeUninit::<libc::timespec>::uninit();
|
||||
let res = unsafe { libc::clock_getres(clock_id, timespec.as_mut_ptr()) };
|
||||
let res = unsafe { timers::clock_getres_helper(clock_id, timespec.as_mut_ptr()) };
|
||||
if res != 0 {
|
||||
return wasm32::errno_from_nix(nix::errno::Errno::last());
|
||||
}
|
||||
|
@ -169,7 +171,7 @@ pub fn wasi_clock_time_get(
|
|||
|
||||
// no `nix` wrapper for clock_getres, so we do it ourselves
|
||||
let mut timespec = MaybeUninit::<libc::timespec>::uninit();
|
||||
let res = unsafe { libc::clock_gettime(clock_id, timespec.as_mut_ptr()) };
|
||||
let res = unsafe { timers::clock_gettime_helper(clock_id, timespec.as_mut_ptr()) };
|
||||
if res != 0 {
|
||||
return wasm32::errno_from_nix(nix::errno::Errno::last());
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
mod fs;
|
||||
mod fs_helpers;
|
||||
mod misc;
|
||||
mod timers;
|
||||
|
||||
use crate::wasm32;
|
||||
|
||||
|
|
|
@ -0,0 +1,113 @@
|
|||
use nix::libc::{self, c_int, c_char};
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
mod notmac
|
||||
{
|
||||
use super::*;
|
||||
|
||||
pub unsafe fn clock_gettime_helper(clock_id: libc::clockid_t, tp: *mut libc::timespec) -> c_int {
|
||||
libc::clock_gettime(clock_id, tp)
|
||||
}
|
||||
|
||||
pub unsafe fn clock_getres_helper(clock_id: libc::clockid_t, res: *mut libc::timespec) -> c_int {
|
||||
libc::clock_getres(clock_id, res)
|
||||
}
|
||||
|
||||
pub unsafe fn futimens_helper(fd: c_int, times: *const libc::timespec) -> c_int {
|
||||
libc::futimens(fd, times)
|
||||
}
|
||||
|
||||
pub unsafe fn utimensat_helper(dirfd: c_int, path: *const c_char, times: *const libc::timespec, flag: c_int) -> c_int {
|
||||
libc::utimensat(dirfd, path, times, flag)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
mod mac
|
||||
{
|
||||
use super::*;
|
||||
use std::mem::MaybeUninit;
|
||||
use std::sync::Once;
|
||||
|
||||
use mach::mach_time::*;
|
||||
|
||||
// Referring these 3 sources
|
||||
//https://stackoverflow.com/questions/5167269/clock-gettime-alternative-in-mac-os-x
|
||||
//https://stackoverflow.com/questions/11680461/monotonic-clock-on-osx
|
||||
//https://gist.github.com/lifthrasiir/393ffb3e9900709fa2e3ae2a540b635f
|
||||
|
||||
static mut CONVERSION_FACTOR : f64 = 0.0;
|
||||
static INIT : Once = Once::new();
|
||||
|
||||
unsafe fn get_cached_conversion_factor() -> f64 {
|
||||
unsafe {
|
||||
INIT.call_once(|| {
|
||||
let mut timebase = MaybeUninit::<mach_timebase_info_data_t>::uninit();
|
||||
mach_timebase_info(timebase.as_mut_ptr());
|
||||
let timebase = unsafe { timebase.assume_init() };
|
||||
|
||||
let numer_d : f64 = timebase.numer as f64;
|
||||
let denom_d : f64 = timebase.denom as f64;
|
||||
|
||||
CONVERSION_FACTOR = numer_d / denom_d;
|
||||
});
|
||||
}
|
||||
CONVERSION_FACTOR
|
||||
}
|
||||
|
||||
pub unsafe fn clock_gettime_helper(clock_id: libc::clockid_t, tp: *mut libc::timespec) -> c_int {
|
||||
if !(clock_id == libc::CLOCK_REALTIME || clock_id == libc::CLOCK_MONOTONIC) {
|
||||
(*libc::__error()) = libc::EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if clock_id == libc::CLOCK_REALTIME {
|
||||
let mut micro = MaybeUninit::<libc::timeval>::uninit();
|
||||
libc::gettimeofday(micro.as_mut_ptr(), core::ptr::null_mut());
|
||||
let micro = unsafe { micro.assume_init() };
|
||||
|
||||
(*tp).tv_sec = micro.tv_sec;
|
||||
(*tp).tv_nsec = i64::from(micro.tv_usec) * 1000;
|
||||
return 0;
|
||||
} else {
|
||||
let time : u64 = mach_absolute_time();
|
||||
let time_d : f64 = time as f64;
|
||||
let conv : f64 = get_cached_conversion_factor();
|
||||
let nseconds : f64 = time_d * conv;
|
||||
let seconds : f64 = nseconds / 1e9;
|
||||
(*tp).tv_sec = seconds as i64;
|
||||
(*tp).tv_nsec = nseconds as i64;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn clock_getres_helper(clock_id: libc::clockid_t, res: *mut libc::timespec) -> c_int {
|
||||
if !(clock_id == libc::CLOCK_REALTIME || clock_id == libc::CLOCK_MONOTONIC) {
|
||||
(*libc::__error()) = libc::EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
(*res).tv_sec = 0 as i64;
|
||||
(*res).tv_nsec =
|
||||
if clock_id == libc::CLOCK_REALTIME {
|
||||
1000 as i64
|
||||
} else {
|
||||
1 as i64
|
||||
};
|
||||
return 0;
|
||||
}
|
||||
|
||||
pub unsafe fn futimens_helper(_fd: c_int, _times: *const libc::timespec) -> c_int {
|
||||
panic!("futimens not implemented");
|
||||
}
|
||||
|
||||
pub unsafe fn utimensat_helper(_dirfd: c_int, _path: *const c_char, _times: *const libc::timespec, _flag: c_int) -> c_int {
|
||||
panic!("utimensat not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
pub use notmac::*;
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
pub use mac::*;
|
|
@ -0,0 +1 @@
|
|||
{"files":{"AUTHORS":"f435ebf37000741d24baea378a85227fd6dcd57612a384ae7aea09e8525f9a1c","Cargo.lock":"624d0112a4e79cf39d3c19f974e1cfffb6d1d1297c617d42a56b3c81766d4ff7","Cargo.toml":"656c0b786a78bd17e4b28f6d8ce989114d42a11f0cc9e9d071230e8777ee238a","LICENSE.md":"cdd45f4d0c552c3a51725728215919e0dedb1e1af250f130e7c2d60eef6721fe","README.md":"0eb82fa97cceb17f63e2d089258fd2db3581d226dd214951f335a88c1450684f","build.rs":"543d76bcb20e6b8e29bbbb7ac47a62efbc62db1422a0f67d6f16a8a1cc5a55c3","ci/before_deploy.ps1":"a8ee0204dd1397a245a47626fecd98eff5da76e12b15139c06271b3cc309a3e1","ci/before_deploy.sh":"ea008e2c544482cba5b659c17887ccd5354779c629096f28e667d40391299cc5","ci/install.sh":"8841985e8645d391829ba52cd669bc5c5d98b1fdd8979c7cfd3cd3573c4a0a4b","ci/script.sh":"e52273d595c672884a2a8b429765aa04708b01735055bc8e11bd3ae73d57bab2","examples/cache.rs":"c8fc57159c15a67aaf64cba3f68405357e99c55607c4f8c5ff2cb7d88fb56c30","examples/cpu.rs":"d868a1b27494ed2d2cf3a940fc51ce50cbb56545575b43d47eea82a663cdf02b","examples/topology.rs":"514a41877c4f2f7a8835c700667e87b78b72e28a695e43da35c0fde512c68a85","examples/tsc_frequency.rs":"f5fb92a82b72d6bd8a55006d9b494da650c5bb398c0635f198616196421f243c","src/bin/cpuid.rs":"10f50c6e5d2917cea59c273b2bad439646c5ca53b8224a44c80ca30c7b378408","src/cpuid.c":"79fa0d852dba6e5e8fd1e7a0e9b8e28369818651a25bbf5d4a0c5e79320053aa","src/lib.rs":"27a1278fd3a1de7c529a98de05658dc328463ee14e05761a68ac388182e7a31e","src/tests.rs":"0fbdd825301037d7f6efc01ba6931e46b33d3363e27bb3c982cdb86a55c2518b"},"package":"b4a349ca83373cfa5d6dbb66fd76e58b2cca08da71a5f6400de0a0a6a9bceeaf"}
|
|
@ -0,0 +1,3 @@
|
|||
Gerd Zellweger <mail@gerdzellweger.com>
|
||||
Bence Meszaros <bence.me@gmail.com>
|
||||
Rafal Mielniczuk <rafalm3@gmail.com>
|
|
@ -0,0 +1,153 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.45"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "core_affinity"
|
||||
version = "0.5.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "kernel32-sys"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.62"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "num_cpus"
|
||||
version = "1.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "raw-cpuid"
|
||||
version = "7.0.3"
|
||||
dependencies = [
|
||||
"bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"core_affinity 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc_version"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "semver-parser"
|
||||
version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.99"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.99"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.2.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-build"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[metadata]
|
||||
"checksum bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3d155346769a6855b86399e9bc3814ab343cd3d62c7e985113d46a0ec3c281fd"
|
||||
"checksum cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)" = "4fc9a35e1f4290eb9e5fc54ba6cf40671ed2a2514c3eeb2b2a908dda2ea5a1be"
|
||||
"checksum core_affinity 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)" = "6d162c6e463c31dbf78fefa99d042156c1c74d404e299cfe3df2923cb857595b"
|
||||
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
|
||||
"checksum libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)" = "34fcd2c08d2f832f376f4173a231990fa5aef4e99fb569867318a227ef4c06ba"
|
||||
"checksum num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bcef43580c035376c0705c42792c294b66974abbfd2789b511784023f71f3273"
|
||||
"checksum proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e98a83a9f9b331f54b924e68a66acb1bb35cb01fb0a23645139967abefb697e8"
|
||||
"checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe"
|
||||
"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
|
||||
"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
|
||||
"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
|
||||
"checksum serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)" = "fec2851eb56d010dc9a21b89ca53ee75e6528bab60c11e89d38390904982da9f"
|
||||
"checksum serde_derive 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)" = "cb4dc18c61206b08dc98216c98faa0232f4337e1e1b8574551d5bad29ea1b425"
|
||||
"checksum syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "66850e97125af79138385e9b88339cbcd037e3f28ceab8c5ad98e64f0f1f80bf"
|
||||
"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
|
||||
"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
|
||||
"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"
|
|
@ -0,0 +1,55 @@
|
|||
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
|
||||
#
|
||||
# When uploading crates to the registry Cargo will automatically
|
||||
# "normalize" Cargo.toml files for maximal compatibility
|
||||
# with all versions of Cargo and also rewrite `path` dependencies
|
||||
# to registry (e.g., crates.io) dependencies
|
||||
#
|
||||
# If you believe there's an error in this file please file an
|
||||
# issue against the rust-lang/cargo repository. If you're
|
||||
# editing this file be aware that the upstream Cargo.toml
|
||||
# will likely look very different (and much more reasonable)
|
||||
|
||||
[package]
|
||||
name = "raw-cpuid"
|
||||
version = "7.0.3"
|
||||
authors = ["Gerd Zellweger <mail@gerdzellweger.com>"]
|
||||
build = "build.rs"
|
||||
description = "A library to parse the x86 CPUID instruction, written in rust with no external dependencies. The implementation closely resembles the Intel CPUID manual description. The library does only depend on libcore."
|
||||
homepage = "https://github.com/gz/rust-cpuid"
|
||||
documentation = "https://docs.rs/raw-cpuid/"
|
||||
readme = "README.md"
|
||||
keywords = ["cpuid", "x86", "amd64", "os", "libcore"]
|
||||
license = "MIT"
|
||||
repository = "https://github.com/gz/rust-cpuid"
|
||||
|
||||
[[bin]]
|
||||
name = "cpuid"
|
||||
path = "src/bin/cpuid.rs"
|
||||
[dependencies.bitflags]
|
||||
version = "1.1"
|
||||
|
||||
[dependencies.serde]
|
||||
version = "1.0"
|
||||
optional = true
|
||||
default-features = false
|
||||
|
||||
[dependencies.serde_derive]
|
||||
version = "1.0"
|
||||
optional = true
|
||||
[build-dependencies.cc]
|
||||
version = "1"
|
||||
|
||||
[build-dependencies.rustc_version]
|
||||
version = "0.2"
|
||||
|
||||
[features]
|
||||
nightly = []
|
||||
serialize = ["serde", "serde_derive"]
|
||||
use_arch = []
|
||||
[target."cfg(unix)".dev-dependencies.core_affinity]
|
||||
version = "0.5.9"
|
||||
|
||||
[target."cfg(unix)".dev-dependencies.libc]
|
||||
version = "0.2"
|
||||
default-features = false
|
|
@ -0,0 +1,21 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Gerd Zellweger
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
|
@ -0,0 +1,38 @@
|
|||
# cpuid [![Build Status](https://travis-ci.org/gz/rust-cpuid.svg)](https://travis-ci.org/gz/rust-cpuid) [![Crates.io](https://img.shields.io/crates/v/raw_cpuid.svg)](https://crates.io/crates/raw-cpuid)
|
||||
|
||||
A library to parse the x86 CPUID instruction, written in rust with no external dependencies. The implementation closely resembles the Intel CPUID manual description. The library does only depend on libcore.
|
||||
|
||||
The code should be in sync with the latest March 2018 revision of the Intel Architectures Software Developer’s Manual.
|
||||
|
||||
## Library usage
|
||||
```rust
|
||||
let cpuid = CpuId::new();
|
||||
|
||||
match cpuid.get_vendor_info() {
|
||||
Some(vf) => assert!(vf.as_string() == "GenuineIntel"),
|
||||
None => ()
|
||||
}
|
||||
|
||||
let has_sse = match cpuid.get_feature_info() {
|
||||
Some(finfo) => finfo.has_sse(),
|
||||
None => false
|
||||
};
|
||||
|
||||
if has_sse {
|
||||
println!("CPU supports SSE!");
|
||||
}
|
||||
|
||||
match cpuid.get_cache_parameters() {
|
||||
Some(cparams) => {
|
||||
for cache in cparams {
|
||||
let size = cache.associativity() * cache.physical_line_partitions() * cache.coherency_line_size() * cache.sets();
|
||||
println!("L{}-Cache size is {}", cache.level(), size);
|
||||
}
|
||||
},
|
||||
None => println!("No cache parameter information available"),
|
||||
}
|
||||
```
|
||||
|
||||
## Documentation
|
||||
* [API Documentation](https://docs.rs/raw-cpuid/)
|
||||
* [Examples](https://github.com/gz/rust-cpuid/tree/master/examples)
|
|
@ -0,0 +1,16 @@
|
|||
extern crate cc;
|
||||
extern crate rustc_version;
|
||||
use rustc_version::{version, version_meta, Channel, Version};
|
||||
|
||||
fn main() {
|
||||
let newer_than_1_27 = version().unwrap() >= Version::parse("1.27.0").unwrap();
|
||||
if newer_than_1_27 {
|
||||
println!("cargo:rustc-cfg=feature=\"use_arch\"");
|
||||
} else {
|
||||
cc::Build::new().file("src/cpuid.c").compile("libcpuid.a");
|
||||
}
|
||||
|
||||
if version_meta().unwrap().channel == Channel::Nightly {
|
||||
println!("cargo:rustc-cfg=feature=\"nightly\"");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
# This script takes care of packaging the build artifacts that will go in the
|
||||
# release zipfile
|
||||
|
||||
$SRC_DIR = $PWD.Path
|
||||
$STAGE = [System.Guid]::NewGuid().ToString()
|
||||
|
||||
Set-Location $ENV:Temp
|
||||
New-Item -Type Directory -Name $STAGE
|
||||
Set-Location $STAGE
|
||||
|
||||
$ZIP = "$SRC_DIR\$($Env:CRATE_NAME)-$($Env:APPVEYOR_REPO_TAG_NAME)-$($Env:TARGET).zip"
|
||||
|
||||
# TODO Update this to package the right artifacts
|
||||
Copy-Item "$SRC_DIR\target\$($Env:TARGET)\release\hello.exe" '.\'
|
||||
|
||||
7z a "$ZIP" *
|
||||
|
||||
Push-AppveyorArtifact "$ZIP"
|
||||
|
||||
Remove-Item *.* -Force
|
||||
Set-Location ..
|
||||
Remove-Item $STAGE
|
||||
Set-Location $SRC_DIR
|
|
@ -0,0 +1,33 @@
|
|||
# This script takes care of building your crate and packaging it for release
|
||||
|
||||
set -ex
|
||||
|
||||
main() {
|
||||
local src=$(pwd) \
|
||||
stage=
|
||||
|
||||
case $TRAVIS_OS_NAME in
|
||||
linux)
|
||||
stage=$(mktemp -d)
|
||||
;;
|
||||
osx)
|
||||
stage=$(mktemp -d -t tmp)
|
||||
;;
|
||||
esac
|
||||
|
||||
test -f Cargo.lock || cargo generate-lockfile
|
||||
|
||||
# TODO Update this to build the artifacts that matter to you
|
||||
cross rustc --bin hello --target $TARGET --release -- -C lto
|
||||
|
||||
# TODO Update this to package the right artifacts
|
||||
cp target/$TARGET/release/hello $stage/
|
||||
|
||||
cd $stage
|
||||
tar czf $src/$CRATE_NAME-$TRAVIS_TAG-$TARGET.tar.gz *
|
||||
cd $src
|
||||
|
||||
rm -rf $stage
|
||||
}
|
||||
|
||||
main
|
|
@ -0,0 +1,47 @@
|
|||
set -ex
|
||||
|
||||
main() {
|
||||
local target=
|
||||
if [ $TRAVIS_OS_NAME = linux ]; then
|
||||
target=x86_64-unknown-linux-musl
|
||||
sort=sort
|
||||
else
|
||||
target=x86_64-apple-darwin
|
||||
sort=gsort # for `sort --sort-version`, from brew's coreutils.
|
||||
fi
|
||||
|
||||
# Builds for iOS are done on OSX, but require the specific target to be
|
||||
# installed.
|
||||
case $TARGET in
|
||||
aarch64-apple-ios)
|
||||
rustup target install aarch64-apple-ios
|
||||
;;
|
||||
armv7-apple-ios)
|
||||
rustup target install armv7-apple-ios
|
||||
;;
|
||||
armv7s-apple-ios)
|
||||
rustup target install armv7s-apple-ios
|
||||
;;
|
||||
i386-apple-ios)
|
||||
rustup target install i386-apple-ios
|
||||
;;
|
||||
x86_64-apple-ios)
|
||||
rustup target install x86_64-apple-ios
|
||||
;;
|
||||
esac
|
||||
|
||||
# This fetches latest stable release
|
||||
local tag=$(git ls-remote --tags --refs --exit-code https://github.com/japaric/cross \
|
||||
| cut -d/ -f3 \
|
||||
| grep -E '^v[0.1.0-9.]+$' \
|
||||
| $sort --version-sort \
|
||||
| tail -n1)
|
||||
curl -LSfs https://japaric.github.io/trust/install.sh | \
|
||||
sh -s -- \
|
||||
--force \
|
||||
--git japaric/cross \
|
||||
--tag $tag \
|
||||
--target $target
|
||||
}
|
||||
|
||||
main
|
|
@ -0,0 +1,24 @@
|
|||
# This script takes care of testing your crate
|
||||
|
||||
set -ex
|
||||
|
||||
# TODO This is the "test phase", tweak it as you see fit
|
||||
main() {
|
||||
cross build --target $TARGET
|
||||
cross build --target $TARGET --release
|
||||
|
||||
if [ ! -z $DISABLE_TESTS ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
cross test --target $TARGET
|
||||
cross test --target $TARGET --release
|
||||
|
||||
cross run --target $TARGET
|
||||
cross run --target $TARGET --release
|
||||
}
|
||||
|
||||
# we don't run the "test phase" when doing deploys
|
||||
if [ -z $TRAVIS_TAG ]; then
|
||||
main
|
||||
fi
|
|
@ -0,0 +1,52 @@
|
|||
//! Example that displays information about the caches.
|
||||
extern crate raw_cpuid;
|
||||
use raw_cpuid::{CacheType, CpuId};
|
||||
|
||||
fn main() {
|
||||
let cpuid = CpuId::new();
|
||||
cpuid.get_cache_parameters().map_or_else(
|
||||
|| println!("No cache parameter information available"),
|
||||
|cparams| {
|
||||
for cache in cparams {
|
||||
let size = cache.associativity()
|
||||
* cache.physical_line_partitions()
|
||||
* cache.coherency_line_size()
|
||||
* cache.sets();
|
||||
|
||||
let typ = match cache.cache_type() {
|
||||
CacheType::Data => "Instruction-Cache",
|
||||
CacheType::Instruction => "Data-Cache",
|
||||
CacheType::Unified => "Unified-Cache",
|
||||
_ => "Unknown cache type",
|
||||
};
|
||||
|
||||
let associativity = if cache.is_fully_associative() {
|
||||
format!("fully associative")
|
||||
} else {
|
||||
format!("{}-way associativity", cache.associativity())
|
||||
};
|
||||
|
||||
let size_repr = if size > 1024 * 1024 {
|
||||
format!("{} MiB", size / (1024 * 1024))
|
||||
} else {
|
||||
format!("{} KiB", size / 1024)
|
||||
};
|
||||
|
||||
let mapping = if cache.has_complex_indexing() {
|
||||
"hash-based-mapping"
|
||||
} else {
|
||||
"direct-mapped"
|
||||
};
|
||||
|
||||
println!(
|
||||
"L{} {}: ({}, {}, {})",
|
||||
cache.level(),
|
||||
typ,
|
||||
size_repr,
|
||||
associativity,
|
||||
mapping
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
//! An example that displays the type/features/configuration of the CPU.
|
||||
extern crate raw_cpuid;
|
||||
|
||||
fn main() {
|
||||
let cpuid = raw_cpuid::CpuId::new();
|
||||
|
||||
let vendor_string = cpuid.get_vendor_info().map_or_else(
|
||||
|| String::from("Unknown Vendor"),
|
||||
|vf| String::from(vf.as_string()),
|
||||
);
|
||||
|
||||
let brand_string: String = cpuid.get_extended_function_info().map_or_else(
|
||||
|| String::from("Unknown CPU"),
|
||||
|extfuninfo| {
|
||||
println!("{:?}", extfuninfo.extended_signature());
|
||||
String::from(extfuninfo.processor_brand_string().unwrap_or("Unknown CPU"))
|
||||
},
|
||||
);
|
||||
|
||||
/*let serial_nr = cpuid.get_processor_serial().map_or_else(
|
||||
|| String::from(""),
|
||||
|extfuninfo| String::from(extfuninfo.processor_brand_string().unwrap_or("Unknown CPU")),
|
||||
);*/
|
||||
|
||||
println!("Vendor is: {}", vendor_string);
|
||||
println!("CPU Model is: {}", brand_string);
|
||||
}
|
|
@ -0,0 +1,196 @@
|
|||
//! An example that uses CPUID to determine the system topology.
|
||||
//!
|
||||
//! Intel Topology is a pretty complicated subject (unfortunately):
|
||||
//! https://software.intel.com/en-us/articles/intel-64-architecture-processor-topology-enumeration/
|
||||
extern crate core_affinity;
|
||||
extern crate raw_cpuid;
|
||||
|
||||
use raw_cpuid::{CpuId, ExtendedTopologyLevel, TopologyType};
|
||||
use std::thread;
|
||||
|
||||
/// Runs CPU ID on every core in the system (to gather all APIC IDs).
|
||||
///
|
||||
/// # Note
|
||||
/// This won't work on macOS, apparently there is no guarantee after setting the affinity
|
||||
/// that a thread will really execute on the pinned core.
|
||||
fn gather_all_xapic_ids() -> Vec<u8> {
|
||||
let core_ids = core_affinity::get_core_ids().unwrap();
|
||||
|
||||
// Create a thread for each active CPU core.
|
||||
core_ids
|
||||
.into_iter()
|
||||
.map(|id| {
|
||||
thread::spawn(move || {
|
||||
// Pin this thread to a single CPU core.
|
||||
core_affinity::set_for_current(id);
|
||||
// Do more work after this.
|
||||
let cpuid = CpuId::new();
|
||||
cpuid
|
||||
.get_feature_info()
|
||||
.map_or_else(|| 0, |finfo| finfo.initial_local_apic_id())
|
||||
})
|
||||
.join()
|
||||
.unwrap_or(0)
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
}
|
||||
|
||||
/// Runs CPU ID on every core in the system (to gather all x2APIC IDs).
|
||||
///
|
||||
/// # Note
|
||||
/// This won't work on macOS, apparently there is no guarantee after setting the affinity
|
||||
/// that a thread will really execute on the pinned core.
|
||||
fn gather_all_x2apic_ids() -> Vec<u32> {
|
||||
let core_ids = core_affinity::get_core_ids().unwrap();
|
||||
|
||||
// Create a thread for each active CPU core.
|
||||
core_ids
|
||||
.into_iter()
|
||||
.map(|id| {
|
||||
thread::spawn(move || {
|
||||
// Pin this thread to a single CPU core.
|
||||
core_affinity::set_for_current(id);
|
||||
// Do more work after this.
|
||||
let cpuid = CpuId::new();
|
||||
cpuid.get_extended_topology_info().map_or_else(
|
||||
|| 0,
|
||||
|mut topiter| topiter.next().as_ref().unwrap().x2apic_id(),
|
||||
)
|
||||
})
|
||||
.join()
|
||||
.unwrap_or(0)
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
}
|
||||
|
||||
fn enumerate_with_extended_topology_info() {
|
||||
let cpuid = CpuId::new();
|
||||
let mut smt_x2apic_shift: u32 = 0;
|
||||
let mut core_x2apic_shift: u32 = 0;
|
||||
|
||||
cpuid.get_extended_topology_info().map_or_else(
|
||||
|| println!("No topology information available."),
|
||||
|topoiter| {
|
||||
let topology: Vec<ExtendedTopologyLevel> = topoiter.collect();
|
||||
for topolevel in topology.iter() {
|
||||
match topolevel.level_type() {
|
||||
TopologyType::SMT => {
|
||||
smt_x2apic_shift = topolevel.shift_right_for_next_apic_id();
|
||||
}
|
||||
TopologyType::Core => {
|
||||
core_x2apic_shift = topolevel.shift_right_for_next_apic_id();
|
||||
}
|
||||
_ => panic!("Topology category not supported."),
|
||||
};
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
println!("Enumeration of all cores in the system (with x2APIC IDs):");
|
||||
let mut all_x2apic_ids: Vec<u32> = gather_all_x2apic_ids();
|
||||
all_x2apic_ids.sort();
|
||||
for x2apic_id in all_x2apic_ids {
|
||||
let smt_select_mask = !(u32::max_value() << smt_x2apic_shift);
|
||||
let core_select_mask = (!((u32::max_value()) << core_x2apic_shift)) ^ smt_select_mask;
|
||||
let pkg_select_mask = u32::max_value() << core_x2apic_shift;
|
||||
|
||||
let smt_id = x2apic_id & smt_select_mask;
|
||||
let core_id = (x2apic_id & core_select_mask) >> smt_x2apic_shift;
|
||||
let pkg_id = (x2apic_id & pkg_select_mask) >> core_x2apic_shift;
|
||||
|
||||
println!(
|
||||
"x2APIC#{} (pkg: {}, core: {}, smt: {})",
|
||||
x2apic_id, pkg_id, core_id, smt_id
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn enumerate_with_legacy_leaf_1_4() {
|
||||
let cpuid = CpuId::new();
|
||||
let max_logical_processor_ids = cpuid
|
||||
.get_feature_info()
|
||||
.map_or_else(|| 0, |finfo| finfo.max_logical_processor_ids());
|
||||
|
||||
let mut smt_max_cores_for_package: u8 = 0;
|
||||
cpuid.get_cache_parameters().map_or_else(
|
||||
|| println!("No cache parameter information available"),
|
||||
|cparams| {
|
||||
for (ecx, cache) in cparams.enumerate() {
|
||||
if ecx == 0 {
|
||||
smt_max_cores_for_package = cache.max_cores_for_package() as u8;
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
fn log2(o: u8) -> u8 {
|
||||
7 - o.leading_zeros() as u8
|
||||
}
|
||||
|
||||
let smt_mask_width: u8 =
|
||||
log2(max_logical_processor_ids.next_power_of_two() / (smt_max_cores_for_package));
|
||||
let smt_select_mask: u8 = !(u8::max_value() << smt_mask_width);
|
||||
|
||||
let core_mask_width: u8 = log2(smt_max_cores_for_package);
|
||||
let core_only_select_mask =
|
||||
(!(u8::max_value() << (core_mask_width + smt_mask_width))) ^ smt_select_mask;
|
||||
|
||||
let pkg_select_mask = u8::max_value() << (core_mask_width + smt_mask_width);
|
||||
|
||||
println!("Enumeration of all cores in the system (with APIC IDs):");
|
||||
let mut all_xapic_ids: Vec<u8> = gather_all_xapic_ids();
|
||||
all_xapic_ids.sort();
|
||||
|
||||
for xapic_id in all_xapic_ids {
|
||||
let smt_id = xapic_id & smt_select_mask;
|
||||
let core_id = (xapic_id & core_only_select_mask) >> smt_mask_width;
|
||||
let pkg_id = (xapic_id & pkg_select_mask) >> (core_mask_width + smt_mask_width);
|
||||
|
||||
println!(
|
||||
"APIC#{} (pkg: {}, core: {}, smt: {})",
|
||||
xapic_id, pkg_id, core_id, smt_id
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let cpuid = CpuId::new();
|
||||
|
||||
cpuid.get_extended_function_info().map_or_else(
|
||||
|| println!("Couldn't find processor serial number."),
|
||||
|extfuninfo| {
|
||||
println!(
|
||||
"CPU Model is: {}",
|
||||
extfuninfo.processor_brand_string().unwrap_or("Unknown CPU")
|
||||
)
|
||||
},
|
||||
);
|
||||
cpuid.get_extended_topology_info().map_or_else(
|
||||
|| println!("No topology information available."),
|
||||
|topoiter| {
|
||||
let mut topology: Vec<ExtendedTopologyLevel> = topoiter.collect();
|
||||
topology.reverse();
|
||||
|
||||
for topolevel in topology.iter() {
|
||||
let typ = match topolevel.level_type() {
|
||||
TopologyType::SMT => "SMT-threads",
|
||||
TopologyType::Core => "cores",
|
||||
_ => panic!("Topology category not supported."),
|
||||
};
|
||||
|
||||
println!(
|
||||
"At level {} the CPU has: {} {}",
|
||||
topolevel.level_number(),
|
||||
topolevel.processors(),
|
||||
typ,
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
println!("");
|
||||
enumerate_with_legacy_leaf_1_4();
|
||||
|
||||
println!("");
|
||||
enumerate_with_extended_topology_info();
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
//! An example that determines the time stamp counter frequency (RDTSC, RDTSCP) .
|
||||
extern crate raw_cpuid;
|
||||
|
||||
use std::time;
|
||||
|
||||
const MHZ_TO_HZ: u64 = 1000000;
|
||||
const KHZ_TO_HZ: u64 = 1000;
|
||||
|
||||
fn main() {
|
||||
let cpuid = raw_cpuid::CpuId::new();
|
||||
let has_tsc = cpuid
|
||||
.get_feature_info()
|
||||
.map_or(false, |finfo| finfo.has_tsc());
|
||||
|
||||
let has_invariant_tsc = cpuid
|
||||
.get_extended_function_info()
|
||||
.map_or(false, |efinfo| efinfo.has_invariant_tsc());
|
||||
|
||||
let tsc_frequency_hz = cpuid.get_tsc_info().map(|tinfo| {
|
||||
if tinfo.nominal_frequency() != 0 {
|
||||
Some(tinfo.tsc_frequency())
|
||||
} else if tinfo.numerator() != 0 && tinfo.denominator() != 0 {
|
||||
// Skylake and Kabylake don't report the crystal clock, approximate with base frequency:
|
||||
cpuid
|
||||
.get_processor_frequency_info()
|
||||
.map(|pinfo| pinfo.processor_base_frequency() as u64 * MHZ_TO_HZ)
|
||||
.map(|cpu_base_freq_hz| {
|
||||
let crystal_hz =
|
||||
cpu_base_freq_hz * tinfo.denominator() as u64 / tinfo.numerator() as u64;
|
||||
crystal_hz * tinfo.numerator() as u64 / tinfo.denominator() as u64
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
});
|
||||
|
||||
if has_tsc {
|
||||
// Try to figure out TSC frequency with CPUID
|
||||
println!(
|
||||
"TSC Frequency is: {} ({})",
|
||||
match tsc_frequency_hz {
|
||||
Some(x) => format!("{} Hz", x.unwrap_or(0)),
|
||||
None => String::from("unknown"),
|
||||
},
|
||||
if has_invariant_tsc {
|
||||
"invariant"
|
||||
} else {
|
||||
"TSC frequency varies with speed-stepping"
|
||||
}
|
||||
);
|
||||
|
||||
// Check if we run in a VM and the hypervisor can give us the TSC frequency
|
||||
cpuid.get_hypervisor_info().map(|hv| {
|
||||
hv.tsc_frequency().map(|tsc_khz| {
|
||||
let virtual_tsc_frequency_hz = tsc_khz as u64 * KHZ_TO_HZ;
|
||||
println!(
|
||||
"Hypervisor reports TSC Frequency at: {} Hz",
|
||||
virtual_tsc_frequency_hz
|
||||
);
|
||||
})
|
||||
});
|
||||
|
||||
// Determine TSC frequency by measuring it (loop for a second, record ticks)
|
||||
let one_second = time::Duration::from_secs(1);
|
||||
let now = time::Instant::now();
|
||||
let start = unsafe { core::arch::x86_64::_rdtsc() };
|
||||
loop {
|
||||
if now.elapsed() >= one_second {
|
||||
break;
|
||||
}
|
||||
}
|
||||
let end = unsafe { core::arch::x86_64::_rdtsc() };
|
||||
println!(
|
||||
"Empirical measurement of TSC frequency was: {} Hz",
|
||||
(end - start)
|
||||
);
|
||||
} else {
|
||||
println!("System does not have a TSC.")
|
||||
}
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
extern crate raw_cpuid;
|
||||
|
||||
use raw_cpuid::CpuId;
|
||||
|
||||
fn main() {
|
||||
let cpuid = CpuId::new();
|
||||
// Implement Display for each of those structs
|
||||
cpuid.get_vendor_info().map(|info| {
|
||||
println!("Vendor");
|
||||
println!("{}", info);
|
||||
});
|
||||
cpuid.get_feature_info().map(|info| {
|
||||
println!("Feature");
|
||||
println!("{:?}", info);
|
||||
});
|
||||
cpuid.get_cache_info().map(|info| {
|
||||
println!("Cache");
|
||||
println!("{:?}", info);
|
||||
});
|
||||
cpuid.get_processor_serial().map(|info| {
|
||||
println!("Processor Serial");
|
||||
println!("{:?}", info);
|
||||
});
|
||||
cpuid.get_cache_parameters().map(|info| {
|
||||
println!("Cache Parameters");
|
||||
println!("{:?}", info);
|
||||
});
|
||||
cpuid.get_monitor_mwait_info().map(|info| {
|
||||
println!("Monitor/MWait");
|
||||
println!("{:?}", info);
|
||||
});
|
||||
cpuid.get_thermal_power_info().map(|info| {
|
||||
println!("Thermal Power");
|
||||
println!("{:?}", info);
|
||||
});
|
||||
cpuid.get_extended_feature_info().map(|info| {
|
||||
println!("Extended Features");
|
||||
println!("{:?}", info);
|
||||
});
|
||||
cpuid.get_direct_cache_access_info().map(|info| {
|
||||
println!("Direct Cache Access");
|
||||
println!("{:?}", info);
|
||||
});
|
||||
cpuid.get_performance_monitoring_info().map(|info| {
|
||||
println!("Performance Monitoring");
|
||||
println!("{:?}", info);
|
||||
});
|
||||
cpuid.get_extended_topology_info().map(|info| {
|
||||
println!("Extended Topology");
|
||||
println!("{:?}", info);
|
||||
});
|
||||
cpuid.get_extended_state_info().map(|info| {
|
||||
println!("Extended State");
|
||||
println!("{:?}", info);
|
||||
});
|
||||
cpuid.get_rdt_monitoring_info().map(|info| {
|
||||
println!("RDT Monitoring");
|
||||
println!("{:?}", info);
|
||||
});
|
||||
cpuid.get_rdt_allocation_info().map(|info| {
|
||||
println!("RDT Allocation");
|
||||
println!("{:?}", info);
|
||||
});
|
||||
cpuid.get_sgx_info().map(|info| {
|
||||
println!("Software Guard Extensions");
|
||||
println!("{:?}", info);
|
||||
});
|
||||
cpuid.get_processor_trace_info().map(|info| {
|
||||
println!("Processor Trace");
|
||||
println!("{:?}", info);
|
||||
});
|
||||
cpuid.get_tsc_info().map(|info| {
|
||||
println!("TSC");
|
||||
println!("{:?}", info);
|
||||
});
|
||||
cpuid.get_processor_frequency_info().map(|info| {
|
||||
println!("Processor Frequency");
|
||||
println!("{:?}", info);
|
||||
});
|
||||
cpuid.deterministic_address_translation_info().map(|dats| {
|
||||
println!("Deterministic Address Translation");
|
||||
for dat in dats {
|
||||
println!("{:?}", dat);
|
||||
}
|
||||
});
|
||||
cpuid.get_soc_vendor_info().map(|info| {
|
||||
println!("SoC Vendor Info");
|
||||
println!("{:?}", info);
|
||||
});
|
||||
cpuid.get_extended_function_info().map(|info| {
|
||||
println!("Extended Function Info");
|
||||
println!("{:?}", info);
|
||||
});
|
||||
cpuid.get_memory_encryption_info().map(|info| {
|
||||
println!("Memory Encryption Info");
|
||||
println!("{:?}", info);
|
||||
});
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
#include <stdint.h>
|
||||
|
||||
void cpuid(uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) {
|
||||
#ifdef _MSC_VER
|
||||
uint32_t regs[4];
|
||||
__cpuidex((int *)regs, *eax, *ecx);
|
||||
*eax = regs[0], *ebx = regs[1], *ecx = regs[2], *edx = regs[3];
|
||||
#else
|
||||
asm volatile(
|
||||
#if defined(__i386__) && defined(__PIC__)
|
||||
// The reason for this ebx juggling is the -fPIC rust compilation mode.
|
||||
// On 32-bit to locate variables it uses a global offset table whose
|
||||
// pointer is stored in ebx. Without temporary storing ebx in edi, the
|
||||
// compiler will complain about inconsistent operand constraints in an
|
||||
// 'asm'.
|
||||
// Also note that this is only an issue on older compiler versions.
|
||||
"mov %%ebx, %%edi;"
|
||||
"cpuid;"
|
||||
"xchgl %%ebx, %%edi;"
|
||||
:
|
||||
"+a" (*eax),
|
||||
"=D" (*ebx),
|
||||
#else
|
||||
"cpuid"
|
||||
:
|
||||
"+a"(*eax),
|
||||
"=b"(*ebx),
|
||||
#endif
|
||||
"+c"(*ecx),
|
||||
"=d"(*edx));
|
||||
#endif
|
||||
}
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,828 @@
|
|||
use *;
|
||||
|
||||
#[test]
|
||||
fn genuine_intel() {
|
||||
let vf = VendorInfo {
|
||||
ebx: 1970169159,
|
||||
edx: 1231384169,
|
||||
ecx: 1818588270,
|
||||
};
|
||||
assert!(vf.as_string() == "GenuineIntel");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn feature_info() {
|
||||
let finfo = FeatureInfo {
|
||||
eax: 198313,
|
||||
ebx: 34605056,
|
||||
edx_ecx: FeatureInfoFlags {
|
||||
bits: 2109399999 | 3219913727 << 32,
|
||||
},
|
||||
};
|
||||
|
||||
assert!(finfo.model_id() == 10);
|
||||
assert!(finfo.extended_model_id() == 3);
|
||||
assert!(finfo.stepping_id() == 9);
|
||||
assert!(finfo.extended_family_id() == 0);
|
||||
assert!(finfo.family_id() == 6);
|
||||
assert!(finfo.stepping_id() == 9);
|
||||
assert!(finfo.brand_index() == 0);
|
||||
|
||||
assert!(finfo.edx_ecx.contains(FeatureInfoFlags::SSE2));
|
||||
assert!(finfo.edx_ecx.contains(FeatureInfoFlags::SSE41));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cache_info() {
|
||||
let cinfos = CacheInfoIter {
|
||||
current: 1,
|
||||
eax: 1979931137,
|
||||
ebx: 15774463,
|
||||
ecx: 0,
|
||||
edx: 13238272,
|
||||
};
|
||||
for (idx, cache) in cinfos.enumerate() {
|
||||
match idx {
|
||||
0 => assert!(cache.num == 0xff),
|
||||
1 => assert!(cache.num == 0x5a),
|
||||
2 => assert!(cache.num == 0xb2),
|
||||
3 => assert!(cache.num == 0x03),
|
||||
4 => assert!(cache.num == 0xf0),
|
||||
5 => assert!(cache.num == 0xca),
|
||||
6 => assert!(cache.num == 0x76),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cache_parameters() {
|
||||
let caches: [CacheParameter; 4] = [
|
||||
CacheParameter {
|
||||
eax: 469778721,
|
||||
ebx: 29360191,
|
||||
ecx: 63,
|
||||
edx: 0,
|
||||
},
|
||||
CacheParameter {
|
||||
eax: 469778722,
|
||||
ebx: 29360191,
|
||||
ecx: 63,
|
||||
edx: 0,
|
||||
},
|
||||
CacheParameter {
|
||||
eax: 469778755,
|
||||
ebx: 29360191,
|
||||
ecx: 511,
|
||||
edx: 0,
|
||||
},
|
||||
CacheParameter {
|
||||
eax: 470008163,
|
||||
ebx: 46137407,
|
||||
ecx: 4095,
|
||||
edx: 6,
|
||||
},
|
||||
];
|
||||
|
||||
for (idx, cache) in caches.into_iter().enumerate() {
|
||||
match idx {
|
||||
0 => {
|
||||
assert!(cache.cache_type() == CacheType::Data);
|
||||
assert!(cache.level() == 1);
|
||||
assert!(cache.is_self_initializing());
|
||||
assert!(!cache.is_fully_associative());
|
||||
assert!(cache.max_cores_for_cache() == 2);
|
||||
assert!(cache.max_cores_for_package() == 8);
|
||||
assert!(cache.coherency_line_size() == 64);
|
||||
assert!(cache.physical_line_partitions() == 1);
|
||||
assert!(cache.associativity() == 8);
|
||||
assert!(!cache.is_write_back_invalidate());
|
||||
assert!(!cache.is_inclusive());
|
||||
assert!(!cache.has_complex_indexing());
|
||||
assert!(cache.sets() == 64);
|
||||
}
|
||||
1 => {
|
||||
assert!(cache.cache_type() == CacheType::Instruction);
|
||||
assert!(cache.level() == 1);
|
||||
assert!(cache.is_self_initializing());
|
||||
assert!(!cache.is_fully_associative());
|
||||
assert!(cache.max_cores_for_cache() == 2);
|
||||
assert!(cache.max_cores_for_package() == 8);
|
||||
assert!(cache.coherency_line_size() == 64);
|
||||
assert!(cache.physical_line_partitions() == 1);
|
||||
assert!(cache.associativity() == 8);
|
||||
assert!(!cache.is_write_back_invalidate());
|
||||
assert!(!cache.is_inclusive());
|
||||
assert!(!cache.has_complex_indexing());
|
||||
assert!(cache.sets() == 64);
|
||||
}
|
||||
2 => {
|
||||
assert!(cache.cache_type() == CacheType::Unified);
|
||||
assert!(cache.level() == 2);
|
||||
assert!(cache.is_self_initializing());
|
||||
assert!(!cache.is_fully_associative());
|
||||
assert!(cache.max_cores_for_cache() == 2);
|
||||
assert!(cache.max_cores_for_package() == 8);
|
||||
assert!(cache.coherency_line_size() == 64);
|
||||
assert!(cache.physical_line_partitions() == 1);
|
||||
assert!(cache.associativity() == 8);
|
||||
assert!(!cache.is_write_back_invalidate());
|
||||
assert!(!cache.is_inclusive());
|
||||
assert!(!cache.has_complex_indexing());
|
||||
assert!(cache.sets() == 512);
|
||||
}
|
||||
3 => {
|
||||
assert!(cache.cache_type() == CacheType::Unified);
|
||||
assert!(cache.level() == 3);
|
||||
assert!(cache.is_self_initializing());
|
||||
assert!(!cache.is_fully_associative());
|
||||
assert!(cache.max_cores_for_cache() == 16);
|
||||
assert!(cache.max_cores_for_package() == 8);
|
||||
assert!(cache.coherency_line_size() == 64);
|
||||
assert!(cache.physical_line_partitions() == 1);
|
||||
assert!(cache.associativity() == 12);
|
||||
assert!(!cache.is_write_back_invalidate());
|
||||
assert!(cache.is_inclusive());
|
||||
assert!(cache.has_complex_indexing());
|
||||
assert!(cache.sets() == 4096);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn monitor_mwait_features() {
|
||||
let mmfeatures = MonitorMwaitInfo {
|
||||
eax: 64,
|
||||
ebx: 64,
|
||||
ecx: 3,
|
||||
edx: 135456,
|
||||
};
|
||||
assert!(mmfeatures.smallest_monitor_line() == 64);
|
||||
assert!(mmfeatures.largest_monitor_line() == 64);
|
||||
assert!(mmfeatures.extensions_supported());
|
||||
assert!(mmfeatures.interrupts_as_break_event());
|
||||
assert!(mmfeatures.supported_c0_states() == 0);
|
||||
assert!(mmfeatures.supported_c1_states() == 2);
|
||||
assert!(mmfeatures.supported_c2_states() == 1);
|
||||
assert!(mmfeatures.supported_c3_states() == 1);
|
||||
assert!(mmfeatures.supported_c4_states() == 2);
|
||||
assert!(mmfeatures.supported_c5_states() == 0);
|
||||
assert!(mmfeatures.supported_c6_states() == 0);
|
||||
assert!(mmfeatures.supported_c7_states() == 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn thermal_power_features() {
|
||||
let tpfeatures = ThermalPowerInfo {
|
||||
eax: ThermalPowerFeaturesEax { bits: 119 },
|
||||
ebx: 2,
|
||||
ecx: ThermalPowerFeaturesEcx { bits: 9 },
|
||||
edx: 0,
|
||||
};
|
||||
|
||||
assert!(tpfeatures.eax.contains(ThermalPowerFeaturesEax::DTS));
|
||||
assert!(tpfeatures
|
||||
.eax
|
||||
.contains(ThermalPowerFeaturesEax::TURBO_BOOST));
|
||||
assert!(tpfeatures.eax.contains(ThermalPowerFeaturesEax::ARAT));
|
||||
assert!(tpfeatures.eax.contains(ThermalPowerFeaturesEax::PLN));
|
||||
assert!(tpfeatures.eax.contains(ThermalPowerFeaturesEax::ECMD));
|
||||
assert!(tpfeatures.eax.contains(ThermalPowerFeaturesEax::PTM));
|
||||
|
||||
assert!(tpfeatures
|
||||
.ecx
|
||||
.contains(ThermalPowerFeaturesEcx::HW_COORD_FEEDBACK));
|
||||
assert!(tpfeatures
|
||||
.ecx
|
||||
.contains(ThermalPowerFeaturesEcx::ENERGY_BIAS_PREF));
|
||||
|
||||
assert!(tpfeatures.dts_irq_threshold() == 0x2);
|
||||
let tpfeatures = ThermalPowerInfo {
|
||||
eax: ThermalPowerFeaturesEax::DTS
|
||||
| ThermalPowerFeaturesEax::TURBO_BOOST
|
||||
| ThermalPowerFeaturesEax::ARAT
|
||||
| ThermalPowerFeaturesEax::PLN
|
||||
| ThermalPowerFeaturesEax::ECMD
|
||||
| ThermalPowerFeaturesEax::PTM
|
||||
| ThermalPowerFeaturesEax::HWP
|
||||
| ThermalPowerFeaturesEax::HWP_NOTIFICATION
|
||||
| ThermalPowerFeaturesEax::HWP_ACTIVITY_WINDOW
|
||||
| ThermalPowerFeaturesEax::HWP_ENERGY_PERFORMANCE_PREFERENCE
|
||||
| ThermalPowerFeaturesEax::HDC,
|
||||
ebx: 2,
|
||||
ecx: ThermalPowerFeaturesEcx::HW_COORD_FEEDBACK | ThermalPowerFeaturesEcx::ENERGY_BIAS_PREF,
|
||||
edx: 0,
|
||||
};
|
||||
|
||||
assert!(tpfeatures.has_dts());
|
||||
assert!(!tpfeatures.has_turbo_boost3());
|
||||
assert!(tpfeatures.has_turbo_boost());
|
||||
assert!(tpfeatures.has_arat());
|
||||
assert!(tpfeatures.has_pln());
|
||||
assert!(tpfeatures.has_ecmd());
|
||||
assert!(tpfeatures.has_ptm());
|
||||
assert!(tpfeatures.has_hwp());
|
||||
assert!(tpfeatures.has_hwp_notification());
|
||||
assert!(tpfeatures.has_hwp_activity_window());
|
||||
assert!(tpfeatures.has_hwp_energy_performance_preference());
|
||||
assert!(!tpfeatures.has_hwp_package_level_request());
|
||||
assert!(tpfeatures.has_hdc());
|
||||
assert!(tpfeatures.has_hw_coord_feedback());
|
||||
assert!(tpfeatures.has_energy_bias_pref());
|
||||
assert!(tpfeatures.dts_irq_threshold() == 0x2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn extended_features() {
|
||||
let tpfeatures = ExtendedFeatures {
|
||||
eax: 0,
|
||||
ebx: ExtendedFeaturesEbx { bits: 641 },
|
||||
ecx: ExtendedFeaturesEcx { bits: 0 },
|
||||
edx: 0,
|
||||
};
|
||||
assert!(tpfeatures.eax == 0);
|
||||
assert!(tpfeatures.has_fsgsbase());
|
||||
assert!(!tpfeatures.has_tsc_adjust_msr());
|
||||
assert!(!tpfeatures.has_bmi1());
|
||||
assert!(!tpfeatures.has_hle());
|
||||
assert!(!tpfeatures.has_avx2());
|
||||
assert!(tpfeatures.has_smep());
|
||||
assert!(!tpfeatures.has_bmi2());
|
||||
assert!(tpfeatures.has_rep_movsb_stosb());
|
||||
assert!(!tpfeatures.has_invpcid());
|
||||
assert!(!tpfeatures.has_rtm());
|
||||
assert!(!tpfeatures.has_rdtm());
|
||||
assert!(!tpfeatures.has_fpu_cs_ds_deprecated());
|
||||
|
||||
let tpfeatures2 = ExtendedFeatures {
|
||||
eax: 0,
|
||||
ebx: ExtendedFeaturesEbx::FSGSBASE
|
||||
| ExtendedFeaturesEbx::ADJUST_MSR
|
||||
| ExtendedFeaturesEbx::BMI1
|
||||
| ExtendedFeaturesEbx::AVX2
|
||||
| ExtendedFeaturesEbx::SMEP
|
||||
| ExtendedFeaturesEbx::BMI2
|
||||
| ExtendedFeaturesEbx::REP_MOVSB_STOSB
|
||||
| ExtendedFeaturesEbx::INVPCID
|
||||
| ExtendedFeaturesEbx::DEPRECATE_FPU_CS_DS
|
||||
| ExtendedFeaturesEbx::MPX
|
||||
| ExtendedFeaturesEbx::RDSEED
|
||||
| ExtendedFeaturesEbx::ADX
|
||||
| ExtendedFeaturesEbx::SMAP
|
||||
| ExtendedFeaturesEbx::CLFLUSHOPT
|
||||
| ExtendedFeaturesEbx::PROCESSOR_TRACE,
|
||||
ecx: ExtendedFeaturesEcx { bits: 0 },
|
||||
edx: 201326592,
|
||||
};
|
||||
|
||||
assert!(tpfeatures2.has_fsgsbase());
|
||||
assert!(tpfeatures2.has_tsc_adjust_msr());
|
||||
assert!(tpfeatures2.has_bmi1());
|
||||
assert!(tpfeatures2.has_avx2());
|
||||
assert!(tpfeatures2.has_smep());
|
||||
assert!(tpfeatures2.has_bmi2());
|
||||
assert!(tpfeatures2.has_rep_movsb_stosb());
|
||||
assert!(tpfeatures2.has_invpcid());
|
||||
assert!(tpfeatures2.has_fpu_cs_ds_deprecated());
|
||||
assert!(tpfeatures2.has_mpx());
|
||||
assert!(tpfeatures2.has_rdseed());
|
||||
assert!(tpfeatures2.has_adx());
|
||||
assert!(tpfeatures2.has_smap());
|
||||
assert!(tpfeatures2.has_clflushopt());
|
||||
assert!(tpfeatures2.has_processor_trace());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn direct_cache_access_info() {
|
||||
let dca = DirectCacheAccessInfo { eax: 0x1 };
|
||||
assert!(dca.get_dca_cap_value() == 0x1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn performance_monitoring_info() {
|
||||
let pm = PerformanceMonitoringInfo {
|
||||
eax: 120587267,
|
||||
ebx: PerformanceMonitoringFeaturesEbx { bits: 0 },
|
||||
ecx: 0,
|
||||
edx: 1539,
|
||||
};
|
||||
|
||||
assert!(pm.version_id() == 3);
|
||||
assert!(pm.number_of_counters() == 4);
|
||||
assert!(pm.counter_bit_width() == 48);
|
||||
assert!(pm.ebx_length() == 7);
|
||||
assert!(pm.fixed_function_counters() == 3);
|
||||
assert!(pm.fixed_function_counters_bit_width() == 48);
|
||||
|
||||
assert!(!pm
|
||||
.ebx
|
||||
.contains(PerformanceMonitoringFeaturesEbx::CORE_CYC_EV_UNAVAILABLE));
|
||||
assert!(!pm
|
||||
.ebx
|
||||
.contains(PerformanceMonitoringFeaturesEbx::INST_RET_EV_UNAVAILABLE));
|
||||
assert!(!pm
|
||||
.ebx
|
||||
.contains(PerformanceMonitoringFeaturesEbx::REF_CYC_EV_UNAVAILABLE));
|
||||
assert!(!pm
|
||||
.ebx
|
||||
.contains(PerformanceMonitoringFeaturesEbx::CACHE_REF_EV_UNAVAILABLE));
|
||||
assert!(!pm
|
||||
.ebx
|
||||
.contains(PerformanceMonitoringFeaturesEbx::LL_CACHE_MISS_EV_UNAVAILABLE));
|
||||
assert!(!pm
|
||||
.ebx
|
||||
.contains(PerformanceMonitoringFeaturesEbx::BRANCH_INST_RET_EV_UNAVAILABLE));
|
||||
assert!(!pm
|
||||
.ebx
|
||||
.contains(PerformanceMonitoringFeaturesEbx::BRANCH_MISPRED_EV_UNAVAILABLE));
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[test]
|
||||
fn extended_topology_info() {
|
||||
let l1 = ExtendedTopologyLevel {
|
||||
eax: 1,
|
||||
ebx: 2,
|
||||
ecx: 256,
|
||||
edx: 3,
|
||||
};
|
||||
let l2 = ExtendedTopologyLevel {
|
||||
eax: 4,
|
||||
ebx: 4,
|
||||
ecx: 513,
|
||||
edx: 3,
|
||||
};
|
||||
|
||||
assert!(l1.processors() == 2);
|
||||
assert!(l1.level_number() == 0);
|
||||
assert!(l1.level_type() == TopologyType::SMT);
|
||||
assert!(l1.x2apic_id() == 3);
|
||||
assert!(l1.shift_right_for_next_apic_id() == 1);
|
||||
|
||||
assert!(l2.processors() == 4);
|
||||
assert!(l2.level_number() == 1);
|
||||
assert!(l2.level_type() == TopologyType::Core);
|
||||
assert!(l2.x2apic_id() == 3);
|
||||
assert!(l2.shift_right_for_next_apic_id() == 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn extended_state_info() {
|
||||
let es = ExtendedStateInfo {
|
||||
eax: ExtendedStateInfoXCR0Flags { bits: 7 },
|
||||
ebx: 832,
|
||||
ecx: 832,
|
||||
edx: 0,
|
||||
eax1: 1,
|
||||
ebx1: 0,
|
||||
ecx1: ExtendedStateInfoXSSFlags { bits: 0 },
|
||||
edx1: 0,
|
||||
};
|
||||
|
||||
assert!(es.xsave_area_size_enabled_features() == 832);
|
||||
assert!(es.xsave_area_size_supported_features() == 832);
|
||||
assert!(es.has_xsaveopt());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn extended_state_info3() {
|
||||
/*let cpuid = CpuId::new();
|
||||
cpuid.get_extended_state_info().map(|info| {
|
||||
println!("{:?}", info);
|
||||
use std::vec::Vec;
|
||||
let es: Vec<ExtendedState> = info.iter().collect();
|
||||
println!("{:?}", es);
|
||||
});*/
|
||||
|
||||
let esi = ExtendedStateInfo {
|
||||
eax: ExtendedStateInfoXCR0Flags::LEGACY_X87
|
||||
| ExtendedStateInfoXCR0Flags::SSE128
|
||||
| ExtendedStateInfoXCR0Flags::AVX256
|
||||
| ExtendedStateInfoXCR0Flags::MPX_BNDREGS
|
||||
| ExtendedStateInfoXCR0Flags::MPX_BNDCSR
|
||||
| ExtendedStateInfoXCR0Flags::AVX512_OPMASK
|
||||
| ExtendedStateInfoXCR0Flags::AVX512_ZMM_HI256
|
||||
| ExtendedStateInfoXCR0Flags::AVX512_ZMM_HI16
|
||||
| ExtendedStateInfoXCR0Flags::PKRU,
|
||||
ebx: 2688,
|
||||
ecx: 2696,
|
||||
edx: 0,
|
||||
eax1: 15,
|
||||
ebx1: 2560,
|
||||
ecx1: ExtendedStateInfoXSSFlags::PT,
|
||||
edx1: 0,
|
||||
};
|
||||
|
||||
assert!(esi.xcr0_supports_legacy_x87());
|
||||
assert!(esi.xcr0_supports_sse_128());
|
||||
assert!(esi.xcr0_supports_avx_256());
|
||||
assert!(esi.xcr0_supports_mpx_bndregs());
|
||||
assert!(esi.xcr0_supports_mpx_bndcsr());
|
||||
assert!(esi.xcr0_supports_avx512_opmask());
|
||||
assert!(esi.xcr0_supports_avx512_zmm_hi256());
|
||||
assert!(esi.xcr0_supports_avx512_zmm_hi16());
|
||||
assert!(esi.xcr0_supports_pkru());
|
||||
assert!(esi.ia32_xss_supports_pt());
|
||||
assert!(!esi.ia32_xss_supports_hdc());
|
||||
|
||||
assert!(esi.xsave_area_size_enabled_features() == 2688);
|
||||
assert!(esi.xsave_area_size_supported_features() == 2696);
|
||||
|
||||
assert!(esi.has_xsaveopt());
|
||||
assert!(esi.has_xsavec());
|
||||
assert!(esi.has_xgetbv());
|
||||
assert!(esi.has_xsaves_xrstors());
|
||||
assert!(esi.xsave_size() == 2560);
|
||||
|
||||
let es = [
|
||||
ExtendedState {
|
||||
subleaf: 2,
|
||||
eax: 256,
|
||||
ebx: 576,
|
||||
ecx: 0,
|
||||
},
|
||||
ExtendedState {
|
||||
subleaf: 3,
|
||||
eax: 64,
|
||||
ebx: 960,
|
||||
ecx: 0,
|
||||
},
|
||||
ExtendedState {
|
||||
subleaf: 4,
|
||||
eax: 64,
|
||||
ebx: 1024,
|
||||
ecx: 0,
|
||||
},
|
||||
ExtendedState {
|
||||
subleaf: 5,
|
||||
eax: 64,
|
||||
ebx: 1088,
|
||||
ecx: 0,
|
||||
},
|
||||
ExtendedState {
|
||||
subleaf: 6,
|
||||
eax: 512,
|
||||
ebx: 1152,
|
||||
ecx: 0,
|
||||
},
|
||||
ExtendedState {
|
||||
subleaf: 7,
|
||||
eax: 1024,
|
||||
ebx: 1664,
|
||||
ecx: 0,
|
||||
},
|
||||
ExtendedState {
|
||||
subleaf: 8,
|
||||
eax: 128,
|
||||
ebx: 0,
|
||||
ecx: 1,
|
||||
},
|
||||
ExtendedState {
|
||||
subleaf: 9,
|
||||
eax: 8,
|
||||
ebx: 2688,
|
||||
ecx: 0,
|
||||
},
|
||||
];
|
||||
|
||||
let e = &es[0];
|
||||
assert!(e.subleaf == 2);
|
||||
assert!(e.size() == 256);
|
||||
assert!(e.offset() == 576);
|
||||
assert!(e.is_in_xcr0());
|
||||
assert!(!e.is_in_ia32_xss());
|
||||
assert!(!e.is_compacted_format());
|
||||
|
||||
let e = &es[1];
|
||||
assert!(e.subleaf == 3);
|
||||
assert!(e.size() == 64);
|
||||
assert!(e.offset() == 960);
|
||||
assert!(e.is_in_xcr0());
|
||||
assert!(!e.is_in_ia32_xss());
|
||||
assert!(!e.is_compacted_format());
|
||||
|
||||
let e = &es[2];
|
||||
assert!(e.subleaf == 4);
|
||||
assert!(e.size() == 64);
|
||||
assert!(e.offset() == 1024);
|
||||
assert!(e.is_in_xcr0());
|
||||
assert!(!e.is_in_ia32_xss());
|
||||
assert!(!e.is_compacted_format());
|
||||
|
||||
let e = &es[3];
|
||||
assert!(e.subleaf == 5);
|
||||
assert!(e.size() == 64);
|
||||
assert!(e.offset() == 1088);
|
||||
assert!(e.is_in_xcr0());
|
||||
assert!(!e.is_in_ia32_xss());
|
||||
assert!(!e.is_compacted_format());
|
||||
|
||||
let e = &es[4];
|
||||
assert!(e.subleaf == 6);
|
||||
assert!(e.size() == 512);
|
||||
assert!(e.offset() == 1152);
|
||||
assert!(e.is_in_xcr0());
|
||||
assert!(!e.is_in_ia32_xss());
|
||||
assert!(!e.is_compacted_format());
|
||||
|
||||
let e = &es[5];
|
||||
assert!(e.subleaf == 7);
|
||||
assert!(e.size() == 1024);
|
||||
assert!(e.offset() == 1664);
|
||||
assert!(e.is_in_xcr0());
|
||||
assert!(!e.is_in_ia32_xss());
|
||||
assert!(!e.is_compacted_format());
|
||||
|
||||
let e = &es[6];
|
||||
assert!(e.subleaf == 8);
|
||||
assert!(e.size() == 128);
|
||||
assert!(e.offset() == 0);
|
||||
assert!(!e.is_in_xcr0());
|
||||
assert!(e.is_in_ia32_xss());
|
||||
assert!(!e.is_compacted_format());
|
||||
|
||||
let e = &es[7];
|
||||
assert!(e.subleaf == 9);
|
||||
assert!(e.size() == 8);
|
||||
assert!(e.offset() == 2688);
|
||||
assert!(e.is_in_xcr0());
|
||||
assert!(!e.is_in_ia32_xss());
|
||||
assert!(!e.is_compacted_format());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn extended_state_info2() {
|
||||
let es = ExtendedStateInfo {
|
||||
eax: ExtendedStateInfoXCR0Flags { bits: 31 },
|
||||
ebx: 1088,
|
||||
ecx: 1088,
|
||||
edx: 0,
|
||||
eax1: 15,
|
||||
ebx1: 960,
|
||||
ecx1: ExtendedStateInfoXSSFlags { bits: 256 },
|
||||
edx1: 0,
|
||||
};
|
||||
|
||||
assert!(es.xcr0_supports_legacy_x87());
|
||||
assert!(es.xcr0_supports_sse_128());
|
||||
assert!(es.xcr0_supports_avx_256());
|
||||
assert!(es.xcr0_supports_mpx_bndregs());
|
||||
assert!(es.xcr0_supports_mpx_bndcsr());
|
||||
assert!(!es.xcr0_supports_avx512_opmask());
|
||||
assert!(!es.xcr0_supports_pkru());
|
||||
assert!(es.ia32_xss_supports_pt());
|
||||
|
||||
assert!(es.xsave_area_size_enabled_features() == 0x440);
|
||||
assert!(es.xsave_area_size_supported_features() == 0x440);
|
||||
|
||||
assert!(es.has_xsaveopt());
|
||||
assert!(es.has_xsavec());
|
||||
assert!(es.has_xgetbv());
|
||||
assert!(es.has_xsaves_xrstors());
|
||||
assert!(es.xsave_size() == 0x3c0);
|
||||
|
||||
let esiter: [ExtendedState; 3] = [
|
||||
ExtendedState {
|
||||
subleaf: 2,
|
||||
eax: 256,
|
||||
ebx: 576,
|
||||
ecx: 0,
|
||||
},
|
||||
ExtendedState {
|
||||
subleaf: 3,
|
||||
eax: 64,
|
||||
ebx: 960,
|
||||
ecx: 0,
|
||||
},
|
||||
ExtendedState {
|
||||
subleaf: 4,
|
||||
eax: 64,
|
||||
ebx: 1024,
|
||||
ecx: 0,
|
||||
},
|
||||
];
|
||||
|
||||
let e = &esiter[0];
|
||||
assert!(e.subleaf == 2);
|
||||
assert!(e.size() == 256);
|
||||
assert!(e.offset() == 576);
|
||||
assert!(e.is_in_xcr0());
|
||||
assert!(!e.is_in_ia32_xss());
|
||||
|
||||
let e = &esiter[1];
|
||||
assert!(e.subleaf == 3);
|
||||
assert!(e.size() == 64);
|
||||
assert!(e.offset() == 960);
|
||||
assert!(e.is_in_xcr0());
|
||||
assert!(!e.is_in_ia32_xss());
|
||||
|
||||
let e = &esiter[2];
|
||||
assert!(e.subleaf == 4);
|
||||
assert!(e.size() == 64);
|
||||
assert!(e.offset() == 1024);
|
||||
assert!(e.is_in_xcr0());
|
||||
assert!(!e.is_in_ia32_xss());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn quality_of_service_info() {
|
||||
let qos = RdtMonitoringInfo { ebx: 832, edx: 0 };
|
||||
|
||||
assert!(qos.rmid_range() == 832);
|
||||
assert!(!qos.has_l3_monitoring());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn extended_functions() {
|
||||
let ef = ExtendedFunctionInfo {
|
||||
max_eax_value: 8,
|
||||
data: [
|
||||
CpuIdResult {
|
||||
eax: 2147483656,
|
||||
ebx: 0,
|
||||
ecx: 0,
|
||||
edx: 0,
|
||||
},
|
||||
CpuIdResult {
|
||||
eax: 0,
|
||||
ebx: 0,
|
||||
ecx: 1,
|
||||
edx: 672139264,
|
||||
},
|
||||
CpuIdResult {
|
||||
eax: 538976288,
|
||||
ebx: 1226842144,
|
||||
ecx: 1818588270,
|
||||
edx: 539578920,
|
||||
},
|
||||
CpuIdResult {
|
||||
eax: 1701998403,
|
||||
ebx: 692933672,
|
||||
ecx: 758475040,
|
||||
edx: 926102323,
|
||||
},
|
||||
CpuIdResult {
|
||||
eax: 1346576469,
|
||||
ebx: 541073493,
|
||||
ecx: 808988209,
|
||||
edx: 8013895,
|
||||
},
|
||||
CpuIdResult {
|
||||
eax: 0,
|
||||
ebx: 0,
|
||||
ecx: 0,
|
||||
edx: 0,
|
||||
},
|
||||
CpuIdResult {
|
||||
eax: 0,
|
||||
ebx: 0,
|
||||
ecx: 16801856,
|
||||
edx: 0,
|
||||
},
|
||||
CpuIdResult {
|
||||
eax: 0,
|
||||
ebx: 0,
|
||||
ecx: 0,
|
||||
edx: 256,
|
||||
},
|
||||
CpuIdResult {
|
||||
eax: 12324,
|
||||
ebx: 0,
|
||||
ecx: 0,
|
||||
edx: 0,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
ef.processor_brand_string().unwrap(),
|
||||
" Intel(R) Core(TM) i5-3337U CPU @ 1.80GHz"
|
||||
);
|
||||
assert!(ef.has_lahf_sahf());
|
||||
assert!(!ef.has_lzcnt());
|
||||
assert!(!ef.has_prefetchw());
|
||||
assert!(ef.has_syscall_sysret());
|
||||
assert!(ef.has_execute_disable());
|
||||
assert!(!ef.has_1gib_pages());
|
||||
assert!(ef.has_rdtscp());
|
||||
assert!(ef.has_64bit_mode());
|
||||
assert!(ef.has_invariant_tsc());
|
||||
|
||||
assert!(ef.extended_signature().unwrap() == 0x0);
|
||||
assert!(ef.cache_line_size().unwrap() == 64);
|
||||
assert!(ef.l2_associativity().unwrap() == L2Associativity::EightWay);
|
||||
assert!(ef.cache_size().unwrap() == 256);
|
||||
assert!(ef.physical_address_bits().unwrap() == 36);
|
||||
assert!(ef.linear_address_bits().unwrap() == 48);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[test]
|
||||
fn sgx_test() {
|
||||
let sgx = SgxInfo {
|
||||
eax: 1,
|
||||
ebx: 0,
|
||||
ecx: 0,
|
||||
edx: 9247,
|
||||
eax1: 54,
|
||||
ebx1: 0,
|
||||
ecx1: 31,
|
||||
edx1: 0,
|
||||
};
|
||||
|
||||
assert!(sgx.max_enclave_size_64bit() == 0x24);
|
||||
assert!(sgx.max_enclave_size_non_64bit() == 0x1f);
|
||||
assert!(sgx.has_sgx1());
|
||||
assert!(!sgx.has_sgx2());
|
||||
assert!(sgx.miscselect() == 0x0);
|
||||
assert!(sgx.secs_attributes() == (0x0000000000000036, 0x000000000000001f));
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[test]
|
||||
fn readme_test() {
|
||||
// let cpuid = CpuId::new();
|
||||
//
|
||||
// match cpuid.get_vendor_info() {
|
||||
// Some(vf) => assert!(vf.as_string() == "GenuineIntel"),
|
||||
// None => ()
|
||||
// }
|
||||
//
|
||||
// let has_sse = match cpuid.get_feature_info() {
|
||||
// Some(finfo) => finfo.has_sse(),
|
||||
// None => false
|
||||
// };
|
||||
//
|
||||
// if has_sse {
|
||||
// println!("CPU supports SSE!");
|
||||
// }
|
||||
//
|
||||
// match cpuid.get_cache_parameters() {
|
||||
// Some(cparams) => {
|
||||
// for cache in cparams {
|
||||
// let size = cache.associativity() * cache.physical_line_partitions() * cache.coherency_line_size() * cache.sets();
|
||||
// println!("L{}-Cache size is {}", cache.level(), size);
|
||||
// }
|
||||
// },
|
||||
// None => println!("No cache parameter information available"),
|
||||
// }
|
||||
//
|
||||
}
|
||||
|
||||
/*
|
||||
extern crate serde_json;
|
||||
|
||||
#[cfg(test)]
|
||||
#[test]
|
||||
fn test_serializability() {
|
||||
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||
struct SerializeDeserializeTest {
|
||||
_x1: CpuId,
|
||||
_x2: CpuIdResult,
|
||||
_x3: VendorInfo,
|
||||
_x4: CacheInfoIter,
|
||||
_x5: CacheInfo,
|
||||
_x6: ProcessorSerial,
|
||||
_x7: FeatureInfo,
|
||||
_x8: CacheParametersIter,
|
||||
_x9: CacheParameter,
|
||||
_x10: MonitorMwaitInfo,
|
||||
_x11: ThermalPowerInfo,
|
||||
_x12: ExtendedFeatures,
|
||||
_x13: DirectCacheAccessInfo,
|
||||
_x14: PerformanceMonitoringInfo,
|
||||
_x15: ExtendedTopologyIter,
|
||||
_x16: ExtendedTopologyLevel,
|
||||
_x17: ExtendedStateInfo,
|
||||
_x18: ExtendedStateIter,
|
||||
_x19: ExtendedState,
|
||||
_x20: RdtAllocationInfo,
|
||||
_x21: RdtMonitoringInfo,
|
||||
_x22: L3CatInfo,
|
||||
_x23: L2CatInfo,
|
||||
_x24: ProcessorTraceInfo,
|
||||
_x25: ProcessorTraceIter,
|
||||
_x26: ProcessorTrace,
|
||||
_x27: TscInfo,
|
||||
_x28: ProcessorFrequencyInfo,
|
||||
_x29: SoCVendorInfo,
|
||||
_x30: SoCVendorAttributesIter,
|
||||
_x31: SoCVendorBrand,
|
||||
_x32: ExtendedFunctionInfo,
|
||||
_x33: MemBwAllocationInfo,
|
||||
_x34: L3MonitoringInfo,
|
||||
_x35: SgxSectionInfo,
|
||||
_x36: EpcSection,
|
||||
_x37: SgxInfo,
|
||||
_x38: SgxSectionIter,
|
||||
_x39: DatInfo,
|
||||
_x40: DatIter,
|
||||
_x41: DatType,
|
||||
}
|
||||
|
||||
let st: SerializeDeserializeTest = Default::default();
|
||||
let test = serde_json::to_string(&st).unwrap();
|
||||
let _st: SerializeDeserializeTest = serde_json::from_str(&test).unwrap();
|
||||
}*/
|
|
@ -1 +1 @@
|
|||
{"files":{".clang-format":"ff4e345608f7674dd1ee1f37b24d4030b260d82516a747093af141b3076a4164",".clang-tidy":"861bc5b367dc85f5fa103f2de9460e158de97f48c59c51a26784b7c2c481e3b7","CMakeLists.txt":"36037a5fb56279891de224657a92705dab8e9ea248883f7373761a477d0c128a","Cargo.toml":"c4b37b1c6fc94626cfc44a935268110af90d8f750b05879d1723804a7fec2e6a","LICENSE":"891d419ba95ab39090775820f4178421dbdcd241c080003aa44f62445a48615a","README.md":"3f19110120d1b6b9de0d879183f1968a6f2e597bf86c84394a496b20245afb5b","c_src/CMakeLists.txt":"ba917a45a37dc9b8b5a7b6f314ccaa4e5117407886945e6e8508f008e6348a98","c_src/lucet_sandbox_wrapper.c":"08b2ab265127aca42b02c8a36e5450284d6794d86867a5808f854588183ab9d9","include/lucet_sandbox.h":"8d4fd6e15c645d7f785eb66bd580774229fffb77908419d28acb947d0893e3e0","include/rlbox_lucet_sandbox.hpp":"b8a4b86460e9b666ec92bf23db37578639a368005ccf4aa722032aaca8ae59db","src/callback.rs":"c40f92e017bc8f2f3136304c1f2d3ca683fe80a1bb505c0fa750cc372305020d","src/create.rs":"25b7920e894209bdaf5029a05b51615d862fa42fafa63de0a6ed27dd1d30dd3b","src/invoke.rs":"d47b167c6048a3221f5e66a4acb5154bc5306bd1053acee56bfb87bb66c78879","src/lib.rs":"677f45b275101c116ea7acf2dafa77f9f1c5e3f379d4da3a9512c71a71878595","src/memory.rs":"8b27396ec4ddba18ac760052e9d11564fdc8c4e68271b817dfd13cefc97cf1a3","src/types.rs":"85907840c233aae0e234bcb5c1e107e76231b6518cc70a1c18be73edc2720742","test/test_lucet_sandbox_glue.cpp":"ea4eb3ace8e9a87550db44f61d065b45f31f1f5b774b4a3e0383e62962c0abf2","test/test_lucet_sandbox_glue_embedder_vars.cpp":"be6abfae367719b12edc5fd8f1de840abed9bb4a2efdebb19ed59e8796fb47b8","test/test_lucet_sandbox_glue_main.cpp":"fde2081cd8b0df3fd73fee1e36dfa5eccfb5bc825072c55a57fcf3048858dbd9","test/test_lucet_sandbox_glue_preload.cpp":"c986ac617327305fcc3ea33114667d4c833ee685c740e482ffde97de4f203e35"},"package":null}
|
||||
{"files":{".clang-format":"ff4e345608f7674dd1ee1f37b24d4030b260d82516a747093af141b3076a4164",".clang-tidy":"861bc5b367dc85f5fa103f2de9460e158de97f48c59c51a26784b7c2c481e3b7",".travis.yml":"a49b61a394520c39bb20c420b587e92ea9c8008764fef0368c4747b71b8f1561","CMakeLists.txt":"be1746d5161db062c96ec2f2060a514229498c0fa7cf20d5ae01e81736320681","Cargo.toml":"7ef6f859045c28f6adcf30b35d6664761aa543faf090165375e3e43ab4b52719","LICENSE":"891d419ba95ab39090775820f4178421dbdcd241c080003aa44f62445a48615a","README.md":"53315d2de00f7a8e932af5ad3267bf56027d22790bb09182e250b9b35fbe0758","c_src/CMakeLists.txt":"41f6338bb8aef5c0a7a6db53f3ed699ae027f0c008e67c9bb344fe0b75513d3f","c_src/lucet_sandbox_wrapper.c":"08b2ab265127aca42b02c8a36e5450284d6794d86867a5808f854588183ab9d9","include/lucet_sandbox.h":"8d24bd5fbd4f717f0bb90b238a7b7fbdd212207297ddf1a723cc98ee13180c5b","include/rlbox_lucet_sandbox.hpp":"b8a4b86460e9b666ec92bf23db37578639a368005ccf4aa722032aaca8ae59db","src/callback.rs":"c40f92e017bc8f2f3136304c1f2d3ca683fe80a1bb505c0fa750cc372305020d","src/create.rs":"5d620a050c1990e7215346fe144a7be7c0e4bb396068ac81ae8b21fb1fdb3dca","src/invoke.rs":"d47b167c6048a3221f5e66a4acb5154bc5306bd1053acee56bfb87bb66c78879","src/lib.rs":"677f45b275101c116ea7acf2dafa77f9f1c5e3f379d4da3a9512c71a71878595","src/memory.rs":"8b27396ec4ddba18ac760052e9d11564fdc8c4e68271b817dfd13cefc97cf1a3","src/types.rs":"85907840c233aae0e234bcb5c1e107e76231b6518cc70a1c18be73edc2720742","test/test_lucet_sandbox_glue.cpp":"ea4eb3ace8e9a87550db44f61d065b45f31f1f5b774b4a3e0383e62962c0abf2","test/test_lucet_sandbox_glue_embedder_vars.cpp":"be6abfae367719b12edc5fd8f1de840abed9bb4a2efdebb19ed59e8796fb47b8","test/test_lucet_sandbox_glue_main.cpp":"fde2081cd8b0df3fd73fee1e36dfa5eccfb5bc825072c55a57fcf3048858dbd9","test/test_lucet_sandbox_glue_preload.cpp":"c986ac617327305fcc3ea33114667d4c833ee685c740e482ffde97de4f203e35"},"package":null}
|
|
@ -0,0 +1,12 @@
|
|||
dist: bionic
|
||||
language: rust
|
||||
|
||||
script:
|
||||
# Install a more recent cmake
|
||||
- wget https://cmake.org/files/v3.16/cmake-3.16.0-Linux-x86_64.tar.gz
|
||||
- tar xzvf cmake-3.16.0-Linux-x86_64.tar.gz
|
||||
- mkdir ./build
|
||||
- cd ./build
|
||||
- ../cmake-3.16.0-Linux-x86_64/bin/cmake -S ..
|
||||
- make
|
||||
- make test
|
|
@ -45,8 +45,8 @@ if(DEV)
|
|||
add_compile_options(-Werror) # warnings as errors
|
||||
add_compile_options(-fsanitize=address)
|
||||
add_link_options(-fsanitize=address)
|
||||
# add_compile_options(-fsanitize=undefined)
|
||||
# add_link_options(-fsanitize=undefined)
|
||||
add_compile_options(-fsanitize=undefined)
|
||||
add_link_options(-fsanitize=undefined)
|
||||
endif()
|
||||
|
||||
find_program(CLANG_TIDY "clang-tidy")
|
||||
|
@ -83,7 +83,7 @@ FetchContent_Declare(
|
|||
rlbox
|
||||
GIT_REPOSITORY https://github.com/PLSysSec/rlbox_api_cpp17.git)
|
||||
FetchContent_GetProperties(rlbox)
|
||||
if(NOT catch2_POPULATED)
|
||||
if(NOT rlbox_POPULATED)
|
||||
FetchContent_Populate(rlbox)
|
||||
endif()
|
||||
|
||||
|
@ -98,11 +98,19 @@ endif()
|
|||
add_subdirectory("${catch2_SOURCE_DIR}")
|
||||
list(APPEND CMAKE_MODULE_PATH "${catch2_SOURCE_DIR}/contrib")
|
||||
|
||||
FetchContent_Declare(
|
||||
wasiclang
|
||||
URL
|
||||
https://github.com/CraneStation/wasi-sdk/releases/download/wasi-sdk-6/wasi-sdk-6.0-linux.tar.gz
|
||||
)
|
||||
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||
FetchContent_Declare(
|
||||
wasiclang
|
||||
URL
|
||||
https://github.com/CraneStation/wasi-sdk/releases/download/wasi-sdk-6/wasi-sdk-6.0-macos.tar.gz
|
||||
)
|
||||
else()
|
||||
FetchContent_Declare(
|
||||
wasiclang
|
||||
URL
|
||||
https://github.com/CraneStation/wasi-sdk/releases/download/wasi-sdk-6/wasi-sdk-6.0-linux.tar.gz
|
||||
)
|
||||
endif()
|
||||
FetchContent_GetProperties(wasiclang)
|
||||
if(NOT wasiclang_POPULATED)
|
||||
FetchContent_Populate(wasiclang)
|
||||
|
@ -118,6 +126,11 @@ endif()
|
|||
|
||||
# Rust Lib ###################
|
||||
|
||||
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||
set(DYLIB_EXT "dylib")
|
||||
else()
|
||||
set(DYLIB_EXT "so")
|
||||
endif()
|
||||
set(LUCET_DIR "${CMAKE_BINARY_DIR}/cargo/release/")
|
||||
set(LUCET_PATH "${LUCET_DIR}/lucetc")
|
||||
file(GLOB_RECURSE LUCET_SOURCE_FILES ${mod_lucet_SOURCE_DIR}/*.rs ${mod_lucet_SOURCE_DIR}/*.S)
|
||||
|
@ -139,11 +152,8 @@ add_custom_target(lucet_release ALL DEPENDS ${LUCET_PATH})
|
|||
|
||||
file(GLOB_RECURSE RUST_SOURCE_FILES src/*.rs)
|
||||
|
||||
# Use the dynamic library as wasi symbols needed by the wasm module are hosted
|
||||
# in it. If we include the static version, we need to make the main executable
|
||||
# expose symbols through rdynamic
|
||||
set(RUST_LIB_DEBUG_PATH
|
||||
"${CMAKE_BINARY_DIR}/cargo/debug/librlbox_lucet_sandbox.so")
|
||||
"${CMAKE_BINARY_DIR}/cargo/debug/librlbox_lucet_sandbox.a")
|
||||
add_custom_command(OUTPUT ${RUST_LIB_DEBUG_PATH}
|
||||
DEPENDS ${RUST_SOURCE_FILES} ${LUCET_SOURCE_FILES} Cargo.toml
|
||||
COMMAND CARGO_TARGET_DIR=${CMAKE_BINARY_DIR}/cargo ${CARGO}
|
||||
|
@ -153,7 +163,7 @@ add_custom_target(lucet_sandbox_rustlib_debug ALL
|
|||
DEPENDS ${RUST_LIB_DEBUG_PATH})
|
||||
|
||||
set(RUST_LIB_RELEASE_PATH
|
||||
"${CMAKE_BINARY_DIR}/cargo/release/librlbox_lucet_sandbox.so")
|
||||
"${CMAKE_BINARY_DIR}/cargo/release/librlbox_lucet_sandbox.a")
|
||||
add_custom_command(OUTPUT ${RUST_LIB_RELEASE_PATH}
|
||||
DEPENDS ${RUST_SOURCE_FILES} ${LUCET_SOURCE_FILES} Cargo.toml
|
||||
COMMAND CARGO_TARGET_DIR=${CMAKE_BINARY_DIR}/cargo
|
||||
|
@ -172,7 +182,14 @@ set_target_properties(lucet_sandbox_rustlib
|
|||
set_target_properties(lucet_sandbox_rustlib
|
||||
PROPERTIES IMPORTED_LOCATION_RELEASE
|
||||
${RUST_LIB_RELEASE_PATH})
|
||||
|
||||
# The wasi symbols needed by the wasm module are in this static lib, but must
|
||||
# be part of the symbol table (locatable through dlsym). We need the following
|
||||
# flag for this.
|
||||
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||
target_link_options(lucet_sandbox_rustlib INTERFACE "-framework" "Security" "-rdynamic")
|
||||
else()
|
||||
target_link_options(lucet_sandbox_rustlib INTERFACE "-rdynamic")
|
||||
endif()
|
||||
# Tests ###################
|
||||
|
||||
include(CTest)
|
||||
|
@ -189,7 +206,7 @@ endif()
|
|||
|
||||
file(GLOB_RECURSE C_SOURCE_FILES c_src/*)
|
||||
set(GLUE_LIB_WASM "${CMAKE_BINARY_DIR}/wasm/glue_lib_lucet.wasm")
|
||||
set(GLUE_LIB_SO "${CMAKE_BINARY_DIR}/wasm/glue_lib_lucet.so")
|
||||
set(GLUE_LIB_SO "${CMAKE_BINARY_DIR}/wasm/glue_lib_lucet.${DYLIB_EXT}")
|
||||
|
||||
add_custom_command(OUTPUT ${GLUE_LIB_WASM} ${GLUE_LIB_SO}
|
||||
DEPENDS ${C_SOURCE_FILES}
|
||||
|
@ -198,20 +215,20 @@ add_custom_command(OUTPUT ${GLUE_LIB_WASM} ${GLUE_LIB_SO}
|
|||
wasiclang_SOURCE_DIR=${wasiclang_SOURCE_DIR}
|
||||
LUCET_DIR=${LUCET_DIR}
|
||||
LUCET_WASI_DIR=${mod_lucet_SOURCE_DIR}/lucet-wasi
|
||||
cmake
|
||||
${CMAKE_COMMAND}
|
||||
-S
|
||||
.
|
||||
-B
|
||||
${CMAKE_BINARY_DIR}/wasm
|
||||
COMMAND VERBOSE=1
|
||||
cmake
|
||||
${CMAKE_COMMAND}
|
||||
--build
|
||||
${CMAKE_BINARY_DIR}/wasm
|
||||
--target
|
||||
all
|
||||
COMMENT "Building wasm library")
|
||||
|
||||
add_custom_target(glue_lib_wasm ALL DEPENDS ${GLUE_LIB_WASM} ${GLUE_LIB_SO})
|
||||
add_custom_target(glue_lib_wasm ALL DEPENDS lucet_release ${GLUE_LIB_WASM} ${GLUE_LIB_SO})
|
||||
|
||||
add_executable(test_rlbox_glue test/test_lucet_sandbox_glue_main.cpp
|
||||
test/test_lucet_sandbox_glue.cpp
|
||||
|
@ -230,6 +247,8 @@ find_package(Threads REQUIRED)
|
|||
target_compile_definitions(test_rlbox_glue PUBLIC
|
||||
GLUE_LIB_LUCET_PATH="${GLUE_LIB_SO}")
|
||||
|
||||
add_dependencies(test_rlbox_glue lucet_sandbox_rustlib_debug lucet_sandbox_rustlib_release)
|
||||
|
||||
target_link_libraries(test_rlbox_glue
|
||||
Catch2::Catch2
|
||||
lucet_sandbox_rustlib
|
||||
|
@ -238,7 +257,7 @@ target_link_libraries(test_rlbox_glue
|
|||
# glue_lib_lucet
|
||||
)
|
||||
|
||||
if(UNIX)
|
||||
if(UNIX AND NOT (${CMAKE_SYSTEM_NAME} MATCHES "Darwin"))
|
||||
target_link_libraries(test_rlbox_glue rt)
|
||||
endif()
|
||||
catch_discover_tests(test_rlbox_glue)
|
||||
|
|
|
@ -8,10 +8,10 @@ license = "MIT"
|
|||
[dependencies]
|
||||
failure = ">=0.1.3" # Experimental error handling abstraction.
|
||||
goblin = ">=0.0.17" # An impish, cross-platform, ELF, Mach-o, and PE binary parsing and loading crate
|
||||
lucet-wasi = { git = "https://github.com/PLSysSec/lucet_sandbox_compiler", rev="58498599272e23ef797bb4304d0f181d7455ca57" }
|
||||
lucet-runtime = { git = "https://github.com/PLSysSec/lucet_sandbox_compiler", rev="58498599272e23ef797bb4304d0f181d7455ca57" }
|
||||
lucet-runtime-internals = { git = "https://github.com/PLSysSec/lucet_sandbox_compiler", rev="58498599272e23ef797bb4304d0f181d7455ca57" }
|
||||
lucet-module = { git = "https://github.com/PLSysSec/lucet_sandbox_compiler", rev="58498599272e23ef797bb4304d0f181d7455ca57" }
|
||||
lucet-wasi = { git = "https://github.com/PLSysSec/lucet_sandbox_compiler", rev="a3fd180d53a6f929a7ef47466ffc2e53338ad4f1" }
|
||||
lucet-runtime = { git = "https://github.com/PLSysSec/lucet_sandbox_compiler", rev="a3fd180d53a6f929a7ef47466ffc2e53338ad4f1" }
|
||||
lucet-runtime-internals = { git = "https://github.com/PLSysSec/lucet_sandbox_compiler", rev="a3fd180d53a6f929a7ef47466ffc2e53338ad4f1" }
|
||||
lucet-module = { git = "https://github.com/PLSysSec/lucet_sandbox_compiler", rev="a3fd180d53a6f929a7ef47466ffc2e53338ad4f1" }
|
||||
# lucet-wasi = { path = "../lucet_sandbox_compiler/lucet-wasi" }
|
||||
# lucet-runtime = { path = "../lucet_sandbox_compiler/lucet-runtime" }
|
||||
# lucet-runtime-internals = { path = "../lucet_sandbox_compiler/lucet-runtime/lucet-runtime-internals" }
|
||||
|
@ -19,4 +19,4 @@ lucet-module = { git = "https://github.com/PLSysSec/lucet_sandbox_compiler", rev
|
|||
|
||||
[lib]
|
||||
name = "rlbox_lucet_sandbox"
|
||||
crate-type = ["rlib", "staticlib", "cdylib"]
|
||||
crate-type = ["rlib", "staticlib"]
|
|
@ -1,9 +1,16 @@
|
|||
[![Build Status](https://travis-ci.com/PLSysSec/rlbox_lucet_sandbox.svg?branch=master)](https://travis-ci.com/PLSysSec/rlbox_lucet_sandbox)
|
||||
|
||||
# RLBOX Lucet Sandbox Integration
|
||||
Integration with RLBox sandboxing API to leverage the sandboxing in WASM modules compiled with lucet compiler.
|
||||
|
||||
For details about the RLBox sandboxing APIs, see [here](https://github.com/PLSysSec/rlbox_api_cpp17).
|
||||
|
||||
Currently lucet supports only Linux x64, therefore this repo will only work in this environment.
|
||||
This code has been tested on 64-bit versions of Ubuntu and Mac OSX.
|
||||
The lucet compiler does not currently support Windows.
|
||||
|
||||
## Reporting security bugs
|
||||
|
||||
If you find a security bug, please do not create a public issue. Instead, file a security bug on bugzilla using the [following template link](https://bugzilla.mozilla.org/enter_bug.cgi?cc=tom%40mozilla.com&cc=nfroyd%40mozilla.com&cc=deian%40cs.ucsd.edu&cc=shravanrn%40gmail.com&component=Security%3A%20Process%20Sandboxing&defined_groups=1&groups=core-security&product=Core&bug_type=defect).
|
||||
|
||||
## Building/Running the tests
|
||||
|
||||
|
@ -15,6 +22,8 @@ cmake --build ./build --target all
|
|||
cmake --build ./build --target test
|
||||
```
|
||||
|
||||
On Arch Linux you'll need to install [ncurses5-compat-libs](https://aur.archlinux.org/packages/ncurses5-compat-libs/).
|
||||
|
||||
## Using this library
|
||||
|
||||
First, build the rlbox_lucet_sandbox repo with
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
cmake_minimum_required(VERSION 3.13)
|
||||
|
||||
# Mac adds extra flags
|
||||
set(HAVE_FLAG_SEARCH_PATHS_FIRST 0)
|
||||
|
||||
project(rlbox_lucet_testlib
|
||||
VERSION 0.1
|
||||
DESCRIPTION "RLBox integration with WASM modules compiled with lucet")
|
||||
|
@ -32,13 +35,20 @@ set(CMAKE_BUILD_TYPE Release)
|
|||
# Apply settings suitable for wasm module compilation
|
||||
set(CMAKE_C_FLAGS
|
||||
"--sysroot ${wasiclang_SOURCE_DIR}/opt/wasi-sdk/share/wasi-sysroot/")
|
||||
# Link flags are set by default on Mac - clearing this
|
||||
set(CMAKE_C_LINK_FLAGS "")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "-Wl,--export-all")
|
||||
|
||||
add_executable(glue_lib_lucet.wasm
|
||||
lucet_sandbox_wrapper.c
|
||||
${rlbox_SOURCE_DIR}/code/tests/rlbox_glue/lib/libtest.c)
|
||||
|
||||
set(GLUE_LIB_PATH "${CMAKE_BINARY_DIR}/glue_lib_lucet.so")
|
||||
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||
set(DYLIB_EXT "dylib")
|
||||
else()
|
||||
set(DYLIB_EXT "so")
|
||||
endif()
|
||||
set(GLUE_LIB_PATH "${CMAKE_BINARY_DIR}/glue_lib_lucet.${DYLIB_EXT}")
|
||||
|
||||
add_custom_command(OUTPUT ${GLUE_LIB_PATH}
|
||||
DEPENDS glue_lib_lucet.wasm
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
#ifndef LUCET_SANDBOX_H
|
||||
#define LUCET_SANDBOX_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
struct LucetSandboxInstance;
|
||||
typedef struct LucetSandboxInstance LucetSandboxInstance;
|
||||
|
||||
|
|
|
@ -62,6 +62,7 @@ fn lucet_load_module_helper(module_path: &String, allow_stdio: bool) -> Result<L
|
|||
heap_address_space_size: 8 * 1024 * 1024 * 1024, // 8GB
|
||||
stack_size: 8 * 1024 * 1024, // 8MB - pthread default
|
||||
globals_size: globals_size,
|
||||
..Limits::default()
|
||||
},
|
||||
4 * 1024 * 1024 * 1024, // 4GB heap alignment
|
||||
)?;
|
||||
|
|
Загрузка…
Ссылка в новой задаче