@@ -154,12 +154,14 @@ pub mod win32 {
154
154
use libc:: types:: os:: arch:: extra:: { LPCWSTR , HMODULE , LPCSTR , LPVOID } ;
155
155
use os:: win32:: as_utf16_p;
156
156
157
- #[ link_name="kernel32" ]
158
157
extern "system" {
159
158
fn GetModuleHandleW ( lpModuleName : LPCWSTR ) -> HMODULE ;
160
159
fn GetProcAddress ( hModule : HMODULE , lpProcName : LPCSTR ) -> LPVOID ;
161
160
}
162
161
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.
163
165
unsafe fn store_func < T : Copy > ( ptr : * mut T , module : & str , symbol : & str , fallback : T ) {
164
166
as_utf16_p ( module, |module| {
165
167
symbol. with_c_str ( |symbol| {
@@ -170,6 +172,17 @@ pub mod win32 {
170
172
} )
171
173
}
172
174
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.
173
186
macro_rules! compat_fn(
174
187
( $module: ident:: $symbol: ident( $( $argname: ident: $argtype: ty) ,* )
175
188
-> $rettype: ty $fallback: block) => (
@@ -198,11 +211,16 @@ pub mod win32 {
198
211
)
199
212
)
200
213
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
201
220
pub mod kernel32 {
202
221
use libc:: types:: os:: arch:: extra:: { DWORD , LPCWSTR , BOOLEAN , HANDLE } ;
203
222
use libc:: consts:: os:: extra:: ERROR_CALL_NOT_IMPLEMENTED ;
204
223
205
- #[ link_name="kernel32" ]
206
224
extern "system" {
207
225
fn SetLastError ( dwErrCode : DWORD ) ;
208
226
}
0 commit comments