Re: [9fans] Undefined Behaviour in C

2015-11-26 Thread Brantley Coile
Hi Bakul. Long time since our Bay Area plan 9 hacking sessions. I've avoided the valley all together for a year and a half now. Not quite long enough yet. I thought the same thing, using ~0 for nil, but realized two things. First, that's a valid address on the PDP11 where the convention

Re: [9fans] Undefined Behaviour in C

2015-11-26 Thread tlaronde
On Thu, Nov 26, 2015 at 06:22:45AM -0500, Brantley Coile wrote: > > I thought the same thing, using ~0 for nil, but realized two things. First, > that's a valid address on the PDP11 where the convention developed. It's the > unibus space. Second, ~0 + member offest is still in page zero. >

Re: [9fans] Undefined Behaviour in C

2015-11-26 Thread Bruce Ellis
Simple data share in Inferno. Define a struct with a single byte in it. Now with b == nil throw in a b.data = 42. Visible channel to every process. This requires 0xF zillion to be writeable. On 26 November 2015 at 22:22, Brantley Coile wrote: > Hi Bakul. Long time since

Re: [9fans] Undefined Behaviour in C

2015-11-26 Thread Charles Forsyth
On 26 November 2015 at 11:37, wrote: > Plus, in C, 0 is used as a truth value for false... > That doesn't say how a 0 value for a pointer is represented; it's just how it's written in the program text. The compiler knows the types and can convert (same as double = 0). In

Re: [9fans] Undefined Behaviour in C

2015-11-26 Thread erik quanstrom
On Thu Nov 26 03:25:34 PST 2015, brantleyco...@me.com wrote: > Hi Bakul. Long time since our Bay Area plan 9 hacking sessions. I've avoided > the valley all together for a year and a half now. Not quite long enough yet. > > I thought the same thing, using ~0 for nil, but realized two things.

Re: [9fans] Undefined Behaviour in C

2015-11-26 Thread Brantley Coile
Thanks, Erik. And of those, how many don’t end with arrays or would not use earlier members to access those arrays? I’m still kind of dubious that there are any structures where one would not catch a null pointer. Of course, this is not the original issue, which was someone fooling the kernel

Re: [9fans] Undefined Behaviour in C

2015-11-26 Thread Alexandru Gheorghe
On Nov 26, 2015 6:35 PM, "erik quanstrom" wrote: > > By the way, are there any structs more than 4K in Linux? Are there any in plan 9? > > since that 4k is really pagesz, on amd64 that would be 2mb. there's no compelling reason on > 64-bit machines to start at the bottom

Re: [9fans] Undefined Behaviour in C

2015-11-26 Thread Charles Forsyth
On 26 November 2015 at 16:42, Brantley Coile wrote: > I’m still kind of dubious that there are any structures where one would > not catch a null pointer. > I don't think there are any. In practice, ome other value lower down will be accessed first. Unless the compiler

Re: [9fans] Undefined Behaviour in C

2015-11-26 Thread erik quanstrom
aren't there any Biobufs at the start of structures?  I only have a phone here so I can't verify. - erik On Nov 26, 2015 8:50 AM, Charles Forsyth wrote:On 26 November 2015 at 16:42, Brantley Coile wrote:I’m still kind of dubious that there are

Re: [9fans] Undefined Behaviour in C

2015-11-26 Thread Bakul Shah
Good points! Though 0 was a valid address on pdp11, right? May be if they had used ~0 as nil and not put any peripheral device at that address, *nil would've had more immediate failures! Many ~0+offset errors would be caught on machines that trap 2 or 4 byte fetch/store to odd addresses. I

Re: [9fans] Undefined Behaviour in C

2015-11-26 Thread Brantley Coile
Hee hee. My comment has more to do with personal experience than a judgment on the area in general. > On Nov 26, 2015, at 12:48 PM, Bakul Shah wrote: > > No comment on the Bay Area :-) Especially since we are trying to hire people!

Re: [9fans] Undefined Behaviour in C

2015-11-26 Thread Steve Simon
I don't know about the PDP but the VAX allowed access to address zero. Even more insidious, it allowed you to dereference a null pointer and guaranteed it would contain a zero, which resulted in many tiresome portability issues - I used Interdatas at the time, which faulted on a read at

Re: [9fans] Undefined Behaviour in C

2015-11-26 Thread Charles Forsyth
On 26 November 2015 at 23:14, Steve Simon wrote: > I don't know about the PDP but the VAX allowed access to address zero. Not in my port.

Re: [9fans] Undefined Behaviour in C

