@@ -414,7 +414,11 @@ get_py_runtime(pid_t pid)
414
414
static uintptr_t
415
415
get_async_debug (pid_t pid )
416
416
{
417
- return search_map_for_section (pid , "AsyncioDebug" , "_asyncio.cpython" );
417
+ uintptr_t result = search_map_for_section (pid , "AsyncioDebug" , "_asyncio.cpython" );
418
+ if (result == 0 && !PyErr_Occurred ()) {
419
+ PyErr_SetString (PyExc_RuntimeError , "Cannot find AsyncioDebug section" );
420
+ }
421
+ return result ;
418
422
}
419
423
420
424
@@ -560,6 +564,16 @@ read_int(pid_t pid, uintptr_t address, int *result)
560
564
return 0 ;
561
565
}
562
566
567
+ static int
568
+ read_unsigned_long (pid_t pid , uintptr_t address , unsigned long * result )
569
+ {
570
+ int bytes_read = read_memory (pid , address , sizeof (unsigned long ), result );
571
+ if (bytes_read < 0 ) {
572
+ return -1 ;
573
+ }
574
+ return 0 ;
575
+ }
576
+
563
577
static int
564
578
read_pyobj (pid_t pid , uintptr_t address , PyObject * ptr_addr )
565
579
{
@@ -627,7 +641,7 @@ read_py_long(pid_t pid, _Py_DebugOffsets* offsets, uintptr_t address)
627
641
return 0 ;
628
642
}
629
643
630
- char * digits = (char * )PyMem_RawMalloc (size * sizeof (digit ));
644
+ digit * digits = (digit * )PyMem_RawMalloc (size * sizeof (digit ));
631
645
if (!digits ) {
632
646
PyErr_NoMemory ();
633
647
return -1 ;
@@ -645,16 +659,13 @@ read_py_long(pid_t pid, _Py_DebugOffsets* offsets, uintptr_t address)
645
659
646
660
long value = 0 ;
647
661
662
+ // In theory this can overflow, but because of llvm/llvm-project#16778
663
+ // we can't use __builtin_mul_overflow because it fails to link with
664
+ // __muloti4 on aarch64. In practice this is fine because all we're
665
+ // testing here are task numbers that would fit in a single byte.
648
666
for (ssize_t i = 0 ; i < size ; ++ i ) {
649
- long long factor ;
650
- if (__builtin_mul_overflow (digits [i ], (1UL << (ssize_t )(shift * i )),
651
- & factor )
652
- ) {
653
- goto error ;
654
- }
655
- if (__builtin_add_overflow (value , factor , & value )) {
656
- goto error ;
657
- }
667
+ long long factor = digits [i ] * (1UL << (ssize_t )(shift * i ));
668
+ value += factor ;
658
669
}
659
670
PyMem_RawFree (digits );
660
671
if (negative ) {
@@ -693,8 +704,8 @@ parse_task_name(
693
704
return NULL ;
694
705
}
695
706
696
- int flags ;
697
- err = read_int (
707
+ unsigned long flags ;
708
+ err = read_unsigned_long (
698
709
pid ,
699
710
(uintptr_t )task_name_obj .ob_type + offsets -> type_object .tp_flags ,
700
711
& flags );
0 commit comments