1 /* 2 * Support for executing code in new tasks and threads. 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 #include <l4/util/util.h> 25 26 #include <exec/process_creator.h> 27 #include <systypes/fcntl.h> 28 #include <systypes/format.h> 29 30 #include <stdio.h> 31 32 33 34 class local_Notifier : public Notifier 35 { 36 public: 37 long notify(notify_flags_t flags, notify_values_t values) 38 { 39 printf("Notified with flags: %" pFMTnotify_flags "x\n", flags); 40 printf("Notified with values: %ld, %ld\n", values.sig, values.val); 41 42 return L4_EOK; 43 } 44 }; 45 46 47 48 int main(int argc, char *argv[]) 49 { 50 long err; 51 52 if (argc < 3) 53 { 54 printf("Need a region mapper and the actual program to run.\n"); 55 return 1; 56 } 57 58 char *rm_filename = argv[1]; 59 char *program_filename = argv[2]; 60 61 ProcessCreator creator(rm_filename); 62 file_t *program_file = client_open(program_filename, O_RDONLY); 63 64 if (!client_opened(program_file)) 65 { 66 printf("Could not open program file.\n"); 67 return 1; 68 } 69 70 local_Notifier notifier; 71 72 creator.set_notifier(¬ifier); 73 err = creator.start(program_file, argc - 2, (const char **) argv + 2); 74 75 if (err) 76 { 77 printf("Could not start process: %s\n", l4sys_errtostr(err)); 78 return 1; 79 } 80 81 printf("Finished program initiation.\n"); 82 printf("End of test.\n"); 83 84 /* NOTE: Should be able to obtain a notification for when the program 85 finishes, which might be done using a capability deletion IRQ. 86 Eventually, this program will operate as a server, invoking new 87 programs and handling termination. This test would then merely 88 involve the invocation of a utility function. */ 89 90 while (1) 91 l4_sleep_forever(); 92 93 return 0; 94 } 95 96 /* vim: tabstop=2 expandtab shiftwidth=2 97 */