Date: Wed, 16 Oct 2013 08:48:45 +0000 (UTC) From: Gleb Smirnoff <glebius@FreeBSD.org> To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256598 - in user/glebius/course/04.synchronisation/code: . application call module Message-ID: <201310160848.r9G8mjP9083881@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: glebius Date: Wed Oct 16 08:48:45 2013 New Revision: 256598 URL: http://svnweb.freebsd.org/changeset/base/256598 Log: An example module that handles a double linked list in racy manner. Added: user/glebius/course/04.synchronisation/code/ - copied from r256591, user/glebius/course/02.entering_kernel/syscall/ user/glebius/course/04.synchronisation/code/call/ - copied from r256591, user/glebius/course/02.entering_kernel/syscall/application/ user/glebius/course/04.synchronisation/code/module/api.h (contents, props changed) user/glebius/course/04.synchronisation/code/module/syscall.c - copied, changed from r256591, user/glebius/course/02.entering_kernel/syscall/module/foo_syscall.c Deleted: user/glebius/course/04.synchronisation/code/application/ user/glebius/course/04.synchronisation/code/module/foo_syscall.c Modified: user/glebius/course/04.synchronisation/code/Makefile user/glebius/course/04.synchronisation/code/call/Makefile user/glebius/course/04.synchronisation/code/call/call.c user/glebius/course/04.synchronisation/code/module/Makefile Modified: user/glebius/course/04.synchronisation/code/Makefile ============================================================================== --- user/glebius/course/02.entering_kernel/syscall/Makefile Wed Oct 16 06:15:40 2013 (r256591) +++ user/glebius/course/04.synchronisation/code/Makefile Wed Oct 16 08:48:45 2013 (r256598) @@ -1,3 +1,3 @@ -SUBDIR= module application +SUBDIR= module call .include <bsd.subdir.mk> Modified: user/glebius/course/04.synchronisation/code/call/Makefile ============================================================================== --- user/glebius/course/02.entering_kernel/syscall/application/Makefile Wed Oct 16 06:15:40 2013 (r256591) +++ user/glebius/course/04.synchronisation/code/call/Makefile Wed Oct 16 08:48:45 2013 (r256598) @@ -1,4 +1,6 @@ PROG= call +CFLAGS+= -I../module + NO_MAN= .include <bsd.prog.mk> Modified: user/glebius/course/04.synchronisation/code/call/call.c ============================================================================== --- user/glebius/course/02.entering_kernel/syscall/application/call.c Wed Oct 16 06:15:40 2013 (r256591) +++ user/glebius/course/04.synchronisation/code/call/call.c Wed Oct 16 08:48:45 2013 (r256598) @@ -5,13 +5,17 @@ #include <err.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <unistd.h> +#include <api.h> + int main(int argc, char **argv) { int modid, syscall_num; struct module_stat stat; + int what; stat.version = sizeof(stat); if ((modid = modfind("sys/foo_syscall")) == -1) @@ -20,5 +24,15 @@ main(int argc, char **argv) err(1, "modstat"); syscall_num = stat.data.intval; - return syscall(syscall_num, argc, argv); + if (argc < 2) + err(1, "argument required"); + + if (strcmp(argv[1], "add") == 0) + what = ADD; + else if (strcmp(argv[1], "delete") == 0) + what = DELETE; + else + err(1, "add or delete"); + + return syscall(syscall_num, what, argv); } Modified: user/glebius/course/04.synchronisation/code/module/Makefile ============================================================================== --- user/glebius/course/02.entering_kernel/syscall/module/Makefile Wed Oct 16 06:15:40 2013 (r256591) +++ user/glebius/course/04.synchronisation/code/module/Makefile Wed Oct 16 08:48:45 2013 (r256598) @@ -1,4 +1,4 @@ -KMOD= foo_syscall -SRCS= foo_syscall.c +KMOD= syscall +SRCS= syscall.c .include <bsd.kmod.mk> Added: user/glebius/course/04.synchronisation/code/module/api.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/glebius/course/04.synchronisation/code/module/api.h Wed Oct 16 08:48:45 2013 (r256598) @@ -0,0 +1,4 @@ +enum { + ADD = 1, + DELETE +}; Copied and modified: user/glebius/course/04.synchronisation/code/module/syscall.c (from r256591, user/glebius/course/02.entering_kernel/syscall/module/foo_syscall.c) ============================================================================== --- user/glebius/course/02.entering_kernel/syscall/module/foo_syscall.c Wed Oct 16 06:15:40 2013 (r256591, copy source) +++ user/glebius/course/04.synchronisation/code/module/syscall.c Wed Oct 16 08:48:45 2013 (r256598) @@ -6,6 +6,8 @@ #include <sys/kernel.h> #include <sys/systm.h> +#include <api.h> + /* * ABI for arguments. Arguments should be aligned by * register size. @@ -24,6 +26,14 @@ struct foo_args { char p_l_[PADL_(int)]; void *p; char p_r_[PADR_(int)]; }; +struct foo_entry { + LIST_ENTRY(foo_entry) foo_link; +}; + +static LIST_HEAD(, foo_entry) foo_head; + +MALLOC_DEFINE(M_FOO, "foo", "foo entries"); + /* * The function implementing the syscall. */ @@ -31,9 +41,25 @@ static int foo_syscall(struct thread *td, void *arg) { struct foo_args *args = (struct foo_args *)arg; + struct foo_entry *ent; + int d = args->d; + + switch (d) { + case ADD: + ent = malloc(sizeof(*ent), M_FOO, M_WAITOK); + LIST_INSERT_HEAD(&foo_head, ent, foo_link); + break; + case DELETE: + ent = LIST_FIRST(&foo_head); + if (ent) { + LIST_REMOVE(ent, foo_link); + free(ent, M_FOO); + } + break; + default: + return (EINVAL); + }; - printf("arguments %d %p\n", - args->d, args->p); return (0); } @@ -59,6 +85,7 @@ foo_load(struct module *module, int cmd, switch (cmd) { case MOD_LOAD : + LIST_INIT(&foo_head); printf("syscall loaded at %d\n", offset); break; case MOD_UNLOAD :
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201310160848.r9G8mjP9083881>