[PATCH] mlock, mlock2, munlock: Tell the compiler we don't derefernce the pointer
Xi Ruoyao
xry111@xry111.site
Thu Dec 26 04:51:18 GMT 2024
Since https://gcc.gnu.org/r11-959, the compiler emits
-Wmaybe-uninitialized if a const pointer to an uninitialized buffer is
passed. Tell the compiler we don't dereference the pointer to remove
the false alarm.
Link: https://gcc.gnu.org/PR118194
Signed-off-by: Xi Ruoyao <xry111@xry111.site>
---
Tested on x86_64-linux.
misc/sys/mman.h | 6 ++++--
sysdeps/unix/sysv/linux/bits/mman-shared.h | 3 ++-
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/misc/sys/mman.h b/misc/sys/mman.h
index c68a85d140..ae8cee3311 100644
--- a/misc/sys/mman.h
+++ b/misc/sys/mman.h
@@ -100,10 +100,12 @@ extern int posix_madvise (void *__addr, size_t __len, int __advice) __THROW;
/* Guarantee all whole pages mapped by the range [ADDR,ADDR+LEN) to
be memory resident. */
-extern int mlock (const void *__addr, size_t __len) __THROW;
+extern int mlock (const void *__addr, size_t __len) __THROW
+ __attr_access ((__none__, 1));
/* Unlock whole pages previously mapped by the range [ADDR,ADDR+LEN). */
-extern int munlock (const void *__addr, size_t __len) __THROW;
+extern int munlock (const void *__addr, size_t __len) __THROW
+ __attr_access ((__none__, 1));
/* Cause all currently mapped pages of the process to be memory resident
until unlocked by a call to the `munlockall', until the process exits,
diff --git a/sysdeps/unix/sysv/linux/bits/mman-shared.h b/sysdeps/unix/sysv/linux/bits/mman-shared.h
index 7a9874204d..d601bd0e8f 100644
--- a/sysdeps/unix/sysv/linux/bits/mman-shared.h
+++ b/sysdeps/unix/sysv/linux/bits/mman-shared.h
@@ -56,7 +56,8 @@ int memfd_create (const char *__name, unsigned int __flags) __THROW;
/* Lock pages from ADDR (inclusive) to ADDR + LENGTH (exclusive) into
memory. FLAGS is a combination of the MLOCK_* flags above. */
-int mlock2 (const void *__addr, size_t __length, unsigned int __flags) __THROW;
+int mlock2 (const void *__addr, size_t __length, unsigned int __flags) __THROW
+ __attr_access ((__none__, 1));
/* Allocate a new protection key, with the PKEY_DISABLE_* bits
specified in ACCESS_RESTRICTIONS. The protection key mask for the
--
2.47.1
More information about the Libc-alpha
mailing list