@@ -97,35 +97,13 @@ static void doraemon_perform_rebinding_with_section(struct doraemon_rebindings_e
9797 const bool isDataConst = strcmp (section -> segname , "__DATA_CONST" ) == 0 ;
9898 uint32_t * indirect_symbol_indices = indirect_symtab + section -> reserved1 ;
9999 void * * indirect_symbol_bindings = (void * * )((uintptr_t )slide + section -> addr );
100- vm_prot_t oldProtection = VM_PROT_NONE ;
101- vm_address_t vmAddress = (vm_address_t )indirect_symbol_bindings ;
102- // https://opensource.apple.com/source/xnu/xnu-7195.141.2/osfmk/vm/vm_user.c.auto.html
103- // OUT argument, but init with zero to eliminate `Variable 'vmSize' may be uninitialized when used here` warning
104- vm_size_t vmSize = 0 ;
105100 if (isDataConst ) {
106- memory_object_name_t object ;
107- #ifdef __LP64__
108- mach_msg_type_number_t count = VM_REGION_BASIC_INFO_COUNT_64 ;
109- vm_region_basic_info_data_64_t vmRegionBasicInfoData ;
110- kern_return_t kernelReturn = vm_region_64 (mach_task_self (), & vmAddress , & vmSize , VM_REGION_BASIC_INFO_64 , (vm_region_info_t )& vmRegionBasicInfoData , & count , & object );
111- #else
112- mach_msg_type_number_t count = VM_REGION_BASIC_INFO_COUNT ;
113- vm_region_basic_info_data_t vmRegionBasicInfoData ;
114- kern_return_t kernelReturn = vm_region (mach_task_self (), & vmAddress , & vmSize , VM_REGION_BASIC_INFO , (vm_region_info_t )& vmRegionBasicInfoData , & count , object );
115- #endif
116- if (__builtin_expect (kernelReturn == KERN_SUCCESS , true)) {
117- oldProtection = vmRegionBasicInfoData .protection ;
118- } else {
119- assert (false && "vm_region() failure." );
120-
121- return ;
122- }
123- kernelReturn = vm_protect (mach_task_self (), vmAddress , vmSize , false, oldProtection | VM_PROT_WRITE );
124- if (__builtin_expect (kernelReturn != KERN_SUCCESS , false)) {
125- assert (false && "vm_protect() failure." );
101+ kern_return_t kernelReturn = vm_protect (mach_task_self (), (vm_address_t )indirect_symbol_bindings , section -> size , false, VM_PROT_READ | VM_PROT_WRITE | VM_PROT_COPY );
102+ if (__builtin_expect (kernelReturn != KERN_SUCCESS , false)) {
103+ assert (false && "vm_protect() failure." );
126104
127- return ;
128- }
105+ return ;
106+ }
129107 }
130108 for (uint i = 0 ; i < section -> size / sizeof (void * ); i ++ ) {
131109 uint32_t symtab_index = indirect_symbol_indices [i ];
@@ -147,16 +125,13 @@ static void doraemon_perform_rebinding_with_section(struct doraemon_rebindings_e
147125 }
148126 indirect_symbol_bindings [i ] = cur -> rebindings [j ].replacement ;
149127 goto symbol_loop ;
128+
150129 }
151130 }
152131 cur = cur -> next ;
153132 }
154133 symbol_loop :;
155134 }
156- if (isDataConst ) {
157- kern_return_t kernelReturn = vm_protect (mach_task_self (), vmAddress , vmSize , false, oldProtection );
158- assert (kernelReturn == KERN_SUCCESS && "vm_protect() failure." );
159- }
160135}
161136
162137static void doraemon_rebind_symbols_for_image (struct doraemon_rebindings_entry * rebindings ,
0 commit comments