xref: /netbsd-src/lib/libc/compat/sys/compat_sigaltstack.c (revision 5688dfcf9c010bc7e0ddd147d4ed9d14a149eec9)
1*5688dfcfSmatt /*	$NetBSD: compat_sigaltstack.c,v 1.5 2012/03/20 17:06:00 matt Exp $	*/
25b84b398Schristos 
35b84b398Schristos /*-
45b84b398Schristos  * Copyright (c) 1997 The NetBSD Foundation, Inc.
55b84b398Schristos  * All rights reserved.
65b84b398Schristos  *
75b84b398Schristos  * This code is derived from software contributed to The NetBSD Foundation
85b84b398Schristos  * by Klaus Klein.
95b84b398Schristos  *
105b84b398Schristos  * Redistribution and use in source and binary forms, with or without
115b84b398Schristos  * modification, are permitted provided that the following conditions
125b84b398Schristos  * are met:
135b84b398Schristos  * 1. Redistributions of source code must retain the above copyright
145b84b398Schristos  *    notice, this list of conditions and the following disclaimer.
155b84b398Schristos  * 2. Redistributions in binary form must reproduce the above copyright
165b84b398Schristos  *    notice, this list of conditions and the following disclaimer in the
175b84b398Schristos  *    documentation and/or other materials provided with the distribution.
185b84b398Schristos  *
195b84b398Schristos  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
205b84b398Schristos  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
215b84b398Schristos  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
225b84b398Schristos  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
235b84b398Schristos  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
245b84b398Schristos  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
255b84b398Schristos  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
265b84b398Schristos  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
275b84b398Schristos  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
285b84b398Schristos  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
295b84b398Schristos  * POSSIBILITY OF SUCH DAMAGE.
305b84b398Schristos  */
315b84b398Schristos 
325b84b398Schristos #include <sys/cdefs.h>
335b84b398Schristos #if defined(LIBC_SCCS) && !defined(lint)
34*5688dfcfSmatt __RCSID("$NetBSD: compat_sigaltstack.c,v 1.5 2012/03/20 17:06:00 matt Exp $");
355b84b398Schristos #endif /* LIBC_SCCS and not lint */
365b84b398Schristos 
375b84b398Schristos #define __LIBC12_SOURCE__
385b84b398Schristos 
395b84b398Schristos #include <limits.h>
40461a86f9Schristos #include <sys/time.h>
41461a86f9Schristos #include <compat/sys/time.h>
425b84b398Schristos #include <signal.h>
435b84b398Schristos #include <compat/include/signal.h>
445b84b398Schristos #include <stddef.h>
455b84b398Schristos 
465b84b398Schristos int
sigaltstack(const struct sigaltstack13 * onss,struct sigaltstack13 * ooss)47*5688dfcfSmatt sigaltstack(const struct sigaltstack13 *onss, struct sigaltstack13 *ooss)
485b84b398Schristos {
495b84b398Schristos 	stack_t nss, oss;
505b84b398Schristos 	int error;
515b84b398Schristos 
525b84b398Schristos 	nss.ss_sp = onss->ss_sp;
535b84b398Schristos 	nss.ss_size = onss->ss_size;
545b84b398Schristos 	nss.ss_flags = onss->ss_flags;
555b84b398Schristos 
565b84b398Schristos 	error = __sigaltstack14(&nss, &oss);
575b84b398Schristos 
585b84b398Schristos 	if (error == 0 && ooss != NULL) {
595b84b398Schristos 		ooss->ss_sp = oss.ss_sp;
605b84b398Schristos 		if (oss.ss_size > INT_MAX)
615b84b398Schristos 			ooss->ss_size = INT_MAX;
625b84b398Schristos 		else
63c5e820caSchristos 			ooss->ss_size = (int)oss.ss_size;
645b84b398Schristos 		ooss->ss_flags = oss.ss_flags;
655b84b398Schristos 	}
665b84b398Schristos 
675b84b398Schristos 	return (error);
685b84b398Schristos }
69