summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sys/kern/uipc_shm.c23
-rw-r--r--sys/sys/mman.h1
2 files changed, 21 insertions, 3 deletions
diff --git a/sys/kern/uipc_shm.c b/sys/kern/uipc_shm.c
index b8eb96c..6f9fc81 100644
--- a/sys/kern/uipc_shm.c
+++ b/sys/kern/uipc_shm.c
@@ -49,6 +49,7 @@ __FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/capability.h>
+#include <sys/conf.h>
#include <sys/fcntl.h>
#include <sys/file.h>
#include <sys/filedesc.h>
@@ -101,12 +102,14 @@ static LIST_HEAD(, shm_mapping) *shm_dictionary;
static struct sx shm_dict_lock;
static struct mtx shm_timestamp_lock;
static u_long shm_hash;
+static struct unrhdr *shm_ino_unr;
+static dev_t shm_dev_ino;
#define SHM_HASH(fnv) (&shm_dictionary[(fnv) & shm_hash])
static int shm_access(struct shmfd *shmfd, struct ucred *ucred, int flags);
static struct shmfd *shm_alloc(struct ucred *ucred, mode_t mode);
-static void shm_dict_init(void *arg);
+static void shm_init(void *arg);
static void shm_drop(struct shmfd *shmfd);
static struct shmfd *shm_hold(struct shmfd *shmfd);
static void shm_insert(char *path, Fnv32_t fnv, struct shmfd *shmfd);
@@ -408,6 +411,8 @@ shm_stat(struct file *fp, struct stat *sb, struct ucred *active_cred,
sb->st_uid = shmfd->shm_uid;
sb->st_gid = shmfd->shm_gid;
mtx_unlock(&shm_timestamp_lock);
+ sb->st_dev = shm_dev_ino;
+ sb->st_ino = shmfd->shm_ino;
return (0);
}
@@ -539,6 +544,7 @@ static struct shmfd *
shm_alloc(struct ucred *ucred, mode_t mode)
{
struct shmfd *shmfd;
+ int ino;
shmfd = malloc(sizeof(*shmfd), M_SHMFD, M_WAITOK | M_ZERO);
shmfd->shm_size = 0;
@@ -555,6 +561,11 @@ shm_alloc(struct ucred *ucred, mode_t mode)
vfs_timestamp(&shmfd->shm_birthtime);
shmfd->shm_atime = shmfd->shm_mtime = shmfd->shm_ctime =
shmfd->shm_birthtime;
+ ino = alloc_unr(shm_ino_unr);
+ if (ino == -1)
+ shmfd->shm_ino = 0;
+ else
+ shmfd->shm_ino = ino;
refcount_init(&shmfd->shm_refs, 1);
mtx_init(&shmfd->shm_mtx, "shmrl", NULL, MTX_DEF);
rangelock_init(&shmfd->shm_rl);
@@ -585,6 +596,8 @@ shm_drop(struct shmfd *shmfd)
rangelock_destroy(&shmfd->shm_rl);
mtx_destroy(&shmfd->shm_mtx);
vm_object_deallocate(shmfd->shm_object);
+ if (shmfd->shm_ino != 0)
+ free_unr(shm_ino_unr, shmfd->shm_ino);
free(shmfd, M_SHMFD);
}
}
@@ -617,14 +630,18 @@ shm_access(struct shmfd *shmfd, struct ucred *ucred, int flags)
* the mappings in a hash table.
*/
static void
-shm_dict_init(void *arg)
+shm_init(void *arg)
{
mtx_init(&shm_timestamp_lock, "shm timestamps", NULL, MTX_DEF);
sx_init(&shm_dict_lock, "shm dictionary");
shm_dictionary = hashinit(1024, M_SHMFD, &shm_hash);
+ shm_ino_unr = new_unrhdr(1, INT32_MAX, NULL);
+ KASSERT(shm_ino_unr != NULL, ("shm fake inodes not initialized"));
+ shm_dev_ino = devfs_alloc_cdp_inode();
+ KASSERT(shm_dev_ino > 0, ("shm dev inode not initialized"));
}
-SYSINIT(shm_dict_init, SI_SUB_SYSV_SHM, SI_ORDER_ANY, shm_dict_init, NULL);
+SYSINIT(shm_init, SI_SUB_SYSV_SHM, SI_ORDER_ANY, shm_init, NULL);
static struct shmfd *
shm_lookup(char *path, Fnv32_t fnv)
diff --git a/sys/sys/mman.h b/sys/sys/mman.h
index e89bee3..a13e3d1 100644
--- a/sys/sys/mman.h
+++ b/sys/sys/mman.h
@@ -219,6 +219,7 @@ struct shmfd {
struct timespec shm_mtime;
struct timespec shm_ctime;
struct timespec shm_birthtime;
+ ino_t shm_ino;
struct label *shm_label; /* MAC label */
const char *shm_path;
OpenPOWER on IntegriCloud