linux.h
来自「这是一个开放源代码的与WINNT/WIN2K/WIN2003兼容的操作系统」· C头文件 代码 · 共 1,877 行 · 第 1/4 页
H
1,877 行
long __magic;
long __creator;
#endif
};
typedef struct __wait_queue_head wait_queue_head_t;
/*
* Debugging macros. We eschew `do { } while (0)' because gcc can generate
* spurious .aligns.
*/
#if WAITQUEUE_DEBUG
#define WQ_BUG() BUG()
#define CHECK_MAGIC(x)
#if 0
do { \
if ((x) != (long)&(x)) { \
printk("bad magic %lx (should be %lx), ", \
(long)x, (long)&(x)); \
WQ_BUG(); \
} \
} while (0)
#endif
#define CHECK_MAGIC_WQHEAD(x)
#if 0
do { \
if ((x)->__magic != (long)&((x)->__magic)) { \
printk("bad magic %lx (should be %lx, creator %lx), ", \
(x)->__magic, (long)&((x)->__magic), (x)->__creator); \
WQ_BUG(); \
} \
} while (0)
#endif
#define WQ_CHECK_LIST_HEAD(list)
#if 0
do { \
if (!(list)->next || !(list)->prev) \
WQ_BUG(); \
} while(0)
#endif
#define WQ_NOTE_WAKER(tsk)
#if 0
do { \
(tsk)->__waker = (long)__builtin_return_address(0); \
} while (0)
#endif
#else
#define WQ_BUG()
#define CHECK_MAGIC(x)
#define CHECK_MAGIC_WQHEAD(x)
#define WQ_CHECK_LIST_HEAD(list)
#define WQ_NOTE_WAKER(tsk)
#endif
/*
* Macros for declaration and initialisaton of the datatypes
*/
#if WAITQUEUE_DEBUG
# define __WAITQUEUE_DEBUG_INIT(name) //(long)&(name).__magic, 0
# define __WAITQUEUE_HEAD_DEBUG_INIT(name) //(long)&(name).__magic, (long)&(name).__magic
#else
# define __WAITQUEUE_DEBUG_INIT(name)
# define __WAITQUEUE_HEAD_DEBUG_INIT(name)
#endif
#define __WAITQUEUE_INITIALIZER(name, tsk)
#if 0
{
task: tsk, \
task_list: { NULL, NULL }, \
__WAITQUEUE_DEBUG_INIT(name)}
#endif
#define DECLARE_WAITQUEUE(name, tsk)
#if 0
wait_queue_t name = __WAITQUEUE_INITIALIZER(name, tsk)
#endif
#define __WAIT_QUEUE_HEAD_INITIALIZER(name)
#if 0
{
lock: WAITQUEUE_RW_LOCK_UNLOCKED, \
task_list: { &(name).task_list, &(name).task_list }, \
__WAITQUEUE_HEAD_DEBUG_INIT(name)}
#endif
#define DECLARE_WAIT_QUEUE_HEAD(name)
#if 0
wait_queue_head_t name = __WAIT_QUEUE_HEAD_INITIALIZER(name)
#endif
static inline void init_waitqueue_head(wait_queue_head_t *q)
{
#if 0
#if WAITQUEUE_DEBUG
if (!q)
WQ_BUG();
#endif
q->lock = WAITQUEUE_RW_LOCK_UNLOCKED;
INIT_LIST_HEAD(&q->task_list);
#if WAITQUEUE_DEBUG
q->__magic = (long)&q->__magic;
q->__creator = (long)current_text_addr();
#endif
#endif
}
static inline void init_waitqueue_entry(wait_queue_t *q, struct task_struct *p)
{
#if 0
#if WAITQUEUE_DEBUG
if (!q || !p)
WQ_BUG();
#endif
q->flags = 0;
q->task = p;
#if WAITQUEUE_DEBUG
q->__magic = (long)&q->__magic;
#endif
#endif
}
static inline int waitqueue_active(wait_queue_head_t *q)
{
#if 0
#if WAITQUEUE_DEBUG
if (!q)
WQ_BUG();
CHECK_MAGIC_WQHEAD(q);
#endif
return !list_empty(&q->task_list);
#endif
}
static inline void __add_wait_queue(wait_queue_head_t *head, wait_queue_t *new)
{
#if 0
#if WAITQUEUE_DEBUG
if (!head || !new)
WQ_BUG();
CHECK_MAGIC_WQHEAD(head);
CHECK_MAGIC(new->__magic);
if (!head->task_list.next || !head->task_list.prev)
WQ_BUG();
#endif
list_add(&new->task_list, &head->task_list);
#endif
}
/*
* Used for wake-one threads:
*/
static inline void __add_wait_queue_tail(wait_queue_head_t *head,
wait_queue_t *new)
{
#if 0
#if WAITQUEUE_DEBUG
if (!head || !new)
WQ_BUG();
CHECK_MAGIC_WQHEAD(head);
CHECK_MAGIC(new->__magic);
if (!head->task_list.next || !head->task_list.prev)
WQ_BUG();
#endif
list_add_tail(&new->task_list, &head->task_list);
#endif
}
static inline void __remove_wait_queue(wait_queue_head_t *head,
wait_queue_t *old)
{
#if 0
#if WAITQUEUE_DEBUG
if (!old)
WQ_BUG();
CHECK_MAGIC(old->__magic);
#endif
list_del(&old->task_list);
#endif
}
#endif /* wait */
#endif
#if 1 /* slab */
typedef struct
{
int x;
} kmem_cache_s;
typedef struct kmem_cache_s kmem_cache_t;
#if 0
#include <linux/mm.h>
#include <linux/cache.h>
#endif
/* flags for kmem_cache_alloc() */
#define SLAB_NOFS GFP_NOFS
#define SLAB_NOIO GFP_NOIO
#define SLAB_NOHIGHIO GFP_NOHIGHIO
#define SLAB_ATOMIC GFP_ATOMIC
#define SLAB_USER GFP_USER
#define SLAB_KERNEL GFP_KERNEL
#define SLAB_NFS GFP_NFS
#define SLAB_DMA GFP_DMA
#define SLAB_LEVEL_MASK (__GFP_WAIT|__GFP_HIGH|__GFP_IO|__GFP_HIGHIO|__GFP_FS)
#define SLAB_NO_GROW 0x00001000UL /* don't grow a cache */
/* flags to pass to kmem_cache_create().
* The first 3 are only valid when the allocator as been build
* SLAB_DEBUG_SUPPORT.
*/
#define SLAB_DEBUG_FREE 0x00000100UL /* Peform (expensive) checks on free */
#define SLAB_DEBUG_INITIAL 0x00000200UL /* Call constructor (as verifier) */
#define SLAB_RED_ZONE 0x00000400UL /* Red zone objs in a cache */
#define SLAB_POISON 0x00000800UL /* Poison objects */
#define SLAB_NO_REAP 0x00001000UL /* never reap from the cache */
#define SLAB_HWCACHE_ALIGN 0x00002000UL /* align objs on a h/w cache lines */
#define SLAB_CACHE_DMA 0x00004000UL /* use GFP_DMA memory */
#define SLAB_MUST_HWCACHE_ALIGN 0x00008000UL /* force alignment */
/* flags passed to a constructor func */
#define SLAB_CTOR_CONSTRUCTOR 0x001UL /* if not set, then deconstructor */
#define SLAB_CTOR_ATOMIC 0x002UL /* tell constructor it can't sleep */
#define SLAB_CTOR_VERIFY 0x004UL /* tell constructor it's a verify call */
/* prototypes */
extern void kmem_cache_init(void);
extern void kmem_cache_sizes_init(void);
extern kmem_cache_t *kmem_find_general_cachep(size_t, int gfpflags);
extern kmem_cache_t *kmem_cache_create(const char *, size_t, size_t, unsigned long,
void (*)(void *, kmem_cache_t *, unsigned long),
void (*)(void *, kmem_cache_t *, unsigned long));
extern int kmem_cache_destroy(kmem_cache_t *);
extern int kmem_cache_shrink(kmem_cache_t *);
extern void *kmem_cache_alloc(kmem_cache_t *, int);
extern void kmem_cache_free(kmem_cache_t *, void *);
extern unsigned int kmem_cache_size(kmem_cache_t *);
extern void *kmalloc(size_t, int);
extern void kfree(const void *);
//extern int FASTCALL(kmem_cache_reap(int));
/* System wide caches */
extern kmem_cache_t *vm_area_cachep;
extern kmem_cache_t *mm_cachep;
extern kmem_cache_t *names_cachep;
extern kmem_cache_t *files_cachep;
extern kmem_cache_t *filp_cachep;
extern kmem_cache_t *dquot_cachep;
extern kmem_cache_t *bh_cachep;
extern kmem_cache_t *fs_cachep;
extern kmem_cache_t *sigact_cachep;
#endif /* slab */
/*
* Berkeley style UIO structures - Alan Cox 1994.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/
/* A word of warning: Our uio structure will clash with the C library one (which is now obsolete). Remove the C
library one from sys/uio.h if you have a very old library set */
struct iovec
{
void *iov_base; /* BSD uses caddr_t (1003.1g requires void *) */
__kernel_size_t iov_len; /* Must be size_t (1003.1g) */
};
/*
* UIO_MAXIOV shall be at least 16 1003.1g (5.4.1.1)
*/
#define UIO_FASTIOV 8
#define UIO_MAXIOV 1024
#if 0
#define UIO_MAXIOV 16 /* Maximum iovec's in one operation
16 matches BSD */
/* Beg pardon: BSD has 1024 --ANK */
#endif
/*
* In Linux 2.4, static timers have been removed from the kernel.
* Timers may be dynamically created and destroyed, and should be initialized
* by a call to init_timer() upon creation.
*
* The "data" field enables use of a common timeout function for several
* timeouts. You can use this field to distinguish between the different
* invocations.
*/
struct timer_list {
struct list_head list;
unsigned long expires;
unsigned long data;
void (*function)(unsigned long);
};
struct timeval {
unsigned long tv_sec;
unsigned long tv_usec;
// time_t tv_sec; /* seconds */
// suseconds_t tv_usec; /* microseconds */
};
#if 1 /* poll */
struct file;
struct poll_table_page;
typedef struct poll_table_struct {
int error;
struct poll_table_page * table;
} poll_table;
extern void __pollwait(struct file * filp, wait_queue_head_t * wait_address, poll_table *p);
static inline void poll_wait(struct file * filp, wait_queue_head_t * wait_address, poll_table *p)
{
if (p && wait_address)
__pollwait(filp, wait_address, p);
}
static inline void poll_initwait(poll_table* pt)
{
pt->error = 0;
pt->table = NULL;
}
extern void poll_freewait(poll_table* pt);
/*
* Scaleable version of the fd_set.
*/
typedef struct {
unsigned long *in, *out, *ex;
unsigned long *res_in, *res_out, *res_ex;
} fd_set_bits;
/*
* How many longwords for "nr" bits?
*/
#define FDS_BITPERLONG (8*sizeof(long))
#define FDS_LONGS(nr) (((nr)+FDS_BITPERLONG-1)/FDS_BITPERLONG)
#define FDS_BYTES(nr) (FDS_LONGS(nr)*sizeof(long))
/*
* We do a VERIFY_WRITE here even though we are only reading this time:
* we'll write to it eventually..
*
* Use "unsigned long" accesses to let user-mode fd_set's be long-aligned.
*/
static inline
int get_fd_set(unsigned long nr, void *ufdset, unsigned long *fdset)
{
#if 0
nr = FDS_BYTES(nr);
if (ufdset) {
int error;
error = verify_area(VERIFY_WRITE, ufdset, nr);
if (!error && __copy_from_user(fdset, ufdset, nr))
error = -EFAULT;
return error;
}
memset(fdset, 0, nr);
return 0;
#else
return 0;
#endif
}
static inline
void set_fd_set(unsigned long nr, void *ufdset, unsigned long *fdset)
{
#if 0
if (ufdset)
__copy_to_user(ufdset, fdset, FDS_BYTES(nr));
#endif
}
static inline
void zero_fd_set(unsigned long nr, unsigned long *fdset)
{
#if 0
memset(fdset, 0, FDS_BYTES(nr));
#endif
}
extern int do_select(int n, fd_set_bits *fds, long *timeout);
#endif /* poll */
typedef struct
{
int x;
} read_descriptor_t;
#if 1 /* poll */
/* These are specified by iBCS2 */
#define POLLIN 0x0001
#define POLLPRI 0x0002
#define POLLOUT 0x0004
#define POLLERR 0x0008
#define POLLHUP 0x0010
#define POLLNVAL 0x0020
/* The rest seem to be more-or-less nonstandard. Check them! */
#define POLLRDNORM 0x0040
#define POLLRDBAND 0x0080
#define POLLWRNORM 0x0100
#define POLLWRBAND 0x0200
#define POLLMSG 0x0400
struct pollfd {
int fd;
short events;
short revents;
};
#endif /* poll */
#endif /* _LINUX_TYPES_H */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?