Index: soft/giet_vm/memo/src/memo.cpp
===================================================================
--- soft/giet_vm/memo/src/memo.cpp	(revision 165)
+++ soft/giet_vm/memo/src/memo.cpp	(revision 173)
@@ -51,5 +51,21 @@
     PSeg::setPageSize(pageSize);
 
-    load_bin(m_path);
+    /* loading map_info blob */
+    m_data = std::malloc(bin_size(m_path));
+    if ( !m_data )
+        throw exception::RunTimeError("malloc failed... No memory space");
+
+    m_size = load_bin(m_path, m_data);
+
+    /* checking signature */
+    mapping_header_t*   header = (mapping_header_t*)m_data; 
+    //assert((IN_MAPPING_SIGNATURE == header->signature) and "wrong signature");
+    if((IN_MAPPING_SIGNATURE != header->signature))
+    {
+        std::cout  << "wrong signature " << std::hex <<header->signature << ", should be:"<< IN_MAPPING_SIGNATURE << std::endl;
+        exit(1);
+    }
+    
+    
 
 #ifdef MOVER_DEBUG
@@ -107,32 +123,9 @@
 }
 
-//TODO:delete
-elfpp::section* MeMo::get_sect_by_name(elfpp::object *loader, std::string name)
-{
-#ifdef MOVER_DEBUG
-    std::cout << "get_sect_by_name " << name << std::endl;
-#endif
-    FOREACH( sect, loader->get_section_table() )
-    {
-        assert(&*sect != NULL);
-        elfpp::sh_flags_e eflags = sect->get_flags();
-        if ( !(eflags & elfpp::SHF_ALLOC) )
-            continue;
-
-#ifdef MOVER_DEBUG
-        std::cout << "Trying " << sect->get_name() << std::endl;
-#endif
-        if(!(sect->get_name()).compare(name)) 
-        {
-            return (&*sect);
-        }
-    }
-    return NULL;
-}
 
 void MeMo::buildSoft(const std::string &filename)
 {
     if(!m_ginit)
-        throw soclib::exception::RunTimeError(std::string("Can't get generator! ") );
+        throw exception::RunTimeError(std::string("Can't get generator! ") );
 
     m_generator->write(filename);
@@ -140,30 +133,56 @@
 }
 
+/* Load the content of filename in buffer, and send the size */
+////////////////////////////////////////////////////////
+size_t MeMo::load_bin(std::string filename, void* buffer)
+{
+
+#ifdef MOVER_DEBUG
+    std::cout  << "Trying to load the binary blob from file '" << filename << "'" << std::endl;
+#endif
+
+    std::ifstream input(filename.c_str(), std::ios_base::binary|std::ios_base::in);
+
+    if ( ! input.good() )
+        throw exception::RunTimeError(std::string("Can't open the file: ") + filename);
+
+    input.seekg( 0, std::ifstream::end );
+    size_t size = input.tellg();
+    input.seekg( 0, std::ifstream::beg );
+
+    if ( !buffer )
+        throw exception::RunTimeError("Empty buffer!");
+
+    input.read( (char*)buffer, size );
+
+    input.close();
+
+    return size;
+}
+
+
+/* get the size of the content of the filename */
 //////////////////////////////////////////
-void* MeMo::load_bin(std::string filename)
-{
-    
-#ifdef MOVER_DEBUG
-    std::cout  << "Trying to load the binary blob from file '" << m_path << "'" << std::endl;
-#endif
-
-    std::ifstream input(m_path.c_str(), std::ios_base::binary|std::ios_base::in);
+size_t MeMo::bin_size(std::string filename)
+{
+
+#ifdef MOVER_DEBUG
+    std::cout  << "Trying to get the size of the binary blob '" << filename << "'" << std::endl;
+#endif
+
+    std::ifstream input(filename.c_str(), std::ios_base::binary|std::ios_base::in);
 
     if ( ! input.good() )
-        throw soclib::exception::RunTimeError(std::string("Can't open the file: ") + m_path);
+        throw exception::RunTimeError(std::string("Can't open the file: ") + filename);
 
     input.seekg( 0, std::ifstream::end );
-    m_size = input.tellg();
+    size_t size = input.tellg();
     input.seekg( 0, std::ifstream::beg );
 
-    //m_data = new void*[m_size];
-    m_data = std::malloc(m_size);
-    if ( !m_data )
-        throw soclib::exception::RunTimeError("malloc failed... No memory space");
-
-    input.read( (char*)m_data, m_size );
-    
-    return m_data;
-}
+    input.close();
+
+    return size;
+}
+
 
 /////////////
