~ubuntu-branches/ubuntu/quantal/nspr/quantal-security

« back to all changes in this revision

Viewing changes to mozilla/nsprpub/pr/src/md/unix/ncr.c

  • Committer: Package Import Robot
  • Author(s): Jamie Strandboge
  • Date: 2013-01-10 10:56:12 UTC
  • mfrom: (1.3.4)
  • Revision ID: package-import@ubuntu.com-20130110105612-zo087hhaexilklvu
Tags: 4.9.4-0ubuntu0.12.10.1
* New upstream release to support security fixes in nss. Dropped the
  following patches:
  - debian/patches/30_pkgconfig.patch (included upstream)
  - debian/patches/38_hurd.patch (included upstream)
  - debian/patches/99_configure.patch (no longer required)
  - debian/patches/sonames.patch (no longer required)
* debian/libnsp4.symbols: added PR_GetThreadName@Base and
  PR_SetCurrentThreadName@Base

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
 
/* ***** BEGIN LICENSE BLOCK *****
3
 
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4
 
 *
5
 
 * The contents of this file are subject to the Mozilla Public License Version
6
 
 * 1.1 (the "License"); you may not use this file except in compliance with
7
 
 * the License. You may obtain a copy of the License at
8
 
 * http://www.mozilla.org/MPL/
9
 
 *
10
 
 * Software distributed under the License is distributed on an "AS IS" basis,
11
 
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
 
 * for the specific language governing rights and limitations under the
13
 
 * License.
14
 
 *
15
 
 * The Original Code is the Netscape Portable Runtime (NSPR).
16
 
 *
17
 
 * The Initial Developer of the Original Code is
18
 
 * Netscape Communications Corporation.
19
 
 * Portions created by the Initial Developer are Copyright (C) 1998-2000
20
 
 * the Initial Developer. All Rights Reserved.
21
 
 *
22
 
 * Contributor(s):
23
 
 *
24
 
 * Alternatively, the contents of this file may be used under the terms of
25
 
 * either the GNU General Public License Version 2 or later (the "GPL"), or
26
 
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27
 
 * in which case the provisions of the GPL or the LGPL are applicable instead
28
 
 * of those above. If you wish to allow use of your version of this file only
29
 
 * under the terms of either the GPL or the LGPL, and not to allow others to
30
 
 * use your version of this file under the terms of the MPL, indicate your
31
 
 * decision by deleting the provisions above and replace them with the notice
32
 
 * and other provisions required by the GPL or the LGPL. If you do not delete
33
 
 * the provisions above, a recipient may use your version of this file under
34
 
 * the terms of any one of the MPL, the GPL or the LGPL.
35
 
 *
36
 
 * ***** END LICENSE BLOCK ***** */
37
 
 
38
 
/*
39
 
 * NCR 3.0  - cloned from UnixWare by ruslan
40
 
 */
41
 
#include "primpl.h"
42
 
 
43
 
#include <setjmp.h>
44
 
 
45
 
void _MD_EarlyInit(void)
46
 
{
47
 
}
48
 
 
49
 
PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
50
 
{
51
 
    if (isCurrent) {
52
 
        (void) setjmp(CONTEXT(t));
53
 
    }
54
 
    *np = sizeof(CONTEXT(t)) / sizeof(PRWord);
55
 
    return (PRWord *) CONTEXT(t);
56
 
}
57
 
 
58
 
#ifdef ALARMS_BREAK_TCP /* I don't think they do */
59
 
 
60
 
PRInt32 _MD_connect(PRInt32 osfd, const PRNetAddr *addr, PRInt32 addrlen,
61
 
                        PRIntervalTime timeout)
62
 
{
63
 
    PRInt32 rv;
64
 
 
65
 
    _MD_BLOCK_CLOCK_INTERRUPTS();
66
 
    rv = _connect(osfd,addr,addrlen);
67
 
    _MD_UNBLOCK_CLOCK_INTERRUPTS();
68
 
}
69
 
 
70
 
