memory.c 10.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/*
 * 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 <stdarg.h>
#include <limits.h>

#include "msvcp90.h"

#include "windef.h"
#include "winbase.h"
26

27 28

/* ?address@?$allocator@D@std@@QBEPADAAD@Z */
29
/* ?address@?$allocator@D@std@@QEBAPEADAEAD@Z */
30
DEFINE_THISCALL_WRAPPER(MSVCP_allocator_char_address, 8)
31
char* __thiscall MSVCP_allocator_char_address(void *this, char *ptr)
32 33 34 35 36
{
    return ptr;
}

/* ?address@?$allocator@D@std@@QBEPBDABD@Z */
37
/* ?address@?$allocator@D@std@@QEBAPEBDAEBD@Z */
38
DEFINE_THISCALL_WRAPPER(MSVCP_allocator_char_const_address, 8)
39
const char* __thiscall MSVCP_allocator_char_const_address(void *this, const char *ptr)
40 41 42 43 44
{
    return ptr;
}

/* ??0?$allocator@D@std@@QAE@XZ */
45
/* ??0?$allocator@D@std@@QEAA@XZ */
46
DEFINE_THISCALL_WRAPPER(MSVCP_allocator_char_ctor, 4)
47
void* __thiscall MSVCP_allocator_char_ctor(void *this)
48 49 50 51 52
{
    return this;
}

/* ??0?$allocator@D@std@@QAE@ABV01@@Z */
53
/* ??0?$allocator@D@std@@QEAA@AEBV01@@Z */
54
DEFINE_THISCALL_WRAPPER(MSVCP_allocator_char_copy_ctor, 8)
55
void* __thiscall MSVCP_allocator_char_copy_ctor(void *this, const void *copy)
56 57 58 59 60
{
    return this;
}

/* ??4?$allocator@D@std@@QAEAAV01@ABV01@@Z */
61
/* ??4?$allocator@D@std@@QEAAAEAV01@AEBV01@@Z */
62
DEFINE_THISCALL_WRAPPER(MSVCP_allocator_char_assign, 8)
63
void* __thiscall MSVCP_allocator_char_assign(void *this, const void *assign)
64 65 66 67 68
{
    return this;
}

/* ?deallocate@?$allocator@D@std@@QAEXPADI@Z */
69
/* ?deallocate@?$allocator@D@std@@QEAAXPEAD_K@Z */
70
DEFINE_THISCALL_WRAPPER(MSVCP_allocator_char_deallocate, 12)
71
void __thiscall MSVCP_allocator_char_deallocate(void *this, char *ptr, MSVCP_size_t size)
72 73 74 75 76
{
    MSVCRT_operator_delete(ptr);
}

/* ?allocate@?$allocator@D@std@@QAEPADI@Z */
77
/* ?allocate@?$allocator@D@std@@QEAAPEAD_K@Z */
78
DEFINE_THISCALL_WRAPPER(MSVCP_allocator_char_allocate, 8)
79
char* __thiscall MSVCP_allocator_char_allocate(void *this, MSVCP_size_t count)
80
{
81
    return MSVCRT_operator_new(count);
82 83 84
}

/* ?allocate@?$allocator@D@std@@QAEPADIPBX@Z */
85
/* ?allocate@?$allocator@D@std@@QEAAPEAD_KPEBX@Z */
86
DEFINE_THISCALL_WRAPPER(MSVCP_allocator_char_allocate_hint, 12)
87
char* __thiscall MSVCP_allocator_char_allocate_hint(void *this,
88
        MSVCP_size_t count, const void *hint)
89 90 91 92 93 94
{
    /* Native ignores hint */
    return MSVCP_allocator_char_allocate(this, count);
}

/* ?construct@?$allocator@D@std@@QAEXPADABD@Z */
95
/* ?construct@?$allocator@D@std@@QEAAXPEADAEBD@Z */
96
DEFINE_THISCALL_WRAPPER(MSVCP_allocator_char_construct, 12)
97
void __thiscall MSVCP_allocator_char_construct(void *this, char *ptr, const char *val)
98 99 100 101 102
{
    *ptr = *val;
}

