2015-11-25 11:09:00 +00:00
|
|
|
/**
|
2018-09-11 22:27:47 +00:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2015-11-25 11:09:00 +00:00
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2015-11-25 11:09:00 +00:00
|
|
|
*/
|
|
|
|
|
2015-10-20 11:11:38 +00:00
|
|
|
#include "RCTDefines.h"
|
2015-10-27 19:59:27 +00:00
|
|
|
#include "RCTMacros.h"
|
2015-10-20 11:11:38 +00:00
|
|
|
|
2016-06-13 11:16:19 +00:00
|
|
|
#if RCT_PROFILE && defined(__arm__)
|
2015-10-20 11:11:38 +00:00
|
|
|
|
2016-03-23 01:24:16 +00:00
|
|
|
.thumb
|
2016-04-04 13:48:44 +00:00
|
|
|
.thumb_func
|
2015-10-27 19:59:27 +00:00
|
|
|
.globl SYMBOL_NAME(RCTProfileTrampoline)
|
|
|
|
SYMBOL_NAME(RCTProfileTrampoline):
|
2015-10-20 11:11:38 +00:00
|
|
|
/**
|
|
|
|
* The explanation here is shorter, refer to the x86_64 implementation to a
|
|
|
|
* richer explanation
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save the parameter registers (r0-r3), r7 (frame pointer) and lr (link
|
|
|
|
* register (contains the address of the caller of RCTProfileTrampoline)
|
|
|
|
*/
|
|
|
|
push {r0-r3, r7, lr}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocate memory to store values across function calls: 12-bytes are
|
|
|
|
* allocated to store 3 values: the previous value of the callee saved
|
|
|
|
* register used to save the pointer to the allocated memory, the caller of
|
|
|
|
* RCTProfileTrampoline and the address of the actual function we want to
|
|
|
|
* profile
|
|
|
|
*/
|
|
|
|
mov r0, #0xc
|
2017-03-16 19:24:11 +00:00
|
|
|
bl SYMBOL_NAME(RCTProfileMalloc)
|
2015-10-20 11:11:38 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
str r4, [r0]
|
|
|
|
mov r4, r0
|
|
|
|
|
|
|
|
/**
|
|
|
|
* void RCTProfileGetImplementation(id object, SEL selector) in RCTProfile.m
|
|
|
|
*
|
|
|
|
* Load the first 2 argumenters (self and _cmd) used to call
|
|
|
|
* RCTProfileTrampoline from the stack and put them on the appropriate registers.
|
|
|
|
*/
|
|
|
|
ldr r0, [sp]
|
|
|
|
ldr r1, [sp, #0x4]
|
2015-10-27 19:59:27 +00:00
|
|
|
bl SYMBOL_NAME(RCTProfileGetImplementation)
|
2015-10-20 11:11:38 +00:00
|
|
|
// store the actual function address in the allocated memory
|
|
|
|
str r0, [r4, #0x4]
|
|
|
|
|
|
|
|
/**
|
|
|
|
* void RCTProfileGetImplementation(id object, SEL selector) in RCTProfile.m
|
|
|
|
*
|
|
|
|
* Load the first 2 arguments again to start the profiler
|
|
|
|
*/
|
|
|
|
ldr r0, [sp]
|
|
|
|
ldr r1, [sp, #0x4]
|
2015-10-27 19:59:27 +00:00
|
|
|
bl SYMBOL_NAME(RCTProfileTrampolineStart)
|
2015-10-20 11:11:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Restore the state to call the actual function we want to profile: pop
|
|
|
|
* all the registers
|
|
|
|
*/
|
|
|
|
pop {r0-r3, r7, lr}
|
|
|
|
|
|
|
|
// store lr (the caller) since it'll be overridden by `blx` (call)
|
|
|
|
str lr, [r4, #0x8]
|
|
|
|
ldr r12, [r4, #0x4] // load the function address
|
|
|
|
blx r12 // call it
|
|
|
|
push {r0} // save return value
|
|
|
|
|
|
|
|
// void RCTProfileTrampolineEnd(void) in RCTProfile.m - just ends this profile
|
2015-10-27 19:59:27 +00:00
|
|
|
bl SYMBOL_NAME(RCTProfileTrampolineEnd)
|
2015-10-20 11:11:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Save the value we still need from the allocated memory (caller address),
|
|
|
|
* restore r4 and free the allocated memory (put its address in r0)
|
|
|
|
*/
|
|
|
|
mov r0, r4
|
|
|
|
ldr r1, [r4, #0x8]
|
|
|
|
ldr r4, [r4]
|
|
|
|
push {r1} // save the caller on the stack
|
2017-03-16 19:24:11 +00:00
|
|
|
bl SYMBOL_NAME(RCTProfileFree)
|
2015-10-20 11:11:38 +00:00
|
|
|
|
|
|
|
pop {lr} // pop the caller
|
|
|
|
pop {r0} // pop the return value
|
|
|
|
bx lr // jump to the calleer
|
|
|
|
|
2016-04-04 13:48:44 +00:00
|
|
|
trap
|
|
|
|
|
2015-10-20 11:11:38 +00:00
|
|
|
#endif
|