Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
This Change Adds initial Support for LongFiles in the VM,
Browse files Browse the repository at this point in the history
They are:
1. Wrappers for OS APIs which  take or return PATHS

2. Fixing the usage of following Api's:

GetEnvironmentVariableW
SearchPathW
GetShortPathNameW
GetLongPathNameW
GetModuleFileName

Work remaining:
Remove fixed size buffers in the VM
  • Loading branch information
ramarag committed Feb 20, 2016
1 parent 01ffa08 commit f98fb85
Show file tree
Hide file tree
Showing 59 changed files with 3,062 additions and 1,320 deletions.
37 changes: 11 additions & 26 deletions src/classlibnative/bcltype/system.cpp
Expand Up @@ -218,34 +218,19 @@ FCIMPL1(Object*, SystemNative::_GetEnvironmentVariable, StringObject* strVarUNSA

HELPER_METHOD_FRAME_BEGIN_RET_2(refRetVal, strVar);

// We loop round getting the length of the env var and then trying to copy
// the value into a managed string. Usually we'll go through this loop
// precisely once, but the caution is ncessary in case the variable mutates
// beneath us.
int len, newLen;
int len;

// Get the length of the environment variable.
WCHAR dummy; // prefix complains if pass a null ptr in, so rely on the final length parm instead
len = WszGetEnvironmentVariable(strVar->GetBuffer(), &dummy, 0);
PathString envPath; // prefix complains if pass a null ptr in, so rely on the final length parm instead
len = WszGetEnvironmentVariable(strVar->GetBuffer(), envPath);

while (len != 0)
if (len != 0)
{
// Allocate the string.
refRetVal = StringObject::NewString(len);

// Get the value.
newLen = WszGetEnvironmentVariable(strVar->GetBuffer(), refRetVal->GetBuffer(), len);
if (newLen != (len - 1))
{
// The envvar changed, need to do this again. Let GC collect the
// string we just allocated.
refRetVal = NULL;

// Go back and try again.
len = newLen;
}
else
break;

wcscpy_s(refRetVal->GetBuffer(), len + 1, envPath);

}

HELPER_METHOD_FRAME_END();
Expand Down Expand Up @@ -297,15 +282,15 @@ FCIMPL0(StringObject*, SystemNative::_GetModuleFileName)
}
else
{
SString wszFilePathString;
PathString wszFilePathString;

WCHAR * wszFile = wszFilePathString.OpenUnicodeBuffer(MAX_LONGPATH);
DWORD lgth = WszGetModuleFileName(NULL, wszFile, MAX_LONGPATH);

DWORD lgth = WszGetModuleFileName(NULL, wszFilePathString);
if (!lgth)
{
COMPlusThrowWin32();
}
wszFilePathString.CloseBuffer(lgth);


refRetVal = StringObject::NewString(wszFilePathString.GetUnicode());
}
Expand Down
6 changes: 3 additions & 3 deletions src/debug/di/cordb.cpp
Expand Up @@ -201,11 +201,11 @@ BOOL WINAPI DbgDllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)

#if defined(LOGGING)
{
WCHAR rcFile[_MAX_PATH];
WszGetModuleFileName(hInstance, rcFile, NumItems(rcFile));
PathString rcFile;
WszGetModuleFileName(hInstance, rcFile);
LOG((LF_CORDB, LL_INFO10000,
"DI::DbgDllMain: load right side support from file '%s'\n",
rcFile));
rcFile.GetUnicode()));
}
#endif

