|
|
1.1 root 1: /*
2: * Mach Operating System
3: * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University
4: * All Rights Reserved.
5: *
6: * Permission to use, copy, modify and distribute this software and its
7: * documentation is hereby granted, provided that both the copyright
8: * notice and this permission notice appear in all copies of the
9: * software, derivative works or modified versions, and any portions
10: * thereof, and that both notices appear in supporting documentation.
11: *
12: * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
13: * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14: * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
15: *
16: * Carnegie Mellon requests users of this software to return to
17: *
18: * Software Distribution Coordinator or [email protected]
19: * School of Computer Science
20: * Carnegie Mellon University
21: * Pittsburgh PA 15213-3890
22: *
23: * any improvements or extensions that they make and grant Carnegie the
24: * rights to redistribute these changes.
25: */
26:
27: #ifndef _MACH_EXEC_H_
28: #define _MACH_EXEC_H_
29:
30: #include <mach/machine/vm_types.h>
31: #include <mach/vm_prot.h>
32:
33: /* XXX */
34: typedef enum
35: {
36: EXEC_ELF = 1,
37: EXEC_AOUT = 2,
38: } exec_format_t;
39:
40: typedef struct exec_info
41: {
42: /* Format of executable loaded - see above. */
43: exec_format_t format;
44:
45: /* Program entrypoint. */
46: vm_offset_t entry;
47:
48: /* Initial data pointer - only some architectures use this. */
49: vm_offset_t init_dp;
50:
51: /* (ELF) Address of interpreter string for loading shared libraries, null if none. */
52: vm_offset_t interp;
53:
54: } exec_info_t;
55:
56: typedef int exec_sectype_t;
57: #define EXEC_SECTYPE_READ VM_PROT_READ
58: #define EXEC_SECTYPE_WRITE VM_PROT_WRITE
59: #define EXEC_SECTYPE_EXECUTE VM_PROT_EXECUTE
60: #define EXEC_SECTYPE_PROT_MASK VM_PROT_ALL
61: #define EXEC_SECTYPE_ALLOC ((exec_sectype_t)0x000100)
62: #define EXEC_SECTYPE_LOAD ((exec_sectype_t)0x000200)
63: #define EXEC_SECTYPE_DEBUG ((exec_sectype_t)0x010000)
64: #define EXEC_SECTYPE_AOUT_SYMTAB ((exec_sectype_t)0x020000)
65: #define EXEC_SECTYPE_AOUT_STRTAB ((exec_sectype_t)0x040000)
66:
67: typedef int exec_read_func_t(void *handle, vm_offset_t file_ofs,
68: void *buf, vm_size_t size,
69: vm_size_t *out_actual);
70:
71: typedef int exec_read_exec_func_t(void *handle,
72: vm_offset_t file_ofs, vm_size_t file_size,
73: vm_offset_t mem_addr, vm_size_t mem_size,
74: exec_sectype_t section_type);
75:
76: /*
77: * Routines exported from libmach_exec.a
78: */
79:
80: /* Generic function to interpret an executable "file"
81: and "load" it into "memory".
82: Doesn't really know about files, loading, or memory;
83: all file I/O and destination memory accesses
84: go through provided functions.
85: Thus, this is a very generic loading mechanism.
86:
87: The read() function is used to read metadata from the file
88: into the local address space.
89:
90: The read_exec() function is used to load the actual sections.
91: It is used for all kinds of sections - code, data, bss, debugging data.
92: The 'section_type' parameter specifies what type of section is being loaded.
93:
94: For code, data, and bss, the EXEC_SECTYPE_ALLOC flag will be set.
95: For code and data (i.e. stuff that's actually loaded from the file),
96: EXEC_SECTYPE_LOAD will also be set.
97: The EXEC_SECTYPE_PROT_MASK contains the intended access permissions
98: for the section.
99: 'file_size' may be less than 'mem_size';
100: the remaining data must be zero-filled.
101: 'mem_size' is always greater than zero, but 'file_size' may be zero
102: (e.g. in the case of a bss section).
103: No two read_exec() calls for one executable
104: will load data into the same virtual memory page,
105: although they may load from arbitrary (possibly overlapping) file positions.
106:
107: For sections that aren't normally loaded into the process image
108: (e.g. debug sections), EXEC_SECTYPE_ALLOC isn't set,
109: but some other appropriate flag is set to indicate the type of section.
110:
111: The 'handle' is an opaque pointer which is simply passed on
112: to the read() and read_exec() functions.
113:
114: On return, the specified info structure is filled in
115: with information about the loaded executable.
116: */
117: int exec_load(exec_read_func_t *read, exec_read_exec_func_t *read_exec,
118: void *handle, exec_info_t *out_info);
119:
120: /*
121: * Error codes
122: */
123:
124: #define EX_NOT_EXECUTABLE 6000 /* not a recognized executable format */
125: #define EX_WRONG_ARCH 6001 /* valid executable, but wrong arch. */
126: #define EX_CORRUPT 6002 /* recognized executable, but mangled */
127: #define EX_BAD_LAYOUT 6003 /* something wrong with the memory or file image layout */
128:
129:
130: #endif /* _MACH_EXEC_H_ */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.