

Your code should be taken out back, lined up against a wall, and machine-gunned - RyanMcGreal
http://www.cygwin.com/ml/cygwin/2005-08/msg00520.html

======
nailer
There's a great story about a heckler at a Windows NT conference:

MS speaker: and we've got POSIX, and we've got POSIX ACLs, and we've got a
Unix Subsystem and we've got Korn Shell, and it works just the same way as
under Unix.

Heckler: NO IT DOESN'T

MS speaker: er, ok. It does work. Anyway...

Heckler: NO IT DOESN'T WORK

MS speaker: What doesn't work?

Heckler: (rattles off differences in behavior and brokenness of ksh on NT)

MS speaker: we'll we've had our top guys working on this ...

Heckler: I'M DAVID KORN.

 _Room erupts in laughter._

Update: source: <http://slashdot.org/articles/01/02/06/2030205.shtml>. See
question 5.

~~~
tokipin
we realllly need people like that at political speeches

------
xpaulbettsx
While I always enjoy a good rant, I don't see why it had to be so vicious and
insulting. Yeah, the guy's clearly pretty confused (if he wanted to do these
kind of tricks, I'd try to use setjmp, fiddle with the structure, then longjmp
to it), but there's no reason to be mean about it.

~~~
ww520
I think it's because his indignant demand of the Cygwin team to fix this "bug"
and make it work for him. Basically it's the attitude that I know my way is
the right way, now fix the platform so that my program runs.

~~~
xpaulbettsx
I don't see any demands in the original mail:

<http://www.cygwin.com/ml/cygwin/2005-08/msg00504.html>

He questions whether it "should be fixed" in Cygwin, a perfectly reasonable
request, and he fully admits that he isn't sure whether it's a problem in
Cygwin or not.

~~~
ww520
"Should be fixed" is a passive aggressive way to demand it to be fixed.

His reference to Linus doing the same thing in kernel (not) sounds very much
like a smack response.

Also he claims he knows what he's doing since he has done the same thing in
DOS so when it's clear that he has no clue of what's going on just irrates
people.

~~~
tptacek
Instead of trying to walk "indignant demand" back to "passive aggressive way
to demand" inch by inch, just concede that all the guy did was ask a question
and make a case for why he thought Cygwin's behavior was broken. Nobody's
saying Cygwin has to agree with him, but you've simply mischaracterized the
start of the thread.

My interpretation is that Korn was trying to be funny (and he succeeded), but
as usual the peanut gallery ruined the joke.

------
boredguy8
Best part is in the follow-up discussion:

    
    
      > Do you actually realise that not all computer languages can 
      > be implemented with a model of one stack?
      > 
    
      Do you actually realize that there are far better ways to implement stacks
      for interpreters than dinking with esp?  Ways that actually have a chance of
      working?  I suggest you investigate those alternatives instead of trying to
      do something that cannot work, and then getting all pissy when people try to
      dissuade you from wasting your time.
    
      And don't make me break out my Turing Machine on you about that statement of
      yours.

~~~
tptacek
Strong disagree. Korn's response is at least funny. The rest of the responses
are petulant, somewhat ill-informed, and orthodoxical. The argument over
whether C does or doesn't have a runtime is particularly tedious. You get the
impression that these people would all be very, very upset at the Detours
paper, except that Detours works so well they'd know a priori they'd lose the
argumet.

The original commenter --- despite his very fragile code --- is right: for
what he wants to do, he needs to create temporary stacks. What he doesn't have
is a mechanism to allocate and swap in and out of those stacks (he's hoping
that switching stacks is a 2-liner that just relies on knowing the inline asm
incantation for changing ESP).

