From 1535129164892679dd7a94ee5007e7ba0e128b5d Mon Sep 17 00:00:00 2001 From: Palak Chaturvedi Date: Wed, 26 Aug 2026 16:15:47 +0000 Subject: [PATCH v20260817 11/11] shmem: distinguish the two mprotect failure messages PGSharedMemoryProtect() calls mprotect() twice, once to make the active region read-write and once to make the reserved tail inaccessible, and both failure paths emitted the identical "could not protect shared memory" message. The caller reports which structure failed, but not which of the two calls, even though they fail for quite different reasons. Give each call site its own message. Reported-by: Yuhang Qiu Discussion: https://postgr.es/m/B6CC6AF0-F7B3-4389-9740-DD1288EC15DB@gmail.com --- src/backend/port/sysv_shmem.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/backend/port/sysv_shmem.c b/src/backend/port/sysv_shmem.c index c052776e94c..179ceab57ff 100644 --- a/src/backend/port/sysv_shmem.c +++ b/src/backend/port/sysv_shmem.c @@ -1200,7 +1200,8 @@ PGSharedMemoryProtect(void *rw_start, void *rw_end, void *prot_end) if (mprotect(rw_start, (char *) rw_end - (char *) rw_start, PROT_READ | PROT_WRITE) != 0) { - ereport(WARNING, errmsg("could not protect shared memory: %m")); + ereport(WARNING, + errmsg("could not make shared memory read-write: %m")); return false; } } @@ -1210,7 +1211,8 @@ PGSharedMemoryProtect(void *rw_start, void *rw_end, void *prot_end) if (mprotect(rw_end, (char *) prot_end - (char *) rw_end, PROT_NONE) != 0) { - ereport(WARNING, errmsg("could not protect shared memory: %m")); + ereport(WARNING, + errmsg("could not make reserved shared memory inaccessible: %m")); return false; } } -- 2.43.0