@@ -539,7 +539,7 @@ get_py_runtime(proc_handle_t* handle)
539539}
540540
541541// Platform-independent memory read function
542- static Py_ssize_t
542+ static int
543543read_memory (proc_handle_t * handle , uint64_t remote_address , size_t len , void * dst )
544544{
545545#ifdef MS_WINDOWS
@@ -552,7 +552,7 @@ read_memory(proc_handle_t *handle, uint64_t remote_address, size_t len, void* ds
552552 }
553553 result += read_bytes ;
554554 } while (result < len );
555- return ( Py_ssize_t ) result ;
555+ return 0 ;
556556#elif defined(__linux__ ) && HAVE_PROCESS_VM_READV
557557 struct iovec local [1 ];
558558 struct iovec remote [1 ];
@@ -573,7 +573,7 @@ read_memory(proc_handle_t *handle, uint64_t remote_address, size_t len, void* ds
573573
574574 result += read_bytes ;
575575 } while ((size_t )read_bytes != local [0 ].iov_len );
576- return result ;
576+ return 0 ;
577577#elif defined(__APPLE__ ) && TARGET_OS_OSX
578578 Py_ssize_t result = -1 ;
579579 kern_return_t kr = mach_vm_read_overwrite (
@@ -596,7 +596,7 @@ read_memory(proc_handle_t *handle, uint64_t remote_address, size_t len, void* ds
596596 }
597597 return -1 ;
598598 }
599- return len ;
599+ return 0 ;
600600#else
601601 PyErr_SetString (
602602 PyExc_RuntimeError ,
@@ -606,7 +606,7 @@ read_memory(proc_handle_t *handle, uint64_t remote_address, size_t len, void* ds
606606}
607607
608608// Platform-independent memory write function
609- static Py_ssize_t
609+ static int
610610write_memory (proc_handle_t * handle , uintptr_t remote_address , size_t len , const void * src )
611611{
612612#ifdef MS_WINDOWS
@@ -619,7 +619,7 @@ write_memory(proc_handle_t *handle, uintptr_t remote_address, size_t len, const
619619 }
620620 result += written ;
621621 } while (result < len );
622- return ( Py_ssize_t ) result ;
622+ return 0 ;
623623#elif defined(__linux__ ) && HAVE_PROCESS_VM_READV
624624 struct iovec local [1 ];
625625 struct iovec remote [1 ];
@@ -640,7 +640,7 @@ write_memory(proc_handle_t *handle, uintptr_t remote_address, size_t len, const
640640
641641 result += written ;
642642 } while ((size_t )written != local [0 ].iov_len );
643- return result ;
643+ return 0 ;
644644#elif defined(__APPLE__ ) && TARGET_OS_OSX
645645 kern_return_t kr = mach_vm_write (
646646 pid_to_task (handle -> pid ),
@@ -661,7 +661,7 @@ write_memory(proc_handle_t *handle, uintptr_t remote_address, size_t len, const
661661 }
662662 return -1 ;
663663 }
664- return len ;
664+ return 0 ;
665665#else
666666 PyErr_Format (PyExc_RuntimeError , "Writing memory is not supported on this platform" );
667667 return -1 ;
@@ -749,9 +749,7 @@ read_offsets(
749749 return -1 ;
750750 }
751751 size_t size = sizeof (struct _Py_DebugOffsets );
752- Py_ssize_t bytes = read_memory (
753- handle , * runtime_start_address , size , debug_offsets );
754- if (bytes < 0 || (size_t )bytes != size ) {
752+ if (0 != read_memory (handle , * runtime_start_address , size , debug_offsets )) {
755753 return -1 ;
756754 }
757755 if (ensure_debug_offset_compatibility (debug_offsets )) {
@@ -773,12 +771,12 @@ send_exec_to_proc_handle(proc_handle_t *handle, int tid, const char *debugger_sc
773771 uintptr_t interpreter_state_list_head = debug_offsets .runtime_state .interpreters_head ;
774772
775773 uintptr_t interpreter_state_addr ;
776- Py_ssize_t bytes = read_memory (
777- handle ,
778- runtime_start_address + interpreter_state_list_head ,
779- sizeof (void * ),
780- & interpreter_state_addr );
781- if ( bytes == -1 ) {
774+ if ( 0 ! = read_memory (
775+ handle ,
776+ runtime_start_address + interpreter_state_list_head ,
777+ sizeof (void * ),
778+ & interpreter_state_addr ))
779+ {
782780 return -1 ;
783781 }
784782
@@ -788,12 +786,12 @@ send_exec_to_proc_handle(proc_handle_t *handle, int tid, const char *debugger_sc
788786 }
789787
790788 int is_remote_debugging_enabled = 0 ;
791- bytes = read_memory (
792- handle ,
793- interpreter_state_addr + debug_offsets .debugger_support .remote_debugging_enabled ,
794- sizeof (int ),
795- & is_remote_debugging_enabled );
796- if ( bytes == -1 ) {
789+ if ( 0 ! = read_memory (
790+ handle ,
791+ interpreter_state_addr + debug_offsets .debugger_support .remote_debugging_enabled ,
792+ sizeof (int ),
793+ & is_remote_debugging_enabled ))
794+ {
797795 return -1 ;
798796 }
799797
@@ -806,44 +804,44 @@ send_exec_to_proc_handle(proc_handle_t *handle, int tid, const char *debugger_sc
806804 pid_t this_tid = 0 ;
807805
808806 if (tid != 0 ) {
809- bytes = read_memory (
810- handle ,
811- interpreter_state_addr + debug_offsets .interpreter_state .threads_head ,
812- sizeof (void * ),
813- & thread_state_addr );
814- if ( bytes == -1 ) {
807+ if ( 0 ! = read_memory (
808+ handle ,
809+ interpreter_state_addr + debug_offsets .interpreter_state .threads_head ,
810+ sizeof (void * ),
811+ & thread_state_addr ))
812+ {
815813 return -1 ;
816814 }
817815 while (thread_state_addr != 0 ) {
818- bytes = read_memory (
819- handle ,
820- thread_state_addr + debug_offsets .thread_state .native_thread_id ,
821- sizeof (pid_t ),
822- & this_tid );
823- if ( bytes == -1 ) {
816+ if ( 0 ! = read_memory (
817+ handle ,
818+ thread_state_addr + debug_offsets .thread_state .native_thread_id ,
819+ sizeof (pid_t ),
820+ & this_tid ))
821+ {
824822 return -1 ;
825823 }
826824
827825 if (this_tid == tid ) {
828826 break ;
829827 }
830828
831- bytes = read_memory (
832- handle ,
833- thread_state_addr + debug_offsets .thread_state .next ,
834- sizeof (void * ),
835- & thread_state_addr );
836- if ( bytes == -1 ) {
829+ if ( 0 ! = read_memory (
830+ handle ,
831+ thread_state_addr + debug_offsets .thread_state .next ,
832+ sizeof (void * ),
833+ & thread_state_addr ))
834+ {
837835 return -1 ;
838836 }
839837 }
840838 } else {
841- bytes = read_memory (
842- handle ,
843- interpreter_state_addr + debug_offsets .interpreter_state .threads_main ,
844- sizeof (void * ),
845- & thread_state_addr );
846- if ( bytes == -1 ) {
839+ if ( 0 ! = read_memory (
840+ handle ,
841+ interpreter_state_addr + debug_offsets .interpreter_state .threads_main ,
842+ sizeof (void * ),
843+ & thread_state_addr ))
844+ {
847845 return -1 ;
848846 }
849847 }
@@ -854,12 +852,12 @@ send_exec_to_proc_handle(proc_handle_t *handle, int tid, const char *debugger_sc
854852 }
855853
856854 uintptr_t eval_breaker ;
857- bytes = read_memory (
858- handle ,
859- thread_state_addr + debug_offsets .debugger_support .eval_breaker ,
860- sizeof (uintptr_t ),
861- & eval_breaker );
862- if ( bytes == -1 ) {
855+ if ( 0 ! = read_memory (
856+ handle ,
857+ thread_state_addr + debug_offsets .debugger_support .eval_breaker ,
858+ sizeof (uintptr_t ),
859+ & eval_breaker ))
860+ {
863861 return -1 ;
864862 }
865863
@@ -876,12 +874,12 @@ send_exec_to_proc_handle(proc_handle_t *handle, int tid, const char *debugger_sc
876874 thread_state_addr +
877875 debug_offsets .debugger_support .remote_debugger_support +
878876 debug_offsets .debugger_support .debugger_script_path );
879- bytes = write_memory (
880- handle ,
881- debugger_script_path_addr ,
882- strlen (debugger_script_path ) + 1 ,
883- debugger_script_path );
884- if ( bytes == -1 ) {
877+ if ( 0 ! = write_memory (
878+ handle ,
879+ debugger_script_path_addr ,
880+ strlen (debugger_script_path ) + 1 ,
881+ debugger_script_path ))
882+ {
885883 return -1 ;
886884 }
887885 }
@@ -891,33 +889,34 @@ send_exec_to_proc_handle(proc_handle_t *handle, int tid, const char *debugger_sc
891889 thread_state_addr +
892890 debug_offsets .debugger_support .remote_debugger_support +
893891 debug_offsets .debugger_support .debugger_pending_call );
894- bytes = write_memory (
895- handle ,
896- debugger_pending_call_addr ,
897- sizeof (int ),
898- & pending_call );
892+ if ( 0 ! = write_memory (
893+ handle ,
894+ debugger_pending_call_addr ,
895+ sizeof (int ),
896+ & pending_call ))
899897
900- if ( bytes == -1 ) {
898+ {
901899 return -1 ;
902900 }
903901
904- bytes = write_memory (
905- handle ,
906- thread_state_addr + debug_offsets .debugger_support .eval_breaker ,
907- sizeof (uintptr_t ),
908- & eval_breaker );
902+ if ( 0 ! = write_memory (
903+ handle ,
904+ thread_state_addr + debug_offsets .debugger_support .eval_breaker ,
905+ sizeof (uintptr_t ),
906+ & eval_breaker ))
909907
910- if ( bytes == -1 ) {
908+ {
911909 return -1 ;
912910 }
913911
914- bytes = read_memory (
915- handle ,
916- thread_state_addr + debug_offsets .debugger_support .eval_breaker ,
917- sizeof (uintptr_t ),
918- & eval_breaker );
919-
920- printf ("Eval breaker: %p\n" , (void * )eval_breaker );
912+ if (0 == read_memory (
913+ handle ,
914+ thread_state_addr + debug_offsets .debugger_support .eval_breaker ,
915+ sizeof (uintptr_t ),
916+ & eval_breaker ))
917+ {
918+ printf ("Eval breaker: %p\n" , (void * )eval_breaker );
919+ }
921920
922921 return 0 ;
923922}
0 commit comments