Message Queue source code in Linux

Source: Internet
Author: User
Linux Message Queue source code-Linux general technology-Linux technology and application information. For more information, see the following section. The source code for sending messages in the message queue in linux. # What kind of behavior should I add alen when applying for a space? How much space is required?
Struct msg_msg * load_msg (const void _ user * src, int len)
{
Struct msg_msg * msg;
Struct msg_msgseg ** using G;
Int err;
Int alen;

Alen = len;
If (alen> DATALEN_MSG)
Alen = DATALEN_MSG;

########## Msg = kmalloc (sizeof (* msg) + alen, GFP_KERNEL );
If (msg = NULL)
Return ERR_PTR (-ENOMEM );

Msg-> next = NULL;
Msg-> security = NULL;

If (copy_from_user (msg + 1, src, alen )){
Err =-EFAULT;
Goto out_err;
}

Len-= alen;
Src = (char _ user *) src) + alen;
Required G = & msg-> next;
While (len> 0 ){
Struct msg_msgseg * seg;
Alen = len;
If (alen> DATALEN_SEG)
Alen = DATALEN_SEG;
Seg = kmalloc (sizeof (* seg) + alen,
GFP_KERNEL );
If (seg = NULL ){
Err =-ENOMEM;
Goto out_err;
}
* Required G = seg;
Seg-> next = NULL;
If (copy_from_user (seg + 1, src, alen )){
Err =-EFAULT;
Goto out_err;
}
Sort G = & seg-> next;
Len-= alen;
Src = (char _ user *) src) + alen;
}

Err = security_msg_msg_alloc (msg );
If (err)
Goto out_err;

Return msg;

Out_err:
Free_msg (msg );
Return ERR_PTR (err );
}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.