Nickolay Kondratyev
Nickolay Kondratyev

Reputation: 5211

VxWorks 5.5 not filling stack with 0xEEEEEEEE

From taskSpawn VxWorks 5.5 documentation :

"The only resource allocated to a spawned task is a stack of a specified size stackSize, which is allocated from the system memory partition. Stack size should be an even integer. A task control block (TCB) is carved from the stack, as well as any memory required by the task name. The remaining memory is the task's stack and every byte is filled with the value 0xEE for the checkStack( ) facility. See the manual entry for checkStack( ) for stack-size checking aids. "

However when tried to scan the stack by spawning a brand new task:

int scan_the_stack(...)
{
    printf("Going to scan the stack forward\n");

    int i = 0;
    int* stack_addr = &i;
    for (int i = 0; i < 100; i++)
    {
        printf("%d : %X\n", i, *stack_addr);
        stack_addr++;
    }

    return 0;
}

void spawn_scan_stack()
{ 
     taskSpawn("tScanner",     /* name of new task (stored at pStackBase) */
                    150,            /* priority of new task */
                    VX_FP_TASK,     /* task option word */
                    10000,          /* size (bytes) of stack needed plus name */
                    scan_the_stack, /* entry point of new task */
                    0,              /* 1st of 10 req'd args to pass to entryPt */
                    0,0,0,0,0,0,0,0,0);
}

Instead of getting expected consecutive 'EEEEEEEE' I got some 'EE' intermixed with other values:

-> spawn_scan_stack
    value = 80735920 = 0x4cfeeb0
    -> Going to scan the stack forward
    0 : 0
    1 : 4CFEE1C
    2 : 2
    3 : EEEEEEEE
    4 : EEEEEEEE
    5 : EEEEEEEE
    6 : EEEEEEEE
    7 : 0
    8 : 0
    9 : 0
    10 : 4CFEE70
    11 : 2951F4
    12 : 0
    13 : 0
    14 : EEEEEEEE
    15 : EEEEEEEE
    16 : EEEEEEEE
    17 : EEEEEEEE
    18 : EEEEEEEE
    19 : 0
    20 : 0
    21 : 0
    22 : 0
    23 : 0
    24 : EEEEEEEE
    25 : EEEEEEEE
    26 : EEEEEEEE
    27 : EEEEEEEE
    28 : 0
    29 : 0
    30 : 0
    31 : 0
    32 : 0
    33 : 0
    34 : 0
    35 : 0
    36 : 0
    37 : 0
    38 : 0
    39 : 0
    40 : 96
    41 : FF630
    42 : 20
    43 : 11000001
    44 : 19BDD /*...*/

The question is why isn't the stack filled with EEEEEEE (also checkStack seems to be working still).

Upvotes: 1

Views: 699

Answers (2)

mjs
mjs

Reputation: 3005

My initial assumption was that the task had been spawned with VX_NO_STACK_FILL, which tells vxworks not to initialise the stack to 0xEE. But, looking at your code, you just use VX_FP_TASK (for floating point support). So the stack should be correctly initialised.

That really leaves two possibilities. The first (and more unlikely) is that something else is writing where it shouldn't be, but you would likely be seeing strange behaviour elsewhere (and i might expect checkStack to show that something has been smashed)

The second, as already suggested by others is that you are on one of the architectures (such as intel) where the stack grows downwards. The VxWorks Architecture Supplement should tell you which direction the stack grows for your architecture.

You might also be able to tell at compile time by including vxArch.h and testing the value of _STACK_DIR for _STACK_GROWS_DOWN or _STACK_GROWS_UP

Upvotes: 0

Martin James
Martin James

Reputation: 24867

Try 'stack_addr--;' - bet you're on Intel where the stacks grow downwards. You are looking up at valid stack data - return addresses and local vars, some of which are uninitialised.

Upvotes: 1

Related Questions