最近在写一个有栈协程库https://github.com/acl-dev/open-coroutine,其中用到了hook技术。
用户代码
use open_coroutine::{co, Yielder};
use std::os::raw::c_void;
use std::time::Duration;
extern "C" fn f1(
_yielder: &Yielder<Option<&'static mut c_void>, (), Option<&'static mut c_void>>,
_input: Option<&'static mut c_void>,
) -> Option<&'static mut c_void> {
println!("[coroutine1] launched");
None
}
extern "C" fn f2(
_yielder: &Yielder<Option<&'static mut c_void>, (), Option<&'static mut c_void>>,
_input: Option<&'static mut c_void>,
) -> Option<&'static mut c_void> {
println!("[coroutine2] launched");
None
}
fn main() {
co(f1, None, 4096);
co(f2, None, 4096);
std::thread::sleep(Duration::from_millis(1));
println!("scheduler finished successfully!");
}
正常输出
[coroutine1] launched
[coroutine2] launched
scheduler finished successfully!
我把std::thread::sleep(Duration::from_millis(1))
的底层系统调用nanosleep
hook了,使得它重定向到了新的实现open-coroutine/libhook/unix.rs
在我继续尝试hook其他系统函数时,出现了问题:通过CI构建出的新动态链接库,无法获取原始系统函数nanosleep
,也许这是rust的bug?
构建动态链接库的命令为cargo build --release -p libhook
代码改动见https://github.com/acl-dev/open-coroutine/pull/46
CI失败的页面:https://github.com/acl-dev/open-coroutine/actions/runs/3780190082/jobs/6426067579
向大佬们求助。
1
共 0 条评论, 1 页
评论区
写评论还没有评论