Thu, 15 Jan 2015 15:59:08 +0100
Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
michael@0 | 2 | * |
michael@0 | 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | #include <stdio.h> |
michael@0 | 7 | #include <stdlib.h> |
michael@0 | 8 | #include <string.h> |
michael@0 | 9 | #include <errno.h> |
michael@0 | 10 | #ifdef HAVE_GETOPT_H |
michael@0 | 11 | #include <getopt.h> |
michael@0 | 12 | #else |
michael@0 | 13 | extern int getopt(int argc, char *const *argv, const char *shortopts); |
michael@0 | 14 | extern char *optarg; |
michael@0 | 15 | extern int optind; |
michael@0 | 16 | #ifdef XP_WIN32 |
michael@0 | 17 | int optind=1; |
michael@0 | 18 | #endif |
michael@0 | 19 | #endif |
michael@0 | 20 | #include <time.h> |
michael@0 | 21 | #include "nsTraceMalloc.h" |
michael@0 | 22 | #include "tmreader.h" |
michael@0 | 23 | |
michael@0 | 24 | static char *program; |
michael@0 | 25 | |
michael@0 | 26 | static void my_tmevent_handler(tmreader *tmr, tmevent *event) |
michael@0 | 27 | { |
michael@0 | 28 | tmcallsite *callsite; |
michael@0 | 29 | |
michael@0 | 30 | switch (event->type) { |
michael@0 | 31 | case TM_EVENT_REALLOC: |
michael@0 | 32 | case TM_EVENT_MALLOC: |
michael@0 | 33 | case TM_EVENT_CALLOC: |
michael@0 | 34 | for (callsite = tmreader_callsite(tmr, event->serial); |
michael@0 | 35 | callsite != &tmr->calltree_root; callsite = callsite->parent) { |
michael@0 | 36 | fprintf(stdout, "%s +%08X (%s:%d)\n", |
michael@0 | 37 | (const char*)callsite->method->graphnode.entry.value, |
michael@0 | 38 | callsite->offset, |
michael@0 | 39 | callsite->method->sourcefile, |
michael@0 | 40 | callsite->method->linenumber); |
michael@0 | 41 | } |
michael@0 | 42 | fprintf(stdout, "\n"); |
michael@0 | 43 | } |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | int main(int argc, char **argv) |
michael@0 | 47 | { |
michael@0 | 48 | int i, j, rv; |
michael@0 | 49 | tmreader *tmr; |
michael@0 | 50 | FILE *fp; |
michael@0 | 51 | time_t start; |
michael@0 | 52 | |
michael@0 | 53 | program = *argv; |
michael@0 | 54 | |
michael@0 | 55 | tmr = tmreader_new(program, NULL); |
michael@0 | 56 | if (!tmr) { |
michael@0 | 57 | perror(program); |
michael@0 | 58 | exit(1); |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | start = time(NULL); |
michael@0 | 62 | fprintf(stdout, "%s starting at %s", program, ctime(&start)); |
michael@0 | 63 | fflush(stdout); |
michael@0 | 64 | |
michael@0 | 65 | argc -= optind; |
michael@0 | 66 | argv += optind; |
michael@0 | 67 | if (argc == 0) { |
michael@0 | 68 | if (tmreader_eventloop(tmr, "-", my_tmevent_handler) <= 0) |
michael@0 | 69 | exit(1); |
michael@0 | 70 | } else { |
michael@0 | 71 | for (i = j = 0; i < argc; i++) { |
michael@0 | 72 | fp = fopen(argv[i], "r"); |
michael@0 | 73 | if (!fp) { |
michael@0 | 74 | fprintf(stderr, "%s: can't open %s: %s\n", |
michael@0 | 75 | program, argv[i], strerror(errno)); |
michael@0 | 76 | exit(1); |
michael@0 | 77 | } |
michael@0 | 78 | rv = tmreader_eventloop(tmr, argv[i], my_tmevent_handler); |
michael@0 | 79 | if (rv < 0) |
michael@0 | 80 | exit(1); |
michael@0 | 81 | if (rv > 0) |
michael@0 | 82 | j++; |
michael@0 | 83 | fclose(fp); |
michael@0 | 84 | } |
michael@0 | 85 | if (j == 0) |
michael@0 | 86 | exit(1); |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | tmreader_destroy(tmr); |
michael@0 | 90 | |
michael@0 | 91 | exit(0); |
michael@0 | 92 | } |