- Create a new library msvcrtex, which will be automatically linked, when msvcrt is linked. This is yet a minimal version which replaces the different mingw libs.
- Use proper unicode entrypoints
- remove unneeded libcoldname.a

svn path=/trunk/; revision=51860
This commit is contained in:
Timo Kreuzer 2011-05-23 15:50:03 +00:00
parent 13719879aa
commit 6243472331
42 changed files with 3500 additions and 634 deletions

View file

@ -17,6 +17,6 @@ add_pch(charmap ${CMAKE_CURRENT_SOURCE_DIR}/precomp.h ${SOURCE})
set_module_type(charmap win32gui)
add_importlibs(charmap user32 gdi32 comctl32 kernel32 msvcrt)
add_importlibs(charmap msvcrt user32 gdi32 comctl32 kernel32)
add_cd_file(TARGET charmap DESTINATION reactos/system32 FOR all)

View file

@ -15,6 +15,6 @@ target_link_libraries(sol cardlib)
set_module_type(sol win32gui)
add_importlibs(sol advapi32 comctl32 user32 gdi32 kernel32 msvcrt)
add_importlibs(sol advapi32 comctl32 user32 gdi32 msvcrt kernel32)
add_cd_file(TARGET sol DESTINATION reactos/system32 FOR all)

View file

@ -15,6 +15,6 @@ target_link_libraries(spider cardlib)
set_module_type(spider win32gui)
add_importlibs(spider advapi32 comctl32 user32 gdi32 kernel32 msvcrt)
add_importlibs(spider advapi32 comctl32 user32 gdi32 msvcrt kernel32)
add_cd_file(TARGET spider DESTINATION reactos/system32 FOR all)

View file

@ -28,5 +28,5 @@ add_executable(telnet
telnet.rc)
set_module_type(telnet win32cui)
add_importlibs(telnet ws2_32 user32 kernel32 msvcrt)
add_importlibs(telnet ws2_32 user32 msvcrt kernel32)
add_cd_file(TARGET telnet DESTINATION reactos/system32 FOR all)

View file

@ -29,7 +29,7 @@ add_executable(rapps ${SOURCE})
set_module_type(rapps win32gui)
target_link_libraries(rapps uuid)
add_importlibs(rapps advapi32 comctl32 gdi32 urlmon user32 shell32 shlwapi kernel32 msvcrt ntdll)
add_importlibs(rapps advapi32 comctl32 gdi32 urlmon user32 shell32 shlwapi msvcrt kernel32 ntdll)
add_dependencies(rapps rappsmsg)
add_message_headers(rappsmsg.mc)
add_cd_file(TARGET rapps DESTINATION reactos/system32 FOR all)

View file

@ -3,7 +3,7 @@
if(ARCH MATCHES i386)
link_directories("${REACTOS_SOURCE_DIR}/importlibs")
endif()
link_directories(${REACTOS_BINARY_DIR}/lib/3rdparty/mingw)
link_directories(${REACTOS_BINARY_DIR}/lib/sdk/crt)
set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
set(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_CXX_COMPILER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
set(CMAKE_EXE_LINKER_FLAGS "-nodefaultlibs -nostdlib -Wl,--enable-auto-image-base -Wl,--disable-auto-import")
@ -180,25 +180,20 @@ macro(set_module_type MODULE TYPE)
set_entrypoint(${MODULE} NtProcessStartup 4)
elseif(${TYPE} MATCHES win32gui)
set_subsystem(${MODULE} windows)
set_entrypoint(${MODULE} WinMainCRTStartup)
if(NOT IS_UNICODE)
target_link_libraries(${MODULE} mingw_main)
if(IS_UNICODE)
set_entrypoint(${MODULE} wWinMainCRTStartup)
else()
target_link_libraries(${MODULE} mingw_wmain)
endif(NOT IS_UNICODE)
target_link_libraries(${MODULE} mingw_common)
set_entrypoint(${MODULE} WinMainCRTStartup)
endif(IS_UNICODE)
elseif(${TYPE} MATCHES win32cui)
set_subsystem(${MODULE} console)
set_entrypoint(${MODULE} mainCRTStartup)
if(NOT IS_UNICODE)
target_link_libraries(${MODULE} mingw_main)
if(IS_UNICODE)
set_entrypoint(${MODULE} wmainCRTStartup)
else()
target_link_libraries(${MODULE} mingw_wmain)
endif(NOT IS_UNICODE)
target_link_libraries(${MODULE} mingw_common)
set_entrypoint(${MODULE} mainCRTStartup)
endif(IS_UNICODE)
elseif(${TYPE} MATCHES win32dll)
set_entrypoint(${MODULE} DllMain 12)
target_link_libraries(${MODULE} mingw_dllmain mingw_common)
if(DEFINED baseaddress_${MODULE})
set_image_base(${MODULE} ${baseaddress_${MODULE}})
else()
@ -206,11 +201,9 @@ macro(set_module_type MODULE TYPE)
endif()
elseif(${TYPE} MATCHES win32ocx)
set_entrypoint(${MODULE} DllMain 12)
target_link_libraries(${MODULE} mingw_dllmain mingw_common)
set_target_properties(${MODULE} PROPERTIES SUFFIX ".ocx")
elseif(${TYPE} MATCHES cpl)
set_entrypoint(${MODULE} DllMain 12)
target_link_libraries(${MODULE} mingw_dllmain mingw_common)
set_target_properties(${MODULE} PROPERTIES SUFFIX ".cpl")
elseif(${TYPE} MATCHES kernelmodedriver)
set_target_properties(${MODULE} PROPERTIES LINK_FLAGS "-Wl,--exclude-all-symbols -Wl,-file-alignment=0x1000 -Wl,-section-alignment=0x1000" SUFFIX ".sys")
@ -271,6 +264,9 @@ set(IDL_DLLDATA_ARG --dlldata-only -o)
macro(add_importlibs MODULE)
add_dependency_node(${MODULE})
foreach(LIB ${ARGN})
if ("${LIB}" MATCHES "msvcrt")
target_link_libraries(${MODULE} msvcrtex)
endif()
target_link_libraries(${MODULE} ${CMAKE_BINARY_DIR}/importlibs/lib${LIB}.a)
add_dependencies(${MODULE} lib${LIB})
add_dependency_edge(${MODULE} ${LIB})

Binary file not shown.

View file

@ -10,6 +10,5 @@ add_subdirectory(libmpg123)
add_subdirectory(libsamplerate)
add_subdirectory(libwine)
add_subdirectory(libxml2)
add_subdirectory(mingw)
add_subdirectory(stlport)
add_subdirectory(zlib)

View file

@ -3,618 +3,10 @@ include_directories(include)
add_definitions(-D_CRTBLD)
list(APPEND CRT_SOURCE
conio/cgets.c
conio/cputs.c
conio/getch.c
conio/getche.c
conio/kbhit.c
conio/putch.c
conio/ungetch.c
direct/chdir.c
direct/chdrive.c
direct/getcwd.c
direct/getdcwd.c
direct/getdfree.c
direct/getdrive.c
direct/mkdir.c
direct/rmdir.c
direct/wchdir.c
direct/wgetcwd.c
direct/wgetdcwd.c
direct/wmkdir.c
direct/wrmdir.c
except/abnorter.c
except/checkesp.c
except/cpp.c
except/cppexcept.c
except/except.c
except/matherr.c
except/xcptfil.c
float/chgsign.c
float/copysign.c
float/fpclass.c
float/fpecode.c
float/isnan.c
float/nafter.c
float/scalb.c
locale/locale.c
math/acos.c
math/adjust.c
math/asin.c
math/cabs.c
math/cosf.c
math/cosh.c
math/div.c
math/fdivbug.c
math/frexp.c
math/huge_val.c
math/hypot.c
math/ldiv.c
math/logf.c
math/modf.c
math/powf.c
math/rand.c
math/sqrtf.c
math/s_modf.c
math/sinf.c
math/sinh.c
math/tanh.c
mbstring/hanzen.c
mbstring/ischira.c
mbstring/iskana.c
mbstring/iskmoji.c
mbstring/iskpun.c
mbstring/islead.c
mbstring/islwr.c
mbstring/ismbal.c
mbstring/ismbaln.c
mbstring/ismbc.c
mbstring/ismbgra.c
mbstring/ismbkaln.c
mbstring/ismblead.c
mbstring/ismbpri.c
mbstring/ismbpun.c
mbstring/ismbtrl.c
mbstring/isuppr.c
mbstring/jistojms.c
mbstring/jmstojis.c
mbstring/mbbtype.c
mbstring/mbccpy.c
mbstring/mbclen.c
mbstring/mbscat.c
mbstring/mbschr.c
mbstring/mbscmp.c
mbstring/mbscoll.c
mbstring/mbscpy.c
mbstring/mbscspn.c
mbstring/mbsdec.c
mbstring/mbsdup.c
mbstring/mbsicmp.c
mbstring/mbsicoll.c
mbstring/mbsinc.c
mbstring/mbslen.c
mbstring/mbslwr.c
mbstring/mbsncat.c
mbstring/mbsnccnt.c
mbstring/mbsncmp.c
mbstring/mbsncoll.c
mbstring/mbsncpy.c
mbstring/mbsnextc.c
mbstring/mbsnicmp.c
mbstring/mbsnicoll.c
mbstring/mbsninc.c
mbstring/mbsnset.c
mbstring/mbspbrk.c
mbstring/mbsrchr.c
mbstring/mbsrev.c
mbstring/mbsset.c
mbstring/mbsspn.c
mbstring/mbsspnp.c
mbstring/mbsstr.c
mbstring/mbstok.c
mbstring/mbstrlen.c
mbstring/mbsupr.c
mem/memcmp.c
mem/memccpy.c
mem/memicmp.c
misc/amsg.c
misc/assert.c
misc/environ.c
misc/getargs.c
misc/i10output.c
misc/initterm.c
misc/lock.c
misc/purecall.c
misc/stubs.c
misc/tls.c
printf/_cprintf.c
printf/_snprintf.c
printf/_snwprintf.c
printf/_vcprintf.c
printf/_vsnprintf.c
printf/_vsnwprintf.c
printf/fprintf.c
printf/fwprintf.c
printf/printf.c
printf/sprintf.c
printf/streamout.c
printf/swprintf.c
printf/vfprintf.c
printf/vfwprintf.c
printf/vprintf.c
printf/vsprintf.c
printf/vswprintf.c
printf/vwprintf.c
printf/wprintf.c
printf/wstreamout.c
process/_cwait.c
process/_system.c
process/dll.c
process/process.c
process/procid.c
process/thread.c
process/threadid.c
process/threadx.c
process/wprocess.c
search/bsearch.c
search/lfind.c
search/lsearch.c
signal/signal.c
signal/xcptinfo.c
stdio/_flsbuf.c
stdio/_flswbuf.c
stdio/access.c
stdio/file.c
stdio/find.c
stdio/find64.c
stdio/findi64.c
stdio/fmode.c
stdio/lock_file.c
stdio/perror.c
stdio/popen.c
stdio/stat.c
stdio/stat64.c
stdio/waccess.c
stdio/wfind.c
stdio/wfind64.c
stdio/wfindi64.c
stdio/wpopen.c
stdio/wstat.c
stdio/wstat64.c
stdlib/_exit.c
stdlib/abort.c
stdlib/atexit.c
stdlib/ecvt.c
stdlib/errno.c
stdlib/fcvt.c
stdlib/fcvtbuf.c
stdlib/fullpath.c
stdlib/gcvt.c
stdlib/getenv.c
stdlib/makepath.c
stdlib/makepath_s.c
stdlib/mbtowc.c
stdlib/mbstowcs.c
stdlib/obsol.c
stdlib/putenv.c
stdlib/qsort.c
stdlib/rot.c
stdlib/senv.c
stdlib/swab.c
stdlib/wfulpath.c
stdlib/wputenv.c
stdlib/wsenv.c
stdlib/wmakpath.c
stdlib/wmakpath_s.c
string/atof.c
string/atoi.c
string/atoi64.c
string/atol.c
string/ctype.c
string/itoa.c
string/itow.c
string/lasttok.c
string/scanf.c
string/splitp.c
string/strcoll.c
string/strcspn.c
string/strdup.c
string/strerror.c
string/stricmp.c
string/string.c
string/strlwr.c
string/strncoll.c
string/strnicmp.c
string/strpbrk.c
string/strrev.c
string/strset.c
string/strspn.c
string/strstr.c
string/strtod.c
string/strtoi64.c
string/strtok.c
string/strtol.c
string/strtoul.c
string/strtoull.c
string/strupr.c
string/strxfrm.c
string/wcs.c
string/wcstol.c
string/wcstoul.c
string/wsplitp.c
string/wtoi.c
string/wtoi64.c
string/wtol.c
sys_stat/systime.c
time/asctime.c
time/clock.c
time/ctime32.c
time/ctime64.c
time/ctime.c
time/difftime32.c
time/difftime64.c
time/difftime.c
time/ftime32.c
time/ftime64.c
time/ftime.c
time/futime32.c
time/futime64.c
time/futime.c
time/gmtime.c
time/localtime32.c
time/localtime64.c
time/localtime.c
time/mktime.c
time/strdate.c
time/strftime.c
time/strtime.c
time/time32.c
time/time64.c
time/time.c
time/timezone.c
time/tzname.c
time/utime32.c
time/utime64.c
time/utime.c
time/wasctime.c
time/wcsftime.c
time/wctime32.c
time/wctime64.c
time/wctime.c
time/wstrdate.c
time/wstrtime.c
time/wutime32.c
time/wutime64.c
time/wutime.c
wstring/wcscoll.c
wstring/wcscspn.c
wstring/wcsicmp.c
wstring/wcslwr.c
wstring/wcsnicmp.c
wstring/wcsspn.c
wstring/wcsstr.c
wstring/wcstok.c
wstring/wcsupr.c
wstring/wcsxfrm.c
wstring/wlasttok.c
wine/heap.c
wine/undname.c)
if(ARCH MATCHES i386)
list(APPEND CRT_SOURCE
except/i386/chkstk_asm.s
except/i386/prolog.s
except/i386/seh.s
except/i386/seh_prolog.s
except/i386/unwind.c
float/i386/clearfp.c
float/i386/cntrlfp.c
float/i386/fpreset.c
float/i386/logb.c
float/i386/statfp.c
setjmp/i386/setjmp.s)
elseif(ARCH MATCHES amd64)
list(APPEND CRT_SOURCE
except/amd64/chkstk_asm.s
except/amd64/seh.s
float/i386/clearfp.c
float/i386/cntrlfp.c
float/i386/fpreset.c
float/i386/logb.c
float/i386/statfp.c
setjmp/amd64/setjmp.s)
endif()
if(ARCH MATCHES i386)
list(APPEND CRT_SOURCE
math/i386/alldiv_asm.s
math/i386/alldvrm_asm.s
math/i386/allmul_asm.s
math/i386/allrem_asm.s
math/i386/allshl_asm.s
math/i386/allshr_asm.s
math/i386/atan_asm.s
math/i386/aulldiv_asm.s
math/i386/aulldvrm_asm.s
math/i386/aullrem_asm.s
math/i386/aullshr_asm.s
math/i386/ceil_asm.s
math/i386/ceilf.S
math/i386/cos_asm.s
math/i386/fabs_asm.s
math/i386/floor_asm.s
math/i386/floorf.S
math/i386/ftol_asm.s
math/i386/ftol2_asm.s
math/i386/log_asm.s
math/i386/log10_asm.s
math/i386/pow_asm.s
math/i386/sin_asm.s
math/i386/sqrt_asm.s
math/i386/tan_asm.s
math/i386/atan2_asm.s
math/i386/ci.c
math/i386/exp_asm.s
math/i386/fmod_asm.s
math/i386/fmodf_asm.s
math/i386/ldexp.c
mem/i386/memchr_asm.s
mem/i386/memmove_asm.s
mem/i386/memset_asm.s
misc/i386/readcr4.S
string/i386/strcat_asm.s
string/i386/strchr_asm.s
string/i386/strcmp_asm.s
string/i386/strcpy_asm.s
string/i386/strlen_asm.s
string/i386/strncat_asm.s
string/i386/strncmp_asm.s
string/i386/strncpy_asm.s
string/i386/strnlen_asm.s
string/i386/strrchr_asm.s
string/i386/wcscat_asm.s
string/i386/wcschr_asm.s
string/i386/wcscmp_asm.s
string/i386/wcscpy_asm.s
string/i386/wcslen_asm.s
string/i386/wcsncat_asm.s
string/i386/wcsncmp_asm.s
string/i386/wcsncpy_asm.s
string/i386/wcsnlen_asm.s
string/i386/wcsrchr_asm.s)
else()
list(APPEND CRT_SOURCE
math/stubs.c
mem/memchr.c
mem/memcpy.c
mem/memmove.c
mem/memset.c
string/strcat.c
string/strchr.c
string/strcmp.c
string/strcpy.c
string/strlen.c
string/strncat.c
string/strncmp.c
string/strncpy.c
string/strnlen.c
string/strrchr.c
string/wcscat.c
string/wcschr.c
string/wcscmp.c
string/wcscpy.c
string/wcslen.c
string/wcsncat.c
string/wcsncmp.c
string/wcsncpy.c
string/wcsnlen.c
string/wcsrchr.c)
endif()
if(ARCH MATCHES amd64)
list(APPEND CRT_SOURCE
math/cos.c
math/sin.c
math/amd64/alldiv.S
math/amd64/atan.S
math/amd64/atan2.S
math/amd64/ceil.S
math/amd64/ceilf.S
math/amd64/exp.S
math/amd64/fabs.S
math/amd64/floor.S
math/amd64/floorf.S
math/amd64/fmod.S
math/amd64/fmodf.S
math/amd64/ldexp.S
math/amd64/log.S
math/amd64/log10.S
math/amd64/pow.S
math/amd64/sqrt.S
math/amd64/sqrtf.S
math/amd64/tan.S)
endif()
add_library(crt ${CMAKE_CURRENT_BINARY_DIR}/crt_precomp.h.gch ${CRT_SOURCE})
set_property(TARGET crt PROPERTY COMPILE_DEFINITIONS __MINGW_IMPORT=extern USE_MSVCRT_PREFIX _MSVCRT_LIB_ _MSVCRT_ _MT)
add_pch(crt ${CMAKE_CURRENT_SOURCE_DIR}/precomp.h ${CRT_SOURCE})
add_dependencies(crt psdk asm)
list(APPEND LIBCNTPR_SOURCE
float/isnan.c
math/abs.c
math/div.c
math/labs.c
math/rand_nt.c
mbstring/mbstrlen.c
mem/memccpy.c
mem/memcmp.c
mem/memicmp.c
printf/_snprintf.c
printf/_snwprintf.c
printf/_vcprintf.c
printf/_vsnprintf.c
printf/_vsnwprintf.c
printf/sprintf.c
printf/streamout.c
printf/swprintf.c
printf/vprintf.c
printf/vsprintf.c
printf/vswprintf.c
printf/wstreamout.c
search/bsearch.c
search/lfind.c
stdlib/qsort.c
string/ctype.c
string/scanf.c
string/strcspn.c
string/stricmp.c
string/strnicmp.c
string/strlwr.c
string/strrev.c
string/strset.c
string/strstr.c
string/strupr.c
string/strpbrk.c
string/strspn.c
string/atoi64.c
string/atoi.c
string/atol.c
string/itoa.c
string/itow.c
string/mbstowcs_nt.c
string/splitp.c
string/strtol.c
string/strtoul.c
string/strtoull.c
string/wcs.c
string/wcstol.c
string/wcstombs_nt.c
string/wcstoul.c
string/wsplitp.c
string/wtoi64.c
string/wtoi.c
string/wtol.c
wstring/wcsicmp.c
wstring/wcslwr.c
wstring/wcsnicmp.c
wstring/wcsupr.c
wstring/wcscspn.c
wstring/wcsspn.c
wstring/wcsstr.c)
if(ARCH MATCHES i386)
list(APPEND LIBCNTPR_SOURCE
except/i386/chkstk_asm.s
except/i386/seh.s
except/i386/seh_prolog.s
setjmp/i386/setjmp.s
math/i386/alldiv_asm.s
math/i386/alldvrm_asm.s
math/i386/allmul_asm.s
math/i386/allrem_asm.s
math/i386/allshl_asm.s
math/i386/allshr_asm.s
math/i386/atan_asm.s
math/i386/aulldiv_asm.s
math/i386/aulldvrm_asm.s
math/i386/aullrem_asm.s
math/i386/aullshr_asm.s
math/i386/ceil_asm.s
math/i386/cos_asm.s
math/i386/fabs_asm.s
math/i386/floor_asm.s
math/i386/ftol_asm.s
math/i386/ftol2_asm.s
math/i386/log_asm.s
math/i386/log10_asm.s
math/i386/pow_asm.s
math/i386/sin_asm.s
math/i386/sqrt_asm.s
math/i386/tan_asm.s
math/i386/ci.c
misc/i386/readcr4.S)
elseif(ARCH MATCHES amd64)
list(APPEND LIBCNTPR_SOURCE
except/amd64/chkstk_asm.s
except/amd64/seh.s
setjmp/amd64/setjmp.s
math/cos.c
math/sin.c
math/amd64/alldiv.S
math/amd64/atan.S
math/amd64/atan2.S
math/amd64/ceil.S
math/amd64/exp.S
math/amd64/fabs.S
math/amd64/floor.S
math/amd64/fmod.S
math/amd64/ldexp.S
math/amd64/log.S
math/amd64/log10.S
math/amd64/pow.S
math/amd64/sqrt.S
math/amd64/tan.S)
endif()
if(ARCH MATCHES i386)
list(APPEND LIBCNTPR_SOURCE
mem/i386/memchr_asm.s
mem/i386/memmove_asm.s
mem/i386/memset_asm.s
string/i386/strcat_asm.s
string/i386/strchr_asm.s
string/i386/strcmp_asm.s
string/i386/strcpy_asm.s
string/i386/strlen_asm.s
string/i386/strncat_asm.s
string/i386/strncmp_asm.s
string/i386/strncpy_asm.s
string/i386/strnlen_asm.s
string/i386/strrchr_asm.s
string/i386/wcscat_asm.s
string/i386/wcschr_asm.s
string/i386/wcscmp_asm.s
string/i386/wcscpy_asm.s
string/i386/wcslen_asm.s
string/i386/wcsncat_asm.s
string/i386/wcsncmp_asm.s
string/i386/wcsncpy_asm.s
string/i386/wcsnlen_asm.s
string/i386/wcsrchr_asm.s)
else()
list(APPEND LIBCNTPR_SOURCE
mem/memchr.c
mem/memcpy.c
mem/memmove.c
mem/memset.c
string/strcat.c
string/strchr.c
string/strcmp.c
string/strcpy.c
string/strlen.c
string/strncat.c
string/strncmp.c
string/strncpy.c
string/strnlen.c
string/strrchr.c
string/wcscat.c
string/wcschr.c
string/wcscmp.c
string/wcscpy.c
string/wcslen.c
string/wcsncat.c
string/wcsncmp.c
string/wcsncpy.c
string/wcsnlen.c
string/wcsrchr.c)
endif()
add_library(libcntpr ${LIBCNTPR_SOURCE})
set_property(TARGET libcntpr PROPERTY COMPILE_DEFINITIONS NO_RTL_INLINES _NTSYSTEM_ _NTDLLBUILD_ _LIBCNT_ __CRT__NO_INLINE)
add_dependencies(libcntpr psdk asm)
include(crt.cmake)
include(libcntpr.cmake)
include(msvcrtex.cmake)
include(oldnames.cmake)
if(MSVC)
# This is a temporary solution until we have proper crt libs
@ -641,3 +33,7 @@ add_library(user32_wsprintf
string/wcstombs_nt.c)
set_property(TARGET user32_wsprintf PROPERTY COMPILE_DEFINITIONS _USER32_WSPRINTF)
add_library(getopt misc/getopt.c)
set_property(TARGET getopt PROPERTY COMPILE_DEFINITIONS _DLL __USE_CRTIMP)
add_dependencies(getopt psdk)

View file

@ -0,0 +1,438 @@
list(APPEND CRT_SOURCE
conio/cgets.c
conio/cputs.c
conio/getch.c
conio/getche.c
conio/kbhit.c
conio/putch.c
conio/ungetch.c
direct/chdir.c
direct/chdrive.c
direct/getcwd.c
direct/getdcwd.c
direct/getdfree.c
direct/getdrive.c
direct/mkdir.c
direct/rmdir.c
direct/wchdir.c
direct/wgetcwd.c
direct/wgetdcwd.c
direct/wmkdir.c
direct/wrmdir.c
except/abnorter.c
except/checkesp.c
except/cpp.c
except/cppexcept.c
except/except.c
except/matherr.c
except/xcptfil.c
float/chgsign.c
float/copysign.c
float/fpclass.c
float/fpecode.c
float/isnan.c
float/nafter.c
float/scalb.c
locale/locale.c
math/acos.c
math/adjust.c
math/asin.c
math/cabs.c
math/cosf.c
math/cosh.c
math/div.c
math/fdivbug.c
math/frexp.c
math/huge_val.c
math/hypot.c
math/ldiv.c
math/logf.c
math/modf.c
math/powf.c
math/rand.c
math/sqrtf.c
math/s_modf.c
math/sinf.c
math/sinh.c
math/tanh.c
mbstring/hanzen.c
mbstring/ischira.c
mbstring/iskana.c
mbstring/iskmoji.c
mbstring/iskpun.c
mbstring/islead.c
mbstring/islwr.c
mbstring/ismbal.c
mbstring/ismbaln.c
mbstring/ismbc.c
mbstring/ismbgra.c
mbstring/ismbkaln.c
mbstring/ismblead.c
mbstring/ismbpri.c
mbstring/ismbpun.c
mbstring/ismbtrl.c
mbstring/isuppr.c
mbstring/jistojms.c
mbstring/jmstojis.c
mbstring/mbbtype.c
mbstring/mbccpy.c
mbstring/mbclen.c
mbstring/mbscat.c
mbstring/mbschr.c
mbstring/mbscmp.c
mbstring/mbscoll.c
mbstring/mbscpy.c
mbstring/mbscspn.c
mbstring/mbsdec.c
mbstring/mbsdup.c
mbstring/mbsicmp.c
mbstring/mbsicoll.c
mbstring/mbsinc.c
mbstring/mbslen.c
mbstring/mbslwr.c
mbstring/mbsncat.c
mbstring/mbsnccnt.c
mbstring/mbsncmp.c
mbstring/mbsncoll.c
mbstring/mbsncpy.c
mbstring/mbsnextc.c
mbstring/mbsnicmp.c
mbstring/mbsnicoll.c
mbstring/mbsninc.c
mbstring/mbsnset.c
mbstring/mbspbrk.c
mbstring/mbsrchr.c
mbstring/mbsrev.c
mbstring/mbsset.c
mbstring/mbsspn.c
mbstring/mbsspnp.c
mbstring/mbsstr.c
mbstring/mbstok.c
mbstring/mbstrlen.c
mbstring/mbsupr.c
mem/memcmp.c
mem/memccpy.c
mem/memicmp.c
misc/amsg.c
misc/assert.c
misc/environ.c
misc/getargs.c
misc/i10output.c
misc/initterm.c
misc/lock.c
misc/purecall.c
misc/stubs.c
misc/tls.c
printf/_cprintf.c
printf/_snprintf.c
printf/_snwprintf.c
printf/_vcprintf.c
printf/_vsnprintf.c
printf/_vsnwprintf.c
printf/fprintf.c
printf/fwprintf.c
printf/printf.c
printf/sprintf.c
printf/streamout.c
printf/swprintf.c
printf/vfprintf.c
printf/vfwprintf.c
printf/vprintf.c
printf/vsprintf.c
printf/vswprintf.c
printf/vwprintf.c
printf/wprintf.c
printf/wstreamout.c
process/_cwait.c
process/_system.c
process/dll.c
process/process.c
process/procid.c
process/thread.c
process/threadid.c
process/threadx.c
process/wprocess.c
search/bsearch.c
search/lfind.c
search/lsearch.c
signal/signal.c
signal/xcptinfo.c
stdio/_flsbuf.c
stdio/_flswbuf.c
stdio/access.c
stdio/file.c
stdio/find.c
stdio/find64.c
stdio/findi64.c
stdio/fmode.c
stdio/lock_file.c
stdio/perror.c
stdio/popen.c
stdio/stat.c
stdio/stat64.c
stdio/waccess.c
stdio/wfind.c
stdio/wfind64.c
stdio/wfindi64.c
stdio/wpopen.c
stdio/wstat.c
stdio/wstat64.c
stdlib/_exit.c
stdlib/abort.c
stdlib/atexit.c
stdlib/ecvt.c
stdlib/errno.c
stdlib/fcvt.c
stdlib/fcvtbuf.c
stdlib/fullpath.c
stdlib/gcvt.c
stdlib/getenv.c
stdlib/makepath.c
stdlib/makepath_s.c
stdlib/mbtowc.c
stdlib/mbstowcs.c
stdlib/obsol.c
stdlib/putenv.c
stdlib/qsort.c
stdlib/rot.c
stdlib/senv.c
stdlib/swab.c
stdlib/wfulpath.c
stdlib/wputenv.c
stdlib/wsenv.c
stdlib/wmakpath.c
stdlib/wmakpath_s.c
string/atof.c
string/atoi.c
string/atoi64.c
string/atol.c
string/ctype.c
string/itoa.c
string/itow.c
string/lasttok.c
string/scanf.c
string/splitp.c
string/strcoll.c
string/strcspn.c
string/strdup.c
string/strerror.c
string/stricmp.c
string/string.c
string/strlwr.c
string/strncoll.c
string/strnicmp.c
string/strpbrk.c
string/strrev.c
string/strset.c
string/strspn.c
string/strstr.c
string/strtod.c
string/strtoi64.c
string/strtok.c
string/strtol.c
string/strtoul.c
string/strtoull.c
string/strupr.c
string/strxfrm.c
string/wcs.c
string/wcstol.c
string/wcstoul.c
string/wsplitp.c
string/wtoi.c
string/wtoi64.c
string/wtol.c
sys_stat/systime.c
time/asctime.c
time/clock.c
time/ctime32.c
time/ctime64.c
time/ctime.c
time/difftime32.c
time/difftime64.c
time/difftime.c
time/ftime32.c
time/ftime64.c
time/ftime.c
time/futime32.c
time/futime64.c
time/futime.c
time/gmtime.c
time/localtime32.c
time/localtime64.c
time/localtime.c
time/mktime.c
time/strdate.c
time/strftime.c
time/strtime.c
time/time32.c
time/time64.c
time/time.c
time/timezone.c
time/tzname.c
time/utime32.c
time/utime64.c
time/utime.c
time/wasctime.c
time/wcsftime.c
time/wctime32.c
time/wctime64.c
time/wctime.c
time/wstrdate.c
time/wstrtime.c
time/wutime32.c
time/wutime64.c
time/wutime.c
wstring/wcscoll.c
wstring/wcscspn.c
wstring/wcsicmp.c
wstring/wcslwr.c
wstring/wcsnicmp.c
wstring/wcsspn.c
wstring/wcsstr.c
wstring/wcstok.c
wstring/wcsupr.c
wstring/wcsxfrm.c
wstring/wlasttok.c
wine/heap.c
wine/undname.c)
if(ARCH MATCHES i386)
list(APPEND CRT_SOURCE
except/i386/chkstk_asm.s
except/i386/prolog.s
except/i386/seh.s
except/i386/seh_prolog.s
except/i386/unwind.c
float/i386/clearfp.c
float/i386/cntrlfp.c
float/i386/fpreset.c
float/i386/logb.c
float/i386/statfp.c
setjmp/i386/setjmp.s)
elseif(ARCH MATCHES amd64)
list(APPEND CRT_SOURCE
except/amd64/chkstk_asm.s
except/amd64/seh.s
float/i386/clearfp.c
float/i386/cntrlfp.c
float/i386/fpreset.c
float/i386/logb.c
float/i386/statfp.c
setjmp/amd64/setjmp.s)
endif()
if(ARCH MATCHES i386)
list(APPEND CRT_SOURCE
math/i386/alldiv_asm.s
math/i386/alldvrm_asm.s
math/i386/allmul_asm.s
math/i386/allrem_asm.s
math/i386/allshl_asm.s
math/i386/allshr_asm.s
math/i386/atan_asm.s
math/i386/aulldiv_asm.s
math/i386/aulldvrm_asm.s
math/i386/aullrem_asm.s
math/i386/aullshr_asm.s
math/i386/ceil_asm.s
math/i386/ceilf.S
math/i386/cos_asm.s
math/i386/fabs_asm.s
math/i386/floor_asm.s
math/i386/floorf.S
math/i386/ftol_asm.s
math/i386/ftol2_asm.s
math/i386/log_asm.s
math/i386/log10_asm.s
math/i386/pow_asm.s
math/i386/sin_asm.s
math/i386/sqrt_asm.s
math/i386/tan_asm.s
math/i386/atan2_asm.s
math/i386/ci.c
math/i386/exp_asm.s
math/i386/fmod_asm.s
math/i386/fmodf_asm.s
math/i386/ldexp.c
mem/i386/memchr_asm.s
mem/i386/memmove_asm.s
mem/i386/memset_asm.s
misc/i386/readcr4.S
string/i386/strcat_asm.s
string/i386/strchr_asm.s
string/i386/strcmp_asm.s
string/i386/strcpy_asm.s
string/i386/strlen_asm.s
string/i386/strncat_asm.s
string/i386/strncmp_asm.s
string/i386/strncpy_asm.s
string/i386/strnlen_asm.s
string/i386/strrchr_asm.s
string/i386/wcscat_asm.s
string/i386/wcschr_asm.s
string/i386/wcscmp_asm.s
string/i386/wcscpy_asm.s
string/i386/wcslen_asm.s
string/i386/wcsncat_asm.s
string/i386/wcsncmp_asm.s
string/i386/wcsncpy_asm.s
string/i386/wcsnlen_asm.s
string/i386/wcsrchr_asm.s)
else()
list(APPEND CRT_SOURCE
math/stubs.c
mem/memchr.c
mem/memcpy.c
mem/memmove.c
mem/memset.c
string/strcat.c
string/strchr.c
string/strcmp.c
string/strcpy.c
string/strlen.c
string/strncat.c
string/strncmp.c
string/strncpy.c
string/strnlen.c
string/strrchr.c
string/wcscat.c
string/wcschr.c
string/wcscmp.c
string/wcscpy.c
string/wcslen.c
string/wcsncat.c
string/wcsncmp.c
string/wcsncpy.c
string/wcsnlen.c
string/wcsrchr.c)
endif()
if(ARCH MATCHES amd64)
list(APPEND CRT_SOURCE
math/cos.c
math/sin.c
math/amd64/alldiv.S
math/amd64/atan.S
math/amd64/atan2.S
math/amd64/ceil.S
math/amd64/ceilf.S
math/amd64/exp.S
math/amd64/fabs.S
math/amd64/floor.S
math/amd64/floorf.S
math/amd64/fmod.S
math/amd64/fmodf.S
math/amd64/ldexp.S
math/amd64/log.S
math/amd64/log10.S
math/amd64/pow.S
math/amd64/sqrt.S
math/amd64/sqrtf.S
math/amd64/tan.S)
endif()
add_library(crt ${CMAKE_CURRENT_BINARY_DIR}/crt_precomp.h.gch ${CRT_SOURCE})
set_property(TARGET crt PROPERTY COMPILE_DEFINITIONS __MINGW_IMPORT=extern USE_MSVCRT_PREFIX _MSVCRT_LIB_ _MSVCRT_ _MT)
add_pch(crt ${CMAKE_CURRENT_SOURCE_DIR}/precomp.h ${CRT_SOURCE})
add_dependencies(crt psdk asm)

View file

@ -0,0 +1,187 @@
/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file is part of the w64 mingw-runtime package.
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
*/
#ifndef _INC_INTERNAL
#define _INC_INTERNAL
#include <crtdefs.h>
#ifdef __cplusplus
extern "C" {
#endif
#include <limits.h>
#include <windows.h>
#pragma pack(push,_CRT_PACKING)
#ifndef __INTERNAL_FUNC_DEFINED
#define __INTERNAL_FUNC_DEFINED
typedef void (__cdecl *_PVFV)(void);
typedef int (__cdecl *_PIFV)(void);
typedef void (__cdecl *_PVFI)(int);
#endif
#if defined (SPECIAL_CRTEXE) && (defined (_DLL) || defined (__GNUC__))
extern int _commode;
#else
_CRTIMP extern int _commode;
#endif
#define __IOINFO_TM_ANSI 0
#define __IOINFO_TM_UTF8 1
#define __IOINFO_TM_UTF16LE 2
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable:4214)
#pragma warning(disable:4820)
#endif
typedef struct {
intptr_t osfhnd;
char osfile;
char pipech;
int lockinitflag;
CRITICAL_SECTION lock;
char textmode : 7;
char unicode : 1;
char pipech2[2];
} ioinfo;
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#define IOINFO_ARRAY_ELTS (1 << 5)
#define _pioinfo(i) (__pioinfo[(i) >> 5] + ((i) & (IOINFO_ARRAY_ELTS - 1)))
#define _osfile(i) (_pioinfo(i)->osfile)
#define _pipech2(i) (_pioinfo(i)->pipech2)
#define _textmode(i) (_pioinfo(i)->textmode)
#define _tm_unicode(i) (_pioinfo(i)->unicode)
#define _pioinfo_safe(i) ((((i) != -1) && ((i) != -2)) ? _pioinfo(i) : &__badioinfo)
#define _osfhnd_safe(i) (_pioinfo_safe(i)->osfhnd)
#define _osfile_safe(i) (_pioinfo_safe(i)->osfile)
#define _pipech_safe(i) (_pioinfo_safe(i)->pipech)
#define _pipech2_safe(i) (_pioinfo_safe(i)->pipech2)
#define _textmode_safe(i) (_pioinfo_safe(i)->textmode)
#define _tm_unicode_safe(i) (_pioinfo_safe(i)->unicode)
#ifndef __badioinfo
extern ioinfo ** __MINGW_IMP_SYMBOL(__badioinfo)[];
#define __badioinfo (* __MINGW_IMP_SYMBOL(__badioinfo))
#endif
#ifndef __pioinfo
extern ioinfo ** __MINGW_IMP_SYMBOL(__pioinfo)[];
#define __pioinfo (* __MINGW_IMP_SYMBOL(__pioinfo))
#endif
#define _NO_CONSOLE_FILENO (intptr_t)-2
#ifndef _FILE_DEFINED
#define _FILE_DEFINED
struct _iobuf {
char *_ptr;
int _cnt;
char *_base;
int _flag;
int _file;
int _charbuf;
int _bufsiz;
char *_tmpfname;
};
typedef struct _iobuf FILE;
#endif
#if !defined (_FILEX_DEFINED) && defined (_WINDOWS_)
#define _FILEX_DEFINED
typedef struct {
FILE f;
CRITICAL_SECTION lock;
} _FILEX;
#endif
extern int _dowildcard;
extern int _newmode;
#ifndef __winitenv
extern wchar_t *** __MINGW_IMP_SYMBOL(__winitenv);
#define __winitenv (* __MINGW_IMP_SYMBOL(__winitenv))
#endif
#ifndef __initenv
extern char *** __MINGW_IMP_SYMBOL(__initenv);
#define __initenv (* __MINGW_IMP_SYMBOL(__initenv))
#endif
#ifndef _acmdln
extern char ** __MINGW_IMP_SYMBOL(_acmdln);
#define _acmdln (* __MINGW_IMP_SYMBOL(_acmdln))
/* _CRTIMP extern char *_acmdln; */
#endif
#ifndef _wcmdln
extern char ** __MINGW_IMP_SYMBOL(_wcmdln);
#define _wcmdln (* __MINGW_IMP_SYMBOL(_wcmdln))
/* __CRTIMP extern wchar_t *_wcmdln; */
#endif
_CRTIMP void __cdecl _amsg_exit(int);
int __CRTDECL _setargv(void);
int __CRTDECL __setargv(void);
int __CRTDECL _wsetargv(void);
int __CRTDECL __wsetargv(void);
int __CRTDECL main(int _Argc, char **_Argv, char **_Env);
int __CRTDECL wmain(int _Argc, wchar_t **_Argv, wchar_t **_Env);
#ifndef _STARTUP_INFO_DEFINED
#define _STARTUP_INFO_DEFINED
typedef struct {
int newmode;
} _startupinfo;
#endif
_CRTIMP int __cdecl __getmainargs(int * _Argc, char *** _Argv, char ***_Env, int _DoWildCard, _startupinfo *_StartInfo);
_CRTIMP int __cdecl __wgetmainargs(int * _Argc, wchar_t ***_Argv, wchar_t ***_Env, int _DoWildCard, _startupinfo *_StartInfo);
#define _CONSOLE_APP 1
#define _GUI_APP 2
typedef enum __enative_startup_state {
__uninitialized, __initializing, __initialized
} __enative_startup_state;
extern volatile __enative_startup_state __native_startup_state;
extern volatile void *__native_startup_lock;
extern volatile unsigned int __native_dllmain_reason;
extern volatile unsigned int __native_vcclrit_reason;
_CRTIMP void __cdecl __set_app_type (int);
typedef LONG NTSTATUS;
#include <crtdbg.h>
#include <errno.h>
void * __cdecl _encode_pointer(void *);
void * __cdecl _encoded_null();
void * __cdecl _decode_pointer(void *);
BOOL __cdecl _ValidateImageBase (PBYTE pImageBase);
PIMAGE_SECTION_HEADER __cdecl _FindPESection (PBYTE pImageBase, DWORD_PTR rva);
BOOL __cdecl _IsNonwritableInCurrentImage (PBYTE pTarget);
#ifdef __cplusplus
}
#endif
#pragma pack(pop)
#endif

