make sure "S" is generated.
[AROS-Contrib.git] / bgui / stkext.c
blob81d2436ccabe5f8f667b4322c70113fc58d4bdac
1 /*
2 * @(#) $Header$
3 *
4 * BGUI library
5 * stkext.c
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)
38 struct Task *task;
39 struct EasyStruct easy = {
40 .es_StructSize = sizeof(struct EasyStruct),
41 .es_Flags = 0,
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
50 // allowed limits
52 if ((IPTR)&task >= ((IPTR)task->tc_SPLower + STKMARGIN))
53 return NULL;
55 // It's not safe to do on-the-fly stack extensions
56 // under AROS.
57 for (;;)
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)