From owner-freebsd-hackers@FreeBSD.ORG Wed Jun 22 21:52:59 2005 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E92BD16A41C for ; Wed, 22 Jun 2005 21:52:59 +0000 (GMT) (envelope-from dan@dan.emsphone.com) Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by mx1.FreeBSD.org (Postfix) with ESMTP id B62D143D55 for ; Wed, 22 Jun 2005 21:52:59 +0000 (GMT) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.13.1/8.13.3) id j5MLqwko049698; Wed, 22 Jun 2005 16:52:58 -0500 (CDT) (envelope-from dan) Date: Wed, 22 Jun 2005 16:52:58 -0500 From: Dan Nelson To: Mauser Message-ID: <20050622215258.GE49171@dan.emsphone.com> References: <20050622192127.05bff1b8.mauser@poczta.fm> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050622192127.05bff1b8.mauser@poczta.fm> X-OS: FreeBSD 5.4-STABLE X-message-flag: Outlook Error User-Agent: Mutt/1.5.9i Cc: freebsd-hackers@freebsd.org Subject: Re: kld problem 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: Wed, 22 Jun 2005 21:53:00 -0000 In the last episode (Jun 22), Mauser said: > Unloading syscall kernel module can cause a system crash. It occurs when we > unload the module while a process is executing our syscall. Example: > > $ cat kldtest.c ... > static int test_syscall(struct thread *td, void *arg) { > struct timeval tv; > tv.tv_sec = 15; > tv.tv_usec = 0; > tsleep(&test_nw,PWAIT,"test",tvtohz(&tv)); > return 0; > } ... > static int test_load(struct module *mod, int cmd, void *arg) { > if(cmd != MOD_LOAD && cmd != MOD_UNLOAD) > return EOPNOTSUPP; > return 0; > } In test_load, you can return a nonzero value on MOD_UNLOAD to abort an unload request. See the module(9) manpage for more details. You may need to increment a counter or hold a mutex while in the syscall to make it easy for test_load to determine whether it's safe to unload or not. -- Dan Nelson dnelson@allantgroup.com