PRInt32 _MD_accept(PRInt32 osfd, PRNetAddr *addr, PRInt32 addrlen,
71
 
                        PRIntervalTime timeout)
72
 
{
73
 
    PRInt32 rv;
74
 
 
75
 
    _MD_BLOCK_CLOCK_INTERRUPTS();
76
 
    rv = _accept(osfd,addr,addrlen);
77
 
    _MD_UNBLOCK_CLOCK_INTERRUPTS();
78
 
    return(rv);
79
 
}
80
 
#endif
81
 
 
82
 
/*
83
 
 * These are also implemented in pratom.c using NSPR locks.  Any reason
84
 
 * this might be better or worse?  If you like this better, define
85
 
 * _PR_HAVE_ATOMIC_OPS in include/md/unixware.h
86
 
 */
87
 
#ifdef _PR_HAVE_ATOMIC_OPS
88
 
/* Atomic operations */
89
 
#include  <stdio.h>
90
 
static FILE *_uw_semf;
91
 
 
92
 
void
93
 
_MD_INIT_ATOMIC(void)
94
 
{
95
 
    /* Sigh.  Sure wish SYSV semaphores weren't such a pain to use */
96
 
    if ((_uw_semf = tmpfile()) == NULL)
97
 
        PR_ASSERT(0);
98
 
 
99
 
    return;
100
 
}
101
 
 
102
 
void
103
 
_MD_ATOMIC_INCREMENT(PRInt32 *val)
104
 
{
105
 
    flockfile(_uw_semf);
106
 
    (*val)++;
107
 
    unflockfile(_uw_semf);
108
 
}
109
 
 
110
 
void
111
 
_MD_ATOMIC_ADD(PRInt32 *ptr, PRInt32 val)
112
 
{
113
 
    flockfile(_uw_semf);
114
 
    (*ptr) += val;
115
 
    unflockfile(_uw_semf);
116
 
}
117
 
 
118
 
 
119
 
void
120
 
_MD_ATOMIC_DECREMENT(PRInt32 *val)
121
 
{
122
 
    flockfile(_uw_semf);
123
 
    (*val)--;
124
 
    unflockfile(_uw_semf);
125
 
}
126
 
 
127
 
void
128
 
_MD_ATOMIC_SET(PRInt32 *val, PRInt32 newval)
129
 
{
130
 
    flockfile(_uw_semf);
131
 
    *val = newval;
132
 
    unflockfile(_uw_semf);
133
 
}
134
 
#endif
135
 
 
136
 
void
137
 
_MD_SET_PRIORITY(_MDThread *thread, PRUintn newPri)
138
 
{
139
 
    return;
140
 
}
141
 
 
142
 
PRStatus
143
 
_MD_InitializeThread(PRThread *thread)
144
 
{
145
 
        return PR_SUCCESS;
146
 
}
147
 
 
148
 
PRStatus
149
 
_MD_WAIT(PRThread *thread, PRIntervalTime ticks)
150
 
{
151
 
    PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
152
 
    _PR_MD_SWITCH_CONTEXT(thread);
153
 
    return PR_SUCCESS;
154
 
}
155
 
 
156
 
PRStatus
157
 
_MD_WAKEUP_WAITER(PRThread *thread)
158
 
{
159
 
    if (thread) {
160
 
        PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
161
 
    }
162
 
    return PR_SUCCESS;
163
 
}
164
 
 
165
 
/* These functions should not be called for Unixware */
166
 
void
167
 
_MD_YIELD(void)
168
 
{
169
 
    PR_NOT_REACHED("_MD_YIELD should not be called for Unixware.");
170
 
}
171
 
 
172
 
PRStatus
173
 
_MD_CREATE_THREAD(
174
 
    PRThread *thread,
175
 
    void (*start) (void *),
176
 
    PRUintn priority,
177
 
    PRThreadScope scope,
178
 
    PRThreadState state,
179
 
    PRUint32 stackSize)
