1 | //===---------- Linux implementation of the prctl function ----------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #include "src/sys/prctl/prctl.h" |
10 | |
11 | #include "src/__support/OSUtil/syscall.h" // For internal syscall function. |
12 | |
13 | #include "src/errno/libc_errno.h" |
14 | #include <sys/syscall.h> // For syscall numbers. |
15 | |
16 | namespace LIBC_NAMESPACE { |
17 | |
18 | LLVM_LIBC_FUNCTION(int, prctl, |
19 | (int option, unsigned long arg2, unsigned long arg3, |
20 | unsigned long arg4, unsigned long arg5)) { |
21 | long ret = |
22 | LIBC_NAMESPACE::syscall_impl(SYS_prctl, arg1: option, arg2: arg2, arg3: arg3, arg4: arg4, arg5: arg5); |
23 | // The manpage states that "... return the nonnegative values described |
24 | // above. All other option values return 0 on success. On error, |
25 | // -1 is returned, and errno is set to indicate the error." |
26 | // According to the kernel implementation |
27 | // (https://github.com/torvalds/linux/blob/bee0e7762ad2c6025b9f5245c040fcc36ef2bde8/kernel/sys.c#L2442), |
28 | // return value from the syscall is set to 0 on default so we do not need to |
29 | // set the value on success manually. |
30 | if (ret < 0) { |
31 | libc_errno = static_cast<int>(-ret); |
32 | return -1; |
33 | } |
34 | return static_cast<int>(ret); |
35 | } |
36 | |
37 | } // namespace LIBC_NAMESPACE |
38 | |