Checked in (unfinished) Rhapsody port provided by Chris McAfee and
authorwtc
Tue, 05 May 1998 23:28:45 +0000
changeset 92 ebfa8639f35143d66c44c4dabd6c8b95aa479d87
parent 80 a03073693c7f200f2652950b670ac27430c504e4
child 93 167712b61eae9b2bfba071589885743a5de1978c
push idunknown
push userunknown
push dateunknown
Checked in (unfinished) Rhapsody port provided by Chris McAfee and Chris Toshok (mcafee, toshok@netscape.com). It is classic NSPR, local threads only (based on setjmp/longjmp).
config/Rhapsody.mk
config/nsinstall.c
config/rules.mk
pr/include/md/Makefile
pr/include/md/_darwin.cfg
pr/include/md/_darwin.h
pr/include/md/_rhapsody.cfg
pr/include/md/_rhapsody.h
pr/include/md/_unixos.h
pr/include/md/prosdep.h
pr/include/private/primpl.h
pr/src/linking/prlink.c
pr/src/md/prosdep.c
pr/src/md/unix/Makefile
pr/src/md/unix/darwin.c
pr/src/md/unix/freebsd.c
pr/src/md/unix/objs.mk
pr/src/md/unix/rhapsody.c
pr/src/md/unix/unix.c
pr/src/md/unix/unix_errors.c
pr/src/md/unix/uxwrap.c
pr/src/memory/prseg.c
new file mode 100644
--- /dev/null
+++ b/config/Rhapsody.mk
@@ -0,0 +1,47 @@
+#
+# The contents of this file are subject to the Netscape Public License
+# Version 1.0 (the "NPL"); you may not use this file except in
+# compliance with the NPL.  You may obtain a copy of the NPL at
+# http://www.mozilla.org/NPL/
+# 
+# Software distributed under the NPL is distributed on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
+# for the specific language governing rights and limitations under the
+# NPL.
+# 
+# The Initial Developer of this code under the NPL is Netscape
+# Communications Corporation.  Portions created by Netscape are
+# Copyright (C) 1998 Netscape Communications Corporation.  All Rights
+# Reserved.
+#
+
+#
+# Config stuff for Rhapsody5.0
+#
+
+include $(MOD_DEPTH)/config/UNIX.mk
+
+CC			= cc
+CCC			= cc++
+RANLIB			= ranlib
+
+OS_REL_CFLAGS		= -Dppc
+CPU_ARCH		= ppc
+
+#OS_REL_CFLAGS		= -mno-486 -Di386
+#CPU_ARCH		= x86
+
+OS_CFLAGS		= $(DSO_CFLAGS) $(OS_REL_CFLAGS) -pipe -DRHAPSODY -DHAVE_STRERROR -DHAVE_BSD_FLOCK
+
+DEFINES			+= -D_PR_LOCAL_THREADS_ONLY -D_PR_NEED_FAKE_POLL
+
+ARCH			= rhapsody
+
+#DSO_CFLAGS		= -fPIC
+#DSO_LDOPTS		= -Bshareable
+#DSO_LDFLAGS		=
+
+MKSHLIB			= $(CC) -arch ppc -dynamiclib -compatibility_version 1 -current_version 1
+DLL_SUFFIX		= dylib
+
+#G++INCLUDES		= -I/usr/include/g++
--- a/config/nsinstall.c
+++ b/config/nsinstall.c
@@ -32,20 +32,28 @@
 #include <unistd.h>
 #include <utime.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include "pathsub.h"
 
 #define HAVE_LCHOWN
 
-#if defined(AIX) || defined(BSDI) || defined(HPUX) || defined(LINUX) || defined(SUNOS4) || defined(SCO) || defined(UNIXWARE)
+#if defined(AIX) || defined(BSDI) || defined(HPUX) || defined(LINUX) || defined(SUNOS4) || defined(SCO) || defined(UNIXWARE) || defined(RHAPSODY)
 #undef HAVE_LCHOWN
 #endif
 
+/*
+ * Does getcwd() take NULL as the first argument and malloc
+ * the result buffer?
+ */
+#if !defined(RHAPSODY)
+#define GETCWD_CAN_MALLOC
+#endif
+
 #ifdef LINUX
 #include <getopt.h>
 #endif
 
 #if defined(SCO) || defined(UNIXWARE) || defined(SNI) || defined(NCR) || defined(NEC)
 #if !defined(S_ISLNK) && defined(S_IFLNK)
 #define S_ISLNK(a)	(((a) & S_IFMT) == S_IFLNK)
 #endif
@@ -182,20 +190,31 @@ main(int argc, char **argv)
     todir = argv[argc-1];
     if ((stat(todir, &sb) < 0 || !S_ISDIR(sb.st_mode)) &&
 	mkdirs(todir, 0777) < 0) {
 	fail("cannot make directory %s", todir);
     }
     if (onlydir)
 	return 0;
 
-    if (!cwd)
+    if (!cwd) {
+#ifdef GETCWD_CAN_MALLOC
 	cwd = getcwd(0, PATH_MAX);
+#else
+	cwd = malloc(PATH_MAX + 1);
+	cwd = getcwd(cwd, PATH_MAX);
+#endif
+    }
     xchdir(todir);
+#ifdef GETCWD_CAN_MALLOC
     todir = getcwd(0, PATH_MAX);
