paul@308 | 1 | /* |
paul@308 | 2 | * Support for executing code in new tasks and threads. |
paul@308 | 3 | * |
paul@477 | 4 | * Copyright (C) 2022, 2023 Paul Boddie <paul@boddie.org.uk> |
paul@308 | 5 | * |
paul@308 | 6 | * This program is free software; you can redistribute it and/or |
paul@308 | 7 | * modify it under the terms of the GNU General Public License as |
paul@308 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@308 | 9 | * the License, or (at your option) any later version. |
paul@308 | 10 | * |
paul@308 | 11 | * This program is distributed in the hope that it will be useful, |
paul@308 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@308 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@308 | 14 | * GNU General Public License for more details. |
paul@308 | 15 | * |
paul@308 | 16 | * You should have received a copy of the GNU General Public License |
paul@308 | 17 | * along with this program; if not, write to the Free Software |
paul@308 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@308 | 19 | * Boston, MA 02110-1301, USA |
paul@308 | 20 | */ |
paul@308 | 21 | |
paul@308 | 22 | #include <l4/re/env.h> |
paul@308 | 23 | #include <l4/sys/err.h> |
paul@312 | 24 | #include <l4/util/util.h> |
paul@308 | 25 | |
paul@483 | 26 | #include <fsclient/client.h> |
paul@483 | 27 | #include <fsclient/process.h> |
paul@477 | 28 | #include <systypes/fcntl.h> |
paul@480 | 29 | #include <systypes/format.h> |
paul@312 | 30 | |
paul@308 | 31 | #include <stdio.h> |
paul@308 | 32 | |
paul@308 | 33 | |
paul@308 | 34 | |
paul@308 | 35 | int main(int argc, char *argv[]) |
paul@308 | 36 | { |
paul@308 | 37 | long err; |
paul@308 | 38 | |
paul@483 | 39 | if (argc < 2) |
paul@308 | 40 | { |
paul@483 | 41 | printf("Need the program to run.\n"); |
paul@370 | 42 | return 1; |
paul@370 | 43 | } |
paul@370 | 44 | |
paul@483 | 45 | char *program_filename = argv[1]; |
paul@370 | 46 | |
paul@477 | 47 | file_t *program_file = client_open(program_filename, O_RDONLY); |
paul@369 | 48 | |
paul@477 | 49 | if (!client_opened(program_file)) |
paul@365 | 50 | { |
paul@477 | 51 | printf("Could not open program file.\n"); |
paul@370 | 52 | return 1; |
paul@370 | 53 | } |
paul@370 | 54 | |
paul@483 | 55 | /* Create a new process structure and obtain the common notifier. */ |
paul@483 | 56 | |
paul@483 | 57 | process_t *process = process_new(); |
paul@483 | 58 | process_notifier_t *notifier = process_notify_task(); |
paul@480 | 59 | |
paul@483 | 60 | /* Start a process for the given program, specifying a notifier from which an |
paul@483 | 61 | endpoint will be obtained for notifications. */ |
paul@483 | 62 | |
paul@483 | 63 | err = process_start(process, program_file, notifier); |
paul@483 | 64 | |
paul@483 | 65 | /* NOTE: Need to be able to send arguments, which would be sent via a context, |
paul@483 | 66 | although capabilities could be sent via arguments. */ |
paul@308 | 67 | |
paul@308 | 68 | if (err) |
paul@308 | 69 | { |
paul@477 | 70 | printf("Could not start process: %s\n", l4sys_errtostr(err)); |
paul@308 | 71 | return 1; |
paul@308 | 72 | } |
paul@308 | 73 | |
paul@402 | 74 | printf("Finished program initiation.\n"); |
paul@483 | 75 | |
paul@483 | 76 | /* Wait for a signal from the process. */ |
paul@483 | 77 | |
paul@483 | 78 | err = process_notify_wait_process(process, notifier); |
paul@402 | 79 | |
paul@483 | 80 | notify_flags_t flags = process_notifications(process); |
paul@483 | 81 | notify_values_t values = process_notification_values(process); |
paul@376 | 82 | |
paul@483 | 83 | printf("Notified with flags: %" pFMTnotify_flags "x\n", flags); |
paul@483 | 84 | printf("Notified with values: %ld, %ld\n", values.sig, values.val); |
paul@308 | 85 | |
paul@483 | 86 | printf("End of test.\n"); |
paul@308 | 87 | return 0; |
paul@308 | 88 | } |
paul@308 | 89 | |
paul@308 | 90 | /* vim: tabstop=2 expandtab shiftwidth=2 |
paul@308 | 91 | */ |