From 78562cb315da1cc5b35c07aba5a3fd7faacdad48 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Tue, 19 Nov 2024 13:15:15 +0100 Subject: [PATCH] More thorough use of PGShmemHeader * instead of void * --- src/backend/port/sysv_shmem.c | 4 ++-- src/backend/port/win32_shmem.c | 4 ++-- src/backend/postmaster/launch_backend.c | 2 +- src/backend/storage/ipc/shmem.c | 13 ++++--------- src/include/storage/pg_shmem.h | 2 +- src/include/storage/shmem.h | 3 ++- 6 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/backend/port/sysv_shmem.c b/src/backend/port/sysv_shmem.c index 362a37d3b3a..fa6ee15ce56 100644 --- a/src/backend/port/sysv_shmem.c +++ b/src/backend/port/sysv_shmem.c @@ -92,7 +92,7 @@ typedef enum unsigned long UsedShmemSegID = 0; -void *UsedShmemSegAddr = NULL; +PGShmemHeader *UsedShmemSegAddr = NULL; static Size AnonymousShmemSize; static void *AnonymousShmem = NULL; @@ -892,7 +892,7 @@ PGSharedMemoryReAttach(void) IpcMemoryId shmid; PGShmemHeader *hdr; IpcMemoryState state; - void *origUsedShmemSegAddr = UsedShmemSegAddr; + PGShmemHeader *origUsedShmemSegAddr = UsedShmemSegAddr; Assert(UsedShmemSegAddr != NULL); Assert(IsUnderPostmaster); diff --git a/src/backend/port/win32_shmem.c b/src/backend/port/win32_shmem.c index 3bcce9d3b63..827f9cd79b4 100644 --- a/src/backend/port/win32_shmem.c +++ b/src/backend/port/win32_shmem.c @@ -42,7 +42,7 @@ void *ShmemProtectiveRegion = NULL; HANDLE UsedShmemSegID = INVALID_HANDLE_VALUE; -void *UsedShmemSegAddr = NULL; +PGShmemHeader *UsedShmemSegAddr = NULL; static Size UsedShmemSegSize = 0; static bool EnableLockPagesPrivilege(int elevel); @@ -424,7 +424,7 @@ void PGSharedMemoryReAttach(void) { PGShmemHeader *hdr; - void *origUsedShmemSegAddr = UsedShmemSegAddr; + PGShmemHeader *origUsedShmemSegAddr = UsedShmemSegAddr; Assert(ShmemProtectiveRegion != NULL); Assert(UsedShmemSegAddr != NULL); diff --git a/src/backend/postmaster/launch_backend.c b/src/backend/postmaster/launch_backend.c index 1f2d829ec5a..8f48c938968 100644 --- a/src/backend/postmaster/launch_backend.c +++ b/src/backend/postmaster/launch_backend.c @@ -94,7 +94,7 @@ typedef struct void *ShmemProtectiveRegion; HANDLE UsedShmemSegID; #endif - void *UsedShmemSegAddr; + PGShmemHeader *UsedShmemSegAddr; slock_t *ShmemLock; #ifdef USE_INJECTION_POINTS struct InjectionPointsCtl *ActiveInjectionPoints; diff --git a/src/backend/storage/ipc/shmem.c b/src/backend/storage/ipc/shmem.c index 6d5f0839864..50f987ae240 100644 --- a/src/backend/storage/ipc/shmem.c +++ b/src/backend/storage/ipc/shmem.c @@ -92,18 +92,13 @@ static HTAB *ShmemIndex = NULL; /* primary index hashtable for shmem */ /* * InitShmemAccess() --- set up basic pointers to shared memory. - * - * Note: the argument should be declared "PGShmemHeader *seghdr", - * but we use void to avoid having to include ipc.h in shmem.h. */ void -InitShmemAccess(void *seghdr) +InitShmemAccess(PGShmemHeader *seghdr) { - PGShmemHeader *shmhdr = (PGShmemHeader *) seghdr; - - ShmemSegHdr = shmhdr; - ShmemBase = (void *) shmhdr; - ShmemEnd = (char *) ShmemBase + shmhdr->totalsize; + ShmemSegHdr = seghdr; + ShmemBase = seghdr; + ShmemEnd = (char *) ShmemBase + seghdr->totalsize; } /* diff --git a/src/include/storage/pg_shmem.h b/src/include/storage/pg_shmem.h index 3065ff5be71..7a07c5807ac 100644 --- a/src/include/storage/pg_shmem.h +++ b/src/include/storage/pg_shmem.h @@ -69,7 +69,7 @@ extern PGDLLIMPORT unsigned long UsedShmemSegID; extern PGDLLIMPORT HANDLE UsedShmemSegID; extern PGDLLIMPORT void *ShmemProtectiveRegion; #endif -extern PGDLLIMPORT void *UsedShmemSegAddr; +extern PGDLLIMPORT PGShmemHeader *UsedShmemSegAddr; #if !defined(WIN32) && !defined(EXEC_BACKEND) #define DEFAULT_SHARED_MEMORY_TYPE SHMEM_TYPE_MMAP diff --git a/src/include/storage/shmem.h b/src/include/storage/shmem.h index 842989111c3..8cdbe7a89c8 100644 --- a/src/include/storage/shmem.h +++ b/src/include/storage/shmem.h @@ -27,7 +27,8 @@ /* shmem.c */ extern PGDLLIMPORT slock_t *ShmemLock; -extern void InitShmemAccess(void *seghdr); +struct PGShmemHeader; /* avoid including storage/pg_shmem.h here */ +extern void InitShmemAccess(struct PGShmemHeader *seghdr); extern void InitShmemAllocation(void); extern void *ShmemAlloc(Size size); extern void *ShmemAllocNoError(Size size); -- 2.47.0