home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / pr / src / md / unix / aix.c next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  3.9 KB  |  166 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /*
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  * 
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  * 
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #include "primpl.h"
  20.  
  21. /*
  22.  * NSPR 2.0 overrides the system select() and poll() functions.
  23.  * On AIX 4.2, we use dlopen("/unix", 0) and dlsym() to get to the
  24.  * original system select() and poll() functions.
  25.  */
  26.  
  27. #ifndef AIX4_1
  28.  
  29. #include <sys/select.h>
  30. #include <sys/poll.h>
  31. #include <dlfcn.h>
  32.  
  33. static void *aix_handle = NULL;
  34. static int (*aix_select_fcn)() = NULL;
  35. static int (*aix_poll_fcn)() = NULL;
  36.  
  37. int _MD_SELECT(int width, fd_set *r, fd_set *w, fd_set *e, struct timeval *t)
  38. {
  39.     int rv;
  40.  
  41.     if (!aix_select_fcn) {
  42.     if (!aix_handle) {
  43.         aix_handle = dlopen("/unix",0);
  44.         if (!aix_handle) {
  45.             PR_SetError(PR_UNKNOWN_ERROR, 0);
  46.             return -1;
  47.         }
  48.     }
  49.     aix_select_fcn = (int(*)())dlsym(aix_handle,"select");
  50.     if (!aix_select_fcn) {
  51.         PR_SetError(PR_UNKNOWN_ERROR, 0);
  52.         return -1;
  53.     }
  54.     }
  55.     rv = (*aix_select_fcn)(width, r, w, e, t);
  56.     return rv;
  57. }
  58.  
  59. int _MD_POLL(void *listptr, unsigned long nfds, long timeout)
  60. {
  61.     int rv;
  62.  
  63.     if (!aix_poll_fcn) {
  64.     if (!aix_handle) {
  65.         aix_handle = dlopen("/unix",0);
  66.         if (!aix_handle) {
  67.             PR_SetError(PR_UNKNOWN_ERROR, 0);
  68.             return -1;
  69.         }
  70.     }
  71.     aix_poll_fcn = (int(*)())dlsym(aix_handle,"poll");
  72.     if (!aix_poll_fcn) {
  73.         PR_SetError(PR_UNKNOWN_ERROR, 0);
  74.         return -1;
  75.     }
  76.     }
  77.     rv = (*aix_poll_fcn)(listptr, nfds, timeout);
  78.     return rv;
  79. }
  80.  
  81. #else
  82.  
  83. /*
  84.  * In AIX versions prior to 4.2, we use the two-step rename/link trick.
  85.  * The binary must contain at least one "poll" symbol for linker's rename
  86.  * to work.  So we must have this dummy function that references poll().
  87.  */
  88. #include <sys/poll.h>
  89. void _pr_aix_dummy()
  90. {
  91.     poll(0,0,0);
  92. }
  93.  
  94. #endif /* !AIX4_1 */
  95.  
  96. #if !defined(PTHREADS_USER)
  97.  
  98. void _MD_EarlyInit(void)
  99. {
  100. }
  101.  
  102. PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
  103. {
  104. #ifndef _PR_PTHREADS
  105.     if (isCurrent) {
  106.     (void) setjmp(CONTEXT(t));
  107.     }
  108.     *np = sizeof(CONTEXT(t)) / sizeof(PRWord);
  109.     return (PRWord *) CONTEXT(t);
  110. #else
  111.     *np = 0;
  112.     return NULL;
  113. #endif
  114. }
  115.  
  116. #ifndef _PR_PTHREADS
  117. PR_IMPLEMENT(void)
  118. _MD_SET_PRIORITY(_MDThread *thread, PRUintn newPri)
  119. {
  120.     return;
  121. }
  122.  
  123. PR_IMPLEMENT(PRStatus)
  124. _MD_InitializeThread(PRThread *thread)
  125. {
  126.     return PR_SUCCESS;
  127. }
  128.  
  129. PR_IMPLEMENT(PRStatus)
  130. _MD_WAIT(PRThread *thread, PRIntervalTime ticks)
  131. {
  132.     PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
  133.     _PR_MD_SWITCH_CONTEXT(thread);
  134.     return PR_SUCCESS;
  135. }
  136.  
  137. PR_IMPLEMENT(PRStatus)
  138. _MD_WAKEUP_WAITER(PRThread *thread)
  139. {
  140.     if (thread) {
  141.     PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
  142.     }
  143.     return PR_SUCCESS;
  144. }
  145.  
  146. /* These functions should not be called for AIX */
  147. PR_IMPLEMENT(void)
  148. _MD_YIELD(void)
  149. {
  150.     PR_NOT_REACHED("_MD_YIELD should not be called for AIX.");
  151. }
  152.  
  153. PR_IMPLEMENT(PRStatus)
  154. _MD_CREATE_THREAD(
  155.     PRThread *thread,
  156.     void (*start) (void *),
  157.     PRThreadPriority priority,
  158.     PRThreadScope scope,
  159.     PRThreadState state,
  160.     PRUint32 stackSize)
  161. {
  162.     PR_NOT_REACHED("_MD_CREATE_THREAD should not be called for AIX.");
  163. }
  164. #endif /* _PR_PTHREADS */
  165. #endif /* PTHREADS_USER */
  166.