11. 共有メモリ管理オブジェクト
• include/linux/shm.h
9 struct shmid_kernel /* private to the kernel */
10 {
11 struct kern_ipc_perm shm_perm;
12 struct file *shm_file;
13 unsigned long shm_nattch;
14 unsigned long shm_segsz;
15 time_t shm_atim;
16 time_t shm_dtim;
17 time_t shm_ctim;
18 pid_t shm_cprid;
19 pid_t shm_lprid;
20 struct user_struct *mlock_user;
21
22 /* The task created the shm object. NULL if the task is dead. */
23 struct task_struct *shm_creator;
24 struct list_head shm_clist; /* list by creator */
25 };
12. セマフォ管理オブジェクト
• include/linux/sem.h
12 struct sem_array {
13 struct kern_ipc_perm ____cacheline_aligned_in_smp
14 sem_perm; /* permissions .. see ipc.h */
15 time_t sem_ctime; /* last change time */
16 struct sem *sem_base; /* ptr to first semaphore in
array */
17 struct list_head pending_alter; /* pending operations */
18 /* that alter the array */
19 struct list_head pending_const; /* pending complex operations */
20 /* that do not alter semvals */
21 struct list_head list_id; /* undo requests on this array
*/
22 int sem_nsems; /* no. of semaphores in array */
23 int complex_count; /* pending complex operations */
24 };
13. message queue管理オブジェクト
• include/linux/msg.h
18 struct msg_queue {
19 struct kern_ipc_perm q_perm;
20 time_t q_stime; /* last msgsnd time */
21 time_t q_rtime; /* last msgrcv time */
22 time_t q_ctime; /* last change time */
23 unsigned long q_cbytes; /* current number of bytes on queue
*/
24 unsigned long q_qnum; /* number of messages in queue */
25 unsigned long q_qbytes; /* max number of bytes on queue */
26 pid_t q_lspid; /* pid of last msgsnd */
27 pid_t q_lrpid; /* last receive pid */
28
29 struct list_head q_messages;
30 struct list_head q_receivers;
31 struct list_head q_senders;
32 };
27. ipcget()の流れ
ipcget()
--> ipcget_new() // if key is IPC_PRIVATE
--> ipcget_public() // if key is not IPC_PRIVATE
--> ipc_findkey() // find key
--> ipcget_new() // if key is not found
--> ipc_check_perms() // if found key
--> (struct ips_ops *)->more_checks()
--> (struct ips_ops *)->associate()
ipcget_new()
--> (struct ipc_ops *)->getnew()
34. セグメントattachの流れ
do_shmat()
--> path_get() // get a file path for shmem
--> alloc_file() // allocate a file object
--> do_mmap_pgoff() // map the file object
--> shm_may_destroy() // check if other process
destroying this shmem
--> shm_destroy() // other process destorying
this shmem
--> shm_unlock() // no one destorys this shmem
37. セグメントdetatchの流れ
shmdt()
--> find_vma() // find a vm_area_struct from
address
--> file_inode() // if vma is found, find
an inode to get file(segment) size
--> do_munmap() // unmap the address
--> do_munmap()
40. セグメント破棄の流れ
shmctl()
--> shmctl_down()
--> do_shm_rmid()
--> shm_unlock() // someone using this segment
--> shm_destroy() // anyone using it
--> shm_rmid() // remove id from namespace and segment's
list
--> shm_unlock()
--> shm_lock() // if shmflg is not SHM_HUGETLB
--> user_shm_unlock() // else if (struct shmid *)-
>mlock_user isn't 0
--> fput() // remove file object