Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 23 Jan 2009 17:55:15 -0500
From:      John Baldwin <jhb@freebsd.org>
To:        freebsd-hackers@freebsd.org
Cc:        Mehul Chadha <mehulc87@gmail.com>, freebsd-ia32@freebsd.org
Subject:   Re: doubts regarding System Initialization working (SYSINIT)
Message-ID:  <200901231755.15548.jhb@freebsd.org>
In-Reply-To: <251d650c0901230755n769de861u1fe2e76dd28bbde8@mail.gmail.com>
References:  <251d650c0901230755n769de861u1fe2e76dd28bbde8@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200901231755.15548.jhb>