home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 15 / 15.iso / s / s053 / 9.ddi / usr / include / vm / faultcatch.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-08  |  2.9 KB  |  102 lines

  1. /*    Copyright (c) 1990 UNIX System Laboratories, Inc.    */
  2. /*    Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T    */
  3. /*      All Rights Reserved      */
  4.  
  5. /*    THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF         */
  6. /*    UNIX System Laboratories, Inc.                         */
  7. /*    The copyright notice above does not evidence any       */
  8. /*    actual or intended publication of such source code.    */
  9.  
  10. #ifndef _VM_FAULTCATCH_H
  11. #define _VM_FAULTCATCH_H
  12.  
  13. #ident    "@(#)/usr/include/vm/faultcatch..sl 1.1 4.0 12/08/90 33222 AT&T-USL"
  14.  
  15. /*
  16.  * This file defines a mechanism for catching kernel page fault errors.
  17.  * Any access to a pageable address should be protected by this mechanism,
  18.  * since the I/O may fail, or (in the case of a user-supplied address)
  19.  * the address may be invalid.
  20.  *
  21.  * Usage:
  22.  *        CATCH_FAULTS(flags)
  23.  *            protected_statement
  24.  *        errno = END_CATCH();
  25.  *
  26.  * The flags define the type of address to protect.  This includes user
  27.  * addresses, seg_u addresses, and seg_map addresses.
  28.  *
  29.  * The value returned by END_CATCH() will be 0 if no fault error occurred,
  30.  * or the errno returned from the fault handler (unless the error occurred
  31.  * on a user address, in which case the fault handler's return value is
  32.  * ignored and EFAULT is returned).
  33.  *
  34.  * Caveats:
  35.  *
  36.  * CATCH_FAULTS should not be used from interrupt routines, or
  37.  * nested within another CATCH_FAULTS.
  38.  *
  39.  * The protected code must not do anything stateful, such as using spl's
  40.  * or setting locks, since it may be aborted in midstream.
  41.  */
  42.  
  43. #define CATCH_UFAULT        0x0001
  44. #define CATCH_SEGMAP_FAULT    0x0002
  45. #define CATCH_SEGU_FAULT    0x0004
  46. #define CATCH_BUS_TIMEOUT    0x4000
  47. #define CATCH_ALL_FAULTS    0x8000
  48.  
  49. #define CATCH_KERNEL_FAULTS    (CATCH_SEGMAP_FAULT|CATCH_SEGU_FAULT)
  50.  
  51. #if !defined(LOCORE)
  52.  
  53. #include <sys/types.h>
  54.  
  55. typedef struct fault_catch {
  56.     u_int    fc_flags;
  57.     int    fc_errno;
  58.     void    (*fc_func)();
  59.     label_t    fc_jmp;
  60. } fault_catch_t;
  61.  
  62. #if defined(_KERNEL)
  63.  
  64. /* NOTE: Although the implementation of CATCH_FAULTS() uses setjmp/longjmp,
  65.  * the enclosed code MUST NOT do anything stateful, since it could be aborted
  66.  * at any point.  This applies to multiprocessing locks as well, so this
  67.  * particular use of setjmp/longjmp is safe in a multiprocessor context.
  68.  */
  69.  
  70. #if DEBUG == 1
  71.  
  72. #include <sys/debug.h>
  73.  
  74. #define CATCH_FAULTS(flags) \
  75.     if (ASSERT(!servicing_interrupt()), \
  76.         ASSERT(u.u_fault_catch.fc_flags == 0), \
  77.         (u.u_fault_catch.fc_errno = 0), \
  78.         (u.u_fault_catch.fc_flags = (flags)), \
  79.         setjmp(&u.u_fault_catch.fc_jmp) == 0)
  80. #else
  81. #define CATCH_FAULTS(flags) \
  82.     if ((u.u_fault_catch.fc_errno = 0), \
  83.         (u.u_fault_catch.fc_flags = (flags)), \
  84.         setjmp(&u.u_fault_catch.fc_jmp) == 0)
  85. #endif
  86.  
  87. #define END_CATCH() \
  88.     ((u.u_fault_catch.fc_flags = 0), \
  89.      u.u_fault_catch.fc_errno)
  90.  
  91. #if defined(__STDC__)
  92. extern void    fc_jmpjmp(void);
  93. #else
  94. extern void    fc_jmpjmp();
  95. #endif    /* __STDC__ */
  96.  
  97. #endif    /* _KERNEL */
  98.  
  99. #endif    /* not LOCORE */
  100.  
  101. #endif    /* _VM_FAULTCATCH_H */
  102.