Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Serial-ATA committed Dec 29, 2024
1 parent dfa159d commit 3da5375
Show file tree
Hide file tree
Showing 14 changed files with 417 additions and 440 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ symbols = { path = "symbols" }
byteorder = "1.5.0"
byte-slice-cast = "1.2.2"
cesu8 = "1.1.0"
cfg-if = "1.0.0"
const_format = "0.2.33"
libc = "0.2"
libloading = "0.8.5"
Expand Down
1 change: 1 addition & 0 deletions platform/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
cfg-if.workspace = true
libc.workspace = true

[target.'cfg(target_family = "windows")'.dependencies]
Expand Down
24 changes: 9 additions & 15 deletions platform/src/arch/mod.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
use crate::macros::match_cfg_meta;

match_cfg_meta! {
match cfg(target_arch) {
"x86" => {
mod x86;
pub use x86::*;
},
"x86_64" => {
mod x86;
pub use x86::*;
},
_ => {
compile_error!("target architecture is not supported!");
}
cfg_if::cfg_if! {
if #[cfg(target_arch = "x86")] {
mod x86;
pub use x86::*;
} else if #[cfg(target_arch = "x86_64")] {
mod x86;
pub use x86::*;
} else {
compile_error!("target architecture is not supported!");
}
}
1 change: 1 addition & 0 deletions platform/src/arch/x86/features.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

28 changes: 19 additions & 9 deletions platform/src/arch/x86/ordering.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,38 @@
#![cfg_attr(rustfmt, rustfmt_skip)]

#[inline(always)]
unsafe fn compiler_barrier() {
// Create a compiler barrier to prevent instruction reordering
core::arch::asm!("", options(nomem))
}

#[inline(always)]
pub fn loadload() { unsafe { compiler_barrier() } }
pub fn loadload() {
unsafe { compiler_barrier() }
}

#[inline(always)]
pub fn storestore() { unsafe { compiler_barrier() } }
pub fn storestore() {
unsafe { compiler_barrier() }
}

#[inline(always)]
pub fn loadstore() { unsafe { compiler_barrier() } }
pub fn loadstore() {
unsafe { compiler_barrier() }
}

#[inline(always)]
pub fn storeload() { fence() }
pub fn storeload() {
fence()
}

#[inline(always)]
pub fn acquire() { unsafe { compiler_barrier() } }
pub fn acquire() {
unsafe { compiler_barrier() }
}

#[inline(always)]
pub fn release() { unsafe { compiler_barrier() } }
pub fn release() {
unsafe { compiler_barrier() }
}

#[cfg(target_arch = "x86")]
#[inline(always)]
Expand All @@ -48,7 +58,7 @@ pub fn fence() {
options(nomem, preserves_flags, att_syntax)
)
}

unsafe { compiler_barrier() }
}

Expand Down
28 changes: 11 additions & 17 deletions platform/src/family/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,18 @@ pub use signals::*;

pub mod properties;

use crate::macros::match_cfg_meta;

// `target_family` specific exports

match_cfg_meta! {
match cfg(target_family) {
"unix" => {
mod unix;
pub use unix::*;
pub use unix::signals::*;
},
"windows" => {
mod windows;
pub use windows::*;
pub use windows::signals::*;
},
_ => {
compile_error!("target family is not supported!");
}
cfg_if::cfg_if! {
if #[cfg(unix)] {
mod unix;
pub use unix::*;
pub use unix::signals::*;
} else if #[cfg(windows)] {
mod windows;
pub use windows::*;
pub use windows::signals::*;
} else {
compile_error!("target family is not supported!");
}
}
197 changes: 100 additions & 97 deletions platform/src/family/properties.rs
Original file line number Diff line number Diff line change
@@ -1,128 +1,131 @@
#![cfg_attr(rustfmt, rustfmt_skip)]
use std::fmt::{Display, Formatter};

// Properties shared between all `target_family`s

pub const CPU_ENDIAN: &str = if cfg!(target_endian = "big") { "big" } else { "little" };
pub const CPU_ENDIAN: &str = if cfg!(target_endian = "big") {
"big"
} else {
"little"
};

