English Amiga Board


Go Back   English Amiga Board > Coders > Coders. System

 
 
Thread Tools
Old 05 June 2019, 06:21   #21
Minuous
Coder/webmaster/gamer
 
Minuous's Avatar
 
Join Date: Oct 2001
Location: Canberra/Australia
Posts: 2,669
@BruceAbbott:

Why is it "not very useful"? Because it requires BB2 rather than BB0? I don't think there are many users still running without any Boing Bags installed.

Last edited by Minuous; 05 June 2019 at 06:33.
Minuous is offline  
Old 05 June 2019, 07:35   #22
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 3,302
Quote:
Originally Posted by Bruce Abbott View Post
So not very useful then - and also a disgusting kludge. Though I guess it's better than expecting users to type a 'stack' command before running programs from the CLI, and then unceremoniously crashing when they don't.
Oh, so you say that you can never add a new feature because old versions would not support it? That does not sound very useful for me.

Do you call the $VER: cookie a discusting kludge?

Do you expect that average Joe User knows how much stack a particular program needs? Do you expect that average Joe User *remembers* to set the stack in the shell?

Tripos and the Tripos executable format (aka AmigaDOS) is not extensible without breaking backwards compatibility, so there is no room for such meta-information without stopping old versions of the segment loader to break with such extensions, or without additional tools accidentally removing them.

Or, put in different words: Do you have anything better to suggest? Provided that a) it works transparently with older Os releases, b) it embeds information such that it cannot get lost easily, and c) it can be easily detected?
Thomas Richter is offline  
Old 05 June 2019, 08:54   #23
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,351
Quote:
Originally Posted by Bruce Abbott View Post
So not very useful then - and also a disgusting kludge. Though I guess it's better than expecting users to type a 'stack' command before running programs from the CLI, and then unceremoniously crashing when they don't.
More than a disgusting kludge, it's totally useless, and worse, dangerous. Because programs will still unceremoniously crash whereever it's not supported.


Quote:
Originally Posted by Minuous View Post
I don't think there are many users still running without any Boing Bags installed.
There is at least me.


Quote:
Originally Posted by Thomas Richter View Post
Oh, so you say that you can never add a new feature because old versions would not support it? That does not sound very useful for me.
Not all new features are dirty, useless little things


Quote:
Originally Posted by Thomas Richter View Post
Do you call the $VER: cookie a discusting kludge?
Programs don't crash if $VER is not supported.


Quote:
Originally Posted by Thomas Richter View Post
Do you expect that average Joe User knows how much stack a particular program needs? Do you expect that average Joe User *remembers* to set the stack in the shell?
Average Joe user isn't using AmigaOS at all.
But granted, programs shouldn't force the user to think about these details. There are, however, better ways to do that than stupid $STACK cookie.


Quote:
Originally Posted by Thomas Richter View Post
Tripos and the Tripos executable format (aka AmigaDOS) is not extensible without breaking backwards compatibility, so there is no room for such meta-information without stopping old versions of the segment loader to break with such extensions, or without additional tools accidentally removing them.
That would have nevertheless been more clever. This way, programs would not run at all under previous OS versions. The cookie isn't backward compatible anyway because if stack size is ignored, the program will crash.


Quote:
Originally Posted by Thomas Richter View Post
Or, put in different words: Do you have anything better to suggest? Provided that a) it works transparently with older Os releases, b) it embeds information such that it cannot get lost easily, and c) it can be easily detected?
From OS V37 we have something called StackSwap.
meynaf is offline  
Old 05 June 2019, 09:08   #24
grond
Registered User
 
