1 /* 2 * (c) 2008-2010 Alexander Warg <warg@os.inf.tu-dresden.de> 3 * economic rights: Technische Universität Dresden (Germany) 4 * 5 * This file is part of TUD:OS and distributed under the terms of the 6 * GNU General Public License 2. 7 * Please see the COPYING-GPL-2 file for details. 8 */ 9 #pragma once 10 11 #include <l4/re/util/cap_alloc> 12 #include <l4/sys/capability> 13 #include <l4/re/dataspace> 14 #include <l4/sys/types.h> 15 #include <l4/libloader/remote_mem> 16 #include <l4/re/rm> 17 #include <l4/re/error_helper> 18 19 class Stack_base 20 { 21 protected: 22 L4Re::Util::Ref_cap<L4Re::Dataspace>::Cap _stack_ds; 23 L4Re::Rm::Unique_region<char*> _vma; 24 25 l4_addr_t _last_checked; 26 Stack_base()27 Stack_base() : _last_checked(0) {} 28 check_access(char * addr,size_t sz)29 void check_access(char *addr, size_t sz) 30 { 31 if (_last_checked != l4_trunc_page(l4_addr_t(addr))) 32 { 33 l4_addr_t offs = l4_trunc_page(addr - _vma.get()); 34 l4_addr_t end = l4_round_page(addr + sz - _vma.get()); 35 L4Re::chksys(_stack_ds->allocate(offs, end - offs)); 36 _last_checked = l4_trunc_page(l4_addr_t(addr)); 37 } 38 39 } 40 }; 41 42 class Stack : public Ldr::Remote_stack<Stack_base> 43 { 44 public: Stack()45 explicit Stack() : Ldr::Remote_stack<Stack_base>(0) {} 46 void set_stack(L4Re::Util::Ref_cap<L4Re::Dataspace>::Cap const &ds, unsigned size); 47 }; 48