ppp_mod.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. * Miscellaneous definitions for PPP STREAMS modules.
  3. */
  4. /*
  5. * Macros for allocating and freeing kernel memory.
  6. */
  7. #ifdef SVR4 /* SVR4, including Solaris 2 */
  8. #include <sys/kmem.h>
  9. #define ALLOC_SLEEP(n) kmem_alloc((n), KM_SLEEP)
  10. #define ALLOC_NOSLEEP(n) kmem_alloc((n), KM_NOSLEEP)
  11. #define FREE(p, n) kmem_free((p), (n))
  12. #endif
  13. #ifdef SUNOS4
  14. #include <sys/kmem_alloc.h> /* SunOS 4.x */
  15. #define ALLOC_SLEEP(n) kmem_alloc((n), KMEM_SLEEP)
  16. #define ALLOC_NOSLEEP(n) kmem_alloc((n), KMEM_NOSLEEP)
  17. #define FREE(p, n) kmem_free((p), (n))
  18. #define NOTSUSER() (suser()? 0: EPERM)
  19. #define bcanputnext(q, band) canputnext((q))
  20. #endif /* SunOS 4 */
  21. #ifdef __osf__
  22. #include <sys/malloc.h>
  23. /* caution: this mirrors macros in sys/malloc.h, and uses interfaces
  24. * which are subject to change.
  25. * The problems are that:
  26. * - the official MALLOC macro wants the lhs of the assignment as an argument,
  27. * and it takes care of the assignment itself (yuck.)
  28. * - PPP insists on using "FREE" which conflicts with a macro of the same name.
  29. *
  30. */
  31. #ifdef BUCKETINDX /* V2.0 */
  32. #define ALLOC_SLEEP(n) (void *)malloc((u_long)(n), BUCKETP(n), M_DEVBUF, M_WAITOK)
  33. #define ALLOC_NOSLEEP(n) (void *)malloc((u_long)(n), BUCKETP(n), M_DEVBUF, M_NOWAIT)
  34. #else
  35. #define ALLOC_SLEEP(n) (void *)malloc((u_long)(n), BUCKETINDEX(n), M_DEVBUF, M_WAITOK)
  36. #define ALLOC_NOSLEEP(n) (void *)malloc((u_long)(n), BUCKETINDEX(n), M_DEVBUF, M_NOWAIT)
  37. #endif
  38. #define bcanputnext(q, band) canputnext((q))
  39. #ifdef FREE
  40. #undef FREE
  41. #endif
  42. #define FREE(p, n) free((void *)(p), M_DEVBUF)
  43. #define NO_DLPI 1
  44. #ifndef IFT_PPP
  45. #define IFT_PPP 0x17
  46. #endif
  47. #include <sys/proc.h>
  48. #define NOTSUSER() (suser(u.u_procp->p_rcred, &u.u_acflag) ? EPERM : 0)
  49. /* #include "ppp_osf.h" */
  50. #endif /* __osf__ */
  51. #ifdef AIX4
  52. #define ALLOC_SLEEP(n) xmalloc((n), 0, pinned_heap) /* AIX V4.x */
  53. #define ALLOC_NOSLEEP(n) xmalloc((n), 0, pinned_heap) /* AIX V4.x */
  54. #define FREE(p, n) xmfree((p), pinned_heap)
  55. #define NOTSUSER() (suser()? 0: EPERM)
  56. #endif /* AIX */
  57. /*
  58. * Macros for printing debugging stuff.
  59. */
  60. #ifdef DEBUG
  61. #if defined(SVR4) || defined(__osf__)
  62. #if defined(SNI)
  63. #include <sys/strlog.h>
  64. #define STRLOG_ID 4712
  65. #define DPRINT(f) strlog(STRLOG_ID, 0, 0, SL_TRACE, f)
  66. #define DPRINT1(f, a1) strlog(STRLOG_ID, 0, 0, SL_TRACE, f, a1)
  67. #define DPRINT2(f, a1, a2) strlog(STRLOG_ID, 0, 0, SL_TRACE, f, a1, a2)
  68. #define DPRINT3(f, a1, a2, a3) strlog(STRLOG_ID, 0, 0, SL_TRACE, f, a1, a2, a3)
  69. #else
  70. #define DPRINT(f) cmn_err(CE_CONT, f)
  71. #define DPRINT1(f, a1) cmn_err(CE_CONT, f, a1)
  72. #define DPRINT2(f, a1, a2) cmn_err(CE_CONT, f, a1, a2)
  73. #define DPRINT3(f, a1, a2, a3) cmn_err(CE_CONT, f, a1, a2, a3)
  74. #endif /* SNI */
  75. #else
  76. #define DPRINT(f) printf(f)
  77. #define DPRINT1(f, a1) printf(f, a1)
  78. #define DPRINT2(f, a1, a2) printf(f, a1, a2)
  79. #define DPRINT3(f, a1, a2, a3) printf(f, a1, a2, a3)
  80. #endif /* SVR4 or OSF */
  81. #else
  82. #define DPRINT(f) 0
  83. #define DPRINT1(f, a1) 0
  84. #define DPRINT2(f, a1, a2) 0
  85. #define DPRINT3(f, a1, a2, a3) 0
  86. #endif /* DEBUG */
  87. #ifndef SVR4
  88. typedef unsigned char uchar_t;
  89. typedef unsigned short ushort_t;
  90. #ifndef __osf__
  91. typedef int minor_t;
  92. #endif
  93. #endif
  94. /*
  95. * If we don't have multithreading support, define substitutes.
  96. */
  97. #ifndef D_MP
  98. # define qprocson(q)
  99. # define qprocsoff(q)
  100. # define put(q, mp) ((*(q)->q_qinfo->qi_putp)((q), (mp)))
  101. # define canputnext(q) canput((q)->q_next)
  102. # define qwriter(q, mp, func, scope) (func)((q), (mp))
  103. #endif
  104. #ifdef D_MP
  105. /* Use msgpullup if we have other multithreading support. */
  106. #define PULLUP(mp, len) \
  107. do { \
  108. mblk_t *np = msgpullup((mp), (len)); \
  109. freemsg((mp)); \
  110. mp = np; \
  111. } while (0)
  112. #else
  113. /* Use pullupmsg if we don't have any multithreading support. */
  114. #define PULLUP(mp, len) \
  115. do { \
  116. if (!pullupmsg((mp), (len))) { \
  117. freemsg((mp)); \
  118. mp = 0; \
  119. } \
  120. } while (0)
  121. #endif
  122. /*
  123. * How to declare the open and close procedures for a module.
  124. */
  125. #ifdef SVR4
  126. #define MOD_OPEN_DECL(name) \
  127. static int name __P((queue_t *, dev_t *, int, int, cred_t *))
  128. #define MOD_CLOSE_DECL(name) \
  129. static int name __P((queue_t *, int, cred_t *))
  130. #define MOD_OPEN(name) \
  131. static int name(q, devp, flag, sflag, credp) \
  132. queue_t *q; \
  133. dev_t *devp; \
  134. int flag, sflag; \
  135. cred_t *credp;
  136. #define MOD_CLOSE(name) \
  137. static int name(q, flag, credp) \
  138. queue_t *q; \
  139. int flag; \
  140. cred_t *credp;
  141. #define OPEN_ERROR(x) return (x)
  142. #define DRV_OPEN_OK(dev) return 0
  143. #define NOTSUSER() (drv_priv(credp))
  144. #else /* not SVR4 */
  145. #define MOD_OPEN_DECL(name) \
  146. static int name __P((queue_t *, int, int, int))
  147. #define MOD_CLOSE_DECL(name) \
  148. static int name __P((queue_t *, int))
  149. #define MOD_OPEN(name) \
  150. static int name(q, dev, flag, sflag) \
  151. queue_t *q; \
  152. int dev; \
  153. int flag, sflag;
  154. #define MOD_CLOSE(name) \
  155. static int name(q, flag) \
  156. queue_t *q; \
  157. int flag;
  158. #define OPEN_ERROR(x) { u.u_error = (x); return OPENFAIL; }
  159. #define DRV_OPEN_OK(dev) return (dev)
  160. #endif /* SVR4 */