Simon Burge wrote:
Elad Efrat wrote:Hi, For a long time I've been thinking about implementing a proplib-based syscall -- I call it "opencomm" -- and only now got around to it. It's like prop_dictionary_sendrecv_ioctl(), only that: - it doesn't require a file-descriptor/command - it takes a syscall slotI like the concept. What exactly does "opencomm" mean or what is it short for? Without any background it seems like a really unintuitive name.
It doesn't mean anything, I just needed a function name. I am known for picking bad names, so we can change it. :)
The changes required to implement it are very small (copy/paste of prop_dictionary_sendrecv_ioctl in prop_kern.c, one line change to syscalls.master, and (for now) a stub in kern_xxx.c). Are there any objections for it being added?Do you have a sample implementation yet?
Of course, but it's just a stub to take a dictionary and return one back on a syscall interface.
I would think that there'd need to be at least one well defined key in the dictionary so that the kernel would know which subsystem to direct the request the dictionary once it got it.
I wanted to see if the idea in general is accepted before we dwell on the implementation details. I've had several thoughts about the dictionary format (fields for type, vendor, NetBSD version, classic or "string value" arguments, etc.), but I'd like to hear what others have to say as well.
I'd like to see more than "copy and paste this" before consenting or objecting to it being added, although as I said I like the concept.
Fair enough, see attached files: - The diffs are obvious (kern_xxx.c only because I couldn't think of a more suitable place): the kernel sys_opencomm() part just prints the c-string value of the default key - opencomm.tar.gz contains prop_changes.c, of which only opencomm() is a newly introduced function -- should really be in prop_kern.c, I think - main.c is just a program that uses opencomm() to test that the dictionary is sent and received okay (if you're asking yourself why it's not a diff against proplib, or why the syscall number is hard-coded: I don't want to pollute anything before we settle on name/location.) Thanks, -e.
Index: syscalls.master =================================================================== RCS file: /usr/cvs/src/sys/kern/syscalls.master,v retrieving revision 1.226 diff -u -p -r1.226 syscalls.master --- syscalls.master 28 Mar 2009 16:33:40 -0000 1.226 +++ syscalls.master 25 Apr 2009 05:20:19 -0000 @@ -334,7 +334,8 @@ #else 171 EXCL 1.0 shmsys #endif -172 UNIMPL +172 STD { int|sys||opencomm(struct plistref *in, \ + struct plistref *out); } 173 STD RUMP { ssize_t|sys||pread(int fd, void *buf, \ size_t nbyte, int pad, off_t offset); } 174 STD RUMP { ssize_t|sys||pwrite(int fd, const void *buf, \
Index: kern_xxx.c =================================================================== RCS file: /usr/cvs/src/sys/kern/kern_xxx.c,v retrieving revision 1.70 diff -u -p -r1.70 kern_xxx.c --- kern_xxx.c 25 Apr 2008 11:23:42 -0000 1.70 +++ kern_xxx.c 25 Apr 2009 05:37:20 -0000 @@ -48,6 +48,9 @@ __KERNEL_RCSID(0, "$NetBSD: kern_xxx.c,v #include <sys/syscallargs.h> #include <sys/kauth.h> +/* For opencomm. */ +#include <prop/proplib.h> + /* ARGSUSED */ int sys_reboot(struct lwp *l, const struct sys_reboot_args *uap, register_t *retval) @@ -183,3 +186,33 @@ scdebug_ret(register_t code, int error, printf("\n"); } #endif /* SYSCALL_DEBUG */ + +int +sys_opencomm(struct lwp *l, const struct sys_opencomm_args *uap, + register_t *retval) +{ + /* { + syscallarg(struct plistref *) in; + syscallarg(struct plistref *) out; + } */ + prop_dictionary_t in, out; + const char *defaultkey = "default_key"; + const char *value; + int error; + + /* Copy "in" dictionary. */ + error = prop_dictionary_copyin_ioctl(SCARG(uap, in), IOC_IN, &in); + error = prop_dictionary_get_cstring_nocopy(in, defaultkey, &value); + printf("opencomm: value for key \"%s\": \"%s\"\n", defaultkey, value); + + /* DEBUG: Create & copy "out" dictionary. */ + out = prop_dictionary_create(); + prop_dictionary_set_cstring_nocopy(out, "result", "success"); + + error = prop_dictionary_copyout_ioctl(SCARG(uap, out), IOC_OUT, out); + + prop_object_release(in); + prop_object_release(out); + + return (0); +}
Attachment:
opencomm.tar.gz
Description: GNU Zip compressed data