23 #include "wine/port.h" 45 #define ROUND_SIZE(size, alignment) (((size) + ((alignment) - 1)) & ~((alignment) - 1)) 47 #define ROUNDING(size, alignment) (((alignment) - 1) - (((size) + ((alignment) - 1)) & ((alignment) - 1))) 75 static const unsigned short IsPipe = 0x0004;
76 static const unsigned short IsIn = 0x0008;
77 static const unsigned short IsOut = 0x0010;
88 const char *
name,
unsigned int *typestring_offset);
91 const char *
name,
int write_ptr,
unsigned int *tfsoff);
95 const char *
name,
unsigned int *typestring_offset);
98 unsigned int *alignment );
105 case FC_BYTE:
return "FC_BYTE";
106 case FC_CHAR:
return "FC_CHAR";
112 case FC_LONG:
return "FC_LONG";
121 case FC_RP:
return "FC_RP";
122 case FC_UP:
return "FC_UP";
123 case FC_OP:
return "FC_OP";
124 case FC_FP:
return "FC_FP";
151 case FC_IP:
return "FC_IP";
170 case FC_PP:
return "FC_PP";
179 case FC_END:
return "FC_END";
180 case FC_PAD:
return "FC_PAD";
186 error(
"string_of_type: unknown type 0x%02x\n",
type);
398 unsigned short offset = 0;
399 unsigned int salign = 1;
408 unsigned int align = 0;
421 unsigned int stack_size;
440 if (by_value) *by_value = by_val;
447 unsigned char flags = 0;
468 unsigned int flags = 0;
481 int has_conformance = 0;
482 int has_variance = 0;
515 error_loc(
"field '%s' deriving from a conformant array must be the last field in the structure\n",
562 error_loc(
"field '%s' deriving from a conformant array must be the last field in the structure\n",
570 error_loc(
"field '%s' deriving from a conformant array must be the last field in the structure\n",
579 error_loc(
"Unknown struct member %s with type (0x%02x)\n",
field->name,
fc);
603 if ( has_conformance )
608 if( has_conformance && has_pointer )
610 if( has_conformance )
807 unsigned short off = 0;
814 error(
"user_type_offset: couldn't find type (%s)\n",
name);
829 if (
type->typestring_offset)
832 type->typestring_offset = 1;
862 #define WRITE_FCTYPE(file, fctype, typestring_offset) \ 865 fprintf(file, "\n", typestring_offset); \ 866 print_file((file), 2, "0x%02x,\t\n", fctype); \ 896 local_var_prefix,
n, local_var_prefix,
n);
943 print_file(
f,
indent,
"static const MIDL_TYPE_FORMAT_STRING __MIDL_TypeFormatString;\n");
944 print_file(
f,
indent,
"static const MIDL_PROC_FORMAT_STRING __MIDL_ProcFormatString;\n");
959 unsigned int *stack_size,
unsigned int *typestring_offset )
961 unsigned int alignment, server_size = 0,
buffer_size = 0;
962 unsigned char fc = 0;
967 if (is_return) is_out =
TRUE;
968 else if (!is_in && !is_out) is_in =
TRUE;
972 *typestring_offset =
var->typestring_offset;
1012 *typestring_offset =
var->type->typestring_offset;
1022 else *typestring_offset += 2;
1028 *typestring_offset += 4;
1064 *typestring_offset =
ref->typestring_offset;
1080 *typestring_offset =
ref->typestring_offset;
1109 server_size = (server_size + 7) / 8;
1110 if (server_size < 8) *
flags |= server_size << 13;
1120 unsigned char oi2_flags = 0x40;
1121 unsigned short flags;
1122 unsigned int stack_size, typestring_offset;
1147 unsigned int stack_size, typestring_offset;
1148 unsigned short flags;
1173 typestring_offset, typestring_offset );
1179 int is_return,
int is_interpreted)
1186 if (!is_in && !is_out) is_in =
TRUE;
1216 unsigned short offset =
var->typestring_offset;
1220 var->type->details.array.ptr_tfsoff)
1225 else if (is_in && is_out)
1292 unsigned short num_proc )
1296 unsigned char explicit_fc, implicit_fc;
1297 unsigned char handle_flags;
1301 unsigned int nb_args = 0;
1302 unsigned int stack_size = 0;
1303 unsigned short param_num = 0;
1304 unsigned short handle_stack_offset = 0;
1305 unsigned short handle_param_num = 0;
1317 if (
var == handle_var)
1319 handle_stack_offset = stack_size;
1320 handle_param_num = param_num;
1338 print_file(
file,
indent,
"NdrFcShort(0x%x),\t/* stack size = %u */\n", stack_size, stack_size );
1343 switch (explicit_fc)
1350 handle_stack_offset, handle_stack_offset );
1358 handle_stack_offset, handle_stack_offset );
1368 handle_stack_offset, handle_stack_offset );
1379 unsigned char ext_flags = 0;
1384 if (iface == iface->
details.
iface->async_iface) oi2_flags |= 0x20;
1400 unsigned short pos = 0, fpu_mask = 0;
1415 if (
pos >= 16)
break;
1425 unsigned short num_proc )
1480 iface = stmt->
u.
type;
1481 if (!pred(iface))
continue;
1555 *typestring_offset += 1;
1564 unsigned char operator_type = 0;
1566 const char *conftype_string =
"field";
1580 error(
"write_conf_or_var_desc: constant value %d is greater than " 1581 "the maximum constant size of %d\n",
expr->cval,
1584 print_file(
file, 2,
"0x%x, /* Corr desc: constant, val = %d */\n",
1595 conftype_string =
"parameter";
1606 conftype_string =
"field pointer";
1611 switch (subexpr->
type)
1614 subexpr = subexpr->
ref;
1620 subexpr = subexpr->
ref;
1627 subexpr = subexpr->
ref;
1634 subexpr = subexpr->
ref;
1641 subexpr = subexpr->
ref;
1652 unsigned char param_type = 0;
1667 correlation_variable =
var->type;
1683 correlation_variable =
var->type;
1690 if (!correlation_variable)
1691 error(
"write_conf_or_var_desc: couldn't find variable %s in %s\n", subexpr->
u.
sval,
name);
1723 error(
"write_conf_or_var_desc: conformance variable type not supported 0x%x\n",
1743 error(
"write_conf_or_var_desc: non-arithmetic type used as correlation variable %s\n",
1757 unsigned int callback_offset = 0;
1777 eval =
xmalloc (
sizeof(*eval));
1787 error(
"Maximum number of callback routines reached\n");
1789 print_file(
file, 2,
"0x%x,\t/* Corr desc: %s in %s */\n", conftype, conftype_string,
name);
1791 print_file(
file, 2,
"NdrFcShort(0x%hx),\t/* %u */\n", (
unsigned short)callback_offset, callback_offset);
1805 unsigned int align = 0;
1814 unsigned int size = 0;
1815 unsigned int max_align;
1818 if (!fields)
return 0;
1821 unsigned int falign = 0;
1837 unsigned int size, maxs = 0;
1838 unsigned int align = *pmaxa;
1857 unsigned int size = 0;
1910 error(
"type_memsize: Unknown enum type\n");
1966 unsigned int align = 0;
2012 error(
"type_buffer_alignment: Unknown enum type\n");
2019 if (!
var->type)
continue;
2028 if (!
var->type)
continue;
2037 if (!
var->type)
continue;
2079 print_file(
file,
indent,
"__frame->_StubMsg.FullPtrXlatTables = NdrFullPointerXlatInit(0,%s);\n",
2080 is_server ?
"XLAT_SERVER" :
"XLAT_CLIENT");
2094 unsigned int *typeformat_offset)
2096 unsigned int start_offset = *typeformat_offset;
2097 short reloff =
offset - (*typeformat_offset + 2);
2098 int in_attr, out_attr;
2100 unsigned char flags = 0;
2106 if (!in_attr && !out_attr) in_attr = 1;
2110 if (out_attr && !in_attr && pointer_type ==
FC_RP)
2126 if (in_attr && out_attr)
2140 if (pointer_type !=
FC_RP) {
2163 *typeformat_offset += 4;
2165 return start_offset;
2172 unsigned char pointer_fc;
2181 error(
"write_simple_pointer: can't handle type %s which is a string type\n",
type->name);
2193 if (out_attr && !in_attr && pointer_fc ==
FC_RP)
2202 print_file(
file, 2,
"0x%02x, 0x%x,\t/* %s %s[simple_pointer] */\n",
2220 unsigned int *typestring_offset)
2222 unsigned int offset = *typestring_offset;
2245 return type->typestring_offset && !
type->tfswrite;
2321 print_file(
file, 2,
"NdrFcShort(0x%hx),\t/* Function offset= %hu */\n", funoff, funoff);
2323 print_file(
file, 2,
"NdrFcShort(0x%hx),\t/* %u */\n", (
unsigned short)usize, usize);
2325 reloff = absoff - *tfsoff;
2326 print_file(
file, 2,
"NdrFcShort(0x%hx),\t/* Offset= %hd (%u) */\n", reloff, reloff, absoff);
2334 unsigned int *tfsoff)
2338 unsigned int absoff;
2348 absoff =
type->typestring_offset;
2350 reloff = absoff - (*tfsoff + 2);
2357 print_file(
file, 2,
"NdrFcShort(0x%hx),\t/* Offset= %hd (%u) */\n",
2358 reloff, reloff, absoff);
2372 int cont_is_complex,
unsigned int *tfsoff)
2383 ref->typestring_offset, tfsoff);
2403 if (*tfsoff % 2 == 0)
2428 reloff = absoff - (*tfsoff + 6);
2434 print_file(
file, 2,
"NdrFcShort(0x%hx),\t/* Offset= %hd (%u) */\n",
2435 (
unsigned short)reloff, reloff, absoff);
2444 unsigned int *offset_in_memory,
unsigned int *offset_in_buffer,
2445 unsigned int *typestring_offset)
2452 if (offset_in_memory && offset_in_buffer)
2454 unsigned int memsize;
2461 print_file(
file, 2,
"NdrFcShort(0x%hx),\t/* Memory offset = %d */\n", (
unsigned short)*offset_in_memory, *offset_in_memory);
2462 print_file(
file, 2,
"NdrFcShort(0x%hx),\t/* Buffer offset = %d */\n", (
unsigned short)*offset_in_buffer, *offset_in_buffer);
2465 *offset_in_memory += memsize;
2468 *offset_in_buffer += memsize;
2470 *typestring_offset += 4;
2480 ref->typestring_offset, typestring_offset);
2484 error(
"write_pointer_description_offsets: type format string unknown\n");
2488 unsigned int offset =
type->typestring_offset;
2503 offset_in_buffer, typestring_offset);
2511 if (offset_in_memory && offset_in_buffer)
2514 unsigned int align = 0;
2521 file,
v->attrs,
v->type, offset_in_memory, offset_in_buffer,
2527 if (offset_in_memory && offset_in_buffer)
2530 *offset_in_memory += memsize;
2533 *offset_in_buffer += memsize;
2542 unsigned int *offset_in_memory,
unsigned int *offset_in_buffer,
2543 unsigned int *typestring_offset)
2552 *typestring_offset += 2;
2555 offset_in_memory, offset_in_buffer, typestring_offset);
2563 if (offset_in_memory && offset_in_buffer)
2566 unsigned int align = 0;
2574 offset_in_memory, offset_in_buffer, typestring_offset);
2580 *offset_in_memory += memsize;
2583 *offset_in_buffer += memsize;
2593 unsigned int *offset_in_memory,
unsigned int *offset_in_buffer,
2594 unsigned int *typestring_offset)
2596 int pointer_count = 0;
2601 unsigned int temp = 0;
2606 if (pointer_count > 0)
2608 unsigned int increment_size;
2609 unsigned int offset_of_array_pointer_mem = 0;
2610 unsigned int offset_of_array_pointer_buf = 0;
2617 print_file(
file, 2,
"NdrFcShort(0x%hx),\t/* Increment = %d */\n", (
unsigned short)increment_size, increment_size);
2618 print_file(
file, 2,
"NdrFcShort(0x%hx),\t/* Offset to array = %d */\n", (
unsigned short)*offset_in_memory, *offset_in_memory);
2619 print_file(
file, 2,
"NdrFcShort(0x%hx),\t/* Number of pointers = %d */\n", (
unsigned short)pointer_count, pointer_count);
2620 *typestring_offset += 10;
2623 file, attrs,
type, &offset_of_array_pointer_mem,
2624 &offset_of_array_pointer_buf, typestring_offset);
2632 if (offset_in_memory && offset_in_buffer)
2635 unsigned int align = 0;
2642 file,
v->attrs,
v->type, offset_in_memory, offset_in_buffer,
2648 if (offset_in_memory && offset_in_buffer)
2650 unsigned int memsize;
2652 *offset_in_memory += memsize;
2655 *offset_in_buffer += memsize;
2659 return pointer_count;
2666 unsigned int offset_in_memory,
unsigned int *typestring_offset)
2668 int pointer_count = 0;
2672 unsigned int temp = 0;
2677 if (pointer_count > 0)
2679 unsigned int increment_size;
2680 unsigned int offset_of_array_pointer_mem = offset_in_memory;
2681 unsigned int offset_of_array_pointer_buf = offset_in_memory;
2686 error(
"array size of %u bytes is too large\n", increment_size);
2690 print_file(
file, 2,
"NdrFcShort(0x%hx),\t/* Increment = %d */\n", (
unsigned short)increment_size, increment_size);
2691 print_file(
file, 2,
"NdrFcShort(0x%hx),\t/* Offset to array = %d */\n", (
unsigned short)offset_in_memory, offset_in_memory);
2692 print_file(
file, 2,
"NdrFcShort(0x%hx),\t/* Number of pointers = %d */\n", (
unsigned short)pointer_count, pointer_count);
2693 *typestring_offset += 8;
2697 &offset_of_array_pointer_mem, &offset_of_array_pointer_buf,
2702 return pointer_count;
2709 unsigned int *offset_in_memory,
unsigned int *offset_in_buffer,
2710 unsigned int *typestring_offset)
2712 int pointer_count = 0;
2716 unsigned int temp = 0;
2721 if (pointer_count > 0)
2723 unsigned int increment_size;
2728 error(
"array size of %u bytes is too large\n", increment_size);
2732 print_file(
file, 2,
"NdrFcShort(0x%hx),\t/* Increment = %d */\n", (
unsigned short)increment_size, increment_size);
2733 print_file(
file, 2,
"NdrFcShort(0x%hx),\t/* Offset to array = %d */\n", (
unsigned short)*offset_in_memory, *offset_in_memory);
2734 print_file(
file, 2,
"NdrFcShort(0x%hx),\t/* Number of pointers = %d */\n", (
unsigned short)pointer_count, pointer_count);
2735 *typestring_offset += 8;
2739 offset_in_buffer, typestring_offset);
2747 if (offset_in_memory && offset_in_buffer)
2753 *offset_in_buffer =
ROUND_SIZE(*offset_in_buffer, 4);
2755 *offset_in_buffer += 8;
2764 file,
v->attrs,
v->type, offset_in_memory, offset_in_buffer,
2770 if (offset_in_memory && offset_in_buffer)
2773 *offset_in_memory += memsize;
2776 *offset_in_buffer += memsize;
2780 return pointer_count;
2784 unsigned int *typestring_offset)
2786 unsigned int offset_in_buffer;
2787 unsigned int offset_in_memory;
2793 offset_in_memory = 0;
2794 offset_in_buffer = 0;
2797 &offset_in_memory, &offset_in_buffer, typestring_offset);
2801 offset_in_memory = 0;
2802 offset_in_buffer = 0;
2805 &offset_in_memory, &offset_in_buffer, typestring_offset);
2812 file, attrs,
type, 0, typestring_offset);
2822 offset_in_memory = 0;
2823 offset_in_buffer = 0;
2826 &offset_in_memory, &offset_in_buffer, typestring_offset);
2831 const char *
name,
unsigned int *typestring_offset)
2833 unsigned int start_offset;
2834 unsigned char rtype;
2838 start_offset = *typestring_offset;
2845 pointer_type =
FC_RP;
2849 flag ?
" [simple_pointer]" :
"");
2850 *typestring_offset += 2;
2854 *typestring_offset += 2;
2856 is_processed =
FALSE;
2869 error(
"write_string_tfs: Unimplemented for non-basic type %s\n",
name);
2870 return start_offset;
2876 error(
"write_string_tfs: Unimplemented for type 0x%x of name: %s\n",
rtype,
name);
2877 return start_offset;
2884 if (is_processed)
return start_offset;
2888 error(
"array size for parameter %s exceeds %u bytes by %u bytes\n",
2889 name, 0xffffu, dim - 0xffffu);
2896 *typestring_offset += 2;
2898 print_file(
file, 2,
"NdrFcShort(0x%hx),\t/* %d */\n", (
unsigned short)dim, dim);
2899 *typestring_offset += 2;
2902 return start_offset;
2911 *typestring_offset += 2;
2921 return start_offset;
2925 if (is_processed)
return start_offset;
2932 *typestring_offset += 2;
2935 return start_offset;
2940 const char *
name,
unsigned int *typestring_offset)
2946 unsigned int start_offset;
2955 pointer_type =
FC_RP;
2964 start_offset = *typestring_offset;
2969 *typestring_offset += 2;
2977 *typestring_offset += 4;
2982 *typestring_offset += 2;
2998 *typestring_offset += 4;
3002 print_file(
file, 2,
"NdrFcShort(0x%hx),\t/* %u */\n", (
unsigned short)dim, dim);
3003 *typestring_offset += 2;
3006 print_file(
file, 2,
"NdrFcShort(0x%hx),\t/* %u */\n", (
unsigned short)elsize, elsize);
3007 *typestring_offset += 2;
3020 *typestring_offset += 2;
3023 *typestring_offset += 1;
3032 print_file(
file, 2,
"NdrFcShort(0x%hx),\t/* %u */\n", (
unsigned short)dim, dim);
3033 *typestring_offset += 2;
3045 return start_offset;
3051 const var_t *last_field;
3058 ft = last_field->
type;
3070 int is_complex,
unsigned int *corroff,
3071 unsigned int *typestring_offset)
3074 unsigned short offset = 0;
3075 unsigned int salign = 1;
3082 unsigned int align = 0;
3091 unsigned char fc = 0;
3108 *typestring_offset += 1;
3122 *typestring_offset += 1;
3129 const char *
name,
unsigned int *tfsoff)
3132 unsigned int total_size;
3134 unsigned int start_offset;
3136 unsigned int corroff;
3149 error(
"structure size for %s exceeds %d bytes by %d bytes\n",
3167 start_offset = *tfsoff;
3172 print_file(
file, 2,
"NdrFcShort(0x%hx),\t/* %d */\n", (
unsigned short)total_size, total_size);
3177 unsigned int absoff =
array->type->typestring_offset;
3178 short reloff = absoff - *tfsoff;
3179 print_file(
file, 2,
"NdrFcShort(0x%hx),\t/* Offset= %hd (%u) */\n",
3180 reloff, reloff, absoff);
3194 unsigned int absoff =
type->ptrdesc ?
type->ptrdesc : *tfsoff;
3195 int reloff = absoff - *tfsoff;
3197 print_file(
file, 2,
"NdrFcShort(0x%hx),\t/* Offset= %d (%u) */\n",
3198 (
unsigned short)reloff, reloff, absoff);
3220 type->ptrdesc = *tfsoff;
3253 if (
type->ptrdesc == *tfsoff)
3258 return start_offset;
3276 print_file(
file, 2,
"NdrFcShort(0x80%02x),\t/* Simple arm type: %s */\n",
3279 else if (
t->typestring_offset)
3281 short reloff =
t->typestring_offset - *tfsoff;
3282 print_file(
file, 2,
"NdrFcShort(0x%hx),\t/* Offset= %d (%d) */\n",
3283 reloff, reloff,
t->typestring_offset);
3295 unsigned int start_offset;
3298 unsigned int nbranch = 0;
3300 short nodeftype = 0xffff;
3306 return type->typestring_offset;
3323 start_offset = *tfsoff;
3330 unsigned int align = 0;
3350 error(
"union switch type must be an integer, char, or enum\n");
3356 error(
"union switch type must be an integer, char, or enum\n");
3393 error(
"union switch type must be an integer, char, or enum\n");
3399 error(
"union switch type must be an integer, char, or enum\n");
3406 print_file(
file, 2,
"NdrFcShort(0x2),\t/* Offset= 2 (%u) */\n", *tfsoff + 2);
3412 print_file(
file, 2,
"NdrFcShort(0x%hx),\t/* %d */\n", (
unsigned short)nbranch, nbranch);
3422 if (cases ==
NULL && !deflt)
3423 error(
"union field %s with neither case nor default attribute\n",
f->name);
3455 return start_offset;
3459 unsigned int *typeformat_offset)
3462 unsigned int start_offset = *typeformat_offset;
3490 for (
i = 0;
i < 8; ++
i)
3496 *typeformat_offset += 18;
3498 return start_offset;
3505 unsigned int *typeformat_offset)
3507 unsigned int start_offset = *typeformat_offset;
3515 if (!pointer_type) pointer_type =
FC_RP;
3516 *typeformat_offset += 4;
3518 print_file(
file, 2,
"NdrFcShort(0x2),\t /* Offset= 2 (%u) */\n", *typeformat_offset);
3533 if ((
flags & 0x21) == 0x20)
3535 if ((
flags & 0x21) == 0x21)
3544 *typeformat_offset += 4;
3547 return start_offset;
3552 unsigned int *typeformat_offset)
3555 unsigned int start_offset = *typeformat_offset;
3573 *typeformat_offset += 10;
3575 return start_offset;
3582 unsigned int *typeformat_offset)
3614 unsigned int absoff =
type->typestring_offset;
3615 short reloff = absoff - (*typeformat_offset + 2);
3616 off = *typeformat_offset;
3620 print_file(
file, 2,
"NdrFcShort(0x%hx),\t/* Offset= %hd (%u) */\n",
3621 reloff, reloff, absoff);
3623 *typeformat_offset += 4;
3625 type->details.array.ptr_tfsoff = off;
3649 unsigned int toplevel_offset = *typeformat_offset;
3671 ref_context, typeformat_offset);
3684 const char *
name,
int write_ptr,
unsigned int *tfsoff)
3726 for (type_entry = stmt->
u.
type_list; type_entry; type_entry = type_entry->
next)
3744 unsigned int typeformat_offset = 2;
3746 return typeformat_offset + 1;
3781 const char *uname =
NULL;
3824 error(
"get_required_buffer_size: unknown basic type 0x%02x\n",
3890 if (!in_attr && !out_attr)
3914 unsigned int total_size = 0, alignment;
3921 total_size += alignment;
3930 total_size += alignment;
3937 const var_t *
var,
unsigned int type_offset)
3939 const char *
function;
3943 function =
"BufferSize";
3946 function =
"Marshall";
3949 function =
"Unmarshall";
3963 (phase ==
PHASE_UNMARSHAL) ?
"(unsigned char **)" :
"(unsigned char *)",
3977 const char *varname)
3980 unsigned int alignment = 0;