diff --git a/React/Profiler/RCTProfile.m b/React/Profiler/RCTProfile.m index b51a9bcc2..d2b0f479d 100644 --- a/React/Profiler/RCTProfile.m +++ b/React/Profiler/RCTProfile.m @@ -153,6 +153,20 @@ static dispatch_group_t RCTProfileGetUnhookGroup(void) return unhookGroup; } +// Used by RCTProfileTrampoline assembly file to call libc`malloc +RCT_EXTERN void *RCTProfileMalloc(size_t size); +void *RCTProfileMalloc(size_t size) +{ + return malloc(size); +} + +// Used by RCTProfileTrampoline assembly file to call libc`free +RCT_EXTERN void RCTProfileFree(void *buf); +void RCTProfileFree(void *buf) +{ + free(buf); +} + RCT_EXTERN IMP RCTProfileGetImplementation(id obj, SEL cmd); IMP RCTProfileGetImplementation(id obj, SEL cmd) { diff --git a/React/Profiler/RCTProfileTrampoline-arm.S b/React/Profiler/RCTProfileTrampoline-arm.S index 99ac6498b..aa622bbd0 100644 --- a/React/Profiler/RCTProfileTrampoline-arm.S +++ b/React/Profiler/RCTProfileTrampoline-arm.S @@ -35,12 +35,7 @@ SYMBOL_NAME(RCTProfileTrampoline): * profile */ mov r0, #0xc - movw ip, :lower16:(L_malloc-(LPC1_0+4)) - movt ip, :upper16:(L_malloc-(LPC1_0+4)) -LPC1_0: - add ip, pc - ldr ip, [ip] - blx ip + bl SYMBOL_NAME(RCTProfileMalloc) /** * r4 is the callee saved register we'll use to refer to the allocated memory, * store its initial value, so we can restore it later @@ -92,12 +87,7 @@ LPC1_0: ldr r1, [r4, #0x8] ldr r4, [r4] push {r1} // save the caller on the stack - movw ip, :lower16:(L_free-(LPC1_1+4)) - movt ip, :upper16:(L_free-(LPC1_1+4)) -LPC1_1: - add ip, pc - ldr ip, [ip] - blx ip + bl SYMBOL_NAME(RCTProfileFree) pop {lr} // pop the caller pop {r0} // pop the return value @@ -105,11 +95,4 @@ LPC1_1: trap - .data - .p2align 2 -L_malloc: - .long SYMBOL_NAME(malloc) -L_free: - .long SYMBOL_NAME(free) - #endif diff --git a/React/Profiler/RCTProfileTrampoline-arm64.S b/React/Profiler/RCTProfileTrampoline-arm64.S index 30ce4a048..e51369687 100644 --- a/React/Profiler/RCTProfileTrampoline-arm64.S +++ b/React/Profiler/RCTProfileTrampoline-arm64.S @@ -48,7 +48,7 @@ SYMBOL_NAME(RCTProfileTrampoline): * the implementation and the caller address. */ mov x0, #0x10 - bl SYMBOL_NAME(malloc) + bl SYMBOL_NAME(RCTProfileMalloc) // store the initial value of r19, the callee saved register we'll use str x19, [x0] mov x19, x0 @@ -111,7 +111,7 @@ SYMBOL_NAME(RCTProfileTrampoline): ldr x10, [x19, #0x8] // load the caller address ldr x19, [x19] // restore x19 str x10, [sp, #0x18] // store x10 on the stack space allocated above - bl SYMBOL_NAME(free) + bl SYMBOL_NAME(RCTProfileFree) // Load both return values and link register from the stack ldr q0, [sp, #0x0] diff --git a/React/Profiler/RCTProfileTrampoline-i386.S b/React/Profiler/RCTProfileTrampoline-i386.S index 7faba7742..d1adf1a08 100644 --- a/React/Profiler/RCTProfileTrampoline-i386.S +++ b/React/Profiler/RCTProfileTrampoline-i386.S @@ -30,7 +30,7 @@ SYMBOL_NAME(RCTProfileTrampoline): */ subl $0x8, %esp // stack padding (16-byte alignment for function calls) pushl $0xc // allocate 12-bytes - calll SYMBOL_NAME(malloc) + calll SYMBOL_NAME(RCTProfileMalloc) addl $0xc, %esp // restore stack (8-byte padding + 4-byte argument) /** @@ -85,7 +85,7 @@ SYMBOL_NAME(RCTProfileTrampoline): * the stack has already been padded and the first and only argument, the * memory address, is already in the bottom of the stack. */ - calll SYMBOL_NAME(free) + calll SYMBOL_NAME(RCTProfileFree) addl $0x8, %esp /** diff --git a/React/Profiler/RCTProfileTrampoline-x86_64.S b/React/Profiler/RCTProfileTrampoline-x86_64.S index 0325fb0f5..21072d842 100644 --- a/React/Profiler/RCTProfileTrampoline-x86_64.S +++ b/React/Profiler/RCTProfileTrampoline-x86_64.S @@ -90,7 +90,7 @@ SYMBOL_NAME(RCTProfileTrampoline): // allocate 16 bytes movq $0x10, %rdi - callq SYMBOL_NAME_PIC(malloc) + callq SYMBOL_NAME_PIC(RCTProfileMalloc) // store the initial value of calle saved registers %r13 and %r14 movq %r13, 0x0(%rax) @@ -169,7 +169,7 @@ SYMBOL_NAME(RCTProfileTrampoline): andq $-0x10, %rsp // Free the memory allocated to stash callee saved registers - callq SYMBOL_NAME_PIC(free) + callq SYMBOL_NAME_PIC(RCTProfileFree) // unalign stack and restore %r12 movq %r12, %rsp