Skip to content

Commit

Permalink
i#1569 AArch64: Implement xfer_to_new_libdr.
Browse files Browse the repository at this point in the history
Some code is moved from arm/arm.asm and aarch64/aarch64.asm into
aarchxx/aarchxx.asm, where it is shared between the two architectures.

Review-URL: https://codereview.appspot.com/296270043
  • Loading branch information
egrimley-arm committed Jun 8, 2016
1 parent c49e30d commit d966e7d
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 72 deletions.
10 changes: 9 additions & 1 deletion core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ set(asm_deps
"${PROJECT_BINARY_DIR}/configure.h")
add_asm_target(arch/${ARCH_NAME}/${ARCH_NAME}.asm arch_core_asm_src arch_core_asm_tgt
"_core" "" "${asm_deps}")
if (NOT "${ARCH_NAME}" STREQUAL "${ARCH_NAME_SHARED}")
add_asm_target(arch/${ARCH_NAME_SHARED}/${ARCH_NAME_SHARED}.asm
archshared_core_asm_src archshared_core_asm_tgt
"_core" "" "${asm_deps}")
endif ()
add_asm_target(arch/pre_inject_asm.asm preinject_asm_src preinject_asm_tgt ""
"-DNOT_DYNAMORIO_CORE_PROPER" "${asm_deps}")

