I am writing a small kext that sends data out to userspace via kernel
control. However, the userspace program cannot receive the expected
data. Anybody plese tell me what I did wrong?
My code is very simple: it sends a variable length text to userspace.
Todo that, I have a structure named MyLog, like below:
--
struct MyLog {
int length; /* text length */
uid_t uid; /* uid that generated this action */
unsigned int action; /* in kernel space: kauth_action_t action */
};
--
Then the ctrl_connect() method of kernel control is defined so
whenever a userspace program connect to kernel control, ctl_connect()
sends out few text. Please see below:
--
static int ctl_connect(kern_ctl_ref ctl_ref, struct sockaddr_ctl *sac,
void **unitinfo)
{
struct MyLog log;
char *text = "Greeting from kernelspace!";
printf("Action %d on %s (%d)\n", log.action, buffer, log.uid);
---
However, while I expect that my userspace program will get the text
"Greeting from kernelspace", it does not. In fact, I only got data
from the first recv() function, and my program printed out:
---
Got packet of 16 byte, variable length: 16
---
So far, it is correct. But then it hangs up there, instead of
succesfully execute the next recv()? Why that happens? In my kernel
code, I already put all the neccessary data in the control buffer, no?
(???)
Then I tried to copy another data into the kernel buffer (use another
command ctl_enqueudata() command). Then the userspace program quit the
hangup status, and continue to print out data. But the data is not
what I expected, like below:
--
Got exactly 26 bytes
Action 1010 on (2006)
--
As you can see, the text "Greeting from kernelspace" is no where to be
seen, although I got 26 bytes as I expected. The only problem is that
the data is incorrect.
It seems that the way I put the kernel data into the buffer is
incorrect, or what else should be fixed?
Thank you a lot, and have a nice weekend (I don't :-)
H
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden