Skip to content

Commit 05b6a2f

Browse files
committed
std: Add Win64 support
Some extern blobs are duplicated without "stdcall" abi, since Win64 does not use any calling convention. (Giving any abi to them causes llvm producing wrong bytecode.)
1 parent 6aff4c6 commit 05b6a2f

File tree

4 files changed

+162
-3
lines changed

4 files changed

+162
-3
lines changed

src/libstd/libc.rs

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3259,6 +3259,7 @@ pub mod funcs {
32593259
LPSYSTEM_INFO};
32603260
use libc::types::os::arch::extra::{HANDLE, LPHANDLE};
32613261

3262+
#[cfg(target_arch = "x86")]
32623263
#[abi = "stdcall"]
32633264
extern "stdcall" {
32643265
pub fn GetEnvironmentVariableW(n: LPCWSTR,
@@ -3363,6 +3364,111 @@ pub mod funcs {
33633364
-> LPVOID;
33643365
pub fn UnmapViewOfFile(lpBaseAddress: LPCVOID) -> BOOL;
33653366
}
3367+
3368+
#[cfg(target_arch = "x86_64")]
3369+
extern {
3370+
pub fn GetEnvironmentVariableW(n: LPCWSTR,
3371+
v: LPWSTR,
3372+
nsize: DWORD)
3373+
-> DWORD;
3374+
pub fn SetEnvironmentVariableW(n: LPCWSTR, v: LPCWSTR)
3375+
-> BOOL;
3376+
pub fn GetEnvironmentStringsA() -> LPTCH;
3377+
pub fn FreeEnvironmentStringsA(env_ptr: LPTCH) -> BOOL;
3378+
pub fn GetModuleFileNameW(hModule: HMODULE,
3379+
lpFilename: LPWSTR,
3380+
nSize: DWORD)
3381+
-> DWORD;
3382+
pub fn CreateDirectoryW(lpPathName: LPCWSTR,
3383+
lpSecurityAttributes:
3384+
LPSECURITY_ATTRIBUTES)
3385+
-> BOOL;
3386+
pub fn CopyFileW(lpExistingFileName: LPCWSTR,
3387+
lpNewFileName: LPCWSTR,
3388+
bFailIfExists: BOOL)
3389+
-> BOOL;
3390+
pub fn DeleteFileW(lpPathName: LPCWSTR) -> BOOL;
3391+
pub fn RemoveDirectoryW(lpPathName: LPCWSTR) -> BOOL;
3392+
pub fn SetCurrentDirectoryW(lpPathName: LPCWSTR) -> BOOL;
3393+
pub fn GetLastError() -> DWORD;
3394+
pub fn FindFirstFileW(fileName: *u16, findFileData: HANDLE)
3395+
-> HANDLE;
3396+
pub fn FindNextFileW(findFile: HANDLE, findFileData: HANDLE)
3397+
-> BOOL;
3398+
pub fn FindClose(findFile: HANDLE) -> BOOL;
3399+
pub fn DuplicateHandle(hSourceProcessHandle: HANDLE,
3400+
hSourceHandle: HANDLE,
3401+
hTargetProcessHandle: HANDLE,
3402+
lpTargetHandle: LPHANDLE,
3403+
dwDesiredAccess: DWORD,
3404+
bInheritHandle: BOOL,
3405+
dwOptions: DWORD)
3406+
-> BOOL;
3407+
pub fn CloseHandle(hObject: HANDLE) -> BOOL;
3408+
pub fn OpenProcess(dwDesiredAccess: DWORD,
3409+
bInheritHandle: BOOL,
3410+
dwProcessId: DWORD)
3411+
-> HANDLE;
3412+
pub fn GetCurrentProcess() -> HANDLE;
3413+
pub fn CreateProcessA(lpApplicationName: LPCTSTR,
3414+
lpCommandLine: LPTSTR,
3415+
lpProcessAttributes:
3416+
LPSECURITY_ATTRIBUTES,
3417+
lpThreadAttributes:
3418+
LPSECURITY_ATTRIBUTES,
3419+
bInheritHandles: BOOL,
3420+
dwCreationFlags: DWORD,
3421+
lpEnvironment: LPVOID,
3422+
lpCurrentDirectory: LPCTSTR,
3423+
lpStartupInfo: LPSTARTUPINFO,
3424+
lpProcessInformation:
3425+
LPPROCESS_INFORMATION)
3426+
-> BOOL;
3427+
pub fn WaitForSingleObject(hHandle: HANDLE,
3428+
dwMilliseconds: DWORD)
3429+
-> DWORD;
3430+
pub fn TerminateProcess(hProcess: HANDLE, uExitCode: c_uint)
3431+
-> BOOL;
3432+
pub fn GetExitCodeProcess(hProcess: HANDLE,
3433+
lpExitCode: LPDWORD)
3434+
-> BOOL;
3435+
pub fn GetSystemInfo(lpSystemInfo: LPSYSTEM_INFO);
3436+
pub fn VirtualAlloc(lpAddress: LPVOID,
3437+
dwSize: SIZE_T,
3438+
flAllocationType: DWORD,
3439+
flProtect: DWORD)
3440+
-> LPVOID;
3441+
pub fn VirtualFree(lpAddress: LPVOID,
3442+
dwSize: SIZE_T,
3443+
dwFreeType: DWORD)
3444+
-> BOOL;
3445+
pub fn VirtualLock(lpAddress: LPVOID, dwSize: SIZE_T) -> BOOL;
3446+
pub fn VirtualUnlock(lpAddress: LPVOID, dwSize: SIZE_T)
3447+
-> BOOL;
3448+
pub fn VirtualProtect(lpAddress: LPVOID,
3449+
dwSize: SIZE_T,
3450+
flNewProtect: DWORD,
3451+
lpflOldProtect: LPDWORD)
3452+
-> BOOL;
3453+
pub fn VirtualQuery(lpAddress: LPCVOID,
3454+
lpBuffer: LPMEMORY_BASIC_INFORMATION,
3455+
dwLength: SIZE_T)
3456+
-> SIZE_T;
3457+
pub fn CreateFileMappingW(hFile: HANDLE,
3458+
lpAttributes: LPSECURITY_ATTRIBUTES,
3459+
flProtect: DWORD,
3460+
dwMaximumSizeHigh: DWORD,
3461+
dwMaximumSizeLow: DWORD,
3462+
lpName: LPCTSTR)
3463+
-> HANDLE;
3464+
pub fn MapViewOfFile(hFileMappingObject: HANDLE,
3465+
dwDesiredAccess: DWORD,
3466+
dwFileOffsetHigh: DWORD,
3467+
dwFileOffsetLow: DWORD,
3468+
dwNumberOfBytesToMap: SIZE_T)
3469+
-> LPVOID;
3470+
pub fn UnmapViewOfFile(lpBaseAddress: LPCVOID) -> BOOL;
3471+
}
33663472
}
33673473

33683474
pub mod msvcrt {

src/libstd/os.rs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,12 +1042,19 @@ pub fn errno() -> uint {
10421042
#[fixed_stack_segment]; #[inline(never)];
10431043
use libc::types::os::arch::extra::DWORD;
10441044

1045+
#[cfg(target_arch = "x86")]
10451046
#[link_name = "kernel32"]
10461047
#[abi = "stdcall"]
10471048
extern "stdcall" {
10481049
fn GetLastError() -> DWORD;
10491050
}
10501051

1052+
#[cfg(target_arch = "x86_64")]
1053+
#[link_name = "kernel32"]
1054+
extern {
1055+
fn GetLastError() -> DWORD;
1056+
}
1057+
10511058
unsafe {
10521059
GetLastError() as uint
10531060
}
@@ -1113,6 +1120,7 @@ pub fn last_os_error() -> ~str {
11131120
use libc::types::os::arch::extra::LPSTR;
11141121
use libc::types::os::arch::extra::LPVOID;
11151122

1123+
#[cfg(target_arch = "x86")]
11161124
#[link_name = "kernel32"]
11171125
#[abi = "stdcall"]
11181126
extern "stdcall" {
@@ -1126,6 +1134,19 @@ pub fn last_os_error() -> ~str {
11261134
-> DWORD;
11271135
}
11281136

1137+
#[cfg(target_arch = "x86_64")]
1138+
#[link_name = "kernel32"]
1139+
extern {
1140+
fn FormatMessageA(flags: DWORD,
1141+
lpSrc: LPVOID,
1142+
msgId: DWORD,
1143+
langId: DWORD,
1144+
buf: LPSTR,
1145+
nsize: DWORD,
1146+
args: *c_void)
1147+
-> DWORD;
1148+
}
1149+
11291150
static FORMAT_MESSAGE_FROM_SYSTEM: DWORD = 0x00001000;
11301151
static FORMAT_MESSAGE_IGNORE_INSERTS: DWORD = 0x00000200;
11311152

@@ -1241,21 +1262,34 @@ fn real_args() -> ~[~str] {
12411262

12421263
type LPCWSTR = *u16;
12431264

1244-
#[cfg(windows)]
1265+
#[cfg(windows, target_arch = "x86")]
12451266
#[link_name="kernel32"]
12461267
#[abi="stdcall"]
12471268
extern "stdcall" {
12481269
fn GetCommandLineW() -> LPCWSTR;
12491270
fn LocalFree(ptr: *c_void);
12501271
}
12511272

1252-
#[cfg(windows)]
1273+
#[cfg(windows, target_arch = "x86_64")]
1274+
#[link_name="kernel32"]
1275+
extern {
1276+
fn GetCommandLineW() -> LPCWSTR;
1277+
fn LocalFree(ptr: *c_void);
1278+
}
1279+
1280+
#[cfg(windows, target_arch = "x86")]
12531281
#[link_name="shell32"]
12541282
#[abi="stdcall"]
12551283
extern "stdcall" {
12561284
fn CommandLineToArgvW(lpCmdLine: LPCWSTR, pNumArgs: *mut c_int) -> **u16;
12571285
}
12581286

1287+
#[cfg(windows, target_arch = "x86_64")]
1288+
#[link_name="shell32"]
1289+
extern {
1290+
fn CommandLineToArgvW(lpCmdLine: LPCWSTR, pNumArgs: *mut c_int) -> **u16;
1291+
}
1292+
12591293
struct OverriddenArgs {
12601294
val: ~[~str]
12611295
}

src/libstd/rt/thread_local_storage.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,21 @@ pub unsafe fn get(key: Key) -> *mut c_void {
8686
TlsGetValue(key)
8787
}
8888

89-
#[cfg(windows)]
89+
#[cfg(windows, target_arch = "x86")]
9090
#[abi = "stdcall"]
9191
extern "stdcall" {
9292
fn TlsAlloc() -> DWORD;
9393
fn TlsSetValue(dwTlsIndex: DWORD, lpTlsvalue: LPVOID) -> BOOL;
9494
fn TlsGetValue(dwTlsIndex: DWORD) -> LPVOID;
9595
}
9696

97+
#[cfg(windows, target_arch = "x86_64")]
98+
extern {
99+
fn TlsAlloc() -> DWORD;
100+
fn TlsSetValue(dwTlsIndex: DWORD, lpTlsvalue: LPVOID) -> BOOL;
101+
fn TlsGetValue(dwTlsIndex: DWORD) -> LPVOID;
102+
}
103+
97104
#[test]
98105
fn tls_smoke_test() {
99106
use cast::transmute;

src/libstd/unstable/dynamic_lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ mod dl {
252252
FreeLibrary(handle); ()
253253
}
254254

255+
#[cfg(target_arch = "x86")]
255256
#[link_name = "kernel32"]
256257
extern "stdcall" {
257258
fn SetLastError(error: u32);
@@ -261,4 +262,15 @@ mod dl {
261262
fn GetProcAddress(handle: *libc::c_void, name: *libc::c_char) -> *libc::c_void;
262263
fn FreeLibrary(handle: *libc::c_void);
263264
}
265+
266+
#[cfg(target_arch = "x86_64")]
267+
#[link_name = "kernel32"]
268+
extern {
269+
fn SetLastError(error: u32);
270+
fn LoadLibraryW(name: *u16) -> *libc::c_void;
271+
fn GetModuleHandleExW(dwFlags: libc::DWORD, name: *u16,
272+
handle: **libc::c_void) -> *libc::c_void;
273+
fn GetProcAddress(handle: *libc::c_void, name: *libc::c_char) -> *libc::c_void;
274+
fn FreeLibrary(handle: *libc::c_void);
275+
}
264276
}

0 commit comments

Comments
 (0)