1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/libexec/include/exec/stack.h Tue May 10 22:39:15 2022 +0200
1.3 @@ -0,0 +1,106 @@
1.4 +/*
1.5 + * Stack support for new tasks and threads.
1.6 + *
1.7 + * Copyright (C) 2022 Paul Boddie <paul@boddie.org.uk>
1.8 + *
1.9 + * This program is free software; you can redistribute it and/or
1.10 + * modify it under the terms of the GNU General Public License as
1.11 + * published by the Free Software Foundation; either version 2 of
1.12 + * the License, or (at your option) any later version.
1.13 + *
1.14 + * This program is distributed in the hope that it will be useful,
1.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.17 + * GNU General Public License for more details.
1.18 + *
1.19 + * You should have received a copy of the GNU General Public License
1.20 + * along with this program; if not, write to the Free Software
1.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
1.22 + * Boston, MA 02110-1301, USA
1.23 + */
1.24 +
1.25 +#pragma once
1.26 +
1.27 +#include <l4/re/env.h>
1.28 +#include <l4/re/l4aux.h>
1.29 +
1.30 +#include <exec/segment.h>
1.31 +
1.32 +
1.33 +
1.34 +/* A stack abstraction. */
1.35 +
1.36 +class Stack
1.37 +{
1.38 +protected:
1.39 +
1.40 + /* Auxiliary vector key-value pair. */
1.41 +
1.42 + struct auxv_entry
1.43 + {
1.44 + l4_umword_t key, value;
1.45 + };
1.46 +
1.47 + /* Program segment holding the stack contents. */
1.48 +
1.49 + Segment &_segment;
1.50 +
1.51 + /* Next element pointer. */
1.52 +
1.53 + l4_umword_t *_element;
1.54 +
1.55 + /* Stack section properties. */
1.56 +
1.57 + l4_addr_t _caps;
1.58 + char *_arg_top, *_env_top;
1.59 + char **_argv;
1.60 + char *_auxv_end;
1.61 + int _env_entries;
1.62 +
1.63 + /* L4Re auxiliary and environment regions. */
1.64 +
1.65 + l4re_aux_t *_aux;
1.66 + l4re_env_t *_env;
1.67 +
1.68 + /* Stack pointer start address. */
1.69 +
1.70 + l4_addr_t _start;
1.71 +
1.72 + /* Internal stack population methods. */
1.73 +
1.74 + void push_cap_entries(l4re_env_cap_entry_t *entries);
1.75 +
1.76 + void push_string(char *s);
1.77 +
1.78 + void push_env(char *envp[]);
1.79 +
1.80 + void push_args(int argc, char *argv[]);
1.81 +
1.82 + void push_l4re_aux();
1.83 +
1.84 + void push_l4re_env();
1.85 +
1.86 + void push_auxv();
1.87 +
1.88 + offset_t write_address(char *arg, char **addr, char *s);
1.89 +
1.90 + void push_envp(char *envp[]);
1.91 +
1.92 + void push_argv(int argc, char *argv[]);
1.93 +
1.94 + l4_addr_t align_stack();
1.95 +
1.96 +public:
1.97 + explicit Stack(Segment &segment);
1.98 +
1.99 + void set_l4re_aux(l4re_aux_t *aux);
1.100 +
1.101 + void set_l4re_env(l4re_env_t *env);
1.102 +
1.103 + void populate(int argc, char *argv[], char *envp[]);
1.104 +
1.105 + l4_addr_t start_address();
1.106 +};
1.107 +
1.108 +/* vim: tabstop=2 expandtab shiftwidth=2
1.109 +*/