English Amiga Board


Go Back   English Amiga Board > Support > support.AmigaOS

 
 
Thread Tools
Old 23 March 2024, 13:36   #1
CCRider
Registered User
 
CCRider's Avatar
 
Join Date: Oct 2017
Location: São Leopoldo / Brazil
Age: 46
Posts: 203
Question Stack size set on icon ignored on 3.2.2.1

Hi there,

Apparently, on my system, the stack size set on a program's .info is being ignored on launch.

My specific test case: AmigaGPT warns if a stack size of at least 32768 isn't set. And despite such value being set on its icon, I get the warn every time I launch it.

Now, if running from the Shell and typing stack 32768 before running the program, such warning doesn't appear.

My system is an Amiga 1200 with TF1260, KS 47.111 and WB 47.4 with no performance patches whatsoever, except for MuFastRom, MuFastChip and MuFastZero.
CCRider is offline  
Old 24 March 2024, 13:45   #2
PeterK
Registered User
 
Join Date: Apr 2005
Location: digital hell, Germany, after 1984, but worse
Posts: 3,367
I've tried out Scout yesterday, a system information tool. Scout also has a stack setting of 32768 in its tool icon, and that stack size really appears in the task list of Scout, too. So, I think that it's not OS 3.2.2 which is responsible for your stack problem.

I still remember that MUI 5 may have some problems in some special cases to get enough stack for some subtasks. If your AmigaGPT program uses MUI 5 then try to install StackAttack with a configuration for a larger stack.
PeterK is online now  
Old 24 March 2024, 17:35   #3
CCRider
Registered User
 
CCRider's Avatar
 
Join Date: Oct 2017
Location: São Leopoldo / Brazil
Age: 46
Posts: 203
AmigaGPT doesn't use MUI, instead it relies completely on AmigaOS's GUI tools.

Maybe it's a bug on it, after all. Weird...
CCRider is offline  
Old 24 March 2024, 18:17   #4
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 3,233
Which type of an icon is that? A project icon or a tool icon?
Thomas Richter is online now  
Old 24 March 2024, 18:36   #5
PeterK
Registered User
 
Join Date: Apr 2005
Location: digital hell, Germany, after 1984, but worse
Posts: 3,367
Sorry, it took a little longer to find that case in my old emails again where the stack problem occured.

In that case it was not MUI 5 directly, not the tool directly, but it was caused by the MagicASL patch, which was injecting MUI 5 with all the stack requirements when the user tried to open an ASL requester with his tool. Since my own tool MinStack didn't support this indirect stack demand, I removed it from Aminet.

But if something similar happens with AmigaGPT, maybe not only loading MUI indirectly, then try StackAttack.
PeterK is online now  
Old 24 March 2024, 19:38   #6
CCRider
Registered User
 
CCRider's Avatar
 
Join Date: Oct 2017
Location: São Leopoldo / Brazil
Age: 46
Posts: 203
Quote:
Originally Posted by Thomas Richter View Post
Which type of an icon is that? A project icon or a tool icon?
Tool icon.
CCRider is offline  
Old 25 March 2024, 07:37   #7
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
Does it still happen if trying to setup a stack that's bigger than the minimum requirement ?
meynaf is offline  
Old 25 March 2024, 21:57   #8
CCRider
Registered User
 
CCRider's Avatar
 
Join Date: Oct 2017
Location: São Leopoldo / Brazil
Age: 46
Posts: 203
Quote:
Originally Posted by meynaf View Post
Does it still happen if trying to setup a stack that's bigger than the minimum requirement ?
Yep. I tried setting it on Workbench Prefs (to 32 KB), and nothing changed.
CCRider is offline  
Old 25 March 2024, 23:59   #9
klx300r
Registered User
 
klx300r's Avatar
 
Join Date: Oct 2007
Location: Toronto, Canada
Posts: 1,595
Thumbs up

@ CCRider


try this as it helped me quite a bit over the years with stack issues


http://aminet.net/package/util/boot/StackAttack2
klx300r is offline  
Old 27 March 2024, 19:35   #10
PeterK
Registered User
 
Join Date: Apr 2005
Location: digital hell, Germany, after 1984, but worse
Posts: 3,367
AmigaGPT seems indeed to have a bug. When reading the stack size from its tool icon it divides the size by 4 by mistake! So, for an entry of 32768 it just sees 8192 bytes of stack.

When I tried 140000 for the stack setting AmigaGPT didn't complain anymore, but 131072 should also work (not tested).
PeterK is online now  
Old 27 March 2024, 20:51   #11
CCRider
Registered User
 
