Affix

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN


```perl
my $errno;
pin( $errno, 'libc', 'errno', Int );
print $errno;
$errno = 0;
```

Variables exported by a library - also names "global" or "extern" variables -
can be accessed using `pin( ... )`. The above example code applies magic to
`$error` that binds it to the integer variable named "errno" as exported by
the [libc](https://metacpan.org/pod/libc) library.

Expected parameters include:

- `$var`

    Perl scalar that will be bound to the exported variable.

- `$lib`

builder/Affix.pm  view on Meta::CPAN

        my %opt = @_;
        die "Must run `./Build build` first\n" if not -d 'blib';
        require TAP::Harness::Env;
        my %test_args = (
            ( verbosity => $opt{verbose} ) x !!exists $opt{verbose},
            ( jobs  => $opt{jobs} ) x !!exists $opt{jobs},
            ( color => 1 ) x !!-t STDOUT,
            lib => [ map { rel2abs( catdir( qw/blib/, $_ ) ) } qw/arch lib/ ],
        );
        my $tester = TAP::Harness::Env->create( \%test_args );
        return $tester->runtests( sort +find( qr/\.t$/, 't' ) )->has_errors;
    },
    install => sub {
        my %opt = @_;
        die "Must run `./Build build` first\n" if not -d 'blib';
        install( $opt{install_paths}->install_map, @opt{qw/verbose dry_run uninst/} );
        return 0;
    },
    clean => sub {
        my %opt = @_;
        rmtree( $_, $opt{verbose} ) for qw/blib temp/;

builder/Affix.pm  view on Meta::CPAN

    write_file( '_build_params', encode_json( [ \@env, \@ARGV ] ) );
    $meta->save(@$_) for ['MYMETA.json'], [ 'MYMETA.yml' => { version => 1.4 } ];
}

