1 // Copyright 2020 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /// Provides safe implementations of common low level functions that assume a Linux environment.
6 use libc::{syscall, SYS_gettid};
7
8 pub type Pid = libc::pid_t;
9
getpid() -> Pid10 pub fn getpid() -> Pid {
11 // Calling getpid() is always safe.
12 unsafe { libc::getpid() }
13 }
14
gettid() -> Pid15 pub fn gettid() -> Pid {
16 // Calling the gettid() sycall is always safe.
17 unsafe { syscall(SYS_gettid) as Pid }
18 }
19