ldr.h File

Purpose

Describes the ld_info and ld_xinfo data types, along with associated loader entry points.

Syntax

#include <sys/ldr.h>

Description

The /usr/include/sys/ldr.h header file contains declarations of the ld_info and ld_xinfo data structures and the system loader entry points available to processes and kernel extensions.

The ld_info structure describes a loadable module in the context of either tracing a process (with the ptrace system call) or examining a core file. The ldr.h file can define 2 variants of the ld_info structure, one for describing 32-bit processes (__ld_info32) and one for describing 64-bit processes (__ld_info64). If the __LDINFO_PTRACE32__ symbol is defined, so is the struct __ld_info32 type. If the __LDINFO_PTRACE64__ symbol is defined, so is the struct __ld_info64 type. If the compilation mode is 32-bit and the __LDINFO_PTRACE32__ symbol is defined, the struct __ld_info32 and struct ld_info types are equivalent. If the compilation mode is 64-bit and the __LDINFO_PTRACE64__ symbol is defined, the struct __ld_info64 and struct ld_info types are equivalent.

When using ptrace in a 32-bit program to debug a 64-bit process, define __LDINFO_PTRACE64__. When using ptrace in a 64-bit program to debug a 32-bit process, define __LDINFO_PTRACE32__.

The types and sizes of these structures' fields depend on whether the compilation mode is 32-bit or 64-bit. The same field names are generated in both structure modes, with the exception that the 64-bit structure has an ldinfo_flags field.

The __ld_info32 and __ld_info64 structures contain the following fields of the indicated sizes and types; when two types are listed, the first is used when the compilation mode is 32-bit and the second is used when the mode is 64-bit:

Field and Description __ld_info32 __ld_info64
ldinfo_next
Offset from current entry of next entry, or zero if last entry.
  • Size: 4
  • Type: uint
  • Size: 4
  • Type: uint
ldinfo_flags
Flags.
  • Size: N/A
  • Type: N/A
  • Size: 4
  • Type: uint
ldinfo_fd
File descriptor returned by ptrace to debugger.
  • Size: 4
  • Type: int
  • Size: 4
  • Type: int
ldinfo_core
Offset into core file of object. (Overlays the ldinfo_fd field.)
  • Size: 4
  • Type: int
  • Size: 8
  • Type: long long, long
ldinfo_textorg
Effective address of the loaded program image, including the XCOFF headers.
  • Size: 4
  • Type: void *, uint
  • Size: 8
  • Type: unsigned long long, void *
ldinfo_textsize
Length of loaded program image.
  • Size: 4
  • Type: int
  • Size: 8
  • Type: long long, long
ldinfo_dataorg
Effective address of the start of data.
  • Size: 4
  • Type: void *, uint
  • Size: 8
  • Type: unsigned long long, void *
ldinfo_datasize
Size of data, including the .bss section.
  • Size: 4
  • Type: int
  • Size: 8
  • Type: long long, long
ldinfo_filename
Nul-terminated path name followed by nul-terminated member name; member name is empty if not an archive.
  • Size: variable
  • Type: char[2]
  • Size: variable
  • Type: char[2]

The ld_xinfo structure is similar to the ld_info structure, but the ld_xinfo structure has additional fields for modules defining thread-local storage. Furthermore, all fields are large enough to describe regions of a 64-bit process, so only a single variant of the ld_xinfo structure exists.

The additional fields in the ld_xinfo structure are the following:

Field Description
ldinfo_tdatasize Size of the .tdata section.
ldinfo_tbsssize Size of the .tbss section.
ldinfo_tdataorg Effective address of the initialization template for .tdata.
ldinfo_tdataoff Offset of the module's thread-local storage in its region.
ldinfo_tls_rnum Thread-local storage region number.

In addition, the ldinfo_filename field has a different interpretation in the ld_xinfo structure. The value of this field in the ld_xinfo structure is an offset from the beginning of the structure to a null-terminated path name followed by null-terminated member name.

The ldr.h header declares the following functions:
int           kmod_load(caddr_t path, uint flags, caddr_t libpath, mid_t *kmid);
int           kmod_unload(mid_t kmid, uint flags);
void         (*(kmod_entrypt(mid_t kmid, uint flags)))();
int           ld_info(int __flags, pid_t __pid, void *__buffer, unsigned int __length);
__LOAD_T     *load(char *__filenameparm, uint __flags, char *__libpathparm);
int           loadbind(int __lflags, void *__exporter, void *__importer);
int           unload(void *__function);
int           loadquery(int __lflags, void *__buffer, unsigned int __length);
__handler_t  *__lazySetErrorHandler( __handler_t *fp );