Commit 24491621 authored by Charlie Jacobsen's avatar Charlie Jacobsen

private-types: Adds struct cap_type_system. Old code builds.

The code builds right now by default (--enable-global-cap-types is
on by default). Next step is to adjust the internals.

Fixed an autoconf script bug: if you AC_SUBST a variable in one
case and AC_SUBST_FILE in another (perhaps in an if statement), autoconf
gets confused. So, I just always AC_SUBST now and cat the file into
the variable when necessary. (I'm referring to the
CAP_INCLUDE_GLOBAL_TYPES variable in configure.ac.)
parent b5dc70da
Pipeline #414 skipped
......@@ -100,8 +100,11 @@ AS_IF([test "x$enable_global_cap_types" = "xyes"],
[
AC_DEFINE([CAP_ENABLE_GLOBAL_TYPES], 1,
[Allow cspaces to use one global type system.])
CAP_INCLUDE_GLOBAL_TYPES=$srcdir/src/include/global_cap_types.h
AC_SUBST_FILE([CAP_INCLUDE_GLOBAL_TYPES])
# Using cat instead of AC_SUBST_FILE. (If you AC_SUBST_FILE a
# variable in one case and AC_SUBST it in another, autoconf
# gets confused.)
CAP_INCLUDE_GLOBAL_TYPES=`cat $srcdir/src/include/global_cap_types.h`
AC_SUBST([CAP_INCLUDE_GLOBAL_TYPES])
AC_MSG_NOTICE([Allowing global capability type system.])
],
[
......@@ -110,6 +113,8 @@ AS_IF([test "x$enable_global_cap_types" = "xyes"],
AC_MSG_NOTICE([Disallowing global capability type system.])
])
AM_SUBST_NOTMAKE(CAP_INCLUDE_GLOBAL_TYPES)
# Kernel module build?
AS_IF([test "x$PLATFORM" = "xkernel"],
......@@ -340,6 +345,7 @@ AC_CONFIG_FILES(
src/common/Makefile
src/include/Makefile
src/include/libcap_config.h
src/include/libcap_types.h
src/include/libcap.h
......
......@@ -212,6 +212,56 @@ cap_cptr_cache_bmap_for_level(struct cptr_cache *c, int lvl)
@CAP_CPTR_CACHE_BMAP_FOR_LEVEL@
}
/* TYPE SYSTEMS -------------------------------------------------- */
/**
* cap_type_system_alloc -- Alloc memory for a type system
* @ts: out param, alloc'd type system stored in pointer
*
* Just like cspaces and cptr caches, the lifetime is:
*
* cap_type_system_alloc - alloc mem
* cap_type_system_init - init type system
* cap_type_system_destroy - tear down type system
* cap_type_system_free - free mem
*/
int cap_type_system_alloc(struct cap_type_system **ts);
/**
* cap_type_system_init -- Initialize type system - locks, etc.
* @ts: the type system to initialize
*/
int cap_type_system_init(struct cap_type_system *ts);
/**
* cap_type_system_destroy -- Tear down type system
* @ts: the type system to destroy
*
* Does not free type system.
*/
void cap_type_system_destroy(struct cap_type_system *ts);
/**
* cap_type_system_free -- Free type system alloc'd via cap_type_system_alloc
* @ts: the type system to free
*/
void cap_type_system_free(struct cap_type_system *ts);
/**
* cap_register_private_type -- Register a new capability object type in
* type system
* @ts: the type system to add the new type to
* @type: integer type index / identifier
* @ops: the cap_type_ops to associate with this type
*
* If you pass type == 0, the system will select the next available
* identifier and return it. You should use the returned value as your
* object identifier. If you attempt to use a type that is already in use,
* this returns -EADDRINUSE. If there are no types remaining or you exceed
* CAP_TYPE_MAX, this returns -ENOMEM.
*
* Every type system comes with the built-in types that are in
* libcap_platform.h, in the definition of cap_type_t.
*/
cap_type_t cap_register_private_type(struct cap_type_system *ts,
cap_type_t type, const struct cap_type_ops *ops);
/* CSPACES -------------------------------------------------- */
/**
......@@ -276,7 +326,7 @@ struct cspace * cap_alloc_cspace(void);
* drops reference on @ts.
*/
int cap_init_cspace_with_type_system(struct cspace *cspace,
struct cap_type_system_t *ts);
struct cap_type_system *ts);
/**
* cap_destroy_cspace -- Equivalent to calling lcd_cap_delete on all cnodes
* in cspace. Frees up all cnode tables, etc.
......@@ -315,25 +365,7 @@ void* cap_cspace_getowner(struct cspace *cspace);
* If you plan to use the type system after all other references go away,
* you should bump its reference count (via cap_type_system_get).
*/
cap_type_system_t* cap_cspace_get_type_system(struct cspace *cspace);
/**
* cap_register_private_type -- Register a new capability object type in
* type system
* @ts: the type system to add the new type to
* @type: integer type index / identifier
* @ops: the cap_type_ops to associate with this type
*
* If you pass type == 0, the system will select the next available
* identifier and return it. You should use the returned value as your
* object identifier. If you attempt to use a type that is already in use,
* this returns -EADDRINUSE. If there are no types remaining or you exceed
* CAP_TYPE_MAX, this returns -ENOMEM.
*
* Every type system comes with the built-in types that are in
* libcap_platform.h, in the definition of cap_type_t.
*/
cap_type_t cap_register_private_type(cap_type_system_t *ts,
cap_type_t type, const struct cap_type_ops *ops);
struct cap_type_system* cap_cspace_get_type_system(struct cspace *cspace);
/**
* cap_insert -- Inserts object data into cspace at cnode pointed at by c
* @cspace: the cspace to insert the object into
......
......@@ -25,6 +25,17 @@ struct cdt_root_node;
struct cspace;
struct cnode_table;
struct cap_type_system {
/*
* Lock
*/
cap_mutex_t lock;
/*
* Array of types in this type system
*/
struct cap_type_ops types[CAP_TYPE_MAX];
};
enum allocation_state {
ALLOCATION_INVALID,
ALLOCATION_VALID,
......
......@@ -77,7 +77,7 @@ struct cap_type_ops {
int (*revoke)(struct cspace *cspace, struct cnode *cnode, void *object);
};
/* MISC -------------------------------------------------- */
/* CAP TYPE SYSTEMS -------------------------------------------------- */
/**
* Maximum number of types allowed per type system
......@@ -86,4 +86,6 @@ struct cap_type_ops {
#define CAP_TYPE_MAX 256
#endif
struct cap_type_system;
#endif /* __LIBCAP_TYPES_H__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment