Commit | Line | Data |
---|---|---|
c906108c SS |
1 | # Reply server mig-output massager |
2 | # | |
0fb0cc75 JB |
3 | # Copyright (C) 1995, 1996, 1999, 2007, 2008, 2009 |
4 | # Free Software Foundation, Inc. | |
c906108c SS |
5 | # |
6 | # Written by Miles Bader <miles@gnu.ai.mit.edu> | |
7 | # | |
8 | # This program is free software; you can redistribute it and/or | |
9 | # modify it under the terms of the GNU General Public License as | |
10 | # published by the Free Software Foundation; either version 2, or (at | |
11 | # your option) any later version. | |
12 | # | |
13 | # This program is distributed in the hope that it will be useful, but | |
14 | # WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | # General Public License for more details. | |
17 | # | |
18 | # You should have received a copy of the GNU General Public License | |
19 | # along with this program; if not, write to the Free Software | |
197e01b6 EZ |
20 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, |
21 | # Boston, MA 02110-1301, USA. | |
c906108c SS |
22 | # |
23 | # This awk script hacks the output of mig-generated reply server code | |
24 | # so that it allows replies with just the error-code in them (as this is | |
25 | # how mig returns errors). | |
26 | # | |
27 | # It is highly, highly, dependent on the exact format of mig output. Ick. | |
28 | # | |
29 | ||
30 | BEGIN { parse_phase = 0; } | |
31 | ||
32 | /^}/ { parse_phase = 0; } | |
33 | ||
34 | parse_phase == 0 && /^mig_internal void _X[a-zA-Z0-9_]*_reply/ { | |
35 | # The start of a mig server routine. Reset everything. Note that we only | |
36 | # mess with rpcs that have the suffix `_reply'. | |
37 | num_args = 0; | |
38 | num_checks = 0; | |
39 | parse_phase = 1; | |
40 | print; next; | |
41 | } | |
42 | ||
43 | parse_phase == 1 && /^[\t ]*typedef struct/ { | |
44 | # The first structure in the server routine should describe the arguments | |
45 | parse_phase = 2; | |
46 | print; next; | |
47 | } | |
48 | ||
49 | parse_phase == 2 { | |
50 | # The message header field in the args structure, which skip. | |
51 | parse_phase = 3; | |
52 | print; next; | |
53 | } | |
54 | ||
55 | parse_phase == 3 && /}/ { | |
56 | # The args structure is over. | |
57 | if (num_args > 1) | |
58 | parse_phase = 5; | |
59 | else | |
60 | # There's no extra args that could screw up the normal mechanism for | |
61 | # error returns, so we don't have to insert any new code. | |
62 | parse_phase = 0; | |
63 | print; next; | |
64 | } | |
65 | ||
66 | parse_phase == 3 { | |
67 | # The type field for an argument. | |
68 | arg_type_code_name[num_args] = $2; | |
69 | sub (/;$/, "", arg_type_code_name[num_args]) # Get rid of the semi-colon | |
70 | parse_phase = 4; | |
71 | print; next; | |
72 | } | |
73 | ||
74 | parse_phase == 4 { | |
75 | # The value field for an argument. | |
76 | arg_name[num_args] = $2; | |
77 | sub (/;$/, "", arg_name[num_args]) # Get rid of the semi-colon | |
78 | arg_type[num_args] = $1; | |
79 | num_args++; | |
80 | parse_phase = 3; | |
81 | print; next; | |
82 | } | |
83 | ||
b970e5bc | 84 | parse_phase == 5 && /^[ \t]*(auto|static) const mach_msg_type_t/ { |
c906108c SS |
85 | # The type check structure for an argument. |
86 | arg_check_name[num_checks] = $4; | |
87 | num_checks++; | |
88 | print; next; | |
89 | } | |
90 | ||
91 | parse_phase == 5 && /^[ \t]*mig_external kern_return_t/ { | |
92 | # The declaration of the user server function for this rpc. | |
93 | user_function_name = $3; | |
94 | print; next; | |
95 | } | |
96 | ||
97 | parse_phase == 5 && /^#if[ \t]TypeCheck/ { | |
98 | # The first args type checking statement; we need to insert our chunk of | |
99 | # code that bypasses all the type checks if this is an error return, after | |
100 | # which we're done until we get to the next function. Handily, the size | |
101 | # of mig's Reply structure is also the size of the alternate Request | |
102 | # structure that we want to check for. | |
103 | print "\tif (In0P->Head.msgh_size == sizeof (Reply)"; | |
104 | print "\t && ! (In0P->Head.msgh_bits & MACH_MSGH_BITS_COMPLEX)"; | |
20249808 | 105 | print "\t && ! BAD_TYPECHECK(&In0P->" arg_type_code_name[0] ", &" arg_check_name[0] ")"; |
c906108c SS |
106 | print "\t && In0P->" arg_name[0] " != 0)"; |
107 | print "\t /* Error return, only the error code argument is passed. */"; | |
108 | print "\t {"; | |
109 | # Force the function into a type that only takes the first two args, via | |
110 | # the temp variable SFUN (is there another way to correctly do this cast?). | |
111 | # This is possibly bogus, but easier than supplying bogus values for all | |
112 | # the other args (we can't just pass 0 for them, as they might not be scalar). | |
113 | printf ("\t kern_return_t (*sfun)(mach_port_t"); | |
114 | for (i = 0; i < num_args; i++) | |
115 | printf (", %s", arg_type[i]); | |
116 | printf (") = %s;\n", user_function_name); | |
117 | print "\t OutP->RetCode = (*(kern_return_t (*)(mach_port_t, kern_return_t))sfun) (In0P->Head.msgh_request_port, In0P->" arg_name[0] ");"; | |
118 | print "\t return;"; | |
119 | print "\t }"; | |
120 | print ""; | |
121 | parse_phase = 0; | |
122 | print; next; | |
123 | } | |
124 | ||
125 | { print; } |