-
Notifications
You must be signed in to change notification settings - Fork 951
Add proc_raise_interval2 syscall
#6309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,15 +29,84 @@ pub fn proc_raise_interval( | |
| interval: Timestamp, | ||
| repeat: Bool, | ||
| ) -> Result<Errno, WasiError> { | ||
| println!("called regular raise"); | ||
| let env = ctx.data(); | ||
| let interval = match interval { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As @zebreus said, an we implement a helper function that uses Rust types, and make both old and new implementation use the helper, to avoid duplication?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah yeah, I wanted to open a PR to have a minimal PoC on the new syscall. Since we are good with the API now, I will do the refactors and add the tests to complete the PR.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Giving it some more thought, I think the functions are currently already implemented in a way that the main logic is shared. Note that the shared logic is:
And in terms of the use of proper Rust types. I kept the fields of |
||
| 0 => None, | ||
| a => Some(Duration::from_millis(a)), | ||
| }; | ||
| let repeat = matches!(repeat, Bool::True); | ||
| env.process.signal_interval(sig, interval, repeat); | ||
| let _ = env | ||
| .process | ||
| .signal_interval(sig, interval, if repeat { interval } else { None }); | ||
|
|
||
| WasiEnv::do_pending_operations(&mut ctx)?; | ||
|
|
||
| Ok(Errno::Success) | ||
| } | ||
|
|
||
| /// ### `proc_raise_interval2()` | ||
| /// Send a delayed signal to the process of the calling thread with an optional interval for repeated signaling. | ||
| /// Note: This is similar to `setitimer` in POSIX. | ||
| /// Inputs: | ||
| /// - `sig`: Signal to be raised for this process | ||
| /// - `new_ptr`: Pointer to the new value | ||
| /// - `ret_old`: Output pointer to the old value. If `null`, it's ignored. | ||
| pub fn proc_raise_interval2<M: MemorySize>( | ||
| mut ctx: FunctionEnvMut<'_, WasiEnv>, | ||
| sig: Signal, | ||
| new_ptr: WasmPtr<__wasi_itimerval_t, M>, | ||
| ret_old: WasmPtr<__wasi_itimerval_t, M>, | ||
| ) -> Result<Errno, WasiError> { | ||
| let env = ctx.data(); | ||
| let memory = unsafe { env.memory_view(&ctx) }; | ||
|
|
||
| let new_ptr = new_ptr.deref(&memory); | ||
| let new = wasi_try_ok!(new_ptr.read().map_err(crate::mem_error_to_wasi)); | ||
|
|
||
| let value = timeval_to_duration(new.value); | ||
| let interval = timeval_to_duration(new.interval); | ||
|
|
||
| println!("duration: {value:?} {interval:?}"); | ||
aeryz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| let old_value = env.process.signal_interval(sig, value, interval); | ||
|
|
||
| if !ret_old.is_null() { | ||
| let ret_ptr = ret_old.deref(&memory); | ||
| let zero = __wasi_timeval_t { sec: 0, usec: 0 }; | ||
| let ret_timer = match old_value { | ||
| Some(old_value) => __wasi_itimerval_t { | ||
| interval: if let Some(interval) = old_value.interval { | ||
| __wasi_timeval_t { | ||
| sec: interval.as_secs(), | ||
| usec: interval.subsec_micros().into(), | ||
| } | ||
| } else { | ||
| zero | ||
| }, | ||
| value: __wasi_timeval_t { | ||
|
||
| sec: old_value.current_value.as_secs(), | ||
| usec: old_value.current_value.subsec_micros().into(), | ||
| }, | ||
| }, | ||
| None => __wasi_itimerval_t { | ||
| interval: zero, | ||
| value: zero, | ||
| }, | ||
| }; | ||
|
|
||
| wasi_try_ok!(ret_ptr.write(ret_timer).map_err(crate::mem_error_to_wasi)); | ||
| } | ||
|
|
||
| WasiEnv::do_pending_operations(&mut ctx)?; | ||
|
|
||
| Ok(Errno::Success) | ||
| } | ||
|
|
||
| fn timeval_to_duration(tv: __wasi_timeval_t) -> Option<Duration> { | ||
| if tv.sec == 0 && tv.usec == 0 { | ||
|
||
| None | ||
| } else { | ||
| Some(Duration::from_secs(tv.sec) + Duration::from_micros(tv.usec)) | ||
| } | ||
| } | ||
|
||
Uh oh!
There was an error while loading. Please reload this page.