1/*
2 * Copyright 2017, Data61
3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO)
4 * ABN 41 687 119 230.
5 *
6 * This software may be distributed and modified according to the terms of
7 * the BSD 2-Clause license. Note that NO WARRANTY is provided.
8 * See "LICENSE_BSD2.txt" for details.
9 *
10 * @TAG(DATA61_BSD)
11 */
12
13#include <errno.h>
14#include <stddef.h>
15#include <vspace/vspace.h>
16#include <sel4utils/stack.h>
17#include <sel4utils/util.h>
18#include <utils/stack.h>
19
20int
21sel4utils_run_on_stack(vspace_t *vspace, void * (*func)(void *arg), void *arg, void **retval)
22{
23    void *stack_top = vspace_new_stack(vspace);
24    if (stack_top == NULL) {
25        ZF_LOGE("Failed to allocate new stack\n");
26        return -1;
27    }
28
29    void *ret = utils_run_on_stack(stack_top, func, arg);
30    if (retval != NULL) {
31        *retval = ret;
32    }
33
34    return 0;
35}
36