1baa3858d3f5d128a5c8466b700098109edcad5f2repo sync/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2baa3858d3f5d128a5c8466b700098109edcad5f2repo sync/*
3baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * The contents of this file are subject to the Mozilla Public
4baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * License Version 1.1 (the "License"); you may not use this file
5baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * except in compliance with the License. You may obtain a copy of
6baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * the License at http://www.mozilla.org/MPL/
7baa3858d3f5d128a5c8466b700098109edcad5f2repo sync *
8baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * Software distributed under the License is distributed on an "AS
9baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
10baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * implied. See the License for the specific language governing
11baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * rights and limitations under the License.
12baa3858d3f5d128a5c8466b700098109edcad5f2repo sync *
13baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * The Original Code is the Netscape Portable Runtime (NSPR).
14baa3858d3f5d128a5c8466b700098109edcad5f2repo sync *
15baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * The Initial Developer of the Original Code is Netscape
16baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * Communications Corporation.  Portions created by Netscape are
17baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * Copyright (C) 1998-2000 Netscape Communications Corporation.  All
18baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * Rights Reserved.
19baa3858d3f5d128a5c8466b700098109edcad5f2repo sync *
20baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * Contributor(s):
21baa3858d3f5d128a5c8466b700098109edcad5f2repo sync *
22baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * Alternatively, the contents of this file may be used under the
23baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * terms of the GNU General Public License Version 2 or later (the
24baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * "GPL"), in which case the provisions of the GPL are applicable
25baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * instead of those above.  If you wish to allow use of your
26baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * version of this file only under the terms of the GPL and not to
27baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * allow others to use your version of this file under the MPL,
28baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * indicate your decision by deleting the provisions above and
29baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * replace them with the notice and other provisions required by
30baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * the GPL.  If you do not delete the provisions above, a recipient
31baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * may use your version of this file under either the MPL or the
32baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * GPL.
33baa3858d3f5d128a5c8466b700098109edcad5f2repo sync */
34baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
35baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#ifndef prunixos_h___
36baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define prunixos_h___
37baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
38baa3858d3f5d128a5c8466b700098109edcad5f2repo sync/*
39baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * If FD_SETSIZE is not defined on the command line, set the default value
40baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * before include select.h
41baa3858d3f5d128a5c8466b700098109edcad5f2repo sync */
42baa3858d3f5d128a5c8466b700098109edcad5f2repo sync/*
43baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * Linux: FD_SETSIZE is defined in /usr/include/sys/select.h and should
44baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * not be redefined.
45baa3858d3f5d128a5c8466b700098109edcad5f2repo sync */
46baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#if !defined(LINUX) && !defined(DARWIN) && !defined(NEXTSTEP)
47baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#ifndef FD_SETSIZE
48baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define FD_SETSIZE  4096
49baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#endif
50baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#endif
51baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
52baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include <unistd.h>
53baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include <stddef.h>
54baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include <sys/stat.h>
55baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include <dirent.h>
56baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include <errno.h>
57baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
58baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "prio.h"
59baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "prmem.h"
60baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "prclist.h"
61baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
62baa3858d3f5d128a5c8466b700098109edcad5f2repo sync/*
63baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * For select(), fd_set, and struct timeval.
64baa3858d3f5d128a5c8466b700098109edcad5f2repo sync *
65baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * In The Single UNIX(R) Specification, Version 2,
66baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * the header file for select() is <sys/time.h>.
67baa3858d3f5d128a5c8466b700098109edcad5f2repo sync *
68baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * fd_set is defined in <sys/types.h>.  Usually
69baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * <sys/time.h> includes <sys/types.h>, but on some
70baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * older systems <sys/time.h> does not include
71baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * <sys/types.h>, so we include it explicitly.
72baa3858d3f5d128a5c8466b700098109edcad5f2repo sync */
73baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include <sys/time.h>
74baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include <sys/types.h>
75baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#if defined(AIX)  /* Only pre-4.2 AIX needs it, but for simplicity... */
76baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include <sys/select.h>
77baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#endif
78baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
79baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define PR_DIRECTORY_SEPARATOR		'/'
80baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define PR_DIRECTORY_SEPARATOR_STR	"/"
81baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define PR_PATH_SEPARATOR		':'
82baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define PR_PATH_SEPARATOR_STR		":"
83baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define GCPTR
84baa3858d3f5d128a5c8466b700098109edcad5f2repo synctypedef int (*FARPROC)();
85baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
86baa3858d3f5d128a5c8466b700098109edcad5f2repo sync/*
87baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * intervals at which GLOBAL threads wakeup to check for pending interrupt
88baa3858d3f5d128a5c8466b700098109edcad5f2repo sync */
89baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _PR_INTERRUPT_CHECK_INTERVAL_SECS 5
90baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRIntervalTime intr_timeout_ticks;
91baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
92baa3858d3f5d128a5c8466b700098109edcad5f2repo sync/*
93baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * The bit flags for the in_flags and out_flags fields
94baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * of _PR_UnixPollDesc
95baa3858d3f5d128a5c8466b700098109edcad5f2repo sync */
96baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#ifdef _PR_USE_POLL
97baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _PR_UNIX_POLL_READ    POLLIN
98baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _PR_UNIX_POLL_WRITE   POLLOUT
99baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _PR_UNIX_POLL_EXCEPT  POLLPRI
100baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _PR_UNIX_POLL_ERR     POLLERR
101baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _PR_UNIX_POLL_NVAL    POLLNVAL
102baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _PR_UNIX_POLL_HUP     POLLHUP
103baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#else /* _PR_USE_POLL */
104baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _PR_UNIX_POLL_READ    0x1
105baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _PR_UNIX_POLL_WRITE   0x2
106baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _PR_UNIX_POLL_EXCEPT  0x4
107baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _PR_UNIX_POLL_ERR     0x8
108baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _PR_UNIX_POLL_NVAL    0x10
109baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _PR_UNIX_POLL_HUP     0x20
110baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#endif /* _PR_USE_POLL */
111baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
112baa3858d3f5d128a5c8466b700098109edcad5f2repo synctypedef struct _PRUnixPollDesc {
113baa3858d3f5d128a5c8466b700098109edcad5f2repo sync	PRInt32 osfd;
114baa3858d3f5d128a5c8466b700098109edcad5f2repo sync	PRInt16 in_flags;
115baa3858d3f5d128a5c8466b700098109edcad5f2repo sync	PRInt16 out_flags;
116baa3858d3f5d128a5c8466b700098109edcad5f2repo sync} _PRUnixPollDesc;
117baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
118baa3858d3f5d128a5c8466b700098109edcad5f2repo synctypedef struct PRPollQueue {
119baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    PRCList links;        /* for linking PRPollQueue's together */
120baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    _PRUnixPollDesc *pds;        /* array of poll descriptors */
121baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    PRUintn npds;            /* length of the array */
122baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    PRPackedBool on_ioq;    /* is this on the async i/o work q? */
123baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    PRIntervalTime timeout;        /* timeout, in ticks */
124baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    struct PRThread *thr;
125baa3858d3f5d128a5c8466b700098109edcad5f2repo sync} PRPollQueue;
126baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
127baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _PR_POLLQUEUE_PTR(_qp) \
128baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    ((PRPollQueue*) ((char*) (_qp) - offsetof(PRPollQueue,links)))
129baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
130baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
131baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRInt32 _PR_WaitForMultipleFDs(
132baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    _PRUnixPollDesc *unixpds,
133baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    PRInt32 pdcnt,
134baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    PRIntervalTime timeout);
135baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern void _PR_Unblock_IO_Wait(struct PRThread *thr);
136baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
137baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#if defined(_PR_LOCAL_THREADS_ONLY) || defined(_PR_GLOBAL_THREADS_ONLY)
138baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_CHECK_FOR_EXIT()
139baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#endif
140baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
141baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern fd_set _pr_md_read_set, _pr_md_write_set, _pr_md_exception_set;
142baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRInt16 _pr_md_read_cnt[], _pr_md_write_cnt[], _pr_md_exception_cnt[];
143baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRInt32 _pr_md_ioq_max_osfd;
144baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRUint32 _pr_md_ioq_timeout;
145baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
146baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstruct _MDFileDesc {
147baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    int osfd;
148baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#if defined(LINUX) && defined(_PR_PTHREADS)
149baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    int tcp_nodelay;  /* used by pt_LinuxSendFile */
150baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#endif
151baa3858d3f5d128a5c8466b700098109edcad5f2repo sync};
152baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
153baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstruct _MDDir {
154baa3858d3f5d128a5c8466b700098109edcad5f2repo sync	DIR *d;
155baa3858d3f5d128a5c8466b700098109edcad5f2repo sync};
156baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
157baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstruct _PRCPU;
158baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern void _MD_unix_init_running_cpu(struct _PRCPU *cpu);
159baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
160baa3858d3f5d128a5c8466b700098109edcad5f2repo sync/*
161baa3858d3f5d128a5c8466b700098109edcad5f2repo sync** Make a redzone at both ends of the stack segment. Disallow access
162baa3858d3f5d128a5c8466b700098109edcad5f2repo sync** to those pages of memory. It's ok if the mprotect call's don't
163baa3858d3f5d128a5c8466b700098109edcad5f2repo sync** work - it just means that we don't really have a functional
164baa3858d3f5d128a5c8466b700098109edcad5f2repo sync** redzone.
165baa3858d3f5d128a5c8466b700098109edcad5f2repo sync*/
166baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include <sys/mman.h>
167baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#ifndef PROT_NONE
168baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define PROT_NONE 0x0
169baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#endif
170baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
171baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#if defined(DEBUG) && !defined(DARWIN) && !defined(NEXTSTEP)
172baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#if !defined(SOLARIS)
173baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include <string.h>  /* for memset() */
174baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_INIT_STACK(ts,REDZONE)					\
175baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    PR_BEGIN_MACRO                 					\
176baa3858d3f5d128a5c8466b700098109edcad5f2repo sync	(void) mprotect((void*)ts->seg->vaddr, REDZONE, PROT_NONE);	\
177baa3858d3f5d128a5c8466b700098109edcad5f2repo sync	(void) mprotect((void*) ((char*)ts->seg->vaddr + REDZONE + ts->stackSize),\
178baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			REDZONE, PROT_NONE);				\
179baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    /*									\
180baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    ** Fill stack memory with something that turns into an illegal	\
181baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    ** pointer value. This will sometimes find runtime references to	\
182baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    ** uninitialized pointers. We don't do this for solaris because we	\
183baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    ** can use purify instead.						\
184baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    */									\
185baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    if (_pr_debugStacks) {						\
186baa3858d3f5d128a5c8466b700098109edcad5f2repo sync	memset(ts->allocBase + REDZONE, 0xf7, ts->stackSize);		\
187baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    }									\
188baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    PR_END_MACRO
189baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#else	/* !SOLARIS	*/
190baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_INIT_STACK(ts,REDZONE)					\
191baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    PR_BEGIN_MACRO                 					\
192baa3858d3f5d128a5c8466b700098109edcad5f2repo sync	(void) mprotect((void*)ts->seg->vaddr, REDZONE, PROT_NONE);	\
193baa3858d3f5d128a5c8466b700098109edcad5f2repo sync	(void) mprotect((void*) ((char*)ts->seg->vaddr + REDZONE + ts->stackSize),\
194baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			REDZONE, PROT_NONE);				\
195baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    PR_END_MACRO
196baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#endif	/* !SOLARIS	*/
197baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
198baa3858d3f5d128a5c8466b700098109edcad5f2repo sync/*
199baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * _MD_CLEAR_STACK
200baa3858d3f5d128a5c8466b700098109edcad5f2repo sync *	Allow access to the redzone pages; the access was turned off in
201baa3858d3f5d128a5c8466b700098109edcad5f2repo sync *	_MD_INIT_STACK.
202baa3858d3f5d128a5c8466b700098109edcad5f2repo sync */
203baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_CLEAR_STACK(ts)						\
204baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    PR_BEGIN_MACRO                 					\
205baa3858d3f5d128a5c8466b700098109edcad5f2repo sync	(void) mprotect((void*)ts->seg->vaddr, REDZONE, PROT_READ|PROT_WRITE);\
206baa3858d3f5d128a5c8466b700098109edcad5f2repo sync	(void) mprotect((void*) ((char*)ts->seg->vaddr + REDZONE + ts->stackSize),\
207baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			REDZONE, PROT_READ|PROT_WRITE);			\
208baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    PR_END_MACRO
209baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
210baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#else	/* DEBUG */
211baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
212baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_INIT_STACK(ts,REDZONE)
213baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_CLEAR_STACK(ts)
214baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
215baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#endif	/* DEBUG */
216baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
217baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#if !defined(SOLARIS)
218baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
219baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define PR_SET_INTSOFF(newval)
220baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
221baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#endif
222baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
223baa3858d3f5d128a5c8466b700098109edcad5f2repo sync/************************************************************************/
224baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
225baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern void _PR_UnixInit(void);
226baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
227baa3858d3f5d128a5c8466b700098109edcad5f2repo sync/************************************************************************/
228baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
229baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstruct _MDProcess {
230baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    pid_t pid;
231baa3858d3f5d128a5c8466b700098109edcad5f2repo sync};
232baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
233baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstruct PRProcess;
234baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstruct PRProcessAttr;
235baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
236baa3858d3f5d128a5c8466b700098109edcad5f2repo sync/* Create a new process (fork() + exec()) */
237baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_CREATE_PROCESS _MD_CreateUnixProcess
238baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern struct PRProcess * _MD_CreateUnixProcess(
239baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    const char *path,
240baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    char *const *argv,
241baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    char *const *envp,
242baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    const struct PRProcessAttr *attr
243baa3858d3f5d128a5c8466b700098109edcad5f2repo sync);
244baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
245baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_DETACH_PROCESS _MD_DetachUnixProcess
246baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRStatus _MD_DetachUnixProcess(struct PRProcess *process);
247baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
248baa3858d3f5d128a5c8466b700098109edcad5f2repo sync/* Wait for a child process to terminate */
249baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_WAIT_PROCESS _MD_WaitUnixProcess
250baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRStatus _MD_WaitUnixProcess(struct PRProcess *process,
251baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    PRInt32 *exitCode);
252baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
253baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_KILL_PROCESS _MD_KillUnixProcess
254baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRStatus _MD_KillUnixProcess(struct PRProcess *process);
255baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
256baa3858d3f5d128a5c8466b700098109edcad5f2repo sync/************************************************************************/
257baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
258baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern void _MD_EnableClockInterrupts(void);
259baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern void _MD_DisableClockInterrupts(void);
260baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
261baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_START_INTERRUPTS			_MD_StartInterrupts
262baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_STOP_INTERRUPTS				_MD_StopInterrupts
263baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_DISABLE_CLOCK_INTERRUPTS	_MD_DisableClockInterrupts
264baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_ENABLE_CLOCK_INTERRUPTS		_MD_EnableClockInterrupts
265baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_BLOCK_CLOCK_INTERRUPTS		_MD_BlockClockInterrupts
266baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_UNBLOCK_CLOCK_INTERRUPTS	_MD_UnblockClockInterrupts
267baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
268baa3858d3f5d128a5c8466b700098109edcad5f2repo sync/************************************************************************/
269baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
270baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern void		_MD_InitCPUS(void);
271baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_INIT_CPUS           _MD_InitCPUS
272baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
273baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern void		_MD_Wakeup_CPUs(void);
274baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_WAKEUP_CPUS _MD_Wakeup_CPUs
275baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
276baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_PAUSE_CPU			_MD_PauseCPU
277baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
278baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#if defined(_PR_LOCAL_THREADS_ONLY) || defined(_PR_GLOBAL_THREADS_ONLY)
279baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_CLEANUP_BEFORE_EXIT()
280baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#endif
281baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
282baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#ifndef IRIX
283baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_EXIT(status)		_exit(status)
284baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#endif
285baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
286baa3858d3f5d128a5c8466b700098109edcad5f2repo sync/************************************************************************/
287baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
288baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_GET_ENV				getenv
289baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_PUT_ENV				putenv
290baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
291baa3858d3f5d128a5c8466b700098109edcad5f2repo sync/************************************************************************/
292baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
293baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_INIT_FILEDESC(fd)
294baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
295baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern void		_MD_MakeNonblock(PRFileDesc *fd);
296baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_MAKE_NONBLOCK			_MD_MakeNonblock
297baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
298baa3858d3f5d128a5c8466b700098109edcad5f2repo sync/************************************************************************/
299baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
300baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#if !defined(_PR_PTHREADS)
301baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
302baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern void		_MD_InitSegs(void);
303baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRStatus	_MD_AllocSegment(PRSegment *seg, PRUint32 size,
304baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				void *vaddr);
305baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern void		_MD_FreeSegment(PRSegment *seg);
306baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
307baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_INIT_SEGS			_MD_InitSegs
308baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_ALLOC_SEGMENT		_MD_AllocSegment
309baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_FREE_SEGMENT		_MD_FreeSegment
310baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
311baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#endif /* !defined(_PR_PTHREADS) */
312baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
313baa3858d3f5d128a5c8466b700098109edcad5f2repo sync/************************************************************************/
314baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
315baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#if !defined(HPUX_LW_TIMER)
316baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_INTERVAL_INIT()
317baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#endif
318baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_INTERVAL_PER_MILLISEC()	(_PR_MD_INTERVAL_PER_SEC() / 1000)
319baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_INTERVAL_PER_MICROSEC()	(_PR_MD_INTERVAL_PER_SEC() / 1000000)
320baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
321baa3858d3f5d128a5c8466b700098109edcad5f2repo sync/************************************************************************/
322baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
323baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_ERRNO()             	(errno)
324baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_GET_SOCKET_ERROR()		(errno)
325baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
326baa3858d3f5d128a5c8466b700098109edcad5f2repo sync/************************************************************************/
327baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
328baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRInt32 _MD_AvailableSocket(PRInt32 osfd);
329baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
330baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern void _MD_StartInterrupts(void);
331baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern void _MD_StopInterrupts(void);
332baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern void _MD_DisableClockInterrupts(void);
333baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern void _MD_BlockClockInterrupts(void);
334baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern void _MD_UnblockClockInterrupts(void);
335baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern void _MD_PauseCPU(PRIntervalTime timeout);
336baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
337baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRStatus _MD_open_dir(struct _MDDir *, const char *);
338baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRInt32  _MD_close_dir(struct _MDDir *);
339baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern char *   _MD_read_dir(struct _MDDir *, PRIntn);
340baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRInt32  _MD_open(const char *name, PRIntn osflags, PRIntn mode);
341baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRInt32	_MD_delete(const char *name);
342baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRInt32	_MD_getfileinfo(const char *fn, PRFileInfo *info);
343baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRInt32  _MD_getfileinfo64(const char *fn, PRFileInfo64 *info);
344baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRInt32  _MD_getopenfileinfo(const PRFileDesc *fd, PRFileInfo *info);
345baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRInt32  _MD_getopenfileinfo64(const PRFileDesc *fd, PRFileInfo64 *info);
346baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRInt32	_MD_rename(const char *from, const char *to);
347baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRInt32	_MD_access(const char *name, PRAccessHow how);
348baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRInt32	_MD_mkdir(const char *name, PRIntn mode);
349baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRInt32	_MD_rmdir(const char *name);
350baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRInt32	_MD_accept_read(PRInt32 sock, PRInt32 *newSock,
351baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				PRNetAddr **raddr, void *buf, PRInt32 amount);
352baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRInt32 	_PR_UnixSendFile(PRFileDesc *sd, PRSendFileData *sfd,
353baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			PRTransmitFileFlags flags, PRIntervalTime timeout);
354baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
355baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRStatus _MD_LockFile(PRInt32 osfd);
356baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRStatus _MD_TLockFile(PRInt32 osfd);
357baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRStatus _MD_UnlockFile(PRInt32 osfd);
358baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
359baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_OPEN_DIR(dir, name)		    _MD_open_dir(dir, name)
360baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_CLOSE_DIR(dir)		        _MD_close_dir(dir)
361baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_READ_DIR(dir, flags)	    _MD_read_dir(dir, flags)
362baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_OPEN(name, osflags, mode)	_MD_open(name, osflags, mode)
363baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_OPEN_FILE(name, osflags, mode)	_MD_open(name, osflags, mode)
364baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRInt32 _MD_read(PRFileDesc *fd, void *buf, PRInt32 amount);
365baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_READ(fd,buf,amount)		    _MD_read(fd,buf,amount)
366baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRInt32 _MD_write(PRFileDesc *fd, const void *buf, PRInt32 amount);
367baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_WRITE(fd,buf,amount)	    _MD_write(fd,buf,amount)
368baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_DELETE(name)		        _MD_delete(name)
369baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_GETFILEINFO(fn, info)	    _MD_getfileinfo(fn, info)
370baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_GETFILEINFO64(fn, info)	    _MD_getfileinfo64(fn, info)
371baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_GETOPENFILEINFO(fd, info)	_MD_getopenfileinfo(fd, info)
372baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_GETOPENFILEINFO64(fd, info)	_MD_getopenfileinfo64(fd, info)
373baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_RENAME(from, to)		    _MD_rename(from, to)
374baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_ACCESS(name, how)		    _MD_access(name, how)
375baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_MKDIR(name, mode)		    _MD_mkdir(name, mode)
376baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_MAKE_DIR(name, mode)		_MD_mkdir(name, mode)
377baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_RMDIR(name)			        _MD_rmdir(name)
378baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_ACCEPT_READ(sock, newSock, raddr, buf, amount)	_MD_accept_read(sock, newSock, raddr, buf, amount)
379baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
380baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_LOCKFILE _MD_LockFile
381baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_TLOCKFILE _MD_TLockFile
382baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_UNLOCKFILE _MD_UnlockFile
383baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
384baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
385baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRInt32		_MD_socket(int af, int type, int flags);
386baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_SOCKET	_MD_socket
387baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRInt32		_MD_connect(PRFileDesc *fd, const PRNetAddr *addr,
388baa3858d3f5d128a5c8466b700098109edcad5f2repo sync								PRUint32 addrlen, PRIntervalTime timeout);
389baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_CONNECT	_MD_connect
390baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRInt32		_MD_accept(PRFileDesc *fd, PRNetAddr *addr, PRUint32 *addrlen,
391baa3858d3f5d128a5c8466b700098109edcad5f2repo sync													PRIntervalTime timeout);
392baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_ACCEPT	_MD_accept
393baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRInt32		_MD_bind(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen);
394baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_BIND	_MD_bind
395baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRInt32		_MD_listen(PRFileDesc *fd, PRIntn backlog);
396baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_LISTEN	_MD_listen
397baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRInt32		_MD_shutdown(PRFileDesc *fd, PRIntn how);
398baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_SHUTDOWN	_MD_shutdown
399baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
400baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRInt32		_MD_recv(PRFileDesc *fd, void *buf, PRInt32 amount,
401baa3858d3f5d128a5c8466b700098109edcad5f2repo sync                               PRIntn flags, PRIntervalTime timeout);
402baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_RECV	_MD_recv
403baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRInt32		_MD_send(PRFileDesc *fd, const void *buf, PRInt32 amount,
404baa3858d3f5d128a5c8466b700098109edcad5f2repo sync									PRIntn flags, PRIntervalTime timeout);
405baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_SEND	_MD_send
406baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRInt32		_MD_recvfrom(PRFileDesc *fd, void *buf, PRInt32 amount,
407baa3858d3f5d128a5c8466b700098109edcad5f2repo sync						PRIntn flags, PRNetAddr *addr, PRUint32 *addrlen,
408baa3858d3f5d128a5c8466b700098109edcad5f2repo sync											PRIntervalTime timeout);
409baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_RECVFROM	_MD_recvfrom
410baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRInt32 _MD_sendto(PRFileDesc *fd, const void *buf, PRInt32 amount,
411baa3858d3f5d128a5c8466b700098109edcad5f2repo sync							PRIntn flags, const PRNetAddr *addr, PRUint32 addrlen,
412baa3858d3f5d128a5c8466b700098109edcad5f2repo sync												PRIntervalTime timeout);
413baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_SENDTO	_MD_sendto
414baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRInt32		_MD_writev(PRFileDesc *fd, const struct PRIOVec *iov,
415baa3858d3f5d128a5c8466b700098109edcad5f2repo sync								PRInt32 iov_size, PRIntervalTime timeout);
416baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_WRITEV	_MD_writev
417baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
418baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRInt32		_MD_socketavailable(PRFileDesc *fd);
419baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define	_MD_SOCKETAVAILABLE		_MD_socketavailable
420baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRInt64		_MD_socketavailable64(PRFileDesc *fd);
421baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define	_MD_SOCKETAVAILABLE64		_MD_socketavailable64
422baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
423baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define	_MD_PIPEAVAILABLE		_MD_socketavailable
424baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
425baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRInt32 _MD_pr_poll(PRPollDesc *pds, PRIntn npds,
426baa3858d3f5d128a5c8466b700098109edcad5f2repo sync												PRIntervalTime timeout);
427baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_PR_POLL		_MD_pr_poll
428baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
429baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRInt32		_MD_close(PRInt32 osfd);
430baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_CLOSE_FILE	_MD_close
431baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRInt32		_MD_lseek(PRFileDesc*, PRInt32, PRSeekWhence);
432baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_LSEEK	_MD_lseek
433baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRInt64		_MD_lseek64(PRFileDesc*, PRInt64, PRSeekWhence);
434baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_LSEEK64	_MD_lseek64
435baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRInt32		_MD_fsync(PRFileDesc *fd);
436baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_FSYNC	_MD_fsync
437baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
438baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRInt32 _MD_socketpair(int af, int type, int flags, PRInt32 *osfd);
439baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_SOCKETPAIR		_MD_socketpair
440baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
441baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_CLOSE_SOCKET	_MD_close
442baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
443baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#ifndef NO_NSPR_10_SUPPORT
444baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_STAT	stat
445baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#endif
446baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
447baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRStatus _MD_getpeername(PRFileDesc *fd, PRNetAddr *addr,
448baa3858d3f5d128a5c8466b700098109edcad5f2repo sync											PRUint32 *addrlen);
449baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_GETPEERNAME _MD_getpeername
450baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRStatus _MD_getsockname(PRFileDesc *fd, PRNetAddr *addr,
451baa3858d3f5d128a5c8466b700098109edcad5f2repo sync											PRUint32 *addrlen);
452baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_GETSOCKNAME _MD_getsockname
453baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
454baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRStatus _MD_getsockopt(PRFileDesc *fd, PRInt32 level,
455baa3858d3f5d128a5c8466b700098109edcad5f2repo sync						PRInt32 optname, char* optval, PRInt32* optlen);
456baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_GETSOCKOPT		_MD_getsockopt
457baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRStatus _MD_setsockopt(PRFileDesc *fd, PRInt32 level,
458baa3858d3f5d128a5c8466b700098109edcad5f2repo sync					PRInt32 optname, const char* optval, PRInt32 optlen);
459baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_SETSOCKOPT		_MD_setsockopt
460baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
461baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRStatus _MD_set_fd_inheritable(PRFileDesc *fd, PRBool inheritable);
462baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_SET_FD_INHERITABLE _MD_set_fd_inheritable
463baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
464baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern void _MD_init_fd_inheritable(PRFileDesc *fd, PRBool imported);
465baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_INIT_FD_INHERITABLE _MD_init_fd_inheritable
466baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
467baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern void _MD_query_fd_inheritable(PRFileDesc *fd);
468baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_QUERY_FD_INHERITABLE _MD_query_fd_inheritable
469baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
470baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRStatus _MD_gethostname(char *name, PRUint32 namelen);
471baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_GETHOSTNAME		_MD_gethostname
472baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
473baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern PRStatus _MD_getsysinfo(PRSysInfo cmd, char *name, PRUint32 namelen);
474baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _MD_GETSYSINFO		_MD_getsysinfo
475baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
476baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern int _MD_unix_get_nonblocking_connect_error(int osfd);
477baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
478baa3858d3f5d128a5c8466b700098109edcad5f2repo sync/* Memory-mapped files */
479baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
480baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstruct _MDFileMap {
481baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    PRIntn prot;
482baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    PRIntn flags;
483    PRBool isAnonFM; /* when true, PR_CloseFileMap() must close the related fd */
484};
485
486extern PRStatus _MD_CreateFileMap(struct PRFileMap *fmap, PRInt64 size);
487#define _MD_CREATE_FILE_MAP _MD_CreateFileMap
488
489#define _MD_GET_MEM_MAP_ALIGNMENT() PR_GetPageSize()
490
491extern void * _MD_MemMap(struct PRFileMap *fmap, PRInt64 offset,
492        PRUint32 len);
493#define _MD_MEM_MAP _MD_MemMap
494
495extern PRStatus _MD_MemUnmap(void *addr, PRUint32 size);
496#define _MD_MEM_UNMAP _MD_MemUnmap
497
498extern PRStatus _MD_CloseFileMap(struct PRFileMap *fmap);
499#define _MD_CLOSE_FILE_MAP _MD_CloseFileMap
500
501/*
502 * The standard (XPG4) gettimeofday() (from BSD) takes two arguments.
503 * On some SVR4 derivatives, gettimeofday() takes only one argument.
504 * The GETTIMEOFDAY macro is intended to hide this difference.
505 */
506#ifdef HAVE_SVID_GETTOD
507#define GETTIMEOFDAY(tp) gettimeofday(tp)
508#else
509#define GETTIMEOFDAY(tp) gettimeofday((tp), NULL)
510#endif
511
512#if defined(_PR_PTHREADS) && !defined(_PR_POLL_AVAILABLE)
513#define _PR_NEED_FAKE_POLL
514#endif
515
516#if defined(_PR_NEED_FAKE_POLL)
517
518/*
519 * Some platforms don't have poll(), but our pthreads code calls poll().
520 * As a temporary measure, I implemented a fake poll() using select().
521 * Here are the struct and macro definitions copied from sys/poll.h
522 * on Solaris 2.5.
523 */
524
525struct pollfd {
526    int fd;
527    short events;
528    short revents;
529};
530
531/* poll events */
532
533#define	POLLIN		0x0001		/* fd is readable */
534#define	POLLPRI		0x0002		/* high priority info at fd */
535#define	POLLOUT		0x0004		/* fd is writeable (won't block) */
536#define	POLLRDNORM	0x0040		/* normal data is readable */
537#define	POLLWRNORM	POLLOUT
538#define	POLLRDBAND	0x0080		/* out-of-band data is readable */
539#define	POLLWRBAND	0x0100		/* out-of-band data is writeable */
540
541#define	POLLNORM	POLLRDNORM
542
543#define	POLLERR		0x0008		/* fd has error condition */
544#define	POLLHUP		0x0010		/* fd has been hung up on */
545#define	POLLNVAL	0x0020		/* invalid pollfd entry */
546
547extern int poll(struct pollfd *, unsigned long, int);
548
549#endif /* _PR_NEED_FAKE_POLL */
550
551/*
552** A vector of the UNIX I/O calls we use. These are here to smooth over
553** the rough edges needed for large files. All of NSPR's implmentaions
554** go through this vector using syntax of the form
555**      result = _md_iovector.xxx64(args);
556*/
557
558#if defined(SOLARIS2_5)
559/*
560** Special case: Solaris 2.5.1
561** Solaris starts to have 64-bit file I/O in 2.6.  We build on Solaris
562** 2.5.1 so that we can use the same binaries on both Solaris 2.5.1 and
563** 2.6.  At run time, we detect whether 64-bit file I/O is available by
564** looking up the 64-bit file function symbols in libc.  At build time,
565** we need to define the 64-bit file I/O datatypes that are compatible
566** with their definitions on Solaris 2.6.
567*/
568typedef PRInt64 off64_t;
569typedef PRUint64 ino64_t;
570typedef PRInt64 blkcnt64_t;
571struct stat64 {
572    dev_t st_dev;
573    long st_pad1[3];
574    ino64_t st_ino;
575    mode_t st_mode;
576    nlink_t st_nlink;
577    uid_t st_uid;
578    gid_t st_gid;
579    dev_t st_rdev;
580    long t_pad2[2];
581    off64_t st_size;
582    timestruc_t st_atim;
583    timestruc_t st_mtim;
584    timestruc_t st_ctim;
585    long st_blksize;
586    blkcnt64_t st_blocks;
587    char st_fstype[_ST_FSTYPSZ];
588    long st_pad4[8];
589};
590typedef struct stat64 _MDStat64;
591typedef off64_t _MDOff64_t;
592
593#elif defined(_PR_HAVE_OFF64_T)
594typedef struct stat64 _MDStat64;
595typedef off64_t _MDOff64_t;
596#elif defined(_PR_HAVE_LARGE_OFF_T)
597typedef struct stat _MDStat64;
598typedef off_t _MDOff64_t;
599#elif defined(_PR_NO_LARGE_FILES)
600typedef struct stat _MDStat64;
601typedef PRInt64 _MDOff64_t;
602#else
603#error "I don't know yet"
604#endif
605
606typedef PRIntn (*_MD_Fstat64)(PRIntn osfd, _MDStat64 *buf);
607typedef PRIntn (*_MD_Open64)(const char *path, int oflag, ...);
608#if defined(VMS)
609typedef PRIntn (*_MD_Stat64)(const char *path, _MDStat64 *buf, ...);
610#else
611typedef PRIntn (*_MD_Stat64)(const char *path, _MDStat64 *buf);
612#endif
613typedef _MDOff64_t (*_MD_Lseek64)(PRIntn osfd, _MDOff64_t, PRIntn whence);
614typedef void* (*_MD_Mmap64)(
615    void *addr, PRSize len, PRIntn prot, PRIntn flags,
616    PRIntn fildes, _MDOff64_t offset);
617struct _MD_IOVector
618{
619    _MD_Open64 _open64;
620    _MD_Mmap64 _mmap64;
621    _MD_Stat64 _stat64;
622    _MD_Fstat64 _fstat64;
623    _MD_Lseek64 _lseek64;
624};
625extern struct _MD_IOVector _md_iovector;
626
627#endif /* prunixos_h___ */
628