sub unzip {
    my ( $file, $dest ) = @_;
    my $retval;
    my $u = IO::Uncompress::Unzip->new($file) or die "Cannot open $file: $UnzipError";
    my %dirs;
    for ( my $status = 1; $status > 0; $status = $u->nextStream() ) {
        last if $status < 0;    # bail on error
        my $header = $u->getHeaderInfo();

        #ddx $header;
        my $destfile = $dest->child( $header->{Name} );
        next if $header->{Name} =~ m[/$];    # Directory
        next if $destfile->is_dir;
        next
            if $destfile->is_file &&
            stat( $destfile->absolute->stringify )->mtime < $header->{Time};
        warn $destfile;

dyncall/CMakeLists.txt  view on Meta::CPAN

# currently we have no use for this, but maybe later..
#set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/buildsys/cmake/Modules" "${CMAKE_MODULE_PATH}")

option(LANG_CXX "Enable and build C++ tests" ON)

if(LANG_CXX)
  enable_language(CXX)
endif()

include(CheckCCompilerFlag)
check_c_compiler_flag("-fPIC -Werror" COMPILER_HAS_FPIC)


add_custom_target(show-compiler-predefs COMMAND ${CMAKE_C_COMPILER_PREDEFINES_COMMAND})


# compile_asm(TARGET target ASM_FILES file1 [file2 ...] OUTPUT_OBJECTS [variableName])
# CMake does not support the ARM or ARM64 assemblers on Windows when using the
# MSBuild generator.
# credit to dotnet/runtime:
#    https://github.com/dotnet/runtime/blob/e98fb61d8b4bb6687ccddead861d8b140751647b/eng/native/functions.cmake#L173-L207

dyncall/ChangeLog  view on Meta::CPAN

Version 1.1 (2020/01/11)

dyncall:
  o support for soft-float MIPS o32 & n64 (big- and little-endian, each)
  o x64 System V syscall support
dyncallback:
  o support for soft-float MIPS o32 & n64 (big- and little-endian, each)
dynload:
  o added UTF-8 support for pathnames on windows
  o reliability/stability fix for dlGetLibraryPath() on glibc based platforms (avoiding
    internal use of glibc's bad impl of dlinfo() which doesn't do any error checking at all)
  o Darwin/macos fix for dlGetLibraryPath() to correctly fail on bogus handles (did return
    paths to random libraries under some circumstances, instead of returning an error)
  o support for dlGetLibraryPath() on glibc platforms with glibc vesions <= 2.3.3
  o dlGetLibraryPath() now accepts NULL as argument to return path to executable
  o dlLoadLibrary() on windows: no more auto-suffixing of the .dll file ext anymore, to be
    more in line with other platforms (not affecting OS specific library search behaviour)
doc:
  o more detail in support matrix for bi-endian platforms
  o improvements/corrections to calling convention appendix
  o PPC64 calling convention description
  o MIPS64/N32 calling convention description
  o man page additions for clarity

dyncall/ChangeLog  view on Meta::CPAN

buildsys:
  o default ./configure: FreeBSD/mips*hf needed -mhard-float compiler flag set explicitly
  o better MacOS Mojave support in ./configure (Mojave dropped i386 builds)


Version 1.0 (2018/04/23)

dyncall:
  o PPC64 single-precision float fixes for more than 13 float args (thanks Masanori Mitsugi!)
  o fixed potential buffer overrun on ARM64
  o error code handling (dcGetError) changes, flag is now cleared (work still underway)
  o MIPS n64 ellipsis call fixes
  o ARM32 armhf ellipsis call fixes
  o fixed ARM32-THUMB stack alignment issues (found on Cortex-m0, thanks Darren Whobrey!)
  o better C++ compiler support (for pointer conversions)
dyncallback:
  o PPC64 single-precision float fixes for more than 13 float args (thanks Masanori Mitsugi!)
  o MIPS o32 (big- and little-endian), EABI (32 bit, little-endian) and n64 (big-endian) support
  o SPARC32 (v7/v8) support
  o SPARC64 (v9) support
  o PPC32 fixes for (old) Darwin/OS X systems

dyncall/ChangeLog  view on Meta::CPAN

Version 0.9 (2015/12/31)

dyncall:
  o ARM64 support (AAPCS64 on Linux & Apple's derived version on iOS)
  o armhf calling convention support for ARM32
  o PPC64 support, including syscalls (thanks Masanori Mitsugi!)
  o introduced dcArgF and dcVArgF for flexible/convenient argument binding (works like
    dcCallF/dcVCallF but without the function call)
  o using -fPIC by default for FreeBSD
  o PPC32 linux syscall support
  o fixed return value errors for ARM32 on some platforms (e.g. freebsd/arm32, nintendo ds); arm & thumb mode
dyncallback:
  o ARM64 support (AAPCS64 on Linux, Apple's derived version on iOS)
  o armhf calling convention support for ARM32
  o PPC64 support (thanks Masanori Mitsugi!)
  o PPC32 System V support (Linux)
  o fix for PPC32 Darwin/OS X
  o more intuitive specification of callback return type
doc:
  o added ARM64 support info and calling convention documentation
  o added ARM32 armhf section

dyncall/ChangeLog  view on Meta::CPAN

  o buildsys/gmake tool chain update: pcc and iphone sdk
  o x64 bugfix: added "-fPIC" even for static libs
dynload:
  o enum symbols update: Mach-O and Win64 (thanks Olivier)
  o numerous convenience changes to dynload interface (thanks Olivier)
  o added support for resolving application images itself
dyncall:
  o new platform support: arm/iphone (armv6), x86/Plan9
  o new MIPS calling conventions: o32, n64 (both endian models)
  o cleanup: unexported functions in MASM files, b/c export not needed (thanks Olivier)
  o interface update: added error reporting facility 'dcGetError'
  o bugfix for ppc32/sysv: ellipsis calls were broken
  o interface update: added new abstract mode for ellipsis calls (DC_CALL_C_ELLIPSIS)
docs:
  o comprehensive update
tests:
  o plain: split "plain" test up in C and C++ part
  o callbacksuite: added multiple configuration support for callback_suite


Version 0.5 (2010/02/01)

dyncall/ToDo  view on Meta::CPAN

- dlGetLibraryPath: dl_iterate_phdr() used on OpenBSD, but not available on version < 3.7
- bug: test/nm crashes on qemu mips linux o32 debian etch
- rename SymsInit to InitSyms and similar for cleanup function to reflect naming
  in dyncall
- get rid of Dl_info and friends (_GNU_SOURCE) in dynload/dynload_syms_elf.c
  for implementation of dlSymsNameFromValue(..)
- check if PSP can support dynload (missing elf.h, dlfcn.h, etc.); fixup readme if successful
- some functionality like java's System.mapLibraryName('name') might be helpful?
- Failed On Open Solaris 11:
    In file included from dynload_syms.c:28:
    dynload_syms_elf.c:56: error: syntax error before "Elf_Dyn"
    dynload_syms_elf.c:56: warning: data definition has no type or storage class
    dynload_syms_elf.c: In function `dlSymsInit':
    dynload_syms_elf.c:155: error: `pDyn' undeclared (first use in this function)
    dynload_syms_elf.c:155: error: (Each undeclared identifier is reported only once
    dynload_syms_elf.c:155: error: for each function it appears in.)
    dynload_syms_elf.c:155: error: syntax error before ')' token
    dynload_syms_elf.c:160: error: `DT_NULL' undeclared (first use in this function)
    dynload_syms_elf.c:163: error: `DT_STRTAB' undeclared (first use in this function)
    dynload_syms_elf.c:164: error: `DT_SYMTAB' undeclared (first use in this function)
    dynload_syms_elf.c:165: error: `DT_HASH' undeclared (first use in this function)
    make: *** [dynload_syms.o] Error 1

dyncallback:
------------
- callback_plain's return value not correct anymore on NDS (maybe just broken testcode?),
  see above under 1.1 items
  * check other platforms also, if asm stub initializes retval space, correctly
- test MIPS32 eabi big endian (current port works on psp, which is little endian)
- implement MIPS64 N32 (gcc -mabi=n32); both, little and big-endian (looks like NetNBSD on and
  EdgeRouter lite uses this: https://blog.netbsd.org/tnf/entry/hands_on_experience_with_edgerouter)

dyncall/buildsys/cmake/Modules/UseLATEX.cmake  view on Meta::CPAN

#       The following targets are made:
#               dvi: Makes <name>.dvi
#               pdf: Makes <name>.pdf using pdflatex.
#               safepdf: Makes <name>.pdf using ps2pdf.  If using the default
#                       program arguments, this will ensure all fonts are
#                       embedded and no lossy compression has been performed
#                       on images.
#               ps: Makes <name>.ps
#               html: Makes <name>.html
#               auxclean: Deletes <name>.aux.  This is sometimes necessary
#                       if a LaTeX error occurs and writes a bad aux file.
#
#       The dvi target is added to the ALL.  That is, it will be the target
#       built by default.  If the DEFAULT_PDF argument is given, then the
#       pdf target will be the default instead of dvi.
#
#       If the argument MANGLE_TARGET_NAMES is given, then each of the
#       target names above will be mangled with the <tex_file> name.  This
#       is to make the targets unique if ADD_LATEX_DOCUMENT is called for
#       multiple documents.  If the argument USE_INDEX is given, then
#       commands to build an index are made.  If the argument USE_GLOSSARY

dyncall/configure  view on Meta::CPAN

      ;;
# Environment variables:
    [A-Za-z_]*=*)
      printf "${X}\n" >>$C
      k=`printf "${X}" | cut -d = -f 1`
      v=`printf "${X}" | cut -d = -f 2`
      export $k="$v"
      ;;
# Others fail:
    *)
      printf "error: invalid option ${X}\n" >&2
      exit 1
      ;;
  esac
done

printf "PREFIX=${PREFIX:=/usr/local}\n" >>$C

case ${TARGET:=`uname`} in
  Linux|GNU/kFreeBSD)
    if [ -z "${CFLAGS}" ]; then

dyncall/configure.rc  view on Meta::CPAN

# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
#//////////////////////////////////////////////////////////////////////////////

# --- configure settings ------------------------------------------------------

PACKAGE=dyncall


# --- message helpers ----------------------------------------------------
fn error {
  echo error: $*
  exit 1
}
fn warning {
  echo warning: $*
}
fn info {
  echo $*
}


dyncall/configure.rc  view on Meta::CPAN

CONFIG_ASM=()
fn guess_asm {
  CONFIG_ASM=`{grep AS /$objtype/mkfile | sed s/AS.//}
  info 'guess assembler '$CONFIG_ASM
}

fn guess {
  if(~ $#CONFIG_OS 0) {
    guess_os
    if(~ $#CONFIG_OS 0) {
      error 'unsupported operating system '$OS
    }
  }

  if(~ $#CONFIG_ARCH 0) {
    guess_arch 
    if(~ $#CONFIG_ARCH 0) {
      error 'unsupported architecture '$ARCH
    }
  }

  if(~ $#CONFIG_TOOL 0) {
    guess_tool
    if(~ $#CONFIG_TOOL 0) {
      error 'no tool'
    }
  }

  if(~ $#CONFIG_ASM 0) {
    guess_asm
    if(~ $#CONFIG_ASM 0) {
      error 'no assembler tool'
    }
  }
}


# --- process arguments ------------------------------------------------------

fn args {
  while(! ~ $#* 0 && ~ $1 -*) {
    OPT=$1

dyncall/doc/manual/callconvs/callconv_ppc32.tex  view on Meta::CPAN

\subsubsection{System V syscalls}

\paragraph{Parameter passing}

\begin{itemize}
\item syscall is issued via the {\em sc} instruction
\item kernel destroys registers r13
\item syscall number is set in r0
\item params are passed in registers r3 through r10
\item no stack in use, meaning syscalls are in theory limited to eight arguments
\item register r3 holds the return value, overflow flag in conditional register cr0 signals errors in syscall
\end{itemize}

dyncall/doc/manual/callconvs/callconv_ppc64.tex  view on Meta::CPAN

\subsubsection{System V syscalls}

\paragraph{Parameter passing}

\begin{itemize}
\item syscall is issued via the {\em sc} instruction
\item kernel destroys registers r13
\item syscall number is set in r0
\item params are passed in registers r3 through r10
\item no stack in use, meaning syscalls are in theory limited to eight arguments
\item register r3 holds the return value, overflow flag in conditional register cr0 signals errors in syscall
\end{itemize}

dyncall/doc/manual/callconvs/callconv_x64.tex  view on Meta::CPAN

\subsubsection{System V syscalls}

\paragraph{Parameter passing}

\begin{itemize}
\item syscall is issued via the {\em syscall} instruction
\item kernel destroys registers rcx and r11
\item syscall number is set in rax
\item params are passed in the following registers in this order: rdi, rsi, rdx, rcx, r8, r9
\item no stack in use, meaning syscalls are in theory limited to six arguments
\item register rax holds the return value (values in between -4095 and -1 indicate errors)
\end{itemize}

dyncall/doc/manual/manual_dyncall_api.tex  view on Meta::CPAN

%
%
%\subsection{Error Reporting}
%
%\paragraph{Function}
%
%\begin{lstlisting}[language=c]
%DCint dcGetError(DCCallVM* vm);
%\end{lstlisting}
%
%Returns the most recent error state code out of the following:
%
%\paragraph{Errors}
%
%\begin{table}[h]
%\begin{center}
%\begin{tabular*}{0.95\textwidth}{ll}
%Constant & Description\\
%\hline
%\lstinline@DC_ERROR_NONE@             & No error occured. \\
%\lstinline@DC_ERROR_UNSUPPORTED_MODE@ & Unsupported mode, caused by \lstinline@dcMode()@ \\
%\end{tabular*}
%\caption{CallVM calling convention modes}
%\label{errorcodes}
%\end{center}
%\end{table}
%
%\pagebreak
%
%\subsection{Configuration}
%
%\paragraph{Function}
%
%\begin{lstlisting}[language=c]

dyncall/doc/manual/manual_dynload_api.tex  view on Meta::CPAN

%\begin{lstlisting}[language=c,label=dl-load]
%DLLib* dlLoadLibrary(const char* libpath);
%void  dlFreeLibrary(void* libhandle);
%\end{lstlisting}
%
%\lstinline{dlLoadLibrary} loads a dynamic library at \lstinline{libpath}
%and returns a handle to it for use in \lstinline{dlFreeLibrary} and
%\lstinline{dlFindSymbol} calls. Passing a null pointer for the \lstinline{libpath}
%argument is valid, and returns a handle to the main executable of the calling code.
%Also, searching libraries in library paths (e.g. by just passing the library's leaf
%name) should work, however, they are OS specific. Returns a null pointer on error.
%
%\lstinline{dlFreeLibrary} frees the loaded library with handle \lstinline{pLib}.
%
%\subsection{Retrieving functions}
%
%\begin{lstlisting}[language=c]
%void* dlFindSymbol(void* libhandle, const char* symbol);
%\end{lstlisting}
%
%This function returns a pointer to a symbol with name \lstinline{pSymbolName} in the

dyncall/doc/manual/manual_dynload_api.tex  view on Meta::CPAN

%void        dlSymsCleanup(DLSyms* pSyms);
%int         dlSymsCount(DLSyms* pSyms);
%const char* dlSymsName(DLSyms* pSyms, int index);
%const char* dlSymsNameFromValue(DLSyms* pSyms, void* value); /* symbol must be loaded */
%\end{lstlisting}
%
%
%These functions can be used to iterate over symbols. Since they can be used on libraries that are not linked, they are made
%for symbol name lookups, not to get a symbol's address. For that refer to
%\lstinline{dlFindSymbol}. \lstinline{dlSymsInit} will return a handle (or a null pointer
%on error) to the shared object specified by \lstinline{libPath}, to be used with the other dlSyms* functions. Note that contrary
%to loading and linking libraries, no (OS-specific) rules for searching libraries in library paths, etc. apply. The handle must be freed with
%\lstinline{dlSymsCleanup}. \lstinline{dlSymsCount} returns the number of
%symbols in the shared object, \lstinline{dlSymsName} and \lstinline{dlSymsNameFromValue}
%are used to lookup symbol names using an index or symbol's address, respectively,
%returning a null pointer on error. The names are returned as they would appear
%in C source code (mangled if C++, etc.). The address passed to \lstinline{dlSymsNameFromValue}
%must point to a loaded symbol.
%

dyncall/dyncall/dyncall.3  view on Meta::CPAN

.Pp
Call
.Fn dcCloseAggr
after having described all fields of an aggregate.
.Pp
Note that c99 flexible array members do not count as a field, and must be
omitted, as passing aggregates with a flexible array member by value in C would
also omit it.
.Sh EXAMPLES
.Em Note :
none of the examples below perform any error checking for simplicity of
the example.
.Pp
Let's start with a simple example, making a call to the function
.Xr sqrt 3 .
Using the
.Nm
library, this function would be called as follows: 
.Bd -literal -offset indent
double r;
DCCallVM* vm = dcNewCallVM(4096);

dyncall/dyncall/dyncall_call.S  view on Meta::CPAN

*/


#include "dyncall_macros.h"

/* Plan9 */
#if defined(DC__OS_Plan9)
#  if defined(DC__Arch_Intel_x86)
#    include "dyncall_call_x86_8a.s"
#  else
#    error Unsupported Architecture on Plan9.
#  endif
#elif defined(DC__C_MSVC)
#  if defined(DC__OS_Win32)
#    include "dyncall_call_x86_generic_masm.asm"
#  elif defined(DC__OS_Win64)
#    include "dyncall_call_x64_generic_masm.asm"
#  endif
#else
#  if defined(DC__Arch_Intel_x86)
#    include "dyncall_call_x86.S"

dyncall/dyncall/dyncall_call.S  view on Meta::CPAN

#    elif defined(DC__ABI_MIPS_N32)
#      include "dyncall_call_mips_n32.S"
#    else
#      include "dyncall_call_mips_eabi_gas.s"
#    endif
#  elif defined(DC__Arch_Sparc64)
#    include "dyncall_call_sparc64.s"
#  elif defined(DC__Arch_Sparc)
#    include "dyncall_call_sparc.s"
#  else
#    error Unsupported Architecture.
#  endif
#endif


/* Use .note.GNU-stack to explicitly indicate a non-exec stack, b/c of bad   */
/* default behaviour when translating handwritten assembly files (needed on  */
/* GNU platforms, Android and FreeBSD, as tests have shown).                 */
#if (defined(DC__C_CLANG) || defined(DC__C_GNU)) && defined(__ELF__) && (defined(DC__OS_Linux) || defined(DC__OS_FreeBSD))
.section .note.GNU-stack,"",%progbits
#endif

dyncall/dyncall/dyncall_callvm.c  view on Meta::CPAN

#elif defined(DC__Arch_MIPS) || defined(DC__Arch_MIPS64)
#  if defined(DC__ABI_MIPS_EABI)
#    include "dyncall_callvm_mips_eabi.c"
#  elif defined(DC__ABI_MIPS_O32)
#    include "dyncall_callvm_mips_o32.c"
#  elif defined(DC__ABI_MIPS_N64)
#    include "dyncall_callvm_mips_n64.c"
#  elif defined(DC__ABI_MIPS_N32)
#    include "dyncall_callvm_mips_n32.c"
#  else
#    error Unknown MIPS ABI.
#  endif /* DC__Arch_MIPS || DC__Arch_MIPS64 */
#elif defined(DC__Arch_ARM_ARM)
#  if defined(DC__ABI_ARM_HF)
#    include "dyncall_callvm_arm32_arm_armhf.c"
#  else
#    include "dyncall_callvm_arm32_arm.c"
#  endif
#elif defined(DC__Arch_ARM_THUMB)
#  if defined(DC__ABI_ARM_HF)
#    include "dyncall_callvm_arm32_arm_armhf.c"

dyncall/dyncall/dyncall_callvm.c  view on Meta::CPAN

#  else
#    include "dyncall_callvm_arm64.c"
#  endif
#elif defined(DC__Arch_Sparc)
#  include "dyncall_callvm_sparc.c"
#elif defined(DC__Arch_Sparc64)
#  include "dyncall_callvm_sparc64.c"
#elif defined(DC__Arch_RiscV)
#  include "dyncall_callvm_riscv.c"
#else
#  error unsupported platform
#endif

dyncall/dyncall/dyncall_callvm_ppc32.c  view on Meta::CPAN

/* Support for Mac OS X (Darwin) and Systen V ABI for Power PC 32-bit */


#if defined(DC_UNIX)
#  if defined(DC__OS_Darwin)
#    define DC__ABI_Darwin
#  else
#    define DC__ABI_SysV
#  endif
#else
#  error Unsupported OS for ppc32 architecture.
#endif

static void dc_callvm_free_ppc32(DCCallVM* in_self)
{
  dcFreeMem(in_self);
}

static void dc_callvm_reset_ppc32(DCCallVM* in_self)
{
  DCCallVM_ppc32* self = (DCCallVM_ppc32*)in_self;

dyncall/dyncall/dyncall_callvm_sparc.h  view on Meta::CPAN

#define DYNCALL_CALLVM_SPARC_H

#include "dyncall_callvm.h"
#include "dyncall_vector.h"

/* NOTE: if something changes here, update offset marks in dyncall_call_sparc.S */

typedef struct DCCallVM_sparc_ DCCallVM_sparc;
struct DCCallVM_sparc_
{
  DCCallVM  mInterface;	/* 8 bytes (vtable,errorid) */
  DCVecHead mVecHead;	/* 8 bytes (max,size)       */
};

#endif /* DYNCALL_CALLVM_SPARC_H */

dyncall/dyncall/dyncall_callvm_x64.h  view on Meta::CPAN


typedef long int64;		/* lp64 */

#define numIntRegs   6
#define numFloatRegs 8
#define DCRegCount_x64 DCRegCount_x64_s
#define DCRegData_x64  DCRegData_x64_s

#else

#error Unsupported OS.

#endif

typedef union
{
  int i;
  int f;
} DCRegCount_x64_u;

typedef struct

dyncall/dyncall/dyncall_vector.c  view on Meta::CPAN

      case 8: *(DCint     *)( ( (char*)dst )+4) = *(const DCint     *)( ( (char*)pData )+4); 
              *(DCint     *)dst = *(const DCint     *)pData; break;
      /* On sparc 32-bit, this one crashes if ptrs are not aligned, so use above.
      case 8: *(DClonglong*)dst = *(const DClonglong*)pData; break;
      */

      default: memcpy(dst, pData, size); /* for all the rest. */
    }
    pHead->mSize = newSize;
  }
  /*else @@@ warning? error?*/
}

dyncall/dyncallback/dyncall_alloc_wx.h  view on Meta::CPAN

   OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

*/


#ifndef DYNCALL_ALLOC_WX_HPP
#define DYNCALL_ALLOC_WX_HPP

#include "dyncall_types.h"

typedef int DCerror;

#ifdef __cplusplus
extern "C" {
#endif

/* returns 0 on success */
DCerror dcAllocWX   (DCsize size, void** p);
DCerror dcInitExecWX(void* p, DCsize size);
void    dcFreeWX    (void* p, DCsize size);

#ifdef __cplusplus
}
#endif


#endif /* DYNCALL_ALLOC_WX_HPP */

dyncall/dyncallback/dyncall_alloc_wx_malloc.c  view on Meta::CPAN

   OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

*/


#include "dyncall_alloc_wx.h"

#include <stdlib.h>


DCerror dcAllocWX(size_t size, void** pp)
{
  *pp = malloc(size);
  return 0;
}

DCerror dcInitExecWX(void* p, size_t size)
{
  return 0;
}

void dcFreeWX(void* p, size_t size)
{
  free(p);
}

dyncall/dyncallback/dyncall_alloc_wx_mmap.c  view on Meta::CPAN

#include <sys/types.h>
#include <sys/mman.h>

/* MAP_ANON is not POSIX, if lacking, we'll use a portable fallback on *nix systems */
#if !defined(MAP_ANON)
#  if defined(MAP_ANONYMOUS)
#    define MAP_ANON MAP_ANONYMOUS
#  elif defined(DC_UNIX)
#    include <fcntl.h>
#  else
#    error "Platform implementation missing for anonymous rwx memory"
#  endif
#endif

/* platforms without mprotect */
#if defined(DC__OS_Minix)
#  define NO_MPROTECT
#endif

/* if no mprotect() available/wanted, make mmap alloc pages as rwx */
#if defined(NO_MPROTECT)
#  define MMAP_PROT_INIT (PROT_READ|PROT_WRITE|PROT_EXEC)
#else
#  define MMAP_PROT_INIT (PROT_READ|PROT_WRITE)
#endif

DCerror dcAllocWX(size_t size, void** pp)
{
  void* p;
#if !defined(MAP_ANON) && defined(DC_UNIX)
  /* Hack around not having POSIX' MAP_ANON by going through /dev/zero; store
     file descr to close on dcFreeWX at beginning of memory, as tiny hack */
  int fd = open("/dev/zero", O_RDWR);
  if(fd == -1)
    return -1;
  p = mmap(0, size+sizeof(int), MMAP_PROT_INIT, MAP_PRIVATE, fd, 0);
  if(p == MAP_FAILED) {

dyncall/dyncallback/dyncall_alloc_wx_mmap.c  view on Meta::CPAN

#else
  p = mmap(0, size, MMAP_PROT_INIT, MAP_PRIVATE|MAP_ANON, -1, 0);
  if(p == MAP_FAILED)
    return -1;
#endif

  *pp = p;
  return 0;
}

DCerror dcInitExecWX(void* p, size_t size)
{
#if defined(NO_MPROTECT)
  return 0;
#else

#if !defined(MAP_ANON) && defined(DC_UNIX)
  /* Fixup pointer for no-MAP_ANON workaround (see above) */
  p -= sizeof(int);
  size += sizeof(int);
#endif

dyncall/dyncallback/dyncall_alloc_wx_win32.c  view on Meta::CPAN

   ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
   OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

*/


#include "dyncall_alloc_wx.h"
#include <windows.h>
#include <assert.h>

DCerror dcAllocWX(size_t size, void** ptr)
{
  LPVOID p = VirtualAlloc(0, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
  if (p == NULL) return -1;
  *ptr = p;
  return 0;
}

DCerror dcInitExecWX(void* p, size_t size)
{
  return 0;
}

void dcFreeWX(void* p, size_t size)
{
  BOOL b = VirtualFree( p, 0, MEM_RELEASE);
  assert(b);
}

dyncall/dyncallback/dyncall_callback.c  view on Meta::CPAN

#include "dyncall_callback_arm32.c"
#elif defined(DC__Arch_MIPS) || defined(DC__Arch_MIPS64)
#include "dyncall_callback_mips.c"
#elif defined(DC__Arch_Sparc)
#include "dyncall_callback_sparc32.c"
#elif defined(DC__Arch_Sparc64)
#include "dyncall_callback_sparc64.c"
#elif defined(DC__Arch_ARM64)
#include "dyncall_callback_arm64.c"
#else
#error unsupported platform
#endif


void dcbInitCallback(DCCallback* pcb, const DCsigchar* signature, DCCallbackHandler* handler, void* userdata)
{
  dcbInitCallback2(pcb, signature, handler, userdata, NULL);
}


DCCallback* dcbNewCallback(const DCsigchar* signature, DCCallbackHandler* handler, void* userdata)

dyncall/dyncallback/dyncall_callback_arch.S  view on Meta::CPAN

#if defined(DC__C_MSVC)
#  if defined(DC__OS_Win32)
#    include "dyncall_callback_x86_masm.asm"
#  elif defined(DC__OS_Win64)
#    include "dyncall_callback_x64_masm.asm"
#  endif
#elif defined(DC__OS_Plan9)
#  if defined(DC__Arch_Intel_x86)
#    include "dyncall_callback_x86_8a.s"
#  else
#    error Unsupported Architecture on Plan9.
#  endif
#elif defined(DC__OS_Darwin)
#  if defined(DC__Arch_PPC32)
#    include "dyncall_callback_ppc32_apple.s"
#  elif defined(DC__Arch_ARM_ARM)
#    include "dyncall_callback_arm32_arm_apple.s"
#  elif defined(DC__Arch_ARM_THUMB)
#    include "dyncall_callback_arm32_thumb_apple.S"
#  elif defined(DC__Arch_AMD64)
#    include "dyncall_callback_x64.S"
#  elif defined(DC__Arch_Intel_x86)
#    include "dyncall_callback_x86.S"
#  elif defined(DC__Arch_ARM64)
#    include "dyncall_callback_arm64.S"
#  else /* e.g. PowerPC G5, which is PPC64, etc. */
#    error Unsupported Architecture on Darwin/OS X.
#  endif
#else 
#  if defined(DC__Arch_Intel_x86)
#    include "dyncall_callback_x86.S"
#  elif defined(DC__Arch_AMD64)
#    include "dyncall_callback_x64.S"
#  elif defined(DC__Arch_PPC32)
#    include "dyncall_callback_ppc32.S"
#  elif defined(DC__Arch_PPC64)
#    include "dyncall_callback_ppc64.S"
#  elif defined(DC__Arch_MIPS) || defined(DC__Arch_MIPS64)
#    if defined(DC__ABI_MIPS_O32)
#      include "dyncall_callback_mips_o32.S"
#    elif defined(DC__ABI_MIPS_N64)
#      include "dyncall_callback_mips_n64.S"
#    elif defined(DC__ABI_MIPS_N32)
#      include "dyncall_callback_mips_n32.S"
#    elif defined(DC__ABI_MIPS_EABI)
#      include "dyncall_callback_mips_eabi_gas.s"
#    else
#      error Unknown MIPS ABI.
#    endif
#  elif defined(DC__Arch_ARM_ARM)
#    include "dyncall_callback_arm32_arm_gas.S"
#  elif defined(DC__Arch_ARM_THUMB)
#    include "dyncall_callback_arm32_thumb_gas.S"
#  elif defined(DC__Arch_Sparc)
#    include "dyncall_callback_sparc32.s"
#  elif defined(DC__Arch_Sparc64)
#    include "dyncall_callback_sparc64.s"
#  elif defined(DC__Arch_ARM64)

dyncall/dyncallback/dyncall_callback_x86_8a.s  view on Meta::CPAN

	FMOVD (BX), F0
	JMP   cont_ret

other_ret:
	MOVL (BX), AX      /* 32bit non-fp are returned in AX */

	/* epilog */
cont_ret:
	ADDL $44, SP       /* Cleanup stack */
	POPL CX            /* hack to emulate RET without getting overly strict */
	JMP CX             /* 'unbalanced PUSH/POP' warning/error from 8l */

dyncall/dyncallback/dyncallback.3  view on Meta::CPAN

.Fn dcbReturnAggr ,
pass NULL for
.Ar ret ,
which will make
.Ar result->p
point to (implicit, caller-provided) memory where the aggregate should be
copied to.

.Sh EXAMPLES
.Em Note :
for simplicity, none of the examples below do any error checking. Also, none of
them pass the callback object pointer as an argument to a function doing the
respective callback (e.g.
.Ar compar
in
.Xr qsort 3 ,
etc.), but demonstrate calling it, directly, for clarity.
.Pp
Let's say, we want to create a callback object and call it. First, we need to
define our callback handler - the following handler illustrates how to access
the passed-in arguments, optional userdata, and how to return values:

dyncall/dynload/dynload.3  view on Meta::CPAN

loads a dynamic library at
.Ar libpath
and returns a handle to it for use in
.Fn dlFreeLibrary 
and
.Fn dlFindSymbol
calls. Passing a null pointer for the
.Ar libpath
argument is valid, and returns a handle to the main executable of the calling code. Also, searching libraries in library paths (e.g. by just passing the library's leaf name) should work, however, they are OS specific. The
.Ar libPath
argument is expected to be UTF-8 encoded. Returns a null pointer on error.
.Pp
.Fn dlFreeLibrary 
frees the loaded library with handle
.Ar pLib .
.Pp
.Fn dlFindSymbol
returns a pointer to a symbol with name
.Ar pSymbolName
in the library with handle
.Ar pLib ,

dyncall/dynload/dynload.3  view on Meta::CPAN

>= return value >= 1, a null-terminted string with the path to the library should be in
.Ar sOut .
If it returns 0, the library name wasn't able to be found. Please note that this might happen in some rare cases, so make sure to always check. Passing a null pointer as
.Ar pLib
returns the path to the executable (not guaranteed to be absolute - if it isn't it's relative to the working directory the process was started in, not the current one).
.Pp
The dlSyms* functions can be used to iterate over symbols. Since they can be used on libraries that are not linked, they are made
for symbol name lookups, not to get symbols' addresses. For that refer to
.Fn dlFindSymbol .
.Fn dlSymsInit
will return a handle (or null pointer on error) to the shared object specified by
.Ar libPath ,
to be used with the other dlSyms* functions. Note that contrary to loading and linking libraries, no (OS-specific) rules for searching libraries in library paths, etc. apply. The handle must be freed with
.Fn dlSymsCleanup .
.Fn dlSymsCount
returns the number of symbols in the shared object,
.Fn dlSymsName
and
.Fn dlSymsNameFromValue
are used to lookup symbol names using an index or symbol's address, respectively, returning a null pointer on error. The names are returned as they would appear in C source code (mangled if C++, etc.). The address passed to
.Fn dlSymsNameFromValue
must point to a loaded symbol.
.Sh NOTES
.Fn dlLoadLibrary
does handle loading dylibs on macos >= 11.0.1 that aren't on the file system but are provided through the OS' "built-in dynamic linker cache of all system-provided libraries" (to load, use same "path" as one would with dlopen(3)).
.Sh BUGS
.Fn dlGetLibraryPath
is not thread-safe on Darwin (macOS, iOS, ...) and OpenBSD.
.Pp
.Fn dlSymsInit

dyncall/dynload/dynload.h  view on Meta::CPAN

extern "C" {
#endif

#ifndef DL_API
#define DL_API
#endif


/* shared library loading and explicit symbol resolving */
/* dlLoadLibrary will search for specified lib (e.g. as leaf name, only), */
/* following platforms' dynamic linking style, returns NULL on error */

typedef struct DLLib_ DLLib;

DL_API DLLib* dlLoadLibrary   (const char* libPath);
DL_API void   dlFreeLibrary   (DLLib* pLib);
DL_API void*  dlFindSymbol    (DLLib* pLib, const char* pSymbolName);
DL_API int    dlGetLibraryPath(DLLib* pLib, char* sOut, int bufSize);


/* symbol table enumeration - only for symbol lookup, not resolve */



( run in 0.532 second using v1.01-cache-2.11-cpan-65fba6d93b7 )