#include "pal/misc.h"
#include "pal/malloc.hpp"
#include "pal/module.h"
+#include "pal/stackstring.hpp"
#include "pal/virtual.h"
#include <signal.h>
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 */
CPalThread *pTargetThread = NULL;
IPalObject *pobjThread = NULL;
int fd = -1;
- char ctlPath[MAX_LONGPATH];
+ char ctlPath[50];
struct
{
}
snprintf(ctlPath, sizeof(ctlPath), "/proc/%u/lwp/%u/lwpctl", getpid(), pTargetThread->GetLwpId());
+
fd = InternalOpen(pThread, ctlPath, O_WRONLY);
if (-1 == fd)
{
CPalThread *pTargetThread = NULL;
IPalObject *pobjThread = NULL;
int fd = -1;
- char ctlPath[MAX_LONGPATH];
+ char ctlPath[50];
struct
{
}
snprintf(ctlPath, sizeof(ctlPath), "/proc/%u/lwp/%u/lwpctl", getpid(), pTargetThread->GetLwpId());
+
fd = InternalOpen(pThread, ctlPath, O_WRONLY);
if (-1 == fd)
{
// 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 <SIZE_T STACKCOUNT>
+template <SIZE_T STACKCOUNT, class T>
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()
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();
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;
}
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)
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