Back to index

glibc  2.9
sigstack.c
Go to the documentation of this file.
00001 /* Emulate sigstack function using sigaltstack.
00002    Copyright (C) 1998, 2000, 2005 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #include <signal.h>
00022 #include <stddef.h>
00023 #include <sys/syscall.h>
00024 
00025 
00026 #ifdef __NR_sigaltstack
00027 int
00028 sigstack (ss, oss)
00029      struct sigstack *ss;
00030      struct sigstack *oss;
00031 {
00032   stack_t sas;
00033   stack_t *sasp = NULL;
00034   stack_t osas;
00035   stack_t *osasp = oss == NULL ? NULL : &osas;
00036   int result;
00037 
00038   if (ss != NULL)
00039     {
00040       /* We have to convert the information.  */
00041       sas.ss_sp = ss->ss_sp;
00042       sas.ss_flags = ss->ss_onstack ? SS_ONSTACK : 0;
00043 
00044       /* For the size of the stack we have no value we can pass to the
00045         kernel.  This is why this function should not be used.  We simply
00046         assume that all the memory down to address zero (in case the stack
00047         grows down) is available.  */
00048       sas.ss_size = ss->ss_sp - NULL;
00049 
00050       sasp = &sas;
00051     }
00052 
00053   /* Call the kernel.  */
00054   result = __sigaltstack (sasp, osasp);
00055 
00056   /* Convert the result, if wanted and possible.  */
00057   if (result == 0 && oss != NULL)
00058     {
00059       oss->ss_sp = osas.ss_sp;
00060       oss->ss_onstack = (osas.ss_flags & SS_ONSTACK) != 0;
00061     }
00062 
00063   return result;
00064 }
00065 
00066 link_warning (sigstack, "the `sigstack' function is dangerous.  `sigaltstack' should be used instead.")
00067 #else
00068 # include <signal/sigstack.c>
00069 #endif