CCRider's Avatar
 
Join Date: Oct 2017
Location: São Leopoldo / Brazil
Age: 46
Posts: 203
Quote:
Originally Posted by PeterK View Post
AmigaGPT seems indeed to have a bug. When reading the stack size from its tool icon it divides the size by 4 by mistake! So, for an entry of 32768 it just sees 8192 bytes of stack.

When I tried 140000 for the stack setting AmigaGPT didn't complain anymore, but 131072 should also work (not tested).
Whoa. It seems you nailed it! Will report to the dev.
CCRider is offline  
Old 29 March 2024, 13:04   #12
CCRider
Registered User
 
CCRider's Avatar
 
Join Date: Oct 2017
Location: São Leopoldo / Brazil
Age: 46
Posts: 203
Quote:
Originally Posted by PeterK View Post
AmigaGPT seems indeed to have a bug. When reading the stack size from its tool icon it divides the size by 4 by mistake! So, for an entry of 32768 it just sees 8192 bytes of stack.

When I tried 140000 for the stack setting AmigaGPT didn't complain anymore, but 131072 should also work (not tested).
Tried here, and indeed 131072 is the lower limit where the warning doesn't appear.

Unfortunately, the author doesn't seem convinced that the bug is on his side.
CCRider is offline  
Old 29 March 2024, 13:30   #13
PeterK
Registered User
 
