9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: dbailey27@ameritech.net
To: prem_mallappa@hotpop.com, 9fans@cse.psu.edu
Subject: Re: [9fans] constant string
Date: Mon,  8 Mar 2004 09:13:36 -0500	[thread overview]
Message-ID: <15d2f5fb6672706b232a46affc5b710e@yourdomain.dom> (raw)
In-Reply-To: <pan.2004.03.07.05.32.00.621137@hotpop.com>

[-- Attachment #1: Type: text/plain, Size: 1475 bytes --]

You answered your own question. Linux uses an ELF 
file format. When the ELF is loaded, the variables loaded
into the DATA segment are marked as read-only pages.
This, of course, will cause a write to such pages to 
manifest a SIGSEGV. 

Plan 9, however, makes no effort to do this. Objects
marked into the DATA segment of the Plan 9 file format
are loaded into pages that are actually RWX. So, it's really
a two-pronged issue. 
	1) The kernel loader doesn't handle the management
	    of page protection in the DATA, Stack, BSS, or even
	    the TEXT. 
	2) The current binary format doesn't allow for specification
	    of whether or not the DATA segment should *be* ~W.

There is one main reason why you would want a W DATA. 
Variables that end up initialized to a value other than nil must 
be put in the DATA segment. Otherwise, they end up in the 
BSS, which is initialized to nil.

Thus, global pointers to objects in the DATA (not const?) must
be R|W, while the object itself (raw data) must be ~W. This is
the ideal solution. 

This is being implemented in my work on the SPARC/SPARCv9
and AMD64 ports. I've discussed this with other members of
the AMD64 port, and there've been no nay-sayers. There will
be other improvements, as well. However, they are to be seen
later. 

FYI, I'm writing the toolchain(s) from scratch, so the new binary
format for these archs will look only slightly different from the
current. 

Don (north_)

[-- Attachment #2: Type: message/rfc822, Size: 3139 bytes --]

From: Prem Mallappa <prem_mallappa@hotpop.com>
To: 9fans@cse.psu.edu
Subject: [9fans] constant string
Date: Mon, 8 Mar 2004 10:15:07 GMT
Message-ID: <pan.2004.03.07.05.32.00.621137@hotpop.com>

hi,

this is my program
------------------------------------------
#include <stdio.h>

int main(void)
{
	char *s = "Hello";
	
	s[2] = 'z';
	
	printf ("%s\n", s);
	
	return 0;
}

------------------------------------------

my question is when i compile this in Linux (gcc) i get a segmentation 
fault at the second statement of main(),
As far as my knowledge i think this is because in 2nd chapter of K&R book
it is being mentioned that
' any thing enclosed between " and " is a string constant' so here i am
changing a constant, and i get a segmentation fault ( and i also noticed
that gcc stores the string Hello in read-only datasegment)

but when i compile the same thing in plan9 C compiler ( both native "8c"
and "pcc" i get a output of "Hezlo")
why this is happenning..

sorry if i am posting to wrong group,
thanks in advance
prem

  parent reply	other threads:[~2004-03-08 14:13 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-03-08 10:15 Prem Mallappa
2004-03-08 10:27 ` lucio
2004-03-08 10:53 ` [9fans] " Richard Bos
2004-03-08 14:13 ` dbailey27 [this message]
2004-03-08 15:22   ` [9fans] " C H Forsyth
2004-03-09  3:41     ` Russ Cox
2004-03-09  9:17       ` Charles Forsyth
2004-03-08 22:40 ` William Josephson
2004-03-10  9:47 ` [9fans] " Peter Pichler
2004-03-12  8:56   ` Bruce Ellis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=15d2f5fb6672706b232a46affc5b710e@yourdomain.dom \
    --to=dbailey27@ameritech.net \
    --cc=9fans@cse.psu.edu \
    --cc=prem_mallappa@hotpop.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).