Expand Down
3 changes: 2 additions & 1 deletion src/debug/di/module.cpp
Expand Up @@ -2568,8 +2568,9 @@ HRESULT CordbModule::CreateReaderForInMemorySymbols(REFIID riid, void** ppObj)
#ifndef FEATURE_PAL
// PDB format - use diasymreader.dll with COM activation
InlineSString<_MAX_PATH> ssBuf;
IfFailThrow(GetHModuleDirectory(GetModuleInst(), ssBuf));
IfFailThrow(FakeCoCreateInstanceEx(CLSID_CorSymBinder_SxS,
GetHModuleDirectory(GetModuleInst(), ssBuf).GetUnicode(),
ssBuf.GetUnicode(),
IID_ISymUnmanagedBinder,
(void**)&pBinder,
NULL));
Expand Down
27 changes: 9 additions & 18 deletions src/debug/di/shimprocess.cpp
Expand Up @@ -1823,50 +1823,41 @@ HRESULT ShimProcess::FindLoadedCLR(CORDB_ADDRESS * pClrInstanceId)
HMODULE ShimProcess::GetDacModule()
{
HModuleHolder hDacDll;
WCHAR wszAccessDllPath[MAX_LONGPATH];
PathString wszAccessDllPath;

#ifdef FEATURE_PAL
if (!PAL_GetPALDirectoryW(wszAccessDllPath, _countof(wszAccessDllPath)))
if (!PAL_GetPALDirectoryWrapper(wszAccessDllPath))
{
ThrowLastError();
}
wcscat_s(wszAccessDllPath, _countof(wszAccessDllPath), MAKEDLLNAME_W(W("mscordaccore")));
PCWSTR eeFlavor = MAKEDLLNAME_W(W("mscordaccore"));
#else
//
// Load the access DLL from the same directory as the the current CLR Debugging Services DLL.
//

if (!WszGetModuleFileName(GetModuleInst(), wszAccessDllPath, NumItems(wszAccessDllPath)))
if (!WszGetModuleFileName(GetModuleInst(), wszAccessDllPath))
{
ThrowLastError();
}

PWSTR pPathTail = wcsrchr(wszAccessDllPath, DIRECTORY_SEPARATOR_CHAR_W);
if (!pPathTail)
if (!SUCCEEDED(CopySystemDirectory(wszAccessDllPath, wszAccessDllPath)))
{
ThrowHR(E_INVALIDARG);
}
pPathTail++;

// Dac Dll is named:
// mscordaccore.dll <-- coreclr
// mscordacwks.dll <-- desktop
PCWSTR eeFlavor =
#if defined(FEATURE_MAIN_CLR_MODULE_USES_CORE_NAME)
W("core");
W("mscordaccore.dll");
#else
W("wks");
W("mscordacwks.dll");
#endif

if (_snwprintf_s(pPathTail,
_countof(wszAccessDllPath) + (wszAccessDllPath - pPathTail),
NumItems(wszAccessDllPath) - (pPathTail - wszAccessDllPath),
MAKEDLLNAME_W(W("mscordac%s")),
eeFlavor) <= 0)
{
ThrowHR(E_INVALIDARG);
}

#endif // FEATURE_PAL
wszAccessDllPath.Append(eeFlavor);

hDacDll.Assign(WszLoadLibrary(wszAccessDllPath));
if (!hDacDll)
Expand Down
16 changes: 7 additions & 9 deletions src/debug/ee/debugger.cpp
Expand Up @@ -2244,9 +2244,9 @@ HRESULT Debugger::StartupPhase2(Thread * pThread)
if (!CORDebuggerAttached())
{
#define DBG_ATTACH_ON_STARTUP_ENV_VAR W("COMPlus_DbgAttachOnStartup")

PathString temp;
// We explicitly just check the env because we don't want a switch this invasive to be global.
DWORD fAttach = WszGetEnvironmentVariable(DBG_ATTACH_ON_STARTUP_ENV_VAR, NULL, 0) > 0;
DWORD fAttach = WszGetEnvironmentVariable(DBG_ATTACH_ON_STARTUP_ENV_VAR, temp) > 0;

if (fAttach)
{
Expand Down Expand Up @@ -15166,8 +15166,7 @@ HRESULT Debugger::InitAppDomainIPC(void)
} hEnsureCleanup(this);

DWORD dwStrLen = 0;
SString szExeNamePathString;
WCHAR * szExeName = szExeNamePathString.OpenUnicodeBuffer(MAX_LONGPATH);
SString szExeName;
int i;

// all fields in the object can be zero initialized.
Expand Down Expand Up @@ -15216,15 +15215,14 @@ HRESULT Debugger::InitAppDomainIPC(void)

// also initialize the process name
dwStrLen = WszGetModuleFileName(NULL,
szExeName,
MAX_LONGPATH);
szExeName);

szExeNamePathString.CloseBuffer(dwStrLen);

// If we couldn't get the name, then use a nice default.
if (dwStrLen == 0)
{
wcscpy_s(szExeName, COUNTOF(szExeName), W("<NoProcessName>"));
dwStrLen = (DWORD)wcslen(szExeName);
szExeName.Set(W("<NoProcessName>"));
dwStrLen = szExeName.GetCount();
}

// If we got the name, copy it into a buffer. dwStrLen is the
Expand Down
8 changes: 4 additions & 4 deletions src/dlls/mscoree/delayload.cpp
Expand Up @@ -376,16 +376,16 @@ FARPROC __stdcall CorDelayLoadHook( // Always 0.
// If we've not yet looked at our environment, then do so.
if (!bInit)
{
WCHAR rcBreak[16];
PathString rcBreak;

// set DelayLoadBreak=[0|1]
if (WszGetEnvironmentVariable(W("DelayLoadBreak"), rcBreak, NumItems(rcBreak)))
if (WszGetEnvironmentVariable(W("DelayLoadBreak"), rcBreak))
{
// "1" means to break hard and display errors.
if (*rcBreak == '1')
if (rcBreak[0] == '1')
bBreak = 1;
// "2" means no break, but display errors.
else if (*rcBreak == '2')
else if (rcBreak[0] == '2')
bBreak = 2;
else
bBreak = false;
Expand Down

0 comments on commit f98fb85

Please sign in to comment.