Skip to content

Convert most of rust_run_program.cpp to rust (issue #2674). #6140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 3, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 127 additions & 4 deletions src/libcore/libc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,12 +582,16 @@ pub mod types {

pub type LPWSTR = *mut WCHAR;
pub type LPSTR = *mut CHAR;
pub type LPTSTR = *mut CHAR;

// Not really, but opaque to us.
pub type LPSECURITY_ATTRIBUTES = LPVOID;

pub type LPVOID = *mut c_void;
pub type LPBYTE = *mut BYTE;
pub type LPWORD = *mut WORD;
pub type LPDWORD = *mut DWORD;
pub type LPHANDLE = *mut HANDLE;

pub type LRESULT = LONG_PTR;
pub type PBOOL = *mut BOOL;
Expand All @@ -596,6 +600,36 @@ pub mod types {

pub type time64_t = i64;
pub type int64 = i64;

pub struct STARTUPINFO {
cb: DWORD,
lpReserved: LPTSTR,
lpDesktop: LPTSTR,
lpTitle: LPTSTR,
dwX: DWORD,
dwY: DWORD,
dwXSize: DWORD,
dwYSize: DWORD,
dwXCountChars: DWORD,
dwYCountCharts: DWORD,
dwFillAttribute: DWORD,
dwFlags: DWORD,
wShowWindow: WORD,
cbReserved2: WORD,
lpReserved2: LPBYTE,
hStdInput: HANDLE,
hStdOutput: HANDLE,
hStdError: HANDLE
}
pub type LPSTARTUPINFO = *mut STARTUPINFO;

pub struct PROCESS_INFORMATION {
hProcess: HANDLE,
hThread: HANDLE,
dwProcessId: DWORD,
dwThreadId: DWORD
}
pub type LPPROCESS_INFORMATION = *mut PROCESS_INFORMATION;
}
}
}
Expand Down Expand Up @@ -848,13 +882,62 @@ pub mod consts {
pub mod bsd44 {
}
pub mod extra {
use libc::types::os::arch::extra::{DWORD, BOOL};

pub static TRUE : BOOL = 1;
pub static FALSE : BOOL = 0;

pub static O_TEXT : int = 16384;
pub static O_BINARY : int = 32768;
pub static O_NOINHERIT: int = 128;

pub static ERROR_SUCCESS : int = 0;
pub static ERROR_INSUFFICIENT_BUFFER : int = 122;
pub static INVALID_HANDLE_VALUE: int = -1;

pub static DELETE : DWORD = 0x00010000;
pub static READ_CONTROL : DWORD = 0x00020000;
pub static SYNCHRONIZE : DWORD = 0x00100000;
pub static WRITE_DAC : DWORD = 0x00040000;
pub static WRITE_OWNER : DWORD = 0x00080000;

pub static PROCESS_CREATE_PROCESS : DWORD = 0x0080;
pub static PROCESS_CREATE_THREAD : DWORD = 0x0002;
pub static PROCESS_DUP_HANDLE : DWORD = 0x0040;
pub static PROCESS_QUERY_INFORMATION : DWORD = 0x0400;
pub static PROCESS_QUERY_LIMITED_INFORMATION : DWORD = 0x1000;
pub static PROCESS_SET_INFORMATION : DWORD = 0x0200;
pub static PROCESS_SET_QUOTA : DWORD = 0x0100;
pub static PROCESS_SUSPEND_RESUME : DWORD = 0x0800;
pub static PROCESS_TERMINATE : DWORD = 0x0001;
pub static PROCESS_VM_OPERATION : DWORD = 0x0008;
pub static PROCESS_VM_READ : DWORD = 0x0010;
pub static PROCESS_VM_WRITE : DWORD = 0x0020;

pub static STARTF_FORCEONFEEDBACK : DWORD = 0x00000040;
pub static STARTF_FORCEOFFFEEDBACK : DWORD = 0x00000080;
pub static STARTF_PREVENTPINNING : DWORD = 0x00002000;
pub static STARTF_RUNFULLSCREEN : DWORD = 0x00000020;
pub static STARTF_TITLEISAPPID : DWORD = 0x00001000;
pub static STARTF_TITLEISLINKNAME : DWORD = 0x00000800;
pub static STARTF_USECOUNTCHARS : DWORD = 0x00000008;
pub static STARTF_USEFILLATTRIBUTE : DWORD = 0x00000010;
pub static STARTF_USEHOTKEY : DWORD = 0x00000200;
pub static STARTF_USEPOSITION : DWORD = 0x00000004;
pub static STARTF_USESHOWWINDOW : DWORD = 0x00000001;
pub static STARTF_USESIZE : DWORD = 0x00000002;
pub static STARTF_USESTDHANDLES : DWORD = 0x00000100;

pub static WAIT_ABANDONED : DWORD = 0x00000080;
pub static WAIT_OBJECT_0 : DWORD = 0x00000000;
pub static WAIT_TIMEOUT : DWORD = 0x00000102;
pub static WAIT_FAILED : DWORD = -1;

pub static DUPLICATE_CLOSE_SOURCE : DWORD = 0x00000001;
pub static DUPLICATE_SAME_ACCESS : DWORD = 0x00000002;

pub static INFINITE : DWORD = -1;
pub static STILL_ACTIVE : DWORD = 259;
}
}

