40 likes | 100 Views
shmget() : Argument Values. key same as before; we use getuid() to make it unique size number of bytes to allocate shmflag Creating: IPC_CREAT and permissions 0 for accessing only. Notes on shmat() arguments. shmid is as before
E N D
shmget(): Argument Values key • same as before; we use getuid() to make it unique size • number of bytes to allocate shmflag • Creating: IPC_CREAT and permissions • 0 for accessing only
Notes on shmat() arguments • shmid is as before • 2nd and 3rd arguments can be used to attach to a specific address within shmem, but it is an absolute address, requiring knowledge of the address of the shared memory segment • Almost always, 2nd and 3rd arguments are 0
Shared Memory Data Structure /* One shmid data structure for each shared memory segment in the system. */ struct shmid_ds { struct ipc_perm shm_perm; /* operation perms */ int shm_segsz; /* size of segment (bytes) */ time_t shm_atime; /* last attach time */ time_t shm_dtime; /* last detach time */ time_t shm_ctime; /* last change time */ unsigned short shm_cpid; /* pid of creator */ unsigned short shm_lpid; /* pid of last operator */ short shm_nattch; /* no. of current attaches */ /* the following are private */ unsigned short shm_npages; /* size of segment (pages) */ unsigned long *shm_pages; /* array of ptrs to frames -> SHMMAX */ struct vm_area_struct *attaches; /* descriptors for attaches */ };
Virtual Memory Area Structure vm_area_struct • defines a memory VMM memory area. There is one of these per VM-area/task. A VM area is any part of the process virtual memory space that has a special rule for the page-fault handlers (ie a shared library, the executable area etc). struct vm_area_struct { struct mm_struct * vm_mm; unsigned long vm_start; unsigned long vm_end; struct vm_area_struct *vm_next; pgprot_t vm_page_prot; unsigned long vm_flags; rb_node_t vm_rb; struct vm_area_struct *vm_next_share; struct vm_area_struct **vm_pprev_share; struct vm_operations_struct * vm_ops; unsigned long vm_pgoff; struct file * vm_file; unsigned long vm_raend; void * vm_private_data; };