Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 51 additions & 57 deletions crates/volamos-core/src/bsdsocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1951,15 +1951,15 @@ fn inet_ntoa_handler<C: Cpu>(ctx: &mut HandlerContext<'_, C>) -> Result<(), Disp
None => {
// "###.###.###.###\0" -- 16 bytes is enough for any IPv4
// dotted-decimal string plus its NUL terminator.
let addr = ctx
.heap
.alloc(16)
.map_err(|e| DispatchError::HandlerFailed {
library: "bsdsocket.library".to_string(),
lvo: -174,
handler_name: "Inet_NtoA".to_string(),
message: format!("Inet_NtoA: guest heap allocation failed: {e}"),
})?;
let addr =
ctx.heap
.alloc(&mut *ctx.mem, 16)
.map_err(|e| DispatchError::HandlerFailed {
library: "bsdsocket.library".to_string(),
lvo: -174,
handler_name: "Inet_NtoA".to_string(),
message: format!("Inet_NtoA: guest heap allocation failed: {e}"),
})?;
ctx.bsdsocket.ntoa_buf = Some(addr);
addr
}
Expand Down Expand Up @@ -2097,15 +2097,14 @@ fn build_hostent<C: Cpu>(

let mut allocs = Vec::new();
let mut alloc = |ctx: &mut HandlerContext<'_, C>, size: u32| -> Result<u32, DispatchError> {
let addr = ctx
.heap
.alloc(size.max(4))
.map_err(|e| DispatchError::HandlerFailed {
let addr = ctx.heap.alloc(&mut *ctx.mem, size.max(4)).map_err(|e| {
DispatchError::HandlerFailed {
library: "bsdsocket.library".to_string(),
lvo,
handler_name: handler_name.to_string(),
message: format!("{handler_name}: guest heap allocation failed: {e}"),
})?;
}
})?;
allocs.push(addr);
Ok(addr)
};
Expand Down Expand Up @@ -2325,15 +2324,14 @@ fn build_servent<C: Cpu>(
}
let mut allocs = Vec::new();
let mut alloc = |ctx: &mut HandlerContext<'_, C>, size: u32| -> Result<u32, DispatchError> {
let addr = ctx
.heap
.alloc(size.max(4))
.map_err(|e| DispatchError::HandlerFailed {
let addr = ctx.heap.alloc(&mut *ctx.mem, size.max(4)).map_err(|e| {
DispatchError::HandlerFailed {
library: "bsdsocket.library".to_string(),
lvo,
handler_name: handler_name.to_string(),
message: format!("{handler_name}: guest heap allocation failed: {e}"),
})?;
}
})?;
allocs.push(addr);
Ok(addr)
};
Expand Down Expand Up @@ -2459,15 +2457,14 @@ fn build_protoent<C: Cpu>(
}
let mut allocs = Vec::new();
let mut alloc = |ctx: &mut HandlerContext<'_, C>, size: u32| -> Result<u32, DispatchError> {
let addr = ctx
.heap
.alloc(size.max(4))
.map_err(|e| DispatchError::HandlerFailed {
let addr = ctx.heap.alloc(&mut *ctx.mem, size.max(4)).map_err(|e| {
DispatchError::HandlerFailed {
library: "bsdsocket.library".to_string(),
lvo,
handler_name: handler_name.to_string(),
message: format!("{handler_name}: guest heap allocation failed: {e}"),
})?;
}
})?;
allocs.push(addr);
Ok(addr)
};
Expand Down Expand Up @@ -2701,17 +2698,16 @@ fn socket_base_tag_list_handler<C: Cpu>(
let ptr = match ctx.bsdsocket.errno_ptr {
Some(ptr) => ptr,
None => {
let addr =
ctx.heap
.alloc(4)
.map_err(|e| DispatchError::HandlerFailed {
library: "bsdsocket.library".to_string(),
lvo: -294,
handler_name: "SocketBaseTagList".to_string(),
message: format!(
"SocketBaseTagList: guest heap allocation failed: {e}"
),
})?;
let addr = ctx.heap.alloc(&mut *ctx.mem, 4).map_err(|e| {
DispatchError::HandlerFailed {
library: "bsdsocket.library".to_string(),
lvo: -294,
handler_name: "SocketBaseTagList".to_string(),
message: format!(
"SocketBaseTagList: guest heap allocation failed: {e}"
),
}
})?;
ctx.mem.write_u32(addr, ctx.bsdsocket.last_errno as u32);
ctx.bsdsocket.errno_ptr = Some(addr);
addr
Expand All @@ -2733,17 +2729,16 @@ fn socket_base_tag_list_handler<C: Cpu>(
let ptr = match ctx.bsdsocket.herrno_ptr {
Some(ptr) => ptr,
None => {
let addr =
ctx.heap
.alloc(4)
.map_err(|e| DispatchError::HandlerFailed {
library: "bsdsocket.library".to_string(),
lvo: -294,
handler_name: "SocketBaseTagList".to_string(),
message: format!(
"SocketBaseTagList: guest heap allocation failed: {e}"
),
})?;
let addr = ctx.heap.alloc(&mut *ctx.mem, 4).map_err(|e| {
DispatchError::HandlerFailed {
library: "bsdsocket.library".to_string(),
lvo: -294,
handler_name: "SocketBaseTagList".to_string(),
message: format!(
"SocketBaseTagList: guest heap allocation failed: {e}"
),
}
})?;
ctx.mem.write_u32(addr, ctx.bsdsocket.last_herrno as u32);
ctx.bsdsocket.herrno_ptr = Some(addr);
addr
Expand Down Expand Up @@ -2795,17 +2790,16 @@ fn socket_base_tag_list_handler<C: Cpu>(
let buf = match ctx.bsdsocket.release_str_buf {
Some(addr) => addr,
None => {
let addr =
ctx.heap
.alloc(32)
.map_err(|e| DispatchError::HandlerFailed {
library: "bsdsocket.library".to_string(),
lvo: -294,
handler_name: "SocketBaseTagList".to_string(),
message: format!(
"SocketBaseTagList: guest heap allocation failed: {e}"
),
})?;
let addr = ctx.heap.alloc(&mut *ctx.mem, 32).map_err(|e| {
DispatchError::HandlerFailed {
library: "bsdsocket.library".to_string(),
lvo: -294,
handler_name: "SocketBaseTagList".to_string(),
message: format!(
"SocketBaseTagList: guest heap allocation failed: {e}"
),
}
})?;
crate::guestmem::write_c_string(
ctx.mem,
addr,
Expand Down
20 changes: 10 additions & 10 deletions crates/volamos-core/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1568,15 +1568,15 @@ fn open_library_common<C: Cpu>(
}

let size = FAKE_LIB_JUMP_TABLE_SIZE;
let block =
ctx.heap
.alloc(size + LIB_STRUCT_SIZE)
.map_err(|e| DispatchError::HandlerFailed {
library: "exec.library".to_string(),
lvo: -552,
handler_name: "OpenLibrary".to_string(),
message: format!("couldn't auto-create fake library {name:?}: {e}"),
})?;
let block = ctx
.heap
.alloc(&mut *ctx.mem, size + LIB_STRUCT_SIZE)
.map_err(|e| DispatchError::HandlerFailed {
library: "exec.library".to_string(),
lvo: -552,
handler_name: "OpenLibrary".to_string(),
message: format!("couldn't auto-create fake library {name:?}: {e}"),
})?;
let base = block.wrapping_add(size);

let mut addr = block;
Expand Down Expand Up @@ -2330,7 +2330,7 @@ impl<C: Cpu + 'static> Runtime<C> {
};
let line_len = line.len() as u32;
let args_addr = heap
.alloc(line_len + 1)
.alloc(&mut mem, line_len + 1)
.expect("guest heap has room for the command-line buffer");
{
let mut a = args_addr;
Expand Down
4 changes: 2 additions & 2 deletions crates/volamos-core/src/dosanchor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ fn set_flag_bit(mem: &mut dyn AddressSpace, ap_addr: u32, bit: u8, set: bool) {

fn alloc_achain(heap: &mut GuestHeap, mem: &mut dyn AddressSpace) -> Result<u32, i32> {
let addr = heap
.alloc(ACHAIN_SIZE)
.alloc(&mut *mem, ACHAIN_SIZE)
.map_err(|_| crate::dosfile::ERROR_NO_FREE_STORE)?;
for i in 0..ACHAIN_SIZE {
mem.write_u8(addr + i, 0);
Expand Down Expand Up @@ -825,7 +825,7 @@ mod tests {
/// `ap_Buf` tail, setting `ap_Strlen` accordingly.
fn alloc_ap(heap: &mut GuestHeap, mem: &mut FlatMemory, strlen: u16) -> u32 {
let size = AP_BUF_OFFSET + u32::from(strlen);
let addr = heap.alloc(size).unwrap();
let addr = heap.alloc(&mut *mem, size).unwrap();
for i in 0..size {
mem.write_u8(addr + i, 0);
}
Expand Down
16 changes: 8 additions & 8 deletions crates/volamos-core/src/dosargs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ fn alloc_c_string(
allocations: &mut Vec<u32>,
bytes: &[u8],
) -> Result<u32, GuestHeapError> {
let addr = heap.alloc(bytes.len() as u32 + 1)?;
let addr = heap.alloc(&mut *mem, bytes.len() as u32 + 1)?;
allocations.push(addr);
write_c_string(mem, addr, bytes);
Ok(addr)
Expand All @@ -508,7 +508,7 @@ fn materialize(
ArgKind::Switch | ArgKind::Toggle => u32::from(slot.bool_val),
ArgKind::Number => match slot.number {
Some(n) => {
let addr = heap.alloc(4)?;
let addr = heap.alloc(&mut *mem, 4)?;
allocations.push(addr);
mem.write_u32(addr, n as u32);
addr
Expand All @@ -528,7 +528,7 @@ fn materialize(
ptrs.push(alloc_c_string(heap, mem, &mut allocations, item)?);
}
ptrs.push(0);
let table_addr = heap.alloc(ptrs.len() as u32 * 4)?;
let table_addr = heap.alloc(&mut *mem, ptrs.len() as u32 * 4)?;
allocations.push(table_addr);
for (j, ptr) in ptrs.iter().enumerate() {
mem.write_u32(table_addr.wrapping_add((j as u32) * 4), *ptr);
Expand Down Expand Up @@ -583,7 +583,7 @@ fn read_args(
let (anchor_addr, owns_anchor) = if rdargs_ptr != 0 {
(rdargs_ptr, false)
} else {
let addr = heap.alloc(RDARGS_ANCHOR_SIZE).map_err(|_| {
let addr = heap.alloc(&mut *mem, RDARGS_ANCHOR_SIZE).map_err(|_| {
for a in &allocations {
let _ = heap.free(*a);
}
Expand Down Expand Up @@ -736,7 +736,7 @@ mod tests {
let mut heap = GuestHeap::new(0x100, 0x3000);
let mut line = cmdline.join(" ").into_bytes();
line.push(b'\n');
let addr = heap.alloc(line.len() as u32).unwrap();
let addr = heap.alloc(&mut mem, line.len() as u32).unwrap();
for (i, &b) in line.iter().enumerate() {
mem.write_u8(addr + i as u32, b);
}
Expand All @@ -754,7 +754,7 @@ mod tests {
template: &str,
slot_count: u32,
) -> (u32, u32) {
let array_addr = heap.alloc(slot_count * 4).unwrap();
let array_addr = heap.alloc(&mut *mem, slot_count * 4).unwrap();
for i in 0..slot_count {
mem.write_u32(array_addr + i * 4, 0);
}
Expand All @@ -772,7 +772,7 @@ mod tests {
template: &str,
slot_count: u32,
) -> i32 {
let array_addr = heap.alloc(slot_count * 4).unwrap();
let array_addr = heap.alloc(&mut *mem, slot_count * 4).unwrap();
for i in 0..slot_count {
mem.write_u32(array_addr + i * 4, 0);
}
Expand Down Expand Up @@ -945,7 +945,7 @@ mod tests {
#[test]
fn caller_supplied_rdargs_anchor_is_not_freed() {
let (mut heap, mut mem, mut dos) = setup(&["value"]);
let array_addr = heap.alloc(4).unwrap();
let array_addr = heap.alloc(&mut mem, 4).unwrap();
mem.write_u32(array_addr, 0);
let caller_rdargs = 0x2000; // not a heap allocation; FreeArgs must not touch it
let anchor = read_args(
Expand Down
6 changes: 3 additions & 3 deletions crates/volamos-core/src/dosdevlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ fn lock_dos_list(
) -> u32 {
let mut allocated = Vec::new();
let header = heap
.alloc(DOSLIST_SIZE)
.alloc(&mut *mem, DOSLIST_SIZE)
.expect("LockDosList: heap exhausted allocating header");
zero_doslist(mem, header);
// DLT_PRIVATE, not a real entry type: this node is a scan starting
Expand All @@ -148,7 +148,7 @@ fn lock_dos_list(
.unwrap_or_default();
for name in volumes {
let addr = heap
.alloc(DOSLIST_SIZE)
.alloc(&mut *mem, DOSLIST_SIZE)
.expect("LockDosList: heap exhausted allocating a DosList entry");
zero_doslist(mem, addr);
mem.write_u32(addr + DOL_TYPE_OFFSET, DLT_VOLUME as u32);
Expand All @@ -163,7 +163,7 @@ fn lock_dos_list(
let name_bytes = name.as_bytes();
// +1 length byte, +1 NUL courtesy byte (see module docs).
let name_addr = heap
.alloc(name_bytes.len() as u32 + 2)
.alloc(&mut *mem, name_bytes.len() as u32 + 2)
.expect("LockDosList: heap exhausted allocating dol_Name");
let written = write_bstr(mem, name_addr, name_bytes);
mem.write_u8(name_addr + 1 + written as u32, 0);
Expand Down
2 changes: 1 addition & 1 deletion crates/volamos-core/src/dosdevproc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ fn get_device_proc(
};

let lock_bptr = dos.lock(heap, mem, &dir_part, SHARED_LOCK)?;
match heap.alloc(DEVPROC_SIZE) {
match heap.alloc(&mut *mem, DEVPROC_SIZE) {
Ok(addr) => {
mem.write_u32(addr + DVP_PORT_OFFSET, 0);
mem.write_u32(addr + DVP_LOCK_OFFSET, lock_bptr);
Expand Down
26 changes: 13 additions & 13 deletions crates/volamos-core/src/dosfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ impl DosState {
return Ok(addr);
}
let addr = heap
.alloc(crate::execlist::MSGPORT_SIZE)
.alloc(&mut *mem, crate::execlist::MSGPORT_SIZE)
.map_err(|_| ERROR_NO_FREE_STORE)?;
for i in 0..crate::execlist::MSGPORT_SIZE {
mem.write_u8(addr.wrapping_add(i), 0);
Expand Down Expand Up @@ -562,7 +562,7 @@ impl DosState {
self.fs_port_addr(heap, mem)?
};
let addr = heap
.alloc(FILE_HANDLE_SIZE)
.alloc(&mut *mem, FILE_HANDLE_SIZE)
.map_err(|_| ERROR_NO_FREE_STORE)?;
for i in 0..FILE_HANDLE_SIZE {
mem.write_u8(addr.wrapping_add(i), 0);
Expand Down Expand Up @@ -1358,17 +1358,17 @@ fn alloc_dos_object_handler<C: Cpu>(ctx: &mut HandlerContext<'_, C>) -> Result<(
}
};

let addr = ctx
.heap
.alloc(struct_size)
.map_err(|e| DispatchError::HandlerFailed {
library: "dos.library".to_string(),
lvo: -228,
handler_name: "AllocDosObject".to_string(),
message: format!(
"AllocDosObject(type={object_type}): guest heap allocation failed: {e}"
),
})?;
let addr =
ctx.heap
.alloc(&mut *ctx.mem, struct_size)
.map_err(|e| DispatchError::HandlerFailed {
library: "dos.library".to_string(),
lvo: -228,
handler_name: "AllocDosObject".to_string(),
message: format!(
"AllocDosObject(type={object_type}): guest heap allocation failed: {e}"
),
})?;
for i in 0..struct_size {
ctx.mem.write_u8(addr.wrapping_add(i), 0);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/volamos-core/src/doslock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ fn alloc_lock_struct(
key: u32,
access: i32,
) -> Result<u32, crate::guestmem::GuestHeapError> {
let addr = heap.alloc(FILE_LOCK_SIZE)?;
let addr = heap.alloc(&mut *mem, FILE_LOCK_SIZE)?;
for i in 0..FILE_LOCK_SIZE {
mem.write_u8(addr.wrapping_add(i), 0);
}
Expand Down
Loading
Loading