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

Commit a9cd7e2

Browse files
author
Lakshmi Priya Sekar
committed
Use PathString type to allocate large path strings on linux scenario.
1 parent b8282e0 commit a9cd7e2

File tree

9 files changed

+80
-94
lines changed

9 files changed

+80
-94
lines changed

src/binder/assemblybinder.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ namespace BINDER_SPACE
164164
}
165165
else
166166
{
167-
PathString fullAssemblyPath;
167+
SString fullAssemblyPath;
168168
WCHAR *pwzFullAssemblyPath = fullAssemblyPath.OpenUnicodeBuffer(MAX_LONGPATH);
169169
DWORD dwCCFullAssemblyPath = MAX_LONGPATH + 1; // SString allocates extra byte for null.
170170

@@ -184,9 +184,6 @@ namespace BINDER_SPACE
184184
{
185185
assemblyPath.Set(fullAssemblyPath);
186186
}
187-
188-
// Now turn this path into our canonical representation
189-
CanonicalizePath(assemblyPath);
190187
}
191188

192189
return hr;

src/binder/cdebuglog.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,6 @@ namespace BINDER_SPACE
334334
CombinePath(g_BinderVariables->logPath, sCategory, logFilePath);
335335
CombinePath(logFilePath, m_applicationName, logFilePath);
336336
CombinePath(logFilePath, m_logFileName, logFilePath);
337-
CanonicalizePath(logFilePath);
338337

339338
BINDER_LOG_STRING(L"logFilePath", logFilePath);
340339

src/binder/debuglog.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ namespace BINDER_SPACE
9090
kCount2.u.HighPart);
9191

9292
PlatformPath(logFilePath);
93-
CanonicalizePath(logFilePath);
9493
}
9594

9695
fFileExists = (FileOrDirectoryExists(logFilePath) == S_OK);

src/binder/inc/bindertypes.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ class PEAssembly;
3232

