public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
From: Frank van der Linden <fllinden@amazon.com>
To: <systemtap@sourceware.org>
Subject: [PATCH] arm64: use sregs for syscall probe registers
Date: Fri, 12 Apr 2019 17:30:00 -0000	[thread overview]
Message-ID: <5cb0cb1f.ROdjA4uUKaH5hT/r%fllinden@amazon.com> (raw)

Since syscall wrappers are now active on arm64 (4.19+), arguments need to
be retrieved the right way, by checking if there is a saved set of system
call registers, and using them if there are.
---
 tapset/arm64/registers.stp | 50 ++++++++++++++++++++++++++++------------------
 1 file changed, 31 insertions(+), 19 deletions(-)

diff --git a/tapset/arm64/registers.stp b/tapset/arm64/registers.stp
index b2e56495d..b001b8efe 100644
--- a/tapset/arm64/registers.stp
+++ b/tapset/arm64/registers.stp
@@ -107,6 +107,36 @@ function u_register:long (name:string) {
 	return _stp_register(name, 0)
 }
 
+function _stp_arg_register:long (argnum:long) %{ /* pure */
+	long val;
+	struct pt_regs *regs;
+
+	if (STAP_ARG_argnum < 1 || STAP_ARG_argnum > 8) {
+		snprintf(CONTEXT->error_buffer, sizeof(CONTEXT->error_buffer),
+				"Cannot access arg(%lld)",
+				(long long)STAP_ARG_argnum);
+		CONTEXT->last_error = CONTEXT->error_buffer;
+		return;
+	}
+
+	/* syscall-in-pt_regs mode, 4.19+ */
+	if (CONTEXT->sregs) {
+		regs = CONTEXT->sregs;
+	} else {
+		regs = (CONTEXT->user_mode_p ? CONTEXT->uregs : CONTEXT->kregs);
+	}
+
+	if (!regs) {
+		CONTEXT->last_error = "No registers available in this context";
+		return;
+	}
+
+	memcpy(&val, ((char *)regs) + ((STAP_ARG_argnum - 1) * sizeof (long)),
+	    sizeof (long));
+
+	STAP_RETVALUE = val;
+%}
+
 /*
  * Return the value of function arg #argnum (1=first arg).
  * If truncate=1, mask off the top 32 bits.
@@ -115,25 +145,7 @@ function u_register:long (name:string) {
  * TODO: 32-bit arm code has different calling conventions than arm64
  */
 function _stp_arg:long (argnum:long, sign_extend:long, truncate:long) {
-	val = 0
-  assert(!(argnum < 1 || argnum > 8), sprintf("Cannot access arg(%d)", argnum))
-
-	if (argnum == 1)
-		val = u_register("x0")
-	else if (argnum == 2)
-		val = u_register("x1")
-	else if (argnum == 3)
-		val = u_register("x2")
-	else if (argnum == 4)
-		val = u_register("x3")
-	else if (argnum == 5)
-		val = u_register("x4")
-	else if (argnum == 6)
-		val = u_register("x5")
-	else if (argnum == 7)
-		val = u_register("x6")
-	else if (argnum == 8)
-		val = u_register("x7")
+	val = _stp_arg_register(argnum)
 
 	if (truncate) {
 		if (sign_extend)
-- 
2.16.5

             reply	other threads:[~2019-04-12 17:30 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-12 17:30 Frank van der Linden [this message]
2019-04-15 21:32 ` William Cohen
2019-04-15 21:40   ` van der Linden, Frank
2019-04-16 15:33 ` Frank Ch. Eigler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5cb0cb1f.ROdjA4uUKaH5hT/r%fllinden@amazon.com \
    --to=fllinden@amazon.com \
    --cc=systemtap@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).