xref: /illumos-gate/usr/src/lib/libdwarf/common/dwarf_object_detector.h (revision 16b76d3cb933ff92018a2a75594449010192eacb)
1 /* Copyright (c) 2018, David Anderson
2 All rights reserved.
3 
4 Redistribution and use in source and binary forms, with
5 or without modification, are permitted provided that the
6 following conditions are met:
7 
8     Redistributions of source code must retain the above
9     copyright notice, this list of conditions and the following
10     disclaimer.
11 
12     Redistributions in binary form must reproduce the above
13     copyright notice, this list of conditions and the following
14     disclaimer in the documentation and/or other materials
15     provided with the distribution.
16 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
18 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
19 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
29 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31 
32 #ifndef DWARF_OBJECT_DETECTOR_H
33 #define DWARF_OBJECT_DETECTOR_H
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif /* __cplusplus */
38 
39 
40 /*  Declares the interface function.
41     outpath is a place you provide, of a length outpath_len
42     you consider reasonable,
43     where the final path used is recorded.
44     outpath_len must be larger than strlen(path);
45 
46     This matters as for mach-o if the path is a directory
47     name the function will look in the standard macho-place
48     for the object file (useful for dSYM) and return the
49     constructed path in oupath.
50     returns DW_DLV_OK, DW_DLV_ERROR, or DW_DLV_NO_ENTRY */
51 
52 #ifndef DW_FTYPE_UNKNOWN
53 #define DW_FTYPE_UNKNOWN 0
54 #define DW_FTYPE_ELF     1
55 #define DW_FTYPE_MACH_O  2
56 #define DW_FTYPE_PE      3
57 #define DW_FTYPE_ARCHIVE 4  /* unix archive */
58 #endif /* DW_FTYPE_UNKNOWN */
59 
60 #ifndef DW_ENDIAN_UNKNOWN
61 #define DW_ENDIAN_UNKNOWN 0
62 #define DW_ENDIAN_BIG     1
63 #define DW_ENDIAN_LITTLE  2
64 #endif /* DW_ENDIAN_UNKNOWN */
65 
66 /*  offsetsize refers to the object-file-format.
67     Elf 32 or macho-32 or PE 32, for example.
68     Not to DWARF offset sizes.  */
69 
70 /*  Path means look(first) for an dynsym object
71     of the same name per MacOS standards,
72     making the outpath space needed is more than
73     that in path.
74     Copies the actual path into outpath, (an error
75     if the length in outpath_len is less than needed
76     for the object found).
77     For non-MacOS outpath will contain the string
78     taken from path.
79 
80     If DW_DLV_NO_ENTRY or DW_DLV_ERROR returned
81     the argument values other than path
82     must be considered to be in an unknown state. */
83 
84 /*  The errcode is a small integer distinct from libdwarf
85     and simply printing the integer (returned through
86     *errcode when the function returns DW_DLV_ERROR)
87     will hopefully suffice for most purposes. */
88 
89 int dwarf_object_detector_path(const char  *path,
90     char *outpath,
91     unsigned long outpath_len,
92     unsigned *ftype,
93     unsigned *endian,
94     unsigned *offsetsize,
95     Dwarf_Unsigned  *filesize,
96     int * errcode);
97 
98 int dwarf_object_detector_fd(int fd,
99     unsigned *ftype,
100     unsigned *endian,
101     unsigned *offsetsize,
102     Dwarf_Unsigned  *filesize,
103     int * errcode);
104 
105 #ifdef __cplusplus
106 }
107 #endif /* __cplusplus */
108 #endif /* DWARF_OBJECT_DETECTOR_H */
109