File indexing completed on 2024-05-03 22:28:20
85ed45e37… Alex*0001
767e6f6f9… Alex*0002
5bc78089d… Alex*0003
0ea28a649… Dani*0004
767e6f6f9… Alex*0005
0006
0007
0799c1a78… Alex*0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
360a3f914… Jona*0020
0799c1a78… Alex*0021
bd007ba1f… Fran*0022 use strict;
767e6f6f9… Alex*0023
bd007ba1f… Fran*0024 my %formats =
f4ec583d0… Alex*0025 (
0026 "int" => [ 4, 4, "%d" ],
0027 "short int" => [ 2, 2, "%d" ],
0028 "char" => [ 1, 1, "%c" ],
0029 "unsigned char" => [ 1, 1, "%02x" ],
0030 "unsigned short"=> [ 2, 2, "%04x" ],
0031 "unsigned int" => [ 4, 4, "%08x" ],
0032 "data_size_t" => [ 4, 4, "%u" ],
0033 "obj_handle_t" => [ 4, 4, "%04x" ],
0c914e475… Alex*0034 "atom_t" => [ 4, 4, "%04x" ],
f4ec583d0… Alex*0035 "user_handle_t" => [ 4, 4, "%08x" ],
0036 "process_id_t" => [ 4, 4, "%04x" ],
0037 "thread_id_t" => [ 4, 4, "%04x" ],
947976f22… Alex*0038 "client_ptr_t" => [ 8, 8, "&dump_uint64" ],
f2c4e09e8… Alex*0039 "mod_handle_t" => [ 8, 8, "&dump_uint64" ],
3cd817b53… Alex*0040 "lparam_t" => [ 8, 8, "&dump_uint64" ],
a6216ab92… Alex*0041 "apc_param_t" => [ 8, 8, "&dump_uint64" ],
29d975915… Alex*0042 "file_pos_t" => [ 8, 8, "&dump_uint64" ],
0043 "mem_size_t" => [ 8, 8, "&dump_uint64" ],
913e792b5… Alex*0044 "affinity_t" => [ 8, 8, "&dump_uint64" ],
f4ec583d0… Alex*0045 "timeout_t" => [ 8, 8, "&dump_timeout" ],
321d26cbb… Piot*0046 "abstime_t" => [ 8, 8, "&dump_abstime" ],
f4ec583d0… Alex*0047 "rectangle_t" => [ 16, 4, "&dump_rectangle" ],
c86ec6445… Alex*0048 "apc_result_t" => [ 40, 8, "&dump_apc_result" ],
6db201080… Alex*0049 "async_data_t" => [ 40, 8, "&dump_async_data" ],
8bce6309a… Jace*0050 "irp_params_t" => [ 32, 8, "&dump_irp_params" ],
7d7322671… Alex*0051 "struct luid" => [ 8, 4, "&dump_luid" ],
928a22cd0… Alex*0052 "generic_map_t" => [ 16, 4, "&dump_generic_map" ],
f4ec583d0… Alex*0053 "ioctl_code_t" => [ 4, 4, "&dump_ioctl_code" ],
fc64aa7e7… Rémi*0054 "hw_input_t" => [ 40, 8, "&dump_hw_input" ],
2705e6c31… Alex*0055
11cd51139… Alex*0056 "apc_call_t" => [ 64, 8 ],
04a2917f6… Paul*0057 "context_t" => [ 1728, 8 ],
2705e6c31… Alex*0058 "cursor_pos_t" => [ 24, 8 ],
0059 "debug_event_t" => [ 160, 8 ],
2eb895039… Rémi*0060 "message_data_t" => [ 48, 8 ],
efd03f40e… Alex*0061 "pe_image_info_t" => [ 88, 8 ],
2705e6c31… Alex*0062 "property_data_t" => [ 16, 8 ],
0063 "select_op_t" => [ 264, 8 ],
82b0bb3c2… Eric*0064 "startup_info_t" => [ 96, 4 ],
2705e6c31… Alex*0065 "user_apc_t" => [ 40, 8 ],
0066 "struct filesystem_event" => [ 12, 4 ],
0067 "struct handle_info" => [ 20, 4 ],
0068 "struct luid_attr" => [ 12, 4 ],
0069 "struct object_attributes" => [ 16, 4 ],
0070 "struct object_type_info" => [ 44, 4 ],
0071 "struct process_info" => [ 40, 8 ],
0072 "struct rawinput_device" => [ 12, 4 ],
0073 "struct thread_info" => [ 40, 8 ],
767e6f6f9… Alex*0074 );
0075
0076 my @requests = ();
0077 my %replies = ();
7f1dc355e… Alex*0078 my @asserts = ();
767e6f6f9… Alex*0079
37ec92753… Alex*0080 my @trace_lines = ();
767e6f6f9… Alex*0081
f4ec583d0… Alex*0082 my $max_req_size = 64;
9caa71eef… Alex*0083
f4ec583d0… Alex*0084 my $warnings = scalar(@ARGV) && $ARGV[0] eq "-w";
767e6f6f9… Alex*0085
3044d734b… Alex*0086 sub add_padding($$)
0087 {
0088 my ($offset, $padding) = @_;
0089 if ($offset % $padding)
0090 {
0091 my $count = $padding - ($offset % $padding);
0092 print SERVER_PROT " char __pad_$offset\[$count\];\n";
0093 $offset += $count;
0094 }
0095 return $offset;
0096 }
0097
11a7b29a6… Fran*0098
0099
0100 sub DO_DUMP_FUNC($$@)
0101 {
0102 my $name = shift;
0103 my $req = shift;
53929f190… Alex*0104 my $prefix = " ";
11a7b29a6… Fran*0105 push @trace_lines, "static void dump_${name}_$req( const struct ${name}_$req *req )\n{\n";
0106 while ($#_ >= 0)
0107 {
0108 my $type = shift;
0109 my $var = shift;
8c8c665a3… Alex*0110 next if $var =~ /^__pad/;
11a7b29a6… Fran*0111 if (defined($formats{$type}))
0112 {
f4ec583d0… Alex*0113 my $fmt = ${$formats{$type}}[2];
0114 if ($fmt =~ /^&(.*)/)
11a7b29a6… Fran*0115 {
0116 my $func = $1;
53929f190… Alex*0117 push @trace_lines, " $func( \"$prefix$var=\", &req->$var );\n";
11a7b29a6… Fran*0118 }
f4ec583d0… Alex*0119 elsif ($fmt =~ /^(%.*)\s+\((.*)\)/)
58273ea9c… Alex*0120 {
0121 my ($format, $cast) = ($1, $2);
53929f190… Alex*0122 push @trace_lines, " fprintf( stderr, \"$prefix$var=$format\", ($cast)req->$var );\n";
58273ea9c… Alex*0123 }
11a7b29a6… Fran*0124 else
0125 {
53929f190… Alex*0126 push @trace_lines, " fprintf( stderr, \"$prefix$var=$fmt\", req->$var );\n";
11a7b29a6… Fran*0127 }
0128 }
0129 else
0130 {
53929f190… Alex*0131 push @trace_lines, " " . sprintf($type, "$prefix$var=") . ";\n";
11a7b29a6… Fran*0132 }
53929f190… Alex*0133 $prefix = ", ";
11a7b29a6… Fran*0134 }
0135 push @trace_lines, "}\n\n";
0136 }
0137
37ec92753… Alex*0138
767e6f6f9… Alex*0139
bd007ba1f… Fran*0140 sub PARSE_REQUESTS()
767e6f6f9… Alex*0141 {
37ec92753… Alex*0142
0143 my $state = 0;
f4ec583d0… Alex*0144 my $offset = 0;
37ec92753… Alex*0145 my $name = "";
ebe29ef37… Alex*0146 my @in_struct = ();
0147 my @out_struct = ();
37ec92753… Alex*0148
0149 open(PROTOCOL,"server/protocol.def") or die "Can't open server/protocol.def";
0150
0151 while (<PROTOCOL>)
767e6f6f9… Alex*0152 {
37ec92753… Alex*0153 my ($type, $var);
0154
767e6f6f9… Alex*0155 s!/\*.*\*/!!g;
37ec92753… Alex*0156
0157 s/\s+$//;
0158
0159 if (/^\@HEADER/)
0160 {
0161 die "Misplaced \@HEADER" unless $state == 0;
0162 $state++;
0163 next;
0164 }
0165
0166
0167 next if $state == 0;
0168
0169 if (/^\@REQ\(\s*(\w+)\s*\)/)
861135305… Alex*0170 {
37ec92753… Alex*0171 $name = $1;
0172 die "Misplaced \@REQ" unless $state == 1;
0173
0174 @in_struct = ();
0175 @out_struct = ();
f4ec583d0… Alex*0176 $offset = 12;
37ec92753… Alex*0177 print SERVER_PROT "struct ${name}_request\n{\n";
0178 print SERVER_PROT " struct request_header __header;\n";
0179 $state++;
861135305… Alex*0180 next;
0181 }
37ec92753… Alex*0182
0183 if (/^\@REPLY/)
861135305… Alex*0184 {
37ec92753… Alex*0185 die "Misplaced \@REPLY" unless $state == 2;
3044d734b… Alex*0186 $offset = add_padding( $offset, 8 );
0187 die "request $name too large ($offset)" if ($offset > $max_req_size);
0188 push @asserts, "C_ASSERT( sizeof(struct ${name}_request) == $offset );\n";
9caa71eef… Alex*0189 print SERVER_PROT "};\n";
0190 print SERVER_PROT "struct ${name}_reply\n{\n";
0191 print SERVER_PROT " struct reply_header __header;\n";
f4ec583d0… Alex*0192 $offset = 8;
37ec92753… Alex*0193 $state++;
0194 next;
861135305… Alex*0195 }
37ec92753… Alex*0196
0197 if (/^\@END/)
861135305… Alex*0198 {
37ec92753… Alex*0199 die "Misplaced \@END" unless ($state == 2 || $state == 3);
0200
3044d734b… Alex*0201 $offset = add_padding( $offset, 8 );
7f1dc355e… Alex*0202 print SERVER_PROT "};\n";
9caa71eef… Alex*0203 if ($state == 2)
0204 {
f4ec583d0… Alex*0205 die "request $name too large ($offset)" if ($offset > $max_req_size);
7f1dc355e… Alex*0206 push @asserts, "C_ASSERT( sizeof(struct ${name}_request) == $offset );\n";
9caa71eef… Alex*0207 print SERVER_PROT "struct ${name}_reply\n{\n";
0208 print SERVER_PROT " struct reply_header __header;\n";
0209 print SERVER_PROT "};\n";
0210 }
f4ec583d0… Alex*0211 else
0212 {
0213 die "reply $name too large ($offset)" if ($offset > $max_req_size);
7f1dc355e… Alex*0214 push @asserts, "C_ASSERT( sizeof(struct ${name}_reply) == $offset );\n";
f4ec583d0… Alex*0215 }
37ec92753… Alex*0216
0217 push @requests, $name;
11a7b29a6… Fran*0218 DO_DUMP_FUNC( $name, "request", @in_struct);
37ec92753… Alex*0219 if ($#out_struct >= 0)
0220 {
0221 $replies{$name} = 1;
11a7b29a6… Fran*0222 DO_DUMP_FUNC( $name, "reply", @out_struct);
37ec92753… Alex*0223 }
0224 $state = 1;
0225 next;
861135305… Alex*0226 }
37ec92753… Alex*0227
0228 if ($state != 1)
861135305… Alex*0229 {
37ec92753… Alex*0230
0231 if (/^$/)
0232 {
0233 print SERVER_PROT "\n";
0234 next;
0235 }
0236
6ca93646b… Gijs*0237 if (/^\s*VARARG\((\w+),(\w+),(\d+)\)/)
0238 {
0239 $var = $1;
0240 $type = "dump_varargs_$2( \"%s\", min(cur_size,$3) )";
0241 s!(VARARG\(.*\)\s*;)!/* $1 */!;
0242 }
0243 elsif (/^\s*VARARG\((\w+),(\w+),(\w+)\)/)
9caa71eef… Alex*0244 {
0245 $var = $1;
53929f190… Alex*0246 $type = "dump_varargs_" . $2 . "( \"%s\", min(cur_size,req->" . $3 . ") )";
9caa71eef… Alex*0247 s!(VARARG\(.*\)\s*;)!/* $1 */!;
0248 }
0249 elsif (/^\s*VARARG\((\w+),(\w+)\)/)
37ec92753… Alex*0250 {
0251 $var = $1;
53929f190… Alex*0252 $type = "dump_varargs_" . $2 . "( \"%s\", cur_size )";
37ec92753… Alex*0253 s!(VARARG\(.*\)\s*;)!/* $1 */!;
0254 }
9caa71eef… Alex*0255 elsif (/^\s*(\w+\**(\s+\w+\**)*)\s+(\w+);/)
37ec92753… Alex*0256 {
9caa71eef… Alex*0257 $type = $1;
37ec92753… Alex*0258 $var = $3;
9caa71eef… Alex*0259 die "Unrecognized type $type" unless defined($formats{$type});
f4ec583d0… Alex*0260 my @fmt = @{$formats{$type}};
0261 if ($offset & ($fmt[1] - 1))
0262 {
7f1dc355e… Alex*0263 my $count = $fmt[1] - ($offset & ($fmt[1] - 1));
f4ec583d0… Alex*0264 print "protocol.def:$.: warning: $name $offset $type $var needs padding\n" if $warnings;
7f1dc355e… Alex*0265 print SERVER_PROT " char __pad_$offset\[$count\];\n";
0266 $offset += $count;
0267 }
0268 if ($state == 2)
0269 {
0270 push @asserts, "C_ASSERT( FIELD_OFFSET(struct ${name}_request, $var) == $offset );\n";
0271 }
0272 else
0273 {
0274 push @asserts, "C_ASSERT( FIELD_OFFSET(struct ${name}_reply, $var) == $offset );\n";
f4ec583d0… Alex*0275 }
0276 $offset += $fmt[0];
37ec92753… Alex*0277 }
0278 else
0279 {
0280 die "Unrecognized syntax $_";
0281 }
0282 if ($state == 2) { push @in_struct, $type, $var; }
0283 if ($state == 3) { push @out_struct, $type, $var; }
861135305… Alex*0284 }
37ec92753… Alex*0285
0286
0287 print SERVER_PROT $_ . "\n";
767e6f6f9… Alex*0288 }
37ec92753… Alex*0289 close PROTOCOL;
767e6f6f9… Alex*0290 }
0291
37ec92753… Alex*0292
0293
bd007ba1f… Fran*0294 sub GET_PROTOCOL_VERSION()
37ec92753… Alex*0295 {
0296 my $protocol = 0;
0297 open SERVER_PROT, "include/wine/server_protocol.h" or return 0;
0298 while (<SERVER_PROT>)
0299 {
0300 if (/^\
0301 }
0302 close SERVER_PROT;
0303 return $protocol;
0304 }
0305
830d1edb9… Alex*0306
0307
0308 sub GET_ERROR_NAMES()
0309 {
0310 my %errors = ();
0311 foreach my $f (glob "server/*.c")
0312 {
3d39c620d… Alex*0313 next if $f eq "server/trace.c";
830d1edb9… Alex*0314 open FILE, $f or die "Can't open $f";
0315 while (<FILE>)
0316 {
4fbabc2ad… Akih*0317 while (/\bSTATUS_(\w+)/g)
60d6518c8… Alex*0318 {
c8faa1925… Akih*0319 $errors{$1} = "STATUS_$1" unless ($1 eq "SUCCESS" || $1 eq "WAIT_0");
830d1edb9… Alex*0320 }
4fbabc2ad… Akih*0321 while (/\bset_win32_error\s*\(\s*(\w+)\s*\)/g)
830d1edb9… Alex*0322 {
0323 $errors{$1} = "0xc0010000 | $1";
0324 }
424a379f6… Alex*0325 while (/\breturn\s+(WSA\w+)/g)
0326 {
0327 $errors{$1} = "0xc0010000 | $1";
0328 }
830d1edb9… Alex*0329 }
0330 close FILE;
0331 }
0332 return %errors;
0333 }
0334
37f3691f7… Alex*0335
0336 sub update_file($)
0337 {
0338 my $file = shift;
0339 my $ret = !(-f $file) || system "cmp $file $file.new >/dev/null";
0340 if (!$ret)
0341 {
0342 unlink "$file.new";
0343 }
0344 else
0345 {
0346 rename "$file.new", "$file";
0347 print "$file updated\n";
0348 }
0349 return $ret;
0350 }
5bc78089d… Alex*0351
37f3691f7… Alex*0352
0353 sub replace_in_file($$$@)
5bc78089d… Alex*0354 {
37f3691f7… Alex*0355 my $file = shift;
0356 my $start = shift;
0357 my $end = shift;
0358
0359 open NEW_FILE, ">$file.new" or die "cannot create $file.new";
0360
0361 if (defined($start))
5bc78089d… Alex*0362 {
37f3691f7… Alex*0363 open OLD_FILE, "$file" or die "cannot open $file";
0364 while (<OLD_FILE>)
0365 {
0366 print NEW_FILE $_;
0367 last if /$start/;
0368 }
5bc78089d… Alex*0369 }
37f3691f7… Alex*0370
0371 print NEW_FILE "\n", @_, "\n";
0372
0373 if (defined($end))
5bc78089d… Alex*0374 {
37f3691f7… Alex*0375 my $skip=1;
0376 while (<OLD_FILE>)
0377 {
0378 $skip = 0 if /$end/;
0379 print NEW_FILE $_ unless $skip;
0380 }
5bc78089d… Alex*0381 }
37f3691f7… Alex*0382
0383 close OLD_FILE if defined($start);
0384 close NEW_FILE;
0385 return update_file($file);
767e6f6f9… Alex*0386 }
bd007ba1f… Fran*0387
0388
0389
0390
0391 my $protocol = GET_PROTOCOL_VERSION();
0392
830d1edb9… Alex*0393 my %errors = GET_ERROR_NAMES();
0394
bd007ba1f… Fran*0395
0396
37f3691f7… Alex*0397 open SERVER_PROT, ">include/wine/server_protocol.h.new" or die "Cannot create include/wine/server_protocol.h.new";
bd007ba1f… Fran*0398 print SERVER_PROT "/*\n * Wine server protocol definitions\n *\n";
0399 print SERVER_PROT " * This file is automatically generated; DO NO EDIT!\n";
0400 print SERVER_PROT " * Edit server/protocol.def instead and re-run tools/make_requests\n";
0401 print SERVER_PROT " */\n\n";
0402 print SERVER_PROT "#ifndef __WINE_WINE_SERVER_PROTOCOL_H\n";
0403 print SERVER_PROT "#define __WINE_WINE_SERVER_PROTOCOL_H\n";
0404
0405
0406
0407 PARSE_REQUESTS();
0408
0409
0410
0411 print SERVER_PROT "\n\nenum request\n{\n";
0412 foreach my $req (@requests) { print SERVER_PROT " REQ_$req,\n"; }
0413 print SERVER_PROT " REQ_NB_REQUESTS\n};\n\n";
0414
0415 print SERVER_PROT "union generic_request\n{\n";
0416 print SERVER_PROT " struct request_max_size max_size;\n";
0417 print SERVER_PROT " struct request_header request_header;\n";
0418 foreach my $req (@requests) { print SERVER_PROT " struct ${req}_request ${req}_request;\n"; }
0419 print SERVER_PROT "};\n";
0420
0421 print SERVER_PROT "union generic_reply\n{\n";
0422 print SERVER_PROT " struct request_max_size max_size;\n";
0423 print SERVER_PROT " struct reply_header reply_header;\n";
0424 foreach my $req (@requests) { print SERVER_PROT " struct ${req}_reply ${req}_reply;\n"; }
0425 print SERVER_PROT "};\n\n";
0426
f181d5ce8… Rémi*0427 print SERVER_PROT "/* ### protocol_version begin ### */\n\n";
0428 printf SERVER_PROT "#define SERVER_PROTOCOL_VERSION %d\n\n", $protocol;
0429 print SERVER_PROT "/* ### protocol_version end ### */\n\n";
bd007ba1f… Fran*0430 print SERVER_PROT "#endif /* __WINE_WINE_SERVER_PROTOCOL_H */\n";
0431 close SERVER_PROT;
f181d5ce8… Rémi*0432
0433 if (update_file( "include/wine/server_protocol.h" ))
0434 {
0435 my @version_lines = ();
0436
0437 push @version_lines, sprintf( "#define SERVER_PROTOCOL_VERSION %d\n", $protocol + 1 );
0438
0439 replace_in_file( "include/wine/server_protocol.h",
0440 "### protocol_version begin ###",
0441 "### protocol_version end ###",
0442 @version_lines );
0443 }
bd007ba1f… Fran*0444
0445
0446
0447 push @trace_lines, "static const dump_func req_dumpers[REQ_NB_REQUESTS] = {\n";
0448 foreach my $req (@requests)
0449 {
0450 push @trace_lines, " (dump_func)dump_${req}_request,\n";
0451 }
0452 push @trace_lines, "};\n\n";
0453
0454 push @trace_lines, "static const dump_func reply_dumpers[REQ_NB_REQUESTS] = {\n";
0455 foreach my $req (@requests)
0456 {
df17fcdaf… Mich*0457 push @trace_lines, " ", $replies{$req} ? "(dump_func)dump_${req}_reply,\n" : "NULL,\n";
bd007ba1f… Fran*0458 }
0459 push @trace_lines, "};\n\n";
0460
0461 push @trace_lines, "static const char * const req_names[REQ_NB_REQUESTS] = {\n";
0462 foreach my $req (@requests)
0463 {
0464 push @trace_lines, " \"$req\",\n";
0465 }
830d1edb9… Alex*0466 push @trace_lines, "};\n\n";
0467
0468 push @trace_lines, "static const struct\n{\n";
0469 push @trace_lines, " const char *name;\n";
0470 push @trace_lines, " unsigned int value;\n";
0471 push @trace_lines, "} status_names[] =\n{\n";
0472
0473 foreach my $err (sort keys %errors)
0474 {
0475 push @trace_lines, sprintf(" { %-30s %s },\n", "\"$err\",", $errors{$err});
0476 }
0477 push @trace_lines, " { NULL, 0 }\n";
bd007ba1f… Fran*0478 push @trace_lines, "};\n";
0479
37f3691f7… Alex*0480 replace_in_file( "server/trace.c",
0481 "### make_requests begin ###",
0482 "### make_requests end ###",
0483 @trace_lines );
691884b9b… Alex*0484
0485
0486
0487 my @request_lines = ();
0488
0489 foreach my $req (@requests) { push @request_lines, "DECL_HANDLER($req);\n"; }
0490 push @request_lines, "\n#ifdef WANT_REQUEST_HANDLERS\n\n";
0491 push @request_lines, "typedef void (*req_handler)( const void *req, void *reply );\n";
0492 push @request_lines, "static const req_handler req_handlers[REQ_NB_REQUESTS] =\n{\n";
0493 foreach my $req (@requests)
0494 {
0495 push @request_lines, " (req_handler)req_$req,\n";
0496 }
7f1dc355e… Alex*0497 push @request_lines, "};\n\n";
0498
0499 foreach my $type (sort keys %formats)
0500 {
2705e6c31… Alex*0501 my ($size, $align) = @{$formats{$type}};
0502 die "$type: invalid size $size for alignment $align" if $size % $align;
7f1dc355e… Alex*0503 push @request_lines, "C_ASSERT( sizeof($type) == $size );\n";
0504 }
0505 push @request_lines, @asserts;
0506 push @request_lines, "\n#endif /* WANT_REQUEST_HANDLERS */\n";
691884b9b… Alex*0507
37f3691f7… Alex*0508 replace_in_file( "server/request.h",
0509 "### make_requests begin ###",
0510 "### make_requests end ###",
0511 @request_lines );