Skip to content

Commit

Permalink
Remove more PAL exports for wprintf wscanf funcs (#76771)
Browse files Browse the repository at this point in the history
* Remove more PAL exports for wprintf funcs

* Remove tests for fwprintf

* Remove swscanf tests

* Remove wprintf tests
  • Loading branch information
AaronRobinsonMSFT authored Oct 10, 2022
1 parent f156fb9 commit a04f75c
Show file tree
Hide file tree
Showing 54 changed files with 144 additions and 4,616 deletions.
1 change: 0 additions & 1 deletion src/coreclr/dlls/mscordac/mscordac_unixexports.src
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ nativeStringResourceTable_mscorrc
#PAL_fflush
#PAL__flushall
#PAL_free
#PAL_fwprintf
#PAL_GetLogicalCpuCountFromOS
#PAL_GetTotalCpuCount
#PAL_GetNumaProcessorNode
Expand Down
100 changes: 67 additions & 33 deletions src/coreclr/ilasm/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,40 @@

WCHAR* EqualOrColon(_In_ __nullterminated WCHAR* szArg)
{
WCHAR* pchE = wcschr(szArg,L'=');
WCHAR* pchC = wcschr(szArg,L':');
WCHAR* pchE = wcschr(szArg,W('='));
WCHAR* pchC = wcschr(szArg,W(':'));
WCHAR* ret;
if(pchE == NULL) ret = pchC;
else if(pchC == NULL) ret = pchE;
else ret = (pchE < pchC)? pchE : pchC;
return ret;
}

// When converting a string for number parsing it is
// possible to simply cast a WCHAR to a char with no
// loss of data.
class NarrowForNumberParsing final
{
char* _buffer;
public:
NarrowForNumberParsing(const WCHAR* str)
{
size_t len = wcslen(str);
_buffer = (char*)malloc(len + 1);
for (size_t i = 0; i < len; ++i)
_buffer[i] = (char)str[i];
_buffer[len] = '\0';
}
~NarrowForNumberParsing()
{
free(_buffer);
}
operator const char*() const
{
return _buffer;
}
};

static DWORD g_dwSubsystem=(DWORD)-1,g_dwComImageFlags=(DWORD)-1,g_dwFileAlignment=0,g_dwTestRepeat=0;
static ULONGLONG g_stBaseAddress=0;
static size_t g_stSizeOfStackReserve=0;
Expand Down Expand Up @@ -214,9 +239,9 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv)
for (i = 1; i < argc; i++)
{
#ifdef TARGET_UNIX
if(argv[i][0] == L'-')
if(argv[i][0] == W('-'))
#else
if((argv[i][0] == L'/') || (argv[i][0] == L'-'))
if((argv[i][0] == W('/')) || (argv[i][0] == W('-')))
#endif
{
char szOpt[3 + 1] = { 0 };
Expand Down Expand Up @@ -247,7 +272,7 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv)
WCHAR *pStr = EqualOrColon(argv[i]);
if(pStr != NULL)
{
for(pStr++; *pStr == L' '; pStr++); //skip the blanks
for(pStr++; *pStr == W(' '); pStr++); //skip the blanks
if(wcslen(pStr)==0) goto InvalidOption; //if no suboption
else
{
Expand All @@ -260,9 +285,10 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv)
pAsm->m_dwIncludeDebugInfo = 0x103;
else
{
const WCHAR *pFmt =((*pStr == '0')&&(*(pStr+1) == 'x'))? W("%lx") : W("%ld");
if(swscanf_s(pStr,pFmt,&(pAsm->m_dwIncludeDebugInfo))!=1)
goto InvalidOption; // bad subooption
const CHAR *pFmt =((*pStr == '0')&&(*(pStr+1) == 'x'))? "%x" : "%d";
NarrowForNumberParsing str{pStr};
if(sscanf_s(str,pFmt,&(pAsm->m_dwIncludeDebugInfo))!=1)
goto InvalidOption; // bad subooption
}
}
}
Expand Down Expand Up @@ -360,7 +386,7 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv)
{
WCHAR *pStr = EqualOrColon(argv[i]);
if(pStr == NULL) goto ErrorExit;
for(pStr++; *pStr == L' '; pStr++); //skip the blanks
for(pStr++; *pStr == W(' '); pStr++); //skip the blanks
if(wcslen(pStr)==0) goto InvalidOption; //if no file name
pAsm->m_wzResourceFile = pStr;
}
Expand All @@ -371,23 +397,23 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv)
{
WCHAR *pStr = EqualOrColon(argv[i]);
if(pStr == NULL) goto InvalidOption;
for(pStr++; *pStr == L' '; pStr++); //skip the blanks
for(pStr++; *pStr == W(' '); pStr++); //skip the blanks
if(wcslen(pStr)==0) goto InvalidOption; //if no file name
pAsm->m_wzKeySourceName = pStr;
}
else if (!_stricmp(szOpt, "INC"))
{
WCHAR *pStr = EqualOrColon(argv[i]);
if(pStr == NULL) goto InvalidOption;
for(pStr++; *pStr == L' '; pStr++); //skip the blanks
for(pStr++; *pStr == W(' '); pStr++); //skip the blanks
if(wcslen(pStr)==0) goto InvalidOption; //if no file name
wzIncludePath = pStr;
}
else if (!_stricmp(szOpt, "OUT"))
{
WCHAR *pStr = EqualOrColon(argv[i]);
if(pStr == NULL) goto InvalidOption;
for(pStr++; *pStr == L' '; pStr++); //skip the blanks
for(pStr++; *pStr == W(' '); pStr++); //skip the blanks
if(wcslen(pStr)==0) goto InvalidOption; //if no file name
if(wcslen(pStr) >= MAX_FILENAME_LENGTH)
{
Expand All @@ -400,19 +426,20 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv)
{
WCHAR *pStr = EqualOrColon(argv[i]);
if(pStr == NULL) goto InvalidOption;
for(pStr++; *pStr == L' '; pStr++); //skip the blanks
for(pStr++; *pStr == W(' '); pStr++); //skip the blanks
if(wcslen(pStr)==0) goto InvalidOption; //if no version string
pAsm->m_wzMetadataVersion = pStr;
}
else if (!_stricmp(szOpt, "MSV"))
{
WCHAR *pStr = EqualOrColon(argv[i]);
if(pStr == NULL) goto InvalidOption;
for(pStr++; *pStr == L' '; pStr++); //skip the blanks
for(pStr++; *pStr == W(' '); pStr++); //skip the blanks
if(wcslen(pStr)==0) goto InvalidOption; //if no version
{
int major=-1,minor=-1;
if(swscanf_s(pStr,W("%d.%d"),&major, &minor)==2)
NarrowForNumberParsing str{pStr};
if(sscanf_s(str,"%d.%d",&major, &minor)==2)
{
if((major >= 0)&&(major < 0xFF))
pAsm->m_wMSVmajor = (WORD)major;
Expand All @@ -426,18 +453,20 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv)
WCHAR *pStr = EqualOrColon(argv[i]);
if(pStr == NULL) goto InvalidOption;
pStr++;
const WCHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? W("%lx") : W("%ld");
if(swscanf_s(pStr,pFmt,&g_dwSubsystem)!=1) goto InvalidOption;
const CHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? "%x" : "%d";
NarrowForNumberParsing str{pStr};
if(sscanf_s(str,pFmt,&g_dwSubsystem)!=1) goto InvalidOption;
}
else if (!_stricmp(szOpt, "SSV"))
{
WCHAR *pStr = EqualOrColon(argv[i]);
if(pStr == NULL) goto InvalidOption;
for(pStr++; *pStr == L' '; pStr++); //skip the blanks
for(pStr++; *pStr == W(' '); pStr++); //skip the blanks
if(wcslen(pStr)==0) goto InvalidOption; //if no version
{
int major=-1,minor=-1;
if(swscanf_s(pStr,W("%d.%d"),&major, &minor)==2)
NarrowForNumberParsing str{pStr};
if(sscanf_s(str,"%d.%d",&major, &minor)==2)
{
if((major >= 0)&&(major < 0xFFFF))
pAsm->m_wSSVersionMajor = (WORD)major;
Expand All @@ -452,8 +481,9 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv)
WCHAR *pStr = EqualOrColon(argv[i]);
if(pStr == NULL) goto InvalidOption;
pStr++;
const WCHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? W("%lx") : W("%ld");
if(swscanf_s(pStr,pFmt,&g_dwFileAlignment)!=1) goto InvalidOption;
const CHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? "%x" : "%d";
NarrowForNumberParsing str{pStr};
if(sscanf_s(str,pFmt,&g_dwFileAlignment)!=1) goto InvalidOption;
if((g_dwFileAlignment & (g_dwFileAlignment-1))
|| (g_dwFileAlignment < 0x200) || (g_dwFileAlignment > 0x10000))
{
Expand All @@ -466,16 +496,18 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv)
WCHAR *pStr = EqualOrColon(argv[i]);
if(pStr == NULL) goto InvalidOption;
pStr++;
const WCHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? W("%lx") : W("%ld");
if(swscanf_s(pStr,pFmt,&g_dwComImageFlags)!=1) goto InvalidOption;
const CHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? "%x" : "%d";
NarrowForNumberParsing str{pStr};
if(sscanf_s(str,pFmt,&g_dwComImageFlags)!=1) goto InvalidOption;
}
else if (!_stricmp(szOpt, "BAS"))
{
WCHAR *pStr = EqualOrColon(argv[i]);
if(pStr == NULL) goto InvalidOption;
pStr++;
const WCHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? W("%I64x") : W("%I64d");
if(swscanf_s(pStr,pFmt,&g_stBaseAddress)!=1) goto InvalidOption;
const CHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? "%llx" : "%lld";
NarrowForNumberParsing str{pStr};
if(sscanf_s(str,pFmt,&g_stBaseAddress)!=1) goto InvalidOption;
if(g_stBaseAddress & 0xFFFF)
{
fprintf(stderr,"\nBase address must be 0x10000-aligned\n");
Expand All @@ -487,17 +519,19 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv)
WCHAR *pStr = EqualOrColon(argv[i]);
if(pStr == NULL) goto InvalidOption;
pStr++;
const WCHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? W("%lx") : W("%ld");
if(swscanf_s(pStr,pFmt,&g_stSizeOfStackReserve)!=1) goto InvalidOption;
const CHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? "%x" : "%d";
NarrowForNumberParsing str{pStr};
if(sscanf_s(str,pFmt,&g_stSizeOfStackReserve)!=1) goto InvalidOption;
}
#ifdef _SPECIAL_INTERNAL_USE_ONLY
else if (!_stricmp(szOpt, "TES"))
{
WCHAR *pStr = EqualOrColon(argv[i]);
if(pStr == NULL) goto InvalidOption;
pStr++;
WCHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? L"%lx" : L"%ld";
if(swscanf_s(pStr,pFmt,&g_dwTestRepeat)!=1) goto InvalidOption;
const CHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? "%x" : "%d";
NarrowForNumberParsing str{pStr};
if(sscanf_s(str,pFmt,&g_dwTestRepeat)!=1) goto InvalidOption;
}
#endif
else
Expand Down Expand Up @@ -592,7 +626,7 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv)
do
{
j--;
if(wzOutputFilename[j] == L'.')
if(wzOutputFilename[j] == W('.'))
{
wzOutputFilename[j] = 0;
break;
Expand All @@ -604,7 +638,7 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv)
if (pAsm->m_fGeneratePDB)
{
wcscpy_s(wzPdbFilename, MAX_FILENAME_LENGTH, wzOutputFilename);
WCHAR* extPos = wcsrchr(wzPdbFilename, L'.');
WCHAR* extPos = wcsrchr(wzPdbFilename, W('.'));
if (extPos != NULL)
*extPos = 0;
wcscat_s(wzPdbFilename, MAX_FILENAME_LENGTH, W(".pdb"));
Expand Down Expand Up @@ -805,11 +839,11 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv)
if (exitval || !bGeneratePdb)
{
// PE file was not created, or no debug info required. Kill PDB if any
WCHAR* pc = wcsrchr(wzOutputFilename,L'.');
WCHAR* pc = wcsrchr(wzOutputFilename,W('.'));
if(pc==NULL)
{
pc = &wzOutputFilename[wcslen(wzOutputFilename)];
*pc = L'.';
*pc = W('.');
}
wcscpy_s(pc+1,4,W("PDB"));
#undef DeleteFileW
Expand Down
10 changes: 0 additions & 10 deletions src/coreclr/pal/inc/pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -4059,7 +4059,6 @@ PAL_GetCurrentThreadAffinitySet(SIZE_T size, UINT_PTR* data);
#define exit PAL_exit
#define printf PAL_printf
#define vprintf PAL_vprintf
#define wprintf PAL_wprintf
#define wcstod PAL_wcstod
#define wcstoul PAL_wcstoul
#define wcscat PAL_wcscat
Expand All @@ -4069,7 +4068,6 @@ PAL_GetCurrentThreadAffinitySet(SIZE_T size, UINT_PTR* data);
#define wcschr PAL_wcschr
#define wcsrchr PAL_wcsrchr
#define wcsstr PAL_wcsstr
#define swscanf PAL_swscanf
#define wcspbrk PAL_wcspbrk
#define wcscmp PAL_wcscmp
#define wcsncpy PAL_wcsncpy
Expand All @@ -4079,9 +4077,7 @@ PAL_GetCurrentThreadAffinitySet(SIZE_T size, UINT_PTR* data);
#define strtoul PAL_strtoul
#define strtoull PAL_strtoull
#define fprintf PAL_fprintf
#define fwprintf PAL_fwprintf
#define vfprintf PAL_vfprintf
#define vfwprintf PAL_vfwprintf
#define rand PAL_rand
#define time PAL_time
#define getenv PAL_getenv
Expand Down Expand Up @@ -4258,9 +4254,6 @@ PALIMPORT DLLEXPORT const WCHAR * __cdecl PAL_wcschr(const WCHAR *, WCHAR);
PALIMPORT DLLEXPORT const WCHAR * __cdecl PAL_wcsrchr(const WCHAR *, WCHAR);
PALIMPORT WCHAR _WConst_return * __cdecl PAL_wcspbrk(const WCHAR *, const WCHAR *);
PALIMPORT DLLEXPORT WCHAR _WConst_return * __cdecl PAL_wcsstr(const WCHAR *, const WCHAR *);
PALIMPORT int __cdecl PAL_swprintf(WCHAR *, const WCHAR *, ...);
PALIMPORT int __cdecl PAL_vswprintf(WCHAR *, const WCHAR *, va_list);
PALIMPORT int __cdecl PAL_swscanf(const WCHAR *, const WCHAR *, ...);
PALIMPORT DLLEXPORT ULONG __cdecl PAL_wcstoul(const WCHAR *, WCHAR **, int);
PALIMPORT double __cdecl PAL_wcstod(const WCHAR *, WCHAR **);

Expand Down Expand Up @@ -4494,9 +4487,6 @@ PALIMPORT LONG __cdecl PAL_ftell(PAL_FILE *);
PALIMPORT int __cdecl PAL_ferror(PAL_FILE *);
PALIMPORT PAL_FILE * __cdecl PAL_fopen(const char *, const char *);
PALIMPORT int __cdecl PAL_setvbuf(PAL_FILE *stream, char *, int, size_t);
PALIMPORT DLLEXPORT int __cdecl PAL_fwprintf(PAL_FILE *, const WCHAR *, ...);
PALIMPORT int __cdecl PAL_vfwprintf(PAL_FILE *, const WCHAR *, va_list);
PALIMPORT int __cdecl PAL_wprintf(const WCHAR*, ...);

PALIMPORT int __cdecl _getw(PAL_FILE *);
PALIMPORT int __cdecl _putw(int, PAL_FILE *);
Expand Down
2 changes: 0 additions & 2 deletions src/coreclr/pal/inc/rt/palrt.h
Original file line number Diff line number Diff line change
Expand Up @@ -672,8 +672,6 @@ The wrappers below are simple implementations that may not be as robust as compl
Remember to fix the errcode definition in safecrt.h.
*/

#define swscanf_s swscanf

#define _wfopen_s _wfopen_unsafe
#define fopen_s _fopen_unsafe

Expand Down
Loading

0 comments on commit a04f75c

Please sign in to comment.