stack size

6 posts / 0 new
Last post
alfkil
alfkil's picture
Offline
Last seen: 2 years 8 months ago
Joined: 2011-05-10 22:02
stack size

Is there a way to set the stacksize from within a process? I need a way to set the stacksize other than stack cookie, because I need it to be set from within a shared object (adding a stack cookie to the shared object doesn't work). I have tried

IDOS->System("stack 2000000", TAG_DONE);

but it doesn't seem to work. Help!

salass00
salass00's picture
Offline
Last seen: 1 year 2 months ago
Joined: 2011-02-03 11:27
@alfkil The function you

@alfkil

The function you want is NewStackRun(). It is detailed in the exec.library autodoc.

hypex
hypex's picture
Offline
Last seen: 2 months 1 week ago
Joined: 2011-09-09 16:20
@alfkil LOL! Do you know

@alfkil

LOL! Do you know what you've done?

You've spawned a shell process to run the Stack command. So all the Stack command will do is set the stack for that shell process and then return to you. :-)

alfkil
alfkil's picture
Offline
Last seen: 2 years 8 months ago
Joined: 2011-05-10 22:02
@salass00: How am I supposed

@salass00:

How am I supposed to use this one? What I want is to run _the same_ process in a larger stack frame, not a new process/function/whatever...

salass00
salass00's picture
Offline
Last seen: 1 year 2 months ago
Joined: 2011-02-03 11:27
@alfkil How am I supposed

@alfkil


How am I supposed to use this one?

You are completely unable to read autodocs?

  1. #include <proto/exec.h>
  2. #include <proto/dos.h>
  3.  
  4. int function_that_needs_more_stack (int argc, char **argv);
  5. int32 GetStackSize (void);
  6.  
  7. int main (int argc, char **argv) {
  8. int rc;
  9. IDOS->Printf("main()\n");
  10. IDOS->Printf("Stack Size: %ld\n", GetStackSize());
  11. rc = IExec->NewStackRunTags((APTR)function_that_needs_more_stack,
  12. NSR_StackSize, 1000000,
  13. NSR_Arg1, argc,
  14. NSR_Arg2, argv,
  15. TAG_END);
  16. IDOS->Printf("main() again\n");
  17. IDOS->Printf("Stack Size: %ld\n", GetStackSize());
  18. return rc;
  19. }
  20.  
  21. int function_that_needs_more_stack (int argc, char **argv) {
  22. int i;
  23. IDOS->Printf("function_that_needs_more_stack()\n");
  24. IDOS->Printf("Stack Size: %ld\n", GetStackSize());
  25. IDOS->Printf("argc: %ld\n", argc);
  26. for (i = 0; i < argc; i++) {
  27. IDOS->Printf("argv[%ld]: %s\n", i, argv[i]);
  28. }
  29. return RETURN_OK;
  30. }
  31.  
  32. int32 GetStackSize (void) {
  33. struct Task *task = IExec->FindTask(NULL);
  34. return (int32)task->tc_SPUpper - (int32)task->tc_SPLower;
  35. }


What I want is to run _the same_ process in a larger stack frame, not a new process/function/whatever...

You can't just change the stack in the middle of a C program and then expect it to run to the end without crashing on AmigaOS as this would require in place resizing of the stack memory which is impossible in a shared memory system and with limited (32-bit) memory space.

Not even the stack command that you tried at first really does this. What the stack command just does is it changes the amount of stack that is used for programs run from the console in question (this fact can be confirmed quite easily by using Ranger).

hypex
hypex's picture
Offline
Last seen: 2 months 1 week ago
Joined: 2011-09-09 16:20
@alfkil I agree. You simply

@alfkil

I agree. You simply want a new stack, not to call a complicated routine needing register setup. You could try it with a main() procedure in your object I suppose.

But, I wonder, would StackSwap() do what you need? There isn't much info in the API about it and they really need quick examples in the AutoDocs.

This was so much easier in the 68K days. For example, AmigaE compiled programs swap the stack first thing. By allocating RAM and swapping it to A7. I thought that E programs would break instantly on OS4 because of this but they run perfectly fine! :-)

Log in or register to post comments