From owner-freebsd-ia32@FreeBSD.ORG Fri Jan 23 22:57:56 2009 Return-Path: Delivered-To: freebsd-ia32@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C7606106564A; Fri, 23 Jan 2009 22:57:56 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id 994088FC17; Fri, 23 Jan 2009 22:57:56 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from server.baldwin.cx (pool-98-109-39-197.nwrknj.fios.verizon.net [98.109.39.197]) by cyrus.watson.org (Postfix) with ESMTPSA id 146CA46B09; Fri, 23 Jan 2009 17:57:56 -0500 (EST) Received: from localhost (john@localhost [127.0.0.1]) (authenticated bits=0) by server.baldwin.cx (8.14.3/8.14.3) with ESMTP id n0NMvoNw054798; Fri, 23 Jan 2009 17:57:50 -0500 (EST) (envelope-from jhb@freebsd.org) From: John Baldwin To: freebsd-hackers@freebsd.org Date: Fri, 23 Jan 2009 17:55:15 -0500 User-Agent: KMail/1.9.7 References: <251d650c0901230755n769de861u1fe2e76dd28bbde8@mail.gmail.com> In-Reply-To: <251d650c0901230755n769de861u1fe2e76dd28bbde8@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200901231755.15548.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH authentication, not delayed by milter-greylist-2.0.2 (server.baldwin.cx [127.0.0.1]); Fri, 23 Jan 2009 17:57:50 -0500 (EST) X-Virus-Scanned: ClamAV 0.94.2/8897/Fri Jan 23 07:59:36 2009 on server.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-4.4 required=4.2 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.1.3 X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on server.baldwin.cx Cc: Mehul Chadha , freebsd-ia32@freebsd.org Subject: Re: doubts regarding System Initialization working (SYSINIT) X-BeenThere: freebsd-ia32@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: FreeBSD on the IA-32 platform List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Jan 2009 22:57:57 -0000 On Friday 23 January 2009 10:55:32 am Mehul Chadha wrote: > Hello all, > I have been browsing through the FreeBSD kernel's > source code trying to understand its working . > > In the mi_startup() in /sys/kern/init_main.c all the SYSINIT objects > are sorted using bubble sort and then they are executed in order. > > My doubt is that we have declared the pointer to the struct sysinit as > const pointer to a const in the macro definition of SYSINIT ie when > the macro > > SYSINIT(kmem, SI_SUB_KMEM, SI_ORDER_FIRST, kmeminit, NULL) is > expanded completely we get the following > > static struct sysinit kmem_sys_init = { SI_SUB_KMEM, SI_ORDER_FIRST, > (sysinit_cfunc_t)(sysinit_ > nfunc_t)kmeminit, ((void *)(((void *)0))) }; static void const * const > __set_sysinit_set_sym_kmem_sys_init __attribute__((__section__("set_" > "sysinit_set"))) __attribute__((__used__)) = &kmem_sys_init; > > Here we see that the pointer is of type const and to a const but when we sort > and swap using > *sipp=*xipp; > > We are trying to change the address of const pointer to a new address > in which case it should segfault but it works fine. > > Why does it not segfault it seems I have not understood the concept > behind using const *const... I will be very thankful if you can help > me with it. I'm guessing the startup code doesn't map the SYSINIT pages read only because it is not smart enough to honor that request perhaps. That is, I wouldn't be surprised if all of .rodata in the kernel was mapped as R/W instead of R/O. -- John Baldwin