diff --git a/src/pal/src/CMakeLists.txt b/src/pal/src/CMakeLists.txt index 20393cd17e42..cbbed24aec20 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 6c36011ecf91..fc862900670c 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,24 @@ 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; + int libNameLength = 10; + if (exe_module.lib_name != NULL) + { + libNameLength = PAL_wcslen(exe_module.lib_name); + } + + SIZE_T dwexe_buf = strlen(EXE_TEXT) + libNameLength + 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 +1608,7 @@ PAL_CreateExecWatchpoint( CPalThread *pTargetThread = NULL; IPalObject *pobjThread = NULL; int fd = -1; - char ctlPath[MAX_LONGPATH]; + char ctlPath[50]; struct { @@ -1642,6 +1652,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 +1730,7 @@ PAL_DeleteExecWatchpoint( CPalThread *pTargetThread = NULL; IPalObject *pobjThread = NULL; int fd = -1; - char ctlPath[MAX_LONGPATH]; + char ctlPath[50]; struct { @@ -1744,6 +1755,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 70% rename from src/pal/src/misc/stackstring.cpp rename to src/pal/src/include/pal/stackstring.hpp index d35c0d88fc03..392c8319f8f8 100644 --- a/src/pal/src/misc/stackstring.cpp +++ b/src/pal/src/include/pal/stackstring.hpp @@ -1,22 +1,22 @@ // 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() { - m_buffer[m_count] = W('\0'); + m_buffer[m_count] = 0; } void DeleteBuffer() @@ -31,10 +31,9 @@ class StackString 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 @@ class StackString 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; } @@ -111,20 +105,25 @@ class StackString return Set(s.m_buffer, s.m_count); } - SIZE_T Getcount() const + SIZE_T GetCount() const { return m_count; } + + SIZE_T GetSizeOf() const + { + return (m_count+1) * sizeof(T); + } - 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 +134,18 @@ class StackString 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