aboutsummaryrefslogtreecommitdiff
path: root/src/linux.rs
blob: 4826730672d67095f3ac78e6fd2eb7911fde8fbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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 }
}