/* ?destroy@?$allocator@D@std@@QAEXPAD@Z */
103
/* ?destroy@?$allocator@D@std@@QEAAXPEAD@Z */
104
DEFINE_THISCALL_WRAPPER(MSVCP_allocator_char_destroy, 8)
105
void __thiscall MSVCP_allocator_char_destroy(void *this, char *ptr)
106 107 108 109
{
}

/* ?max_size@?$allocator@D@std@@QBEIXZ */
110
/* ?max_size@?$allocator@D@std@@QEBA_KXZ */
111
DEFINE_THISCALL_WRAPPER(MSVCP_allocator_char_max_size, 4)
112
MSVCP_size_t __thiscall MSVCP_allocator_char_max_size(const void *this)
113 114 115
{
    return UINT_MAX/sizeof(char);
}
116 117 118 119 120 121


/* allocator<wchar_t> */
/* ?address@?$allocator@_W@std@@QBEPA_WAA_W@Z */
/* ?address@?$allocator@_W@std@@QEBAPEA_WAEA_W@Z */
DEFINE_THISCALL_WRAPPER(MSVCP_allocator_wchar_address, 8)
122
wchar_t* __thiscall MSVCP_allocator_wchar_address(void *this, wchar_t *ptr)
123 124 125 126 127 128 129
{
    return ptr;
}

/* ?address@?$allocator@_W@std@@QBEPB_WAB_W@Z */
/* ?address@?$allocator@_W@std@@QEBAPEB_WAEB_W@Z */
DEFINE_THISCALL_WRAPPER(MSVCP_allocator_wchar_const_address, 8)
130
const wchar_t* __thiscall MSVCP_allocator_wchar_const_address(void *this, const wchar_t *ptr)
131 132 133 134 135 136 137
{
    return ptr;
}

/* ??0?$allocator@_W@std@@QAE@XZ */
/* ??0?$allocator@_W@std@@QEAA@XZ */
DEFINE_THISCALL_WRAPPER(MSVCP_allocator_wchar_ctor, 4)
138
void* __thiscall MSVCP_allocator_wchar_ctor(void *this)
139 140 141 142 143 144 145
{
    return this;
}

/* ??0?$allocator@_W@std@@QAE@ABV01@@Z */
/* ??0?$allocator@_W@std@@QEAA@AEBV01@@Z */
DEFINE_THISCALL_WRAPPER(MSVCP_allocator_wchar_copy_ctor, 8)
146
void* __thiscall MSVCP_allocator_wchar_copy_ctor(void *this, void *copy)
147 148 149 150 151 152 153
{
    return this;
}

/* ??4?$allocator@_W@std@@QAEAAV01@ABV01@@Z */
/* ??4?$allocator@_W@std@@QEAAAEAV01@AEBV01@@Z */
DEFINE_THISCALL_WRAPPER(MSVCP_allocator_wchar_assign, 8)
154
void* __thiscall MSVCP_allocator_wchar_assign(void *this, void *assign)
155 156 157 158 159 160 161
{
    return this;
}

/* ?deallocate@?$allocator@_W@std@@QAEXPA_WI@Z */
/* ?deallocate@?$allocator@_W@std@@QEAAXPEA_W_K@Z */
DEFINE_THISCALL_WRAPPER(MSVCP_allocator_wchar_deallocate, 12)
162
void __thiscall MSVCP_allocator_wchar_deallocate(void *this,
163
        wchar_t *ptr, MSVCP_size_t size)
164 165 166 167 168 169 170
{
    MSVCRT_operator_delete(ptr);
}

/* ?allocate@?$allocator@_W@std@@QAEPA_WI@Z */
/* ?allocate@?$allocator@_W@std@@QEAAPEA_W_K@Z */
DEFINE_THISCALL_WRAPPER(MSVCP_allocator_wchar_allocate, 8)
171
wchar_t* __thiscall MSVCP_allocator_wchar_allocate(void *this, MSVCP_size_t count)
172 173 174 175 176 177
{
    if(UINT_MAX/count < sizeof(wchar_t)) {
        throw_exception(EXCEPTION_BAD_ALLOC, NULL);
        return NULL;
    }

178
    return MSVCRT_operator_new(count * sizeof(wchar_t));
179 180 181 182 183
}

