linux内核代码 sem.c 中结将结构体视为数组的问题 在Linux3.0.1的内核代码中:.../ipc/sem.c 的第1246行有如下代码:new->semadj = (short *) &new[1]; 其中: new 的定义为:struct sem_undo *new; new 通过这条语句申请空间:new = kzalloc(sizeof(struct sem_undo) + sizeof(short)*nsems, GFP_KERNEL); 其中使用到一些结构体的定义如下: in : .../ipc/sem.h /* * Each task has a list of undo requests. They are executed automatically * when the process exits. */ struct sem_undo { struct list_head list_proc; /* per-process list: all undos from one process. */ /* rcu protected */ struct rcu_head rcu; /* rcu struct for sem_undo() */ struct sem_undo_list *ulp; /* sem_undo_list for the process */ struct list_head list_id; /* per semaphore array list: all undos for one array */ int semid; /* semaphore set identifier */ short * semadj; /* array of adjustments, one per semaphore */ };
/* * sem_undo_list controls shared access to the list of sem_undo structures * that may be shared among all a CLONE_SYSVSEM task group. */ struct sem_undo_list { atomic_t refcnt; spinlock_t lock; struct list_head list_proc; };
in : .../include/linux/rcupdate.h /* * struct rcu_head - callback structure for use with RCU * @next: next update requests in a list * @func: actual update function to call after the grace period. */ struct rcu_head { struct rcu_head *next; void (*func)(struct rcu_head *head); };
in : .../include/linux/spinlock_types.h
typedef struct spinlock { union { struct raw_spinlock rlock;