Skip to content

Instantly share code, notes, and snippets.

@tmathmeyer
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmathmeyer/9316093 to your computer and use it in GitHub Desktop.
Save tmathmeyer/9316093 to your computer and use it in GitHub Desktop.
asmlinkage long receive(pid_t* sender, void* mesg, int* len, bool block)
{
mailbox* my_mail;
message* msg;
my_mail = map_get(current->pid);
if (!my_mail)
{
my_mail = make_mailbox(current -> pid);
map_put(my_mail);
}
do
{
wait_event(my_mail -> access, atomic_read(my_mail -> r_w) == 0);
atomic_inc(my_mail -> r_w);
msg = my_mail -> contents;
if (msg)
{
if (copy_to_user(sender, &(msg->sender), sizeof(pid_t)))
{
printk(KERN_INFO "EFUALT @recieve_mail_1 EF_id: %i, proc: %i", EFAULT, current->pid);
atomic_dec(my_mail -> r_w);
wake_up(my_mail -> access);
return MAILBOX_ERROR;
}
if (copy_to_user(mesg, msg->data, msg->real_len))
{
printk(KERN_INFO "EFUALT @recieve_mail_2 EF_id: %i, proc: %i", EFAULT, current->pid);
atomic_dec(my_mail -> r_w);
wake_up(my_mail -> access);
return MAILBOX_ERROR;
}
if (copy_to_user(len, &(msg->real_len), sizeof(int)))
{
printk(KERN_INFO "EFUALT @recieve_mail_3 EF_id: %i, proc: %i", EFAULT, current->pid);
atomic_dec(my_mail -> r_w);
wake_up(my_mail -> access);
return MAILBOX_ERROR;
}
my_mail -> contents = my_mail -> contents -> next;
mem_cache_free(messages, msg);
atomic_dec(my_mail -> r_w);
wake_up(my_mail -> access);
return 0;
}
}
while(block);
return MAILBOX_EMPTY;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment