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 <fsclient/client.h> 27 #include <fsclient/process.h> 28 #include <systypes/fcntl.h> 29 #include <systypes/format.h> 30 31 #include <stdio.h> 32 33 34 35 int main(int argc, char *argv[]) 36 { 37 long err; 38 39 if (argc < 2) 40 { 41 printf("Need the program to run.\n"); 42 return 1; 43 } 44 45 char *program_filename = argv[1]; 46 47 file_t *program_file = client_open(program_filename, O_RDONLY); 48 49 if (!client_opened(program_file)) 50 { 51 printf("Could not open program file.\n"); 52 return 1; 53 } 54 55 /* Create a new process structure. */ 56 57 process_t *process = process_new(); 58 59 /* Start a process for the given program. */ 60 61 err = process_start(process, program_file); 62 63 /* NOTE: Need to be able to send arguments, which would be sent via a context, 64 although capabilities could be sent via arguments. */ 65 66 if (err) 67 { 68 printf("Could not start process: %s\n", l4sys_errtostr(err)); 69 return 1; 70 } 71 72 printf("Finished program initiation.\n"); 73 74 /* Obtain the common notifier. */ 75 76 process_notifier_t *notifier = process_notify_task(); 77 78 /* Subscribe to the process for notifications. */ 79 80 err = process_notify_subscribe(process, NOTIFY_TASK_SIGNAL, notifier); 81 82 if (err) 83 { 84 printf("Could not subscribe to process: %s\n", l4sys_errtostr(err)); 85 return 1; 86 } 87 88 /* Wait for a signal from the process. */ 89 90 err = process_notify_wait_process(process, notifier); 91 92 if (err) 93 { 94 printf("Could not wait for process: %s\n", l4sys_errtostr(err)); 95 return 1; 96 } 97 98 notify_flags_t flags = process_notifications(process); 99 notify_values_t values = process_notification_values(process); 100 101 printf("Notified with flags: %" pFMTnotify_flags "x\n", flags); 102 printf("Notified with values: %ld, %ld\n", values.sig, values.val); 103 104 printf("End of test.\n"); 105 return 0; 106 } 107 108 /* vim: tabstop=2 expandtab shiftwidth=2 109 */