Skip to content

Commit 8186c40

Browse files
authored
Merge branch 'main' into bugfix/read-readme-content
2 parents 3a7c8b8 + a09ad41 commit 8186c40

39 files changed

+442
-192
lines changed

deny.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ allow = [
103103
# BOOST source license
104104
# NOTE: not to be confused with business source license!
105105
"BSL-1.0",
106+
"Unicode-3.0",
106107
]
107108
# The confidence threshold for detecting a license from license text.
108109
# The higher the value, the more closely the license text must be to the
@@ -138,7 +139,7 @@ exceptions = [
138139
[[licenses.clarify]]
139140
crate = "ring"
140141
expression = "MIT AND ISC AND OpenSSL"
141-
license-files = [ { path = "LICENSE", hash = 0xbd0eed23 } ]
142+
license-files = [{ path = "LICENSE", hash = 0xbd0eed23 }]
142143

143144
[licenses.private]
144145
# If true, ignores workspace crates that aren't published, or are only

lib/cli/src/commands/app/deploy.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub struct CmdAppDeploy {
6363
#[clap(long)]
6464
pub no_default: bool,
6565

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

lib/compiler-llvm/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ let mut store = Store::new(compiler);
1717
## When to use LLVM
1818

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

2323
## Requirements

lib/compiler-llvm/src/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ impl LLVM {
221221
self.opt_level,
222222
self.reloc_mode(),
223223
match triple.architecture {
224-
Architecture::Riscv64(_) => CodeModel::Medium,
224+
Architecture::LoongArch64 | Architecture::Riscv64(_) => CodeModel::Medium,
225225
_ => self.code_model(),
226226
},
227227
)

lib/compiler-llvm/src/object_file.rs

+28
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,34 @@ where
254254
object::RelocationKind::Elf(object::elf::R_LARCH_ABS64_LO20),
255255
0,
256256
) => RelocationKind::LArchAbs64Lo20,
257+
(
258+
object::Architecture::LoongArch64,
259+
// FIXME: Replace with R_LARCH_CALL36 while object is updated
260+
// to 0.32.2.
261+
// https://github.com/gimli-rs/object/commit/16b6d902f6c9b39ec7aaea141460f8981e57dd79
262+
object::RelocationKind::Elf(110),
263+
0,
264+
) => RelocationKind::LArchCall36,
265+
(
266+
object::Architecture::LoongArch64,
267+
object::RelocationKind::Elf(object::elf::R_LARCH_PCALA_HI20),
268+
0,
269+
) => RelocationKind::LArchPCAlaHi20,
270+
(
271+
object::Architecture::LoongArch64,
272+
object::RelocationKind::Elf(object::elf::R_LARCH_PCALA_LO12),
273+
0,
274+
) => RelocationKind::LArchPCAlaLo12,
275+
(
276+
object::Architecture::LoongArch64,
277+
object::RelocationKind::Elf(object::elf::R_LARCH_PCALA64_HI12),
278+
0,
279+
) => RelocationKind::LArchPCAla64Hi12,
280+
(
281+
object::Architecture::LoongArch64,
282+
object::RelocationKind::Elf(object::elf::R_LARCH_PCALA64_LO20),
283+
0,
284+
) => RelocationKind::LArchPCAla64Lo20,
257285
(
258286
object::Architecture::Aarch64,
259287
object::RelocationKind::Elf(object::elf::R_AARCH64_ADR_PREL_LO21),

lib/compiler/src/artifact_builders/trampoline.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const RISCV64_TRAMPOLINE: [u8; 24] = [
4545
// JR r12 80 01 00 4c [00 00 00 00]
4646
// JMPADDR 00 00 00 00 00 00 00 00
4747
const LOONGARCH64_TRAMPOLINE: [u8; 24] = [
48-
0x0c, 0x00, 0x00, 0x0c, 0x8c, 0x41, 0xc0, 0x28, 0x80, 0x01, 0x00, 0x4c, 0, 0, 0, 0, 0, 0, 0, 0,
48+
0x0c, 0x00, 0x00, 0x18, 0x8c, 0x41, 0xc0, 0x28, 0x80, 0x01, 0x00, 0x4c, 0, 0, 0, 0, 0, 0, 0, 0,
4949
0, 0, 0, 0,
5050
];
5151

lib/compiler/src/engine/link.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -127,30 +127,39 @@ fn apply_relocation(
127127
| read_unaligned(reloc_address as *mut u64);
128128
write_unaligned(reloc_address as *mut u64, reloc_delta);
129129
},
130-
RelocationKind::LArchAbsHi20 => unsafe {
130+
RelocationKind::LArchAbsHi20 | RelocationKind::LArchPCAlaHi20 => unsafe {
131131
let (reloc_address, reloc_abs) = r.for_address(body, target_func_address as u64);
132132
let reloc_abs = ((((reloc_abs >> 12) & 0xfffff) as u32) << 5)
133133
| read_unaligned(reloc_address as *mut u32);
134134
write_unaligned(reloc_address as *mut u32, reloc_abs);
135135
},
136-
RelocationKind::LArchAbsLo12 => unsafe {
136+
RelocationKind::LArchAbsLo12 | RelocationKind::LArchPCAlaLo12 => unsafe {
137137
let (reloc_address, reloc_abs) = r.for_address(body, target_func_address as u64);
138138
let reloc_abs =
139139
(((reloc_abs & 0xfff) as u32) << 10) | read_unaligned(reloc_address as *mut u32);
140140
write_unaligned(reloc_address as *mut u32, reloc_abs);
141141
},
142-
RelocationKind::LArchAbs64Hi12 => unsafe {
142+
RelocationKind::LArchAbs64Hi12 | RelocationKind::LArchPCAla64Hi12 => unsafe {
143143
let (reloc_address, reloc_abs) = r.for_address(body, target_func_address as u64);
144144
let reloc_abs = ((((reloc_abs >> 52) & 0xfff) as u32) << 10)
145145
| read_unaligned(reloc_address as *mut u32);
146146
write_unaligned(reloc_address as *mut u32, reloc_abs);
147147
},
148-
RelocationKind::LArchAbs64Lo20 => unsafe {
148+
RelocationKind::LArchAbs64Lo20 | RelocationKind::LArchPCAla64Lo20 => unsafe {
149149
let (reloc_address, reloc_abs) = r.for_address(body, target_func_address as u64);
150150
let reloc_abs = ((((reloc_abs >> 32) & 0xfffff) as u32) << 5)
151151
| read_unaligned(reloc_address as *mut u32);
152152
write_unaligned(reloc_address as *mut u32, reloc_abs);
153153
},
154+
RelocationKind::LArchCall36 => unsafe {
155+
let (reloc_address, reloc_delta) = r.for_address(body, target_func_address as u64);
156+
let reloc_delta1 = ((((reloc_delta >> 18) & 0xfffff) as u32) << 5)
157+
| read_unaligned(reloc_address as *mut u32);
158+
write_unaligned(reloc_address as *mut u32, reloc_delta1);
159+
let reloc_delta2 = ((((reloc_delta >> 2) & 0xffff) as u32) << 10)
160+
| read_unaligned((reloc_address + 4) as *mut u32);
161+
write_unaligned((reloc_address + 4) as *mut u32, reloc_delta2);
162+
},
154163
RelocationKind::Aarch64AdrPrelPgHi21 => unsafe {
155164
let (reloc_address, delta) = r.for_address(body, target_func_address as u64);
156165

lib/compiler/src/types/relocation.rs

+60-1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ pub enum RelocationKind {
8585
LArchAbs64Hi12,
8686
/// LoongArch absolute low 20bit
8787
LArchAbs64Lo20,
88+
/// LoongArch PC-relative call 38bit
89+
LArchCall36,
90+
/// LoongArch PC-relative high 20bit
91+
LArchPCAlaHi20,
92+
/// LoongArch PC-relative low 12bit
93+
LArchPCAlaLo12,
94+
/// LoongArch PC64-relative high 12bit
95+
LArchPCAla64Hi12,
96+
/// LoongArch PC64-relative low 20bit
97+
LArchPCAla64Lo20,
8898
/// Elf x86_64 32 bit signed PC relative offset to two GOT entries for GD symbol.
8999
ElfX86_64TlsGd,
90100
// /// Mach-O x86_64 32 bit signed PC relative offset to a `__thread_vars` entry.
@@ -115,6 +125,11 @@ impl fmt::Display for RelocationKind {
115125
Self::LArchAbsLo12 => write!(f, "LArchAbsLo12"),
116126
Self::LArchAbs64Hi12 => write!(f, "LArchAbs64Hi12"),
117127
Self::LArchAbs64Lo20 => write!(f, "LArchAbs64Lo20"),
128+
Self::LArchCall36 => write!(f, "LArchCall36"),
129+
Self::LArchPCAlaHi20 => write!(f, "LArchPCAlaHi20"),
130+
Self::LArchPCAlaLo12 => write!(f, "LArchPCAlaLo12"),
131+
Self::LArchPCAla64Hi12 => write!(f, "LArchPCAla64Hi12"),
132+
Self::LArchPCAla64Lo20 => write!(f, "LArchPCAla64Lo20"),
118133
Self::Aarch64AdrPrelLo21 => write!(f, "Aarch64AdrPrelLo21"),
119134
Self::Aarch64AdrPrelPgHi21 => write!(f, "Aarch64AdrPrelPgHi21"),
120135
Self::Aarch64AddAbsLo12Nc => write!(f, "Aarch64AddAbsLo12Nc"),
@@ -172,7 +187,12 @@ pub trait RelocationLike {
172187
| RelocationKind::Arm64Movw3
173188
| RelocationKind::RiscvPCRelLo12I
174189
| RelocationKind::Aarch64Ldst128AbsLo12Nc
175-
| RelocationKind::Aarch64Ldst64AbsLo12Nc => {
190+
| RelocationKind::Aarch64Ldst64AbsLo12Nc
191+
| RelocationKind::LArchAbsHi20
192+
| RelocationKind::LArchAbsLo12
193+
| RelocationKind::LArchAbs64Lo20
194+
| RelocationKind::LArchAbs64Hi12
195+
| RelocationKind::LArchPCAlaLo12 => {
176196
let reloc_address = start + self.offset() as usize;
177197
let reloc_addend = self.addend() as isize;
178198
let reloc_abs = target_func_address
@@ -239,6 +259,45 @@ pub trait RelocationLike {
239259
let pc_page = reloc_address & !(0xFFF);
240260
(reloc_address, target_page.wrapping_sub(pc_page) as u64)
241261
}
262+
RelocationKind::LArchCall36 => {
263+
let reloc_address = start + self.offset() as usize;
264+
let reloc_addend = self.addend() as isize;
265+
let reloc_delta = target_func_address
266+
.wrapping_sub(reloc_address as u64)
267+
.wrapping_add(reloc_addend as u64);
268+
(
269+
reloc_address,
270+
reloc_delta.wrapping_add((reloc_delta & 0x20000) << 1),
271+
)
272+
}
273+
RelocationKind::LArchPCAlaHi20 => {
274+
let reloc_address = start + self.offset() as usize;
275+
let reloc_addend = self.addend() as isize;
276+
let target_page = (target_func_address
277+
.wrapping_add(reloc_addend as u64)
278+
.wrapping_add(0x800)
279+
& !(0xFFF)) as usize;
280+
let pc_page = reloc_address & !(0xFFF);
281+
(reloc_address, target_page.wrapping_sub(pc_page) as u64)
282+
}
283+
RelocationKind::LArchPCAla64Hi12 | RelocationKind::LArchPCAla64Lo20 => {
284+
let reloc_address = start + self.offset() as usize;
285+
let reloc_addend = self.addend() as isize;
286+
let reloc_offset = match self.kind() {
287+
RelocationKind::LArchPCAla64Lo20 => 8,
288+
RelocationKind::LArchPCAla64Hi12 => 12,
289+
_ => 0,
290+
};
291+
let target_func_address = target_func_address.wrapping_add(reloc_addend as u64);
292+
let target_page = (target_func_address & !(0xFFF)) as usize;
293+
let pc_page = (reloc_address - reloc_offset) & !(0xFFF);
294+
let mut reloc_delta = target_page.wrapping_sub(pc_page) as u64;
295+
reloc_delta = reloc_delta
296+
.wrapping_add((target_func_address & 0x800) << 1)
297+
.wrapping_sub((target_func_address & 0x800) << 21);
298+
reloc_delta = reloc_delta.wrapping_add((reloc_delta & 0x80000000) << 1);
299+
(reloc_address, reloc_delta)
300+
}
242301
_ => panic!("Relocation kind unsupported"),
243302
}
244303
}

lib/config/rust-toolchain.toml

-3
This file was deleted.

lib/virtual-io/src/selector.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,14 @@ impl Selector {
134134
let mut events = mio::Events::with_capacity(128);
135135
loop {
136136
// Wait for an event to trigger
137-
poll.poll(&mut events, None).unwrap();
137+
if let Err(e) = poll.poll(&mut events, None) {
138+
// This can happen when a debugger is attached
139+
#[cfg(debug_assertions)]
140+
if e.kind() == std::io::ErrorKind::Interrupted {
141+
continue;
142+
}
143+
panic!("Unexpected error in selector poll loop: {e:?}");
144+
}
138145

139146
// Loop through all the events while under a guard lock
140147
let mut guard = engine.inner.lock().unwrap();

lib/wasix/src/capabilities.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::time::Duration;
33
use crate::http::HttpClientCapabilityV1;
44

55
/// Defines capabilities for a Wasi environment.
6-
#[derive(Clone, Debug)]
6+
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
77
pub struct Capabilities {
88
pub insecure_allow_all: bool,
99
pub http_client: HttpClientCapabilityV1,
@@ -40,7 +40,7 @@ impl Default for Capabilities {
4040
}
4141

4242
/// Defines threading related permissions.
43-
#[derive(Debug, Default, Clone)]
43+
#[derive(Debug, Default, Clone, PartialEq, Eq, Hash)]
4444
pub struct CapabilityThreadingV1 {
4545
/// Maximum number of threads that can be spawned.
4646
///

lib/wasix/src/fs/fd.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl Fd {
6262
pub struct InodeVal {
6363
pub stat: RwLock<Filestat>,
6464
pub is_preopened: bool,
65-
pub name: Cow<'static, str>,
65+
pub name: RwLock<Cow<'static, str>>,
6666
pub kind: RwLock<Kind>,
6767
}
6868

lib/wasix/src/fs/fd_list.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ mod tests {
218218
inner: Arc::new(InodeVal {
219219
is_preopened: false,
220220
kind: RwLock::new(Kind::Buffer { buffer: vec![] }),
221-
name: Cow::Borrowed(""),
221+
name: RwLock::new(Cow::Borrowed("")),
222222
stat: RwLock::new(Default::default()),
223223
}),
224224
},

lib/wasix/src/fs/mod.rs

+36-11
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ impl WasiFs {
545545

546546
/// Converts a relative path into an absolute path
547547
pub(crate) fn relative_path_to_absolute(&self, mut path: String) -> String {
548-
if path.starts_with("./") {
548+
if !path.starts_with("/") {
549549
let current_dir = self.current_dir.lock().unwrap();
550550
path = format!("{}{}", current_dir.as_str(), &path[1..]);
551551
if path.contains("//") {
@@ -575,7 +575,7 @@ impl WasiFs {
575575
let root_inode = inodes.add_inode_val(InodeVal {
576576
stat: RwLock::new(stat),
577577
is_preopened: true,
578-
name: "/".into(),
578+
name: RwLock::new("/".into()),
579579
kind: RwLock::new(root_kind),
580580
});
581581

@@ -895,6 +895,13 @@ impl WasiFs {
895895

896896
// TODO: rights checks
897897
'path_iter: for (i, component) in path.components().enumerate() {
898+
// Since we're resolving the path against the given inode, we want to
899+
// assume '/a/b' to be the same as `a/b` relative to the inode, so
900+
// we skip over the RootDir component.
901+
if matches!(component, Component::RootDir) {
902+
continue;
903+
}
904+
898905
// used to terminate symlink resolution properly
899906
let last_component = i + 1 == n_components;
900907
// for each component traverse file structure
@@ -1255,13 +1262,31 @@ impl WasiFs {
12551262
follow_symlinks: bool,
12561263
) -> Result<InodeGuard, Errno> {
12571264
let base_inode = self.get_fd_inode(base)?;
1258-
let start_inode =
1259-
if !base_inode.deref().name.starts_with('/') && self.is_wasix.load(Ordering::Acquire) {
1260-
let (cur_inode, _) = self.get_current_dir(inodes, base)?;
1261-
cur_inode
1265+
let name = base_inode.name.read().unwrap();
1266+
1267+
let start_inode;
1268+
if name.starts_with('/') {
1269+
drop(name);
1270+
start_inode = base_inode;
1271+
} else {
1272+
let kind = base_inode.kind.read().unwrap();
1273+
1274+
// HACK: We preopen '/' with an alias of '.' by default in `prepare_webc_env`. If wasix-libc
1275+
// picks that up as the base FD, we want to do the same thing we do when the base is '/'
1276+
if *name == "."
1277+
&& matches!(kind.deref(), Kind::Dir { path, .. } if path.as_os_str().as_encoded_bytes() == b"/")
1278+
{
1279+
drop(name);
1280+
drop(kind);
1281+
start_inode = base_inode;
12621282
} else {
1263-
self.get_fd_inode(base)?
1264-
};
1283+
drop(name);
1284+
drop(kind);
1285+
let (cur_inode, _) = self.get_current_dir(inodes, base)?;
1286+
start_inode = cur_inode;
1287+
}
1288+
};
1289+
12651290
self.get_inode_at_path_inner(inodes, start_inode, path, 0, follow_symlinks)
12661291
}
12671292

@@ -1416,7 +1441,7 @@ impl WasiFs {
14161441
// REVIEW:
14171442
// no need for +1, because there is no 0 end-of-string marker
14181443
// john: removing the +1 seems cause regression issues
1419-
pr_name_len: inode_val.name.len() as u32 + 1,
1444+
pr_name_len: inode_val.name.read().unwrap().len() as u32 + 1,
14201445
}
14211446
.untagged(),
14221447
}
@@ -1527,7 +1552,7 @@ impl WasiFs {
15271552
inodes.add_inode_val(InodeVal {
15281553
stat: RwLock::new(stat),
15291554
is_preopened,
1530-
name,
1555+
name: RwLock::new(name),
15311556
kind: RwLock::new(kind),
15321557
})
15331558
}
@@ -1906,7 +1931,7 @@ impl WasiFs {
19061931
inodes.add_inode_val(InodeVal {
19071932
stat: RwLock::new(stat),
19081933
is_preopened: true,
1909-
name: name.to_string().into(),
1934+
name: RwLock::new(name.to_string().into()),
19101935
kind: RwLock::new(kind),
19111936
})
19121937
};

0 commit comments

Comments
 (0)