From owner-freebsd-hackers@FreeBSD.ORG Mon Feb 8 11:38:11 2010 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 D197B1065672 for ; Mon, 8 Feb 2010 11:38:11 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.zoral.com.ua (mx0.zoral.com.ua [91.193.166.200]) by mx1.freebsd.org (Postfix) with ESMTP id 2C4E08FC0C for ; Mon, 8 Feb 2010 11:38:10 +0000 (UTC) Received: from deviant.kiev.zoral.com.ua (root@deviant.kiev.zoral.com.ua [10.1.1.148]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id o18Bc6qq095493 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 8 Feb 2010 13:38:06 +0200 (EET) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.3/8.14.3) with ESMTP id o18Bc63o071460; Mon, 8 Feb 2010 13:38:06 +0200 (EET) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.3/8.14.3/Submit) id o18Bc6nL071459; Mon, 8 Feb 2010 13:38:06 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Mon, 8 Feb 2010 13:38:06 +0200 From: Kostik Belousov To: Shrivats Message-ID: <20100208113806.GI9991@deviant.kiev.zoral.com.ua> References: <780520.92654.qm@web112015.mail.gq1.yahoo.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="zqjkMoGlbUJ91oFe" Content-Disposition: inline In-Reply-To: <780520.92654.qm@web112015.mail.gq1.yahoo.com> User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: clamav-milter 0.95.2 at skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-4.4 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua Cc: freebsd-hackers@freebsd.org Subject: Re: Invoking a signal handler 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: Mon, 08 Feb 2010 11:38:11 -0000 --zqjkMoGlbUJ91oFe Content-Type: text/plain; charset=koi8-r Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Feb 07, 2010 at 10:55:53PM -0800, Shrivats wrote: > Hi, >=20 >=20 > I am trying to understand how the kernel invokes the signal handler for a process, to deliver an asynchronous signal posted by another process. > I was looking at the sendsig() function which saves the current user > context. My question is, when and how does the transition from the > kernel mode to the user mode take place so that the signal handler is > invoked?=9A The sendsig() does two things. First, it copies out the currently saved user context to the user stack. Then, it modifies the current context to arrange the call to the signal handler when return to user mode is done. After that, when the thread does usual return from the kernel to user mode, be it return from the interrupt, or syscall, the modified context causes execution to jump to signal trampoline code implanted to the user mode stack by image activator. Trampoline is supplied required data by sendsig() to call signal handler with the right arguments. More, upon return from the signal handler, the trampoline on the stack gets the control again, and calls sigreturn(2) syscall that restores the old, pre-signal context saved by sendsig(). This is the model used on i386/amd64 FreeBSD, and I think that other architectures are quite similar. --zqjkMoGlbUJ91oFe Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (FreeBSD) iEYEARECAAYFAktv954ACgkQC3+MBN1Mb4hPigCgotuDK/8qFah4QQev0MMIfLHr E8YAn1zUwVqk1cFJAJExMa/QqlttBvsB =6chm -----END PGP SIGNATURE----- --zqjkMoGlbUJ91oFe--