- stack_protector.c doesn't really belong under sys/. Add a new directory
for misc support routines and put it there. - Add a libc constructor. Use this to initialize threading and the stack protector stuff. libpthread cannot be initialized safely using its own constructor because libc and libpthread are deeply intertwined. PR bin/37347
This commit is contained in:
parent
ac0bd149f2
commit
ec4d182d4a
|
@ -1,4 +1,4 @@
|
|||
# $NetBSD: Makefile,v 1.131 2007/05/30 01:13:15 tls Exp $
|
||||
# $NetBSD: Makefile,v 1.132 2007/11/13 15:21:19 ad Exp $
|
||||
# @(#)Makefile 8.2 (Berkeley) 2/3/94
|
||||
#
|
||||
# All library objects contain sccsid strings by default; they may be
|
||||
|
@ -65,6 +65,7 @@ COMPATDIR=${.CURDIR}/compat
|
|||
.include "${.CURDIR}/isc/Makefile.inc"
|
||||
.include "${.CURDIR}/locale/Makefile.inc"
|
||||
.include "${.CURDIR}/md/Makefile.inc"
|
||||
.include "${.CURDIR}/misc/Makefile.inc"
|
||||
.include "${.CURDIR}/net/Makefile.inc"
|
||||
.include "${.CURDIR}/nameser/Makefile.inc"
|
||||
.include "${.CURDIR}/nls/Makefile.inc"
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
# $NetBSD: Makefile.inc,v 1.1 2007/11/13 15:21:20 ad Exp $
|
||||
# @(#)Makefile.inc 8.3 (Berkeley) 10/24/94
|
||||
|
||||
.PATH: ${.CURDIR}/misc
|
||||
|
||||
# constructor
|
||||
SRCS+= initfini.c
|
||||
|
||||
# for -fstack-protector
|
||||
SRCS+= stack_protector.c
|
|
@ -0,0 +1,53 @@
|
|||
/* $NetBSD: initfini.c,v 1.1 2007/11/13 15:21:20 ad Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2007 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Andrew Doran.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the NetBSD
|
||||
* Foundation, Inc. and its contributors.
|
||||
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
static void __libc_init(void) __attribute__((__constructor__, __used__));
|
||||
|
||||
void __guard_setup(void);
|
||||
void __libc_thr_init(void);
|
||||
|
||||
static void
|
||||
__libc_init(void)
|
||||
{
|
||||
|
||||
/* For -fstack-protector */
|
||||
__guard_setup();
|
||||
|
||||
/* Threads */
|
||||
__libc_thr_init();
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: stack_protector.c,v 1.5 2007/09/27 17:53:05 christos Exp $ */
|
||||
/* $NetBSD: stack_protector.c,v 1.1 2007/11/13 15:21:20 ad Exp $ */
|
||||
/* $OpenBSD: stack_protector.c,v 1.10 2006/03/31 05:34:44 deraadt Exp $ */
|
||||
|
||||
/*
|
||||
|
@ -28,7 +28,7 @@
|
|||
*
|
||||
*/
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: stack_protector.c,v 1.5 2007/09/27 17:53:05 christos Exp $");
|
||||
__RCSID("$NetBSD: stack_protector.c,v 1.1 2007/11/13 15:21:20 ad Exp $");
|
||||
|
||||
#ifdef _LIBC
|
||||
#include "namespace.h"
|
||||
|
@ -49,14 +49,13 @@ extern int xprintf(const char *fmt, ...);
|
|||
#endif
|
||||
|
||||
long __stack_chk_guard[8] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||
static void __guard_setup(void) __attribute__((__constructor__, __used__));
|
||||
static void __fail(const char *);
|
||||
void __stack_chk_fail(void);
|
||||
void __chk_fail(void);
|
||||
void __stack_chk_fail_local(void);
|
||||
void __guard_setup(void);
|
||||
|
||||
/*LINTED used*/
|
||||
static void
|
||||
void
|
||||
__guard_setup(void)
|
||||
{
|
||||
int mib[2];
|
|
@ -1,4 +1,4 @@
|
|||
# $NetBSD: Makefile.inc,v 1.179 2007/11/12 23:11:58 ad Exp $
|
||||
# $NetBSD: Makefile.inc,v 1.180 2007/11/13 15:21:19 ad Exp $
|
||||
# @(#)Makefile.inc 8.3 (Berkeley) 10/24/94
|
||||
|
||||
# sys sources
|
||||
|
@ -22,9 +22,6 @@ DPSRCS+= ${_LSRC:MLintSys*.c}
|
|||
CLEANFILES+= ${_LSRC:MLintSys*.c}
|
||||
.endif
|
||||
|
||||
# for -fstack-protector
|
||||
SRCS+= stack_protector.c
|
||||
|
||||
# glue to offer userland wrappers for some syscalls
|
||||
SRCS+= sigtimedwait.c sigwait.c sigwaitinfo.c statvfs.c
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: thread-stub.c,v 1.14 2005/11/29 03:12:00 christos Exp $ */
|
||||
/* $NetBSD: thread-stub.c,v 1.15 2007/11/13 15:21:20 ad Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2003 The NetBSD Foundation, Inc.
|
||||
|
@ -38,7 +38,7 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
__RCSID("$NetBSD: thread-stub.c,v 1.14 2005/11/29 03:12:00 christos Exp $");
|
||||
__RCSID("$NetBSD: thread-stub.c,v 1.15 2007/11/13 15:21:20 ad Exp $");
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
/*
|
||||
|
@ -74,6 +74,20 @@ do { \
|
|||
#define CHECK_NOT_THREADED() /* nothing */
|
||||
#endif
|
||||
|
||||
/* libpthread init */
|
||||
|
||||
void __libc_thr_init(void);
|
||||
void __libc_thr_init_stub(void);
|
||||
|
||||
__weak_alias(__libc_thr_init,__libc_thr_init_stub)
|
||||
|
||||
void
|
||||
__libc_thr_init_stub(void)
|
||||
{
|
||||
|
||||
/* nothing, may be overridden by libpthread */
|
||||
}
|
||||
|
||||
/* mutexes */
|
||||
|
||||
int __libc_mutex_init_stub(mutex_t *, const mutexattr_t *);
|
||||
|
|
Loading…
Reference in New Issue