@@ -153,41 +153,15 @@ static int prepend_rebindings(struct rebindings_entry **rebindings_head,
153
153
return 0 ;
154
154
}
155
155
156
- static vm_prot_t get_protection (void *sectionStart) {
157
- mach_port_t task = mach_task_self ();
158
- vm_size_t size = 0 ;
159
- vm_address_t address = (vm_address_t )sectionStart;
160
- memory_object_name_t object;
161
- mach_msg_type_number_t count = VM_REGION_BASIC_INFO_COUNT_64;
162
- vm_region_basic_info_data_64_t info;
163
- kern_return_t info_ret = vm_region_64 (task,
164
- &address,
165
- &size,
166
- VM_REGION_BASIC_INFO_64,
167
- (vm_region_info_64_t )&info,
168
- &count,
169
- &object);
170
- if (info_ret == KERN_SUCCESS) {
171
- return info.protection ;
172
- } else {
173
- return VM_PROT_READ;
174
- }
175
- }
176
-
177
156
static void perform_rebinding_with_section (struct rebindings_entry *rebindings,
178
157
section_t *section,
179
158
intptr_t slide,
180
159
nlist_t *symtab,
181
160
char *strtab,
182
161
uint32_t *indirect_symtab) {
183
- const bool isDataConst = strcmp (section->segname , SEG_DATA_CONST) == 0 ;
184
162
uint32_t *indirect_symbol_indices = indirect_symtab + section->reserved1 ;
185
163
void **indirect_symbol_bindings = (void **)((uintptr_t )slide + section->addr );
186
- vm_prot_t oldProtection = VM_PROT_READ;
187
- if (isDataConst) {
188
- oldProtection = get_protection (rebindings);
189
- mprotect (indirect_symbol_bindings, section->size , PROT_READ | PROT_WRITE);
190
- }
164
+
191
165
for (uint i = 0 ; i < section->size / sizeof (void *); i++) {
192
166
uint32_t symtab_index = indirect_symbol_indices[i];
193
167
if (symtab_index == INDIRECT_SYMBOL_ABS || symtab_index == INDIRECT_SYMBOL_LOCAL ||
@@ -200,33 +174,24 @@ static void perform_rebinding_with_section(struct rebindings_entry *rebindings,
200
174
struct rebindings_entry *cur = rebindings;
201
175
while (cur) {
202
176
for (uint j = 0 ; j < cur->rebindings_nel ; j++) {
203
- if (symbol_name_longer_than_1 &&
204
- strcmp (&symbol_name[1 ], cur->rebindings [j].name ) == 0 ) {
205
- if (cur->rebindings [j].replaced != NULL &&
206
- indirect_symbol_bindings[i] != cur->rebindings [j].replacement ) {
177
+ if (symbol_name_longer_than_1 && strcmp (&symbol_name[1 ], cur->rebindings [j].name ) == 0 ) {
178
+ if (cur->rebindings [j].replaced != NULL && indirect_symbol_bindings[i] != cur->rebindings [j].replacement ) {
207
179
*(cur->rebindings [j].replaced ) = indirect_symbol_bindings[i];
208
180
}
209
- indirect_symbol_bindings[i] = cur->rebindings [j].replacement ;
181
+
182
+ kern_return_t err = vm_protect (mach_task_self (), (uintptr_t )indirect_symbol_bindings, section->size , 0 , VM_PROT_READ | VM_PROT_WRITE | VM_PROT_COPY);
183
+
184
+ if (err == KERN_SUCCESS) {
185
+ indirect_symbol_bindings[i] = cur->rebindings [j].replacement ;
186
+ }
187
+
210
188
goto symbol_loop;
211
189
}
212
190
}
213
191
cur = cur->next ;
214
192
}
215
193
symbol_loop:;
216
194
}
217
- if (isDataConst) {
218
- int protection = 0 ;
219
- if (oldProtection & VM_PROT_READ) {
220
- protection |= PROT_READ;
221
- }
222
- if (oldProtection & VM_PROT_WRITE) {
223
- protection |= PROT_WRITE;
224
- }
225
- if (oldProtection & VM_PROT_EXECUTE) {
226
- protection |= PROT_EXEC;
227
- }
228
- mprotect (indirect_symbol_bindings, section->size , protection);
229
- }
230
195
}
231
196
232
197
static void rebind_symbols_for_image (struct rebindings_entry *rebindings,
0 commit comments