@@ -97,35 +97,13 @@ static void doraemon_perform_rebinding_with_section(struct doraemon_rebindings_e
97
97
const bool isDataConst = strcmp (section -> segname , "__DATA_CONST" ) == 0 ;
98
98
uint32_t * indirect_symbol_indices = indirect_symtab + section -> reserved1 ;
99
99
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 ;
105
100
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." );
126
104
127
- return ;
128
- }
105
+ return ;
106
+ }
129
107
}
130
108
for (uint i = 0 ; i < section -> size / sizeof (void * ); i ++ ) {
131
109
uint32_t symtab_index = indirect_symbol_indices [i ];
@@ -147,16 +125,13 @@ static void doraemon_perform_rebinding_with_section(struct doraemon_rebindings_e
147
125
}
148
126
indirect_symbol_bindings [i ] = cur -> rebindings [j ].replacement ;
149
127
goto symbol_loop ;
128
+
150
129
}
151
130
}
152
131
cur = cur -> next ;
153
132
}
154
133
symbol_loop :;
155
134
}
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
- }
160
135
}
161
136
162
137
static void doraemon_rebind_symbols_for_image (struct doraemon_rebindings_entry * rebindings ,
0 commit comments