Join Date: Jun 2015
Location: Germany
Posts: 1,924
Quote:
Originally Posted by meynaf View Post
More than a disgusting kludge, it's totally useless, and worse, dangerous. Because programs will still unceremoniously crash whereever it's not supported.
Why would that be? I guess you could still check the stack size assigned to your program and allocate some extra stack if the original stack isn't enough. Of course, you can do this in earlier OS versions, too, but with the $STACK cookie you can at least avoid wasting the memory allocated for the original stack.
grond is offline  
Old 05 June 2019, 09:17   #25
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,351
Quote:
Originally Posted by grond View Post
Why would that be? I guess you could still check the stack size assigned to your program and allocate some extra stack if the original stack isn't enough. Of course, you can do this in earlier OS versions, too, but with the $STACK cookie you can at least avoid wasting the memory allocated for the original stack.
But the $STACK cookie has to restore original stack size at the end of the program as well, so why wouldn't it also waste original stack space ?
And if it does not, why can't the program itself do the same thing ?
meynaf is offline  
Old 05 June 2019, 09:35   #26
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 3,302
Quote:
Originally Posted by meynaf View Post
But the $STACK cookie has to restore original stack size at the end of the program as well, so why wouldn't it also waste original stack space ?
And if it does not, why can't the program itself do the same thing ?
No, it does not. You do not know how AmigaOs handles the stack. To remind you: The "STACK" command does not allocate any stack at all. It just records the stack size in the CommandLineInterface structure. The stack is allocated *every time* you execute a program from the shell (or the workbench), anew. Thus, whether you use the STACK command, or the $STACK cookie makes no freaking difference whatsoever.
Thomas Richter is offline  
Old 05 June 2019, 09:39   #27
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 3,302
Quote:
Originally Posted by meynaf View Post
More than a disgusting kludge, it's totally useless, and worse, dangerous. Because programs will still unceremoniously crash whereever it's not supported.
It's up to you to write programs that do not crash.
Quote:
Originally Posted by meynaf View Post
Programs don't crash if $VER is not supported.
Programs neither crash if $STACK is not supported - if the STACK is set manually.
Quote:
Originally Posted by meynaf View Post
But granted, programs shouldn't force the user to think about these details. There are, however, better ways to do that than stupid $STACK cookie.
As you haven't suggested any, I suppose you are not aware of any.
Quote:
Originally Posted by meynaf View Post
That would have nevertheless been more clever. This way, programs would not run at all under previous OS versions. The cookie isn't backward compatible anyway because if stack size is ignored, the program will crash.
Not if the user has set STACK or the program allocated stack at all.
Quote:
Originally Posted by meynaf View Post
From OS V37 we have something called StackSwap.
Oh wow, but *this* (unlike $STACK) will indeed require the memory of the originally allocated stack *PLUS* the size of the additionally allocated stack. Unlike the STACK command o the $STACK cookie.
Thomas Richter is offline  
Old 05 June 2019, 10:18   #28
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,351
Quote:
Originally Posted by Thomas Richter View Post
No, it does not. You do not know how AmigaOs handles the stack. To remind you: The "STACK" command does not allocate any stack at all. It just records the stack size in the CommandLineInterface structure. The stack is allocated *every time* you execute a program from the shell (or the workbench), anew. Thus, whether you use the STACK command, or the $STACK cookie makes no freaking difference whatsoever.
Then the called program can do the same. Why wouldn't it be able to ?
And this means we have two stacks already : the one of the CLI process itself, and the one of the currently running program...


Quote:
Originally Posted by Thomas Richter View Post
It's up to you to write programs that do not crash.
This implies not using the cookie but using instead a proper way to handle the stack.


Quote:
Originally Posted by Thomas Richter View Post
Programs neither crash if $STACK is not supported - if the STACK is set manually.
Right of course, the program won't crash if the cookie isn't supported and would have had no effect (and is therefore useless). Big deal.


Quote:
Originally Posted by Thomas Richter View Post
As you haven't suggested any, I suppose you are not aware of any.
I have suggested two, actually... That you rejected one for a minor shortcoming does not invalidate it. Better wasting 4k than taking the risk of a very bad crash, no ?
And you silently rejected the other - yes, a change in the hunk structure would have been a more intelligent way (not that it is clever in the absolute, but still better than the stack cookie).