View file

@ -0,0 +1,60 @@
/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file is part of the w64 mingw-runtime package.
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
*/
#ifndef _INC_OSCALLS
#define _INC_OSCALLS
#ifndef _CRTBLD
#error ERROR: Use of C runtime library internal header file.
#endif
#include <crtdefs.h>
#ifdef NULL
#undef NULL
#endif
#define NOMINMAX
#define _WIN32_FUSION 0x0100
#include <windows.h>
#ifndef NULL
#ifdef __cplusplus
#define NULL 0
#else
#define NULL ((void *)0)
#endif
#endif
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable:4214)
#endif
typedef struct _FTIME
{
unsigned short twosecs : 5;
unsigned short minutes : 6;
unsigned short hours : 5;
} FTIME;
typedef FTIME *PFTIME;
typedef struct _FDATE
{
unsigned short day : 5;
unsigned short month : 4;
unsigned short year : 7;
} FDATE;
#ifdef _MSC_VER
#pragma warning(pop)
#endif
typedef FDATE *PFDATE;
#endif

View file

@ -0,0 +1,72 @@
/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file is part of the w64 mingw-runtime package.
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
*/
#if defined(_MSC_VER)
#if defined(_M_IA64) || defined(_M_AMD64)
#define _ATTRIBUTES
#else
#define _ATTRIBUTES read
#endif
/* Reference list of existing section for msvcrt. */
#pragma section(".CRTMP$XCA",long,_ATTRIBUTES)
#pragma section(".CRTMP$XCZ",long,_ATTRIBUTES)
#pragma section(".CRTMP$XIA",long,_ATTRIBUTES)
#pragma section(".CRTMP$XIZ",long,_ATTRIBUTES)
#pragma section(".CRTMA$XCA",long,_ATTRIBUTES)
#pragma section(".CRTMA$XCZ",long,_ATTRIBUTES)
#pragma section(".CRTMA$XIA",long,_ATTRIBUTES)
#pragma section(".CRTMA$XIZ",long,_ATTRIBUTES)
#pragma section(".CRTVT$XCA",long,_ATTRIBUTES)
#pragma section(".CRTVT$XCZ",long,_ATTRIBUTES)
#pragma section(".CRT$XCA",long,_ATTRIBUTES)
#pragma section(".CRT$XCAA",long,_ATTRIBUTES)
#pragma section(".CRT$XCC",long,_ATTRIBUTES)
#pragma section(".CRT$XCZ",long,_ATTRIBUTES)
#pragma section(".CRT$XDA",long,_ATTRIBUTES)
#pragma section(".CRT$XDC",long,_ATTRIBUTES)
#pragma section(".CRT$XDZ",long,_ATTRIBUTES)
#pragma section(".CRT$XIA",long,_ATTRIBUTES)
#pragma section(".CRT$XIAA",long,_ATTRIBUTES)
#pragma section(".CRT$XIC",long,_ATTRIBUTES)
#pragma section(".CRT$XID",long,_ATTRIBUTES)
#pragma section(".CRT$XIY",long,_ATTRIBUTES)
#pragma section(".CRT$XIZ",long,_ATTRIBUTES)
#pragma section(".CRT$XLA",long,_ATTRIBUTES)
#pragma section(".CRT$XLC",long,_ATTRIBUTES)
#pragma section(".CRT$XLD",long,_ATTRIBUTES)
#pragma section(".CRT$XLZ",long,_ATTRIBUTES)
#pragma section(".CRT$XPA",long,_ATTRIBUTES)
#pragma section(".CRT$XPX",long,_ATTRIBUTES)
#pragma section(".CRT$XPXA",long,_ATTRIBUTES)
#pragma section(".CRT$XPZ",long,_ATTRIBUTES)
#pragma section(".CRT$XTA",long,_ATTRIBUTES)
#pragma section(".CRT$XTB",long,_ATTRIBUTES)
#pragma section(".CRT$XTX",long,_ATTRIBUTES)
#pragma section(".CRT$XTZ",long,_ATTRIBUTES)
#pragma section(".rdata$T",long,read)
#pragma section(".rtc$IAA",long,read)
#pragma section(".rtc$IZZ",long,read)
#pragma section(".rtc$TAA",long,read)
#pragma section(".rtc$TZZ",long,read)
/* for tlssup.c: */
#pragma section(".tls",long,read,write)
#pragma section(".tls$AAA",long,read,write)
#pragma section(".tls$ZZZ",long,read,write)
#endif /* _MSC_VER */
#if defined(_MSC_VER)
#define _CRTALLOC(x) __declspec(allocate(x))
#elif defined(__GNUC__)
#define _CRTALLOC(x) __attribute__ ((section (x) ))
#else
#error Your compiler is not supported.
#endif

View file

