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 #include <l4/re/l4aux.h> 26 27 #include <exec/segment.h> 28 29 30 31 /* A stack abstraction. */ 32 33 class Stack 34 { 35 protected: 36 37 /* Auxiliary vector key-value pair. */ 38 39 struct auxv_entry 40 { 41 l4_umword_t key, value; 42 }; 43 44 /* Program segment holding the stack contents. */ 45 46 Segment &_segment; 47 48 /* Next element pointer. */ 49 50 l4_umword_t *_element; 51 52 /* Stack section properties. */ 53 54 l4_addr_t _caps; 55 char *_arg_top, *_env_top; 56 char **_argv; 57 char *_auxv_end; 58 int _env_entries; 59 60 /* L4Re auxiliary and environment regions. */ 61 62 l4re_aux_t *_aux; 63 l4re_env_t *_env; 64 65 /* Stack pointer start address. */ 66 67 l4_addr_t _start; 68 69 /* Internal stack population methods. */ 70 71 void push_cap_entries(l4re_env_cap_entry_t *entries); 72 73 void push_string(char *s); 74 75 void push_env(char *envp[]); 76 77 void push_args(int argc, char *argv[]); 78 79 void push_l4re_aux(); 80 81 void push_l4re_env(); 82 83 void push_auxv(); 84 85 offset_t write_address(char *arg, char **addr, char *s); 86 87 void push_envp(char *envp[]); 88 89 void push_argv(int argc, char *argv[]); 90 91 l4_addr_t align_stack(); 92 93 public: 94 explicit Stack(Segment &segment); 95 96 void set_l4re_aux(l4re_aux_t *aux); 97 98 void set_l4re_env(l4re_env_t *env); 99 100 void populate(int argc, char *argv[], char *envp[]); 101 102 l4_addr_t start_address(); 103 }; 104 105 /* vim: tabstop=2 expandtab shiftwidth=2 106 */