msvcr90.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
/*
 * msvcr90 specific functions
 *
 * Copyright 2010 Detlef Riekenberg
 *
 * 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
 */

21
#include "config.h"
22 23
#include <stdarg.h>

24
#include "stdlib.h"
25
#include "stdio.h"
26 27
#include "errno.h"
#include "malloc.h"
28 29
#include "windef.h"
#include "winbase.h"
30
#include "wine/debug.h"
31
#include "sys/stat.h"
32

33 34
WINE_DEFAULT_DEBUG_CHANNEL(msvcr90);

35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
#ifdef __i386__  /* thiscall functions are i386-specific */

#define THISCALL(func) __thiscall_ ## func
#define THISCALL_NAME(func) __ASM_NAME("__thiscall_" #func)
#define __thiscall __stdcall
#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) )

#else /* __i386__ */

#define THISCALL(func) func
#define THISCALL_NAME(func) __ASM_NAME(#func)
#define __thiscall __cdecl
#define DEFINE_THISCALL_WRAPPER(func,args) /* nothing */

#endif /* __i386__ */

struct __type_info_node
{
    void *memPtr;
    struct __type_info_node* next;
};

typedef struct __type_info
{
  const void *vtable;
  char       *name;        /* Unmangled name, allocated lazily */
  char        mangled[32]; /* Variable length, but we declare it large enough for static RTTI */
} type_info;

70 71
typedef void* (__cdecl *malloc_func_t)(size_t);
typedef void  (__cdecl *free_func_t)(void*);
72 73 74

extern char* __cdecl __unDName(char *,const char*,int,malloc_func_t,free_func_t,unsigned short int);

75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
/*********************************************************************
 *  msvcr90_stat64_to_stat32 [internal]
 */
static void msvcr90_stat64_to_stat32(const struct _stat64 *buf64, struct _stat32 *buf)
{
    buf->st_dev   = buf64->st_dev;
    buf->st_ino   = buf64->st_ino;
    buf->st_mode  = buf64->st_mode;
    buf->st_nlink = buf64->st_nlink;
    buf->st_uid   = buf64->st_uid;
    buf->st_gid   = buf64->st_gid;
    buf->st_rdev  = buf64->st_rdev;
    buf->st_size  = buf64->st_size;
    buf->st_atime = buf64->st_atime;
    buf->st_mtime = buf64->st_mtime;
    buf->st_ctime = buf64->st_ctime;
}

93 94 95
/*********************************************************************
 *  DllMain (MSVCR90.@)
 */
96 97 98 99 100 101 102 103 104
BOOL WINAPI DllMain(HINSTANCE hdll, DWORD reason, LPVOID reserved)
{
    switch (reason)
    {
    case DLL_WINE_PREATTACH:
        return FALSE;  /* prefer native version */

    case DLL_PROCESS_ATTACH:
        DisableThreadLibraryCalls(hdll);
105
        _set_printf_count_output(0);
106 107 108
    }
    return TRUE;
}
109

110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
/*********************************************************************
 *  _decode_pointer (MSVCR90.@)
 *
 * cdecl version of DecodePointer
 *
 */
void * CDECL MSVCR90_decode_pointer(void * ptr)
{
    return DecodePointer(ptr);
}

/*********************************************************************
 *  _encode_pointer (MSVCR90.@)
 *
 * cdecl version of EncodePointer
 *
 */
void * CDECL MSVCR90_encode_pointer(void * ptr)
{
    return EncodePointer(ptr);
}
131

132 133 134 135 136 137 138 139 140 141
/*********************************************************************
 *  _encoded_null (MSVCR90.@)
 */
void * CDECL _encoded_null(void)
{
    TRACE("\n");

    return MSVCR90_encode_pointer(NULL);
}

142 143 144 145 146 147 148 149
/*********************************************************************
 * _invalid_parameter_noinfo (MSVCR90.@)
 */
void CDECL _invalid_parameter_noinfo(void)
{
    _invalid_parameter( NULL, NULL, NULL, 0, 0 );
}