@@ -171,5 +190,5 @@
 {
     //std::cout << "Deleted MeMo " << *this << std::endl;
-    std::free(m_data);
+    //std::free(m_data);//should be done by the elfpp driver since we passed the pointer
     std::map<std::string, elfpp::object*>::iterator l;
     for(l = m_loaders.begin(); l != m_loaders.end(); l++)
@@ -322,7 +341,7 @@
 
 //////////////////////////////////////////
-void MeMo::vseg_map( mapping_vseg_t* vseg) 
-{
-    mapping_vobj_t*     vobj   = get_vobj_base( (mapping_header_t*) m_data ); 
+void MeMo::vseg_map( mapping_vseg_t* vseg)
+{
+    mapping_vobj_t*     vobj   = get_vobj_base( (mapping_header_t*) m_data );
     PSeg *ps = &(m_psegh.get(vseg->psegid));// get physical segment pointer(PSegHandler::get)
     elfpp::section* sect = NULL;
@@ -343,9 +362,9 @@
     mapping_vobj_t* cur_vobj;
     size_t simple_size = 0; //for debug
-    
+
 #ifdef MOVER_DEBUG
     std::cout << "--------------------vseg_map "<< vseg->name <<"---------------------" << std::endl;
 #endif
-    
+
     for ( size_t vobj_id = vseg->vobj_offset ; vobj_id < (vseg->vobj_offset + vseg->vobjs) ; vobj_id++ )
     {
@@ -353,12 +372,67 @@
 
 #ifdef MOVER_DEBUG
-        std::cout << "current vobj("<< vobj_id <<"): " << cur_vobj->name << " (" <<cur_vobj->vaddr << ")" 
+        std::cout << std::hex << "current vobj("<< vobj_id <<"): " << cur_vobj->name << " (" <<cur_vobj->vaddr << ")"
                         << " size: "<< cur_vobj->length << " type: " <<  cur_vobj->type << std::endl;
 #endif
-
-        if(cur_vobj->type == VOBJ_TYPE_ELF)
-        {
-            if(!first) 
-                throw soclib::exception::RunTimeError(std::string("elf vobj type, must be placed first in a vseg"));
+        if(cur_vobj->type == VOBJ_TYPE_BLOB)
+        {
+            size_t blob_size;
+            std::string filePath(m_pathHandler.getFullPath(std::string(cur_vobj->binpath)));
+
+#ifdef MOVER_DEBUG
+            std::cout << std::hex << "Handling: " << filePath << " ..." << std::endl;
+#endif
+
+            if(!filePath.compare(m_path))    //local blob: map_info
+            {
+#ifdef MOVER_DEBUG
+                std::cout << "Found the vseg of the mapping info" << std::endl;
+#endif
+                blob_size = this->m_size;
+                assert((blob_size >0) and "MAPPING INFO file is empty !?");
+            }
+            else
+            {
+#ifdef MOVER_DEBUG
+                std::cout << "Found an BLOB vseg" << std::endl;
+#endif
+                blob_size = bin_size(filePath);
+            }
+
+
+            /**creating a new section */
+            sect = new elfpp::section(*m_generator, elfpp::SHT_PROGBITS);
+
+            sect->set_name(std::string(cur_vobj->name));
+            sect->set_flags(elfpp::SHF_ALLOC | elfpp::SHF_WRITE);
+            sect->set_size(blob_size);//do the malloc for the get_content fonction
+
+            assert(sect->get_content());//check allocation
+
+            if(!filePath.compare(m_path))    //local blob: map_info
+                //memcpy(sect->get_content(), m_data, sect->get_size());
+                /* this way the modification of the elf size are propageted to the giet */
+                sect->set_content(this->m_data);
+            else
+                load_bin(filePath, sect->get_content());
+
+
+            if(blob_size > cur_vobj->length)
+            {
+                std::cout << std::hex << "!!! Warning, specified blob type vobj ("<<
+                cur_vobj->name  <<") size is "<< cur_vobj->length << ", the actual size is "
+                << blob_size  << " !!!" <<std::endl;
+                assert(0 and "blob vobj length smaller than the actual content" );//???
+            }
+
+            cur_vobj->length = blob_size;//set the true size of this BLOB vobj
+
+            vSO->m_file = filePath;
+            vSO->m_loadable = true;
+        }
+        else if(cur_vobj->type == VOBJ_TYPE_ELF)
+        {
+            if(!first)
+                throw exception::RunTimeError(std::string("elf vobj type, must be placed first in a vseg"));
 
             size_t elf_size;
@@ -366,66 +440,44 @@
 #ifdef MOVER_DEBUG
             std::cout << "Handling: " << filePath << " ..." << std::endl;
-#endif
-            if(!filePath.compare(m_path))    //local blob: map_info
+            std::cout << "Found an ELF vseg" << std::endl;
+#endif
+            if(m_loaders.count(filePath) == 0 )
+                m_loaders[filePath] = new elfpp::object(filePath);
+            elfpp::object* loader = m_loaders[filePath];//TODO:free!?
+
+            sect =  get_sect_by_addr(loader, cur_vaddr);
+            assert(sect and "No section found");
+
+            sect->set_name(std::string(cur_vobj->name));
+
+
+            elf_size = sect->get_size();
+            assert((elf_size > 0) and "ELF section empty ?");
+
+            if(!m_ginit)
             {
-#ifdef MOVER_DEBUG
-                std::cout << "Found the vseg of the mapping info" << std::endl;
-#endif
-                /**creating a new section */
-                sect = new elfpp::section(*m_generator, elfpp::SHT_PROGBITS);
-
-                sect->set_name(std::string(cur_vobj->name));
-                sect->set_flags(elfpp::SHF_ALLOC | elfpp::SHF_WRITE);
-                sect->set_size(this->m_size);
-                sect->set_content(this->m_data);                
-
-                elf_size = this->m_size;       
-                assert((elf_size >0) and "MAPPING INFO file is empty !?");
+                /** Initailising the header of the generator from the first binary,
+                ** we suppose that the header is the same for all the binarys **/
+                m_generator->copy_info(*loader);
+                m_ginit=true;
             }
-            else
-            { 
-#ifdef MOVER_DEBUG
-                std::cout << "Found an ELF vseg" << std::endl;
-#endif
-                if(m_loaders.count(filePath) == 0 )
-                    m_loaders[filePath] = new elfpp::object(filePath);
-                elfpp::object* loader = m_loaders[filePath];//TODO:free!?
-
-                //TODO: delete
-                //sect =  get_sect_by_name(loader, std::string(cur_vobj->name));
-                //assert(( sect->get_vaddr() == cur_vaddr) and "Vaddr doesn't match!");
-
-                sect =  get_sect_by_addr(loader, cur_vaddr);
-                assert(sect and "No section found");
-
-                sect->set_name(std::string(cur_vobj->name));
-
-
-                elf_size = sect->get_size();
-                assert((elf_size >0) and "ELF section empty ?");
-
-                if(!m_ginit)
-                {
-                    /** Initailising the header of the generator from the first binary,
-                    * we suppose that the header is the same for all the binarys
-                    * */
-                    m_generator->copy_info(*loader);
-                    m_ginit=true;
-                }
-            }
 
             if(elf_size > cur_vobj->length)
+            {
                 std::cout << "Warning, specified elf type vobj ("<<
                 cur_vobj->name  <<") size is "<< cur_vobj->length << ", the actual size is "
                 << elf_size  << std::endl;
+                //assert((elf_size < cur_vobj->length) and "elf vobj length smaller than the actual content" );//???
+                assert((0) and "elf vobj length smaller than the actual content" );//???
+            }
 
             cur_vobj->length = elf_size;//set the true size of this ELF vobj
 
             vSO->m_file = filePath;
-            vSO->m_loadable = true;        
-        }
-        first = false;
+            vSO->m_loadable = true;
+        }
 
         //aligning the vobj->paddr if necessary
+        //
         if(cur_vobj->align)
         {
@@ -437,4 +489,5 @@
         cur_paddr += cur_vobj->length;
         simple_size += cur_vobj->length;
+        first = false;
     }
 
@@ -449,5 +502,5 @@
         std::cout << "vseg base "<< std::hex << ps->nextLma()
         <<(ps->nextLma()+simple_size)  <<" size " << std::dec << simple_size <<
-        std::endl; 
+        std::endl;
 
         std::cout << "vseg aligned to: base: " << std::hex << ps->nextLma()
@@ -456,6 +509,6 @@
     }
 #endif
-     
-    vSO->m_ident = vseg->ident;      
+
+    vSO->m_ident = vseg->ident;
 
     //set the lma
@@ -464,5 +517,5 @@
     else
         ps->add( *vSO );
-    
+
     if(!sect)
         return;
@@ -476,5 +529,5 @@
 
 } // end vseg_map()
-
+ 
 
 ///////////////////////////////
