diff options
Diffstat (limited to 'libc/src/sys/mman/linux/mprotect.cpp')
| -rw-r--r-- | libc/src/sys/mman/linux/mprotect.cpp | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/libc/src/sys/mman/linux/mprotect.cpp b/libc/src/sys/mman/linux/mprotect.cpp index 6b14915b60c9..c891f03a4713 100644 --- a/libc/src/sys/mman/linux/mprotect.cpp +++ b/libc/src/sys/mman/linux/mprotect.cpp @@ -11,26 +11,22 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" +#include "src/__support/error_or.h" #include "src/__support/libc_errno.h" #include "src/__support/macros/config.h" +#include "src/sys/mman/linux/mprotect_common.h" #include <sys/syscall.h> // For syscall numbers. namespace LIBC_NAMESPACE_DECL { -// This function is currently linux only. It has to be refactored suitably if -// mprotect is to be supported on non-linux operating systems also. LLVM_LIBC_FUNCTION(int, mprotect, (void *addr, size_t size, int prot)) { - int ret = LIBC_NAMESPACE::syscall_impl<int>( - SYS_mprotect, reinterpret_cast<long>(addr), size, prot); - - // A negative return value indicates an error with the magnitude of the - // value being the error code. - if (ret < 0) { - libc_errno = -ret; + ErrorOr<int> result = + LIBC_NAMESPACE::mprotect_common::mprotect_impl(addr, size, prot); + if (!result.has_value()) { + libc_errno = result.error(); return -1; } - - return 0; + return result.value(); } } // namespace LIBC_NAMESPACE_DECL |