2015-11-26 Thread Brantley Coile
I did a port just like that (DTS Generic Unix) just to see what it would be like. It was awful. I’ll never do that again. > On Nov 26, 2015, at 6:14 PM, Steve Simon wrote: > > > I don't know about the PDP but the VAX allowed access to address zero. > > Even more

Re: [9fans] Undefined Behaviour in C

2015-11-25 Thread plannine
On Wed, Nov 25, 2015 at 09:25:55AM -0500, Brantley Coile wrote: > unindented consequences Is that a class of Python bugs or an awesome name for a Nerdcore band?

Re: [9fans] Undefined Behaviour in C

2015-11-25 Thread Ryan Gonzalez
Neither! It's what happens when you run sed 's/^\s*//' on your whole code base, yielding results like (from cmd/yacc.c): void setup(int argc, char *argv[]) { long c, t; int i, j, fd, lev, ty, ytab, *p; int vflag, dflag, stem; char actnm[8], *stemc, *s, dirbuf[128]; Biobuf *fout; ytab = 0; vflag

Re: [9fans] Undefined Behaviour in C

2015-11-25 Thread Prof Brucee
gcc is indeed a very sad tome. The mmap of 0 is disgusting. I like kenc. It just works. My behaviour this afternoon will be undefined but not as stupid as that of some programmers. On 26/11/2015 5:43 AM, "Brantley Coile" wrote: > Align it to column 7 and it looks like all

Re: [9fans] Undefined Behaviour in C

2015-11-25 Thread Brantley Coile
Bruce's law: undefined != stupid Sent from my iPad > On Nov 25, 2015, at 9:04 PM, Prof Brucee wrote: > > gcc is indeed a very sad tome. The mmap of 0 is disgusting. I like kenc. It > just works. My behaviour this afternoon will be undefined but not as stupid > as that

Re: [9fans] Undefined Behaviour in C

2015-11-25 Thread Prof Brucee
I am still fascinated by the VAX architecture manual which designates as "unpredictable" many things with consequences including machine crash. Pissed that I can't get my vaxen to crash or burst into flames. On 26/11/2015 1:46 PM, "Brantley Coile" wrote: > Bruce's law:

Re: [9fans] Undefined Behaviour in C

2015-11-25 Thread Ryan Gonzalez
I remember reading Jack Crenshaw's Let's Build a Compiler. In part 16, he mentioned that compiling an empty C source file on the VAX took 60 seconds and generated a 50K object file. Link (just search for the text "vax"): http://compilers.iecc.com/crenshaw/tutor16.txt (BTW, what exactly do you

Re: [9fans] Undefined Behaviour in C

2015-11-25 Thread Brantley Coile
Align it to column 7 and it looks like all the code I saw when I started. iPhone email > On Nov 25, 2015, at 12:13 PM, Ryan Gonzalez wrote: > > Neither! It's what happens when you run sed 's/^\s*//' on your whole code > base, yielding results like (from cmd/yacc.c): > > >

Re: [9fans] Undefined Behaviour in C

2015-11-25 Thread Steffen Nurpmeso
plann...@sigint.cs.purdue.edu wrote: |On Wed, Nov 25, 2015 at 09:25:55AM -0500, Brantley Coile wrote: |> unindented consequences | |Is that a class of Python bugs or an awesome name for a Nerdcore band? all that new C stuff and sequencing is shit. imho :) --steffen

Re: [9fans] Undefined Behaviour in C

2015-11-25 Thread Bakul Shah
Using 0xfff...f instead of 0 for a null ptr might've been less "disgusting"! > On Nov 25, 2015, at 6:04 PM, Prof Brucee wrote: > > gcc is indeed a very sad tome. The mmap of 0 is disgusting. I like kenc. It > just works. My behaviour this afternoon will be undefined but

Re: [9fans] Undefined Behaviour in C

2015-11-25 Thread Brantley Coile
Just curious, will Linux not panic when the kernel deterrences a nil pointer? Sent from my iPad > On Nov 25, 2015, at 5:27 AM, Alexandru Gheorghe > wrote: > >> On 11/23/2015 01:20 PM, Vasudev Kamath wrote: >> Ramakrishnan Muthukrishnan writes: >>

Re: [9fans] Undefined Behaviour in C

2015-11-25 Thread Alexandru Gheorghe
On 11/23/2015 01:20 PM, Vasudev Kamath wrote: > Ramakrishnan Muthukrishnan writes: > >> Had been reading the SOSP paper: >> >> >> and this blog post that proposes a simpler C: >> > I

