From owner-svn-src-user@FreeBSD.ORG Wed Oct 16 08:48:46 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id EB61AC13; Wed, 16 Oct 2013 08:48:46 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id C92042B58; Wed, 16 Oct 2013 08:48:46 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9G8mkox083898; Wed, 16 Oct 2013 08:48:46 GMT (envelope-from glebius@svn.freebsd.org) Received: (from glebius@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9G8mjP9083881; Wed, 16 Oct 2013 08:48:45 GMT (envelope-from glebius@svn.freebsd.org) Message-Id: <201310160848.r9G8mjP9083881@svn.freebsd.org> From: Gleb Smirnoff Date: Wed, 16 Oct 2013 08:48:45 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256598 - in user/glebius/course/04.synchronisation/code: . application call module X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Oct 2013 08:48:47 -0000 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 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 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 #include #include +#include #include +#include + 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 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 #include +#include + /* * 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 :