Anyway... code properly, and you won't need big stacks at all
(That's 3 better ways than the cookie already, btw.)


Quote:
Originally Posted by Thomas Richter View Post
Not if the user has set STACK or the program allocated stack at all.
But the purpose of the cookie is precisely to avoid the fact the user has to set the stack !
So either the user does, in that case the cookie is utterly useless.
Or he does not, in that case the program crashes.
In both cases the cookie does not fare very well.

Of course if the program itself allocated a stack, the cookie becomes redundant and more useless than ever.
Right, it could check if the cookie worked before allocating anything, but it's a lot simpler to allocate the stack in all cases.


Quote:
Originally Posted by Thomas Richter View Post
Oh wow, but *this* (unlike $STACK) will indeed require the memory of the originally allocated stack *PLUS* the size of the additionally allocated stack. Unlike the STACK command o the $STACK cookie.
Right, and ?
If your program uses huge 300kb stack, are you really after 4k ?
The mere fact of using a compiler to build your program wastes a magnitude more than that due to significantly larger code - but you would still defend doing it...

Furthermore, what happens if we copy original stack contents and do not restore the old stack upon exit ?
meynaf is offline  
Old 05 June 2019, 12:47   #29
grond
Registered User
 
Join Date: Jun 2015
Location: Germany
Posts: 1,924
@meynaf: you act like you are forced to use the STACK cookie...
grond is offline  
Old 05 June 2019, 12:59   #30
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,351
Quote:
Originally Posted by grond View Post
@meynaf: you act like you are forced to use the STACK cookie...
Nonsense. I can perfectly tell something is a bad idea without being forced to use it in any way. Please refrain speaking about people, especially those you do not know.
Besides, the problem is far from being located there. The problem would be if someone actually uses it, i run the program believing the stack size is automatically handled, but it crashes because in reality it is not.
meynaf is offline  
Old 05 June 2019, 13:23   #31
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 3,302
Quote:
Originally Posted by meynaf View Post
Then the called program can do the same. Why wouldn't it be able to ?
Did you read what I have written? Because that requires both the original stack size as memory *plus* the stack the program allocated manually. With $STACK, it requires only the correct stack size.
Quote:
Originally Posted by meynaf View Post
And this means we have two stacks already : the one of the CLI process itself, and the one of the currently running program...
Right, which is what we have since the stone age of Tripos. Do you now finally get it? The stack the shell gets is in no relation to the stack the programs get that are executed by it. This is not at all new - it has always been like that. Tripos, AmigaOs from Kickstart 1.0 on, creates a custom stack for every executable it launches, and this stack is separate from the stack of the shell itself. Yes, really, there are two stacks: The stack of the shell, and the stack of the programs executed by the shell, and STACK and the stack cookie only control the size of the latter. The shell only has a quite minimal stack for itself, which is separate and unrelated to the program stack.
Quote:
Originally Posted by meynaf View Post
Right of course, the program won't crash if the cookie isn't supported and would have had no effect (and is therefore useless). Big deal.
The "deal" is that programs that check their stack size upon entry do not need to allocate a new custom stack and thus leave the stack allocated for them by the shell unused. Is that really so hard to understand?
Quote:
Originally Posted by meynaf View Post
And you silently rejected the other - yes, a change in the hunk structure would have been a more intelligent way (not that it is clever in the absolute, but still better than the stack cookie).
A non-working one. That would have meant that all the legacy tools we have would not be able to process such binaries, Mr. Smartipants. Or loose the stack information when processing them. The cookie can be easily checked, and can be easily embedded, and there is no chance of loosing it.
Quote:
Originally Posted by meynaf View Post
Anyway... code properly, and you won't need big stacks at all.
With the 4K default stack, you already run into limitations right ahead. Probably you don't know, but various intuition functions (such as OpenWindow() & friends, OpenScreen() & friends, the auto requesters) and various datatypes (the picture datatype, the animation datatype and so on) already contain a stack check and stack exchange code to avoid stack problems when run from programs with 4K stack only. All that stack code will detect whether there is sufficient stack space, and won't swap if there is. This swapping you can avoid with adjusting the stack properly in first place.
Quote:
Originally Posted by meynaf View Post
So either the user does, in that case the cookie is utterly useless.
And if the user does not, it is quite useful.
Quote:
Originally Posted by meynaf View Post
Or he does not, in that case the program crashes.
Not in case the program is run under a 3.9 shell, or something later than the 3.9 shell. So, I call that "useful" and "a good deal".
Quote:
Originally Posted by meynaf View Post
In both cases the cookie does not fare very well.
I call "avoiding a crash" a good deal.
Quote:
Originally Posted by meynaf View Post
Of course if the program itself allocated a stack, the cookie becomes redundant and more useless than ever.
Again, no. It avoids a memory allocation, and wasteful use of resources.
Quote:
Originally Posted by meynaf View Post
Right, it could check if the cookie worked before allocating anything, but it's a lot simpler to allocate the stack in all cases.
It is wasteful, whereas the stack cookie requires 10 bytes in the executable. I call that a good deal.
Quote:
Originally Posted by meynaf View Post
If your program uses huge 300kb stack, are you really after 4k ?
If I can get them that easily, yes.
Quote:
Originally Posted by meynaf View Post
The mere fact of using a compiler to build your program wastes a magnitude more than that due to significantly larger code - but you would still defend doing it...
It avoids spending a lot of *time*, which is an important resource. Time developing and time debugging. Besides, the code is quite good in most cases if you know how to handle the compiler.
Quote:
Originally Posted by meynaf View Post
Furthermore, what happens if we copy original stack contents and do not restore the old stack upon exit ?
You crash. And your point is? The stack cookie works like the stack command. It does not require the program to take any action. The dos.library RunCommand() takes care of the stack allocation and stack release, the shell takes care of supplying it with the right arguments. The stack argument to this call is the maximum of the current stack size noted in the command line interface structure and the contents of the stack cookie, should it exist.
Thomas Richter is offline  
Old 05 June 2019, 13:48   #32
grond
Registered User
 
Join Date: Jun 2015
Location: Germany
Posts: 1,924
Quote:
Originally Posted by meynaf View Post
The problem would be if someone actually uses it, i run the program believing the stack size is automatically handled, but it crashes because in reality it is not.
Um, I thought we had discussed this already. Use the $STACK cookie, check actual stack size on startup to see whether your program really got enough stack (either by being run on an OS version that does support the cookie or because the user has set enough stack), if not enough stack is present, allocate your own and optionally output a message that asks for the correct stack size for future use. How difficult can this be?

Actually all your complaining is about how AmigaOS was lacking severely with regard to stack handling right from the start and how this got fixed (more or less) when AmigaOS was already a dead fish in the water. I don't see how Thomas is the right person to complain to.
grond is offline  
Old 05 June 2019, 14:43   #33
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,351
Quote:
Originally Posted by Thomas Richter View Post
Did you read what I have written? Because that requires both the original stack size as memory *plus* the stack the program allocated manually. With $STACK, it requires only the correct stack size.
Yes of course i have read what you have written, but what you have written did not answer the question. The called program can still free the allocated stack and allocate a bigger one. The question was : what could prevent it from doing so.


Quote:
Originally Posted by Thomas Richter View Post
Right, which is what we have since the stone age of Tripos. Do you now finally get it? The stack the shell gets is in no relation to the stack the programs get that are executed by it. This is not at all new - it has always been like that. Tripos, AmigaOs from Kickstart 1.0 on, creates a custom stack for every executable it launches, and this stack is separate from the stack of the shell itself. Yes, really, there are two stacks: The stack of the shell, and the stack of the programs executed by the shell, and STACK and the stack cookie only control the size of the latter. The shell only has a quite minimal stack for itself, which is separate and unrelated to the program stack.
Ok, but if the purpose of the cookie is to spare an extra stack, why not merging the stack of the shell with the one of the program, while we're here ?


Quote:
Originally Posted by Thomas Richter View Post
The "deal" is that programs that check their stack size upon entry do not need to allocate a new custom stack and thus leave the stack allocated for them by the shell unused. Is that really so hard to understand?
It is not hard to understand. But it is not new. No need for a stack cookie for it.
It would have been fine if programs did not need to check their stack size at all. But they sometimes need to, and no amount of cookies will change this.


Quote:
Originally Posted by Thomas Richter View Post
A non-working one. That would have meant that all the legacy tools we have would not be able to process such binaries, Mr. Smartipants. Or loose the stack information when processing them. The cookie can be easily checked, and can be easily embedded, and there is no chance of loosing it.
No chance of loosing it, huh ? This is simply not true. It will be lost any time some bozo uses a cruncher - yes, a legacy tool - to reduce the size of your executable. A quite likely situation, more likely than with any other type of tool having to parse hunks.
And now the cookie is hidden in crunched data and thus is not able to do what it has been designed to do. Congratulations, flotsam.


Quote:
Originally Posted by Thomas Richter View Post
With the 4K default stack, you already run into limitations right ahead. Probably you don't know, but various intuition functions (such as OpenWindow() & friends, OpenScreen() & friends, the auto requesters) and various datatypes (the picture datatype, the animation datatype and so on) already contain a stack check and stack exchange code to avoid stack problems when run from programs with 4K stack only. All that stack code will detect whether there is sufficient stack space, and won't swap if there is. This swapping you can avoid with adjusting the stack properly in first place.
As if a stack swap could take a significant amount of time... Compare that to the time taken by every program run, by merely scanning the first code hunk (especially in large programs where the cookie is simply not there).


Quote:
Originally Posted by Thomas Richter View Post
And if the user does not, it is quite useful.
Maybe, but that remains a rare case.


Quote:
Originally Posted by Thomas Richter View Post
Not in case the program is run under a 3.9 shell, or something later than the 3.9 shell. So, I call that "useful" and "a good deal".
But the problem is that it is silently ignored if not supported. Important things shall not be ignored.


Quote:
Originally Posted by Thomas Richter View Post
I call "avoiding a crash" a good deal.
Should be. But it only does that in a limited number of cases. In the others -- gives a false impression of safety.


Quote:
Originally Posted by Thomas Richter View Post
Again, no. It avoids a memory allocation, and wasteful use of resources.
Not if that memory can be freed by the called program (i'm not saying it can, but i still see no reason why it can't).


Quote:
Originally Posted by Thomas Richter View Post
It is wasteful, whereas the stack cookie requires 10 bytes in the executable. I call that a good deal.
I don't call a good deal, a deal that only works in a very limited number of cases.
(I'm trying here to resist the temptation of saying 10 bytes is actually not enough...)


Quote:
Originally Posted by Thomas Richter View Post
If I can get them that easily, yes.
Even if the cost is extra risk of crashing on other people's setups ?


Quote:
Originally Posted by Thomas Richter View Post
It avoids spending a lot of *time*, which is an important resource. Time developing and time debugging. Besides, the code is quite good in most cases if you know how to handle the compiler.
Time developing, yes. Time debugging, i doubt.
Especially when some users will complain the program crashes and you take a lot of time in debug just to discover their setup did not support the cookie.
If you want to spare time by using a compiler, at least let the compiler setup the stack by more compatible means - i think they can do this.


Quote:
Originally Posted by Thomas Richter View Post
You crash.
And why ? A stack is allocated when running the program and freed afterwards, why would changing it during the program crash anything ?
Is the stack address and size stored in other place than in exec task structure, where it can be changed ?


Quote:
Originally Posted by Thomas Richter View Post
And your point is? The stack cookie works like the stack command. It does not require the program to take any action. The dos.library RunCommand() takes care of the stack allocation and stack release, the shell takes care of supplying it with the right arguments. The stack argument to this call is the maximum of the current stack size noted in the command line interface structure and the contents of the stack cookie, should it exist.
And who reads the stack cookie ?
Certainly not the one calling RunCommand directly. So what about file managers, or worse, debuggers ? Are all possible paths for program execution patched to check the cookie ? I doubt. And now the stack cookie gets ignored in some cases, leaving the user wonder why his program crashes (whereas mere stackswap would have worked everywhere).


Quote:
Originally Posted by grond View Post
Um, I thought we had discussed this already. Use the $STACK cookie, check actual stack size on startup to see whether your program really got enough stack (either by being run on an OS version that does support the cookie or because the user has set enough stack), if not enough stack is present, allocate your own and optionally output a message that asks for the correct stack size for future use. How difficult can this be?
It's not difficult but it only works if all users of the cookie actually do it this way. And i expect it might eventually not be the case.


Quote:
Originally Posted by grond View Post
Actually all your complaining is about how AmigaOS was lacking severely with regard to stack handling right from the start and how this got fixed (more or less) when AmigaOS was already a dead fish in the water. I don't see how Thomas is the right person to complain to.
I'm not complaining. I'm just saying the cookie isn't a proper solution, and ThoR did not agree, hence what we have here.
meynaf is offline  
Old 05 June 2019, 15:04   #34
Don_Adan
Registered User
 
Join Date: Jan 2008
Location: Warsaw/Poland
Age: 56
Posts: 2,029
Quote:
Originally Posted by meynaf View Post
I'm not complaining. I'm just saying the cookie isn't a proper solution, and ThoR did not agree, hence what we have here.
Right, for me ths is dirty hack only, not very useful too. The only good and clean solution is updating dos.library routine LoadSeg for new hunk type StackSize. Maybe exec.library must be updated too, i dont remember.
Don_Adan is offline  
Old 05 June 2019, 15:15   #35
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 3,302
Quote:
Originally Posted by Don_Adan View Post
Right, for me ths is dirty hack only, not very useful too. The only good and clean solution is updating dos.library routine LoadSeg for new hunk type StackSize. Maybe exec.library must be updated too, i dont remember.
Ok, so you update the programs that work on the Amiga hunk structure, would you? Please start with SLink, and let me know when you are done. Until then, I stick to the stack cookie.
Thomas Richter is offline  
Old 05 June 2019, 15:37   #36
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 3,302
Quote:
Originally Posted by meynaf View Post
Yes of course i have read what you have written, but what you have written did not answer the question. The called program can still free the allocated stack and allocate a bigger one. The question was : what could prevent it from doing so.
The stack allocation of RunCommand() is private, and places there a couple of data structures for the BCPL runtime. You cannot deallocate the stack yourself as the way how it was allocated depends on the way how the program was run.
Quote:
Originally Posted by meynaf View Post
Ok, but if the purpose of the cookie is to spare an extra stack, why not merging the stack of the shell with the one of the program, while we're here ?
Because that requires touching a lot of legacy code, the BCPL runtime (emulation) within the dos.library and the working of the shell.
Quote:
Originally Posted by meynaf View Post
It is not hard to understand. But it is not new. No need for a stack cookie for it.
It would have been fine if programs did not need to check their stack size at all. But they sometimes need to, and no amount of cookies will change this.
Once again: Nothing against checking the stack size - but the cookie avoids the reallocation of the stack.
Quote:
Originally Posted by meynaf View Post
No chance of loosing it, huh ? This is simply not true. It will be lost any time some bozo uses a cruncher - yes, a legacy tool - to reduce the size of your executable.
Then it would rather be the job of the cruncher to take care of the cookie or your "customized hunk structure" either. None of that survives the process.
Quote:
Originally Posted by meynaf View Post
A quite likely situation, more likely than with any other type of tool having to parse hunks.
Heck no. Development touches hunks. The linker touches hunks. Worse, it would make the program non-loadable on older versions of the Os.
Quote:
Originally Posted by meynaf View Post
And now the cookie is hidden in crunched data and thus is not able to do what it has been designed to do. Congratulations, flotsam.
Sounds more like an argument against crunching.
Quote:
Originally Posted by meynaf View Post
As if a stack swap could take a significant amount of time... Compare that to the time taken by every program run, by merely scanning the first code hunk (especially in large programs where the cookie is simply not there).
First, I do not care about the time so much - but the memory is wasted - for nothing. The scan is actually quite smart. It only has to read every 7th byte of the first hunk.
Quote:
Originally Posted by meynaf View Post
Should be. But it only does that in a limited number of cases. In the others -- gives a false impression of safety.
A brilliant argument. There is no safety in AmigaOs to begin with. If you want that, go for a serious operating system.
Quote:
Originally Posted by meynaf View Post
Not if that memory can be freed by the called program (i'm not saying it can, but i still see no reason why it can't).
Then tell me how, Mr. Smartipants. There is more on the initial stack RunCommand() puts there, and depends upon. Well, go ahead, write a "stack swapper" that works robustly no matter how the program was run.
Quote:
Originally Posted by meynaf View Post
I don't call a good deal, a deal that only works in a very limited number of cases.
In an increasing number of cases given that the feature costs almost nothing and is trivial to add to programs.
Quote:
Originally Posted by meynaf View Post
Even if the cost is extra risk of crashing on other people's setups ?
The stack cookie never crashes anything. It can only increase the stack.
Quote:
Originally Posted by meynaf View Post
Time developing, yes. Time debugging, i doubt.
Then you never actually wrote and debugged a larger program.
Quote:
Originally Posted by meynaf View Post
Especially when some users will complain the program crashes and you take a lot of time in debug just to discover their setup did not support the cookie.
If you want to spare time by using a compiler, at least let the compiler setup the stack by more compatible means - i think they can do this.
Some compilers can inject stack checking code at the start of each function. Which has a run-time penalty. It's not turned on in any Os component since the checking cost is considered harmful. It is "modestly safe" in the sense of "it works as long as a single function does not eat the entire stack at once".
Quote:
Originally Posted by meynaf View Post
Is the stack address and size stored in other place than in exec task structure, where it can be changed ?
Yes, it is. There is more data on this "stack segment" that you seem to know. It all depends on how the program was launched, but there is, depending on the startup, *) an additional BPCL cookie at the start of the stack *) a pointer to that for the Exit() function in the process structure, *) potentially the name of the program, pointed to by the task structure *) potentially a small startup stub to emulate a segment if the stack was created through CreateNewProc()... ...and multiple other things. How exactly the stack was allocated, and which other structures where allocated along with it depends a lot on how the program was launched. There is more than one method. You cannot get rid of the stack. Only the (implicitly called) exit code of the task or process or command can. There are at least three different ways how the stack could have been created, and they are not easily distinguished from within the running program.
Quote:
Originally Posted by meynaf View Post
And who reads the stack cookie ?
The shell and the workbench, apparently. The same argument can be raised about the stack size in the "icon". This is also read by the workbench, and implemented by the workbench. If programs don't look there... well, then they don't look there. Same goes for the stack cookie. Except that things are even worse for the icon. Change it, or edit it, and loose the information. Here, at least, the cookie is bundled directly with the program, without the chance of getting lost or replaced.
Quote:
Originally Posted by meynaf View Post
I'm not complaining. I'm just saying the cookie isn't a proper solution, and ThoR did not agree, hence what we have here.
There is no "proper" solution for an Os that does not support stack overflow identification. There are only methods that simplify the workflow.
Thomas Richter is offline  
Old 05 June 2019, 16:27   #37
grond
Registered User
 
