[Xenomai-git] Gilles Chanteperdrix : cobalt: use the cobalt registry for semaphores

2013-12-19 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 8fc3d3522e2a31b89c810a6250ab2cb6f7bb89ec
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=8fc3d3522e2a31b89c810a6250ab2cb6f7bb89ec

Author: Gilles Chanteperdrix 
Date:   Sun Dec 15 17:09:32 2013 +0100

cobalt: use the cobalt registry for semaphores

---

 include/cobalt/uapi/sem.h|4 +-
 kernel/cobalt/posix/Makefile |1 +
 kernel/cobalt/posix/init.c   |7 +
 kernel/cobalt/posix/nsem.c   |  306 ++
 kernel/cobalt/posix/sem.c|  574 +-
 kernel/cobalt/posix/sem.h|   33 ++-
 lib/cobalt/semaphore.c   |   19 +-
 7 files changed, 475 insertions(+), 469 deletions(-)

diff --git a/include/cobalt/uapi/sem.h b/include/cobalt/uapi/sem.h
index a1a9526..e011141 100644
--- a/include/cobalt/uapi/sem.h
+++ b/include/cobalt/uapi/sem.h
@@ -18,6 +18,8 @@
 #ifndef _COBALT_UAPI_SEM_H
 #define _COBALT_UAPI_SEM_H
 
+#include 
+
 #define COBALT_SEM_MAGIC (0x86860707)
 #define COBALT_NAMED_SEM_MAGIC (0x86860D0D)
 
@@ -32,8 +34,8 @@ union cobalt_sem_union {
sem_t native_sem;
struct __shadow_sem {
unsigned int magic;
-   struct cobalt_sem *sem;
int datp_offset;
+   xnhandle_t handle;
} shadow_sem;
 };
 
