1 /* 2 * A region mapper for deployment in a new task. 3 * 4 * Copyright (C) 2022, 2023 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 #include <l4/re/env.h> 23 #include <l4/sys/err.h> 24 25 #include <exec/common.h> 26 #include <exec/internal_pager.h> 27 #include <exec/stack.h> 28 #include <fsserver/resource_server.h> 29 30 31 32 /* Initialise a pager for programs, reserving space below the allocated regions 33 for the region mapper itself. */ 34 35 static InternalPager exec_pager(L4_PAGESIZE * 10); 36 37 38 39 int main(int argc, char *argv[]) 40 { 41 /* Initialise pager regions from region descriptions obtained via the 42 auxiliary data. */ 43 44 l4re_aux_t *l4re_aux = exec_get_l4re_aux(argc, argv); 45 46 printf("aux = {%s, %lx, %lx, %lx}\n", l4re_aux->binary, l4re_aux->kip_ds, l4re_aux->dbg_lvl, l4re_aux->ldr_flags); 47 48 /* Skip past the auxiliary structure itself. */ 49 50 struct exec_region *region = (struct exec_region *) *((l4_addr_t *) (l4re_aux + 1)); 51 52 if (!region) 53 { 54 printf("Could not find regions.\n"); 55 return 1; 56 } 57 58 for (; region && (region->ds != L4_INVALID_CAP); region++) 59 { 60 printf("Adding region: {%lx, %llx, %lx, %lx}\n", region->start, region->start + region->size, region->flags, region->ds); 61 MappedRegion r(region->start, region->start + region->size, region->flags, region->ds); 62 exec_pager.add(r); 63 } 64 65 /* Start the pager. */ 66 67 printf("Initialising pager...\n"); 68 printf("Pager capability: %lx\n", l4re_env_get_cap(ENV_INTERNAL_PAGER_NAME)); 69 printf("Main thread: %lx\n", l4re_env()->main_thread); 70 71 /* Initialise the server, enabling notifications. */ 72 73 ResourceServer server(&exec_pager); 74 long err = server.bind(ENV_INTERNAL_PAGER_NAME); 75 76 if (err) 77 { 78 printf("Could not bind server: %s\n", l4sys_errtostr(err)); 79 return 1; 80 } 81 82 printf("Starting pager...\n"); 83 server.start(true); 84 85 printf("Ending pager...\n"); 86 return 0; 87 } 88 89 /* vim: tabstop=2 expandtab shiftwidth=2 90 */