Expand Down Expand Up @@ -1751,12 +1834,24 @@ pub mod funcs {

unsafe fn sysctlnametomib(name: *c_char, mibp: *mut c_int,
sizep: *mut size_t) -> c_int;

unsafe fn getdtablesize() -> c_int;
}
}


#[cfg(target_os = "linux")]
#[cfg(target_os = "android")]
pub mod bsd44 {
use libc::types::os::arch::c95::{c_int};

#[abi = "cdecl"]
pub extern {
unsafe fn getdtablesize() -> c_int;
}
}


#[cfg(target_os = "win32")]
pub mod bsd44 {
}
Expand Down Expand Up @@ -1790,9 +1885,11 @@ pub mod funcs {
pub mod kernel32 {
use libc::types::os::arch::c95::{c_uint};
use libc::types::os::arch::extra::{BOOL, DWORD, HMODULE};
use libc::types::os::arch::extra::{LPCWSTR, LPWSTR, LPTCH};
use libc::types::os::arch::extra::{LPSECURITY_ATTRIBUTES};
use libc::types::os::arch::extra::{HANDLE};
use libc::types::os::arch::extra::{LPCWSTR, LPWSTR, LPCTSTR,
LPTSTR, LPTCH, LPDWORD, LPVOID};
use libc::types::os::arch::extra::{LPSECURITY_ATTRIBUTES, LPSTARTUPINFO,
LPPROCESS_INFORMATION};
use libc::types::os::arch::extra::{HANDLE, LPHANDLE};

#[abi = "stdcall"]
pub extern "stdcall" {
Expand Down Expand Up @@ -1829,19 +1926,45 @@ pub mod funcs {
findFileData: HANDLE)
-> BOOL;
unsafe fn FindClose(findFile: HANDLE) -> BOOL;
unsafe fn DuplicateHandle(hSourceProcessHandle: HANDLE,
hSourceHandle: HANDLE,
hTargetProcessHandle: HANDLE,
lpTargetHandle: LPHANDLE,
dwDesiredAccess: DWORD,
bInheritHandle: BOOL,
dwOptions: DWORD) -> BOOL;
unsafe fn CloseHandle(hObject: HANDLE) -> BOOL;
unsafe fn OpenProcess(dwDesiredAccess: DWORD,
bInheritHandle: BOOL,
dwProcessId: DWORD) -> HANDLE;
unsafe fn GetCurrentProcess() -> HANDLE;
unsafe fn CreateProcessA(lpApplicationName: LPCTSTR,
lpCommandLine: LPTSTR,
lpProcessAttributes: LPSECURITY_ATTRIBUTES,
lpThreadAttributes: LPSECURITY_ATTRIBUTES,
bInheritHandles: BOOL,
dwCreationFlags: DWORD,
lpEnvironment: LPVOID,
lpCurrentDirectory: LPCTSTR,
lpStartupInfo: LPSTARTUPINFO,
lpProcessInformation: LPPROCESS_INFORMATION) -> BOOL;
unsafe fn WaitForSingleObject(hHandle: HANDLE, dwMilliseconds: DWORD) -> DWORD;
unsafe fn TerminateProcess(hProcess: HANDLE, uExitCode: c_uint) -> BOOL;
unsafe fn GetExitCodeProcess(hProcess: HANDLE, lpExitCode: LPDWORD) -> BOOL;
}
}

pub mod msvcrt {
use libc::types::os::arch::c95::c_int;
use libc::types::os::arch::c95::{c_int, c_long};

#[abi = "cdecl"]
#[nolink]
pub extern {
#[link_name = "_commit"]
unsafe fn commit(fd: c_int) -> c_int;

#[link_name = "_get_osfhandle"]
unsafe fn get_osfhandle(fd: c_int) -> c_long;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ pub fn pipe() -> Pipe {
// inheritance has to be handled in a different way that I do not
// fully understand. Here we explicitly make the pipe non-inheritable,
// which means to pass it to a subprocess they need to be duplicated
// first, as in rust_run_program.
// first, as in core::run.
let mut fds = Pipe {in: 0 as c_int,
out: 0 as c_int };
let res = libc::pipe(&mut fds.in, 1024 as ::libc::c_uint,
Expand Down
Loading