@@ -414,7 +414,11 @@ get_py_runtime(pid_t pid)
414414static uintptr_t
415415get_async_debug (pid_t pid )
416416{
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 ;
418422}
419423
420424
@@ -560,6 +564,16 @@ read_int(pid_t pid, uintptr_t address, int *result)
560564 return 0 ;
561565}
562566
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+
563577static int
564578read_pyobj (pid_t pid , uintptr_t address , PyObject * ptr_addr )
565579{
@@ -627,7 +641,7 @@ read_py_long(pid_t pid, _Py_DebugOffsets* offsets, uintptr_t address)
627641 return 0 ;
628642 }
629643
630- char * digits = (char * )PyMem_RawMalloc (size * sizeof (digit ));
644+ digit * digits = (digit * )PyMem_RawMalloc (size * sizeof (digit ));
631645 if (!digits ) {
632646 PyErr_NoMemory ();
633647 return -1 ;
@@ -645,16 +659,13 @@ read_py_long(pid_t pid, _Py_DebugOffsets* offsets, uintptr_t address)
645659
646660 long value = 0 ;
647661
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.
648666 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 ;
658669 }
659670 PyMem_RawFree (digits );
660671 if (negative ) {
@@ -693,8 +704,8 @@ parse_task_name(
693704 return NULL ;
694705 }
695706
696- int flags ;
697- err = read_int (
707+ unsigned long flags ;
708+ err = read_unsigned_long (
698709 pid ,
699710 (uintptr_t )task_name_obj .ob_type + offsets -> type_object .tp_flags ,
700711 & flags );
0 commit comments