Expand Down Expand Up @@ -211,6 +216,7 @@ set(ARCH_SRCS
arch/steal_reg.c
arch/x86_code.c
${arch_core_asm_src}
${archshared_core_asm_src}
arch/${ARCH_NAME}/optimize.c
arch/sideline.c
arch/retcheck.c
Expand Down Expand Up @@ -409,6 +415,7 @@ endif ()
if ("${CMAKE_GENERATOR}" MATCHES "Visual Studio")
# For VS generators, we also need one for our asm custom commands.
add_dependencies(dynamorio ${arch_core_asm_tgt})
add_dependencies(dynamorio ${archshared_core_asm_tgt})
endif ()

target_link_libraries(dynamorio drhelper)
Expand Down Expand Up @@ -921,7 +928,8 @@ if (BUILD_TESTS)
add_gen_events_deps(unit_tests)
if ("${CMAKE_GENERATOR}" MATCHES "Visual Studio")
# for parallel build correctness we need a target dependence
add_dependencies(unit_tests ${arch_core_asm_tgt} ntdll_imports)
add_dependencies(unit_tests ${arch_core_asm_tgt} ${archshared_core_asm_tgt}
ntdll_imports)
endif ()
set(unit_tests_extra_flags "")
if (UNIX AND NOT DEBUG)
Expand Down
24 changes: 3 additions & 21 deletions core/arch/aarch64/aarch64.asm
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ START_FILE
# error Non-Unix is not supported
#endif

/* sizeof(priv_mcontext_t) rounded up to a multiple of 16 */
#define PRIV_MCONTEXT_SIZE 800

/* offsetof(dcontext_t, dstack) */
#define dstack_OFFSET 0x360
/* offsetof(dcontext_t, is_exiting) */
Expand All @@ -55,24 +58,6 @@ START_FILE
DECL_EXTERN(dr_setjmp_sigmask)
#endif

#ifdef UNIX
# if !defined(STANDALONE_UNIT_TEST) && !defined(STATIC_LIBRARY)
DECLARE_FUNC(_start)
GLOBAL_LABEL(_start:)
mov x29, #0 /* clear frame ptr for stack trace bottom */
CALLC2(GLOBAL_REF(relocate_dynamorio), #0, #0)
CALLC3(GLOBAL_REF(privload_early_inject), sp, #0, #0)
/* shouldn't return */
bl GLOBAL_REF(unexpected_return)
END_FUNC(_start)

DECLARE_FUNC(xfer_to_new_libdr)
GLOBAL_LABEL(xfer_to_new_libdr:)
bl GLOBAL_REF(unexpected_return) /* FIXME i#1569: NYI */
END_FUNC(xfer_to_new_libdr)
# endif /* !STANDALONE_UNIT_TEST && !STATIC_LIBRARY */
#endif /* UNIX */

/* All CPU ID registers are accessible only in privileged modes. */
DECLARE_FUNC(cpuid_supported)
GLOBAL_LABEL(cpuid_supported:)
Expand Down Expand Up @@ -139,9 +124,6 @@ GLOBAL_LABEL(dr_app_running_under_dynamorio:)
END_FUNC(dr_app_running_under_dynamorio)
#endif /* DR_APP_EXPORTS */

/* sizeof(priv_mcontext_t) rounded up to a multiple of 16 */
#define PRIV_MCONTEXT_SIZE 800

DECLARE_EXPORTED_FUNC(dynamorio_app_take_over)
GLOBAL_LABEL(dynamorio_app_take_over:)
/* Save FP and LR for the case that DR is not taking over. */
Expand Down
92 changes: 92 additions & 0 deletions core/arch/aarchxx/aarchxx.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/* **********************************************************
* Copyright (c) 2014-2016 Google, Inc. All rights reserved.
* Copyright (c) 2016 ARM Limited. All rights reserved.
* **********************************************************/

/*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of ARM Limited nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL ARM LIMITED OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*/

/***************************************************************************
* Assembly and trampoline code shared between between ARM and AArch64.
*/

#include "../asm_defines.asm"
START_FILE

#ifdef UNIX
# if !defined(STANDALONE_UNIT_TEST) && !defined(STATIC_LIBRARY)
DECLARE_FUNC(_start)
GLOBAL_LABEL(_start:)
mov FP, #0 /* clear frame ptr for stack trace bottom */
/* i#1676, i#1708: relocate dynamorio if it is not loaded to preferred address.
* We call this here to ensure it's safe to access globals once in C code
* (xref i#1865).
*/
CALLC2(GLOBAL_REF(relocate_dynamorio), #0, #0)

/* Clear 2nd & 3rd args to distinguish from xfer_to_new_libdr */
mov ARG2, #0
mov ARG3, #0

/* Entry from xfer_to_new_libdr is here. It has set up 2nd & 3rd args already. */
.L_start_invoke_C:
mov FP, #0 /* clear frame ptr for stack trace bottom */
mov ARG1, sp /* 1st arg to privload_early_inject */
bl GLOBAL_REF(privload_early_inject)
/* shouldn't return */
bl GLOBAL_REF(unexpected_return)
END_FUNC(_start)

/* i#1227: on a conflict with the app we reload ourselves.
* xfer_to_new_libdr(entry, init_sp, cur_dr_map, cur_dr_size)
* =>
* Invokes entry after setting sp to init_sp and placing the current (old)
* libdr bounds in registers for the new libdr to unmap.
*/
DECLARE_FUNC(xfer_to_new_libdr)
GLOBAL_LABEL(xfer_to_new_libdr:)
mov REG_PRESERVED_1, ARG1
/* Restore sp */
mov sp, ARG2
/* Skip prologue that calls relocate_dynamorio() and clears args 2+3 by
* adjusting the _start in the reloaded DR by the same distance as in
* the current DR, but w/o clobbering ARG3 or ARG4.
*/
adr ARG1, .L_start_invoke_C
adr ARG2, _start
sub ARG1, ARG1, ARG2
add REG_PRESERVED_1, REG_PRESERVED_1, ARG1
/* _start expects these as 2nd & 3rd args */
mov ARG2, ARG3
mov ARG3, ARG4
INDJMP REG_PRESERVED_1
END_FUNC(xfer_to_new_libdr)
# endif /* !STANDALONE_UNIT_TEST && !STATIC_LIBRARY */
#endif /* UNIX */

END_FILE
50 changes: 0 additions & 50 deletions core/arch/arm/arm.asm
Original file line number Diff line number Diff line change
Expand Up @@ -79,56 +79,6 @@ DECL_EXTERN(initstack_mutex)
# error Non-Unix is not supported
#endif

#ifdef UNIX
# if !defined(STANDALONE_UNIT_TEST) && !defined(STATIC_LIBRARY)
DECLARE_FUNC(_start)
GLOBAL_LABEL(_start:)
/* i#1676, i#1708: relocate dynamorio if it is not loaded to preferred address.
* We call this here to ensure it's safe to access globals once in C code
* (xref i#1865).
*/
CALLC2(GLOBAL_REF(relocate_dynamorio), #0, #0)

/* Clear 2nd & 3rd args to distinguish from xfer_to_new_libdr */
eor ARG2, ARG2
eor ARG3, ARG3

/* Entry from xfer_to_new_libdr is here. It has set up 2nd & 3rd args already. */
.L_start_invoke_C:
eor r11, r11 /* clear frame ptr for stack trace bottom */
mov r0, sp /* 1st arg to privload_early_inject */
blx GLOBAL_REF(privload_early_inject)
/* shouldn't return */
bl GLOBAL_REF(unexpected_return)
END_FUNC(_start)

/* i#1227: on a conflict with the app we reload ourselves.
* xfer_to_new_libdr(entry, init_sp, cur_dr_map, cur_dr_size)
* =>
* Invokes entry after setting sp to init_sp and placing the current (old)
* libdr bounds in registers for the new libdr to unmap.
*/
DECLARE_FUNC(xfer_to_new_libdr)
GLOBAL_LABEL(xfer_to_new_libdr:)
mov r5, ARG1
/* Restore sp */
mov sp, ARG2
/* Skip prologue that calls relocate_dynamorio() and clears args 2+3 by
* adjusting the _start in the reloaded DR by the same distance as in
* the current DR, but w/o clobbering ARG3 or ARG4.
*/
adr r0, .L_start_invoke_C
adr r1, _start
sub r0, r0, r1
add r5, r5, r0
/* _start expects these as 2nd & 3rd args */
mov ARG2, ARG3
mov ARG3, ARG4
bx r5
END_FUNC(xfer_to_new_libdr)
# endif /* !STANDALONE_UNIT_TEST && !STATIC_LIBRARY */
#endif /* UNIX */

/* all of the CPUID registers are only accessible in privileged modes */
DECLARE_FUNC(cpuid_supported)
GLOBAL_LABEL(cpuid_supported:)
Expand Down
11 changes: 11 additions & 0 deletions core/arch/asm_defines.asm
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,17 @@ ASSUME fs:_DATA @N@\
# define ARG8_NORETADDR ARG8
# define ARG9_NORETADDR ARG9
# define ARG10_NORETADDR ARG10

# ifndef AARCH64
# define FP r11
# define INDJMP bx
# define REG_PRESERVED_1 r4
# else
# define FP x29
# define INDJMP br
# define REG_PRESERVED_1 x19
# endif

#else /* Intel X86 */
# ifdef X64
# ifdef WINDOWS
Expand Down

0 comments on commit d966e7d

Please sign in to comment.