180
 
{
181
 
    PR_NOT_REACHED("_MD_CREATE_THREAD should not be called for Unixware.");
182
 
    return PR_FAILURE;
183
 
}
184
 
 
185
 
/*
186
 
 This is temp. replacement for localtime_r. Normally PR_ExplodeTime should
187
 
 be used as to my understanding
188
 
*/
189
 
 
190
 
/*
191
 
** $$$$$ THEN WHY ARE WE DOING THIS? - AOF $$$$$
192
 
*/
193
 
 
194
 
#define NEED_LOCALTIME_R
195
 
#define NEED_GMTIME_R
196
 
#define NEED_ASCTIME_R
197
 
#define NEED_STRTOK_R
198
 
#define NEED_CTIME_R
199
 
 
200
 
#if defined (NEED_LOCALTIME_R) || defined (NEED_CTIME_R) || defined (NEED_ASCTIME_R) || defined (NEED_GMTIME_R) || defined (NEED_STRTOK_R)
201
 
#include "prlock.h"
202
 
#endif
203
 
 
204
 
#if defined (NEED_LOCALTIME_R)
205
 
 
206
 
static PRLock *localtime_r_monitor = NULL;
207
 
 
208
 
struct tm *localtime_r (const time_t *clock, struct tm *result)
209
 
{
210
 
    struct tm *tmPtr;
211
 
    int needLock = PR_Initialized();  /* We need to use a lock to protect
212
 
                                       * against NSPR threads only when the
213
 
                                       * NSPR thread system is activated. */
214
 
 
215
 
    if (needLock) {
216
 
        if (localtime_r_monitor == NULL) {
217
 
 
218
 
            localtime_r_monitor = PR_NewLock();
219
 
        }
220
 
        PR_Lock(localtime_r_monitor);
221
 
    }
222
 
 
223
 
    /*
224
 
     * On Windows, localtime() returns a NULL pointer if 'clock'
225
 
     * represents a time before midnight January 1, 1970.  In
226
 
     * that case, we also return a NULL pointer and the struct tm
227
 
     * object pointed to by 'result' is not modified.
228
 
     */
229
 
 
230
 
    tmPtr = localtime(clock);
231
 
    if (tmPtr) {
232
 
        *result = *tmPtr;
233
 
    } else {
234
 
        result = NULL;
235
 
    }
236
 
 
237
 
    if (needLock) PR_Unlock(localtime_r_monitor);
238
 
 
239
 
    return result;
240
 
}
241
 
 
242
 
#endif
243
 
 
244
 
#if defined (NEED_GMTIME_R)
245
 
 
246
 
static PRLock *gmtime_r_monitor = NULL;
247
 
 
248
 
struct tm *gmtime_r (const time_t *clock, struct tm *result)
249
 
{
250
 
    struct tm *tmPtr;
251
 
    int needLock = PR_Initialized();  /* We need to use a lock to protect
252
 
                                       * against NSPR threads only when the
253
 
                                       * NSPR thread system is activated. */
254
 
 
255
 
    if (needLock) {
256
 
        if (gmtime_r_monitor == NULL) {
257
 
            gmtime_r_monitor = PR_NewLock();
258
 
        }
259
 
        PR_Lock(gmtime_r_monitor);
260
 
    }
261
 
 
262
 
    tmPtr = gmtime(clock);
263
 
    if (tmPtr) {
264
 
        *result = *tmPtr;
265
 
    } else {
266
 
        result = NULL;
267
 
    }
268
 
 
269
 
    if (needLock) PR_Unlock(gmtime_r_monitor);
270
 
 
271
 
    return result;
272
 
}
273
 
 
274
 
#endif
275
 
 
276
 
#if defined (NEED_CTIME_R)
277
 
 
278
 
static PRLock *ctime_r_monitor = NULL;
279
 
 
280
 
char  *ctime_r (const time_t *clock, char *buf, int buflen)
281
 