150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
/*********************************************************************
 * __sys_nerr (MSVCR90.@)
 */
int* CDECL __sys_nerr(void)
{
        return (int*)GetProcAddress(GetModuleHandleA("msvcrt.dll"), "_sys_nerr");
}

/*********************************************************************
 *  __sys_errlist (MSVCR90.@)
 */
char** CDECL __sys_errlist(void)
{
    return (char**)GetProcAddress(GetModuleHandleA("msvcrt.dll"), "_sys_errlist");
}
165 166 167 168 169 170 171 172

/*********************************************************************
 * __clean_type_info_names_internal (MSVCR90.@)
 */
void CDECL __clean_type_info_names_internal(void *p)
{
    FIXME("(%p) stub\n", p);
}
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194

/*********************************************************************
 * _recalloc (MSVCR90.@)
 */
void* CDECL _recalloc(void* mem, size_t num, size_t size)
{
    size_t old_size;
    void *ret;

    if(!mem)
        return calloc(num, size);

    size = num*size;
    old_size = _msize(mem);

    ret = realloc(mem, size);
    if(!ret) {
        *_errno() = ENOMEM;
        return NULL;
    }

    if(size>old_size)
195
        memset((BYTE*)ret+old_size, 0, size-old_size);
196 197
    return ret;
}
198

199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
/*********************************************************************
 *  _fstat32 (MSVCR90.@)
 */
int CDECL _fstat32(int fd, struct _stat32* buf)
{
  int ret;
  struct _stat64 buf64;

  ret = _fstat64(fd, &buf64);
  if (!ret)
      msvcr90_stat64_to_stat32(&buf64, buf);
  return ret;
}

/*********************************************************************
 *  _stat32 (MSVCR90.@)
 */
int CDECL _stat32(const char *path, struct _stat32* buf)
{
  int ret;
  struct _stat64 buf64;

  ret = _stat64(path, &buf64);
  if (!ret)
      msvcr90_stat64_to_stat32(&buf64, buf);
  return ret;
}

/*********************************************************************
 *  _wstat32 (MSVCR90.@)
 */
int CDECL _wstat32(const wchar_t *path, struct _stat32* buf)
{
  int ret;
  struct _stat64 buf64;

  ret = _wstat64(path, &buf64);
  if (!ret)
      msvcr90_stat64_to_stat32(&buf64, buf);
  return ret;
}

241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
/*********************************************************************
 *		_fstat64i32 (MSVCRT.@)
 */

static void msvcrt_stat64_to_stat64i32(const struct _stat64 *buf64, struct _stat64i32 *buf)
{
    buf->st_dev   = buf64->st_dev;
    buf->st_ino   = buf64->st_ino;
    buf->st_mode  = buf64->st_mode;
    buf->st_nlink = buf64->st_nlink;
    buf->st_uid   = buf64->st_uid;
    buf->st_gid   = buf64->st_gid;
    buf->st_rdev  = buf64->st_rdev;
    buf->st_size  = buf64->st_size;
    buf->st_atime = buf64->st_atime;
    buf->st_mtime = buf64->st_mtime;
    buf->st_ctime = buf64->st_ctime;
}

int CDECL _fstat64i32(int fd, struct _stat64i32* buf)
{
  int ret;
  struct _stat64 buf64;

  ret = _fstat64(fd, &buf64);
  if (!ret)
      msvcrt_stat64_to_stat64i32(&buf64, buf);
  return ret;
}
270 271 272 273 274 275 276 277 278 279 280 281 282 283

/*********************************************************************
 *		_stat64i32 (MSVCRT.@)
 */
int CDECL _stat64i32(const char* path, struct _stat64i32 * buf)
{
  int ret;
  struct _stat64 buf64;

  ret = _stat64(path, &buf64);
  if (!ret)
    msvcrt_stat64_to_stat64i32(&buf64, buf);
  return ret;
}
284 285 286 287 288 289 290 291 292 293 294 295 296 297

/*********************************************************************
 *              _wstat64i32 (MSVCRT.@)
 */
