2005-12-08 12:52:13 +01:00
|
|
|
/*
|
|
|
|
* Format String Generator for IDL Compiler
|
|
|
|
*
|
2006-03-23 10:33:08 +01:00
|
|
|
* Copyright 2005-2006 Eric Kohl
|
2006-01-31 12:24:54 +01:00
|
|
|
* Copyright 2005-2006 Robert Shearman
|
2005-12-08 12:52:13 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-12-08 12:52:13 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <ctype.h>
|
2006-01-24 11:07:13 +01:00
|
|
|
#include <limits.h>
|
2005-12-08 12:52:13 +01:00
|
|
|
|
|
|
|
#include "widl.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "parser.h"
|
|
|
|
#include "header.h"
|
2008-12-29 13:05:27 +01:00
|
|
|
#include "typetree.h"
|
2005-12-08 12:52:13 +01:00
|
|
|
|
2005-12-12 12:14:31 +01:00
|
|
|
#include "typegen.h"
|
2008-04-22 12:36:38 +02:00
|
|
|
#include "expr.h"
|
2005-12-08 12:52:13 +01:00
|
|
|
|
2008-06-23 13:57:28 +02:00
|
|
|
/* round size up to multiple of alignment */
|
|
|
|
#define ROUND_SIZE(size, alignment) (((size) + ((alignment) - 1)) & ~((alignment) - 1))
|
|
|
|
/* value to add on to round size up to a multiple of alignment */
|
|
|
|
#define ROUNDING(size, alignment) (((alignment) - 1) - (((size) + ((alignment) - 1)) & ((alignment) - 1)))
|
|
|
|
|
2006-01-27 12:53:32 +01:00
|
|
|
static const type_t *current_structure;
|
2011-05-26 21:34:51 +02:00
|
|
|
static const var_t *current_func;
|
2008-04-24 20:06:28 +02:00
|
|
|
static const type_t *current_iface;
|
2006-01-27 12:53:32 +01:00
|
|
|
|
|
|
|
static struct list expr_eval_routines = LIST_INIT(expr_eval_routines);
|
|
|
|
struct expr_eval_routine
|
|
|
|
{
|
2011-05-26 21:34:51 +02:00
|
|
|
struct list entry;
|
|
|
|
const type_t *iface;
|
|
|
|
const type_t *cont_type;
|
|
|
|
char *name;
|
|
|
|
unsigned int baseoff;
|
2006-01-27 12:53:32 +01:00
|
|
|
const expr_t *expr;
|
|
|
|
};
|
2006-01-24 11:12:54 +01:00
|
|
|
|
2010-03-15 20:29:57 +01:00
|
|
|
enum type_context
|
|
|
|
{
|
|
|
|
TYPE_CONTEXT_TOPLEVELPARAM,
|
|
|
|
TYPE_CONTEXT_PARAM,
|
|
|
|
TYPE_CONTEXT_CONTAINER,
|
|
|
|
TYPE_CONTEXT_CONTAINER_NO_POINTERS,
|
2019-01-24 13:38:40 +01:00
|
|
|
TYPE_CONTEXT_RETVAL,
|
2010-03-15 20:29:57 +01:00
|
|
|
};
|
|
|
|
|
2011-06-03 14:54:14 +02:00
|
|
|
/* parameter flags in Oif mode */
|
|
|
|
static const unsigned short MustSize = 0x0001;
|
|
|
|
static const unsigned short MustFree = 0x0002;
|
|
|
|
static const unsigned short IsPipe = 0x0004;
|
|
|
|
static const unsigned short IsIn = 0x0008;
|
|
|
|
static const unsigned short IsOut = 0x0010;
|
|
|
|
static const unsigned short IsReturn = 0x0020;
|
|
|
|
static const unsigned short IsBasetype = 0x0040;
|
|
|
|
static const unsigned short IsByValue = 0x0080;
|
|
|
|
static const unsigned short IsSimpleRef = 0x0100;
|
|
|
|
/* static const unsigned short IsDontCallFreeInst = 0x0200; */
|
|
|
|
/* static const unsigned short SaveForAsyncFinish = 0x0400; */
|
|
|
|
|
2009-07-03 12:02:30 +02:00
|
|
|
static unsigned int field_memsize(const type_t *type, unsigned int *offset);
|
2009-02-06 14:30:38 +01:00
|
|
|
static unsigned int fields_memsize(const var_list_t *fields, unsigned int *align);
|
2014-04-02 11:37:47 +02:00
|
|
|
static unsigned int write_array_tfs(FILE *file, const attr_list_t *attrs, type_t *type,
|
|
|
|
const char *name, unsigned int *typestring_offset);
|
2009-02-06 14:30:38 +01:00
|
|
|
static unsigned int write_struct_tfs(FILE *file, type_t *type, const char *name, unsigned int *tfsoff);
|
2007-05-25 02:48:39 +02:00
|
|
|
static int write_embedded_types(FILE *file, const attr_list_t *attrs, type_t *type,
|
2007-06-12 03:51:41 +02:00
|
|
|
const char *name, int write_ptr, unsigned int *tfsoff);
|
2007-10-11 00:29:54 +02:00
|
|
|
static const var_t *find_array_or_string_in_struct(const type_t *type);
|
2009-02-06 14:30:38 +01:00
|
|
|
static unsigned int write_string_tfs(FILE *file, const attr_list_t *attrs,
|
2011-06-14 12:24:00 +02:00
|
|
|
type_t *type, enum type_context context,
|
|
|
|
const char *name, unsigned int *typestring_offset);
|
2011-06-03 14:54:14 +02:00
|
|
|
static unsigned int get_required_buffer_size_type( const type_t *type, const char *name,
|
|
|
|
const attr_list_t *attrs, int toplevel_param,
|
|
|
|
unsigned int *alignment );
|
|
|
|
static unsigned int get_function_buffer_size( const var_t *func, enum pass pass );
|
2007-05-19 01:53:27 +02:00
|
|
|
|
2010-01-21 12:56:53 +01:00
|
|
|
static const char *string_of_type(unsigned char type)
|
2007-05-10 05:46:31 +02:00
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_BYTE: return "FC_BYTE";
|
|
|
|
case FC_CHAR: return "FC_CHAR";
|
|
|
|
case FC_SMALL: return "FC_SMALL";
|
|
|
|
case FC_USMALL: return "FC_USMALL";
|
|
|
|
case FC_WCHAR: return "FC_WCHAR";
|
|
|
|
case FC_SHORT: return "FC_SHORT";
|
|
|
|
case FC_USHORT: return "FC_USHORT";
|
|
|
|
case FC_LONG: return "FC_LONG";
|
|
|
|
case FC_ULONG: return "FC_ULONG";
|
|
|
|
case FC_FLOAT: return "FC_FLOAT";
|
|
|
|
case FC_HYPER: return "FC_HYPER";
|
|
|
|
case FC_DOUBLE: return "FC_DOUBLE";
|
|
|
|
case FC_ENUM16: return "FC_ENUM16";
|
|
|
|
case FC_ENUM32: return "FC_ENUM32";
|
|
|
|
case FC_IGNORE: return "FC_IGNORE";
|
|
|
|
case FC_ERROR_STATUS_T: return "FC_ERROR_STATUS_T";
|
|
|
|
case FC_RP: return "FC_RP";
|
|
|
|
case FC_UP: return "FC_UP";
|
|
|
|
case FC_OP: return "FC_OP";
|
|
|
|
case FC_FP: return "FC_FP";
|
|
|
|
case FC_ENCAPSULATED_UNION: return "FC_ENCAPSULATED_UNION";
|
|
|
|
case FC_NON_ENCAPSULATED_UNION: return "FC_NON_ENCAPSULATED_UNION";
|
|
|
|
case FC_STRUCT: return "FC_STRUCT";
|
|
|
|
case FC_PSTRUCT: return "FC_PSTRUCT";
|
|
|
|
case FC_CSTRUCT: return "FC_CSTRUCT";
|
|
|
|
case FC_CPSTRUCT: return "FC_CPSTRUCT";
|
|
|
|
case FC_CVSTRUCT: return "FC_CVSTRUCT";
|
|
|
|
case FC_BOGUS_STRUCT: return "FC_BOGUS_STRUCT";
|
|
|
|
case FC_SMFARRAY: return "FC_SMFARRAY";
|
|
|
|
case FC_LGFARRAY: return "FC_LGFARRAY";
|
|
|
|
case FC_SMVARRAY: return "FC_SMVARRAY";
|
|
|
|
case FC_LGVARRAY: return "FC_LGVARRAY";
|
|
|
|
case FC_CARRAY: return "FC_CARRAY";
|
|
|
|
case FC_CVARRAY: return "FC_CVARRAY";
|
|
|
|
case FC_BOGUS_ARRAY: return "FC_BOGUS_ARRAY";
|
|
|
|
case FC_ALIGNM2: return "FC_ALIGNM2";
|
|
|
|
case FC_ALIGNM4: return "FC_ALIGNM4";
|
|
|
|
case FC_ALIGNM8: return "FC_ALIGNM8";
|
|
|
|
case FC_POINTER: return "FC_POINTER";
|
|
|
|
case FC_C_CSTRING: return "FC_C_CSTRING";
|
|
|
|
case FC_C_WSTRING: return "FC_C_WSTRING";
|
|
|
|
case FC_CSTRING: return "FC_CSTRING";
|
|
|
|
case FC_WSTRING: return "FC_WSTRING";
|
|
|
|
case FC_BYTE_COUNT_POINTER: return "FC_BYTE_COUNT_POINTER";
|
|
|
|
case FC_TRANSMIT_AS: return "FC_TRANSMIT_AS";
|
|
|
|
case FC_REPRESENT_AS: return "FC_REPRESENT_AS";
|
|
|
|
case FC_IP: return "FC_IP";
|
|
|
|
case FC_BIND_CONTEXT: return "FC_BIND_CONTEXT";
|
|
|
|
case FC_BIND_GENERIC: return "FC_BIND_GENERIC";
|
|
|
|
case FC_BIND_PRIMITIVE: return "FC_BIND_PRIMITIVE";
|
|
|
|
case FC_AUTO_HANDLE: return "FC_AUTO_HANDLE";
|
|
|
|
case FC_CALLBACK_HANDLE: return "FC_CALLBACK_HANDLE";
|
|
|
|
case FC_STRUCTPAD1: return "FC_STRUCTPAD1";
|
|
|
|
case FC_STRUCTPAD2: return "FC_STRUCTPAD2";
|
|
|
|
case FC_STRUCTPAD3: return "FC_STRUCTPAD3";
|
|
|
|
case FC_STRUCTPAD4: return "FC_STRUCTPAD4";
|
|
|
|
case FC_STRUCTPAD5: return "FC_STRUCTPAD5";
|
|
|
|
case FC_STRUCTPAD6: return "FC_STRUCTPAD6";
|
|
|
|
case FC_STRUCTPAD7: return "FC_STRUCTPAD7";
|
|
|
|
case FC_STRING_SIZED: return "FC_STRING_SIZED";
|
|
|
|
case FC_NO_REPEAT: return "FC_NO_REPEAT";
|
|
|
|
case FC_FIXED_REPEAT: return "FC_FIXED_REPEAT";
|
|
|
|
case FC_VARIABLE_REPEAT: return "FC_VARIABLE_REPEAT";
|
|
|
|
case FC_FIXED_OFFSET: return "FC_FIXED_OFFSET";
|
|
|
|
case FC_VARIABLE_OFFSET: return "FC_VARIABLE_OFFSET";
|
|
|
|
case FC_PP: return "FC_PP";
|
|
|
|
case FC_EMBEDDED_COMPLEX: return "FC_EMBEDDED_COMPLEX";
|
|
|
|
case FC_DEREFERENCE: return "FC_DEREFERENCE";
|
|
|
|
case FC_DIV_2: return "FC_DIV_2";
|
|
|
|
case FC_MULT_2: return "FC_MULT_2";
|
|
|
|
case FC_ADD_1: return "FC_ADD_1";
|
|
|
|
case FC_SUB_1: return "FC_SUB_1";
|
|
|
|
case FC_CALLBACK: return "FC_CALLBACK";
|
|
|
|
case FC_CONSTANT_IID: return "FC_CONSTANT_IID";
|
|
|
|
case FC_END: return "FC_END";
|
|
|
|
case FC_PAD: return "FC_PAD";
|
|
|
|
case FC_USER_MARSHAL: return "FC_USER_MARSHAL";
|
|
|
|
case FC_RANGE: return "FC_RANGE";
|
|
|
|
case FC_INT3264: return "FC_INT3264";
|
|
|
|
case FC_UINT3264: return "FC_UINT3264";
|
2007-05-10 05:46:31 +02:00
|
|
|
default:
|
|
|
|
error("string_of_type: unknown type 0x%02x\n", type);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-07 15:54:28 +01:00
|
|
|
static void *get_aliaschain_attrp(const type_t *type, enum attr_type attr)
|
|
|
|
{
|
|
|
|
const type_t *t = type;
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if (is_attr(t->attrs, attr))
|
|
|
|
return get_attrp(t->attrs, attr);
|
|
|
|
else if (type_is_alias(t))
|
|
|
|
t = type_alias_get_aliasee(t);
|
2010-01-21 12:56:53 +01:00
|
|
|
else return NULL;
|
2009-11-07 15:54:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-08 00:24:00 +01:00
|
|
|
unsigned char get_basic_fc(const type_t *type)
|
|
|
|
{
|
|
|
|
int sign = type_basic_get_sign(type);
|
|
|
|
switch (type_basic_get_type(type))
|
|
|
|
{
|
2018-06-13 04:19:11 +02:00
|
|
|
case TYPE_BASIC_INT8: return (sign <= 0 ? FC_SMALL : FC_USMALL);
|
|
|
|
case TYPE_BASIC_INT16: return (sign <= 0 ? FC_SHORT : FC_USHORT);
|
2018-11-01 15:02:28 +01:00
|
|
|
case TYPE_BASIC_INT32:
|
|
|
|
case TYPE_BASIC_LONG: return (sign <= 0 ? FC_LONG : FC_ULONG);
|
2018-06-13 04:19:11 +02:00
|
|
|
case TYPE_BASIC_INT64: return FC_HYPER;
|
|
|
|
case TYPE_BASIC_INT: return (sign <= 0 ? FC_LONG : FC_ULONG);
|
|
|
|
case TYPE_BASIC_INT3264: return (sign <= 0 ? FC_INT3264 : FC_UINT3264);
|
|
|
|
case TYPE_BASIC_BYTE: return FC_BYTE;
|
|
|
|
case TYPE_BASIC_CHAR: return FC_CHAR;
|
|
|
|
case TYPE_BASIC_WCHAR: return FC_WCHAR;
|
|
|
|
case TYPE_BASIC_HYPER: return FC_HYPER;
|
|
|
|
case TYPE_BASIC_FLOAT: return FC_FLOAT;
|
|
|
|
case TYPE_BASIC_DOUBLE: return FC_DOUBLE;
|
|
|
|
case TYPE_BASIC_ERROR_STATUS_T: return FC_ERROR_STATUS_T;
|
|
|
|
case TYPE_BASIC_HANDLE: return FC_BIND_PRIMITIVE;
|
2009-03-08 00:24:00 +01:00
|
|
|
}
|
2009-11-07 15:54:56 +01:00
|
|
|
return 0;
|
2009-03-08 00:24:00 +01:00
|
|
|
}
|
|
|
|
|
2011-06-03 12:26:31 +02:00
|
|
|
static unsigned char get_basic_fc_signed(const type_t *type)
|
|
|
|
{
|
|
|
|
switch (type_basic_get_type(type))
|
|
|
|
{
|
2018-06-13 04:19:11 +02:00
|
|
|
case TYPE_BASIC_INT8: return FC_SMALL;
|
|
|
|
case TYPE_BASIC_INT16: return FC_SHORT;
|
|
|
|
case TYPE_BASIC_INT32: return FC_LONG;
|
|
|
|
case TYPE_BASIC_INT64: return FC_HYPER;
|
|
|
|
case TYPE_BASIC_INT: return FC_LONG;
|
|
|
|
case TYPE_BASIC_INT3264: return FC_INT3264;
|
2018-11-01 15:02:28 +01:00
|
|
|
case TYPE_BASIC_LONG: return FC_LONG;
|
2018-06-13 04:19:11 +02:00
|
|
|
case TYPE_BASIC_BYTE: return FC_BYTE;
|
|
|
|
case TYPE_BASIC_CHAR: return FC_CHAR;
|
|
|
|
case TYPE_BASIC_WCHAR: return FC_WCHAR;
|
|
|
|
case TYPE_BASIC_HYPER: return FC_HYPER;
|
|
|
|
case TYPE_BASIC_FLOAT: return FC_FLOAT;
|
|
|
|
case TYPE_BASIC_DOUBLE: return FC_DOUBLE;
|
|
|
|
case TYPE_BASIC_ERROR_STATUS_T: return FC_ERROR_STATUS_T;
|
|
|
|
case TYPE_BASIC_HANDLE: return FC_BIND_PRIMITIVE;
|
2011-06-03 12:26:31 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-08-25 14:29:47 +02:00
|
|
|
static inline unsigned int clamp_align(unsigned int align)
|
|
|
|
{
|
|
|
|
unsigned int packing = (pointer_size == 4) ? win32_packing : win64_packing;
|
|
|
|
if(align > packing) align = packing;
|
|
|
|
return align;
|
|
|
|
}
|
|
|
|
|
2009-03-08 00:23:44 +01:00
|
|
|
unsigned char get_pointer_fc(const type_t *type, const attr_list_t *attrs, int toplevel_param)
|
2009-01-07 00:20:59 +01:00
|
|
|
{
|
2009-03-08 00:23:44 +01:00
|
|
|
const type_t *t;
|
|
|
|
int pointer_type;
|
|
|
|
|
|
|
|
assert(is_ptr(type) || is_array(type));
|
|
|
|
|
|
|
|
pointer_type = get_attrv(attrs, ATTR_POINTERTYPE);
|
|
|
|
if (pointer_type)
|
|
|
|
return pointer_type;
|
|
|
|
|
|
|
|
for (t = type; type_is_alias(t); t = type_alias_get_aliasee(t))
|
|
|
|
{
|
|
|
|
pointer_type = get_attrv(t->attrs, ATTR_POINTERTYPE);
|
|
|
|
if (pointer_type)
|
|
|
|
return pointer_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (toplevel_param)
|
2018-06-13 04:19:11 +02:00
|
|
|
return FC_RP;
|
2009-03-08 00:23:44 +01:00
|
|
|
else if (is_ptr(type))
|
|
|
|
return type_pointer_get_default_fc(type);
|
|
|
|
else
|
|
|
|
return type_array_get_ptr_default_fc(type);
|
2009-01-07 00:20:59 +01:00
|
|
|
}
|
|
|
|
|
2011-06-14 12:24:00 +02:00
|
|
|
static unsigned char get_pointer_fc_context( const type_t *type, const attr_list_t *attrs,
|
|
|
|
enum type_context context )
|
|
|
|
{
|
|
|
|
int pointer_fc = get_pointer_fc(type, attrs, context == TYPE_CONTEXT_TOPLEVELPARAM);
|
|
|
|
|
2018-06-13 04:19:11 +02:00
|
|
|
if (pointer_fc == FC_UP && is_attr( attrs, ATTR_OUT ) &&
|
2019-01-24 13:38:40 +01:00
|
|
|
(context == TYPE_CONTEXT_PARAM || context == TYPE_CONTEXT_RETVAL) && is_object( current_iface ))
|
2018-06-13 04:19:11 +02:00
|
|
|
pointer_fc = FC_OP;
|
2011-06-14 12:24:00 +02:00
|
|
|
|
|
|
|
return pointer_fc;
|
|
|
|
}
|
|
|
|
|
2009-02-23 14:48:34 +01:00
|
|
|
static unsigned char get_enum_fc(const type_t *type)
|
|
|
|
{
|
|
|
|
assert(type_get_type(type) == TYPE_ENUM);
|
|
|
|
if (is_aliaschain_attr(type, ATTR_V1ENUM))
|
2018-06-13 04:19:11 +02:00
|
|
|
return FC_ENUM32;
|
2009-02-23 14:48:34 +01:00
|
|
|
else
|
2018-06-13 04:19:11 +02:00
|
|
|
return FC_ENUM16;
|
2009-02-23 14:48:34 +01:00
|
|
|
}
|
|
|
|
|
2010-03-15 20:29:33 +01:00
|
|
|
static type_t *get_user_type(const type_t *t, const char **pname)
|
|
|
|
{
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
type_t *ut = get_attrp(t->attrs, ATTR_WIREMARSHAL);
|
|
|
|
if (ut)
|
|
|
|
{
|
|
|
|
if (pname)
|
|
|
|
*pname = t->name;
|
|
|
|
return ut;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type_is_alias(t))
|
|
|
|
t = type_alias_get_aliasee(t);
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int is_user_type(const type_t *t)
|
|
|
|
{
|
|
|
|
return get_user_type(t, NULL) != NULL;
|
|
|
|
}
|
|
|
|
|
2009-02-23 14:48:46 +01:00
|
|
|
enum typegen_type typegen_detect_type(const type_t *type, const attr_list_t *attrs, unsigned int flags)
|
|
|
|
{
|
|
|
|
if (is_user_type(type))
|
|
|
|
return TGT_USER_TYPE;
|
|
|
|
|
|
|
|
if (is_aliaschain_attr(type, ATTR_CONTEXTHANDLE))
|
|
|
|
return TGT_CTXT_HANDLE;
|
|
|
|
|
|
|
|
if (!(flags & TDT_IGNORE_STRINGS) && is_string_type(attrs, type))
|
|
|
|
return TGT_STRING;
|
|
|
|
|
|
|
|
switch (type_get_type(type))
|
|
|
|
{
|
|
|
|
case TYPE_BASIC:
|
2009-11-12 11:31:25 +01:00
|
|
|
if (!(flags & TDT_IGNORE_RANGES) &&
|
|
|
|
(is_attr(attrs, ATTR_RANGE) || is_aliaschain_attr(type, ATTR_RANGE)))
|
2009-11-07 15:54:28 +01:00
|
|
|
return TGT_RANGE;
|
2009-02-23 14:48:46 +01:00
|
|
|
return TGT_BASIC;
|
|
|
|
case TYPE_ENUM:
|
2009-11-12 11:31:25 +01:00
|
|
|
if (!(flags & TDT_IGNORE_RANGES) &&
|
|
|
|
(is_attr(attrs, ATTR_RANGE) || is_aliaschain_attr(type, ATTR_RANGE)))
|
2009-11-07 15:54:28 +01:00
|
|
|
return TGT_RANGE;
|
2009-02-23 14:48:46 +01:00
|
|
|
return TGT_ENUM;
|
|
|
|
case TYPE_POINTER:
|
|
|
|
if (type_get_type(type_pointer_get_ref(type)) == TYPE_INTERFACE ||
|
|
|
|
(type_get_type(type_pointer_get_ref(type)) == TYPE_VOID && is_attr(attrs, ATTR_IIDIS)))
|
|
|
|
return TGT_IFACE_POINTER;
|
|
|
|
else if (is_aliaschain_attr(type_pointer_get_ref(type), ATTR_CONTEXTHANDLE))
|
|
|
|
return TGT_CTXT_HANDLE_POINTER;
|
|
|
|
else
|
|
|
|
return TGT_POINTER;
|
|
|
|
case TYPE_STRUCT:
|
|
|
|
return TGT_STRUCT;
|
|
|
|
case TYPE_ENCAPSULATED_UNION:
|
|
|
|
case TYPE_UNION:
|
|
|
|
return TGT_UNION;
|
|
|
|
case TYPE_ARRAY:
|
|
|
|
return TGT_ARRAY;
|
|
|
|
case TYPE_FUNCTION:
|
|
|
|
case TYPE_COCLASS:
|
|
|
|
case TYPE_INTERFACE:
|
|
|
|
case TYPE_MODULE:
|
|
|
|
case TYPE_VOID:
|
|
|
|
case TYPE_ALIAS:
|
2009-11-07 15:55:09 +01:00
|
|
|
case TYPE_BITFIELD:
|
2009-02-23 14:48:46 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TGT_INVALID;
|
|
|
|
}
|
|
|
|
|
2011-06-14 12:55:39 +02:00
|
|
|
static int cant_be_null(const var_t *v)
|
|
|
|
{
|
|
|
|
switch (typegen_detect_type(v->type, v->attrs, TDT_IGNORE_STRINGS))
|
|
|
|
{
|
|
|
|
case TGT_ARRAY:
|
|
|
|
if (!type_array_is_decl_as_ptr( v->type )) return 0;
|
|
|
|
/* fall through */
|
|
|
|
case TGT_POINTER:
|
2018-06-13 04:19:11 +02:00
|
|
|
return (get_pointer_fc(v->type, v->attrs, TRUE) == FC_RP);
|
2011-06-14 12:55:39 +02:00
|
|
|
case TGT_CTXT_HANDLE_POINTER:
|
|
|
|
return TRUE;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-03-15 20:29:33 +01:00
|
|
|
static int get_padding(const var_list_t *fields)
|
|
|
|
{
|
|
|
|
unsigned short offset = 0;
|
|
|
|
unsigned int salign = 1;
|
|
|
|
const var_t *f;
|
|
|
|
|
|
|
|
if (!fields)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(f, fields, const var_t, entry)
|
|
|
|
{
|
|
|
|
type_t *ft = f->type;
|
|
|
|
unsigned int align = 0;
|
2010-04-05 19:48:07 +02:00
|
|
|
unsigned int size = type_memsize_and_alignment(ft, &align);
|
2010-03-15 20:29:33 +01:00
|
|
|
align = clamp_align(align);
|
|
|
|
if (align > salign) salign = align;
|
|
|
|
offset = ROUND_SIZE(offset, align);
|
|
|
|
offset += size;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ROUNDING(offset, salign);
|
|
|
|
}
|
|
|
|
|
2011-09-19 11:54:42 +02:00
|
|
|
static unsigned int get_stack_size( const var_t *var, int *by_value )
|
2011-05-25 20:32:12 +02:00
|
|
|
{
|
|
|
|
unsigned int stack_size;
|
|
|
|
int by_val;
|
|
|
|
|
2011-09-19 11:54:42 +02:00
|
|
|
switch (typegen_detect_type( var->type, var->attrs, TDT_ALL_TYPES ))
|
2011-05-25 20:32:12 +02:00
|
|
|
{
|
|
|
|
case TGT_BASIC:
|
|
|
|
case TGT_ENUM:
|
|
|
|
case TGT_RANGE:
|
|
|
|
case TGT_STRUCT:
|
|
|
|
case TGT_UNION:
|
|
|
|
case TGT_USER_TYPE:
|
2011-09-19 11:54:42 +02:00
|
|
|
stack_size = type_memsize( var->type );
|
2011-05-25 20:32:12 +02:00
|
|
|
by_val = (pointer_size < 8 || stack_size <= pointer_size); /* FIXME: should be platform-specific */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
by_val = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!by_val) stack_size = pointer_size;
|
|
|
|
if (by_value) *by_value = by_val;
|
|
|
|
return ROUND_SIZE( stack_size, pointer_size );
|
|
|
|
}
|
|
|
|
|
2011-06-01 20:21:37 +02:00
|
|
|
static unsigned char get_contexthandle_flags( const type_t *iface, const attr_list_t *attrs,
|
2019-01-24 13:38:40 +01:00
|
|
|
const type_t *type, int is_return )
|
2011-06-01 20:21:37 +02:00
|
|
|
{
|
|
|
|
unsigned char flags = 0;
|
2019-01-24 13:38:51 +01:00
|
|
|
int is_out;
|
2011-06-01 20:21:37 +02:00
|
|
|
|
|
|
|
if (is_attr(iface->attrs, ATTR_STRICTCONTEXTHANDLE)) flags |= NDR_STRICT_CONTEXT_HANDLE;
|
|
|
|
|
|
|
|
if (is_ptr(type) &&
|
|
|
|
!is_attr( type->attrs, ATTR_CONTEXTHANDLE ) &&
|
|
|
|
!is_attr( attrs, ATTR_CONTEXTHANDLE ))
|
2019-01-23 12:27:26 +01:00
|
|
|
flags |= HANDLE_PARAM_IS_VIA_PTR;
|
2011-06-01 20:21:37 +02:00
|
|
|
|
2019-01-24 13:38:40 +01:00
|
|
|
if (is_return) return flags | HANDLE_PARAM_IS_OUT | HANDLE_PARAM_IS_RETURN;
|
|
|
|
|
2019-01-24 13:38:51 +01:00
|
|
|
is_out = is_attr(attrs, ATTR_OUT);
|
|
|
|
if (is_attr(attrs, ATTR_IN) || !is_out)
|
2011-06-01 20:21:37 +02:00
|
|
|
{
|
2019-01-23 12:27:26 +01:00
|
|
|
flags |= HANDLE_PARAM_IS_IN;
|
2019-01-24 13:38:51 +01:00
|
|
|
if (!is_out) flags |= NDR_CONTEXT_HANDLE_CANNOT_BE_NULL;
|
2011-06-01 20:21:37 +02:00
|
|
|
}
|
2019-01-24 13:38:51 +01:00
|
|
|
if (is_out) flags |= HANDLE_PARAM_IS_OUT;
|
2011-06-01 20:21:37 +02:00
|
|
|
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2011-06-01 21:06:14 +02:00
|
|
|
static unsigned int get_rpc_flags( const attr_list_t *attrs )
|
|
|
|
{
|
|
|
|
unsigned int flags = 0;
|
|
|
|
|
|
|
|
if (is_attr( attrs, ATTR_IDEMPOTENT )) flags |= 0x0001;
|
|
|
|
if (is_attr( attrs, ATTR_BROADCAST )) flags |= 0x0002;
|
|
|
|
if (is_attr( attrs, ATTR_MAYBE )) flags |= 0x0004;
|
|
|
|
if (is_attr( attrs, ATTR_MESSAGE )) flags |= 0x0100;
|
|
|
|
if (is_attr( attrs, ATTR_ASYNC )) flags |= 0x4000;
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2009-02-23 14:48:34 +01:00
|
|
|
unsigned char get_struct_fc(const type_t *type)
|
2008-12-26 16:26:59 +01:00
|
|
|
{
|
|
|
|
int has_pointer = 0;
|
|
|
|
int has_conformance = 0;
|
|
|
|
int has_variance = 0;
|
|
|
|
var_t *field;
|
2008-12-29 13:05:27 +01:00
|
|
|
var_list_t *fields;
|
2008-12-26 16:26:59 +01:00
|
|
|
|
2008-12-29 13:05:27 +01:00
|
|
|
fields = type_struct_get_fields(type);
|
|
|
|
|
|
|
|
if (get_padding(fields))
|
2018-06-13 04:19:11 +02:00
|
|
|
return FC_BOGUS_STRUCT;
|
2008-12-26 16:26:59 +01:00
|
|
|
|
2008-12-29 13:05:27 +01:00
|
|
|
if (fields) LIST_FOR_EACH_ENTRY( field, fields, var_t, entry )
|
2008-12-26 16:26:59 +01:00
|
|
|
{
|
|
|
|
type_t *t = field->type;
|
2009-02-23 14:48:46 +01:00
|
|
|
enum typegen_type typegen_type;
|
2008-12-26 16:26:59 +01:00
|
|
|
|
2009-02-23 14:48:46 +01:00
|
|
|
typegen_type = typegen_detect_type(t, field->attrs, TDT_IGNORE_STRINGS);
|
2008-12-26 16:26:59 +01:00
|
|
|
|
2009-03-05 09:21:35 +01:00
|
|
|
if (typegen_type == TGT_ARRAY && !type_array_is_decl_as_ptr(t))
|
2008-12-26 16:26:59 +01:00
|
|
|
{
|
|
|
|
if (is_string_type(field->attrs, field->type))
|
|
|
|
{
|
2009-02-23 14:48:34 +01:00
|
|
|
if (is_conformant_array(t))
|
2008-12-26 16:26:59 +01:00
|
|
|
has_conformance = 1;
|
|
|
|
has_variance = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-01-06 00:34:58 +01:00
|
|
|
if (is_array(type_array_get_element(field->type)))
|
2018-06-13 04:19:11 +02:00
|
|
|
return FC_BOGUS_STRUCT;
|
2008-12-26 16:26:59 +01:00
|
|
|
|
2009-01-06 00:33:36 +01:00
|
|
|
if (type_array_has_conformance(field->type))
|
2008-12-26 16:26:59 +01:00
|
|
|
{
|
|
|
|
has_conformance = 1;
|
2009-02-23 14:48:34 +01:00
|
|
|
if (list_next(fields, &field->entry))
|
2008-12-26 16:26:59 +01:00
|
|
|
error_loc("field '%s' deriving from a conformant array must be the last field in the structure\n",
|
|
|
|
field->name);
|
|
|
|
}
|
2009-02-23 14:48:34 +01:00
|
|
|
if (type_array_has_variance(t))
|
2008-12-26 16:26:59 +01:00
|
|
|
has_variance = 1;
|
|
|
|
|
2009-02-23 14:48:34 +01:00
|
|
|
t = type_array_get_element(t);
|
2009-02-23 14:48:46 +01:00
|
|
|
typegen_type = typegen_detect_type(t, field->attrs, TDT_IGNORE_STRINGS);
|
2009-02-23 14:48:34 +01:00
|
|
|
}
|
2008-12-26 16:26:59 +01:00
|
|
|
|
2009-02-23 14:48:46 +01:00
|
|
|
switch (typegen_type)
|
2009-02-23 14:48:34 +01:00
|
|
|
{
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_USER_TYPE:
|
|
|
|
case TGT_IFACE_POINTER:
|
2018-06-13 04:19:11 +02:00
|
|
|
return FC_BOGUS_STRUCT;
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_BASIC:
|
2009-11-07 15:54:56 +01:00
|
|
|
if (type_basic_get_type(t) == TYPE_BASIC_INT3264 && pointer_size != 4)
|
2018-06-13 04:19:11 +02:00
|
|
|
return FC_BOGUS_STRUCT;
|
2009-02-23 14:48:34 +01:00
|
|
|
break;
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_ENUM:
|
2018-06-13 04:19:11 +02:00
|
|
|
if (get_enum_fc(t) == FC_ENUM16)
|
|
|
|
return FC_BOGUS_STRUCT;
|
2009-02-23 14:48:34 +01:00
|
|
|
break;
|
2009-08-21 13:10:56 +02:00
|
|
|
case TGT_POINTER:
|
2009-11-07 13:29:19 +01:00
|
|
|
case TGT_ARRAY:
|
2018-06-13 04:19:11 +02:00
|
|
|
if (get_pointer_fc(t, field->attrs, FALSE) == FC_RP || pointer_size != 4)
|
|
|
|
return FC_BOGUS_STRUCT;
|
2009-02-23 14:48:34 +01:00
|
|
|
has_pointer = 1;
|
|
|
|
break;
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_UNION:
|
2018-06-13 04:19:11 +02:00
|
|
|
return FC_BOGUS_STRUCT;
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_STRUCT:
|
2009-02-23 14:48:34 +01:00
|
|
|
{
|
|
|
|
unsigned char fc = get_struct_fc(t);
|
|
|
|
switch (fc)
|
|
|
|
{
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_STRUCT:
|
2009-02-23 14:48:34 +01:00
|
|
|
break;
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_CVSTRUCT:
|
2009-02-23 14:48:34 +01:00
|
|
|
has_conformance = 1;
|
|
|
|
has_variance = 1;
|
|
|
|
has_pointer = 1;
|
|
|
|
break;
|
2008-12-26 16:26:59 +01:00
|
|
|
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_CPSTRUCT:
|
2009-02-23 14:48:34 +01:00
|
|
|
has_conformance = 1;
|
|
|
|
if (list_next( fields, &field->entry ))
|
|
|
|
error_loc("field '%s' deriving from a conformant array must be the last field in the structure\n",
|
|
|
|
field->name);
|
|
|
|
has_pointer = 1;
|
|
|
|
break;
|
2008-12-26 16:26:59 +01:00
|
|
|
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_CSTRUCT:
|
2009-02-23 14:48:34 +01:00
|
|
|
has_conformance = 1;
|
|
|
|
if (list_next( fields, &field->entry ))
|
|
|
|
error_loc("field '%s' deriving from a conformant array must be the last field in the structure\n",
|
|
|
|
field->name);
|
|
|
|
break;
|
2008-12-26 16:26:59 +01:00
|
|
|
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_PSTRUCT:
|
2009-02-23 14:48:34 +01:00
|
|
|
has_pointer = 1;
|
|
|
|
break;
|
2008-12-26 16:26:59 +01:00
|
|
|
|
2009-02-23 14:48:34 +01:00
|
|
|
default:
|
|
|
|
error_loc("Unknown struct member %s with type (0x%02x)\n", field->name, fc);
|
|
|
|
/* fallthru - treat it as complex */
|
2008-12-26 16:26:59 +01:00
|
|
|
|
2009-02-23 14:48:34 +01:00
|
|
|
/* as soon as we see one of these these members, it's bogus... */
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_BOGUS_STRUCT:
|
|
|
|
return FC_BOGUS_STRUCT;
|
2009-02-23 14:48:34 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2009-11-07 15:54:28 +01:00
|
|
|
case TGT_RANGE:
|
2018-06-13 04:19:11 +02:00
|
|
|
return FC_BOGUS_STRUCT;
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_STRING:
|
|
|
|
/* shouldn't get here because of TDT_IGNORE_STRINGS above. fall through */
|
|
|
|
case TGT_INVALID:
|
|
|
|
case TGT_CTXT_HANDLE:
|
|
|
|
case TGT_CTXT_HANDLE_POINTER:
|
|
|
|
/* checking after parsing should mean that we don't get here. if we do,
|
|
|
|
* it's a checker bug */
|
|
|
|
assert(0);
|
2008-12-26 16:26:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( has_variance )
|
|
|
|
{
|
|
|
|
if ( has_conformance )
|
2018-06-13 04:19:11 +02:00
|
|
|
return FC_CVSTRUCT;
|
2008-12-26 16:26:59 +01:00
|
|
|
else
|
2018-06-13 04:19:11 +02:00
|
|
|
return FC_BOGUS_STRUCT;
|
2008-12-26 16:26:59 +01:00
|
|
|
}
|
|
|
|
if( has_conformance && has_pointer )
|
2018-06-13 04:19:11 +02:00
|
|
|
return FC_CPSTRUCT;
|
2008-12-26 16:26:59 +01:00
|
|
|
if( has_conformance )
|
2018-06-13 04:19:11 +02:00
|
|
|
return FC_CSTRUCT;
|
2008-12-26 16:26:59 +01:00
|
|
|
if( has_pointer )
|
2018-06-13 04:19:11 +02:00
|
|
|
return FC_PSTRUCT;
|
|
|
|
return FC_STRUCT;
|
2008-12-26 16:26:59 +01:00
|
|
|
}
|
|
|
|
|
2010-01-21 12:56:53 +01:00
|
|
|
static unsigned char get_array_fc(const type_t *type)
|
2008-12-26 16:26:59 +01:00
|
|
|
{
|
2009-01-07 00:20:59 +01:00
|
|
|
unsigned char fc;
|
|
|
|
const expr_t *size_is;
|
|
|
|
const type_t *elem_type;
|
|
|
|
|
|
|
|
elem_type = type_array_get_element(type);
|
|
|
|
size_is = type_array_get_conformance(type);
|
|
|
|
|
|
|
|
if (!size_is)
|
|
|
|
{
|
2010-04-05 19:48:07 +02:00
|
|
|
unsigned int size = type_memsize(elem_type);
|
2009-01-07 00:20:59 +01:00
|
|
|
if (size * type_array_get_dim(type) > 0xffffuL)
|
2018-06-13 04:19:11 +02:00
|
|
|
fc = FC_LGFARRAY;
|
2009-01-07 00:20:59 +01:00
|
|
|
else
|
2018-06-13 04:19:11 +02:00
|
|
|
fc = FC_SMFARRAY;
|
2009-01-07 00:20:59 +01:00
|
|
|
}
|
|
|
|
else
|
2018-06-13 04:19:11 +02:00
|
|
|
fc = FC_CARRAY;
|
2009-01-07 00:20:59 +01:00
|
|
|
|
|
|
|
if (type_array_has_variance(type))
|
2008-12-26 16:26:59 +01:00
|
|
|
{
|
2018-06-13 04:19:11 +02:00
|
|
|
if (fc == FC_SMFARRAY)
|
|
|
|
fc = FC_SMVARRAY;
|
|
|
|
else if (fc == FC_LGFARRAY)
|
|
|
|
fc = FC_LGVARRAY;
|
|
|
|
else if (fc == FC_CARRAY)
|
|
|
|
fc = FC_CVARRAY;
|
2009-01-07 00:20:59 +01:00
|
|
|
}
|
|
|
|
|
2009-02-23 14:48:46 +01:00
|
|
|
switch (typegen_detect_type(elem_type, NULL, TDT_IGNORE_STRINGS))
|
2009-01-07 00:20:59 +01:00
|
|
|
{
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_USER_TYPE:
|
2018-06-13 04:19:11 +02:00
|
|
|
fc = FC_BOGUS_ARRAY;
|
2009-02-23 14:48:46 +01:00
|
|
|
break;
|
2009-11-07 15:54:56 +01:00
|
|
|
case TGT_BASIC:
|
|
|
|
if (type_basic_get_type(elem_type) == TYPE_BASIC_INT3264 &&
|
|
|
|
pointer_size != 4)
|
2018-06-13 04:19:11 +02:00
|
|
|
fc = FC_BOGUS_ARRAY;
|
2009-11-07 15:54:56 +01:00
|
|
|
break;
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_STRUCT:
|
2009-02-23 14:48:34 +01:00
|
|
|
switch (get_struct_fc(elem_type))
|
2008-12-26 16:26:59 +01:00
|
|
|
{
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_BOGUS_STRUCT:
|
|
|
|
fc = FC_BOGUS_ARRAY;
|
2008-12-26 16:26:59 +01:00
|
|
|
break;
|
|
|
|
}
|
2009-02-23 14:48:34 +01:00
|
|
|
break;
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_ENUM:
|
2009-01-07 00:20:59 +01:00
|
|
|
/* is 16-bit enum - if so, wire size differs from mem size and so
|
|
|
|
* the array cannot be block copied, which means the array is complex */
|
2018-06-13 04:19:11 +02:00
|
|
|
if (get_enum_fc(elem_type) == FC_ENUM16)
|
|
|
|
fc = FC_BOGUS_ARRAY;
|
2009-02-23 14:48:34 +01:00
|
|
|
break;
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_UNION:
|
|
|
|
case TGT_IFACE_POINTER:
|
2018-06-13 04:19:11 +02:00
|
|
|
fc = FC_BOGUS_ARRAY;
|
2009-02-23 14:48:34 +01:00
|
|
|
break;
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_POINTER:
|
2009-01-07 00:20:59 +01:00
|
|
|
/* ref pointers cannot just be block copied. unique pointers to
|
|
|
|
* interfaces need special treatment. either case means the array is
|
|
|
|
* complex */
|
2018-06-13 04:19:11 +02:00
|
|
|
if (get_pointer_fc(elem_type, NULL, FALSE) == FC_RP || pointer_size != 4)
|
|
|
|
fc = FC_BOGUS_ARRAY;
|
2009-02-23 14:48:34 +01:00
|
|
|
break;
|
2009-11-07 15:54:28 +01:00
|
|
|
case TGT_RANGE:
|
2018-06-13 04:19:11 +02:00
|
|
|
fc = FC_BOGUS_ARRAY;
|
2009-11-07 15:54:28 +01:00
|
|
|
break;
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_CTXT_HANDLE:
|
|
|
|
case TGT_CTXT_HANDLE_POINTER:
|
|
|
|
case TGT_STRING:
|
|
|
|
case TGT_INVALID:
|
|
|
|
case TGT_ARRAY:
|
2009-02-23 14:48:34 +01:00
|
|
|
/* nothing to do for everything else */
|
|
|
|
break;
|
2009-01-07 00:20:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return fc;
|
2008-12-26 16:26:59 +01:00
|
|
|
}
|
|
|
|
|
2007-06-19 13:05:25 +02:00
|
|
|
static int is_non_complex_struct(const type_t *type)
|
|
|
|
{
|
2009-02-23 14:48:34 +01:00
|
|
|
return (type_get_type(type) == TYPE_STRUCT &&
|
2018-06-13 04:19:11 +02:00
|
|
|
get_struct_fc(type) != FC_BOGUS_STRUCT);
|
2007-05-19 01:53:27 +02:00
|
|
|
}
|
|
|
|
|
2007-12-25 18:06:28 +01:00
|
|
|
static int type_has_pointers(const type_t *type)
|
|
|
|
{
|
2009-02-23 14:48:46 +01:00
|
|
|
switch (typegen_detect_type(type, NULL, TDT_IGNORE_STRINGS))
|
2009-02-23 14:48:34 +01:00
|
|
|
{
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_USER_TYPE:
|
|
|
|
return FALSE;
|
|
|
|
case TGT_POINTER:
|
2007-12-25 18:06:28 +01:00
|
|
|
return TRUE;
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_ARRAY:
|
2009-10-16 14:59:01 +02:00
|
|
|
return type_array_is_decl_as_ptr(type) || type_has_pointers(type_array_get_element(type));
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_STRUCT:
|
2007-12-25 18:06:28 +01:00
|
|
|
{
|
2008-12-29 13:05:27 +01:00
|
|
|
var_list_t *fields = type_struct_get_fields(type);
|
2007-12-25 18:06:28 +01:00
|
|
|
const var_t *field;
|
2008-12-29 13:05:27 +01:00
|
|
|
if (fields) LIST_FOR_EACH_ENTRY( field, fields, const var_t, entry )
|
2007-12-25 18:06:28 +01:00
|
|
|
{
|
|
|
|
if (type_has_pointers(field->type))
|
|
|
|
return TRUE;
|
|
|
|
}
|
2009-02-23 14:48:34 +01:00
|
|
|
break;
|
2007-12-25 18:06:28 +01:00
|
|
|
}
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_UNION:
|
2007-12-25 18:06:28 +01:00
|
|
|
{
|
|
|
|
var_list_t *fields;
|
|
|
|
const var_t *field;
|
2008-12-29 13:05:27 +01:00
|
|
|
fields = type_union_get_cases(type);
|
2007-12-25 18:06:28 +01:00
|
|
|
if (fields) LIST_FOR_EACH_ENTRY( field, fields, const var_t, entry )
|
|
|
|
{
|
|
|
|
if (field->type && type_has_pointers(field->type))
|
|
|
|
return TRUE;
|
|
|
|
}
|
2009-02-23 14:48:34 +01:00
|
|
|
break;
|
|
|
|
}
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_CTXT_HANDLE:
|
|
|
|
case TGT_CTXT_HANDLE_POINTER:
|
|
|
|
case TGT_STRING:
|
|
|
|
case TGT_IFACE_POINTER:
|
|
|
|
case TGT_BASIC:
|
|
|
|
case TGT_ENUM:
|
2009-11-07 15:54:28 +01:00
|
|
|
case TGT_RANGE:
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_INVALID:
|
2009-02-23 14:48:34 +01:00
|
|
|
break;
|
2007-12-25 18:06:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-03-08 00:23:44 +01:00
|
|
|
static int type_has_full_pointer(const type_t *type, const attr_list_t *attrs,
|
|
|
|
int toplevel_param)
|
2008-01-30 23:29:39 +01:00
|
|
|
{
|
2009-02-23 14:48:46 +01:00
|
|
|
switch (typegen_detect_type(type, NULL, TDT_IGNORE_STRINGS))
|
2009-02-23 14:48:34 +01:00
|
|
|
{
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_USER_TYPE:
|
|
|
|
return FALSE;
|
|
|
|
case TGT_POINTER:
|
2018-06-13 04:19:11 +02:00
|
|
|
if (get_pointer_fc(type, attrs, toplevel_param) == FC_FP)
|
2009-02-23 14:48:34 +01:00
|
|
|
return TRUE;
|
|
|
|
else
|
|
|
|
return FALSE;
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_ARRAY:
|
2018-06-13 04:19:11 +02:00
|
|
|
if (get_pointer_fc(type, attrs, toplevel_param) == FC_FP)
|
2009-03-08 00:23:44 +01:00
|
|
|
return TRUE;
|
|
|
|
else
|
|
|
|
return type_has_full_pointer(type_array_get_element(type), NULL, FALSE);
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_STRUCT:
|
2008-01-30 23:29:39 +01:00
|
|
|
{
|
2008-12-29 13:05:27 +01:00
|
|
|
var_list_t *fields = type_struct_get_fields(type);
|
2008-01-30 23:29:39 +01:00
|
|
|
const var_t *field;
|
2008-12-29 13:05:27 +01:00
|
|
|
if (fields) LIST_FOR_EACH_ENTRY( field, fields, const var_t, entry )
|
2008-01-30 23:29:39 +01:00
|
|
|
{
|
2009-03-08 00:23:44 +01:00
|
|
|
if (type_has_full_pointer(field->type, field->attrs, FALSE))
|
2008-01-30 23:29:39 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
2009-02-23 14:48:34 +01:00
|
|
|
break;
|
2008-01-30 23:29:39 +01:00
|
|
|
}
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_UNION:
|
2008-01-30 23:29:39 +01:00
|
|
|
{
|
|
|
|
var_list_t *fields;
|
|
|
|
const var_t *field;
|
2008-12-29 13:05:27 +01:00
|
|
|
fields = type_union_get_cases(type);
|
2008-01-30 23:29:39 +01:00
|
|
|
if (fields) LIST_FOR_EACH_ENTRY( field, fields, const var_t, entry )
|
|
|
|
{
|
2009-03-08 00:23:44 +01:00
|
|
|
if (field->type && type_has_full_pointer(field->type, field->attrs, FALSE))
|
2008-01-30 23:29:39 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
2009-02-23 14:48:34 +01:00
|
|
|
break;
|
|
|
|
}
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_CTXT_HANDLE:
|
|
|
|
case TGT_CTXT_HANDLE_POINTER:
|
|
|
|
case TGT_STRING:
|
|
|
|
case TGT_IFACE_POINTER:
|
|
|
|
case TGT_BASIC:
|
|
|
|
case TGT_ENUM:
|
2009-11-07 15:54:28 +01:00
|
|
|
case TGT_RANGE:
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_INVALID:
|
2009-02-23 14:48:34 +01:00
|
|
|
break;
|
2008-01-30 23:29:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-06-14 01:13:04 +02:00
|
|
|
static unsigned short user_type_offset(const char *name)
|
|
|
|
{
|
|
|
|
user_type_t *ut;
|
|
|
|
unsigned short off = 0;
|
|
|
|
LIST_FOR_EACH_ENTRY(ut, &user_type_list, user_type_t, entry)
|
|
|
|
{
|
|
|
|
if (strcmp(name, ut->name) == 0)
|
|
|
|
return off;
|
|
|
|
++off;
|
|
|
|
}
|
|
|
|
error("user_type_offset: couldn't find type (%s)\n", name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-05-25 02:50:02 +02:00
|
|
|
static void update_tfsoff(type_t *type, unsigned int offset, FILE *file)
|
|
|
|
{
|
|
|
|
type->typestring_offset = offset;
|
|
|
|
if (file) type->tfswrite = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void guard_rec(type_t *type)
|
|
|
|
{
|
|
|
|
/* types that contain references to themselves (like a linked list),
|
|
|
|
need to be shielded from infinite recursion when writing embedded
|
|
|
|
types */
|
|
|
|
if (type->typestring_offset)
|
|
|
|
type->tfswrite = FALSE;
|
|
|
|
else
|
|
|
|
type->typestring_offset = 1;
|
|
|
|
}
|
|
|
|
|
2007-05-19 01:53:27 +02:00
|
|
|
static int is_embedded_complex(const type_t *type)
|
|
|
|
{
|
2009-02-23 14:48:46 +01:00
|
|
|
switch (typegen_detect_type(type, NULL, TDT_ALL_TYPES))
|
2009-02-23 14:48:34 +01:00
|
|
|
{
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_USER_TYPE:
|
|
|
|
case TGT_STRUCT:
|
|
|
|
case TGT_UNION:
|
|
|
|
case TGT_ARRAY:
|
|
|
|
case TGT_IFACE_POINTER:
|
2009-02-23 14:48:34 +01:00
|
|
|
return TRUE;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
2007-05-19 01:53:27 +02:00
|
|
|
}
|
|
|
|
|
2007-09-28 02:38:27 +02:00
|
|
|
static const char *get_context_handle_type_name(const type_t *type)
|
|
|
|
{
|
|
|
|
const type_t *t;
|
2009-02-23 14:48:34 +01:00
|
|
|
for (t = type;
|
|
|
|
is_ptr(t) || type_is_alias(t);
|
|
|
|
t = type_is_alias(t) ? type_alias_get_aliasee(t) : type_pointer_get_ref(t))
|
2007-09-28 02:38:27 +02:00
|
|
|
if (is_attr(t->attrs, ATTR_CONTEXTHANDLE))
|
|
|
|
return t->name;
|
|
|
|
assert(0);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-01-31 12:25:54 +01:00
|
|
|
#define WRITE_FCTYPE(file, fctype, typestring_offset) \
|
|
|
|
do { \
|
|
|
|
if (file) \
|
|
|
|
fprintf(file, "/* %2u */\n", typestring_offset); \
|
2018-06-13 04:19:11 +02:00
|
|
|
print_file((file), 2, "0x%02x,\t/* " #fctype " */\n", fctype); \
|
2006-01-31 12:25:54 +01:00
|
|
|
} \
|
|
|
|
while (0)
|
|
|
|
|
2009-02-06 14:31:29 +01:00
|
|
|
static void print_file(FILE *file, int indent, const char *format, ...) __attribute__((format (printf, 3, 4)));
|
2007-06-15 03:29:33 +02:00
|
|
|
static void print_file(FILE *file, int indent, const char *format, ...)
|
2005-12-08 12:52:13 +01:00
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
va_start(va, format);
|
2007-06-15 03:29:33 +02:00
|
|
|
print(file, indent, format, va);
|
2005-12-08 12:52:13 +01:00
|
|
|
va_end(va);
|
2007-06-15 03:29:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void print(FILE *file, int indent, const char *format, va_list va)
|
|
|
|
{
|
|
|
|
if (file)
|
|
|
|
{
|
|
|
|
if (format[0] != '\n')
|
|
|
|
while (0 < indent--)
|
|
|
|
fprintf(file, " ");
|
|
|
|
vfprintf(file, format, va);
|
|
|
|
}
|
2005-12-08 12:52:13 +01:00
|
|
|
}
|
|
|
|
|
2007-12-10 15:24:11 +01:00
|
|
|
|
2008-09-15 16:46:01 +02:00
|
|
|
static void write_var_init(FILE *file, int indent, const type_t *t, const char *n, const char *local_var_prefix)
|
2007-12-10 15:24:11 +01:00
|
|
|
{
|
|
|
|
if (decl_indirect(t))
|
2008-09-15 16:46:33 +02:00
|
|
|
{
|
2008-09-15 16:46:01 +02:00
|
|
|
print_file(file, indent, "MIDL_memset(&%s%s, 0, sizeof(%s%s));\n",
|
|
|
|
local_var_prefix, n, local_var_prefix, n);
|
2008-09-15 16:46:33 +02:00
|
|
|
print_file(file, indent, "%s_p_%s = &%s%s;\n", local_var_prefix, n, local_var_prefix, n);
|
|
|
|
}
|
2007-12-10 15:24:11 +01:00
|
|
|
else if (is_ptr(t) || is_array(t))
|
2008-09-15 16:46:01 +02:00
|
|
|
print_file(file, indent, "%s%s = 0;\n", local_var_prefix, n);
|
2007-12-10 15:24:11 +01:00
|
|
|
}
|
|
|
|
|
2009-01-06 00:33:27 +01:00
|
|
|
void write_parameters_init(FILE *file, int indent, const var_t *func, const char *local_var_prefix)
|
2007-06-15 03:30:26 +02:00
|
|
|
{
|
2011-09-17 13:38:15 +02:00
|
|
|
const var_t *var = type_function_get_retval(func->type);
|
2007-06-15 03:30:26 +02:00
|
|
|
|
2011-09-17 13:38:15 +02:00
|
|
|
if (!is_void(var->type))
|
|
|
|
write_var_init(file, indent, var->type, var->name, local_var_prefix);
|
2007-12-10 15:24:11 +01:00
|
|
|
|
2009-01-06 00:33:27 +01:00
|
|
|
if (!type_get_function_args(func->type))
|
2007-06-15 03:30:26 +02:00
|
|
|
return;
|
|
|
|
|
2009-01-06 00:33:27 +01:00
|
|
|
LIST_FOR_EACH_ENTRY( var, type_get_function_args(func->type), const var_t, entry )
|
2008-09-15 16:46:01 +02:00
|
|
|
write_var_init(file, indent, var->type, var->name, local_var_prefix);
|
2007-06-15 03:30:26 +02:00
|
|
|
|
|
|
|
fprintf(file, "\n");
|
|
|
|
}
|
|
|
|
|
2006-08-17 03:01:56 +02:00
|
|
|
static void write_formatdesc(FILE *f, int indent, const char *str)
|
|
|
|
{
|
|
|
|
print_file(f, indent, "typedef struct _MIDL_%s_FORMAT_STRING\n", str);
|
|
|
|
print_file(f, indent, "{\n");
|
|
|
|
print_file(f, indent + 1, "short Pad;\n");
|
|
|
|
print_file(f, indent + 1, "unsigned char Format[%s_FORMAT_STRING_SIZE];\n", str);
|
|
|
|
print_file(f, indent, "} MIDL_%s_FORMAT_STRING;\n", str);
|
|
|
|
print_file(f, indent, "\n");
|
|
|
|
}
|
|
|
|
|
2008-04-24 20:06:28 +02:00
|
|
|
void write_formatstringsdecl(FILE *f, int indent, const statement_list_t *stmts, type_pred_t pred)
|
2006-08-17 03:01:56 +02:00
|
|
|
{
|
2008-12-26 17:22:25 +01:00
|
|
|
clear_all_offsets();
|
|
|
|
|
2006-08-17 03:01:56 +02:00
|
|
|
print_file(f, indent, "#define TYPE_FORMAT_STRING_SIZE %d\n",
|
2008-04-24 20:06:28 +02:00
|
|
|
get_size_typeformatstring(stmts, pred));
|
2006-08-17 03:01:56 +02:00
|
|
|
|
|
|
|
print_file(f, indent, "#define PROC_FORMAT_STRING_SIZE %d\n",
|
2008-04-24 20:06:28 +02:00
|
|
|
get_size_procformatstring(stmts, pred));
|
2006-08-17 03:01:56 +02:00
|
|
|
|
|
|
|
fprintf(f, "\n");
|
|
|
|
write_formatdesc(f, indent, "TYPE");
|
|
|
|
write_formatdesc(f, indent, "PROC");
|
|
|
|
fprintf(f, "\n");
|
|
|
|
print_file(f, indent, "static const MIDL_TYPE_FORMAT_STRING __MIDL_TypeFormatString;\n");
|
|
|
|
print_file(f, indent, "static const MIDL_PROC_FORMAT_STRING __MIDL_ProcFormatString;\n");
|
|
|
|
print_file(f, indent, "\n");
|
|
|
|
}
|
|
|
|
|
2007-06-14 01:13:04 +02:00
|
|
|
int decl_indirect(const type_t *t)
|
|
|
|
{
|
2009-02-23 14:48:34 +01:00
|
|
|
if (is_user_type(t))
|
|
|
|
return TRUE;
|
|
|
|
return (type_get_type(t) != TYPE_BASIC &&
|
|
|
|
type_get_type(t) != TYPE_ENUM &&
|
|
|
|
type_get_type(t) != TYPE_POINTER &&
|
|
|
|
type_get_type(t) != TYPE_ARRAY);
|
2007-06-14 01:13:04 +02:00
|
|
|
}
|
|
|
|
|
2011-09-19 11:54:42 +02:00
|
|
|
static unsigned char get_parameter_fc( const var_t *var, int is_return, unsigned short *flags,
|
|
|
|
unsigned int *stack_size, unsigned int *typestring_offset )
|
2011-06-03 14:54:14 +02:00
|
|
|
{
|
|
|
|
unsigned int alignment, server_size = 0, buffer_size = 0;
|
|
|
|
unsigned char fc = 0;
|
|
|
|
int is_byval;
|
2011-09-19 11:54:42 +02:00
|
|
|
int is_in = is_attr(var->attrs, ATTR_IN);
|
|
|
|
int is_out = is_attr(var->attrs, ATTR_OUT);
|
2011-06-03 14:54:14 +02:00
|
|
|
|
|
|
|
if (is_return) is_out = TRUE;
|
|
|
|
else if (!is_in && !is_out) is_in = TRUE;
|
|
|
|
|
|
|
|
*flags = 0;
|
2011-09-19 11:54:42 +02:00
|
|
|
*stack_size = get_stack_size( var, &is_byval );
|
2011-09-19 12:23:01 +02:00
|
|
|
*typestring_offset = var->typestring_offset;
|
2011-06-03 14:54:14 +02:00
|
|
|
|
|
|
|
if (is_in) *flags |= IsIn;
|
|
|
|
if (is_out) *flags |= IsOut;
|
|
|
|
if (is_return) *flags |= IsReturn;
|
|
|
|
|
2011-09-19 11:54:42 +02:00
|
|
|
if (!is_string_type( var->attrs, var->type ))
|
|
|
|
buffer_size = get_required_buffer_size_type( var->type, NULL, var->attrs, TRUE, &alignment );
|
2011-06-03 14:54:14 +02:00
|
|
|
|
2011-09-19 11:54:42 +02:00
|
|
|
switch (typegen_detect_type( var->type, var->attrs, TDT_ALL_TYPES ))
|
2011-06-03 14:54:14 +02:00
|
|
|
{
|
|
|
|
case TGT_BASIC:
|
|
|
|
*flags |= IsBasetype;
|
2011-09-19 11:54:42 +02:00
|
|
|
fc = get_basic_fc_signed( var->type );
|
2018-06-13 04:19:11 +02:00
|
|
|
if (fc == FC_BIND_PRIMITIVE)
|
2011-06-03 14:54:14 +02:00
|
|
|
{
|
|
|
|
buffer_size = 4; /* actually 0 but avoids setting MustSize */
|
2018-06-13 04:19:11 +02:00
|
|
|
fc = FC_LONG;
|
2011-06-03 14:54:14 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TGT_ENUM:
|
|
|
|
*flags |= IsBasetype;
|
2011-09-19 11:54:42 +02:00
|
|
|
fc = get_enum_fc( var->type );
|
2011-06-03 14:54:14 +02:00
|
|
|
break;
|
|
|
|
case TGT_RANGE:
|
|
|
|
*flags |= IsByValue;
|
|
|
|
break;
|
|
|
|
case TGT_STRUCT:
|
|
|
|
case TGT_UNION:
|
|
|
|
case TGT_USER_TYPE:
|
|
|
|
*flags |= MustFree | (is_byval ? IsByValue : IsSimpleRef);
|
|
|
|
break;
|
|
|
|
case TGT_IFACE_POINTER:
|
|
|
|
*flags |= MustFree;
|
|
|
|
break;
|
|
|
|
case TGT_ARRAY:
|
|
|
|
*flags |= MustFree;
|
2011-09-19 11:54:42 +02:00
|
|
|
if (type_array_is_decl_as_ptr(var->type) && var->type->details.array.ptr_tfsoff &&
|
2018-06-13 04:19:11 +02:00
|
|
|
get_pointer_fc( var->type, var->attrs, !is_return ) == FC_RP)
|
2011-09-19 12:23:01 +02:00
|
|
|
{
|
|
|
|
*typestring_offset = var->type->typestring_offset;
|
2011-06-03 14:54:14 +02:00
|
|
|
*flags |= IsSimpleRef;
|
2011-09-19 12:23:01 +02:00
|
|
|
}
|
2011-06-03 14:54:14 +02:00
|
|
|
break;
|
|
|
|
case TGT_STRING:
|
|
|
|
*flags |= MustFree;
|
2018-06-13 04:19:11 +02:00
|
|
|
if (is_declptr( var->type ) && get_pointer_fc( var->type, var->attrs, !is_return ) == FC_RP)
|
2011-06-03 14:54:14 +02:00
|
|
|
{
|
|
|
|
/* skip over pointer description straight to string description */
|
2011-09-19 11:54:42 +02:00
|
|
|
if (is_conformant_array( var->type )) *typestring_offset += 4;
|
2011-06-09 13:18:58 +02:00
|
|
|
else *typestring_offset += 2;
|
2011-06-03 14:54:14 +02:00
|
|
|
*flags |= IsSimpleRef;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TGT_CTXT_HANDLE_POINTER:
|
|
|
|
*flags |= IsSimpleRef;
|
2011-06-13 20:09:47 +02:00
|
|
|
*typestring_offset += 4;
|
2011-06-03 14:54:14 +02:00
|
|
|
/* fall through */
|
|
|
|
case TGT_CTXT_HANDLE:
|
|
|
|
buffer_size = 20;
|
|
|
|
break;
|
|
|
|
case TGT_POINTER:
|
2018-06-13 04:19:11 +02:00
|
|
|
if (get_pointer_fc( var->type, var->attrs, !is_return ) == FC_RP)
|
2011-06-03 14:54:14 +02:00
|
|
|
{
|
2011-09-19 11:54:42 +02:00
|
|
|
const type_t *ref = type_pointer_get_ref( var->type );
|
2011-06-03 14:54:14 +02:00
|
|
|
|
2011-09-19 11:54:42 +02:00
|
|
|
if (!is_string_type( var->attrs, ref ))
|
2011-06-03 14:54:14 +02:00
|
|
|
buffer_size = get_required_buffer_size_type( ref, NULL, NULL, TRUE, &alignment );
|
|
|
|
|
|
|
|
switch (typegen_detect_type( ref, NULL, TDT_ALL_TYPES ))
|
|
|
|
{
|
|
|
|
case TGT_BASIC:
|
|
|
|
*flags |= IsSimpleRef | IsBasetype;
|
|
|
|
fc = get_basic_fc( ref );
|
|
|
|
if (!is_in && is_out) server_size = pointer_size;
|
|
|
|
break;
|
|
|
|
case TGT_ENUM:
|
2018-06-13 04:19:11 +02:00
|
|
|
if ((fc = get_enum_fc( ref )) == FC_ENUM32)
|
2011-06-03 14:54:14 +02:00
|
|
|
{
|
|
|
|
*flags |= IsSimpleRef | IsBasetype;
|
|
|
|
if (!is_in && is_out) server_size = pointer_size;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
server_size = pointer_size;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TGT_UNION:
|
|
|
|
case TGT_USER_TYPE:
|
|
|
|
case TGT_RANGE:
|
2019-06-14 00:49:34 +02:00
|
|
|
*flags |= MustFree | IsSimpleRef;
|
|
|
|
*typestring_offset = ref->typestring_offset;
|
2019-05-29 07:24:05 +02:00
|
|
|
if (!is_in && is_out) server_size = type_memsize( ref );
|
|
|
|
break;
|
2018-10-10 23:19:23 +02:00
|
|
|
case TGT_ARRAY:
|
2019-05-29 07:24:05 +02:00
|
|
|
*flags |= MustFree;
|
|
|
|
if (!type_array_is_decl_as_ptr(ref))
|
|
|
|
{
|
|
|
|
*flags |= IsSimpleRef;
|
|
|
|
*typestring_offset = ref->typestring_offset;
|
|
|
|
}
|
2011-06-03 14:54:14 +02:00
|
|
|
if (!is_in && is_out) server_size = type_memsize( ref );
|
|
|
|
break;
|
|
|
|
case TGT_STRING:
|
|
|
|
case TGT_POINTER:
|
|
|
|
case TGT_CTXT_HANDLE:
|
|
|
|
case TGT_CTXT_HANDLE_POINTER:
|
|
|
|
*flags |= MustFree;
|
|
|
|
server_size = pointer_size;
|
|
|
|
break;
|
|
|
|
case TGT_IFACE_POINTER:
|
|
|
|
*flags |= MustFree;
|
|
|
|
if (is_in && is_out) server_size = pointer_size;
|
|
|
|
break;
|
|
|
|
case TGT_STRUCT:
|
|
|
|
*flags |= IsSimpleRef | MustFree;
|
|
|
|
*typestring_offset = ref->typestring_offset;
|
|
|
|
switch (get_struct_fc(ref))
|
|
|
|
{
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_STRUCT:
|
|
|
|
case FC_PSTRUCT:
|
|
|
|
case FC_BOGUS_STRUCT:
|
2011-06-03 14:54:14 +02:00
|
|
|
if (!is_in && is_out) server_size = type_memsize( ref );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TGT_INVALID:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else /* not ref pointer */
|
|
|
|
{
|
|
|
|
*flags |= MustFree;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TGT_INVALID:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!buffer_size) *flags |= MustSize;
|
|
|
|
|
|
|
|
if (server_size)
|
|
|
|
{
|
|
|
|
server_size = (server_size + 7) / 8;
|
|
|
|
if (server_size < 8) *flags |= server_size << 13;
|
|
|
|
}
|
|
|
|
return fc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned char get_func_oi2_flags( const var_t *func )
|
|
|
|
{
|
|
|
|
const var_t *var;
|
|
|
|
var_list_t *args = type_get_function_args( func->type );
|
2011-09-19 11:54:42 +02:00
|
|
|
var_t *retval = type_function_get_retval( func->type );
|
2011-06-03 14:54:14 +02:00
|
|
|
unsigned char oi2_flags = 0x40; /* HasExtensions */
|
|
|
|
unsigned short flags;
|
|
|
|
unsigned int stack_size, typestring_offset;
|
|
|
|
|
|
|
|
if (args) LIST_FOR_EACH_ENTRY( var, args, const var_t, entry )
|
|
|
|
{
|
2011-09-19 11:54:42 +02:00
|
|
|
get_parameter_fc( var, 0, &flags, &stack_size, &typestring_offset );
|
2011-06-03 14:54:14 +02:00
|
|
|
if (flags & MustSize)
|
|
|
|
{
|
|
|
|
if (flags & IsIn) oi2_flags |= 0x02; /* ClientMustSize */
|
|
|
|
if (flags & IsOut) oi2_flags |= 0x01; /* ServerMustSize */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-19 11:54:42 +02:00
|
|
|
if (!is_void( retval->type ))
|
2011-06-03 14:54:14 +02:00
|
|
|
{
|
|
|
|
oi2_flags |= 0x04; /* HasRet */
|
2011-09-19 11:54:42 +02:00
|
|
|
get_parameter_fc( retval, 1, &flags, &stack_size, &typestring_offset );
|
2011-06-03 14:54:14 +02:00
|
|
|
if (flags & MustSize) oi2_flags |= 0x01; /* ServerMustSize */
|
|
|
|
}
|
|
|
|
return oi2_flags;
|
|
|
|
}
|
|
|
|
|
2011-09-19 11:54:42 +02:00
|
|
|
static unsigned int write_new_procformatstring_type(FILE *file, int indent, const var_t *var,
|
2011-06-03 14:54:14 +02:00
|
|
|
int is_return, unsigned int *stack_offset)
|
|
|
|
{
|
2015-07-10 17:49:44 +02:00
|
|
|
char buffer[128];
|
2011-06-03 14:54:14 +02:00
|
|
|
unsigned int stack_size, typestring_offset;
|
|
|
|
unsigned short flags;
|
2011-09-19 11:54:42 +02:00
|
|
|
unsigned char fc = get_parameter_fc( var, is_return, &flags, &stack_size, &typestring_offset );
|
2011-06-03 14:54:14 +02:00
|
|
|
|
|
|
|
strcpy( buffer, "/* flags:" );
|
|
|
|
if (flags & MustSize) strcat( buffer, " must size," );
|
|
|
|
if (flags & MustFree) strcat( buffer, " must free," );
|
|
|
|
if (flags & IsPipe) strcat( buffer, " pipe," );
|
|
|
|
if (flags & IsIn) strcat( buffer, " in," );
|
|
|
|
if (flags & IsOut) strcat( buffer, " out," );
|
|
|
|
if (flags & IsReturn) strcat( buffer, " return," );
|
|
|
|
if (flags & IsBasetype) strcat( buffer, " base type," );
|
|
|
|
if (flags & IsByValue) strcat( buffer, " by value," );
|
|
|
|
if (flags & IsSimpleRef) strcat( buffer, " simple ref," );
|
|
|
|
if (flags >> 13) sprintf( buffer + strlen(buffer), " srv size=%u,", (flags >> 13) * 8 );
|
|
|
|
strcpy( buffer + strlen( buffer ) - 1, " */" );
|
|
|
|
print_file( file, indent, "NdrFcShort(0x%hx),\t%s\n", flags, buffer );
|
2013-06-17 11:13:57 +02:00
|
|
|
print_file( file, indent, "NdrFcShort(0x%x), /* stack offset = %u */\n",
|
2011-06-03 14:54:14 +02:00
|
|
|
*stack_offset, *stack_offset );
|
|
|
|
if (flags & IsBasetype)
|
|
|
|
{
|
|
|
|
print_file( file, indent, "0x%02x, /* %s */\n", fc, string_of_type(fc) );
|
|
|
|
print_file( file, indent, "0x0,\n" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
print_file( file, indent, "NdrFcShort(0x%x), /* type offset = %u */\n",
|
|
|
|
typestring_offset, typestring_offset );
|
|
|
|
*stack_offset += max( stack_size, pointer_size );
|
|
|
|
return 6;
|
|
|
|
}
|
|
|
|
|
2011-09-19 11:54:42 +02:00
|
|
|
static unsigned int write_old_procformatstring_type(FILE *file, int indent, const var_t *var,
|
2011-06-03 14:54:14 +02:00
|
|
|
int is_return, int is_interpreted)
|
2005-12-08 12:53:58 +01:00
|
|
|
{
|
2009-02-06 14:30:38 +01:00
|
|
|
unsigned int size;
|
2006-01-24 11:05:51 +01:00
|
|
|
|
2011-09-19 11:54:42 +02:00
|
|
|
int is_in = is_attr(var->attrs, ATTR_IN);
|
|
|
|
int is_out = is_attr(var->attrs, ATTR_OUT);
|
2006-01-24 11:05:51 +01:00
|
|
|
|
|
|
|
if (!is_in && !is_out) is_in = TRUE;
|
2005-12-26 13:22:32 +01:00
|
|
|
|
2011-09-19 11:54:42 +02:00
|
|
|
if (type_get_type(var->type) == TYPE_BASIC ||
|
|
|
|
type_get_type(var->type) == TYPE_ENUM)
|
2005-12-08 12:53:58 +01:00
|
|
|
{
|
2009-02-23 14:48:34 +01:00
|
|
|
unsigned char fc;
|
|
|
|
|
2005-12-26 13:05:55 +01:00
|
|
|
if (is_return)
|
|
|
|
print_file(file, indent, "0x53, /* FC_RETURN_PARAM_BASETYPE */\n");
|
|
|
|
else
|
|
|
|
print_file(file, indent, "0x4e, /* FC_IN_PARAM_BASETYPE */\n");
|
|
|
|
|
2011-09-19 11:54:42 +02:00
|
|
|
if (type_get_type(var->type) == TYPE_ENUM)
|
2005-12-26 13:05:55 +01:00
|
|
|
{
|
2011-09-19 11:54:42 +02:00
|
|
|
fc = get_enum_fc(var->type);
|
2007-05-10 05:46:31 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-19 11:54:42 +02:00
|
|
|
fc = get_basic_fc_signed(var->type);
|
2009-02-23 14:48:34 +01:00
|
|
|
|
2018-06-13 04:19:11 +02:00
|
|
|
if (fc == FC_BIND_PRIMITIVE)
|
|
|
|
fc = FC_IGNORE;
|
2005-12-26 13:05:55 +01:00
|
|
|
}
|
2009-02-23 14:48:34 +01:00
|
|
|
|
|
|
|
print_file(file, indent, "0x%02x, /* %s */\n",
|
|
|
|
fc, string_of_type(fc));
|
|
|
|
size = 2; /* includes param type prefix */
|
2005-12-26 13:05:55 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-19 12:23:01 +02:00
|
|
|
unsigned short offset = var->typestring_offset;
|
2011-06-01 21:27:56 +02:00
|
|
|
|
2011-09-19 12:23:01 +02:00
|
|
|
if (!is_interpreted && is_array(var->type) &&
|
2011-09-19 11:54:42 +02:00
|
|
|
type_array_is_decl_as_ptr(var->type) &&
|
|
|
|
var->type->details.array.ptr_tfsoff)
|
2011-09-19 12:23:01 +02:00
|
|
|
offset = var->type->typestring_offset;
|
2011-06-01 21:27:56 +02:00
|
|
|
|
2005-12-26 13:05:55 +01:00
|
|
|
if (is_return)
|
|
|
|
print_file(file, indent, "0x52, /* FC_RETURN_PARAM */\n");
|
2005-12-26 13:22:32 +01:00
|
|
|
else if (is_in && is_out)
|
2005-12-26 13:07:55 +01:00
|
|
|
print_file(file, indent, "0x50, /* FC_IN_OUT_PARAM */\n");
|
2005-12-26 13:22:32 +01:00
|
|
|
else if (is_out)
|
2005-12-26 13:07:55 +01:00
|
|
|
print_file(file, indent, "0x51, /* FC_OUT_PARAM */\n");
|
2005-12-26 13:06:29 +01:00
|
|
|
else
|
|
|
|
print_file(file, indent, "0x4d, /* FC_IN_PARAM */\n");
|
2005-12-26 13:07:55 +01:00
|
|
|
|
2011-09-19 11:54:42 +02:00
|
|
|
size = get_stack_size( var, NULL );
|
2011-05-25 20:32:12 +02:00
|
|
|
print_file(file, indent, "0x%02x,\n", size / pointer_size );
|
2011-06-01 21:27:56 +02:00
|
|
|
print_file(file, indent, "NdrFcShort(0x%x), /* type offset = %u */\n", offset, offset);
|
2005-12-26 13:05:55 +01:00
|
|
|
size = 4; /* includes param type prefix */
|
2005-12-08 12:53:58 +01:00
|
|
|
}
|
2005-12-26 13:05:29 +01:00
|
|
|
return size;
|
2005-12-08 12:53:58 +01:00
|
|
|
}
|
|
|
|
|
2011-05-28 13:38:25 +02:00
|
|
|
int is_interpreted_func( const type_t *iface, const var_t *func )
|
|
|
|
{
|
|
|
|
const char *str;
|
2011-06-01 20:46:50 +02:00
|
|
|
const var_t *var;
|
|
|
|
const var_list_t *args = type_get_function_args( func->type );
|
2011-05-28 13:38:25 +02:00
|
|
|
const type_t *ret_type = type_function_get_rettype( func->type );
|
|
|
|
|
2011-06-01 20:46:50 +02:00
|
|
|
if (type_get_type( ret_type ) == TYPE_BASIC)
|
|
|
|
{
|
|
|
|
switch (type_basic_get_type( ret_type ))
|
|
|
|
{
|
|
|
|
case TYPE_BASIC_INT64:
|
|
|
|
case TYPE_BASIC_HYPER:
|
|
|
|
/* return value must fit in a long_ptr */
|
|
|
|
if (pointer_size < 8) return 0;
|
|
|
|
break;
|
|
|
|
case TYPE_BASIC_FLOAT:
|
|
|
|
case TYPE_BASIC_DOUBLE:
|
|
|
|
/* floating point values can't be returned */
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-06-08 12:14:47 +02:00
|
|
|
if (get_stub_mode() != MODE_Oif && args)
|
2011-06-08 13:57:41 +02:00
|
|
|
{
|
2011-06-03 14:54:14 +02:00
|
|
|
LIST_FOR_EACH_ENTRY( var, args, const var_t, entry )
|
2011-06-08 13:57:41 +02:00
|
|
|
switch (type_get_type( var->type ))
|
|
|
|
{
|
|
|
|
case TYPE_BASIC:
|
|
|
|
switch (type_basic_get_type( var->type ))
|
|
|
|
{
|
|
|
|
/* floating point arguments are not supported in Oi mode */
|
|
|
|
case TYPE_BASIC_FLOAT: return 0;
|
|
|
|
case TYPE_BASIC_DOUBLE: return 0;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
/* unions passed by value are not supported in Oi mode */
|
|
|
|
case TYPE_UNION: return 0;
|
|
|
|
case TYPE_ENCAPSULATED_UNION: return 0;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
2011-06-01 20:46:50 +02:00
|
|
|
|
2011-05-28 13:38:25 +02:00
|
|
|
if ((str = get_attrp( func->attrs, ATTR_OPTIMIZE ))) return !strcmp( str, "i" );
|
|
|
|
if ((str = get_attrp( iface->attrs, ATTR_OPTIMIZE ))) return !strcmp( str, "i" );
|
2011-06-08 12:14:47 +02:00
|
|
|
return (get_stub_mode() != MODE_Os);
|
2011-05-28 13:38:25 +02:00
|
|
|
}
|
|
|
|
|
2011-06-01 21:06:14 +02:00
|
|
|
static void write_proc_func_header( FILE *file, int indent, const type_t *iface,
|
|
|
|
const var_t *func, unsigned int *offset,
|
|
|
|
unsigned short num_proc )
|
2010-10-16 13:51:50 +02:00
|
|
|
{
|
2011-06-01 21:06:14 +02:00
|
|
|
var_t *var;
|
|
|
|
var_list_t *args = type_get_function_args( func->type );
|
|
|
|
unsigned char explicit_fc, implicit_fc;
|
|
|
|
unsigned char handle_flags;
|
|
|
|
const var_t *handle_var = get_func_handle_var( iface, func, &explicit_fc, &implicit_fc );
|
2018-06-13 04:19:11 +02:00
|
|
|
unsigned char oi_flags = Oi_HAS_RPCFLAGS | Oi_USE_NEW_INIT_ROUTINES;
|
2011-06-01 21:06:14 +02:00
|
|
|
unsigned int rpc_flags = get_rpc_flags( func->attrs );
|
2011-06-03 14:54:14 +02:00
|
|
|
unsigned int nb_args = 0;
|
2011-06-01 21:06:14 +02:00
|
|
|
unsigned int stack_size = 0;
|
|
|
|
unsigned short param_num = 0;
|
|
|
|
unsigned short handle_stack_offset = 0;
|
|
|
|
unsigned short handle_param_num = 0;
|
|
|
|
|
2018-06-13 04:19:11 +02:00
|
|
|
if (is_full_pointer_function( func )) oi_flags |= Oi_FULL_PTR_USED;
|
2011-06-01 21:06:14 +02:00
|
|
|
if (is_object( iface ))
|
|
|
|
{
|
2018-06-13 04:19:11 +02:00
|
|
|
oi_flags |= Oi_OBJECT_PROC;
|
|
|
|
if (get_stub_mode() == MODE_Oif) oi_flags |= Oi_OBJ_USE_V2_INTERPRETER;
|
2011-06-01 21:06:14 +02:00
|
|
|
stack_size += pointer_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args) LIST_FOR_EACH_ENTRY( var, args, var_t, entry )
|
|
|
|
{
|
|
|
|
if (var == handle_var)
|
|
|
|
{
|
|
|
|
handle_stack_offset = stack_size;
|
|
|
|
handle_param_num = param_num;
|
|
|
|
}
|
2011-09-19 11:54:42 +02:00
|
|
|
stack_size += get_stack_size( var, NULL );
|
2011-06-01 21:06:14 +02:00
|
|
|
param_num++;
|
2011-06-03 14:54:14 +02:00
|
|
|
nb_args++;
|
|
|
|
}
|
|
|
|
if (!is_void( type_function_get_rettype( func->type )))
|
|
|
|
{
|
|
|
|
stack_size += pointer_size;
|
|
|
|
nb_args++;
|
2011-06-01 21:06:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
print_file( file, 0, "/* %u (procedure %s::%s) */\n", *offset, iface->name, func->name );
|
|
|
|
print_file( file, indent, "0x%02x,\t/* %s */\n", implicit_fc,
|
|
|
|
implicit_fc ? string_of_type(implicit_fc) : "explicit handle" );
|
|
|
|
print_file( file, indent, "0x%02x,\n", oi_flags );
|
|
|
|
print_file( file, indent, "NdrFcLong(0x%x),\n", rpc_flags );
|
|
|
|
print_file( file, indent, "NdrFcShort(0x%hx),\t/* method %hu */\n", num_proc, num_proc );
|
2013-06-17 11:13:57 +02:00
|
|
|
print_file( file, indent, "NdrFcShort(0x%x),\t/* stack size = %u */\n", stack_size, stack_size );
|
2011-06-01 21:06:14 +02:00
|
|
|
*offset += 10;
|
|
|
|
|
2011-06-03 14:54:14 +02:00
|
|
|
if (!implicit_fc)
|
|
|
|
{
|
|
|
|
switch (explicit_fc)
|
|
|
|
{
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_BIND_PRIMITIVE:
|
2011-06-03 14:54:14 +02:00
|
|
|
handle_flags = 0;
|
|
|
|
print_file( file, indent, "0x%02x,\t/* %s */\n", explicit_fc, string_of_type(explicit_fc) );
|
|
|
|
print_file( file, indent, "0x%02x,\n", handle_flags );
|
|
|
|
print_file( file, indent, "NdrFcShort(0x%hx),\t/* stack offset = %hu */\n",
|
|
|
|
handle_stack_offset, handle_stack_offset );
|
|
|
|
*offset += 4;
|
|
|
|
break;
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_BIND_GENERIC:
|
2011-06-03 14:54:14 +02:00
|
|
|
handle_flags = type_memsize( handle_var->type );
|
|
|
|
print_file( file, indent, "0x%02x,\t/* %s */\n", explicit_fc, string_of_type(explicit_fc) );
|
|
|
|
print_file( file, indent, "0x%02x,\n", handle_flags );
|
|
|
|
print_file( file, indent, "NdrFcShort(0x%hx),\t/* stack offset = %hu */\n",
|
|
|
|
handle_stack_offset, handle_stack_offset );
|
|
|
|
print_file( file, indent, "0x%02x,\n", get_generic_handle_offset( handle_var->type ) );
|
2018-06-13 04:19:11 +02:00
|
|
|
print_file( file, indent, "0x%x,\t/* FC_PAD */\n", FC_PAD);
|
2011-06-03 14:54:14 +02:00
|
|
|
*offset += 6;
|
|
|
|
break;
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_BIND_CONTEXT:
|
2019-01-24 13:38:40 +01:00
|
|
|
handle_flags = get_contexthandle_flags( iface, handle_var->attrs, handle_var->type, 0 );
|
2011-06-03 14:54:14 +02:00
|
|
|
print_file( file, indent, "0x%02x,\t/* %s */\n", explicit_fc, string_of_type(explicit_fc) );
|
|
|
|
print_file( file, indent, "0x%02x,\n", handle_flags );
|
|
|
|
print_file( file, indent, "NdrFcShort(0x%hx),\t/* stack offset = %hu */\n",
|
|
|
|
handle_stack_offset, handle_stack_offset );
|
|
|
|
print_file( file, indent, "0x%02x,\n", get_context_handle_offset( handle_var->type ) );
|
|
|
|
print_file( file, indent, "0x%02x,\t/* param %hu */\n", handle_param_num, handle_param_num );
|
|
|
|
*offset += 6;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-06-01 21:06:14 +02:00
|
|
|
|
2011-06-08 12:14:47 +02:00
|
|
|
if (get_stub_mode() == MODE_Oif)
|
2011-06-01 21:06:14 +02:00
|
|
|
{
|
2011-06-03 14:54:14 +02:00
|
|
|
unsigned char oi2_flags = get_func_oi2_flags( func );
|
|
|
|
unsigned char ext_flags = 0;
|
|
|
|
unsigned int size;
|
|
|
|
|
|
|
|
if (is_attr( func->attrs, ATTR_NOTIFY )) ext_flags |= 0x08; /* HasNotify */
|
|
|
|
if (is_attr( func->attrs, ATTR_NOTIFYFLAG )) ext_flags |= 0x10; /* HasNotify2 */
|
2018-11-07 16:14:56 +01:00
|
|
|
if (iface == iface->details.iface->async_iface) oi2_flags |= 0x20;
|
2011-06-03 14:54:14 +02:00
|
|
|
|
|
|
|
size = get_function_buffer_size( func, PASS_IN );
|
2013-06-17 11:13:57 +02:00
|
|
|
print_file( file, indent, "NdrFcShort(0x%x),\t/* client buffer = %u */\n", size, size );
|
2011-06-03 14:54:14 +02:00
|
|
|
size = get_function_buffer_size( func, PASS_OUT );
|
2013-06-17 11:13:57 +02:00
|
|
|
print_file( file, indent, "NdrFcShort(0x%x),\t/* server buffer = %u */\n", size, size );
|
2011-06-03 14:54:14 +02:00
|
|
|
print_file( file, indent, "0x%02x,\n", oi2_flags );
|
|
|
|
print_file( file, indent, "0x%02x,\t/* %u params */\n", nb_args, nb_args );
|
|
|
|
print_file( file, indent, "0x%02x,\n", pointer_size == 8 ? 10 : 8 );
|
|
|
|
print_file( file, indent, "0x%02x,\n", ext_flags );
|
|
|
|
print_file( file, indent, "NdrFcShort(0x0),\n" ); /* server corr hint */
|
|
|
|
print_file( file, indent, "NdrFcShort(0x0),\n" ); /* client corr hint */
|
|
|
|
print_file( file, indent, "NdrFcShort(0x0),\n" ); /* FIXME: notify index */
|
|
|
|
*offset += 14;
|
|
|
|
if (pointer_size == 8)
|
|
|
|
{
|
2011-06-08 11:51:14 +02:00
|
|
|
unsigned short pos = 0, fpu_mask = 0;
|
|
|
|
|
|
|
|
if (is_object( iface )) pos += 2;
|
|
|
|
if (args) LIST_FOR_EACH_ENTRY( var, args, var_t, entry )
|
|
|
|
{
|
|
|
|
if (type_get_type( var->type ) == TYPE_BASIC)
|
|
|
|
{
|
|
|
|
switch (type_basic_get_type( var->type ))
|
|
|
|
{
|
|
|
|
case TYPE_BASIC_FLOAT: fpu_mask |= 1 << pos; break;
|
|
|
|
case TYPE_BASIC_DOUBLE: fpu_mask |= 2 << pos; break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pos += 2;
|
|
|
|
if (pos >= 16) break;
|
|
|
|
}
|
|
|
|
print_file( file, indent, "NdrFcShort(0x%x),\n", fpu_mask ); /* floating point mask */
|
2011-06-03 14:54:14 +02:00
|
|
|
*offset += 2;
|
|
|
|
}
|
2011-06-01 21:06:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void write_procformatstring_func( FILE *file, int indent, const type_t *iface,
|
|
|
|
const var_t *func, unsigned int *offset,
|
|
|
|
unsigned short num_proc )
|
|
|
|
{
|
2011-06-03 14:54:14 +02:00
|
|
|
unsigned int stack_offset = is_object( iface ) ? pointer_size : 0;
|
2011-06-01 21:27:56 +02:00
|
|
|
int is_interpreted = is_interpreted_func( iface, func );
|
2011-06-08 12:14:47 +02:00
|
|
|
int is_new_style = is_interpreted && (get_stub_mode() == MODE_Oif);
|
2011-09-19 11:54:42 +02:00
|
|
|
var_t *retval = type_function_get_retval( func->type );
|
2011-06-01 21:27:56 +02:00
|
|
|
|
|
|
|
if (is_interpreted) write_proc_func_header( file, indent, iface, func, offset, num_proc );
|
2011-06-01 21:06:14 +02:00
|
|
|
|
2010-10-16 13:51:50 +02:00
|
|
|
/* emit argument data */
|
|
|
|
if (type_get_function_args(func->type))
|
|
|
|
{
|
|
|
|
const var_t *var;
|
|
|
|
LIST_FOR_EACH_ENTRY( var, type_get_function_args(func->type), const var_t, entry )
|
|
|
|
{
|
|
|
|
print_file( file, 0, "/* %u (parameter %s) */\n", *offset, var->name );
|
2011-06-03 14:54:14 +02:00
|
|
|
if (is_new_style)
|
2011-09-19 11:54:42 +02:00
|
|
|
*offset += write_new_procformatstring_type(file, indent, var, FALSE, &stack_offset);
|
2011-06-03 14:54:14 +02:00
|
|
|
else
|
2011-09-19 11:54:42 +02:00
|
|
|
*offset += write_old_procformatstring_type(file, indent, var, FALSE, is_interpreted);
|
2010-10-16 13:51:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* emit return value data */
|
2011-09-19 11:54:42 +02:00
|
|
|
if (is_void(retval->type))
|
2010-10-16 13:51:50 +02:00
|
|
|
{
|
2011-06-03 14:54:14 +02:00
|
|
|
if (!is_new_style)
|
|
|
|
{
|
|
|
|
print_file(file, 0, "/* %u (void) */\n", *offset);
|
2014-03-19 11:26:24 +01:00
|
|
|
print_file(file, indent, "0x5b,\t/* FC_END */\n");
|
|
|
|
print_file(file, indent, "0x5c,\t/* FC_PAD */\n");
|
2011-06-03 14:54:14 +02:00
|
|
|
*offset += 2;
|
|
|
|
}
|
2010-10-16 13:51:50 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
print_file( file, 0, "/* %u (return value) */\n", *offset );
|
2011-06-03 14:54:14 +02:00
|
|
|
if (is_new_style)
|
2011-09-19 11:54:42 +02:00
|
|
|
*offset += write_new_procformatstring_type(file, indent, retval, TRUE, &stack_offset);
|
2011-06-03 14:54:14 +02:00
|
|
|
else
|
2011-09-19 11:54:42 +02:00
|
|
|
*offset += write_old_procformatstring_type(file, indent, retval, TRUE, is_interpreted);
|
2010-10-16 13:51:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-07 16:14:20 +01:00
|
|
|
static void for_each_iface(const statement_list_t *stmts,
|
|
|
|
void (*proc)(type_t *iface, FILE *file, int indent, unsigned int *offset),
|
|
|
|
type_pred_t pred, FILE *file, int indent, unsigned int *offset)
|
2005-12-08 12:52:13 +01:00
|
|
|
{
|
2008-04-24 20:06:28 +02:00
|
|
|
const statement_t *stmt;
|
2018-11-07 16:14:20 +01:00
|
|
|
type_t *iface;
|
|
|
|
|
2008-04-24 20:06:28 +02:00
|
|
|
if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, const statement_t, entry )
|
2005-12-08 12:52:13 +01:00
|
|
|
{
|
2018-11-07 16:14:20 +01:00
|
|
|
if (stmt->type != STMT_TYPE || type_get_type(stmt->u.type) != TYPE_INTERFACE)
|
|
|
|
continue;
|
|
|
|
iface = stmt->u.type;
|
|
|
|
if (!pred(iface)) continue;
|
|
|
|
proc(iface, file, indent, offset);
|
2018-11-07 16:14:56 +01:00
|
|
|
if (iface->details.iface->async_iface)
|
|
|
|
proc(iface->details.iface->async_iface, file, indent, offset);
|
2018-11-07 16:14:20 +01:00
|
|
|
}
|
|
|
|
}
|
2011-06-01 21:06:14 +02:00
|
|
|
|
2018-11-07 16:14:20 +01:00
|
|
|
static void write_iface_procformatstring(type_t *iface, FILE *file, int indent, unsigned int *offset)
|
|
|
|
{
|
|
|
|
const statement_t *stmt;
|
|
|
|
const type_t *parent = type_iface_get_inherit( iface );
|
|
|
|
int count = parent ? count_methods( parent ) : 0;
|
|
|
|
|
|
|
|
STATEMENTS_FOR_EACH_FUNC(stmt, type_iface_get_stmts(iface))
|
|
|
|
{
|
|
|
|
var_t *func = stmt->u.var;
|
|
|
|
if (is_local(func->attrs)) continue;
|
|
|
|
write_procformatstring_func( file, indent, iface, func, offset, count++ );
|
2005-12-08 12:52:13 +01:00
|
|
|
}
|
2008-04-24 20:06:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void write_procformatstring(FILE *file, const statement_list_t *stmts, type_pred_t pred)
|
|
|
|
{
|
|
|
|
int indent = 0;
|
2010-10-16 12:37:39 +02:00
|
|
|
unsigned int offset = 0;
|
2008-04-24 20:06:28 +02:00
|
|
|
|
|
|
|
print_file(file, indent, "static const MIDL_PROC_FORMAT_STRING __MIDL_ProcFormatString =\n");
|
|
|
|
print_file(file, indent, "{\n");
|
|
|
|
indent++;
|
|
|
|
print_file(file, indent, "0,\n");
|
|
|
|
print_file(file, indent, "{\n");
|
|
|
|
indent++;
|
|
|
|
|
2018-11-07 16:14:20 +01:00
|
|
|
for_each_iface(stmts, write_iface_procformatstring, pred, file, indent, &offset);
|
2005-12-08 12:52:13 +01:00
|
|
|
|
|
|
|
print_file(file, indent, "0x0\n");
|
|
|
|
indent--;
|
|
|
|
print_file(file, indent, "}\n");
|
|
|
|
indent--;
|
|
|
|
print_file(file, indent, "};\n");
|
|
|
|
print_file(file, indent, "\n");
|
|
|
|
}
|
|
|
|
|
2010-10-22 20:46:00 +02:00
|
|
|
void write_procformatstring_offsets( FILE *file, const type_t *iface )
|
|
|
|
{
|
|
|
|
const statement_t *stmt;
|
|
|
|
int indent = 0;
|
|
|
|
|
|
|
|
print_file( file, indent, "static const unsigned short %s_FormatStringOffsetTable[] =\n",
|
|
|
|
iface->name );
|
|
|
|
print_file( file, indent, "{\n" );
|
|
|
|
indent++;
|
|
|
|
STATEMENTS_FOR_EACH_FUNC( stmt, type_iface_get_stmts(iface) )
|
|
|
|
{
|
|
|
|
var_t *func = stmt->u.var;
|
|
|
|
if (is_local( func->attrs )) continue;
|
|
|
|
print_file( file, indent, "%u, /* %s */\n", func->procstring_offset, func->name );
|
|
|
|
}
|
|
|
|
indent--;
|
|
|
|
print_file( file, indent, "};\n\n" );
|
|
|
|
}
|
|
|
|
|
2011-06-03 12:26:31 +02:00
|
|
|
static int write_base_type(FILE *file, const type_t *type, unsigned int *typestring_offset)
|
2007-02-06 15:55:29 +01:00
|
|
|
{
|
2009-02-23 14:48:34 +01:00
|
|
|
unsigned char fc;
|
|
|
|
|
|
|
|
if (type_get_type(type) == TYPE_BASIC)
|
2011-06-03 12:26:31 +02:00
|
|
|
fc = get_basic_fc_signed(type);
|
2009-02-23 14:48:34 +01:00
|
|
|
else if (type_get_type(type) == TYPE_ENUM)
|
|
|
|
fc = get_enum_fc(type);
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
print_file(file, 2, "0x%02x,\t/* %s */\n", fc, string_of_type(fc));
|
|
|
|
*typestring_offset += 1;
|
|
|
|
return 1;
|
2007-02-06 15:55:29 +01:00
|
|
|
}
|
|
|
|
|
2006-01-24 11:08:20 +01:00
|
|
|
/* write conformance / variance descriptor */
|
2011-05-26 21:34:51 +02:00
|
|
|
static unsigned int write_conf_or_var_desc(FILE *file, const type_t *cont_type,
|
2009-02-06 14:30:38 +01:00
|
|
|
unsigned int baseoff, const type_t *type,
|
|
|
|
const expr_t *expr)
|
2006-01-24 11:08:20 +01:00
|
|
|
{
|
2006-01-24 11:09:03 +01:00
|
|
|
unsigned char operator_type = 0;
|
2018-06-13 04:19:11 +02:00
|
|
|
unsigned char conftype = FC_NORMAL_CONFORMANCE;
|
2011-05-26 21:34:51 +02:00
|
|
|
const char *conftype_string = "field";
|
2007-06-06 03:50:31 +02:00
|
|
|
const expr_t *subexpr;
|
2011-05-26 21:34:51 +02:00
|
|
|
const type_t *iface = NULL;
|
|
|
|
const char *name;
|
2006-01-24 11:09:03 +01:00
|
|
|
|
2007-09-18 00:24:14 +02:00
|
|
|
if (!expr)
|
|
|
|
{
|
|
|
|
print_file(file, 2, "NdrFcLong(0xffffffff),\t/* -1 */\n");
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
2006-01-31 18:05:43 +01:00
|
|
|
if (expr->is_const)
|
|
|
|
{
|
|
|
|
if (expr->cval > UCHAR_MAX * (USHRT_MAX + 1) + USHRT_MAX)
|
2010-03-26 11:42:28 +01:00
|
|
|
error("write_conf_or_var_desc: constant value %d is greater than "
|
2006-01-31 18:05:43 +01:00
|
|
|
"the maximum constant size of %d\n", expr->cval,
|
|
|
|
UCHAR_MAX * (USHRT_MAX + 1) + USHRT_MAX);
|
|
|
|
|
2010-03-26 11:42:28 +01:00
|
|
|
print_file(file, 2, "0x%x, /* Corr desc: constant, val = %d */\n",
|
2018-06-13 04:19:11 +02:00
|
|
|
FC_CONSTANT_CONFORMANCE, expr->cval);
|
2010-03-26 11:42:28 +01:00
|
|
|
print_file(file, 2, "0x%x,\n", expr->cval >> 16);
|
2009-02-06 14:38:45 +01:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%hx),\n", (unsigned short)expr->cval);
|
2006-01-31 18:05:43 +01:00
|
|
|
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
2011-05-26 21:34:51 +02:00
|
|
|
if (!cont_type) /* top-level conformance */
|
2010-03-23 14:34:03 +01:00
|
|
|
{
|
2018-06-13 04:19:11 +02:00
|
|
|
conftype = FC_TOP_LEVEL_CONFORMANCE;
|
2011-05-26 21:34:51 +02:00
|
|
|
conftype_string = "parameter";
|
|
|
|
cont_type = current_func->type;
|
|
|
|
name = current_func->name;
|
|
|
|
iface = current_iface;
|
2010-03-23 14:34:03 +01:00
|
|
|
}
|
2011-05-26 21:34:51 +02:00
|
|
|
else
|
2007-10-11 00:29:54 +02:00
|
|
|
{
|
2011-05-26 21:34:51 +02:00
|
|
|
name = cont_type->name;
|
|
|
|
if (is_ptr(type) || (is_array(type) && type_array_is_decl_as_ptr(type)))
|
|
|
|
{
|
2018-06-13 04:19:11 +02:00
|
|
|
conftype = FC_POINTER_CONFORMANCE;
|
2011-05-26 21:34:51 +02:00
|
|
|
conftype_string = "field pointer";
|
|
|
|
}
|
2007-10-11 00:29:54 +02:00
|
|
|
}
|
|
|
|
|
2007-06-06 03:50:31 +02:00
|
|
|
subexpr = expr;
|
2006-01-24 11:09:03 +01:00
|
|
|
switch (subexpr->type)
|
|
|
|
{
|
|
|
|
case EXPR_PPTR:
|
|
|
|
subexpr = subexpr->ref;
|
2018-06-13 04:19:11 +02:00
|
|
|
operator_type = FC_DEREFERENCE;
|
2006-01-24 11:09:03 +01:00
|
|
|
break;
|
|
|
|
case EXPR_DIV:
|
|
|
|
if (subexpr->u.ext->is_const && (subexpr->u.ext->cval == 2))
|
|
|
|
{
|
|
|
|
subexpr = subexpr->ref;
|
2018-06-13 04:19:11 +02:00
|
|
|
operator_type = FC_DIV_2;
|
2006-01-24 11:09:03 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EXPR_MUL:
|
|
|
|
if (subexpr->u.ext->is_const && (subexpr->u.ext->cval == 2))
|
|
|
|
{
|
|
|
|
subexpr = subexpr->ref;
|
2018-06-13 04:19:11 +02:00
|
|
|
operator_type = FC_MULT_2;
|
2006-01-24 11:09:03 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EXPR_SUB:
|
|
|
|
if (subexpr->u.ext->is_const && (subexpr->u.ext->cval == 1))
|
|
|
|
{
|
|
|
|
subexpr = subexpr->ref;
|
2018-06-13 04:19:11 +02:00
|
|
|
operator_type = FC_SUB_1;
|
2006-01-24 11:09:03 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EXPR_ADD:
|
|
|
|
if (subexpr->u.ext->is_const && (subexpr->u.ext->cval == 1))
|
|
|
|
{
|
|
|
|
subexpr = subexpr->ref;
|
2018-06-13 04:19:11 +02:00
|
|
|
operator_type = FC_ADD_1;
|
2006-01-24 11:09:03 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (subexpr->type == EXPR_IDENTIFIER)
|
2006-01-24 11:08:20 +01:00
|
|
|
{
|
2006-01-24 11:12:54 +01:00
|
|
|
const type_t *correlation_variable = NULL;
|
|
|
|
unsigned char param_type = 0;
|
2009-02-06 14:30:38 +01:00
|
|
|
unsigned int offset = 0;
|
2007-09-04 18:33:23 +02:00
|
|
|
const var_t *var;
|
2011-05-26 21:34:51 +02:00
|
|
|
struct expr_loc expr_loc;
|
2006-01-24 11:12:54 +01:00
|
|
|
|
2011-05-26 21:34:51 +02:00
|
|
|
if (type_get_type(cont_type) == TYPE_FUNCTION)
|
2006-01-24 11:12:54 +01:00
|
|
|
{
|
2011-05-26 21:34:51 +02:00
|
|
|
var_list_t *args = type_get_function_args( cont_type );
|
|
|
|
|
|
|
|
if (is_object( iface )) offset += pointer_size;
|
|
|
|
if (args) LIST_FOR_EACH_ENTRY( var, args, const var_t, entry )
|
2006-01-24 11:12:54 +01:00
|
|
|
{
|
2011-05-26 21:34:51 +02:00
|
|
|
if (var->name && !strcmp(var->name, subexpr->u.sval))
|
|
|
|
{
|
|
|
|
expr_loc.v = var;
|
|
|
|
correlation_variable = var->type;
|
|
|
|
break;
|
|
|
|
}
|
2011-09-19 11:54:42 +02:00
|
|
|
offset += get_stack_size( var, NULL );
|
2011-05-26 21:34:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var_list_t *fields = type_struct_get_fields( cont_type );
|
|
|
|
|
|
|
|
if (fields) LIST_FOR_EACH_ENTRY( var, fields, const var_t, entry )
|
|
|
|
{
|
|
|
|
unsigned int size = field_memsize( var->type, &offset );
|
|
|
|
if (var->name && !strcmp(var->name, subexpr->u.sval))
|
|
|
|
{
|
|
|
|
expr_loc.v = var;
|
|
|
|
correlation_variable = var->type;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
offset += size;
|
2006-01-24 11:08:20 +01:00
|
|
|
}
|
2006-01-24 11:12:54 +01:00
|
|
|
}
|
2006-01-24 11:08:20 +01:00
|
|
|
|
2011-05-26 21:34:51 +02:00
|
|
|
if (!correlation_variable)
|
|
|
|
error("write_conf_or_var_desc: couldn't find variable %s in %s\n", subexpr->u.sval, name);
|
|
|
|
expr_loc.attr = NULL;
|
|
|
|
correlation_variable = expr_resolve_type(&expr_loc, cont_type, expr);
|
2008-04-22 12:36:54 +02:00
|
|
|
|
2007-09-04 18:33:23 +02:00
|
|
|
offset -= baseoff;
|
2006-01-24 11:08:20 +01:00
|
|
|
|
2009-02-23 14:48:34 +01:00
|
|
|
if (type_get_type(correlation_variable) == TYPE_BASIC)
|
2006-01-24 11:12:54 +01:00
|
|
|
{
|
2009-03-08 00:24:00 +01:00
|
|
|
switch (get_basic_fc(correlation_variable))
|
2009-02-23 14:48:34 +01:00
|
|
|
{
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_CHAR:
|
|
|
|
case FC_SMALL:
|
|
|
|
param_type = FC_SMALL;
|
2009-02-23 14:48:34 +01:00
|
|
|
break;
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_BYTE:
|
|
|
|
case FC_USMALL:
|
|
|
|
param_type = FC_USMALL;
|
2009-02-23 14:48:34 +01:00
|
|
|
break;
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_WCHAR:
|
|
|
|
case FC_SHORT:
|
|
|
|
param_type = FC_SHORT;
|
2009-02-23 14:48:34 +01:00
|
|
|
break;
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_USHORT:
|
|
|
|
param_type = FC_USHORT;
|
2009-02-23 14:48:34 +01:00
|
|
|
break;
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_LONG:
|
|
|
|
param_type = FC_LONG;
|
2009-02-23 14:48:34 +01:00
|
|
|
break;
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_ULONG:
|
|
|
|
param_type = FC_ULONG;
|
2009-02-23 14:48:34 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error("write_conf_or_var_desc: conformance variable type not supported 0x%x\n",
|
2009-03-08 00:24:00 +01:00
|
|
|
get_basic_fc(correlation_variable));
|
2009-02-23 14:48:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (type_get_type(correlation_variable) == TYPE_ENUM)
|
|
|
|
{
|
2018-06-13 04:19:11 +02:00
|
|
|
if (get_enum_fc(correlation_variable) == FC_ENUM32)
|
|
|
|
param_type = FC_LONG;
|
2009-02-23 14:48:34 +01:00
|
|
|
else
|
2018-06-13 04:19:11 +02:00
|
|
|
param_type = FC_SHORT;
|
2009-02-23 14:48:34 +01:00
|
|
|
}
|
2010-03-15 20:30:20 +01:00
|
|
|
else if (type_get_type(correlation_variable) == TYPE_POINTER)
|
|
|
|
{
|
|
|
|
if (pointer_size == 8)
|
2018-06-13 04:19:11 +02:00
|
|
|
param_type = FC_HYPER;
|
2010-03-15 20:30:20 +01:00
|
|
|
else
|
2018-06-13 04:19:11 +02:00
|
|
|
param_type = FC_LONG;
|
2010-03-15 20:30:20 +01:00
|
|
|
}
|
2009-02-23 14:48:34 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
error("write_conf_or_var_desc: non-arithmetic type used as correlation variable %s\n",
|
|
|
|
subexpr->u.sval);
|
|
|
|
return 0;
|
2006-01-24 11:08:20 +01:00
|
|
|
}
|
2006-01-24 11:12:54 +01:00
|
|
|
|
2011-05-26 21:34:51 +02:00
|
|
|
print_file(file, 2, "0x%x,\t/* Corr desc: %s %s, %s */\n",
|
|
|
|
conftype | param_type, conftype_string, subexpr->u.sval, string_of_type(param_type));
|
|
|
|
print_file(file, 2, "0x%x,\t/* %s */\n", operator_type,
|
2010-03-23 14:33:59 +01:00
|
|
|
operator_type ? string_of_type(operator_type) : "no operators");
|
2009-02-06 14:38:45 +01:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%hx),\t/* offset = %d */\n",
|
2010-09-16 12:12:40 +02:00
|
|
|
(unsigned short)offset, offset);
|
2006-01-24 11:08:20 +01:00
|
|
|
}
|
2011-05-28 13:38:25 +02:00
|
|
|
else if (!iface || is_interpreted_func( iface, current_func ))
|
2006-01-27 12:53:32 +01:00
|
|
|
{
|
|
|
|
unsigned int callback_offset = 0;
|
2007-09-04 18:33:23 +02:00
|
|
|
struct expr_eval_routine *eval;
|
|
|
|
int found = 0;
|
2006-01-27 12:53:32 +01:00
|
|
|
|
2007-09-04 18:33:23 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(eval, &expr_eval_routines, struct expr_eval_routine, entry)
|
2006-01-27 12:53:32 +01:00
|
|
|
{
|
2011-05-26 21:34:51 +02:00
|
|
|
if (eval->cont_type == cont_type ||
|
|
|
|
(type_get_type( eval->cont_type ) == type_get_type( cont_type ) &&
|
|
|
|
eval->iface == iface &&
|
|
|
|
eval->name && name && !strcmp(eval->name, name) &&
|
2010-03-15 20:30:37 +01:00
|
|
|
!compare_expr(eval->expr, expr)))
|
2006-01-31 12:24:11 +01:00
|
|
|
{
|
2007-09-04 18:33:23 +02:00
|
|
|
found = 1;
|
|
|
|
break;
|
2006-01-31 12:24:11 +01:00
|
|
|
}
|
2007-09-04 18:33:23 +02:00
|
|
|
callback_offset++;
|
2006-01-27 12:53:32 +01:00
|
|
|
}
|
2007-09-04 18:33:23 +02:00
|
|
|
|
|
|
|
if (!found)
|
2006-01-27 12:53:32 +01:00
|
|
|
{
|
2007-09-04 18:33:23 +02:00
|
|
|
eval = xmalloc (sizeof(*eval));
|
2011-05-26 21:34:51 +02:00
|
|
|
eval->iface = iface;
|
|
|
|
eval->cont_type = cont_type;
|
|
|
|
eval->name = xstrdup( name );
|
2007-10-11 00:29:54 +02:00
|
|
|
eval->baseoff = baseoff;
|
2007-09-04 18:33:23 +02:00
|
|
|
eval->expr = expr;
|
|
|
|
list_add_tail (&expr_eval_routines, &eval->entry);
|
2006-01-27 12:53:32 +01:00
|
|
|
}
|
|
|
|
|
2006-01-31 12:24:11 +01:00
|
|
|
if (callback_offset > USHRT_MAX)
|
|
|
|
error("Maximum number of callback routines reached\n");
|
|
|
|
|
2011-05-26 21:34:51 +02:00
|
|
|
print_file(file, 2, "0x%x,\t/* Corr desc: %s in %s */\n", conftype, conftype_string, name);
|
2018-06-13 04:19:11 +02:00
|
|
|
print_file(file, 2, "0x%x,\t/* %s */\n", FC_CALLBACK, "FC_CALLBACK");
|
2010-09-16 12:12:40 +02:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%hx),\t/* %u */\n", (unsigned short)callback_offset, callback_offset);
|
2006-01-27 12:53:32 +01:00
|
|
|
}
|
2011-05-28 13:38:25 +02:00
|
|
|
else /* output a dummy corr desc that isn't used */
|
|
|
|
{
|
|
|
|
print_file(file, 2, "0x%x,\t/* Corr desc: unused for %s */\n", conftype, name);
|
|
|
|
print_file(file, 2, "0x0,\n" );
|
|
|
|
print_file(file, 2, "NdrFcShort(0x0),\n" );
|
|
|
|
}
|
2006-01-24 11:08:20 +01:00
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
2009-07-03 12:02:30 +02:00
|
|
|
/* return size and start offset of a data field based on current offset */
|
|
|
|
static unsigned int field_memsize(const type_t *type, unsigned int *offset)
|
|
|
|
{
|
|
|
|
unsigned int align = 0;
|
2010-04-05 19:48:07 +02:00
|
|
|
unsigned int size = type_memsize_and_alignment( type, &align );
|
2009-07-03 12:02:30 +02:00
|
|
|
|
|
|
|
*offset = ROUND_SIZE( *offset, align );
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2009-02-06 14:30:38 +01:00
|
|
|
static unsigned int fields_memsize(const var_list_t *fields, unsigned int *align)
|
2006-01-24 11:07:13 +01:00
|
|
|
{
|
2009-02-06 14:30:38 +01:00
|
|
|
unsigned int size = 0;
|
2009-08-17 16:16:54 +02:00
|
|
|
unsigned int max_align;
|
2007-01-22 14:26:12 +01:00
|
|
|
const var_t *v;
|
|
|
|
|
|
|
|
if (!fields) return 0;
|
|
|
|
LIST_FOR_EACH_ENTRY( v, fields, const var_t, entry )
|
2007-09-04 20:04:37 +02:00
|
|
|
{
|
|
|
|
unsigned int falign = 0;
|
2010-04-05 19:48:07 +02:00
|
|
|
unsigned int fsize = type_memsize_and_alignment(v->type, &falign);
|
2009-07-03 12:02:07 +02:00
|
|
|
if (*align < falign) *align = falign;
|
2009-08-25 14:29:47 +02:00
|
|
|
falign = clamp_align(falign);
|
2008-06-23 13:57:28 +02:00
|
|
|
size = ROUND_SIZE(size, falign);
|
2007-09-04 20:04:37 +02:00
|
|
|
size += fsize;
|
|
|
|
}
|
2007-01-22 14:26:12 +01:00
|
|
|
|
2009-08-25 14:29:47 +02:00
|
|
|
max_align = clamp_align(*align);
|
2009-08-17 16:16:54 +02:00
|
|
|
size = ROUND_SIZE(size, max_align);
|
|
|
|
|
2006-01-24 11:07:13 +01:00
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2009-02-06 14:30:38 +01:00
|
|
|
static unsigned int union_memsize(const var_list_t *fields, unsigned int *pmaxa)
|
2007-05-19 01:53:27 +02:00
|
|
|
{
|
2009-02-06 14:30:38 +01:00
|
|
|
unsigned int size, maxs = 0;
|
2007-05-19 01:53:27 +02:00
|
|
|
unsigned int align = *pmaxa;
|
|
|
|
const var_t *v;
|
|
|
|
|
|
|
|
if (fields) LIST_FOR_EACH_ENTRY( v, fields, const var_t, entry )
|
|
|
|
{
|
|
|
|
/* we could have an empty default field with NULL type */
|
|
|
|
if (v->type)
|
|
|
|
{
|
2010-04-05 19:48:07 +02:00
|
|
|
size = type_memsize_and_alignment(v->type, &align);
|
2007-05-19 01:53:27 +02:00
|
|
|
if (maxs < size) maxs = size;
|
|
|
|
if (*pmaxa < align) *pmaxa = align;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return maxs;
|
|
|
|
}
|
|
|
|
|
2018-06-05 00:59:34 +02:00
|
|
|
unsigned int type_memsize_and_alignment(const type_t *t, unsigned int *align)
|
2006-01-24 11:07:13 +01:00
|
|
|
{
|
2009-02-06 14:30:38 +01:00
|
|
|
unsigned int size = 0;
|
2006-01-24 11:07:13 +01:00
|
|
|
|
2009-02-23 14:48:34 +01:00
|
|
|
switch (type_get_type(t))
|
2007-02-06 15:54:58 +01:00
|
|
|
{
|
2009-02-23 14:48:34 +01:00
|
|
|
case TYPE_BASIC:
|
2009-03-08 00:24:00 +01:00
|
|
|
switch (get_basic_fc(t))
|
2009-02-23 14:48:34 +01:00
|
|
|
{
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_BYTE:
|
|
|
|
case FC_CHAR:
|
|
|
|
case FC_USMALL:
|
|
|
|
case FC_SMALL:
|
2009-02-23 14:48:34 +01:00
|
|
|
size = 1;
|
|
|
|
if (size > *align) *align = size;
|
|
|
|
break;
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_WCHAR:
|
|
|
|
case FC_USHORT:
|
|
|
|
case FC_SHORT:
|
2009-02-23 14:48:34 +01:00
|
|
|
size = 2;
|
|
|
|
if (size > *align) *align = size;
|
|
|
|
break;
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_ULONG:
|
|
|
|
case FC_LONG:
|
|
|
|
case FC_ERROR_STATUS_T:
|
|
|
|
case FC_FLOAT:
|
2009-02-23 14:48:34 +01:00
|
|
|
size = 4;
|
|
|
|
if (size > *align) *align = size;
|
|
|
|
break;
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_HYPER:
|
|
|
|
case FC_DOUBLE:
|
2009-02-23 14:48:34 +01:00
|
|
|
size = 8;
|
|
|
|
if (size > *align) *align = size;
|
|
|
|
break;
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_INT3264:
|
|
|
|
case FC_UINT3264:
|
|
|
|
case FC_BIND_PRIMITIVE:
|
2009-11-07 15:54:56 +01:00
|
|
|
assert( pointer_size );
|
|
|
|
size = pointer_size;
|
|
|
|
if (size > *align) *align = size;
|
|
|
|
break;
|
2009-02-23 14:48:34 +01:00
|
|
|
default:
|
2009-03-08 00:24:00 +01:00
|
|
|
error("type_memsize: Unknown type 0x%x\n", get_basic_fc(t));
|
2009-02-23 14:48:34 +01:00
|
|
|
size = 0;
|
|
|
|
}
|
2006-01-24 11:07:13 +01:00
|
|
|
break;
|
2009-02-23 14:48:34 +01:00
|
|
|
case TYPE_ENUM:
|
|
|
|
switch (get_enum_fc(t))
|
|
|
|
{
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_ENUM16:
|
|
|
|
case FC_ENUM32:
|
2009-02-23 14:48:34 +01:00
|
|
|
size = 4;
|
|
|
|
if (size > *align) *align = size;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error("type_memsize: Unknown enum type\n");
|
|
|
|
size = 0;
|
|
|
|
}
|
2006-01-24 11:07:13 +01:00
|
|
|
break;
|
2009-02-23 14:48:34 +01:00
|
|
|
case TYPE_STRUCT:
|
2008-12-29 13:05:27 +01:00
|
|
|
size = fields_memsize(type_struct_get_fields(t), align);
|
2007-05-19 01:53:27 +02:00
|
|
|
break;
|
2009-02-23 14:48:34 +01:00
|
|
|
case TYPE_ENCAPSULATED_UNION:
|
2008-12-29 13:05:27 +01:00
|
|
|
size = fields_memsize(type_encapsulated_union_get_fields(t), align);
|
|
|
|
break;
|
2009-02-23 14:48:34 +01:00
|
|
|
case TYPE_UNION:
|
2008-12-29 13:05:27 +01:00
|
|
|
size = union_memsize(type_union_get_cases(t), align);
|
2006-01-24 11:07:13 +01:00
|
|
|
break;
|
2009-02-23 14:48:34 +01:00
|
|
|
case TYPE_POINTER:
|
2018-06-05 00:59:34 +02:00
|
|
|
case TYPE_INTERFACE:
|
2009-02-23 14:48:34 +01:00
|
|
|
assert( pointer_size );
|
|
|
|
size = pointer_size;
|
|
|
|
if (size > *align) *align = size;
|
2007-06-06 03:50:31 +02:00
|
|
|
break;
|
2009-02-23 14:48:34 +01:00
|
|
|
case TYPE_ARRAY:
|
2009-03-05 09:21:35 +01:00
|
|
|
if (!type_array_is_decl_as_ptr(t))
|
2009-02-23 14:48:34 +01:00
|
|
|
{
|
|
|
|
if (is_conformant_array(t))
|
|
|
|
{
|
2010-04-05 19:48:07 +02:00
|
|
|
type_memsize_and_alignment(type_array_get_element(t), align);
|
2009-02-23 14:48:34 +01:00
|
|
|
size = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
size = type_array_get_dim(t) *
|
2010-04-05 19:48:07 +02:00
|
|
|
type_memsize_and_alignment(type_array_get_element(t), align);
|
2009-02-23 14:48:34 +01:00
|
|
|
}
|
|
|
|
else /* declared as a pointer */
|
|
|
|
{
|
|
|
|
assert( pointer_size );
|
|
|
|
size = pointer_size;
|
|
|
|
if (size > *align) *align = size;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TYPE_ALIAS:
|
|
|
|
case TYPE_VOID:
|
|
|
|
case TYPE_COCLASS:
|
|
|
|
case TYPE_MODULE:
|
|
|
|
case TYPE_FUNCTION:
|
2009-11-07 15:55:09 +01:00
|
|
|
case TYPE_BITFIELD:
|
2009-02-23 14:48:34 +01:00
|
|
|
/* these types should not be encountered here due to language
|
|
|
|
* restrictions (interface, void, coclass, module), logical
|
|
|
|
* restrictions (alias - due to type_get_type call above) or
|
2009-11-07 15:55:09 +01:00
|
|
|
* checking restrictions (function, bitfield). */
|
2009-02-23 14:48:34 +01:00
|
|
|
assert(0);
|
2006-01-24 11:07:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2010-04-05 19:48:07 +02:00
|
|
|
unsigned int type_memsize(const type_t *t)
|
|
|
|
{
|
|
|
|
unsigned int align = 0;
|
|
|
|
return type_memsize_and_alignment( t, &align );
|
|
|
|
}
|
|
|
|
|
2010-04-05 20:05:05 +02:00
|
|
|
static unsigned int type_buffer_alignment(const type_t *t)
|
|
|
|
{
|
|
|
|
const var_list_t *fields;
|
|
|
|
const var_t *var;
|
|
|
|
unsigned int max = 0, align;
|
|
|
|
|
|
|
|
switch (type_get_type(t))
|
|
|
|
{
|
|
|
|
case TYPE_BASIC:
|
|
|
|
switch (get_basic_fc(t))
|
|
|
|
{
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_BYTE:
|
|
|
|
case FC_CHAR:
|
|
|
|
case FC_USMALL:
|
|
|
|
case FC_SMALL:
|
2010-04-05 20:05:05 +02:00
|
|
|
return 1;
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_WCHAR:
|
|
|
|
case FC_USHORT:
|
|
|
|
case FC_SHORT:
|
2010-04-05 20:05:05 +02:00
|
|
|
return 2;
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_ULONG:
|
|
|
|
case FC_LONG:
|
|
|
|
case FC_ERROR_STATUS_T:
|
|
|
|
case FC_FLOAT:
|
|
|
|
case FC_INT3264:
|
|
|
|
case FC_UINT3264:
|
2010-04-05 20:05:05 +02:00
|
|
|
return 4;
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_HYPER:
|
|
|
|
case FC_DOUBLE:
|
2010-04-05 20:05:05 +02:00
|
|
|
return 8;
|
|
|
|
default:
|
|
|
|
error("type_buffer_alignment: Unknown type 0x%x\n", get_basic_fc(t));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TYPE_ENUM:
|
|
|
|
switch (get_enum_fc(t))
|
|
|
|
{
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_ENUM16:
|
2010-04-05 20:05:05 +02:00
|
|
|
return 2;
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_ENUM32:
|
2010-04-05 20:05:05 +02:00
|
|
|
return 4;
|
|
|
|
default:
|
|
|
|
error("type_buffer_alignment: Unknown enum type\n");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TYPE_STRUCT:
|
|
|
|
if (!(fields = type_struct_get_fields(t))) break;
|
|
|
|
LIST_FOR_EACH_ENTRY( var, fields, const var_t, entry )
|
|
|
|
{
|
|
|
|
if (!var->type) continue;
|
|
|
|
align = type_buffer_alignment( var->type );
|
|
|
|
if (max < align) max = align;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TYPE_ENCAPSULATED_UNION:
|
|
|
|
if (!(fields = type_encapsulated_union_get_fields(t))) break;
|
|
|
|
LIST_FOR_EACH_ENTRY( var, fields, const var_t, entry )
|
|
|
|
{
|
|
|
|
if (!var->type) continue;
|
|
|
|
align = type_buffer_alignment( var->type );
|
|
|
|
if (max < align) max = align;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TYPE_UNION:
|
|
|
|
if (!(fields = type_union_get_cases(t))) break;
|
|
|
|
LIST_FOR_EACH_ENTRY( var, fields, const var_t, entry )
|
|
|
|
{
|
|
|
|
if (!var->type) continue;
|
|
|
|
align = type_buffer_alignment( var->type );
|
|
|
|
if (max < align) max = align;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TYPE_ARRAY:
|
|
|
|
if (!type_array_is_decl_as_ptr(t))
|
|
|
|
return type_buffer_alignment( type_array_get_element(t) );
|
|
|
|
/* else fall through */
|
|
|
|
case TYPE_POINTER:
|
|
|
|
return 4;
|
|
|
|
case TYPE_INTERFACE:
|
|
|
|
case TYPE_ALIAS:
|
|
|
|
case TYPE_VOID:
|
|
|
|
case TYPE_COCLASS:
|
|
|
|
case TYPE_MODULE:
|
|
|
|
case TYPE_FUNCTION:
|
|
|
|
case TYPE_BITFIELD:
|
|
|
|
/* these types should not be encountered here due to language
|
|
|
|
* restrictions (interface, void, coclass, module), logical
|
|
|
|
* restrictions (alias - due to type_get_type call above) or
|
|
|
|
* checking restrictions (function, bitfield). */
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
return max;
|
|
|
|
}
|
|
|
|
|
2009-01-06 00:33:27 +01:00
|
|
|
int is_full_pointer_function(const var_t *func)
|
2008-01-30 23:29:39 +01:00
|
|
|
{
|
|
|
|
const var_t *var;
|
2009-03-08 00:23:44 +01:00
|
|
|
if (type_has_full_pointer(type_function_get_rettype(func->type), func->attrs, TRUE))
|
2008-01-30 23:29:39 +01:00
|
|
|
return TRUE;
|
2009-01-06 00:33:27 +01:00
|
|
|
if (!type_get_function_args(func->type))
|
2008-01-30 23:29:39 +01:00
|
|
|
return FALSE;
|
2009-01-06 00:33:27 +01:00
|
|
|
LIST_FOR_EACH_ENTRY( var, type_get_function_args(func->type), const var_t, entry )
|
2009-03-08 00:23:44 +01:00
|
|
|
if (type_has_full_pointer( var->type, var->attrs, TRUE ))
|
2008-01-30 23:29:39 +01:00
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-01-06 00:33:27 +01:00
|
|
|
void write_full_pointer_init(FILE *file, int indent, const var_t *func, int is_server)
|
2008-01-30 23:29:39 +01:00
|
|
|
{
|
2008-09-15 14:02:26 +02:00
|
|
|
print_file(file, indent, "__frame->_StubMsg.FullPtrXlatTables = NdrFullPointerXlatInit(0,%s);\n",
|
2008-01-30 23:29:39 +01:00
|
|
|
is_server ? "XLAT_SERVER" : "XLAT_CLIENT");
|
|
|
|
fprintf(file, "\n");
|
|
|
|
}
|
|
|
|
|
2009-01-06 00:33:27 +01:00
|
|
|
void write_full_pointer_free(FILE *file, int indent, const var_t *func)
|
2008-01-30 23:29:39 +01:00
|
|
|
{
|
2008-09-15 14:02:26 +02:00
|
|
|
print_file(file, indent, "NdrFullPointerXlatFree(__frame->_StubMsg.FullPtrXlatTables);\n");
|
2008-01-30 23:29:39 +01:00
|
|
|
fprintf(file, "\n");
|
|
|
|
}
|
|
|
|
|
2009-03-08 00:23:39 +01:00
|
|
|
static unsigned int write_nonsimple_pointer(FILE *file, const attr_list_t *attrs,
|
|
|
|
const type_t *type,
|
2011-06-14 12:24:00 +02:00
|
|
|
enum type_context context,
|
2009-03-08 00:23:39 +01:00
|
|
|
unsigned int offset,
|
|
|
|
unsigned int *typeformat_offset)
|
2007-05-10 05:50:49 +02:00
|
|
|
{
|
2009-03-08 00:23:39 +01:00
|
|
|
unsigned int start_offset = *typeformat_offset;
|
|
|
|
short reloff = offset - (*typeformat_offset + 2);
|
|
|
|
int in_attr, out_attr;
|
|
|
|
int pointer_type;
|
|
|
|
unsigned char flags = 0;
|
2007-05-12 02:27:40 +02:00
|
|
|
|
2011-06-14 12:24:00 +02:00
|
|
|
pointer_type = get_pointer_fc_context(type, attrs, context);
|
2009-03-08 00:23:39 +01:00
|
|
|
|
|
|
|
in_attr = is_attr(attrs, ATTR_IN);
|
|
|
|
out_attr = is_attr(attrs, ATTR_OUT);
|
|
|
|
if (!in_attr && !out_attr) in_attr = 1;
|
|
|
|
|
2018-10-31 00:23:22 +01:00
|
|
|
if (!is_interpreted_func(current_iface, current_func))
|
|
|
|
{
|
|
|
|
if (out_attr && !in_attr && pointer_type == FC_RP)
|
|
|
|
flags |= FC_ALLOCED_ON_STACK;
|
|
|
|
}
|
|
|
|
else if (get_stub_mode() == MODE_Oif)
|
|
|
|
{
|
|
|
|
if (context == TYPE_CONTEXT_TOPLEVELPARAM && is_ptr(type) && pointer_type == FC_RP)
|
|
|
|
{
|
|
|
|
switch (typegen_detect_type(type_pointer_get_ref(type), NULL, TDT_ALL_TYPES))
|
|
|
|
{
|
|
|
|
case TGT_STRING:
|
|
|
|
case TGT_POINTER:
|
|
|
|
case TGT_CTXT_HANDLE:
|
|
|
|
case TGT_CTXT_HANDLE_POINTER:
|
2019-05-29 07:24:06 +02:00
|
|
|
case TGT_ARRAY:
|
2018-10-31 00:23:22 +01:00
|
|
|
flags |= FC_ALLOCED_ON_STACK;
|
|
|
|
break;
|
|
|
|
case TGT_IFACE_POINTER:
|
|
|
|
if (in_attr && out_attr)
|
|
|
|
flags |= FC_ALLOCED_ON_STACK;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-03-08 00:23:39 +01:00
|
|
|
|
2011-02-03 12:53:30 +01:00
|
|
|
if (is_ptr(type))
|
|
|
|
{
|
|
|
|
type_t *ref = type_pointer_get_ref(type);
|
|
|
|
if(is_declptr(ref) && !is_user_type(ref))
|
2018-06-13 04:19:11 +02:00
|
|
|
flags |= FC_POINTER_DEREF;
|
2011-02-03 12:53:30 +01:00
|
|
|
}
|
2009-03-08 00:23:39 +01:00
|
|
|
|
|
|
|
print_file(file, 2, "0x%x, 0x%x,\t\t/* %s",
|
|
|
|
pointer_type,
|
|
|
|
flags,
|
|
|
|
string_of_type(pointer_type));
|
|
|
|
if (file)
|
|
|
|
{
|
2018-06-13 04:19:11 +02:00
|
|
|
if (flags & FC_ALLOCED_ON_STACK)
|
2009-03-08 00:23:39 +01:00
|
|
|
fprintf(file, " [allocated_on_stack]");
|
2018-06-13 04:19:11 +02:00
|
|
|
if (flags & FC_POINTER_DEREF)
|
2009-03-08 00:23:39 +01:00
|
|
|
fprintf(file, " [pointer_deref]");
|
|
|
|
fprintf(file, " */\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
print_file(file, 2, "NdrFcShort(0x%hx),\t/* Offset= %hd (%u) */\n", reloff, reloff, offset);
|
|
|
|
*typeformat_offset += 4;
|
|
|
|
|
|
|
|
return start_offset;
|
2007-05-10 05:50:49 +02:00
|
|
|
}
|
|
|
|
|
2011-06-14 12:24:00 +02:00
|
|
|
static unsigned int write_simple_pointer(FILE *file, const attr_list_t *attrs,
|
|
|
|
const type_t *type, enum type_context context)
|
2007-05-10 05:50:49 +02:00
|
|
|
{
|
2009-02-23 14:48:34 +01:00
|
|
|
unsigned char fc;
|
|
|
|
unsigned char pointer_fc;
|
|
|
|
const type_t *ref;
|
2010-03-15 20:29:48 +01:00
|
|
|
int in_attr = is_attr(attrs, ATTR_IN);
|
|
|
|
int out_attr = is_attr(attrs, ATTR_OUT);
|
2018-06-13 04:19:11 +02:00
|
|
|
unsigned char flags = FC_SIMPLE_POINTER;
|
2009-02-23 14:48:34 +01:00
|
|
|
|
2008-03-27 15:05:45 +01:00
|
|
|
/* for historical reasons, write_simple_pointer also handled string types,
|
|
|
|
* but no longer does. catch bad uses of the function with this check */
|
2009-03-08 00:23:39 +01:00
|
|
|
if (is_string_type(attrs, type))
|
2008-03-27 15:05:45 +01:00
|
|
|
error("write_simple_pointer: can't handle type %s which is a string type\n", type->name);
|
2009-02-23 14:48:34 +01:00
|
|
|
|
2011-06-14 12:24:00 +02:00
|
|
|
pointer_fc = get_pointer_fc_context(type, attrs, context);
|
2009-02-23 14:48:34 +01:00
|
|
|
|
|
|
|
ref = type_pointer_get_ref(type);
|
|
|
|
if (type_get_type(ref) == TYPE_ENUM)
|
|
|
|
fc = get_enum_fc(ref);
|
|
|
|
else
|
2009-03-08 00:24:00 +01:00
|
|
|
fc = get_basic_fc(ref);
|
2009-02-23 14:48:34 +01:00
|
|
|
|
2018-10-31 00:23:22 +01:00
|
|
|
if (!is_interpreted_func(current_iface, current_func))
|
|
|
|
{
|
|
|
|
if (out_attr && !in_attr && pointer_fc == FC_RP)
|
|
|
|
flags |= FC_ALLOCED_ON_STACK;
|
|
|
|
}
|
|
|
|
else if (get_stub_mode() == MODE_Oif)
|
|
|
|
{
|
|
|
|
if (context == TYPE_CONTEXT_TOPLEVELPARAM && fc == FC_ENUM16 && pointer_fc == FC_RP)
|
|
|
|
flags |= FC_ALLOCED_ON_STACK;
|
|
|
|
}
|
2010-03-15 20:29:48 +01:00
|
|
|
|
|
|
|
print_file(file, 2, "0x%02x, 0x%x,\t/* %s %s[simple_pointer] */\n",
|
|
|
|
pointer_fc, flags, string_of_type(pointer_fc),
|
2018-06-13 04:19:11 +02:00
|
|
|
flags & FC_ALLOCED_ON_STACK ? "[allocated_on_stack] " : "");
|
2007-09-26 20:32:47 +02:00
|
|
|
print_file(file, 2, "0x%02x,\t/* %s */\n", fc, string_of_type(fc));
|
2007-05-10 05:50:49 +02:00
|
|
|
print_file(file, 2, "0x5c,\t/* FC_PAD */\n");
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
2007-10-03 06:40:13 +02:00
|
|
|
static void print_start_tfs_comment(FILE *file, type_t *t, unsigned int tfsoff)
|
|
|
|
{
|
|
|
|
print_file(file, 0, "/* %u (", tfsoff);
|
|
|
|
write_type_decl(file, t, NULL);
|
|
|
|
print_file(file, 0, ") */\n");
|
|
|
|
}
|
|
|
|
|
2009-03-08 00:23:44 +01:00
|
|
|
static unsigned int write_pointer_tfs(FILE *file, const attr_list_t *attrs,
|
2010-03-15 20:29:48 +01:00
|
|
|
type_t *type, unsigned int ref_offset,
|
2011-06-14 12:24:00 +02:00
|
|
|
enum type_context context,
|
2009-03-08 00:23:44 +01:00
|
|
|
unsigned int *typestring_offset)
|
2007-05-16 02:48:20 +02:00
|
|
|
{
|
2007-05-21 08:55:43 +02:00
|
|
|
unsigned int offset = *typestring_offset;
|
2009-02-23 14:48:34 +01:00
|
|
|
type_t *ref = type_pointer_get_ref(type);
|
2007-05-16 02:48:20 +02:00
|
|
|
|
2007-10-03 06:40:13 +02:00
|
|
|
print_start_tfs_comment(file, type, offset);
|
2007-05-25 02:50:02 +02:00
|
|
|
update_tfsoff(type, offset, file);
|
2007-05-16 02:48:20 +02:00
|
|
|
|
2010-03-15 20:29:38 +01:00
|
|
|
switch (typegen_detect_type(ref, attrs, TDT_ALL_TYPES))
|
|
|
|
{
|
|
|
|
case TGT_BASIC:
|
|
|
|
case TGT_ENUM:
|
2011-06-14 12:24:00 +02:00
|
|
|
*typestring_offset += write_simple_pointer(file, attrs, type, context);
|
2010-03-15 20:29:38 +01:00
|
|
|
break;
|
|
|
|
default:
|
2010-03-15 20:29:48 +01:00
|
|
|
if (ref_offset)
|
2011-06-14 12:24:00 +02:00
|
|
|
write_nonsimple_pointer(file, attrs, type, context, ref_offset, typestring_offset);
|
2010-03-15 20:29:38 +01:00
|
|
|
break;
|
|
|
|
}
|
2007-05-16 02:48:20 +02:00
|
|
|
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
2007-05-25 02:50:02 +02:00
|
|
|
static int processed(const type_t *type)
|
2007-05-16 02:48:20 +02:00
|
|
|
{
|
2007-05-25 02:50:02 +02:00
|
|
|
return type->typestring_offset && !type->tfswrite;
|
2007-05-16 02:48:20 +02:00
|
|
|
}
|
|
|
|
|
2007-10-20 00:30:12 +02:00
|
|
|
static int user_type_has_variable_size(const type_t *t)
|
|
|
|
{
|
|
|
|
if (is_ptr(t))
|
|
|
|
return TRUE;
|
2009-02-23 14:48:34 +01:00
|
|
|
else if (type_get_type(t) == TYPE_STRUCT)
|
|
|
|
{
|
|
|
|
switch (get_struct_fc(t))
|
2007-10-20 00:30:12 +02:00
|
|
|
{
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_PSTRUCT:
|
|
|
|
case FC_CSTRUCT:
|
|
|
|
case FC_CPSTRUCT:
|
|
|
|
case FC_CVSTRUCT:
|
2007-10-20 00:30:12 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
2009-02-23 14:48:34 +01:00
|
|
|
}
|
2007-10-20 00:30:12 +02:00
|
|
|
/* Note: Since this only applies to user types, we can't have a conformant
|
|
|
|
array here, and strings should get filed under pointer in this case. */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-05-26 14:59:46 +02:00
|
|
|
static unsigned int write_user_tfs(FILE *file, type_t *type, unsigned int *tfsoff)
|
2007-06-14 01:13:04 +02:00
|
|
|
{
|
2007-06-14 01:15:41 +02:00
|
|
|
unsigned int start, absoff, flags;
|
2008-07-07 12:10:06 +02:00
|
|
|
const char *name = NULL;
|
2007-06-14 01:13:04 +02:00
|
|
|
type_t *utype = get_user_type(type, &name);
|
2010-04-05 20:05:05 +02:00
|
|
|
unsigned int usize = type_memsize(utype);
|
|
|
|
unsigned int ualign = type_buffer_alignment(utype);
|
2010-04-05 19:48:07 +02:00
|
|
|
unsigned int size = type_memsize(type);
|
2007-06-14 01:13:04 +02:00
|
|
|
unsigned short funoff = user_type_offset(name);
|
|
|
|
short reloff;
|
|
|
|
|
2011-05-26 14:59:46 +02:00
|
|
|
if (processed(type)) return type->typestring_offset;
|
|
|
|
|
2007-06-14 01:13:04 +02:00
|
|
|
guard_rec(type);
|
|
|
|
|
2009-08-21 14:20:16 +02:00
|
|
|
if(user_type_has_variable_size(utype)) usize = 0;
|
|
|
|
|
2009-02-23 14:48:34 +01:00
|
|
|
if (type_get_type(utype) == TYPE_BASIC ||
|
|
|
|
type_get_type(utype) == TYPE_ENUM)
|
2007-06-14 01:13:04 +02:00
|
|
|
{
|
2009-02-23 14:48:34 +01:00
|
|
|
unsigned char fc;
|
|
|
|
|
|
|
|
if (type_get_type(utype) == TYPE_ENUM)
|
|
|
|
fc = get_enum_fc(utype);
|
|
|
|
else
|
2009-03-08 00:24:00 +01:00
|
|
|
fc = get_basic_fc(utype);
|
2009-02-23 14:48:34 +01:00
|
|
|
|
2007-06-14 01:13:04 +02:00
|
|
|
absoff = *tfsoff;
|
2007-10-03 06:40:13 +02:00
|
|
|
print_start_tfs_comment(file, utype, absoff);
|
2009-02-23 14:48:34 +01:00
|
|
|
print_file(file, 2, "0x%x,\t/* %s */\n", fc, string_of_type(fc));
|
2007-06-14 01:13:04 +02:00
|
|
|
print_file(file, 2, "0x5c,\t/* FC_PAD */\n");
|
|
|
|
*tfsoff += 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!processed(utype))
|
|
|
|
write_embedded_types(file, NULL, utype, utype->name, TRUE, tfsoff);
|
|
|
|
absoff = utype->typestring_offset;
|
|
|
|
}
|
|
|
|
|
2018-06-13 04:19:11 +02:00
|
|
|
if (type_get_type(utype) == TYPE_POINTER && get_pointer_fc(utype, NULL, FALSE) == FC_RP)
|
2007-06-14 01:15:41 +02:00
|
|
|
flags = 0x40;
|
2018-06-13 04:19:11 +02:00
|
|
|
else if (type_get_type(utype) == TYPE_POINTER && get_pointer_fc(utype, NULL, FALSE) == FC_UP)
|
2007-06-14 01:15:41 +02:00
|
|
|
flags = 0x80;
|
|
|
|
else
|
|
|
|
flags = 0;
|
|
|
|
|
2007-06-14 01:13:04 +02:00
|
|
|
start = *tfsoff;
|
|
|
|
update_tfsoff(type, start, file);
|
2007-10-03 06:40:13 +02:00
|
|
|
print_start_tfs_comment(file, type, start);
|
2018-06-13 04:19:11 +02:00
|
|
|
print_file(file, 2, "0x%x,\t/* FC_USER_MARSHAL */\n", FC_USER_MARSHAL);
|
2007-06-14 01:15:41 +02:00
|
|
|
print_file(file, 2, "0x%x,\t/* Alignment= %d, Flags= %02x */\n",
|
2009-08-21 14:20:16 +02:00
|
|
|
flags | (ualign - 1), ualign - 1, flags);
|
2007-06-14 01:13:04 +02:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%hx),\t/* Function offset= %hu */\n", funoff, funoff);
|
2010-09-16 12:12:40 +02:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%hx),\t/* %u */\n", (unsigned short)size, size);
|
|
|
|
print_file(file, 2, "NdrFcShort(0x%hx),\t/* %u */\n", (unsigned short)usize, usize);
|
2007-06-14 01:13:04 +02:00
|
|
|
*tfsoff += 8;
|
|
|
|
reloff = absoff - *tfsoff;
|
2009-02-06 14:31:29 +01:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%hx),\t/* Offset= %hd (%u) */\n", reloff, reloff, absoff);
|
2007-06-14 01:13:04 +02:00
|
|
|
*tfsoff += 2;
|
2011-05-26 14:59:46 +02:00
|
|
|
return start;
|
2007-06-14 01:13:04 +02:00
|
|
|
}
|
|
|
|
|
2007-09-19 00:28:49 +02:00
|
|
|
static void write_member_type(FILE *file, const type_t *cont,
|
2009-02-23 14:48:34 +01:00
|
|
|
int cont_is_complex, const attr_list_t *attrs,
|
|
|
|
const type_t *type, unsigned int *corroff,
|
|
|
|
unsigned int *tfsoff)
|
2007-06-06 03:50:31 +02:00
|
|
|
{
|
2007-10-11 00:29:54 +02:00
|
|
|
if (is_embedded_complex(type) && !is_conformant_array(type))
|
2007-06-06 03:50:31 +02:00
|
|
|
{
|
2009-02-06 14:30:38 +01:00
|
|
|
unsigned int absoff;
|
2007-06-12 03:51:41 +02:00
|
|
|
short reloff;
|
|
|
|
|
2009-02-23 14:48:34 +01:00
|
|
|
if (type_get_type(type) == TYPE_UNION && is_attr(attrs, ATTR_SWITCHIS))
|
2007-06-12 03:51:41 +02:00
|
|
|
{
|
|
|
|
absoff = *corroff;
|
|
|
|
*corroff += 8;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
absoff = type->typestring_offset;
|
|
|
|
}
|
|
|
|
reloff = absoff - (*tfsoff + 2);
|
2007-06-06 03:50:31 +02:00
|
|
|
|
|
|
|
print_file(file, 2, "0x4c,\t/* FC_EMBEDDED_COMPLEX */\n");
|
2010-03-15 20:30:50 +01:00
|
|
|
/* padding is represented using FC_STRUCTPAD* types, so presumably
|
|
|
|
* this is left over in the format for historical purposes in MIDL
|
|
|
|
* or rpcrt4. */
|
|
|
|
print_file(file, 2, "0x0,\n");
|
2009-02-06 14:31:29 +01:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%hx),\t/* Offset= %hd (%u) */\n",
|
2007-06-06 03:50:31 +02:00
|
|
|
reloff, reloff, absoff);
|
|
|
|
*tfsoff += 4;
|
|
|
|
}
|
2007-10-11 00:29:54 +02:00
|
|
|
else if (is_ptr(type) || is_conformant_array(type))
|
2007-06-15 03:27:19 +02:00
|
|
|
{
|
2018-06-13 04:19:11 +02:00
|
|
|
unsigned char fc = cont_is_complex ? FC_POINTER : FC_LONG;
|
2007-09-19 00:28:49 +02:00
|
|
|
print_file(file, 2, "0x%x,\t/* %s */\n", fc, string_of_type(fc));
|
2007-06-15 03:27:19 +02:00
|
|
|
*tfsoff += 1;
|
|
|
|
}
|
2011-06-03 12:26:31 +02:00
|
|
|
else if (!write_base_type(file, type, tfsoff))
|
2009-02-23 14:48:34 +01:00
|
|
|
error("Unsupported member type %d\n", type_get_type(type));
|
2007-06-06 03:50:31 +02:00
|
|
|
}
|
|
|
|
|
2014-04-02 11:37:32 +02:00
|
|
|
static void write_array_element_type(FILE *file, const attr_list_t *attrs, const type_t *type,
|
2009-10-16 20:56:41 +02:00
|
|
|
int cont_is_complex, unsigned int *tfsoff)
|
|
|
|
{
|
|
|
|
type_t *elem = type_array_get_element(type);
|
|
|
|
|
|
|
|
if (!is_embedded_complex(elem) && is_ptr(elem))
|
|
|
|
{
|
|
|
|
type_t *ref = type_pointer_get_ref(elem);
|
|
|
|
|
|
|
|
if (processed(ref))
|
|
|
|
{
|
2011-06-14 12:24:00 +02:00
|
|
|
write_nonsimple_pointer(file, NULL, elem, TYPE_CONTEXT_CONTAINER,
|
|
|
|
ref->typestring_offset, tfsoff);
|
2009-10-16 20:56:41 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-04-02 11:37:32 +02:00
|
|
|
if (cont_is_complex && is_string_type(attrs, elem))
|
2011-09-16 21:08:54 +02:00
|
|
|
{
|
|
|
|
write_string_tfs(file, NULL, elem, TYPE_CONTEXT_CONTAINER, NULL, tfsoff);
|
|
|
|
return;
|
|
|
|
}
|
2009-10-16 20:56:41 +02:00
|
|
|
if (!is_string_type(NULL, elem) &&
|
|
|
|
(type_get_type(ref) == TYPE_BASIC || type_get_type(ref) == TYPE_ENUM))
|
|
|
|
{
|
2011-06-14 12:24:00 +02:00
|
|
|
*tfsoff += write_simple_pointer(file, NULL, elem, TYPE_CONTEXT_CONTAINER);
|
2009-10-16 20:56:41 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-12-19 21:55:46 +01:00
|
|
|
write_member_type(file, type, cont_is_complex, NULL, elem, NULL, tfsoff);
|
2009-10-16 20:56:41 +02:00
|
|
|
}
|
|
|
|
|
2007-06-06 03:50:31 +02:00
|
|
|
static void write_end(FILE *file, unsigned int *tfsoff)
|
|
|
|
{
|
|
|
|
if (*tfsoff % 2 == 0)
|
|
|
|
{
|
2018-06-13 04:19:11 +02:00
|
|
|
print_file(file, 2, "0x%x,\t/* FC_PAD */\n", FC_PAD);
|
2007-06-06 03:50:31 +02:00
|
|
|
*tfsoff += 1;
|
|
|
|
}
|
2018-06-13 04:19:11 +02:00
|
|
|
print_file(file, 2, "0x%x,\t/* FC_END */\n", FC_END);
|
2007-06-06 03:50:31 +02:00
|
|
|
*tfsoff += 1;
|
|
|
|
}
|
|
|
|
|
2007-06-12 03:51:41 +02:00
|
|
|
static void write_descriptors(FILE *file, type_t *type, unsigned int *tfsoff)
|
|
|
|
{
|
|
|
|
unsigned int offset = 0;
|
2008-12-29 13:05:27 +01:00
|
|
|
var_list_t *fs = type_struct_get_fields(type);
|
2007-06-12 03:51:41 +02:00
|
|
|
var_t *f;
|
|
|
|
|
|
|
|
if (fs) LIST_FOR_EACH_ENTRY(f, fs, var_t, entry)
|
|
|
|
{
|
|
|
|
type_t *ft = f->type;
|
2009-07-03 12:02:30 +02:00
|
|
|
unsigned int size = field_memsize( ft, &offset );
|
2009-02-23 14:48:34 +01:00
|
|
|
if (type_get_type(ft) == TYPE_UNION && is_attr(f->attrs, ATTR_SWITCHIS))
|
2007-06-12 03:51:41 +02:00
|
|
|
{
|
2009-07-03 11:44:10 +02:00
|
|
|
short reloff;
|
2007-06-12 03:51:41 +02:00
|
|
|
unsigned int absoff = ft->typestring_offset;
|
2009-07-03 11:44:10 +02:00
|
|
|
if (is_attr(ft->attrs, ATTR_SWITCHTYPE))
|
|
|
|
absoff += 8; /* we already have a corr descr, skip it */
|
|
|
|
reloff = absoff - (*tfsoff + 6);
|
2007-06-12 03:51:41 +02:00
|
|
|
print_file(file, 0, "/* %d */\n", *tfsoff);
|
2018-06-13 04:19:11 +02:00
|
|
|
print_file(file, 2, "0x%x,\t/* FC_NON_ENCAPSULATED_UNION */\n", FC_NON_ENCAPSULATED_UNION);
|
|
|
|
print_file(file, 2, "0x%x,\t/* FIXME: always FC_LONG */\n", FC_LONG);
|
2007-10-11 00:29:54 +02:00
|
|
|
write_conf_or_var_desc(file, current_structure, offset, ft,
|
2007-06-12 03:51:41 +02:00
|
|
|
get_attrp(f->attrs, ATTR_SWITCHIS));
|
2011-11-22 23:25:37 +01:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%hx),\t/* Offset= %hd (%u) */\n",
|
|
|
|
(unsigned short)reloff, reloff, absoff);
|
2007-06-12 03:51:41 +02:00
|
|
|
*tfsoff += 8;
|
|
|
|
}
|
2009-07-03 12:02:30 +02:00
|
|
|
offset += size;
|
2007-06-12 03:51:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-19 13:05:25 +02:00
|
|
|
static int write_pointer_description_offsets(
|
|
|
|
FILE *file, const attr_list_t *attrs, type_t *type,
|
2009-02-06 14:30:38 +01:00
|
|
|
unsigned int *offset_in_memory, unsigned int *offset_in_buffer,
|
2007-06-19 13:05:25 +02:00
|
|
|
unsigned int *typestring_offset)
|
|
|
|
{
|
|
|
|
int written = 0;
|
|
|
|
|
2009-10-16 14:59:01 +02:00
|
|
|
if ((is_ptr(type) && type_get_type(type_pointer_get_ref(type)) != TYPE_INTERFACE) ||
|
|
|
|
(is_array(type) && type_array_is_decl_as_ptr(type)))
|
2007-06-19 13:05:25 +02:00
|
|
|
{
|
|
|
|
if (offset_in_memory && offset_in_buffer)
|
|
|
|
{
|
2009-02-06 14:30:38 +01:00
|
|
|
unsigned int memsize;
|
2008-06-23 13:58:03 +02:00
|
|
|
|
2010-03-15 20:30:50 +01:00
|
|
|
/* pointer instance
|
|
|
|
*
|
|
|
|
* note that MSDN states that for pointer layouts in structures,
|
|
|
|
* this is a negative offset from the end of the structure, but
|
|
|
|
* this statement is incorrect. all offsets are positive */
|
2010-09-16 12:12:40 +02:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%hx),\t/* Memory offset = %d */\n", (unsigned short)*offset_in_memory, *offset_in_memory);
|
|
|
|
print_file(file, 2, "NdrFcShort(0x%hx),\t/* Buffer offset = %d */\n", (unsigned short)*offset_in_buffer, *offset_in_buffer);
|
2007-06-19 13:05:25 +02:00
|
|
|
|
2010-04-05 19:48:07 +02:00
|
|
|
memsize = type_memsize(type);
|
2008-06-23 13:58:03 +02:00
|
|
|
*offset_in_memory += memsize;
|
|
|
|
/* increment these separately as in the case of conformant (varying)
|
|
|
|
* structures these start at different values */
|
|
|
|
*offset_in_buffer += memsize;
|
2007-06-19 13:05:25 +02:00
|
|
|
}
|
|
|
|
*typestring_offset += 4;
|
|
|
|
|
2009-10-16 14:59:01 +02:00
|
|
|
if (is_ptr(type))
|
|
|
|
{
|
|
|
|
type_t *ref = type_pointer_get_ref(type);
|
|
|
|
|
|
|
|
if (is_string_type(attrs, type))
|
2011-06-14 12:24:00 +02:00
|
|
|
write_string_tfs(file, attrs, type, TYPE_CONTEXT_CONTAINER, NULL, typestring_offset);
|
2009-10-16 14:59:01 +02:00
|
|
|
else if (processed(ref))
|
2011-06-14 12:24:00 +02:00
|
|
|
write_nonsimple_pointer(file, attrs, type, TYPE_CONTEXT_CONTAINER,
|
|
|
|
ref->typestring_offset, typestring_offset);
|
2009-10-16 14:59:01 +02:00
|
|
|
else if (type_get_type(ref) == TYPE_BASIC || type_get_type(ref) == TYPE_ENUM)
|
2011-06-14 12:24:00 +02:00
|
|
|
*typestring_offset += write_simple_pointer(file, attrs, type, TYPE_CONTEXT_CONTAINER);
|
2009-10-16 14:59:01 +02:00
|
|
|
else
|
|
|
|
error("write_pointer_description_offsets: type format string unknown\n");
|
|
|
|
}
|
2007-06-19 13:05:25 +02:00
|
|
|
else
|
2009-10-16 14:59:01 +02:00
|
|
|
{
|
|
|
|
unsigned int offset = type->typestring_offset;
|
|
|
|
/* skip over the pointer that is written for strings, since a
|
|
|
|
* pointer has to be written in-place here */
|
|
|
|
if (is_string_type(attrs, type))
|
|
|
|
offset += 4;
|
2011-06-14 12:24:00 +02:00
|
|
|
write_nonsimple_pointer(file, attrs, type, TYPE_CONTEXT_CONTAINER, offset, typestring_offset);
|
2009-10-16 14:59:01 +02:00
|
|
|
}
|
2007-06-19 13:05:25 +02:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_array(type))
|
2006-02-03 18:51:17 +01:00
|
|
|
{
|
2007-06-19 13:05:25 +02:00
|
|
|
return write_pointer_description_offsets(
|
2009-01-06 00:34:52 +01:00
|
|
|
file, attrs, type_array_get_element(type), offset_in_memory,
|
|
|
|
offset_in_buffer, typestring_offset);
|
2007-06-19 13:05:25 +02:00
|
|
|
}
|
|
|
|
else if (is_non_complex_struct(type))
|
|
|
|
{
|
|
|
|
/* otherwise search for interesting fields to parse */
|
|
|
|
const var_t *v;
|
2008-12-29 13:05:27 +01:00
|
|
|
LIST_FOR_EACH_ENTRY( v, type_struct_get_fields(type), const var_t, entry )
|
2007-05-10 05:50:49 +02:00
|
|
|
{
|
2008-06-23 13:58:03 +02:00
|
|
|
if (offset_in_memory && offset_in_buffer)
|
|
|
|
{
|
2009-02-06 14:30:38 +01:00
|
|
|
unsigned int padding;
|
2010-04-05 19:48:07 +02:00
|
|
|
unsigned int align = 0;
|
|
|
|
type_memsize_and_alignment(v->type, &align);
|
2008-06-23 13:58:03 +02:00
|
|
|
padding = ROUNDING(*offset_in_memory, align);
|
|
|
|
*offset_in_memory += padding;
|
|
|
|
*offset_in_buffer += padding;
|
|
|
|
}
|
2007-06-19 13:05:25 +02:00
|
|
|
written += write_pointer_description_offsets(
|
|
|
|
file, v->attrs, v->type, offset_in_memory, offset_in_buffer,
|
|
|
|
typestring_offset);
|
2007-05-10 05:50:49 +02:00
|
|
|
}
|
2006-02-03 18:51:17 +01:00
|
|
|
}
|
2007-06-19 13:05:25 +02:00
|
|
|
else
|
|
|
|
{
|
2008-06-23 13:58:03 +02:00
|
|
|
if (offset_in_memory && offset_in_buffer)
|
|
|
|
{
|
2010-04-05 19:48:07 +02:00
|
|
|
unsigned int memsize = type_memsize(type);
|
2008-06-23 13:58:03 +02:00
|
|
|
*offset_in_memory += memsize;
|
|
|
|
/* increment these separately as in the case of conformant (varying)
|
|
|
|
* structures these start at different values */
|
|
|
|
*offset_in_buffer += memsize;
|
|
|
|
}
|
2007-06-19 13:05:25 +02:00
|
|
|
}
|
2006-02-03 18:51:17 +01:00
|
|
|
|
2007-06-19 13:05:25 +02:00
|
|
|
return written;
|
|
|
|
}
|
|
|
|
|
2009-10-16 15:00:27 +02:00
|
|
|
static int write_no_repeat_pointer_descriptions(
|
|
|
|
FILE *file, const attr_list_t *attrs, type_t *type,
|
|
|
|
unsigned int *offset_in_memory, unsigned int *offset_in_buffer,
|
|
|
|
unsigned int *typestring_offset)
|
|
|
|
{
|
|
|
|
int written = 0;
|
|
|
|
|
|
|
|
if (is_ptr(type) ||
|
|
|
|
(is_conformant_array(type) && type_array_is_decl_as_ptr(type)))
|
|
|
|
{
|
2018-06-13 04:19:11 +02:00
|
|
|
print_file(file, 2, "0x%02x, /* FC_NO_REPEAT */\n", FC_NO_REPEAT);
|
|
|
|
print_file(file, 2, "0x%02x, /* FC_PAD */\n", FC_PAD);
|
2009-10-16 15:00:27 +02:00
|
|
|
*typestring_offset += 2;
|
|
|
|
|
|
|
|
return write_pointer_description_offsets(file, attrs, type,
|
|
|
|
offset_in_memory, offset_in_buffer, typestring_offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_non_complex_struct(type))
|
|
|
|
{
|
|
|
|
const var_t *v;
|
|
|
|
LIST_FOR_EACH_ENTRY( v, type_struct_get_fields(type), const var_t, entry )
|
|
|
|
{
|
|
|
|
if (offset_in_memory && offset_in_buffer)
|
|
|
|
{
|
|
|
|
unsigned int padding;
|
2010-04-05 19:48:07 +02:00
|
|
|
unsigned int align = 0;
|
|
|
|
type_memsize_and_alignment(v->type, &align);
|
2009-10-16 15:00:27 +02:00
|
|
|
padding = ROUNDING(*offset_in_memory, align);
|
|
|
|
*offset_in_memory += padding;
|
|
|
|
*offset_in_buffer += padding;
|
|
|
|
}
|
|
|
|
written += write_no_repeat_pointer_descriptions(
|
|
|
|
file, v->attrs, v->type,
|
|
|
|
offset_in_memory, offset_in_buffer, typestring_offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-04-05 19:48:07 +02:00
|
|
|
unsigned int memsize = type_memsize(type);
|
2009-10-16 15:00:27 +02:00
|
|
|
*offset_in_memory += memsize;
|
|
|
|
/* increment these separately as in the case of conformant (varying)
|
|
|
|
* structures these start at different values */
|
|
|
|
*offset_in_buffer += memsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
return written;
|
|
|
|
}
|
|
|
|
|
2007-06-19 13:05:25 +02:00
|
|
|
/* Note: if file is NULL return value is number of pointers to write, else
|
|
|
|
* it is the number of type format characters written */
|
|
|
|
static int write_fixed_array_pointer_descriptions(
|
|
|
|
FILE *file, const attr_list_t *attrs, type_t *type,
|
2009-02-06 14:30:38 +01:00
|
|
|
unsigned int *offset_in_memory, unsigned int *offset_in_buffer,
|
2007-06-19 13:05:25 +02:00
|
|
|
unsigned int *typestring_offset)
|
|
|
|
{
|
|
|
|
int pointer_count = 0;
|
|
|
|
|
2009-02-23 14:48:34 +01:00
|
|
|
if (type_get_type(type) == TYPE_ARRAY &&
|
|
|
|
!type_array_has_conformance(type) && !type_array_has_variance(type))
|
2007-06-19 13:05:25 +02:00
|
|
|
{
|
|
|
|
unsigned int temp = 0;
|
|
|
|
/* unfortunately, this needs to be done in two passes to avoid
|
|
|
|
* writing out redundant FC_FIXED_REPEAT descriptions */
|
|
|
|
pointer_count = write_pointer_description_offsets(
|
2009-01-06 00:34:52 +01:00
|
|
|
NULL, attrs, type_array_get_element(type), NULL, NULL, &temp);
|
2007-06-19 13:05:25 +02:00
|
|
|
if (pointer_count > 0)
|
|
|
|
{
|
|
|
|
unsigned int increment_size;
|
2009-02-06 14:30:38 +01:00
|
|
|
unsigned int offset_of_array_pointer_mem = 0;
|
|
|
|
unsigned int offset_of_array_pointer_buf = 0;
|
2007-06-19 13:05:25 +02:00
|
|
|
|
2010-04-05 19:48:07 +02:00
|
|
|
increment_size = type_memsize(type_array_get_element(type));
|
2007-06-19 13:05:25 +02:00
|
|
|
|
2018-06-13 04:19:11 +02:00
|
|
|
print_file(file, 2, "0x%02x, /* FC_FIXED_REPEAT */\n", FC_FIXED_REPEAT);
|
|
|
|
print_file(file, 2, "0x%02x, /* FC_PAD */\n", FC_PAD);
|
2010-09-16 12:12:40 +02:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%hx),\t/* Iterations = %d */\n", (unsigned short)type_array_get_dim(type), type_array_get_dim(type));
|
|
|
|
print_file(file, 2, "NdrFcShort(0x%hx),\t/* Increment = %d */\n", (unsigned short)increment_size, increment_size);
|
|
|
|
print_file(file, 2, "NdrFcShort(0x%hx),\t/* Offset to array = %d */\n", (unsigned short)*offset_in_memory, *offset_in_memory);
|
|
|
|
print_file(file, 2, "NdrFcShort(0x%hx),\t/* Number of pointers = %d */\n", (unsigned short)pointer_count, pointer_count);
|
2007-06-19 13:05:25 +02:00
|
|
|
*typestring_offset += 10;
|
|
|
|
|
|
|
|
pointer_count = write_pointer_description_offsets(
|
|
|
|
file, attrs, type, &offset_of_array_pointer_mem,
|
|
|
|
&offset_of_array_pointer_buf, typestring_offset);
|
|
|
|
}
|
|
|
|
}
|
2009-02-23 14:48:34 +01:00
|
|
|
else if (type_get_type(type) == TYPE_STRUCT)
|
2007-06-19 13:05:25 +02:00
|
|
|
{
|
|
|
|
const var_t *v;
|
2008-12-29 13:05:27 +01:00
|
|
|
LIST_FOR_EACH_ENTRY( v, type_struct_get_fields(type), const var_t, entry )
|
2007-06-19 13:05:25 +02:00
|
|
|
{
|
2008-06-23 13:58:03 +02:00
|
|
|
if (offset_in_memory && offset_in_buffer)
|
|
|
|
{
|
2009-02-06 14:30:38 +01:00
|
|
|
unsigned int padding;
|
2010-04-05 19:48:07 +02:00
|
|
|
unsigned int align = 0;
|
|
|
|
type_memsize_and_alignment(v->type, &align);
|
2008-06-23 13:58:03 +02:00
|
|
|
padding = ROUNDING(*offset_in_memory, align);
|
|
|
|
*offset_in_memory += padding;
|
|
|
|
*offset_in_buffer += padding;
|
|
|
|
}
|
2007-06-19 13:05:25 +02:00
|
|
|
pointer_count += write_fixed_array_pointer_descriptions(
|
|
|
|
file, v->attrs, v->type, offset_in_memory, offset_in_buffer,
|
|
|
|
typestring_offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-06-23 13:58:03 +02:00
|
|
|
if (offset_in_memory && offset_in_buffer)
|
|
|
|
{
|
2009-02-06 14:30:38 +01:00
|
|
|
unsigned int memsize;
|
2010-04-05 19:48:07 +02:00
|
|
|
memsize = type_memsize(type);
|
2008-06-23 13:58:03 +02:00
|
|
|
*offset_in_memory += memsize;
|
|
|
|
/* increment these separately as in the case of conformant (varying)
|
|
|
|
* structures these start at different values */
|
|
|
|
*offset_in_buffer += memsize;
|
|
|
|
}
|
2007-06-19 13:05:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return pointer_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Note: if file is NULL return value is number of pointers to write, else
|
|
|
|
* it is the number of type format characters written */
|
|
|
|
static int write_conformant_array_pointer_descriptions(
|
|
|
|
FILE *file, const attr_list_t *attrs, type_t *type,
|
2009-02-06 14:30:38 +01:00
|
|
|
unsigned int offset_in_memory, unsigned int *typestring_offset)
|
2007-06-19 13:05:25 +02:00
|
|
|
{
|
|
|
|
int pointer_count = 0;
|
|
|
|
|
2009-01-06 00:33:36 +01:00
|
|
|
if (is_conformant_array(type) && !type_array_has_variance(type))
|
2007-06-19 13:05:25 +02:00
|
|
|
{
|
|
|
|
unsigned int temp = 0;
|
|
|
|
/* unfortunately, this needs to be done in two passes to avoid
|
|
|
|
* writing out redundant FC_VARIABLE_REPEAT descriptions */
|
|
|
|
pointer_count = write_pointer_description_offsets(
|
2009-01-06 00:34:52 +01:00
|
|
|
NULL, attrs, type_array_get_element(type), NULL, NULL, &temp);
|
2007-06-19 13:05:25 +02:00
|
|
|
if (pointer_count > 0)
|
|
|
|
{
|
|
|
|
unsigned int increment_size;
|
2009-02-06 14:30:38 +01:00
|
|
|
unsigned int offset_of_array_pointer_mem = offset_in_memory;
|
|
|
|
unsigned int offset_of_array_pointer_buf = offset_in_memory;
|
2007-06-19 13:05:25 +02:00
|
|
|
|
2010-04-05 19:48:07 +02:00
|
|
|
increment_size = type_memsize(type_array_get_element(type));
|
2007-06-19 13:05:25 +02:00
|
|
|
|
|
|
|
if (increment_size > USHRT_MAX)
|
|
|
|
error("array size of %u bytes is too large\n", increment_size);
|
|
|
|
|
2018-06-13 04:19:11 +02:00
|
|
|
print_file(file, 2, "0x%02x, /* FC_VARIABLE_REPEAT */\n", FC_VARIABLE_REPEAT);
|
|
|
|
print_file(file, 2, "0x%02x, /* FC_FIXED_OFFSET */\n", FC_FIXED_OFFSET);
|
2010-09-16 12:12:40 +02:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%hx),\t/* Increment = %d */\n", (unsigned short)increment_size, increment_size);
|
|
|
|
print_file(file, 2, "NdrFcShort(0x%hx),\t/* Offset to array = %d */\n", (unsigned short)offset_in_memory, offset_in_memory);
|
|
|
|
print_file(file, 2, "NdrFcShort(0x%hx),\t/* Number of pointers = %d */\n", (unsigned short)pointer_count, pointer_count);
|
2007-06-19 13:05:25 +02:00
|
|
|
*typestring_offset += 8;
|
|
|
|
|
|
|
|
pointer_count = write_pointer_description_offsets(
|
2009-01-06 00:34:52 +01:00
|
|
|
file, attrs, type_array_get_element(type),
|
|
|
|
&offset_of_array_pointer_mem, &offset_of_array_pointer_buf,
|
|
|
|
typestring_offset);
|
2007-06-19 13:05:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pointer_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Note: if file is NULL return value is number of pointers to write, else
|
|
|
|
* it is the number of type format characters written */
|
|
|
|
static int write_varying_array_pointer_descriptions(
|
|
|
|
FILE *file, const attr_list_t *attrs, type_t *type,
|
2009-02-06 14:30:38 +01:00
|
|
|
unsigned int *offset_in_memory, unsigned int *offset_in_buffer,
|
2007-06-19 13:05:25 +02:00
|
|
|
unsigned int *typestring_offset)
|
|
|
|
{
|
|
|
|
int pointer_count = 0;
|
|
|
|
|
2009-01-06 00:33:36 +01:00
|
|
|
if (is_array(type) && type_array_has_variance(type))
|
2007-06-19 13:05:25 +02:00
|
|
|
{
|
|
|
|
unsigned int temp = 0;
|
|
|
|
/* unfortunately, this needs to be done in two passes to avoid
|
|
|
|
* writing out redundant FC_VARIABLE_REPEAT descriptions */
|
|
|
|
pointer_count = write_pointer_description_offsets(
|
2009-01-06 00:34:52 +01:00
|
|
|
NULL, attrs, type_array_get_element(type), NULL, NULL, &temp);
|
2007-06-19 13:05:25 +02:00
|
|
|
if (pointer_count > 0)
|
|
|
|
{
|
|
|
|
unsigned int increment_size;
|
|
|
|
|
2010-04-05 19:48:07 +02:00
|
|
|
increment_size = type_memsize(type_array_get_element(type));
|
2007-06-19 13:05:25 +02:00
|
|
|
|
|
|
|
if (increment_size > USHRT_MAX)
|
|
|
|
error("array size of %u bytes is too large\n", increment_size);
|
|
|
|
|
2018-06-13 04:19:11 +02:00
|
|
|
print_file(file, 2, "0x%02x, /* FC_VARIABLE_REPEAT */\n", FC_VARIABLE_REPEAT);
|
|
|
|
print_file(file, 2, "0x%02x, /* FC_VARIABLE_OFFSET */\n", FC_VARIABLE_OFFSET);
|
2010-09-16 12:12:40 +02:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%hx),\t/* Increment = %d */\n", (unsigned short)increment_size, increment_size);
|
|
|
|
print_file(file, 2, "NdrFcShort(0x%hx),\t/* Offset to array = %d */\n", (unsigned short)*offset_in_memory, *offset_in_memory);
|
|
|
|
print_file(file, 2, "NdrFcShort(0x%hx),\t/* Number of pointers = %d */\n", (unsigned short)pointer_count, pointer_count);
|
2007-06-19 13:05:25 +02:00
|
|
|
*typestring_offset += 8;
|
|
|
|
|
|
|
|
pointer_count = write_pointer_description_offsets(
|
2009-10-16 14:59:01 +02:00
|
|
|
file, attrs, type_array_get_element(type), offset_in_memory,
|
2008-06-23 13:58:03 +02:00
|
|
|
offset_in_buffer, typestring_offset);
|
2007-06-19 13:05:25 +02:00
|
|
|
}
|
|
|
|
}
|
2009-02-23 14:48:34 +01:00
|
|
|
else if (type_get_type(type) == TYPE_STRUCT)
|
2007-06-19 13:05:25 +02:00
|
|
|
{
|
|
|
|
const var_t *v;
|
2008-12-29 13:05:27 +01:00
|
|
|
LIST_FOR_EACH_ENTRY( v, type_struct_get_fields(type), const var_t, entry )
|
2007-06-19 13:05:25 +02:00
|
|
|
{
|
2008-06-23 13:58:03 +02:00
|
|
|
if (offset_in_memory && offset_in_buffer)
|
|
|
|
{
|
2010-04-05 19:48:07 +02:00
|
|
|
unsigned int align = 0, padding;
|
2008-07-02 01:00:43 +02:00
|
|
|
|
2009-01-06 00:33:36 +01:00
|
|
|
if (is_array(v->type) && type_array_has_variance(v->type))
|
2008-07-02 01:00:43 +02:00
|
|
|
{
|
|
|
|
*offset_in_buffer = ROUND_SIZE(*offset_in_buffer, 4);
|
|
|
|
/* skip over variance and offset in buffer */
|
|
|
|
*offset_in_buffer += 8;
|
|
|
|
}
|
|
|
|
|
2010-04-05 19:48:07 +02:00
|
|
|
type_memsize_and_alignment(v->type, &align);
|
2008-06-23 13:58:03 +02:00
|
|
|
padding = ROUNDING(*offset_in_memory, align);
|
|
|
|
*offset_in_memory += padding;
|
|
|
|
*offset_in_buffer += padding;
|
|
|
|
}
|
2007-06-19 13:05:25 +02:00
|
|
|
pointer_count += write_varying_array_pointer_descriptions(
|
|
|
|
file, v->attrs, v->type, offset_in_memory, offset_in_buffer,
|
|
|
|
typestring_offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-06-23 13:58:03 +02:00
|
|
|
if (offset_in_memory && offset_in_buffer)
|
|
|
|
{
|
2010-04-05 19:48:07 +02:00
|
|
|
unsigned int memsize = type_memsize(type);
|
2008-06-23 13:58:03 +02:00
|
|
|
*offset_in_memory += memsize;
|
|
|
|
/* increment these separately as in the case of conformant (varying)
|
|
|
|
* structures these start at different values */
|
|
|
|
*offset_in_buffer += memsize;
|
|
|
|
}
|
2007-06-19 13:05:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return pointer_count;
|
|
|
|
}
|
|
|
|
|
2014-04-02 11:37:27 +02:00
|
|
|
static void write_pointer_description(FILE *file, const attr_list_t *attrs, type_t *type,
|
2007-06-19 13:05:25 +02:00
|
|
|
unsigned int *typestring_offset)
|
|
|
|
{
|
2009-02-06 14:30:38 +01:00
|
|
|
unsigned int offset_in_buffer;
|
|
|
|
unsigned int offset_in_memory;
|
2007-06-19 13:05:25 +02:00
|
|
|
|
|
|
|
/* pass 1: search for single instance of a pointer (i.e. don't descend
|
|
|
|
* into arrays) */
|
2007-10-11 00:29:54 +02:00
|
|
|
if (!is_array(type))
|
|
|
|
{
|
|
|
|
offset_in_memory = 0;
|
2008-07-02 01:00:43 +02:00
|
|
|
offset_in_buffer = 0;
|
2007-10-11 00:29:54 +02:00
|
|
|
write_no_repeat_pointer_descriptions(
|
2009-03-05 09:23:54 +01:00
|
|
|
file, NULL, type,
|
2007-10-11 00:29:54 +02:00
|
|
|
&offset_in_memory, &offset_in_buffer, typestring_offset);
|
|
|
|
}
|
2007-06-19 13:05:25 +02:00
|
|
|
|
|
|
|
/* pass 2: search for pointers in fixed arrays */
|
|
|
|
offset_in_memory = 0;
|
2008-07-02 01:00:43 +02:00
|
|
|
offset_in_buffer = 0;
|
2007-06-19 13:05:25 +02:00
|
|
|
write_fixed_array_pointer_descriptions(
|
|
|
|
file, NULL, type,
|
|
|
|
&offset_in_memory, &offset_in_buffer, typestring_offset);
|
|
|
|
|
|
|
|
/* pass 3: search for pointers in conformant only arrays (but don't descend
|
|
|
|
* into conformant varying or varying arrays) */
|
2009-03-05 09:21:35 +01:00
|
|
|
if (is_conformant_array(type) &&
|
|
|
|
(type_array_is_decl_as_ptr(type) || !current_structure))
|
2007-10-11 00:29:54 +02:00
|
|
|
write_conformant_array_pointer_descriptions(
|
2014-04-02 11:37:27 +02:00
|
|
|
file, attrs, type, 0, typestring_offset);
|
2009-02-23 14:48:34 +01:00
|
|
|
else if (type_get_type(type) == TYPE_STRUCT &&
|
2018-06-13 04:19:11 +02:00
|
|
|
get_struct_fc(type) == FC_CPSTRUCT)
|
2007-10-11 00:29:54 +02:00
|
|
|
{
|
|
|
|
type_t *carray = find_array_or_string_in_struct(type)->type;
|
2010-04-05 19:48:07 +02:00
|
|
|
write_conformant_array_pointer_descriptions( file, NULL, carray,
|
|
|
|
type_memsize(type), typestring_offset);
|
2007-10-11 00:29:54 +02:00
|
|
|
}
|
2007-06-19 13:05:25 +02:00
|
|
|
|
2008-06-23 13:58:03 +02:00
|
|
|
/* pass 4: search for pointers in varying arrays */
|
2007-06-19 13:05:25 +02:00
|
|
|
offset_in_memory = 0;
|
2008-07-02 01:00:43 +02:00
|
|
|
offset_in_buffer = 0;
|
2007-06-19 13:05:25 +02:00
|
|
|
write_varying_array_pointer_descriptions(
|
|
|
|
file, NULL, type,
|
|
|
|
&offset_in_memory, &offset_in_buffer, typestring_offset);
|
2006-02-03 18:51:17 +01:00
|
|
|
}
|
|
|
|
|
2009-02-06 14:30:38 +01:00
|
|
|
static unsigned int write_string_tfs(FILE *file, const attr_list_t *attrs,
|
2011-06-14 12:24:00 +02:00
|
|
|
type_t *type, enum type_context context,
|
2009-02-06 14:30:38 +01:00
|
|
|
const char *name, unsigned int *typestring_offset)
|
2006-01-24 11:06:32 +01:00
|
|
|
{
|
2009-02-06 14:30:38 +01:00
|
|
|
unsigned int start_offset;
|
2006-08-09 23:20:35 +02:00
|
|
|
unsigned char rtype;
|
2009-02-23 14:48:34 +01:00
|
|
|
type_t *elem_type;
|
2011-05-26 14:59:46 +02:00
|
|
|
int is_processed = processed(type);
|
2006-08-09 23:20:35 +02:00
|
|
|
|
2009-03-08 00:23:54 +01:00
|
|
|
start_offset = *typestring_offset;
|
|
|
|
|
2008-03-27 15:05:45 +01:00
|
|
|
if (is_declptr(type))
|
2006-09-08 01:57:16 +02:00
|
|
|
{
|
2018-06-13 04:19:11 +02:00
|
|
|
unsigned char flag = is_conformant_array(type) ? 0 : FC_SIMPLE_POINTER;
|
2011-06-14 12:24:00 +02:00
|
|
|
int pointer_type = get_pointer_fc_context(type, attrs, context);
|
2007-09-05 00:46:30 +02:00
|
|
|
if (!pointer_type)
|
2018-06-13 04:19:11 +02:00
|
|
|
pointer_type = FC_RP;
|
2008-03-27 15:05:45 +01:00
|
|
|
print_start_tfs_comment(file, type, *typestring_offset);
|
2007-09-05 00:46:30 +02:00
|
|
|
print_file(file, 2,"0x%x, 0x%x,\t/* %s%s */\n",
|
|
|
|
pointer_type, flag, string_of_type(pointer_type),
|
|
|
|
flag ? " [simple_pointer]" : "");
|
|
|
|
*typestring_offset += 2;
|
|
|
|
if (!flag)
|
|
|
|
{
|
|
|
|
print_file(file, 2, "NdrFcShort(0x2),\n");
|
|
|
|
*typestring_offset += 2;
|
|
|
|
}
|
2011-05-26 14:59:46 +02:00
|
|
|
is_processed = FALSE;
|
2006-09-08 01:57:16 +02:00
|
|
|
}
|
2007-12-13 17:12:13 +01:00
|
|
|
|
2009-01-06 00:34:58 +01:00
|
|
|
if (is_array(type))
|
2009-02-23 14:48:34 +01:00
|
|
|
elem_type = type_array_get_element(type);
|
2009-01-06 00:34:58 +01:00
|
|
|
else
|
2009-02-23 14:48:34 +01:00
|
|
|
elem_type = type_pointer_get_ref(type);
|
2006-03-31 13:45:16 +02:00
|
|
|
|
2014-04-02 11:37:47 +02:00
|
|
|
if (type_get_type(elem_type) == TYPE_POINTER && is_array(type))
|
|
|
|
return write_array_tfs(file, attrs, type, name, typestring_offset);
|
|
|
|
|
2009-02-23 14:48:34 +01:00
|
|
|
if (type_get_type(elem_type) != TYPE_BASIC)
|
|
|
|
{
|
|
|
|
error("write_string_tfs: Unimplemented for non-basic type %s\n", name);
|
|
|
|
return start_offset;
|
|
|
|
}
|
|
|
|
|
2009-03-08 00:24:00 +01:00
|
|
|
rtype = get_basic_fc(elem_type);
|
2018-06-13 04:19:11 +02:00
|
|
|
if ((rtype != FC_BYTE) && (rtype != FC_CHAR) && (rtype != FC_WCHAR))
|
2006-01-24 11:07:39 +01:00
|
|
|
{
|
2006-08-09 23:20:35 +02:00
|
|
|
error("write_string_tfs: Unimplemented for type 0x%x of name: %s\n", rtype, name);
|
2006-01-31 18:07:20 +01:00
|
|
|
return start_offset;
|
2006-01-24 11:07:39 +01:00
|
|
|
}
|
|
|
|
|
2009-03-05 09:21:35 +01:00
|
|
|
if (type_get_type(type) == TYPE_ARRAY && !type_array_has_conformance(type))
|
2006-01-24 11:07:39 +01:00
|
|
|
{
|
2009-02-06 14:30:38 +01:00
|
|
|
unsigned int dim = type_array_get_dim(type);
|
2009-01-06 00:33:36 +01:00
|
|
|
|
2011-05-26 14:59:46 +02:00
|
|
|
if (is_processed) return start_offset;
|
|
|
|
|
2007-01-22 14:31:40 +01:00
|
|
|
/* FIXME: multi-dimensional array */
|
2009-02-06 14:30:38 +01:00
|
|
|
if (0xffffu < dim)
|
|
|
|
error("array size for parameter %s exceeds %u bytes by %u bytes\n",
|
2009-01-06 00:33:36 +01:00
|
|
|
name, 0xffffu, dim - 0xffffu);
|
2006-01-24 11:07:39 +01:00
|
|
|
|
2018-06-13 04:19:11 +02:00
|
|
|
if (rtype == FC_WCHAR)
|
2006-01-31 18:07:20 +01:00
|
|
|
WRITE_FCTYPE(file, FC_WSTRING, *typestring_offset);
|
2009-02-23 14:48:34 +01:00
|
|
|
else
|
|
|
|
WRITE_FCTYPE(file, FC_CSTRING, *typestring_offset);
|
2018-06-13 04:19:11 +02:00
|
|
|
print_file(file, 2, "0x%x,\t/* FC_PAD */\n", FC_PAD);
|
2006-01-31 18:07:20 +01:00
|
|
|
*typestring_offset += 2;
|
2006-01-24 11:07:39 +01:00
|
|
|
|
2010-09-16 12:12:40 +02:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%hx),\t/* %d */\n", (unsigned short)dim, dim);
|
2006-01-31 18:07:20 +01:00
|
|
|
*typestring_offset += 2;
|
2006-01-24 11:07:39 +01:00
|
|
|
|
2011-05-26 14:59:46 +02:00
|
|
|
update_tfsoff(type, start_offset, file);
|
2006-01-31 18:07:20 +01:00
|
|
|
return start_offset;
|
2006-01-24 11:07:39 +01:00
|
|
|
}
|
2009-01-06 00:33:36 +01:00
|
|
|
else if (is_conformant_array(type))
|
2006-01-24 11:07:39 +01:00
|
|
|
{
|
2018-06-13 04:19:11 +02:00
|
|
|
if (rtype == FC_WCHAR)
|
2006-01-31 18:07:20 +01:00
|
|
|
WRITE_FCTYPE(file, FC_C_WSTRING, *typestring_offset);
|
2009-02-23 14:48:34 +01:00
|
|
|
else
|
|
|
|
WRITE_FCTYPE(file, FC_C_CSTRING, *typestring_offset);
|
2018-06-13 04:19:11 +02:00
|
|
|
print_file(file, 2, "0x%x,\t/* FC_STRING_SIZED */\n", FC_STRING_SIZED);
|
2006-01-31 18:07:20 +01:00
|
|
|
*typestring_offset += 2;
|
2006-01-24 11:07:39 +01:00
|
|
|
|
2007-06-12 03:51:41 +02:00
|
|
|
*typestring_offset += write_conf_or_var_desc(
|
2007-09-13 01:10:01 +02:00
|
|
|
file, current_structure,
|
2009-03-05 09:21:35 +01:00
|
|
|
(!type_array_is_decl_as_ptr(type) && current_structure
|
2010-04-05 19:48:07 +02:00
|
|
|
? type_memsize(current_structure)
|
2007-06-12 03:51:41 +02:00
|
|
|
: 0),
|
2009-01-06 00:33:36 +01:00
|
|
|
type, type_array_get_conformance(type));
|
2006-01-24 11:08:20 +01:00
|
|
|
|
2011-05-26 14:59:46 +02:00
|
|
|
update_tfsoff(type, start_offset, file);
|
2006-01-31 18:07:20 +01:00
|
|
|
return start_offset;
|
2006-01-24 11:07:39 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-05-26 14:59:46 +02:00
|
|
|
if (is_processed) return start_offset;
|
|
|
|
|
2018-06-13 04:19:11 +02:00
|
|
|
if (rtype == FC_WCHAR)
|
2006-01-31 18:07:20 +01:00
|
|
|
WRITE_FCTYPE(file, FC_C_WSTRING, *typestring_offset);
|
2007-09-05 00:46:30 +02:00
|
|
|
else
|
|
|
|
WRITE_FCTYPE(file, FC_C_CSTRING, *typestring_offset);
|
2018-06-13 04:19:11 +02:00
|
|
|
print_file(file, 2, "0x%x,\t/* FC_PAD */\n", FC_PAD);
|
2006-01-31 18:07:20 +01:00
|
|
|
*typestring_offset += 2;
|
2006-01-24 11:07:39 +01:00
|
|
|
|
2011-05-26 14:59:46 +02:00
|
|
|
update_tfsoff(type, start_offset, file);
|
2006-01-31 18:07:20 +01:00
|
|
|
return start_offset;
|
2006-01-24 11:07:39 +01:00
|
|
|
}
|
2006-01-24 11:06:32 +01:00
|
|
|
}
|
|
|
|
|
2009-02-06 14:30:38 +01:00
|
|
|
static unsigned int write_array_tfs(FILE *file, const attr_list_t *attrs, type_t *type,
|
|
|
|
const char *name, unsigned int *typestring_offset)
|
2006-01-24 11:06:32 +01:00
|
|
|
{
|
2009-01-06 00:33:36 +01:00
|
|
|
const expr_t *length_is = type_array_get_variance(type);
|
|
|
|
const expr_t *size_is = type_array_get_conformance(type);
|
2010-04-05 20:05:05 +02:00
|
|
|
unsigned int align;
|
2009-02-06 14:30:38 +01:00
|
|
|
unsigned int size;
|
|
|
|
unsigned int start_offset;
|
2009-02-23 14:48:34 +01:00
|
|
|
unsigned char fc;
|
2007-09-19 00:29:59 +02:00
|
|
|
unsigned int baseoff
|
2009-03-05 09:21:35 +01:00
|
|
|
= !type_array_is_decl_as_ptr(type) && current_structure
|
2010-04-05 19:48:07 +02:00
|
|
|
? type_memsize(current_structure)
|
2007-09-19 00:29:59 +02:00
|
|
|
: 0;
|
|
|
|
|
2014-04-02 11:37:41 +02:00
|
|
|
if (!is_string_type(attrs, type_array_get_element(type)))
|
|
|
|
write_embedded_types(file, attrs, type_array_get_element(type), name, FALSE, typestring_offset);
|
2006-01-24 11:07:13 +01:00
|
|
|
|
2010-04-05 20:05:05 +02:00
|
|
|
size = type_memsize(is_conformant_array(type) ? type_array_get_element(type) : type);
|
|
|
|
align = type_buffer_alignment(is_conformant_array(type) ? type_array_get_element(type) : type);
|
2009-02-23 14:48:34 +01:00
|
|
|
fc = get_array_fc(type);
|
2006-02-03 18:51:17 +01:00
|
|
|
|
2007-06-06 03:50:31 +02:00
|
|
|
start_offset = *typestring_offset;
|
|
|
|
update_tfsoff(type, start_offset, file);
|
2007-10-03 06:40:13 +02:00
|
|
|
print_start_tfs_comment(file, type, start_offset);
|
2009-02-23 14:48:34 +01:00
|
|
|
print_file(file, 2, "0x%02x,\t/* %s */\n", fc, string_of_type(fc));
|
2007-06-06 03:50:31 +02:00
|
|
|
print_file(file, 2, "0x%x,\t/* %d */\n", align - 1, align - 1);
|
|
|
|
*typestring_offset += 2;
|
2006-02-03 18:51:17 +01:00
|
|
|
|
2007-06-12 03:51:41 +02:00
|
|
|
align = 0;
|
2018-06-13 04:19:11 +02:00
|
|
|
if (fc != FC_BOGUS_ARRAY)
|
2007-06-06 03:50:31 +02:00
|
|
|
{
|
2018-06-13 04:19:11 +02:00
|
|
|
if (fc == FC_LGFARRAY || fc == FC_LGVARRAY)
|
2006-01-24 11:07:13 +01:00
|
|
|
{
|
2009-02-06 14:31:29 +01:00
|
|
|
print_file(file, 2, "NdrFcLong(0x%x),\t/* %u */\n", size, size);
|
2007-06-06 03:50:31 +02:00
|
|
|
*typestring_offset += 4;
|
2006-01-24 11:07:13 +01:00
|
|
|
}
|
2007-06-06 03:50:31 +02:00
|
|
|
else
|
2006-01-24 11:07:13 +01:00
|
|
|
{
|
2010-09-16 12:12:40 +02:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%hx),\t/* %u */\n", (unsigned short)size, size);
|
2006-01-31 18:07:20 +01:00
|
|
|
*typestring_offset += 2;
|
2007-06-06 03:50:31 +02:00
|
|
|
}
|
2006-01-24 11:07:13 +01:00
|
|
|
|
2007-06-06 03:50:31 +02:00
|
|
|
if (is_conformant_array(type))
|
|
|
|
*typestring_offset
|
2007-09-13 01:10:01 +02:00
|
|
|
+= write_conf_or_var_desc(file, current_structure, baseoff,
|
2007-10-11 00:29:54 +02:00
|
|
|
type, size_is);
|
2006-01-24 11:07:13 +01:00
|
|
|
|
2018-06-13 04:19:11 +02:00
|
|
|
if (fc == FC_SMVARRAY || fc == FC_LGVARRAY)
|
2006-01-24 11:07:13 +01:00
|
|
|
{
|
2010-04-05 19:48:07 +02:00
|
|
|
unsigned int elsize = type_memsize(type_array_get_element(type));
|
2009-02-06 14:30:38 +01:00
|
|
|
unsigned int dim = type_array_get_dim(type);
|
2006-01-24 11:08:20 +01:00
|
|
|
|
2018-06-13 04:19:11 +02:00
|
|
|
if (fc == FC_LGVARRAY)
|
2006-02-03 18:51:17 +01:00
|
|
|
{
|
2009-02-06 14:31:29 +01:00
|
|
|
print_file(file, 2, "NdrFcLong(0x%x),\t/* %u */\n", dim, dim);
|
2007-06-06 03:50:31 +02:00
|
|
|
*typestring_offset += 4;
|
2006-02-03 18:51:17 +01:00
|
|
|
}
|
2007-06-06 03:50:31 +02:00
|
|
|
else
|
2007-02-06 15:55:29 +01:00
|
|
|
{
|
2010-09-16 12:12:40 +02:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%hx),\t/* %u */\n", (unsigned short)dim, dim);
|
2007-06-06 03:50:31 +02:00
|
|
|
*typestring_offset += 2;
|
2007-02-06 15:55:29 +01:00
|
|
|
}
|
2006-01-24 11:07:13 +01:00
|
|
|
|
2010-09-16 12:12:40 +02:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%hx),\t/* %u */\n", (unsigned short)elsize, elsize);
|
2007-06-06 03:50:31 +02:00
|
|
|
*typestring_offset += 2;
|
2006-01-24 11:07:13 +01:00
|
|
|
}
|
|
|
|
|
2007-06-06 03:50:31 +02:00
|
|
|
if (length_is)
|
|
|
|
*typestring_offset
|
2007-09-13 01:10:01 +02:00
|
|
|
+= write_conf_or_var_desc(file, current_structure, baseoff,
|
2007-10-11 00:29:54 +02:00
|
|
|
type, length_is);
|
2006-01-24 11:08:20 +01:00
|
|
|
|
2010-03-15 20:29:53 +01:00
|
|
|
if (type_has_pointers(type_array_get_element(type)) &&
|
|
|
|
(type_array_is_decl_as_ptr(type) || !current_structure))
|
2007-06-06 03:50:31 +02:00
|
|
|
{
|
2018-06-13 04:19:11 +02:00
|
|
|
print_file(file, 2, "0x%x,\t/* FC_PP */\n", FC_PP);
|
|
|
|
print_file(file, 2, "0x%x,\t/* FC_PAD */\n", FC_PAD);
|
2007-06-06 03:50:31 +02:00
|
|
|
*typestring_offset += 2;
|
2014-04-02 11:37:27 +02:00
|
|
|
write_pointer_description(file, is_string_type(attrs, type) ? attrs : NULL, type, typestring_offset);
|
2018-06-13 04:19:11 +02:00
|
|
|
print_file(file, 2, "0x%x,\t/* FC_END */\n", FC_END);
|
2007-02-06 15:55:29 +01:00
|
|
|
*typestring_offset += 1;
|
2006-01-24 11:07:13 +01:00
|
|
|
}
|
2007-06-06 03:50:31 +02:00
|
|
|
|
2014-04-02 11:37:32 +02:00
|
|
|
write_array_element_type(file, is_string_type(attrs, type) ? attrs : NULL, type, FALSE, typestring_offset);
|
2007-06-06 03:50:31 +02:00
|
|
|
write_end(file, typestring_offset);
|
2006-01-24 11:07:13 +01:00
|
|
|
}
|
2007-06-06 03:50:31 +02:00
|
|
|
else
|
2007-09-19 00:29:59 +02:00
|
|
|
{
|
2009-01-06 00:33:36 +01:00
|
|
|
unsigned int dim = size_is ? 0 : type_array_get_dim(type);
|
2010-09-16 12:12:40 +02:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%hx),\t/* %u */\n", (unsigned short)dim, dim);
|
2007-09-19 00:29:59 +02:00
|
|
|
*typestring_offset += 2;
|
|
|
|
*typestring_offset
|
|
|
|
+= write_conf_or_var_desc(file, current_structure, baseoff,
|
2007-10-11 00:29:54 +02:00
|
|
|
type, size_is);
|
2007-09-19 00:29:59 +02:00
|
|
|
*typestring_offset
|
|
|
|
+= write_conf_or_var_desc(file, current_structure, baseoff,
|
2007-10-11 00:29:54 +02:00
|
|
|
type, length_is);
|
2009-10-16 20:56:41 +02:00
|
|
|
|
2014-04-02 11:37:32 +02:00
|
|
|
write_array_element_type(file, is_string_type(attrs, type) ? attrs : NULL, type, TRUE, typestring_offset);
|
2007-09-19 00:29:59 +02:00
|
|
|
write_end(file, typestring_offset);
|
|
|
|
}
|
2007-06-06 03:50:31 +02:00
|
|
|
|
|
|
|
return start_offset;
|
2006-01-24 11:06:32 +01:00
|
|
|
}
|
2005-12-08 12:52:13 +01:00
|
|
|
|
2006-01-24 11:14:59 +01:00
|
|
|
static const var_t *find_array_or_string_in_struct(const type_t *type)
|
2006-01-24 11:13:49 +01:00
|
|
|
{
|
2008-12-29 13:05:27 +01:00
|
|
|
const var_list_t *fields = type_struct_get_fields(type);
|
2008-06-23 23:28:56 +02:00
|
|
|
const var_t *last_field;
|
|
|
|
const type_t *ft;
|
|
|
|
|
2008-12-29 13:05:27 +01:00
|
|
|
if (!fields || list_empty(fields))
|
2008-06-23 23:28:56 +02:00
|
|
|
return NULL;
|
|
|
|
|
2008-12-29 13:05:27 +01:00
|
|
|
last_field = LIST_ENTRY( list_tail(fields), const var_t, entry );
|
2008-06-23 23:28:56 +02:00
|
|
|
ft = last_field->type;
|
2007-01-22 14:26:12 +01:00
|
|
|
|
2009-03-05 09:21:35 +01:00
|
|
|
if (is_conformant_array(ft) && !type_array_is_decl_as_ptr(ft))
|
2006-01-24 11:13:49 +01:00
|
|
|
return last_field;
|
|
|
|
|
2009-02-23 14:48:34 +01:00
|
|
|
if (type_get_type(ft) == TYPE_STRUCT)
|
2008-06-23 23:28:56 +02:00
|
|
|
return find_array_or_string_in_struct(ft);
|
2007-06-06 03:52:24 +02:00
|
|
|
else
|
|
|
|
return NULL;
|
2006-01-24 11:13:49 +01:00
|
|
|
}
|
|
|
|
|
2007-06-12 03:51:41 +02:00
|
|
|
static void write_struct_members(FILE *file, const type_t *type,
|
2009-02-23 14:48:34 +01:00
|
|
|
int is_complex, unsigned int *corroff,
|
|
|
|
unsigned int *typestring_offset)
|
2006-04-09 14:38:57 +02:00
|
|
|
{
|
2007-01-22 14:26:12 +01:00
|
|
|
const var_t *field;
|
2007-09-04 20:04:37 +02:00
|
|
|
unsigned short offset = 0;
|
2009-07-03 12:02:07 +02:00
|
|
|
unsigned int salign = 1;
|
2007-09-14 03:04:32 +02:00
|
|
|
int padding;
|
2008-12-29 13:05:27 +01:00
|
|
|
var_list_t *fields = type_struct_get_fields(type);
|
2006-04-09 14:38:57 +02:00
|
|
|
|
2008-12-29 13:05:27 +01:00
|
|
|
if (fields) LIST_FOR_EACH_ENTRY( field, fields, const var_t, entry )
|
2007-06-06 03:52:24 +02:00
|
|
|
{
|
|
|
|
type_t *ft = field->type;
|
2009-07-13 09:23:06 +02:00
|
|
|
unsigned int align = 0;
|
2010-04-05 19:48:07 +02:00
|
|
|
unsigned int size = type_memsize_and_alignment(ft, &align);
|
2009-08-25 14:29:47 +02:00
|
|
|
align = clamp_align(align);
|
2009-07-13 09:23:06 +02:00
|
|
|
if (salign < align) salign = align;
|
|
|
|
|
2009-03-05 09:21:35 +01:00
|
|
|
if (!is_conformant_array(ft) || type_array_is_decl_as_ptr(ft))
|
2007-09-04 20:04:37 +02:00
|
|
|
{
|
|
|
|
if ((align - 1) & offset)
|
|
|
|
{
|
|
|
|
unsigned char fc = 0;
|
|
|
|
switch (align)
|
|
|
|
{
|
2009-08-17 16:16:54 +02:00
|
|
|
case 2:
|
2018-06-13 04:19:11 +02:00
|
|
|
fc = FC_ALIGNM2;
|
2009-08-17 16:16:54 +02:00
|
|
|
break;
|
2007-09-04 20:04:37 +02:00
|
|
|
case 4:
|
2018-06-13 04:19:11 +02:00
|
|
|
fc = FC_ALIGNM4;
|
2007-09-04 20:04:37 +02:00
|
|
|
break;
|
|
|
|
case 8:
|
2018-06-13 04:19:11 +02:00
|
|
|
fc = FC_ALIGNM8;
|
2007-09-04 20:04:37 +02:00
|
|
|
break;
|
|
|
|
default:
|
2009-02-23 14:48:34 +01:00
|
|
|
error("write_struct_members: cannot align type %d\n", type_get_type(ft));
|
2007-09-04 20:04:37 +02:00
|
|
|
}
|
|
|
|
print_file(file, 2, "0x%x,\t/* %s */\n", fc, string_of_type(fc));
|
2008-06-23 13:57:28 +02:00
|
|
|
offset = ROUND_SIZE(offset, align);
|
2007-09-04 20:04:37 +02:00
|
|
|
*typestring_offset += 1;
|
|
|
|
}
|
2009-02-23 14:48:34 +01:00
|
|
|
write_member_type(file, type, is_complex, field->attrs, field->type, corroff,
|
2007-09-19 00:28:49 +02:00
|
|
|
typestring_offset);
|
2007-09-04 20:04:37 +02:00
|
|
|
offset += size;
|
|
|
|
}
|
2007-06-06 03:52:24 +02:00
|
|
|
}
|
2006-04-09 14:38:57 +02:00
|
|
|
|
2008-06-23 13:57:28 +02:00
|
|
|
padding = ROUNDING(offset, salign);
|
2007-09-14 03:04:32 +02:00
|
|
|
if (padding)
|
|
|
|
{
|
|
|
|
print_file(file, 2, "0x%x,\t/* FC_STRUCTPAD%d */\n",
|
2018-06-13 04:19:11 +02:00
|
|
|
FC_STRUCTPAD1 + padding - 1,
|
2007-09-14 03:04:32 +02:00
|
|
|
padding);
|
|
|
|
*typestring_offset += 1;
|
|
|
|
}
|
|
|
|
|
2007-06-06 03:50:31 +02:00
|
|
|
write_end(file, typestring_offset);
|
2006-04-09 14:38:57 +02:00
|
|
|
}
|
|
|
|
|
2009-02-06 14:30:38 +01:00
|
|
|
static unsigned int write_struct_tfs(FILE *file, type_t *type,
|
|
|
|
const char *name, unsigned int *tfsoff)
|
2006-01-24 11:10:59 +01:00
|
|
|
{
|
2007-06-12 03:51:41 +02:00
|
|
|
const type_t *save_current_structure = current_structure;
|
2006-06-13 14:13:49 +02:00
|
|
|
unsigned int total_size;
|
2006-01-24 11:13:49 +01:00
|
|
|
const var_t *array;
|
2009-02-06 14:30:38 +01:00
|
|
|
unsigned int start_offset;
|
2010-04-05 20:05:05 +02:00
|
|
|
unsigned int align;
|
2007-06-12 03:51:41 +02:00
|
|
|
unsigned int corroff;
|
|
|
|
var_t *f;
|
2009-02-23 14:48:34 +01:00
|
|
|
unsigned char fc = get_struct_fc(type);
|
2008-12-29 13:05:27 +01:00
|
|
|
var_list_t *fields = type_struct_get_fields(type);
|
2006-01-24 11:13:49 +01:00
|
|
|
|
2011-05-26 14:59:46 +02:00
|
|
|
if (processed(type)) return type->typestring_offset;
|
|
|
|
|
2007-05-25 02:50:02 +02:00
|
|
|
guard_rec(type);
|
2007-06-12 03:51:41 +02:00
|
|
|
current_structure = type;
|
2007-05-25 02:50:02 +02:00
|
|
|
|
2010-04-05 20:05:05 +02:00
|
|
|
total_size = type_memsize(type);
|
|
|
|
align = type_buffer_alignment(type);
|
2007-06-06 03:52:24 +02:00
|
|
|
if (total_size > USHRT_MAX)
|
|
|
|
error("structure size for %s exceeds %d bytes by %d bytes\n",
|
|
|
|
name, USHRT_MAX, total_size - USHRT_MAX);
|
2006-01-24 11:14:59 +01:00
|
|
|
|
2008-12-29 13:05:27 +01:00
|
|
|
if (fields) LIST_FOR_EACH_ENTRY(f, fields, var_t, entry)
|
2010-03-15 20:29:53 +01:00
|
|
|
write_embedded_types(file, f->attrs, f->type, f->name, FALSE, tfsoff);
|
2006-01-24 11:14:59 +01:00
|
|
|
|
2007-06-06 03:52:24 +02:00
|
|
|
array = find_array_or_string_in_struct(type);
|
|
|
|
if (array && !processed(array->type))
|
2010-05-02 20:48:39 +02:00
|
|
|
{
|
|
|
|
if(is_string_type(array->attrs, array->type))
|
2011-06-14 12:24:00 +02:00
|
|
|
write_string_tfs(file, array->attrs, array->type, TYPE_CONTEXT_CONTAINER, array->name, tfsoff);
|
2010-05-02 20:48:39 +02:00
|
|
|
else
|
|
|
|
write_array_tfs(file, array->attrs, array->type, array->name, tfsoff);
|
|
|
|
}
|
2007-06-12 03:51:41 +02:00
|
|
|
|
|
|
|
corroff = *tfsoff;
|
|
|
|
write_descriptors(file, type, tfsoff);
|
2006-01-31 18:08:03 +01:00
|
|
|
|
2007-06-06 03:52:24 +02:00
|
|
|
start_offset = *tfsoff;
|
|
|
|
update_tfsoff(type, start_offset, file);
|
2007-10-03 06:40:13 +02:00
|
|
|
print_start_tfs_comment(file, type, start_offset);
|
2009-02-23 14:48:34 +01:00
|
|
|
print_file(file, 2, "0x%x,\t/* %s */\n", fc, string_of_type(fc));
|
2007-06-06 03:52:24 +02:00
|
|
|
print_file(file, 2, "0x%x,\t/* %d */\n", align - 1, align - 1);
|
2010-09-16 12:12:40 +02:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%hx),\t/* %d */\n", (unsigned short)total_size, total_size);
|
2007-06-06 03:52:24 +02:00
|
|
|
*tfsoff += 4;
|
2007-05-19 01:53:27 +02:00
|
|
|
|
2007-06-06 03:52:24 +02:00
|
|
|
if (array)
|
|
|
|
{
|
|
|
|
unsigned int absoff = array->type->typestring_offset;
|
|
|
|
short reloff = absoff - *tfsoff;
|
2009-02-06 14:31:29 +01:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%hx),\t/* Offset= %hd (%u) */\n",
|
2007-06-06 03:52:24 +02:00
|
|
|
reloff, reloff, absoff);
|
|
|
|
*tfsoff += 2;
|
|
|
|
}
|
2018-06-13 04:19:11 +02:00
|
|
|
else if (fc == FC_BOGUS_STRUCT)
|
2007-06-06 03:52:24 +02:00
|
|
|
{
|
|
|
|
print_file(file, 2, "NdrFcShort(0x0),\n");
|
|
|
|
*tfsoff += 2;
|
|
|
|
}
|
2007-05-19 01:53:27 +02:00
|
|
|
|
2018-06-13 04:19:11 +02:00
|
|
|
if (fc == FC_BOGUS_STRUCT)
|
2007-06-06 03:52:24 +02:00
|
|
|
{
|
2007-09-19 00:28:49 +02:00
|
|
|
/* On the sizing pass, type->ptrdesc may be zero, but it's ok as
|
|
|
|
nothing is written to file yet. On the actual writing pass,
|
|
|
|
this will have been updated. */
|
2009-08-03 13:00:29 +02:00
|
|
|
unsigned int absoff = type->ptrdesc ? type->ptrdesc : *tfsoff;
|
2008-11-25 21:47:47 +01:00
|
|
|
int reloff = absoff - *tfsoff;
|
|
|
|
assert( reloff >= 0 );
|
2009-02-06 14:38:45 +01:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%hx),\t/* Offset= %d (%u) */\n",
|
2010-09-16 12:12:40 +02:00
|
|
|
(unsigned short)reloff, reloff, absoff);
|
2007-06-06 03:52:24 +02:00
|
|
|
*tfsoff += 2;
|
|
|
|
}
|
2018-06-13 04:19:11 +02:00
|
|
|
else if ((fc == FC_PSTRUCT) ||
|
|
|
|
(fc == FC_CPSTRUCT) ||
|
|
|
|
(fc == FC_CVSTRUCT && type_has_pointers(type)))
|
2007-06-06 03:52:24 +02:00
|
|
|
{
|
2018-06-13 04:19:11 +02:00
|
|
|
print_file(file, 2, "0x%x,\t/* FC_PP */\n", FC_PP);
|
|
|
|
print_file(file, 2, "0x%x,\t/* FC_PAD */\n", FC_PAD);
|
2007-06-06 03:52:24 +02:00
|
|
|
*tfsoff += 2;
|
2014-04-02 11:37:27 +02:00
|
|
|
write_pointer_description(file, NULL, type, tfsoff);
|
2018-06-13 04:19:11 +02:00
|
|
|
print_file(file, 2, "0x%x,\t/* FC_END */\n", FC_END);
|
2007-06-06 03:52:24 +02:00
|
|
|
*tfsoff += 1;
|
|
|
|
}
|
2007-05-19 01:53:27 +02:00
|
|
|
|
2018-06-13 04:19:11 +02:00
|
|
|
write_struct_members(file, type, fc == FC_BOGUS_STRUCT, &corroff,
|
2009-02-23 14:48:34 +01:00
|
|
|
tfsoff);
|
2007-05-19 01:53:27 +02:00
|
|
|
|
2018-06-13 04:19:11 +02:00
|
|
|
if (fc == FC_BOGUS_STRUCT)
|
2007-09-19 00:28:49 +02:00
|
|
|
{
|
|
|
|
const var_t *f;
|
|
|
|
|
2009-08-03 13:00:29 +02:00
|
|
|
type->ptrdesc = *tfsoff;
|
2008-12-29 13:05:27 +01:00
|
|
|
if (fields) LIST_FOR_EACH_ENTRY(f, fields, const var_t, entry)
|
2007-09-19 00:28:49 +02:00
|
|
|
{
|
|
|
|
type_t *ft = f->type;
|
2010-03-15 20:30:02 +01:00
|
|
|
switch (typegen_detect_type(ft, f->attrs, TDT_IGNORE_STRINGS))
|
2008-03-27 15:05:45 +01:00
|
|
|
{
|
2010-03-15 20:30:02 +01:00
|
|
|
case TGT_POINTER:
|
2008-03-27 15:05:45 +01:00
|
|
|
if (is_string_type(f->attrs, ft))
|
2011-06-14 12:24:00 +02:00
|
|
|
write_string_tfs(file, f->attrs, ft, TYPE_CONTEXT_CONTAINER, f->name, tfsoff);
|
2008-03-27 15:05:45 +01:00
|
|
|
else
|
2010-03-15 20:29:48 +01:00
|
|
|
write_pointer_tfs(file, f->attrs, ft,
|
|
|
|
type_pointer_get_ref(ft)->typestring_offset,
|
2011-06-14 12:24:00 +02:00
|
|
|
TYPE_CONTEXT_CONTAINER, tfsoff);
|
2010-03-15 20:30:02 +01:00
|
|
|
break;
|
|
|
|
case TGT_ARRAY:
|
|
|
|
if (type_array_is_decl_as_ptr(ft))
|
|
|
|
{
|
|
|
|
unsigned int offset;
|
2009-03-08 00:23:54 +01:00
|
|
|
|
2010-03-15 20:30:02 +01:00
|
|
|
print_file(file, 0, "/* %d */\n", *tfsoff);
|
2009-03-08 00:23:54 +01:00
|
|
|
|
2010-03-15 20:30:02 +01:00
|
|
|
offset = ft->typestring_offset;
|
|
|
|
/* skip over the pointer that is written for strings, since a
|
|
|
|
* pointer has to be written in-place here */
|
|
|
|
if (is_string_type(f->attrs, ft))
|
|
|
|
offset += 4;
|
2011-06-14 12:24:00 +02:00
|
|
|
write_nonsimple_pointer(file, f->attrs, ft, TYPE_CONTEXT_CONTAINER, offset, tfsoff);
|
2010-03-15 20:30:02 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2007-10-18 03:06:26 +02:00
|
|
|
}
|
2007-09-19 00:28:49 +02:00
|
|
|
}
|
2009-08-03 13:00:29 +02:00
|
|
|
if (type->ptrdesc == *tfsoff)
|
|
|
|
type->ptrdesc = 0;
|
2007-09-19 00:28:49 +02:00
|
|
|
}
|
|
|
|
|
2007-06-12 03:51:41 +02:00
|
|
|
current_structure = save_current_structure;
|
2007-06-06 03:52:24 +02:00
|
|
|
return start_offset;
|
2006-01-24 11:10:59 +01:00
|
|
|
}
|
|
|
|
|
2007-05-23 09:36:08 +02:00
|
|
|
static void write_branch_type(FILE *file, const type_t *t, unsigned int *tfsoff)
|
2006-01-24 11:10:59 +01:00
|
|
|
{
|
2007-06-15 03:28:03 +02:00
|
|
|
if (t == NULL)
|
|
|
|
{
|
|
|
|
print_file(file, 2, "NdrFcShort(0x0),\t/* No type */\n");
|
|
|
|
}
|
2009-02-23 14:48:34 +01:00
|
|
|
else
|
2007-05-19 01:53:27 +02:00
|
|
|
{
|
2009-02-23 14:48:34 +01:00
|
|
|
if (type_get_type(t) == TYPE_BASIC || type_get_type(t) == TYPE_ENUM)
|
|
|
|
{
|
|
|
|
unsigned char fc;
|
|
|
|
if (type_get_type(t) == TYPE_BASIC)
|
2009-03-08 00:24:00 +01:00
|
|
|
fc = get_basic_fc(t);
|
2009-02-23 14:48:34 +01:00
|
|
|
else
|
|
|
|
fc = get_enum_fc(t);
|
|
|
|
print_file(file, 2, "NdrFcShort(0x80%02x),\t/* Simple arm type: %s */\n",
|
|
|
|
fc, string_of_type(fc));
|
|
|
|
}
|
|
|
|
else if (t->typestring_offset)
|
|
|
|
{
|
|
|
|
short reloff = t->typestring_offset - *tfsoff;
|
|
|
|
print_file(file, 2, "NdrFcShort(0x%hx),\t/* Offset= %d (%d) */\n",
|
|
|
|
reloff, reloff, t->typestring_offset);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
error("write_branch_type: type unimplemented %d\n", type_get_type(t));
|
2007-05-19 01:53:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
*tfsoff += 2;
|
|
|
|
}
|
|
|
|
|
2011-05-26 21:34:51 +02:00
|
|
|
static unsigned int write_union_tfs(FILE *file, const attr_list_t *attrs,
|
|
|
|
type_t *type, unsigned int *tfsoff)
|
2007-05-19 01:53:27 +02:00
|
|
|
{
|
2007-05-23 09:36:08 +02:00
|
|
|
unsigned int start_offset;
|
2009-02-23 14:48:34 +01:00
|
|
|
unsigned int size;
|
2007-06-15 03:28:03 +02:00
|
|
|
var_list_t *fields;
|
2009-02-06 14:30:38 +01:00
|
|
|
unsigned int nbranch = 0;
|
2007-05-19 01:53:27 +02:00
|
|
|
type_t *deftype = NULL;
|
|
|
|
short nodeftype = 0xffff;
|
2018-04-11 03:30:29 +02:00
|
|
|
unsigned int dummy;
|
2007-05-19 01:53:27 +02:00
|
|
|
var_t *f;
|
|
|
|
|
2011-05-26 14:59:46 +02:00
|
|
|
if (processed(type) &&
|
|
|
|
(type_get_type(type) == TYPE_ENCAPSULATED_UNION || !is_attr(type->attrs, ATTR_SWITCHTYPE)))
|
|
|
|
return type->typestring_offset;
|
|
|
|
|
2007-05-25 02:50:02 +02:00
|
|
|
guard_rec(type);
|
|
|
|
|
2008-12-29 13:05:27 +01:00
|
|
|
fields = type_union_get_cases(type);
|
2007-06-15 03:28:03 +02:00
|
|
|
|
2018-04-11 03:30:29 +02:00
|
|
|
size = union_memsize(fields, &dummy);
|
|
|
|
|
2007-05-19 01:53:27 +02:00
|
|
|
if (fields) LIST_FOR_EACH_ENTRY(f, fields, var_t, entry)
|
|
|
|
{
|
|
|
|
expr_list_t *cases = get_attrp(f->attrs, ATTR_CASE);
|
|
|
|
if (cases)
|
|
|
|
nbranch += list_count(cases);
|
2007-06-12 03:51:41 +02:00
|
|
|
if (f->type)
|
|
|
|
write_embedded_types(file, f->attrs, f->type, f->name, TRUE, tfsoff);
|
2007-05-19 01:53:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
start_offset = *tfsoff;
|
2007-05-25 02:50:02 +02:00
|
|
|
update_tfsoff(type, start_offset, file);
|
2007-10-03 06:40:13 +02:00
|
|
|
print_start_tfs_comment(file, type, start_offset);
|
2009-02-23 14:48:34 +01:00
|
|
|
if (type_get_type(type) == TYPE_ENCAPSULATED_UNION)
|
2007-06-15 03:28:03 +02:00
|
|
|
{
|
2008-12-29 13:05:27 +01:00
|
|
|
const var_t *sv = type_union_get_switch_value(type);
|
2007-06-15 03:28:03 +02:00
|
|
|
const type_t *st = sv->type;
|
2018-04-11 03:30:26 +02:00
|
|
|
unsigned int align = 0;
|
2009-02-23 14:48:34 +01:00
|
|
|
unsigned char fc;
|
2007-06-15 03:28:03 +02:00
|
|
|
|
2009-02-23 14:48:34 +01:00
|
|
|
if (type_get_type(st) == TYPE_BASIC)
|
2007-06-26 03:27:24 +02:00
|
|
|
{
|
2011-06-03 12:26:31 +02:00
|
|
|
fc = get_basic_fc(st);
|
|
|
|
switch (fc)
|
2009-02-23 14:48:34 +01:00
|
|
|
{
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_CHAR:
|
|
|
|
case FC_SMALL:
|
|
|
|
case FC_BYTE:
|
|
|
|
case FC_USMALL:
|
|
|
|
case FC_WCHAR:
|
|
|
|
case FC_SHORT:
|
|
|
|
case FC_USHORT:
|
|
|
|
case FC_LONG:
|
|
|
|
case FC_ULONG:
|
2009-02-23 14:48:34 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fc = 0;
|
|
|
|
error("union switch type must be an integer, char, or enum\n");
|
|
|
|
}
|
2007-06-26 03:27:24 +02:00
|
|
|
}
|
2009-02-23 14:48:34 +01:00
|
|
|
else if (type_get_type(st) == TYPE_ENUM)
|
|
|
|
fc = get_enum_fc(st);
|
|
|
|
else
|
|
|
|
error("union switch type must be an integer, char, or enum\n");
|
|
|
|
|
2018-04-11 03:30:26 +02:00
|
|
|
type_memsize_and_alignment(st, &align);
|
|
|
|
if (fields) LIST_FOR_EACH_ENTRY(f, fields, var_t, entry)
|
|
|
|
{
|
|
|
|
if (f->type)
|
|
|
|
type_memsize_and_alignment(f->type, &align);
|
|
|
|
}
|
|
|
|
|
2018-06-13 04:19:11 +02:00
|
|
|
print_file(file, 2, "0x%x,\t/* FC_ENCAPSULATED_UNION */\n", FC_ENCAPSULATED_UNION);
|
2009-02-23 14:48:34 +01:00
|
|
|
print_file(file, 2, "0x%x,\t/* Switch type= %s */\n",
|
2018-04-11 03:30:26 +02:00
|
|
|
(align << 4) | fc, string_of_type(fc));
|
2009-02-23 14:48:34 +01:00
|
|
|
*tfsoff += 2;
|
2007-06-15 03:28:03 +02:00
|
|
|
}
|
2008-07-01 12:25:44 +02:00
|
|
|
else if (is_attr(type->attrs, ATTR_SWITCHTYPE))
|
|
|
|
{
|
2011-05-26 21:34:51 +02:00
|
|
|
const expr_t *switch_is = get_attrp(attrs, ATTR_SWITCHIS);
|
2008-07-01 12:25:44 +02:00
|
|
|
const type_t *st = get_attrp(type->attrs, ATTR_SWITCHTYPE);
|
2009-02-23 14:48:34 +01:00
|
|
|
unsigned char fc;
|
2008-07-01 12:25:44 +02:00
|
|
|
|
2009-02-23 14:48:34 +01:00
|
|
|
if (type_get_type(st) == TYPE_BASIC)
|
2008-07-01 12:25:44 +02:00
|
|
|
{
|
2011-06-03 12:26:31 +02:00
|
|
|
fc = get_basic_fc(st);
|
|
|
|
switch (fc)
|
2009-02-23 14:48:34 +01:00
|
|
|
{
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_CHAR:
|
|
|
|
case FC_SMALL:
|
|
|
|
case FC_USMALL:
|
|
|
|
case FC_SHORT:
|
|
|
|
case FC_USHORT:
|
|
|
|
case FC_LONG:
|
|
|
|
case FC_ULONG:
|
|
|
|
case FC_ENUM16:
|
|
|
|
case FC_ENUM32:
|
2009-02-23 14:48:34 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fc = 0;
|
|
|
|
error("union switch type must be an integer, char, or enum\n");
|
|
|
|
}
|
2008-07-01 12:25:44 +02:00
|
|
|
}
|
2009-02-23 14:48:34 +01:00
|
|
|
else if (type_get_type(st) == TYPE_ENUM)
|
|
|
|
fc = get_enum_fc(st);
|
|
|
|
else
|
|
|
|
error("union switch type must be an integer, char, or enum\n");
|
|
|
|
|
2018-06-13 04:19:11 +02:00
|
|
|
print_file(file, 2, "0x%x,\t/* FC_NON_ENCAPSULATED_UNION */\n", FC_NON_ENCAPSULATED_UNION);
|
2009-02-23 14:48:34 +01:00
|
|
|
print_file(file, 2, "0x%x,\t/* Switch type= %s */\n",
|
|
|
|
fc, string_of_type(fc));
|
|
|
|
*tfsoff += 2;
|
2011-05-26 21:34:51 +02:00
|
|
|
*tfsoff += write_conf_or_var_desc(file, current_structure, 0, st, switch_is );
|
2009-01-23 16:47:51 +01:00
|
|
|
print_file(file, 2, "NdrFcShort(0x2),\t/* Offset= 2 (%u) */\n", *tfsoff + 2);
|
|
|
|
*tfsoff += 2;
|
2009-07-03 11:44:10 +02:00
|
|
|
print_file(file, 0, "/* %u */\n", *tfsoff);
|
2008-07-01 12:25:44 +02:00
|
|
|
}
|
|
|
|
|
2010-09-16 12:12:40 +02:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%hx),\t/* %d */\n", (unsigned short)size, size);
|
|
|
|
print_file(file, 2, "NdrFcShort(0x%hx),\t/* %d */\n", (unsigned short)nbranch, nbranch);
|
2007-05-19 01:53:27 +02:00
|
|
|
*tfsoff += 4;
|
|
|
|
|
|
|
|
if (fields) LIST_FOR_EACH_ENTRY(f, fields, var_t, entry)
|
|
|
|
{
|
|
|
|
type_t *ft = f->type;
|
|
|
|
expr_list_t *cases = get_attrp(f->attrs, ATTR_CASE);
|
|
|
|
int deflt = is_attr(f->attrs, ATTR_DEFAULT);
|
|
|
|
expr_t *c;
|
|
|
|
|
|
|
|
if (cases == NULL && !deflt)
|
|
|
|
error("union field %s with neither case nor default attribute\n", f->name);
|
|
|
|
|
|
|
|
if (cases) LIST_FOR_EACH_ENTRY(c, cases, expr_t, entry)
|
|
|
|
{
|
|
|
|
/* MIDL doesn't check for duplicate cases, even though that seems
|
|
|
|
like a reasonable thing to do, it just dumps them to the TFS
|
|
|
|
like we're going to do here. */
|
2010-03-26 11:42:28 +01:00
|
|
|
print_file(file, 2, "NdrFcLong(0x%x),\t/* %d */\n", c->cval, c->cval);
|
2007-05-19 01:53:27 +02:00
|
|
|
*tfsoff += 4;
|
|
|
|
write_branch_type(file, ft, tfsoff);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* MIDL allows multiple default branches, even though that seems
|
|
|
|
illogical, it just chooses the last one, which is what we will
|
|
|
|
do. */
|
|
|
|
if (deflt)
|
|
|
|
{
|
|
|
|
deftype = ft;
|
|
|
|
nodeftype = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (deftype)
|
|
|
|
{
|
|
|
|
write_branch_type(file, deftype, tfsoff);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-02-06 14:38:45 +01:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%hx),\n", nodeftype);
|
2007-05-19 01:53:27 +02:00
|
|
|
*tfsoff += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return start_offset;
|
2006-01-24 11:10:59 +01:00
|
|
|
}
|
|
|
|
|
2009-02-06 14:30:38 +01:00
|
|
|
static unsigned int write_ip_tfs(FILE *file, const attr_list_t *attrs, type_t *type,
|
|
|
|
unsigned int *typeformat_offset)
|
2006-08-18 03:09:20 +02:00
|
|
|
{
|
2009-02-06 14:30:38 +01:00
|
|
|
unsigned int i;
|
|
|
|
unsigned int start_offset = *typeformat_offset;
|
2007-12-10 14:30:48 +01:00
|
|
|
expr_t *iid = get_attrp(attrs, ATTR_IIDIS);
|
2006-08-18 03:09:20 +02:00
|
|
|
|
2011-05-26 14:59:46 +02:00
|
|
|
if (!iid && processed(type)) return type->typestring_offset;
|
|
|
|
|
2010-03-15 20:30:20 +01:00
|
|
|
print_start_tfs_comment(file, type, start_offset);
|
2011-06-01 20:45:37 +02:00
|
|
|
update_tfsoff(type, start_offset, file);
|
2010-03-15 20:30:20 +01:00
|
|
|
|
2007-02-06 16:00:41 +01:00
|
|
|
if (iid)
|
|
|
|
{
|
|
|
|
print_file(file, 2, "0x2f, /* FC_IP */\n");
|
|
|
|
print_file(file, 2, "0x5c, /* FC_PAD */\n");
|
2007-10-11 00:29:54 +02:00
|
|
|
*typeformat_offset
|
2010-03-15 20:30:20 +01:00
|
|
|
+= write_conf_or_var_desc(file, current_structure, 0, type, iid) + 2;
|
2007-02-06 16:00:41 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-01-06 00:34:58 +01:00
|
|
|
const type_t *base = is_ptr(type) ? type_pointer_get_ref(type) : type;
|
2007-02-06 16:00:41 +01:00
|
|
|
const UUID *uuid = get_attrp(base->attrs, ATTR_UUID);
|
2006-08-18 03:09:20 +02:00
|
|
|
|
2007-02-06 16:00:41 +01:00
|
|
|
if (! uuid)
|
|
|
|
error("%s: interface %s missing UUID\n", __FUNCTION__, base->name);
|
2006-08-18 03:09:20 +02:00
|
|
|
|
2007-02-06 16:00:41 +01:00
|
|
|
print_file(file, 2, "0x2f,\t/* FC_IP */\n");
|
|
|
|
print_file(file, 2, "0x5a,\t/* FC_CONSTANT_IID */\n");
|
2009-02-06 14:31:29 +01:00
|
|
|
print_file(file, 2, "NdrFcLong(0x%08x),\n", uuid->Data1);
|
2007-02-06 16:00:41 +01:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%04x),\n", uuid->Data2);
|
|
|
|
print_file(file, 2, "NdrFcShort(0x%04x),\n", uuid->Data3);
|
|
|
|
for (i = 0; i < 8; ++i)
|
|
|
|
print_file(file, 2, "0x%02x,\n", uuid->Data4[i]);
|
|
|
|
|
|
|
|
if (file)
|
|
|
|
fprintf(file, "\n");
|
2006-08-18 03:09:20 +02:00
|
|
|
|
2007-02-06 16:00:41 +01:00
|
|
|
*typeformat_offset += 18;
|
|
|
|
}
|
2006-08-18 03:09:20 +02:00
|
|
|
return start_offset;
|
|
|
|
}
|
|
|
|
|
2010-03-15 20:29:57 +01:00
|
|
|
static unsigned int write_contexthandle_tfs(FILE *file,
|
|
|
|
const attr_list_t *attrs,
|
2011-06-01 20:21:37 +02:00
|
|
|
type_t *type,
|
2019-01-24 13:38:40 +01:00
|
|
|
enum type_context context,
|
2009-02-06 14:30:38 +01:00
|
|
|
unsigned int *typeformat_offset)
|
2007-09-28 02:38:27 +02:00
|
|
|
{
|
2009-02-06 14:30:38 +01:00
|
|
|
unsigned int start_offset = *typeformat_offset;
|
2019-01-24 13:38:40 +01:00
|
|
|
unsigned char flags = get_contexthandle_flags( current_iface, attrs, type, context == TYPE_CONTEXT_RETVAL );
|
2008-01-06 22:25:50 +01:00
|
|
|
|
2011-06-01 20:21:37 +02:00
|
|
|
print_start_tfs_comment(file, type, start_offset);
|
2007-09-28 02:38:27 +02:00
|
|
|
|
2011-06-01 20:21:37 +02:00
|
|
|
if (flags & 0x80) /* via ptr */
|
2008-01-07 14:27:05 +01:00
|
|
|
{
|
2019-01-24 13:38:40 +01:00
|
|
|
int pointer_type = get_pointer_fc( type, attrs, context == TYPE_CONTEXT_TOPLEVELPARAM );
|
2018-06-13 04:19:11 +02:00
|
|
|
if (!pointer_type) pointer_type = FC_RP;
|
2011-06-01 20:21:37 +02:00
|
|
|
*typeformat_offset += 4;
|
|
|
|
print_file(file, 2,"0x%x, 0x0,\t/* %s */\n", pointer_type, string_of_type(pointer_type) );
|
|
|
|
print_file(file, 2, "NdrFcShort(0x2),\t /* Offset= 2 (%u) */\n", *typeformat_offset);
|
|
|
|
print_file(file, 0, "/* %2u */\n", *typeformat_offset);
|
2008-01-07 14:27:05 +01:00
|
|
|
}
|
2007-09-28 02:38:27 +02:00
|
|
|
|
2018-06-13 04:19:11 +02:00
|
|
|
print_file(file, 2, "0x%02x,\t/* FC_BIND_CONTEXT */\n", FC_BIND_CONTEXT);
|
2007-09-28 02:38:27 +02:00
|
|
|
print_file(file, 2, "0x%x,\t/* Context flags: ", flags);
|
2019-01-23 12:27:16 +01:00
|
|
|
if (flags & NDR_CONTEXT_HANDLE_CANNOT_BE_NULL)
|
2007-09-28 02:38:27 +02:00
|
|
|
print_file(file, 0, "can't be null, ");
|
2008-01-07 14:27:19 +01:00
|
|
|
if (flags & NDR_CONTEXT_HANDLE_SERIALIZE)
|
2007-09-28 02:38:27 +02:00
|
|
|
print_file(file, 0, "serialize, ");
|
2018-06-13 04:19:11 +02:00
|
|
|
if (flags & NDR_CONTEXT_HANDLE_NOSERIALIZE)
|
2007-09-28 02:38:27 +02:00
|
|
|
print_file(file, 0, "no serialize, ");
|
2008-01-07 14:27:19 +01:00
|
|
|
if (flags & NDR_STRICT_CONTEXT_HANDLE)
|
2007-09-28 02:38:27 +02:00
|
|
|
print_file(file, 0, "strict, ");
|
2019-01-23 12:27:26 +01:00
|
|
|
if (flags & HANDLE_PARAM_IS_RETURN)
|
2007-09-28 02:38:27 +02:00
|
|
|
print_file(file, 0, "return, ");
|
2019-01-23 12:27:26 +01:00
|
|
|
if (flags & HANDLE_PARAM_IS_OUT)
|
2019-01-23 12:27:16 +01:00
|
|
|
print_file(file, 0, "out, ");
|
2019-01-23 12:27:26 +01:00
|
|
|
if (flags & HANDLE_PARAM_IS_IN)
|
2007-09-28 02:38:27 +02:00
|
|
|
print_file(file, 0, "in, ");
|
2019-01-23 12:27:26 +01:00
|
|
|
if (flags & HANDLE_PARAM_IS_VIA_PTR)
|
2007-09-28 02:38:27 +02:00
|
|
|
print_file(file, 0, "via ptr, ");
|
|
|
|
print_file(file, 0, "*/\n");
|
2011-06-01 20:21:37 +02:00
|
|
|
print_file(file, 2, "0x%x,\t/* rundown routine */\n", get_context_handle_offset( type ));
|
2007-09-28 02:38:27 +02:00
|
|
|
print_file(file, 2, "0, /* FIXME: param num */\n");
|
|
|
|
*typeformat_offset += 4;
|
|
|
|
|
2011-06-01 20:45:37 +02:00
|
|
|
update_tfsoff( type, start_offset, file );
|
2007-09-28 02:38:27 +02:00
|
|
|
return start_offset;
|
|
|
|
}
|
|
|
|
|
2009-11-07 15:54:28 +01:00
|
|
|
static unsigned int write_range_tfs(FILE *file, const attr_list_t *attrs,
|
|
|
|
type_t *type, expr_list_t *range_list,
|
|
|
|
unsigned int *typeformat_offset)
|
|
|
|
{
|
|
|
|
unsigned char fc;
|
|
|
|
unsigned int start_offset = *typeformat_offset;
|
|
|
|
const expr_t *range_min = LIST_ENTRY(list_head(range_list), const expr_t, entry);
|
|
|
|
const expr_t *range_max = LIST_ENTRY(list_next(range_list, list_head(range_list)), const expr_t, entry);
|
|
|
|
|
|
|
|
if (type_get_type(type) == TYPE_BASIC)
|
|
|
|
fc = get_basic_fc(type);
|
|
|
|
else
|
|
|
|
fc = get_enum_fc(type);
|
|
|
|
|
|
|
|
/* fc must fit in lower 4-bits of 8-bit field below */
|
|
|
|
assert(fc <= 0xf);
|
|
|
|
|
|
|
|
print_file(file, 0, "/* %u */\n", *typeformat_offset);
|
2018-06-13 04:19:11 +02:00
|
|
|
print_file(file, 2, "0x%x,\t/* FC_RANGE */\n", FC_RANGE);
|
2009-11-07 15:54:28 +01:00
|
|
|
print_file(file, 2, "0x%x,\t/* %s */\n", fc, string_of_type(fc));
|
2010-03-26 11:42:28 +01:00
|
|
|
print_file(file, 2, "NdrFcLong(0x%x),\t/* %u */\n", range_min->cval, range_min->cval);
|
|
|
|
print_file(file, 2, "NdrFcLong(0x%x),\t/* %u */\n", range_max->cval, range_max->cval);
|
2011-06-01 20:45:37 +02:00
|
|
|
update_tfsoff( type, start_offset, file );
|
2009-11-07 15:54:28 +01:00
|
|
|
*typeformat_offset += 10;
|
|
|
|
|
|
|
|
return start_offset;
|
|
|
|
}
|
|
|
|
|
2019-06-14 00:49:35 +02:00
|
|
|
static unsigned int write_type_tfs(FILE *file, const attr_list_t *attrs,
|
|
|
|
type_t *type, const char *name,
|
2010-03-15 20:29:57 +01:00
|
|
|
enum type_context context,
|
|
|
|
unsigned int *typeformat_offset)
|
2005-12-13 11:22:08 +01:00
|
|
|
{
|
2009-02-06 14:30:38 +01:00
|
|
|
unsigned int offset;
|
2006-03-31 13:46:43 +02:00
|
|
|
|
2010-03-15 20:29:57 +01:00
|
|
|
switch (typegen_detect_type(type, attrs, TDT_ALL_TYPES))
|
2007-06-14 01:13:04 +02:00
|
|
|
{
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_CTXT_HANDLE:
|
|
|
|
case TGT_CTXT_HANDLE_POINTER:
|
2019-01-24 13:38:40 +01:00
|
|
|
return write_contexthandle_tfs(file, attrs, type, context, typeformat_offset);
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_USER_TYPE:
|
2011-05-26 14:59:46 +02:00
|
|
|
return write_user_tfs(file, type, typeformat_offset);
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_STRING:
|
2011-06-14 12:24:00 +02:00
|
|
|
return write_string_tfs(file, attrs, type, context, name, typeformat_offset);
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_ARRAY:
|
2007-09-26 20:32:08 +02:00
|
|
|
{
|
2009-02-06 14:30:38 +01:00
|
|
|
unsigned int off;
|
2010-03-15 20:29:57 +01:00
|
|
|
/* conformant and pointer arrays are handled specially */
|
|
|
|
if ((context != TYPE_CONTEXT_CONTAINER &&
|
|
|
|
context != TYPE_CONTEXT_CONTAINER_NO_POINTERS) ||
|
|
|
|
!is_conformant_array(type) || type_array_is_decl_as_ptr(type))
|
|
|
|
off = write_array_tfs(file, attrs, type, name, typeformat_offset);
|
|
|
|
else
|
|
|
|
off = 0;
|
|
|
|
if (context != TYPE_CONTEXT_CONTAINER &&
|
|
|
|
context != TYPE_CONTEXT_CONTAINER_NO_POINTERS)
|
|
|
|
{
|
|
|
|
int ptr_type;
|
2019-05-29 07:24:08 +02:00
|
|
|
ptr_type = get_pointer_fc_context(type, attrs, context);
|
2018-06-13 04:19:11 +02:00
|
|
|
if (ptr_type != FC_RP || type_array_is_decl_as_ptr(type))
|
2010-03-15 20:29:57 +01:00
|
|
|
{
|
|
|
|
unsigned int absoff = type->typestring_offset;
|
|
|
|
short reloff = absoff - (*typeformat_offset + 2);
|
|
|
|
off = *typeformat_offset;
|
|
|
|
print_file(file, 0, "/* %d */\n", off);
|
|
|
|
print_file(file, 2, "0x%x, 0x0,\t/* %s */\n", ptr_type,
|
|
|
|
string_of_type(ptr_type));
|
|
|
|
print_file(file, 2, "NdrFcShort(0x%hx),\t/* Offset= %hd (%u) */\n",
|
|
|
|
reloff, reloff, absoff);
|
2018-06-13 04:19:11 +02:00
|
|
|
if (ptr_type != FC_RP) update_tfsoff( type, off, file );
|
2010-03-15 20:29:57 +01:00
|
|
|
*typeformat_offset += 4;
|
|
|
|
}
|
2011-06-01 21:27:56 +02:00
|
|
|
type->details.array.ptr_tfsoff = off;
|
2007-09-26 20:32:08 +02:00
|
|
|
}
|
|
|
|
return off;
|
|
|
|
}
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_STRUCT:
|
2010-03-15 20:29:57 +01:00
|
|
|
return write_struct_tfs(file, type, name, typeformat_offset);
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_UNION:
|
2011-05-26 21:34:51 +02:00
|
|
|
return write_union_tfs(file, attrs, type, typeformat_offset);
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_ENUM:
|
|
|
|
case TGT_BASIC:
|
|
|
|
/* nothing to do */
|
|
|
|
return 0;
|
2009-11-07 15:54:28 +01:00
|
|
|
case TGT_RANGE:
|
|
|
|
{
|
2010-03-15 20:29:57 +01:00
|
|
|
expr_list_t *range_list = get_attrp(attrs, ATTR_RANGE);
|
2009-11-07 15:54:28 +01:00
|
|
|
if (!range_list)
|
|
|
|
range_list = get_aliaschain_attrp(type, ATTR_RANGE);
|
2010-03-15 20:29:57 +01:00
|
|
|
return write_range_tfs(file, attrs, type, range_list, typeformat_offset);
|
2009-11-07 15:54:28 +01:00
|
|
|
}
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_IFACE_POINTER:
|
2010-03-15 20:29:57 +01:00
|
|
|
return write_ip_tfs(file, attrs, type, typeformat_offset);
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_POINTER:
|
2011-05-26 14:59:46 +02:00
|
|
|
{
|
|
|
|
enum type_context ref_context;
|
2014-04-02 11:37:37 +02:00
|
|
|
type_t *ref = type_pointer_get_ref(type);
|
|
|
|
|
2011-05-26 14:59:46 +02:00
|
|
|
if (context == TYPE_CONTEXT_TOPLEVELPARAM)
|
|
|
|
ref_context = TYPE_CONTEXT_PARAM;
|
|
|
|
else if (context == TYPE_CONTEXT_CONTAINER_NO_POINTERS)
|
|
|
|
ref_context = TYPE_CONTEXT_CONTAINER;
|
2010-03-15 20:29:57 +01:00
|
|
|
else
|
2011-05-26 14:59:46 +02:00
|
|
|
ref_context = context;
|
2014-04-02 11:37:37 +02:00
|
|
|
|
2014-04-03 06:57:13 +02:00
|
|
|
if (is_string_type(attrs, ref))
|
2014-04-02 11:37:37 +02:00
|
|
|
{
|
|
|
|
if (context != TYPE_CONTEXT_CONTAINER_NO_POINTERS)
|
|
|
|
write_pointer_tfs(file, attrs, type, *typeformat_offset + 4, context, typeformat_offset);
|
|
|
|
|
2019-06-14 00:49:35 +02:00
|
|
|
offset = write_type_tfs(file, attrs, ref, name, ref_context, typeformat_offset);
|
2014-04-02 11:37:37 +02:00
|
|
|
if (context == TYPE_CONTEXT_CONTAINER_NO_POINTERS)
|
|
|
|
return 0;
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
2019-06-14 00:49:35 +02:00
|
|
|
offset = write_type_tfs( file, attrs, type_pointer_get_ref(type), name,
|
2011-05-26 14:59:46 +02:00
|
|
|
ref_context, typeformat_offset);
|
2010-03-15 20:29:57 +01:00
|
|
|
if (context == TYPE_CONTEXT_CONTAINER_NO_POINTERS)
|
|
|
|
return 0;
|
2011-06-14 12:24:00 +02:00
|
|
|
return write_pointer_tfs(file, attrs, type, offset, context, typeformat_offset);
|
2011-05-26 14:59:46 +02:00
|
|
|
}
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_INVALID:
|
|
|
|
break;
|
|
|
|
}
|
2010-03-15 20:29:57 +01:00
|
|
|
error("invalid type %s for var %s\n", type->name, name);
|
2009-02-23 14:48:46 +01:00
|
|
|
return 0;
|
2005-12-13 11:22:08 +01:00
|
|
|
}
|
|
|
|
|
2007-05-25 02:48:39 +02:00
|
|
|
static int write_embedded_types(FILE *file, const attr_list_t *attrs, type_t *type,
|
2007-06-12 03:51:41 +02:00
|
|
|
const char *name, int write_ptr, unsigned int *tfsoff)
|
2007-05-19 01:53:27 +02:00
|
|
|
{
|
2019-06-14 00:49:35 +02:00
|
|
|
return write_type_tfs(file, attrs, type, name, write_ptr ? TYPE_CONTEXT_CONTAINER : TYPE_CONTEXT_CONTAINER_NO_POINTERS, tfsoff);
|
2007-05-19 01:53:27 +02:00
|
|
|
}
|
|
|
|
|
2018-11-07 16:14:31 +01:00
|
|
|
static void process_tfs_iface(type_t *iface, FILE *file, int indent, unsigned int *offset)
|
2007-05-16 02:45:59 +02:00
|
|
|
{
|
2018-11-09 13:51:10 +01:00
|
|
|
const statement_list_t *stmts = type_iface_get_stmts(iface);
|
|
|
|
const statement_t *stmt;
|
2011-09-19 12:23:01 +02:00
|
|
|
var_t *var;
|
2005-12-13 11:22:08 +01:00
|
|
|
|
2018-11-07 16:14:31 +01:00
|
|
|
current_iface = iface;
|
2018-11-09 13:51:10 +01:00
|
|
|
if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, statement_t, entry )
|
2005-12-13 11:22:08 +01:00
|
|
|
{
|
2018-11-09 13:51:10 +01:00
|
|
|
switch(stmt->type)
|
|
|
|
{
|
|
|
|
case STMT_DECLARATION:
|
|
|
|
{
|
|
|
|
const var_t *func = stmt->u.var;
|
|
|
|
|
|
|
|
if(stmt->u.var->stgclass != STG_NONE
|
|
|
|
|| type_get_type_detect_alias(stmt->u.var->type) != TYPE_FUNCTION)
|
|
|
|
continue;
|
2007-05-19 01:52:25 +02:00
|
|
|
|
2018-11-09 13:51:10 +01:00
|
|
|
current_func = func;
|
|
|
|
if (is_local(func->attrs)) continue;
|
2008-02-22 00:46:51 +01:00
|
|
|
|
2018-11-09 13:51:10 +01:00
|
|
|
var = type_function_get_retval(func->type);
|
|
|
|
if (!is_void(var->type))
|
2019-06-14 00:49:35 +02:00
|
|
|
var->typestring_offset = write_type_tfs( file, var->attrs, var->type, func->name,
|
2019-01-24 13:38:40 +01:00
|
|
|
TYPE_CONTEXT_RETVAL, offset);
|
2018-11-09 13:51:10 +01:00
|
|
|
|
|
|
|
if (type_get_function_args(func->type))
|
|
|
|
LIST_FOR_EACH_ENTRY( var, type_get_function_args(func->type), var_t, entry )
|
2019-06-14 00:49:35 +02:00
|
|
|
var->typestring_offset = write_type_tfs( file, var->attrs, var->type, var->name,
|
2018-11-09 13:51:10 +01:00
|
|
|
TYPE_CONTEXT_TOPLEVELPARAM, offset );
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
case STMT_TYPEDEF:
|
|
|
|
{
|
|
|
|
const type_list_t *type_entry;
|
|
|
|
for (type_entry = stmt->u.type_list; type_entry; type_entry = type_entry->next)
|
|
|
|
{
|
|
|
|
if (is_attr(type_entry->type->attrs, ATTR_ENCODE)
|
|
|
|
|| is_attr(type_entry->type->attrs, ATTR_DECODE))
|
2019-06-14 00:49:35 +02:00
|
|
|
type_entry->type->typestring_offset = write_type_tfs( file,
|
2018-11-09 13:51:10 +01:00
|
|
|
type_entry->type->attrs, type_entry->type, type_entry->type->name,
|
|
|
|
TYPE_CONTEXT_CONTAINER, offset);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2005-12-13 11:22:08 +01:00
|
|
|
}
|
2008-04-24 20:06:28 +02:00
|
|
|
}
|
|
|
|
|
2009-02-06 14:30:38 +01:00
|
|
|
static unsigned int process_tfs(FILE *file, const statement_list_t *stmts, type_pred_t pred)
|
2008-04-24 20:06:28 +02:00
|
|
|
{
|
|
|
|
unsigned int typeformat_offset = 2;
|
2018-11-07 16:14:31 +01:00
|
|
|
for_each_iface(stmts, process_tfs_iface, pred, file, 0, &typeformat_offset);
|
|
|
|
return typeformat_offset + 1;
|
2007-05-16 02:45:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-24 20:06:28 +02:00
|
|
|
void write_typeformatstring(FILE *file, const statement_list_t *stmts, type_pred_t pred)
|
2007-05-16 02:45:59 +02:00
|
|
|
{
|
|
|
|
int indent = 0;
|
|
|
|
|
|
|
|
print_file(file, indent, "static const MIDL_TYPE_FORMAT_STRING __MIDL_TypeFormatString =\n");
|
|
|
|
print_file(file, indent, "{\n");
|
|
|
|
indent++;
|
|
|
|
print_file(file, indent, "0,\n");
|
|
|
|
print_file(file, indent, "{\n");
|
|
|
|
indent++;
|
|
|
|
print_file(file, indent, "NdrFcShort(0x0),\n");
|
|
|
|
|
2007-10-09 01:47:28 +02:00
|
|
|
set_all_tfswrite(TRUE);
|
2008-04-24 20:06:28 +02:00
|
|
|
process_tfs(file, stmts, pred);
|
2007-05-16 02:45:59 +02:00
|
|
|
|
2005-12-08 12:52:13 +01:00
|
|
|
print_file(file, indent, "0x0\n");
|
|
|
|
indent--;
|
|
|
|
print_file(file, indent, "}\n");
|
|
|
|
indent--;
|
|
|
|
print_file(file, indent, "};\n");
|
|
|
|
print_file(file, indent, "\n");
|
|
|
|
}
|
|
|
|
|
2005-12-26 13:22:32 +01:00
|
|
|
static unsigned int get_required_buffer_size_type(
|
2009-03-08 00:23:44 +01:00
|
|
|
const type_t *type, const char *name, const attr_list_t *attrs, int toplevel_param, unsigned int *alignment)
|
2005-12-08 12:52:13 +01:00
|
|
|
{
|
2005-12-26 13:20:59 +01:00
|
|
|
*alignment = 0;
|
2011-05-24 23:13:47 +02:00
|
|
|
switch (typegen_detect_type(type, NULL, TDT_IGNORE_RANGES))
|
2009-02-23 14:48:46 +01:00
|
|
|
{
|
|
|
|
case TGT_USER_TYPE:
|
2007-06-26 03:23:33 +02:00
|
|
|
{
|
2018-08-15 10:48:51 +02:00
|
|
|
const char *uname = NULL;
|
2009-02-23 14:48:46 +01:00
|
|
|
const type_t *utype = get_user_type(type, &uname);
|
2009-03-08 00:23:44 +01:00
|
|
|
return get_required_buffer_size_type(utype, uname, NULL, FALSE, alignment);
|
2007-06-26 03:23:33 +02:00
|
|
|
}
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_BASIC:
|
2009-03-08 00:24:00 +01:00
|
|
|
switch (get_basic_fc(type))
|
2005-12-26 13:20:59 +01:00
|
|
|
{
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_BYTE:
|
|
|
|
case FC_CHAR:
|
|
|
|
case FC_USMALL:
|
|
|
|
case FC_SMALL:
|
2009-02-23 14:48:46 +01:00
|
|
|
*alignment = 4;
|
|
|
|
return 1;
|
2009-02-23 14:48:34 +01:00
|
|
|
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_WCHAR:
|
|
|
|
case FC_USHORT:
|
|
|
|
case FC_SHORT:
|
2009-02-23 14:48:46 +01:00
|
|
|
*alignment = 4;
|
|
|
|
return 2;
|
2009-02-23 14:48:34 +01:00
|
|
|
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_ULONG:
|
|
|
|
case FC_LONG:
|
|
|
|
case FC_FLOAT:
|
|
|
|
case FC_ERROR_STATUS_T:
|
2009-02-23 14:48:46 +01:00
|
|
|
*alignment = 4;
|
|
|
|
return 4;
|
2009-02-23 14:48:34 +01:00
|
|
|
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_HYPER:
|
|
|
|
case FC_DOUBLE:
|
2009-02-23 14:48:46 +01:00
|
|
|
*alignment = 8;
|
|
|
|
return 8;
|
2009-02-23 14:48:34 +01:00
|
|
|
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_INT3264:
|
|
|
|
case FC_UINT3264:
|
2009-11-07 15:54:56 +01:00
|
|
|
assert( pointer_size );
|
|
|
|
*alignment = pointer_size;
|
|
|
|
return pointer_size;
|
|
|
|
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_IGNORE:
|
|
|
|
case FC_BIND_PRIMITIVE:
|
2009-02-23 14:48:46 +01:00
|
|
|
return 0;
|
2005-12-08 12:52:13 +01:00
|
|
|
|
2009-02-23 14:48:46 +01:00
|
|
|
default:
|
|
|
|
error("get_required_buffer_size: unknown basic type 0x%02x\n",
|
2009-03-08 00:24:00 +01:00
|
|
|
get_basic_fc(type));
|
2009-02-23 14:48:46 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
2005-12-08 12:52:13 +01:00
|
|
|
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_ENUM:
|
|
|
|
switch (get_enum_fc(type))
|
|
|
|
{
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_ENUM32:
|
2009-02-23 14:48:46 +01:00
|
|
|
*alignment = 4;
|
|
|
|
return 4;
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_ENUM16:
|
2009-02-23 14:48:46 +01:00
|
|
|
*alignment = 4;
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
break;
|
2006-01-31 18:06:17 +01:00
|
|
|
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_STRUCT:
|
2018-06-13 04:19:11 +02:00
|
|
|
if (get_struct_fc(type) == FC_STRUCT)
|
2009-02-23 14:48:46 +01:00
|
|
|
{
|
|
|
|
if (!type_struct_get_fields(type)) return 0;
|
|
|
|
return fields_memsize(type_struct_get_fields(type), alignment);
|
|
|
|
}
|
|
|
|
break;
|
2006-01-06 21:06:24 +01:00
|
|
|
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_POINTER:
|
|
|
|
{
|
2011-05-24 23:53:11 +02:00
|
|
|
unsigned int size, align;
|
2009-02-23 14:48:46 +01:00
|
|
|
const type_t *ref = type_pointer_get_ref(type);
|
2011-05-24 23:13:47 +02:00
|
|
|
if (is_string_type( attrs, ref )) break;
|
2011-05-24 23:53:11 +02:00
|
|
|
if (!(size = get_required_buffer_size_type( ref, name, NULL, FALSE, &align ))) break;
|
2018-06-13 04:19:11 +02:00
|
|
|
if (get_pointer_fc(type, attrs, toplevel_param) != FC_RP)
|
2011-05-24 23:53:11 +02:00
|
|
|
{
|
|
|
|
size += 4 + align;
|
|
|
|
align = 4;
|
|
|
|
}
|
|
|
|
*alignment = align;
|
|
|
|
return size;
|
2009-02-23 14:48:46 +01:00
|
|
|
}
|
2007-06-06 03:50:31 +02:00
|
|
|
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_ARRAY:
|
2018-06-13 04:19:11 +02:00
|
|
|
if (get_pointer_fc(type, attrs, toplevel_param) == FC_RP)
|
2011-05-24 22:30:23 +02:00
|
|
|
{
|
|
|
|
switch (get_array_fc(type))
|
|
|
|
{
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_SMFARRAY:
|
|
|
|
case FC_LGFARRAY:
|
2011-05-24 22:30:23 +02:00
|
|
|
return type_array_get_dim(type) *
|
|
|
|
get_required_buffer_size_type(type_array_get_element(type), name,
|
|
|
|
NULL, FALSE, alignment);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2007-01-24 20:10:57 +01:00
|
|
|
|
2009-02-23 14:48:46 +01:00
|
|
|
default:
|
|
|
|
break;
|
2005-12-08 12:52:13 +01:00
|
|
|
}
|
2009-02-23 14:48:34 +01:00
|
|
|
return 0;
|
2005-12-08 12:52:13 +01:00
|
|
|
}
|
|
|
|
|
2007-01-24 20:02:05 +01:00
|
|
|
static unsigned int get_required_buffer_size(const var_t *var, unsigned int *alignment, enum pass pass)
|
2005-12-26 13:22:32 +01:00
|
|
|
{
|
2006-03-29 12:42:29 +02:00
|
|
|
int in_attr = is_attr(var->attrs, ATTR_IN);
|
|
|
|
int out_attr = is_attr(var->attrs, ATTR_OUT);
|
|
|
|
|
|
|
|
if (!in_attr && !out_attr)
|
|
|
|
in_attr = 1;
|
|
|
|
|
2006-04-09 14:38:57 +02:00
|
|
|
*alignment = 0;
|
|
|
|
|
2008-11-30 17:25:01 +01:00
|
|
|
if ((pass == PASS_IN && in_attr) || (pass == PASS_OUT && out_attr) ||
|
|
|
|
pass == PASS_RETURN)
|
|
|
|
{
|
|
|
|
if (is_ptrchain_attr(var, ATTR_CONTEXTHANDLE))
|
2007-09-28 02:38:27 +02:00
|
|
|
{
|
|
|
|
*alignment = 4;
|
|
|
|
return 20;
|
|
|
|
}
|
|
|
|
|
2008-11-30 17:25:01 +01:00
|
|
|
if (!is_string_type(var->attrs, var->type))
|
|
|
|
return get_required_buffer_size_type(var->type, var->name,
|
2009-03-08 00:23:44 +01:00
|
|
|
var->attrs, TRUE, alignment);
|
2006-04-09 14:38:57 +02:00
|
|
|
}
|
2008-11-30 17:25:01 +01:00
|
|
|
return 0;
|
2005-12-26 13:22:32 +01:00
|
|
|
}
|
|
|
|
|
2009-01-06 00:33:27 +01:00
|
|
|
static unsigned int get_function_buffer_size( const var_t *func, enum pass pass )
|
2007-01-24 20:02:05 +01:00
|
|
|
{
|
|
|
|
const var_t *var;
|
|
|
|
unsigned int total_size = 0, alignment;
|
|
|
|
|
2009-01-06 00:33:27 +01:00
|
|
|
if (type_get_function_args(func->type))
|
2007-01-24 20:02:05 +01:00
|
|
|
{
|
2009-01-06 00:33:27 +01:00
|
|
|
LIST_FOR_EACH_ENTRY( var, type_get_function_args(func->type), const var_t, entry )
|
2007-01-24 20:02:05 +01:00
|
|
|
{
|
|
|
|
total_size += get_required_buffer_size(var, &alignment, pass);
|
|
|
|
total_size += alignment;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-06 00:35:24 +01:00
|
|
|
if (pass == PASS_OUT && !is_void(type_function_get_rettype(func->type)))
|
2007-01-24 20:02:05 +01:00
|
|
|
{
|
2009-01-06 00:33:27 +01:00
|
|
|
var_t v = *func;
|
2009-01-06 00:35:24 +01:00
|
|
|
v.type = type_function_get_rettype(func->type);
|
2008-04-02 13:55:34 +02:00
|
|
|
total_size += get_required_buffer_size(&v, &alignment, PASS_RETURN);
|
2007-01-24 20:02:05 +01:00
|
|
|
total_size += alignment;
|
|
|
|
}
|
|
|
|
return total_size;
|
|
|
|
}
|
|
|
|
|
2006-03-31 13:47:35 +02:00
|
|
|
static void print_phase_function(FILE *file, int indent, const char *type,
|
2008-09-15 16:46:01 +02:00
|
|
|
const char *local_var_prefix, enum remoting_phase phase,
|
2007-06-14 01:13:04 +02:00
|
|
|
const var_t *var, unsigned int type_offset)
|
2006-02-07 12:32:24 +01:00
|
|
|
{
|
2006-03-31 13:47:35 +02:00
|
|
|
const char *function;
|
2006-02-07 12:32:24 +01:00
|
|
|
switch (phase)
|
|
|
|
{
|
|
|
|
case PHASE_BUFFERSIZE:
|
2006-03-31 13:47:35 +02:00
|
|
|
function = "BufferSize";
|
|
|
|
break;
|
2006-02-07 12:32:24 +01:00
|
|
|
case PHASE_MARSHAL:
|
2006-03-31 13:47:35 +02:00
|
|
|
function = "Marshall";
|
|
|
|
break;
|
2006-02-07 12:32:24 +01:00
|
|
|
case PHASE_UNMARSHAL:
|
2006-03-31 13:47:35 +02:00
|
|
|
function = "Unmarshall";
|
|
|
|
break;
|
2006-02-07 12:32:24 +01:00
|
|
|
case PHASE_FREE:
|
2006-03-31 13:47:35 +02:00
|
|
|
function = "Free";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
return;
|
2006-02-07 12:32:24 +01:00
|
|
|
}
|
2006-03-31 13:47:35 +02:00
|
|
|
|
|
|
|
print_file(file, indent, "Ndr%s%s(\n", type, function);
|
|
|
|
indent++;
|
2008-09-15 14:02:26 +02:00
|
|
|
print_file(file, indent, "&__frame->_StubMsg,\n");
|
2008-09-15 16:46:01 +02:00
|
|
|
print_file(file, indent, "%s%s%s%s%s,\n",
|
2007-06-14 01:13:04 +02:00
|
|
|
(phase == PHASE_UNMARSHAL) ? "(unsigned char **)" : "(unsigned char *)",
|
|
|
|
(phase == PHASE_UNMARSHAL || decl_indirect(var->type)) ? "&" : "",
|
2008-09-15 16:46:01 +02:00
|
|
|
local_var_prefix,
|
2007-06-14 01:13:04 +02:00
|
|
|
(phase == PHASE_UNMARSHAL && decl_indirect(var->type)) ? "_p_" : "",
|
|
|
|
var->name);
|
2006-03-31 13:47:35 +02:00
|
|
|
print_file(file, indent, "(PFORMAT_STRING)&__MIDL_TypeFormatString.Format[%d]%s\n",
|
|
|
|
type_offset, (phase == PHASE_UNMARSHAL) ? "," : ");");
|
|
|
|
if (phase == PHASE_UNMARSHAL)
|
|
|
|
print_file(file, indent, "0);\n");
|
|
|
|
indent--;
|
2006-02-07 12:32:24 +01:00
|
|
|
}
|
|
|
|
|
2008-09-15 16:46:01 +02:00
|
|
|
void print_phase_basetype(FILE *file, int indent, const char *local_var_prefix,
|
|
|
|
enum remoting_phase phase, enum pass pass, const var_t *var,
|
2006-03-31 13:48:24 +02:00
|
|
|
const char *varname)
|
|
|
|
{
|
2007-05-10 05:50:49 +02:00
|
|
|
type_t *type = var->type;
|
2006-03-31 13:48:24 +02:00
|
|
|
unsigned int alignment = 0;
|
|
|
|
|
|
|
|
/* no work to do for other phases, buffer sizing is done elsewhere */
|
|
|
|
if (phase != PHASE_MARSHAL && phase != PHASE_UNMARSHAL)
|
|
|
|
return;
|
|
|
|
|
2009-11-07 15:54:56 +01:00
|
|
|
if (type_get_type(type) == TYPE_ENUM ||
|
|
|
|
(type_get_type(type) == TYPE_BASIC &&
|
|
|
|
type_basic_get_type(type) == TYPE_BASIC_INT3264 &&
|
|
|
|
pointer_size != 4))
|
2006-03-31 13:48:24 +02:00
|
|
|
{
|
2009-11-07 15:54:56 +01:00
|
|
|
unsigned char fc;
|
|
|
|
|
|
|
|
if (type_get_type(type) == TYPE_ENUM)
|
|
|
|
fc = get_enum_fc(type);
|
|
|
|
else
|
|
|
|
fc = get_basic_fc(type);
|
|
|
|
|
|
|
|
if (phase == PHASE_MARSHAL)
|
|
|
|
print_file(file, indent, "NdrSimpleTypeMarshall(\n");
|
|
|
|
else
|
|
|
|
print_file(file, indent, "NdrSimpleTypeUnmarshall(\n");
|
|
|
|
print_file(file, indent+1, "&__frame->_StubMsg,\n");
|
|
|
|
print_file(file, indent+1, "(unsigned char *)&%s%s,\n",
|
|
|
|
local_var_prefix,
|
|
|
|
var->name);
|
|
|
|
print_file(file, indent+1, "0x%02x /* %s */);\n", fc, string_of_type(fc));
|
2009-02-23 14:48:34 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-11-07 15:54:56 +01:00
|
|
|
const type_t *ref = is_ptr(type) ? type_pointer_get_ref(type) : type;
|
2009-03-08 00:24:00 +01:00
|
|
|
switch (get_basic_fc(ref))
|
2009-02-23 14:48:34 +01:00
|
|
|
{
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_BYTE:
|
|
|
|
case FC_CHAR:
|
|
|
|
case FC_SMALL:
|
|
|
|
case FC_USMALL:
|
2006-03-31 13:48:24 +02:00
|
|
|
alignment = 1;
|
|
|
|
break;
|
|
|
|
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_WCHAR:
|
|
|
|
case FC_USHORT:
|
|
|
|
case FC_SHORT:
|
2006-03-31 13:48:24 +02:00
|
|
|
alignment = 2;
|
|
|
|
break;
|
|
|
|
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_ULONG:
|
|
|
|
case FC_LONG:
|
|
|
|
case FC_FLOAT:
|
|
|
|
case FC_ERROR_STATUS_T:
|
2009-11-07 15:54:56 +01:00
|
|
|
/* pointer_size must be 4 if we got here in these two cases */
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_INT3264:
|
|
|
|
case FC_UINT3264:
|
2006-03-31 13:48:24 +02:00
|
|
|
alignment = 4;
|
|
|
|
break;
|
|
|
|
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_HYPER:
|
|
|
|
case FC_DOUBLE:
|
2006-03-31 13:48:24 +02:00
|
|
|
alignment = 8;
|
|
|
|
break;
|
|
|
|
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_IGNORE:
|
|
|
|
case FC_BIND_PRIMITIVE:
|
2006-03-31 13:48:24 +02:00
|
|
|
/* no marshalling needed */
|
|
|
|
return;
|
|
|
|
|
|
|
|
default:
|
2009-02-23 14:48:34 +01:00
|
|
|
error("print_phase_basetype: Unsupported type: %s (0x%02x, ptr_level: 0)\n",
|
2009-03-08 00:24:00 +01:00
|
|
|
var->name, get_basic_fc(ref));
|
2009-02-23 14:48:34 +01:00
|
|
|
}
|
2006-03-31 13:48:24 +02:00
|
|
|
|
2009-11-18 19:39:08 +01:00
|
|
|
if (phase == PHASE_MARSHAL && alignment > 1)
|
2009-11-07 15:54:56 +01:00
|
|
|
print_file(file, indent, "MIDL_memset(__frame->_StubMsg.Buffer, 0, (0x%x - (ULONG_PTR)__frame->_StubMsg.Buffer) & 0x%x);\n", alignment, alignment - 1);
|
|
|
|
print_file(file, indent, "__frame->_StubMsg.Buffer = (unsigned char *)(((ULONG_PTR)__frame->_StubMsg.Buffer + %u) & ~0x%x);\n",
|
|
|
|
alignment - 1, alignment - 1);
|
2006-03-31 13:48:24 +02:00
|
|
|
|
2009-11-07 15:54:56 +01:00
|
|
|
if (phase == PHASE_MARSHAL)
|
|
|
|
{
|
|
|
|
print_file(file, indent, "*(");
|
|
|
|
write_type_decl(file, is_ptr(type) ? type_pointer_get_ref(type) : type, NULL);
|
|
|
|
if (is_ptr(type))
|
|
|
|
fprintf(file, " *)__frame->_StubMsg.Buffer = *");
|
|
|
|
else
|
|
|
|
fprintf(file, " *)__frame->_StubMsg.Buffer = ");
|
|
|
|
fprintf(file, "%s%s", local_var_prefix, varname);
|
|
|
|
fprintf(file, ";\n");
|
|
|
|
}
|
|
|
|
else if (phase == PHASE_UNMARSHAL)
|
|
|
|
{
|
|
|
|
print_file(file, indent, "if (__frame->_StubMsg.Buffer + sizeof(");
|
|
|
|
write_type_decl(file, is_ptr(type) ? type_pointer_get_ref(type) : type, NULL);
|
|
|
|
fprintf(file, ") > __frame->_StubMsg.BufferEnd)\n");
|
|
|
|
print_file(file, indent, "{\n");
|
|
|
|
print_file(file, indent + 1, "RpcRaiseException(RPC_X_BAD_STUB_DATA);\n");
|
|
|
|
print_file(file, indent, "}\n");
|
|
|
|
print_file(file, indent, "%s%s%s",
|
|
|
|
(pass == PASS_IN || pass == PASS_RETURN) ? "" : "*",
|
|
|
|
local_var_prefix, varname);
|
|
|
|
if (pass == PASS_IN && is_ptr(type))
|
|
|
|
fprintf(file, " = (");
|
|
|
|
else
|
|
|
|
fprintf(file, " = *(");
|
|
|
|
write_type_decl(file, is_ptr(type) ? type_pointer_get_ref(type) : type, NULL);
|
|
|
|
fprintf(file, " *)__frame->_StubMsg.Buffer;\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
print_file(file, indent, "__frame->_StubMsg.Buffer += sizeof(");
|
2009-01-06 00:34:58 +01:00
|
|
|
write_type_decl(file, is_ptr(type) ? type_pointer_get_ref(type) : type, NULL);
|
2009-11-07 15:54:56 +01:00
|
|
|
fprintf(file, ");\n");
|
2006-03-31 13:48:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-31 13:47:08 +02:00
|
|
|
/* returns whether the MaxCount, Offset or ActualCount members need to be
|
|
|
|
* filled in for the specified phase */
|
2008-07-03 10:11:00 +02:00
|
|
|
static inline int is_conformance_needed_for_phase(enum remoting_phase phase)
|
2006-03-31 13:47:08 +02:00
|
|
|
{
|
|
|
|
return (phase != PHASE_UNMARSHAL);
|
|
|
|
}
|
|
|
|
|
2007-11-02 23:25:26 +01:00
|
|
|
expr_t *get_size_is_expr(const type_t *t, const char *name)
|
|
|
|
{
|
|
|
|
expr_t *x = NULL;
|
|
|
|
|
2009-01-06 00:34:52 +01:00
|
|
|
for ( ; is_array(t); t = type_array_get_element(t))
|
2010-03-23 14:33:17 +01:00
|
|
|
if (type_array_has_conformance(t) &&
|
|
|
|
type_array_get_conformance(t)->type != EXPR_VOID)
|
2007-11-02 23:25:26 +01:00
|
|
|
{
|
|
|
|
if (!x)
|
2009-01-06 00:33:36 +01:00
|
|
|
x = type_array_get_conformance(t);
|
2007-11-02 23:25:26 +01:00
|
|
|
else
|
|
|
|
error("%s: multidimensional conformant"
|
|
|
|
" arrays not supported at the top level\n",
|
|
|
|
name);
|
|
|
|
}
|
|
|
|
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2011-07-27 16:04:22 +02:00
|
|
|
void write_parameter_conf_or_var_exprs(FILE *file, int indent, const char *local_var_prefix,
|
|
|
|
enum remoting_phase phase, const var_t *var, int valid_variance)
|
2008-07-03 10:11:00 +02:00
|
|
|
{
|
|
|
|
const type_t *type = var->type;
|
|
|
|
/* get fundamental type for the argument */
|
|
|
|
for (;;)
|
|
|
|
{
|
2010-03-15 20:31:10 +01:00
|
|
|
switch (typegen_detect_type(type, var->attrs, TDT_IGNORE_STRINGS|TDT_IGNORE_RANGES))
|
2008-07-03 10:11:00 +02:00
|
|
|
{
|
2010-03-15 20:31:10 +01:00
|
|
|
case TGT_ARRAY:
|
|
|
|
if (is_conformance_needed_for_phase(phase))
|
2008-07-03 10:11:00 +02:00
|
|
|
{
|
2010-03-23 14:33:17 +01:00
|
|
|
if (type_array_has_conformance(type) &&
|
|
|
|
type_array_get_conformance(type)->type != EXPR_VOID)
|
2008-07-03 10:11:00 +02:00
|
|
|
{
|
2008-12-15 20:08:39 +01:00
|
|
|
print_file(file, indent, "__frame->_StubMsg.MaxCount = (ULONG_PTR)");
|
2009-01-06 00:33:36 +01:00
|
|
|
write_expr(file, type_array_get_conformance(type), 1, 1, NULL, NULL, local_var_prefix);
|
2008-07-03 10:11:00 +02:00
|
|
|
fprintf(file, ";\n\n");
|
|
|
|
}
|
2009-01-06 00:33:36 +01:00
|
|
|
if (type_array_has_variance(type))
|
2008-07-03 10:11:00 +02:00
|
|
|
{
|
2008-12-15 20:08:39 +01:00
|
|
|
print_file(file, indent, "__frame->_StubMsg.Offset = 0;\n"); /* FIXME */
|
2011-07-27 16:04:22 +02:00
|
|
|
if (valid_variance)
|
|
|
|
{
|
|
|
|
print_file(file, indent, "__frame->_StubMsg.ActualCount = (ULONG_PTR)");
|
|
|
|
write_expr(file, type_array_get_variance(type), 1, 1, NULL, NULL, local_var_prefix);
|
|
|
|
fprintf(file, ";\n\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
print_file(file, indent, "__frame->_StubMsg.ActualCount = __frame->_StubMsg.MaxCount;\n\n");
|
2008-07-03 10:11:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2010-03-15 20:31:10 +01:00
|
|
|
case TGT_UNION:
|
|
|
|
if (type_get_type(type) == TYPE_UNION &&
|
|
|
|
is_conformance_needed_for_phase(phase))
|
2008-07-03 10:11:00 +02:00
|
|
|
{
|
2008-12-15 20:08:39 +01:00
|
|
|
print_file(file, indent, "__frame->_StubMsg.MaxCount = (ULONG_PTR)");
|
2008-09-15 16:46:01 +02:00
|
|
|
write_expr(file, get_attrp(var->attrs, ATTR_SWITCHIS), 1, 1, NULL, NULL, local_var_prefix);
|
2008-07-03 10:11:00 +02:00
|
|
|
fprintf(file, ";\n\n");
|
|
|
|
}
|
|
|
|
break;
|
2010-03-15 20:31:10 +01:00
|
|
|
case TGT_IFACE_POINTER:
|
2008-07-03 10:11:00 +02:00
|
|
|
{
|
|
|
|
expr_t *iid;
|
|
|
|
|
|
|
|
if (is_conformance_needed_for_phase(phase) && (iid = get_attrp( var->attrs, ATTR_IIDIS )))
|
|
|
|
{
|
2008-12-15 20:08:39 +01:00
|
|
|
print_file( file, indent, "__frame->_StubMsg.MaxCount = (ULONG_PTR) " );
|
2008-09-15 16:46:01 +02:00
|
|
|
write_expr( file, iid, 1, 1, NULL, NULL, local_var_prefix );
|
2008-07-03 10:11:00 +02:00
|
|
|
fprintf( file, ";\n\n" );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2010-03-15 20:31:10 +01:00
|
|
|
case TGT_POINTER:
|
2009-01-06 00:34:58 +01:00
|
|
|
type = type_pointer_get_ref(type);
|
2010-03-15 20:31:10 +01:00
|
|
|
continue;
|
|
|
|
case TGT_INVALID:
|
|
|
|
case TGT_USER_TYPE:
|
|
|
|
case TGT_CTXT_HANDLE:
|
|
|
|
case TGT_CTXT_HANDLE_POINTER:
|
|
|
|
case TGT_STRING:
|
|
|
|
case TGT_BASIC:
|
|
|
|
case TGT_ENUM:
|
|
|
|
case TGT_STRUCT:
|
|
|
|
case TGT_RANGE:
|
2008-07-03 10:11:00 +02:00
|
|
|
break;
|
2010-03-15 20:31:10 +01:00
|
|
|
}
|
|
|
|
break;
|
2008-07-03 10:11:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-06 00:33:27 +01:00
|
|
|
static void write_remoting_arg(FILE *file, int indent, const var_t *func, const char *local_var_prefix,
|
2008-09-15 16:46:01 +02:00
|
|
|
enum pass pass, enum remoting_phase phase, const var_t *var)
|
2005-12-08 12:52:13 +01:00
|
|
|
{
|
2007-06-06 03:50:31 +02:00
|
|
|
int in_attr, out_attr, pointer_type;
|
2011-05-24 23:10:48 +02:00
|
|
|
const char *type_str = NULL;
|
2007-12-10 15:24:11 +01:00
|
|
|
const type_t *type = var->type;
|
2011-05-24 22:47:07 +02:00
|
|
|
unsigned int alignment, start_offset = type->typestring_offset;
|
2005-12-08 12:52:13 +01:00
|
|
|
|
2009-03-08 00:23:44 +01:00
|
|
|
if (is_ptr(type) || is_array(type))
|
|
|
|
pointer_type = get_pointer_fc(type, var->attrs, pass != PASS_RETURN);
|
|
|
|
else
|
|
|
|
pointer_type = 0;
|
2005-12-08 12:52:13 +01:00
|
|
|
|
2007-12-10 15:24:11 +01:00
|
|
|
in_attr = is_attr(var->attrs, ATTR_IN);
|
|
|
|
out_attr = is_attr(var->attrs, ATTR_OUT);
|
|
|
|
if (!in_attr && !out_attr)
|
|
|
|
in_attr = 1;
|
2007-01-24 20:02:05 +01:00
|
|
|
|
2007-12-19 15:52:13 +01:00
|
|
|
if (phase != PHASE_FREE)
|
2007-12-10 15:24:11 +01:00
|
|
|
switch (pass)
|
|
|
|
{
|
|
|
|
case PASS_IN:
|
|
|
|
if (!in_attr) return;
|
|
|
|
break;
|
|
|
|
case PASS_OUT:
|
|
|
|
if (!out_attr) return;
|
|
|
|
break;
|
|
|
|
case PASS_RETURN:
|
|
|
|
break;
|
|
|
|
}
|
2005-12-26 13:14:28 +01:00
|
|
|
|
2011-05-24 22:47:07 +02:00
|
|
|
if (phase == PHASE_BUFFERSIZE && get_required_buffer_size( var, &alignment, pass )) return;
|
|
|
|
|
2011-07-27 16:04:22 +02:00
|
|
|
write_parameter_conf_or_var_exprs(file, indent, local_var_prefix, phase, var, TRUE);
|
2005-12-26 13:14:28 +01:00
|
|
|
|
2009-02-23 14:48:46 +01:00
|
|
|
switch (typegen_detect_type(type, var->attrs, TDT_ALL_TYPES))
|
2007-12-10 15:24:11 +01:00
|
|
|
{
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_CTXT_HANDLE:
|
|
|
|
case TGT_CTXT_HANDLE_POINTER:
|
2007-12-10 15:24:11 +01:00
|
|
|
if (phase == PHASE_MARSHAL)
|
2005-12-26 13:14:28 +01:00
|
|
|
{
|
2007-12-10 15:24:11 +01:00
|
|
|
if (pass == PASS_IN)
|
|
|
|
{
|
2008-03-27 15:03:23 +01:00
|
|
|
/* if the context_handle attribute appears in the chain of types
|
|
|
|
* without pointers being followed, then the context handle must
|
|
|
|
* be direct, otherwise it is a pointer */
|
2012-08-14 23:56:28 +02:00
|
|
|
const char *ch_ptr = is_aliaschain_attr(type, ATTR_CONTEXTHANDLE) ? "" : "*";
|
2007-12-10 15:24:11 +01:00
|
|
|
print_file(file, indent, "NdrClientContextMarshall(\n");
|
2008-09-15 14:02:26 +02:00
|
|
|
print_file(file, indent + 1, "&__frame->_StubMsg,\n");
|
2012-08-14 23:56:28 +02:00
|
|
|
print_file(file, indent + 1, "(NDR_CCONTEXT)%s%s%s,\n", ch_ptr, local_var_prefix,
|
|
|
|
var->name);
|
2007-12-10 15:24:11 +01:00
|
|
|
print_file(file, indent + 1, "%s);\n", in_attr && out_attr ? "1" : "0");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-01-06 22:21:03 +01:00
|
|
|
print_file(file, indent, "NdrServerContextNewMarshall(\n");
|
2008-09-15 14:02:26 +02:00
|
|
|
print_file(file, indent + 1, "&__frame->_StubMsg,\n");
|
2008-09-15 16:46:01 +02:00
|
|
|
print_file(file, indent + 1, "(NDR_SCONTEXT)%s%s,\n", local_var_prefix, var->name);
|
2008-01-06 22:21:03 +01:00
|
|
|
print_file(file, indent + 1, "(NDR_RUNDOWN)%s_rundown,\n", get_context_handle_type_name(var->type));
|
|
|
|
print_file(file, indent + 1, "(PFORMAT_STRING)&__MIDL_TypeFormatString.Format[%d]);\n", start_offset);
|
2007-12-10 15:24:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (phase == PHASE_UNMARSHAL)
|
|
|
|
{
|
2019-01-30 13:48:46 +01:00
|
|
|
if (pass == PASS_OUT || pass == PASS_RETURN)
|
2007-12-10 15:24:11 +01:00
|
|
|
{
|
2008-01-20 11:56:15 +01:00
|
|
|
if (!in_attr)
|
2008-09-15 16:46:01 +02:00
|
|
|
print_file(file, indent, "*%s%s = 0;\n", local_var_prefix, var->name);
|
2007-12-10 15:24:11 +01:00
|
|
|
print_file(file, indent, "NdrClientContextUnmarshall(\n");
|
2008-09-15 14:02:26 +02:00
|
|
|
print_file(file, indent + 1, "&__frame->_StubMsg,\n");
|
2019-01-30 13:48:46 +01:00
|
|
|
print_file(file, indent + 1, "(NDR_CCONTEXT *)%s%s%s,\n",
|
|
|
|
pass == PASS_RETURN ? "&" : "", local_var_prefix, var->name);
|
2008-09-15 18:03:56 +02:00
|
|
|
print_file(file, indent + 1, "__frame->_Handle);\n");
|
2007-12-10 15:24:11 +01:00
|
|
|
}
|
|
|
|
else
|
2008-01-06 22:21:03 +01:00
|
|
|
{
|
2008-09-15 16:46:01 +02:00
|
|
|
print_file(file, indent, "%s%s = NdrServerContextNewUnmarshall(\n", local_var_prefix, var->name);
|
2008-09-15 14:02:26 +02:00
|
|
|
print_file(file, indent + 1, "&__frame->_StubMsg,\n");
|
2008-01-06 22:21:03 +01:00
|
|
|
print_file(file, indent + 1, "(PFORMAT_STRING)&__MIDL_TypeFormatString.Format[%d]);\n", start_offset);
|
|
|
|
}
|
2005-12-26 13:14:28 +01:00
|
|
|
}
|
2009-02-23 14:48:46 +01:00
|
|
|
break;
|
|
|
|
case TGT_USER_TYPE:
|
2008-09-15 16:46:01 +02:00
|
|
|
print_phase_function(file, indent, "UserMarshal", local_var_prefix, phase, var, start_offset);
|
2009-02-23 14:48:46 +01:00
|
|
|
break;
|
|
|
|
case TGT_STRING:
|
2009-02-14 19:11:35 +01:00
|
|
|
if (phase == PHASE_FREE || pass == PASS_RETURN ||
|
2018-06-13 04:19:11 +02:00
|
|
|
pointer_type != FC_RP)
|
2009-02-14 19:11:35 +01:00
|
|
|
{
|
2011-06-20 13:51:27 +02:00
|
|
|
/* strings returned are assumed to be global and hence don't
|
|
|
|
* need freeing */
|
|
|
|
if (is_declptr(type) && !(phase == PHASE_FREE && pass == PASS_RETURN))
|
|
|
|
print_phase_function(file, indent, "Pointer", local_var_prefix,
|
|
|
|
phase, var, start_offset);
|
2018-06-13 04:19:11 +02:00
|
|
|
else if (pointer_type == FC_RP && phase == PHASE_FREE &&
|
2009-03-20 17:15:46 +01:00
|
|
|
!in_attr && is_conformant_array(type))
|
|
|
|
{
|
|
|
|
print_file(file, indent, "if (%s%s)\n", local_var_prefix, var->name);
|
|
|
|
indent++;
|
|
|
|
print_file(file, indent, "__frame->_StubMsg.pfnFree(%s%s);\n", local_var_prefix, var->name);
|
|
|
|
}
|
2009-02-14 19:11:35 +01:00
|
|
|
}
|
2007-09-13 01:08:43 +02:00
|
|
|
else
|
2007-12-10 15:24:11 +01:00
|
|
|
{
|
2009-03-08 00:23:54 +01:00
|
|
|
unsigned int real_start_offset = start_offset;
|
|
|
|
/* skip over pointer description straight to string description */
|
|
|
|
if (is_declptr(type))
|
|
|
|
{
|
|
|
|
if (is_conformant_array(type))
|
|
|
|
real_start_offset += 4;
|
|
|
|
else
|
|
|
|
real_start_offset += 2;
|
|
|
|
}
|
2009-02-14 19:11:35 +01:00
|
|
|
if (is_array(type) && !is_conformant_array(type))
|
|
|
|
print_phase_function(file, indent, "NonConformantString",
|
|
|
|
local_var_prefix, phase, var,
|
2009-03-08 00:23:54 +01:00
|
|
|
real_start_offset);
|
2007-12-10 15:24:11 +01:00
|
|
|
else
|
2008-09-15 16:46:01 +02:00
|
|
|
print_phase_function(file, indent, "ConformantString", local_var_prefix,
|
2009-03-08 00:23:54 +01:00
|
|
|
phase, var, real_start_offset);
|
2007-12-10 15:24:11 +01:00
|
|
|
}
|
2009-02-23 14:48:46 +01:00
|
|
|
break;
|
|
|
|
case TGT_ARRAY:
|
2009-02-23 14:48:34 +01:00
|
|
|
{
|
|
|
|
unsigned char tc = get_array_fc(type);
|
2010-03-15 20:31:00 +01:00
|
|
|
const char *array_type = NULL;
|
2006-03-31 13:45:16 +02:00
|
|
|
|
2007-12-10 15:24:11 +01:00
|
|
|
/* We already have the size_is expression since it's at the
|
|
|
|
top level, but do checks for multidimensional conformant
|
|
|
|
arrays. When we handle them, we'll need to extend this
|
|
|
|
function to return a list, and then we'll actually use
|
|
|
|
the return value. */
|
|
|
|
get_size_is_expr(type, var->name);
|
|
|
|
|
2010-03-15 20:31:00 +01:00
|
|
|
switch (tc)
|
2007-09-28 02:38:27 +02:00
|
|
|
{
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_SMFARRAY:
|
|
|
|
case FC_LGFARRAY:
|
2010-03-15 20:31:00 +01:00
|
|
|
array_type = "FixedArray";
|
|
|
|
break;
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_SMVARRAY:
|
|
|
|
case FC_LGVARRAY:
|
2007-12-10 15:24:11 +01:00
|
|
|
array_type = "VaryingArray";
|
2010-03-15 20:31:00 +01:00
|
|
|
break;
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_CARRAY:
|
2007-12-10 15:24:11 +01:00
|
|
|
array_type = "ConformantArray";
|
2010-03-15 20:31:00 +01:00
|
|
|
break;
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_CVARRAY:
|
2010-03-15 20:31:00 +01:00
|
|
|
array_type = "ConformantVaryingArray";
|
|
|
|
break;
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_BOGUS_ARRAY:
|
2010-03-15 20:31:00 +01:00
|
|
|
array_type = "ComplexArray";
|
|
|
|
break;
|
2006-01-24 11:09:53 +01:00
|
|
|
}
|
2007-12-10 15:24:11 +01:00
|
|
|
|
2018-06-13 04:19:11 +02:00
|
|
|
if (pointer_type != FC_RP) array_type = "Pointer";
|
2011-06-20 13:51:27 +02:00
|
|
|
|
2018-06-13 04:19:11 +02:00
|
|
|
if (phase == PHASE_FREE && pointer_type == FC_RP)
|
2005-12-26 13:12:03 +01:00
|
|
|
{
|
2008-01-07 11:17:32 +01:00
|
|
|
/* these are all unmarshalled by allocating memory */
|
2018-06-13 04:19:11 +02:00
|
|
|
if (tc == FC_BOGUS_ARRAY ||
|
|
|
|
tc == FC_CVARRAY ||
|
|
|
|
((tc == FC_SMVARRAY || tc == FC_LGVARRAY) && in_attr) ||
|
|
|
|
(tc == FC_CARRAY && !in_attr))
|
2005-12-26 13:12:03 +01:00
|
|
|
{
|
2011-06-20 13:51:27 +02:00
|
|
|
if (type_array_is_decl_as_ptr(type) && type->details.array.ptr_tfsoff)
|
|
|
|
{
|
|
|
|
print_phase_function(file, indent, "Pointer", local_var_prefix, phase, var,
|
|
|
|
type->details.array.ptr_tfsoff);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
print_phase_function(file, indent, array_type, local_var_prefix, phase, var, start_offset);
|
2008-09-15 16:46:01 +02:00
|
|
|
print_file(file, indent, "if (%s%s)\n", local_var_prefix, var->name);
|
2007-12-10 15:24:11 +01:00
|
|
|
indent++;
|
2008-09-15 16:46:01 +02:00
|
|
|
print_file(file, indent, "__frame->_StubMsg.pfnFree(%s%s);\n", local_var_prefix, var->name);
|
2011-06-20 13:51:27 +02:00
|
|
|
break;
|
2005-12-26 13:12:03 +01:00
|
|
|
}
|
|
|
|
}
|
2011-06-20 13:51:27 +02:00
|
|
|
print_phase_function(file, indent, array_type, local_var_prefix, phase, var, start_offset);
|
2009-02-23 14:48:34 +01:00
|
|
|
break;
|
2007-12-10 15:24:11 +01:00
|
|
|
}
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_BASIC:
|
2009-11-07 15:54:56 +01:00
|
|
|
print_phase_basetype(file, indent, local_var_prefix, phase, pass, var, var->name);
|
2009-02-23 14:48:34 +01:00
|
|
|
break;
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_ENUM:
|
2009-11-07 15:54:56 +01:00
|
|
|
print_phase_basetype(file, indent, local_var_prefix, phase, pass, var, var->name);
|
2009-02-23 14:48:34 +01:00
|
|
|
break;
|
2009-11-07 15:54:28 +01:00
|
|
|
case TGT_RANGE:
|
2009-11-07 15:54:56 +01:00
|
|
|
print_phase_basetype(file, indent, local_var_prefix, phase, pass, var, var->name);
|
2009-11-07 15:54:28 +01:00
|
|
|
/* Note: this goes beyond what MIDL does - it only supports arguments
|
|
|
|
* with the [range] attribute in Oicf mode */
|
|
|
|
if (phase == PHASE_UNMARSHAL)
|
|
|
|
{
|
|
|
|
const expr_t *range_min;
|
|
|
|
const expr_t *range_max;
|
|
|
|
expr_list_t *range_list = get_attrp(var->attrs, ATTR_RANGE);
|
|
|
|
if (!range_list)
|
|
|
|
range_list = get_aliaschain_attrp(type, ATTR_RANGE);
|
|
|
|
range_min = LIST_ENTRY(list_head(range_list), const expr_t, entry);
|
|
|
|
range_max = LIST_ENTRY(list_next(range_list, list_head(range_list)), const expr_t, entry);
|
|
|
|
|
|
|
|
print_file(file, indent, "if ((%s%s < (", local_var_prefix, var->name);
|
|
|
|
write_type_decl(file, var->type, NULL);
|
2010-03-26 11:42:28 +01:00
|
|
|
fprintf(file, ")0x%x) || (%s%s > (", range_min->cval, local_var_prefix, var->name);
|
2009-11-07 15:54:28 +01:00
|
|
|
write_type_decl(file, var->type, NULL);
|
2010-03-26 11:42:28 +01:00
|
|
|
fprintf(file, ")0x%x))\n", range_max->cval);
|
2009-11-07 15:54:28 +01:00
|
|
|
print_file(file, indent, "{\n");
|
|
|
|
print_file(file, indent+1, "RpcRaiseException(RPC_S_INVALID_BOUND);\n");
|
|
|
|
print_file(file, indent, "}\n");
|
|
|
|
}
|
|
|
|
break;
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_STRUCT:
|
2009-02-23 14:48:34 +01:00
|
|
|
switch (get_struct_fc(type))
|
2005-12-26 13:09:36 +01:00
|
|
|
{
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_STRUCT:
|
2009-02-14 19:11:00 +01:00
|
|
|
if (phase == PHASE_MARSHAL || phase == PHASE_UNMARSHAL)
|
|
|
|
print_phase_function(file, indent, "SimpleStruct", local_var_prefix, phase, var, start_offset);
|
|
|
|
break;
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_PSTRUCT:
|
2008-09-15 16:46:01 +02:00
|
|
|
print_phase_function(file, indent, "SimpleStruct", local_var_prefix, phase, var, start_offset);
|
2007-12-10 15:24:11 +01:00
|
|
|
break;
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_CSTRUCT:
|
|
|
|
case FC_CPSTRUCT:
|
2008-09-15 16:46:01 +02:00
|
|
|
print_phase_function(file, indent, "ConformantStruct", local_var_prefix, phase, var, start_offset);
|
2007-12-10 15:24:11 +01:00
|
|
|
break;
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_CVSTRUCT:
|
2008-09-15 16:46:01 +02:00
|
|
|
print_phase_function(file, indent, "ConformantVaryingStruct", local_var_prefix, phase, var, start_offset);
|
2007-12-10 15:24:11 +01:00
|
|
|
break;
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_BOGUS_STRUCT:
|
2008-09-15 16:46:01 +02:00
|
|
|
print_phase_function(file, indent, "ComplexStruct", local_var_prefix, phase, var, start_offset);
|
2007-12-10 15:24:11 +01:00
|
|
|
break;
|
|
|
|
default:
|
2009-02-23 14:48:34 +01:00
|
|
|
error("write_remoting_arguments: Unsupported type: %s (0x%02x)\n", var->name, get_struct_fc(type));
|
2007-12-10 15:24:11 +01:00
|
|
|
}
|
2009-02-23 14:48:34 +01:00
|
|
|
break;
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_UNION:
|
2009-02-14 19:11:00 +01:00
|
|
|
{
|
|
|
|
const char *union_type = NULL;
|
|
|
|
|
2009-02-23 14:48:34 +01:00
|
|
|
if (type_get_type(type) == TYPE_UNION)
|
2009-02-14 19:11:00 +01:00
|
|
|
union_type = "NonEncapsulatedUnion";
|
2009-02-23 14:48:34 +01:00
|
|
|
else if (type_get_type(type) == TYPE_ENCAPSULATED_UNION)
|
2009-02-14 19:11:00 +01:00
|
|
|
union_type = "EncapsulatedUnion";
|
|
|
|
|
|
|
|
print_phase_function(file, indent, union_type, local_var_prefix,
|
|
|
|
phase, var, start_offset);
|
2009-02-23 14:48:34 +01:00
|
|
|
break;
|
2009-02-14 19:11:00 +01:00
|
|
|
}
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_POINTER:
|
2007-12-10 15:24:11 +01:00
|
|
|
{
|
2009-01-06 00:34:58 +01:00
|
|
|
const type_t *ref = type_pointer_get_ref(type);
|
2018-06-13 04:19:11 +02:00
|
|
|
if (pointer_type == FC_RP) switch (typegen_detect_type(ref, NULL, TDT_ALL_TYPES))
|
2007-12-10 15:24:11 +01:00
|
|
|
{
|
2009-11-07 15:54:28 +01:00
|
|
|
case TGT_BASIC:
|
2009-11-07 15:54:56 +01:00
|
|
|
print_phase_basetype(file, indent, local_var_prefix, phase, pass, var, var->name);
|
2009-02-23 14:48:34 +01:00
|
|
|
break;
|
2009-11-07 15:54:28 +01:00
|
|
|
case TGT_ENUM:
|
2009-02-23 14:48:34 +01:00
|
|
|
/* base types have known sizes, so don't need a sizing pass
|
|
|
|
* and don't have any memory to free and so don't need a
|
|
|
|
* freeing pass */
|
|
|
|
if (phase == PHASE_MARSHAL || phase == PHASE_UNMARSHAL)
|
|
|
|
print_phase_function(file, indent, "Pointer", local_var_prefix, phase, var, start_offset);
|
|
|
|
break;
|
2009-11-07 15:54:28 +01:00
|
|
|
case TGT_STRUCT:
|
2009-02-23 14:48:34 +01:00
|
|
|
switch (get_struct_fc(ref))
|
2009-02-14 19:11:00 +01:00
|
|
|
{
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_STRUCT:
|
2009-02-14 19:11:00 +01:00
|
|
|
/* simple structs have known sizes, so don't need a sizing
|
|
|
|
* pass and don't have any memory to free and so don't
|
|
|
|
* need a freeing pass */
|
|
|
|
if (phase == PHASE_MARSHAL || phase == PHASE_UNMARSHAL)
|
2011-05-24 23:10:48 +02:00
|
|
|
type_str = "SimpleStruct";
|
2009-03-08 00:23:48 +01:00
|
|
|
else if (phase == PHASE_FREE && pass == PASS_RETURN)
|
|
|
|
{
|
|
|
|
print_file(file, indent, "if (%s%s)\n", local_var_prefix, var->name);
|
|
|
|
indent++;
|
|
|
|
print_file(file, indent, "__frame->_StubMsg.pfnFree(%s%s);\n", local_var_prefix, var->name);
|
|
|
|
indent--;
|
|
|
|
}
|
2009-02-14 19:11:00 +01:00
|
|
|
break;
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_PSTRUCT:
|
2011-05-24 23:10:48 +02:00
|
|
|
type_str = "SimpleStruct";
|
2009-02-14 19:11:00 +01:00
|
|
|
break;
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_CSTRUCT:
|
|
|
|
case FC_CPSTRUCT:
|
2011-05-24 23:10:48 +02:00
|
|
|
type_str = "ConformantStruct";
|
2009-02-14 19:11:00 +01:00
|
|
|
break;
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_CVSTRUCT:
|
2011-05-24 23:10:48 +02:00
|
|
|
type_str = "ConformantVaryingStruct";
|
2009-02-14 19:11:00 +01:00
|
|
|
break;
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_BOGUS_STRUCT:
|
2011-05-24 23:10:48 +02:00
|
|
|
type_str = "ComplexStruct";
|
2009-02-14 19:11:00 +01:00
|
|
|
break;
|
|
|
|
default:
|
2009-02-23 14:48:34 +01:00
|
|
|
error("write_remoting_arguments: Unsupported type: %s (0x%02x)\n", var->name, get_struct_fc(ref));
|
2009-02-14 19:11:00 +01:00
|
|
|
}
|
|
|
|
|
2011-05-24 23:10:48 +02:00
|
|
|
if (type_str)
|
2009-02-14 19:11:00 +01:00
|
|
|
{
|
|
|
|
if (phase == PHASE_FREE)
|
2011-05-24 23:10:48 +02:00
|
|
|
type_str = "Pointer";
|
2009-02-14 19:11:00 +01:00
|
|
|
else
|
|
|
|
start_offset = ref->typestring_offset;
|
2011-05-24 23:10:48 +02:00
|
|
|
print_phase_function(file, indent, type_str, local_var_prefix, phase, var, start_offset);
|
2009-02-14 19:11:00 +01:00
|
|
|
}
|
2009-02-23 14:48:34 +01:00
|
|
|
break;
|
2009-11-07 15:54:28 +01:00
|
|
|
case TGT_UNION:
|
2009-02-14 19:11:00 +01:00
|
|
|
if (phase == PHASE_FREE)
|
2011-05-24 23:10:48 +02:00
|
|
|
type_str = "Pointer";
|
2009-02-14 19:11:00 +01:00
|
|
|
else
|
|
|
|
{
|
2009-02-23 14:48:34 +01:00
|
|
|
if (type_get_type(ref) == TYPE_UNION)
|
2011-05-24 23:10:48 +02:00
|
|
|
type_str = "NonEncapsulatedUnion";
|
2009-02-23 14:48:34 +01:00
|
|
|
else if (type_get_type(ref) == TYPE_ENCAPSULATED_UNION)
|
2011-05-24 23:10:48 +02:00
|
|
|
type_str = "EncapsulatedUnion";
|
2009-02-14 19:11:00 +01:00
|
|
|
|
|
|
|
start_offset = ref->typestring_offset;
|
|
|
|
}
|
|
|
|
|
2011-05-24 23:10:48 +02:00
|
|
|
print_phase_function(file, indent, type_str, local_var_prefix,
|
2009-02-14 19:11:00 +01:00
|
|
|
phase, var, start_offset);
|
2009-02-23 14:48:34 +01:00
|
|
|
break;
|
2011-05-24 23:10:48 +02:00
|
|
|
case TGT_USER_TYPE:
|
|
|
|
if (phase != PHASE_FREE)
|
|
|
|
{
|
|
|
|
type_str = "UserMarshal";
|
|
|
|
start_offset = ref->typestring_offset;
|
|
|
|
}
|
|
|
|
else type_str = "Pointer";
|
|
|
|
|
|
|
|
print_phase_function(file, indent, type_str, local_var_prefix, phase, var, start_offset);
|
|
|
|
break;
|
2009-11-07 15:54:28 +01:00
|
|
|
case TGT_STRING:
|
|
|
|
case TGT_POINTER:
|
|
|
|
case TGT_ARRAY:
|
|
|
|
case TGT_RANGE:
|
|
|
|
case TGT_IFACE_POINTER:
|
|
|
|
case TGT_CTXT_HANDLE:
|
|
|
|
case TGT_CTXT_HANDLE_POINTER:
|
2009-02-23 14:48:34 +01:00
|
|
|
print_phase_function(file, indent, "Pointer", local_var_prefix, phase, var, start_offset);
|
|
|
|
break;
|
2009-11-07 15:54:28 +01:00
|
|
|
case TGT_INVALID:
|
2009-02-23 14:48:34 +01:00
|
|
|
assert(0);
|
|
|
|
break;
|
2005-12-08 12:52:13 +01:00
|
|
|
}
|
2009-02-23 14:48:34 +01:00
|
|
|
else
|
|
|
|
print_phase_function(file, indent, "Pointer", local_var_prefix, phase, var, start_offset);
|
|
|
|
break;
|
|
|
|
}
|
2009-02-23 14:48:46 +01:00
|
|
|
case TGT_IFACE_POINTER:
|
|
|
|
print_phase_function(file, indent, "InterfacePointer", local_var_prefix, phase, var, start_offset);
|
|
|
|
break;
|
|
|
|
case TGT_INVALID:
|
2009-02-23 14:48:34 +01:00
|
|
|
assert(0);
|
|
|
|
break;
|
2007-12-10 15:24:11 +01:00
|
|
|
}
|
|
|
|
fprintf(file, "\n");
|
|
|
|
}
|
|
|
|
|
2009-01-06 00:33:27 +01:00
|
|
|
void write_remoting_arguments(FILE *file, int indent, const var_t *func, const char *local_var_prefix,
|
2007-12-10 15:24:11 +01:00
|
|
|
enum pass pass, enum remoting_phase phase)
|
|
|
|
{
|
|
|
|
if (phase == PHASE_BUFFERSIZE && pass != PASS_RETURN)
|
|
|
|
{
|
|
|
|
unsigned int size = get_function_buffer_size( func, pass );
|
2008-09-15 14:02:26 +02:00
|
|
|
print_file(file, indent, "__frame->_StubMsg.BufferLength = %u;\n", size);
|
2007-12-10 15:24:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pass == PASS_RETURN)
|
|
|
|
{
|
2011-09-17 13:38:15 +02:00
|
|
|
write_remoting_arg( file, indent, func, local_var_prefix, pass, phase,
|
|
|
|
type_function_get_retval(func->type) );
|
2007-12-10 15:24:11 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const var_t *var;
|
2009-01-06 00:33:27 +01:00
|
|
|
if (!type_get_function_args(func->type))
|
2007-12-10 15:24:11 +01:00
|
|
|
return;
|
2009-01-06 00:33:27 +01:00
|
|
|
LIST_FOR_EACH_ENTRY( var, type_get_function_args(func->type), const var_t, entry )
|
2008-09-15 16:46:01 +02:00
|
|
|
write_remoting_arg( file, indent, func, local_var_prefix, pass, phase, var );
|
2005-12-08 12:52:13 +01:00
|
|
|
}
|
|
|
|
}
|
2005-12-26 13:05:29 +01:00
|
|
|
|
|
|
|
|
2011-06-01 21:06:14 +02:00
|
|
|
unsigned int get_size_procformatstring_func(const type_t *iface, const var_t *func)
|
2007-01-24 20:05:22 +01:00
|
|
|
{
|
2010-10-16 13:51:50 +02:00
|
|
|
unsigned int offset = 0;
|
2011-06-01 21:06:14 +02:00
|
|
|
write_procformatstring_func( NULL, 0, iface, func, &offset, 0 );
|
2010-10-16 13:51:50 +02:00
|
|
|
return offset;
|
2007-01-24 20:05:22 +01:00
|
|
|
}
|
|
|
|
|
2018-11-07 16:14:42 +01:00
|
|
|
static void get_size_procformatstring_iface(type_t *iface, FILE *file, int indent, unsigned int *size)
|
2006-03-23 10:33:08 +01:00
|
|
|
{
|
2008-04-24 20:06:28 +02:00
|
|
|
const statement_t *stmt;
|
2018-11-07 16:14:42 +01:00
|
|
|
STATEMENTS_FOR_EACH_FUNC( stmt, type_iface_get_stmts(iface) )
|
2006-03-23 10:33:08 +01:00
|
|
|
{
|
2018-11-07 16:14:42 +01:00
|
|
|
const var_t *func = stmt->u.var;
|
|
|
|
if (!is_local(func->attrs))
|
|
|
|
*size += get_size_procformatstring_func( iface, func );
|
2006-03-23 10:33:08 +01:00
|
|
|
}
|
2018-11-07 16:14:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int get_size_procformatstring(const statement_list_t *stmts, type_pred_t pred)
|
|
|
|
{
|
|
|
|
unsigned int size = 1;
|
|
|
|
for_each_iface(stmts, get_size_procformatstring_iface, pred, NULL, 0, &size);
|
2006-03-23 10:33:08 +01:00
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2009-02-06 14:30:38 +01:00
|
|
|
unsigned int get_size_typeformatstring(const statement_list_t *stmts, type_pred_t pred)
|
2006-03-23 10:33:08 +01:00
|
|
|
{
|
2007-10-09 01:47:28 +02:00
|
|
|
set_all_tfswrite(FALSE);
|
2008-04-24 20:06:28 +02:00
|
|
|
return process_tfs(NULL, stmts, pred);
|
2006-03-23 10:33:08 +01:00
|
|
|
}
|
|
|
|
|
2009-01-06 00:33:27 +01:00
|
|
|
void declare_stub_args( FILE *file, int indent, const var_t *func )
|
2007-01-24 19:59:16 +01:00
|
|
|
{
|
|
|
|
int in_attr, out_attr;
|
|
|
|
int i = 0;
|
2011-09-17 13:38:15 +02:00
|
|
|
const var_t *var = type_function_get_retval(func->type);
|
2007-01-24 19:59:16 +01:00
|
|
|
|
2011-09-17 13:38:15 +02:00
|
|
|
/* declare return value */
|
|
|
|
if (!is_void(var->type))
|
2007-01-24 19:59:16 +01:00
|
|
|
{
|
2019-01-30 13:48:46 +01:00
|
|
|
if (is_context_handle(var->type))
|
|
|
|
print_file(file, indent, "NDR_SCONTEXT %s;\n", var->name);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
print_file(file, indent, "%s", "");
|
|
|
|
write_type_decl(file, var->type, var->name);
|
|
|
|
fprintf(file, ";\n");
|
|
|
|
}
|
2007-01-24 19:59:16 +01:00
|
|
|
}
|
|
|
|
|
2009-01-06 00:33:27 +01:00
|
|
|
if (!type_get_function_args(func->type))
|
2007-01-24 19:59:16 +01:00
|
|
|
return;
|
|
|
|
|
2009-01-06 00:33:27 +01:00
|
|
|
LIST_FOR_EACH_ENTRY( var, type_get_function_args(func->type), const var_t, entry )
|
2007-01-24 19:59:16 +01:00
|
|
|
{
|
|
|
|
in_attr = is_attr(var->attrs, ATTR_IN);
|
|
|
|
out_attr = is_attr(var->attrs, ATTR_OUT);
|
|
|
|
if (!out_attr && !in_attr)
|
|
|
|
in_attr = 1;
|
|
|
|
|
2007-09-28 02:38:27 +02:00
|
|
|
if (is_context_handle(var->type))
|
|
|
|
print_file(file, indent, "NDR_SCONTEXT %s;\n", var->name);
|
|
|
|
else
|
2007-01-24 19:59:16 +01:00
|
|
|
{
|
2009-03-20 17:15:46 +01:00
|
|
|
if (!in_attr && !is_conformant_array(var->type))
|
2007-09-28 02:38:27 +02:00
|
|
|
{
|
2009-01-06 00:34:58 +01:00
|
|
|
type_t *type_to_print;
|
2009-02-10 12:32:36 +01:00
|
|
|
char name[16];
|
2009-02-06 14:31:29 +01:00
|
|
|
print_file(file, indent, "%s", "");
|
2009-03-05 09:21:35 +01:00
|
|
|
if (type_get_type(var->type) == TYPE_ARRAY &&
|
|
|
|
!type_array_is_decl_as_ptr(var->type))
|
2009-01-06 00:34:58 +01:00
|
|
|
type_to_print = var->type;
|
|
|
|
else
|
|
|
|
type_to_print = type_pointer_get_ref(var->type);
|
2009-02-10 12:32:36 +01:00
|
|
|
sprintf(name, "_W%u", i++);
|
|
|
|
write_type_decl(file, type_to_print, name);
|
2007-09-28 02:38:27 +02:00
|
|
|
fprintf(file, ";\n");
|
|
|
|
}
|
|
|
|
|
2009-02-06 14:31:29 +01:00
|
|
|
print_file(file, indent, "%s", "");
|
2007-10-03 06:39:38 +02:00
|
|
|
write_type_decl_left(file, var->type);
|
2007-09-28 02:38:27 +02:00
|
|
|
fprintf(file, " ");
|
2009-03-05 09:21:35 +01:00
|
|
|
if (type_get_type(var->type) == TYPE_ARRAY &&
|
|
|
|
!type_array_is_decl_as_ptr(var->type)) {
|
2008-09-15 16:46:01 +02:00
|
|
|
fprintf(file, "(*%s)", var->name);
|
2007-09-28 02:38:27 +02:00
|
|
|
} else
|
2008-09-15 16:46:01 +02:00
|
|
|
fprintf(file, "%s", var->name);
|
2007-09-28 02:38:27 +02:00
|
|
|
write_type_right(file, var->type, FALSE);
|
2007-06-06 03:50:31 +02:00
|
|
|
fprintf(file, ";\n");
|
2007-01-24 19:59:16 +01:00
|
|
|
|
2007-09-28 02:38:27 +02:00
|
|
|
if (decl_indirect(var->type))
|
2008-09-15 16:46:33 +02:00
|
|
|
print_file(file, indent, "void *_p_%s;\n", var->name);
|
2007-09-28 02:38:27 +02:00
|
|
|
}
|
2007-01-24 19:59:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-06 00:33:27 +01:00
|
|
|
void assign_stub_out_args( FILE *file, int indent, const var_t *func, const char *local_var_prefix )
|
2007-01-24 19:59:16 +01:00
|
|
|
{
|
|
|
|
int in_attr, out_attr;
|
|
|
|
int i = 0, sep = 0;
|
|
|
|
const var_t *var;
|
2011-12-13 16:29:49 +01:00
|
|
|
type_t *ref;
|
2007-01-24 19:59:16 +01:00
|
|
|
|
2009-01-06 00:33:27 +01:00
|
|
|
if (!type_get_function_args(func->type))
|
2007-01-24 19:59:16 +01:00
|
|
|
return;
|
|
|
|
|
2009-01-06 00:33:27 +01:00
|
|
|
LIST_FOR_EACH_ENTRY( var, type_get_function_args(func->type), const var_t, entry )
|
2007-01-24 19:59:16 +01:00
|
|
|
{
|
|
|
|
in_attr = is_attr(var->attrs, ATTR_IN);
|
|
|
|
out_attr = is_attr(var->attrs, ATTR_OUT);
|
|
|
|
if (!out_attr && !in_attr)
|
|
|
|
in_attr = 1;
|
|
|
|
|
|
|
|
if (!in_attr)
|
|
|
|
{
|
2008-09-15 16:46:01 +02:00
|
|
|
print_file(file, indent, "%s%s", local_var_prefix, var->name);
|
2007-01-24 19:59:16 +01:00
|
|
|
|
2010-03-23 14:33:08 +01:00
|
|
|
switch (typegen_detect_type(var->type, var->attrs, TDT_IGNORE_STRINGS))
|
2007-12-25 20:08:21 +01:00
|
|
|
{
|
2010-03-23 14:33:08 +01:00
|
|
|
case TGT_CTXT_HANDLE_POINTER:
|
2007-12-25 20:08:21 +01:00
|
|
|
fprintf(file, " = NdrContextHandleInitialize(\n");
|
2008-09-15 14:02:26 +02:00
|
|
|
print_file(file, indent + 1, "&__frame->_StubMsg,\n");
|
2007-12-25 20:08:21 +01:00
|
|
|
print_file(file, indent + 1, "(PFORMAT_STRING)&__MIDL_TypeFormatString.Format[%d]);\n",
|
2011-09-19 12:23:01 +02:00
|
|
|
var->typestring_offset);
|
2010-03-23 14:33:08 +01:00
|
|
|
break;
|
|
|
|
case TGT_ARRAY:
|
|
|
|
if (type_array_has_conformance(var->type))
|
2007-02-06 15:59:24 +01:00
|
|
|
{
|
2010-04-05 19:48:07 +02:00
|
|
|
unsigned int size;
|
2011-03-02 12:14:36 +01:00
|
|
|
type_t *type;
|
2010-03-23 14:33:08 +01:00
|
|
|
|
|
|
|
fprintf(file, " = NdrAllocate(&__frame->_StubMsg, ");
|
2011-03-02 12:14:36 +01:00
|
|
|
for (type = var->type;
|
|
|
|
is_array(type) && type_array_has_conformance(type);
|
|
|
|
type = type_array_get_element(type))
|
|
|
|
{
|
|
|
|
write_expr(file, type_array_get_conformance(type), TRUE,
|
|
|
|
TRUE, NULL, NULL, local_var_prefix);
|
|
|
|
fprintf(file, " * ");
|
|
|
|
}
|
|
|
|
size = type_memsize(type);
|
|
|
|
fprintf(file, "%u);\n", size);
|
|
|
|
|
|
|
|
print_file(file, indent, "memset(%s%s, 0, ", local_var_prefix, var->name);
|
|
|
|
for (type = var->type;
|
2010-03-23 14:33:08 +01:00
|
|
|
is_array(type) && type_array_has_conformance(type);
|
|
|
|
type = type_array_get_element(type))
|
|
|
|
{
|
|
|
|
write_expr(file, type_array_get_conformance(type), TRUE,
|
|
|
|
TRUE, NULL, NULL, local_var_prefix);
|
|
|
|
fprintf(file, " * ");
|
|
|
|
}
|
2010-04-05 19:48:07 +02:00
|
|
|
size = type_memsize(type);
|
2010-03-23 14:33:08 +01:00
|
|
|
fprintf(file, "%u);\n", size);
|
2007-02-06 15:59:24 +01:00
|
|
|
}
|
2010-03-23 14:33:08 +01:00
|
|
|
else
|
|
|
|
fprintf(file, " = &%s_W%u;\n", local_var_prefix, i++);
|
|
|
|
break;
|
|
|
|
case TGT_POINTER:
|
2008-09-15 16:46:01 +02:00
|
|
|
fprintf(file, " = &%s_W%u;\n", local_var_prefix, i);
|
2011-12-13 16:29:49 +01:00
|
|
|
ref = type_pointer_get_ref(var->type);
|
|
|
|
switch (typegen_detect_type(ref, var->attrs, TDT_IGNORE_STRINGS))
|
2009-03-20 17:16:25 +01:00
|
|
|
{
|
|
|
|
case TGT_BASIC:
|
|
|
|
case TGT_ENUM:
|
|
|
|
case TGT_POINTER:
|
2009-11-07 15:54:28 +01:00
|
|
|
case TGT_RANGE:
|
2011-02-02 13:16:29 +01:00
|
|
|
case TGT_IFACE_POINTER:
|
2008-09-15 16:46:01 +02:00
|
|
|
print_file(file, indent, "%s_W%u = 0;\n", local_var_prefix, i);
|
2009-03-20 17:16:25 +01:00
|
|
|
break;
|
2011-02-02 13:16:29 +01:00
|
|
|
case TGT_USER_TYPE:
|
|
|
|
print_file(file, indent, "memset(&%s_W%u, 0, sizeof(%s_W%u));\n",
|
|
|
|
local_var_prefix, i, local_var_prefix, i);
|
|
|
|
break;
|
2011-12-13 16:29:49 +01:00
|
|
|
case TGT_ARRAY:
|
|
|
|
if (type_array_is_decl_as_ptr(ref))
|
|
|
|
{
|
|
|
|
print_file(file, indent, "%s_W%u = 0;\n", local_var_prefix, i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ref = type_array_get_element(ref);
|
|
|
|
/* fall through */
|
2009-03-20 17:16:25 +01:00
|
|
|
case TGT_STRUCT:
|
|
|
|
case TGT_UNION:
|
2011-12-13 16:29:49 +01:00
|
|
|
if (type_has_pointers(ref))
|
|
|
|
print_file(file, indent, "memset(&%s_W%u, 0, sizeof(%s_W%u));\n",
|
|
|
|
local_var_prefix, i, local_var_prefix, i);
|
|
|
|
break;
|
2009-03-20 17:16:25 +01:00
|
|
|
case TGT_CTXT_HANDLE:
|
|
|
|
case TGT_CTXT_HANDLE_POINTER:
|
|
|
|
case TGT_INVALID:
|
|
|
|
case TGT_STRING:
|
|
|
|
/* not initialised */
|
|
|
|
break;
|
|
|
|
}
|
2007-01-24 19:59:16 +01:00
|
|
|
i++;
|
2010-03-23 14:33:08 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2007-01-24 19:59:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sep = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sep)
|
|
|
|
fprintf(file, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-09 11:42:21 +02:00
|
|
|
void write_func_param_struct( FILE *file, const type_t *iface, const type_t *func,
|
|
|
|
const char *var_decl, int add_retval )
|
2011-06-07 12:00:50 +02:00
|
|
|
{
|
2011-09-17 13:38:15 +02:00
|
|
|
var_t *retval = type_function_get_retval( func );
|
2011-06-07 12:00:50 +02:00
|
|
|
const var_list_t *args = type_get_function_args( func );
|
|
|
|
const var_t *arg;
|
2011-06-09 12:03:54 +02:00
|
|
|
int needs_packing;
|
|
|
|
unsigned int align = 0;
|
|
|
|
|
|
|
|
if (args)
|
|
|
|
LIST_FOR_EACH_ENTRY( arg, args, const var_t, entry )
|
|
|
|
if (!is_array( arg->type )) type_memsize_and_alignment( arg->type, &align );
|
|
|
|
|
|
|
|
needs_packing = (align > pointer_size);
|
2011-06-07 12:00:50 +02:00
|
|
|
|
2011-06-09 12:03:54 +02:00
|
|
|
if (needs_packing) print_file( file, 0, "#include <pshpack%u.h>\n", pointer_size );
|
2011-06-07 12:00:50 +02:00
|
|
|
print_file(file, 1, "struct _PARAM_STRUCT\n" );
|
|
|
|
print_file(file, 1, "{\n" );
|
|
|
|
if (is_object( iface )) print_file(file, 2, "%s *This;\n", iface->name );
|
|
|
|
|
|
|
|
if (args) LIST_FOR_EACH_ENTRY( arg, args, const var_t, entry )
|
|
|
|
{
|
|
|
|
print_file(file, 2, "%s", "");
|
2015-08-07 15:41:55 +02:00
|
|
|
write_type_left( file, (type_t *)arg->type, NAME_DEFAULT, TRUE );
|
2011-06-07 12:00:50 +02:00
|
|
|
if (needs_space_after( arg->type )) fputc( ' ', file );
|
|
|
|
if (is_array( arg->type ) && !type_array_is_decl_as_ptr( arg->type )) fputc( '*', file );
|
2011-06-09 12:03:54 +02:00
|
|
|
|
2011-06-07 12:00:50 +02:00
|
|
|
/* FIXME: should check for large args being passed by pointer */
|
2011-06-09 12:03:54 +02:00
|
|
|
align = 0;
|
|
|
|
if (is_array( arg->type ) || is_ptr( arg->type )) align = pointer_size;
|
|
|
|
else type_memsize_and_alignment( arg->type, &align );
|
|
|
|
|
|
|
|
if (align >= pointer_size)
|
2011-06-07 12:00:50 +02:00
|
|
|
fprintf( file, "%s;\n", arg->name );
|
|
|
|
else
|
|
|
|
fprintf( file, "%s DECLSPEC_ALIGN(%u);\n", arg->name, pointer_size );
|
|
|
|
}
|
2011-09-17 13:38:15 +02:00
|
|
|
if (add_retval && !is_void( retval->type ))
|
2011-06-07 12:00:50 +02:00
|
|
|
{
|
|
|
|
print_file(file, 2, "%s", "");
|
2011-09-17 13:38:15 +02:00
|
|
|
write_type_decl( file, retval->type, retval->name );
|
|
|
|
if (is_array( retval->type ) || is_ptr( retval->type ) ||
|
|
|
|
type_memsize( retval->type ) == pointer_size)
|
2011-06-09 11:42:21 +02:00
|
|
|
fprintf( file, ";\n" );
|
|
|
|
else
|
|
|
|
fprintf( file, " DECLSPEC_ALIGN(%u);\n", pointer_size );
|
2011-06-07 12:00:50 +02:00
|
|
|
}
|
2011-06-09 12:03:54 +02:00
|
|
|
print_file(file, 1, "} %s;\n", var_decl );
|
|
|
|
if (needs_packing) print_file( file, 0, "#include <poppack.h>\n" );
|
|
|
|
print_file( file, 0, "\n" );
|
2011-06-07 12:00:50 +02:00
|
|
|
}
|
|
|
|
|
2011-06-14 12:55:39 +02:00
|
|
|
void write_pointer_checks( FILE *file, int indent, const var_t *func )
|
|
|
|
{
|
|
|
|
const var_list_t *args = type_get_function_args( func->type );
|
|
|
|
const var_t *var;
|
|
|
|
|
|
|
|
if (!args) return;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY( var, args, const var_t, entry )
|
|
|
|
if (cant_be_null( var ))
|
|
|
|
print_file( file, indent, "if (!%s) RpcRaiseException(RPC_X_NULL_REF_POINTER);\n", var->name );
|
|
|
|
}
|
|
|
|
|
2006-01-27 12:53:32 +01:00
|
|
|
int write_expr_eval_routines(FILE *file, const char *iface)
|
|
|
|
{
|
2007-09-04 18:33:23 +02:00
|
|
|
static const char *var_name = "pS";
|
2008-04-22 12:37:07 +02:00
|
|
|
static const char *var_name_expr = "pS->";
|
2006-01-27 12:53:32 +01:00
|
|
|
int result = 0;
|
|
|
|
struct expr_eval_routine *eval;
|
|
|
|
unsigned short callback_offset = 0;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(eval, &expr_eval_routines, struct expr_eval_routine, entry)
|
|
|
|
{
|
2011-05-26 21:34:51 +02:00
|
|
|
const char *name = eval->name;
|
2006-01-27 12:53:32 +01:00
|
|
|
result = 1;
|
2007-09-04 18:33:23 +02:00
|
|
|
|
|
|
|
print_file(file, 0, "static void __RPC_USER %s_%sExprEval_%04u(PMIDL_STUB_MESSAGE pStubMsg)\n",
|
2011-06-13 23:59:04 +02:00
|
|
|
eval->iface ? eval->iface->name : iface, name, callback_offset);
|
2007-09-04 18:33:23 +02:00
|
|
|
print_file(file, 0, "{\n");
|
2011-05-26 21:34:51 +02:00
|
|
|
if (type_get_type( eval->cont_type ) == TYPE_FUNCTION)
|
|
|
|
{
|
2011-06-09 11:42:21 +02:00
|
|
|
write_func_param_struct( file, eval->iface, eval->cont_type,
|
|
|
|
"*pS = (struct _PARAM_STRUCT *)pStubMsg->StackTop", FALSE );
|
2011-05-26 21:34:51 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
print_file(file, 1, "%s", "");
|
2015-08-07 15:41:55 +02:00
|
|
|
write_type_left(file, (type_t *)eval->cont_type, NAME_DEFAULT, TRUE);
|
2011-05-26 21:34:51 +02:00
|
|
|
fprintf(file, " *%s = (", var_name);
|
2015-08-07 15:41:55 +02:00
|
|
|
write_type_left(file, (type_t *)eval->cont_type, NAME_DEFAULT, TRUE);
|
2011-05-26 21:34:51 +02:00
|
|
|
fprintf(file, " *)(pStubMsg->StackTop - %u);\n", eval->baseoff);
|
|
|
|
}
|
2007-09-04 18:33:23 +02:00
|
|
|
print_file(file, 1, "pStubMsg->Offset = 0;\n"); /* FIXME */
|
2008-12-15 20:08:39 +01:00
|
|
|
print_file(file, 1, "pStubMsg->MaxCount = (ULONG_PTR)");
|
2011-05-26 21:34:51 +02:00
|
|
|
write_expr(file, eval->expr, 1, 1, var_name_expr, eval->cont_type, "");
|
2006-01-27 12:53:32 +01:00
|
|
|
fprintf(file, ";\n");
|
2007-09-04 18:33:23 +02:00
|
|
|
print_file(file, 0, "}\n\n");
|
2006-01-27 12:53:32 +01:00
|
|
|
callback_offset++;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void write_expr_eval_routine_list(FILE *file, const char *iface)
|
|
|
|
{
|
|
|
|
struct expr_eval_routine *eval;
|
|
|
|
struct expr_eval_routine *cursor;
|
|
|
|
unsigned short callback_offset = 0;
|
|
|
|
|
|
|
|
fprintf(file, "static const EXPR_EVAL ExprEvalRoutines[] =\n");
|
|
|
|
fprintf(file, "{\n");
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(eval, cursor, &expr_eval_routines, struct expr_eval_routine, entry)
|
|
|
|
{
|
2011-06-13 23:59:04 +02:00
|
|
|
print_file(file, 1, "%s_%sExprEval_%04u,\n",
|
|
|
|
eval->iface ? eval->iface->name : iface, eval->name, callback_offset);
|
2006-01-27 12:53:32 +01:00
|
|
|
callback_offset++;
|
|
|
|
list_remove(&eval->entry);
|
2011-05-26 21:34:51 +02:00
|
|
|
free(eval->name);
|
2006-01-27 12:53:32 +01:00
|
|
|
free(eval);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(file, "};\n\n");
|
|
|
|
}
|
2007-02-07 17:55:09 +01:00
|
|
|
|
2007-06-14 01:13:04 +02:00
|
|
|
void write_user_quad_list(FILE *file)
|
|
|
|
{
|
|
|
|
user_type_t *ut;
|
|
|
|
|
|
|
|
if (list_empty(&user_type_list))
|
|
|
|
return;
|
|
|
|
|
|
|
|
fprintf(file, "static const USER_MARSHAL_ROUTINE_QUADRUPLE UserMarshalRoutines[] =\n");
|
|
|
|
fprintf(file, "{\n");
|
|
|
|
LIST_FOR_EACH_ENTRY(ut, &user_type_list, user_type_t, entry)
|
|
|
|
{
|
|
|
|
const char *sep = &ut->entry == list_tail(&user_type_list) ? "" : ",";
|
|
|
|
print_file(file, 1, "{\n");
|
2007-06-14 12:10:45 +02:00
|
|
|
print_file(file, 2, "(USER_MARSHAL_SIZING_ROUTINE)%s_UserSize,\n", ut->name);
|
|
|
|
print_file(file, 2, "(USER_MARSHAL_MARSHALLING_ROUTINE)%s_UserMarshal,\n", ut->name);
|
|
|
|
print_file(file, 2, "(USER_MARSHAL_UNMARSHALLING_ROUTINE)%s_UserUnmarshal,\n", ut->name);
|
|
|
|
print_file(file, 2, "(USER_MARSHAL_FREEING_ROUTINE)%s_UserFree\n", ut->name);
|
2007-06-14 01:13:04 +02:00
|
|
|
print_file(file, 1, "}%s\n", sep);
|
|
|
|
}
|
|
|
|
fprintf(file, "};\n\n");
|
|
|
|
}
|
2007-02-07 17:55:09 +01:00
|
|
|
|
|
|
|
void write_endpoints( FILE *f, const char *prefix, const str_list_t *list )
|
|
|
|
{
|
|
|
|
const struct str_list_entry_t *endpoint;
|
|
|
|
const char *p;
|
|
|
|
|
|
|
|
/* this should be an array of RPC_PROTSEQ_ENDPOINT but we want const strings */
|
2008-11-11 06:06:43 +01:00
|
|
|
print_file( f, 0, "static const unsigned char * const %s__RpcProtseqEndpoint[][2] =\n{\n", prefix );
|
2007-02-07 17:55:09 +01:00
|
|
|
LIST_FOR_EACH_ENTRY( endpoint, list, const struct str_list_entry_t, entry )
|
|
|
|
{
|
|
|
|
print_file( f, 1, "{ (const unsigned char *)\"" );
|
|
|
|
for (p = endpoint->str; *p && *p != ':'; p++)
|
|
|
|
{
|
|
|
|
if (*p == '"' || *p == '\\') fputc( '\\', f );
|
|
|
|
fputc( *p, f );
|
|
|
|
}
|
|
|
|
if (!*p) goto error;
|
|
|
|
if (p[1] != '[') goto error;
|
|
|
|
|
|
|
|
fprintf( f, "\", (const unsigned char *)\"" );
|
|
|
|
for (p += 2; *p && *p != ']'; p++)
|
|
|
|
{
|
|
|
|
if (*p == '"' || *p == '\\') fputc( '\\', f );
|
|
|
|
fputc( *p, f );
|
|
|
|
}
|
|
|
|
if (*p != ']') goto error;
|
|
|
|
fprintf( f, "\" },\n" );
|
|
|
|
}
|
|
|
|
print_file( f, 0, "};\n\n" );
|
|
|
|
return;
|
|
|
|
|
|
|
|
error:
|
|
|
|
error("Invalid endpoint syntax '%s'\n", endpoint->str);
|
|
|
|
}
|
2008-09-15 14:05:26 +02:00
|
|
|
|
2011-06-09 10:12:48 +02:00
|
|
|
void write_client_call_routine( FILE *file, const type_t *iface, const var_t *func,
|
|
|
|
const char *prefix, unsigned int proc_offset )
|
|
|
|
{
|
|
|
|
type_t *rettype = type_function_get_rettype( func->type );
|
|
|
|
int has_ret = !is_void( rettype );
|
|
|
|
const var_list_t *args = type_get_function_args( func->type );
|
|
|
|
const var_t *arg;
|
2011-06-09 11:42:21 +02:00
|
|
|
int len, needs_params = 0;
|
|
|
|
|
|
|
|
/* we need a param structure if we have more than one arg */
|
|
|
|
if (pointer_size == 4 && args) needs_params = is_object( iface ) || list_count( args ) > 1;
|
2011-06-09 10:12:48 +02:00
|
|
|
|
|
|
|
print_file( file, 0, "{\n");
|
2011-06-09 11:42:21 +02:00
|
|
|
if (needs_params)
|
|
|
|
{
|
|
|
|
if (has_ret) print_file( file, 1, "%s", "CLIENT_CALL_RETURN _RetVal;\n" );
|
|
|
|
write_func_param_struct( file, iface, func->type, "__params", FALSE );
|
|
|
|
if (is_object( iface )) print_file( file, 1, "__params.This = This;\n" );
|
|
|
|
if (args)
|
|
|
|
LIST_FOR_EACH_ENTRY( arg, args, const var_t, entry )
|
|
|
|
print_file( file, 1, "__params.%s = %s;\n", arg->name, arg->name );
|
|
|
|
}
|
|
|
|
else if (has_ret) print_file( file, 1, "%s", "CLIENT_CALL_RETURN _RetVal;\n\n" );
|
|
|
|
|
2011-06-09 10:12:48 +02:00
|
|
|
len = fprintf( file, " %s%s( ",
|
|
|
|
has_ret ? "_RetVal = " : "",
|
|
|
|
get_stub_mode() == MODE_Oif ? "NdrClientCall2" : "NdrClientCall" );
|
|
|
|
fprintf( file, "&%s_StubDesc,", prefix );
|
|
|
|
fprintf( file, "\n%*s&__MIDL_ProcFormatString.Format[%u]", len, "", proc_offset );
|
2011-06-09 11:42:21 +02:00
|
|
|
if (needs_params)
|
|
|
|
{
|
|
|
|
fprintf( file, ",\n%*s&__params", len, "" );
|
|
|
|
}
|
|
|
|
else if (pointer_size == 8)
|
2011-06-09 10:12:48 +02:00
|
|
|
{
|
|
|
|
if (is_object( iface )) fprintf( file, ",\n%*sThis", len, "" );
|
|
|
|
if (args)
|
|
|
|
LIST_FOR_EACH_ENTRY( arg, args, const var_t, entry )
|
|
|
|
fprintf( file, ",\n%*s%s", len, "", arg->name );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (is_object( iface )) fprintf( file, ",\n%*s&This", len, "" );
|
|
|
|
else if (args)
|
|
|
|
{
|
|
|
|
arg = LIST_ENTRY( list_head(args), const var_t, entry );
|
|
|
|
fprintf( file, ",\n%*s&%s", len, "", arg->name );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf( file, " );\n" );
|
|
|
|
if (has_ret)
|
|
|
|
{
|
|
|
|
print_file( file, 1, "return (" );
|
|
|
|
write_type_decl_left(file, rettype);
|
|
|
|
fprintf( file, ")%s;\n", pointer_size == 8 ? "_RetVal.Simple" : "*(LONG_PTR *)&_RetVal" );
|
|
|
|
}
|
|
|
|
print_file( file, 0, "}\n\n");
|
|
|
|
}
|
|
|
|
|
2008-09-15 14:05:26 +02:00
|
|
|
void write_exceptions( FILE *file )
|
|
|
|
{
|
|
|
|
fprintf( file, "#ifndef USE_COMPILER_EXCEPTIONS\n");
|
|
|
|
fprintf( file, "\n");
|
|
|
|
fprintf( file, "#include \"wine/exception.h\"\n");
|
|
|
|
fprintf( file, "#undef RpcTryExcept\n");
|
|
|
|
fprintf( file, "#undef RpcExcept\n");
|
|
|
|
fprintf( file, "#undef RpcEndExcept\n");
|
|
|
|
fprintf( file, "#undef RpcTryFinally\n");
|
|
|
|
fprintf( file, "#undef RpcFinally\n");
|
|
|
|
fprintf( file, "#undef RpcEndFinally\n");
|
|
|
|
fprintf( file, "#undef RpcExceptionCode\n");
|
2008-09-15 18:18:16 +02:00
|
|
|
fprintf( file, "#undef RpcAbnormalTermination\n");
|
2008-09-15 14:05:26 +02:00
|
|
|
fprintf( file, "\n");
|
|
|
|
fprintf( file, "struct __exception_frame;\n");
|
2009-10-22 13:04:09 +02:00
|
|
|
fprintf( file, "typedef int (*__filter_func)(struct __exception_frame *);\n");
|
2008-09-15 14:05:26 +02:00
|
|
|
fprintf( file, "typedef void (*__finally_func)(struct __exception_frame *);\n");
|
|
|
|
fprintf( file, "\n");
|
|
|
|
fprintf( file, "#define __DECL_EXCEPTION_FRAME \\\n");
|
|
|
|
fprintf( file, " EXCEPTION_REGISTRATION_RECORD frame; \\\n");
|
|
|
|
fprintf( file, " __filter_func filter; \\\n");
|
|
|
|
fprintf( file, " __finally_func finally; \\\n");
|
|
|
|
fprintf( file, " sigjmp_buf jmp; \\\n");
|
|
|
|
fprintf( file, " DWORD code; \\\n");
|
2008-09-15 18:18:16 +02:00
|
|
|
fprintf( file, " unsigned char abnormal_termination; \\\n");
|
2008-09-15 14:05:26 +02:00
|
|
|
fprintf( file, " unsigned char filter_level; \\\n");
|
|
|
|
fprintf( file, " unsigned char finally_level;\n");
|
|
|
|
fprintf( file, "\n");
|
|
|
|
fprintf( file, "struct __exception_frame\n{\n");
|
2008-11-15 08:53:38 +01:00
|
|
|
fprintf( file, " __DECL_EXCEPTION_FRAME\n");
|
2008-09-15 14:05:26 +02:00
|
|
|
fprintf( file, "};\n");
|
|
|
|
fprintf( file, "\n");
|
2009-06-18 13:32:26 +02:00
|
|
|
fprintf( file, "static inline void __widl_unwind_target(void)\n" );
|
|
|
|
fprintf( file, "{\n");
|
|
|
|
fprintf( file, " struct __exception_frame *exc_frame = (struct __exception_frame *)__wine_get_frame();\n" );
|
|
|
|
fprintf( file, " if (exc_frame->finally_level > exc_frame->filter_level)\n" );
|
|
|
|
fprintf( file, " {\n");
|
|
|
|
fprintf( file, " exc_frame->abnormal_termination = 1;\n");
|
|
|
|
fprintf( file, " exc_frame->finally( exc_frame );\n");
|
|
|
|
fprintf( file, " __wine_pop_frame( &exc_frame->frame );\n");
|
|
|
|
fprintf( file, " }\n");
|
|
|
|
fprintf( file, " exc_frame->filter_level = 0;\n");
|
|
|
|
fprintf( file, " siglongjmp( exc_frame->jmp, 1 );\n");
|
|
|
|
fprintf( file, "}\n");
|
|
|
|
fprintf( file, "\n");
|
2019-05-30 12:13:21 +02:00
|
|
|
fprintf( file, "static DWORD __cdecl __widl_exception_handler( EXCEPTION_RECORD *record,\n");
|
|
|
|
fprintf( file, " EXCEPTION_REGISTRATION_RECORD *frame,\n");
|
|
|
|
fprintf( file, " CONTEXT *context,\n");
|
|
|
|
fprintf( file, " EXCEPTION_REGISTRATION_RECORD **pdispatcher )\n");
|
2008-09-15 14:05:26 +02:00
|
|
|
fprintf( file, "{\n");
|
|
|
|
fprintf( file, " struct __exception_frame *exc_frame = (struct __exception_frame *)frame;\n");
|
|
|
|
fprintf( file, "\n");
|
|
|
|
fprintf( file, " if (record->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND | EH_NESTED_CALL))\n");
|
|
|
|
fprintf( file, " {\n" );
|
|
|
|
fprintf( file, " if (exc_frame->finally_level && (record->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND)))\n");
|
2008-09-15 18:18:16 +02:00
|
|
|
fprintf( file, " {\n" );
|
|
|
|
fprintf( file, " exc_frame->abnormal_termination = 1;\n");
|
2008-09-15 14:05:26 +02:00
|
|
|
fprintf( file, " exc_frame->finally( exc_frame );\n");
|
2008-09-15 18:18:16 +02:00
|
|
|
fprintf( file, " }\n" );
|
2008-09-15 14:05:26 +02:00
|
|
|
fprintf( file, " return ExceptionContinueSearch;\n");
|
|
|
|
fprintf( file, " }\n" );
|
|
|
|
fprintf( file, " exc_frame->code = record->ExceptionCode;\n");
|
2009-10-22 13:04:09 +02:00
|
|
|
fprintf( file, " if (exc_frame->filter_level && exc_frame->filter( exc_frame ) == EXCEPTION_EXECUTE_HANDLER)\n" );
|
2009-06-18 13:32:26 +02:00
|
|
|
fprintf( file, " __wine_rtl_unwind( frame, record, __widl_unwind_target );\n");
|
2008-09-15 14:05:26 +02:00
|
|
|
fprintf( file, " return ExceptionContinueSearch;\n");
|
|
|
|
fprintf( file, "}\n");
|
|
|
|
fprintf( file, "\n");
|
|
|
|
fprintf( file, "#define RpcTryExcept \\\n");
|
|
|
|
fprintf( file, " if (!sigsetjmp( __frame->jmp, 0 )) \\\n");
|
|
|
|
fprintf( file, " { \\\n");
|
|
|
|
fprintf( file, " if (!__frame->finally_level) \\\n" );
|
|
|
|
fprintf( file, " __wine_push_frame( &__frame->frame ); \\\n");
|
|
|
|
fprintf( file, " __frame->filter_level = __frame->finally_level + 1;\n" );
|
|
|
|
fprintf( file, "\n");
|
|
|
|
fprintf( file, "#define RpcExcept(expr) \\\n");
|
|
|
|
fprintf( file, " if (!__frame->finally_level) \\\n" );
|
|
|
|
fprintf( file, " __wine_pop_frame( &__frame->frame ); \\\n");
|
|
|
|
fprintf( file, " __frame->filter_level = 0; \\\n" );
|
|
|
|
fprintf( file, " } \\\n");
|
|
|
|
fprintf( file, " else \\\n");
|
|
|
|
fprintf( file, "\n");
|
|
|
|
fprintf( file, "#define RpcEndExcept\n");
|
|
|
|
fprintf( file, "\n");
|
|
|
|
fprintf( file, "#define RpcExceptionCode() (__frame->code)\n");
|
|
|
|
fprintf( file, "\n");
|
|
|
|
fprintf( file, "#define RpcTryFinally \\\n");
|
|
|
|
fprintf( file, " if (!__frame->filter_level) \\\n");
|
|
|
|
fprintf( file, " __wine_push_frame( &__frame->frame ); \\\n");
|
|
|
|
fprintf( file, " __frame->finally_level = __frame->filter_level + 1;\n");
|
|
|
|
fprintf( file, "\n");
|
|
|
|
fprintf( file, "#define RpcFinally \\\n");
|
|
|
|
fprintf( file, " if (!__frame->filter_level) \\\n");
|
|
|
|
fprintf( file, " __wine_pop_frame( &__frame->frame ); \\\n");
|
|
|
|
fprintf( file, " __frame->finally_level = 0;\n");
|
|
|
|
fprintf( file, "\n");
|
|
|
|
fprintf( file, "#define RpcEndFinally\n");
|
|
|
|
fprintf( file, "\n");
|
2008-09-15 18:18:16 +02:00
|
|
|
fprintf( file, "#define RpcAbnormalTermination() (__frame->abnormal_termination)\n");
|
|
|
|
fprintf( file, "\n");
|
2008-09-15 14:05:26 +02:00
|
|
|
fprintf( file, "#define RpcExceptionInit(filter_func,finally_func) \\\n");
|
|
|
|
fprintf( file, " do { \\\n");
|
|
|
|
fprintf( file, " __frame->frame.Handler = __widl_exception_handler; \\\n");
|
|
|
|
fprintf( file, " __frame->filter = (__filter_func)(filter_func); \\\n" );
|
|
|
|
fprintf( file, " __frame->finally = (__finally_func)(finally_func); \\\n");
|
2008-09-15 18:18:16 +02:00
|
|
|
fprintf( file, " __frame->abnormal_termination = 0; \\\n");
|
2008-09-15 14:05:26 +02:00
|
|
|
fprintf( file, " __frame->filter_level = 0; \\\n");
|
|
|
|
fprintf( file, " __frame->finally_level = 0; \\\n");
|
|
|
|
fprintf( file, " } while (0)\n");
|
|
|
|
fprintf( file, "\n");
|
|
|
|
fprintf( file, "#else /* USE_COMPILER_EXCEPTIONS */\n");
|
|
|
|
fprintf( file, "\n");
|
2009-02-06 14:03:54 +01:00
|
|
|
fprintf( file, "#define RpcExceptionInit(filter_func,finally_func) \\\n");
|
|
|
|
fprintf( file, " do { (void)(filter_func); } while(0)\n");
|
|
|
|
fprintf( file, "\n");
|
2009-02-06 14:03:29 +01:00
|
|
|
fprintf( file, "#define __DECL_EXCEPTION_FRAME \\\n");
|
|
|
|
fprintf( file, " DWORD code;\n");
|
2008-09-15 14:05:26 +02:00
|
|
|
fprintf( file, "\n");
|
|
|
|
fprintf( file, "#endif /* USE_COMPILER_EXCEPTIONS */\n");
|
|
|
|
}
|