Commit 6368c10c authored by fbarchard@google.com's avatar fbarchard@google.com

Add __declspec(safebuffers) to functions with arrays on stack that have explicit…

Add __declspec(safebuffers) to functions with arrays on stack that have explicit checks to avoid a redundent compiler stack check.
BUG=none
TEST=unitests pass
R=ryanpetrie@google.com

Review URL: https://webrtc-codereview.appspot.com/3289004

git-svn-id: http://libyuv.googlecode.com/svn/trunk@837 16f28f9a-4ce2-e073-06de-1de4eb20be90
parent f3871ce9
Name: libyuv
URL: http://code.google.com/p/libyuv/
Version: 836
Version: 837
License: BSD
License File: LICENSE
......
......@@ -377,6 +377,14 @@ typedef uint8 uvec8[16];
#define OMITFP __attribute__((optimize("omit-frame-pointer")))
#endif
// For functions that use rowbuffer and have runtime checks for overflow,
// use SAFEBUFFERS to avoid additional check.
#if defined(_MSC_VER) && (_MSC_FULL_VER >= 160040219)
#define SAFEBUFFERS __declspec(safebuffers)
#else
#define SAFEBUFFERS
#endif
void I444ToARGBRow_NEON(const uint8* src_y,
const uint8* src_u,
const uint8* src_v,
......
......@@ -11,6 +11,6 @@
#ifndef INCLUDE_LIBYUV_VERSION_H_ // NOLINT
#define INCLUDE_LIBYUV_VERSION_H_
#define LIBYUV_VERSION 836
#define LIBYUV_VERSION 837
#endif // INCLUDE_LIBYUV_VERSION_H_ NOLINT
......@@ -1047,7 +1047,7 @@ int RGBAToI420(const uint8* src_rgba, int src_stride_rgba,
}
// Convert RGB24 to I420.
LIBYUV_API
LIBYUV_API SAFEBUFFERS
int RGB24ToI420(const uint8* src_rgb24, int src_stride_rgb24,
uint8* dst_y, int dst_stride_y,
uint8* dst_u, int dst_stride_u,
......@@ -1150,7 +1150,7 @@ int RGB24ToI420(const uint8* src_rgb24, int src_stride_rgb24,
}
// Convert RAW to I420.
LIBYUV_API
LIBYUV_API SAFEBUFFERS
int RAWToI420(const uint8* src_raw, int src_stride_raw,
uint8* dst_y, int dst_stride_y,
uint8* dst_u, int dst_stride_u,
......@@ -1253,7 +1253,7 @@ int RAWToI420(const uint8* src_raw, int src_stride_raw,
}
// Convert RGB565 to I420.
LIBYUV_API
LIBYUV_API SAFEBUFFERS
int RGB565ToI420(const uint8* src_rgb565, int src_stride_rgb565,
uint8* dst_y, int dst_stride_y,
uint8* dst_u, int dst_stride_u,
......@@ -1356,7 +1356,7 @@ int RGB565ToI420(const uint8* src_rgb565, int src_stride_rgb565,
}
// Convert ARGB1555 to I420.
LIBYUV_API
LIBYUV_API SAFEBUFFERS
int ARGB1555ToI420(const uint8* src_argb1555, int src_stride_argb1555,
uint8* dst_y, int dst_stride_y,
uint8* dst_u, int dst_stride_u,
......@@ -1461,7 +1461,7 @@ int ARGB1555ToI420(const uint8* src_argb1555, int src_stride_argb1555,
}
// Convert ARGB4444 to I420.
LIBYUV_API
LIBYUV_API SAFEBUFFERS
int ARGB4444ToI420(const uint8* src_argb4444, int src_stride_argb4444,
uint8* dst_y, int dst_stride_y,
uint8* dst_u, int dst_stride_u,
......
......@@ -245,7 +245,7 @@ int ARGBToI411(const uint8* src_argb, int src_stride_argb,
return 0;
}
LIBYUV_API
LIBYUV_API SAFEBUFFERS
int ARGBToNV12(const uint8* src_argb, int src_stride_argb,
uint8* dst_y, int dst_stride_y,
uint8* dst_uv, int dst_stride_uv,
......@@ -347,7 +347,7 @@ int ARGBToNV12(const uint8* src_argb, int src_stride_argb,
}
// Same as NV12 but U and V swapped.
LIBYUV_API
LIBYUV_API SAFEBUFFERS
int ARGBToNV21(const uint8* src_argb, int src_stride_argb,
uint8* dst_y, int dst_stride_y,
uint8* dst_uv, int dst_stride_uv,
......@@ -449,7 +449,7 @@ int ARGBToNV21(const uint8* src_argb, int src_stride_argb,
}
// Convert ARGB to YUY2.
LIBYUV_API
LIBYUV_API SAFEBUFFERS
int ARGBToYUY2(const uint8* src_argb, int src_stride_argb,
uint8* dst_yuy2, int dst_stride_yuy2,
int width, int height) {
......@@ -545,7 +545,7 @@ int ARGBToYUY2(const uint8* src_argb, int src_stride_argb,
}
// Convert ARGB to UYVY.
LIBYUV_API
LIBYUV_API SAFEBUFFERS
int ARGBToUYVY(const uint8* src_argb, int src_stride_argb,
uint8* dst_uyvy, int dst_stride_uyvy,
int width, int height) {
......
......@@ -33,6 +33,14 @@ namespace libyuv {
extern "C" {
#endif
// For functions that use rowbuffer and have runtime checks for overflow,
// use SAFEBUFFERS to avoid additional check.
#if defined(_MSC_VER) && (_MSC_FULL_VER >= 160040219)
#define SAFEBUFFERS __declspec(safebuffers)
#else
#define SAFEBUFFERS
#endif
// Low level cpuid for X86. Returns zeros on other CPUs.
#if !defined(__CLR_VER) && (defined(_M_IX86) || defined(_M_X64) || \
defined(__i386__) || defined(__x86_64__))
......@@ -108,10 +116,7 @@ void CpuId(uint32 eax, uint32 ecx, uint32* cpu_info) {
// based on libvpx arm_cpudetect.c
// For Arm, but public to allow testing on any CPU
#if defined(_MSC_VER) && (_MSC_FULL_VER >= 160040219)
__declspec(safebuffers)
#endif
LIBYUV_API
LIBYUV_API SAFEBUFFERS
int ArmCpuCaps(const char* cpuinfo_name) {
FILE* f = fopen(cpuinfo_name, "r");
if (f) {
......@@ -171,10 +176,7 @@ static bool TestEnv(const char*) {
}
#endif
#if defined(_MSC_VER) && (_MSC_FULL_VER >= 160040219)
__declspec(safebuffers)
#endif
LIBYUV_API
LIBYUV_API SAFEBUFFERS
int InitCpuFlags(void) {
#if !defined(__CLR_VER) && defined(CPU_X86)
uint32 cpu_info1[4] = { 0, 0, 0, 0 };
......
......@@ -280,7 +280,7 @@ int BayerToARGB(const uint8* src_bayer, int src_stride_bayer,
}
// Converts any Bayer RGB format to ARGB.
LIBYUV_API
LIBYUV_API SAFEBUFFERS
int BayerToI420(const uint8* src_bayer, int src_stride_bayer,
uint8* dst_y, int dst_stride_y,
uint8* dst_u, int dst_stride_u,
......@@ -380,7 +380,7 @@ int BayerToI420(const uint8* src_bayer, int src_stride_bayer,
}
// Convert I420 to Bayer.
LIBYUV_API
LIBYUV_API SAFEBUFFERS
int I420ToBayer(const uint8* src_y, int src_stride_y,
const uint8* src_u, int src_stride_u,
const uint8* src_v, int src_stride_v,
......
......@@ -420,9 +420,12 @@ void MJpegDecoder::ErrorHandler(j_common_ptr cinfo) {
// recover from errors we use setjmp() as shown in their example. setjmp() is
// C's implementation for the "call with current continuation" functionality
// seen in some functional programming languages.
// A formatted message can be output, but is unsafe for release.
#ifdef DEBUG
char buf[JMSG_LENGTH_MAX];
(*cinfo->err->format_message)(cinfo, buf);
// ERROR: Error in jpeglib: buf
#endif
SetJmpErrorMgr* mgr = reinterpret_cast<SetJmpErrorMgr*>(cinfo->err);
// This rewinds the call stack to the point of the corresponding setjmp()
......
......@@ -1366,7 +1366,7 @@ int ARGBColorMatrix(const uint8* src_argb, int src_stride_argb,
// Apply a 4x3 matrix to each ARGB pixel.
// Deprecated.
LIBYUV_API
LIBYUV_API SAFEBUFFERS
int RGBColorMatrix(uint8* dst_argb, int dst_stride_argb,
const int8* matrix_rgb,
int dst_x, int dst_y, int width, int height) {
......@@ -1828,12 +1828,13 @@ int ARGBShuffle(const uint8* src_bgra, int src_stride_bgra,
}
// Sobel ARGB effect.
static int ARGBSobelize(const uint8* src_argb, int src_stride_argb,
uint8* dst_argb, int dst_stride_argb,
int width, int height,
void (*SobelRow)(const uint8* src_sobelx,
const uint8* src_sobely,
uint8* dst, int width)) {
static SAFEBUFFERS
int ARGBSobelize(const uint8* src_argb, int src_stride_argb,
uint8* dst_argb, int dst_stride_argb,
int width, int height,
void (*SobelRow)(const uint8* src_sobelx,
const uint8* src_sobely,
uint8* dst, int width)) {
const int kMaxRow = kMaxStride / 4;
const int kEdge = 16; // Extra pixels at start of row for extrude/align.
if (!src_argb || !dst_argb ||
......
......@@ -867,7 +867,7 @@ void RotatePlane270(const uint8* src, int src_stride,
TransposePlane(src, src_stride, dst, dst_stride, width, height);
}
LIBYUV_API
LIBYUV_API SAFEBUFFERS
void RotatePlane180(const uint8* src, int src_stride,
uint8* dst, int dst_stride,
int width, int height) {
......
......@@ -89,6 +89,7 @@ void ARGBRotate270(const uint8* src, int src_stride,
ARGBTranspose(src, src_stride, dst, dst_stride, width, height);
}
SAFEBUFFERS
void ARGBRotate180(const uint8* src, int src_stride,
uint8* dst, int dst_stride,
int width, int height) {
......
......@@ -1943,10 +1943,19 @@ void I422ToUYVYRow_C(const uint8* src_y,
}
}
// TODO(fbarchard): Ensure these are stack safe.
#ifdef DEBUG
#define MAYBE_SAFEBUFFERS
#else
#define MAYBE_SAFEBUFFERS SAFEBUFFERS
#endif
#if !defined(LIBYUV_DISABLE_X86) && defined(HAS_I422TOARGBROW_SSSE3)
// row_win.cc has asm version, but GCC uses 2 step wrapper. 5% slower.
// TODO(fbarchard): Handle width > kMaxStride here instead of calling code.
#if defined(__x86_64__) || defined(__i386__)
MAYBE_SAFEBUFFERS
void I422ToRGB565Row_SSSE3(const uint8* src_y,
const uint8* src_u,
const uint8* src_v,
......@@ -1959,6 +1968,7 @@ void I422ToRGB565Row_SSSE3(const uint8* src_y,
#endif // defined(__x86_64__) || defined(__i386__)
#if defined(_M_IX86) || defined(__x86_64__) || defined(__i386__)
MAYBE_SAFEBUFFERS
void I422ToARGB1555Row_SSSE3(const uint8* src_y,
const uint8* src_u,
const uint8* src_v,
......@@ -1969,6 +1979,7 @@ void I422ToARGB1555Row_SSSE3(const uint8* src_y,
ARGBToARGB1555Row_SSE2(row, rgb_buf, width);
}
MAYBE_SAFEBUFFERS
void I422ToARGB4444Row_SSSE3(const uint8* src_y,
const uint8* src_u,
const uint8* src_v,
......@@ -1979,6 +1990,7 @@ void I422ToARGB4444Row_SSSE3(const uint8* src_y,
ARGBToARGB4444Row_SSE2(row, rgb_buf, width);
}
MAYBE_SAFEBUFFERS
void NV12ToRGB565Row_SSSE3(const uint8* src_y,
const uint8* src_uv,
uint8* dst_rgb565,
......@@ -1988,6 +2000,7 @@ void NV12ToRGB565Row_SSSE3(const uint8* src_y,
ARGBToRGB565Row_SSE2(row, dst_rgb565, width);
}
MAYBE_SAFEBUFFERS
void NV21ToRGB565Row_SSSE3(const uint8* src_y,
const uint8* src_vu,
uint8* dst_rgb565,
......@@ -1997,6 +2010,7 @@ void NV21ToRGB565Row_SSSE3(const uint8* src_y,
ARGBToRGB565Row_SSE2(row, dst_rgb565, width);
}
MAYBE_SAFEBUFFERS
void YUY2ToARGBRow_SSSE3(const uint8* src_yuy2,
uint8* dst_argb,
int width) {
......@@ -2008,6 +2022,7 @@ void YUY2ToARGBRow_SSSE3(const uint8* src_yuy2,
I422ToARGBRow_SSSE3(row_y, row_u, row_v, dst_argb, width);
}
MAYBE_SAFEBUFFERS
void YUY2ToARGBRow_Unaligned_SSSE3(const uint8* src_yuy2,
uint8* dst_argb,
int width) {
......@@ -2019,6 +2034,7 @@ void YUY2ToARGBRow_Unaligned_SSSE3(const uint8* src_yuy2,
I422ToARGBRow_Unaligned_SSSE3(row_y, row_u, row_v, dst_argb, width);
}
MAYBE_SAFEBUFFERS
void UYVYToARGBRow_SSSE3(const uint8* src_uyvy,
uint8* dst_argb,
int width) {
......@@ -2030,6 +2046,7 @@ void UYVYToARGBRow_SSSE3(const uint8* src_uyvy,
I422ToARGBRow_SSSE3(row_y, row_u, row_v, dst_argb, width);
}
MAYBE_SAFEBUFFERS
void UYVYToARGBRow_Unaligned_SSSE3(const uint8* src_uyvy,
uint8* dst_argb,
int width) {
......
......@@ -2004,7 +2004,7 @@ static void ScaleAddCols1_C(int dst_width, int boxheight, int x, int dx,
// one pixel of destination using fixed point (16.16) to step
// through source, sampling a box of pixel with simple
// averaging.
SAFEBUFFERS
static void ScalePlaneBox(int src_width, int src_height,
int dst_width, int dst_height,
int src_stride, int dst_stride,
......@@ -2076,7 +2076,7 @@ static void ScalePlaneBox(int src_width, int src_height,
}
// Scale plane to/from any dimensions, with bilinear interpolation.
SAFEBUFFERS
void ScalePlaneBilinear(int src_width, int src_height,
int dst_width, int dst_height,
int src_stride, int dst_stride,
......
......@@ -895,6 +895,7 @@ static void ScaleARGBDownEven(int src_width, int src_height,
}
// Scale ARGB down with bilinear interpolation.
SAFEBUFFERS
static void ScaleARGBBilinearDown(int src_height,
int dst_width, int dst_height,
int src_stride, int dst_stride,
......@@ -987,6 +988,7 @@ static void ScaleARGBBilinearDown(int src_height,
}
// Scale ARGB up with bilinear interpolation.
SAFEBUFFERS
static void ScaleARGBBilinearUp(int src_width, int src_height,
int dst_width, int dst_height,
int src_stride, int dst_stride,
......@@ -1089,6 +1091,7 @@ static void ScaleARGBBilinearUp(int src_width, int src_height,
#ifdef YUVSCALEUP
// Scale YUV to ARGB up with bilinear interpolation.
SAFEBUFFERS
static void ScaleYUVToARGBBilinearUp(int src_width, int src_height,
int dst_width, int dst_height,
int src_stride_y,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment