Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source Code:ipc\shm.c Create Date:2022-07-28 16:48:29
Last Modify:2020-03-17 22:58:32 Copyright©Brick
home page Tree
Annotation kernel can get tool activityDownload SCCTChinese

Name:Fix shmaddr, allocate descriptor, map shm, add attach descriptor to lists.* NOTE! Despite the name, this is NOT a direct system call entrypoint. The* "raddr" thing points to kernel space, and there has to be a wrapper around* this.

Proto:long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr, unsigned long shmlba)

Type:long

Parameter:

TypeParameterName
intshmid
char __user *shmaddr
intshmflg
ulong *raddr
unsigned longshmlba
1422  addr = shmaddr
1426  flags = Share changes
1432  populate = 0
1434  err = -EINVAL
1435  If shmid < 0 Then Go to out
1438  If addr Then
1439  If addr & shmlba - 1 Then
1441  addr &= ~(shmlba - 1)
1448  If Not addr && shmflg & ake-over region on attach Then Go to out
1450  Else If addr & ~PAGE_MASK Then
1454  Go to out
1457  flags |= Interpret addr exactly
1458  Else if shmflg & ake-over region on attach Then Go to out
1461  If shmflg & ad-only access Then
1462  prot = page can be read
1463  acc_mode = S_IRUGO
1464  f_flags = O_RDONLY
1465  Else
1466  prot = page can be read | page can be written
1467  acc_mode = S_IRUGO | S_IWUGO
1468  f_flags = O_RDWR
1470  If shmflg & xecution access Then
1471  prot |= page can be executed
1472  acc_mode |= S_IXUGO
1479  ns = ipc_ns
1480  _read_lock() - mark the beginning of an RCU read-side critical section* When synchronize_rcu() is invoked on one CPU while other CPUs* are within RCU read-side critical sections, then the* synchronize_rcu() is guaranteed to block until after all the other
1481  shp = shm_obtain_object_check(ns, shmid)
1482  If IS_ERR(shp) Then
1483  err = PTR_ERR(shp)
1484  Go to out_unlock
1487  err = -EACCES
1488  If pcperms - check ipc permissions*@ns: ipc namespace*@ipcp: ipc permission set*@flag: desired permission set* Check user, group, other permissions for access* to ipc resources. return 0 if allowed*@flag will most probably be 0 or ``S_ Then Go to out_unlock
1491  err = security_shm_shmat( & shm_perm, shmaddr, shmflg)
1492  If err Then Go to out_unlock
1495  ipc_lock_object( & shm_perm)
1498  If Not pc_valid_object() - helper to sort out IPC_RMID races for codepaths* where the respective ipc_ids.rwsem is not being held down.* Checks whether the ipc object is still around or if it's gone already, as Then
1499  ipc_unlock_object( & shm_perm)
1500  err = -EIDRM
1501  Go to out_unlock
1513  base = get_file(shm_file)
1514  shm_nattch++
1515  size = NOTE: in a 32bit arch with a preemptable kernel and* an UP compile the i_size_read/write must be atomic* with respect to the local cpu (unlike with preempt disabled),* but they don't need to be atomic with respect to other cpus like in* true SMP (so they
1516  ipc_unlock_object( & shm_perm)
1517  _read_unlock() - marks the end of an RCU read-side critical section.* In most situations, rcu_read_unlock() is immune from deadlock.* However, in kernels built with CONFIG_RCU_BOOST, rcu_read_unlock()
1519  err = -ENOMEM
1520  sfd = kzalloc - allocate memory. The memory is set to zero.*@size: how many bytes of memory are required.*@flags: the type of memory to allocate (see kmalloc).
1521  If Not sfd Then
1522  fput(base)
1523  Go to out_nattch
1526  file = alloc_file_clone(base, f_flags, is_file_hugepages(base) ? & shm_file_operations_huge is now identical to shm_file_operations,* but we keep it distinct for the sake of is_file_shm_hugepages(). : & shm_file_operations)
1530  err = PTR_ERR(file)
1531  If IS_ERR(file) Then
1532  kfree(sfd)
1533  fput(base)
1534  Go to out_nattch
1537  id = id
1538  ns = get_ipc_ns(ns)
1539  file = base
1540  vm_ops = NULL
1541  needed for tty driver, and maybe others = sfd
1543  err = security_mmap_file(file, prot, flags)
1544  If err Then Go to out_fput
1547  If lock for writing Then
1548  err = -EINTR
1549  Go to out_fput
1552  If addr && Not (shmflg & ake-over region on attach ) Then
1553  err = -EINVAL
1554  If addr + size < addr Then Go to invalid
1557  If Look up the first VMA which intersects the interval start_addr..end_addr-1,NULL if none. Assume start_addr < end_addr. Then Go to invalid
1561  addr = do_mmap_pgoff(file, addr, size, prot, flags, 0, & populate, NULL)
1562  raddr = addr
1563  err = 0
1564  If IS_ERR_VALUE(addr) Then err = addr
1566  invalid :
1567  lease a write lock
1568  If populate Then mm_populate(addr, populate)
1571  out_fput :
1572  fput(file)
1574  out_nattch :
1575  lock for writing
1576  shp = shm_lock_(check_) routines are called in the paths where the rwsem* is not necessarily held.
1577  shm_nattch--
1578  If shm_may_destroy - identifies whether shm segment should be destroyed now* Returns true if and only if there are no active users of the segment and* one of the following is true:* 1) shmctl(id, IPC_RMID, NULL) was called for this shp* 2) sysctl kernel Then shm_destroy(ns, shp)
1580  Else shm_unlock(shp)
1582  lease a write lock
1583  Return err
1585  out_unlock :
1586  _read_unlock() - marks the end of an RCU read-side critical section.* In most situations, rcu_read_unlock() is immune from deadlock.* However, in kernels built with CONFIG_RCU_BOOST, rcu_read_unlock()
1587  out :
1588  Return err
Caller
NameDescribe
SYSCALL_DEFINE3
COMPAT_SYSCALL_DEFINE3
ksys_ipc