1 /* 2 * Generation of server dispatch and handle functions. 3 * 4 * Copyright (C) 2019 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 <stdlib.h> 23 #include "common.h" 24 #include "dispatch.h" 25 #include "templates.h" 26 27 28 29 /* Generate dispatch function signatures. */ 30 31 void write_dispatcher_signature(const char *name, enum signature_role role, 32 FILE *fp) 33 { 34 fprintf(fp, dispatch_function_signature, name, name); 35 fputs(get_signature_terminator(role), fp); 36 } 37 38 /* Generate handler function signatures. */ 39 40 void write_handler_signature(const char *name, enum signature_role role, 41 FILE *fp) 42 { 43 fprintf(fp, handle_function_signature, name, name); 44 fputs(get_signature_terminator(role), fp); 45 } 46 47 /* Generate a dispatch function for the different operations. */ 48 49 void write_dispatcher(struct signature *sig, FILE *fp, struct interface *iface) 50 { 51 write_dispatcher_signature(iface->name, DEFINITION_ROLE, fp); 52 53 /* Interpret an operation indicator in the word data if a protocol applies to 54 the entire interface. */ 55 56 if (get_protocol(iface->attributes)) 57 fputs(" switch (ipc_message_get_word(msg, 0))\n {\n", fp); 58 else 59 fputs(" switch (l4_msgtag_label(msg->tag))\n {\n", fp); 60 61 write_dispatcher_cases(sig, fp, iface, 0); 62 fputs(server_function_dispatcher_body_epilogue, fp); 63 64 fputs("}\n", fp); 65 } 66 67 /* Generate each dispatch possibility within an interface. */ 68 69 void write_dispatcher_cases(struct signature *sig, FILE *fp, 70 struct interface *iface, int compound) 71 { 72 char *opcode, *opname, *protocol, *prefix, *ref, *s; 73 74 if (sig == NULL) 75 return; 76 77 opname = get_operation_name(iface, sig); 78 opcode = get_opcode_identifier(NULL, opname); 79 prefix = get_operation_wrapper_prefix(sig->attributes); 80 ref = get_object_conversion(iface, compound); 81 82 /* Generate a reply if appropriate. */ 83 84 if (have_attribute(sig->attributes, "completion")) 85 s = dispatch_function_wrapper_case; 86 else 87 s = dispatch_function_reply_wrapper_case; 88 89 /* Generate the case and invocation. */ 90 91 fprintf(fp, s, opcode, prefix, opname, ref); 92 93 /* Generate the other cases. */ 94 95 write_dispatcher_cases(sig->tail, fp, iface, compound); 96 97 /* Free allocated strings. */ 98 99 free(opcode); 100 free(opname); 101 free(ref); 102 }