Join Date: Apr 2005
Location: digital hell, Germany, after 1984, but worse
Posts: 3,367
It's not the problem that AmigaGPT won't get enough stack with a setting of 32768, it really gets what it needs (you can see that in Scout's tasklist or with other stack monitoring tools). AmigaGPT just seems to have a bug in code which checks the stack size, maybe a shift right by 2 bits accidentally?

And I did my test on OS 3.9 with Rom 3.1.4, not on OS 3.2.2.x. For a MinStack value of 50000 AmigaGPT complained about getting 12500 only. Thousands of programs would have crashed in the past if that was true and a bug of the OS.
PeterK is online now  
Old 29 March 2024, 14:25   #14
PeterK
Registered User
 
Join Date: Apr 2005
Location: digital hell, Germany, after 1984, but worse
Posts: 3,367
Exactly as supposed: AmigaGPT divides the stack size by 4 with a shift right 2 bits:
Code:
...
lab_b8:
   move.l  $3e(a2),d0  ; 19d0 : 202a 003e
   sub.l   $3a(a2),d0  ; 19d4 : 90aa 003a      stack size
   asr.l   #2,d0       ; 19d8 : e480           shift right by 2 !!
   cmpi.l  #$7fff,d0   ; 19da : 0c80 0000 7fff compare with 32767
   bhi.w   lab_b0      ; 19e0 : 6200 fcf8
lab_b9:
   move.l  d0,-(sp)    ; 19e4 : 2f00
   pea     lab_6c(pc)  ; 19e6 : 487a f4d9      stack warning
   bsr.l   _printf     ; 19ea : 61ff 0000 b658
   addq.l  #8,sp       ; 19f0 : 508f
...
Attached Thumbnails
Click image for larger version

Name:	AmigaGPT_Stack32768.png
Views:	49
Size:	40.6 KB
ID:	81929  
PeterK is online now  
Old 29 March 2024, 14:33   #15
CCRider
Registered User
 
CCRider's Avatar
 
Join Date: Oct 2017
Location: São Leopoldo / Brazil
Age: 46
Posts: 203
Nice findings!

Informed the dev about them... Thanks a lot!
CCRider is offline  
Old 31 March 2024, 13:22   #16
Nightfox
Registered User
 
Nightfox's Avatar
 
Join Date: Apr 2016
Location: Perth, Australia
Posts: 385
Hey, the dev here

I don't get why it would divide by 4. In my testing it does actually work for me.

Here'e the code that does all the work:

Code:
	struct Process *currentTask = (struct Process*)FindTask(NULL);
	struct CommandLineInterface *cli = (struct CommandLineInterface *)BADDR(currentTask->pr_CLI);

	/* If we started from Workbench then we must retrieve the startup message
	 before doing anything else. The startup message also contains a lock on
	 the program directory. */
	if (cli == NULL) {
		wbStartupMessage = (struct WBStartup*)GetMsg(&currentTask->pr_MsgPort);
	}

	ULONG *upper, *lower, total;

    // For CLI tasks, stack bounds are determined differently
    if (currentTask->pr_CLI) {
        upper = (ULONG *)currentTask->pr_ReturnAddr + sizeof(ULONG);
        total = *(ULONG *)currentTask->pr_ReturnAddr;
        lower = upper - total;
    } else {
        upper = (ULONG *)currentTask->pr_Task.tc_SPUpper;
        lower = (ULONG *)currentTask->pr_Task.tc_SPLower;
        total = upper - lower;
    }

	if (total < 32768) {
		printf("Warning: The stack size of %ld bytes is too small. The minimum recommended stack size is 32768 bytes to avoid crashes.\n", total);
	}
Nightfox is offline  
Old 31 March 2024, 13:28   #17
a/b
Registered User
 
Join Date: Jun 2016
Location: europe
Posts: 1,039
Because those are ULONG pointers, not BYTE pointers.
a/b is offline  
Old 31 March 2024, 14:01   #18
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 3,233
[QUOTE=Nightfox;1677059]Hey, the dev here

I don't get why it would divide by 4. In my testing it does actually work for me.

Here'e the code that does all the work:
Code:
     // For CLI tasks, stack bounds are determined differently
That is not correct. For the CLI, stack bounds are determined exactly as the stack bounds for the workbench. The shell or rather RunCommand() performs a complete stack swap and the stack bounds in the task structure are the correct one. The ReturnAddr is a legacy mechanism for BCPL programs.
Thomas Richter is online now  
Old 31 March 2024, 15:08   #19
PeterK
Registered User
 
Join Date: Apr 2005
Location: digital hell, Germany, after 1984, but worse
Posts: 3,367
Quote:
Originally Posted by Nightfox View Post
... I don't get why it would divide by 4. In my testing it does actually work for me.

Here'e the code that does all the work:

Code:
...
 else {
        upper = (ULONG *)currentTask->pr_Task.tc_SPUpper;
        lower = (ULONG *)currentTask->pr_Task.tc_SPLower;
        total = upper - lower;
    }

	if (total < 32768) {
		printf("Warning: The stack size of %ld bytes is too small. The minimum recommended stack size is 32768 bytes to avoid crashes.\n", total);
	}
Code:
...
lab_b8:
   move.l  $3e(a2),d0  ; 19d0 : 202a 003e
   sub.l   $3a(a2),d0  ; 19d4 : 90aa 003a      stack size
   asr.l   #2,d0       ; 19d8 : e480           shift right by 2 !!
   cmpi.l  #$7fff,d0   ; 19da : 0c80 0000 7fff compare with 32767
   bhi.w   lab_b0      ; 19e0 : 6200 fcf8
lab_b9:
   move.l  d0,-(sp)    ; 19e4 : 2f00
   pea     lab_6c(pc)  ; 19e6 : 487a f4d9      stack warning
   bsr.l   _printf     ; 19ea : 61ff 0000 b658
   addq.l  #8,sp       ; 19f0 : 508f
My ADis disassembler code is from AmigaGPT 1.4.4 for OS 3.x.

I'm not a C coder and have no experience with GCC, but maybe there is a bug in the compiler, because both tc_SPUpper and tc_SPLower are APTR pointers, so there is no reason to shift anything by 2 in any direction. Please check your includes for the correct declaration of both pointers.

And the compiler also compares the stack size with 32767 in asm and not with 32768 as in your C code, maybe just an optimization, but if a compiler makes changes like that, then the resulting asm code gets unpredictable. I can send you the complete disassembler listing, but didn't want to publish it here without your permission.
PeterK is online now  
Old 31 March 2024, 15:54   #20
a/b
Registered User
 
Join Date: Jun 2016
Location: europe
Posts: 1,039
As I said, he is recasting upper and lower to ULONG*, so when a pointer subtraction happens the result is also normalized.
If you inc/dec (++/--) a ULONG pointer, it's increased/decreased by 4, not by 1. M68K asm works the same way (predec/postinc are the operand size, not 1).
Use void*, char*, (un)signed byte* or similar instead of ULONG* (or multiply total by sizeof(ULONG) after subtraction) to get the size in bytes.
a/b 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
Custom stack size for own application neoman Coders. System 14 14 October 2022 17:47
Supervisor stack size? alpine9000 Coders. System 71 09 June 2019 01:36
Stack position and size hop Coders. Asm / Hardware 2 26 May 2019 18:20
Get Icon size? volvo_0ne Coders. AMOS 2 13 November 2018 19:56
Icon size mritter0 support.Other 1 23 May 2014 08:46

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 20:26.

Top

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