[llvm] [Support][Memory] Add memfd based fallback for strict W^X Linux systems (PR #98538)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 24 04:24:02 PDT 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff e4163c0927772f2ec73cf16d53e000614c419c45 8942359145b9afe011c2e63d9fa219e1b0eb4c56 --extensions cpp,inc,h -- llvm/lib/Support/Unix/MemoryLinux.h llvm/lib/Support/Unix/Memory.inc llvm/unittests/Support/MemoryTest.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/llvm/lib/Support/Unix/Memory.inc b/llvm/lib/Support/Unix/Memory.inc
index b3d8f78797..2f622e27f6 100644
--- a/llvm/lib/Support/Unix/Memory.inc
+++ b/llvm/lib/Support/Unix/Memory.inc
@@ -196,10 +196,19 @@ std::error_code Memory::protectMappedMemory(const MemoryBlock &M,
     public:
       FDWrapper(int fd) : fd(fd) {}
       ~FDWrapper() { close(); }
-      FDWrapper& operator=(int nfd) { close(); fd = nfd; return *this; }
+      FDWrapper &operator=(int nfd) {
+        close();
+        fd = nfd;
+        return *this;
+      }
       operator int() const { return fd; }
+
     private:
-      void close() { if (fd >= 0) ::close(fd); fd = -1; }
+      void close() {
+        if (fd >= 0)
+          ::close(fd);
+        fd = -1;
+      }
       int fd;
     } fd(memfd_create("llvm", flags));
 
diff --git a/llvm/unittests/Support/MemoryTest.cpp b/llvm/unittests/Support/MemoryTest.cpp
index 9bbdb8491a..028a5fda97 100644
--- a/llvm/unittests/Support/MemoryTest.cpp
+++ b/llvm/unittests/Support/MemoryTest.cpp
@@ -316,10 +316,10 @@ TEST_P(MappedMemoryTest, MakeExec) {
   MemoryBlock M = Memory::allocateMappedMemory(sizeof(int), nullptr, Flags, EC);
   EXPECT_EQ(std::error_code(), EC);
 
-  EXPECT_NE((void*)nullptr, M.base());
+  EXPECT_NE((void *)nullptr, M.base());
   EXPECT_LE(sizeof(int), M.allocatedSize());
 
-  int *x = (int*)M.base();
+  int *x = (int *)M.base();
   *x = 0xcc;
 
   EXPECT_EQ(0xcc, *x);

``````````

</details>


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


More information about the llvm-commits mailing list