Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(269)

Side by Side Diff: experimental/webtry/main.cpp

Issue 228693002: Initial code for webtry, a web application for allowing users to try out Skia. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: More cleanup Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 #include <sys/time.h>
2 #include <sys/resource.h>
3
4 #include "SkCanvas.h"
5 #include "SkCommandLineFlags.h"
6 #include "SkData.h"
7 #include "SkForceLinking.h"
8 #include "SkGraphics.h"
9 #include "SkImageEncoder.h"
10 #include "SkImageInfo.h"
11 #include "SkStream.h"
12 #include "SkSurface.h"
13
14 #include "seccomp_bpf.h"
15 #include "syscall_reporter.h"
16
17 DEFINE_string(out, "", "Filename of the PNG to write to.");
18 DEFINE_bool(logSyscall, false, "Dump the name of the blocked syscall that was at tempted. Use only for debugging.");
19
20 static int installSyscallFilter(void) {
mtklein 2014/04/08 19:00:23 Usually static methods are named_like_this
jcgregorio 2014/04/09 14:10:31 Done.
21 struct sock_filter filter[] = {
22 /* Validate architecture. */
23 VALIDATE_ARCHITECTURE,
24 /* Grab the system call number. */
25 EXAMINE_SYSCALL,
26 /* List allowed syscalls. */
27 ALLOW_SYSCALL(exit_group),
28 ALLOW_SYSCALL(exit),
29 ALLOW_SYSCALL(fstat),
30 ALLOW_SYSCALL(read),
31 ALLOW_SYSCALL(write),
32 ALLOW_SYSCALL(close),
33 ALLOW_SYSCALL(mmap),
34 ALLOW_SYSCALL(munmap),
35 ALLOW_SYSCALL(brk),
36 KILL_PROCESS,
37 };
38 struct sock_fprog prog = {
39 (unsigned short)(sizeof(filter)/sizeof(filter[0])),
mtklein 2014/04/08 19:00:23 SK_ARRAY_COUNT?
jcgregorio 2014/04/09 14:10:31 Done.
40 filter,
41 };
42
43 if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0)) {
mtklein 2014/04/08 19:00:23 This function could use a bit of comment narration
jcgregorio 2014/04/09 14:10:31 Done.
44 perror("prctl(NO_NEW_PRIVS)");
45 goto failed;
46 }
47 if (prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog)) {
48 perror("prctl(SECCOMP)");
49 goto failed;
50 }
51 return 0;
52
53 failed:
54 if (errno == EINVAL)
55 fprintf(stderr, "SECCOMP_FILTER is not available. :(\n");
56 return 1;
57 }
58
59 void setLimits() {
mtklein 2014/04/08 19:00:23 static void set_limits?
jcgregorio 2014/04/09 14:10:31 Done.
60 struct rlimit n;
61
62 // Limit to 5 seconds of CPU.
63 n.rlim_cur = 5;
64 n.rlim_max = 5;
65 if (setrlimit(RLIMIT_CPU, &n)) {
66 perror("setrlimit(RLIMIT_CPU)");
67 }
68
69 // Limit to 50M of Address space.
70 n.rlim_cur = 50000000;
71 n.rlim_max = 50000000;
72 if (setrlimit(RLIMIT_AS, &n)) {
73 perror("setrlimit(RLIMIT_CPU)");
74 }
75 }
76
77 void draw(SkCanvas* canvas);
mtklein 2014/04/08 19:00:23 Can't hurt to remind us that this comes from outsi
jcgregorio 2014/04/09 14:10:31 Done.
78
79 int main(int argc, char** argv) {
80 SkCommandLineFlags::Parse(argc, argv);
81 SkForceLinking(false);
mtklein 2014/04/08 19:00:23 Typically I use the __SK_FORCE_IMAGE_DECODER_LINKI
jcgregorio 2014/04/09 14:10:31 Done.
82 SkAutoGraphics init;
83
84 SkFILEWStream stream(FLAGS_out[0]);
mtklein 2014/04/08 19:00:23 Bail if FLAGS_out.count() == 0?
jcgregorio 2014/04/09 14:10:31 Done.
85
86 SkImageInfo info = SkImageInfo::MakeN32(300, 300, kPremul_SkAlphaType);
87 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info));
88 SkCanvas* canvas = surface->getCanvas();
89
90 setLimits();
91
92 if (FLAGS_logSyscall && install_syscall_reporter()) {
mtklein 2014/04/08 19:00:23 Ordinarily I'd prefer true, false over 0, 1. I gu
jcgregorio 2014/04/09 14:10:31 Done.
93 return 1;
94 }
95 if (installSyscallFilter()) {
96 return 1;
97 }
98
99 draw(canvas);
100
101 // Write out the image as a PNG.
102 SkAutoTUnref<SkImage> image(surface->newImageSnapshot());
mtklein 2014/04/08 19:00:23 I know it's sort of notional, but I can't help but
jcgregorio 2014/04/09 14:10:31 Yeah, I'm torn between making the code look exactl
103 SkAutoTUnref<SkData> data(image->encode(SkImageEncoder::kPNG_Type, 100));
104 if (NULL == data.get()) {
105 printf("Failed to encode\n");
106 exit(1);
107 }
108 stream.write(data->data(), data->size());
109 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698