+#else
+    todir = malloc(PATH_MAX + 1);
+    todir = getcwd(todir, PATH_MAX);
+#endif
     tdlen = strlen(todir);
     xchdir(cwd);
     tdlen = strlen(todir);
 
     uid = owner ? touid(owner) : -1;
     gid = group ? togid(group) : -1;
 
     while (--argc > 0) {
--- a/config/rules.mk
+++ b/config/rules.mk
@@ -126,17 +126,17 @@ ifeq ($(OS_TARGET), WIN16)
 	comma := ,
 	empty :=
 	space := $(empty) $(empty)
 	W16OBJS = $(subst $(space),$(comma)$(space),$(strip $(OBJS)))
 	W16TEMP =$(OS_LIBS) $(EXTRA_LIBS)
     ifeq ($(strip $(W16TEMP)),)
 		W16LIBS =
     else
-    	W16LIBS = library $(subst $(space),$(comma)$(space),$(strip $(W16TEMP)))
+		W16LIBS = library $(subst $(space),$(comma)$(space),$(strip $(W16TEMP)))
     endif
 	W16DEF = $(notdir $(basename $(SHARED_LIBRARY))).DEF
 endif
 
 ifeq ($(OS_ARCH), WINNT)
 ifneq ($(OS_TARGET), WIN16)
 ifneq ($(OS_TARGET), OS2)
 OBJS += $(RES)
@@ -252,16 +252,22 @@ endif
 ifeq ($(OS_ARCH)$(OS_RELEASE), AIX4.1)
 	echo "#!" > $(OBJDIR)/lib$(LIBRARY_NAME)_syms
 	nm -B -C -g $(OBJS) \
 		| awk '/ [T,D] / {print $$3}' \
 		| sed -e 's/^\.//' \
 		| sort -u >> $(OBJDIR)/lib$(LIBRARY_NAME)_syms
 	$(LD) $(XCFLAGS) -o $@ $(OBJS) -bE:$(OBJDIR)/lib$(LIBRARY_NAME)_syms \
 		-bM:SRE -bnoentry $(OS_LIBS) $(EXTRA_LIBS)
+else
+ifeq ($(OS_ARCH)$(OS_RELEASE), Rhapsody5.0)
+	@echo Trying to generate Rhapsody dynamic library.
+	# Do we need this?: -install_name 
+	$(CC) -arch ppc -dynamiclib -compatibility_version 1 -current_version 1 -all_load $(OBJS) -o $@
+
 
 else
 ifeq ($(OS_ARCH), WINNT)
 ifeq ($(OS_TARGET), WIN16)
 	echo system windows dll initinstance >w16link
 	echo option map >>w16link
 	echo option oneautodata >>w16link
 	echo option heapsize=32K >>w16link
@@ -289,16 +295,17 @@ ifeq ($(OS_TARGET), OS2)
 else
 	$(LINK_DLL) -MAP $(DLLBASE) $(OS_LIBS) $(EXTRA_LIBS) $(OBJS)
 endif
 endif
 else
 	$(MKSHLIB) -o $@ $(OBJS) $(EXTRA_LIBS) $(OS_LIBS)
 endif
 endif
+endif
 
 $(PURE_LIBRARY):
 	rm -f $@
 ifneq ($(OS_ARCH), WINNT)
 	$(AR) $(OBJS)
 endif
 	$(RANLIB) $@
 
--- a/pr/include/md/Makefile
+++ b/pr/include/md/Makefile
@@ -74,16 +74,20 @@ else
 MDCPUCFG_H = _solaris.cfg
 endif
 endif
 
 ifeq ($(OS_ARCH),SINIX)
 MDCPUCFG_H = _reliantunix.cfg
 endif
 
+ifeq ($(OS_ARCH),Rhapsody)
+MDCPUCFG_H = _rhapsody.cfg
+endif
+
 ifeq ($(OS_ARCH),NEWS-OS)
 MDCPUCFG_H = _sony.cfg
 endif
 
 ifeq ($(OS_ARCH),NEC)
 MDCPUCFG_H = _nec.cfg
 endif
 
new file mode 100644
--- /dev/null
+++ b/pr/include/md/_darwin.cfg
@@ -0,0 +1,119 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * The contents of this file are subject to the Netscape Public License
+ * Version 1.0 (the "NPL"); you may not use this file except in
+ * compliance with the NPL.  You may obtain a copy of the NPL at
+ * http://www.mozilla.org/NPL/
+ * 
+ * Software distributed under the NPL is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
+ * for the specific language governing rights and limitations under the
+ * NPL.
+ * 
+ * The Initial Developer of this code under the NPL is Netscape
+ * Communications Corporation.  Portions created by Netscape are
+ * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
+ * Reserved.
+ */
+
+#ifndef nspr_cpucfg___
+#define nspr_cpucfg___
+
+#ifndef XP_UNIX
+#define XP_UNIX
+#endif
+
+#ifndef RHAPOSDY
+#define RHAPOSDY
+#endif
+
+#undef IS_LITTLE_ENDIAN
+#define  IS_BIG_ENDIAN 1
+#define	HAVE_LONG_LONG
+#undef	HAVE_ALIGNED_DOUBLES
+#define	HAVE_ALIGNED_LONGLONGS 1
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+#define PR_BYTES_PER_WORD_LOG2   2
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   4
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  4
+#define PR_ALIGN_OF_POINTER 4
+
+#ifndef NO_NSPR_10_SUPPORT
+
+#define BYTES_PER_BYTE		PR_BYTES_PER_BYTE
+#define BYTES_PER_SHORT 	PR_BYTES_PER_SHORT
+#define BYTES_PER_INT 		PR_BYTES_PER_INT
+#define BYTES_PER_INT64		PR_BYTES_PER_INT64
+#define BYTES_PER_LONG		PR_BYTES_PER_LONG
+#define BYTES_PER_FLOAT		PR_BYTES_PER_FLOAT
+#define BYTES_PER_DOUBLE	PR_BYTES_PER_DOUBLE
+#define BYTES_PER_WORD		PR_BYTES_PER_WORD
+#define BYTES_PER_DWORD		PR_BYTES_PER_DWORD
+
+#define BITS_PER_BYTE		PR_BITS_PER_BYTE
+#define BITS_PER_SHORT		PR_BITS_PER_SHORT
+#define BITS_PER_INT		PR_BITS_PER_INT
+#define BITS_PER_INT64		PR_BITS_PER_INT64
+#define BITS_PER_LONG		PR_BITS_PER_LONG
+#define BITS_PER_FLOAT		PR_BITS_PER_FLOAT
+#define BITS_PER_DOUBLE		PR_BITS_PER_DOUBLE
+#define BITS_PER_WORD		PR_BITS_PER_WORD
+
+#define BITS_PER_BYTE_LOG2	PR_BITS_PER_BYTE_LOG2
+#define BITS_PER_SHORT_LOG2	PR_BITS_PER_SHORT_LOG2
+#define BITS_PER_INT_LOG2	PR_BITS_PER_INT_LOG2
+#define BITS_PER_INT64_LOG2	PR_BITS_PER_INT64_LOG2
+#define BITS_PER_LONG_LOG2	PR_BITS_PER_LONG_LOG2
+#define BITS_PER_FLOAT_LOG2	PR_BITS_PER_FLOAT_LOG2
+#define BITS_PER_DOUBLE_LOG2 	PR_BITS_PER_DOUBLE_LOG2
+#define BITS_PER_WORD_LOG2	PR_BITS_PER_WORD_LOG2
+
+#define ALIGN_OF_SHORT		PR_ALIGN_OF_SHORT
+#define ALIGN_OF_INT		PR_ALIGN_OF_INT
+#define ALIGN_OF_LONG		PR_ALIGN_OF_LONG
+#define ALIGN_OF_INT64		PR_ALIGN_OF_INT64
+#define ALIGN_OF_FLOAT		PR_ALIGN_OF_FLOAT
+#define ALIGN_OF_DOUBLE		PR_ALIGN_OF_DOUBLE
+#define ALIGN_OF_POINTER	PR_ALIGN_OF_POINTER
+#define ALIGN_OF_WORD		PR_ALIGN_OF_WORD
+
+#define BYTES_PER_WORD_LOG2	PR_BYTES_PER_WORD_LOG2
+#define BYTES_PER_DWORD_LOG2	PR_BYTES_PER_DWORD_LOG2
+#define WORDS_PER_DWORD_LOG2	PR_WORDS_PER_DWORD_LOG2
+
+#endif /* NO_NSPR_10_SUPPORT */
+
+#endif /* nspr_cpucfg___ */
new file mode 100644
--- /dev/null
+++ b/pr/include/md/_darwin.h
@@ -0,0 +1,144 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * The contents of this file are subject to the Netscape Public License
+ * Version 1.0 (the "NPL"); you may not use this file except in
+ * compliance with the NPL.  You may obtain a copy of the NPL at
+ * http://www.mozilla.org/NPL/
+ * 
+ * Software distributed under the NPL is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
+ * for the specific language governing rights and limitations under the
+ * NPL.
+ * 
+ * The Initial Developer of this code under the NPL is Netscape
+ * Communications Corporation.  Portions created by Netscape are
+ * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
+ * Reserved.
+ */
+
+#ifndef nspr_rhapsody_defs_h___
+#define nspr_rhapsody_defs_h___
+
+#include <sys/syscall.h>
+
+#define PR_LINKER_ARCH	"rhapsody"
+#define _PR_SI_SYSNAME  "RHAPSODY"
+#ifdef i386
+#define _PR_SI_ARCHITECTURE "x86"
+#else
+#define _PR_SI_ARCHITECTURE "ppc"
+#endif
+#define PR_DLL_SUFFIX		".dylib"
+
+#define _PR_VMBASE              0x30000000
+#define _PR_STACK_VMBASE	0x50000000
+#define _MD_DEFAULT_STACK_SIZE	65536L
+#define _MD_MMAP_FLAGS          MAP_PRIVATE
+
+#undef  HAVE_STACK_GROWING_UP
+#define HAVE_WEAK_MALLOC_SYMBOLS
+/* do this until I figure out the rhapsody dll stuff. */
+#define HAVE_DLL
+#define USE_RLD
+#define _PR_HAVE_SOCKADDR_LEN
+
+#define USE_SETJMP
+
+#include <setjmp.h>
+
+#define PR_CONTEXT_TYPE	jmp_buf
+
+#define CONTEXT(_th) ((_th)->md.context)
+
+#define _MD_GET_SP(_th)    (_th)->md.context[2]
+#define PR_NUM_GCREGS	_JBLEN
+
+/*
+** Initialize a thread context to run "_main()" when started
+*/
+#define _MD_INIT_CONTEXT(_thread, _sp, _main, status)  \
+{  \
+    *status = PR_TRUE;  \
+    if (setjmp(CONTEXT(_thread))) {  \
+        _main();  \
+    }  \
+    _MD_GET_SP(_thread) = (unsigned char*) ((_sp) - 128); \
+}
+
+#define _MD_SWITCH_CONTEXT(_thread)  \
+    if (!setjmp(CONTEXT(_thread))) {  \
+	(_thread)->md.errcode = errno;  \
+	_PR_Schedule();  \
+    }
+
+/*
+** Restore a thread context, saved by _MD_SWITCH_CONTEXT
+*/
+#define _MD_RESTORE_CONTEXT(_thread) \
+{   \
+    errno = (_thread)->md.errcode;  \
+    _MD_SET_CURRENT_THREAD(_thread);  \
+    longjmp(CONTEXT(_thread), 1);  \
+}
+
+/* Machine-dependent (MD) data structures */
+
+struct _MDThread {
+    PR_CONTEXT_TYPE context;
+    int id;
+    int errcode;
+};
+
+struct _MDThreadStack {
+    PRInt8 notused;
+};
+
+struct _MDLock {
+    PRInt8 notused;
+};
+
+struct _MDSemaphore {
+    PRInt8 notused;
+};
+
+struct _MDCVar {
+    PRInt8 notused;
+};
+
+struct _MDSegment {
+    PRInt8 notused;
+};
+
+struct _MDCPU {
+	struct _MDCPU_Unix md_unix;
+};
+
+#define _MD_INIT_LOCKS()
+#define _MD_NEW_LOCK(lock) PR_SUCCESS
+#define _MD_FREE_LOCK(lock)
+#define _MD_LOCK(lock)
+#define _MD_UNLOCK(lock)
+#define _MD_INIT_IO()
+#define _MD_IOQ_LOCK()
+#define _MD_IOQ_UNLOCK()
+
+#define _MD_INIT_RUNNING_CPU(cpu)       _MD_unix_init_running_cpu(cpu)
+#define _MD_INIT_THREAD                 _MD_InitializeThread
+#define _MD_EXIT_THREAD(thread)
+#define _MD_SUSPEND_THREAD(thread)      _MD_suspend_thread
+#define _MD_RESUME_THREAD(thread)       _MD_resume_thread
+#define _MD_CLEAN_THREAD(_thread)
+
+#define _MD_EARLY_INIT                  _MD_EarlyInit
+#define _MD_FINAL_INIT			_PR_UnixInit
+#define _MD_GET_INTERVAL                  _PR_UNIX_GetInterval
+#define _MD_INTERVAL_PER_SEC              _PR_UNIX_TicksPerSecond
+
+/*
+ * We wrapped the select() call.  _MD_SELECT refers to the built-in,
+ * unwrapped version.
+ */
+#define _MD_SELECT(nfds,r,w,e,tv) syscall(SYS_select,nfds,r,w,e,tv)
+
+
+#endif /* nspr_rhapsody_defs_h___ */
new file mode 100644
--- /dev/null
+++ b/pr/include/md/_rhapsody.cfg
@@ -0,0 +1,119 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * The contents of this file are subject to the Netscape Public License
+ * Version 1.0 (the "NPL"); you may not use this file except in
+ * compliance with the NPL.  You may obtain a copy of the NPL at
+ * http://www.mozilla.org/NPL/
+ * 
+ * Software distributed under the NPL is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
+ * for the specific language governing rights and limitations under the
+ * NPL.
+ * 
+ * The Initial Developer of this code under the NPL is Netscape
+ * Communications Corporation.  Portions created by Netscape are
+ * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
+ * Reserved.
+ */
+
+#ifndef nspr_cpucfg___
+#define nspr_cpucfg___
+
+#ifndef XP_UNIX
+#define XP_UNIX
+#endif
+
+#ifndef RHAPOSDY
+#define RHAPOSDY
+#endif
+
+#undef IS_LITTLE_ENDIAN
+#define  IS_BIG_ENDIAN 1
+#define	HAVE_LONG_LONG
+#undef	HAVE_ALIGNED_DOUBLES
+#define	HAVE_ALIGNED_LONGLONGS 1
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+#define PR_BYTES_PER_WORD_LOG2   2
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   4
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  4
+#define PR_ALIGN_OF_POINTER 4
+
+#ifndef NO_NSPR_10_SUPPORT
+
+#define BYTES_PER_BYTE		PR_BYTES_PER_BYTE
+#define BYTES_PER_SHORT 	PR_BYTES_PER_SHORT
+#define BYTES_PER_INT 		PR_BYTES_PER_INT
+#define BYTES_PER_INT64		PR_BYTES_PER_INT64
+#define BYTES_PER_LONG		PR_BYTES_PER_LONG
+#define BYTES_PER_FLOAT		PR_BYTES_PER_FLOAT
+#define BYTES_PER_DOUBLE	PR_BYTES_PER_DOUBLE
+#define BYTES_PER_WORD		PR_BYTES_PER_WORD
+#define BYTES_PER_DWORD		PR_BYTES_PER_DWORD
+
+#define BITS_PER_BYTE		PR_BITS_PER_BYTE
+#define BITS_PER_SHORT		PR_BITS_PER_SHORT
+#define BITS_PER_INT		PR_BITS_PER_INT
+#define BITS_PER_INT64		PR_BITS_PER_INT64
+#define BITS_PER_LONG		PR_BITS_PER_LONG
+#define BITS_PER_FLOAT		PR_BITS_PER_FLOAT
+#define BITS_PER_DOUBLE		PR_BITS_PER_DOUBLE
+#define BITS_PER_WORD		PR_BITS_PER_WORD
+
+#define BITS_PER_BYTE_LOG2	PR_BITS_PER_BYTE_LOG2
+#define BITS_PER_SHORT_LOG2	PR_BITS_PER_SHORT_LOG2
+#define BITS_PER_INT_LOG2	PR_BITS_PER_INT_LOG2
+#define BITS_PER_INT64_LOG2	PR_BITS_PER_INT64_LOG2
+#define BITS_PER_LONG_LOG2	PR_BITS_PER_LONG_LOG2
+#define BITS_PER_FLOAT_LOG2	PR_BITS_PER_FLOAT_LOG2
+#define BITS_PER_DOUBLE_LOG2 	PR_BITS_PER_DOUBLE_LOG2
+#define BITS_PER_WORD_LOG2	PR_BITS_PER_WORD_LOG2
+
+#define ALIGN_OF_SHORT		PR_ALIGN_OF_SHORT
+#define ALIGN_OF_INT		PR_ALIGN_OF_INT
+#define ALIGN_OF_LONG		PR_ALIGN_OF_LONG
+#define ALIGN_OF_INT64		PR_ALIGN_OF_INT64
+#define ALIGN_OF_FLOAT		PR_ALIGN_OF_FLOAT
+#define ALIGN_OF_DOUBLE		PR_ALIGN_OF_DOUBLE
+#define ALIGN_OF_POINTER	PR_ALIGN_OF_POINTER
+#define ALIGN_OF_WORD		PR_ALIGN_OF_WORD
+
+#define BYTES_PER_WORD_LOG2	PR_BYTES_PER_WORD_LOG2
+#define BYTES_PER_DWORD_LOG2	PR_BYTES_PER_DWORD_LOG2
+#define WORDS_PER_DWORD_LOG2	PR_WORDS_PER_DWORD_LOG2
+
+#endif /* NO_NSPR_10_SUPPORT */
+
+#endif /* nspr_cpucfg___ */
new file mode 100644
--- /dev/null
+++ b/pr/include/md/_rhapsody.h
@@ -0,0 +1,144 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * The contents of this file are subject to the Netscape Public License
+ * Version 1.0 (the "NPL"); you may not use this file except in
+ * compliance with the NPL.  You may obtain a copy of the NPL at
+ * http://www.mozilla.org/NPL/
+ * 
+ * Software distributed under the NPL is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
+ * for the specific language governing rights and limitations under the
+ * NPL.
+ * 
+ * The Initial Developer of this code under the NPL is Netscape
+ * Communications Corporation.  Portions created by Netscape are
+ * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
+ * Reserved.
+ */
+
+#ifndef nspr_rhapsody_defs_h___
+#define nspr_rhapsody_defs_h___
+
+#include <sys/syscall.h>
+
+#define PR_LINKER_ARCH	"rhapsody"
+#define _PR_SI_SYSNAME  "RHAPSODY"
+#ifdef i386
+#define _PR_SI_ARCHITECTURE "x86"
+#else
+#define _PR_SI_ARCHITECTURE "ppc"
+#endif
+#define PR_DLL_SUFFIX		".dylib"
+
+#define _PR_VMBASE              0x30000000
+#define _PR_STACK_VMBASE	0x50000000
+#define _MD_DEFAULT_STACK_SIZE	65536L
+#define _MD_MMAP_FLAGS          MAP_PRIVATE
+
+#undef  HAVE_STACK_GROWING_UP
+#define HAVE_WEAK_MALLOC_SYMBOLS
+/* do this until I figure out the rhapsody dll stuff. */
+#define HAVE_DLL
+#define USE_RLD
+#define _PR_HAVE_SOCKADDR_LEN
+
+#define USE_SETJMP
+
+#include <setjmp.h>
+
+#define PR_CONTEXT_TYPE	jmp_buf
+
+#define CONTEXT(_th) ((_th)->md.context)
+
+#define _MD_GET_SP(_th)    (_th)->md.context[2]
+#define PR_NUM_GCREGS	_JBLEN
+
+/*
+** Initialize a thread context to run "_main()" when started
+*/
+#define _MD_INIT_CONTEXT(_thread, _sp, _main, status)  \
+{  \
+    *status = PR_TRUE;  \
+    if (setjmp(CONTEXT(_thread))) {  \
+        _main();  \
+    }  \
+    _MD_GET_SP(_thread) = (unsigned char*) ((_sp) - 128); \
+}
+
+#define _MD_SWITCH_CONTEXT(_thread)  \
+    if (!setjmp(CONTEXT(_thread))) {  \
+	(_thread)->md.errcode = errno;  \
+	_PR_Schedule();  \
+    }
+
+/*
+** Restore a thread context, saved by _MD_SWITCH_CONTEXT
+*/
+#define _MD_RESTORE_CONTEXT(_thread) \
+{   \
+    errno = (_thread)->md.errcode;  \
+    _MD_SET_CURRENT_THREAD(_thread);  \
+    longjmp(CONTEXT(_thread), 1);  \
+}
+
+/* Machine-dependent (MD) data structures */
+
+struct _MDThread {
+    PR_CONTEXT_TYPE context;
+    int id;
+    int errcode;
+};
+
+struct _MDThreadStack {
+    PRInt8 notused;
+};
+
+struct _MDLock {
+    PRInt8 notused;
+};
+
+struct _MDSemaphore {
+    PRInt8 notused;
+};
+
+struct _MDCVar {
+    PRInt8 notused;
+};
+
+struct _MDSegment {
+    PRInt8 notused;
+};
+
+struct _MDCPU {
+	struct _MDCPU_Unix md_unix;
+};
+
+#define _MD_INIT_LOCKS()
+#define _MD_NEW_LOCK(lock) PR_SUCCESS
+#define _MD_FREE_LOCK(lock)
+#define _MD_LOCK(lock)
+#define _MD_UNLOCK(lock)
+#define _MD_INIT_IO()
+#define _MD_IOQ_LOCK()
+#define _MD_IOQ_UNLOCK()
+
+#define _MD_INIT_RUNNING_CPU(cpu)       _MD_unix_init_running_cpu(cpu)
+#define _MD_INIT_THREAD                 _MD_InitializeThread
+#define _MD_EXIT_THREAD(thread)
+#define _MD_SUSPEND_THREAD(thread)      _MD_suspend_thread
+#define _MD_RESUME_THREAD(thread)       _MD_resume_thread
+#define _MD_CLEAN_THREAD(_thread)
+
+#define _MD_EARLY_INIT                  _MD_EarlyInit
+#define _MD_FINAL_INIT			_PR_UnixInit
+#define _MD_GET_INTERVAL                  _PR_UNIX_GetInterval
+#define _MD_INTERVAL_PER_SEC              _PR_UNIX_TicksPerSecond
+
+/*
+ * We wrapped the select() call.  _MD_SELECT refers to the built-in,
+ * unwrapped version.
+ */
+#define _MD_SELECT(nfds,r,w,e,tv) syscall(SYS_select,nfds,r,w,e,tv)
+
+
+#endif /* nspr_rhapsody_defs_h___ */
--- a/pr/include/md/_unixos.h
+++ b/pr/include/md/_unixos.h
@@ -44,17 +44,17 @@
 
 /* To pick up fd_set */
 #if defined(HPUX)
 #include <sys/time.h>
 #elif defined(OSF1) || defined(AIX) || defined(SOLARIS) || defined(IRIX) \
         || defined(UNIXWARE) || defined(NCR) || defined(SNI) || defined(NEC) \
         || defined(BSDI) || defined(SONY)
 #include <sys/select.h>
-#elif defined(SUNOS4) || defined(SCO) || defined(FREEBSD)
+#elif defined(SUNOS4) || defined(SCO) || defined(FREEBSD) || defined(RHAPSODY)
 #include <sys/types.h>
 #elif defined(LINUX)
 #include <sys/time.h>
 #include <sys/types.h>
 #else
 #error Find out what include file defines fd_set on this platform
 #endif
 
@@ -151,17 +151,17 @@ extern void _MD_unix_init_running_cpu(st
 
 
 /*
 ** Make a redzone at both ends of the stack segment. Disallow access
 ** to those pages of memory. It's ok if the mprotect call's don't
 ** work - it just means that we don't really have a functional
 ** redzone.
 */
-#if defined(DEBUG)
+#if defined(DEBUG) && !defined(RHAPSODY)
 #if !defined(SOLARIS)	
 #include <string.h>  /* for memset() */
 #define _MD_INIT_STACK(ts,REDZONE)					\
     PR_BEGIN_MACRO                 					\
 	(void) mprotect((void*)ts->seg->vaddr, REDZONE, PROT_NONE);	\
 	(void) mprotect((void*) ((char*)ts->seg->vaddr + REDZONE + ts->stackSize),\
 			REDZONE, PROT_NONE);				\
     /*									\
--- a/pr/include/md/prosdep.h
+++ b/pr/include/md/prosdep.h
@@ -69,16 +69,19 @@ PR_BEGIN_EXTERN_C
 #include "md/_irix.h"
 
 #elif defined(LINUX)
 #include "md/_linux.h"
 
 #elif defined(OSF1)
 #include "md/_osf1.h"
 
+#elif defined(RHAPSODY)
+#include "md/_rhapsody.h"
+
 #elif defined(SOLARIS)
 #include "md/_solaris.h"
 
 #elif defined(SUNOS4)
 #include "md/_sunos4.h"
 
 #elif defined(SNI)
 #include "md/_reliantunix.h"
--- a/pr/include/private/primpl.h
+++ b/pr/include/private/primpl.h
@@ -1465,16 +1465,17 @@ extern PRBool _pr_ipv6_enabled;  /* defi
 /* Overriding malloc, free, etc. */
 #if !defined(_PR_NO_PREEMPT) && defined(XP_UNIX) \
         && (!defined(SOLARIS) || !defined(_PR_GLOBAL_THREADS_ONLY)) \
         && (!defined(AIX) || !defined(_PR_PTHREADS)) \
         && (!defined(OSF1) || !defined(_PR_PTHREADS)) \
         && (!defined(HPUX) || !defined(_PR_PTHREADS)) \
         && (!defined(IRIX) || !defined(_PR_PTHREADS)) \
         && (!defined(LINUX) || !defined(_PR_PTHREADS)) \
+	&& (!defined(RHAPSODY)) \
         && !defined(PURIFY) \
         && !(defined (UNIXWARE) && defined (USE_SVR4_THREADS))
 #define _PR_OVERRIDE_MALLOC
 #endif
 
 /*************************************************************************
 * External machine-dependent code provided by each OS.                     *                                                                     *
 *************************************************************************/
--- a/pr/src/linking/prlink.c
+++ b/pr/src/linking/prlink.c
@@ -27,16 +27,20 @@
 #include <Strings.h>
 #endif
 
 #ifdef XP_UNIX
 #ifdef USE_DLFCN
 #include <dlfcn.h>
 #elif defined(USE_HPSHL)
 #include <dl.h>
+#elif defined(USE_RLD)
+#include <fcntl.h>
+#include <streams/streams.h>
+#include <mach-o/rld.h>
 #endif
 
 /* Define this on systems which don't have it (AIX) */
 #ifndef RTLD_LAZY
 #define RTLD_LAZY RTLD_NOW
 #endif
 #endif /* XP_UNIX */
 
@@ -57,64 +61,59 @@ struct PRLibrary {
 #endif
 #ifdef XP_MAC
     CFragConnectionID		dlh;
 #endif
 
 #ifdef XP_UNIX
 #if defined(USE_HPSHL)
     shl_t			dlh;
+#elif defined(USE_RLD)
+    NXStream*			dlh;
+    int				rld_fd;
 #else
     void*			dlh;
 #endif 
 #endif 
 };
 
 static PRLibrary *pr_loadmap;
 static PRLibrary *pr_exe_loadmap;
 static PRMonitor *pr_linker_lock;
 static char* _pr_currentLibPath = NULL;
 
 /************************************************************************/
 
-#if ( !defined(USE_DLFCN) && !defined(HAVE_STRERROR) ) || defined(HPUX) || defined(BSDI) || defined(LINUX)
+#if !defined(USE_DLFCN) && !defined(HAVE_STRERROR)
 static char* errStrBuf = NULL;
 #define ERR_STR_BUF_LENGTH	20
 static char* errno_string(PRIntn oserr)
 {
     if (errStrBuf == NULL)
 	    errStrBuf = PR_MALLOC(ERR_STR_BUF_LENGTH);
-    PR_snprintf(errStrBuf, ERR_STR_BUF_LENGTH, "error %ld", oserr);
+    PR_snprintf(errStrBuf, ERR_STR_BUF_LENGTH, "error %d", oserr);
     return errStrBuf;
 }
 #endif
 
 static void DLLErrorInternal(PRIntn oserr)
 /*
 ** This whole function, and most of the code in this file, are run
 ** with a big hairy lock wrapped around it. Not the best of situations,
 ** but will eventually come up with the right answer.
 */
 {
     const char *error = NULL;
-#ifdef HAVE_DLL
-#	ifdef USE_DLFCN
-	    error = dlerror();  /* $$$ That'll be wrong some of the time - AOF */
-#	elif defined(USE_HPSHL)
-#		ifdef HAVE_STRERROR
-		    error = strerror(oserr);  /* This should be okay */
-#		else
-		    error = errno_string(oserr);
-#		endif /* HAVE_STRERROR */
-#	else
-	    error = errno_string(oserr);
-#	endif
+#ifdef USE_DLFCN
+    error = dlerror();  /* $$$ That'll be wrong some of the time - AOF */
+#elif defined(HAVE_STRERROR)
+    error = strerror(oserr);  /* this should be okay */
 #else
     error = errno_string(oserr);
-#endif /* HAVE_DLL */
+#endif
     if (NULL != error)
         PR_SetErrorText(strlen(error), error);
 }  /* DLLErrorInternal */
 
 void _PR_InitLinker(void)
 {
 #ifndef XP_MAC
     PRLibrary *lm;
@@ -162,16 +161,18 @@ void _PR_InitLinker(void)
 	    fprintf(stderr, "failed to initialize shared libraries [%s]\n",
 		    error);
 		PR_DELETE(error);
 	    abort();/* XXX */
 	}
 #elif defined(USE_HPSHL)
 	h = NULL;
 	/* don't abort with this NULL */
+#elif defined(USE_RLD)
+	h = NULL; /* XXXX  toshok */
 #else
 #error no dll strategy
 #endif /* USE_DLFCN */
 
     lm = PR_NEWZAP(PRLibrary);
     if (lm) {
         lm->name = strdup("a.out");
     	lm->refCount = 1;
@@ -274,17 +275,17 @@ PR_GetLibraryPath()
 	if (p) {
 	    strcpy(p, ev);
 	}
 	ev = p;
 	}
 #endif
 
 #ifdef XP_UNIX
-#if defined USE_DLFCN
+#if defined USE_DLFCN || defined USE_RLD
     {
 	char *home;
 	char *local;
 	char *p=NULL;
     char * mozilla_home=NULL;
 	int len;
 
 	ev = getenv("LD_LIBRARY_PATH");
@@ -635,16 +636,21 @@ PR_LoadLibrary(const char *name)
 #if defined(USE_DLFCN)
 	void *h = dlopen(name, RTLD_LAZY);
 #elif defined(USE_HPSHL)
     /*
      * Shared libraries built using aCC cannot be dynamically loaded
      * with BIND_DEFERRED, so we have to use the BIND_IMMEDIATE flag.
      */
     shl_t h = shl_load(name, BIND_IMMEDIATE | DYNAMIC_PATH, 0L);
+#elif defined(USE_RLD)
+    int fd = open(name, O_RDONLY);
+    NXStream *h = NXOpenFile(fd, NX_READONLY);
+
+    lm->rld_fd = fd;
 #else
 #error Configuration error
 #endif
 	if (!h) {
 	    PR_DELETE(lm);
 	    goto unlock;
 	}
 	lm->name = strdup(name);
@@ -701,16 +707,20 @@ PR_UnloadLibrary(PRLibrary *lib)
 	goto done;
     }
 #ifdef XP_UNIX
 #ifdef HAVE_DLL
 #ifdef USE_DLFCN
     result = dlclose(lib->dlh);
 #elif defined(USE_HPSHL)
     result = shl_unload(lib->dlh);
+#elif defined(USE_RLD)
+    result = rld_unload(lib->dlh);
+    NXClose(lib->dlh);
+    close(lib->rld_fd);
 #else
 #error Configuration error
 #endif
 #endif /* HAVE_DLL */
 #endif /* XP_UNIX */
 #ifdef XP_PC
     if (lib->dlh) {
         FreeLibrary((HINSTANCE)(lib->dlh));
@@ -811,16 +821,19 @@ pr_FindSymbolInLib(PRLibrary *lm, const 
 
 #ifdef XP_UNIX
 #ifdef HAVE_DLL
 #ifdef USE_DLFCN
     f = dlsym(lm->dlh, name);
 #elif defined(USE_HPSHL)
     if (shl_findsym(&lm->dlh, name, TYPE_PROCEDURE, &f) == -1)
 	f = NULL;
+#elif defined(USE_RLD)
+    if (rld_lookup(lm->dlh, name, (unsigned long*)&f) == -1)
+	f = NULL;
 #endif
 #endif /* HAVE_DLL */
 #endif /* XP_UNIX */
     if (f == NULL) {
         PR_SetError(PR_FIND_SYMBOL_ERROR, _MD_ERRNO());
         DLLErrorInternal(_MD_ERRNO());
     }
     return f;
--- a/pr/src/md/prosdep.c
+++ b/pr/src/md/prosdep.c
@@ -37,17 +37,17 @@ PRInt32 _pr_pageSize;
 */
 static void GetPageSize(void)
 {
 	PRInt32 pageSize;
 
     /* Get page size */
 #ifdef XP_UNIX
 #if defined SUNOS4 || defined LINUX || defined BSDI || defined AIX \
-	|| defined FREEBSD
+	|| defined FREEBSD || defined RHAPSODY
     _pr_pageSize = getpagesize();
 #elif defined(HPUX)
     /* I have no idea. Don't get me started. --Rob */
     _pr_pageSize = sysconf(_SC_PAGE_SIZE);
 #else
     _pr_pageSize = sysconf(_SC_PAGESIZE);
 #endif
 #endif /* XP_UNIX */
--- a/pr/src/md/unix/Makefile
+++ b/pr/src/md/unix/Makefile
@@ -76,16 +76,20 @@ LINUX_CSRCS = \
 UNIXWARE_CSRCS = \
 	unixware.c \
 	$(NULL)
 
 RELIANTUNIX_CSRCS = \
       reliantunix.c \
       $(NULL)
 
+RHAPSODY_CSRCS = \
+	rhapsody.c \
+	$(NULL)
+
 NEC_CSRCS = \
 	nec.c \
 	$(NULL)
 
 SONY_CSRCS = \
 	sony.c \
 	$(NULL)
 
@@ -132,16 +136,19 @@ ifeq ($(OS_ARCH),Linux)
 CSRCS += $(LINUX_CSRCS)
 endif
 ifeq ($(OS_ARCH),UNIXWARE)
 CSRCS += $(UNIXWARE_CSRCS)
 endif
 ifeq ($(OS_ARCH),SINIX)
 CSRCS += $(RELIANTUNIX_CSRCS)
 endif
+ifeq ($(OS_ARCH),Rhapsody)
+CSRCS += $(RHAPSODY_CSRCS)
+endif
 ifeq ($(OS_ARCH),NEC)
 CSRCS += $(NEC_CSRCS)
 endif
 ifeq ($(OS_ARCH),NEWS-OS)
 CSRCS += $(SONY_CSRCS)
 endif
 ifeq ($(OS_ARCH),NCR)
 CSRCS += $(NCR_CSRCS)
new file mode 100644
--- /dev/null
+++ b/pr/src/md/unix/darwin.c
@@ -0,0 +1,100 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * The contents of this file are subject to the Netscape Public License
+ * Version 1.0 (the "NPL"); you may not use this file except in
+ * compliance with the NPL.  You may obtain a copy of the NPL at
+ * http://www.mozilla.org/NPL/
+ * 
+ * Software distributed under the NPL is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
+ * for the specific language governing rights and limitations under the
+ * NPL.
+ * 
+ * The Initial Developer of this code under the NPL is Netscape
+ * Communications Corporation.  Portions created by Netscape are
+ * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
+ * Reserved.
+ */
+
+#include "primpl.h"
+
+#include <signal.h>
+
+void _MD_EarlyInit(void)
+{
+    /*
+     * Ignore FPE because coercion of a NaN to an int causes SIGFPE
+     * to be raised.
+     */
+    struct sigaction act;
+
+    act.sa_handler = SIG_IGN;
+    sigemptyset(&act.sa_mask);
+    act.sa_flags = SA_RESTART;
+    sigaction(SIGFPE, &act, 0);
+}
+
+PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
+{
+#ifndef _PR_PTHREADS
+    if (isCurrent) {
+	(void) setjmp(CONTEXT(t));
+    }
+    *np = sizeof(CONTEXT(t)) / sizeof(PRWord);
+    return (PRWord *) CONTEXT(t);
+#else
+	*np = 0;
+	return NULL;
+#endif
+}
+
+#ifndef _PR_PTHREADS
+void
+_MD_SET_PRIORITY(_MDThread *thread, PRUintn newPri)
+{
+    return;
+}
+
+PRStatus
+_MD_InitializeThread(PRThread *thread)
+{
+	return PR_SUCCESS;
+}
+
+PRStatus
+_MD_WAIT(PRThread *thread, PRIntervalTime ticks)
+{
+    PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
+    _PR_MD_SWITCH_CONTEXT(thread);
+    return PR_SUCCESS;
+}
+
+PRStatus
+_MD_WAKEUP_WAITER(PRThread *thread)
+{
+    if (thread) {
+	PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
+    }
+    return PR_SUCCESS;
+}
+
+/* These functions should not be called for OSF1 */
+void
+_MD_YIELD(void)
+{
+    PR_NOT_REACHED("_MD_YIELD should not be called for OSF1.");
+}
+
+PRStatus
+_MD_CREATE_THREAD(
+    PRThread *thread,
+    void (*start) (void *),
+    PRThreadPriority priority,
+    PRThreadScope scope,
+    PRThreadState state,
+    PRUint32 stackSize)
+{
+    PR_NOT_REACHED("_MD_CREATE_THREAD should not be called for OSF1.");
+	return PR_FAILURE;
+}
+#endif /* ! _PR_PTHREADS */
--- a/pr/src/md/unix/freebsd.c
+++ b/pr/src/md/unix/freebsd.c
@@ -73,28 +73,28 @@ PRStatus
 _MD_WAKEUP_WAITER(PRThread *thread)
 {
     if (thread) {
 	PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
     }
     return PR_SUCCESS;
 }
 
-/* These functions should not be called for OSF1 */
+/* These functions should not be called for FreeBSD */
 void
 _MD_YIELD(void)
 {
-    PR_NOT_REACHED("_MD_YIELD should not be called for OSF1.");
+    PR_NOT_REACHED("_MD_YIELD should not be called for FreeBSD.");
 }
 
 PRStatus
 _MD_CREATE_THREAD(
     PRThread *thread,
     void (*start) (void *),
     PRThreadPriority priority,
     PRThreadScope scope,
     PRThreadState state,
     PRUint32 stackSize)
 {
-    PR_NOT_REACHED("_MD_CREATE_THREAD should not be called for OSF1.");
+    PR_NOT_REACHED("_MD_CREATE_THREAD should not be called for FreeBSD.");
 	return PR_FAILURE;
 }
 #endif /* ! _PR_PTHREADS */
--- a/pr/src/md/unix/objs.mk
+++ b/pr/src/md/unix/objs.mk
@@ -68,16 +68,20 @@ LINUX_CSRCS = \
 UNIXWARE_CSRCS = \
 	unixware.c \
 	$(NULL)
 
 RELIANTUNIX_CSRCS = \
 	reliantunix.c \
 	$(NULL)
 
+RHAPSODY_CSRCS = \
+	rhapsody.c \
+	$(NULL)
+
 NEC_CSRCS = \
 	nec.c \
 	$(NULL)
 
 SONY_CSRCS = \
 	sony.c \
 	$(NULL)
 
@@ -125,16 +129,19 @@ ifeq ($(OS_ARCH),Linux)
 CSRCS += $(LINUX_CSRCS)
 endif
 ifeq ($(OS_ARCH),UNIXWARE)
 CSRCS += $(UNIXWARE_CSRCS)
 endif
 ifeq ($(OS_ARCH),SINIX)
 CSRCS += $(RELIANTUNIX_CSRCS)
 endif
+ifeq ($(OS_ARCH),Rhapsody)
+CSRCS += $(RHAPSODY_CSRCS)
+endif
 ifeq ($(OS_ARCH),NEC)
 CSRCS += $(NEC_CSRCS)
 endif
 ifeq ($(OS_ARCH),NEWS-OS)
 CSRCS += $(SONY_CSRCS)
 endif
 ifeq ($(OS_ARCH),NCR)
 CSRCS += $(NCR_CSRCS)
new file mode 100644
--- /dev/null
+++ b/pr/src/md/unix/rhapsody.c
@@ -0,0 +1,100 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * The contents of this file are subject to the Netscape Public License
+ * Version 1.0 (the "NPL"); you may not use this file except in
+ * compliance with the NPL.  You may obtain a copy of the NPL at
+ * http://www.mozilla.org/NPL/
+ * 
+ * Software distributed under the NPL is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
+ * for the specific language governing rights and limitations under the
+ * NPL.
+ * 
+ * The Initial Developer of this code under the NPL is Netscape
+ * Communications Corporation.  Portions created by Netscape are
+ * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
+ * Reserved.
+ */
+
+#include "primpl.h"
+
+#include <signal.h>
+
+void _MD_EarlyInit(void)
+{
+    /*
+     * Ignore FPE because coercion of a NaN to an int causes SIGFPE
+     * to be raised.
+     */
+    struct sigaction act;
+
+    act.sa_handler = SIG_IGN;
+    sigemptyset(&act.sa_mask);
+    act.sa_flags = SA_RESTART;
+    sigaction(SIGFPE, &act, 0);
+}
+
+PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
+{
+#ifndef _PR_PTHREADS
+    if (isCurrent) {
+	(void) setjmp(CONTEXT(t));
+    }
+    *np = sizeof(CONTEXT(t)) / sizeof(PRWord);
+    return (PRWord *) CONTEXT(t);
+#else
+	*np = 0;
+	return NULL;
+#endif
+}
+
+#ifndef _PR_PTHREADS
+void
+_MD_SET_PRIORITY(_MDThread *thread, PRUintn newPri)
+{
+    return;
+}
+
+PRStatus
+_MD_InitializeThread(PRThread *thread)
+{
+	return PR_SUCCESS;
+}
+
+PRStatus
+_MD_WAIT(PRThread *thread, PRIntervalTime ticks)
+{
+    PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
+    _PR_MD_SWITCH_CONTEXT(thread);
+    return PR_SUCCESS;
+}
+
+PRStatus
+_MD_WAKEUP_WAITER(PRThread *thread)
+{
+    if (thread) {
+	PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
+    }
+    return PR_SUCCESS;
+}
+
+/* These functions should not be called for OSF1 */
+void
+_MD_YIELD(void)
+{
+    PR_NOT_REACHED("_MD_YIELD should not be called for OSF1.");
+}
+
+PRStatus
+_MD_CREATE_THREAD(
+    PRThread *thread,
+    void (*start) (void *),
+    PRThreadPriority priority,
+    PRThreadScope scope,
+    PRThreadState state,
+    PRUint32 stackSize)
+{
+    PR_NOT_REACHED("_MD_CREATE_THREAD should not be called for OSF1.");
+	return PR_FAILURE;
+}
+#endif /* ! _PR_PTHREADS */
--- a/pr/src/md/unix/unix.c
+++ b/pr/src/md/unix/unix.c
@@ -43,17 +43,17 @@
  * PRInt32* pointer to a _PRSockLen_t* pointer.
  */
 #if defined(IRIX) || defined(HPUX) || defined(OSF1) || defined(SOLARIS) \
     || defined(AIX4_1) || defined(LINUX) || defined(SONY) \
     || defined(BSDI) || defined(SCO) || defined(NEC) || defined(SNI) \
     || defined(SUNOS4) || defined(NCR)
 #define _PRSockLen_t int
 #elif (defined(AIX) && !defined(AIX4_1)) || defined(FREEBSD) \
-    || defined(UNIXWARE)
+    || defined(UNIXWARE) || defined(RHAPSODY)
 #define _PRSockLen_t size_t
 #else
 #error "Cannot determine architecture"
 #endif
 
 /*
 ** Global lock variable used to bracket calls into rusty libraries that
 ** aren't thread safe (like libc, libX, etc).
--- a/pr/src/md/unix/unix_errors.c
+++ b/pr/src/md/unix/unix_errors.c
@@ -155,17 +155,17 @@ void _MD_unix_map_unlink_error(int err)
 			PR_SetError(PR_NOT_DIRECTORY_ERROR, err);
 			break;
 		case EPERM:
 			PR_SetError(PR_IS_DIRECTORY_ERROR, err);
 			break;
 		case EROFS:
 			PR_SetError(PR_READ_ONLY_FILESYSTEM_ERROR, err);
 			break;
-#if !defined(OSF1) && !defined(FREEBSD) && !defined(BSDI)
+#if !defined(OSF1) && !defined(FREEBSD) && !defined(BSDI) && !defined(RHAPSODY)
 		case EMULTIHOP:
 		case ENOLINK:
 			PR_SetError(PR_REMOTE_FILE_ERROR, err);
 			break;
 #endif
 		default:
 			PR_SetError(PR_UNKNOWN_ERROR, err);
 			break;
@@ -180,17 +180,17 @@ void _MD_unix_map_stat_error(int err)
 			break;
 		case EFAULT:
 			PR_SetError(PR_ACCESS_FAULT_ERROR, err);
 			break;
 		case EINTR:
 			PR_SetError(PR_PENDING_INTERRUPT_ERROR, err);
 			break;
 		case ETIMEDOUT:
-#if !defined(OSF1) && !defined(FREEBSD) && !defined(BSDI)
+#if !defined(OSF1) && !defined(FREEBSD) && !defined(BSDI) && !defined(RHAPSODY)
 		case EMULTIHOP:
 		case ENOLINK:
 #endif
 			PR_SetError(PR_REMOTE_FILE_ERROR, err);
 			break;
 		case ELOOP:
 			PR_SetError(PR_LOOP_ERROR, err);
 			break;
@@ -273,17 +273,17 @@ void _MD_unix_map_rename_error(int err)
 			PR_SetError(PR_IO_ERROR, err);
 			break;
 		case EISDIR:
 			PR_SetError(PR_IS_DIRECTORY_ERROR, err);
 			break;
 		case ELOOP:
 			PR_SetError(PR_LOOP_ERROR, err);
 			break;
-#if !defined(OSF1) && !defined(FREEBSD) && !defined(BSDI)
+#if !defined(OSF1) && !defined(FREEBSD) && !defined(BSDI) && !defined(RHAPSODY)
 		case EMULTIHOP:
 		case ENOLINK:
 			PR_SetError(PR_REMOTE_FILE_ERROR, err);
 			break;
 #endif
 		case ENAMETOOLONG:
 			PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
 			break;
@@ -324,17 +324,17 @@ void _MD_unix_map_access_error(int err)
 			PR_SetError(PR_PENDING_INTERRUPT_ERROR, err);
 			break;
 		case EINVAL:
 			PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
 			break;
 		case ELOOP:
 			PR_SetError(PR_LOOP_ERROR, err);
 			break;
-#if !defined(OSF1) && !defined(FREEBSD) && !defined(BSDI)
+#if !defined(OSF1) && !defined(FREEBSD) && !defined(BSDI) && !defined(RHAPSODY)
 		case EMULTIHOP:
 		case ENOLINK:
 #endif
 		case ETIMEDOUT:
 			PR_SetError(PR_REMOTE_FILE_ERROR, err);
 			break;
 		case ENAMETOOLONG:
 			PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
@@ -390,17 +390,17 @@ void _MD_unix_map_mkdir_error(int err)
 #ifdef EDQUOT
 		case EDQUOT:
 			PR_SetError(PR_NO_DEVICE_SPACE_ERROR, err);
 			break;
 #endif
 		case EIO:
 			PR_SetError(PR_IO_ERROR, err);
 			break;
-#if !defined(OSF1) && !defined(FREEBSD) && !defined(BSDI)
+#if !defined(OSF1) && !defined(FREEBSD) && !defined(BSDI) && !defined(RHAPSODY)
 		case EMULTIHOP:
 		case ENOLINK:
 			PR_SetError(PR_REMOTE_FILE_ERROR, err);
 			break;
 #endif
 		default:
 			PR_SetError(PR_UNKNOWN_ERROR, err);
 			break;
@@ -427,17 +427,17 @@ void _MD_unix_map_rmdir_error(int err)
 			PR_SetError(PR_DIRECTORY_NOT_EMPTY_ERROR, err);
 			break;
 		case EIO:
 			PR_SetError(PR_IO_ERROR, err);
 			break;
 		case ELOOP:
 			PR_SetError(PR_LOOP_ERROR, err);
 			break;
-#if !defined(OSF1) && !defined(FREEBSD) && !defined(BSDI)
+#if !defined(OSF1) && !defined(FREEBSD) && !defined(BSDI) && !defined(RHAPSODY)
 		case EMULTIHOP:
 		case ENOLINK:
 #endif
 		case ETIMEDOUT:
 			PR_SetError(PR_REMOTE_FILE_ERROR, err);
 			break;
 		case ENAMETOOLONG:
 			PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
@@ -1340,17 +1340,17 @@ void _MD_unix_map_open_error(int err)
 			break;
 		case ENOTDIR:
 			PR_SetError(PR_NOT_DIRECTORY_ERROR, err);
 			break;
 		case EPERM:
 			PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
 			break;
 		case ETIMEDOUT:
-#if !defined(OSF1) && !defined(FREEBSD) && !defined(BSDI)
+#if !defined(OSF1) && !defined(FREEBSD) && !defined(BSDI) && !defined(RHAPSODY)
 		case EMULTIHOP:
 		case ENOLINK:
 #endif
 			PR_SetError(PR_REMOTE_FILE_ERROR, err);
 			break;
 		case EROFS:
 			PR_SetError(PR_READ_ONLY_FILESYSTEM_ERROR, err);
 			break;
--- a/pr/src/md/unix/uxwrap.c
+++ b/pr/src/md/unix/uxwrap.c
@@ -291,20 +291,20 @@ int select(int width, fd_set *rd, fd_set
     PR_ASSERT(tv || retVal != 0);
     PR_LOG(_pr_io_lm, PR_LOG_MIN, ("select returns %d", retVal));
     PR_DELETE(pollset);
 
     return retVal;
 }
 
 /*
- * Linux, BSDI, and FreeBSD don't have poll()
+ * Linux, BSDI, FreeBSD, and Rhapsody don't have poll().
  */
 
-#if !defined(LINUX) && !defined(FREEBSD) && !defined(BSDI)
+#if !defined(LINUX) && !defined(FREEBSD) && !defined(BSDI) && !defined(RHAPSODY)
 
 /*
  *-----------------------------------------------------------------------
  * poll() --
  *
  * RETURN VALUES: 
  *     -1:  fails, errno indicates the error.
  *      0:  timed out, the revents bitmasks are not set.
--- a/pr/src/memory/prseg.c
+++ b/pr/src/memory/prseg.c
@@ -144,32 +144,34 @@ PR_IMPLEMENT(PRUint32) PR_GrowSegment(PR
 ** it.
 */
 PR_IMPLEMENT(void) PR_MapSegment(PRSegment *seg, PRSegmentAccess how)
 {
     if (seg->access == how) return;
     seg->access = how;
 
 #ifdef XP_UNIX
+#ifndef RHAPSODY
     if (seg->flags & _PR_SEG_VM) {
 	int prot;
 	switch (how) {
 	  case PR_SEGMENT_NONE:
 	    prot = PROT_NONE;
 	    break;
 	  case PR_SEGMENT_RDONLY:
 	    prot = PROT_READ;
 	    break;
 	  case PR_SEGMENT_RDWR:
 	    prot = PROT_READ|PROT_WRITE;
 	    break;
 	}
 	(void) mprotect(seg->vaddr, seg->size, prot);
     }
 #endif
+#endif
 }
 
 /*
 ** Return the size of the segment
 */
 PR_IMPLEMENT(size_t) PR_GetSegmentSize(PRSegment *seg)
 {
     return seg->size;