blob: 9c8b942bd67f0bdb18ec674280e36c293ccde499 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _LINUX_SHM_H_
2#define _LINUX_SHM_H_
3
Jack Millerab602f72014-08-08 14:23:19 -07004#include <linux/list.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005#include <asm/page.h>
David Howells607ca462012-10-13 10:46:48 +01006#include <uapi/linux/shm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <asm/shmparam.h>
Manfred Spraul060028b2014-06-06 14:37:42 -07008
Linus Torvalds1da177e2005-04-16 15:20:36 -07009struct shmid_kernel /* private to the kernel */
10{
11 struct kern_ipc_perm shm_perm;
Manfred Spraul239521f2014-01-27 17:07:04 -080012 struct file *shm_file;
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 unsigned long shm_nattch;
14 unsigned long shm_segsz;
15 time_t shm_atim;
16 time_t shm_dtim;
17 time_t shm_ctim;
18 pid_t shm_cprid;
19 pid_t shm_lprid;
20 struct user_struct *mlock_user;
Vasiliy Kulikov5774ed02011-07-29 03:55:31 +040021
Alexander Mikhalitsyncc927c12021-11-19 16:43:21 -080022 /*
23 * The task created the shm object, for
24 * task_lock(shp->shm_creator)
25 */
Vasiliy Kulikov5774ed02011-07-29 03:55:31 +040026 struct task_struct *shm_creator;
Alexander Mikhalitsyncc927c12021-11-19 16:43:21 -080027
28 /*
29 * List by creator. task_lock(->shm_creator) required for read/write.
30 * If list_empty(), then the creator is dead already.
31 */
32 struct list_head shm_clist;
33 struct ipc_namespace *ns;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034};
35
36/* shm_mode upper byte flags */
37#define SHM_DEST 01000 /* segment will be destroyed on last detach */
38#define SHM_LOCKED 02000 /* segment will not be swapped */
39#define SHM_HUGETLB 04000 /* segment will use huge TLB pages */
Badari Pulavartybf8f9722005-11-07 00:59:27 -080040#define SHM_NORESERVE 010000 /* don't check for reservations */
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Andi Kleen42d73952012-12-11 16:01:34 -080042/* Bits [26:31] are reserved */
43
44/*
45 * When SHM_HUGETLB is set bits [26:31] encode the log2 of the huge page size.
46 * This gives us 6 bits, which is enough until someone invents 128 bit address
47 * spaces.
48 *
49 * Assume these are all power of twos.
50 * When 0 use the default page size.
51 */
52#define SHM_HUGE_SHIFT 26
53#define SHM_HUGE_MASK 0x3f
54#define SHM_HUGE_2MB (21 << SHM_HUGE_SHIFT)
55#define SHM_HUGE_1GB (30 << SHM_HUGE_SHIFT)
56
Linus Torvalds1da177e2005-04-16 15:20:36 -070057#ifdef CONFIG_SYSVIPC
Jack Millerab602f72014-08-08 14:23:19 -070058struct sysv_shm {
59 struct list_head shm_clist;
60};
61
Will Deacon079a96a2012-07-30 14:42:38 -070062long do_shmat(int shmid, char __user *shmaddr, int shmflg, unsigned long *addr,
63 unsigned long shmlba);
Yaowei Bai2954e4402016-01-20 15:01:11 -080064bool is_file_shm_hugepages(struct file *file);
Jack Millerab602f72014-08-08 14:23:19 -070065void exit_shm(struct task_struct *task);
66#define shm_init_task(task) INIT_LIST_HEAD(&(task)->sysvshm.shm_clist)
Linus Torvalds1da177e2005-04-16 15:20:36 -070067#else
Jack Millerab602f72014-08-08 14:23:19 -070068struct sysv_shm {
69 /* empty */
70};
71
Linus Torvalds1da177e2005-04-16 15:20:36 -070072static inline long do_shmat(int shmid, char __user *shmaddr,
Will Deacon079a96a2012-07-30 14:42:38 -070073 int shmflg, unsigned long *addr,
74 unsigned long shmlba)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075{
76 return -ENOSYS;
77}
Yaowei Bai2954e4402016-01-20 15:01:11 -080078static inline bool is_file_shm_hugepages(struct file *file)
Adam Litke516dffd2007-03-01 15:46:08 -080079{
Yaowei Bai2954e4402016-01-20 15:01:11 -080080 return false;
Adam Litke516dffd2007-03-01 15:46:08 -080081}
Vasiliy Kulikovb34a6b12011-07-26 16:08:48 -070082static inline void exit_shm(struct task_struct *task)
83{
84}
Jack Millerab602f72014-08-08 14:23:19 -070085static inline void shm_init_task(struct task_struct *task)
86{
87}
Linus Torvalds1da177e2005-04-16 15:20:36 -070088#endif
89
Linus Torvalds1da177e2005-04-16 15:20:36 -070090#endif /* _LINUX_SHM_H_ */