From owner-freebsd-hackers@FreeBSD.ORG Fri Jan 23 15:55:34 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 2CCC3106566B for ; Fri, 23 Jan 2009 15:55:34 +0000 (UTC) (envelope-from mehulc87@gmail.com) Received: from mail-gx0-f21.google.com (mail-gx0-f21.google.com [209.85.217.21]) by mx1.freebsd.org (Postfix) with ESMTP id C9B838FC19 for ; Fri, 23 Jan 2009 15:55:33 +0000 (UTC) (envelope-from mehulc87@gmail.com) Received: by gxk14 with SMTP id 14so5358342gxk.19 for ; Fri, 23 Jan 2009 07:55:33 -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-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 15:55:34 -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