Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenlinux.h
Go to the documentation of this file.
00001 #pragma once 00002 00003 #include <ntddk.h> 00004 00005 #ifndef NULL 00006 #define NULL (void*)0 00007 #endif 00008 00009 typedef struct page { 00010 int x; 00011 } mem_map_t; 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 00023 00024 00025 /* i386 */ 00026 00027 typedef unsigned short umode_t; 00028 00029 /* 00030 * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the 00031 * header files exported to user space 00032 */ 00033 00034 typedef __signed__ char __s8; 00035 typedef unsigned char __u8; 00036 00037 typedef __signed__ short __s16; 00038 typedef unsigned short __u16; 00039 00040 typedef __signed__ int __s32; 00041 typedef unsigned int __u32; 00042 00043 #if defined(__GNUC__) && !defined(__STRICT_ANSI__) 00044 typedef __signed__ long long __s64; 00045 typedef unsigned long long __u64; 00046 #endif 00047 00048 /* 00049 * These aren't exported outside the kernel to avoid name space clashes 00050 */ 00051 typedef signed char s8; 00052 typedef unsigned char u8; 00053 00054 typedef signed short s16; 00055 typedef unsigned short u16; 00056 00057 typedef signed int s32; 00058 typedef unsigned int u32; 00059 00060 typedef signed long long s64; 00061 typedef unsigned long long u64; 00062 00063 #define BITS_PER_LONG 32 00064 00065 /* DMA addresses come in generic and 64-bit flavours. */ 00066 00067 #ifdef CONFIG_HIGHMEM64G 00068 typedef u64 dma_addr_t; 00069 #else 00070 typedef u32 dma_addr_t; 00071 #endif 00072 typedef u64 dma64_addr_t; 00073 00074 00075 00076 /* 00077 * This allows for 1024 file descriptors: if NR_OPEN is ever grown 00078 * beyond that you'll have to change this too. But 1024 fd's seem to be 00079 * enough even for such "real" unices like OSF/1, so hopefully this is 00080 * one limit that doesn't have to be changed [again]. 00081 * 00082 * Note that POSIX wants the FD_CLEAR(fd,fdsetp) defines to be in 00083 * <sys/time.h> (and thus <linux/time.h>) - but this is a more logical 00084 * place for them. Solved by having dummy defines in <sys/time.h>. 00085 */ 00086 00087 /* 00088 * Those macros may have been defined in <gnu/types.h>. But we always 00089 * use the ones here. 00090 */ 00091 #undef __NFDBITS 00092 #define __NFDBITS (8 * sizeof(unsigned long)) 00093 00094 #undef __FD_SETSIZE 00095 #define __FD_SETSIZE 1024 00096 00097 #undef __FDSET_LONGS 00098 #define __FDSET_LONGS (__FD_SETSIZE/__NFDBITS) 00099 00100 #undef __FDELT 00101 #define __FDELT(d) ((d) / __NFDBITS) 00102 00103 #undef __FDMASK 00104 #define __FDMASK(d) (1UL << ((d) % __NFDBITS)) 00105 00106 typedef struct { 00107 unsigned long fds_bits [__FDSET_LONGS]; 00108 } __kernel_fd_set; 00109 00110 /* Type of a signal handler. */ 00111 typedef void (*__kernel_sighandler_t)(int); 00112 00113 /* Type of a SYSV IPC key. */ 00114 typedef int __kernel_key_t; 00115 00116 00117 /* 00118 * This file is generally used by user-level software, so you need to 00119 * be a little careful about namespace pollution etc. Also, we cannot 00120 * assume GCC is being used. 00121 */ 00122 00123 typedef unsigned short __kernel_dev_t; 00124 typedef unsigned long __kernel_ino_t; 00125 typedef unsigned short __kernel_mode_t; 00126 typedef unsigned short __kernel_nlink_t; 00127 typedef long __kernel_off_t; 00128 typedef int __kernel_pid_t; 00129 typedef unsigned short __kernel_ipc_pid_t; 00130 typedef unsigned short __kernel_uid_t; 00131 typedef unsigned short __kernel_gid_t; 00132 typedef unsigned int __kernel_size_t; 00133 typedef int __kernel_ssize_t; 00134 typedef int __kernel_ptrdiff_t; 00135 typedef long __kernel_time_t; 00136 typedef long __kernel_suseconds_t; 00137 typedef long __kernel_clock_t; 00138 typedef int __kernel_daddr_t; 00139 typedef char * __kernel_caddr_t; 00140 typedef unsigned short __kernel_uid16_t; 00141 typedef unsigned short __kernel_gid16_t; 00142 typedef unsigned int __kernel_uid32_t; 00143 typedef unsigned int __kernel_gid32_t; 00144 00145 typedef unsigned short __kernel_old_uid_t; 00146 typedef unsigned short __kernel_old_gid_t; 00147 00148 #ifdef __GNUC__ 00149 typedef long long __kernel_loff_t; 00150 #endif 00151 00152 typedef struct { 00153 #if defined(__KERNEL__) || defined(__USE_ALL) 00154 int val[2]; 00155 #else /* !defined(__KERNEL__) && !defined(__USE_ALL) */ 00156 int __val[2]; 00157 #endif /* !defined(__KERNEL__) && !defined(__USE_ALL) */ 00158 } __kernel_fsid_t; 00159 00160 #if defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2) 00161 00162 #undef __FD_SET 00163 #define __FD_SET(fd,fdsetp) \ 00164 __asm__ __volatile__("btsl %1,%0": \ 00165 "=m" (*(__kernel_fd_set *) (fdsetp)):"r" ((int) (fd))) 00166 00167 #undef __FD_CLR 00168 #define __FD_CLR(fd,fdsetp) \ 00169 __asm__ __volatile__("btrl %1,%0": \ 00170 "=m" (*(__kernel_fd_set *) (fdsetp)):"r" ((int) (fd))) 00171 00172 #undef __FD_ISSET 00173 #define __FD_ISSET(fd,fdsetp) (__extension__ ({ \ 00174 unsigned char __result; \ 00175 __asm__ __volatile__("btl %1,%2 ; setb %0" \ 00176 :"=q" (__result) :"r" ((int) (fd)), \ 00177 "m" (*(__kernel_fd_set *) (fdsetp))); \ 00178 __result; })) 00179 00180 #undef __FD_ZERO 00181 #define __FD_ZERO(fdsetp) \ 00182 do { \ 00183 int __d0, __d1; \ 00184 __asm__ __volatile__("cld ; rep ; stosl" \ 00185 :"=m" (*(__kernel_fd_set *) (fdsetp)), \ 00186 "=&c" (__d0), "=&D" (__d1) \ 00187 :"a" (0), "1" (__FDSET_LONGS), \ 00188 "2" ((__kernel_fd_set *) (fdsetp)) : "memory"); \ 00189 } while (0) 00190 00191 #endif /* defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2) */ 00192 00193 00194 #ifndef __KERNEL_STRICT_NAMES 00195 00196 typedef __kernel_fd_set fd_set; 00197 typedef __kernel_dev_t dev_t; 00198 typedef __kernel_ino_t ino_t; 00199 typedef __kernel_mode_t mode_t; 00200 typedef __kernel_nlink_t nlink_t; 00201 typedef __kernel_off_t off_t; 00202 typedef __kernel_pid_t pid_t; 00203 typedef __kernel_daddr_t daddr_t; 00204 typedef __kernel_key_t key_t; 00205 typedef __kernel_suseconds_t suseconds_t; 00206 00207 #ifdef __KERNEL__ 00208 typedef __kernel_uid32_t uid_t; 00209 typedef __kernel_gid32_t gid_t; 00210 typedef __kernel_uid16_t uid16_t; 00211 typedef __kernel_gid16_t gid16_t; 00212 00213 #ifdef CONFIG_UID16 00214 /* This is defined by include/asm-{arch}/posix_types.h */ 00215 typedef __kernel_old_uid_t old_uid_t; 00216 typedef __kernel_old_gid_t old_gid_t; 00217 #endif /* CONFIG_UID16 */ 00218 00219 /* libc5 includes this file to define uid_t, thus uid_t can never change 00220 * when it is included by non-kernel code 00221 */ 00222 #else 00223 typedef __kernel_uid_t uid_t; 00224 typedef __kernel_gid_t gid_t; 00225 #endif /* __KERNEL__ */ 00226 00227 #if defined(__GNUC__) 00228 typedef __kernel_loff_t loff_t; 00229 #endif 00230 00231 /* 00232 * The following typedefs are also protected by individual ifdefs for 00233 * historical reasons: 00234 */ 00235 #ifndef _SIZE_T 00236 #define _SIZE_T 00237 typedef __kernel_size_t size_t; 00238 #endif 00239 00240 #ifndef _SSIZE_T 00241 #define _SSIZE_T 00242 typedef __kernel_ssize_t ssize_t; 00243 #endif 00244 00245 #ifndef _PTRDIFF_T 00246 #define _PTRDIFF_T 00247 typedef __kernel_ptrdiff_t ptrdiff_t; 00248 #endif 00249 00250 #ifndef _TIME_T 00251 #define _TIME_T 00252 typedef __kernel_time_t time_t; 00253 #endif 00254 00255 #ifndef _CLOCK_T 00256 #define _CLOCK_T 00257 typedef __kernel_clock_t clock_t; 00258 #endif 00259 00260 #ifndef _CADDR_T 00261 #define _CADDR_T 00262 typedef __kernel_caddr_t caddr_t; 00263 #endif 00264 00265 /* bsd */ 00266 typedef unsigned char u_char; 00267 typedef unsigned short u_short; 00268 typedef unsigned int u_int; 00269 typedef unsigned long u_long; 00270 00271 /* sysv */ 00272 typedef unsigned char unchar; 00273 typedef unsigned short ushort; 00274 typedef unsigned int uint; 00275 typedef unsigned long ulong; 00276 00277 #ifndef __BIT_TYPES_DEFINED__ 00278 #define __BIT_TYPES_DEFINED__ 00279 00280 typedef __u8 u_int8_t; 00281 typedef __s8 int8_t; 00282 typedef __u16 u_int16_t; 00283 typedef __s16 int16_t; 00284 typedef __u32 u_int32_t; 00285 typedef __s32 int32_t; 00286 00287 #endif /* !(__BIT_TYPES_DEFINED__) */ 00288 00289 typedef __u8 uint8_t; 00290 typedef __u16 uint16_t; 00291 typedef __u32 uint32_t; 00292 00293 #if defined(__GNUC__) && !defined(__STRICT_ANSI__) 00294 typedef __u64 uint64_t; 00295 typedef __u64 u_int64_t; 00296 typedef __s64 int64_t; 00297 #endif 00298 00299 #endif /* __KERNEL_STRICT_NAMES */ 00300 00301 /* 00302 * Below are truly Linux-specific types that should never collide with 00303 * any application/library that wants linux/types.h. 00304 */ 00305 00306 struct ustat { 00307 __kernel_daddr_t f_tfree; 00308 __kernel_ino_t f_tinode; 00309 char f_fname[6]; 00310 char f_fpack[6]; 00311 }; 00312 00313 00314 00315 00316 00317 00318 00319 00320 00321 00322 00323 00324 00325 00326 #ifndef __LITTLE_ENDIAN 00327 #define __LITTLE_ENDIAN 1234 00328 #endif 00329 #ifndef __LITTLE_ENDIAN_BITFIELD 00330 #define __LITTLE_ENDIAN_BITFIELD 00331 #endif 00332 00333 #if 1 /* swab */ 00334 00335 /* 00336 * linux/byteorder/swab.h 00337 * Byte-swapping, independently from CPU endianness 00338 * swabXX[ps]?(foo) 00339 * 00340 * Francois-Rene Rideau <fare@tunes.org> 19971205 00341 * separated swab functions from cpu_to_XX, 00342 * to clean up support for bizarre-endian architectures. 00343 * 00344 * See asm-i386/byteorder.h and suches for examples of how to provide 00345 * architecture-dependent optimized versions 00346 * 00347 */ 00348 00349 /* casts are necessary for constants, because we never know how for sure 00350 * how U/UL/ULL map to __u16, __u32, __u64. At least not in a portable way. 00351 */ 00352 #define ___swab16(x) \ 00353 ({ \ 00354 __u16 __x = (x); \ 00355 ((__u16)( \ 00356 (((__u16)(__x) & (__u16)0x00ffU) << 8) | \ 00357 (((__u16)(__x) & (__u16)0xff00U) >> 8) )); \ 00358 }) 00359 00360 #define ___swab24(x) \ 00361 ({ \ 00362 __u32 __x = (x); \ 00363 ((__u32)( \ 00364 ((__x & (__u32)0x000000ffUL) << 16) | \ 00365 (__x & (__u32)0x0000ff00UL) | \ 00366 ((__x & (__u32)0x00ff0000UL) >> 16) )); \ 00367 }) 00368 00369 #define ___swab32(x) \ 00370 ({ \ 00371 __u32 __x = (x); \ 00372 ((__u32)( \ 00373 (((__u32)(__x) & (__u32)0x000000ffUL) << 24) | \ 00374 (((__u32)(__x) & (__u32)0x0000ff00UL) << 8) | \ 00375 (((__u32)(__x) & (__u32)0x00ff0000UL) >> 8) | \ 00376 (((__u32)(__x) & (__u32)0xff000000UL) >> 24) )); \ 00377 }) 00378 00379 #define ___swab64(x) \ 00380 ({ \ 00381 __u64 __x = (x); \ 00382 ((__u64)( \ 00383 (__u64)(((__u64)(__x) & (__u64)0x00000000000000ffULL) << 56) | \ 00384 (__u64)(((__u64)(__x) & (__u64)0x000000000000ff00ULL) << 40) | \ 00385 (__u64)(((__u64)(__x) & (__u64)0x0000000000ff0000ULL) << 24) | \ 00386 (__u64)(((__u64)(__x) & (__u64)0x00000000ff000000ULL) << 8) | \ 00387 (__u64)(((__u64)(__x) & (__u64)0x000000ff00000000ULL) >> 8) | \ 00388 (__u64)(((__u64)(__x) & (__u64)0x0000ff0000000000ULL) >> 24) | \ 00389 (__u64)(((__u64)(__x) & (__u64)0x00ff000000000000ULL) >> 40) | \ 00390 (__u64)(((__u64)(__x) & (__u64)0xff00000000000000ULL) >> 56) )); \ 00391 }) 00392 00393 #define ___constant_swab16(x) \ 00394 ((__u16)( \ 00395 (((__u16)(x) & (__u16)0x00ffU) << 8) | \ 00396 (((__u16)(x) & (__u16)0xff00U) >> 8) )) 00397 #define ___constant_swab24(x) \ 00398 ((__u32)( \ 00399 (((__u32)(x) & (__u32)0x000000ffU) << 16) | \ 00400 (((__u32)(x) & (__u32)0x0000ff00U) | \ 00401 (((__u32)(x) & (__u32)0x00ff0000U) >> 16) )) 00402 #define ___constant_swab32(x) \ 00403 ((__u32)( \ 00404 (((__u32)(x) & (__u32)0x000000ffUL) << 24) | \ 00405 (((__u32)(x) & (__u32)0x0000ff00UL) << 8) | \ 00406 (((__u32)(x) & (__u32)0x00ff0000UL) >> 8) | \ 00407 (((__u32)(x) & (__u32)0xff000000UL) >> 24) )) 00408 #define ___constant_swab64(x) \ 00409 ((__u64)( \ 00410 (__u64)(((__u64)(x) & (__u64)0x00000000000000ffULL) << 56) | \ 00411 (__u64)(((__u64)(x) & (__u64)0x000000000000ff00ULL) << 40) | \ 00412 (__u64)(((__u64)(x) & (__u64)0x0000000000ff0000ULL) << 24) | \ 00413 (__u64)(((__u64)(x) & (__u64)0x00000000ff000000ULL) << 8) | \ 00414 (__u64)(((__u64)(x) & (__u64)0x000000ff00000000ULL) >> 8) | \ 00415 (__u64)(((__u64)(x) & (__u64)0x0000ff0000000000ULL) >> 24) | \ 00416 (__u64)(((__u64)(x) & (__u64)0x00ff000000000000ULL) >> 40) | \ 00417 (__u64)(((__u64)(x) & (__u64)0xff00000000000000ULL) >> 56) )) 00418 00419 /* 00420 * provide defaults when no architecture-specific optimization is detected 00421 */ 00422 #ifndef __arch__swab16 00423 # define __arch__swab16(x) ({ __u16 __tmp = (x) ; ___swab16(__tmp); }) 00424 #endif 00425 #ifndef __arch__swab24 00426 # define __arch__swab24(x) ({ __u32 __tmp = (x) ; ___swab24(__tmp); }) 00427 #endif 00428 #ifndef __arch__swab32 00429 # define __arch__swab32(x) ({ __u32 __tmp = (x) ; ___swab32(__tmp); }) 00430 #endif 00431 #ifndef __arch__swab64 00432 # define __arch__swab64(x) ({ __u64 __tmp = (x) ; ___swab64(__tmp); }) 00433 #endif 00434 00435 #ifndef __arch__swab16p 00436 # define __arch__swab16p(x) __arch__swab16(*(x)) 00437 #endif 00438 #ifndef __arch__swab24p 00439 # define __arch__swab24p(x) __arch__swab24(*(x)) 00440 #endif 00441 #ifndef __arch__swab32p 00442 # define __arch__swab32p(x) __arch__swab32(*(x)) 00443 #endif 00444 #ifndef __arch__swab64p 00445 # define __arch__swab64p(x) __arch__swab64(*(x)) 00446 #endif 00447 00448 #ifndef __arch__swab16s 00449 # define __arch__swab16s(x) do { *(x) = __arch__swab16p((x)); } while (0) 00450 #endif 00451 #ifndef __arch__swab24s 00452 # define __arch__swab24s(x) do { *(x) = __arch__swab24p((x)); } while (0) 00453 #endif 00454 #ifndef __arch__swab32s 00455 # define __arch__swab32s(x) do { *(x) = __arch__swab32p((x)); } while (0) 00456 #endif 00457 #ifndef __arch__swab64s 00458 # define __arch__swab64s(x) do { *(x) = __arch__swab64p((x)); } while (0) 00459 #endif 00460 00461 00462 /* 00463 * Allow constant folding 00464 */ 00465 #if defined(__GNUC__) && (__GNUC__ >= 2) && defined(__OPTIMIZE__) 00466 # define __swab16(x) \ 00467 (__builtin_constant_p((__u16)(x)) ? \ 00468 ___swab16((x)) : \ 00469 __fswab16((x))) 00470 # define __swab24(x) \ 00471 (__builtin_constant_p((__u32)(x)) ? \ 00472 ___swab24((x)) : \ 00473 __fswab24((x))) 00474 # define __swab32(x) \ 00475 (__builtin_constant_p((__u32)(x)) ? \ 00476 ___swab32((x)) : \ 00477 __fswab32((x))) 00478 # define __swab64(x) \ 00479 (__builtin_constant_p((__u64)(x)) ? \ 00480 ___swab64((x)) : \ 00481 __fswab64((x))) 00482 #else 00483 # define __swab16(x) __fswab16(x) 00484 # define __swab24(x) __fswab24(x) 00485 # define __swab32(x) __fswab32(x) 00486 # define __swab64(x) __fswab64(x) 00487 #endif /* OPTIMIZE */ 00488 00489 00490 static __inline__ __const__ __u16 __fswab16(__u16 x) 00491 { 00492 return __arch__swab16(x); 00493 } 00494 static __inline__ __u16 __swab16p(__u16 *x) 00495 { 00496 return __arch__swab16p(x); 00497 } 00498 static __inline__ void __swab16s(__u16 *addr) 00499 { 00500 __arch__swab16s(addr); 00501 } 00502 00503 static __inline__ __const__ __u32 __fswab24(__u32 x) 00504 { 00505 return __arch__swab24(x); 00506 } 00507 static __inline__ __u32 __swab24p(__u32 *x) 00508 { 00509 return __arch__swab24p(x); 00510 } 00511 static __inline__ void __swab24s(__u32 *addr) 00512 { 00513 __arch__swab24s(addr); 00514 } 00515 00516 static __inline__ __const__ __u32 __fswab32(__u32 x) 00517 { 00518 return __arch__swab32(x); 00519 } 00520 static __inline__ __u32 __swab32p(__u32 *x) 00521 { 00522 return __arch__swab32p(x); 00523 } 00524 static __inline__ void __swab32s(__u32 *addr) 00525 { 00526 __arch__swab32s(addr); 00527 } 00528 00529 #ifdef __BYTEORDER_HAS_U64__ 00530 static __inline__ __const__ __u64 __fswab64(__u64 x) 00531 { 00532 # ifdef __SWAB_64_THRU_32__ 00533 __u32 h = x >> 32; 00534 __u32 l = x & ((1ULL<<32)-1); 00535 return (((__u64)__swab32(l)) << 32) | ((__u64)(__swab32(h))); 00536 # else 00537 return __arch__swab64(x); 00538 # endif 00539 } 00540 static __inline__ __u64 __swab64p(__u64 *x) 00541 { 00542 return __arch__swab64p(x); 00543 } 00544 static __inline__ void __swab64s(__u64 *addr) 00545 { 00546 __arch__swab64s(addr); 00547 } 00548 #endif /* __BYTEORDER_HAS_U64__ */ 00549 00550 #if defined(__KERNEL__) 00551 #define swab16 __swab16 00552 #define swab24 __swab24 00553 #define swab32 __swab32 00554 #define swab64 __swab64 00555 #define swab16p __swab16p 00556 #define swab24p __swab24p 00557 #define swab32p __swab32p 00558 #define swab64p __swab64p 00559 #define swab16s __swab16s 00560 #define swab24s __swab24s 00561 #define swab32s __swab32s 00562 #define swab64s __swab64s 00563 #endif 00564 00565 #endif /* swab */ 00566 00567 00568 00569 #if 1 /* generic */ 00570 00571 /* 00572 * linux/byteorder_generic.h 00573 * Generic Byte-reordering support 00574 * 00575 * Francois-Rene Rideau <fare@tunes.org> 19970707 00576 * gathered all the good ideas from all asm-foo/byteorder.h into one file, 00577 * cleaned them up. 00578 * I hope it is compliant with non-GCC compilers. 00579 * I decided to put __BYTEORDER_HAS_U64__ in byteorder.h, 00580 * because I wasn't sure it would be ok to put it in types.h 00581 * Upgraded it to 2.1.43 00582 * Francois-Rene Rideau <fare@tunes.org> 19971012 00583 * Upgraded it to 2.1.57 00584 * to please Linus T., replaced huge #ifdef's between little/big endian 00585 * by nestedly #include'd files. 00586 * Francois-Rene Rideau <fare@tunes.org> 19971205 00587 * Made it to 2.1.71; now a facelift: 00588 * Put files under include/linux/byteorder/ 00589 * Split swab from generic support. 00590 * 00591 * TODO: 00592 * = Regular kernel maintainers could also replace all these manual 00593 * byteswap macros that remain, disseminated among drivers, 00594 * after some grep or the sources... 00595 * = Linus might want to rename all these macros and files to fit his taste, 00596 * to fit his personal naming scheme. 00597 * = it seems that a few drivers would also appreciate 00598 * nybble swapping support... 00599 * = every architecture could add their byteswap macro in asm/byteorder.h 00600 * see how some architectures already do (i386, alpha, ppc, etc) 00601 * = cpu_to_beXX and beXX_to_cpu might some day need to be well 00602 * distinguished throughout the kernel. This is not the case currently, 00603 * since little endian, big endian, and pdp endian machines needn't it. 00604 * But this might be the case for, say, a port of Linux to 20/21 bit 00605 * architectures (and F21 Linux addict around?). 00606 */ 00607 00608 /* 00609 * The following macros are to be defined by <asm/byteorder.h>: 00610 * 00611 * Conversion of long and short int between network and host format 00612 * ntohl(__u32 x) 00613 * ntohs(__u16 x) 00614 * htonl(__u32 x) 00615 * htons(__u16 x) 00616 * It seems that some programs (which? where? or perhaps a standard? POSIX?) 00617 * might like the above to be functions, not macros (why?). 00618 * if that's true, then detect them, and take measures. 00619 * Anyway, the measure is: define only ___ntohl as a macro instead, 00620 * and in a separate file, have 00621 * unsigned long inline ntohl(x){return ___ntohl(x);} 00622 * 00623 * The same for constant arguments 00624 * __constant_ntohl(__u32 x) 00625 * __constant_ntohs(__u16 x) 00626 * __constant_htonl(__u32 x) 00627 * __constant_htons(__u16 x) 00628 * 00629 * Conversion of XX-bit integers (16- 32- or 64-) 00630 * between native CPU format and little/big endian format 00631 * 64-bit stuff only defined for proper architectures 00632 * cpu_to_[bl]eXX(__uXX x) 00633 * [bl]eXX_to_cpu(__uXX x) 00634 * 00635 * The same, but takes a pointer to the value to convert 00636 * cpu_to_[bl]eXXp(__uXX x) 00637 * [bl]eXX_to_cpup(__uXX x) 00638 * 00639 * The same, but change in situ 00640 * cpu_to_[bl]eXXs(__uXX x) 00641 * [bl]eXX_to_cpus(__uXX x) 00642 * 00643 * See asm-foo/byteorder.h for examples of how to provide 00644 * architecture-optimized versions 00645 * 00646 */ 00647 00648 00649 #if defined(__KERNEL__) 00650 /* 00651 * inside the kernel, we can use nicknames; 00652 * outside of it, we must avoid POSIX namespace pollution... 00653 */ 00654 #define cpu_to_le64 __cpu_to_le64 00655 #define le64_to_cpu __le64_to_cpu 00656 #define cpu_to_le32 __cpu_to_le32 00657 #define le32_to_cpu __le32_to_cpu 00658 #define cpu_to_le16 __cpu_to_le16 00659 #define le16_to_cpu __le16_to_cpu 00660 #define cpu_to_be64 __cpu_to_be64 00661 #define be64_to_cpu __be64_to_cpu 00662 #define cpu_to_be32 __cpu_to_be32 00663 #define be32_to_cpu __be32_to_cpu 00664 #define cpu_to_be16 __cpu_to_be16 00665 #define be16_to_cpu __be16_to_cpu 00666 #define cpu_to_le64p __cpu_to_le64p 00667 #define le64_to_cpup __le64_to_cpup 00668 #define cpu_to_le32p __cpu_to_le32p 00669 #define le32_to_cpup __le32_to_cpup 00670 #define cpu_to_le16p __cpu_to_le16p 00671 #define le16_to_cpup __le16_to_cpup 00672 #define cpu_to_be64p __cpu_to_be64p 00673 #define be64_to_cpup __be64_to_cpup 00674 #define cpu_to_be32p __cpu_to_be32p 00675 #define be32_to_cpup __be32_to_cpup 00676 #define cpu_to_be16p __cpu_to_be16p 00677 #define be16_to_cpup __be16_to_cpup 00678 #define cpu_to_le64s __cpu_to_le64s 00679 #define le64_to_cpus __le64_to_cpus 00680 #define cpu_to_le32s __cpu_to_le32s 00681 #define le32_to_cpus __le32_to_cpus 00682 #define cpu_to_le16s __cpu_to_le16s 00683 #define le16_to_cpus __le16_to_cpus 00684 #define cpu_to_be64s __cpu_to_be64s 00685 #define be64_to_cpus __be64_to_cpus 00686 #define cpu_to_be32s __cpu_to_be32s 00687 #define be32_to_cpus __be32_to_cpus 00688 #define cpu_to_be16s __cpu_to_be16s 00689 #define be16_to_cpus __be16_to_cpus 00690 #endif 00691 00692 00693 /* 00694 * Handle ntohl and suches. These have various compatibility 00695 * issues - like we want to give the prototype even though we 00696 * also have a macro for them in case some strange program 00697 * wants to take the address of the thing or something.. 00698 * 00699 * Note that these used to return a "long" in libc5, even though 00700 * long is often 64-bit these days.. Thus the casts. 00701 * 00702 * They have to be macros in order to do the constant folding 00703 * correctly - if the argument passed into a inline function 00704 * it is no longer constant according to gcc.. 00705 */ 00706 00707 #undef ntohl 00708 #undef ntohs 00709 #undef htonl 00710 #undef htons 00711 00712 /* 00713 * Do the prototypes. Somebody might want to take the 00714 * address or some such sick thing.. 00715 */ 00716 #if defined(__KERNEL__) || (defined (__GLIBC__) && __GLIBC__ >= 2) 00717 extern __u32 ntohl(__u32); 00718 extern __u32 htonl(__u32); 00719 #else 00720 extern unsigned long int ntohl(unsigned long int); 00721 extern unsigned long int htonl(unsigned long int); 00722 #endif 00723 extern unsigned short int ntohs(unsigned short int); 00724 extern unsigned short int htons(unsigned short int); 00725 00726 00727 #if defined(__GNUC__) && (__GNUC__ >= 2) && defined(__OPTIMIZE__) && !defined(__STRICT_ANSI__) 00728 00729 #define ___htonl(x) __cpu_to_be32(x) 00730 #define ___htons(x) __cpu_to_be16(x) 00731 #define ___ntohl(x) __be32_to_cpu(x) 00732 #define ___ntohs(x) __be16_to_cpu(x) 00733 00734 #if defined(__KERNEL__) || (defined (__GLIBC__) && __GLIBC__ >= 2) 00735 #define htonl(x) ___htonl(x) 00736 #define ntohl(x) ___ntohl(x) 00737 #else 00738 #define htonl(x) ((unsigned long)___htonl(x)) 00739 #define ntohl(x) ((unsigned long)___ntohl(x)) 00740 #endif 00741 #define htons(x) ___htons(x) 00742 #define ntohs(x) ___ntohs(x) 00743 00744 #endif /* OPTIMIZE */ 00745 00746 #endif /* generic */ 00747 00748 00749 #define __constant_htonl(x) ___constant_swab32((x)) 00750 #define __constant_ntohl(x) ___constant_swab32((x)) 00751 #define __constant_htons(x) ___constant_swab16((x)) 00752 #define __constant_ntohs(x) ___constant_swab16((x)) 00753 #define __constant_cpu_to_le64(x) ((__u64)(x)) 00754 #define __constant_le64_to_cpu(x) ((__u64)(x)) 00755 #define __constant_cpu_to_le32(x) ((__u32)(x)) 00756 #define __constant_le32_to_cpu(x) ((__u32)(x)) 00757 #define __constant_cpu_to_le24(x) ((__u32)(x)) 00758 #define __constant_le24_to_cpu(x) ((__u32)(x)) 00759 #define __constant_cpu_to_le16(x) ((__u16)(x)) 00760 #define __constant_le16_to_cpu(x) ((__u16)(x)) 00761 #define __constant_cpu_to_be64(x) ___constant_swab64((x)) 00762 #define __constant_be64_to_cpu(x) ___constant_swab64((x)) 00763 #define __constant_cpu_to_be32(x) ___constant_swab32((x)) 00764 #define __constant_be32_to_cpu(x) ___constant_swab32((x)) 00765 #define __constant_cpu_to_be24(x) ___constant_swab24((x)) 00766 #define __constant_be24_to_cpu(x) ___constant_swab24((x)) 00767 #define __constant_cpu_to_be16(x) ___constant_swab16((x)) 00768 #define __constant_be16_to_cpu(x) ___constant_swab16((x)) 00769 #define __cpu_to_le64(x) ((__u64)(x)) 00770 #define __le64_to_cpu(x) ((__u64)(x)) 00771 #define __cpu_to_le32(x) ((__u32)(x)) 00772 #define __le32_to_cpu(x) ((__u32)(x)) 00773 #define __cpu_to_le24(x) ((__u32)(x)) 00774 #define __le24_to_cpu(x) ((__u32)(x)) 00775 #define __cpu_to_le16(x) ((__u16)(x)) 00776 #define __le16_to_cpu(x) ((__u16)(x)) 00777 #define __cpu_to_be64(x) __swab64((x)) 00778 #define __be64_to_cpu(x) __swab64((x)) 00779 #define __cpu_to_be32(x) __swab32((x)) 00780 #define __be32_to_cpu(x) __swab32((x)) 00781 #define __cpu_to_be24(x) __swab24((x)) 00782 #define __be24_to_cpu(x) __swab24((x)) 00783 #define __cpu_to_be16(x) __swab16((x)) 00784 #define __be16_to_cpu(x) __swab16((x)) 00785 #define __cpu_to_le64p(x) (*(__u64*)(x)) 00786 #define __le64_to_cpup(x) (*(__u64*)(x)) 00787 #define __cpu_to_le32p(x) (*(__u32*)(x)) 00788 #define __le32_to_cpup(x) (*(__u32*)(x)) 00789 #define __cpu_to_le24p(x) (*(__u32*)(x)) 00790 #define __le24_to_cpup(x) (*(__u32*)(x)) 00791 #define __cpu_to_le16p(x) (*(__u16*)(x)) 00792 #define __le16_to_cpup(x) (*(__u16*)(x)) 00793 #define __cpu_to_be64p(x) __swab64p((x)) 00794 #define __be64_to_cpup(x) __swab64p((x)) 00795 #define __cpu_to_be32p(x) __swab32p((x)) 00796 #define __be32_to_cpup(x) __swab32p((x)) 00797 #define __cpu_to_be24p(x) __swab24p((x)) 00798 #define __be24_to_cpup(x) __swab24p((x)) 00799 #define __cpu_to_be16p(x) __swab16p((x)) 00800 #define __be16_to_cpup(x) __swab16p((x)) 00801 #define __cpu_to_le64s(x) do {} while (0) 00802 #define __le64_to_cpus(x) do {} while (0) 00803 #define __cpu_to_le32s(x) do {} while (0) 00804 #define __le32_to_cpus(x) do {} while (0) 00805 #define __cpu_to_le24s(x) do {} while (0) 00806 #define __le24_to_cpus(x) do {} while (0) 00807 #define __cpu_to_le16s(x) do {} while (0) 00808 #define __le16_to_cpus(x) do {} while (0) 00809 #define __cpu_to_be64s(x) __swab64s((x)) 00810 #define __be64_to_cpus(x) __swab64s((x)) 00811 #define __cpu_to_be32s(x) __swab32s((x)) 00812 #define __be32_to_cpus(x) __swab32s((x)) 00813 #define __cpu_to_be24s(x) __swab24s((x)) 00814 #define __be24_to_cpus(x) __swab24s((x)) 00815 #define __cpu_to_be16s(x) __swab16s((x)) 00816 #define __be16_to_cpus(x) __swab16s((x)) 00817 00818 00819 00820 00821 00822 00823 00824 00825 #if 1 00826 00827 /* Dummy types */ 00828 00829 #define ____cacheline_aligned 00830 00831 typedef struct 00832 { 00833 volatile unsigned int lock; 00834 } rwlock_t; 00835 00836 typedef struct { 00837 volatile unsigned int lock; 00838 } spinlock_t; 00839 00840 struct task_struct; 00841 00842 00843 00844 00845 00846 #if 1 /* atomic */ 00847 00848 /* 00849 * Atomic operations that C can't guarantee us. Useful for 00850 * resource counting etc.. 00851 */ 00852 00853 #ifdef CONFIG_SMP 00854 #define LOCK "lock ; " 00855 #else 00856 #define LOCK "" 00857 #endif 00858 00859 /* 00860 * Make sure gcc doesn't try to be clever and move things around 00861 * on us. We need to use _exactly_ the address the user gave us, 00862 * not some alias that contains the same information. 00863 */ 00864 typedef struct { volatile int counter; } atomic_t; 00865 00866 #define ATOMIC_INIT(i) { (i) } 00867 00875 #define atomic_read(v) ((v)->counter) 00876 00885 #define atomic_set(v,i) (((v)->counter) = (i)) 00886 00895 static __inline__ void atomic_add(int i, atomic_t *v) 00896 { 00897 #if 0 00898 __asm__ __volatile__( 00899 LOCK "addl %1,%0" 00900 :"=m" (v->counter) 00901 :"ir" (i), "m" (v->counter)); 00902 #endif 00903 } 00904 00913 static __inline__ void atomic_sub(int i, atomic_t *v) 00914 { 00915 #if 0 00916 __asm__ __volatile__( 00917 LOCK "subl %1,%0" 00918 :"=m" (v->counter) 00919 :"ir" (i), "m" (v->counter)); 00920 #endif 00921 } 00922 00933 static __inline__ int atomic_sub_and_test(int i, atomic_t *v) 00934 { 00935 #if 0 00936 unsigned char c; 00937 00938 __asm__ __volatile__( 00939 LOCK "subl %2,%0; sete %1" 00940 :"=m" (v->counter), "=qm" (c) 00941 :"ir" (i), "m" (v->counter) : "memory"); 00942 return c; 00943 #endif 00944 } 00945 00953 static __inline__ void atomic_inc(atomic_t *v) 00954 { 00955 #if 0 00956 __asm__ __volatile__( 00957 LOCK "incl %0" 00958 :"=m" (v->counter) 00959 :"m" (v->counter)); 00960 #endif 00961 } 00962 00970 static __inline__ void atomic_dec(atomic_t *v) 00971 { 00972 #if 0 00973 __asm__ __volatile__( 00974 LOCK "decl %0" 00975 :"=m" (v->counter) 00976 :"m" (v->counter)); 00977 #endif 00978 } 00979 00989 static __inline__ int atomic_dec_and_test(atomic_t *v) 00990 { 00991 #if 0 00992 unsigned char c; 00993 00994 __asm__ __volatile__( 00995 LOCK "decl %0; sete %1" 00996 :"=m" (v->counter), "=qm" (c) 00997 :"m" (v->counter) : "memory"); 00998 return c != 0; 00999 #else 01000 return 1; 01001 #endif 01002 } 01003 01013 static __inline__ int atomic_inc_and_test(atomic_t *v) 01014 { 01015 #if 0 01016 unsigned char c; 01017 01018 __asm__ __volatile__( 01019 LOCK "incl %0; sete %1" 01020 :"=m" (v->counter), "=qm" (c) 01021 :"m" (v->counter) : "memory"); 01022 return c != 0; 01023 #else 01024 return 1; 01025 #endif 01026 } 01027 01038 static __inline__ int atomic_add_negative(int i, atomic_t *v) 01039 { 01040 #if 0 01041 unsigned char c; 01042 01043 __asm__ __volatile__( 01044 LOCK "addl %2,%0; sets %1" 01045 :"=m" (v->counter), "=qm" (c) 01046 :"ir" (i), "m" (v->counter) : "memory"); 01047 return c; 01048 #else 01049 return 0; 01050 #endif 01051 } 01052 01053 /* These are x86-specific, used by some header files */ 01054 #define atomic_clear_mask(mask, addr) 01055 #if 0 01056 __asm__ __volatile__(LOCK "andl %0,%1" \ 01057 : : "r" (~(mask)),"m" (*addr) : "memory") 01058 #endif 01059 01060 #define atomic_set_mask(mask, addr) 01061 #if 0 01062 __asm__ __volatile__(LOCK "orl %0,%1" \ 01063 : : "r" (mask),"m" (*addr) : "memory") 01064 #endif 01065 01066 /* Atomic operations are already serializing on x86 */ 01067 #define smp_mb__before_atomic_dec() 01068 #define smp_mb__after_atomic_dec() 01069 #define smp_mb__before_atomic_inc() 01070 #define smp_mb__after_atomic_inc() 01071 01072 01073 01074 #endif /* atomic */ 01075 01076 01077 01078 01079 01080 #if 1 /* list */ 01081 01082 struct list_head { 01083 struct list_head *next, *prev; 01084 }; 01085 01086 #define LIST_HEAD_INIT(name) { &(name), &(name) } 01087 01088 #define LIST_HEAD(name) \ 01089 struct list_head name = LIST_HEAD_INIT(name) 01090 01091 #define INIT_LIST_HEAD(ptr) do { \ 01092 (ptr)->next = (ptr); (ptr)->prev = (ptr); \ 01093 } while (0) 01094 01095 /* 01096 * Insert a new entry between two known consecutive entries. 01097 * 01098 * This is only for internal list manipulation where we know 01099 * the prev/next entries already! 01100 */ 01101 static inline void __list_add(struct list_head *new, 01102 struct list_head *prev, 01103 struct list_head *next) 01104 { 01105 #if 0 01106 next->prev = new; 01107 new->next = next; 01108 new->prev = prev; 01109 prev->next = new; 01110 #endif 01111 } 01112 01121 static inline void list_add(struct list_head *new, struct list_head *head) 01122 { 01123 #if 0 01124 __list_add(new, head, head->next); 01125 #endif 01126 } 01127 01136 static inline void list_add_tail(struct list_head *new, struct list_head *head) 01137 { 01138 #if 0 01139 __list_add(new, head->prev, head); 01140 #endif 01141 } 01142 01143 /* 01144 * Delete a list entry by making the prev/next entries 01145 * point to each other. 01146 * 01147 * This is only for internal list manipulation where we know 01148 * the prev/next entries already! 01149 */ 01150 static inline void __list_del(struct list_head *prev, struct list_head *next) 01151 { 01152 next->prev = prev; 01153 prev->next = next; 01154 } 01155 01161 static inline void list_del(struct list_head *entry) 01162 { 01163 #if 0 01164 __list_del(entry->prev, entry->next); 01165 entry->next = (void *) 0; 01166 entry->prev = (void *) 0; 01167 #endif 01168 } 01169 01174 static inline void list_del_init(struct list_head *entry) 01175 { 01176 #if 0 01177 __list_del(entry->prev, entry->next); 01178 INIT_LIST_HEAD(entry); 01179 #endif 01180 } 01181 01187 static inline void list_move(struct list_head *list, struct list_head *head) 01188 { 01189 #if 0 01190 __list_del(list->prev, list->next); 01191 list_add(list, head); 01192 #endif 01193 } 01194 01200 static inline void list_move_tail(struct list_head *list, 01201 struct list_head *head) 01202 { 01203 #if 0 01204 __list_del(list->prev, list->next); 01205 list_add_tail(list, head); 01206 #endif 01207 } 01208 01213 static inline int list_empty(struct list_head *head) 01214 { 01215 return head->next == head; 01216 } 01217 01218 static inline void __list_splice(struct list_head *list, 01219 struct list_head *head) 01220 { 01221 #if 0 01222 struct list_head *first = list->next; 01223 struct list_head *last = list->prev; 01224 struct list_head *at = head->next; 01225 01226 first->prev = head; 01227 head->next = first; 01228 01229 last->next = at; 01230 at->prev = last; 01231 #endif 01232 } 01233 01239 static inline void list_splice(struct list_head *list, struct list_head *head) 01240 { 01241 #if 0 01242 if (!list_empty(list)) 01243 __list_splice(list, head); 01244 #endif 01245 } 01246 01254 static inline void list_splice_init(struct list_head *list, 01255 struct list_head *head) 01256 { 01257 #if 0 01258 if (!list_empty(list)) { 01259 __list_splice(list, head); 01260 INIT_LIST_HEAD(list); 01261 } 01262 #endif 01263 } 01264 01271 #define list_entry(ptr, type, member) 01272 #if 0 01273 ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member))) 01274 #endif 01275 01281 #define list_for_each(pos, head) 01282 #if 0 01283 for (pos = (head)->next, prefetch(pos->next); pos != (head); \ 01284 pos = pos->next, prefetch(pos->next)) 01285 #endif 01286 01292 #define list_for_each_prev(pos, head) 01293 #if 0 01294 for (pos = (head)->prev, prefetch(pos->prev); pos != (head); \ 01295 pos = pos->prev, prefetch(pos->prev)) 01296 #endif 01297 01304 #define list_for_each_safe(pos, n, head) 01305 #if 0 01306 for (pos = (head)->next, n = pos->next; pos != (head); \ 01307 pos = n, n = pos->next) 01308 #endif 01309 01316 #define list_for_each_entry(pos, head, member) 01317 #if 0 01318 for (pos = list_entry((head)->next, typeof(*pos), member), \ 01319 prefetch(pos->member.next); \ 01320 &pos->member != (head); \ 01321 pos = list_entry(pos->member.next, typeof(*pos), member), \ 01322 prefetch(pos->member.next)) 01323 #endif 01324 01325 #endif /* list */ 01326 01327 01328 01329 01330 01331 #if 1 /* wait */ 01332 01333 #define WNOHANG 0x00000001 01334 #define WUNTRACED 0x00000002 01335 01336 #define __WNOTHREAD 0x20000000 /* Don't wait on children of other threads in this group */ 01337 #define __WALL 0x40000000 /* Wait on all children, regardless of type */ 01338 #define __WCLONE 0x80000000 /* Wait only on non-SIGCHLD children */ 01339 01340 #if 0 01341 #include <linux/kernel.h> 01342 #include <linux/list.h> 01343 #include <linux/stddef.h> 01344 #include <linux/spinlock.h> 01345 #include <linux/config.h> 01346 01347 #include <asm/page.h> 01348 #include <asm/processor.h> 01349 #endif 01350 01351 /* 01352 * Debug control. Slow but useful. 01353 */ 01354 #if defined(CONFIG_DEBUG_WAITQ) 01355 #define WAITQUEUE_DEBUG 1 01356 #else 01357 #define WAITQUEUE_DEBUG 0 01358 #endif 01359 01360 struct __wait_queue { 01361 unsigned int flags; 01362 #define WQ_FLAG_EXCLUSIVE 0x01 01363 struct task_struct * task; 01364 struct list_head task_list; 01365 #if WAITQUEUE_DEBUG 01366 long __magic; 01367 long __waker; 01368 #endif 01369 }; 01370 typedef struct __wait_queue wait_queue_t; 01371 01372 /* 01373 * 'dual' spinlock architecture. Can be switched between spinlock_t and 01374 * rwlock_t locks via changing this define. Since waitqueues are quite 01375 * decoupled in the new architecture, lightweight 'simple' spinlocks give 01376 * us slightly better latencies and smaller waitqueue structure size. 01377 */ 01378 #define USE_RW_WAIT_QUEUE_SPINLOCK 0 01379 01380 #if USE_RW_WAIT_QUEUE_SPINLOCK 01381 # define wq_lock_t rwlock_t 01382 # define WAITQUEUE_RW_LOCK_UNLOCKED RW_LOCK_UNLOCKED 01383 01384 # define wq_read_lock read_lock 01385 # define wq_read_lock_irqsave read_lock_irqsave 01386 # define wq_read_unlock_irqrestore read_unlock_irqrestore 01387 # define wq_read_unlock read_unlock 01388 # define wq_write_lock_irq write_lock_irq 01389 # define wq_write_lock_irqsave write_lock_irqsave 01390 # define wq_write_unlock_irqrestore write_unlock_irqrestore 01391 # define wq_write_unlock write_unlock 01392 #else 01393 # define wq_lock_t spinlock_t 01394 # define WAITQUEUE_RW_LOCK_UNLOCKED SPIN_LOCK_UNLOCKED 01395 01396 # define wq_read_lock spin_lock 01397 # define wq_read_lock_irqsave spin_lock_irqsave 01398 # define wq_read_unlock spin_unlock 01399 # define wq_read_unlock_irqrestore spin_unlock_irqrestore 01400 # define wq_write_lock_irq spin_lock_irq 01401 # define wq_write_lock_irqsave spin_lock_irqsave 01402 # define wq_write_unlock_irqrestore spin_unlock_irqrestore 01403 # define wq_write_unlock spin_unlock 01404 #endif 01405 01406 struct __wait_queue_head { 01407 wq_lock_t lock; 01408 struct list_head task_list; 01409 #if WAITQUEUE_DEBUG 01410 long __magic; 01411 long __creator; 01412 #endif 01413 }; 01414 typedef struct __wait_queue_head wait_queue_head_t; 01415 01416 01417 /* 01418 * Debugging macros. We eschew `do { } while (0)' because gcc can generate 01419 * spurious .aligns. 01420 */ 01421 #if WAITQUEUE_DEBUG 01422 #define WQ_BUG() BUG() 01423 #define CHECK_MAGIC(x) 01424 #if 0 01425 do { \ 01426 if ((x) != (long)&(x)) { \ 01427 printk("bad magic %lx (should be %lx), ", \ 01428 (long)x, (long)&(x)); \ 01429 WQ_BUG(); \ 01430 } \ 01431 } while (0) 01432 #endif 01433 01434 #define CHECK_MAGIC_WQHEAD(x) 01435 #if 0 01436 do { \ 01437 if ((x)->__magic != (long)&((x)->__magic)) { \ 01438 printk("bad magic %lx (should be %lx, creator %lx), ", \ 01439 (x)->__magic, (long)&((x)->__magic), (x)->__creator); \ 01440 WQ_BUG(); \ 01441 } \ 01442 } while (0) 01443 #endif 01444 01445 #define WQ_CHECK_LIST_HEAD(list) 01446 #if 0 01447 do { \ 01448 if (!(list)->next || !(list)->prev) \ 01449 WQ_BUG(); \ 01450 } while(0) 01451 #endif 01452 01453 #define WQ_NOTE_WAKER(tsk) 01454 #if 0 01455 do { \ 01456 (tsk)->__waker = (long)__builtin_return_address(0); \ 01457 } while (0) 01458 #endif 01459 #else 01460 #define WQ_BUG() 01461 #define CHECK_MAGIC(x) 01462 #define CHECK_MAGIC_WQHEAD(x) 01463 #define WQ_CHECK_LIST_HEAD(list) 01464 #define WQ_NOTE_WAKER(tsk) 01465 #endif 01466 01467 /* 01468 * Macros for declaration and initialisaton of the datatypes 01469 */ 01470 01471 #if WAITQUEUE_DEBUG 01472 # define __WAITQUEUE_DEBUG_INIT(name) //(long)&(name).__magic, 0 01473 # define __WAITQUEUE_HEAD_DEBUG_INIT(name) //(long)&(name).__magic, (long)&(name).__magic 01474 #else 01475 # define __WAITQUEUE_DEBUG_INIT(name) 01476 # define __WAITQUEUE_HEAD_DEBUG_INIT(name) 01477 #endif 01478 01479 #define __WAITQUEUE_INITIALIZER(name, tsk) 01480 #if 0 01481 { 01482 task: tsk, \ 01483 task_list: { NULL, NULL }, \ 01484 __WAITQUEUE_DEBUG_INIT(name)} 01485 #endif 01486 01487 #define DECLARE_WAITQUEUE(name, tsk) 01488 #if 0 01489 wait_queue_t name = __WAITQUEUE_INITIALIZER(name, tsk) 01490 #endif 01491 01492 #define __WAIT_QUEUE_HEAD_INITIALIZER(name) 01493 #if 0 01494 { 01495 lock: WAITQUEUE_RW_LOCK_UNLOCKED, \ 01496 task_list: { &(name).task_list, &(name).task_list }, \ 01497 __WAITQUEUE_HEAD_DEBUG_INIT(name)} 01498 #endif 01499 01500 #define DECLARE_WAIT_QUEUE_HEAD(name) 01501 #if 0 01502 wait_queue_head_t name = __WAIT_QUEUE_HEAD_INITIALIZER(name) 01503 #endif 01504 01505 static inline void init_waitqueue_head(wait_queue_head_t *q) 01506 { 01507 #if 0 01508 #if WAITQUEUE_DEBUG 01509 if (!q) 01510 WQ_BUG(); 01511 #endif 01512 q->lock = WAITQUEUE_RW_LOCK_UNLOCKED; 01513 INIT_LIST_HEAD(&q->task_list); 01514 #if WAITQUEUE_DEBUG 01515 q->__magic = (long)&q->__magic; 01516 q->__creator = (long)current_text_addr(); 01517 #endif 01518 #endif 01519 } 01520 01521 static inline void init_waitqueue_entry(wait_queue_t *q, struct task_struct *p) 01522 { 01523 #if 0 01524 #if WAITQUEUE_DEBUG 01525 if (!q || !p) 01526 WQ_BUG(); 01527 #endif 01528 q->flags = 0; 01529 q->task = p; 01530 #if WAITQUEUE_DEBUG 01531 q->__magic = (long)&q->__magic; 01532 #endif 01533 #endif 01534 } 01535 01536 static inline int waitqueue_active(wait_queue_head_t *q) 01537 { 01538 #if 0 01539 #if WAITQUEUE_DEBUG 01540 if (!q) 01541 WQ_BUG(); 01542 CHECK_MAGIC_WQHEAD(q); 01543 #endif 01544 01545 return !list_empty(&q->task_list); 01546 #endif 01547 } 01548 01549 static inline void __add_wait_queue(wait_queue_head_t *head, wait_queue_t *new) 01550 { 01551 #if 0 01552 #if WAITQUEUE_DEBUG 01553 if (!head || !new) 01554 WQ_BUG(); 01555 CHECK_MAGIC_WQHEAD(head); 01556 CHECK_MAGIC(new->__magic); 01557 if (!head->task_list.next || !head->task_list.prev) 01558 WQ_BUG(); 01559 #endif 01560 list_add(&new->task_list, &head->task_list); 01561 #endif 01562 } 01563 01564 /* 01565 * Used for wake-one threads: 01566 */ 01567 static inline void __add_wait_queue_tail(wait_queue_head_t *head, 01568 wait_queue_t *new) 01569 { 01570 #if 0 01571 #if WAITQUEUE_DEBUG 01572 if (!head || !new) 01573 WQ_BUG(); 01574 CHECK_MAGIC_WQHEAD(head); 01575 CHECK_MAGIC(new->__magic); 01576 if (!head->task_list.next || !head->task_list.prev) 01577 WQ_BUG(); 01578 #endif 01579 list_add_tail(&new->task_list, &head->task_list); 01580 #endif 01581 } 01582 01583 static inline void __remove_wait_queue(wait_queue_head_t *head, 01584 wait_queue_t *old) 01585 { 01586 #if 0 01587 #if WAITQUEUE_DEBUG 01588 if (!old) 01589 WQ_BUG(); 01590 CHECK_MAGIC(old->__magic); 01591 #endif 01592 list_del(&old->task_list); 01593 #endif 01594 } 01595 01596 01597 01598 01599 #endif /* wait */ 01600 01601 01602 #endif 01603 01604 01605 01606 01607 #if 1 /* slab */ 01608 01609 typedef struct 01610 { 01611 int x; 01612 } kmem_cache_s; 01613 01614 typedef struct kmem_cache_s kmem_cache_t; 01615 01616 #if 0 01617 #include <linux/mm.h> 01618 #include <linux/cache.h> 01619 #endif 01620 01621 /* flags for kmem_cache_alloc() */ 01622 #define SLAB_NOFS GFP_NOFS 01623 #define SLAB_NOIO GFP_NOIO 01624 #define SLAB_NOHIGHIO GFP_NOHIGHIO 01625 #define SLAB_ATOMIC GFP_ATOMIC 01626 #define SLAB_USER GFP_USER 01627 #define SLAB_KERNEL GFP_KERNEL 01628 #define SLAB_NFS GFP_NFS 01629 #define SLAB_DMA GFP_DMA 01630 01631 #define SLAB_LEVEL_MASK (__GFP_WAIT|__GFP_HIGH|__GFP_IO|__GFP_HIGHIO|__GFP_FS) 01632 #define SLAB_NO_GROW 0x00001000UL /* don't grow a cache */ 01633 01634 /* flags to pass to kmem_cache_create(). 01635 * The first 3 are only valid when the allocator as been build 01636 * SLAB_DEBUG_SUPPORT. 01637 */ 01638 #define SLAB_DEBUG_FREE 0x00000100UL /* Peform (expensive) checks on free */ 01639 #define SLAB_DEBUG_INITIAL 0x00000200UL /* Call constructor (as verifier) */ 01640 #define SLAB_RED_ZONE 0x00000400UL /* Red zone objs in a cache */ 01641 #define SLAB_POISON 0x00000800UL /* Poison objects */ 01642 #define SLAB_NO_REAP 0x00001000UL /* never reap from the cache */ 01643 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* align objs on a h/w cache lines */ 01644 #define SLAB_CACHE_DMA 0x00004000UL /* use GFP_DMA memory */ 01645 #define SLAB_MUST_HWCACHE_ALIGN 0x00008000UL /* force alignment */ 01646 01647 /* flags passed to a constructor func */ 01648 #define SLAB_CTOR_CONSTRUCTOR 0x001UL /* if not set, then deconstructor */ 01649 #define SLAB_CTOR_ATOMIC 0x002UL /* tell constructor it can't sleep */ 01650 #define SLAB_CTOR_VERIFY 0x004UL /* tell constructor it's a verify call */ 01651 01652 /* prototypes */ 01653 extern void kmem_cache_init(void); 01654 extern void kmem_cache_sizes_init(void); 01655 01656 extern kmem_cache_t *kmem_find_general_cachep(size_t, int gfpflags); 01657 extern kmem_cache_t *kmem_cache_create(const char *, size_t, size_t, unsigned long, 01658 void (*)(void *, kmem_cache_t *, unsigned long), 01659 void (*)(void *, kmem_cache_t *, unsigned long)); 01660 extern int kmem_cache_destroy(kmem_cache_t *); 01661 extern int kmem_cache_shrink(kmem_cache_t *); 01662 extern void *kmem_cache_alloc(kmem_cache_t *, int); 01663 extern void kmem_cache_free(kmem_cache_t *, void *); 01664 extern unsigned int kmem_cache_size(kmem_cache_t *); 01665 01666 extern void *kmalloc(size_t, int); 01667 extern void kfree(const void *); 01668 01669 //extern int FASTCALL(kmem_cache_reap(int)); 01670 01671 /* System wide caches */ 01672 extern kmem_cache_t *vm_area_cachep; 01673 extern kmem_cache_t *mm_cachep; 01674 extern kmem_cache_t *names_cachep; 01675 extern kmem_cache_t *files_cachep; 01676 extern kmem_cache_t *filp_cachep; 01677 extern kmem_cache_t *dquot_cachep; 01678 extern kmem_cache_t *bh_cachep; 01679 extern kmem_cache_t *fs_cachep; 01680 extern kmem_cache_t *sigact_cachep; 01681 01682 #endif /* slab */ 01683 01684 01685 01686 /* 01687 * Berkeley style UIO structures - Alan Cox 1994. 01688 * 01689 * This program is free software; you can redistribute it and/or 01690 * modify it under the terms of the GNU General Public License 01691 * as published by the Free Software Foundation; either version 01692 * 2 of the License, or (at your option) any later version. 01693 */ 01694 01695 01696 /* A word of warning: Our uio structure will clash with the C library one (which is now obsolete). Remove the C 01697 library one from sys/uio.h if you have a very old library set */ 01698 01699 struct iovec 01700 { 01701 void *iov_base; /* BSD uses caddr_t (1003.1g requires void *) */ 01702 __kernel_size_t iov_len; /* Must be size_t (1003.1g) */ 01703 }; 01704 01705 /* 01706 * UIO_MAXIOV shall be at least 16 1003.1g (5.4.1.1) 01707 */ 01708 01709 #define UIO_FASTIOV 8 01710 #define UIO_MAXIOV 1024 01711 #if 0 01712 #define UIO_MAXIOV 16 /* Maximum iovec's in one operation 01713 16 matches BSD */ 01714 /* Beg pardon: BSD has 1024 --ANK */ 01715 #endif 01716 01717 01718 01719 /* 01720 * In Linux 2.4, static timers have been removed from the kernel. 01721 * Timers may be dynamically created and destroyed, and should be initialized 01722 * by a call to init_timer() upon creation. 01723 * 01724 * The "data" field enables use of a common timeout function for several 01725 * timeouts. You can use this field to distinguish between the different 01726 * invocations. 01727 */ 01728 struct timer_list { 01729 struct list_head list; 01730 unsigned long expires; 01731 unsigned long data; 01732 void (*function)(unsigned long); 01733 }; 01734 01735 01736 01737 struct timeval { 01738 unsigned long tv_sec; 01739 unsigned long tv_usec; 01740 // time_t tv_sec; /* seconds */ 01741 // suseconds_t tv_usec; /* microseconds */ 01742 }; 01743 01744 01745 01746 01747 01748 01749 01750 #if 1 /* poll */ 01751 01752 struct file; 01753 01754 struct poll_table_page; 01755 01756 typedef struct poll_table_struct { 01757 int error; 01758 struct poll_table_page * table; 01759 } poll_table; 01760 01761 extern void __pollwait(struct file * filp, wait_queue_head_t * wait_address, poll_table *p); 01762 01763 static inline void poll_wait(struct file * filp, wait_queue_head_t * wait_address, poll_table *p) 01764 { 01765 if (p && wait_address) 01766 __pollwait(filp, wait_address, p); 01767 } 01768 01769 static inline void poll_initwait(poll_table* pt) 01770 { 01771 pt->error = 0; 01772 pt->table = NULL; 01773 } 01774 extern void poll_freewait(poll_table* pt); 01775 01776 01777 /* 01778 * Scaleable version of the fd_set. 01779 */ 01780 01781 typedef struct { 01782 unsigned long *in, *out, *ex; 01783 unsigned long *res_in, *res_out, *res_ex; 01784 } fd_set_bits; 01785 01786 /* 01787 * How many longwords for "nr" bits? 01788 */ 01789 #define FDS_BITPERLONG (8*sizeof(long)) 01790 #define FDS_LONGS(nr) (((nr)+FDS_BITPERLONG-1)/FDS_BITPERLONG) 01791 #define FDS_BYTES(nr) (FDS_LONGS(nr)*sizeof(long)) 01792 01793 /* 01794 * We do a VERIFY_WRITE here even though we are only reading this time: 01795 * we'll write to it eventually.. 01796 * 01797 * Use "unsigned long" accesses to let user-mode fd_set's be long-aligned. 01798 */ 01799 static inline 01800 int get_fd_set(unsigned long nr, void *ufdset, unsigned long *fdset) 01801 { 01802 #if 0 01803 nr = FDS_BYTES(nr); 01804 if (ufdset) { 01805 int error; 01806 error = verify_area(VERIFY_WRITE, ufdset, nr); 01807 if (!error && __copy_from_user(fdset, ufdset, nr)) 01808 error = -EFAULT; 01809 return error; 01810 } 01811 memset(fdset, 0, nr); 01812 return 0; 01813 #else 01814 return 0; 01815 #endif 01816 } 01817 01818 static inline 01819 void set_fd_set(unsigned long nr, void *ufdset, unsigned long *fdset) 01820 { 01821 #if 0 01822 if (ufdset) 01823 __copy_to_user(ufdset, fdset, FDS_BYTES(nr)); 01824 #endif 01825 } 01826 01827 static inline 01828 void zero_fd_set(unsigned long nr, unsigned long *fdset) 01829 { 01830 #if 0 01831 memset(fdset, 0, FDS_BYTES(nr)); 01832 #endif 01833 } 01834 01835 extern int do_select(int n, fd_set_bits *fds, long *timeout); 01836 01837 #endif /* poll */ 01838 01839 01840 01841 typedef struct 01842 { 01843 int x; 01844 } read_descriptor_t; 01845 01846 01847 01848 01849 01850 #if 1 /* poll */ 01851 01852 /* These are specified by iBCS2 */ 01853 #define POLLIN 0x0001 01854 #define POLLPRI 0x0002 01855 #define POLLOUT 0x0004 01856 #define POLLERR 0x0008 01857 #define POLLHUP 0x0010 01858 #define POLLNVAL 0x0020 01859 01860 /* The rest seem to be more-or-less nonstandard. Check them! */ 01861 #define POLLRDNORM 0x0040 01862 #define POLLRDBAND 0x0080 01863 #define POLLWRNORM 0x0100 01864 #define POLLWRBAND 0x0200 01865 #define POLLMSG 0x0400 01866 01867 struct pollfd { 01868 int fd; 01869 short events; 01870 short revents; 01871 }; 01872 01873 #endif /* poll */ Generated on Sun May 27 2012 04:19:14 for ReactOS by
1.7.6.1
|