Re: [9fans] Undefined Behaviour in C

2015-11-25 Thread Brantley Coile
My apologies for my iPad's spelling correction and my lack of proof reading. Proof reading is impotent. :) I meant "dereference". It's an easy matter to have page zero invalid in both user space and kernel space. Sent from my iPad > On Nov 25, 2015, at 5:43 AM, Brantley Coile

Re: [9fans] Undefined Behaviour in C

2015-11-25 Thread Charles Forsyth
The link to the lwn.net article explains that using mmap the naughty application mapped a page to virtual 0, which was then available in kernel mode in that process, and all they'd need to do is put their own "socket" structure at 0 + offsetof(struct tun_struct, sk). On 25 November 2015 at 10:43,

Re: [9fans] Undefined Behaviour in C

2015-11-25 Thread erik quanstrom
so to answer bwc's question, no.  not always.  On Nov 25, 2015 4:59 AM, Charles Forsyth wrote:The link to the lwn.net article explains that using mmap the naughty application mapped a page to virtual 0, which was then available in kernel mode in that process, and all

Re: [9fans] Undefined Behaviour in C

2015-11-25 Thread Brantley Coile
Insert various complaints about unwise complexities and their unindented consequences here. Just my personal taste, but I didn’t like shared libraries when the Unix world in the 1980’s were copying Window’s DLLs, and could never see the reason for linking the file system and paging system.

Re: [9fans] Undefined Behaviour in C

2015-11-25 Thread Brantley Coile
Dang it! I basically suck at proof reading! unintended consequences! > On Nov 25, 2015, at 9:25 AM, Brantley Coile wrote: > > Insert various complaints about unwise complexities and their unindented > consequences here.

Re: [9fans] Undefined Behaviour in C

2015-11-23 Thread Charles Forsyth
There is quite a bit there to work through, but I was struck by one of the responses to a gcc bug report: "you're leading to undefined behaviour - do you understand this simple fact? in such cases compiler can do *anything* with your code." I've seen similar comments before (about

Re: [9fans] Undefined Behaviour in C

2015-11-23 Thread Vasudev Kamath
Ramakrishnan Muthukrishnan writes: > Had been reading the SOSP paper: > > > and this blog post that proposes a simpler C: > I started reading the paper and its interesting. I didn't

[9fans] Undefined Behaviour in C

2015-11-23 Thread Ramakrishnan Muthukrishnan
Had been reading the SOSP paper: and this blog post that proposes a simpler C: I wonder how Plan 9 C compiler, which is a non-ANSI compliant compiler, treats those parts that the ANSI C standard treats as

Re: [9fans] Undefined Behaviour in C

2015-11-23 Thread Charles Forsyth
On 23 November 2015 at 11:32, Charles Forsyth wrote: > The Plan 9 C compiler is firmly in that historical tradition In short: http://www.terzarima.net/images/careful-now.jpg

Re: [9fans] Undefined Behaviour in C

2015-11-23 Thread Brantley Coile
This is an interesting issue to me because I'm becoming more and more aware of a fundamental misunderstanding of C which will make it difficult for people to write efficient code in the future. These two documents show a lack of understanding regarding the reason for undefined behavior and a

Re: [9fans] Undefined Behaviour in C

2015-11-23 Thread Charles Forsyth
On 23 November 2015 at 11:50, Brantley Coile wrote: > These bloated compilers can never be idiot proof because idiots are so > ingenious. One thing that struck me about that earlier gcc example, where the test for "tun" is eliminated because of bad compiler reasoning, is

Re: [9fans] Undefined Behaviour in C

2015-11-23 Thread Brantley Coile
I've lived with the old definition so long that I didn't notice Plan 9's definition, which is not a problem on today's architectures because there are two equally efficient instructions to choose from. Sent from my iPad > On Nov 23, 2015, at 7:05 AM, Charles Forsyth

Re: [9fans] Undefined Behaviour in C

2015-11-23 Thread Charles Forsyth
On 23 November 2015 at 12:17, Brantley Coile wrote: > I've lived with the old definition so long that I didn't notice Plan 9's > definition, which is not a problem on today's architectures because there > are two equally efficient instructions to choose from. There are a

Re: [9fans] Undefined Behaviour in C

2015-11-23 Thread Charles Forsyth
On 23 November 2015 at 10:20, Ramakrishnan Muthukrishnan wrote: > Had been reading the SOSP paper: > > As an example of how tricky it can be, one of their examples is const uint8_t *data = /* buffer head */; const uint8_t