38 lines · cpp
1//===---------- Linux implementation of the Linux pkey_alloc 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-exception6//7//===----------------------------------------------------------------------===//8 9#include "src/sys/mman/pkey_alloc.h"10 11#include "hdr/errno_macros.h" // For ENOSYS12#include "src/__support/OSUtil/syscall.h" // For internal syscall function.13#include "src/__support/common.h"14#include "src/__support/libc_errno.h"15#include "src/__support/macros/config.h"16 17#include <sys/syscall.h> // For syscall numbers.18 19namespace LIBC_NAMESPACE_DECL {20 21LLVM_LIBC_FUNCTION(int, pkey_alloc,22 (unsigned int flags, unsigned int access_rights)) {23#if !defined(SYS_pkey_alloc)24 libc_errno = ENOSYS;25 return -1;26#else27 int ret =28 LIBC_NAMESPACE::syscall_impl<int>(SYS_pkey_alloc, flags, access_rights);29 if (ret < 0) {30 libc_errno = -ret;31 return -1;32 }33 return static_cast<int>(ret);34#endif35}36 37} // namespace LIBC_NAMESPACE_DECL38