1 /* 2 * Stack support for new tasks and threads. 3 * 4 * Copyright (C) 2022 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #pragma once 23 24 #include <l4/re/env.h> 25 26 #include <exec/common.h> 27 #include <exec/segment.h> 28 29 30 31 /* A stack abstraction. */ 32 33 class Stack 34 { 35 protected: 36 37 /* Program segment holding the stack contents. */ 38 39 Segment &_segment; 40 41 /* Next element pointer. */ 42 43 l4_umword_t *_element; 44 45 /* Stack section properties. */ 46 47 l4_addr_t _regions = 0; 48 l4_addr_t _caps = 0; 49 int _num_caps = 0; 50 char *_arg_top, *_env_top; 51 char **_argv; 52 char *_auxv_end; 53 int _env_entries = 0; 54 55 /* L4Re auxiliary and environment regions. */ 56 57 l4re_aux_t *_aux; 58 l4re_env_t *_env; 59 60 /* Any indicated initial capabilities and regions. */ 61 62 l4re_env_cap_entry_t *_cap_entries = NULL; 63 struct exec_region *_region_entries = NULL; 64 65 /* Stack pointer start address. */ 66 67 l4_addr_t _start; 68 69 /* Internal stack population methods. */ 70 71 void push_string(const char *s); 72 73 void push_env(const char *envp[]); 74 75 void push_args(int argc, const char *argv[]); 76 77 void push_l4re_aux(); 78 79 void push_l4re_env(); 80 81 void push_auxv(); 82 83 void push_init_caps(); 84 85 void push_regions(); 86 87 offset_t write_address(char *arg, char **addr, const char *s); 88 89 void push_envp(const char *envp[]); 90 91 void push_argv(int argc, const char *argv[]); 92 93 l4_addr_t align_stack(); 94 95 public: 96 explicit Stack(Segment &segment); 97 98 void set_init_caps(l4re_env_cap_entry_t *entries); 99 100 void set_regions(struct exec_region *regions); 101 102 void set_l4re_aux(l4re_aux_t *aux); 103 104 void set_l4re_env(l4re_env_t *env); 105 106 void populate(int argc, const char *argv[], const char *envp[]); 107 108 l4_addr_t start_address(); 109 }; 110 111 /* vim: tabstop=2 expandtab shiftwidth=2 112 */