Skip to content

Commit

Permalink
Merge branch 'main' into bugfix/read-readme-content
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary authored Dec 11, 2024
2 parents 3a7c8b8 + a09ad41 commit 8186c40
Show file tree
Hide file tree
Showing 39 changed files with 442 additions and 192 deletions.
3 changes: 2 additions & 1 deletion deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ allow = [
# BOOST source license
# NOTE: not to be confused with business source license!
"BSL-1.0",
"Unicode-3.0",
]
# The confidence threshold for detecting a license from license text.
# The higher the value, the more closely the license text must be to the
Expand Down Expand Up @@ -138,7 +139,7 @@ exceptions = [
[[licenses.clarify]]
crate = "ring"
expression = "MIT AND ISC AND OpenSSL"
license-files = [ { path = "LICENSE", hash = 0xbd0eed23 } ]
license-files = [{ path = "LICENSE", hash = 0xbd0eed23 }]

[licenses.private]
# If true, ignores workspace crates that aren't published, or are only
Expand Down
2 changes: 1 addition & 1 deletion lib/cli/src/commands/app/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub struct CmdAppDeploy {
#[clap(long)]
pub no_default: bool,

/// Do not persist the app version ID in the app.yaml.
/// Do not persist the app ID under `app_id` field in app.yaml.
#[clap(long)]
pub no_persist_id: bool,

Expand Down
2 changes: 1 addition & 1 deletion lib/compiler-llvm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let mut store = Store::new(compiler);
## When to use LLVM

We recommend using LLVM as the default compiler when running WebAssembly
files on any **production** system, as it offers maximum peformance near
files on any **production** system, as it offers maximum performance near
to native speeds.

## Requirements
Expand Down
2 changes: 1 addition & 1 deletion lib/compiler-llvm/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ impl LLVM {
self.opt_level,
self.reloc_mode(),
match triple.architecture {
Architecture::Riscv64(_) => CodeModel::Medium,
Architecture::LoongArch64 | Architecture::Riscv64(_) => CodeModel::Medium,
_ => self.code_model(),
},
)
Expand Down
28 changes: 28 additions & 0 deletions lib/compiler-llvm/src/object_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,34 @@ where
object::RelocationKind::Elf(object::elf::R_LARCH_ABS64_LO20),
0,
) => RelocationKind::LArchAbs64Lo20,
(
object::Architecture::LoongArch64,
// FIXME: Replace with R_LARCH_CALL36 while object is updated
// to 0.32.2.
// https://github.com/gimli-rs/object/commit/16b6d902f6c9b39ec7aaea141460f8981e57dd79
object::RelocationKind::Elf(110),
0,
) => RelocationKind::LArchCall36,
(
object::Architecture::LoongArch64,
object::RelocationKind::Elf(object::elf::R_LARCH_PCALA_HI20),
0,
) => RelocationKind::LArchPCAlaHi20,
(
object::Architecture::LoongArch64,
object::RelocationKind::Elf(object::elf::R_LARCH_PCALA_LO12),
0,
) => RelocationKind::LArchPCAlaLo12,
(
object::Architecture::LoongArch64,
object::RelocationKind::Elf(object::elf::R_LARCH_PCALA64_HI12),
0,
) => RelocationKind::LArchPCAla64Hi12,
(
object::Architecture::LoongArch64,
object::RelocationKind::Elf(object::elf::R_LARCH_PCALA64_LO20),
0,
) => RelocationKind::LArchPCAla64Lo20,
(
object::Architecture::Aarch64,
object::RelocationKind::Elf(object::elf::R_AARCH64_ADR_PREL_LO21),
Expand Down
2 changes: 1 addition & 1 deletion lib/compiler/src/artifact_builders/trampoline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const RISCV64_TRAMPOLINE: [u8; 24] = [
// JR r12 80 01 00 4c [00 00 00 00]
// JMPADDR 00 00 00 00 00 00 00 00
const LOONGARCH64_TRAMPOLINE: [u8; 24] = [
0x0c, 0x00, 0x00, 0x0c, 0x8c, 0x41, 0xc0, 0x28, 0x80, 0x01, 0x00, 0x4c, 0, 0, 0, 0, 0, 0, 0, 0,
0x0c, 0x00, 0x00, 0x18, 0x8c, 0x41, 0xc0, 0x28, 0x80, 0x01, 0x00, 0x4c, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0,
];

Expand Down
17 changes: 13 additions & 4 deletions lib/compiler/src/engine/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,30 +127,39 @@ fn apply_relocation(
| read_unaligned(reloc_address as *mut u64);
write_unaligned(reloc_address as *mut u64, reloc_delta);
},
RelocationKind::LArchAbsHi20 => unsafe {
RelocationKind::LArchAbsHi20 | RelocationKind::LArchPCAlaHi20 => unsafe {
let (reloc_address, reloc_abs) = r.for_address(body, target_func_address as u64);
let reloc_abs = ((((reloc_abs >> 12) & 0xfffff) as u32) << 5)
| read_unaligned(reloc_address as *mut u32);
write_unaligned(reloc_address as *mut u32, reloc_abs);
},
RelocationKind::LArchAbsLo12 => unsafe {
RelocationKind::LArchAbsLo12 | RelocationKind::LArchPCAlaLo12 => unsafe {
let (reloc_address, reloc_abs) = r.for_address(body, target_func_address as u64);
let reloc_abs =
(((reloc_abs & 0xfff) as u32) << 10) | read_unaligned(reloc_address as *mut u32);
write_unaligned(reloc_address as *mut u32, reloc_abs);
},
RelocationKind::LArchAbs64Hi12 => unsafe {
RelocationKind::LArchAbs64Hi12 | RelocationKind::LArchPCAla64Hi12 => unsafe {
let (reloc_address, reloc_abs) = r.for_address(body, target_func_address as u64);
let reloc_abs = ((((reloc_abs >> 52) & 0xfff) as u32) << 10)
| read_unaligned(reloc_address as *mut u32);
write_unaligned(reloc_address as *mut u32, reloc_abs);
},
RelocationKind::LArchAbs64Lo20 => unsafe {
RelocationKind::LArchAbs64Lo20 | RelocationKind::LArchPCAla64Lo20 => unsafe {
let (reloc_address, reloc_abs) = r.for_address(body, target_func_address as u64);
let reloc_abs = ((((reloc_abs >> 32) & 0xfffff) as u32) << 5)
| read_unaligned(reloc_address as *mut u32);
write_unaligned(reloc_address as *mut u32, reloc_abs);
},
RelocationKind::LArchCall36 => unsafe {
let (reloc_address, reloc_delta) = r.for_address(body, target_func_address as u64);
let reloc_delta1 = ((((reloc_delta >> 18) & 0xfffff) as u32) << 5)
| read_unaligned(reloc_address as *mut u32);
write_unaligned(reloc_address as *mut u32, reloc_delta1);
let reloc_delta2 = ((((reloc_delta >> 2) & 0xffff) as u32) << 10)
| read_unaligned((reloc_address + 4) as *mut u32);
write_unaligned((reloc_address + 4) as *mut u32, reloc_delta2);
},
RelocationKind::Aarch64AdrPrelPgHi21 => unsafe {
let (reloc_address, delta) = r.for_address(body, target_func_address as u64);

Expand Down
61 changes: 60 additions & 1 deletion lib/compiler/src/types/relocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ pub enum RelocationKind {
LArchAbs64Hi12,
/// LoongArch absolute low 20bit
LArchAbs64Lo20,
/// LoongArch PC-relative call 38bit
LArchCall36,
/// LoongArch PC-relative high 20bit
LArchPCAlaHi20,
/// LoongArch PC-relative low 12bit
LArchPCAlaLo12,
/// LoongArch PC64-relative high 12bit
LArchPCAla64Hi12,
/// LoongArch PC64-relative low 20bit
LArchPCAla64Lo20,
/// Elf x86_64 32 bit signed PC relative offset to two GOT entries for GD symbol.
ElfX86_64TlsGd,
// /// Mach-O x86_64 32 bit signed PC relative offset to a `__thread_vars` entry.
Expand Down Expand Up @@ -115,6 +125,11 @@ impl fmt::Display for RelocationKind {
Self::LArchAbsLo12 => write!(f, "LArchAbsLo12"),
Self::LArchAbs64Hi12 => write!(f, "LArchAbs64Hi12"),
Self::LArchAbs64Lo20 => write!(f, "LArchAbs64Lo20"),
Self::LArchCall36 => write!(f, "LArchCall36"),
Self::LArchPCAlaHi20 => write!(f, "LArchPCAlaHi20"),
Self::LArchPCAlaLo12 => write!(f, "LArchPCAlaLo12"),
Self::LArchPCAla64Hi12 => write!(f, "LArchPCAla64Hi12"),
Self::LArchPCAla64Lo20 => write!(f, "LArchPCAla64Lo20"),
Self::Aarch64AdrPrelLo21 => write!(f, "Aarch64AdrPrelLo21"),
Self::Aarch64AdrPrelPgHi21 => write!(f, "Aarch64AdrPrelPgHi21"),
Self::Aarch64AddAbsLo12Nc => write!(f, "Aarch64AddAbsLo12Nc"),
Expand Down Expand Up @@ -172,7 +187,12 @@ pub trait RelocationLike {
| RelocationKind::Arm64Movw3
| RelocationKind::RiscvPCRelLo12I
| RelocationKind::Aarch64Ldst128AbsLo12Nc
| RelocationKind::Aarch64Ldst64AbsLo12Nc => {
| RelocationKind::Aarch64Ldst64AbsLo12Nc
| RelocationKind::LArchAbsHi20
| RelocationKind::LArchAbsLo12
| RelocationKind::LArchAbs64Lo20
| RelocationKind::LArchAbs64Hi12
| RelocationKind::LArchPCAlaLo12 => {
let reloc_address = start + self.offset() as usize;
let reloc_addend = self.addend() as isize;
let reloc_abs = target_func_address
Expand Down Expand Up @@ -239,6 +259,45 @@ pub trait RelocationLike {
let pc_page = reloc_address & !(0xFFF);
(reloc_address, target_page.wrapping_sub(pc_page) as u64)
}
RelocationKind::LArchCall36 => {
let reloc_address = start + self.offset() as usize;
let reloc_addend = self.addend() as isize;
let reloc_delta = target_func_address
.wrapping_sub(reloc_address as u64)
.wrapping_add(reloc_addend as u64);
(
reloc_address,
reloc_delta.wrapping_add((reloc_delta & 0x20000) << 1),
)
}
RelocationKind::LArchPCAlaHi20 => {
let reloc_address = start + self.offset() as usize;
let reloc_addend = self.addend() as isize;
let target_page = (target_func_address
.wrapping_add(reloc_addend as u64)
.wrapping_add(0x800)
& !(0xFFF)) as usize;
let pc_page = reloc_address & !(0xFFF);
(reloc_address, target_page.wrapping_sub(pc_page) as u64)
}
RelocationKind::LArchPCAla64Hi12 | RelocationKind::LArchPCAla64Lo20 => {
let reloc_address = start + self.offset() as usize;
let reloc_addend = self.addend() as isize;
let reloc_offset = match self.kind() {
RelocationKind::LArchPCAla64Lo20 => 8,
RelocationKind::LArchPCAla64Hi12 => 12,
_ => 0,
};
let target_func_address = target_func_address.wrapping_add(reloc_addend as u64);
let target_page = (target_func_address & !(0xFFF)) as usize;
let pc_page = (reloc_address - reloc_offset) & !(0xFFF);
let mut reloc_delta = target_page.wrapping_sub(pc_page) as u64;
reloc_delta = reloc_delta
.wrapping_add((target_func_address & 0x800) << 1)
.wrapping_sub((target_func_address & 0x800) << 21);
reloc_delta = reloc_delta.wrapping_add((reloc_delta & 0x80000000) << 1);
(reloc_address, reloc_delta)
}
_ => panic!("Relocation kind unsupported"),
}
}
Expand Down
3 changes: 0 additions & 3 deletions lib/config/rust-toolchain.toml

This file was deleted.

9 changes: 8 additions & 1 deletion lib/virtual-io/src/selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,14 @@ impl Selector {
let mut events = mio::Events::with_capacity(128);
loop {
// Wait for an event to trigger
poll.poll(&mut events, None).unwrap();
if let Err(e) = poll.poll(&mut events, None) {
// This can happen when a debugger is attached
#[cfg(debug_assertions)]
if e.kind() == std::io::ErrorKind::Interrupted {
continue;
}
panic!("Unexpected error in selector poll loop: {e:?}");
}

// Loop through all the events while under a guard lock
let mut guard = engine.inner.lock().unwrap();
Expand Down
4 changes: 2 additions & 2 deletions lib/wasix/src/capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::time::Duration;
use crate::http::HttpClientCapabilityV1;

/// Defines capabilities for a Wasi environment.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Capabilities {
pub insecure_allow_all: bool,
pub http_client: HttpClientCapabilityV1,
Expand Down Expand Up @@ -40,7 +40,7 @@ impl Default for Capabilities {
}

/// Defines threading related permissions.
#[derive(Debug, Default, Clone)]
#[derive(Debug, Default, Clone, PartialEq, Eq, Hash)]
pub struct CapabilityThreadingV1 {
/// Maximum number of threads that can be spawned.
///
Expand Down
2 changes: 1 addition & 1 deletion lib/wasix/src/fs/fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl Fd {
pub struct InodeVal {
pub stat: RwLock<Filestat>,
pub is_preopened: bool,
pub name: Cow<'static, str>,
pub name: RwLock<Cow<'static, str>>,
pub kind: RwLock<Kind>,
}

Expand Down
2 changes: 1 addition & 1 deletion lib/wasix/src/fs/fd_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ mod tests {
inner: Arc::new(InodeVal {
is_preopened: false,
kind: RwLock::new(Kind::Buffer { buffer: vec![] }),
name: Cow::Borrowed(""),
name: RwLock::new(Cow::Borrowed("")),
stat: RwLock::new(Default::default()),
}),
},
Expand Down
47 changes: 36 additions & 11 deletions lib/wasix/src/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ impl WasiFs {

/// Converts a relative path into an absolute path
pub(crate) fn relative_path_to_absolute(&self, mut path: String) -> String {
if path.starts_with("./") {
if !path.starts_with("/") {
let current_dir = self.current_dir.lock().unwrap();
path = format!("{}{}", current_dir.as_str(), &path[1..]);
if path.contains("//") {
Expand Down Expand Up @@ -575,7 +575,7 @@ impl WasiFs {
let root_inode = inodes.add_inode_val(InodeVal {
stat: RwLock::new(stat),
is_preopened: true,
name: "/".into(),
name: RwLock::new("/".into()),
kind: RwLock::new(root_kind),
});

Expand Down Expand Up @@ -895,6 +895,13 @@ impl WasiFs {

// TODO: rights checks
'path_iter: for (i, component) in path.components().enumerate() {
// Since we're resolving the path against the given inode, we want to
// assume '/a/b' to be the same as `a/b` relative to the inode, so
// we skip over the RootDir component.
if matches!(component, Component::RootDir) {
continue;
}

// used to terminate symlink resolution properly
let last_component = i + 1 == n_components;
// for each component traverse file structure
Expand Down Expand Up @@ -1255,13 +1262,31 @@ impl WasiFs {
follow_symlinks: bool,
) -> Result<InodeGuard, Errno> {
let base_inode = self.get_fd_inode(base)?;
let start_inode =
if !base_inode.deref().name.starts_with('/') && self.is_wasix.load(Ordering::Acquire) {
let (cur_inode, _) = self.get_current_dir(inodes, base)?;
cur_inode
let name = base_inode.name.read().unwrap();

let start_inode;
if name.starts_with('/') {
drop(name);
start_inode = base_inode;
} else {
let kind = base_inode.kind.read().unwrap();

// HACK: We preopen '/' with an alias of '.' by default in `prepare_webc_env`. If wasix-libc
// picks that up as the base FD, we want to do the same thing we do when the base is '/'
if *name == "."
&& matches!(kind.deref(), Kind::Dir { path, .. } if path.as_os_str().as_encoded_bytes() == b"/")
{
drop(name);
drop(kind);
start_inode = base_inode;
} else {
self.get_fd_inode(base)?
};
drop(name);
drop(kind);
let (cur_inode, _) = self.get_current_dir(inodes, base)?;
start_inode = cur_inode;
}
};

self.get_inode_at_path_inner(inodes, start_inode, path, 0, follow_symlinks)
}

Expand Down Expand Up @@ -1416,7 +1441,7 @@ impl WasiFs {
// REVIEW:
// no need for +1, because there is no 0 end-of-string marker
// john: removing the +1 seems cause regression issues
pr_name_len: inode_val.name.len() as u32 + 1,
pr_name_len: inode_val.name.read().unwrap().len() as u32 + 1,
}
.untagged(),
}
Expand Down Expand Up @@ -1527,7 +1552,7 @@ impl WasiFs {
inodes.add_inode_val(InodeVal {
stat: RwLock::new(stat),
is_preopened,
name,
name: RwLock::new(name),
kind: RwLock::new(kind),
})
}
Expand Down Expand Up @@ -1906,7 +1931,7 @@ impl WasiFs {
inodes.add_inode_val(InodeVal {
stat: RwLock::new(stat),
is_preopened: true,
name: name.to_string().into(),
name: RwLock::new(name.to_string().into()),
kind: RwLock::new(kind),
})
};
Expand Down
Loading

0 comments on commit 8186c40

Please sign in to comment.