@ -0,0 +1,174 @@
list(APPEND LIBCNTPR_SOURCE
float/isnan.c
math/abs.c
math/div.c
math/labs.c
math/rand_nt.c
mbstring/mbstrlen.c
mem/memccpy.c
mem/memcmp.c
mem/memicmp.c
printf/_snprintf.c
printf/_snwprintf.c
printf/_vcprintf.c
printf/_vsnprintf.c
printf/_vsnwprintf.c
printf/sprintf.c
printf/streamout.c
printf/swprintf.c
printf/vprintf.c
printf/vsprintf.c
printf/vswprintf.c
printf/wstreamout.c
search/bsearch.c
search/lfind.c
stdlib/qsort.c
string/ctype.c
string/scanf.c
string/strcspn.c
string/stricmp.c
string/strnicmp.c
string/strlwr.c
string/strrev.c
string/strset.c
string/strstr.c
string/strupr.c
string/strpbrk.c
string/strspn.c
string/atoi64.c
string/atoi.c
string/atol.c
string/itoa.c
string/itow.c
string/mbstowcs_nt.c
string/splitp.c
string/strtol.c
string/strtoul.c
string/strtoull.c
string/wcs.c
string/wcstol.c
string/wcstombs_nt.c
string/wcstoul.c
string/wsplitp.c
string/wtoi64.c
string/wtoi.c
string/wtol.c
wstring/wcsicmp.c
wstring/wcslwr.c
wstring/wcsnicmp.c
wstring/wcsupr.c
wstring/wcscspn.c
wstring/wcsspn.c
wstring/wcsstr.c)
if(ARCH MATCHES i386)
list(APPEND LIBCNTPR_SOURCE
except/i386/chkstk_asm.s
except/i386/seh.s
except/i386/seh_prolog.s
setjmp/i386/setjmp.s
math/i386/alldiv_asm.s
math/i386/alldvrm_asm.s
math/i386/allmul_asm.s
math/i386/allrem_asm.s
math/i386/allshl_asm.s
math/i386/allshr_asm.s
math/i386/atan_asm.s
math/i386/aulldiv_asm.s
math/i386/aulldvrm_asm.s
math/i386/aullrem_asm.s
math/i386/aullshr_asm.s
math/i386/ceil_asm.s
math/i386/cos_asm.s
math/i386/fabs_asm.s
math/i386/floor_asm.s
math/i386/ftol_asm.s
math/i386/ftol2_asm.s
math/i386/log_asm.s
math/i386/log10_asm.s
math/i386/pow_asm.s
math/i386/sin_asm.s
math/i386/sqrt_asm.s
math/i386/tan_asm.s
math/i386/ci.c
misc/i386/readcr4.S)
elseif(ARCH MATCHES amd64)
list(APPEND LIBCNTPR_SOURCE
except/amd64/chkstk_asm.s
except/amd64/seh.s
setjmp/amd64/setjmp.s
math/cos.c
math/sin.c
math/amd64/alldiv.S
math/amd64/atan.S
math/amd64/atan2.S
math/amd64/ceil.S
math/amd64/exp.S
math/amd64/fabs.S
math/amd64/floor.S
math/amd64/fmod.S
math/amd64/ldexp.S
math/amd64/log.S
math/amd64/log10.S
math/amd64/pow.S
math/amd64/sqrt.S
math/amd64/tan.S)
endif()
if(ARCH MATCHES i386)
list(APPEND LIBCNTPR_SOURCE
mem/i386/memchr_asm.s
mem/i386/memmove_asm.s
mem/i386/memset_asm.s
string/i386/strcat_asm.s
string/i386/strchr_asm.s
string/i386/strcmp_asm.s
string/i386/strcpy_asm.s
string/i386/strlen_asm.s
string/i386/strncat_asm.s
string/i386/strncmp_asm.s
string/i386/strncpy_asm.s
string/i386/strnlen_asm.s
string/i386/strrchr_asm.s
string/i386/wcscat_asm.s
string/i386/wcschr_asm.s
string/i386/wcscmp_asm.s
string/i386/wcscpy_asm.s
string/i386/wcslen_asm.s
string/i386/wcsncat_asm.s
string/i386/wcsncmp_asm.s
string/i386/wcsncpy_asm.s
string/i386/wcsnlen_asm.s
string/i386/wcsrchr_asm.s)
else()
list(APPEND LIBCNTPR_SOURCE
mem/memchr.c
mem/memcpy.c
mem/memmove.c
mem/memset.c
string/strcat.c
string/strchr.c
string/strcmp.c
string/strcpy.c
string/strlen.c
string/strncat.c
string/strncmp.c
string/strncpy.c
string/strnlen.c
string/strrchr.c
string/wcscat.c
string/wcschr.c
string/wcscmp.c
string/wcscpy.c
string/wcslen.c
string/wcsncat.c
string/wcsncmp.c
string/wcsncpy.c
string/wcsnlen.c
string/wcsrchr.c)
endif()
add_library(libcntpr ${LIBCNTPR_SOURCE})
set_property(TARGET libcntpr PROPERTY COMPILE_DEFINITIONS NO_RTL_INLINES _NTSYSTEM_ _NTDLLBUILD_ _LIBCNT_ __CRT__NO_INLINE)
add_dependencies(libcntpr psdk asm)

View file

@ -0,0 +1,394 @@
#include <assert.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <stdarg.h>
#include <stdio.h>
#define REPLACE_GETOPT
#define _DIAGASSERT(x) do {} while (0)
#ifdef REPLACE_GETOPT
#ifdef __weak_alias
__weak_alias(getopt,_getopt)
#endif
int opterr = 1;
int optind = 1;
int optopt = '?';
int optreset;
char *optarg;
#endif
#ifdef __weak_alias
__weak_alias(getopt_long,_getopt_long)
#endif
#ifndef __CYGWIN__
#define __progname __argv[0]
#else
extern char __declspec(dllimport) *__progname;
#endif
#define IGNORE_FIRST (*options == '-' || *options == '+')
#define PRINT_ERROR ((opterr) && ((*options != ':') || (IGNORE_FIRST && options[1] != ':')))
#ifndef IS_POSIXLY_CORRECT
#define IS_POSIXLY_CORRECT (getenv("POSIXLY_CORRECT") != NULL)
#endif
#define PERMUTE (!IS_POSIXLY_CORRECT && !IGNORE_FIRST)
#define IN_ORDER (!IS_POSIXLY_CORRECT && *options == '-')
#define BADCH (int)'?'
#define BADARG ((IGNORE_FIRST && options[1] == ':') || (*options == ':') ? (int)':' : (int)'?')
#define INORDER (int)1
static char EMSG[1];
static int getopt_internal (int,char * const *,const char *);
static int gcd (int,int);
static void permute_args (int,int,int,char * const *);
static char *place = EMSG;
static int nonopt_start = -1;
static int nonopt_end = -1;
static const char recargchar[] = "option requires an argument -- %c";
static const char recargstring[] = "option requires an argument -- %s";
static const char ambig[] = "ambiguous option -- %.*s";
static const char noarg[] = "option doesn't take an argument -- %.*s";
static const char illoptchar[] = "unknown option -- %c";
static const char illoptstring[] = "unknown option -- %s";
static void
_vwarnx(const char *fmt,va_list ap)
{
(void)fprintf(stderr,"%s: ",__progname);
if (fmt != NULL)
(void)vfprintf(stderr,fmt,ap);
(void)fprintf(stderr,"\n");
}
static void
warnx(const char *fmt,...)
{
va_list ap;
va_start(ap,fmt);
_vwarnx(fmt,ap);
va_end(ap);
}
static int
gcd(a,b)
int a;
int b;
{
int c;
c = a % b;
while (c != 0) {
a = b;
b = c;
c = a % b;
}
return b;
}
static void
permute_args(panonopt_start,panonopt_end,opt_end,nargv)
int panonopt_start;
int panonopt_end;
int opt_end;
char * const *nargv;
{
int cstart,cyclelen,i,j,ncycle,nnonopts,nopts,pos;
char *swap;
_DIAGASSERT(nargv != NULL);
nnonopts = panonopt_end - panonopt_start;
nopts = opt_end - panonopt_end;
ncycle = gcd(nnonopts,nopts);
cyclelen = (opt_end - panonopt_start) / ncycle;
for (i = 0; i < ncycle; i++) {
cstart = panonopt_end+i;
pos = cstart;
for (j = 0; j < cyclelen; j++) {
if (pos >= panonopt_end)
pos -= nnonopts;
else
pos += nopts;
swap = nargv[pos];
((char **) nargv)[pos] = nargv[cstart];
((char **)nargv)[cstart] = swap;
}
}
}
static int
getopt_internal(nargc,nargv,options)
int nargc;
char * const *nargv;
const char *options;
{
char *oli;
int optchar;
_DIAGASSERT(nargv != NULL);
_DIAGASSERT(options != NULL);
optarg = NULL;
if (optind == 0)
optind = 1;
if (optreset)
nonopt_start = nonopt_end = -1;
start:
if (optreset || !*place) {
optreset = 0;
if (optind >= nargc) {
place = EMSG;
if (nonopt_end != -1) {
permute_args(nonopt_start,nonopt_end,optind,nargv);
optind -= nonopt_end - nonopt_start;
}
else if (nonopt_start != -1) {
optind = nonopt_start;
}
nonopt_start = nonopt_end = -1;
return -1;
}
if ((*(place = nargv[optind]) != '-')
|| (place[1] == '\0')) {
place = EMSG;
if (IN_ORDER) {
optarg = nargv[optind++];
return INORDER;
}
if (!PERMUTE) {
return -1;
}
if (nonopt_start == -1)
nonopt_start = optind;
else if (nonopt_end != -1) {
permute_args(nonopt_start,nonopt_end,optind,nargv);
nonopt_start = optind -
(nonopt_end - nonopt_start);
nonopt_end = -1;
}
optind++;
goto start;
}
if (nonopt_start != -1 && nonopt_end == -1)
nonopt_end = optind;
if (place[1] && *++place == '-') {
place++;
return -2;
}
}
if ((optchar = (int)*place++) == (int)':' ||
(oli = strchr(options + (IGNORE_FIRST ? 1 : 0),optchar)) == NULL) {
if (!*place)
++optind;
if (PRINT_ERROR)
warnx(illoptchar,optchar);
optopt = optchar;
return BADCH;
}
if (optchar == 'W' && oli[1] == ';') {
if (*place)
return -2;
if (++optind >= nargc) {
place = EMSG;
if (PRINT_ERROR)
warnx(recargchar,optchar);
optopt = optchar;
return BADARG;
} else
place = nargv[optind];
return -2;
}
if (*++oli != ':') {
if (!*place)
++optind;
} else {
optarg = NULL;
if (*place)
optarg = place;
else if (oli[1] != ':') {
if (++optind >= nargc) {
place = EMSG;
if (PRINT_ERROR)
warnx(recargchar,optchar);
optopt = optchar;
return BADARG;
} else
optarg = nargv[optind];
}
place = EMSG;
++optind;
}
return optchar;
}
#ifdef REPLACE_GETOPT
int
getopt(nargc,nargv,options)
int nargc;
char * const *nargv;
const char *options;
{
int retval;
_DIAGASSERT(nargv != NULL);
_DIAGASSERT(options != NULL);
if ((retval = getopt_internal(nargc,nargv,options)) == -2) {
++optind;
if (nonopt_end != -1) {
permute_args(nonopt_start,nonopt_end,optind,nargv);
optind -= nonopt_end - nonopt_start;
}
nonopt_start = nonopt_end = -1;
retval = -1;
}
return retval;
}
#endif
int
getopt_long(nargc,nargv,options,long_options,idx)
int nargc;
char * const *nargv;
const char *options;
const struct option *long_options;
int *idx;
{
int retval;
_DIAGASSERT(nargv != NULL);
_DIAGASSERT(options != NULL);
_DIAGASSERT(long_options != NULL);
if ((retval = getopt_internal(nargc,nargv,options)) == -2) {
char *current_argv,*has_equal;
size_t current_argv_len;
int i,match;
current_argv = place;
match = -1;
optind++;
place = EMSG;
if (*current_argv == '\0') {
if (nonopt_end != -1) {
permute_args(nonopt_start,nonopt_end,optind,nargv);
optind -= nonopt_end - nonopt_start;
}
nonopt_start = nonopt_end = -1;
return -1;
}
if ((has_equal = strchr(current_argv,'=')) != NULL) {
current_argv_len = has_equal - current_argv;
has_equal++;
} else
current_argv_len = strlen(current_argv);
for (i = 0; long_options[i].name; i++) {
if (strncmp(current_argv,long_options[i].name,current_argv_len))
continue;
if (strlen(long_options[i].name) ==
(unsigned)current_argv_len) {
match = i;
break;
}
if (match == -1)
match = i;
else {
if (PRINT_ERROR)
warnx(ambig,(int)current_argv_len,current_argv);
optopt = 0;
return BADCH;
}
}
if (match != -1) {
if (long_options[match].has_arg == no_argument
&& has_equal) {
if (PRINT_ERROR)
warnx(noarg,(int)current_argv_len,current_argv);
if (long_options[match].flag == NULL)
optopt = long_options[match].val;
else
optopt = 0;
return BADARG;
}
if (long_options[match].has_arg == required_argument ||
long_options[match].has_arg == optional_argument) {
if (has_equal)
optarg = has_equal;
else if (long_options[match].has_arg ==
required_argument) {
optarg = nargv[optind++];
}
}
if ((long_options[match].has_arg == required_argument)
&& (optarg == NULL)) {
if (PRINT_ERROR)
warnx(recargstring,current_argv);
if (long_options[match].flag == NULL)
optopt = long_options[match].val;
else
optopt = 0;
--optind;
return BADARG;
}
} else {
if (PRINT_ERROR)
warnx(illoptstring,current_argv);
optopt = 0;
return BADCH;
}
if (long_options[match].flag) {
*long_options[match].flag = long_options[match].val;
retval = 0;
} else
retval = long_options[match].val;
if (idx)
*idx = match;
}
return retval;
}

View file

@ -0,0 +1,121 @@
LIBRARY msvcrt.dll
EXPORTS
access==_access
chdir==_chdir
chmod==_chmod
chsize==_chsize
close==_close
creat==_creat
cwait==_cwait
daylight==_daylight
dup==_dup
dup2==_dup2
ecvt==_ecvt
eof==_eof
execl==_execl
execle==_execle
execlp==_execlp
execlpe==_execlpe
execv==_execv
execve==_execve
execvp==_execvp
execvpe==_execvpe
fcvt==_fcvt
fdopen==_fdopen
fgetchar==_fgetchar
fgetwchar==_fgetwchar
filelength==_filelength
fileno==_fileno
fpreset==_fpreset
fputchar==_fputchar
fputwchar==_fputwchar
fstat==_fstat
ftime==_ftime
gcvt==_gcvt
getch==_getch
getche==_getche
getcwd==_getcwd
getpid==_getpid
getw==_getw
heapwalk==_heapwalk
isatty==_isatty
itoa==_itoa
kbhit==_kbhit
lfind==_lfind
lsearch==_lsearch
lseek==_lseek
ltoa==_ltoa
memccpy==_memccpy
memicmp==_memicmp
mkdir==_mkdir
mktemp==_mktemp
open==_open
pclose==_pclose
popen==_popen
putch==_putch
putenv==_putenv
putw==_putw
read==_read
rmdir==_rmdir
rmtmp==_rmtmp
searchenv==_searchenv
setmode==_setmode
snprintf=_snprintf
sopen==_sopen
spawnl==_spawnl
spawnle==_spawnle
spawnlp==_spawnlp
spawnlpe==_spawnlpe
spawnv==_spawnv
spawnve==_spawnve
spawnvp==_spawnvp
spawnvpe==_spawnvpe
stat==_stat
strcmpi==_strcmpi
strdup==_strdup
stricmp==_stricmp
stricoll==_stricoll
strlwr==_strlwr
strnicmp==_strnicmp
strnset==_strnset
strrev==_strrev
strset==_strset
strupr==_strupr
swab==_swab
tell==_tell
tempnam==_tempnam
timezone==_timezone
tzname==_tzname
tzset==_tzset
umask==_umask
ungetch==_ungetch
unlink==_unlink
utime==_utime
wcsdup==_wcsdup
wcsicmp==_wcsicmp
wcsicoll==_wcsicoll
wcslwr==_wcslwr
wcsnicmp==_wcsnicmp
wcsnset==_wcsnset
wcsrev==_wcsrev
wcsset==_wcsset
wcsupr==_wcsupr
wpopen==_wpopen
write==_write
; non-ANSI functions declared in math.h
j0==_j0
j1==_j1
jn==_jn
y0==_y0
y1==_y1
yn==_yn
chgsign==_chgsign
scalb==_scalb
finite==_finite
fpclass==_fpclass
; C99 functions
cabs==_cabs
hypot==_hypot
logb==_logb
nextafter==_nextafter

View file

@ -0,0 +1,47 @@
include_directories(include/internal/mingw-w64)
if(NOT MSVC)
add_definitions(-Wno-main)
endif()
list(APPEND MSVCRTEX_SOURCE
startup/crtexe.c
startup/wcrtexe.c
startup/_newmode.c
startup/wildcard.c
startup/tlssup.c
startup/mingw_helpers.c
startup/natstart.c
startup/charmax.c
startup/merr.c
startup/atonexit.c
startup/txtmode.c
startup/pseudo-reloc.c
startup/tlsmcrt.c
startup/tlsthrd.c
startup/tlsmthread.c
startup/cinitexe.c
startup/gs_support.c
startup/dll_argv.c
startup/dllargv.c
startup/wdllargv.c
startup/crt0_c.c
startup/crt0_w.c
misc/fltused.c
)
if(MSVC)
list(APPEND MSVCRTEX_SOURCE startup/mscmain.c)
else()
list(APPEND MSVCRTEX_SOURCE startup/gccmain.c)
endif()
add_library(msvcrtex ${MSVCRTEX_SOURCE})
set_target_properties(msvcrtex PROPERTIES COMPILE_DEFINITIONS _M_CEE_PURE)
if(NOT MSVC)
target_link_libraries(msvcrtex oldnames)
endif()

View file

@ -0,0 +1,10 @@
if(NOT MSVC)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/liboldnames.a
COMMAND ${MINGW_PREFIX}dlltool --def ${CMAKE_CURRENT_SOURCE_DIR}/moldname-msvcrt.def --kill-at --output-lib ${CMAKE_CURRENT_BINARY_DIR}/liboldnames.a
COMMAND ${MINGW_PREFIX}ar -rc ${CMAKE_CURRENT_BINARY_DIR}/liboldnames.a)
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/liboldnames.a PROPERTIES GENERATED TRUE)
add_custom_target(oldnames ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/liboldnames.a)
endif()

View file

@ -0,0 +1,7 @@
/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file is part of the w64 mingw-runtime package.
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
*/
int _newmode = 0;

View file

@ -0,0 +1,59 @@
/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file is part of the w64 mingw-runtime package.
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
*/
#undef CRTDLL
#ifndef _DLL
#define _DLL
#endif
#include <oscalls.h>
#include <internal.h>
#include <stdlib.h>
#include <crtdefs.h>
#include <limits.h>
#include <windows.h>
#define _EXIT_LOCK1 8
void __cdecl _lock (int _File);
void __cdecl _unlock (int _File);
_PVFV *__onexitbegin;
_PVFV *__onexitend;
extern _CRTIMP _onexit_t __dllonexit (_onexit_t, _PVFV**, _PVFV**);
extern _onexit_t (__cdecl * __MINGW_IMP_SYMBOL(_onexit)) (_onexit_t func);
/* Choose a different name to prevent name conflicts. The CRT one works fine. */
_onexit_t __cdecl mingw_onexit(_onexit_t func);
_onexit_t __cdecl mingw_onexit(_onexit_t func)
{
_PVFV *onexitbegin;
_PVFV *onexitend;
_onexit_t retval;
onexitbegin = (_PVFV *) _decode_pointer (__onexitbegin);
if (onexitbegin == (_PVFV *) -1)
return (* __MINGW_IMP_SYMBOL(_onexit)) (func);
_lock (_EXIT_LOCK1);
onexitbegin = (_PVFV *) _decode_pointer (__onexitbegin);
onexitend = (_PVFV *) _decode_pointer (__onexitend);
retval = __dllonexit (func, &onexitbegin, &onexitend);
__onexitbegin = (_PVFV *) _encode_pointer (onexitbegin);
__onexitend = (_PVFV *) _encode_pointer (onexitend);
_unlock (_EXIT_LOCK1);
return retval;
}
int __cdecl
atexit (_PVFV func)
{
return (mingw_onexit((_onexit_t)func) == NULL) ? -1 : 0;
}

View file

@ -0,0 +1,21 @@
/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file is part of the w64 mingw-runtime package.
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
*/
#include <sect_attribs.h>
#include <internal.h>
__declspec(dllimport) int __lconv_init (void);
int mingw_initcharmax = 0;
int _charmax = 255;
static int my_lconv_init(void)
{
return __lconv_init();
}
_CRTALLOC(".CRT$XIC") _PIFV __mingw_pinit = my_lconv_init;

View file

@ -0,0 +1,12 @@
#include <stdio.h>
#include <internal.h>
#include <sect_attribs.h>
#ifdef _MSC_VER
#pragma comment(linker, "/merge:.CRT=.rdata")
#endif
_CRTALLOC(".CRT$XIA") _PVFV __xi_a[] = { NULL };
_CRTALLOC(".CRT$XIZ") _PVFV __xi_z[] = { NULL };
_CRTALLOC(".CRT$XCA") _PVFV __xc_a[] = { NULL };
_CRTALLOC(".CRT$XCZ") _PVFV __xc_z[] = { NULL };

View file

@ -0,0 +1,20 @@
/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file is part of the w64 mingw-runtime package.
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
*/
#include <windows.h>
extern HINSTANCE __mingw_winmain_hInstance;
extern LPSTR __mingw_winmain_lpCmdLine;
extern DWORD __mingw_winmain_nShowCmd;
/*ARGSUSED*/
int main (int __UNUSED_PARAM(flags),
char ** __UNUSED_PARAM(cmdline),
char ** __UNUSED_PARAM(inst))
{
return (int) WinMain (__mingw_winmain_hInstance, NULL,
__mingw_winmain_lpCmdLine, __mingw_winmain_nShowCmd);
}

View file

@ -0,0 +1,25 @@
/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file is part of the w64 mingw-runtime package.
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
*/
#include <windows.h>
/* Do the UNICODE prototyping of WinMain. Be aware that in winbase.h WinMain is a macro
defined to wWinMain. */
int WINAPI wWinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPWSTR lpCmdLine,int nShowCmd);
extern HINSTANCE __mingw_winmain_hInstance;
extern LPWSTR __mingw_winmain_lpCmdLine;
extern DWORD __mingw_winmain_nShowCmd;
int wmain (int, wchar_t **, wchar_t **);
/*ARGSUSED*/
int wmain (int __UNUSED_PARAM(flags),
wchar_t ** __UNUSED_PARAM(cmdline),
wchar_t ** __UNUSED_PARAM(inst))
{
return (int) wWinMain (__mingw_winmain_hInstance, NULL,
__mingw_winmain_lpCmdLine, __mingw_winmain_nShowCmd);
}

View file

@ -0,0 +1,502 @@
/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file is part of the w64 mingw-runtime package.
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
*/
#undef CRTDLL
#ifndef _DLL
#define _DLL
#endif
#define SPECIAL_CRTEXE
#include <oscalls.h>
#include <internal.h>
#include <process.h>
#include <signal.h>
#include <math.h>
#include <stdlib.h>
#include <tchar.h>
#include <sect_attribs.h>
#include <locale.h>
#include <intrin.h>
#ifndef __winitenv
extern wchar_t *** __MINGW_IMP_SYMBOL(__winitenv);
#define __winitenv (* __MINGW_IMP_SYMBOL(__winitenv))
#endif
#ifndef __initenv
extern char *** __MINGW_IMP_SYMBOL(__initenv);
#define __initenv (* __MINGW_IMP_SYMBOL(__initenv))
#endif
/* Hack, for bug in ld. Will be removed soon. */
#ifndef _MSC_VER
#define __ImageBase __MINGW_LSYMBOL(_image_base__)
#endif
/* This symbol is defined by ld. */
extern IMAGE_DOS_HEADER __ImageBase;
extern void _fpreset (void);
#define SPACECHAR _T(' ')
#define DQUOTECHAR _T('\"')
__declspec(dllimport) void __setusermatherr(int (__cdecl *)(struct _exception *));
extern int * __MINGW_IMP_SYMBOL(_fmode);
extern int * __MINGW_IMP_SYMBOL(_commode);
extern int * __MINGW_IMP_SYMBOL(_commode);
#define _commode (* __MINGW_IMP_SYMBOL(_commode))
extern int _dowildcard;
#if defined(__GNUC__)
int _MINGW_INSTALL_DEBUG_MATHERR __attribute__((weak)) = 0;
#else
int _MINGW_INSTALL_DEBUG_MATHERR = 0;
#endif
extern int __defaultmatherr;
extern _CRTIMP void __cdecl _initterm(_PVFV *, _PVFV *);
static int __cdecl check_managed_app (void);
extern _CRTALLOC(".CRT$XIA") _PIFV __xi_a[];
extern _CRTALLOC(".CRT$XIZ") _PIFV __xi_z[];
extern _CRTALLOC(".CRT$XCA") _PVFV __xc_a[];
extern _CRTALLOC(".CRT$XCZ") _PVFV __xc_z[];
/* TLS initialization hook. */
extern const PIMAGE_TLS_CALLBACK __dyn_tls_init_callback;
extern _PVFV *__onexitbegin;
extern _PVFV *__onexitend;
extern int mingw_app_type;
HINSTANCE __mingw_winmain_hInstance;
_TCHAR *__mingw_winmain_lpCmdLine;
DWORD __mingw_winmain_nShowCmd;
static int argc;
#ifdef WPRFLAG
extern void __main(void);
static wchar_t **argv;
static wchar_t **envp;
#else
static char **argv;
static char **envp;
#endif
static int argret;
static int mainret=0;
static int managedapp;
static int has_cctor = 0;
static _startupinfo startinfo;
static LPTOP_LEVEL_EXCEPTION_FILTER __mingw_oldexcpt_handler = NULL;
extern void _pei386_runtime_relocator (void);
static long CALLBACK _gnu_exception_handler (EXCEPTION_POINTERS * exception_data);
#ifdef WPRFLAG
static void duplicate_ppstrings (int ac, wchar_t ***av);
#else
static void duplicate_ppstrings (int ac, char ***av);
#endif
static int __cdecl pre_c_init (void);
static void __cdecl pre_cpp_init (void);
static void __cdecl __mingw_prepare_except_for_msvcr80_and_higher (void);
_CRTALLOC(".CRT$XIAA") _PIFV mingw_pcinit = pre_c_init;
_CRTALLOC(".CRT$XCAA") _PVFV mingw_pcppinit = pre_cpp_init;
static int __cdecl
pre_c_init (void)
{
managedapp = check_managed_app ();
if (mingw_app_type)
__set_app_type(_GUI_APP);
else
__set_app_type (_CONSOLE_APP);
__onexitbegin = __onexitend = (_PVFV *) _encode_pointer ((_PVFV *)(-1));
* __MINGW_IMP_SYMBOL(_fmode) = _fmode;
* __MINGW_IMP_SYMBOL(_commode) = _commode;
#ifdef WPRFLAG
_wsetargv();
#else
_setargv();
#endif
if (_MINGW_INSTALL_DEBUG_MATHERR)
{
if (! __defaultmatherr)
{
__setusermatherr (_matherr);
__defaultmatherr = 1;
}
}
if (__globallocalestatus == -1)
{
}
return 0;
}
static void __cdecl
pre_cpp_init (void)
{
startinfo.newmode = _newmode;
#ifdef WPRFLAG
argret = __wgetmainargs(&argc,&argv,&envp,_dowildcard,&startinfo);
#else
argret = __getmainargs(&argc,&argv,&envp,_dowildcard,&startinfo);
#endif
}
static int __tmainCRTStartup (void);
int WinMainCRTStartup (void);
int WinMainCRTStartup (void)
{
mingw_app_type = 1;
__security_init_cookie ();
return __tmainCRTStartup ();
}
int mainCRTStartup (void);
#ifdef _WIN64
int __mingw_init_ehandler (void);
#endif
int mainCRTStartup (void)
{
mingw_app_type = 0;
__security_init_cookie ();
return __tmainCRTStartup ();
}
static
__declspec(noinline) int
__tmainCRTStartup (void)
{
_TCHAR *lpszCommandLine = NULL;
STARTUPINFO StartupInfo;
WINBOOL inDoubleQuote = FALSE;
memset (&StartupInfo, 0, sizeof (STARTUPINFO));
if (mingw_app_type)
GetStartupInfo (&StartupInfo);
{
void *lock_free = NULL;
void *fiberid = ((PNT_TIB)NtCurrentTeb())->StackBase;
int nested = FALSE;
while((lock_free = InterlockedCompareExchangePointer ((volatile PVOID *) &__native_startup_lock,
fiberid, 0)) != 0)
{
if (lock_free == fiberid)
{
nested = TRUE;
break;
}
Sleep(1000);
}
if (__native_startup_state == __initializing)
{
_amsg_exit (31);
}
else if (__native_startup_state == __uninitialized)
{
__native_startup_state = __initializing;
_initterm ((_PVFV *)(void *)__xi_a, (_PVFV *)(void *) __xi_z);
}
else
has_cctor = 1;
if (__native_startup_state == __initializing)
{
_initterm (__xc_a, __xc_z);
__native_startup_state = __initialized;
}
_ASSERTE(__native_startup_state == __initialized);
if (! nested)
(VOID)InterlockedExchangePointer ((volatile PVOID *) &__native_startup_lock, 0);
if (__dyn_tls_init_callback != NULL)
__dyn_tls_init_callback (NULL, DLL_THREAD_ATTACH, NULL);
_pei386_runtime_relocator ();
__mingw_oldexcpt_handler = SetUnhandledExceptionFilter (_gnu_exception_handler);
#ifdef _WIN64
__mingw_init_ehandler ();
#endif
__mingw_prepare_except_for_msvcr80_and_higher ();
_fpreset ();
if (mingw_app_type)
{
#ifdef WPRFLAG
lpszCommandLine = (_TCHAR *) _wcmdln;
#else
lpszCommandLine = (char *) _acmdln;
#endif
while (*lpszCommandLine > SPACECHAR || (*lpszCommandLine&&inDoubleQuote))
{
if (*lpszCommandLine == DQUOTECHAR)
inDoubleQuote = !inDoubleQuote;
#ifdef _MBCS
if (_ismbblead (*lpszCommandLine))
{
if (lpszCommandLine) /* FIXME: Why this check? Should I check for *lpszCommandLine != 0 too? */
lpszCommandLine++;
}
#endif
++lpszCommandLine;
}
while (*lpszCommandLine && (*lpszCommandLine <= SPACECHAR))
lpszCommandLine++;
__mingw_winmain_hInstance = (HINSTANCE) &__ImageBase;
__mingw_winmain_lpCmdLine = lpszCommandLine;
__mingw_winmain_nShowCmd = StartupInfo.dwFlags & STARTF_USESHOWWINDOW ?
StartupInfo.wShowWindow : SW_SHOWDEFAULT;
}
duplicate_ppstrings (argc, &argv);
#ifdef WPRFLAG
__winitenv = envp;
/* C++ initialization.
gcc inserts this call automatically for a function called main, but not for wmain. */
__main ();
mainret = wmain (argc, argv, envp);
#else
__initenv = envp;
mainret = main (argc, argv, envp);
#endif
if (!managedapp)
exit (mainret);
if (has_cctor == 0)
_cexit ();
}
return mainret;
}
extern int mingw_initltsdrot_force;
extern int mingw_initltsdyn_force;
extern int mingw_initltssuo_force;
extern int mingw_initcharmax;
static int __cdecl
check_managed_app (void)
{
PIMAGE_DOS_HEADER pDOSHeader;
PIMAGE_NT_HEADERS pPEHeader;
PIMAGE_OPTIONAL_HEADER32 pNTHeader32;
PIMAGE_OPTIONAL_HEADER64 pNTHeader64;
/* Force to be linked. */
mingw_initltsdrot_force=1;
mingw_initltsdyn_force=1;
mingw_initltssuo_force=1;
mingw_initcharmax=1;
pDOSHeader = (PIMAGE_DOS_HEADER) &__ImageBase;
if (pDOSHeader->e_magic != IMAGE_DOS_SIGNATURE)
return 0;
pPEHeader = (PIMAGE_NT_HEADERS)((char *)pDOSHeader + pDOSHeader->e_lfanew);
if (pPEHeader->Signature != IMAGE_NT_SIGNATURE)
return 0;
pNTHeader32 = (PIMAGE_OPTIONAL_HEADER32) &pPEHeader->OptionalHeader;
switch (pNTHeader32->Magic)
{
case IMAGE_NT_OPTIONAL_HDR32_MAGIC:
if (pNTHeader32->NumberOfRvaAndSizes <= IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR)
return 0;
return !! pNTHeader32->DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].VirtualAddress;
case IMAGE_NT_OPTIONAL_HDR64_MAGIC:
pNTHeader64 = (PIMAGE_OPTIONAL_HEADER64)pNTHeader32;
if (pNTHeader64->NumberOfRvaAndSizes <= IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR)
return 0;
return !! pNTHeader64->DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].VirtualAddress;
}
return 0;
}
static long CALLBACK
_gnu_exception_handler (EXCEPTION_POINTERS *exception_data)
{
void (*old_handler) (int);
long action = EXCEPTION_CONTINUE_SEARCH;
int reset_fpu = 0;
switch (exception_data->ExceptionRecord->ExceptionCode)
{
case EXCEPTION_ACCESS_VIOLATION:
/* test if the user has set SIGSEGV */
old_handler = signal (SIGSEGV, SIG_DFL);
if (old_handler == SIG_IGN)
{
/* this is undefined if the signal was raised by anything other
than raise (). */
signal (SIGSEGV, SIG_IGN);
action = EXCEPTION_CONTINUE_EXECUTION;
}
else if (old_handler != SIG_DFL)
{
/* This means 'old' is a user defined function. Call it */
(*old_handler) (SIGSEGV);
action = EXCEPTION_CONTINUE_EXECUTION;
}
break;
case EXCEPTION_ILLEGAL_INSTRUCTION:
case EXCEPTION_PRIV_INSTRUCTION:
/* test if the user has set SIGILL */
old_handler = signal (SIGILL, SIG_DFL);
if (old_handler == SIG_IGN)
{
/* this is undefined if the signal was raised by anything other
than raise (). */
signal (SIGILL, SIG_IGN);
action = EXCEPTION_CONTINUE_EXECUTION;
}
else if (old_handler != SIG_DFL)
{
/* This means 'old' is a user defined function. Call it */
(*old_handler) (SIGILL);
action = EXCEPTION_CONTINUE_EXECUTION;
}
break;
case EXCEPTION_FLT_INVALID_OPERATION:
case EXCEPTION_FLT_DIVIDE_BY_ZERO:
case EXCEPTION_FLT_DENORMAL_OPERAND:
case EXCEPTION_FLT_OVERFLOW:
case EXCEPTION_FLT_UNDERFLOW:
case EXCEPTION_FLT_INEXACT_RESULT:
reset_fpu = 1;
/* fall through. */
case EXCEPTION_INT_DIVIDE_BY_ZERO:
/* test if the user has set SIGFPE */
old_handler = signal (SIGFPE, SIG_DFL);
if (old_handler == SIG_IGN)
{
signal (SIGFPE, SIG_IGN);
if (reset_fpu)
_fpreset ();
action = EXCEPTION_CONTINUE_EXECUTION;
}
else if (old_handler != SIG_DFL)
{
/* This means 'old' is a user defined function. Call it */
(*old_handler) (SIGFPE);
action = EXCEPTION_CONTINUE_EXECUTION;
}
break;
#ifdef _WIN64
case EXCEPTION_DATATYPE_MISALIGNMENT:
case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
case EXCEPTION_FLT_STACK_CHECK:
case EXCEPTION_INT_OVERFLOW:
case EXCEPTION_INVALID_HANDLE:
/*case EXCEPTION_POSSIBLE_DEADLOCK: */
action = EXCEPTION_CONTINUE_EXECUTION;
break;
#endif
default:
break;
}
if (action == EXCEPTION_CONTINUE_SEARCH && __mingw_oldexcpt_handler)
action = (*__mingw_oldexcpt_handler)(exception_data);
return action;
}
#ifdef WPRFLAG
static size_t wbytelen(const wchar_t *p)
{
size_t ret = 1;
while (*p!=0) {
ret++,++p;
}
return ret*2;
}
static void duplicate_ppstrings (int ac, wchar_t ***av)
{
wchar_t **avl;
int i;
wchar_t **n = (wchar_t **) malloc (sizeof (wchar_t *) * (ac + 1));
avl=*av;
for (i=0; i < ac; i++)
{
int l = wbytelen (avl[i]);
n[i] = (wchar_t *) malloc (l);
memcpy (n[i], avl[i], l);
}
n[i] = NULL;
*av = n;
}
#else
static void duplicate_ppstrings (int ac, char ***av)
{
char **avl;
int i;
char **n = (char **) malloc (sizeof (char *) * (ac + 1));
avl=*av;
for (i=0; i < ac; i++)
{
int l = strlen (avl[i]) + 1;
n[i] = (char *) malloc (l);
memcpy (n[i], avl[i], l);
}
n[i] = NULL;
*av = n;
}
#endif
#ifdef __MINGW_SHOW_INVALID_PARAMETER_EXCEPTION
#define __UNUSED_PARAM_1(x) x
#else
#define __UNUSED_PARAM_1 __UNUSED_PARAM
#endif
static void
__mingw_invalidParameterHandler (const wchar_t * __UNUSED_PARAM_1(expression),
const wchar_t * __UNUSED_PARAM_1(function),
const wchar_t * __UNUSED_PARAM_1(file),
unsigned int __UNUSED_PARAM_1(line),
uintptr_t __UNUSED_PARAM(pReserved))
{
#ifdef __MINGW_SHOW_INVALID_PARAMETER_EXCEPTION
wprintf(L"Invalid parameter detected in function %s. File: %s Line: %d\n", function, file, line);
wprintf(L"Expression: %s\n", expression);
#endif
}
static void __cdecl
__mingw_prepare_except_for_msvcr80_and_higher (void)
{
_invalid_parameter_handler (*fIPH)(_invalid_parameter_handler) = NULL;
HMODULE hmsv = GetModuleHandleA ("msvcr80.dll");
if(!hmsv)
hmsv = GetModuleHandleA ("msvcr70.dll");
if (!hmsv)
hmsv = GetModuleHandleA ("msvcrt.dll");
if (!hmsv)
hmsv = LoadLibraryA ("msvcrt.dll");
if (!hmsv)
return;
fIPH = (_invalid_parameter_handler (*)(_invalid_parameter_handler))
GetProcAddress (hmsv, "_set_invalid_parameter_handler");
if (fIPH)
(*fIPH)(__mingw_invalidParameterHandler);
}

