Fix stack initialization code
[kopensolaris-gnu/glibc.git] / sysdeps / unix / sysv / solaris2 / kopensolaris-gnu / init-first.c
index d6b8773..0e585b9 100644 (file)
@@ -80,11 +80,17 @@ _init (int argc, char **argv, char **envp)
       if (getrlimit (RLIMIT_STACK, &rlim) == 0 &&
           rlim.rlim_cur != RLIM_INFINITY && getcontext (&ctx) == 0)
         {
-          _dl_stack.ss_sp = ctx.uc_stack.ss_sp;
+          _dl_stack.ss_sp = ctx.uc_stack.ss_sp +
+              ctx.uc_stack.ss_size - rlim.rlim_cur;
           _dl_stack.ss_size = rlim.rlim_cur;
-          _dl_stack.ss_flags = 0;
-          setustack (&_dl_stack);
         }
+      else
+        {
+          _dl_stack.ss_sp = ctx.uc_stack.ss_sp;
+          _dl_stack.ss_size = 0;
+        }
+      _dl_stack.ss_flags = 0;
+      setustack (&_dl_stack);
     }
 
   /* Save the command-line arguments.  */