ipc: remove the ipc_get() routine
[GitHub/LineageOS/android_kernel_motorola_exynos9610.git] / ipc / util.h
CommitLineData
1da177e4
LT
1/*
2 * linux/ipc/util.h
3 * Copyright (C) 1999 Christoph Rohland
4 *
624dffcb 5 * ipc helper functions (c) 1999 Manfred Spraul <manfred@colorfullife.com>
73ea4130
KK
6 * namespaces support. 2006 OpenVZ, SWsoft Inc.
7 * Pavel Emelianov <xemul@openvz.org>
1da177e4
LT
8 */
9
10#ifndef _IPC_UTIL_H
11#define _IPC_UTIL_H
12
7ca7e564
ND
13#include <linux/idr.h>
14
1da177e4
LT
15#define USHRT_MAX 0xffff
16#define SEQ_MULTIPLIER (IPCMNI)
17
18void sem_init (void);
19void msg_init (void);
20void shm_init (void);
21
73ea4130
KK
22int sem_init_ns(struct ipc_namespace *ns);
23int msg_init_ns(struct ipc_namespace *ns);
24int shm_init_ns(struct ipc_namespace *ns);
25
26void sem_exit_ns(struct ipc_namespace *ns);
27void msg_exit_ns(struct ipc_namespace *ns);
28void shm_exit_ns(struct ipc_namespace *ns);
29
1da177e4
LT
30struct ipc_ids {
31 int in_use;
1da177e4
LT
32 unsigned short seq;
33 unsigned short seq_max;
5f921ae9 34 struct mutex mutex;
7ca7e564 35 struct idr ipcs_idr;
1da177e4
LT
36};
37
7748dbfa
ND
38/*
39 * Structure that holds the parameters needed by the ipc operations
40 * (see after)
41 */
42struct ipc_params {
43 key_t key;
44 int flg;
45 union {
46 size_t size; /* for shared memories */
47 int nsems; /* for semaphores */
48 } u; /* holds the getnew() specific param */
49};
50
51/*
52 * Structure that holds some ipc operations. This structure is used to unify
53 * the calls to sys_msgget(), sys_semget(), sys_shmget()
54 * . routine to call to create a new ipc object. Can be one of newque,
55 * newary, newseg
56 * . routine to call to call to check permissions for a new ipc object.
57 * Can be one of security_msg_associate, security_sem_associate,
58 * security_shm_associate
59 * . routine to call for an extra check if needed
60 */
61struct ipc_ops {
62 int (*getnew) (struct ipc_namespace *, struct ipc_params *);
63 int (*associate) (void *, int);
64 int (*more_checks) (void *, struct ipc_params *);
65};
66
ae781774 67struct seq_file;
7d69a1f4 68
7ca7e564 69void ipc_init_ids(struct ipc_ids *);
ae781774
MW
70#ifdef CONFIG_PROC_FS
71void __init ipc_init_proc_interface(const char *path, const char *header,
73ea4130 72 int ids, int (*show)(struct seq_file *, void *));
ae781774
MW
73#else
74#define ipc_init_proc_interface(path, header, ids, show) do {} while (0)
75#endif
1da177e4 76
73ea4130
KK
77#define IPC_SEM_IDS 0
78#define IPC_MSG_IDS 1
79#define IPC_SHM_IDS 2
80
5f921ae9 81/* must be called with ids->mutex acquired.*/
7ca7e564
ND
82int ipc_addid(struct ipc_ids *, struct kern_ipc_perm *, int);
83int ipc_get_maxid(struct ipc_ids *);
1da177e4
LT
84
85/* must be called with both locks acquired. */
7ca7e564 86void ipc_rmid(struct ipc_ids *, struct kern_ipc_perm *);
1da177e4
LT
87
88int ipcperms (struct kern_ipc_perm *ipcp, short flg);
89
90/* for rare, potentially huge allocations.
91 * both function can sleep
92 */
93void* ipc_alloc(int size);
94void ipc_free(void* ptr, int size);
95
96/*
97 * For allocation that need to be freed by RCU.
98 * Objects are reference counted, they start with reference count 1.
99 * getref increases the refcount, the putref call that reduces the recount
100 * to 0 schedules the rcu destruction. Caller must guarantee locking.
101 */
102void* ipc_rcu_alloc(int size);
103void ipc_rcu_getref(void *ptr);
104void ipc_rcu_putref(void *ptr);
105
1da177e4
LT
106struct kern_ipc_perm* ipc_lock(struct ipc_ids* ids, int id);
107void ipc_lock_by_ptr(struct kern_ipc_perm *ipcp);
108void ipc_unlock(struct kern_ipc_perm* perm);
109int ipc_buildid(struct ipc_ids* ids, int id, int seq);
110int ipc_checkid(struct ipc_ids* ids, struct kern_ipc_perm* ipcp, int uid);
111
112void kernel_to_ipc64_perm(struct kern_ipc_perm *in, struct ipc64_perm *out);
113void ipc64_perm_to_ipc_perm(struct ipc64_perm *in, struct ipc_perm *out);
114
813e6783 115#if defined(__ia64__) || defined(__x86_64__) || defined(__hppa__) || defined(__XTENSA__)
1da177e4
LT
116 /* On IA-64, we always use the "64-bit version" of the IPC structures. */
117# define ipc_parse_version(cmd) IPC_64
118#else
119int ipc_parse_version (int *cmd);
120#endif
121
122extern void free_msg(struct msg_msg *msg);
123extern struct msg_msg *load_msg(const void __user *src, int len);
124extern int store_msg(void __user *dest, struct msg_msg *msg, int len);
7748dbfa
ND
125extern int ipcget_new(struct ipc_namespace *, struct ipc_ids *,
126 struct ipc_ops *, struct ipc_params *);
127extern int ipcget_public(struct ipc_namespace *, struct ipc_ids *,
128 struct ipc_ops *, struct ipc_params *);
129
130static inline int ipcget(struct ipc_namespace *ns, struct ipc_ids *ids,
131 struct ipc_ops *ops, struct ipc_params *params)
132{
133 if (params->key == IPC_PRIVATE)
134 return ipcget_new(ns, ids, ops, params);
135 else
136 return ipcget_public(ns, ids, ops, params);
137}
1da177e4
LT
138
139#endif