Linux PARISC architecture development
 help / color / mirror / Atom feed
* Questions about hppa *context functions.
@ 2010-01-31 16:25 Carlos O'Donell
  2010-01-31 20:15 ` Carlos O'Donell
  0 siblings, 1 reply; 4+ messages in thread
From: Carlos O'Donell @ 2010-01-31 16:25 UTC (permalink / raw)
  To: Helge Deller, linux-parisc, libc-ports

[-- Attachment #1: Type: text/plain, Size: 1262 bytes --]

Helge,

On December 15th, 2009 an additional *context test was added to glibc,
see stdlib/tst-makecontext3.c.

This test fails on hppa with:
~~~
makecontext: does not know how to handle more than 8 arguments
~~~

I have a couple of questions and comments about hppa's *context implementation:

1. Why limit the number of input arguments to 8?

The ABI should allow an unlimited number of arguments to be placed on
the stack. It is up to the caller to make sure that
ucp->uc_stack.ss_sp points to enough space to hold all of the
additional arguments.

2. It doesn't appear that the current implementation transfers
ucp->uc_stack.ss_sp to the stack pointer when makecontext() is called.

Take a look at:
http://www.opengroup.org/onlinepubs/009695399/functions/makecontext.html

The caller can set an alternate stack by setting ucp->uc_stack.ss_sp,
and makecontext should likely do:
ucp->uc_mcontext.sc_gr[30] = ucp->uc_stack.ss_sp + <space required by args>;

3. POSIX says that all the arguments must be of type int, but in a
comment you write "XXX: This implementation only handles integer
arguments."

Is there any reason this comment should stay there?

To give you an example, I'm attaching a modified makecontext.diff for
you to comment on.

Cheers,
Carlos.

[-- Attachment #2: makecontext.diff --]
[-- Type: application/octet-stream, Size: 1604 bytes --]

diff --git a/sysdeps/unix/sysv/linux/hppa/makecontext.c b/sysdeps/unix/sysv/linux/hppa/makecontext.c
index 69a1813..356a094 100644
--- a/sysdeps/unix/sysv/linux/hppa/makecontext.c
+++ b/sysdeps/unix/sysv/linux/hppa/makecontext.c
@@ -25,7 +25,7 @@
 #include <sysdep.h>
 #include <ucontext.h>
 
-/* XXX: This implementation only handles integer arguments.  */
+/* POSIX only supports integer arguments.  */
 
 void
 __makecontext (ucontext_t *ucp, void (*func) (void), int argc, ...)
@@ -50,29 +50,26 @@ makecontext: does not know how to handle more than 8 arguments\n"));
   va_start (ap, argc);
   /* Handle arguments.  */
   for (i = 0; i < argc; ++i)
-    switch (i)
-      {
-      case 0:
-      case 1:
-      case 2:
-      case 3:
-      	ucp->uc_mcontext.sc_gr[26-i] = va_arg (ap, int);
-	break;
-      case 4:
-      case 5:
-      case 6:
-      case 7:
-	if (sizeof(unsigned long) == 4) {
-		/* 32bit: put arg7-arg4 on stack.  */
-		sp[7-i] = va_arg (ap, int);
-	} else {
-		/* 64bit: r19-r22 are arg7-arg4.  */
-		ucp->uc_mcontext.sc_gr[22+4-i] = va_arg (ap, int);
+    {
+      if (i < 4)
+	{
+	  ucp->uc_mcontext.sc_gr[26-i] = va_arg (ap, int);
+	  continue;
 	}
-	break;
-      }
-  va_end (ap);
 
+      if ((i < 8) && (sizeof(unsigned int) == 8))
+	{
+	  /* 64bit: r19-r22 are arg7-arg4.  */
+	  ucp->uc_mcontext.sc_gr[22+4-i] = va_arg (ap, int);
+	  continue;
+	} 
+
+      /* All other arguments go on the stack.  */
+      sp[i] = va_arg (ap, int);
+    }
+  va_end (ap); 
+  /* Adjust the stack pointer to last used argument.  */
+  ucp->uc_mcontext.sc_gr[30] = sp[argc - 1];
 }
 
 

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-01-31 23:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-31 16:25 Questions about hppa *context functions Carlos O'Donell
2010-01-31 20:15 ` Carlos O'Donell
2010-01-31 20:47   ` Helge Deller
2010-01-31 23:47     ` Carlos O'Donell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox