#include <linux/slab.h>
#include <linux/mm.h>
#include <linux/hugetlb.h>
#include <linux/shm.h>
#include <uapi/linux/shm.h>
#include <linux/init.h>
#include <linux/file.h>
#include <linux/mman.h>
#include <linux/shmem_fs.h>
#include <linux/security.h>
#include <linux/syscalls.h>
#include <linux/audit.h>
#include <linux/capability.h>
#include <linux/ptrace.h>
#include <linux/seq_file.h>
#include <linux/rwsem.h>
#include <linux/nsproxy.h>
#include <linux/mount.h>
#include <linux/ipc_namespace.h>
#include <linux/rhashtable.h>
#include <linux/uaccess.h>
#include "util.h"
struct shmid_kernel
{ … } __randomize_layout;
#define SHM_DEST …
#define SHM_LOCKED …
struct shm_file_data { … };
#define shm_file_data(file) …
static const struct file_operations shm_file_operations;
static const struct vm_operations_struct shm_vm_ops;
#define shm_ids(ns) …
#define shm_unlock(shp) …
static int newseg(struct ipc_namespace *, struct ipc_params *);
static void shm_open(struct vm_area_struct *vma);
static void shm_close(struct vm_area_struct *vma);
static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
#ifdef CONFIG_PROC_FS
static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
#endif
void shm_init_ns(struct ipc_namespace *ns)
{ … }
static void do_shm_rmid(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp)
{ … }
#ifdef CONFIG_IPC_NS
void shm_exit_ns(struct ipc_namespace *ns)
{ … }
#endif
static int __init ipc_ns_init(void)
{ … }
pure_initcall(ipc_ns_init);
void __init shm_init(void)
{ … }
static inline struct shmid_kernel *shm_obtain_object(struct ipc_namespace *ns, int id)
{ … }
static inline struct shmid_kernel *shm_obtain_object_check(struct ipc_namespace *ns, int id)
{ … }
static inline struct shmid_kernel *shm_lock(struct ipc_namespace *ns, int id)
{ … }
static inline void shm_lock_by_ptr(struct shmid_kernel *ipcp)
{ … }
static void shm_rcu_free(struct rcu_head *head)
{ … }
static inline void shm_clist_rm(struct shmid_kernel *shp)
{ … }
static inline void shm_rmid(struct shmid_kernel *s)
{ … }
static int __shm_open(struct shm_file_data *sfd)
{ … }
static void shm_open(struct vm_area_struct *vma)
{ … }
static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
{ … }
static bool shm_may_destroy(struct shmid_kernel *shp)
{ … }
static void __shm_close(struct shm_file_data *sfd)
{ … }
static void shm_close(struct vm_area_struct *vma)
{ … }
static int shm_try_destroy_orphaned(int id, void *p, void *data)
{ … }
void shm_destroy_orphaned(struct ipc_namespace *ns)
{ … }
void exit_shm(struct task_struct *task)
{ … }
static vm_fault_t shm_fault(struct vm_fault *vmf)
{ … }
static int shm_may_split(struct vm_area_struct *vma, unsigned long addr)
{ … }
static unsigned long shm_pagesize(struct vm_area_struct *vma)
{ … }
#ifdef CONFIG_NUMA
static int shm_set_policy(struct vm_area_struct *vma, struct mempolicy *mpol)
{ … }
static struct mempolicy *shm_get_policy(struct vm_area_struct *vma,
unsigned long addr, pgoff_t *ilx)
{ … }
#endif
static int shm_mmap(struct file *file, struct vm_area_struct *vma)
{ … }
static int shm_release(struct inode *ino, struct file *file)
{ … }
static int shm_fsync(struct file *file, loff_t start, loff_t end, int datasync)
{ … }
static long shm_fallocate(struct file *file, int mode, loff_t offset,
loff_t len)
{ … }
static unsigned long shm_get_unmapped_area(struct file *file,
unsigned long addr, unsigned long len, unsigned long pgoff,
unsigned long flags)
{ … }
static const struct file_operations shm_file_operations = …;
static const struct file_operations shm_file_operations_huge = …;
static const struct vm_operations_struct shm_vm_ops = …;
static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
{ … }
static int shm_more_checks(struct kern_ipc_perm *ipcp, struct ipc_params *params)
{ … }
long ksys_shmget(key_t key, size_t size, int shmflg)
{ … }
SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
{ … }
static inline unsigned long copy_shmid_to_user(void __user *buf, struct shmid64_ds *in, int version)
{ … }
static inline unsigned long
copy_shmid_from_user(struct shmid64_ds *out, void __user *buf, int version)
{ … }
static inline unsigned long copy_shminfo_to_user(void __user *buf, struct shminfo64 *in, int version)
{ … }
static void shm_add_rss_swap(struct shmid_kernel *shp,
unsigned long *rss_add, unsigned long *swp_add)
{ … }
static void shm_get_stat(struct ipc_namespace *ns, unsigned long *rss,
unsigned long *swp)
{ … }
static int shmctl_down(struct ipc_namespace *ns, int shmid, int cmd,
struct shmid64_ds *shmid64)
{ … }
static int shmctl_ipc_info(struct ipc_namespace *ns,
struct shminfo64 *shminfo)
{ … }
static int shmctl_shm_info(struct ipc_namespace *ns,
struct shm_info *shm_info)
{ … }
static int shmctl_stat(struct ipc_namespace *ns, int shmid,
int cmd, struct shmid64_ds *tbuf)
{ … }
static int shmctl_do_lock(struct ipc_namespace *ns, int shmid, int cmd)
{ … }
static long ksys_shmctl(int shmid, int cmd, struct shmid_ds __user *buf, int version)
{ … }
SYSCALL_DEFINE3(shmctl, int, shmid, int, cmd, struct shmid_ds __user *, buf)
{ … }
#ifdef CONFIG_ARCH_WANT_IPC_PARSE_VERSION
long ksys_old_shmctl(int shmid, int cmd, struct shmid_ds __user *buf)
{
int version = ipc_parse_version(&cmd);
return ksys_shmctl(shmid, cmd, buf, version);
}
SYSCALL_DEFINE3(old_shmctl, int, shmid, int, cmd, struct shmid_ds __user *, buf)
{
return ksys_old_shmctl(shmid, cmd, buf);
}
#endif
#ifdef CONFIG_COMPAT
struct compat_shmid_ds { … };
struct compat_shminfo64 { … };
struct compat_shm_info { … };
static int copy_compat_shminfo_to_user(void __user *buf, struct shminfo64 *in,
int version)
{ … }
static int put_compat_shm_info(struct shm_info *ip,
struct compat_shm_info __user *uip)
{ … }
static int copy_compat_shmid_to_user(void __user *buf, struct shmid64_ds *in,
int version)
{ … }
static int copy_compat_shmid_from_user(struct shmid64_ds *out, void __user *buf,
int version)
{ … }
static long compat_ksys_shmctl(int shmid, int cmd, void __user *uptr, int version)
{ … }
COMPAT_SYSCALL_DEFINE3(shmctl, int, shmid, int, cmd, void __user *, uptr)
{ … }
#ifdef CONFIG_ARCH_WANT_COMPAT_IPC_PARSE_VERSION
long compat_ksys_old_shmctl(int shmid, int cmd, void __user *uptr)
{ … }
COMPAT_SYSCALL_DEFINE3(old_shmctl, int, shmid, int, cmd, void __user *, uptr)
{ … }
#endif
#endif
long do_shmat(int shmid, char __user *shmaddr, int shmflg,
ulong *raddr, unsigned long shmlba)
{ … }
SYSCALL_DEFINE3(shmat, int, shmid, char __user *, shmaddr, int, shmflg)
{ … }
#ifdef CONFIG_COMPAT
#ifndef COMPAT_SHMLBA
#define COMPAT_SHMLBA …
#endif
COMPAT_SYSCALL_DEFINE3(shmat, int, shmid, compat_uptr_t, shmaddr, int, shmflg)
{ … }
#endif
long ksys_shmdt(char __user *shmaddr)
{ … }
SYSCALL_DEFINE1(shmdt, char __user *, shmaddr)
{ … }
#ifdef CONFIG_PROC_FS
static int sysvipc_shm_proc_show(struct seq_file *s, void *it)
{ … }
#endif