View file

@ -0,0 +1,25 @@
/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file is part of the w64 mingw-runtime package.
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
*/
#ifdef CRTDLL
#undef CRTDLL
#endif
#include <internal.h>
extern int _dowildcard;
#ifdef WPRFLAG
int __CRTDECL
__wsetargv (void)
#else
int __CRTDECL
__setargv (void)
#endif
{
_dowildcard = 1;
return 0;
}

View file

@ -0,0 +1,22 @@
/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file is part of the w64 mingw-runtime package.
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
*/
#ifdef CRTDLL
#undef CRTDLL
#endif
#include <internal.h>
#ifdef WPRFLAG
int __CRTDECL
_wsetargv (void)
#else
int __CRTDECL
_setargv (void)
#endif
{
return 0;
}

View file

@ -0,0 +1,86 @@
/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file is part of the w64 mingw-runtime package.
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
*/
#include <windows.h>
#include <stdlib.h>
#include <setjmp.h>
typedef void (*func_ptr) (void);
extern func_ptr __CTOR_LIST__[];
extern func_ptr __DTOR_LIST__[];
static HMODULE hMsvcrt = NULL;
static int free_Msvcrt = 0;
typedef void __cdecl flongjmp(jmp_buf _Buf,int _Value);
flongjmp *fctMsvcrtLongJmp = NULL;
void __do_global_dtors (void);
void __do_global_ctors (void);
void __main (void);
void
__do_global_dtors (void)
{
static func_ptr *p = __DTOR_LIST__ + 1;
while (*p)
{
(*(p)) ();
p++;
}
if (free_Msvcrt && hMsvcrt)
{
free_Msvcrt = 0;
FreeLibrary (hMsvcrt);
hMsvcrt = NULL;
}
}
void
__do_global_ctors (void)
{
unsigned long nptrs = (unsigned long) (ptrdiff_t) __CTOR_LIST__[0];
unsigned long i;
if (!hMsvcrt) {
hMsvcrt = GetModuleHandleA ("msvcr80.dll");
if (!hMsvcrt)
hMsvcrt = GetModuleHandleA ("msvcr70.dll");
if (!hMsvcrt)
hMsvcrt = GetModuleHandleA ("msvcrt.dll");
if (!hMsvcrt) {
hMsvcrt = LoadLibraryA ("msvcrt.dll");
free_Msvcrt = 1;
}
fctMsvcrtLongJmp = (flongjmp *) GetProcAddress( hMsvcrt, "longjmp");
}
if (nptrs == (unsigned long) -1)
{
for (nptrs = 0; __CTOR_LIST__[nptrs + 1] != 0; nptrs++);
}
for (i = nptrs; i >= 1; i--)
{
__CTOR_LIST__[i] ();
}
atexit (__do_global_dtors);
}
static int initialized = 0;
void
__main (void)
{
if (!initialized)
{
initialized = 1;
__do_global_ctors ();
}
}

View file

@ -0,0 +1,152 @@
/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file is part of the w64 mingw-runtime package.
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
*/
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#define WIN32_NO_STATUS
#include <stdlib.h> /* abort () */
#include <windows.h>
#undef WIN32_NO_STATUS
#include <ntstatus.h> /* STATUS macros */
#ifdef _WIN64
#include <intrin.h>
#endif
#ifdef _WIN64
#define DEFAULT_SECURITY_COOKIE 0x00002B992DDFA232ll
#else
#define DEFAULT_SECURITY_COOKIE 0xBB40E64E
#endif
/* Externals. */
#ifdef _WIN64
PRUNTIME_FUNCTION RtlLookupFunctionEntry (ULONG64, PULONG64, PVOID);
PVOID RtlVirtualUnwind (ULONG HandlerType, ULONG64, ULONG64, PRUNTIME_FUNCTION,
PCONTEXT, PVOID *, PULONG64, PVOID);
#endif
typedef LONG NTSTATUS; /* same as in ntdef.h / winternl.h */
#define UNW_FLAG_NHANDLER 0x00
typedef union
{
unsigned __int64 ft_scalar;
FILETIME ft_struct;
} FT;
static EXCEPTION_RECORD GS_ExceptionRecord;
static CONTEXT GS_ContextRecord;
static const EXCEPTION_POINTERS GS_ExceptionPointers = {
&GS_ExceptionRecord,&GS_ContextRecord
};
DECLSPEC_SELECTANY UINT_PTR __security_cookie = DEFAULT_SECURITY_COOKIE;
DECLSPEC_SELECTANY UINT_PTR __security_cookie_complement = ~(DEFAULT_SECURITY_COOKIE);
void __cdecl __security_init_cookie (void);
void __cdecl
__security_init_cookie (void)
{
UINT_PTR cookie;
FT systime = { 0, };
LARGE_INTEGER perfctr;
if (__security_cookie != DEFAULT_SECURITY_COOKIE)
{
__security_cookie_complement = ~__security_cookie;
return;
}
GetSystemTimeAsFileTime (&systime.ft_struct);
#ifdef _WIN64
cookie = systime.ft_scalar;
#else
cookie = systime.ft_struct.dwLowDateTime;
cookie ^= systime.ft_struct.dwHighDateTime;
#endif
cookie ^= GetCurrentProcessId ();
cookie ^= GetCurrentThreadId ();
cookie ^= GetTickCount ();
QueryPerformanceCounter (&perfctr);
#ifdef _WIN64
cookie ^= perfctr.QuadPart;
#else
cookie ^= perfctr.LowPart;
cookie ^= perfctr.HighPart;
#endif
#ifdef _WIN64
cookie &= 0x0000ffffffffffffll;
#endif
if (cookie == DEFAULT_SECURITY_COOKIE)
cookie = DEFAULT_SECURITY_COOKIE + 1;
__security_cookie = cookie;
__security_cookie_complement = ~cookie;
}
#if defined(__GNUC__) /* wrap msvc intrinsics onto gcc builtins */
#undef _ReturnAddress
#undef _AddressOfReturnAddress
#define _ReturnAddress() __builtin_return_address(0)
#define _AddressOfReturnAddress() __builtin_frame_address (0)
#endif /* __GNUC__ */
__declspec(noreturn) void __cdecl __report_gsfailure (ULONGLONG);
__declspec(noreturn) void __cdecl
__report_gsfailure (ULONGLONG StackCookie)
{
volatile UINT_PTR cookie[2] __MINGW_ATTRIB_UNUSED;
#ifdef _WIN64
ULONG64 controlPC, imgBase, establisherFrame;
PRUNTIME_FUNCTION fctEntry;
PVOID hndData;
RtlCaptureContext (&GS_ContextRecord);
controlPC = GS_ContextRecord.Rip;
fctEntry = RtlLookupFunctionEntry (controlPC, &imgBase, NULL);
if (fctEntry != NULL)
{
RtlVirtualUnwind (UNW_FLAG_NHANDLER, imgBase, controlPC, fctEntry,
&GS_ContextRecord, &hndData, &establisherFrame, NULL);
}
else
#endif /* _WIN64 */
{
#ifdef _WIN64
GS_ContextRecord.Rip = (ULONGLONG) _ReturnAddress();
GS_ContextRecord.Rsp = (ULONGLONG) _AddressOfReturnAddress() + 8;
#else
GS_ContextRecord.Eip = (DWORD) _ReturnAddress();
GS_ContextRecord.Esp = (DWORD) _AddressOfReturnAddress() + 4;
#endif /* _WIN64 */
}
#ifdef _WIN64
GS_ExceptionRecord.ExceptionAddress = (PVOID) GS_ContextRecord.Rip;
GS_ContextRecord.Rcx = StackCookie;
#else
GS_ExceptionRecord.ExceptionAddress = (PVOID) GS_ContextRecord.Eip;
GS_ContextRecord.Ecx = StackCookie;
#endif /* _WIN64 */
GS_ExceptionRecord.ExceptionCode = STATUS_STACK_BUFFER_OVERRUN;
GS_ExceptionRecord.ExceptionFlags = EXCEPTION_NONCONTINUABLE;
cookie[0] = __security_cookie;
cookie[1] = __security_cookie_complement;
SetUnhandledExceptionFilter (NULL);
UnhandledExceptionFilter ((EXCEPTION_POINTERS *) &GS_ExceptionPointers);
TerminateProcess (GetCurrentProcess (), STATUS_STACK_BUFFER_OVERRUN);
abort();
}

