-
Notifications
You must be signed in to change notification settings - Fork 677
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #311 - fiveop:context, r=@kamalmarhubi
Add context module. The module wraps context handling related functions and structs.
- Loading branch information
Showing
3 changed files
with
32 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
#[cfg(any(target_os = "linux", target_os = "android"))] | ||
pub mod epoll; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use libc; | ||
use {Errno, Result}; | ||
use std::mem; | ||
|
||
#[derive(Clone, Copy)] | ||
pub struct UContext { | ||
context: libc::ucontext_t, | ||
} | ||
|
||
impl UContext { | ||
pub fn get() -> Result<UContext> { | ||
let mut context: libc::ucontext_t = unsafe { mem::uninitialized() }; | ||
let res = unsafe { | ||
libc::getcontext(&mut context as *mut libc::ucontext_t) | ||
}; | ||
Errno::result(res).map(|_| UContext { context: context }) | ||
} | ||
|
||
pub fn set(&self) -> Result<()> { | ||
let res = unsafe { | ||
libc::setcontext(&self.context as *const libc::ucontext_t) | ||
}; | ||
Errno::result(res).map(drop) | ||
} | ||
} |