[libc-commits] [libc] add mremap (PR #112804)

Michael Jones via libc-commits libc-commits at lists.llvm.org
Fri Oct 18 15:46:27 PDT 2024


================
@@ -0,0 +1,53 @@
+//===---------- 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 */)) {
+
+#ifdef SYS_mremap
+  long syscall_number = SYS_mremap;
+#else
+#error "mremap syscalls not available."
+#endif
+  long ret = 0;
+  if (flags & MREMAP_FIXED) {
+    void *arg;
----------------
michaelrj-google wrote:

`arg` should have a more descriptive name, it looks like `new_address` is the actual name for the argument so I'd suggest that.

https://github.com/llvm/llvm-project/pull/112804


More information about the libc-commits mailing list