39 lines · c
1//===---------- Shared Linux implementation of POSIX mprotect. ------------===//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/__support/OSUtil/syscall.h" // For internal syscall function.10#include "src/__support/common.h"11#include "src/__support/error_or.h"12#include "src/__support/libc_errno.h"13#include "src/__support/macros/attributes.h"14#include "src/__support/macros/config.h"15#include <sys/syscall.h> // For syscall numbers.16 17namespace LIBC_NAMESPACE_DECL {18 19namespace mprotect_common {20 21// This function is currently linux only. It has to be refactored suitably if22// mprotect is to be supported on non-linux operating systems also.23LIBC_INLINE ErrorOr<int> mprotect_impl(void *addr, size_t size, int prot) {24 int ret = LIBC_NAMESPACE::syscall_impl<int>(25 SYS_mprotect, reinterpret_cast<long>(addr), size, prot);26 27 // A negative return value indicates an error with the magnitude of the28 // value being the error code.29 if (ret < 0) {30 return Error(-ret);31 }32 33 return 0;34}35 36} // namespace mprotect_common37 38} // namespace LIBC_NAMESPACE_DECL39