2010-07-20 23:22:59 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2010 Piotr Caban for CodeWeavers
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdlib.h"
|
2010-08-18 10:36:40 +02:00
|
|
|
#include "windef.h"
|
2010-07-20 23:22:59 +02:00
|
|
|
|
2011-05-27 14:34:27 +02:00
|
|
|
typedef unsigned char MSVCP_bool;
|
2011-05-27 14:56:18 +02:00
|
|
|
typedef SIZE_T MSVCP_size_t;
|
2011-08-23 11:50:56 +02:00
|
|
|
typedef SIZE_T streamoff;
|
|
|
|
typedef SIZE_T streamsize;
|
2010-07-20 23:22:59 +02:00
|
|
|
|
|
|
|
void __cdecl _invalid_parameter(const wchar_t*, const wchar_t*,
|
|
|
|
const wchar_t*, unsigned int, uintptr_t);
|
2010-07-22 09:40:19 +02:00
|
|
|
|
2011-05-27 14:56:18 +02:00
|
|
|
extern void* (__cdecl *MSVCRT_operator_new)(MSVCP_size_t);
|
2010-07-25 12:23:22 +02:00
|
|
|
extern void (__cdecl *MSVCRT_operator_delete)(void*);
|
2011-09-13 10:30:29 +02:00
|
|
|
extern void* (__cdecl *MSVCRT_set_new_handler)(void*);
|
2010-07-22 09:40:19 +02:00
|
|
|
|
|
|
|
/* Copied from dlls/msvcrt/cpp.c */
|
|
|
|
#ifdef __i386__ /* thiscall functions are i386-specific */
|
|
|
|
|
|
|
|
#define THISCALL(func) __thiscall_ ## func
|
2010-08-18 10:36:52 +02:00
|
|
|
#define THISCALL_NAME(func) __ASM_NAME("__thiscall_" #func)
|
2010-08-24 16:31:25 +02:00
|
|
|
#define __thiscall __stdcall
|
2010-07-22 09:40:19 +02:00
|
|
|
#define DEFINE_THISCALL_WRAPPER(func,args) \
|
|
|
|
extern void THISCALL(func)(void); \
|
|
|
|
__ASM_GLOBAL_FUNC(__thiscall_ ## func, \
|
|
|
|
"popl %eax\n\t" \
|
|
|
|
"pushl %ecx\n\t" \
|
|
|
|
"pushl %eax\n\t" \
|
|
|
|
"jmp " __ASM_NAME(#func) __ASM_STDCALL(args) )
|
2011-06-22 14:03:39 +02:00
|
|
|
|
|
|
|
#define DEFINE_THISCALL_WRAPPER_RETPTR(func,args) \
|
|
|
|
extern void THISCALL(func)(void); \
|
|
|
|
__ASM_GLOBAL_FUNC(__thiscall_ ## func, \
|
|
|
|
"popl %eax\n\t" \
|
|
|
|
"popl %edx\n\t" \
|
|
|
|
"pushl %ecx\n\t" \
|
|
|
|
"pushl %edx\n\t" \
|
|
|
|
"pushl %eax\n\t" \
|
|
|
|
"jmp " __ASM_NAME(#func) __ASM_STDCALL(args) )
|
2010-07-22 09:40:19 +02:00
|
|
|
#else /* __i386__ */
|
|
|
|
|
|
|
|
#define THISCALL(func) func
|
2010-08-18 10:36:52 +02:00
|
|
|
#define THISCALL_NAME(func) __ASM_NAME(#func)
|
2010-08-24 16:31:25 +02:00
|
|
|
#define __thiscall __cdecl
|
2010-07-22 09:40:19 +02:00
|
|
|
#define DEFINE_THISCALL_WRAPPER(func,args) /* nothing */
|
2011-06-22 14:03:39 +02:00
|
|
|
#define DEFINE_THISCALL_WRAPPER_RETPTR(func,args) /* nothing */
|
2010-07-22 09:40:19 +02:00
|
|
|
|
|
|
|
#endif /* __i386__ */
|
2010-08-18 10:36:40 +02:00
|
|
|
|
2011-05-27 14:34:27 +02:00
|
|
|
#ifdef _WIN64
|
|
|
|
|
|
|
|
#define __ASM_VTABLE(name,funcs) \
|
|
|
|
__asm__(".data\n" \
|
|
|
|
"\t.align 8\n" \
|
|
|
|
"\t.quad " __ASM_NAME(#name "_rtti") "\n" \
|
|
|
|
"\t.globl " __ASM_NAME("MSVCP_" #name "_vtable") "\n" \
|
|
|
|
__ASM_NAME("MSVCP_" #name "_vtable") ":\n" \
|
|
|
|
"\t.quad " THISCALL_NAME(MSVCP_ ## name ## _vector_dtor) "\n" \
|
|
|
|
funcs "\n\t.text");
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#define __ASM_VTABLE(name,funcs) \
|
|
|
|
__asm__(".data\n" \
|
|
|
|
"\t.align 4\n" \
|
|
|
|
"\t.long " __ASM_NAME(#name "_rtti") "\n" \
|
|
|
|
"\t.globl " __ASM_NAME("MSVCP_" #name "_vtable") "\n" \
|
|
|
|
__ASM_NAME("MSVCP_" #name "_vtable") ":\n" \
|
|
|
|
"\t.long " THISCALL_NAME(MSVCP_ ## name ## _vector_dtor) "\n" \
|
|
|
|
funcs "\n\t.text");
|
|
|
|
|
|
|
|
#endif /* _WIN64 */
|
|
|
|
|
2010-08-18 10:36:40 +02:00
|
|
|
/* exception object */
|
|
|
|
typedef void (*vtable_ptr)(void);
|
|
|
|
typedef struct __exception
|
|
|
|
{
|
|
|
|
const vtable_ptr *vtable;
|
|
|
|
char *name; /* Name of this exception, always a new copy for each object */
|
|
|
|
int do_free; /* Whether to free 'name' in our dtor */
|
|
|
|
} exception;
|
|
|
|
|
|
|
|
/* Internal: throws selected exception */
|
|
|
|
typedef enum __exception_type {
|
2010-08-18 10:36:52 +02:00
|
|
|
EXCEPTION,
|
2010-08-19 23:48:56 +02:00
|
|
|
EXCEPTION_BAD_ALLOC,
|
2010-08-19 23:49:08 +02:00
|
|
|
EXCEPTION_LOGIC_ERROR,
|
2010-08-19 23:49:18 +02:00
|
|
|
EXCEPTION_LENGTH_ERROR,
|
2010-08-23 16:34:15 +02:00
|
|
|
EXCEPTION_OUT_OF_RANGE,
|
|
|
|
EXCEPTION_INVALID_ARGUMENT
|
2010-08-18 10:36:40 +02:00
|
|
|
} exception_type;
|
|
|
|
void throw_exception(exception_type, const char *);
|
|
|
|
void set_exception_vtable(void);
|
2010-08-18 10:36:52 +02:00
|
|
|
|
|
|
|
/* rtti */
|
|
|
|
typedef struct __type_info
|
|
|
|
{
|
|
|
|
const vtable_ptr *vtable;
|
|
|
|
char *name; /* Unmangled name, allocated lazily */
|
2011-05-27 14:35:40 +02:00
|
|
|
char mangled[64]; /* Variable length, but we declare it large enough for static RTTI */
|
2010-08-18 10:36:52 +02:00
|
|
|
} type_info;
|
|
|
|
|
|
|
|
/* offsets for computing the this pointer */
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int this_offset; /* offset of base class this pointer from start of object */
|
|
|
|
int vbase_descr; /* offset of virtual base class descriptor */
|
|
|
|
int vbase_offset; /* offset of this pointer offset in virtual base class descriptor */
|
|
|
|
} this_ptr_offsets;
|
|
|
|
|
|
|
|
typedef struct _rtti_base_descriptor
|
|
|
|
{
|
|
|
|
const type_info *type_descriptor;
|
|
|
|
int num_base_classes;
|
|
|
|
this_ptr_offsets offsets; /* offsets for computing the this pointer */
|
|
|
|
unsigned int attributes;
|
|
|
|
} rtti_base_descriptor;
|
|
|
|
|
|
|
|
typedef struct _rtti_base_array
|
|
|
|
{
|
2011-08-24 14:38:11 +02:00
|
|
|
const rtti_base_descriptor *bases[4]; /* First element is the class itself */
|
2010-08-18 10:36:52 +02:00
|
|
|
} rtti_base_array;
|
|
|
|
|
|
|
|
typedef struct _rtti_object_hierarchy
|
|
|
|
{
|
|
|
|
unsigned int signature;
|
|
|
|
unsigned int attributes;
|
|
|
|
int array_len; /* Size of the array pointed to by 'base_classes' */
|
|
|
|
const rtti_base_array *base_classes;
|
|
|
|
} rtti_object_hierarchy;
|
|
|
|
|
|
|
|
typedef struct _rtti_object_locator
|
|
|
|
{
|
|
|
|
unsigned int signature;
|
|
|
|
int base_class_offset;
|
|
|
|
unsigned int flags;
|
|
|
|
const type_info *type_descriptor;
|
|
|
|
const rtti_object_hierarchy *type_hierarchy;
|
|
|
|
} rtti_object_locator;
|
2010-08-19 12:17:11 +02:00
|
|
|
|
|
|
|
/* basic_string<char, char_traits<char>, allocator<char>> */
|
|
|
|
#define BUF_SIZE_CHAR 16
|
|
|
|
typedef struct _basic_string_char
|
|
|
|
{
|
|
|
|
void *allocator;
|
2010-08-30 16:35:30 +02:00
|
|
|
union {
|
2010-08-19 12:17:11 +02:00
|
|
|
char buf[BUF_SIZE_CHAR];
|
|
|
|
char *ptr;
|
|
|
|
} data;
|
2011-05-27 14:56:18 +02:00
|
|
|
MSVCP_size_t size;
|
|
|
|
MSVCP_size_t res;
|
2010-08-19 12:17:11 +02:00
|
|
|
} basic_string_char;
|
|
|
|
|
2010-08-19 23:48:56 +02:00
|
|
|
basic_string_char* __stdcall MSVCP_basic_string_char_ctor_cstr(basic_string_char*, const char*);
|
|
|
|
basic_string_char* __stdcall MSVCP_basic_string_char_copy_ctor(basic_string_char*, const basic_string_char*);
|
|
|
|
void __stdcall MSVCP_basic_string_char_dtor(basic_string_char*);
|
|
|
|
const char* __stdcall MSVCP_basic_string_char_c_str(basic_string_char*);
|
|
|
|
|
2010-08-30 16:35:30 +02:00
|
|
|
#define BUF_SIZE_WCHAR 8
|
|
|
|
typedef struct _basic_string_wchar
|
|
|
|
{
|
|
|
|
void *allocator;
|
|
|
|
union {
|
|
|
|
wchar_t buf[BUF_SIZE_WCHAR];
|
|
|
|
wchar_t *ptr;
|
|
|
|
} data;
|
2011-05-27 14:56:18 +02:00
|
|
|
MSVCP_size_t size;
|
|
|
|
MSVCP_size_t res;
|
2010-08-30 16:35:30 +02:00
|
|
|
} basic_string_wchar;
|
|
|
|
|
2011-05-27 14:56:18 +02:00
|
|
|
char* __stdcall MSVCP_allocator_char_allocate(void*, MSVCP_size_t);
|
|
|
|
void __stdcall MSVCP_allocator_char_deallocate(void*, char*, MSVCP_size_t);
|
2011-10-14 15:01:22 +02:00
|
|
|
MSVCP_size_t __stdcall MSVCP_allocator_char_max_size(void*);
|
2011-05-27 14:56:18 +02:00
|
|
|
wchar_t* __stdcall MSVCP_allocator_wchar_allocate(void*, MSVCP_size_t);
|
|
|
|
void __stdcall MSVCP_allocator_wchar_deallocate(void*, wchar_t*, MSVCP_size_t);
|
2011-10-14 15:01:22 +02:00
|
|
|
MSVCP_size_t __stdcall MSVCP_allocator_wchar_max_size(void*);
|
2011-05-27 14:34:27 +02:00
|
|
|
|
|
|
|
/* class locale */
|
|
|
|
typedef struct
|
|
|
|
{
|
2011-06-22 14:03:39 +02:00
|
|
|
struct locale__Locimp *ptr;
|
2011-05-27 14:34:27 +02:00
|
|
|
} locale;
|
2011-06-22 14:03:54 +02:00
|
|
|
|
2011-08-24 14:38:53 +02:00
|
|
|
locale* __thiscall locale_ctor(locale*);
|
|
|
|
void __thiscall locale_dtor(locale*);
|
|
|
|
|
2011-06-22 14:03:54 +02:00
|
|
|
/* class _Lockit */
|
|
|
|
typedef struct {
|
|
|
|
int locktype;
|
|
|
|
} _Lockit;
|
|
|
|
|
2011-08-24 14:38:35 +02:00
|
|
|
#define _LOCK_LOCALE 0
|
|
|
|
#define _LOCK_MALLOC 1
|
|
|
|
#define _LOCK_STREAM 2
|
|
|
|
#define _LOCK_DEBUG 3
|
|
|
|
#define _MAX_LOCK 4
|
|
|
|
|
2011-06-22 14:03:54 +02:00
|
|
|
void init_lockit(void);
|
|
|
|
void free_lockit(void);
|
2011-08-24 14:38:35 +02:00
|
|
|
_Lockit* __thiscall _Lockit_ctor_locktype(_Lockit*, int);
|
|
|
|
void __thiscall _Lockit_dtor(_Lockit*);
|
2011-08-23 11:50:56 +02:00
|
|
|
|
|
|
|
/* class mutex */
|
|
|
|
typedef struct {
|
|
|
|
void *mutex;
|
|
|
|
} mutex;
|
2011-08-24 14:39:12 +02:00
|
|
|
|
|
|
|
mutex* __thiscall mutex_ctor(mutex*);
|
|
|
|
void __thiscall mutex_dtor(mutex*);
|
|
|
|
void __thiscall mutex_lock(mutex*);
|
|
|
|
void __thiscall mutex_unlock(mutex*);
|