other-licenses/android/list.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 /*	$NetBSD: list.h,v 1.2 2004/05/20 19:51:55 christos Exp $	*/
     3 /*
     4  * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
     5  * Copyright (c) 1997,1999 by Internet Software Consortium.
     6  *
     7  * Permission to use, copy, modify, and distribute this software for any
     8  * purpose with or without fee is hereby granted, provided that the above
     9  * copyright notice and this permission notice appear in all copies.
    10  *
    11  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
    12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
    13  * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR
    14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
    15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
    16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
    17  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
    18  */
    20 /*
    21  * This version of this file is derived from Android 2.3 "Gingerbread",
    22  * which contains uncredited changes by Android/Google developers.  It has
    23  * been modified in 2011 for use in the Android build of Mozilla Firefox by
    24  * Mozilla contributors (including Michael Edwards <m.k.edwards@gmail.com>,
    25  * and Steve Workman <sjhworkman@gmail.com>).
    26  * These changes are offered under the same license as the original NetBSD
    27  * file, whose copyright and license are unchanged above.
    28  */
    30 #ifndef LIST_H
    31 #define LIST_H 1
    32 #include "assertions.h"
    34 #define LIST(type) struct { type *head, *tail; }
    35 #define INIT_LIST(list) \
    36 	do { (list).head = NULL; (list).tail = NULL; } while (/*CONSTCOND*/0)
    38 #define LINK(type) struct { type *prev, *next; }
    39 #define INIT_LINK_TYPE(elt, link, type) \
    40 	do { \
    41 		(elt)->link.prev = (type *)(-1); \
    42 		(elt)->link.next = (type *)(-1); \
    43 	} while (/*CONSTCOND*/0)
    44 #define INIT_LINK(elt, link) \
    45 	INIT_LINK_TYPE(elt, link, void)
    46 #define LINKED(elt, link) ((void *)((elt)->link.prev) != (void *)(-1))
    48 #define HEAD(list) ((list).head)
    49 #define TAIL(list) ((list).tail)
    50 #define EMPTY(list) ((list).head == NULL)
    52 #define PREPEND(list, elt, link) \
    53 	do { \
    54 		INSIST(!LINKED(elt, link));\
    55 		if ((list).head != NULL) \
    56 			(list).head->link.prev = (elt); \
    57 		else \
    58 			(list).tail = (elt); \
    59 		(elt)->link.prev = NULL; \
    60 		(elt)->link.next = (list).head; \
    61 		(list).head = (elt); \
    62 	} while (/*CONSTCOND*/0)
    64 #define APPEND(list, elt, link) \
    65 	do { \
    66 		INSIST(!LINKED(elt, link));\
    67 		if ((list).tail != NULL) \
    68 			(list).tail->link.next = (elt); \
    69 		else \
    70 			(list).head = (elt); \
    71 		(elt)->link.prev = (list).tail; \
    72 		(elt)->link.next = NULL; \
    73 		(list).tail = (elt); \
    74 	} while (/*CONSTCOND*/0)
    76 #define UNLINK_TYPE(list, elt, link, type) \
    77 	do { \
    78 		INSIST(LINKED(elt, link));\
    79 		if ((elt)->link.next != NULL) \
    80 			(elt)->link.next->link.prev = (elt)->link.prev; \
    81 		else \
    82 			(list).tail = (elt)->link.prev; \
    83 		if ((elt)->link.prev != NULL) \
    84 			(elt)->link.prev->link.next = (elt)->link.next; \
    85 		else \
    86 			(list).head = (elt)->link.next; \
    87 		INIT_LINK_TYPE(elt, link, type); \
    88 	} while (/*CONSTCOND*/0)
    89 #define UNLINK(list, elt, link) \
    90 	UNLINK_TYPE(list, elt, link, void)
    92 #define PREV(elt, link) ((elt)->link.prev)
    93 #define NEXT(elt, link) ((elt)->link.next)
    95 #define INSERT_BEFORE(list, before, elt, link) \
    96 	do { \
    97 		INSIST(!LINKED(elt, link));\
    98 		if ((before)->link.prev == NULL) \
    99 			PREPEND(list, elt, link); \
   100 		else { \
   101 			(elt)->link.prev = (before)->link.prev; \
   102 			(before)->link.prev = (elt); \
   103 			(elt)->link.prev->link.next = (elt); \
   104 			(elt)->link.next = (before); \
   105 		} \
   106 	} while (/*CONSTCOND*/0)
   108 #define INSERT_AFTER(list, after, elt, link) \
   109 	do { \
   110 		INSIST(!LINKED(elt, link));\
   111 		if ((after)->link.next == NULL) \
   112 			APPEND(list, elt, link); \
   113 		else { \
   114 			(elt)->link.next = (after)->link.next; \
   115 			(after)->link.next = (elt); \
   116 			(elt)->link.next->link.prev = (elt); \
   117 			(elt)->link.prev = (after); \
   118 		} \
   119 	} while (/*CONSTCOND*/0)
   121 #define ENQUEUE(list, elt, link) APPEND(list, elt, link)
   122 #define DEQUEUE(list, elt, link) UNLINK(list, elt, link)
   124 #endif /* LIST_H */

mercurial