package ocaml-probes

  1. Overview
  2. Docs
USDT probes for OCaml: command line tool

Install

Dune Dependency

Authors

Maintainers

Sources

ocaml-probes-v0.16.0.tar.gz
sha256=bc8d2b0449a43966aace3815d20a71c51188317a2e8268b6e68cb4955d482f10

doc/src/ocaml-probes.probes_lib/mmap.ml.html

Source file mmap.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
exception Error of string

let verbose = ref false

type entry =
  { addr : int64 (** start address of the segment *)
  ; offset : int64 (** file offset *)
  }

type t =
  { vma_offset_text : int64
  ; vma_offset_data : int64
  ; vma_offset_semaphores : int64
  }

let default = { vma_offset_text = 0L; vma_offset_data = 0L; vma_offset_semaphores = 0L }

(* The following calculation give the dynamic address of a symbol:
   sym_dynamic_addr
   "symbol's dynamic address"
   = "segment start"
   + "offset of symbol's static address from the start of its section"
   + "offset of its section from the base of the segment's offset in the file"
   = "segment start"
   + "symbol's static address" - "section start"
   + "section offset into the file" - "segment offset into the file"
   = seg_addr + (sym_static_addr - sec_addr) + (sec_offset - seg_offset)
   = seg_addr + sec_offset  - seg_offset - sec_addr + sym_static_addr
   Read "segment start" and "segment offset into file" from mmap.
   The rest is known from reading elf file.
   Precompute the offset of dynamic address from static address
   for each type of symbol, making sure it doesn't over/underflow.
*)
let _vma_offset mmap_entry (elf_section : Elf.section) =
  if mmap_entry.addr < elf_section.addr || elf_section.offset < mmap_entry.offset
  then raise (Failure "Unexpected section sizes");
  Int64.sub
    (Int64.add (Int64.sub mmap_entry.addr mmap_entry.offset) elf_section.offset)
    elf_section.addr
;;

let read ~pid:_ (elf : Elf.t) =
  if elf.pie
  then
    failwith
      "Probes-lib has not implemented support for position independent executables.";
  default
;;
OCaml

Innovation. Community. Security.