/* ?allocate@?$allocator@_W@std@@QAEPA_WIPBX@Z */
/* ?allocate@?$allocator@_W@std@@QEAAPEA_W_KPEBX@Z */
DEFINE_THISCALL_WRAPPER(MSVCP_allocator_wchar_allocate_hint, 12)
184
wchar_t* __thiscall MSVCP_allocator_wchar_allocate_hint(void *this,
185
        MSVCP_size_t count, const void *hint)
186 187 188 189 190 191 192
{
    return MSVCP_allocator_wchar_allocate(this, count);
}

/* ?construct@?$allocator@_W@std@@QAEXPA_WAB_W@Z */
/* ?construct@?$allocator@_W@std@@QEAAXPEA_WAEB_W@Z */
DEFINE_THISCALL_WRAPPER(MSVCP_allocator_wchar_construct, 12)
193
void __thiscall MSVCP_allocator_wchar_construct(void *this,
194 195 196 197 198 199 200 201
        wchar_t *ptr, const wchar_t *val)
{
    *ptr = *val;
}

/* ?destroy@?$allocator@_W@std@@QAEXPA_W@Z */
/* ?destroy@?$allocator@_W@std@@QEAAXPEA_W@Z */
DEFINE_THISCALL_WRAPPER(MSVCP_allocator_wchar_destroy, 8)
202
void __thiscall MSVCP_allocator_wchar_destroy(void *this, char *ptr)
203 204 205 206 207 208
{
}

/* ?max_size@?$allocator@_W@std@@QBEIXZ */
/* ?max_size@?$allocator@_W@std@@QEBA_KXZ */
DEFINE_THISCALL_WRAPPER(MSVCP_allocator_wchar_max_size, 4)
209
MSVCP_size_t __thiscall MSVCP_allocator_wchar_max_size(const void *this)
210 211 212
{
    return UINT_MAX/sizeof(wchar_t);
}
213 214 215 216 217

/* allocator<unsigned short> */
/* ?address@?$allocator@G@std@@QBEPAGAAG@Z */
/* ?address@?$allocator@G@std@@QEBAPEAGAEAG@Z */
DEFINE_THISCALL_WRAPPER(MSVCP_allocator_short_address, 8)
218
unsigned short* __thiscall MSVCP_allocator_short_address(
219 220 221 222 223 224 225 226
        void *this, unsigned short *ptr)
{
    return ptr;
}

/* ?address@?$allocator@G@std@@QBEPBGABG@Z */
/* ?address@?$allocator@G@std@@QEBAPEBGAEBG@Z */
DEFINE_THISCALL_WRAPPER(MSVCP_allocator_short_const_address, 8)
227
const unsigned short* __thiscall MSVCP_allocator_short_const_address(
228 229 230 231 232 233 234 235
        void *this, const unsigned short *ptr)
{
    return ptr;
}

/* ??0?$allocator@G@std@@QAE@XZ */
/* ??0?$allocator@G@std@@QEAA@XZ */
DEFINE_THISCALL_WRAPPER(MSVCP_allocator_short_ctor, 4)
236
void* __thiscall MSVCP_allocator_short_ctor(void *this)
237 238 239 240 241 242 243
{
    return this;
}

/* ??0?$allocator@G@std@@QAE@ABV01@@Z */
/* ??0?$allocator@G@std@@QEAA@AEBV01@@Z */
DEFINE_THISCALL_WRAPPER(MSVCP_allocator_short_copy_ctor, 8)
244
void* __thiscall MSVCP_allocator_short_copy_ctor(void *this, void *copy)
245 246 247 248 249 250 251
{
    return this;
}

/* ??4?$allocator@G@std@@QAEAAV01@ABV01@@Z */
/* ??4?$allocator@G@std@@QEAAAEAV01@AEBV01@@Z */
DEFINE_THISCALL_WRAPPER(MSVCP_allocator_short_assign, 8)
252
void* __thiscall MSVCP_allocator_short_assign(void *this, void *assign)
253 254 255 256 257 258 259
{
    return this;
}

