Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

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

Name:do_semtimedop

Proto:static long do_semtimedop(int semid, struct sembuf __user *tsops, unsigned nsops, const struct timespec64 *timeout)

Type:long

Parameter:

TypeParameterName
intsemid
struct sembuf __user *tsops
unsignednsops
const struct timespec64 *timeout
1969  error = -EINVAL
1972  sops = fast_sops
1975  bool undos = TSC's on different sockets may be reset asynchronously.* This may cause the TSC ADJUST value on socket 0 to be NOT 0., alter = TSC's on different sockets may be reset asynchronously.* This may cause the TSC ADJUST value on socket 0 to be NOT 0., dupsop = false
1977  dup = 0 , jiffies_left = 0
1980  ns = ipc_ns
1982  If nsops < 1 || semid < 0 Then Return -EINVAL
1984  If nsops > sc_semopm Then Return -E2BIG
1986  If nsops > ~ 372 bytes on stack Then
1987  sops = kvmalloc_array(nsops, size of sops , GFP_KERNEL)
1988  If (sops == NULL) Then Return -ENOMEM
1992  If copy_from_user(sops, tsops, nsops * size of tsops ) Then
1993  error = -EFAULT
1994  Go to out_free
1997  If timeout Then
1998  If seconds < 0 || nanoseconds < 0 || nanoseconds >= 1000000000L Then
2000  error = -EINVAL
2001  Go to out_free
2003  jiffies_left = timespec64_to_jiffies(timeout)
2006  max = 0
2007  When sop < sops + nsops cycle
2008  mask = 1ULL << semaphore index in array % BITS_PER_LONG
2010  If semaphore index in array >= max Then max = semaphore index in array
2012  If peration flags & undo the operation on exit Then undos = true
2014  If dup & mask Then
2021  dupsop = true
2023  If semaphore operation != 0 Then
2024  alter = true
2025  dup |= mask
2029  If undos Then
2031  un = d_alloc_undo - lookup (and if not present create) undo array*@ns: namespace*@semid: semaphore array id* The function looks up (and if not present creates) the undo structure.* The size of the undo structure depends on the size of the semaphore
2032  If IS_ERR(un) Then
2033  error = PTR_ERR(un)
2034  Go to out_free
2036  Else
2037  un = NULL
2038  _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
2041  sma = sem_obtain_object_check(ns, semid)
2042  If IS_ERR(sma) Then
2043  _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()
2044  error = PTR_ERR(sma)
2045  Go to out_free
2048  error = -EFBIG
2049  If max >= . of semaphores in array Then
2050  _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()
2051  Go to out_free
2054  error = -EACCES
2055  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
2056  _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()
2057  Go to out_free
2060  error = security_sem_semop( & permissions .. see ipc.h , sops, nsops, alter)
2061  If error Then
2062  _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()
2063  Go to out_free
2066  error = -EIDRM
2067  locknum = If the request contains only one semaphore operation, and there are* no complex transactions pending, lock only the semaphore involved
2076  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 Go to out_unlock_free
2085  If un && semaphore set identifier == -1 Then Go to out_unlock_free
2088  array of pending operations = sops
2089  umber of operations = nsops
2090  undo structure = un
2091  process id of requesting process = task_tgid(current process)
2092  does *sops alter the array? = alter
2093  sops on more than one sem_num = dupsop
2095  error = perform_atomic_semop(sma, & queue)
2096  If error == 0 Then
2103  If alter Then 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
2105  Else set_semotime - set sem_otime*@sma: semaphore array*@sops: operations that modified the array, may be NULL* sem_otime is replicated to avoid cache line trashing.* This function sets one instance to the current time.
2108  sem_unlock(sma, locknum)
2109  _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()
2110  wake_up_q( & wake_q)
2112  Go to out_free
2114  If error < 0 Then Go to out_unlock_free
2121  If nsops == 1 Then
2123  idx = 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];* }* (semaphore index in array , . of semaphores in array )
2124  curr = sems[idx]
2126  If alter Then
2130  Else
2135  Else
2138  Else
2139  If Not pending complex operations Then merge_queues - merge single semop queues into global queue*@sma: semaphore array* This function merges all per-semaphore queues into the global queue.* It is necessary to achieve FIFO ordering for the pending single-sop
2142  If alter Then list_add_tail - add a new entry*@new: new entry to be added*@head: list head to add it before* Insert a new entry before the specified head.* This is useful for implementing queues.
2144  Else list_add_tail - add a new entry*@new: new entry to be added*@head: list head to add it before* Insert a new entry before the specified head.* This is useful for implementing queues.
2147  pending complex operations ++
2150  Do
2151  WRITE_ONCE(completion status of operation , - EINTR)
2152  his process = current process
2154  set_current_state() includes a barrier so that the write of current->state* is correctly serialised wrt the caller's subsequent test of whether to* actually sleep:* for (;;) {* set_current_state(TASK_UNINTERRUPTIBLE);* if (!need_sleep)* break;* (TASK_INTERRUPTIBLE)
2155  sem_unlock(sma, locknum)
2156  _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()
2158  If timeout Then jiffies_left = schedule_timeout - sleep until timeout*@timeout: timeout value in jiffies* Make the current task sleep until @timeout jiffies have* elapsed
2160  Else schedule()
2174  error = READ_ONCE(completion status of operation )
2175  If error != -EINTR Then
2182  smp_mb()
2183  Go to out_free
2186  _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
2187  locknum = If the request contains only one semaphore operation, and there are* no complex transactions pending, lock only the semaphore involved
2189  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 Go to out_unlock_free
2192  error = READ_ONCE(completion status of operation )
2198  If error != -EINTR Then Go to out_unlock_free
2204  If timeout && jiffies_left == 0 Then error = -EAGAIN
2206  When error == -EINTR && Not signal_pending(current process) cycle
2208  unlink_queue(sma, & queue)
2210  out_unlock_free :
2211  sem_unlock(sma, locknum)
2212  _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()
2213  out_free :
2214  If sops != fast_sops 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.
2216  Return error
Caller
NameDescribe
ksys_semtimedop
SYSCALL_DEFINE3