diff --git a/kernel/cobalt/posix/Makefile b/kernel/cobalt/posix/Makefile
index d08442d..aad94a6 100644
--- a/kernel/cobalt/posix/Makefile
+++ b/kernel/cobalt/posix/Makefile
@@ -12,6 +12,7 @@ posix-y :=\
mutex_attr.o\
registry.o  \
sem.o   \
+   nsem.o  \
select.o\
signal.o\
syscall.o   \
diff --git a/kernel/cobalt/posix/init.c b/kernel/cobalt/posix/init.c
index 4676d27..02e0b08 100644
--- a/kernel/cobalt/posix/init.c
+++ b/kernel/cobalt/posix/init.c
@@ -64,6 +64,7 @@ MODULE_LICENSE("GPL");
 void cobalt_cleanup(void)
 {
cobalt_syscall_cleanup();
+   cobalt_nsem_pkg_cleanup();
cobalt_timer_pkg_cleanup();
cobalt_monitor_pkg_cleanup();
cobalt_event_pkg_cleanup();
@@ -83,6 +84,12 @@ int __init cobalt_init(void)
if (ret)
return ret;
 
+   ret = cobalt_nsem_pkg_init();
+   if (ret) {
+   cobalt_syscall_cleanup();
+   return ret;
+   }
+
cobalt_reg_pkg_init(64, 128);   /* FIXME: replace with compilation 
constants. */
cobalt_mutex_pkg_init();
cobalt_sem_pkg_init();
diff --git a/kernel/cobalt/posix/nsem.c b/kernel/cobalt/posix/nsem.c
new file mode 100644
index 000..1e003c9
--- /dev/null
+++ b/kernel/cobalt/posix/nsem.c
@@ -0,0 +1,306 @@
+/*
+ * Copyright (C) 2013 Gilles Chanteperdrix .
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include "internal.h"
+#include "sem.h"
+
+static struct hlist_head *nsem_hash;
+DEFINE_XNLOCK(nsem_lock);
+
+struct nsem {
+   struct cobalt_sem *sem;
+   struct mm_struct *mm;
+   struct __shadow_sem __user *usem;
+   unsigned refs;
+   struct hlist_node hlink; /* Link in global hash */
+   struct list_head link;   /* Link in per-process queue */
+};
+
+static unsigned __attribute__((pure)) 
+nsem_hash_crunch(xnhandle_t handle, struct mm_struct *mm)
+{
+   unsigned hash = handle + (unsigned long)mm / sizeof(struct mm_struct);
+   return hash % CONFIG_XENO_OPT_REGISTRY_NRSLOTS;
+}
+
+static struct nsem *
+nsem_hash_search(xnhandle_t handle, struct mm_struct *mm)
+{
+   unsigned bucket = nsem_hash_crunch(handle, mm);
+   struct nsem *u;
+
+   hlist_for_each_entry(u, &nsem_hash[bucket], hlink)
+   if (u->sem->handle == handle && u->mm == mm)
+   return u;
+
+   return NULL;
+}
+
+static void nsem_hash_enter(xnhandle_t handle, struct nsem *nsem)
+{
+   unsigned bucket = nsem_hash_crunch(handle, current->mm);
+
+   hlist_add_head(&nsem->hlink, &nsem_hash[bucket]);
+}
+
+static void nsem_hash_remove(struct nsem *u)
+{
+   hlist_del(&u->hlink);
+}
+
+static struct __shadow_sem __user *
+nsem_open(struct __shadow_sem __user *ushadow, const char *name, 
+   int oflags, mode_t mode, unsigned value)
+{
+   struct __shadow_sem shadow;
+   struct cobalt_sem *

[Xenomai-git] Gilles Chanteperdrix : cobalt: use the cobalt registry for semaphores

2013-12-19 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 66f9472e206b76ce79d80dc481a01140bcc6f39c
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=66f9472e206b76ce79d80dc481a01140bcc6f39c

Author: Gilles Chanteperdrix 
Date:   Sun Dec 15 17:09:32 2013 +0100

cobalt: use the cobalt registry for semaphores

---

 include/cobalt/uapi/sem.h|4 +-
 kernel/cobalt/posix/Makefile |1 +
 kernel/cobalt/posix/init.c   |7 +
 kernel/cobalt/posix/nsem.c   |  306 ++
 kernel/cobalt/posix/sem.c|  573 +-
 kernel/cobalt/posix/sem.h|   33 ++-
 lib/cobalt/semaphore.c   |   19 +-
 7 files changed, 475 insertions(+), 468 deletions(-)

diff --git a/include/cobalt/uapi/sem.h b/include/cobalt/uapi/sem.h
index a1a9526..e011141 100644
--- a/include/cobalt/uapi/sem.h
+++ b/include/cobalt/uapi/sem.h
@@ -18,6 +18,8 @@
 #ifndef _COBALT_UAPI_SEM_H
 #define _COBALT_UAPI_SEM_H
 
+#include 
+
 #define COBALT_SEM_MAGIC (0x86860707)
 #define COBALT_NAMED_SEM_MAGIC (0x86860D0D)
 
@@ -32,8 +34,8 @@ union cobalt_sem_union {
sem_t native_sem;
struct __shadow_sem {
unsigned int magic;
-   struct cobalt_sem *sem;
int datp_offset;
+   xnhandle_t handle;
} shadow_sem;
 };
 
diff --git a/kernel/cobalt/posix/Makefile b/kernel/cobalt/posix/Makefile
index d08442d..aad94a6 100644
--- a/kernel/cobalt/posix/Makefile
+++ b/kernel/cobalt/posix/Makefile
@@ -12,6 +12,7 @@ posix-y :=\
mutex_attr.o\
registry.o  \
sem.o   \
+   nsem.o  \
select.o\
signal.o\
syscall.o   \
diff --git a/kernel/cobalt/posix/init.c b/kernel/cobalt/posix/init.c
index 4676d27..02e0b08 100644
--- a/kernel/cobalt/posix/init.c
+++ b/kernel/cobalt/posix/init.c
@@ -64,6 +64,7 @@ MODULE_LICENSE("GPL");
 void cobalt_cleanup(void)
 {
cobalt_syscall_cleanup();
+   cobalt_nsem_pkg_cleanup();
cobalt_timer_pkg_cleanup();
cobalt_monitor_pkg_cleanup();
cobalt_event_pkg_cleanup();
@@ -83,6 +84,12 @@ int __init cobalt_init(void)
if (ret)
return ret;
 
+   ret = cobalt_nsem_pkg_init();
+   if (ret) {
+   cobalt_syscall_cleanup();
+   return ret;
+   }
+
cobalt_reg_pkg_init(64, 128);   /* FIXME: replace with compilation 
constants. */
cobalt_mutex_pkg_init();
cobalt_sem_pkg_init();
diff --git a/kernel/cobalt/posix/nsem.c b/kernel/cobalt/posix/nsem.c
new file mode 100644
index 000..1e003c9
--- /dev/null
+++ b/kernel/cobalt/posix/nsem.c
@@ -0,0 +1,306 @@
+/*
+ * Copyright (C) 2013 Gilles Chanteperdrix .
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include "internal.h"
+#include "sem.h"
+
+static struct hlist_head *nsem_hash;
+DEFINE_XNLOCK(nsem_lock);
+
+struct nsem {
+   struct cobalt_sem *sem;
+   struct mm_struct *mm;
+   struct __shadow_sem __user *usem;
+   unsigned refs;
+   struct hlist_node hlink; /* Link in global hash */
+   struct list_head link;   /* Link in per-process queue */
+};
+
+static unsigned __attribute__((pure)) 
+nsem_hash_crunch(xnhandle_t handle, struct mm_struct *mm)
+{
+   unsigned hash = handle + (unsigned long)mm / sizeof(struct mm_struct);
+   return hash % CONFIG_XENO_OPT_REGISTRY_NRSLOTS;
+}
+
+static struct nsem *
+nsem_hash_search(xnhandle_t handle, struct mm_struct *mm)
+{
+   unsigned bucket = nsem_hash_crunch(handle, mm);
+   struct nsem *u;
+
+   hlist_for_each_entry(u, &nsem_hash[bucket], hlink)
+   if (u->sem->handle == handle && u->mm == mm)
+   return u;
+
+   return NULL;
+}
+
+static void nsem_hash_enter(xnhandle_t handle, struct nsem *nsem)
+{
+   unsigned bucket = nsem_hash_crunch(handle, current->mm);
+
+   hlist_add_head(&nsem->hlink, &nsem_hash[bucket]);
+}
+
+static void nsem_hash_remove(struct nsem *u)
+{
+   hlist_del(&u->hlink);
+}
+
+static struct __shadow_sem __user *
+nsem_open(struct __shadow_sem __user *ushadow, const char *name, 
+   int oflags, mode_t mode, unsigned value)
+{
+   struct __shadow_sem shadow;
+   struct cobalt_sem *

[Xenomai-git] Gilles Chanteperdrix : cobalt: use the cobalt registry for semaphores

2013-12-19 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: cc344d29ba85ebb0dd04e19607e0d6542d8f7668
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=cc344d29ba85ebb0dd04e19607e0d6542d8f7668

Author: Gilles Chanteperdrix 
Date:   Sun Dec 15 17:09:32 2013 +0100

cobalt: use the cobalt registry for semaphores

---

 include/cobalt/uapi/sem.h|4 +-
 kernel/cobalt/posix/Makefile |1 +
 kernel/cobalt/posix/init.c   |7 +
 kernel/cobalt/posix/nsem.c   |  303 ++
 kernel/cobalt/posix/sem.c|  571 +-
 kernel/cobalt/posix/sem.h|   33 ++-
 lib/cobalt/semaphore.c   |   19 +-
 7 files changed, 472 insertions(+), 466 deletions(-)

diff --git a/include/cobalt/uapi/sem.h b/include/cobalt/uapi/sem.h
index a1a9526..e011141 100644
--- a/include/cobalt/uapi/sem.h
+++ b/include/cobalt/uapi/sem.h
@@ -18,6 +18,8 @@
 #ifndef _COBALT_UAPI_SEM_H
 #define _COBALT_UAPI_SEM_H
 
+#include 
+
 #define COBALT_SEM_MAGIC (0x86860707)
 #define COBALT_NAMED_SEM_MAGIC (0x86860D0D)
 
@@ -32,8 +34,8 @@ union cobalt_sem_union {
sem_t native_sem;
struct __shadow_sem {
unsigned int magic;
-   struct cobalt_sem *sem;
int datp_offset;
+   xnhandle_t handle;
} shadow_sem;
 };
 
diff --git a/kernel/cobalt/posix/Makefile b/kernel/cobalt/posix/Makefile
index d08442d..aad94a6 100644
--- a/kernel/cobalt/posix/Makefile
+++ b/kernel/cobalt/posix/Makefile
@@ -12,6 +12,7 @@ posix-y :=\
mutex_attr.o\
registry.o  \
sem.o   \
+   nsem.o  \
select.o\
signal.o\
syscall.o   \
diff --git a/kernel/cobalt/posix/init.c b/kernel/cobalt/posix/init.c
index 4676d27..02e0b08 100644
--- a/kernel/cobalt/posix/init.c
+++ b/kernel/cobalt/posix/init.c
@@ -64,6 +64,7 @@ MODULE_LICENSE("GPL");
 void cobalt_cleanup(void)
 {
cobalt_syscall_cleanup();
+   cobalt_nsem_pkg_cleanup();
cobalt_timer_pkg_cleanup();
cobalt_monitor_pkg_cleanup();
cobalt_event_pkg_cleanup();
@@ -83,6 +84,12 @@ int __init cobalt_init(void)
if (ret)
return ret;
 
+   ret = cobalt_nsem_pkg_init();
+   if (ret) {
+   cobalt_syscall_cleanup();
+   return ret;
+   }
+
cobalt_reg_pkg_init(64, 128);   /* FIXME: replace with compilation 
constants. */
cobalt_mutex_pkg_init();
cobalt_sem_pkg_init();
diff --git a/kernel/cobalt/posix/nsem.c b/kernel/cobalt/posix/nsem.c
new file mode 100644
index 000..72edacb
--- /dev/null
+++ b/kernel/cobalt/posix/nsem.c
@@ -0,0 +1,303 @@
+/*
+ * Copyright (C) 2013 Gilles Chanteperdrix .
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include "internal.h"
+#include "sem.h"
+
+static struct hlist_head *nsem_hash;
+DEFINE_XNLOCK(nsem_lock);
+
+struct nsem {
+   struct cobalt_sem *sem;
+   struct mm_struct *mm;
+   struct __shadow_sem __user *usem;
+   unsigned refs;
+   struct hlist_node hlink; /* Link in global hash */
+   struct list_head link;   /* Link in per-process queue */
+};
+
+static unsigned __attribute__((pure)) 
+nsem_hash_crunch(xnhandle_t handle, struct mm_struct *mm)
+{
+   unsigned hash = handle + (unsigned long)mm / sizeof(struct mm_struct);
+   return hash % CONFIG_XENO_OPT_REGISTRY_NRSLOTS;
+}
+
+static struct nsem *
+nsem_hash_search(xnhandle_t handle, struct mm_struct *mm)
+{
+   unsigned bucket = nsem_hash_crunch(handle, mm);
+   struct nsem *u;
+
+   hlist_for_each_entry(u, &nsem_hash[bucket], hlink)
+   if (u->sem->handle == handle && u->mm == mm)
+   return u;
+
+   return NULL;
+}
+
+static void nsem_hash_enter(xnhandle_t handle, struct nsem *nsem)
+{
+   unsigned bucket = nsem_hash_crunch(handle, current->mm);
+
+   hlist_add_head(&nsem->hlink, &nsem_hash[bucket]);
+}
+
+static void nsem_hash_remove(struct nsem *u)
+{
+   hlist_del(&u->hlink);
+}
+
+static struct __shadow_sem __user *
+nsem_open(struct __shadow_sem __user *ushadow, const char *name, 
+   int oflags, mode_t mode, unsigned value)
+{
+   struct __shadow_sem shadow;
+   struct cobalt_sem *

[Xenomai-git] Gilles Chanteperdrix : cobalt: use the cobalt registry for semaphores

2013-12-16 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 51ae837312460f495606d9ec92670afb485f3b8d
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=51ae837312460f495606d9ec92670afb485f3b8d

Author: Gilles Chanteperdrix 
Date:   Sun Dec 15 17:09:32 2013 +0100

cobalt: use the cobalt registry for semaphores

---

 include/cobalt/uapi/sem.h|4 +-
 kernel/cobalt/posix/Makefile |1 +
 kernel/cobalt/posix/init.c   |7 +
 kernel/cobalt/posix/nsem.c   |  307 +++
 kernel/cobalt/posix/sem.c|  553 +-
 kernel/cobalt/posix/sem.h|   32 ++-
 lib/cobalt/semaphore.c   |   19 +-
 7 files changed, 464 insertions(+), 459 deletions(-)

diff --git a/include/cobalt/uapi/sem.h b/include/cobalt/uapi/sem.h
index a1a9526..e011141 100644
--- a/include/cobalt/uapi/sem.h
+++ b/include/cobalt/uapi/sem.h
@@ -18,6 +18,8 @@
 #ifndef _COBALT_UAPI_SEM_H
 #define _COBALT_UAPI_SEM_H
 
+#include 
+
 #define COBALT_SEM_MAGIC (0x86860707)
 #define COBALT_NAMED_SEM_MAGIC (0x86860D0D)
 
@@ -32,8 +34,8 @@ union cobalt_sem_union {
sem_t native_sem;
struct __shadow_sem {
unsigned int magic;
-   struct cobalt_sem *sem;
int datp_offset;
+   xnhandle_t handle;
} shadow_sem;
 };
 
diff --git a/kernel/cobalt/posix/Makefile b/kernel/cobalt/posix/Makefile
index d08442d..aad94a6 100644
--- a/kernel/cobalt/posix/Makefile
+++ b/kernel/cobalt/posix/Makefile
@@ -12,6 +12,7 @@ posix-y :=\
mutex_attr.o\
registry.o  \
sem.o   \
+   nsem.o  \
select.o\
signal.o\
syscall.o   \
diff --git a/kernel/cobalt/posix/init.c b/kernel/cobalt/posix/init.c
index 4676d27..02e0b08 100644
--- a/kernel/cobalt/posix/init.c
+++ b/kernel/cobalt/posix/init.c
@@ -64,6 +64,7 @@ MODULE_LICENSE("GPL");
 void cobalt_cleanup(void)
 {
cobalt_syscall_cleanup();
+   cobalt_nsem_pkg_cleanup();
cobalt_timer_pkg_cleanup();
cobalt_monitor_pkg_cleanup();
cobalt_event_pkg_cleanup();
@@ -83,6 +84,12 @@ int __init cobalt_init(void)
if (ret)
return ret;
 
+   ret = cobalt_nsem_pkg_init();
+   if (ret) {
+   cobalt_syscall_cleanup();
+   return ret;
+   }
+
cobalt_reg_pkg_init(64, 128);   /* FIXME: replace with compilation 
constants. */
cobalt_mutex_pkg_init();
cobalt_sem_pkg_init();
diff --git a/kernel/cobalt/posix/nsem.c b/kernel/cobalt/posix/nsem.c
new file mode 100644
index 000..7e66ea8
--- /dev/null
+++ b/kernel/cobalt/posix/nsem.c
@@ -0,0 +1,307 @@
+/*
+ * Copyright (C) 2013 Gilles Chanteperdrix .
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include "internal.h"
+#include "sem.h"
+
+static struct hlist_head *nsem_hash;
+DEFINE_XNLOCK(nsem_lock);
+
+struct nsem {
+   struct cobalt_sem *sem;
+   struct mm_struct *mm;
+   struct __shadow_sem __user *usem;
+   unsigned refs;
+   struct hlist_node hlink; /* Link in global hash */
+   struct list_head link;   /* Link in per-process queue */
+};
+
+static unsigned __attribute__((pure)) 
+nsem_hash_crunch(xnhandle_t handle, struct mm_struct *mm)
+{
+   unsigned hash = handle + (unsigned long)mm / sizeof(struct mm_struct);
+   return hash % CONFIG_XENO_OPT_REGISTRY_NRSLOTS;
+}
+
+static struct nsem *
+nsem_hash_search(xnhandle_t handle, struct mm_struct *mm)
+{
+   unsigned bucket = nsem_hash_crunch(handle, mm);
+   struct nsem *u;
+
+   hlist_for_each_entry(u, &nsem_hash[bucket], hlink)
+   if (u->sem->handle == handle && u->mm == mm)
+   return u;
+
+   return NULL;
+}
+
+static void nsem_hash_enter(xnhandle_t handle, struct nsem *nsem)
+{
+   unsigned bucket = nsem_hash_crunch(handle, current->mm);
+
+   hlist_add_head(&nsem->hlink, &nsem_hash[bucket]);
+}
+
+static void nsem_hash_remove(struct nsem *u)
+{
+   hlist_del(&u->hlink);
+}
+
+static struct __shadow_sem __user *
+nsem_open(struct __shadow_sem __user *ushadow, const char *name, 
+   int oflags, mode_t mode, unsigned value)
+{
+   struct __shadow_sem shadow;
+   struct cobalt_sem 

[Xenomai-git] Gilles Chanteperdrix : cobalt: use the cobalt registry for semaphores

2013-12-15 Thread git repository hosting
Module: xenomai-gch
Branch: for-forge
Commit: 51ae837312460f495606d9ec92670afb485f3b8d
URL:
http://git.xenomai.org/?p=xenomai-gch.git;a=commit;h=51ae837312460f495606d9ec92670afb485f3b8d

Author: Gilles Chanteperdrix 
Date:   Sun Dec 15 17:09:32 2013 +0100

cobalt: use the cobalt registry for semaphores

---

 include/cobalt/uapi/sem.h|4 +-
 kernel/cobalt/posix/Makefile |1 +
 kernel/cobalt/posix/init.c   |7 +
 kernel/cobalt/posix/nsem.c   |  307 +++
 kernel/cobalt/posix/sem.c|  553 +-
 kernel/cobalt/posix/sem.h|   32 ++-
 lib/cobalt/semaphore.c   |   19 +-
 7 files changed, 464 insertions(+), 459 deletions(-)

diff --git a/include/cobalt/uapi/sem.h b/include/cobalt/uapi/sem.h
index a1a9526..e011141 100644
--- a/include/cobalt/uapi/sem.h
+++ b/include/cobalt/uapi/sem.h
@@ -18,6 +18,8 @@
 #ifndef _COBALT_UAPI_SEM_H
 #define _COBALT_UAPI_SEM_H
 
+#include 
+
 #define COBALT_SEM_MAGIC (0x86860707)
 #define COBALT_NAMED_SEM_MAGIC (0x86860D0D)
 
@@ -32,8 +34,8 @@ union cobalt_sem_union {
sem_t native_sem;
struct __shadow_sem {
unsigned int magic;
-   struct cobalt_sem *sem;
int datp_offset;
+   xnhandle_t handle;
} shadow_sem;
 };
 
diff --git a/kernel/cobalt/posix/Makefile b/kernel/cobalt/posix/Makefile
index d08442d..aad94a6 100644
--- a/kernel/cobalt/posix/Makefile
+++ b/kernel/cobalt/posix/Makefile
@@ -12,6 +12,7 @@ posix-y :=\
mutex_attr.o\
registry.o  \
sem.o   \
+   nsem.o  \
select.o\
signal.o\
syscall.o   \
diff --git a/kernel/cobalt/posix/init.c b/kernel/cobalt/posix/init.c
index 4676d27..02e0b08 100644
--- a/kernel/cobalt/posix/init.c
+++ b/kernel/cobalt/posix/init.c
@@ -64,6 +64,7 @@ MODULE_LICENSE("GPL");
 void cobalt_cleanup(void)
 {
cobalt_syscall_cleanup();
+   cobalt_nsem_pkg_cleanup();
cobalt_timer_pkg_cleanup();
cobalt_monitor_pkg_cleanup();
cobalt_event_pkg_cleanup();
@@ -83,6 +84,12 @@ int __init cobalt_init(void)
if (ret)
return ret;
 
+   ret = cobalt_nsem_pkg_init();
+   if (ret) {
+   cobalt_syscall_cleanup();
+   return ret;
+   }
+
cobalt_reg_pkg_init(64, 128);   /* FIXME: replace with compilation 
constants. */
cobalt_mutex_pkg_init();
cobalt_sem_pkg_init();
diff --git a/kernel/cobalt/posix/nsem.c b/kernel/cobalt/posix/nsem.c
new file mode 100644
index 000..7e66ea8
--- /dev/null
+++ b/kernel/cobalt/posix/nsem.c
@@ -0,0 +1,307 @@
+/*
+ * Copyright (C) 2013 Gilles Chanteperdrix .
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include "internal.h"
+#include "sem.h"
+
+static struct hlist_head *nsem_hash;
+DEFINE_XNLOCK(nsem_lock);
+
+struct nsem {
+   struct cobalt_sem *sem;
+   struct mm_struct *mm;
+   struct __shadow_sem __user *usem;
+   unsigned refs;
+   struct hlist_node hlink; /* Link in global hash */
+   struct list_head link;   /* Link in per-process queue */
+};
+
+static unsigned __attribute__((pure)) 
+nsem_hash_crunch(xnhandle_t handle, struct mm_struct *mm)
+{
+   unsigned hash = handle + (unsigned long)mm / sizeof(struct mm_struct);
+   return hash % CONFIG_XENO_OPT_REGISTRY_NRSLOTS;
+}
+
+static struct nsem *
+nsem_hash_search(xnhandle_t handle, struct mm_struct *mm)
+{
+   unsigned bucket = nsem_hash_crunch(handle, mm);
+   struct nsem *u;
+
+   hlist_for_each_entry(u, &nsem_hash[bucket], hlink)
+   if (u->sem->handle == handle && u->mm == mm)
+   return u;
+
+   return NULL;
+}
+
+static void nsem_hash_enter(xnhandle_t handle, struct nsem *nsem)
+{
+   unsigned bucket = nsem_hash_crunch(handle, current->mm);
+
+   hlist_add_head(&nsem->hlink, &nsem_hash[bucket]);
+}
+
+static void nsem_hash_remove(struct nsem *u)
+{
+   hlist_del(&u->hlink);
+}
+
+static struct __shadow_sem __user *
+nsem_open(struct __shadow_sem __user *ushadow, const char *name, 
+   int oflags, mode_t mode, unsigned value)
+{
+   struct __shadow_sem shadow;
+   struct cobalt_sem