6 * Generic stack extension routines.
8 * Copyright © 2011, The AROS Development Team.
9 * (C) Janne Jalkanen 1998
10 * (C) Copyright 1998 Manuel Lemos.
11 * (C) Copyright 1996-1997 Ian J. Einman.
12 * (C) Copyright 1993-1996 Jaba Development.
13 * (C) Copyright 1993-1996 Jan van den Baard.
14 * All Rights Reserved.
16 * Converted by hand from stkext.asm
20 #include <proto/intuition.h>
21 #include <proto/exec.h>
23 #define STKMARGIN 2048 // When should we start worrying about the stack?
24 #define STKSIZE 16384 // Allocate this much stack space
25 #define CTLBLOCK sizeof(StackSwapStruct)
27 extern struct Task
*InputDevice
;
28 extern APTR InputStack
;
30 /*****************************************************************************
32 * EnsureStack allocates a handle, which must be returned back to RevertStack
34 * Registers preserved: all, except d0 and sp
36 APTR
EnsureStack(VOID
)
39 struct EasyStruct easy
= {
40 .es_StructSize
= sizeof(struct EasyStruct
),
42 .es_Title
= "BGUI Stack Overflow",
43 .es_TextFormat
= "The \"%s\" process is out of stack space.",
44 .es_GadgetFormat
= "Suspend",
46 // Figure out our address
47 task
= FindTask(NULL
);
49 // Calculate current stack left and check if it is within
52 if ((IPTR
)&task
>= ((IPTR
)task
->tc_SPLower
+ STKMARGIN
))
55 // It's not safe to do on-the-fly stack extensions
58 EasyRequest(NULL
, &easy
, NULL
, task
->tc_Node
.ln_Name
);
61 /*****************************************************************************
63 * This function returns the stack back to free memory pool.
64 * Safe to call with NULL args
66 * Registers destroyed: d0/a0/a1/a7
69 VOID
RevertStack(APTR stack
)
73 /*******************************************************************************
75 * This function allocates memory for the input.device stack extension,
76 * which is allocated only during library initialization.
79 VOID
InitInputStack(VOID
)
83 VOID
FreeInputStack(VOID
)