Skip to content

Commit f4e3aed

Browse files
committed
[MSVCRT] Make msvcrt compile with MSVC
1 parent fda35b6 commit f4e3aed

13 files changed

Lines changed: 139 additions & 8 deletions

File tree

dll/win32/msvcrt/cppexcept.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
#include <fpieee.h>
2525
#include "cxx.h"
2626

27+
#ifdef __REACTOS__
28+
#include "msvc_fwd_decl.h"
29+
#endif
30+
2731
#define CXX_FRAME_MAGIC_VC6 0x19930520
2832
#define CXX_FRAME_MAGIC_VC7 0x19930521
2933
#define CXX_FRAME_MAGIC_VC8 0x19930522
@@ -137,7 +141,7 @@ typedef struct
137141
#define TYPE_FLAG_VOLATILE 2
138142
#define TYPE_FLAG_REFERENCE 8
139143

140-
void WINAPI DECLSPEC_NORETURN _CxxThrowException(void*,const cxx_exception_type*);
144+
DECLSPEC_NORETURN void WINAPI _CxxThrowException(void*,const cxx_exception_type*);
141145

142146
static inline BOOL is_cxx_exception( EXCEPTION_RECORD *rec )
143147
{

dll/win32/msvcrt/cxx.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
#define RTTI_USE_RVA 1
2828
#endif
2929

30+
#ifdef _MSC_VER
31+
#define __ASM_VTABLE(name,funcs)
32+
#else
3033
#ifdef _WIN64
3134

3235
#define VTABLE_ADD_FUNC(name) "\t.quad " THISCALL_NAME(name) "\n"
@@ -52,6 +55,7 @@
5255
funcs "\n\t.text")
5356

5457
#endif /* _WIN64 */
58+
#endif // _MSC_VER
5559

5660
#ifndef RTTI_USE_RVA
5761

@@ -481,6 +485,10 @@ static inline void *rtti_rva( const void *ptr, uintptr_t base )
481485

482486
#endif
483487

488+
#ifdef __REACTOS__
489+
void * __thiscall type_info_vector_dtor(type_info * _this, unsigned int flags);
490+
#endif
491+
484492
#define CREATE_TYPE_INFO_VTABLE \
485493
DEFINE_THISCALL_WRAPPER(type_info_vector_dtor,8) \
486494
void * __thiscall type_info_vector_dtor(type_info * _this, unsigned int flags) \

dll/win32/msvcrt/except_i386.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,8 +601,11 @@ int CDECL _except_handler3(PEXCEPTION_RECORD rec,
601601
rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress,
602602
frame->handler, context, dispatcher);
603603

