Bugzilla bug #40629: the _PR_NewSegment and _PR_DestroySegment functions

are not needed in the pthreads version.  The /dev/zero file, if opened,
should have the close-on-exec flag so that it won't get inherited by
child processes.
Modified files: _unixos.h, primpl.h, prseg.c, unix.c
This commit is contained in:
wtc%netscape.com 2000-05-25 23:26:10 +00:00
Родитель ff11ad4fa2
Коммит f151332642
4 изменённых файлов: 66 добавлений и 46 удалений

Просмотреть файл

@ -276,6 +276,9 @@ extern void _MD_MakeNonblock(PRFileDesc *fd);
/************************************************************************/
#if !defined(_PR_PTHREADS)
extern void _MD_InitSegs(void);
extern PRStatus _MD_AllocSegment(PRSegment *seg, PRUint32 size,
void *vaddr);
extern void _MD_FreeSegment(PRSegment *seg);
@ -284,6 +287,8 @@ extern void _MD_FreeSegment(PRSegment *seg);
#define _MD_ALLOC_SEGMENT _MD_AllocSegment
#define _MD_FREE_SEGMENT _MD_FreeSegment
#endif /* !defined(_PR_PTHREADS) */
/************************************************************************/
#if !defined(HPUX_LW_TIMER)
@ -301,7 +306,6 @@ extern void _MD_FreeSegment(PRSegment *seg);
extern PRInt32 _MD_AvailableSocket(PRInt32 osfd);
extern void _MD_InitSegs(void);
extern void _MD_StartInterrupts(void);
extern void _MD_StopInterrupts(void);
extern void _MD_DisableClockInterrupts(void);

Просмотреть файл

