VPP-327 Coding standards cleanup for vppinfra
[vpp.git] / vppinfra / vppinfra / elf_clib.c
index 8c70548..7bb72ee 100644 (file)
@@ -18,8 +18,9 @@
 #include <fcntl.h>
 #include <sys/stat.h>
 
-typedef struct {
-  char ** path;
+typedef struct
+{
+  char **path;
 } path_search_t;
 
 always_inline void
@@ -32,11 +33,11 @@ path_search_free (path_search_t * p)
 }
 
 static char **
-split_string (char * string, u8 delimiter)
+split_string (char *string, u8 delimiter)
 {
-  char ** result = 0;
-  char * p, * start, * s;
-  
+  char **result = 0;
+  char *p, *start, *s;
+
   p = string;
   while (1)
     {
@@ -56,9 +57,9 @@ split_string (char * string, u8 delimiter)
 }
 
 static int
-file_exists_and_is_executable (char * dir, char * file)
+file_exists_and_is_executable (char *dir, char *file)
 {
-  char * path = (char *) format (0, "%s/%s%c", dir, file, 0);
+  char *path = (char *) format (0, "%s/%s%c", dir, file, 0);
   struct stat s;
   uword yes;
 
@@ -72,17 +73,17 @@ file_exists_and_is_executable (char * dir, char * file)
 }
 
 static char *
-path_search (char * file)
+path_search (char *file)
 {
   path_search_t ps;
   uword i;
-  char * result;
+  char *result;
 
   /* Relative or absolute path. */
   if (file[0] == '.' || file[0] == '/')
     return file;
 
-  if (getenv("PATH") == 0)
+  if (getenv ("PATH") == 0)
     return file;
 
   ps.path = split_string (getenv ("PATH"), ':');
@@ -102,16 +103,15 @@ path_search (char * file)
 
 static clib_error_t *
 clib_elf_parse_file (clib_elf_main_t * cem,
-                    char * file_name,
-                    void * link_address)
+                    char *file_name, void *link_address)
 {
-  elf_main_t * em;
-  elf_section_t * s;
+  elf_main_t *em;
+  elf_section_t *s;
   int fd;
   struct stat fd_stat;
   uword mmap_length = 0;
-  void * data = 0;
-  clib_error_t * error = 0;
+  void *data = 0;
+  clib_error_t *error = 0;
 
   vec_add2 (cem->elf_mains, em, 1);
 
@@ -142,66 +142,66 @@ clib_elf_parse_file (clib_elf_main_t * cem,
 
   /* Look for CLIB special sections. */
   {
-    char * section_name_start = CLIB_ELF_SECTION_ADD_PREFIX ();
+    char *section_name_start = CLIB_ELF_SECTION_ADD_PREFIX ();
     uword section_name_start_len = strlen (section_name_start);
 
     vec_foreach (s, em->sections)
-      {
-       u8 * name = elf_section_name (em, s);
-       uword * p;
-       clib_elf_section_t * vs;
-       clib_elf_section_bounds_t * b;
-
-       /* Section name must begin with CLIB_ELF_SECTION key. */
-       if (memcmp (name, section_name_start, section_name_start_len))
-         continue;
-
-       name += section_name_start_len;
-       p = hash_get_mem (cem->section_by_name, name);
-       if (p)
-         vs = vec_elt_at_index (cem->sections, p[0]);
-       else
-         {
-           name = format (0, "%s%c", name, 0);
-           if (! cem->section_by_name)
-             cem->section_by_name = hash_create_string (0, sizeof (uword));
-           hash_set_mem (cem->section_by_name, name, vec_len (cem->sections));
-           vec_add2 (cem->sections, vs, 1);
-           vs->name = name;
-         }
+    {
+      u8 *name = elf_section_name (em, s);
+      uword *p;
+      clib_elf_section_t *vs;
+      clib_elf_section_bounds_t *b;
+
+      /* Section name must begin with CLIB_ELF_SECTION key. */
+      if (memcmp (name, section_name_start, section_name_start_len))
+       continue;
+
+      name += section_name_start_len;
+      p = hash_get_mem (cem->section_by_name, name);
+      if (p)
+       vs = vec_elt_at_index (cem->sections, p[0]);
+      else
+       {
+         name = format (0, "%s%c", name, 0);
+         if (!cem->section_by_name)
+           cem->section_by_name = hash_create_string (0, sizeof (uword));
+         hash_set_mem (cem->section_by_name, name, vec_len (cem->sections));
+         vec_add2 (cem->sections, vs, 1);
+         vs->name = name;
+       }
 
-       vec_add2 (vs->bounds, b, 1);
-       b->lo = link_address + s->header.exec_address;
-       b->hi = b->lo + s->header.file_size;
-      }
+      vec_add2 (vs->bounds, b, 1);
+      b->lo = link_address + s->header.exec_address;
+      b->hi = b->lo + s->header.file_size;
+    }
   }
 
   /* Parse symbols for this file. */
   {
-    elf_symbol_table_t * t;
-    elf64_symbol_t * s;
+    elf_symbol_table_t *t;
+    elf64_symbol_t *s;
 
     elf_parse_symbols (em);
     vec_foreach (t, em->symbol_tables)
+    {
+      vec_foreach (s, t->symbols)
       {
-       vec_foreach (s, t->symbols)
-         {
-           s->value += pointer_to_uword (link_address);
-         }
+       s->value += pointer_to_uword (link_address);
       }
+    }
   }
 
   /* No need to keep section contents around. */
   {
-    elf_section_t * s;
+    elf_section_t *s;
     vec_foreach (s, em->sections)
-      {
-       if (s->header.type != ELF_SECTION_STRING_TABLE)
-         vec_free (s->contents);
-      }
+    {
+      if (s->header.type != ELF_SECTION_STRING_TABLE)
+       vec_free (s->contents);
+    }
   }
 
- done:
+done:
   if (error)
     elf_main_free (em);
   if (fd >= 0)
@@ -215,12 +215,12 @@ clib_elf_parse_file (clib_elf_main_t * cem,
 #include <link.h>
 
 static int
-add_section (struct dl_phdr_info * info, size_t size, void * opaque)
+add_section (struct dl_phdr_info *info, size_t size, void *opaque)
 {
-  clib_elf_main_t * cem = opaque;
-  clib_error_t * error;
-  char * name = (char *) info->dlpi_name;
-  void * addr = (void *) info->dlpi_addr;
+  clib_elf_main_t *cem = opaque;
+  clib_error_t *error;
+  char *name = (char *) info->dlpi_name;
+  void *addr = (void *) info->dlpi_addr;
   uword is_main;
 
   is_main = strlen (name) == 0;
@@ -233,11 +233,11 @@ add_section (struct dl_phdr_info * info, size_t size, void * opaque)
        return 0;
 
       name = path_search (cem->exec_path);
-      if (! name)
-        {
-          clib_error ("failed to find %s on PATH", cem->exec_path);
-          return 0;
-        }
+      if (!name)
+       {
+         clib_error ("failed to find %s on PATH", cem->exec_path);
+         return 0;
+       }
       addr = 0;
     }
 
@@ -253,9 +253,10 @@ add_section (struct dl_phdr_info * info, size_t size, void * opaque)
 
 static clib_elf_main_t clib_elf_main;
 
-void clib_elf_main_init (char * exec_path)
+void
+clib_elf_main_init (char *exec_path)
 {
-  clib_elf_main_t * cem = &clib_elf_main;
+  clib_elf_main_t *cem = &clib_elf_main;
 
   cem->exec_path = exec_path;
 
@@ -263,70 +264,76 @@ void clib_elf_main_init (char * exec_path)
 }
 
 clib_elf_section_bounds_t *
-clib_elf_get_section_bounds (char * name)
+clib_elf_get_section_bounds (char *name)
 {
-  clib_elf_main_t * em = &clib_elf_main;
-  uword * p = hash_get (em->section_by_name, name);
+  clib_elf_main_t *em = &clib_elf_main;
+  uword *p = hash_get (em->section_by_name, name);
   return p ? vec_elt_at_index (em->sections, p[0])->bounds : 0;
 }
 
 static uword
-symbol_by_address_or_name (char * by_name,
-                          uword by_address,
-                          clib_elf_symbol_t * s)
+symbol_by_address_or_name (char *by_name,
+                          uword by_address, clib_elf_symbol_t * s)
 {
-  clib_elf_main_t * cem = &clib_elf_main;
-  elf_main_t * em;
+  clib_elf_main_t *cem = &clib_elf_main;
+  elf_main_t *em;
 
   vec_foreach (em, cem->elf_mains)
+  {
+    elf_symbol_table_t *t;
+    s->elf_main_index = em - cem->elf_mains;
+    vec_foreach (t, em->symbol_tables)
     {
-      elf_symbol_table_t * t;
-      s->elf_main_index = em - cem->elf_mains;
-      vec_foreach (t, em->symbol_tables)
+      s->symbol_table_index = t - em->symbol_tables;
+      if (by_name)
        {
-         s->symbol_table_index = t - em->symbol_tables;
-         if (by_name)
-           {
-             uword * p = hash_get (t->symbol_by_name, by_name);
-             if (p)
-               {
-                 s->symbol = vec_elt (t->symbols, p[0]);
-                 return 1;
-               }
-           }
-         else
+         uword *p = hash_get (t->symbol_by_name, by_name);
+         if (p)
            {
-             elf64_symbol_t * x;
-             /* FIXME linear search. */
-             vec_foreach (x, t->symbols)
-               {
-                 if (by_address >= x->value && by_address < x->value + x->size)
-                   {
-                     s->symbol = x[0];
-                     return 1;
-                   }
-               }
+             s->symbol = vec_elt (t->symbols, p[0]);
+             return 1;
            }
        }
+      else
+       {
+         elf64_symbol_t *x;
+         /* FIXME linear search. */
+         vec_foreach (x, t->symbols)
+         {
+           if (by_address >= x->value && by_address < x->value + x->size)
+             {
+               s->symbol = x[0];
+               return 1;
+             }
+         }
+       }
     }
+  }
 
   return 0;
 }
 
-uword clib_elf_symbol_by_name (char * by_name, clib_elf_symbol_t * s)
-{ return symbol_by_address_or_name (by_name, /* by_address */ 0, s); }
+uword
+clib_elf_symbol_by_name (char *by_name, clib_elf_symbol_t * s)
+{
+  return symbol_by_address_or_name (by_name, /* by_address */ 0, s);
+}
 
-uword clib_elf_symbol_by_address (uword by_address, clib_elf_symbol_t * s)
-{ return symbol_by_address_or_name (/* by_name */ 0, by_address, s); }
+uword
+clib_elf_symbol_by_address (uword by_address, clib_elf_symbol_t * s)
+{
+  return symbol_by_address_or_name ( /* by_name */ 0, by_address, s);
+}
 
-u8 * format_clib_elf_symbol (u8 * s, va_list * args)
+u8 *
+format_clib_elf_symbol (u8 * s, va_list * args)
 {
-  clib_elf_main_t * cem = &clib_elf_main;
-  clib_elf_symbol_t * sym = va_arg (*args, clib_elf_symbol_t *);
-  elf_main_t * em;
-  elf_symbol_table_t * t;
+  clib_elf_main_t *cem = &clib_elf_main;
+  clib_elf_symbol_t *sym = va_arg (*args, clib_elf_symbol_t *);
+  elf_main_t *em;
+  elf_symbol_table_t *t;
 
-  if (! sym)
+  if (!sym)
     /* Just print table headings. */
     return format (s, "%U", format_elf_symbol, 0, 0, 0);
 
@@ -338,13 +345,14 @@ u8 * format_clib_elf_symbol (u8 * s, va_list * args)
     }
 }
 
-u8 * format_clib_elf_symbol_with_address (u8 * s, va_list * args)
+u8 *
+format_clib_elf_symbol_with_address (u8 * s, va_list * args)
 {
   uword address = va_arg (*args, uword);
-  clib_elf_main_t * cem = &clib_elf_main;
+  clib_elf_main_t *cem = &clib_elf_main;
   clib_elf_symbol_t sym;
-  elf_main_t * em;
-  elf_symbol_table_t * t;
+  elf_main_t *em;
+  elf_symbol_table_t *t;
 
   if (clib_elf_symbol_by_address (address, &sym))
     {
@@ -359,3 +367,11 @@ u8 * format_clib_elf_symbol_with_address (u8 * s, va_list * args)
 
   return s;
 }
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */