3 * Copyright (C) 1999, 2004 Manfred Spraul
5 * This file is released under GNU General Public Licence version 2 or
6 * (at your option) any later version.
8 * See the file COPYING for more details.
11 #include <linux/spinlock.h>
12 #include <linux/init.h>
13 #include <linux/security.h>
14 #include <linux/slab.h>
15 #include <linux/ipc.h>
16 #include <asm/uaccess.h>
21 struct msg_msgseg
* next
;
22 /* the next part of the message follows immediately */
25 #define DATALEN_MSG (PAGE_SIZE-sizeof(struct msg_msg))
26 #define DATALEN_SEG (PAGE_SIZE-sizeof(struct msg_msgseg))
28 struct msg_msg
*load_msg(const void __user
*src
, int len
)
31 struct msg_msgseg
**pseg
;
36 if (alen
> DATALEN_MSG
)
39 msg
= kmalloc(sizeof(*msg
) + alen
, GFP_KERNEL
);
41 return ERR_PTR(-ENOMEM
);
46 if (copy_from_user(msg
+ 1, src
, alen
)) {
52 src
= ((char __user
*)src
) + alen
;
55 struct msg_msgseg
*seg
;
57 if (alen
> DATALEN_SEG
)
59 seg
= kmalloc(sizeof(*seg
) + alen
,
67 if (copy_from_user(seg
+ 1, src
, alen
)) {
73 src
= ((char __user
*)src
) + alen
;
76 err
= security_msg_msg_alloc(msg
);
87 int store_msg(void __user
*dest
, struct msg_msg
*msg
, int len
)
90 struct msg_msgseg
*seg
;
93 if (alen
> DATALEN_MSG
)
95 if (copy_to_user(dest
, msg
+ 1, alen
))
99 dest
= ((char __user
*)dest
) + alen
;
103 if (alen
> DATALEN_SEG
)
105 if (copy_to_user(dest
, seg
+ 1, alen
))
108 dest
= ((char __user
*)dest
) + alen
;
114 void free_msg(struct msg_msg
*msg
)
116 struct msg_msgseg
*seg
;
118 security_msg_msg_free(msg
);
122 while (seg
!= NULL
) {
123 struct msg_msgseg
*tmp
= seg
->next
;