1 /* 2 * A pipe server. 3 * 4 * Copyright (C) 2020, 2021, 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/debugger.h> 24 #include <l4/sys/err.h> 25 26 #include <ipc/thread.h> 27 28 #include <stdio.h> 29 #include <stdlib.h> 30 31 #include <mem/memory_incremental.h> 32 #include <fsserver/pipe_opener_resource.h> 33 #include <resource/resource_server.h> 34 #include <systypes/env.h> 35 36 37 38 /* Server program. */ 39 40 int main(int argc, char *argv[]) 41 { 42 l4_debugger_set_object_name(l4re_env()->main_thread, "pipe_server"); 43 long err; 44 45 /* Introduce concurrency control. */ 46 47 err = ipc_thread_init(); 48 49 if (err) 50 { 51 printf("Initialisation error: %s\n", l4sys_errtostr(err)); 52 return 1; 53 } 54 55 unsigned int memory_pages = 0; 56 57 if (argc > 1) 58 memory_pages = atoi(argv[1]); 59 60 /* Some memory plus infrastructure. */ 61 62 Memory *mem = NULL; 63 64 if (memory_pages) 65 mem = new MemoryIncremental(memory_pages); 66 else 67 mem = new MemoryIncremental(); 68 69 PipeOpenerResource opener(mem); 70 71 /* Register a server associating it with the given object. */ 72 73 const char *server_name = (argc > 2) ? argv[2] : ENV_PIPE_SERVER_NAME; 74 75 ResourceServer server(&opener); 76 err = server.bind(server_name); 77 78 if (err) 79 { 80 printf("Could not bind server: %s\n", l4sys_errtostr(err)); 81 return 1; 82 } 83 84 printf("Starting server using %d pages...\n", memory_pages); 85 server.start(); 86 return 0; 87 } 88 89 // vim: tabstop=2 expandtab shiftwidth=2