Skip to content

Commit dae9eef

Browse files
dpdanisrinivasreddy
authored andcommitted
pythongh-117657: TSAN Fix races in PyMember_Get and PyMember_Set for C extensions (pythonGH-123211)
1 parent 956fc5a commit dae9eef

File tree

10 files changed

+735
-50
lines changed

10 files changed

+735
-50
lines changed

Include/cpython/pyatomic.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,27 @@ _Py_atomic_load_ptr(const void *obj);
321321
static inline int
322322
_Py_atomic_load_int_relaxed(const int *obj);
323323

324+
static inline char
325+
_Py_atomic_load_char_relaxed(const char *obj);
326+
327+
static inline unsigned char
328+
_Py_atomic_load_uchar_relaxed(const unsigned char *obj);
329+
330+
static inline short
331+
_Py_atomic_load_short_relaxed(const short *obj);
332+
333+
static inline unsigned short
334+
_Py_atomic_load_ushort_relaxed(const unsigned short *obj);
335+
336+
static inline long
337+
_Py_atomic_load_long_relaxed(const long *obj);
338+
339+
static inline double
340+
_Py_atomic_load_double_relaxed(const double *obj);
341+
342+
static inline long long
343+
_Py_atomic_load_llong_relaxed(const long long *obj);
344+
324345
static inline int8_t
325346
_Py_atomic_load_int8_relaxed(const int8_t *obj);
326347

@@ -458,6 +479,30 @@ static inline void
458479
_Py_atomic_store_ullong_relaxed(unsigned long long *obj,
459480
unsigned long long value);
460481

482+
static inline void
483+
_Py_atomic_store_char_relaxed(char *obj, char value);
484+
485+
static inline void
486+
_Py_atomic_store_uchar_relaxed(unsigned char *obj, unsigned char value);
487+
488+
static inline void
489+
_Py_atomic_store_short_relaxed(short *obj, short value);
490+
491+
static inline void
492+
_Py_atomic_store_ushort_relaxed(unsigned short *obj, unsigned short value);
493+
494+
static inline void
495+
_Py_atomic_store_long_relaxed(long *obj, long value);
496+
497+
static inline void
498+
_Py_atomic_store_float_relaxed(float *obj, float value);
499+
500+
static inline void
501+
_Py_atomic_store_double_relaxed(double *obj, double value);
502+
503+
static inline void
504+
_Py_atomic_store_llong_relaxed(long long *obj, long long value);
505+
461506

462507
// --- _Py_atomic_load_ptr_acquire / _Py_atomic_store_ptr_release ------------
463508

Include/cpython/pyatomic_gcc.h

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,34 @@ static inline int
306306
_Py_atomic_load_int_relaxed(const int *obj)
307307
{ return __atomic_load_n(obj, __ATOMIC_RELAXED); }
308308

309+
static inline char
310+
_Py_atomic_load_char_relaxed(const char *obj)
311+
{ return __atomic_load_n(obj, __ATOMIC_RELAXED); }
312+
313+
static inline unsigned char
314+
_Py_atomic_load_uchar_relaxed(const unsigned char *obj)
315+
{ return __atomic_load_n(obj, __ATOMIC_RELAXED); }
316+
317+
static inline short
318+
_Py_atomic_load_short_relaxed(const short *obj)
319+
{ return __atomic_load_n(obj, __ATOMIC_RELAXED); }
320+
321+
static inline unsigned short
322+
_Py_atomic_load_ushort_relaxed(const unsigned short *obj)
323+
{ return __atomic_load_n(obj, __ATOMIC_RELAXED); }
324+
325+
static inline long
326+
_Py_atomic_load_long_relaxed(const long *obj)
327+
{ return __atomic_load_n(obj, __ATOMIC_RELAXED); }
328+
329+
static inline float
330+
_Py_atomic_load_float_relaxed(const float *obj)
331+
{ float ret; __atomic_load(obj, &ret, __ATOMIC_RELAXED); return ret; }
332+
333+
static inline double
334+
_Py_atomic_load_double_relaxed(const double *obj)
335+
{ double ret; __atomic_load(obj, &ret, __ATOMIC_RELAXED); return ret; }
336+
309337
static inline int8_t
310338
_Py_atomic_load_int8_relaxed(const int8_t *obj)
311339
{ return __atomic_load_n(obj, __ATOMIC_RELAXED); }
@@ -362,6 +390,10 @@ static inline unsigned long long
362390
_Py_atomic_load_ullong_relaxed(const unsigned long long *obj)
363391
{ return __atomic_load_n(obj, __ATOMIC_RELAXED); }
364392

393+
static inline long long
394+
_Py_atomic_load_llong_relaxed(const long long *obj)
395+
{ return __atomic_load_n(obj, __ATOMIC_RELAXED); }
396+
365397

366398
// --- _Py_atomic_store ------------------------------------------------------
367399

@@ -485,6 +517,38 @@ _Py_atomic_store_ullong_relaxed(unsigned long long *obj,
485517
unsigned long long value)
486518
{ __atomic_store_n(obj, value, __ATOMIC_RELAXED); }
487519

