MCPcopy Index your code
hub / github.com/RustPython/RustPython / getppid

Function getppid

crates/vm/src/stdlib/nt.rs:2063–2114  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2061
2062 #[pyfunction]
2063 fn getppid() -> u32 {
2064 use windows_sys::Win32::System::Threading::{GetCurrentProcess, PROCESS_BASIC_INFORMATION};
2065
2066 type NtQueryInformationProcessFn = unsafe extern "system" fn(
2067 process_handle: isize,
2068 process_information_class: u32,
2069 process_information: *mut core::ffi::c_void,
2070 process_information_length: u32,
2071 return_length: *mut u32,
2072 ) -> i32;
2073
2074 let ntdll = unsafe {
2075 windows_sys::Win32::System::LibraryLoader::GetModuleHandleW(windows_sys::w!(
2076 "ntdll.dll"
2077 ))
2078 };
2079 if ntdll.is_null() {
2080 return 0;
2081 }
2082
2083 let func = unsafe {
2084 windows_sys::Win32::System::LibraryLoader::GetProcAddress(
2085 ntdll,
2086 c"NtQueryInformationProcess".as_ptr() as *const u8,
2087 )
2088 };
2089 let Some(func) = func else {
2090 return 0;
2091 };
2092 let nt_query: NtQueryInformationProcessFn = unsafe { core::mem::transmute(func) };
2093
2094 let mut info: PROCESS_BASIC_INFORMATION = unsafe { core::mem::zeroed() };
2095
2096 let status = unsafe {
2097 nt_query(
2098 GetCurrentProcess() as isize,
2099 0, // ProcessBasicInformation
2100 &mut info as *mut _ as *mut core::ffi::c_void,
2101 core::mem::size_of::<PROCESS_BASIC_INFORMATION>() as u32,
2102 core::ptr::null_mut(),
2103 )
2104 };
2105
2106 if status >= 0
2107 && info.InheritedFromUniqueProcessId != 0
2108 && info.InheritedFromUniqueProcessId < u32::MAX as usize
2109 {
2110 info.InheritedFromUniqueProcessId as u32
2111 } else {
2112 0
2113 }
2114 }
2115
2116 #[pyfunction]
2117 fn dup(fd: i32, vm: &VirtualMachine) -> PyResult<i32> {

Callers

nothing calls this directly

Calls 2

GetCurrentProcessFunction · 0.85
as_ptrMethod · 0.45

Tested by

no test coverage detected