summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJennifer Averett <jennifer.averett@oarcorp.com>2012-04-18 14:10:44 -0500
committerJennifer Averett <jennifer.averett@oarcorp.com>2012-04-18 14:10:44 -0500
commita2ec3326e32db9a4a5a9661e15637b485f1855f1 (patch)
tree63f3bafc97c83818f9b654cbc439c5d224de09b6
parentCommented out calls to pin and unpin. (diff)
downloadrtems-libbsd-a2ec3326e32db9a4a5a9661e15637b485f1855f1.tar.bz2
Merged the rtems version of resource back to kern_resource and added method to resolve linker errors.
-rw-r--r--Makefile1
-rwxr-xr-xfreebsd-to-rtems.py1
-rw-r--r--freebsd/kern/kern_resource.c14
-rw-r--r--rtemsbsd/src/rtems-bsd-resource.c174
4 files changed, 14 insertions, 176 deletions
diff --git a/Makefile b/Makefile
index d267920f..6ebebc2b 100644
--- a/Makefile
+++ b/Makefile
@@ -38,7 +38,6 @@ C_FILES += rtemsbsd/src/rtems-bsd-callout.c
C_FILES += rtemsbsd/src/rtems-bsd-init.c
C_FILES += rtemsbsd/src/rtems-bsd-init-with-irq.c
C_FILES += rtemsbsd/src/rtems-bsd-assert.c
-C_FILES += rtemsbsd/src/rtems-bsd-resource.c
C_FILES += rtemsbsd/src/rtems-bsd-jail.c
C_FILES += rtemsbsd/src/rtems-bsd-shell.c
C_FILES += rtemsbsd/src/rtems-bsd-syscalls.c
diff --git a/freebsd-to-rtems.py b/freebsd-to-rtems.py
index 3cc7fddc..597c5acf 100755
--- a/freebsd-to-rtems.py
+++ b/freebsd-to-rtems.py
@@ -531,7 +531,6 @@ rtems.addRTEMSSourceFiles(
'src/rtems-bsd-init.c',
'src/rtems-bsd-init-with-irq.c',
'src/rtems-bsd-assert.c',
- 'src/rtems-bsd-resource.c',
'src/rtems-bsd-jail.c',
'src/rtems-bsd-shell.c',
'src/rtems-bsd-syscalls.c',
diff --git a/freebsd/kern/kern_resource.c b/freebsd/kern/kern_resource.c
index 790403a0..939a1d24 100644
--- a/freebsd/kern/kern_resource.c
+++ b/freebsd/kern/kern_resource.c
@@ -69,12 +69,14 @@ __FBSDID("$FreeBSD$");
static MALLOC_DEFINE(M_PLIMIT, "plimit", "plimit structures");
+#endif /* __rtems__ */
static MALLOC_DEFINE(M_UIDINFO, "uidinfo", "uidinfo structures");
#define UIHASH(uid) (&uihashtbl[(uid) & uihash])
static struct rwlock uihashtbl_lock;
static LIST_HEAD(uihashhead, uidinfo) *uihashtbl;
static u_long uihash; /* size of hash table - 1 */
+#ifndef __rtems__
static void calcru1(struct proc *p, struct rusage_ext *ruxp,
struct timeval *up, struct timeval *sp);
static int donice(struct thread *td, struct proc *chgp, int n);
@@ -1140,6 +1142,7 @@ lim_max(struct proc *p, int which)
lim_rlimit(p, which, &rl);
return (rl.rlim_max);
}
+#endif /* __rtems__ */
/*
* Return the current (soft) limit for a particular system resource.
@@ -1148,12 +1151,21 @@ lim_max(struct proc *p, int which)
rlim_t
lim_cur(struct proc *p, int which)
{
+#ifndef __rtems__
struct rlimit rl;
lim_rlimit(p, which, &rl);
return (rl.rlim_cur);
+#else
+ /*
+ * Resource limits not currently supported in RTEMS version.
+ * This is left for future work.
+ */
+ return RLIM_INFINITY;
+#endif /* __rtems__ */
}
+#ifndef __rtems__
/*
* Return a copy of the entire rlimit structure for the system limit
* specified by 'which' in the rlimit structure pointed to by 'rlp'.
@@ -1169,6 +1181,7 @@ lim_rlimit(struct proc *p, int which, struct rlimit *rlp)
if (p->p_sysent->sv_fixlimit != NULL)
p->p_sysent->sv_fixlimit(rlp, which);
}
+#endif /* __rtems__ */
/*
* Find the uidinfo structure for a uid. This structure is used to
@@ -1304,6 +1317,7 @@ uifree(uip)
rw_wunlock(&uihashtbl_lock);
}
+#ifndef __rtems__
/*
* Change the count associated with number of processes
* a given user is using. When 'max' is 0, don't enforce a limit
diff --git a/rtemsbsd/src/rtems-bsd-resource.c b/rtemsbsd/src/rtems-bsd-resource.c
deleted file mode 100644
index e821fe05..00000000
--- a/rtemsbsd/src/rtems-bsd-resource.c
+++ /dev/null
@@ -1,174 +0,0 @@
-/**
- * @file
- *
- * @ingroup rtems_bsd_rtems
- *
- * @brief TODO.
- */
-
-/*
- * Copyright (c) 2009, 2010 embedded brains GmbH. All rights reserved.
- *
- * embedded brains GmbH
- * Obere Lagerstr. 30
- * 82178 Puchheim
- * Germany
- * <rtems@embedded-brains.de>
- *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rtems.com/license/LICENSE.
- */
-
-#include <freebsd/machine/rtems-bsd-config.h>
-
-#include <freebsd/sys/types.h>
-#include <freebsd/sys/systm.h>
-#include <freebsd/sys/lock.h>
-#include <freebsd/sys/malloc.h>
-#include <freebsd/sys/mutex.h>
-#include <freebsd/sys/proc.h>
-#include <freebsd/sys/resourcevar.h>
-#include <freebsd/sys/rwlock.h>
-#include <freebsd/sys/refcount.h>
-
-static MALLOC_DEFINE(M_UIDINFO, "uidinfo", "uidinfo structures");
-
-#define UIHASH(uid) (&uihashtbl[(uid) & uihash])
-static struct rwlock uihashtbl_lock;
-static LIST_HEAD(uihashhead, uidinfo) *uihashtbl;
-static u_long uihash; /* size of hash table - 1 */
-
-/*
- * Find the uidinfo structure for a uid. This structure is used to
- * track the total resource consumption (process count, socket buffer
- * size, etc.) for the uid and impose limits.
- */
-void
-uihashinit()
-{
-
- uihashtbl = hashinit(maxproc / 16, M_UIDINFO, &uihash);
- rw_init(&uihashtbl_lock, "uidinfo hash");
-}
-
-/*
- * Look up a uidinfo struct for the parameter uid.
- * uihashtbl_lock must be locked.
- */
-static struct uidinfo *
-uilookup(uid)
- uid_t uid;
-{
- struct uihashhead *uipp;
- struct uidinfo *uip;
-
- rw_assert(&uihashtbl_lock, RA_LOCKED);
- uipp = UIHASH(uid);
- LIST_FOREACH(uip, uipp, ui_hash)
- if (uip->ui_uid == uid)
- break;
-
- return (uip);
-}
-
-/*
- * Find or allocate a struct uidinfo for a particular uid.
- * Increase refcount on uidinfo struct returned.
- * uifree() should be called on a struct uidinfo when released.
- */
-struct uidinfo *
-uifind(uid)
- uid_t uid;
-{
- struct uidinfo *old_uip, *uip;
-
- rw_rlock(&uihashtbl_lock);
- uip = uilookup(uid);
- if (uip == NULL) {
- rw_runlock(&uihashtbl_lock);
- uip = malloc(sizeof(*uip), M_UIDINFO, M_WAITOK | M_ZERO);
- rw_wlock(&uihashtbl_lock);
- /*
- * There's a chance someone created our uidinfo while we
- * were in malloc and not holding the lock, so we have to
- * make sure we don't insert a duplicate uidinfo.
- */
- if ((old_uip = uilookup(uid)) != NULL) {
- /* Someone else beat us to it. */
- free(uip, M_UIDINFO);
- uip = old_uip;
- } else {
- refcount_init(&uip->ui_ref, 0);
- uip->ui_uid = uid;
- mtx_init(&uip->ui_vmsize_mtx, "ui_vmsize", NULL,
- MTX_DEF);
- LIST_INSERT_HEAD(UIHASH(uid), uip, ui_hash);
- }
- }
- uihold(uip);
- rw_unlock(&uihashtbl_lock);
- return (uip);
-}
-
-/*
- * Place another refcount on a uidinfo struct.
- */
-void
-uihold(uip)
- struct uidinfo *uip;
-{
-
- refcount_acquire(&uip->ui_ref);
-}
-
-/*-
- * Since uidinfo structs have a long lifetime, we use an
- * opportunistic refcounting scheme to avoid locking the lookup hash
- * for each release.
- *
- * If the refcount hits 0, we need to free the structure,
- * which means we need to lock the hash.
- * Optimal case:
- * After locking the struct and lowering the refcount, if we find
- * that we don't need to free, simply unlock and return.
- * Suboptimal case:
- * If refcount lowering results in need to free, bump the count
- * back up, lose the lock and acquire the locks in the proper
- * order to try again.
- */
-void
-uifree(uip)
- struct uidinfo *uip;
-{
- int old;
-
- /* Prepare for optimal case. */
- old = uip->ui_ref;
- if (old > 1 && atomic_cmpset_int(&uip->ui_ref, old, old - 1))
- return;
-
- /* Prepare for suboptimal case. */
- rw_wlock(&uihashtbl_lock);
- if (refcount_release(&uip->ui_ref)) {
- LIST_REMOVE(uip, ui_hash);
- rw_wunlock(&uihashtbl_lock);
- if (uip->ui_sbsize != 0)
- printf("freeing uidinfo: uid = %d, sbsize = %ld\n",
- uip->ui_uid, uip->ui_sbsize);
- if (uip->ui_proccnt != 0)
- printf("freeing uidinfo: uid = %d, proccnt = %ld\n",
- uip->ui_uid, uip->ui_proccnt);
- if (uip->ui_vmsize != 0)
- printf("freeing uidinfo: uid = %d, swapuse = %lld\n",
- uip->ui_uid, (unsigned long long)uip->ui_vmsize);
- mtx_destroy(&uip->ui_vmsize_mtx);
- free(uip, M_UIDINFO);
- return;
- }
- /*
- * Someone added a reference between atomic_cmpset_int() and
- * rw_wlock(&uihashtbl_lock).
- */
- rw_wunlock(&uihashtbl_lock);
-}