Regardless, it is a uniquely and flagrantly _bad_ way to educate (both the
questioner and the world who's reading the thread) to start from the premise
that "you're not ready to build the thing you want to build" --- at least when
"the thing" we're talking about is systems code. 90% of C programmers are not
"ready" to build production C code that will get deployed in hostile
environments, and as a result, in every web project we ever do, we have to
embark on a tedious inventory of all the 3rd party stuff our clients use to
find the horrible C ZIP library they accidentally included. No C coder is
blameless.

Unless I missed a whole leg of this thread (the part where they explained temp
stacks and stack switching to this guy, who, in challenging the notion that C
has a real runtime or the notion that the OS should [heh] be controlling ESP,
is demonstrating more on-the-ground systems programming knowhow than several
of the commenters), I think this is a remarkably douchey example of a
programming help thread.

~~~
ww520
Why don't you show us a working version of the code instead of spewing endless
argument?

~~~
tptacek
Because, as you've demonstrated amply downthread, the people making the most
noise about how incompetent the original poster was for asking this question
about Cygwin are the ones least qualified to have an opinion about this stuff,
and are actually making Dave Korn (who was at least funny and who clearly does
know what he's talking about) look worse.

But if you know how to use The Google, you can actually find code of mine that
does this. I doubt very highly you can say the same thing.

~~~
ww520
Really I don't know you before this thread. I did what you asked and googled
"thomas ptacek" and here are some of the result on the first page.

I'd Like Thomas Ptacek To Apologize Please
<http://www.zedshaw.com/blog/2010-01-12.html>

Welcome to Thomas J Ptacek Furniture <http://www.thomasjptacek.com/>

Security Idiot: Thomas Ptacek: Too Quick By Far!
[http://www.securityidiot.com/2008/07/thomas-ptacek-too-
quick...](http://www.securityidiot.com/2008/07/thomas-ptacek-too-quick-by-
far.html)

Are those yours?

~~~
apower
This is hilarious.

------
chacha102

      Then the bleeding corpse should be hung, drawn and quartered.
      
      Then burnt.
      
      Then the smouldering rubble should be jumped up and down on.
      
      By a hippo.
    

By a hippo....

~~~
JeanPierre
It is a natural choice. 3,600 lb is more than the weight of any human in the
world, and elephants can't jump.

~~~
sliverstorm
Well, you'd at least hope so.

------
ivenkys
I for one would pay good money to get a response like this.

He points out the errors,the incorrect assumptions and offers pointers of what
to do. The general standard of discourse on most mailing lists tend to be
quite a bit lower than this.

------
mattmight
Or, the code could be released under the CRAPL:

<http://matt.might.net/articles/crapl/>

------
j_baker
I'm a little bit slow with the low level stuff. Could someone explain what's
so horrific about this code?

~~~
ww520
For one thing, he's using assembly of one type of machine and expects it to
work on different type of machine. He confuses Linux as a machine abstraction
and demands that Cygwin running on Windows to be the same.

For the low level mess, he sets the stack frame pointer to a uninitialized
heap-allocated buffer which contains God-know-what garbage. When main()
returns, it pops its return address from the stack frame pointer, which
contains garbage and crashes. The printf() might sometime work depending on
how the compiler emits code to set up the stack frame.

It just shows how dangerous some ignorant programmers can be.

~~~
rntz
Uh, actually, his original program
(<http://www.cygwin.com/ml/cygwin/2005-08/msg00542.html>) did restore the
stack pointer before returning from main. He "wanted to cut [the example's
size] down for the sake of the mailing list", so he left that bit out.

~~~
phaedrus
Still a terrible thing to do. I think it's possible just calling printf()
itself could do wacky things if printf is depending on the stack being set up
a certain way by the C runtime startup code prior to main.

But the real issue is that what he's doing is completely unnecessary, because
you could manage multiple stacks yourself using ordinary C data structures and
ordinary C code. Evidently he thinks he's gaining some kind of speed advantage
by doing things this way, but the risk is very high versus the gain. This kind
of optimization may have worked OK on a DOS machine, but it's neither safe nor
obviously faster to do things like this on a modern CPU and OS.

~~~
Confusion
Well, doing terrible things is sometimes necessary to perform magic or to get
a better understanding about how things work. From the less flamey parts of
the discussion, I gather his ideas weren't all that unsound, just extremely
hard to pull off.

~~~
InclinedPlane
Generally speaking if you have to do terrible things then you need to _a:_
know exactly what you are doing before hand and _b:_ have the fortitude to be
able to withstand harsh criticism until you can prove your code.

In this case I think the harsh criticism was fully justified. People should be
warned away from doing this sort of thing, precisely because it's hard to get
right. As the thread makes abundantly clear the original programmer was fairly
clueless, otherwise he wouldn't have gone off half-cocked thinking that the
fault was with cygwin or somesuch. He was making his own dynamite and was too
clueless to realize what he was doing wrong.

~~~
Confusion
I don't agree: we have no reason to doubt his claim that he wrote a task
switcher for DOS. That means he's reasonably clueful. It's easy to dismiss
someone as a complete loony, because he's wrong/confused about some things and
is getting burned to the ground for that. Remove the flaming and there is
criticism and the pointing out of mistakes, but nothing to indicate the guy
has no clue whatsoever. If that were the case, it would be hard to even being
criticising the idea. The fact that people could succinctly point out the
problems means the ideas were stated in reasonably clear language.

------
afhof
Why was he complaining about the stack pointer first? Isn't this line:

st1 = (void *)malloc(5000) + 5000;

completely invalid too? You can't (I think it's undefined) increment a void
pointer.

~~~
tptacek
It may be undefined, but gcc accepts it without warning under -Wall and does
exactly what you'd expect. Note that (a) casting malloc's return is evil, (b)
casting malloc to void* is silly since it's declared returning void* already,
and (c) casting malloc to void* so it can be received as a char* is also
pretty goofy.

~~~
NickPollard
This might be a stupid question, but what are you meant to do if not cast
malloc's return?

My C is a bit rusty, but how else are you meant to allocate data of different
types on the heap?

~~~
scott_s
C allows implict casting of void* to any other kind of pointer. Hence, you
never need to cast the return from a malloc if you're storing it in a pointer.

C++, however, does not allow this. So, if for some reason you're calling
malloc rather than new in C++, you need to cast.

~~~
sanderjd
You are not the poster who said "casting malloc's return is evil", so perhaps
you don't agree with that statement, but I don't see how either of the points
you make lead to the conclusion that it is "evil". You say that since void* is
implicitly cast to all pointer types, you never need to explicitly cast it,
but why would that make an explicit cast evil?

~~~
mfukar
An explicit cast of the result of malloc() can mask an error when you haven't
included its proper definition in stdlib.h.

------
edge17
Is that the same Dave Korn that did Korn Shell?

~~~
Confusion
In case you haven't gathered from other responses in this thread or are only
reading this in your 'threads' view: yes.

~~~
astrange
Er, no he isn't.

(The older David Korn actually wrote a sort-of-competitor to Cygwin, called
UWIN.)

~~~
Confusion
Oops, sorry, I took the top comment at face value :(

------
thibaut_barrere
Recruiting tip: don't hire someone who is able to answer this way to someone,
no matter how skilled.

