netwerk/sctp/src/netinet/sctp_callout.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
-rwxr-xr-x

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.

michael@0 1 /*-
michael@0 2 * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved.
michael@0 3 * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
michael@0 4 * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
michael@0 5 *
michael@0 6 * Redistribution and use in source and binary forms, with or without
michael@0 7 * modification, are permitted provided that the following conditions
michael@0 8 * are met:
michael@0 9 * 1. Redistributions of source code must retain the above copyright
michael@0 10 * notice, this list of conditions and the following disclaimer.
michael@0 11 * 2. Redistributions in binary form must reproduce the above copyright
michael@0 12 * notice, this list of conditions and the following disclaimer in the
michael@0 13 * documentation and/or other materials provided with the distribution.
michael@0 14 * 3. Neither the name of the project nor the names of its contributors
michael@0 15 * may be used to endorse or promote products derived from this software
michael@0 16 * without specific prior written permission.
michael@0 17 *
michael@0 18 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
michael@0 19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
michael@0 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
michael@0 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
michael@0 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
michael@0 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
michael@0 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
michael@0 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
michael@0 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
michael@0 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
michael@0 28 * SUCH DAMAGE.
michael@0 29 */
michael@0 30
michael@0 31 #ifdef __FreeBSD__
michael@0 32 #include <sys/cdefs.h>
michael@0 33 __FBSDID("$FreeBSD$");
michael@0 34 #endif
michael@0 35
michael@0 36 #ifndef _NETINET_SCTP_CALLOUT_
michael@0 37 #define _NETINET_SCTP_CALLOUT_
michael@0 38
michael@0 39 /*
michael@0 40 * NOTE: the following MACROS are required for locking the callout
michael@0 41 * queue along with a lock/mutex in the OS specific headers and
michael@0 42 * implementation files::
michael@0 43 * - SCTP_TIMERQ_LOCK()
michael@0 44 * - SCTP_TIMERQ_UNLOCK()
michael@0 45 * - SCTP_TIMERQ_LOCK_INIT()
michael@0 46 * - SCTP_TIMERQ_LOCK_DESTROY()
michael@0 47 */
michael@0 48
michael@0 49 #define _SCTP_NEEDS_CALLOUT_ 1
michael@0 50
michael@0 51 #define SCTP_TICKS_PER_FASTTIMO 20 /* called about every 20ms */
michael@0 52
michael@0 53 #if defined(__Userspace__)
michael@0 54 #if defined(__Userspace_os_Windows)
michael@0 55 #define SCTP_TIMERQ_LOCK() EnterCriticalSection(&SCTP_BASE_VAR(timer_mtx))
michael@0 56 #define SCTP_TIMERQ_UNLOCK() LeaveCriticalSection(&SCTP_BASE_VAR(timer_mtx))
michael@0 57 #define SCTP_TIMERQ_LOCK_INIT() InitializeCriticalSection(&SCTP_BASE_VAR(timer_mtx))
michael@0 58 #define SCTP_TIMERQ_LOCK_DESTROY() DeleteCriticalSection(&SCTP_BASE_VAR(timer_mtx))
michael@0 59 #else
michael@0 60 #define SCTP_TIMERQ_LOCK() (void)pthread_mutex_lock(&SCTP_BASE_VAR(timer_mtx))
michael@0 61 #define SCTP_TIMERQ_UNLOCK() (void)pthread_mutex_unlock(&SCTP_BASE_VAR(timer_mtx))
michael@0 62 #define SCTP_TIMERQ_LOCK_INIT() (void)pthread_mutex_init(&SCTP_BASE_VAR(timer_mtx), NULL)
michael@0 63 #define SCTP_TIMERQ_LOCK_DESTROY() (void)pthread_mutex_destroy(&SCTP_BASE_VAR(timer_mtx))
michael@0 64 #endif
michael@0 65
michael@0 66 extern int ticks;
michael@0 67 #endif
michael@0 68
michael@0 69 TAILQ_HEAD(calloutlist, sctp_callout);
michael@0 70
michael@0 71 struct sctp_callout {
michael@0 72 TAILQ_ENTRY(sctp_callout) tqe;
michael@0 73 int c_time; /* ticks to the event */
michael@0 74 void *c_arg; /* function argument */
michael@0 75 void (*c_func)(void *); /* function to call */
michael@0 76 int c_flags; /* state of this entry */
michael@0 77 };
michael@0 78 typedef struct sctp_callout sctp_os_timer_t;
michael@0 79
michael@0 80 #define SCTP_CALLOUT_ACTIVE 0x0002 /* callout is currently active */
michael@0 81 #define SCTP_CALLOUT_PENDING 0x0004 /* callout is waiting for timeout */
michael@0 82
michael@0 83 void sctp_os_timer_init(sctp_os_timer_t *tmr);
michael@0 84 void sctp_os_timer_start(sctp_os_timer_t *, int, void (*)(void *), void *);
michael@0 85 int sctp_os_timer_stop(sctp_os_timer_t *);
michael@0 86
michael@0 87 #define SCTP_OS_TIMER_INIT sctp_os_timer_init
michael@0 88 #define SCTP_OS_TIMER_START sctp_os_timer_start
michael@0 89 #define SCTP_OS_TIMER_STOP sctp_os_timer_stop
michael@0 90 /* MT FIXME: Is the following correct? */
michael@0 91 #define SCTP_OS_TIMER_STOP_DRAIN SCTP_OS_TIMER_STOP
michael@0 92 #define SCTP_OS_TIMER_PENDING(tmr) ((tmr)->c_flags & SCTP_CALLOUT_PENDING)
michael@0 93 #define SCTP_OS_TIMER_ACTIVE(tmr) ((tmr)->c_flags & SCTP_CALLOUT_ACTIVE)
michael@0 94 #define SCTP_OS_TIMER_DEACTIVATE(tmr) ((tmr)->c_flags &= ~SCTP_CALLOUT_ACTIVE)
michael@0 95
michael@0 96 #if defined(__Userspace__)
michael@0 97 void sctp_start_timer(void);
michael@0 98 #endif
michael@0 99 #if defined(__APPLE__)
michael@0 100 void sctp_timeout(void *);
michael@0 101 #endif
michael@0 102
michael@0 103 #endif

mercurial