OSSP CVS Repository

ossp - Check-in [4888]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 4888
Date: 2004-Dec-03 17:21:08 (local)
2004-Dec-03 16:21:08 (UTC)
User:rse
Branch:
Comment: The pth_uctx_save() and pth_uctx_restore() API functions unfortunately were broken by design because they are C functions. This leads to one more deadly nesting on the run-time stack which effectively caused the pth_mctx_restore() in pth_uctx_restore() to return to the end of pth_uctx_save() but then the control flow unfortunately returns to the pth_uctx_restore() caller instead of the pth_uctx_save() caller because the call to pth_uctx_restore() had already overwritten the run-time stack position where the original return address for the pth_uctx_save() call was stored.

The only workaround would be to #define pth_uctx_save() and pth_uctx_restore() as C macros, but this then would require that lots of the GNU Pth internals from pth_mctx.c would have to be exported in the GNU Pth API (which in turn is not acceptable). So, the only consequence is to remove the two functions again from the GNU Pth API.

Prompted by hints from: Stefan Brantschen <sbr@acm.org>

Tickets:
Inspections:
Files:
ossp-pkg/pth/ChangeLog      1.629 -> 1.630     19 inserted, 0 deleted
ossp-pkg/pth/THANKS      1.97 -> 1.98     1 inserted, 0 deleted
ossp-pkg/pth/pth.h.in      1.143 -> 1.144     0 inserted, 2 deleted
ossp-pkg/pth/pth.pod      1.164 -> 1.165     12 inserted, 31 deleted
ossp-pkg/pth/pth_uctx.c      1.3 -> 1.4     3 inserted, 36 deleted

ossp-pkg/pth/ChangeLog 1.629 -> 1.630

--- ChangeLog    2004/12/03 16:17:54     1.629
+++ ChangeLog    2004/12/03 16:21:08     1.630
@@ -21,6 +21,25 @@
                   
   Changes between 2.0.2 and 2.0.3 (12-Sep-2004 to xx-xxx-2004)
 
+   *) The pth_uctx_save() and pth_uctx_restore() API functions
+      unfortunately were broken by design because they are C
+      _functions_. This leads to one more deadly nesting on the
+      run-time stack which effectively caused the pth_mctx_restore()
+      in pth_uctx_restore() to return to the end of pth_uctx_save()
+      but then the control flow unfortunately returns to the
+      pth_uctx_restore() caller instead of the pth_uctx_save() caller
+      because the call to pth_uctx_restore() had already overwritten the
+      run-time stack position where the original return address for the
+      pth_uctx_save() call was stored.
+      
+      The only workaround would be to #define pth_uctx_save() and
+      pth_uctx_restore() as C _macros_, but this then would require that
+      lots of the GNU Pth internals from pth_mctx.c would have to be
+      exported in the GNU Pth API (which in turn is not acceptable). So,
+      the only consequence is to remove the two functions again from the
+      GNU Pth API.
+      [Ralf S. Engelschall, Stefan Brantschen <sbr@acm.org>]
+
    *) Enhance internal pth_mctx_save() if getcontext(3) is used for the
       machine context saving by better emulating the setjmp(3) style
       return code semantics.


ossp-pkg/pth/THANKS 1.97 -> 1.98

--- THANKS       2004/10/08 16:17:02     1.97
+++ THANKS       2004/12/03 16:21:08     1.98
@@ -22,6 +22,7 @@
     o  Felix Berger                <bflat1@gmx.net>
     o  Paolo Bonzini               <bonzini@pc-amo3.elet.polimi.it>
     o  Raphael Bossek              <raphael.bossek@solutions4linux.de>
+    o  Stefan Brantschen           <sbr@acm.org>
     o  Edwin Brown                 <Edwin.Brown@sdrc.com>
     o  Dan Buckler                 <buckler@sco.com>
     o  Mark Burton                 <markb@ordern.com>


ossp-pkg/pth/pth.h.in 1.143 -> 1.144

--- pth.h.in     2004/10/08 16:17:02     1.143
+++ pth.h.in     2004/12/03 16:21:08     1.144
@@ -505,8 +505,6 @@
     /* user-space context functions */
 extern int            pth_uctx_create(pth_uctx_t *);
 extern int            pth_uctx_make(pth_uctx_t, char *, size_t, const sigset_t *, void (*)(void *), void *, pth_uctx_t);
-extern int            pth_uctx_save(pth_uctx_t);
-extern int            pth_uctx_restore(pth_uctx_t);
 extern int            pth_uctx_switch(pth_uctx_t, pth_uctx_t);
 extern int            pth_uctx_destroy(pth_uctx_t);
 


ossp-pkg/pth/pth.pod 1.164 -> 1.165

--- pth.pod      2004/10/08 16:17:02     1.164
+++ pth.pod      2004/12/03 16:21:08     1.165
@@ -142,8 +142,6 @@
 
 pth_uctx_create,
 pth_uctx_make,
-pth_uctx_save,
-pth_uctx_restore,
 pth_uctx_switch,
 pth_uctx_destroy.
 
@@ -1520,8 +1518,8 @@
 
 This function creates a user-space context and stores it into I<uctx>.
 There is still no underlying user-space context configured. You still
