public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Leif Lindholm <leif.lindholm@arm.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] Save/restore global data pointer on API boundary
Date: Tue, 07 Aug 2012 18:02:48 +0100	[thread overview]
Message-ID: <50214A38.3000305@arm.com> (raw)

Most architectures keep the global data pointer (gd) in a register.
When using the external app API, because they are calling us rather
than we calling them, this register can be corrupted.

The attached (trivial) patch saves the gd pointer at api_init(),
and restores it on every entry to syscall(). This may want to be
put behind an ifdef for those architectures that don't use a
dedicated register.

Signed-off-by: Leif Lindholm <leif.lindholm@arm.com>
---
diff --git a/api/api.c b/api/api.c
index a3bf60a..b911270 100644
--- a/api/api.c
+++ b/api/api.c
@@ -33,6 +33,8 @@

  #include "api_private.h"

+DECLARE_GLOBAL_DATA_PTR;
+
  #define DEBUG
  #undef DEBUG

@@ -600,6 +602,13 @@ static int API_display_clear(va_list ap)
  static cfp_t calls_table[API_MAXCALL] = { NULL, };

  /*
+ * The global data pointer is held in a register on most if not all
+ * architectures. Its value is not retained across the API boundary,
+ * so must be manually restored.
+ */
+static void volatile *gd_backup;
+
+/*
   * The main syscall entry point - this is not reentrant, only one call is
   * serviced until finished.
   *
@@ -620,6 +629,8 @@ int syscall(int call, int *retval, ...)
         va_list ap;
         int rv;

+       gd = gd_backup;
+
         if (call < 0 || call >= calls_no) {
                 debugf("invalid call #%d\n", call);
                 return 0;
@@ -686,6 +697,7 @@ void api_init(void)
         sig->checksum = crc32(0, (unsigned char *)sig,
                               sizeof(struct api_signature));
         debugf("syscall entry: 0x%08x\n", sig->syscall);
+       gd_backup = gd;
  }

  void platform_set_mr(struct sys_info *si, unsigned long start, unsigned long size,

             reply	other threads:[~2012-08-07 17:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-07 17:02 Leif Lindholm [this message]
2012-08-07 18:30 ` [U-Boot] [PATCH] Save/restore global data pointer on API boundary Wolfgang Denk
2012-08-08  9:44   ` Leif Lindholm

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=50214A38.3000305@arm.com \
    --to=leif.lindholm@arm.com \
    --cc=u-boot@lists.denx.de \
    /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