05 June 2019, 17:48 | #41 | ||||||||||
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,335
|
Quote:
But this gives another shortcoming of the cookie in comparison to normal methods : it's not dynamic. While the program could stack swap on demand with the most appropriate size, the cookie has to contain the maximum possible size. So much for the sparing of memory it's supposed to give. Quote:
Then arrange so that your program doesn't need a big stack. Problem solved. Quote:
Quote:
Quote:
Now we have a nice bunch of data just for that. We get better every day. Quote:
Nope - as it ain't safe in any manner. Quote:
Quote:
Remember ? You wrote "static const char". Seems it's easily missed. When will you notice the mistake ? Maybe the end user will, when he sees his program crash ? Quote:
Quote:
So everyone should be using 3.9, now ? You decided that alone ? Not exactly. $VER can work in all kinds of files, you often see them in e.g. scripts (which don't have a hunk structure). This is why it is a cookie and not an entry in the executable file format (and also the reason why there is a newline, as it can appear in text files of course not having the null at the end). It was about how it should have been done from day one (and wasn't), not about what we can do now... |
||||||||||
05 June 2019, 17:56 | #42 |
Registered User
Join Date: Jan 2008
Location: Warsaw/Poland
Age: 55
Posts: 2,007
|
Why? This is very easy to do without breaking compability. For old dos.library versions StackSize hunk will be ignored. Normal Amiga exe files, ended with hunkend $000003F2. Add 8 bytes at end of Amiga exe file, 4 bytes for stack size, 4 bytes for StackSize hunk ID. LoadSeg will be checked for last 4 bytes of exe file, and if StackSize hunk ID at end, then stored stack size will be used.
|
05 June 2019, 18:23 | #43 |
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,248
|
|
05 June 2019, 18:31 | #44 |
Registered User
Join Date: Jan 2008
Location: Warsaw/Poland
Age: 55
Posts: 2,007
|
|
05 June 2019, 18:41 | #45 | |||||||
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,248
|
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
If you want to speculate what should have been done 30 years ago, then I can tell you: Create a robust operating system in first place, one with memory protection and a guard page below the stack. *THAT* would have worked robustly. Unfortunately, that was not really an option for a consumer device. The hunk structure is just a minor inconvenience compared to the major issues the Os has. |
|||||||
05 June 2019, 18:43 | #46 |
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,248
|
That, of course, depends on some details of the binary. And you ignore what happens if you process the binary, or how programs react that attempt to load such a binary. You are opening a compatibility problem that can be quite easily avoided.
|
05 June 2019, 19:16 | #47 | |||||||
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,335
|
Quote:
Quote:
Quote:
But what ? You did not pick this at random ? So you were the developer behind it ? That explains why you defend it so much No way. It does not say anything but a hint on the stack size. Not what the program will use as resources. In some way, yes. It's just a command to be able to run badly written programs. Quote:
So now stack overflows don't crash ? Remember, if your cookie gets removed, your stack size won't change... Quote:
Now nothing has changed. We're not forced to go to 3.9 more than we were 18 years ago. Quote:
Quote:
By comparison, a program can have 1MB as first hunk, in which the stack cookie can just be missing. |
|||||||
05 June 2019, 22:22 | #48 | |||||||||
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,248
|
That you state something as "easy and obvious", whereas it is, in reality, not simple at all if you look at all the pesky details. Of course the theory of "how to play a flute" is simple. Yet, it requires a bit more to actually play some music on it. No, not only for mine. For anyone's, using 3.9.
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
|
|||||||||
06 June 2019, 00:27 | #49 | |
Registered User
Join Date: Jan 2008
Location: Warsaw/Poland
Age: 55
Posts: 2,007
|
Quote:
1. If i remember right not all legal hunks handled by LoadSeg has code (only skip bytes code is used). Choose one as Stack Size. 2. Modify debug hunk code, add extra check for stacksize ID and handle stack size. Your method is not good. |
|
06 June 2019, 09:17 | #50 | ||
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,248
|
Nope. You seem to assume that LoadSeg is the only way how such data is processed, which is not given. There are multiple other tools that operate on such files, and that could fail or misinterpret such data. It is a "protocol violation" because it fails to follow the specs of how a HUNK format should look like.
Quote:
Quote:
|
||
06 June 2019, 10:38 | #51 | |||||||||||
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,335
|
Quote:
Yeah, and surely you can ensure not even GCC with max optimization will not remove your cookie... Quote:
But the problem here isn't even the search algorithm. It is the mere fact of having to perform a search. If you don't do this, believe me, it'll be a magnitude faster. Quote:
Quote:
Quote:
Quote:
Quote:
You can prevent the removal if it's simply code that gets executed as part of the startup. And right, playing with the hunk format may be likely to break, but why not just using overlay hunks. Quote:
Only startup code is guaranteed to be in the first one, you cannot do that for any data. Quote:
Quote:
Quote:
Resident tags are mandatory for libraries and devices so the search will hopefully end with a success - and needs not be fast otherwise. On the other hand, not even 1% of executables that'll run actually contain the stack cookie and it'll be searched in vain by scanning all of their first hunk entirely. Definitely not the same situation. By "missing" i meant "not there because not used", not "should be there but isn't". |
|||||||||||
06 June 2019, 10:55 | #52 | |
Registered User
Join Date: Jan 2008
Location: Warsaw/Poland
Age: 55
Posts: 2,007
|
Quote:
I know, that you think that your version is good, but this is useless, only wasting some bytes or kilobytes in Amiga ROM space. If my ideas are really bad, then we can try to find other clear solution for stacksize support. For me your way is dirty hack only, not clean way. |
|
06 June 2019, 16:16 | #53 |
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,248
|
Which is precisely what your proposal doesn't. Let's boil it down to one sentence: You modify a well-documented file format without being able to update the tools that depend on it. That is really it. Nothing else to say.
|
06 June 2019, 16:42 | #54 | ||||||||||||||
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,248
|
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
|
||||||||||||||
06 June 2019, 18:14 | #55 | |||||||||||||||
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,335
|
Quote:
Quote:
What you did here is a typical behavior of people out of argument. I didn't know you were the type, though. This is deceiving. Aren't you better than that ? Anyhow, my "very limited experience" tells me that none of your tricks will guarantee you get the cookie in the right hunk. It works for you purely by luck. Ok, it will not be stripped (at the price of something quite ugly). So it will be in your executable and still possibly in the wrong section. The fact it never happens in your setup isn't a proof it can't happen at all. IOW, "works for me" isn't a correct reply. Quote:
The point here was that you have some table (256 bytes ?) that is there permanently eating memory, just to spare a few temporary kb in some rare cases. Clear now ? Quote:
But indeed it's probably not noticeable. Neither is the second stack when doing a swap. Quote:
Quote:
Quote:
Gains i get by rewriting parts of compiled code into asm easily spare a lot more bytes than that little "waste" uses. Quote:
The fact the cookie is still there for resident programs may seem a good argument for it... ... Except for the fact resident made programs are quite rare in current setups, and they are for small, often used commands that of course don't need big stacks. Quote:
And i don't put hacks in programs when i can do otherwise. Quote:
Quote:
Quote:
Quote:
And yes, ROM-based segments can have a stack cookie -- but neither libraries, devices, resources, nor small resident commands need to use something like that. Quote:
And again you can not tell the compiler in which hunk to put things. Quote:
But i don't really care if it sticks or not, even if i would certainly delete it if i had to rewrite the OS. At least it's relative harmless. |
|||||||||||||||
06 June 2019, 18:47 | #56 | ||
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,510
|
Quote:
Quote:
I think the STACK cookie is a good idea. There is nothing bad about it (I don't care about a few cycles scanning for it at program start) and it is implemented in a flexible, backwards-compatible way. Other operating systems, like Atari MiNT, have a similar cookie. My problem is that it is much too late. In my software I would never expect that most users are running 3.9 or 3.1.4, or even requiring it. So I will still use StackSwap() to be safe. Now I need to know: which additional advantage would I get by including the STACK cookie? When it means that the STACK cookie launches my program with a large enough stack, so that StackSwap() is no longer needed under 3.9/3.1.4, then I should probably add it. I will check the current stack size anyway, so I can avoid StackSwap() when the stack was already large enough. |
||
06 June 2019, 19:06 | #57 | |||
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,335
|
Quote:
Quote:
Quote:
But as it's taking its toll regardless if wanted or not, indeed why not using it. |
|||
06 June 2019, 19:20 | #58 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,510
|
|
06 June 2019, 19:29 | #59 |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,335
|
|
06 June 2019, 19:48 | #60 |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,335
|
Another problem i'm just thinking about.
Even if the stack cookie is there and honored, things can still go haywire. I think many compilers will setup the stack as part of their startup code. Or at least they should. Now the programmer, not knowing about this fact, will put the cookie in his code. A cookie at the right place. Perfectly detected, with stack perfecly allocated. And then the startup code performs its regular stack swap... |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Moving supervisor stack | roondar | Coders. Asm / Hardware | 6 | 18 July 2017 17:13 |
Stack available | mritter0 | Coders. General | 4 | 03 August 2014 18:31 |
TCP/IP Stack | redneon | Amiga scene | 18 | 24 July 2005 16:01 |
Stack Up | Galaxy | request.Old Rare Games | 5 | 08 September 2004 03:06 |
Who wants a stack of originals? | FromWithin | Games images which need to be WHDified | 41 | 31 July 2003 09:31 |
|
|