/* ?deallocate@?$allocator@G@std@@QAEXPAGI@Z */
/* ?deallocate@?$allocator@G@std@@QEAAXPEAG_K@Z */
DEFINE_THISCALL_WRAPPER(MSVCP_allocator_short_deallocate, 12)
260
void __thiscall MSVCP_allocator_short_deallocate(void *this,
261
        unsigned short *ptr, MSVCP_size_t size)
262 263 264 265 266 267 268
{
    MSVCRT_operator_delete(ptr);
}

/* ?allocate@?$allocator@G@std@@QAEPAGI@Z */
/* ?allocate@?$allocator@G@std@@QEAAPEAG_K@Z */
DEFINE_THISCALL_WRAPPER(MSVCP_allocator_short_allocate, 8)
269
unsigned short* __thiscall MSVCP_allocator_short_allocate(
270
        void *this, MSVCP_size_t count)
271 272 273 274 275 276
{
    if(UINT_MAX/count < sizeof(unsigned short)) {
        throw_exception(EXCEPTION_BAD_ALLOC, NULL);
        return NULL;
    }

277
    return MSVCRT_operator_new(count * sizeof(unsigned short));
278 279 280 281 282
}

/* ?allocate@?$allocator@G@std@@QAEPAGIPBX@Z */
/* ?allocate@?$allocator@G@std@@QEAAPEAG_KPEBX@Z */
DEFINE_THISCALL_WRAPPER(MSVCP_allocator_short_allocate_hint, 12)
283
unsigned short* __thiscall MSVCP_allocator_short_allocate_hint(
284
        void *this, MSVCP_size_t count, const void *hint)
285 286 287 288 289 290 291
{
    return MSVCP_allocator_short_allocate(this, count);
}

/* ?construct@?$allocator@G@std@@QAEXPAGABG@Z */
/* ?construct@?$allocator@G@std@@QEAAXPEAGAEBG@Z */
DEFINE_THISCALL_WRAPPER(MSVCP_allocator_short_construct, 12)
292
void __thiscall MSVCP_allocator_short_construct(void *this,
293 294 295 296 297 298 299 300
        unsigned short *ptr, unsigned short *val)
{
    *ptr = *val;
}

/* ?destroy@?$allocator@G@std@@QAEXPAG@Z */
/* ?destroy@?$allocator@G@std@@QEAAXPEAG@Z */
DEFINE_THISCALL_WRAPPER(MSVCP_allocator_short_destroy, 8)
301
void __thiscall MSVCP_allocator_short_destroy(void *this, MSVCP_size_t *ptr)
302 303 304 305 306 307
{
}

/* ?max_size@?$allocator@G@std@@QBEIXZ */
/* ?max_size@?$allocator@G@std@@QEBA_KXZ */
DEFINE_THISCALL_WRAPPER(MSVCP_allocator_short_max_size, 4)
308
MSVCP_size_t __thiscall MSVCP_allocator_short_max_size(void *this)
309 310 311
{
    return UINT_MAX/sizeof(unsigned short);
}
312 313 314 315

/* allocator<void> */
/* ??0?$allocator@X@std@@QAE@XZ */
/* ??0?$allocator@X@std@@QEAA@XZ */
316
DEFINE_THISCALL_WRAPPER(MSVCP_allocator_void_ctor, 4)
317
void* __thiscall MSVCP_allocator_void_ctor(void *this)
318 319 320 321 322 323
{
    return this;
}

/* ??0?$allocator@X@std@@QAE@ABV01@@Z */
/* ??0?$allocator@X@std@@QEAA@AEBV01@@Z */
324
DEFINE_THISCALL_WRAPPER(MSVCP_allocator_void_copy_ctor, 8)
325
void* __thiscall MSVCP_allocator_void_copy_ctor(void *this, void *copy)
326 327 328 329 330 331
{
    return this;
}

/* ??4?$allocator@X@std@@QAEAAV01@ABV01@@Z */
/* ??4?$allocator@X@std@@QEAAAEAV01@AEBV01@@Z */
332
DEFINE_THISCALL_WRAPPER(MSVCP_allocator_void_assign, 8)
333
void* __thiscall MSVCP_allocator_void_assign(void *this, void *assign)
334 335 336
{
    return this;
}