Skip to content

Commit db3abd3

Browse files
committed
Add function pointer test
1 parent 541d45d commit db3abd3

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

vm/src/vm.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1994,6 +1994,24 @@ mod tests
19941994
eval_i64(" push FN; call_fp 0; ret; FN: push_i8 33; ret;", 33);
19951995
}
19961996

1997+
#[test]
1998+
fn test_patch_fp()
1999+
{
2000+
// Patch a function's code address into the data segment at runtime,
2001+
// then load it back and call it via call_fp
2002+
eval_i64(
2003+
".data; FPTR: .u64 0; .code; push FPTR; push FN; store_u64; push FPTR; load_u64; call_fp 0; ret; FN: push_i8 33; ret;",
2004+
33
2005+
);
2006+
2007+
// Same, but the code address is assembled into the data segment
2008+
// statically using the .addr64 directive
2009+
eval_i64(
2010+
".data; FPTR: .addr64 FN; .code; push FPTR; load_u64; call_fp 0; ret; FN: push_i8 33; ret;",
2011+
33
2012+
);
2013+
}
2014+
19972015
#[test]
19982016
fn test_syscalls()
19992017
{

0 commit comments

Comments
 (0)