オープンソース・ソフトウェアの開発とダウンロード

Subversion リポジトリの参照

Diff of /trunk/1.8.x/ccs-patch/security/ccsecurity/memory.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3129 by kumaneko, Mon Nov 2 06:16:30 2009 UTC revision 3131 by kumaneko, Tue Nov 3 03:51:07 2009 UTC
# Line 3  Line 3 
3   *   *
4   * Copyright (C) 2005-2009  NTT DATA CORPORATION   * Copyright (C) 2005-2009  NTT DATA CORPORATION
5   *   *
6   * Version: 1.7.1-pre   2009/11/02   * Version: 1.7.1-pre   2009/11/03
7   *   *
8   * This file is applicable to both 2.4.30 and 2.6.11 and later.   * This file is applicable to both 2.4.30 and 2.6.11 and later.
9   * See README.ccs for ChangeLog.   * See README.ccs for ChangeLog.
# Line 82  void ccs_memory_free(const void *ptr, si Line 82  void ccs_memory_free(const void *ptr, si
82          kfree(ptr);          kfree(ptr);
83  }  }
84    
85  static LIST_HEAD(ccs_address_list);  LIST_HEAD(ccs_address_list);
86    
87  /**  /**
88   * ccs_get_ipv6_address - Keep the given IPv6 address on the RAM.   * ccs_get_ipv6_address - Keep the given IPv6 address on the RAM.
# Line 121  const struct in6_addr *ccs_get_ipv6_addr Line 121  const struct in6_addr *ccs_get_ipv6_addr
121          return ptr ? &ptr->addr : NULL;          return ptr ? &ptr->addr : NULL;
122  }  }
123    
 /**  
  * ccs_put_ipv6_address - Delete the given IPv6 address on the RAM.  
  *  
  * @addr: Pointer to "struct in6_addr".  
  */  
 void ccs_put_ipv6_address(const struct in6_addr *addr)  
 {  
         struct ccs_ipv6addr_entry *ptr;  
         bool can_delete = false;  
         if (!addr)  
                 return;  
         ptr = container_of(addr, struct ccs_ipv6addr_entry, addr);  
         mutex_lock(&ccs_policy_lock);  
         if (atomic_dec_and_test(&ptr->users)) {  
                 list_del(&ptr->list);  
                 can_delete = true;  
         }  
         mutex_unlock(&ccs_policy_lock);  
         if (can_delete)  
                 ccs_memory_free(ptr, sizeof(*ptr));  
 }  
   
 /**  
  * ccs_put_condition - Delete memory for "struct ccs_condition".  
  *  
  * @cond: Pointer to "struct ccs_condition".  
  */  
 void ccs_put_condition(struct ccs_condition *cond)  
 {  
         const struct ccs_condition_element *condp;  
         struct ccs_number_union *numbers_p;  
         struct ccs_name_union *names_p;  
         const struct ccs_argv_entry *argv;  
         const struct ccs_envp_entry *envp;  
         u16 condc;  
         u16 numbers_count;  
         u16 names_count;  
         u16 argc;  
         u16 envc;  
         u16 i;  
         bool can_delete = false;  
         if (!cond)  
                 return;  
         BUG_ON(atomic_read(&cond->users) <= 0);  
         mutex_lock(&ccs_policy_lock);  
         if (atomic_dec_and_test(&cond->users)) {  
                 list_del(&cond->list);  
                 can_delete = true;  
         }  
         mutex_unlock(&ccs_policy_lock);  
         if (!can_delete)  
                 return;  
         condc = cond->condc;  
         numbers_count = cond->numbers_count;  
         names_count = cond->names_count;  
         argc = cond->argc;  
         envc = cond->envc;  
         condp = (const struct ccs_condition_element *) (cond + 1);  
         numbers_p = (struct ccs_number_union *) (condp + condc);  
         names_p = (struct ccs_name_union *) (numbers_p + numbers_count);  
         argv = (const struct ccs_argv_entry *) (names_p + names_count);  
         envp = (const struct ccs_envp_entry *) (argv + argc);  
         for (i = 0; i < numbers_count; i++)  
                 ccs_put_number_union(numbers_p++);  
         for (i = 0; i < names_count; i++)  
                 ccs_put_name_union(names_p++);  
         for (i = 0; i < argc; argv++, i++)  
                 ccs_put_name(argv->value);  
         for (i = 0; i < envc; envp++, i++) {  
                 ccs_put_name(envp->name);  
                 ccs_put_name(envp->value);  
         }  
         ccs_memory_free(cond, cond->size);  
 }  
   
 #define CCS_MAX_HASH 256  
   
 /* Structure for string data. */  
 struct ccs_name_entry {  
         struct list_head list;  
         atomic_t users;  
         int size;  
         struct ccs_path_info entry;  
 };  
   
124  /* The list for "struct ccs_name_entry". */  /* The list for "struct ccs_name_entry". */
125  static struct list_head ccs_name_list[CCS_MAX_HASH];  struct list_head ccs_name_list[CCS_MAX_HASH];
126  static DEFINE_MUTEX(ccs_name_list_lock);  DEFINE_MUTEX(ccs_name_list_lock);
127    
128  /**  /**
129   * ccs_get_name - Allocate memory for string data.   * ccs_get_name - Allocate memory for string data.
# Line 258  const struct ccs_path_info *ccs_get_name Line 173  const struct ccs_path_info *ccs_get_name
173  }  }
174    
175  /**  /**
  * ccs_put_name - Delete shared memory for string data.  
  *  
  * @name: Pointer to "struct ccs_path_info".  
  */  
 void ccs_put_name(const struct ccs_path_info *name)  
 {  
         struct ccs_name_entry *ptr;  
         bool can_delete = false;  
         if (!name)  
                 return;  
         ptr = container_of(name, struct ccs_name_entry, entry);  
         mutex_lock(&ccs_name_list_lock);  
         if (atomic_dec_and_test(&ptr->users)) {  
                 list_del(&ptr->list);  
                 can_delete = true;  
         }  
         mutex_unlock(&ccs_name_list_lock);  
         if (can_delete) {  
                 atomic_sub(ptr->size, &ccs_policy_memory_size);  
                 kfree(ptr);  
         }  
 }  
   
 /**  
176   * ccs_mm_init - Initialize mm related code.   * ccs_mm_init - Initialize mm related code.
177   *   *
178   * Returns 0.   * Returns 0.

Legend:
Removed from v.3129  
changed lines
  Added in v.3131

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26