Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 035d96b

Browse files
Fix memmove/memset and add tests
This could've gone unnoticed for a while since we didn't have coverage for these functions.
1 parent 0551959 commit 035d96b

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed

‎src/table/boot.rs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,33 @@ pub struct BootServices {
4747
unload_image: usize,
4848
exit_boot_services: extern "C" fn(Handle, MemoryMapKey) -> Status,
4949

50-
// Misc functions
50+
// Misc services
5151
get_next_monotonic_count: usize,
5252
stall: extern "C" fn(usize) -> Status,
53-
copy_mem: extern "C" fn(dest: usize, src: usize, len: usize),
54-
set_mem: extern "C" fn(buffer: usize, len: usize, value: u8),
53+
set_watchdog_timer: usize,
54+
55+
// Driver support services
56+
connect_controller: usize,
57+
disconnect_controller: usize,
58+
59+
// Protocol open / close services
60+
open_protocol: usize,
61+
close_protocol: usize,
62+
open_protocol_information: usize,
63+
64+
// Library services
65+
protocols_per_handle: usize,
66+
locate_handle_buffer: usize,
67+
locate_protocol: usize,
68+
install_multiple_protocol_interfaces: usize,
69+
uninstall_multiple_protocol_interfaces: usize,
70+
71+
// CRC services
72+
calculate_crc32: usize,
73+
74+
// Misc services
75+
copy_mem: extern "C" fn(dest: *mut u8, src: *const u8, len: usize),
76+
set_mem: extern "C" fn(buffer: *mut u8, len: usize, value: u8),
5577

5678
// New event functions (UEFI 2.0 or newer)
5779
create_event_ex: usize,
@@ -215,12 +237,12 @@ impl BootServices {
215237
}
216238

217239
/// Copies memory from source to destination. The buffers can overlap.
218-
pub fn memmove(&self, dest: usize, src: usize, size: usize) {
240+
pub fn memmove(&self, dest: *mutu8, src: *constu8, size: usize) {
219241
(self.copy_mem)(dest, src, size);
220242
}
221243

222244
/// Sets a buffer to a certain value.
223-
pub fn memset(&self, buffer: usize, size: usize, value: u8) {
245+
pub fn memset(&self, buffer: *mutu8, size: usize, value: u8) {
224246
(self.set_mem)(buffer, size, value);
225247
}
226248
}

‎uefi-test-runner/src/boot/memory.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::alloc::vec::Vec;
66
pub fn test(bt: &BootServices) {
77
allocate_pages(bt);
88
vec_alloc();
9+
memmove(bt);
910

1011
memory_map(bt);
1112
}
@@ -43,6 +44,22 @@ fn vec_alloc() {
4344
assert_eq!(values[..], [-5, 0, 4, 16, 23], "Failed to sort vector");
4445
}
4546

47+
// Test that the `memmove` / `memset` functions work.
48+
fn memmove(bt: &BootServices) {
49+
let src = [1, 2, 3, 4];
50+
let mut dest = [0u8; 4];
51+
52+
// Fill the buffer with a value
53+
bt.memset(dest.as_mut_ptr(), dest.len(), 1);
54+
55+
assert_eq!(dest, [1; 4], "Failed to set memory");
56+
57+
// Copy other values on it
58+
bt.memmove(dest.as_mut_ptr(), src.as_ptr(), dest.len());
59+
60+
assert_eq!(dest, src, "Failed to copy memory");
61+
}
62+
4663
fn memory_map(bt: &BootServices) {
4764
// Get an estimate of the memory map size.
4865
let map_sz = bt.memory_map_size();

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /