Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

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

Name:wseg - Create a new shared memory segment*@ns: namespace*@params: ptr to the structure that contains key, size and shmflg* Called with shm_ids.rwsem held as a writer.

Proto:static int newseg(struct ipc_namespace *ns, struct ipc_params *params)

Type:int

Parameter:

TypeParameterName
struct ipc_namespace *ns
struct ipc_params *params
602  key = key
603  shmflg = flg
604  size = for shared memories
607  numpages = size + PAGE_SIZE - 1 >> PAGE_SHIFT determines the page size
610  acctflag = 0
612  If size < min shared seg size (bytes) || size > shm_ctlmax Then Return -EINVAL
615  If numpages << PAGE_SHIFT determines the page size < size Then Return -ENOSPC
618  If shm_tot + numpages < shm_tot || shm_tot + numpages > shm_ctlall Then Return -ENOSPC
622  shp = kvmalloc( size of shp , GFP_KERNEL)
623  If Value for the false possibility is greater at compile time(!shp) Then Return -ENOMEM
626  key = key
627  mode = shmflg & S_IRWXUGO
628  mlock_user = NULL
630  security = NULL
631  error = security_shm_alloc( & shm_perm)
632  If error Then
633  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.
634  Return error
637  sprintf - Format a string and place it in a buffer*@buf: The buffer to place the result into*@fmt: The format string to use*@...: Arguments for the format string* The function returns the number of characters written* into @buf
638  If shmflg & segment will use huge TLB pages Then
642  hs = hstate_sizelog((shmflg >> Huge page size encoding when SHM_HUGETLB is specified, and a huge page* size other than the default is desired. See hugetlb_encode.h) & SHM_HUGE_MASK)
643  If Not hs Then
644  error = -EINVAL
645  Go to no_file
647  hugesize = @a is a power of 2 value (size, huge_page_size(hs))
650  If shmflg & don't check for reservations Then acctflag = should the VM suppress accounting
652  file = hugetlb_file_setup(name, hugesize, acctflag, & mlock_user, HUGETLB_SHMFS_INODE, (shmflg >> Huge page size encoding when SHM_HUGETLB is specified, and a huge page* size other than the default is desired. See hugetlb_encode.h) & SHM_HUGE_MASK)
655  Else
660  If shmflg & don't check for reservations && sysctl_overcommit_memory != OVERCOMMIT_NEVER Then acctflag = should the VM suppress accounting
663  file = shmem_kernel_file_setup - get an unlinked file living in tmpfs which must be* kernel internal. There will be NO LSM permission checks against the* underlying inode. So users of this interface must do LSM checks at a* higher layer
665  error = PTR_ERR(file)
666  If IS_ERR(file) Then Go to no_file
669  shm_cprid = get_pid(task_tgid(current process))
670  shm_lprid = NULL
671  shm_atim = shm_dtim = 0
672  shm_ctim = 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.
673  shm_segsz = size
674  shm_nattch = 0
675  shm_file = file
676  The task created the shm object. NULL if the task is dead. = current process
679  error = pc_addid - add an ipc identifier*@ids: ipc identifier set*@new: new ipc permission set*@limit: limit for the number of used ids* Add an entry 'new' to the ipc ids idr
680  If error < 0 Then Go to no_id
683  list_add - add a new entry*@new: new entry to be added*@head: list head to add it after* Insert a new entry after the specified head.* This is good for implementing stacks.
689  Stat data, not accessed from path walking = id
691  shm_tot += numpages
692  error = id
694  ipc_unlock_object( & shm_perm)
695  _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()
696  Return error
698  no_id :
699  ipc_update_pid( & shm_cprid, NULL)
700  ipc_update_pid( & shm_lprid, NULL)
701  If is_file_hugepages(file) && mlock_user Then user_shm_unlock(size, mlock_user)
703  fput(file)
704  ipc_rcu_putref( & shm_perm, shm_rcu_free)
705  Return error
706  no_file :
707  Post an RCU callback to be invoked after the end of an RCU grace* period. But since we have but one CPU, that would be after any* quiescent state.
708  Return error