Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source Code:ipc\sem.c Create Date:2022-07-28 16:44:47
Last Modify:2020-03-12 14:18:49 Copyright©Brick
home page Tree
Annotation kernel can get tool activityDownload SCCTChinese

Name:semctl_main

Proto:static int semctl_main(struct ipc_namespace *ns, int semid, int semnum, int cmd, void __user *p)

Type:int

Parameter:

TypeParameterName
struct ipc_namespace *ns
intsemid
intsemnum
intcmd
void __user *p
1393  sem_io = fast_sem_io
1396  _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
1397  sma = sem_obtain_object_check(ns, semid)
1398  If IS_ERR(sma) Then
1399  _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()
1400  Return PTR_ERR(sma)
1403  nsems = . of semaphores in array
1405  err = -EACCES
1406  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_rcu_wakeup
1409  err = security_sem_semctl( & permissions .. see ipc.h , cmd)
1410  If err Then Go to out_rcu_wakeup
1413  err = -EACCES
1415  Case cmd == get all semval's
1417  __user * array = p
1420  If the request contains only one semaphore operation, and there are* no complex transactions pending, lock only the semaphore involved
1422  err = -EIDRM
1423  Go to out_unlock
1425  If nsems > 512 bytes on stack Then
1426  If Not ipc_rcu_getref( & permissions .. see ipc.h ) Then
1427  err = -EIDRM
1428  Go to out_unlock
1430  sem_unlock(sma, - 1)
1434  If (sem_io == NULL) Then
1442  err = -EIDRM
1443  Go to out_unlock
1446  When i < . of semaphores in array cycle sem_io[i] = current value
1448  sem_unlock(sma, - 1)
1449  _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()
1450  err = 0
1451  If copy_to_user(array, sem_io, nsems * sizeof(ushort)) Then err = -EFAULT
1453  Go to out_free
1455  Case cmd == set all semval's
1460  If Not ipc_rcu_getref( & permissions .. see ipc.h ) Then
1461  err = -EIDRM
1462  Go to out_rcu_wakeup
1464  _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()
1466  If nsems > 512 bytes on stack Then
1469  If (sem_io == NULL) Then
1475  If copy_from_user(sem_io, p, nsems * sizeof(ushort)) Then
1477  err = -EFAULT
1478  Go to out_free
1481  When i < nsems cycle
1488  _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
1489  sem_lock_and_putref(sma)
1491  err = -EIDRM
1492  Go to out_unlock
1495  When i < nsems cycle
1500  ipc_assert_locked_object( & permissions .. see ipc.h )
1502  When i < nsems cycle array of adjustments [i] = 0
1505  create/last semctl() time = ktime_get_real_seconds - Get the seconds portion of CLOCK_REALTIME* Returns the wall clock seconds since 1970. This replaces the* get_seconds() interface which is not y2038 safe on 32bit systems.
1507  do_smart_update - optimized update_queue*@sma: semaphore array*@sops: operations that were performed*@nsops: number of operations*@otime: force setting otime*@wake_q: lockless wake-queue head* do_smart_update() does the required calls to update_queue and
1508  err = 0
1509  Go to out_unlock
1513  err = -EINVAL
1514  If semnum < 0 || semnum >= nsems Then Go to out_rcu_wakeup
1517  If the request contains only one semaphore operation, and there are* no complex transactions pending, lock only the semaphore involved
1518  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
1519  err = -EIDRM
1520  Go to out_unlock
1523  semnum = array_index_nospec - sanitize an array index after a bounds check* For a code sequence like:* if (index < size) {* index = array_index_nospec(index, size);* val = array[index];* }* (semnum, nsems)
1524  curr = sems[semnum]
1527  Case cmd == get semval
1528  err = current value
1529  Go to out_unlock
1530  Case cmd == get sempid
1531  err = pid_vnr(PID of the process that last modified the semaphore. For* Linux, specifically these are:* - semop* - semctl, via SETVAL and SETALL.* - at task exit when performing undo adjustments (see exit_sem).)
1532  Go to out_unlock
1533  Case cmd == get semncnt
1534  err = The following counts are associated to each semaphore:* semncnt number of tasks waiting on semval being nonzero* semzcnt number of tasks waiting on semval being zero* Per definition, a task waits only on the semaphore of the first semop
1535  Go to out_unlock
1536  Case cmd == get semzcnt
1537  err = The following counts are associated to each semaphore:* semncnt number of tasks waiting on semval being nonzero* semzcnt number of tasks waiting on semval being zero* Per definition, a task waits only on the semaphore of the first semop
1538  Go to out_unlock
1541  out_unlock :
1542  sem_unlock(sma, - 1)
1543  out_rcu_wakeup :
1544  _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()
1545  wake_up_q( & wake_q)
1546  out_free :
1547  If sem_io != fast_sem_io Then kvfree() - Free memory.*@addr: Pointer to allocated memory.* kvfree frees memory allocated by any of vmalloc(), kmalloc() or kvmalloc().* It is slightly more efficient to use kfree() or vfree() if you are certain* that you know which one to use.
1549  Return err
Caller
NameDescribe
ksys_semctl
compat_ksys_semctl