English Amiga Board


Go Back   English Amiga Board > Support > support.AmigaOS

 
 
Thread Tools
Old 31 March 2024, 16:34   #21
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 54
Posts: 4,483
Quote:
Originally Posted by a/b View Post
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.
Yep, I would have used similar code:
Code:
	ULONG upper, lower, total;

    // For CLI tasks, stack bounds are determined differently
    if (currentTask->pr_CLI) {
 ..
    } else {
        upper = (ULONG)currentTask->pr_Task.tc_SPUpper;
        lower = (ULONG)currentTask->pr_Task.tc_SPLower;
        total = upper - lower;
    }
Maybe coder fooled by this warning in types.h?
Code:
  /*  WARNING: APTR was redefined for the V36 Includes!  APTR is a   */
 /*  32-Bit Absolute Memory Pointer.  C pointer math will not	    */
/*  operate on APTR --	use "ULONG *" instead.			   */
...
typedef void *		APTR;	    /* 32-bit untyped pointer */
...
typedef unsigned long	ULONG;	    /* unsigned 32-bit quantity */
Sorry for the invasion, this is not my section
ross is offline  
Old 01 April 2024, 11:11   #22
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,350
To make it short, subtracting two ULONG pointers in C will give result in number of ULONGs, not in number of bytes.
meynaf is offline  
Old 01 April 2024, 13:23   #23
Nightfox
Registered User
 
Nightfox's Avatar
 
Join Date: Apr 2016
Location: Perth, Australia
Posts: 396
Thanks for the feedback. I’ll rework it on the weekend. Sorry about this bug
Nightfox is offline  
Old 01 April 2024, 19:24   #24
nocash
Registered User
 
Join Date: Feb 2016
Location: Homeless
Posts: 64
Why is the amiga os requiring users to specify stack sizes in icons or command line?

I mean, if I would write a program that needs 32Kbyte stack, then I would allocate that memory, or pre-allocate it in bss segment, and then redirect the stack pointer to that memory area... or is there something in the os that prevents doing that?
nocash is offline  
Old 01 April 2024, 20:04   #25
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 3,280
Quote:
Originally Posted by nocash View Post
Why is the amiga os requiring users to specify stack sizes in icons or command line?
A good question, and in general, the user cannot know how much stack an application requires. From 3.1.4 onwards, authors can specify a stack size in their programs as simple as that:
Code:
 UBYTE stack[]="$STACK:32768";
and this will ensure that the program receives 32K stack minimum.
Quote:
Originally Posted by nocash View Post
I mean, if I would write a program that needs 32Kbyte stack, then I would allocate that memory, or pre-allocate it in bss segment, and then redirect the stack pointer to that memory area... or is there something in the os that prevents doing that?
That is in general not recommendable. First of all, you should *also* denote the stack for your program in the task structure (task->tc_Lower and task->tc_Upper) and second, that prevents the user for enlarging the stack should it be necessary because some Os patches between your program and the Os enlarge the size of the stack your program requires. Thus, always leave the flexibility of the stack to the user, but also provide a reasonable default stack size. The above stack-cookie defines a lower bound for the stack, but it can always be overridden by a larger size.
Thomas Richter is online now  
Old 01 April 2024, 22:24   #26
Rotareneg
Registered User
 
Rotareneg's Avatar
 
Join Date: Sep 2017
Location: Kansas, USA
Posts: 328
Quote:
Originally Posted by nocash View Post
Why is the amiga os requiring users to specify stack sizes in icons or command line?
If I remember right it's a relic of its Tripos origins, something to do with BCPL I think?
Rotareneg is offline  
Old 04 April 2024, 07:51   #27
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 3,280
Quote:
Originally Posted by Rotareneg View Post
If I remember right it's a relic of its Tripos origins, something to do with BCPL I think?
Not really. The 68K does not have a MMU, and thus cannot detect if the stack overruns. Thus, unlike in unix operating systems, the Os cannot assist in automatically extending the stack when necessary. You find similar constructions in MacOs, sometimes even weirder ones where you even need to specify the maximum heap a program takes - in the icon of the program.
Thomas Richter is online now  
Old 06 April 2024, 12:23   #28
Nightfox
Registered User
 
Nightfox's Avatar
 
Join Date: Apr 2016
Location: Perth, Australia
Posts: 396
The stack size calculation bug is now fixed in version 1.4.5 which I just released.

Thanks for your assistance everyone. I'll be more careful with pointer arithmetic from now on!

And yep AmigaGPT does use the stack cookie "$STACK:32768" to increase the stack if required but as mentioned, it requires AmigaOS 3.1.4 for that to work. If anyone is using an older version of AmigaOS, they will get a warning if the stack is too small. This would most likely happen if launched from CLI, since the AmigaGPT icon has 32768 set as stack so if launched from Workbench the stack should be automatically set.
Nightfox 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 19:10.

Top

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