View file

@ -0,0 +1,52 @@
/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file is part of the w64 mingw-runtime package.
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
*/
#include <internal.h>
#include <math.h>
#include <stdio.h>
int __defaultmatherr = 0;
int __CRTDECL
_matherr (struct _exception *pexcept)
{
const char * type;
switch(pexcept->type)
{
case _DOMAIN:
type = "Argument domain error (DOMAIN)";
break;
case _SING:
type = "Argument singularity (SIGN)";
break;
case _OVERFLOW:
type = "Overflow range error (OVERFLOW)";
break;
case _PLOSS:
type = "Partial loss of significance (PLOSS)";
break;
case _TLOSS:
type = "Total loss of significance (TLOSS)";
break;
case _UNDERFLOW:
type = "The result is too small to be represented (UNDERFLOW)";
break;
default:
type = "Unknown error";
break;
}
fprintf(stderr, "_matherr(): %s in %s(%g, %g) (retval=%g)\n",
type, pexcept->name, pexcept->arg1, pexcept->arg2, pexcept->retval);
return 0;
}

View file

@ -0,0 +1,31 @@
/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file is part of the w64 mingw-runtime package.
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
*/
#include <oscalls.h>
#include <internal.h>
#include <process.h>
#include <math.h>
#include <stdlib.h>
#include <tchar.h>
#include <sect_attribs.h>
#include <locale.h>
extern const PIMAGE_TLS_CALLBACK __dyn_tls_init_callback;
void * __cdecl
_decode_pointer (void *codedptr)
{
return (void *) codedptr;
}
void * __cdecl
_encode_pointer (void *ptr)
{
return ptr;
}
/* 0:console, 1:windows. */
int mingw_app_type = 0;

View file

@ -0,0 +1,43 @@
/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file is part of the w64 mingw-runtime package.
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
*/
#include <windows.h>
#include <stdlib.h>
int _fltused;
void
__do_global_dtors (void)
{
}
void
__do_global_ctors (void)
{
}
BOOL
WINAPI
_CRT_INIT0(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
{
return TRUE;
}
static int initialized = 0;
void
__main (void)
{
if (!initialized)
{
initialized = 1;
__do_global_ctors ();
}
}

View file

@ -0,0 +1,14 @@
/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file is part of the w64 mingw-runtime package.
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
*/
#include <crtdefs.h>
#include <internal.h>
_PGLOBAL
volatile unsigned int __native_dllmain_reason = UINT_MAX;
volatile unsigned int __native_vcclrit_reason = UINT_MAX;
volatile __enative_startup_state __native_startup_state;
volatile void *__native_startup_lock;

View file

@ -0,0 +1,370 @@
/* pseudo-reloc.c
Contributed by Egor Duda <deo@logos-m.ru>
Modified by addition of runtime_pseudo_reloc version 2
by Kai Tietz <kai.tietz@onevision.com>
THIS SOFTWARE IS NOT COPYRIGHTED
This source code is offered for use in the public domain. You may
use, modify or distribute it freely.
This code is distributed in the hope that it will be useful but
WITHOUT ANY WARRANTY. ALL WARRENTIES, EXPRESS OR IMPLIED ARE HEREBY
DISCLAMED. This includes but is not limited to warrenties of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <memory.h>
#if defined(__CYGWIN__)
#include <wchar.h>
#include <ntdef.h>
#include <sys/cygwin.h>
/* copied from winsup.h */
# define NO_COPY __attribute__((nocommon)) __attribute__((section(".data_cygwin_nocopy")))
/* custom status code: */
#define STATUS_ILLEGAL_DLL_PSEUDO_RELOCATION ((NTSTATUS) 0xe0000269)
#define SHORT_MSG_BUF_SZ 128
#else
# define NO_COPY
#endif
#ifdef __GNUC__
#define ATTRIBUTE_NORETURN __attribute__ ((noreturn))
#else
#define ATTRIBUTE_NORETURN
#endif
#ifndef __MINGW_LSYMBOL
#define __MINGW_LSYMBOL(sym) sym
#endif
extern char __RUNTIME_PSEUDO_RELOC_LIST__;
extern char __RUNTIME_PSEUDO_RELOC_LIST_END__;
#ifndef _MSC_VER
#define __ImageBase __MINGW_LSYMBOL(_image_base__)
#endif
extern char __ImageBase;
void _pei386_runtime_relocator (void);
/* v1 relocation is basically:
* *(base + .target) += .addend
* where (base + .target) is always assumed to point
* to a DWORD (4 bytes).
*/
typedef struct {
DWORD addend;
DWORD target;
} runtime_pseudo_reloc_item_v1;
/* v2 relocation is more complex. In effect, it is
* *(base + .target) += *(base + .sym) - (base + .sym)
* with care taken in both reading, sign extension, and writing
* because .flags may indicate that (base + .target) may point
* to a BYTE, WORD, DWORD, or QWORD (w64).
*/
typedef struct {
DWORD sym;
DWORD target;
DWORD flags;
} runtime_pseudo_reloc_item_v2;
typedef struct {
DWORD magic1;
DWORD magic2;
DWORD version;
} runtime_pseudo_reloc_v2;
static void ATTRIBUTE_NORETURN
__report_error (const char *msg, ...)
{
#ifdef __CYGWIN__
/* This function is used to print short error messages
* to stderr, which may occur during DLL initialization
* while fixing up 'pseudo' relocations. This early, we
* may not be able to use cygwin stdio functions, so we
* use the win32 WriteFile api. This should work with both
* normal win32 console IO handles, redirected ones, and
* cygwin ptys.
*/
char buf[SHORT_MSG_BUF_SZ];
wchar_t module[MAX_PATH];
char * posix_module = NULL;
static const char UNKNOWN_MODULE[] = "<unknown module>: ";
static const size_t UNKNOWN_MODULE_LEN = sizeof (UNKNOWN_MODULE) - 1;
static const char CYGWIN_FAILURE_MSG[] = "Cygwin runtime failure: ";
static const size_t CYGWIN_FAILURE_MSG_LEN = sizeof (CYGWIN_FAILURE_MSG) - 1;
DWORD len;
DWORD done;
va_list args;
HANDLE errh = GetStdHandle (STD_ERROR_HANDLE);
ssize_t modulelen = GetModuleFileNameW (NULL, module, sizeof (module));
if (errh == INVALID_HANDLE_VALUE)
cygwin_internal (CW_EXIT_PROCESS,
STATUS_ILLEGAL_DLL_PSEUDO_RELOCATION,
1);
if (modulelen > 0)
posix_module = cygwin_create_path (CCP_WIN_W_TO_POSIX, module);
va_start (args, msg);
len = (DWORD) vsnprintf (buf, SHORT_MSG_BUF_SZ, msg, args);
va_end (args);
buf[SHORT_MSG_BUF_SZ-1] = '\0'; /* paranoia */
if (posix_module)
{
WriteFile (errh, (PCVOID)CYGWIN_FAILURE_MSG,
CYGWIN_FAILURE_MSG_LEN, &done, NULL);
WriteFile (errh, (PCVOID)posix_module,
strlen(posix_module), &done, NULL);
WriteFile (errh, (PCVOID)": ", 2, &done, NULL);
WriteFile (errh, (PCVOID)buf, len, &done, NULL);
free (posix_module);
}
else
{
WriteFile (errh, (PCVOID)CYGWIN_FAILURE_MSG,
CYGWIN_FAILURE_MSG_LEN, &done, NULL);
WriteFile (errh, (PCVOID)UNKNOWN_MODULE,
UNKNOWN_MODULE_LEN, &done, NULL);
WriteFile (errh, (PCVOID)buf, len, &done, NULL);
}
WriteFile (errh, (PCVOID)"\n", 1, &done, NULL);
cygwin_internal (CW_EXIT_PROCESS,
STATUS_ILLEGAL_DLL_PSEUDO_RELOCATION,
1);
/* not reached, but silences noreturn warning */
abort ();
#else
va_list argp;
va_start (argp, msg);
# ifdef __MINGW64_VERSION_MAJOR
fprintf (stderr, "Mingw-w64 runtime failure:\n");
# else
fprintf (stderr, "Mingw runtime failure:\n");
# endif
vfprintf (stderr, msg, argp);
va_end (argp);
abort ();
#endif
}
/* This function temporarily marks the page containing addr
* writable, before copying len bytes from *src to *addr, and
* then restores the original protection settings to the page.
*
* Using this function eliminates the requirement with older
* pseudo-reloc implementations, that sections containing
* pseudo-relocs (such as .text and .rdata) be permanently
* marked writable. This older behavior sabotaged any memory
* savings achieved by shared libraries on win32 -- and was
* slower, too. However, on cygwin as of binutils 2.20 the
* .text section is still marked writable, and the .rdata section
* is folded into the (writable) .data when --enable-auto-import.
*/
static void
__write_memory (void *addr, const void *src, size_t len)
{
MEMORY_BASIC_INFORMATION b;
DWORD oldprot;
if (!len)
return;
if (!VirtualQuery (addr, &b, sizeof(b)))
{
__report_error (" VirtualQuery failed for %d bytes at address %p",
(int) sizeof(b), addr);
}
/* Temporarily allow write access to read-only protected memory. */
if (b.Protect != PAGE_EXECUTE_READWRITE && b.Protect != PAGE_READWRITE)
VirtualProtect (b.BaseAddress, b.RegionSize, PAGE_EXECUTE_READWRITE,
&oldprot);
/* write the data. */
memcpy (addr, src, len);
/* Restore original protection. */
if (b.Protect != PAGE_EXECUTE_READWRITE && b.Protect != PAGE_READWRITE)
VirtualProtect (b.BaseAddress, b.RegionSize, oldprot, &oldprot);
}
#define RP_VERSION_V1 0
#define RP_VERSION_V2 1
static void
do_pseudo_reloc (void * start, void * end, void * base)
{
ptrdiff_t addr_imp, reldata;
ptrdiff_t reloc_target = (ptrdiff_t) ((char *)end - (char*)start);
runtime_pseudo_reloc_v2 *v2_hdr = (runtime_pseudo_reloc_v2 *) start;
runtime_pseudo_reloc_item_v2 *r;
/* A valid relocation list will contain at least one entry, and
* one v1 data structure (the smallest one) requires two DWORDs.
* So, if the relocation list is smaller than 8 bytes, bail.
*/
if (reloc_target < 8)
return;
/* Check if this is the old pseudo relocation version. */
/* There are two kinds of v1 relocation lists:
* 1) With a (v2-style) version header. In this case, the
* first entry in the list is a 3-DWORD structure, with
* value:
* { 0, 0, RP_VERSION_V1 }
* In this case, we skip to the next entry in the list,
* knowing that all elements after the head item can
* be cast to runtime_pseudo_reloc_item_v1.
* 2) Without a (v2-style) version header. In this case, the
* first element in the list IS an actual v1 relocation
* record, which is two DWORDs. Because there will never
* be a case where a v1 relocation record has both
* addend == 0 and target == 0, this case will not be
* confused with the prior one.
* All current binutils, when generating a v1 relocation list,
* use the second (e.g. original) form -- that is, without the
* v2-style version header.
*/
if (reloc_target >= 12
&& v2_hdr->magic1 == 0 && v2_hdr->magic2 == 0
&& v2_hdr->version == RP_VERSION_V1)
{
/* We have a list header item indicating that the rest
* of the list contains v1 entries. Move the pointer to
* the first true v1 relocation record. By definition,
* that v1 element will not have both addend == 0 and
* target == 0 (and thus, when interpreted as a
* runtime_pseudo_reloc_v2, it will not have both
* magic1 == 0 and magic2 == 0).
*/
v2_hdr++;
}
if (v2_hdr->magic1 != 0 || v2_hdr->magic2 != 0)
{
/*************************
* Handle v1 relocations *
*************************/
runtime_pseudo_reloc_item_v1 * o;
for (o = (runtime_pseudo_reloc_item_v1 *) v2_hdr;
o < (runtime_pseudo_reloc_item_v1 *)end;
o++)
{
DWORD newval;
reloc_target = (ptrdiff_t) base + o->target;
newval = (*((DWORD*) reloc_target)) + o->addend;
__write_memory ((void *) reloc_target, &newval, sizeof(DWORD));
}
return;
}
/* If we got this far, then we have relocations of version 2 or newer */
/* Check if this is a known version. */
if (v2_hdr->version != RP_VERSION_V2)
{
__report_error (" Unknown pseudo relocation protocol version %d.\n",
(int) v2_hdr->version);
return;
}
/*************************
* Handle v2 relocations *
*************************/
/* Walk over header. */
r = (runtime_pseudo_reloc_item_v2 *) &v2_hdr[1];
for (; r < (runtime_pseudo_reloc_item_v2 *) end; r++)
{
/* location where new address will be written */
reloc_target = (ptrdiff_t) base + r->target;
/* get sym pointer. It points either to the iat entry
* of the referenced element, or to the stub function.
*/
addr_imp = (ptrdiff_t) base + r->sym;
addr_imp = *((ptrdiff_t *) addr_imp);
/* read existing relocation value from image, casting to the
* bitsize indicated by the 8 LSBs of flags. If the value is
* negative, manually sign-extend to ptrdiff_t width. Raise an
* error if the bitsize indicated by the 8 LSBs of flags is not
* supported.
*/
switch ((r->flags & 0xff))
{
case 8:
reldata = (ptrdiff_t) (*((unsigned char *)reloc_target));
if ((reldata & 0x80) != 0)
reldata |= ~((ptrdiff_t) 0xff);
break;
case 16:
reldata = (ptrdiff_t) (*((unsigned short *)reloc_target));
if ((reldata & 0x8000) != 0)
reldata |= ~((ptrdiff_t) 0xffff);
break;
case 32:
reldata = (ptrdiff_t) (*((unsigned int *)reloc_target));
#ifdef _WIN64
if ((reldata & 0x80000000) != 0)
reldata |= ~((ptrdiff_t) 0xffffffff);
#endif
break;
#ifdef _WIN64
case 64:
reldata = (ptrdiff_t) (*((unsigned long long *)reloc_target));
break;
#endif
default:
reldata=0;
__report_error (" Unknown pseudo relocation bit size %d.\n",
(int) (r->flags & 0xff));
break;
}
/* Adjust the relocation value */
reldata -= ((ptrdiff_t) base + r->sym);
reldata += addr_imp;
/* Write the new relocation value back to *reloc_target */
switch ((r->flags & 0xff))
{
case 8:
__write_memory ((void *) reloc_target, &reldata, 1);
break;
case 16:
__write_memory ((void *) reloc_target, &reldata, 2);
break;
case 32:
__write_memory ((void *) reloc_target, &reldata, 4);
break;
#ifdef _WIN64
case 64:
__write_memory ((void *) reloc_target, &reldata, 8);
break;
#endif
}
}
}
void
_pei386_runtime_relocator (void)
{
static NO_COPY int was_init = 0;
if (was_init)
return;
++was_init;
do_pseudo_reloc (&__RUNTIME_PSEUDO_RELOC_LIST__,
&__RUNTIME_PSEUDO_RELOC_LIST_END__,
&__ImageBase);
}

View file

@ -0,0 +1,44 @@
/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file is part of the w64 mingw-runtime package.
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
*
* Written by Kai Tietz <kai.tietz@onevision.com>
*/
/* We support TLS cleanup code in any case. If shared version of libgcc is used _CRT_MT has value 1,
otherwise
we do tls cleanup in runtime and _CRT_MT has value 2. */
int _CRT_MT = 2;
// HACK around broken imports from libmingwex, until RosBE64 is updated
#ifdef _M_AMD64
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#include <stdlib.h>
int __mingwthr_key_dtor (DWORD key, void (*dtor)(void *));
int __mingwthr_remove_key_dtor (DWORD key);
extern int ___w64_mingwthr_remove_key_dtor (DWORD key);
extern int ___w64_mingwthr_add_key_dtor (DWORD key, void (*dtor)(void *));
int
__mingwthr_remove_key_dtor (DWORD key)
{
return ___w64_mingwthr_remove_key_dtor (key);
}
int
__mingwthr_key_dtor (DWORD key, void (*dtor)(void *))
{
if (dtor)
return ___w64_mingwthr_add_key_dtor (key, dtor);
return 0;
}
#endif

View file

@ -0,0 +1,59 @@
/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file is part of the w64 mingw-runtime package.
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
*
* Written by Kai Tietz <kai.tietz@onevision.com>
*/
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#include <stdlib.h>
int __mingwthr_key_dtor (DWORD key, void (*dtor)(void *));
int __mingwthr_remove_key_dtor (DWORD key);
extern int ___w64_mingwthr_remove_key_dtor (DWORD key);
extern int ___w64_mingwthr_add_key_dtor (DWORD key, void (*dtor)(void *));
#ifndef _WIN64
#define MINGWM10_DLL "mingwm10.dll"
typedef int (*fMTRemoveKeyDtor)(DWORD key);
typedef int (*fMTKeyDtor)(DWORD key, void (*dtor)(void *));
extern fMTRemoveKeyDtor __mingw_gMTRemoveKeyDtor;
extern fMTKeyDtor __mingw_gMTKeyDtor;
extern int __mingw_usemthread_dll;
#endif
int
__mingwthr_remove_key_dtor (DWORD key)
{
#ifndef _WIN64
if (!__mingw_usemthread_dll)
#endif
return ___w64_mingwthr_remove_key_dtor (key);
#ifndef _WIN64
if (__mingw_gMTRemoveKeyDtor)
return (*__mingw_gMTRemoveKeyDtor) (key);
return 0;
#endif
}
int
__mingwthr_key_dtor (DWORD key, void (*dtor)(void *))
{
if (dtor)
{
#ifndef _WIN64
if (!__mingw_usemthread_dll)
#endif
return ___w64_mingwthr_add_key_dtor (key, dtor);
#ifndef _WIN64
if (__mingw_gMTKeyDtor)
return (*__mingw_gMTKeyDtor) (key, dtor);
#endif
}
return 0;
}

View file

@ -0,0 +1,218 @@
/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file is part of the w64 mingw-runtime package.
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
*
* Written by Kai Tietz <kai.tietz@onevision.com>
*/
#ifdef CRTDLL
#undef CRTDLL
#endif
#include <sect_attribs.h>
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#include <stdio.h>
#include <memory.h>
#include <malloc.h>
#ifndef _WIN64
#include <stdlib.h> /* for _winmajor */
#endif
#ifndef __INTERNAL_FUNC_DEFINED
#define __INTERNAL_FUNC_DEFINED
typedef void (__cdecl *_PVFV)(void);
typedef int (__cdecl *_PIFV)(void);
typedef void (__cdecl *_PVFI)(int);
#endif
extern WINBOOL __mingw_TLScallback (HANDLE hDllHandle, DWORD reason, LPVOID reserved);
#define FUNCS_PER_NODE 30
typedef struct TlsDtorNode {
int count;
struct TlsDtorNode *next;
_PVFV funcs[FUNCS_PER_NODE];
} TlsDtorNode;
ULONG _tls_index = 0;
/* TLS raw template data start and end. */
_CRTALLOC(".tls$AAA") char _tls_start = 0;
_CRTALLOC(".tls$ZZZ") char _tls_end = 0;
_CRTALLOC(".CRT$XLA") PIMAGE_TLS_CALLBACK __xl_a = 0;
_CRTALLOC(".CRT$XLZ") PIMAGE_TLS_CALLBACK __xl_z = 0;
#ifdef _WIN64
_CRTALLOC(".tls") const IMAGE_TLS_DIRECTORY64 _tls_used = {
(ULONGLONG) &_tls_start+1, (ULONGLONG) &_tls_end, (ULONGLONG) &_tls_index,
(ULONGLONG) (&__xl_a+1), (ULONG) 0, (ULONG) 0
};
#else
_CRTALLOC(".tls") const IMAGE_TLS_DIRECTORY _tls_used = {
(ULONG)(ULONG_PTR) &_tls_start+1, (ULONG)(ULONG_PTR) &_tls_end,
(ULONG)(ULONG_PTR) &_tls_index, (ULONG)(ULONG_PTR) (&__xl_a+1),
(ULONG) 0, (ULONG) 0
};
#endif
#ifndef __CRT_THREAD
#ifdef HAVE_ATTRIBUTE_THREAD
#define __CRT_THREAD __declspec(thread)
#else
#define __CRT_THREAD __thread
#endif
#endif
#define DISABLE_MS_TLS 1
static _CRTALLOC(".CRT$XDA") _PVFV __xd_a = 0;
static _CRTALLOC(".CRT$XDZ") _PVFV __xd_z = 0;
#if !defined (DISABLE_MS_TLS)
static __CRT_THREAD TlsDtorNode *dtor_list;
static __CRT_THREAD TlsDtorNode dtor_list_head;
#endif
extern int _CRT_MT;
#ifndef _WIN64
#define MINGWM10_DLL "mingwm10.dll"
typedef int (*fMTRemoveKeyDtor)(DWORD key);
typedef int (*fMTKeyDtor)(DWORD key, void (*dtor)(void *));
fMTRemoveKeyDtor __mingw_gMTRemoveKeyDtor;
fMTKeyDtor __mingw_gMTKeyDtor;
int __mingw_usemthread_dll;
static HANDLE __mingw_mthread_hdll;
#endif
BOOL WINAPI __dyn_tls_init (HANDLE, DWORD, LPVOID);
BOOL WINAPI
__dyn_tls_init (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved)
{
_PVFV *pfunc;
#ifndef _WIN64
if (_winmajor < 4)
{
__mingw_usemthread_dll = 1;
__mingw_mthread_hdll = LoadLibrary (MINGWM10_DLL);
if (__mingw_mthread_hdll != NULL)
{
__mingw_gMTRemoveKeyDtor = (fMTRemoveKeyDtor) GetProcAddress (__mingw_mthread_hdll, "__mingwthr_remove_key_dtor");
__mingw_gMTKeyDtor = (fMTKeyDtor) GetProcAddress (__mingw_mthread_hdll, "__mingwthr_key_dtor");
}
if (__mingw_mthread_hdll == NULL || !__mingw_gMTRemoveKeyDtor || !__mingw_gMTKeyDtor)
{
__mingw_gMTKeyDtor = NULL;
__mingw_gMTRemoveKeyDtor = NULL;
if (__mingw_mthread_hdll)
FreeLibrary (__mingw_mthread_hdll);
__mingw_mthread_hdll = NULL;
_CRT_MT = 0;
return TRUE;
}
_CRT_MT = 1;
return TRUE;
}
#endif
/* We don't let us trick here. */
if (_CRT_MT != 2)
_CRT_MT = 2;
if (dwReason != DLL_THREAD_ATTACH)
{
if (dwReason == DLL_PROCESS_ATTACH)
__mingw_TLScallback (hDllHandle, dwReason, lpreserved);
return TRUE;
}
for (pfunc = &__xd_a + 1; pfunc != &__xd_z; ++pfunc)
{
if (*pfunc != NULL)
(*pfunc)();
}
return TRUE;
}
const PIMAGE_TLS_CALLBACK __dyn_tls_init_callback = (const PIMAGE_TLS_CALLBACK) __dyn_tls_init;
_CRTALLOC(".CRT$XLC") PIMAGE_TLS_CALLBACK __xl_c = (PIMAGE_TLS_CALLBACK) __dyn_tls_init;
int __cdecl __tlregdtor (_PVFV);
int __cdecl
__tlregdtor (_PVFV func)
{
if (!func)
return 0;
#if !defined (DISABLE_MS_TLS)
if (dtor_list == NULL)
{
dtor_list = &dtor_list_head;
dtor_list_head.count = 0;
}
else if (dtor_list->count == FUNCS_PER_NODE)
{
TlsDtorNode *pnode = (TlsDtorNode *) malloc (sizeof (TlsDtorNode));
if (pnode == NULL)
return -1;
pnode->count = 0;
pnode->next = dtor_list;
dtor_list = pnode;
dtor_list->count = 0;
}
dtor_list->funcs[dtor_list->count++] = func;
#endif
return 0;
}
static BOOL WINAPI
__dyn_tls_dtor (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved)
{
#if !defined (DISABLE_MS_TLS)
TlsDtorNode *pnode, *pnext;
int i;
#endif
if (dwReason != DLL_THREAD_DETACH && dwReason != DLL_PROCESS_DETACH)
return TRUE;
/* As TLS variables are detroyed already by DLL_THREAD_DETACH
call, we have to avoid access on the possible DLL_PROCESS_DETACH
call the already destroyed TLS vars.
TODO: The used local thread based variables have to be handled
manually, so that we can control their lifetime here. */
#if !defined (DISABLE_MS_TLS)
if (dwReason != DLL_PROCESS_DETACH)
{
for (pnode = dtor_list; pnode != NULL; pnode = pnext)
{
for (i = pnode->count - 1; i >= 0; --i)
{
if (pnode->funcs[i] != NULL)
(*pnode->funcs[i])();
}
pnext = pnode->next;
if (pnext != NULL)
free ((void *) pnode);
}
}
#endif
__mingw_TLScallback (hDllHandle, dwReason, lpreserved);
return TRUE;
}
_CRTALLOC(".CRT$XLD") PIMAGE_TLS_CALLBACK __xl_d = (PIMAGE_TLS_CALLBACK) __dyn_tls_dtor;
int mingw_initltsdrot_force = 0;
int mingw_initltsdyn_force = 0;
int mingw_initltssuo_force = 0;

View file

@ -0,0 +1,148 @@
/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file is part of the w64 mingw-runtime package.
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
*
* Written by Kai Tietz <kai.tietz@onevision.com>
*
* This file is used by if gcc is built with --enable-threads=win32.
*
* Based on version created by Mumit Khan <khan@nanotech.wisc.edu>
*
*/
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#include <stdlib.h>
WINBOOL __mingw_TLScallback (HANDLE hDllHandle, DWORD reason, LPVOID reserved);
int ___w64_mingwthr_remove_key_dtor (DWORD key);
int ___w64_mingwthr_add_key_dtor (DWORD key, void (*dtor)(void *));
/* To protect the thread/key association data structure modifications. */
static CRITICAL_SECTION __mingwthr_cs;
static volatile int __mingwthr_cs_init = 0;
typedef struct __mingwthr_key __mingwthr_key_t;
/* The list of threads active with key/dtor pairs. */
struct __mingwthr_key {
DWORD key;
void (*dtor)(void *);
__mingwthr_key_t volatile *next;
};
static __mingwthr_key_t volatile *key_dtor_list;
int
___w64_mingwthr_add_key_dtor (DWORD key, void (*dtor)(void *))
{
__mingwthr_key_t *new_key;
if (__mingwthr_cs_init == 0)
return 0;
new_key = (__mingwthr_key_t *) calloc (1, sizeof (__mingwthr_key_t));
if (new_key == NULL)
return -1;
new_key->key = key;
new_key->dtor = dtor;
EnterCriticalSection (&__mingwthr_cs);
new_key->next = key_dtor_list;
key_dtor_list = new_key;
LeaveCriticalSection (&__mingwthr_cs);
return 0;
}
int
___w64_mingwthr_remove_key_dtor (DWORD key)
{
__mingwthr_key_t volatile *prev_key;
__mingwthr_key_t volatile *cur_key;
if (__mingwthr_cs_init == 0)
return 0;
EnterCriticalSection (&__mingwthr_cs);
prev_key = NULL;
cur_key = key_dtor_list;
while (cur_key != NULL)
{
if ( cur_key->key == key)
{
if (prev_key == NULL)
key_dtor_list = cur_key->next;
else
prev_key->next = cur_key->next;
free ((void*)cur_key);
break;
}
prev_key = cur_key;
cur_key = cur_key->next;
}
LeaveCriticalSection (&__mingwthr_cs);
return 0;
}
static void
__mingwthr_run_key_dtors (void)
{
__mingwthr_key_t volatile *keyp;
if (__mingwthr_cs_init == 0)
return;
EnterCriticalSection (&__mingwthr_cs);
for (keyp = key_dtor_list; keyp; )
{
LPVOID value = TlsGetValue (keyp->key);
if (GetLastError () == ERROR_SUCCESS)
{
if (value)
(*keyp->dtor) (value);
}
keyp = keyp->next;
}
LeaveCriticalSection (&__mingwthr_cs);
}
WINBOOL
__mingw_TLScallback (HANDLE __UNUSED_PARAM(hDllHandle),
DWORD reason,
LPVOID __UNUSED_PARAM(reserved))
{
switch (reason)
{
case DLL_PROCESS_ATTACH:
if (__mingwthr_cs_init == 0)
InitializeCriticalSection (&__mingwthr_cs);
__mingwthr_cs_init = 1;
break;
case DLL_PROCESS_DETACH:
__mingwthr_run_key_dtors();
if (__mingwthr_cs_init == 1)
{
__mingwthr_cs_init = 0;
DeleteCriticalSection (&__mingwthr_cs);
}
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
__mingwthr_run_key_dtors();
break;
}
return TRUE;
}

View file

@ -0,0 +1,13 @@
/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file is part of the w64 mingw-runtime package.
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
*/
#include <fcntl.h>
/* Set default file mode to text */
/* Is this correct? Default value of _fmode in msvcrt.dll is 0. */
int _fmode = _O_TEXT;

View file

@ -0,0 +1,13 @@
/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file is part of the w64 mingw-runtime package.
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
*/
#define WPRFLAG
#define UNICODE
#define _UNICODE
#define mainCRTStartup wmainCRTStartup
#define WinMainCRTStartup wWinMainCRTStartup
#include "crtexe.c"

View file

@ -0,0 +1,3 @@
#define WPRFLAG
#include "dllargv.c"

View file

@ -0,0 +1,33 @@
/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file is part of the w64 mingw-runtime package.
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
*/
/* _dowildcard is an int that controls the globbing of the command line.
* If _dowildcard is non-zero, the command line will be globbed: *.*
* will be expanded to be all files in the startup directory.
*
* In the mingw-w64 library the _dowildcard variable is defined as being
* 0, therefore command line globbing is DISABLED by default. To turn it
* on and to leave wildcard command line processing MS's globbing code,
* include a line in one of your source modules defining _dowildcard and
* setting it to -1, like so:
* int _dowildcard = -1;
*
* Alternatively, the mingw-w64 library can be configured using the
* --enable-wildcard option and compiled thusly upon which the resulting
* library will have _dowildcard as -1 and command line globbing will be
* enabled by default.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifndef __ENABLE_GLOBBING
#define __ENABLE_GLOBBING 0 /* -1 */
#endif
int _dowildcard = __ENABLE_GLOBBING;