[libc-commits] [libc] add mremap (PR #112804)
Michael Jones via libc-commits
libc-commits at lists.llvm.org
Thu Oct 31 14:06:37 PDT 2024
================
@@ -0,0 +1,48 @@
+//===---------- Linux implementation of the POSIX mremap function
+//-----------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/sys/mman/mremap.h"
+
+#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
+#include "src/__support/common.h"
+
+#include "src/__support/macros/config.h"
+#include "src/errno/libc_errno.h"
+#include <linux/param.h> // For EXEC_PAGESIZE.
+#include <stdarg.h>
+#include <sys/syscall.h> // For syscall numbers.
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(void *, mremap,
+ (void *old_address, size_t old_size, size_t new_size,
+ int flags, ... /* void *new_address */)) {
+
+ long ret = 0;
+ void *new_address = nullptr;
+ if (flags & MREMAP_FIXED) {
+ va_list varargs;
+ va_start(varargs, flags);
+ new_address = va_arg(varargs, void *);
+ va_end(varargs);
+ ret = LIBC_NAMESPACE::syscall_impl<long>(SYS_mremap, old_address, old_size,
----------------
michaelrj-google wrote:
you can move this call outside of the `if`. The extra argument will be ignored by the syscall if it's not used.
https://github.com/llvm/llvm-project/pull/112804
More information about the libc-commits
mailing list