From owner-freebsd-ia32@FreeBSD.ORG Fri Jan 23 16:28:44 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 A1D13106571E for ; Fri, 23 Jan 2009 16:28:44 +0000 (UTC) (envelope-from mehulc87@gmail.com) Received: from yw-out-2324.google.com (yw-out-2324.google.com [74.125.46.29]) by mx1.freebsd.org (Postfix) with ESMTP id 586868FC13 for ; Fri, 23 Jan 2009 16:28:44 +0000 (UTC) (envelope-from mehulc87@gmail.com) Received: by yw-out-2324.google.com with SMTP id 9so1985563ywe.13 for ; Fri, 23 Jan 2009 08:28:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type:content-transfer-encoding; bh=jQ6IvJR2s2mqLhCFx5fxpuLkhdd+/Dg57ujR4YFJbPg=; b=XEg9WPDssKVzTz6/yTFLRR6i63myATkbtUbDzdMAqFiwql6OZKllPspO8maC29KsWH tRSc1kLlszWxuki2eMfj6eMLstxXidJJ/sVMFk4oQz9nPRTfCj1gsDaFbBLz/27dobxK ZmiHab/5Mxs3CoJfaE1QGob3/UolT4rjBiKY4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type :content-transfer-encoding; b=GKJs2d3czMCMUBUFF3e61sBmgx7M87cPkxRviOgTSZbB4A7gmTSfVp54T3/RDHmv56 0Jpe4HRaEsC74F4E9aAWWNkWSUSQFV/zY6VUZauhb+lxTsbDxgM+mIX9hjkZFYn0vkfW Lra5n0XjCCotxrncImOHcwW5zuILy8YG0mlB8= MIME-Version: 1.0 Received: by 10.142.162.9 with SMTP id k9mr1546350wfe.159.1232726132884; Fri, 23 Jan 2009 07:55:32 -0800 (PST) Date: Fri, 23 Jan 2009 21:25:32 +0530 Message-ID: <251d650c0901230755n769de861u1fe2e76dd28bbde8@mail.gmail.com> From: Mehul Chadha To: freebsd-hackers@freebsd.org, freebsd-ia32@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: Subject: 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 16:28:46 -0000 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. Regards, Mehul 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