diff options
Diffstat (limited to 'src/linux.rs')
-rw-r--r-- | src/linux.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/linux.rs b/src/linux.rs new file mode 100644 index 0000000..4826730 --- /dev/null +++ b/src/linux.rs @@ -0,0 +1,18 @@ +// Copyright 2020 The Chromium OS Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/// Provides safe implementations of common low level functions that assume a Linux environment. +use libc::{syscall, SYS_gettid}; + +pub type Pid = libc::pid_t; + +pub fn getpid() -> Pid { + // Calling getpid() is always safe. + unsafe { libc::getpid() } +} + +pub fn gettid() -> Pid { + // Calling the gettid() sycall is always safe. + unsafe { syscall(SYS_gettid) as Pid } +} |