From: Justin Sobota Date: Tue, 15 Jan 2013 22:47:51 +0000 (-0500) Subject: Wrote policy validation routines X-Git-Tag: DEV.RM_LLD.02.00.00.01~10^2~18 X-Git-Url: https://git.ti.com/gitweb?p=keystone-rtos%2Frm-lld.git;a=commitdiff_plain;h=4139506354ba9978e3a98d55e034aeccc38059df Wrote policy validation routines --- diff --git a/include/rm_loc.h b/include/rm_loc.h index f1d6513..efb5f07 100644 --- a/include/rm_loc.h +++ b/include/rm_loc.h @@ -194,11 +194,16 @@ void Rm_transactionProcessor (Rm_Inst *rmInst, Rm_Transaction *transaction); **********************************************************************/ /* Declare the tree structure nodes */ +typedef struct Rm_AllocatedTo_s { + char instName[RM_INSTANCE_NAME_MAX_CHARS]; + struct Rm_AllocatedTo_s *nextAllocatedTo; +} Rm_AllocatedTo; + typedef struct _Rm_ResourceNode { RB_ENTRY(_Rm_ResourceNode) linkage; uint32_t base; uint32_t length; - char allocatedTo[RM_INSTANCE_NAME_MAX_CHARS]; + Rm_AllocatedTo *allocatedTo; } Rm_ResourceNode; /* Declare the tree head structure. A structure of type Rm_ResourceTree will need to be diff --git a/include/rm_policyloc.h b/include/rm_policyloc.h index a7592c2..b51e746 100644 --- a/include/rm_policyloc.h +++ b/include/rm_policyloc.h @@ -52,12 +52,14 @@ extern "C" { /* Bit : Description *----------------------------- - * 0 : Init (iI) - RM instance has initialization permission for resource - * 1 : Use (uU) - RM instance has usage permission for resource - * 2 : Exclusive (xX) - RM instance has exclusive allocation privilege for resource - * i.e. No other RM instance can reserve the resource if a RM - * instance with exclusive privilege reserves the resource - * 3 - 15 : UNUSED + * 0 : Init (iI) - RM instance has initialization permission for resource + * 1 : Use (uU) - RM instance has usage permission for resource + * 2 : Exclusive (xX) - RM instance has exclusive allocation privilege for resource + * i.e. No other RM instance can reserve the resource if a RM + * instance with exclusive privilege reserves the resource + * 3 : Shared Linux (sS) - Resource has been reserved by the Linux kernel but can be + * allocated by the specified RM instances + * 4 - 15 : UNUSED */ typedef uint16_t Rm_PermissionBits; @@ -70,6 +72,9 @@ typedef uint16_t Rm_PermissionBits; #define RM_POLICY_PERM_EXCLUSIVE_LOWER 'x' #define RM_POLICY_PERM_EXCLUSIVE_UPPER 'X' #define RM_POLICY_PERM_EXCLUSIVE_SHIFT 2 +#define RM_POLICY_PERM_SHARED_LINUX_LOWER 's' +#define RM_POLICY_PERM_SHARED_LINUX_UPPER 'S' +#define RM_POLICY_PERM_SHARED_LINUX_SHIFT 3 #define RM_POLICY_PERM_SUBGROUP_START '(' #define RM_POLICY_PERM_SUBGROUP_END ')' diff --git a/rm.h b/rm.h index c9d0825..d5f2cb2 100644 --- a/rm.h +++ b/rm.h @@ -141,7 +141,7 @@ extern "C" { #define RM_INIT_OK 0 #define RM_INIT_ERROR_INSTANCE_NAME_TOO_BIG -256 #define RM_INIT_ERROR_POLICY_NO_VALID_INSTANCES_DEFINED -257 -#define RM_INIT_ERROR_POLICY_UNKNOWN_VALID_INSTANCE -258 +#define RM_INIT_ERROR_POLICY_UNKNOWN_INSTANCE -258 #define RM_INIT_ERROR_POLICY_PERMISSION_SYNTAX_ERROR -259 #define RM_INIT_ERROR_POLICY_UNKNOWN_RESOURCE -260 #define RM_INIT_ERROR_POLICY_SYNTAX_ERROR - 261 diff --git a/src/rm.c b/src/rm.c index 43a5460..64d79f0 100644 --- a/src/rm.c +++ b/src/rm.c @@ -88,7 +88,9 @@ Rm_ResourceNode *Rm_newResourceNode(uint32_t resourceBase, uint32_t resourceLeng /* Populate the RM relevant fields */ newNode->base = resourceBase; newNode->length = resourceLength; - strcpy(newNode->allocatedTo, allocatedTo); + newNode->allocatedTo = Rm_osalMalloc(sizeof(Rm_AllocatedTo); + strcpy(newNode->allocatedTo->instName, allocatedTo); + newNode->allocatedTo->nextAllocatedTo = NULL; return(newNode); } diff --git a/src/rm_policy.c b/src/rm_policy.c index 2118e22..f741468 100644 --- a/src/rm_policy.c +++ b/src/rm_policy.c @@ -58,10 +58,49 @@ /* RM OSAL layer */ #include +char Rm_policyAllInstances[] = "*"; + int32_t Rm_policyCheckInstances(Rm_PolicyValidInst *validInstList, Rm_PolicyPermission *permissionsList) { + Rm_PolicyValidInst *validInst = validInstList; + Rm_PolicyPermission *permission = permissionsList; + bool instNameMatch = FALSE; + + /* Check each instance name in the permission list against the list of valid instance + * names. Return an error if any permission instance name is not in the valid instance + * name list */ + while (permission) + { + /* Instantly declare a name match if the permission's instance name is the "all" + * wildcard */ + if (strcmp(permission->instName, Rm_policyAllInstances) == 0) + { + instNameMatch = TRUE; + } + else + { + while (validInst) + { + if (strcmp(permission->instName, validInst->instName) == 0) + { + instNameMatch = TRUE; + } + validInst = validInst->nextValidInst; + } + } + if (!instNameMatch) + { + return(RM_INIT_ERROR_POLICY_UNKNOWN_INSTANCE); + } + + /* Get the next permission and reset to the beginning of the valid instance list */ + permission = permission->nextPermission; + validInst = validInstList; + instNameMatch = FALSE; + } + return(RM_INIT_OK); } @@ -116,9 +155,10 @@ Rm_PolicyPermission *Rm_policyParseSubPermission(char *permStrStart, char *permS instNameIndex = 0; foundInstName = FALSE; instNameComplete = FALSE; - while (permStrPtr < subgroupEnd) + while (permStrPtr <= subgroupEnd) { - if (isspace(*permStrPtr) && foundInstName) + if ((isspace(*permStrPtr) || (*permStrPtr == RM_POLICY_PERM_SUBGROUP_END)) + && foundInstName) { /* First space encountered after copying an instance name. This * terminates the instance name. All other space characters are @@ -202,25 +242,47 @@ Rm_PolicyPermission *Rm_policyParseSubPermission(char *permStrStart, char *permS if ((*permStrPtr == RM_POLICY_PERM_INIT_LOWER) || (*permStrPtr == RM_POLICY_PERM_INIT_UPPER)) { - - /* Set the init permissions */ - RM_POLICY_SET_PERM(newPerm->permissionBits, RM_POLICY_PERM_INIT_SHIFT, 1); - permStrPtr++; + /* Set the init permissions for each of the instances specified in the group */ + newPerm = startPerm; + while (newPerm) + { + RM_POLICY_SET_PERM(newPerm->permissionBits, RM_POLICY_PERM_INIT_SHIFT, 1); + newPerm = newPerm->nextPermission; + } } else if ((*permStrPtr == RM_POLICY_PERM_USE_LOWER) || (*permStrPtr == RM_POLICY_PERM_USE_UPPER)) { - /* Set the use permissions */ - RM_POLICY_SET_PERM(newPerm->permissionBits, RM_POLICY_PERM_USE_SHIFT, 1); - permStrPtr++; + /* Set the use permissions for each of the instances specified in the group */ + newPerm = startPerm; + while (newPerm) + { + RM_POLICY_SET_PERM(newPerm->permissionBits, RM_POLICY_PERM_USE_SHIFT, 1); + newPerm = newPerm->nextPermission; + } } else if ((*permStrPtr == RM_POLICY_PERM_EXCLUSIVE_LOWER) || (*permStrPtr == RM_POLICY_PERM_EXCLUSIVE_UPPER)) { - /* Set the exclusive permissions */ - RM_POLICY_SET_PERM(newPerm->permissionBits, RM_POLICY_PERM_EXCLUSIVE_SHIFT, 1); - permStrPtr++; + /* Set the exclusive permissions for each of the instances specified in the group */ + newPerm = startPerm; + while (newPerm) + { + RM_POLICY_SET_PERM(newPerm->permissionBits, RM_POLICY_PERM_EXCLUSIVE_SHIFT, 1); + newPerm = newPerm->nextPermission; + } } + else if ((*permStrPtr == RM_POLICY_PERM_SHARED_LINUX_LOWER) || + (*permStrPtr == RM_POLICY_PERM_SHARED_LINUX_UPPER)) + { + /* Set the shared Linux permissions for each of the instances specified in the group */ + newPerm = startPerm; + while (newPerm) + { + RM_POLICY_SET_PERM(newPerm->permissionBits, RM_POLICY_PERM_SHARED_LINUX_SHIFT, 1); + newPerm = newPerm->nextPermission; + } + } else { /* Invalid permission character. This is a @@ -289,25 +351,47 @@ Rm_PolicyPermission *Rm_policyParseSubPermission(char *permStrStart, char *permS if ((*permStrPtr == RM_POLICY_PERM_INIT_LOWER) || (*permStrPtr == RM_POLICY_PERM_INIT_UPPER)) { - - /* Set the init permissions */ - RM_POLICY_SET_PERM(newPerm->permissionBits, RM_POLICY_PERM_INIT_SHIFT, 1); - permStrPtr++; + /* Set the init permissions for each of the instances specified in the group */ + newPerm = startPerm; + while (newPerm) + { + RM_POLICY_SET_PERM(newPerm->permissionBits, RM_POLICY_PERM_INIT_SHIFT, 1); + newPerm = newPerm->nextPermission; + } } else if ((*permStrPtr == RM_POLICY_PERM_USE_LOWER) || (*permStrPtr == RM_POLICY_PERM_USE_UPPER)) { - /* Set the use permissions */ - RM_POLICY_SET_PERM(newPerm->permissionBits, RM_POLICY_PERM_USE_SHIFT, 1); - permStrPtr++; + /* Set the use permissions for each of the instances specified in the group */ + newPerm = startPerm; + while (newPerm) + { + RM_POLICY_SET_PERM(newPerm->permissionBits, RM_POLICY_PERM_USE_SHIFT, 1); + newPerm = newPerm->nextPermission; + } } else if ((*permStrPtr == RM_POLICY_PERM_EXCLUSIVE_LOWER) || (*permStrPtr == RM_POLICY_PERM_EXCLUSIVE_UPPER)) { - /* Set the exclusive permissions */ - RM_POLICY_SET_PERM(newPerm->permissionBits, RM_POLICY_PERM_EXCLUSIVE_SHIFT, 1); - permStrPtr++; + /* Set the exclusive permissions for each of the instances specified in the group */ + newPerm = startPerm; + while (newPerm) + { + RM_POLICY_SET_PERM(newPerm->permissionBits, RM_POLICY_PERM_EXCLUSIVE_SHIFT, 1); + newPerm = newPerm->nextPermission; + } } + else if ((*permStrPtr == RM_POLICY_PERM_SHARED_LINUX_LOWER) || + (*permStrPtr == RM_POLICY_PERM_SHARED_LINUX_UPPER)) + { + /* Set the shared Linux permissions for each of the instances specified in the group */ + newPerm = startPerm; + while (newPerm) + { + RM_POLICY_SET_PERM(newPerm->permissionBits, RM_POLICY_PERM_SHARED_LINUX_SHIFT, 1); + newPerm = newPerm->nextPermission; + } + } else { /* Invalid permission character. This is a