Join Date: Jun 2015
Location: Germany
Posts: 1,924
Quote:
Originally Posted by Don_Adan View Post
Right, for me ths is dirty hack only, not very useful too.
It's only not very useful because it wasn't introduced with say Kick 1.3 or 2.0 but with something even after 3.1. If it had been introduced much earlier, it would be a perfectly acceptable (because widely accepted) solution for something that was broken from the start.
grond is offline  
Old 05 June 2019, 16:41   #38
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,351
Quote:
Originally Posted by Thomas Richter View Post
Once again: Nothing against checking the stack size - but the cookie avoids the reallocation of the stack.
Scanning every program upon startup just to avoid a simple reallocation on a few of them does not sound very useful to me.


Quote:
Originally Posted by Thomas Richter View Post
Then it would rather be the job of the cruncher to take care of the cookie or your "customized hunk structure" either. None of that survives the process.
Of course, but a mere call to StackSwap does survive the process.
The hunk structure is more the way it should have been done initially.


Quote:
Originally Posted by Thomas Richter View Post
Heck no. Development touches hunks. The linker touches hunks. Worse, it would make the program non-loadable on older versions of the Os.
Right, did not think about this. But then, the linker does not necessarily know it has to put the cookie in the first code hunk...
And if relying on the cookie alone, the program is non-loadable on older versions of the OS (well, actually it is loadable and will fail silently).


Quote:
Originally Posted by Thomas Richter View Post
Sounds more like an argument against crunching.
Maybe. But i've seen a lot more crunched programs than i've seen stack cookies.


Quote:
Originally Posted by Thomas Richter View Post
First, I do not care about the time so much - but the memory is wasted - for nothing. The scan is actually quite smart. It only has to read every 7th byte of the first hunk.
Reading every 7th byte won't make it 7 times faster because said byte needs to be compared against several possible values.
But even if it's fast, what do we have ? Well, the memory wasted is small, the amount of time wasted is small. Seems it's equal at the end. I still prefer using the memory, though, as at least it's always safe.


Quote:
Originally Posted by Thomas Richter View Post
A brilliant argument. There is no safety in AmigaOs to begin with. If you want that, go for a serious operating system.
Being already not very safe, isn't a reason to add more on top of it.
Rather, we should do our possible to make it reasonably safe.


Quote:
Originally Posted by Thomas Richter View Post
Then tell me how, Mr. Smartipants. There is more on the initial stack RunCommand() puts there, and depends upon.
I didn't claim it was possible, just that i did not see a reason why it wouldn't, Mr. Smarty Pants.


Quote:
Originally Posted by Thomas Richter View Post
Well, go ahead, write a "stack swapper" that works robustly no matter how the program was run.
Let me think... a stack swapper that works robustly no matter how the program was run... hey, wait. Yes it's a mere pair of calls to StackSwap !


