From owner-freebsd-arch@FreeBSD.ORG Thu Jan 15 14:48:24 2009 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id DB86E1065680 for ; Thu, 15 Jan 2009 14:48:24 +0000 (UTC) (envelope-from mehulc87@gmail.com) Received: from yw-out-2324.google.com (yw-out-2324.google.com [74.125.46.30]) by mx1.freebsd.org (Postfix) with ESMTP id 98E448FC16 for ; Thu, 15 Jan 2009 14:48:24 +0000 (UTC) (envelope-from mehulc87@gmail.com) Received: by yw-out-2324.google.com with SMTP id 9so437890ywe.13 for ; Thu, 15 Jan 2009 06:48:24 -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; bh=6Pqi1MbGS35lMcc8rFw4obSrifI9PN4XSYH6YdV4U0A=; b=B9VdTKiXld3XbGqwARhmm/PTHgSE1A89UDiSnf2SGEgX8xjXSC6R+rOK+bNuqjVX7+ iu5FyA6Lv1FcT0wfc27GGALlFJA4JWupEFRYZS8kuzHTK+qy9eVkbxL8+OtkcTz1aeIX zxYuKUT8HUhV0tqaXKe+OGbTwpogRdnla1wzQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=KgV05w+p+95cFXxLb4xCVNOJwDfexAisz1rL8izYhVMWPJjByMirMb8LFUit35f8it T6Lkf7bUaJlbqT/24txVqXmK8S323LUht4vTUlbE5x+bzCdc6dv5yEYZ3ghB7BX6nOVA LvEZWjoUbQcE4EthcUa4lWqWFq0mN3hQIs9H0= MIME-Version: 1.0 Received: by 10.143.6.1 with SMTP id j1mr541880wfi.152.1232029138758; Thu, 15 Jan 2009 06:18:58 -0800 (PST) Date: Thu, 15 Jan 2009 19:48:58 +0530 Message-ID: <251d650c0901150618o7a460083i2caab3982dce133a@mail.gmail.com> From: Mehul Chadha To: freebsd-arch@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Subject: doubts regarding System Initialization working (SYSINIT) X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Jan 2009 14:48:25 -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