520+
static inline void
521+
_Py_atomic_store_char_relaxed(char *obj, char value)
522+
{ __atomic_store_n(obj, value, __ATOMIC_RELEASE); }
523+
524+
static inline void
525+
_Py_atomic_store_uchar_relaxed(unsigned char *obj, unsigned char value)
526+
{ __atomic_store_n(obj, value, __ATOMIC_RELAXED); }
527+
528+
static inline void
529+
_Py_atomic_store_short_relaxed(short *obj, short value)
530+
{ __atomic_store_n(obj, value, __ATOMIC_RELAXED); }
531+
532+
static inline void
533+
_Py_atomic_store_ushort_relaxed(unsigned short *obj, unsigned short value)
534+
{ __atomic_store_n(obj, value, __ATOMIC_RELAXED); }
535+
536+
static inline void
537+
_Py_atomic_store_long_relaxed(long *obj, long value)
538+
{ __atomic_store_n(obj, value, __ATOMIC_RELAXED); }
539+
540+
static inline void
541+
_Py_atomic_store_float_relaxed(float *obj, float value)
542+
{ __atomic_store(obj, &value, __ATOMIC_RELAXED); }
543+
544+
static inline void
545+
_Py_atomic_store_double_relaxed(double *obj, double value)
546+
{ __atomic_store(obj, &value, __ATOMIC_RELAXED); }
547+
548+
static inline void
549+
_Py_atomic_store_llong_relaxed(long long *obj, long long value)
550+
{ __atomic_store_n(obj, value, __ATOMIC_RELAXED); }
551+
488552

489553
// --- _Py_atomic_load_ptr_acquire / _Py_atomic_store_ptr_release ------------
490554

Include/cpython/pyatomic_msc.h

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,48 @@ _Py_atomic_load_int_relaxed(const int *obj)
634634
return *(volatile int *)obj;
635635
}
636636

637+
static inline char
638+
_Py_atomic_load_char_relaxed(const char *obj)
639+
{
640+
return *(volatile char *)obj;
641+
}
642+
643+
static inline unsigned char
644+
_Py_atomic_load_uchar_relaxed(const unsigned char *obj)
645+
{
646+
return *(volatile unsigned char *)obj;
647+
}
648+
649+
static inline short
650+
_Py_atomic_load_short_relaxed(const short *obj)
651+
{
652+
return *(volatile short *)obj;
653+
}
654+
655+
static inline unsigned short
656+
_Py_atomic_load_ushort_relaxed(const unsigned short *obj)
657+
{
658+
return *(volatile unsigned short *)obj;
659+
}
660+
661+
static inline long
662+
_Py_atomic_load_long_relaxed(const long *obj)
663+
{
664+
return *(volatile long *)obj;
665+
}
666+
667+
static inline float
668+
_Py_atomic_load_float_relaxed(const float *obj)
669+
{
670+
return *(volatile float *)obj;
671+
}
672+
673+
static inline double
674+
_Py_atomic_load_double_relaxed(const double *obj)
675+
{
676+
return *(volatile double *)obj;
677+
}
678+
637679
static inline int8_t
638680
_Py_atomic_load_int8_relaxed(const int8_t *obj)
639681
{
@@ -718,6 +760,12 @@ _Py_atomic_load_ullong_relaxed(const unsigned long long *obj)
718760
return *(volatile unsigned long long *)obj;
719761
}
720762

763+
static inline long long
764+
_Py_atomic_load_llong_relaxed(const long long *obj)
765+
{
766+
return *(volatile long long *)obj;
767+
}
768+
721769

722770
// --- _Py_atomic_store ------------------------------------------------------
723771

@@ -899,6 +947,60 @@ _Py_atomic_store_ullong_relaxed(unsigned long long *obj,
899947
*(volatile unsigned long long *)obj = value;
900948
}
901949

950+
static inline void
951+
_Py_atomic_store_char_relaxed(char *obj, char value)
952+
{
953+
*(volatile char *)obj = value;
954+
}
955+
956+
static inline void
957+
_Py_atomic_store_uchar_relaxed(unsigned char *obj, unsigned char value)
958+
{
959+
*(volatile unsigned char *)obj = value;
960+
}
961+
962+
static inline void
963+
_Py_atomic_store_short_relaxed(short *obj, short value)
964+
{
965+
*(volatile short *)obj = value;
966+
}
967+
968+
static inline void
969+
_Py_atomic_store_ushort_relaxed(unsigned short *obj, unsigned short value)
970+
{
971+
*(volatile unsigned short *)obj = value;
972+
}
973+
974+
static inline void
975+
_Py_atomic_store_uint_release(unsigned int *obj, unsigned int value)
976+
{
977+
*(volatile unsigned int *)obj = value;
978+
}
979+
980+
static inline void
981+
_Py_atomic_store_long_relaxed(long *obj, long value)
982+
{
983+
*(volatile long *)obj = value;
984+
}
985+
986+
static inline void
987+
_Py_atomic_store_float_relaxed(float *obj, float value)
988+
{
989+
*(volatile float *)obj = value;
990+
}
991+
992+
static inline void
993+
_Py_atomic_store_double_relaxed(double *obj, double value)
994+
{
995+
*(volatile double *)obj = value;
996+
}
997+
998+
static inline void
999+
_Py_atomic_store_llong_relaxed(long long *obj, long long value)
1000+
{
1001+
*(volatile long long *)obj = value;
1002+
}
1003+
9021004

9031005
// --- _Py_atomic_load_ptr_acquire / _Py_atomic_store_ptr_release ------------
9041006

0 commit comments

Comments
 (0)