1 /* 2 * Test dataspace operations. 3 * 4 * Copyright (C) 2020, 2021, 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/sys/debugger.h> 23 #include <l4/sys/err.h> 24 25 #include <ipc/thread.h> 26 27 #include <stdio.h> 28 #include <stdlib.h> 29 30 #include <mem/memory_incremental.h> 31 #include <mem/memory_utils.h> 32 #include <fsserver/page_queue_shared.h> 33 #include <fsserver/pages.h> 34 #include <fsserver/test_file_opener.h> 35 #include <resource/resource_server.h> 36 #include <systypes/env.h> 37 38 39 40 const unsigned int REGION_PAGES = 8; 41 const unsigned int MEMORY_PAGES = REGION_PAGES * 10; 42 const unsigned int FILE_PAGES = 20; 43 44 int main(int argc, char *argv[]) 45 { 46 l4_debugger_set_object_name(l4re_env()->main_thread, "test_server"); 47 long err; 48 49 /* Introduce concurrency control. */ 50 51 err = ipc_thread_init(); 52 53 if (err) 54 { 55 printf("Initialisation error: %s\n", l4sys_errtostr(err)); 56 return 1; 57 } 58 59 /* Configure the number of available pages using any argument. */ 60 61 unsigned int memory_pages = MEMORY_PAGES; 62 63 if (argc > 1) 64 memory_pages = atoi(argv[1]) * REGION_PAGES; 65 66 /* Some memory plus infrastructure. */ 67 68 MemoryIncremental mem(memory_pages, page(REGION_PAGES)); 69 PageQueueShared queue; 70 Pages pages(&mem, &queue); 71 ResourceRegistry registry(&pages); 72 TestFileOpener opener(®istry, page(FILE_PAGES)); 73 74 /* Register a server associating it with the given object. */ 75 76 const char *server_name = (argc > 2) ? argv[2] : ENV_FILESYSTEM_SERVER_NAME; 77 78 ResourceServer server(&opener); 79 err = server.bind(server_name); 80 81 if (err) 82 { 83 printf("Could not bind server: %s\n", l4sys_errtostr(err)); 84 return 1; 85 } 86 87 printf("Starting server...\n"); 88 server.start(); 89 return 0; 90 } 91 92 // vim: tabstop=2 expandtab shiftwidth=2