Skip to content

Commit 9fa1c7d

Browse files
authored
Merge branch 'master' into master
2 parents 7f2a706 + a2fa282 commit 9fa1c7d

File tree

9 files changed

+749
-505
lines changed

9 files changed

+749
-505
lines changed

CHANGELOG.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,31 @@ This project adheres to [Semantic Versioning](http://semver.org/).
55

66
## [Unreleased]
77
### Added
8-
8+
- Add IP_RECVIF & IP_RECVDSTADDR. Enable IP_PKTINFO and IP6_PKTINFO on netbsd/openbsd.
9+
([#1002](https://github.com/nix-rust/nix/pull/1002))
910
- Added `inotify_init1`, `inotify_add_watch` and `inotify_rm_watch` wrappers for
1011
Android and Linux. ([#1016](https://github.com/nix-rust/nix/pull/1016))
11-
1212
### Changed
13+
- `PollFd` event flags renamed to `PollFlags` ([#1024](https://github.com/nix-rust/nix/pull/1024/))
14+
- `recvmsg` now returns an Iterator over `ControlMessageOwned` objects rather
15+
than `ControlMessage` objects. This is sadly not backwards-compatible. Fix
16+
code like this:
17+
```rust
18+
if let ControlMessage::ScmRights(&fds) = cmsg {
19+
```
20+
21+
By replacing it with code like this:
22+
```rust
23+
if let ControlMessageOwned::ScmRights(fds) = cmsg {
24+
```
25+
([#1020](https://github.com/nix-rust/nix/pull/1020))
26+
- Replaced `CmsgSpace` with the `cmsg_space` macro.
27+
([#1020](https://github.com/nix-rust/nix/pull/1020))
28+
1329
### Fixed
30+
- Fixed multiple bugs when using `sendmsg` and `recvmsg` with ancillary control messages
31+
([#1020](https://github.com/nix-rust/nix/pull/1020))
32+
1433
### Removed
1534

1635
## [0.13.0] - 2019-01-15
@@ -27,6 +46,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
2746
([#1010](https://github.com/nix-rust/nix/pull/1010))
2847
- Added `nix::sys::signal::signal`.
2948
([#817](https://github.com/nix-rust/nix/pull/817))
49+
- Added an `mprotect` wrapper.
50+
([#991](https://github.com/nix-rust/nix/pull/991))
3051

3152
### Changed
3253
### Fixed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ cc = "1"
2727
[dev-dependencies]
2828
bytes = "0.4.8"
2929
lazy_static = "1.2"
30-
rand = "0.5"
31-
tempfile = "3"
30+
rand = "0.6"
31+
tempfile = "3.0.5"
3232

3333
[target.'cfg(target_os = "freebsd")'.dev-dependencies]
3434
sysctl = "0.1"

src/poll.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,19 @@ pub struct PollFd {
2727
impl PollFd {
2828
/// Creates a new `PollFd` specifying the events of interest
2929
/// for a given file descriptor.
30-
pub fn new(fd: RawFd, events: EventFlags) -> PollFd {
30+
pub fn new(fd: RawFd, events: PollFlags) -> PollFd {
3131
PollFd {
3232
pollfd: libc::pollfd {
3333
fd: fd,
3434
events: events.bits(),
35-
revents: EventFlags::empty().bits(),
35+
revents: PollFlags::empty().bits(),
3636
},
3737
}
3838
}
3939

4040
/// Returns the events that occured in the last call to `poll` or `ppoll`.
41-
pub fn revents(&self) -> Option<EventFlags> {
42-
EventFlags::from_bits(self.pollfd.revents)
41+
pub fn revents(&self) -> Option<PollFlags> {
42+
PollFlags::from_bits(self.pollfd.revents)
4343
}
4444
}
4545

@@ -48,11 +48,11 @@ impl fmt::Debug for PollFd {
4848
let pfd = self.pollfd;
4949
let mut ds = f.debug_struct("PollFd");
5050
ds.field("fd", &pfd.fd);
51-
match EventFlags::from_bits(pfd.events) {
51+
match PollFlags::from_bits(pfd.events) {
5252
None => ds.field("events", &pfd.events),
5353
Some(ef) => ds.field("events", &ef),
5454
};
55-
match EventFlags::from_bits(pfd.revents) {
55+
match PollFlags::from_bits(pfd.revents) {
5656
None => ds.field("revents", &pfd.revents),
5757
Some(ef) => ds.field("revents", &ef),
5858
};
@@ -62,7 +62,7 @@ impl fmt::Debug for PollFd {
6262

6363
libc_bitflags! {
6464
/// These flags define the different events that can be monitored by `poll` and `ppoll`
65-
pub struct EventFlags: libc::c_short {
65+
pub struct PollFlags: libc::c_short {
6666
/// There is data to read.
6767
POLLIN;
6868
/// There is some exceptional condition on the file descriptor.

src/sys/mman.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,35 @@ pub unsafe fn madvise(addr: *mut c_void, length: size_t, advise: MmapAdvise) ->
258258
Errno::result(libc::madvise(addr, length, advise as i32)).map(drop)
259259
}
260260

261+
/// Set protection of memory mapping.
262+
///
263+
/// See [`mprotect(3)`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/mprotect.html) for
264+
/// details.
265+
///
266+
/// # Safety
267+
///
268+
/// Calls to `mprotect` are inherently unsafe, as changes to memory protections can lead to
269+
/// SIGSEGVs.
270+
///
271+
/// ```
272+
/// # use nix::libc::size_t;
273+
/// # use nix::sys::mman::{mmap, mprotect, MapFlags, ProtFlags};
274+
/// # use std::ptr;
275+
/// const ONE_K: size_t = 1024;
276+
/// let mut slice: &mut [u8] = unsafe {
277+
/// let mem = mmap(ptr::null_mut(), ONE_K, ProtFlags::PROT_NONE,
278+
/// MapFlags::MAP_ANON | MapFlags::MAP_PRIVATE, -1, 0).unwrap();
279+
/// mprotect(mem, ONE_K, ProtFlags::PROT_READ | ProtFlags::PROT_WRITE).unwrap();
280+
/// std::slice::from_raw_parts_mut(mem as *mut u8, ONE_K)
281+
/// };
282+
/// assert_eq!(slice[0], 0x00);
283+
/// slice[0] = 0xFF;
284+
/// assert_eq!(slice[0], 0xFF);
285+
/// ```
286+
pub unsafe fn mprotect(addr: *mut c_void, length: size_t, prot: ProtFlags) -> Result<()> {
287+
Errno::result(libc::mprotect(addr, length, prot.bits())).map(drop)
288+
}
289+
261290
pub unsafe fn msync(addr: *mut c_void, length: size_t, flags: MsFlags) -> Result<()> {
262291
Errno::result(libc::msync(addr, length, flags.bits())).map(drop)
263292
}

0 commit comments

Comments
 (0)