Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
v0
  • Loading branch information
zhengyu123 committed Jul 14, 2025
commit f523bb2f604c79a38ad878fffee2e458a112b37a
5 changes: 4 additions & 1 deletion ddprof-lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ tasks.whenTaskAdded { task ->
if (compileTask != null) {
dependsOn compileTask
}
dependsOn asmTask
linkerArgs.addAll(config.linkerArgs)
toolChain = task.toolChain
targetPlatform = task.targetPlatform
Expand Down Expand Up @@ -604,7 +605,9 @@ tasks.register('javadocJar', Jar) {
from javadoc.destinationDir
}


tasks.register('asmTask', Exec) {
commandLine 'clang', '-D__aarch64__', 'src/main/asm/safefetch.S', '-o', 'build/obj/safefetch.o'
}

tasks.register('scanBuild', Exec) {
workingDir "${projectDir}/src/test/make"
Expand Down
53 changes: 53 additions & 0 deletions ddprof-lib/src/main/asm/safefetch.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

#define DECLARE_FUNC(func) \
.globl func %% \
.hidden func %% \
.type func, %function %% \
func

#if defined(__x86_64__)
.text

# Support for int SafeFetch32(int* address, int defaultval);
#
# %rdi : address
# %esi : defaultval
DECLARE_FUNC(SafeFetch32_impl):
DECLARE_FUNC(_SafeFetch32_fault):
movl (%rdi), %eax # load target value, may fault
ret
DECLARE_FUNC(_SafeFetch32_continuation):
movl %esi, %eax # return default
ret

#elif defined(__aarch64__)
#ifdef __APPLE__
# Support for int SafeFetch32(int* address, int defaultval);
#
# x0 : address
# w1 : defaultval

# needed to align function start to 4 byte
.align 6
DECLARE_FUNC(SafeFetch32_impl):
DECLARE_FUNC(_SafeFetch32_fault):
ldr w0, [x0]
ret
DECLARE_FUNC(_SafeFetch32_continuation):
mov x0, x1
ret
#else
# Support for int SafeFetch32(int* address, int defaultval);
#
# x0 : address
# x1 : defaultval
DECLARE_FUNC(SafeFetch32_impl):
DECLARE_FUNC(_SafeFetch32_fault):
ldr w0, [x0]
ret
DECLARE_FUNC(_SafeFetch32_continuation):
mov x0, x1
ret
#endif // __APPLE__

#endif