From owner-freebsd-hackers@FreeBSD.ORG Fri May 16 17:23:50 2008 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0D3681065672 for ; Fri, 16 May 2008 17:23:50 +0000 (UTC) (envelope-from deathjestr@gmail.com) Received: from fg-out-1718.google.com (fg-out-1718.google.com [72.14.220.155]) by mx1.freebsd.org (Postfix) with ESMTP id 8E6918FC15 for ; Fri, 16 May 2008 17:23:49 +0000 (UTC) (envelope-from deathjestr@gmail.com) Received: by fg-out-1718.google.com with SMTP id l26so972241fgb.35 for ; Fri, 16 May 2008 10:23:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=mRFSXovDfrP79rP03EGlxavSOlyxuNOm3xQiQRa6ejs=; b=b4rqsmpq6WAicDX/Z/3e2PQNHifHKT1l2gSQ4dLDurd6KUM5oJvN1BRCTbHkv35O8V8IfxkxFomQuiasTuOXyLX3N9p1hFwJvAt6mlsJz5hHbDBdWLbrUP133pmMfsu9PeYf6I1gkF5fMukqTU2cz/pUxR7YZZSvt4LDG9NuOZQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=nqL80tsZzTddCexnWmthW/IlkmJRx7hsPzgLp7OvJWqAUf5F21CmLneRKB88hwFLq3Ot+sNBblsJNoMShw/ms9CeYQkf5swcZQTY9K8GzMSPXQqPPvDcypn9tgpDGDILiiK+IqNAHSDf6og/NVSb8eUi9D2j3CcVNWRGQ386tdE= Received: by 10.78.199.8 with SMTP id w8mr983409huf.106.1210956958923; Fri, 16 May 2008 09:55:58 -0700 (PDT) Received: by 10.78.118.10 with HTTP; Fri, 16 May 2008 09:55:58 -0700 (PDT) Message-ID: <44b564930805160955r76d6861fo1949c7f4d5b71ca5@mail.gmail.com> Date: Fri, 16 May 2008 12:55:58 -0400 From: Mike To: "Jille Timmermans" In-Reply-To: <482DAB0E.70600@quis.cx> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <482DAB0E.70600@quis.cx> Cc: freebsd-hackers@freebsd.org Subject: Re: Trying (not) to crash with libpthread (6.3-RELEASE) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 May 2008 17:23:50 -0000 > void > sigcatcher(int sig) { > printf("[%p] signal %d\n", pthread_self(), sig); > printf("Test (probably) succeeded\n"); > fflush(NULL); > success=1; > exit(0); > } Take a look at the man page for sigaction(2). Here's an excerpt: "All functions not in the above lists are considered to be unsafe with respect to signals. That is to say, the behaviour of such functions when called from a signal handler is undefined. In general though, signal handlers should do little more than set a flag; most other actions are not safe." > void * > crashingthread(void *nada) { > /* This will likely crash */ > char *x=malloc(1); > > if(signal(SIGSEGV, sigcatcher)==SIG_ERR) > err(1, "signal(SIGSEGV, catchz0r)"); > > x[666]=0; > > /* HOPEFULLY NOT REACHED (aargh! die harder!) */ > > int i; > for(i=1; 999999>i; i++) > x[i]=0; > > /* NOT REACHED (either killed, or exit()'ed in sigcatcher) */ > abort(); > } Something like *(int*)0 = 0 is probably an easier, more reliable way to crash your program. Maybe not quite as much fun though. ;-)