int CDECL _wstat64i32(const wchar_t *path, struct _stat64i32 *buf)
{
    int ret;
    struct _stat64 buf64;

    ret = _wstat64(path, &buf64);
    if (!ret)
        msvcrt_stat64_to_stat64i32(&buf64, buf);
    return ret;
}
298 299 300 301 302 303 304 305

/*********************************************************************
 *		_atoflt  (MSVCR90.@)
 */
int CDECL _atoflt( _CRT_FLOAT *value, char *str )
{
    return _atoflt_l( value, str, NULL );
}
306 307 308 309 310 311 312 313 314 315 316 317 318 319

/*********************************************************************
 * ?_name_internal_method@type_info@@QBEPBDPAU__type_info_node@@@Z (MSVCR90.@)
 */
DEFINE_THISCALL_WRAPPER(MSVCRT_type_info_name_internal_method,8)
const char * __thiscall MSVCRT_type_info_name_internal_method(type_info * _this, struct __type_info_node *node)
{
    static int once;

    if (node && !once++) FIXME("type_info_node parameter ignored\n");

    if (!_this->name)
    {
      /* Create and set the demangled name */
André Hentschel's avatar
André Hentschel committed
320
      /* Note: mangled name in type_info struct always starts with a '.', while
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
       * it isn't valid for mangled name.
       * Is this '.' really part of the mangled name, or has it some other meaning ?
       */
      char* name = __unDName(0, _this->mangled + 1, 0, malloc, free, 0x2800);
      if (name)
      {
        unsigned int len = strlen(name);

        /* It seems _unDName may leave blanks at the end of the demangled name */
        while (len && name[--len] == ' ')
          name[len] = '\0';

        if (InterlockedCompareExchangePointer((void**)&_this->name, name, NULL))
        {
          /* Another thread set this member since we checked above - use it */
          free(name);
        }
      }
    }
    TRACE("(%p) returning %s\n", _this, _this->name);
    return _this->name;
}
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360

/*********************************************************************
 *              _CRT_RTC_INIT (MSVCR90.@)
 */
void* CDECL _CRT_RTC_INIT(void *unk1, void *unk2, int unk3, int unk4, int unk5)
{
    TRACE("%p %p %x %x %x\n", unk1, unk2, unk3, unk4, unk5);
    return NULL;
}

/*********************************************************************
 *              _CRT_RTC_INITW (MSVCR90.@)
 */
void* CDECL _CRT_RTC_INITW(void *unk1, void *unk2, int unk3, int unk4, int unk5)
{
    TRACE("%p %p %x %x %x\n", unk1, unk2, unk3, unk4, unk5);
    return NULL;
}
361 362 363 364 365 366 367 368

/*********************************************************************
 *              _vswprintf_p (MSVCR90.@)
 */
int CDECL MSVCR90__vswprintf_p(wchar_t *buffer, size_t length, const wchar_t *format, __ms_va_list args)
{
    return _vswprintf_p_l(buffer, length, format, NULL, args);
}
369 370 371 372 373 374 375 376 377 378 379 380

/*********************************************************************
 *              _byteswap_ushort (MSVCR90.@)
 */
unsigned short CDECL _byteswap_ushort(unsigned short s)
{
    return (s<<8) + (s>>8);
}

/*********************************************************************
 *              _byteswap_ulong (MSVCR90.@)
 */
381
ULONG CDECL _byteswap_ulong(ULONG l)
382 383 384 385 386 387 388 389 390 391 392 393
{
    return (l<<24) + ((l<<8)&0xFF0000) + ((l>>8)&0xFF00) + (l>>24);
}

/*********************************************************************
 *              _byteswap_uint64 (MSVCR90.@)
 */
unsigned __int64 CDECL _byteswap_uint64(unsigned __int64 i)
{
    return (i<<56) + ((i&0xFF00)<<40) + ((i&0xFF0000)<<24) + ((i&0xFF000000)<<8) +
        ((i>>8)&0xFF000000) + ((i>>24)&0xFF0000) + ((i>>40)&0xFF00) + (i>>56);
}