DragImageRef createDragImageFromImage(Image* img, ImageOrientationDescription) { HWndDC dc(0); auto workingDC = adoptGDIObject(::CreateCompatibleDC(dc)); if (!workingDC) return 0; CGContextRef drawContext = 0; auto hbmp = allocImage(workingDC.get(), img->size(), &drawContext); if (!hbmp || !drawContext) return 0; CGImageRef srcImage = img->getCGImageRef(); CGRect rect; rect.size = img->size(); rect.origin.x = 0; rect.origin.y = -rect.size.height; static const CGFloat white [] = {1.0, 1.0, 1.0, 1.0}; CGContextScaleCTM(drawContext, 1, -1); CGContextSetFillColor(drawContext, white); CGContextFillRect(drawContext, rect); if (srcImage) { CGContextSetBlendMode(drawContext, kCGBlendModeNormal); CGContextDrawImage(drawContext, rect, srcImage); } CGContextRelease(drawContext); return hbmp.leak(); }
void *thr_func(void *arg) { while (1) { size_t s = calc_size(); void *p = malloc(s); if (p == NULL) { printf("Failed to malloc: %d\n", s); return NULL; } if (!is_access()) memset(p, 0xaa, s); if (!leak()) free(p); /* sleep */ const static useconds_t slp_min = 10*1000; const static useconds_t slp_max = 100*1000; useconds_t slp = (slp_max - slp_min) * frand() + slp_min; usleep(slp); } }
HDC GraphicsContext::getWindowsContext(const IntRect& dstRect, bool supportAlphaBlend, bool mayCreateBitmap) { // FIXME: Should a bitmap be created also when a shadow is set? if (mayCreateBitmap && (!m_data->m_hdc || isInTransparencyLayer())) { if (dstRect.isEmpty()) return 0; // Create a bitmap DC in which to draw. BitmapInfo bitmapInfo = BitmapInfo::create(dstRect.size()); void* pixels = 0; HBITMAP bitmap = ::CreateDIBSection(NULL, &bitmapInfo, DIB_RGB_COLORS, &pixels, 0, 0); if (!bitmap) return 0; auto bitmapDC = adoptGDIObject(::CreateCompatibleDC(m_data->m_hdc)); ::SelectObject(bitmapDC.get(), bitmap); // Fill our buffer with clear if we're going to alpha blend. if (supportAlphaBlend) fillWithClearColor(bitmap); // Make sure we can do world transforms. ::SetGraphicsMode(bitmapDC.get(), GM_ADVANCED); // Apply a translation to our context so that the drawing done will be at (0,0) of the bitmap. XFORM xform = TransformationMatrix().translate(-dstRect.x(), -dstRect.y()); ::SetWorldTransform(bitmapDC.get(), &xform); return bitmapDC.leak(); } m_data->flush(); m_data->save(); return m_data->m_hdc; }
DragImageRef createDragImageForLink(URL& url, const String& inLabel, FontRenderingMode fontRenderingMode) { // This is more or less an exact match for the Mac OS X code. const Font* labelFont; const Font* urlFont; FontCachePurgePreventer fontCachePurgePreventer; if (fontRenderingMode == AlternateRenderingMode) { static const Font alternateRenderingModeLabelFont = dragLabelFont(DragLinkLabelFontsize, true, AlternateRenderingMode); static const Font alternateRenderingModeURLFont = dragLabelFont(DragLinkUrlFontSize, false, AlternateRenderingMode); labelFont = &alternateRenderingModeLabelFont; urlFont = &alternateRenderingModeURLFont; } else { static const Font normalRenderingModeLabelFont = dragLabelFont(DragLinkLabelFontsize, true, NormalRenderingMode); static const Font normalRenderingModeURLFont = dragLabelFont(DragLinkUrlFontSize, false, NormalRenderingMode); labelFont = &normalRenderingModeLabelFont; urlFont = &normalRenderingModeURLFont; } bool drawURLString = true; bool clipURLString = false; bool clipLabelString = false; String urlString = url.string(); String label = inLabel; if (label.isEmpty()) { drawURLString = false; label = urlString; } // First step in drawing the link drag image width. TextRun labelRun(label.impl()); TextRun urlRun(urlString.impl()); IntSize labelSize(labelFont->width(labelRun), labelFont->fontMetrics().ascent() + labelFont->fontMetrics().descent()); if (labelSize.width() > MaxDragLabelStringWidth) { labelSize.setWidth(MaxDragLabelStringWidth); clipLabelString = true; } IntSize urlStringSize; IntSize imageSize(labelSize.width() + DragLabelBorderX * 2, labelSize.height() + DragLabelBorderY * 2); if (drawURLString) { urlStringSize.setWidth(urlFont->width(urlRun)); urlStringSize.setHeight(urlFont->fontMetrics().ascent() + urlFont->fontMetrics().descent()); imageSize.setHeight(imageSize.height() + urlStringSize.height()); if (urlStringSize.width() > MaxDragLabelStringWidth) { imageSize.setWidth(MaxDragLabelWidth); clipURLString = true; } else imageSize.setWidth(std::max(labelSize.width(), urlStringSize.width()) + DragLabelBorderX * 2); } // We now know how big the image needs to be, so we create and // fill the background HWndDC dc(0); auto workingDC = adoptGDIObject(::CreateCompatibleDC(dc)); if (!workingDC) return 0; PlatformGraphicsContext* contextRef; auto image = allocImage(workingDC.get(), imageSize, &contextRef); if (!image) return 0; ::SelectObject(workingDC.get(), image.get()); GraphicsContext context(contextRef); // On Mac alpha is {0.7, 0.7, 0.7, 0.8}, however we can't control alpha // for drag images on win, so we use 1 static const Color backgroundColor(140, 140, 140); static const IntSize radii(DragLabelRadius, DragLabelRadius); IntRect rect(0, 0, imageSize.width(), imageSize.height()); context.fillRoundedRect(FloatRoundedRect(rect, radii, radii, radii, radii), backgroundColor, ColorSpaceDeviceRGB); // Draw the text static const Color topColor(0, 0, 0, 255); // original alpha = 0.75 static const Color bottomColor(255, 255, 255, 127); // original alpha = 0.5 if (drawURLString) { if (clipURLString) urlString = StringTruncator::rightTruncate(urlString, imageSize.width() - (DragLabelBorderX * 2.0f), *urlFont, StringTruncator::EnableRoundingHacks); IntPoint textPos(DragLabelBorderX, imageSize.height() - (LabelBorderYOffset + urlFont->fontMetrics().descent())); WebCoreDrawDoubledTextAtPoint(context, urlString, textPos, *urlFont, topColor, bottomColor); } if (clipLabelString) label = StringTruncator::rightTruncate(label, imageSize.width() - (DragLabelBorderX * 2.0f), *labelFont, StringTruncator::EnableRoundingHacks); IntPoint textPos(DragLabelBorderX, DragLabelBorderY + labelFont->pixelSize()); WebCoreDrawDoubledTextAtPoint(context, label, textPos, *labelFont, topColor, bottomColor); deallocContext(contextRef); return image.leak(); }
noinline int do_action(const char* arg) { // Prefixes. if (!strncmp(arg, "wait-", strlen("wait-"))) { char buf[1]; TEMP_FAILURE_RETRY(read(STDIN_FILENO, buf, sizeof(buf))); return do_action(arg + strlen("wait-")); } else if (!strncmp(arg, "exhaustfd-", strlen("exhaustfd-"))) { errno = 0; while (errno != EMFILE) { open("/dev/null", O_RDONLY); } return do_action(arg + strlen("exhaustfd-")); } else if (!strncmp(arg, "thread-", strlen("thread-"))) { return do_action_on_thread(arg + strlen("thread-")); } // Actions. if (!strcasecmp(arg, "SIGSEGV-non-null")) { sigsegv_non_null(); } else if (!strcasecmp(arg, "smash-stack")) { volatile int len = 128; return smash_stack(&len); } else if (!strcasecmp(arg, "stack-overflow")) { overflow_stack(nullptr); } else if (!strcasecmp(arg, "nostack")) { crashnostack(); } else if (!strcasecmp(arg, "exit")) { exit(1); } else if (!strcasecmp(arg, "crash") || !strcmp(arg, "SIGSEGV")) { return crash(42); } else if (!strcasecmp(arg, "abort")) { maybe_abort(); } else if (!strcasecmp(arg, "assert")) { __assert("some_file.c", 123, "false"); } else if (!strcasecmp(arg, "assert2")) { __assert2("some_file.c", 123, "some_function", "false"); } else if (!strcasecmp(arg, "fortify")) { char buf[10]; __read_chk(-1, buf, 32, 10); while (true) pause(); } else if (!strcasecmp(arg, "LOG(FATAL)")) { LOG(FATAL) << "hello " << 123; } else if (!strcasecmp(arg, "LOG_ALWAYS_FATAL")) { LOG_ALWAYS_FATAL("hello %s", "world"); } else if (!strcasecmp(arg, "LOG_ALWAYS_FATAL_IF")) { LOG_ALWAYS_FATAL_IF(true, "hello %s", "world"); } else if (!strcasecmp(arg, "SIGFPE")) { raise(SIGFPE); return EXIT_SUCCESS; } else if (!strcasecmp(arg, "SIGTRAP")) { raise(SIGTRAP); return EXIT_SUCCESS; } else if (!strcasecmp(arg, "fprintf-NULL")) { fprintf_null(); } else if (!strcasecmp(arg, "readdir-NULL")) { readdir_null(); } else if (!strcasecmp(arg, "strlen-NULL")) { return strlen_null(); } else if (!strcasecmp(arg, "pthread_join-NULL")) { return pthread_join(0, nullptr); } else if (!strcasecmp(arg, "heap-usage")) { abuse_heap(); } else if (!strcasecmp(arg, "leak")) { leak(); } else if (!strcasecmp(arg, "SIGSEGV-unmapped")) { char* map = reinterpret_cast<char*>(mmap(nullptr, sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0)); munmap(map, sizeof(int)); map[0] = '8'; } else if (!strcasecmp(arg, "seccomp")) { set_seccomp_filter(); syscall(99999); #if defined(__arm__) } else if (!strcasecmp(arg, "kuser_helper_version")) { return __kuser_helper_version; } else if (!strcasecmp(arg, "kuser_get_tls")) { return !__kuser_get_tls(); } else if (!strcasecmp(arg, "kuser_cmpxchg")) { return __kuser_cmpxchg(0, 0, 0); } else if (!strcasecmp(arg, "kuser_memory_barrier")) { __kuser_dmb(); } else if (!strcasecmp(arg, "kuser_cmpxchg64")) { return __kuser_cmpxchg64(0, 0, 0); #endif } else if (!strcasecmp(arg, "no_new_privs")) { if (prctl(PR_SET_NO_NEW_PRIVS, 1) != 0) { fprintf(stderr, "prctl(PR_SET_NO_NEW_PRIVS, 1) failed: %s\n", strerror(errno)); return EXIT_SUCCESS; } abort(); } else { return usage(); } fprintf(stderr, "%s: exiting normally!\n", getprogname()); return EXIT_SUCCESS; }
int main() { leak(t()); }