1
0
mirror of https://github.com/postgres/postgres.git synced 2026-10-23 13:29:09 +03:00

Fix casting away of volatile qualifier

Fix some issues involving volatile that would be triggered by
-Wcast-qual.

For PMSignalState, move the volatile qualifiers to the PMSignalData
fields that need it rather than making the whole structure have it.

For the MemSet() calls, do the initialization honestly with a loop
instead.

Note that the MemSet() calls would be normal "discards qualifier"
warnings if memset() (or another function with a prototype, not a
macro) were used.

Reviewed-by: Rui Zhao <zhaorui126@gmail.com>
Reviewed-by: Andres Freund <andres@anarazel.de> (older version)
Discussion: https://www.postgresql.org/message-id/c76b72dd-5736-453a-b698-6968d42e4768%40eisentraut.org
This commit is contained in:
Peter Eisentraut
2026-10-19 08:31:05 +02:00
parent 2db51901c4
commit 22ff4fc5a2
5 changed files with 12 additions and 9 deletions

View File

@@ -105,7 +105,7 @@ typedef struct
PROC_HDR *ProcGlobal;
PGPROC *AuxiliaryProcs;
PGPROC *PreparedXactProcs;
volatile PMSignalData *PMSignalState;
PMSignalData *PMSignalState;
ProcSignalHeader *ProcSignal;
pid_t PostmasterPid;
TimestampTz PgStartTime;

View File

@@ -73,16 +73,16 @@
struct PMSignalData
{
/* per-reason flags for signaling the postmaster */
sig_atomic_t PMSignalFlags[NUM_PMSIGNALS];
volatile sig_atomic_t PMSignalFlags[NUM_PMSIGNALS];
/* global flags for signals from postmaster to children */
QuitSignalReason sigquit_reason; /* why SIGQUIT was sent */
volatile QuitSignalReason sigquit_reason; /* why SIGQUIT was sent */
/* per-child-process flags */
int num_child_flags; /* # of entries in PMChildFlags[] */
sig_atomic_t PMChildFlags[FLEXIBLE_ARRAY_MEMBER];
volatile sig_atomic_t PMChildFlags[FLEXIBLE_ARRAY_MEMBER];
};
/* PMSignalState pointer is valid in both postmaster and child processes */
NON_EXEC_STATIC volatile PMSignalData *PMSignalState = NULL;
NON_EXEC_STATIC PMSignalData *PMSignalState = NULL;
static void PMSignalShmemRequest(void *);
static void PMSignalShmemInit(void *);

View File

@@ -155,7 +155,8 @@ ProcSignalShmemInit(void *arg)
SpinLockInit(&slot->pss_mutex);
pg_atomic_init_u32(&slot->pss_pid, 0);
slot->pss_cancel_key_len = 0;
MemSet(slot->pss_signalFlags, 0, sizeof(slot->pss_signalFlags));
for (int j = 0; j < NUM_PROCSIGNALS; j++)
slot->pss_signalFlags[j] = false;
pg_atomic_init_u64(&slot->pss_barrierGeneration, PG_UINT64_MAX);
pg_atomic_init_u32(&slot->pss_barrierCheckMask, 0);
ConditionVariableInit(&slot->pss_barrierCV);
@@ -186,7 +187,8 @@ ProcSignalInit(const uint8 *cancel_key, int cancel_key_len)
old_pss_pid = pg_atomic_read_u32(&slot->pss_pid);
/* Clear out any leftover signal reasons */
MemSet(slot->pss_signalFlags, 0, NUM_PROCSIGNALS * sizeof(sig_atomic_t));
for (int i = 0; i < NUM_PROCSIGNALS; i++)
slot->pss_signalFlags[i] = false;
/*
* Publish the PID before reading the global barrier generation to ensure

View File

@@ -35,7 +35,8 @@ pgstat_progress_start_command(ProgressCommandType cmdtype, Oid relid)
PGSTAT_BEGIN_WRITE_ACTIVITY(beentry);
beentry->st_progress_command = cmdtype;
beentry->st_progress_command_target = relid;
MemSet(&beentry->st_progress_param, 0, sizeof(beentry->st_progress_param));
for (int i = 0; i < PGSTAT_NUM_PROGRESS_PARAM; i++)
beentry->st_progress_param[i] = 0;
PGSTAT_END_WRITE_ACTIVITY(beentry);
}

View File

@@ -61,7 +61,7 @@ typedef enum
typedef struct PMSignalData PMSignalData;
#ifdef EXEC_BACKEND
extern PGDLLIMPORT volatile PMSignalData *PMSignalState;
extern PGDLLIMPORT PMSignalData *PMSignalState;
#endif
/*