{
282
 
    char *cbuf;
283
 
    int needLock = PR_Initialized();  /* We need to use a lock to protect
284
 
                                       * against NSPR threads only when the
285
 
                                       * NSPR thread system is activated. */
286
 
 
287
 
    if (needLock) {
288
 
 
289
 
        if (ctime_r_monitor == NULL) {
290
 
            ctime_r_monitor = PR_NewLock();
291
 
        }
292
 
        PR_Lock(ctime_r_monitor);
293
 
    }
294
 
 
295
 
    cbuf = ctime (clock);
296
 
    if (cbuf) {
297
 
        strncpy (buf, cbuf, buflen - 1);
298
 
        buf[buflen - 1] = 0;
299
 
    }
300
 
 
301
 
    if (needLock) PR_Unlock(ctime_r_monitor);
302
 
 
303
 
    return cbuf;
304
 
}
305
 
 
306
 
#endif
307
 
 
308
 
#if defined (NEED_ASCTIME_R)
309
 
 
310
 
static PRLock *asctime_r_monitor = NULL;
311
 
 
312
 
 
313
 
char  *asctime_r (const struct tm  *tm, char *buf, int buflen)
314
 
{
315
 
    char *cbuf;
316
 
    int needLock = PR_Initialized();  /* We need to use a lock to protect
317
 
                                       * against NSPR threads only when the
318
 
                                       * NSPR thread system is activated. */
319
 
 
320
 
    if (needLock) {
321
 
        if (asctime_r_monitor == NULL) {
322
 
            asctime_r_monitor = PR_NewLock();
323
 
        }
324
 
        PR_Lock(asctime_r_monitor);
325
 
    }
326
 
 
327
 
    cbuf = asctime (tm);
328
 
    if (cbuf) {
329
 
        strncpy (buf, cbuf, buflen - 1);
330
 
        buf[buflen - 1] = 0;
331
 
    }
332
 
 
333
 
    if (needLock) PR_Unlock(asctime_r_monitor);
334
 
 
335
 
    return cbuf;
336
 
 
337
 
}
338
 
#endif
339
 
 
340
 
#if defined (NEED_STRTOK_R)
341
 
 
342
 
char *
343
 
strtok_r (s, delim, last)
344
 
        register char *s;
345
 
        register const char *delim;
346
 
        register char **last;
347
 
{
348
 
        register char *spanp;
349
 
        register int c, sc;
350
 
        char *tok;
351
 
 
352
 
 
353
 
        if (s == NULL && (s = *last) == NULL)
354
 
                return (NULL);
355
 
 
356
 
        /*
357
 
         * Skip (span) leading delimiters (s += strspn(s, delim), sort of).
358
 
         */
359
 
cont:
360
 
 
361
 
        c = *s++;
362
 
        for (spanp = (char *)delim; (sc = *spanp++) != 0;) {
363
 
                if (c == sc)
364
 
                        goto cont;
365
 
        }
366
 
 
367
 
        if (c == 0) {           /* no non-delimiter characters */
368
 
                *last = NULL;
369
 
                return (NULL);
370
 
        }
371
 
        tok = s - 1;
372
 
 
373
 
        /*
374
 
         * Scan token (scan for delimiters: s += strcspn(s, delim), sort of).
375
 
         * Note that delim must have one NUL; we stop if we see that, too.
376
 
         */
377
 
        for (;;) {
378
 
                c = *s++;
379
 
                spanp = (char *)delim;
380
 
                do {
381
 
                        if ((sc = *spanp++) == c) {
382
 
                                if (c == 0)
383
 
                                        s = NULL;
384
 
 
385
 
                                else
386
 
                                        s[-1] = 0;
387
 
                                *last = s;
388
 
                                return (tok);
389
 
                        }
390
 
                } while (sc != 0);
391
 
        }
392
 
        /* NOTREACHED */
393
 
}
394
 
 
395
 
#endif