Skip to content

Commit 14daaa9

Browse files
authored
Add support for asm, rename and alias nightly to beta (#8)
1 parent cbea31e commit 14daaa9

File tree

6 files changed

+29
-31
lines changed

6 files changed

+29
-31
lines changed

Cargo.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ edition = "2018"
1414

1515
[package.metadata.docs.rs]
1616
default-target = "x86_64-pc-windows-msvc"
17-
features = ["nightly"]
17+
features = ["beta"]
1818
targets = ["aarch64-pc-windows-msvc", "i686-pc-windows-msvc", "x86_64-pc-windows-msvc"]
1919

2020
[dependencies.winapi]
@@ -27,4 +27,5 @@ func-types = []
2727
impl-default = ["winapi/impl-default"]
2828
user = []
2929
kernel = []
30-
nightly = []
30+
beta = []
31+
nightly = ["beta"]

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Rust FFI bindings for Native API. Mostly based on Process Hacker [phnt](https://github.com/processhacker/processhacker/tree/master/phnt) headers as the most complete source of bindings to be found. The comments there also contain useful information on how to use specific things.
44

55
### Minimum supported Rust
6-
Always the latest stable. Some [features][docs_link] require a nightly compiler.
6+
Always the latest stable. Some [features][docs_link] require a beta compiler.
77

88
[travis_link]: https://travis-ci.org/MSxDOS/ntapi
99
[travis_badge]: https://travis-ci.org/MSxDOS/ntapi.svg?branch=master

src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! **`impl-default`** -- Implement [`Default`] for structs and unions.<br/>
44
//! **`user`** *(default)* -- Link to `ntdll`.<br/>
55
//! **`kernel`** -- Link to `ntoskrnl` on MSVC targets.<br/>
6-
//! **`nightly`** -- Unlock unstable features that require a nightly compiler:
6+
//! **`beta`** -- Unlock unstable features that require a beta compiler:
77
//! - [`NtCurrentTeb`]
88
//! - [`__readfsdword`]
99
//! - [`__readgsqword`]
@@ -30,7 +30,6 @@
3030
#![deny(unused, unused_qualifications)]
3131
#![warn(unused_attributes)]
3232
#![allow(bad_style, overflowing_literals, unused_macros, clippy::cast_lossless, clippy::cast_ptr_alignment, clippy::len_without_is_empty, clippy::trivially_copy_pass_by_ref, clippy::unreadable_literal)]
33-
#![cfg_attr(feature = "nightly", feature(llvm_asm))]
3433
#[doc(hidden)]
3534
pub extern crate core as _core;
3635
#[macro_use]

src/ntpsapi.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use winapi::um::winnt::{
1919
PROCESS_MITIGATION_STRICT_HANDLE_CHECK_POLICY, PROCESS_MITIGATION_SYSTEM_CALL_DISABLE_POLICY,
2020
PROCESS_MITIGATION_SYSTEM_CALL_FILTER_POLICY, PSECURITY_QUALITY_OF_SERVICE,
2121
};
22-
#[cfg(all(feature = "nightly", not(target_arch = "aarch64")))]
22+
#[cfg(all(feature = "beta", not(target_arch = "aarch64")))]
2323
use crate::winapi_local::um::winnt::NtCurrentTeb;
2424
pub const GDI_HANDLE_BUFFER_SIZE32: usize = 34;
2525
pub const GDI_HANDLE_BUFFER_SIZE64: usize = 60;
@@ -932,19 +932,19 @@ pub const NtCurrentThread: HANDLE = -2isize as *mut c_void;
932932
pub const ZwCurrentThread: HANDLE = NtCurrentThread;
933933
pub const NtCurrentSession: HANDLE = -3isize as *mut c_void;
934934
pub const ZwCurrentSession: HANDLE = NtCurrentSession;
935-
#[inline] #[cfg(all(feature = "nightly", not(target_arch = "aarch64")))]
935+
#[inline] #[cfg(all(feature = "beta", not(target_arch = "aarch64")))]
936936
pub unsafe fn NtCurrentPeb() -> PPEB {
937937
(*NtCurrentTeb()).ProcessEnvironmentBlock
938938
}
939939
pub const NtCurrentProcessToken: HANDLE = -4isize as *mut c_void;
940940
pub const NtCurrentThreadToken: HANDLE = -5isize as *mut c_void;
941941
pub const NtCurrentEffectiveToken: HANDLE = -6isize as *mut c_void;
942942
pub const NtCurrentSilo: HANDLE = -1isize as *mut c_void;
943-
#[inline] #[cfg(all(feature = "nightly", not(target_arch = "aarch64")))]
943+
#[inline] #[cfg(all(feature = "beta", not(target_arch = "aarch64")))]
944944
pub unsafe fn NtCurrentProcessId() -> HANDLE {
945945
(*NtCurrentTeb()).ClientId.UniqueProcess
946946
}
947-
#[inline] #[cfg(all(feature = "nightly", not(target_arch = "aarch64")))]
947+
#[inline] #[cfg(all(feature = "beta", not(target_arch = "aarch64")))]
948948
pub unsafe fn NtCurrentThreadId() -> HANDLE {
949949
(*NtCurrentTeb()).ClientId.UniqueThread
950950
}

src/ntrtl.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2196,7 +2196,7 @@ EXTERN!{extern "system" {
21962196
MakeReadOnly: BOOLEAN,
21972197
);
21982198
}}
2199-
#[inline] #[cfg(all(feature = "nightly", not(target_arch = "aarch64")))]
2199+
#[inline] #[cfg(all(feature = "beta", not(target_arch = "aarch64")))]
22002200
pub unsafe fn RtlProcessHeap() -> PVOID {
22012201
use crate::ntpsapi::NtCurrentPeb;
22022202
(*NtCurrentPeb()).ProcessHeap
@@ -2944,13 +2944,13 @@ EXTERN!{extern "system" {
29442944
}}
29452945
#[inline]
29462946
pub unsafe fn RtlCheckBit(BitMapHeader: &RTL_BITMAP, BitPosition: ULONG) -> u8 {
2947-
#[cfg(all(target_arch = "x86_64", feature = "nightly"))] {
2947+
#[cfg(all(target_arch = "x86_64", feature = "beta"))] {
29482948
use crate::winapi_local::um::winnt::_bittest64;
29492949
_bittest64(BitMapHeader.Buffer as *const i64, BitPosition as i64)
29502950
}
29512951
#[cfg(any(
29522952
target_arch = "x86",
2953-
all(target_arch = "x86_64", not(feature = "nightly")),
2953+
all(target_arch = "x86_64", not(feature = "beta")),
29542954
target_arch = "aarch64",
29552955
))] {
29562956
(*BitMapHeader.Buffer.offset(BitPosition as isize / 32) >> (BitPosition % 32) & 1) as u8

src/winapi_local/um/winnt.rs

+17-19
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#[cfg(all(feature = "beta", not(target_arch = "aarch64")))]
2+
use core::arch::asm;
13
use winapi::shared::basetsd::{DWORD64, SIZE_T, ULONG64};
24
use winapi::shared::minwindef::DWORD;
35
use winapi::um::winnt::{HANDLE, PVOID};
@@ -6,40 +8,36 @@ use winapi::um::winnt::{HANDLE, PVOID};
68
pub const fn UInt32x32To64(a: u32, b: u32) -> u64 {
79
a as u64 * b as u64
810
}
9-
#[cfg(all(feature = "nightly", not(target_arch = "aarch64")))]
11+
#[cfg(all(feature = "beta", not(target_arch = "aarch64")))]
1012
IFDEF!{
1113
use crate::ntpebteb::TEB;
1214
#[inline]
1315
pub unsafe fn _bittest64(Base: *const i64, Offset: i64) -> u8 {
1416
let out: u8;
15-
llvm_asm!("bt $1, $2; setb $0"
16-
: "=r"(out)
17-
: "*m"(Base), "r"(Offset)
18-
: "cc"
19-
: "intel"
20-
);
17+
asm!(
18+
"bt {1}, {2}",
19+
"setb {0}",
20+
out(reg_byte) out,
21+
in(reg) Base,
22+
in(reg) Offset);
2123
out
2224
}
2325
#[inline]
2426
pub unsafe fn __readfsdword(Offset: DWORD) -> DWORD {
2527
let out: u32;
26-
llvm_asm!("mov $0, fs:[$1]"
27-
: "=r"(out)
28-
: "ri"(Offset)
29-
:
30-
: "intel"
31-
);
28+
asm!(
29+
"mov {0:e}, fs:[{1:e}]",
30+
out(reg) out,
31+
in(reg) Offset);
3232
out
3333
}
3434
#[inline]
3535
pub unsafe fn __readgsqword(Offset: DWORD) -> DWORD64 {
3636
let out: u64;
37-
llvm_asm!("mov $0, gs:[$1]"
38-
: "=r"(out)
39-
: "ri"(Offset)
40-
:
41-
: "intel"
42-
);
37+
asm!(
38+
"mov {0}, gs:[{1:e}]",
39+
out(reg) out,
40+
in(reg) Offset);
4341
out
4442
}
4543
#[inline] #[allow(unused_unsafe)]

0 commit comments

Comments
 (0)