{
if (Prefix == PFF_PREFIX_LONG && Type == PFF_TYPE_STRING)
{
+ if (WIDTH_STAR == Width)
+ {
+ Width = va_arg(ap, INT);
+ }
+ else if (WIDTH_INVALID == Width)
+ {
+ /* both a '*' and a number, ignore, but remove arg */
+ TempInt = va_arg(ap, INT); /* value not used */
+ }
+
if (PRECISION_STAR == Precision)
{
Precision = va_arg(ap, INT);
/* both a '*' and a number, ignore, but remove arg */
TempInt = va_arg(ap, INT); /* value not used */
}
+
TempWStr = va_arg(ap, LPWSTR);
Length = Silent_WideCharToMultiByte(TempWStr, -1, 0, 0);
if (!Length)
}
/* clip string output to MAX_STR_LEN characters */
- if(-1 == Precision)
+ if (PRECISION_DOT == Precision)
{
Precision = MAX_STR_LEN;
}
else if (Prefix == PFF_PREFIX_LONG && Type == PFF_TYPE_CHAR)
{
CHAR TempBuffer[4];
+
+ if (WIDTH_STAR == Width ||
+ WIDTH_INVALID == Width)
+ {
+ /* ignore (because it's a char), and remove arg */
+ TempInt = va_arg(ap, INT); /* value not used */
+ }
if (PRECISION_STAR == Precision ||
PRECISION_INVALID == Precision)
{
next arg */
else if (Type == PFF_TYPE_N)
{
+ if (WIDTH_STAR == Width)
+ {
+ Width = va_arg(ap, INT);
+ }
if (PRECISION_STAR == Precision)
{
Precision = va_arg(ap, INT);
*(va_arg(ap, LPLONG)) = BufferPtr - Buffer;
}
}
+ else if (Type == PFF_TYPE_CHAR && (Flags & PFF_ZERO) != 0)
+ {
+ // Some versions of sprintf don't support 0-padded chars,
+ // so we handle them here.
+ char ch[2];
+
+ ch[0] = (char) va_arg(ap, int);
+ ch[1] = '\0';
+ Length = 1;
+ BufferRanOut = !Internal_AddPaddingA(&BufferPtr,
+ Count - (BufferPtr - Buffer),
+ ch,
+ Width - Length,
+ Flags);
+ }
+ else if (Type == PFF_TYPE_STRING && (Flags & PFF_ZERO) != 0)
+ {
+ // Some versions of sprintf don't support 0-padded strings,
+ // so we handle them here.
+ char *tempStr;
+
+ tempStr = va_arg(ap, char *);
+ Length = strlen(tempStr);
+ BufferRanOut = !Internal_AddPaddingA(&BufferPtr,
+ Count - (BufferPtr - Buffer),
+ tempStr,
+ Width - Length,
+ Flags);
+ }
/* types that sprintf can handle */
else
{
TempInt = snprintf(BufferPtr, TempCount, TempBuff, trunc2);
}
+ else if (Type == PFF_TYPE_INT && Prefix == PFF_PREFIX_SHORT)
+ {
+ // Convert explicitly from int to short to get
+ // correct sign extension for shorts on all systems.
+ int n;
+ short s;
+
+ n = va_arg(ap, int);
+ s = (short) n;
+
+ TempInt = snprintf(BufferPtr, TempCount, TempBuff, s);
+ }
else
{
/* limit string output (%s) to 300 characters */
- if(TempBuff[0]=='%' && TempBuff[1]=='s')
+ if(TempBuff[0] == '%' && TempBuff[1] == 's')
{
if (strcpy_s(TempBuff, sizeof(TempBuff), "%.300s") != SAFECRT_SUCCESS)
{
}
else
{
-
return BufferPtr - Buffer;
}
}
{
if (Prefix == PFF_PREFIX_LONG && Type == PFF_TYPE_STRING)
{
+ if (WIDTH_STAR == Width)
+ {
+ Width = va_arg(ap, INT);
+ }
+ else if (WIDTH_INVALID == Width)
+ {
+ /* both a '*' and a number, ignore, but remove arg */
+ TempInt = va_arg(ap, INT); /* value not used */
+ }
+
if (PRECISION_STAR == Precision)
{
Precision = va_arg(ap, INT);
/* both a '*' and a number, ignore, but remove arg */
TempInt = va_arg(ap, INT); /* value not used */
}
+
TempWStr = va_arg(ap, LPWSTR);
Length = Silent_WideCharToMultiByte(TempWStr, -1, 0, 0);
if (!Length)
else if (Prefix == PFF_PREFIX_LONG && Type == PFF_TYPE_CHAR)
{
CHAR TempBuffer[4];
+ if (WIDTH_STAR == Width ||
+ WIDTH_INVALID == Width)
+ {
+ /* ignore (because it's a char), and remove arg */
+ TempInt = va_arg(ap, INT); /* value not used */
+ }
if (PRECISION_STAR == Precision ||
PRECISION_INVALID == Precision)
{
next arg */
else if (Type == PFF_TYPE_N)
{
+ if (WIDTH_STAR == Width)
+ {
+ Width = va_arg(ap, INT);
+ }
if (PRECISION_STAR == Precision)
{
Precision = va_arg(ap, INT);
}
+
if (Prefix == PFF_PREFIX_SHORT)
{
*(va_arg(ap, short *)) = written;
TempInt = fprintf((FILE*)stream, TempBuff, trunc2);
}
+ else if (Type == PFF_TYPE_INT && Prefix == PFF_PREFIX_SHORT)
+ {
+ // Convert explicitly from int to short to get
+ // correct sign extension for shorts on all systems.
+ int n;
+ short s;
+
+ n = va_arg(ap, int);
+ s = (short)n;
+
+ TempInt = fprintf((FILE*)stream, TempBuff, s);
+ }
else
{
va_list apcopy;
see Internal_ExtractFormatA function in printf.c
*******************************************************************************/
-BOOL Silent_ExtractFormatA(LPCSTR *Fmt, LPSTR Out, LPINT Flags,
- LPINT Width, LPINT Precision,
- LPINT Prefix, LPINT Type)
+BOOL Silent_ExtractFormatA(LPCSTR *Fmt, LPSTR Out, LPINT Flags, LPINT Width, LPINT Precision, LPINT Prefix, LPINT Type)
{
BOOL Result = FALSE;
LPSTR TempStr;
LPSTR TempStrPtr;
- *Width = -1;
- *Precision = -1;
- *Flags = 0;
- *Prefix = -1;
- *Type = -1;
+ *Width = WIDTH_DEFAULT;
+ *Precision = PRECISION_DEFAULT;
+ *Flags = PFF_NONE;
+ *Prefix = PFF_PREFIX_DEFAULT;
+ *Type = PFF_TYPE_DEFAULT;
if (*Fmt && **Fmt == '%')
{
return Result;
}
}
+ else if (**Fmt == '*')
+ {
+ *Width = WIDTH_STAR;
+ *Out++ = *(*Fmt)++;
+ if (isdigit((unsigned char) **Fmt))
+ {
+ /* this is an invalid width because we have a * then a number */
+ /* printf handles this by just printing the whole string */
+ *Width = WIDTH_INVALID;
+ while (isdigit((unsigned char) **Fmt))
+ {
+ *Out++ = *(*Fmt)++;
+ }
+ }
+ }
+
/* grab precision specifier */
if (**Fmt == '.')
*Out++ = *(*Fmt)++;
}
}
- else
- {
- *Precision = PRECISION_STAR;
- }
}
else
{
}
}
+#ifdef BIT64
+ if (**Fmt == 'p')
+ {
+ *Prefix = PFF_PREFIX_LONGLONG;
+ }
+#endif
/* grab prefix of 'I64' for __int64 */
if ((*Fmt)[0] == 'I' && (*Fmt)[1] == '6' && (*Fmt)[2] == '4')
{
/* grab prefix of 'l' or the undocumented 'w' (at least in MSDN) */
else if (**Fmt == 'l' || **Fmt == 'w')
{
- *Prefix = PFF_PREFIX_LONG;
++(*Fmt);
+#ifdef BIT64
+ // Only want to change the prefix on 64 bit when printing characters.
+ if (**Fmt == 'c' || **Fmt == 's')
+#endif
+ {
+ *Prefix = PFF_PREFIX_LONG;
+ }
}
else if (**Fmt == 'L')
{
else if (**Fmt == 'p')
{
*Type = PFF_TYPE_P;
- if (*Prefix == PFF_PREFIX_SHORT)
- {
- *Out++ = 'h';
- }
- else if (*Prefix == PFF_PREFIX_LONG)
+ *Out++ = *(*Fmt)++;
+
+ if (*Prefix == PFF_PREFIX_LONGLONG)
{
- *Out++ = 'l';
+ if (*Precision == PRECISION_DEFAULT)
+ {
+ *Precision = 16;
+ }
}
- else if (*Prefix == PFF_PREFIX_LONGLONG)
+ else
{
- /* native *printf does not support %I64p
- (actually %llp), so we need to cheat a little bit */
- *Out++ = 'l';
- *Out++ = 'l';
+ if (*Precision == PRECISION_DEFAULT)
+ {
+ *Precision = 8;
+ }
}
- (*Fmt)++;
- *Out++ = '.';
- *Out++ = '8';
- *Out++ = 'X';
Result = TRUE;
}
#endif // !DISABLE_EXCEPTIONS
static const char * PAL_MACH_EXCEPTION_MODE = "PAL_MachExceptionMode";
+
enum MachExceptionMode
{
// special value to indicate we've not initialized yet
MachException_SuppressManaged = 4,
// Default value to use if environment variable not set.
- MachException_Default = 2,
+ MachException_Default = 0,
};
static exception_mask_t GetExceptionMask()
pointers.ExceptionRecord = pExRecord;
pointers.ContextRecord = pContext;
+ NONPAL_TRACE("PAL_DispatchException(EC %08x EA %p)\n", pExRecord->ExceptionCode, pExRecord->ExceptionAddress);
SEHProcessException(&pointers);
}
#endif // _AMD64_
);
- ThreadContext.ContextFlags = CONTEXT_ALL;
+ // Don't save/restore the debug registers because loading them on OSx causes a
+ // priviledged instruction fault. The "DE" in CR4 is set.
+#ifdef _X86_
+ ThreadContext.ContextFlags = CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | CONTEXT_FLOATING_POINT | CONTEXT_EXTENDED_REGISTERS
+#else
+ ThreadContext.ContextFlags = CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | CONTEXT_FLOATING_POINT;
+#endif
MachRet = CONTEXT_GetThreadContextFromPort(thread, &ThreadContext);
CHECK_MACH("CONTEXT_GetThreadContextFromPort", MachRet);
if (IsWithinCoreCLR(ip))
{
NONPAL_TRACE(" IP (%p) is in CoreCLR.\n", ip);
- return true;
+ return CatchHardwareExceptionHolder::IsEnabled();
}
// Check inside our executable heap.
- bool fExecutableHeap = s_pExecutableHeap != NULL &&
- malloc_zone_owns_addr(s_pExecutableHeap, ip);
+ bool fExecutableHeap = s_pExecutableHeap != NULL && malloc_zone_owns_addr(s_pExecutableHeap, ip);
if (fExecutableHeap)
{
NONPAL_TRACE(" IP (%p) is in the executable heap (%p).\n", ip, s_pExecutableHeap);
void *pCallerIP = (void *)*((PULONG64)(rbpFaultingFunc+1));
if (IsWithinCoreCLR(pCallerIP))
{
- NONPAL_TRACE(" CallerIP (%p) is in CoreCLR.\n", pCallerIP);
+ NONPAL_TRACE(" CallerIP (%p) is in CoreCLR (IP %p).\n", pCallerIP, ip);
return true;
}
#endif // defined(_AMD64_)