Quote:
Originally Posted by Thomas Richter View Post
In an increasing number of cases given that the feature costs almost nothing and is trivial to add to programs.
Not that trivial i'm afraid. The compiler may eventually remove it altogether because it was unused data (and the linker put it at the wrong place, as stated above).


Quote:
Originally Posted by Thomas Richter View Post
The stack cookie never crashes anything. It can only increase the stack.
Not the stack cookie itself, of course
It can only increase the stack, but the point is for when it does not !


Quote:
Originally Posted by Thomas Richter View Post
Then you never actually wrote and debugged a larger program.
A bloatware, indeed i haven't.


Quote:
Originally Posted by Thomas Richter View Post
Some compilers can inject stack checking code at the start of each function. Which has a run-time penalty. It's not turned on in any Os component since the checking cost is considered harmful. It is "modestly safe" in the sense of "it works as long as a single function does not eat the entire stack at once".
I was just speaking about compilers using normal stack swap as part of their startup code.


Quote:
Originally Posted by Thomas Richter View Post
The shell and the workbench, apparently. The same argument can be raised about the stack size in the "icon". This is also read by the workbench, and implemented by the workbench. If programs don't look there... well, then they don't look there. Same goes for the stack cookie. Except that things are even worse for the icon. Change it, or edit it, and loose the information. Here, at least, the cookie is bundled directly with the program, without the chance of getting lost or replaced.
If your icon editor deletes information it ought not, you should switch to another one
And if programs don't look there... well, they're broken because it's quite standard way of doing things since very long - which is not the case for the cookie.


