From: Lakshmi Priya Sekar Date: Mon, 5 Oct 2015 18:51:50 +0000 (-0700) Subject: Apply StackString for pal MAX_LONGPATH references. X-Git-Tag: accepted/tizen/base/20180629.140029~6282^2~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f724894027c9c72483262f17457dac44356cc719;p=platform%2Fupstream%2Fcoreclr.git Apply StackString for pal MAX_LONGPATH references. --- diff --git a/src/pal/src/CMakeLists.txt b/src/pal/src/CMakeLists.txt index 20393cd..cbbed24 100644 --- a/src/pal/src/CMakeLists.txt +++ b/src/pal/src/CMakeLists.txt @@ -141,7 +141,6 @@ set(SOURCES misc/interlock.cpp misc/miscpalapi.cpp misc/msgbox.cpp - misc/stackstring.cpp misc/strutil.cpp misc/sysinfo.cpp misc/time.cpp diff --git a/src/pal/src/debug/debug.cpp b/src/pal/src/debug/debug.cpp index 6c36011..e36a46b 100644 --- a/src/pal/src/debug/debug.cpp +++ b/src/pal/src/debug/debug.cpp @@ -38,6 +38,7 @@ Revision History: #include "pal/misc.h" #include "pal/malloc.hpp" #include "pal/module.h" +#include "pal/stackstring.hpp" #include "pal/virtual.h" #include @@ -343,15 +344,18 @@ DebugBreakCommand() const char *command_string = getenv (PAL_RUN_ON_DEBUG_BREAK); if (command_string) { char pid_buf[sizeof (PID_TEXT) + 32]; - char exe_buf[sizeof (EXE_TEXT) + MAX_LONGPATH + 1]; + PathCharString exe_bufString; + SIZE_T dwexe_buf = strlen(EXE_TEXT) + PAL_wcslen(exe_module.lib_name) + 1; + CHAR * exe_buf = exe_bufString.OpenStringBuffer(dwexe_buf); if (snprintf (pid_buf, sizeof (pid_buf), PID_TEXT "%d", getpid()) <= 0) { goto FAILED; } - if (snprintf (exe_buf, sizeof (exe_buf), EXE_TEXT "%ls", (wchar_t *)exe_module.lib_name) <= 0) { + if (snprintf (exe_buf, sizeof (CHAR) * (dwexe_buf + 1), EXE_TEXT "%ls", (wchar_t *)exe_module.lib_name) <= 0) { goto FAILED; } + exe_bufString.CloseBuffer(dwexe_buf); /* strictly speaking, we might want to only set these environment variables in the child process, but if we do that we can't check for errors. putenv/setenv can fail when out of memory */ @@ -1598,7 +1602,7 @@ PAL_CreateExecWatchpoint( CPalThread *pTargetThread = NULL; IPalObject *pobjThread = NULL; int fd = -1; - char ctlPath[MAX_LONGPATH]; + char ctlPath[50]; struct { @@ -1642,6 +1646,7 @@ PAL_CreateExecWatchpoint( } snprintf(ctlPath, sizeof(ctlPath), "/proc/%u/lwp/%u/lwpctl", getpid(), pTargetThread->GetLwpId()); + fd = InternalOpen(pThread, ctlPath, O_WRONLY); if (-1 == fd) { @@ -1719,7 +1724,7 @@ PAL_DeleteExecWatchpoint( CPalThread *pTargetThread = NULL; IPalObject *pobjThread = NULL; int fd = -1; - char ctlPath[MAX_LONGPATH]; + char ctlPath[50]; struct { @@ -1744,6 +1749,7 @@ PAL_DeleteExecWatchpoint( } snprintf(ctlPath, sizeof(ctlPath), "/proc/%u/lwp/%u/lwpctl", getpid(), pTargetThread->GetLwpId()); + fd = InternalOpen(pThread, ctlPath, O_WRONLY); if (-1 == fd) { diff --git a/src/pal/src/misc/stackstring.cpp b/src/pal/src/include/pal/stackstring.hpp similarity index 74% rename from src/pal/src/misc/stackstring.cpp rename to src/pal/src/include/pal/stackstring.hpp index d35c0d8..aa8bd3e 100644 --- a/src/pal/src/misc/stackstring.cpp +++ b/src/pal/src/include/pal/stackstring.hpp @@ -1,17 +1,17 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#include "pal/malloc.hpp" -#include "pal/dbgmsg.h" +#ifndef __STACKSTRING_H_ +#define __STACKSTRING_H_ -SET_DEFAULT_DEBUG_CHANNEL(MISC); +#include "pal/malloc.hpp" -template +template class StackString { private: - WCHAR m_innerBuffer[STACKCOUNT + 1]; - WCHAR * m_buffer; + T m_innerBuffer[STACKCOUNT + 1]; + T * m_buffer; SIZE_T m_count; // actual allocated count void NullTerminate() @@ -31,10 +31,9 @@ private: void ReallocateBuffer(SIZE_T count) { // count is always > STACKCOUNT here. - WCHAR * newBuffer = (WCHAR *)PAL_malloc((count + 1) * sizeof(WCHAR)); + T * newBuffer = (T *)PAL_malloc((count + 1) * sizeof(T)); if (NULL == newBuffer) { - ERROR("malloc failed\n"); SetLastError(ERROR_NOT_ENOUGH_MEMORY); DeleteBuffer(); @@ -84,24 +83,19 @@ private: Set(s); } - ~StackString() - { - DeleteBuffer(); - } - public: StackString() - : m_count(0), m_buffer(m_innerBuffer) + : m_buffer(m_innerBuffer), m_count(0) { } - BOOL Set(const WCHAR * buffer, SIZE_T count) + BOOL Set(const T * buffer, SIZE_T count) { Resize(count); if (NULL == m_buffer) return FALSE; - CopyMemory(m_buffer, buffer, (count + 1) * sizeof(WCHAR)); + CopyMemory(m_buffer, buffer, (count + 1) * sizeof(T)); NullTerminate(); return TRUE; } @@ -116,15 +110,15 @@ public: return m_count; } - CONST WCHAR * GetString() const + CONST T * GetString() const { - return (const WCHAR *)m_buffer; + return (const T *)m_buffer; } - WCHAR * OpenStringBuffer(SIZE_T count) + T * OpenStringBuffer(SIZE_T count) { Resize(count); - return (WCHAR *)m_buffer; + return (T *)m_buffer; } void CloseBuffer(SIZE_T count) @@ -135,4 +129,18 @@ public: NullTerminate(); return; } + + ~StackString() + { + DeleteBuffer(); + } }; + +#if _DEBUG +typedef StackString<32, CHAR> PathCharString; +typedef StackString<32, WCHAR> PathWCharString; +#else +typedef StackString<260, CHAR> PathCharString; +typedef StackString<260, WCHAR> PathWCharString; +#endif +#endif