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.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 /**
6 * @section intro_sec Introduction
7 * CPR is an OS-abstraction layer which provides the functionality set of an OS
8 * while hiding all the operational details from the applications. CPR also
9 * provides additional functionality when certain operating-systems prove
10 * deficient providing a consistent set of functionality for the applications
11 * to use. The pSipCC library uses the CPR routines to achieve portablity. It
12 * is the responsibility of any vendor requiring to port pSipCC into their
13 * platforms to have the correct implementation of the CPR layer.
14 *
15 * The CPR delivery includes two "archives/binary" for memory and string
16 * related operations. These binaries contain functions that the pSIPCC uses
17 * for it's functionality. The header files that contain the external functions
18 * (APIs) from these binaries are also distributed.
19 *
20 * @section sub_sec Functionality
21 * CPR consists of a number of functional subsystems to achieve OS abstraction. The main
22 * functionality provided by CPR to the pSIPCC library are
23 * @li Memory Management - Provided as a binary that needs to be linked into CPR
24 * @li Timers
25 * @li Inter Process Communication - Sockets, Message Queues, Mutex, Semaphores
26 * @li String Handling - Provided as a binary that needs to be linked into CPR
27 * @li Thread Abstraction
28 * @li Other Platform/OS Abstractions
29 * @li Debug/Logging Abstraction
30 *
31 * @section file_list EXTERNAL APIS
32 * The External APIs that need to be exposed by CPR to the pSIPCC application are
33 * defined in the following header files. The documentation within
34 * each header file lists the functions/macros that @b NEED to be defined for
35 * pSIPCC to work correctly. Example functions (and an implementation for
36 * Linux) is available for most functions defined in these headers. Look under
37 * the "Modules" tab to find the various subsystems and associated APIs and
38 * helper functions.
39 * @li cpr_debug.h
40 * @li cpr_errno.h
41 * @li cpr_in.h
42 * @li cpr_locks.h
43 * @li cpr_rand.h
44 * @li cpr_socket.h
45 * @li cpr_stdio.h
46 * @li cpr_threads.h
47 * @li cpr_timers.h
48 * @li cpr.h
49 * @li cpr_ipc.h
50 * @li cpr_stddef.h
51 * @li cpr_time.h
52 * @li cpr_types.h
53 *
54 * The function prototypes in these header files are implemented in the
55 * binaries related to memory and string functionality. The prototypes are
56 * given so that vendors can use these functions for implementation of other
57 * CPR parts.
58 * @li cpr_memory.h
59 * @li cpr_stdlib.h
60 * @li cpr_string.h
61 * @li cpr_strings.h
62 *
63 * @section standard_headers Standard Header Files
64 * The pSIPCC component expects some standard header files and associated
65 * functionality to be present in the native operating system of the vendors
66 * porting it. These header files contain some basic functionality that pSIPCC
67 * uses for proper operation. A list of the standard headers (from a standard
68 * Linux distribution) are -
69 * @li <assert.h>
70 * @li <errno.h>
71 * @li <arpa/inet.h>
72 * @li <netinet/in.h>
73 * @li <netinet/tcp.h>
74 * @li <pthread.h>
75 * @li <sys/socket.h>
76 * @li <sys/select.h>
77 * @li <sys/un.h>
78 * @li <unistd.h>
79 * @li <stdarg.h>
80 * @li <stdio.h>
81 * @li <stdlib.h>
82 * @li <string.h>
83 * @li <ctype.h>
84 * @li <strings.h>
85 * @li <time.h>
86 *
87 *
88 * @section Comp Compiling CPR
89 * A sample makefile is also provided with the Linux distribution. Running
90 * "make" generates a CPR executable called "cprtest". This sample makefile can
91 * be modified to generate a shared library if required. Modify the CC, STDINC,
92 * STDLIB paths to point to the correct compiler and header files in the
93 * environment where this is being built.
94 * @note The README file shows the exact commands required to build/test the CPR
95 * functionality.
96 *
97 * @file cpr_linux_init.c
98 * @brief This file contains CPR initialization routines
99 *
100 * DESCRIPTION
101 * Initialization routine for the Cisco Portable Runtime layer
102 * running in the Linux operating System.
103 */
105 /**
106 * @addtogroup Initialization The initialization module
107 * @ingroup CPR
108 * @brief The intialization module consists of APIs used to initialize or destroy the CPR layer by pSipCC
109 *
110 * @{
111 */
112 #include "cpr.h"
113 #include "cpr_stdlib.h"
114 #include "cpr_stdio.h"
115 #include "cpr_timers.h"
116 #include "cpr_android_timers.h"
117 #include "plat_api.h"
118 #include <errno.h>
119 #ifndef ANDROID
120 #include <sys/msg.h>
121 #include <sys/ipc.h>
122 #endif
123 #include "plat_debug.h"
125 /**
126 * Mutex to manage message queue list.
127 */
128 extern pthread_mutex_t msgQueueListMutex;
130 /**
131 * Boolean to check that cprPreInit been called
132 */
133 static boolean pre_init_called = FALSE;
135 /**
136 * cprInfo prints out informational messages that are
137 * not necessarily errors, but maybe of interest to
138 * someone debugging a problem. Examples of this are
139 * requesting a msg from a msg queue that is empty,
140 * stopping a timer that is not running, etc...
141 */
142 int32_t cprInfo = TRUE;
145 /**
146 * cprPreInit
147 *
148 * @brief The cprPreInit function IS called from pSIPCC @b before any components are initialized.
149 *
150 * This function @b SHOULD initialize those portions of the CPR that
151 * are needed before applications can start using it. The memory subsystem
152 * (sandbox) is initialized from this routine.
153 *
154 *
155 * @return CPR_SUCCESS or CPR_FAILURE
156 * @note pSIPCC will NOT continue and stop initialization if the return value is CPR_FAILURE.
157 */
158 cprRC_t
159 cprPreInit (void)
160 {
161 static const char fname[] = "cprPreInit";
162 int32_t returnCode;
164 /*
165 * Make function reentreant
166 */
167 if (pre_init_called == TRUE) {
168 return CPR_SUCCESS;
169 }
170 pre_init_called = TRUE;
171 /*
172 * Create message queue list mutex
173 */
174 returnCode = pthread_mutex_init(&msgQueueListMutex, NULL);
175 if (returnCode != 0) {
176 CPR_ERROR("%s: MsgQueue Mutex init failure %d\n", fname, returnCode);
177 return CPR_FAILURE;
178 }
179 #ifdef CPR_TIMERS_ENABLED
180 returnCode = cpr_timer_pre_init();
181 if (returnCode != 0) {
182 CPR_ERROR("%s: timer pre init failed %d\n", fname, returnCode);
183 return CPR_FAILURE;
184 }
185 #endif
186 return CPR_SUCCESS;
187 }
190 /**
191 * cprPostInit
192 *
193 * @brief The cprPostInit function IS called from pSIPCC @b after all the components are initialized.
194 *
195 * This function @b SHOULD complete any CPR activities before the phone is
196 * operational. In other words a call to this function will be the last line of
197 * the phone initializtion routine from pSIPCC. This function implementation
198 * ties in a couple of debug commands to get more information on the CPR from
199 * the shell.
200 *
201 *
202 * @return CPR_SUCCESS or CPR_FAILURE
203 * @note pSIPCC will NOT continue and stop initialization if the return value is CPR_FAILURE.
204 */
205 cprRC_t
206 cprPostInit (void)
207 {
208 /* if (cpr_memory_mgmt_post_init() not_eq TRUE) {
209 return CPR_FAILURE;
210 }
211 */
212 return CPR_SUCCESS;
213 }