Quote:
Originally Posted by Thomas Richter View Post
There is no "proper" solution for an Os that does not support stack overflow identification. There are only methods that simplify the workflow.
Agreed.
It's just that i prefer methods that work regardless of the setup.


Quote:
Originally Posted by grond View Post
It's only not very useful because it wasn't introduced with say Kick 1.3 or 2.0 but with something even after 3.1. If it had been introduced much earlier, it would be a perfectly acceptable (because widely accepted) solution for something that was broken from the start.
Not even. It would still have been a hack.
Why having to scan a whole hunk of data for an info which can be put directly in the header ?
meynaf is offline  
Old 05 June 2019, 16:52   #39
grond
Registered User
 
Join Date: Jun 2015
Location: Germany
Posts: 1,924
Quote:
Originally Posted by meynaf View Post
Of course, but a mere call to StackSwap does survive the process.
The drawback is that if the programmer calculated the need for stack wrong (e.g. when dealing with unexpectedly large objects), stack size can't be increased from the outside without patching the binary.

The argument with the slow loading of the program doesn't seem very convincing because, again, it is up to the user whether he wants to use an updated loader that needs to search the binary for the cookie or not. For all I know typical 3.9BB users aren't of the A500 with 1MB RAM kind.
grond is offline  
Old 05 June 2019, 17:10   #40
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 3,302
Quote:
Originally Posted by meynaf View Post
Of course, but a mere call to StackSwap does survive the process.
The hunk structure is more the way it should have been done initially.
I'm not *against* stackswap. it's just wasteful.
Quote:
Originally Posted by meynaf View Post
Right, did not think about this. But then, the linker does not necessarily know it has to put the cookie in the first code hunk...
You, as the author, have to use the tools such that the cookie appears at a location that is accessible. Which is not particularly difficult. Hint:
Code:
 static const char *stack="$STACK:8192\n";