@ -711,6 +711,32 @@ NSPR_API(void) _PR_Unlock(PRLock *lock);
NSPR_API(void) _PR_SuspendThread(PRThread *t);
NSPR_API(void) _PR_ResumeThread(PRThread *t);
/***********************************************************************
** FUNCTION: _PR_NewSegment()
** DESCRIPTION:
** Allocate a memory segment. The "size" value is rounded up to the
** native system page size and a page aligned portion of memory is
** returned. This memory is not part of the malloc heap. If "vaddr" is
** not NULL then PR tries to allocate the segment at the desired virtual
** address.
** INPUTS: size: size of the desired memory segment
** vaddr: address at which the newly aquired segment is to be
** mapped into memory.
** OUTPUTS: a memory segment is allocated, a PRSegment is allocated
** RETURN: pointer to PRSegment
***********************************************************************/
extern PRSegment* _PR_NewSegment(PRUint32 size, void *vaddr);
/***********************************************************************
** FUNCTION: _PR_DestroySegment()
** DESCRIPTION:
** The memory segment and the PRSegment are freed
** INPUTS: seg: pointer to PRSegment to be freed
** OUTPUTS: the the PRSegment and its associated memory segment are freed
** RETURN: void
***********************************************************************/
extern void _PR_DestroySegment(PRSegment *seg);
extern PRThreadStack * _PR_NewStack(PRUint32 stackSize);
extern void _PR_FreeStack(PRThreadStack *stack);
extern PRBool _PR_NotifyThread (PRThread *thread, PRThread *me);
@ -987,6 +1013,16 @@ extern void _PR_MD_SWITCH_CONTEXT(PRThread *thread);
extern void _PR_MD_RESTORE_CONTEXT(PRThread *thread);
#define _PR_MD_RESTORE_CONTEXT _MD_RESTORE_CONTEXT
/* Segment related */
extern void _PR_MD_INIT_SEGS(void);
#define _PR_MD_INIT_SEGS _MD_INIT_SEGS
extern PRStatus _PR_MD_ALLOC_SEGMENT(PRSegment *seg, PRUint32 size, void *vaddr);
#define _PR_MD_ALLOC_SEGMENT _MD_ALLOC_SEGMENT
extern void _PR_MD_FREE_SEGMENT(PRSegment *seg);
#define _PR_MD_FREE_SEGMENT _MD_FREE_SEGMENT
/* Directory enumeration related */
extern PRStatus _PR_MD_OPEN_DIR(_MDDir *md,const char *name);
#define _PR_MD_OPEN_DIR _MD_OPEN_DIR
@ -1630,32 +1666,6 @@ struct PRSegment {
/* PRSegment.flags */
#define _PR_SEG_VM 0x1
/***********************************************************************
** FUNCTION: _PR_NewSegment()
** DESCRIPTION:
** Allocate a memory segment. The "size" value is rounded up to the
** native system page size and a page aligned portion of memory is
** returned. This memory is not part of the malloc heap. If "vaddr" is
** not NULL then PR tries to allocate the segment at the desired virtual
** address.
** INPUTS: size: size of the desired memory segment
** vaddr: address at which the newly aquired segment is to be
** mapped into memory.
** OUTPUTS: a memory segment is allocated, a PRSegment is allocated
** RETURN: pointer to PRSegment
***********************************************************************/
extern PRSegment* _PR_NewSegment(PRUint32 size, void *vaddr);
/***********************************************************************
** FUNCTION: _PR_DestroySegment()
** DESCRIPTION:
** The memory segment and the PRSegment are freed
** INPUTS: seg: pointer to PRSegment to be freed
** OUTPUTS: the the PRSegment and its associated memory segment are freed
** RETURN: void
***********************************************************************/
extern void _PR_DestroySegment(PRSegment *seg);
/************************************************************************/
extern PRInt32 _pr_pageSize;
@ -1697,9 +1707,6 @@ extern void _PR_MD_EARLY_INIT(void);
extern void _PR_MD_INTERVAL_INIT(void);
#define _PR_MD_INTERVAL_INIT _MD_INTERVAL_INIT
NSPR_API(void) _PR_MD_INIT_SEGS(void);
#define _PR_MD_INIT_SEGS _MD_INIT_SEGS
NSPR_API(void) _PR_MD_FINAL_INIT(void);
#define _PR_MD_FINAL_INIT _MD_FINAL_INIT
@ -1749,13 +1756,6 @@ extern PRInt32 _PR_MD_ATOMIC_DECREMENT(PRInt32 *);
extern PRInt32 _PR_MD_ATOMIC_SET(PRInt32 *, PRInt32);
#define _PR_MD_ATOMIC_SET _MD_ATOMIC_SET
/* Segment related */
NSPR_API(PRStatus) _PR_MD_ALLOC_SEGMENT(PRSegment *seg, PRUint32 size, void *vaddr);
#define _PR_MD_ALLOC_SEGMENT _MD_ALLOC_SEGMENT
NSPR_API(void) _PR_MD_FREE_SEGMENT(PRSegment *seg);
#define _PR_MD_FREE_SEGMENT _MD_FREE_SEGMENT
/* Garbage collection */
/*

Просмотреть файл

@ -71,16 +71,7 @@
static PRLock *_pr_rename_lock = NULL;
static PRMonitor *_pr_Xfe_mon = NULL;
/*
* Variables used by the GC code, initialized in _MD_InitSegs().
* _pr_zero_fd should be a static variable. Unfortunately, there is
* still some Unix-specific code left in function PR_GrowSegment()
* in file memory/prseg.c that references it, so it needs
* to be a global variable for now.
*/
PRInt32 _pr_zero_fd = -1;
static PRInt64 minus_one;
static PRLock *_pr_md_lock = NULL;
sigset_t timer_set;
@ -2827,6 +2818,14 @@ void _PR_UnixInit(void)
_PR_InitIOV(); /* one last hack */
}
#if !defined(_PR_PTHREADS)
/*
* Variables used by the GC code, initialized in _MD_InitSegs().
*/
static PRInt32 _pr_zero_fd = -1;
static PRLock *_pr_md_lock = NULL;
/*
* _MD_InitSegs --
*
@ -2846,6 +2845,8 @@ void _MD_InitSegs(void)
}
#endif
_pr_zero_fd = open("/dev/zero",O_RDWR , 0);
/* Prevent the fd from being inherited by child processes */
fcntl(_pr_zero_fd, F_SETFD, FD_CLOEXEC);
_pr_md_lock = PR_NewLock();
}
@ -2905,6 +2906,8 @@ void _MD_FreeSegment(PRSegment *seg)
PR_DELETE(seg->vaddr);
}
#endif /* _PR_PTHREADS */
/*
*-----------------------------------------------------------------------
*

Просмотреть файл

@ -18,6 +18,17 @@
#include "primpl.h"
#if defined(_PR_PTHREADS)
/*
** The pthreads version doesn't use these functions.
*/
void _PR_InitSegs(void)
{
}
#else /* _PR_PTHREADS */
void _PR_InitSegs(void)
{
_PR_MD_INIT_SEGS();
@ -59,3 +70,5 @@ void _PR_DestroySegment(PRSegment *seg)
_PR_MD_FREE_SEGMENT(seg);
PR_DELETE(seg);
}
#endif /* _PR_PTHREADS */