604+
#ifdef _MSC_VER
605+
__asm{ cld }
606+
#else
604607
__asm__ __volatile__ ("cld");
605-
608+
#endif
606609
if (rec->ExceptionFlags & (EXCEPTION_UNWINDING | EXCEPTION_EXIT_UNWIND))
607610
{
608611
/* Unwinding the current frame */

dll/win32/msvcrt/include/conio.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,13 @@ static inline int kbhit(void) { return _kbhit(); }
4646
static inline int putch(int c) { return _putch(c); }
4747
static inline int ungetch(int c) { return _ungetch(c); }
4848
#ifdef _M_IX86
49+
#ifndef _MSC_VER
4950
static inline int inp(unsigned short i) { return _inp(i); }
5051
static inline unsigned short inpw(unsigned short i) { return _inpw(i); }
5152
static inline int outp(unsigned short i, int j) { return _outp(i, j); }
5253
static inline unsigned short outpw(unsigned short i, unsigned short j) { return _outpw(i, j); }
5354
#endif
55+
#endif
5456

5557
#if defined(__GNUC__) && (__GNUC__ < 4)
5658
_ACRTIMP int __cdecl cprintf(const char*,...) __attribute__((alias("_cprintf"),format(printf,1,2)));

dll/win32/msvcrt/include/stdlib.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ static inline unsigned __int64 __cdecl strtoull(const char *ptr, char **endptr,
297297
static inline void swab(char* src, char* dst, int len) { _swab(src, dst, len); }
298298
static inline char* ultoa(__msvcrt_ulong value, char* str, int radix) { return _ultoa(value, str, radix); }
299299

300+
#ifndef __REACTOS__
300301
#ifdef __i386__
301302
static inline div_t __wine_msvcrt_div(int num, int denom)
302303
{
@@ -319,6 +320,7 @@ static inline ldiv_t __wine_msvcrt_ldiv(__msvcrt_long num, __msvcrt_long denom)
319320
#define div(num,denom) __wine_msvcrt_div(num,denom)
320321
#define ldiv(num,denom) __wine_msvcrt_ldiv(num,denom)
321322
#endif
323+
#endif /* !__REACTOS__ */
322324

323325
#include <poppack.h>
324326

dll/win32/msvcrt/include/string.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
#define _NLSCMP_DEFINED
1717
#endif
1818

19+
#ifdef _MSC_VER
20+
#pragma function(strset)
21+
#endif
22+
1923
#ifdef __cplusplus
2024
extern "C" {
2125
#endif

dll/win32/msvcrt/include/sys/timeb.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ _ACRTIMP void __cdecl _ftime64(struct __timeb64*);
6262
#endif
6363

6464
#ifdef _USE_32BIT_TIME_T
65-
static inline void __cdecl _ftime(struct _timeb *tb) { return _ftime32((struct __timeb32*)tb); }
65+
static inline void __cdecl _ftime(struct _timeb *tb) { _ftime32((struct __timeb32*)tb); }
6666
#else
67-
static inline void __cdecl _ftime(struct _timeb *tb) { return _ftime64((struct __timeb64*)tb); }
67+
static inline void __cdecl _ftime(struct _timeb *tb) { _ftime64((struct __timeb64*)tb); }
6868
#endif
6969

7070
#define timeb _timeb
7171

72-
static inline void ftime(struct _timeb* ptr) { return _ftime(ptr); }
72+
static inline void ftime(struct _timeb* ptr) { _ftime(ptr); }
7373

7474
#include <poppack.h>
7575

dll/win32/msvcrt/math.c

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@
5252

5353
WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
5454

55+
#ifdef _MSC_VER
56+
#pragma function(abs,labs,div,ldiv)
57+
#endif
58+
5559
#undef div
5660
#undef ldiv
5761

@@ -699,13 +703,19 @@ intmax_t CDECL imaxabs( intmax_t n )
699703
/*********************************************************************
700704
* _abs64 (MSVCRT.@)
701705
*/
706+
#ifdef _MSC_VER
707+
#pragma function(_abs64)
708+
#endif
702709
__int64 CDECL _abs64( __int64 n )
703710
{
704711
return n >= 0 ? n : -n;
705712
}
706713

707714
#if defined(__i386__) || defined(__x86_64__)
708-
715+
#ifdef _MSC_VER
716+
#define get_mxcsr() _mm_getcsr()
717+
#define set_mxcsr(val) _mm_setcsr(val)
718+
#else
709719
static unsigned int get_mxcsr(void)
710720
{
711721
unsigned int ret;
@@ -727,6 +737,7 @@ static void set_mxcsr( unsigned int val )
727737
__asm__ __volatile__( "ldmxcsr %0" : : "m" (val) );
728738
#endif
729739
}
740+
#endif
730741

731742
static void _setfp_sse( unsigned int *cw, unsigned int cw_mask,
732743
unsigned int *sw, unsigned int sw_mask )
@@ -826,7 +837,7 @@ static void _setfp_sse( unsigned int *cw, unsigned int cw_mask,
826837
static void _setfp( unsigned int *cw, unsigned int cw_mask,
827838
unsigned int *sw, unsigned int sw_mask )
828839
{
829-
#if (defined(__GNUC__) || defined(__clang__)) && defined(__i386__)
840+
#if (defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER)) && defined(__i386__)
830841
unsigned long oldcw = 0, newcw = 0;
831842
unsigned long oldsw = 0, newsw = 0;
832843
unsigned int flags;
@@ -836,7 +847,11 @@ static void _setfp( unsigned int *cw, unsigned int cw_mask,
836847

837848
if (sw)
838849
{
850+
#ifdef _MSC_VER
851+
__asm { fstsw newsw }
852+
#else
839853
__asm__ __volatile__( "fstsw %0" : "=m" (newsw) );
854+
#endif
840855
oldsw = newsw;
841856

842857
flags = 0;
@@ -861,7 +876,11 @@ static void _setfp( unsigned int *cw, unsigned int cw_mask,
861876

862877
if (cw)
863878
{
864-
__asm__ __volatile__( "fstcw %0" : "=m" (newcw) );
879+
#ifdef _MSC_VER
880+
__asm { fstcw newcw }
881+
#else
882+
__asm__ __volatile__( "fstcw %0" : "=m" (newcw) );
883+
#endif
865884
oldcw = newcw;
866885

867886
flags = 0;
@@ -928,18 +947,34 @@ static void _setfp( unsigned int *cw, unsigned int cw_mask,
928947

929948
assert(cw);
930949

950+
#ifdef _MSC_VER
951+
__asm { fnstenv fenv }
952+
#else
931953
__asm__ __volatile__( "fnstenv %0" : "=m" (fenv) );
954+
#endif
932955
fenv.control_word = newcw;
933956
fenv.status_word = newsw;
957+
#ifdef _MSC_VER
958+
__asm { fldenv fenv }
959+
#else
934960
__asm__ __volatile__( "fldenv %0" : : "m" (fenv) : "st", "st(1)",
935961
"st(2)", "st(3)", "st(4)", "st(5)", "st(6)", "st(7)" );
962+
#endif
936963
return;
937964
}
938965

939966
if (oldsw != newsw)
967+
#ifdef _MSC_VER
968+
__asm { fnclex }
969+
#else
940970
__asm__ __volatile__( "fnclex" );
971+
#endif
941972
if (oldcw != newcw)
973+
#ifdef _MSC_VER
974+
__asm { fldcw newcw }
975+
#else
942976
__asm__ __volatile__( "fldcw %0" : : "m" (newcw) );
977+
#endif
943978
#elif defined(__x86_64__)
944979
_setfp_sse(cw, cw_mask, sw, sw_mask);
945980
#elif defined(__aarch64__)
@@ -2012,6 +2047,7 @@ int CDECL _gcvt_s(char *buff, size_t size, double number, int digits)
20122047

20132048
#include <stdlib.h> /* div_t, ldiv_t */
20142049

2050+
#ifndef __REACTOS__
20152051
/*********************************************************************
20162052
* div (MSVCRT.@)
20172053
* VERSION
@@ -2078,6 +2114,7 @@ ldiv_t CDECL ldiv(__msvcrt_long num, __msvcrt_long denom)
20782114
return ret;
20792115
}
20802116
#endif /* ifdef __i386__ */
2117+
#endif /* !__REACTOS__ */
20812118

20822119
#if _MSVCR_VER>=100
20832120
/*********************************************************************
@@ -2325,6 +2362,7 @@ void _safe_fprem1(void)
23252362
TRACE("(): stub\n");
23262363
}
23272364

2365+
#ifndef __REACTOS__
23282366
/***********************************************************************
23292367
* __libm_sse2_acos (MSVCRT.@)
23302368
*/
@@ -2580,6 +2618,7 @@ void __cdecl __libm_sse2_sqrt_precise(void)
25802618
}
25812619
__asm__ __volatile__( "sqrtsd %xmm0, %xmm0" );
25822620
}
2621+
#endif /* !__REACTOS__ */
25832622
#endif /* __i386__ */
25842623

25852624
#if _MSVCR_VER>=120

dll/win32/msvcrt/misc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
3131

3232
static unsigned int output_format;
3333

34+
#ifdef _MSC_VER
35+
#pragma function(_byteswap_ushort, _byteswap_ulong, _byteswap_uint64)
36+
#endif
37+
3438
/*********************************************************************
3539
* _beep (MSVCRT.@)
3640
*/

dll/win32/msvcrt/msvc_fwd_decl.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
#define bad_cast exception
3+
#define bad_typeid exception
4+
#define __non_rtti_object exception
5+
6+
exception* __thiscall exception_ctor(exception* _this, const char** name);
7+
exception* __thiscall exception_copy_ctor(exception* _this, const exception* rhs);
8+
exception* __thiscall exception_ctor_noalloc(exception* _this, char** name, int noalloc);
9+
exception* __thiscall exception_default_ctor(exception* _this);
10+
exception* __thiscall exception_opequals(exception* _this, const exception* rhs);
11+
void __thiscall exception_dtor(exception* _this);
12+
void* __thiscall exception_vector_dtor(exception* _this, unsigned int flags);
13+
void* __thiscall exception_scalar_dtor(exception* _this, unsigned int flags);
14+
const char* __thiscall exception_what(exception* _this);
15+
bad_typeid* __thiscall bad_typeid_copy_ctor(bad_typeid* _this, const bad_typeid* rhs);
16+
bad_typeid* __thiscall bad_typeid_ctor(bad_typeid* _this, const char* name);
17+
bad_typeid* __thiscall bad_typeid_default_ctor(bad_typeid* _this);
18+
void __thiscall bad_typeid_dtor(bad_typeid* _this);
19+
bad_typeid* __thiscall bad_typeid_opequals(bad_typeid* _this, const bad_typeid* rhs);
20+
void* __thiscall bad_typeid_vector_dtor(bad_typeid* _this, unsigned int flags);
21+
void* __thiscall bad_typeid_scalar_dtor(bad_typeid* _this, unsigned int flags);
22+
__non_rtti_object* __thiscall __non_rtti_object_copy_ctor(__non_rtti_object* _this, const __non_rtti_object* rhs);
23+
__non_rtti_object* __thiscall __non_rtti_object_ctor(__non_rtti_object* _this, const char* name);
24+
void __thiscall __non_rtti_object_dtor(__non_rtti_object* _this);
25+
__non_rtti_object* __thiscall __non_rtti_object_opequals(__non_rtti_object* _this, const __non_rtti_object* rhs);
26+
void* __thiscall __non_rtti_object_vector_dtor(__non_rtti_object* _this, unsigned int flags);
27+
void* __thiscall __non_rtti_object_scalar_dtor(__non_rtti_object* _this, unsigned int flags);
28+
bad_cast* __thiscall bad_cast_ctor(bad_cast* _this, const char** name);
29+
bad_cast* __thiscall bad_cast_copy_ctor(bad_cast* _this, const bad_cast* rhs);
30+
bad_cast* __thiscall bad_cast_ctor_charptr(bad_cast* _this, const char* name);
31+
bad_cast* __thiscall bad_cast_default_ctor(bad_cast* _this);
32+
void __thiscall bad_cast_dtor(bad_cast* _this);
33+
void* __thiscall bad_cast_vector_dtor(bad_cast* _this, unsigned int flags);
34+
void* __thiscall bad_cast_scalar_dtor(bad_cast* _this, unsigned int flags);
35+
bad_cast* __thiscall bad_cast_opequals(bad_cast* _this, const bad_cast* rhs);
36+
int __thiscall type_info_opequals_equals(type_info* _this, const type_info* rhs);
37+
int __thiscall type_info_opnot_equals(type_info* _this, const type_info* rhs);
38+
int __thiscall type_info_before(type_info* _this, const type_info *rhs);
39+
void __thiscall type_info_dtor(type_info* _this);
40+
const char* __thiscall type_info_name(type_info* _this);
41+
const char* __thiscall type_info_raw_name(type_info* _this);
42+
43+
#undef bad_cast
44+
#undef bad_typeid
45+
#undef __non_rtti_object

0 commit comments

Comments
 (0)