Skip to content
Snippets Groups Projects
Select Git revision
  • wip/smcv/library-cmp
  • master default
  • wip/smcv/longer-fallback-search
  • wip/smcv/config-fallback-search
  • revert-65a6e3e1
  • v0.20240916.0
  • v0.20240806.0
  • v0.20240520.0
  • v0.20230928.0
  • v0.20230802.0
  • v0.20221006.0
  • v0.20220623.0
  • v0.20211026.0
  • v0.20210906.0
  • v0.20210728.0
  • v0.20210114.0
  • v0.20210104.0
  • v0.20201120.0
  • v0.20201022.0
  • v0.20200921.0
  • v0.20200908.0
  • v0.20200708.0
  • v0.20200624.0
  • v0.20190926.0
  • v0.20190724.0
25 results

_int_dlopen.h

Blame
  • _int_dlopen.h 1.73 KiB
    // Copyright © 2017 Collabora Ltd
    //
    // This file is part of libcapsule.
    //
    // libcapsule is free software: you can redistribute it and/or modify
    // it under the terms of the GNU Lesser General Public License as
    // published by the Free Software Foundation; either version 2.1 of the
    // License, or (at your option) any later version.
    //
    // libcapsule is distributed in the hope that it will be useful,
    // but WITHOUT ANY WARRANTY; without even the implied warranty of
    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    // GNU Lesser General Public License for more details.
    //
    // You should have received a copy of the GNU Lesser General Public
    // License along with libcapsule.  If not, see <http://www.gnu.org/licenses/>.
    
    // Standard implementation of _int_dlopen(), the implementation used
    // when a library inside the capsule calls dlopen(). To override this
    // implementation, copy this file to shim/capsule/_int_dlopen.h in
    // your shim library and modify as needed.
    static void *
    _int_dlopen (const char *filename, int flag)
    {
        if( flag & RTLD_GLOBAL )
        {
            fprintf( stderr, "Warning: libcapsule dlopen wrapper cannot pass "
                             "RTLD_GLOBAL to underlying dlmopen(%s...) call\n",
                     filename );
            flag = (flag & ~RTLD_GLOBAL) & 0xfffff;
        }
        return capsule_shim_dlopen( cap, filename, flag );
    }
    
    // if the libc instances aren't unified (ie > 1 libc) then
    // we must try to dispatch the to-be-freed pointer to the one
    // that actually allocated it.
    // This is far from foolproof:
    static void
    _wrapped_free (void *ptr)
    {
        if (ptr)
            capsule_shim_free( cap, ptr );
    }
    
    static void *
    _wrapped_realloc (void *ptr, size_t size)
    {
        return capsule_shim_realloc( cap, ptr, size );
    }