3333
namespace BINDER_SPACE
3434
{
35-
typedef InlineSString<512> PathString;
36-
3735
class AssemblyVersion;
3836
class AssemblyName;
3937
class Assembly;

src/binder/utils.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -267,17 +267,15 @@ namespace BINDER_SPACE
267267

268268
if (!path.IsEmpty())
269269
{
270-
PathString wszCanonicalPathString;
271-
WCHAR * pwszCanonicalPath = wszCanonicalPathString.OpenUnicodeBuffer(MAX_LONGPATH);
270+
// PathCanonicalizeW is hard coded as MAX_PATH on windows.
271+
WCHAR wszCanonicalPath[MAX_PATH];
272272
PlatformPath(path);
273273

274274
// This is also defined in rotor pal
275-
if (PathCanonicalizeW(pwszCanonicalPath, path))
275+
if (PathCanonicalizeW(wszCanonicalPath, path))
276276
{
277-
path.Set(pwszCanonicalPath);
277+
path.Set(wszCanonicalPath);
278278
}
279-
280-
wszCanonicalPathString.CloseBuffer();
281279

282280
if (fAppendPathSeparator)
283281
{
@@ -303,20 +301,21 @@ namespace BINDER_SPACE
303301
BINDER_LOG_STRING(W("path A"), pathA);
304302
BINDER_LOG_STRING(W("path B"), pathB);
305303

306-
PathString tempResultPathString;
307-
WCHAR * tempResultPath = tempResultPathString.OpenUnicodeBuffer(MAX_LONGPATH);
304+
PathString tempResultPath;
308305

309-
if (PathCombineW(tempResultPath, pathA, pathB))
310-
{
311-
combinedPath.Set(tempResultPath);
312-
BINDER_LOG_STRING(W("combined path"), tempResultPath);
313-
}
314-
else
306+
SString platformPathSeparator(SString::Literal, GetPlatformPathSeparator());
307+
tempResultPath.Set(pathA);
308+
309+
if (!tempResultPath.EndsWith(platformPathSeparator))
315310
{
316-
combinedPath.Clear();
311+
tempResultPath.Append(platformPathSeparator);
317312
}
318313

319-
tempResultPathString.CloseBuffer();
314+
tempResultPath.Append(pathB);
315+
316+
combinedPath.Set(tempResultPath);
317+
318+
BINDER_LOG_STRING(W("combined path"), tempResultPath);
320319
BINDER_LOG_LEAVE(W("Utils::CombinePath"));
321320
}
322321

src/classlibnative/bcltype/system.cpp

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "classnames.h"
2525
#include "system.h"
2626
#include "string.h"
27+
#include "sstring.h"
2728
#include "eeconfig.h"
2829
#include "assemblynative.hpp"
2930
#include "generics.h"
@@ -288,34 +289,29 @@ FCIMPL0(StringObject*, SystemNative::_GetModuleFileName)
288289
{
289290
FCALL_CONTRACT;
290291

291-
WCHAR wszFile[MAX_LONGPATH];
292-
STRINGREF refRetVal = NULL;
293-
LPCWSTR pFileName = NULL;
294-
DWORD lgth = 0;
292+
STRINGREF refRetVal = NULL;
295293

294+
HELPER_METHOD_FRAME_BEGIN_RET_1(refRetVal);
296295
if (g_pCachedModuleFileName)
297296
{
298-
pFileName = g_pCachedModuleFileName;
299-
lgth = (DWORD)wcslen(pFileName);
297+
refRetVal = StringObject::NewString(g_pCachedModuleFileName);
300298
}
301299
else
302300
{
303-
HELPER_METHOD_FRAME_BEGIN_RET_1(refRetVal);
304-
lgth = WszGetModuleFileName(NULL, wszFile, MAX_LONGPATH);
301+
SString wszFilePathString;
302+
303+
WCHAR * wszFile = wszFilePathString.OpenUnicodeBuffer(MAX_LONGPATH);
304+
DWORD lgth = WszGetModuleFileName(NULL, wszFile, MAX_LONGPATH);
305305
if (!lgth)
306306
{
307307
COMPlusThrowWin32();
308308
}
309-
HELPER_METHOD_FRAME_END();
310-
pFileName = wszFile;
311-
}
309+
wszFilePathString.CloseBuffer(lgth);
312310

313-
if(lgth)
314-
{
315-
HELPER_METHOD_FRAME_BEGIN_RET_1(refRetVal);
316-
refRetVal = StringObject::NewString(pFileName, lgth);
317-
HELPER_METHOD_FRAME_END();
311+
refRetVal = StringObject::NewString(wszFilePathString.GetUnicode());
318312
}
313+
HELPER_METHOD_FRAME_END();
314+
319315
return (StringObject*)OBJECTREFToObject(refRetVal);
320316
}
321317
FCIMPLEND
@@ -347,14 +343,16 @@ FCIMPL0(StringObject*, SystemNative::GetRuntimeDirectory)
347343
{
348344
FCALL_CONTRACT;
349345

350-
wchar_t wszFile[MAX_LONGPATH+1];
351346
STRINGREF refRetVal = NULL;
352347
DWORD dwFile = MAX_LONGPATH+1;
353348

354349
HELPER_METHOD_FRAME_BEGIN_RET_1(refRetVal);
350+
SString wszFilePathString;
355351

352+
WCHAR * wszFile = wszFilePathString.OpenUnicodeBuffer(dwFile);
356353
HRESULT hr = GetInternalSystemDirectory(wszFile, &dwFile);
357-
354+
wszFilePathString.CloseBuffer(dwFile);
355+
358356
if(FAILED(hr))
359357
COMPlusThrowHR(hr);
360358

src/debug/ee/debugger.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15136,7 +15136,8 @@ HRESULT Debugger::InitAppDomainIPC(void)
1513615136
} hEnsureCleanup(this);
1513715137

1513815138
DWORD dwStrLen = 0;
15139-
WCHAR szExeName[MAX_LONGPATH];
15139+
SString szExeNamePathString;
15140+
WCHAR * szExeName = szExeNamePathString.OpenUnicodeBuffer(MAX_LONGPATH);
1514015141
int i;
1514115142

1514215143
// all fields in the object can be zero initialized.
@@ -15188,6 +15189,7 @@ HRESULT Debugger::InitAppDomainIPC(void)
1518815189
szExeName,
1518915190
MAX_LONGPATH);
1519015191

15192+
szExeNamePathString.CloseBuffer(dwStrLen);
1519115193
// If we couldn't get the name, then use a nice default.
1519215194
if (dwStrLen == 0)
1519315195
{

src/dlls/mscoree/mscoree.cpp

Lines changed: 36 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -792,14 +792,21 @@ BOOL PAL_GetPALDirectory(__out_ecount(cchBuffer) LPWSTR pbuffer,
792792

793793
HRESULT hr = S_OK;
794794

795-
WCHAR pPath[MAX_LONGPATH];
795+
WCHAR * pPath = new (nothrow) WCHAR[MAX_LONGPATH];
796+
if (pPath == NULL)
797+
{
798+
WCHAR pPathStack[MAX_LONGPATH];
799+
pPath = pPathStack;
800+
}
801+
796802
DWORD dwPath = MAX_LONGPATH;
797803

798804
#ifndef CROSSGEN_COMPILE
799805
_ASSERTE(g_pMSCorEE != NULL);
800806
#endif
801807

802808
dwPath = WszGetModuleFileName(g_pMSCorEE, pPath, dwPath);
809+
803810
if(dwPath == 0)
804811
{
805812
hr = HRESULT_FROM_GetLastErrorNA();
@@ -809,7 +816,11 @@ BOOL PAL_GetPALDirectory(__out_ecount(cchBuffer) LPWSTR pbuffer,
809816
DWORD dwLength;
810817
hr = CopySystemDirectory(pPath, pbuffer, cchBuffer, &dwLength);
811818
}
812-
819+
820+
if (pPath != pPathStack)
821+
{
822+
delete [] pPath;
823+
}
813824
return (hr == S_OK);
814825
}
815826

@@ -1115,44 +1126,10 @@ __out_ecount_z_opt(cchBuffer) LPWSTR pBuffer,
11151126

11161127
}
11171128

1118-
11191129
#ifndef CROSSGEN_COMPILE
1130+
#ifndef FEATURE_CORECLR
11201131
STDAPI LoadLibraryShimInternal(LPCWSTR szDllName, LPCWSTR szVersion, LPVOID pvReserved, HMODULE *phModDll)
11211132
{
1122-
#ifdef FEATURE_CORECLR
1123-
1124-
CONTRACTL {
1125-
NOTHROW;
1126-
GC_NOTRIGGER;
1127-
PRECONDITION(CheckPointer(szDllName, NULL_OK));
1128-
PRECONDITION(CheckPointer(szVersion, NULL_OK));
1129-
PRECONDITION(CheckPointer(pvReserved, NULL_OK));
1130-
PRECONDITION(CheckPointer(phModDll));
1131-
} CONTRACTL_END;
1132-
1133-
if (szDllName == NULL)
1134-
return E_POINTER;
1135-
1136-
HRESULT hr = S_OK;
1137-
1138-
BEGIN_ENTRYPOINT_NOTHROW;
1139-
1140-
WCHAR szDllPath[MAX_LONGPATH+1];
1141-
1142-
if (!PAL_GetPALDirectoryW(szDllPath, MAX_LONGPATH)) {
1143-
IfFailGo(HRESULT_FROM_GetLastError());
1144-
}
1145-
wcsncat_s(szDllPath, MAX_LONGPATH+1, szDllName, MAX_LONGPATH - wcslen(szDllPath));
1146-
1147-
if ((*phModDll = WszLoadLibrary(szDllPath)) == NULL)
1148-
IfFailGo(HRESULT_FROM_GetLastError());
1149-
1150-
ErrExit:
1151-
END_ENTRYPOINT_NOTHROW;
1152-
return hr;
1153-
1154-
#else // FEATURE_CORECLR
1155-
11561133
// Simply forward the call to the ICLRRuntimeInfo implementation.
11571134
STATIC_CONTRACT_WRAPPER;
11581135
if (g_pCLRRuntime)
@@ -1163,7 +1140,7 @@ STDAPI LoadLibraryShimInternal(LPCWSTR szDllName, LPCWSTR szVersion, LPVOID pvRe
11631140
{
11641141
// no runtime info, probably loaded directly (e.g. from Fusion)
11651142
// just look next to ourselves.
1166-
WCHAR wszPath[MAX_LONGPATH];
1143+
WCHAR wszPath[MAX_PATH];
11671144
DWORD dwLength = WszGetModuleFileName(g_hThisInst, wszPath,NumItems(wszPath));
11681145

11691146

@@ -1188,15 +1165,12 @@ STDAPI LoadLibraryShimInternal(LPCWSTR szDllName, LPCWSTR szVersion, LPVOID pvRe
11881165
}
11891166
return S_OK;
11901167
}
1191-
1192-
#endif // FEATURE_CORECLR
1193-
11941168
}
1195-
1196-
#endif // CROSSGEN_COMPILE
1169+
#endif
1170+
#endif
11971171

11981172
static DWORD g_dwSystemDirectory = 0;
1199-
static WCHAR g_pSystemDirectory[MAX_LONGPATH + 1];
1173+
static WCHAR * g_pSystemDirectory = new WCHAR[MAX_LONGPATH+1];
12001174

12011175
HRESULT GetInternalSystemDirectory(__out_ecount_part_opt(*pdwLength,*pdwLength) LPWSTR buffer, __inout DWORD* pdwLength)
12021176
{
@@ -1263,17 +1237,27 @@ HRESULT SetInternalSystemDirectory()
12631237
DWORD len;
12641238

12651239
// use local buffer for thread safety
1266-
WCHAR wzSystemDirectory[COUNTOF(g_pSystemDirectory)];
1240+
WCHAR * wzSystemDirectory = new (nothrow) WCHAR[MAX_LONGPATH+1];
1241+
if (wzSystemDirectory == NULL)
1242+
{
1243+
WCHAR wzSystemDirectoryStack[MAX_LONGPATH+1];
1244+
wzSystemDirectory = wzSystemDirectoryStack;
1245+
}
12671246

1268-
hr = GetCORSystemDirectoryInternal(wzSystemDirectory, COUNTOF(wzSystemDirectory), &len);
1247+
hr = GetCORSystemDirectoryInternal(wzSystemDirectory, MAX_LONGPATH+1, &len);
12691248

12701249
if(FAILED(hr)) {
1271-
wzSystemDirectory[0] = W('\0');
1250+
*wzSystemDirectory = W('\0');
12721251
len = 1;
12731252
}
1274-
1253+
12751254
// publish results idempotently with correct memory ordering
12761255
memcpy(g_pSystemDirectory, wzSystemDirectory, len * sizeof(WCHAR));
1256+
if (wzSystemDirectory != wzSystemDirectoryStack)
1257+
{
1258+
delete [] wzSystemDirectory;
1259+
}
1260+
12771261
(void)InterlockedExchange((LONG *)&g_dwSystemDirectory, len);
12781262
}
12791263

@@ -1283,17 +1267,18 @@ HRESULT SetInternalSystemDirectory()
12831267
#if defined(CROSSGEN_COMPILE) && defined(FEATURE_CORECLR)
12841268
void SetMscorlibPath(LPCWSTR wzSystemDirectory)
12851269
{
1286-
wcscpy_s(g_pSystemDirectory, COUNTOF(g_pSystemDirectory), wzSystemDirectory);
1287-
1270+
wcscpy_s(g_pSystemDirectory, MAX_LONGPATH+1, wzSystemDirectory);
12881271
DWORD len = (DWORD)wcslen(g_pSystemDirectory);
1289-
1272+
12901273
if(g_pSystemDirectory[len-1] != '\\')
12911274
{
12921275
g_pSystemDirectory[len] = W('\\');
12931276
g_pSystemDirectory[len+1] = W('\0');
12941277
g_dwSystemDirectory = len + 1;
12951278
}
12961279
else
1280+
{
12971281
g_dwSystemDirectory = len;
1282+
}
12981283
}
12991284
#endif

src/inc/sstring.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,15 @@ typedef InlineSString<512> StackSString;
10061006
// be needed is small and it's preferable not to take up the stack space.
10071007
typedef InlineSString<32> SmallStackSString;
10081008

1009+
// To be used specifically for path strings.
1010+
#ifdef _DEBUG
1011+
// This is a smaller version for debug builds to exercise the buffer allocation path
1012+
typedef InlineSString<32> PathString;
1013+
#else
1014+
// Set it to the current MAX_PATH
1015+
typedef InlineSString<260> PathString;
1016+
#endif
1017+
10091018
// ================================================================================
10101019
// Quick macro to create an SString around a literal string.
10111020
// usage:

0 commit comments

Comments
 (0)