Boost logo

Boost :

From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2007-07-16 14:44:37


Wilbur Lang wrote:
> Hi,
>
> Oh.....my dirty solution is wrong too....

The solution might be this:

    m_base = mmap ( (void*)address
                     , static_cast<std::size_t>(m_extra_offset + m_size)
                     , prot
                     , flags
                     , mapping.get_mapping_handle()
                     , offset - m_extra_offset);

    //Check if mapping was successful
    if(m_base == MAP_FAILED){
       error_info err = system_error_code();
       this->priv_close();
       throw interprocess_exception(err);
    }

    //Calculate new base for the user
    void *old_base = m_base;
    m_base = static_cast<char*>(m_base) + m_extra_offset;
    m_offset = offset;
    m_size = size;

    //Check for fixed mapping error
    if(address && (old_base != (void*)address)){
       error_info err = system_error_code();
       this->priv_close();
       throw interprocess_exception(err);
    }

The mapping address is cached and tested when the object is in a stable
state, so that priv_close() can properly clean all the resources.

Regards,

Ion


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk