1 # Reply server mig-output massager
3 # Copyright (C) 1995-1996, 1999, 2007-2012 Free Software Foundation,
6 # Written by Miles Bader <miles@gnu.ai.mit.edu>
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 3, or (at
11 # your option) any later version.
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.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 # This awk script hacks the output of mig-generated reply server code
22 # so that it allows replies with just the error-code in them (as this is
23 # how mig returns errors).
25 # It is highly, highly, dependent on the exact format of mig output. Ick.
28 BEGIN { parse_phase =
0; }
30 /^
}/ { parse_phase =
0; }
32 parse_phase ==
0 && /^mig_internal void _X
[a
-zA
-Z0
-9_
]*_reply
/ {
33 # The start of a mig server routine. Reset everything. Note that we only
34 # mess with rpcs that have the suffix `_reply'.
41 parse_phase ==
1 && /^
[\t ]*typedef struct
/ {
42 # The first structure in the server routine should describe the arguments
48 # The message header field in the args structure, which skip.
53 parse_phase ==
3 && /}/ {
54 # The args structure is over.
58 # There's no extra args that could screw up the normal mechanism for
59 # error returns, so we don't have to insert any new code.
65 # The type field for an argument.
66 arg_type_code_name
[num_args
] = $
2;
67 sub (/;$
/, "", arg_type_code_name
[num_args
]) # Get rid of the semi-colon
73 # The value field for an argument.
74 arg_name
[num_args
] = $
2;
75 sub (/;$
/, "", arg_name
[num_args
]) # Get rid of the semi-colon
76 arg_type
[num_args
] = $
1;
82 parse_phase ==
5 && /^
[ \t]*(auto
|static
) const mach_msg_type_t
/ {
83 # The type check structure for an argument.
84 arg_check_name
[num_checks
] = $
4;
89 parse_phase ==
5 && /^
[ \t]*mig_external kern_return_t
/ {
90 # The declaration of the user server function for this rpc.
91 user_function_name = $
3;
95 parse_phase ==
5 && /^
#if[ \t]TypeCheck/ {
96 # The first args type checking statement; we need to insert our chunk of
97 # code that bypasses all the type checks if this is an error return, after
98 # which we're done until we get to the next function. Handily, the size
99 # of mig's Reply structure is also the size of the alternate Request
100 # structure that we want to check for.
101 print "\tif (In0P->Head.msgh_size == sizeof (Reply)";
102 print "\t && ! (In0P->Head.msgh_bits & MACH_MSGH_BITS_COMPLEX)";
103 print "\t && ! BAD_TYPECHECK(&In0P->" arg_type_code_name
[0] ", &" arg_check_name
[0] ")";
104 print "\t && In0P->" arg_name
[0] " != 0)";
105 print "\t /* Error return, only the error code argument is passed. */";
107 # Force the function into a type that only takes the first two args, via
108 # the temp variable SFUN (is there another way to correctly do this cast?).
109 # This is possibly bogus, but easier than supplying bogus values for all
110 # the other args (we can't just pass 0 for them, as they might not be scalar).
111 printf ("\t kern_return_t (*sfun)(mach_port_t");
112 for (i =
0; i
< num_args
; i
++)
113 printf (", %s", arg_type
[i
]);
114 printf (") = %s;\n", user_function_name
);
115 print "\t OutP->RetCode = (*(kern_return_t (*)(mach_port_t, kern_return_t))sfun) (In0P->Head.msgh_request_port, In0P->" arg_name
[0] ");";