Skip to content

Commit 8543e1b

Browse files
committed
Add documentation for Windows compatibility layer and remove unneeded attributes
1 parent 073d7ff commit 8543e1b

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/libstd/os.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,14 @@ pub mod win32 {
154154
use libc::types::os::arch::extra::{LPCWSTR, HMODULE, LPCSTR, LPVOID};
155155
use os::win32::as_utf16_p;
156156

157-
#[link_name="kernel32"]
158157
extern "system" {
159158
fn GetModuleHandleW(lpModuleName: LPCWSTR) -> HMODULE;
160159
fn GetProcAddress(hModule: HMODULE, lpProcName: LPCSTR) -> LPVOID;
161160
}
162161

162+
// store_func() is idempotent, so using relaxed ordering for the atomics should be enough.
163+
// This way, calling a function in this compatibility layer (after it's loaded) shouldn't
164+
// be any slower than a regular DLL call.
163165
unsafe fn store_func<T: Copy>(ptr: *mut T, module: &str, symbol: &str, fallback: T) {
164166
as_utf16_p(module, |module| {
165167
symbol.with_c_str(|symbol| {
@@ -170,6 +172,17 @@ pub mod win32 {
170172
})
171173
}
172174

175+
/// Macro for creating a compatibility fallback for a Windows function
176+
///
177+
/// # Example
178+
/// ```
179+
/// compat_fn!(adll32::SomeFunctionW(_arg: LPCWSTR) {
180+
/// // Fallback implementation
181+
/// })
182+
/// ```
183+
///
184+
/// Note that arguments unused by the fallback implementation should not be called `_` as
185+
/// they are used to be passed to the real function if available.
173186
macro_rules! compat_fn(
174187
($module:ident::$symbol:ident($($argname:ident: $argtype:ty),*)
175188
-> $rettype:ty $fallback:block) => (
@@ -198,11 +211,16 @@ pub mod win32 {
198211
)
199212
)
200213

214+
/// Compatibility layer for functions in `kernel32.dll`
215+
///
216+
/// Latest versions of Windows this is needed for:
217+
///
218+
/// * `CreateSymbolicLinkW`: Windows XP, Windows Server 2003
219+
/// * `GetFinalPathNameByHandleW`: Windows XP, Windows Server 2003
201220
pub mod kernel32 {
202221
use libc::types::os::arch::extra::{DWORD, LPCWSTR, BOOLEAN, HANDLE};
203222
use libc::consts::os::extra::ERROR_CALL_NOT_IMPLEMENTED;
204223

205-
#[link_name="kernel32"]
206224
extern "system" {
207225
fn SetLastError(dwErrCode: DWORD);
208226
}

0 commit comments

Comments
 (0)