works nicely for the default configuration. Just place in any source code you like. This is quite "$VER:". As this is a constant string, it ends up in the TEXT segment, like any other constant string.
Quote:
Originally Posted by meynaf View Post
And if relying on the cookie alone, the program is non-loadable on older versions of the OS (well, actually it is loadable and will fail silently).
Heck, no. Why do you continue to tell such nonsense. The program is fully fine. It is just that under such circumstances, you have to deliver either an icon with the proper stack size set, or tell the user "please use the stack command to increase the stack to .. XXX bytes" if run from the shell.
Quote:
Originally Posted by meynaf View Post
Maybe. But i've seen a lot more crunched programs than i've seen stack cookies.
Which is not a miracle given that 3.9 is from a time where floppy disks became obsolete, and thus the need for crunching.
Quote:
Originally Posted by meynaf View Post
Reading every 7th byte won't make it 7 times faster because said byte needs to be compared against several possible values.
Nope. A single read and a table lookup is sufficient. This is not quite as stupid as you seem to imagine.
Quote:
Originally Posted by meynaf View Post
But even if it's fast, what do we have ? Well, the memory wasted is small, the amount of time wasted is small. Seems it's equal at the end. I still prefer using the memory, though, as at least it's always safe.
Then that's you. I prefer that programs tell which resources they require.
Quote:
Originally Posted by meynaf View Post
Being already not very safe, isn't a reason to add more on top of it.
Rather, we should do our possible to make it reasonably safe.
And for that we have a stack cookie, exactly.
Quote:
Originally Posted by meynaf View Post
Let me think... a stack swapper that works robustly no matter how the program was run... hey, wait. Yes it's a mere pair of calls to StackSwap !
You cannot release the stack. You allocate a new one on top.
Quote:
Originally Posted by meynaf View Post
Not that trivial i'm afraid. The compiler may eventually remove it altogether because it was unused data (and the linker put it at the wrong place, as stated above).
See above, no. Give it global lifetime, non-static linkage, constant string, and you will be fine. Slink does not attempt to remove data with external linkage. Things are really easy.
Quote:
Originally Posted by meynaf View Post
I was just speaking about compilers using normal stack swap as part of their startup code. And if programs don't look there... well, they're broken because it's quite standard way of doing things since very long - which is not the case for the cookie.
In other words: Evolution of AmigaOs is worthless because you don't care. That's not an argument against adding functionality.
Quote:
Originally Posted by meynaf View Post
It's just that i prefer methods that work regardless of the setup.
Then setup properly. It's not that 3.9 is *that* new.
Quote:
Originally Posted by meynaf View Post
Not even. It would still have been a hack.
Then $VER is the same hack.
Quote:
Originally Posted by meynaf View Post
Why having to scan a whole hunk of data for an info which can be put directly in the header ?
Because there is no room in the header. The Tripos HUNK structure does not reserve a hunk for it, quite simple. Of course, scanning ends earlier if you put it near the top of the hunk (which is neither hard to arrange).
Thomas Richter is offline  
 


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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 07:30.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.13426 seconds with 13 queries