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