From owner-freebsd-hackers@FreeBSD.ORG Fri Jan 23 23:21:49 2009 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 8846C1065782 for ; Fri, 23 Jan 2009 23:21:49 +0000 (UTC) (envelope-from sam@freebsd.org) Received: from ebb.errno.com (ebb.errno.com [69.12.149.25]) by mx1.freebsd.org (Postfix) with ESMTP id 5A3F28FC0C for ; Fri, 23 Jan 2009 23:21:49 +0000 (UTC) (envelope-from sam@freebsd.org) Received: from trouble.errno.com (trouble.errno.com [10.0.0.248]) (authenticated bits=0) by ebb.errno.com (8.13.6/8.12.6) with ESMTP id n0NNLmhg094684 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 23 Jan 2009 15:21:48 -0800 (PST) (envelope-from sam@freebsd.org) Message-ID: <497A510C.3030106@freebsd.org> Date: Fri, 23 Jan 2009 15:21:48 -0800 From: Sam Leffler Organization: FreeBSD Project User-Agent: Thunderbird 2.0.0.18 (X11/20081209) MIME-Version: 1.0 To: John Baldwin References: <251d650c0901230755n769de861u1fe2e76dd28bbde8@mail.gmail.com> <200901231755.15548.jhb@freebsd.org> In-Reply-To: <200901231755.15548.jhb@freebsd.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-DCC-Misty-Metrics: ebb.errno.com; whitelist Cc: freebsd-hackers@freebsd.org, Mehul Chadha Subject: Re: doubts regarding System Initialization working (SYSINIT) 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, 23 Jan 2009 23:21:49 -0000 John Baldwin wrote: > 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. > > I think I have an ancient patch from someone to fix the code to not do this; let me dig for it. Sam