// TODO: Document
// TODO: Probably make all fields `Option`, to avoid setting empty values at runtime
#[allow(non_snake_case)]
pub struct PropertySet {
pub display_country: String,
pub display_language: String,
pub display_script: String,
pub display_variant: String,
pub file_encoding: String,
pub file_separator: String,
pub format_country: String,
pub format_language: String,
pub format_script: String,
pub format_variant: String,
pub ftp_nonProxyHosts: Option<String>,
pub ftp_proxyHost: Option<String>,
pub ftp_proxyPort: Option<String>,
pub http_nonProxyHosts: Option<String>,
pub http_proxyHost: Option<String>,
pub http_proxyPort: Option<String>,
pub https_proxyHost: Option<String>,
pub https_proxyPort: Option<String>,
pub java_io_tmpdir: String,
pub line_separator: String,
pub os_arch: String,
pub os_name: String,
pub os_version: String,
pub path_separator: String,
pub socksNonProxyHosts: Option<String>,
pub socksProxyHost: Option<String>,
pub socksProxyPort: Option<String>,
pub stderr_encoding: Option<String>,
pub stdout_encoding: Option<String>,
pub sun_arch_abi: Option<String>,
pub sun_arch_data_model: String,
pub sun_cpu_endian: String,
pub sun_cpu_isalist: Option<String>,
pub sun_io_unicode_encoding: String,
pub sun_jnu_encoding: String,
pub sun_os_patch_level: String,
pub user_dir: String,
pub user_home: String,
pub user_name: String,
pub display_country: String,
pub display_language: String,
pub display_script: String,
pub display_variant: String,
pub file_encoding: String,
pub file_separator: String,
pub format_country: String,
pub format_language: String,
pub format_script: String,
pub format_variant: String,
pub ftp_nonProxyHosts: Option<String>,
pub ftp_proxyHost: Option<String>,
pub ftp_proxyPort: Option<String>,
pub http_nonProxyHosts: Option<String>,
pub http_proxyHost: Option<String>,
pub http_proxyPort: Option<String>,
pub https_proxyHost: Option<String>,
pub https_proxyPort: Option<String>,
pub java_io_tmpdir: String,
pub line_separator: String,
pub os_arch: String,
pub os_name: String,
pub os_version: String,
pub path_separator: String,
pub socksNonProxyHosts: Option<String>,
pub socksProxyHost: Option<String>,
pub socksProxyPort: Option<String>,
pub stderr_encoding: Option<String>,
pub stdout_encoding: Option<String>,
pub sun_arch_abi: Option<String>,
pub sun_arch_data_model: String,
pub sun_cpu_endian: String,
pub sun_cpu_isalist: Option<String>,
pub sun_io_unicode_encoding: String,
pub sun_jnu_encoding: String,
pub sun_os_patch_level: String,
pub user_dir: String,
pub user_home: String,
pub user_name: String,
}

impl PropertySet {
pub fn fill(&mut self) -> Result<(), Error> {
fill_properties_impl(self)
}
pub fn fill(&mut self) -> Result<(), Error> {
fill_properties_impl(self)
}
}

impl Default for PropertySet {
fn default() -> Self {
PropertySet {
// Set the constant properties, exported below
file_separator: FILE_SEPARATOR.into(),
line_separator: LINE_SEPARATOR.into(),
os_arch: OS_ARCH.into(),
path_separator: PATH_SEPARATOR.into(),
sun_cpu_endian: CPU_ENDIAN.into(),
sun_io_unicode_encoding: UNICODE_ENCODING.into(),
fn default() -> Self {
PropertySet {
// Set the constant properties, exported below
file_separator: FILE_SEPARATOR.into(),
line_separator: LINE_SEPARATOR.into(),
os_arch: OS_ARCH.into(),
path_separator: PATH_SEPARATOR.into(),
sun_cpu_endian: CPU_ENDIAN.into(),
sun_io_unicode_encoding: UNICODE_ENCODING.into(),

// Others will need to be filled by their platform-specific implementations
display_country: String::new(),
display_language: String::new(),
display_script: String::new(),
display_variant: String::new(),
file_encoding: String::new(),
format_country: String::new(),
format_language: String::new(),
format_script: String::new(),
format_variant: String::new(),
ftp_nonProxyHosts: None,
ftp_proxyHost: None,
ftp_proxyPort: None,
http_nonProxyHosts: None,
http_proxyHost: None,
http_proxyPort: None,
https_proxyHost: None,
https_proxyPort: None,
java_io_tmpdir: String::new(),
os_name: String::new(),
os_version: String::new(),
socksNonProxyHosts: None,
socksProxyHost: None,
socksProxyPort: None,
stderr_encoding: None,
stdout_encoding: None,
sun_arch_abi: None,
sun_arch_data_model: String::new(),
sun_cpu_isalist: None,
sun_jnu_encoding: String::new(),
sun_os_patch_level: String::new(),
user_dir: String::new(),
user_home: String::new(),
user_name: String::new(),
}
}
// Others will need to be filled by their platform-specific implementations
display_country: String::new(),
display_language: String::new(),
display_script: String::new(),
display_variant: String::new(),
file_encoding: String::new(),
format_country: String::new(),
format_language: String::new(),
format_script: String::new(),
format_variant: String::new(),
ftp_nonProxyHosts: None,
ftp_proxyHost: None,
ftp_proxyPort: None,
http_nonProxyHosts: None,
http_proxyHost: None,
http_proxyPort: None,
https_proxyHost: None,
https_proxyPort: None,
java_io_tmpdir: String::new(),
os_name: String::new(),
os_version: String::new(),
socksNonProxyHosts: None,
socksProxyHost: None,
socksProxyPort: None,
stderr_encoding: None,
stdout_encoding: None,
sun_arch_abi: None,
sun_arch_data_model: String::new(),
sun_cpu_isalist: None,
sun_jnu_encoding: String::new(),
sun_os_patch_level: String::new(),
user_dir: String::new(),
user_home: String::new(),
user_name: String::new(),
}
}
}

#[derive(Debug)]
pub enum Error {
WorkingDir,
WorkingDir,
}

impl Display for Error {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Error::WorkingDir => f.write_str("Could not determine currenting working directory")
}
}
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Error::WorkingDir => f.write_str("Could not determine currenting working directory"),
}
}
}

impl core::error::Error for Error {}

// Export family specific properties

use std::fmt::{Display, Formatter};
#[cfg(target_family = "unix")]
pub use super::unix::properties::*;
#[cfg(target_family = "windows")]
pub use super::windows::properties::*;
pub use super::windows::properties::*;
Loading

0 comments on commit 3da5375

Please sign in to comment.