Skip to content

Commit

Permalink
some rust fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Fedor committed Jun 28, 2023
1 parent 9cff3c3 commit 3e54d27
Show file tree
Hide file tree
Showing 17 changed files with 134 additions and 35 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion third_party/rust/mio-named-pipes/.cargo-checksum.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"files":{"Cargo.toml":"d0a5c57e548259b2ef7d6e443f72a91775cfd20b926ccd88d7505ce24400faa1","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"378f5840b258e2779c39418f3f2d7b2ba96f1c7917dd6be0713f88305dbda397","README.md":"76068a8cb49c12b1f45599fe8ed1ed53554485afe1cc5302360cc73687458a1a","appveyor.yml":"0bd9b8e5a94a36972b37227cc59984fc6ec01b4ee4b617ef20d0e3acd19f44b1","src/from_raw_arc.rs":"c2cee14a0355256beb55a1feb54ccdcc50c8ab2d9abb3b7f114be00ed8a5583f","src/lib.rs":"30459bb034caad0b44ac23dc04bf11a326b88769398622a71e3a364927422cf3","tests/smoke.rs":"b1bd2ecbaae2a6458fdc2c50b8b1607277108196b607c12f47f4c5c78b9a250e"},"package":"82f43a815b57d2d652550f3d20cec88a495bb2d0956aa873dc43040278455677"}
{"files":{"Cargo.toml":"d0a5c57e548259b2ef7d6e443f72a91775cfd20b926ccd88d7505ce24400faa1","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"378f5840b258e2779c39418f3f2d7b2ba96f1c7917dd6be0713f88305dbda397","README.md":"76068a8cb49c12b1f45599fe8ed1ed53554485afe1cc5302360cc73687458a1a","appveyor.yml":"0bd9b8e5a94a36972b37227cc59984fc6ec01b4ee4b617ef20d0e3acd19f44b1","src/from_raw_arc.rs":"c2cee14a0355256beb55a1feb54ccdcc50c8ab2d9abb3b7f114be00ed8a5583f","tests/smoke.rs":"b1bd2ecbaae2a6458fdc2c50b8b1607277108196b607c12f47f4c5c78b9a250e"},"package":"82f43a815b57d2d652550f3d20cec88a495bb2d0956aa873dc43040278455677"}
6 changes: 6 additions & 0 deletions third_party/rust/mio-named-pipes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,12 @@ impl Inner {

unsafe fn cancel(handle: &AsRawHandle,
overlapped: &windows::Overlapped) -> io::Result<()> {
let o_ptr = overlapped.as_mut_ptr();
let h = (*o_ptr).hEvent;
(*o_ptr).Internal = winapi::STATUS_CANCELLED as u32;
let mut data_t:winapi::DWORD = 0;
kernel32::SetEvent(h);
kernel32::GetOverlappedResult(h, o_ptr, &mut data_t as *mut _, true as winapi::BOOL);
let ret = kernel32::CancelIo(handle.as_raw_handle());
if ret == 0 {
Err(io::Error::last_os_error())
Expand Down
2 changes: 1 addition & 1 deletion third_party/rust/mio/.cargo-checksum.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions third_party/rust/mio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ version = "0.3.2"
version = "0.2.42"
[target."cfg(windows)".dependencies.kernel32-sys]
version = "0.2"
[target."cfg(windows)".dependencies.ntdll-sys]
version = "0.2"

[target."cfg(windows)".dependencies.miow]
version = "0.2.1"
Expand Down
3 changes: 3 additions & 0 deletions third_party/rust/mio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ extern crate miow;
#[cfg(windows)]
extern crate winapi;

#[cfg(windows)]
extern crate ntdll;

#[cfg(windows)]
extern crate kernel32;

Expand Down
26 changes: 13 additions & 13 deletions third_party/rust/mio/src/sys/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,10 @@ use std::io;
use std::os::windows::prelude::*;
use std::mem;

//use winapi::um::ntifs::{FILE_IO_COMPLETION_NOTIFICATION_INFORMATION, IO_STATUS_BLOCK, NtSetInformationFile};

use kernel32;
use ntdll;
use winapi;


mod awakener;
#[macro_use]
mod selector;
Expand All @@ -167,6 +165,12 @@ enum Family {
unsafe fn cancel(socket: &AsRawSocket,
overlapped: &Overlapped) -> io::Result<()> {
let handle = socket.as_raw_socket() as winapi::HANDLE;
let o_ptr = overlapped.as_mut_ptr();
let h = (*o_ptr).hEvent;
(*o_ptr).Internal = winapi::STATUS_CANCELLED as u32;
let mut data_t:winapi::DWORD = 0;
kernel32::SetEvent(h);
kernel32::GetOverlappedResult(h, o_ptr, &mut data_t as *mut _, true as winapi::BOOL);
let ret = kernel32::CancelIo(handle);
if ret == 0 {
Err(io::Error::last_os_error())
Expand All @@ -176,19 +180,15 @@ unsafe fn cancel(socket: &AsRawSocket,
}

unsafe fn no_notify_on_instant_completion(handle: winapi::HANDLE) -> io::Result<()> {
const FILE_SKIP_COMPLETION_PORT_ON_SUCCESS: winapi::UCHAR = 1;
const FILE_SKIP_SET_EVENT_ON_HANDLE: winapi::UCHAR = 2;
/*let mut info: FILE_IO_COMPLETION_NOTIFICATION_INFORMATION = mem::zeroed();
let mut io: IO_STATUS_BLOCK = mem::zeroed();
info.Flags = FILE_SKIP_COMPLETION_PORT_ON_SUCCESS | FILE_SKIP_SET_EVENT_ON_HANDLE;
let r = NtQueryInformationFile(
let mut info: winapi::FILE_IO_COMPLETION_NOTIFICATION_INFORMATION = mem::zeroed();
let mut io: winapi::IO_STATUS_BLOCK = mem::zeroed();
info.Flags = 1|2; //FILE_SKIP_COMPLETION_PORT_ON_SUCCESS | FILE_SKIP_SET_EVENT_ON_HANDLE
let r = ntdll::NtSetInformationFile(
handle,
&mut io as *mut _ as *mut _,
&mut info as *mut _ as *mut _,
mem::size_of::<FILE_STANDARD_INFO>() as DWORD,
41);*/

let r=1;
mem::size_of::<winapi::FILE_STANDARD_INFO>() as winapi::DWORD,
41);
if r == 0 {
Ok(())
} else {
Expand Down
4 changes: 2 additions & 2 deletions third_party/rust/mio/src/sys/windows/selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl Selector {
events.clear();

trace!("polling IOCP");
/*let n = match self.inner.port.get_many(&mut events.statuses, timeout) {
let n = match self.inner.port.get_many(&mut events.statuses, timeout) {
Ok(statuses) => statuses.len(),
Err(ref e) if e.raw_os_error() == Some(WAIT_TIMEOUT as i32) => 0,
Err(e) => return Err(e),
Expand All @@ -98,7 +98,7 @@ impl Selector {

trace!("select; -> got overlapped");
callback(status.entry());
}*/
}

trace!("returning");
Ok(false)
Expand Down
2 changes: 1 addition & 1 deletion third_party/rust/miow/.cargo-checksum.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"files":{"Cargo.toml":"7a72c6e4b9cce0cd1105ab0234e8b3caae6c1bd7af2c41eae39f031becfc5a37","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"378f5840b258e2779c39418f3f2d7b2ba96f1c7917dd6be0713f88305dbda397","README.md":"05cefe09de4f980658e2868df1a220e3da5fd6ddb6d6c1eab1b5e6f5cb000879","appveyor.yml":"ffdfb9572a6362866bea6787a726b0d4e43f6bb6516f3a38ebdd561859531602","src/handle.rs":"ada6cf8482d49bc7be6d26adeb8ae47df9ff0a5637424474aa4a86ad699be63d","src/iocp.rs":"ced8c15c7f56add5a03475f6e490bb6ead22fb3ae1387841d4ac8a37319aebb8","src/lib.rs":"0d30428e89c7a2be7e479148211360a56d6c6b3b5a86d5ee7254277484506efa","src/net.rs":"054b8772bf51acc80b74a261f2d759645332288e03c72e2bd05c555364fe05bf","src/overlapped.rs":"b3c7f7b45fd9b22090bd11563decb09e9c412db8757c0e7484cfaa9ec5e29b9c","src/pipe.rs":"97ef5d456d7e5a72af2c4509a8155bd45a2a755275524ce1cd2d79f44f264c65"},"package":"8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919"}
{"files":{"Cargo.toml":"7a72c6e4b9cce0cd1105ab0234e8b3caae6c1bd7af2c41eae39f031becfc5a37","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"378f5840b258e2779c39418f3f2d7b2ba96f1c7917dd6be0713f88305dbda397","README.md":"05cefe09de4f980658e2868df1a220e3da5fd6ddb6d6c1eab1b5e6f5cb000879","appveyor.yml":"ffdfb9572a6362866bea6787a726b0d4e43f6bb6516f3a38ebdd561859531602","src/handle.rs":"ada6cf8482d49bc7be6d26adeb8ae47df9ff0a5637424474aa4a86ad699be63d","src/lib.rs":"0d30428e89c7a2be7e479148211360a56d6c6b3b5a86d5ee7254277484506efa","src/net.rs":"054b8772bf51acc80b74a261f2d759645332288e03c72e2bd05c555364fe05bf","src/overlapped.rs":"b3c7f7b45fd9b22090bd11563decb09e9c412db8757c0e7484cfaa9ec5e29b9c","src/pipe.rs":"97ef5d456d7e5a72af2c4509a8155bd45a2a755275524ce1cd2d79f44f264c65"},"package":"8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919"}
40 changes: 24 additions & 16 deletions third_party/rust/miow/src/iocp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,29 +132,37 @@ impl CompletionPort {
/// function does not wait to fill up the entire list of statuses provided.
///
/// Like with `get`, a timeout may be specified for this operation.
/*pub fn get_many<'a>(&self,
list: &'a mut [CompletionStatus],
timeout: Option<Duration>)
-> io::Result<&'a mut [CompletionStatus]>
{
debug_assert_eq!(mem::size_of::<CompletionStatus>(),
mem::size_of::<OVERLAPPED_ENTRY>());
pub fn get_many<'a>(
&self,
list: &'a mut [CompletionStatus],
timeout: Option<Duration>,
) -> io::Result<&'a mut [CompletionStatus]> {
debug_assert_eq!(
mem::size_of::<CompletionStatus>(),
mem::size_of::<OVERLAPPED_ENTRY>()
);
let mut removed = 0;
let mut d: DWORD = 0;
let timeout = ::dur2ms(timeout);
let len = cmp::min(list.len(), <ULONG>::max_value() as usize) as ULONG;
let ret = unsafe {
GetQueuedCompletionStatusEx(self.handle.raw(),
list.as_ptr() as *mut _,
len,
&mut removed,
timeout,
FALSE)
};
let mut ret = 0;
for i in 0..len - 1 {
let mut oe = list[i as usize].entry();
ret = unsafe {
GetQueuedCompletionStatus(
self.handle.raw(),
&mut d as *mut _,
oe.lpCompletionKey as *mut _,
oe.lpOverlapped as *mut _,
timeout,
)
};
}
match ::cvt(ret) {
Ok(_) => Ok(&mut list[..removed as usize]),
Err(e) => Err(e),
}
}*/
}

/// Posts a new completion status onto this I/O completion port.
///
Expand Down
1 change: 1 addition & 0 deletions third_party/rust/ntdll-sys/.cargo-checksum.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"files":{},"package":"1234567890"}
15 changes: 15 additions & 0 deletions third_party/rust/ntdll-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "ntdll-sys"
version = "0.2.2"
authors = ["feodor2 <[email protected]>"]
description = "Contains function definitions for the Windows API library ntdll. See winapi for types and constants."
readme = "README.md"
keywords = ["windows", "ffi", "win32"]
license = "MIT"
build = "build.rs"
[lib]
name = "ntdll"
[dependencies]
winapi = { version = "0.2.5", path = "../.." }
[build-dependencies]
winapi-build = { version = "0.1.1", path = "../../build" }
11 changes: 11 additions & 0 deletions third_party/rust/ntdll-sys/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# ntdll #
Contains function definitions for the Windows API library ntdll. See winapi for types and constants.

```toml
[dependencies]
ntdll-sys = "0.2.1"
```

```rust
extern crate ntdll;
```
4 changes: 4 additions & 0 deletions third_party/rust/ntdll-sys/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
extern crate build;
fn main() {
build::link("ntdll", false)
}
20 changes: 20 additions & 0 deletions third_party/rust/ntdll-sys/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//! FFI bindings to ntdll.
#![cfg(windows)]
extern crate winapi;
use winapi::*;
extern "system" {
pub fn NtQueryInformationFile(
hFile: HANDLE,
IoStatusBlock: PIO_STATUS_BLOCK,
FileInformation: PVOID,
Length: ULONG,
FileInformationClass: UINT,
) -> NTSTATUS;
pub fn NtSetInformationFile(
hFile: HANDLE,
IoStatusBlock: PIO_STATUS_BLOCK,
FileInformation: PVOID,
Length: ULONG,
FileInformationClass: UINT,
) -> NTSTATUS;
}
Loading

0 comments on commit 3e54d27

Please sign in to comment.