-have to do this with pth_uctx_make(3) or pth_uctx_set(3). On success,
-this function returns C<TRUE>, else C<FALSE>.
+have to do this with pth_uctx_make(3). On success, this function returns
+C<TRUE>, else C<FALSE>.
 
 =item int B<pth_uctx_make>(pth_uctx_t I<uctx>, char *I<sk_addr>, size_t I<sk_size>, const sigset_t *I<sigmask>, void (*I<start_func>)(void *), void *I<start_arg>, pth_uctx_t I<uctx_after>);
 
@@ -1538,41 +1536,24 @@
 after POSIX makecontext(3). On success, this function returns C<TRUE>,
 else C<FALSE>.
 
-=item int B<pth_uctx_save>(pth_uctx_t I<uctx>);
-
-This function saves the current user-space context in I<uctx> for later
-restoring by either pth_uctx_restore(3) or pth_uctx_switch(3). This
-function is somewhat modeled after POSIX getcontext(3). If I<uctx> is
-C<NULL>, C<FALSE> is returned instead of C<TRUE>. This is the only error
-possible.
-
-=item int B<pth_uctx_restore>(pth_uctx_t I<uctx>);
-
-This function restores the current user-space context from I<uctx>,
-which previously had to be set with either pth_uctx_make(3) or
-pth_uctx_save(3). This function is somewhat modeled after POSIX
-setcontext(3). If I<uctx> is C<NULL> or I<uctx> contains no valid
-user-space context, C<FALSE> is returned instead of C<TRUE>. These are
-the only errors possible.
-
 =item int B<pth_uctx_switch>(pth_uctx_t I<uctx_from>, pth_uctx_t I<uctx_to>);
 
 This function saves the current user-space context in I<uctx_from> for
-later restoring by either pth_uctx_restore(3) or pth_uctx_switch(3) and
-restores the new user-space context from I<uctx>, which previously
-had to be set with either pth_uctx_make(3) or pth_uctx_save(3). This
-function is somewhat modeled after POSIX swapcontext(3). If I<uctx_from>
-or I<uctx_to> are C<NULL> or if I<uctx_to> contains no valid user-space
-context, C<FALSE> is returned instead of C<TRUE>. These are the only
-errors possible.
+later restoring by another call to pth_uctx_switch(3) and restores
+the new user-space context from I<uctx_to>, which previously had to
+be set with either a previous call to pth_uctx_switch(3) or initially
+by pth_uctx_make(3). This function is somewhat modeled after POSIX
+swapcontext(3). If I<uctx_from> or I<uctx_to> are C<NULL> or if
+I<uctx_to> contains no valid user-space context, C<FALSE> is returned
+instead of C<TRUE>. These are the only errors possible.
 
 =item int B<pth_uctx_destroy>(pth_uctx_t I<uctx>);
 
 This function destroys the user-space context in I<uctx>. The run-time
 stack associated with the user-space context is deallocated only if it
-was given by the application (see I<sk_addr> of pth_uctx_create(3)).
-If I<uctx> is C<NULL>, C<FALSE> is returned instead of C<TRUE>. This
-is the only error possible.
+was not given by the application (see I<sk_addr> of pth_uctx_create(3)).
+If I<uctx> is C<NULL>, C<FALSE> is returned instead of C<TRUE>. This is
+the only error possible.
 
 =back
 


ossp-pkg/pth/pth_uctx.c 1.3 -> 1.4

--- pth_uctx.c   2004/07/13 10:50:49     1.3
+++ pth_uctx.c   2004/12/03 16:21:08     1.4
@@ -97,7 +97,7 @@
 
     /* switch to successor user-space context */
     if (ctx.uctx_after != NULL)
-        pth_uctx_restore(ctx.uctx_after);
+        pth_mctx_restore(&(ctx.uctx_after->uc_mctx));
 
     /* terminate process (the only reasonable thing to do here) */
     exit(0);
@@ -150,7 +150,7 @@
         sigprocmask(SIG_SETMASK, sigmask, &ss);
 
     /* perform the trampoline step */
-    pth_mctx_switch(&mctx_parent, &uctx->uc_mctx);
+    pth_mctx_switch(&mctx_parent, &(uctx->uc_mctx));
 
     /* optionally restore original signal mask */
     if (sigmask != NULL)
@@ -162,39 +162,6 @@
     return TRUE;
 }
 
-/* save current user-space context */
-int
-pth_uctx_save(
-    pth_uctx_t uctx)
-{
-    /* argument sanity checking */
-    if (uctx == NULL)
-        return pth_error(FALSE, EINVAL);
-
-    /* save underlying machine context */
-    pth_mctx_save(&uctx->uc_mctx);
-    uctx->uc_mctx_set = TRUE;
-
-    return TRUE;
-}
-
-/* restore current user-space context */
-int
-pth_uctx_restore(
-    pth_uctx_t uctx)
-{
-    /* argument sanity checking */
-    if (uctx == NULL)
-        return pth_error(FALSE, EINVAL);
-    if (!(uctx->uc_mctx_set))
-        return pth_error(FALSE, EPERM);
-
-    /* restore underlying machine context */
-    pth_mctx_restore(&uctx->uc_mctx);
-
-    return TRUE;
-}
-
 /* switch from current to other user-space context */
 int
 pth_uctx_switch(
@@ -209,7 +176,7 @@
 
     /* switch underlying machine context */
     uctx_from->uc_mctx_set = TRUE;
-    pth_mctx_switch(&uctx_from->uc_mctx, &uctx_to->uc_mctx);
+    pth_mctx_switch(&(uctx_from->uc_mctx), &(uctx_to->uc_mctx));
 
     return TRUE;
 }

CVSTrac 2.0.1