Xv6 with picoc & Linkage editor
v1.0
The project delineate mutual cohesion between c library, linkage editor ( linker), interpreter and operating system by porting the same on xv6 kernel
|
00001 /* 00002 * libelf.h - public header file for libelf. 00003 * Copyright (C) 1995 - 2006 Michael Riepe 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Library General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Library General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Library General Public 00016 * License along with this library; if not, write to the Free Software 00017 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 */ 00019 00020 /* @(#) $Id: libelf.h,v 1.25 2006/08/18 00:00:38 michael Exp $ */ 00021 00022 #ifndef _LIBELF_H 00023 #define _LIBELF_H 00024 00025 #include <stddef.h> /* for size_t */ 00026 #include <sys/types.h> 00027 00028 #if __LIBELF_INTERNAL__ 00029 #include <sys_elf.h> 00030 #else /* __LIBELF_INTERNAL__ */ 00031 #include <libelf/sys_elf.h> 00032 #endif /* __LIBELF_INTERNAL__ */ 00033 00034 #ifdef __cplusplus 00035 extern "C" { 00036 #endif /* __cplusplus */ 00037 00038 #ifndef __P 00039 # if (__STDC__ + 0) || defined(__cplusplus) || defined(_WIN32) 00040 # define __P(args) args 00041 # else /* __STDC__ || defined(__cplusplus) */ 00042 # define __P(args) () 00043 # endif /* __STDC__ || defined(__cplusplus) */ 00044 #endif /* __P */ 00045 00046 /* 00047 * Commands 00048 */ 00049 typedef enum { 00050 ELF_C_NULL = 0, /* must be first, 0 */ 00051 ELF_C_READ, 00052 ELF_C_WRITE, 00053 ELF_C_CLR, 00054 ELF_C_SET, 00055 ELF_C_FDDONE, 00056 ELF_C_FDREAD, 00057 ELF_C_RDWR, 00058 ELF_C_NUM /* must be last */ 00059 } Elf_Cmd; 00060 00061 /* 00062 * Flags 00063 */ 00064 #define ELF_F_DIRTY 0x1 00065 #define ELF_F_LAYOUT 0x4 00066 00067 /* 00068 * File types 00069 */ 00070 typedef enum { 00071 ELF_K_NONE = 0, /* must be first, 0 */ 00072 ELF_K_AR, 00073 ELF_K_COFF, 00074 ELF_K_ELF, 00075 ELF_K_NUM /* must be last */ 00076 } Elf_Kind; 00077 00078 /* 00079 * Data types 00080 */ 00081 typedef enum { 00082 ELF_T_BYTE = 0, /* must be first, 0 */ 00083 ELF_T_ADDR, 00084 ELF_T_DYN, 00085 ELF_T_EHDR, 00086 ELF_T_HALF, 00087 ELF_T_OFF, 00088 ELF_T_PHDR, 00089 ELF_T_RELA, 00090 ELF_T_REL, 00091 ELF_T_SHDR, 00092 ELF_T_SWORD, 00093 ELF_T_SYM, 00094 ELF_T_WORD, 00095 /* 00096 * New stuff for 64-bit. 00097 * 00098 * Most implementations add ELF_T_SXWORD after ELF_T_SWORD 00099 * which breaks binary compatibility with earlier versions. 00100 * If this causes problems for you, contact me. 00101 */ 00102 ELF_T_SXWORD, 00103 ELF_T_XWORD, 00104 /* 00105 * Symbol versioning. Sun broke binary compatibility (again!), 00106 * but I won't. 00107 */ 00108 ELF_T_VDEF, 00109 ELF_T_VNEED, 00110 ELF_T_NUM /* must be last */ 00111 } Elf_Type; 00112 00113 /* 00114 * Elf descriptor 00115 */ 00116 typedef struct Elf Elf; 00117 00118 /* 00119 * Section descriptor 00120 */ 00121 typedef struct Elf_Scn Elf_Scn; 00122 00123 /* 00124 * Archive member header 00125 */ 00126 typedef struct { 00127 char* ar_name; 00128 time_t ar_date; 00129 long ar_uid; 00130 long ar_gid; 00131 unsigned long ar_mode; 00132 off_t ar_size; 00133 char* ar_rawname; 00134 } Elf_Arhdr; 00135 00136 /* 00137 * Archive symbol table 00138 */ 00139 typedef struct { 00140 char* as_name; 00141 size_t as_off; 00142 unsigned long as_hash; 00143 } Elf_Arsym; 00144 00145 /* 00146 * Data descriptor 00147 */ 00148 typedef struct { 00149 void* d_buf; 00150 Elf_Type d_type; 00151 size_t d_size; 00152 off_t d_off; 00153 size_t d_align; 00154 unsigned d_version; 00155 } Elf_Data; 00156 00157 /* 00158 * Function declarations 00159 */ 00160 extern Elf *elf_begin __P((int __fd, Elf_Cmd __cmd, Elf *__ref)); 00161 extern Elf *elf_memory __P((char *__image, size_t __size)); 00162 extern int elf_cntl __P((Elf *__elf, Elf_Cmd __cmd)); 00163 extern int elf_end __P((Elf *__elf)); 00164 extern const char *elf_errmsg __P((int __err)); 00165 extern int elf_errno __P((void)); 00166 extern void elf_fill __P((int __fill)); 00167 extern unsigned elf_flagdata __P((Elf_Data *__data, Elf_Cmd __cmd, 00168 unsigned __flags)); 00169 extern unsigned elf_flagehdr __P((Elf *__elf, Elf_Cmd __cmd, 00170 unsigned __flags)); 00171 extern unsigned elf_flagelf __P((Elf *__elf, Elf_Cmd __cmd, 00172 unsigned __flags)); 00173 extern unsigned elf_flagphdr __P((Elf *__elf, Elf_Cmd __cmd, 00174 unsigned __flags)); 00175 extern unsigned elf_flagscn __P((Elf_Scn *__scn, Elf_Cmd __cmd, 00176 unsigned __flags)); 00177 extern unsigned elf_flagshdr __P((Elf_Scn *__scn, Elf_Cmd __cmd, 00178 unsigned __flags)); 00179 extern size_t elf32_fsize __P((Elf_Type __type, size_t __count, 00180 unsigned __ver)); 00181 extern Elf_Arhdr *elf_getarhdr __P((Elf *__elf)); 00182 extern Elf_Arsym *elf_getarsym __P((Elf *__elf, size_t *__ptr)); 00183 extern off_t elf_getbase __P((Elf *__elf)); 00184 extern Elf_Data *elf_getdata __P((Elf_Scn *__scn, Elf_Data *__data)); 00185 extern Elf32_Ehdr *elf32_getehdr __P((Elf *__elf)); 00186 extern char *elf_getident __P((Elf *__elf, size_t *__ptr)); 00187 extern Elf32_Phdr *elf32_getphdr __P((Elf *__elf)); 00188 extern Elf_Scn *elf_getscn __P((Elf *__elf, size_t __index)); 00189 extern Elf32_Shdr *elf32_getshdr __P((Elf_Scn *__scn)); 00190 extern unsigned long elf_hash __P((const unsigned char *__name)); 00191 extern Elf_Kind elf_kind __P((Elf *__elf)); 00192 extern size_t elf_ndxscn __P((Elf_Scn *__scn)); 00193 extern Elf_Data *elf_newdata __P((Elf_Scn *__scn)); 00194 extern Elf32_Ehdr *elf32_newehdr __P((Elf *__elf)); 00195 extern Elf32_Phdr *elf32_newphdr __P((Elf *__elf, size_t __count)); 00196 extern Elf_Scn *elf_newscn __P((Elf *__elf)); 00197 extern Elf_Cmd elf_next __P((Elf *__elf)); 00198 extern Elf_Scn *elf_nextscn __P((Elf *__elf, Elf_Scn *__scn)); 00199 extern size_t elf_rand __P((Elf *__elf, size_t __offset)); 00200 extern Elf_Data *elf_rawdata __P((Elf_Scn *__scn, Elf_Data *__data)); 00201 extern char *elf_rawfile __P((Elf *__elf, size_t *__ptr)); 00202 extern char *elf_strptr __P((Elf *__elf, size_t __section, size_t __offset)); 00203 extern off_t elf_update __P((Elf *__elf, Elf_Cmd __cmd)); 00204 extern unsigned elf_version __P((unsigned __ver)); 00205 extern Elf_Data *elf32_xlatetof __P((Elf_Data *__dst, const Elf_Data *__src, 00206 unsigned __encode)); 00207 extern Elf_Data *elf32_xlatetom __P((Elf_Data *__dst, const Elf_Data *__src, 00208 unsigned __encode)); 00209 00210 /* 00211 * Additional functions found on Solaris 00212 */ 00213 extern long elf32_checksum __P((Elf *__elf)); 00214 00215 #if __LIBELF64 00216 /* 00217 * 64-bit ELF functions 00218 * Not available on all platforms 00219 */ 00220 extern Elf64_Ehdr *elf64_getehdr __P((Elf *__elf)); 00221 extern Elf64_Ehdr *elf64_newehdr __P((Elf *__elf)); 00222 extern Elf64_Phdr *elf64_getphdr __P((Elf *__elf)); 00223 extern Elf64_Phdr *elf64_newphdr __P((Elf *__elf, size_t __count)); 00224 extern Elf64_Shdr *elf64_getshdr __P((Elf_Scn *__scn)); 00225 extern size_t elf64_fsize __P((Elf_Type __type, size_t __count, 00226 unsigned __ver)); 00227 extern Elf_Data *elf64_xlatetof __P((Elf_Data *__dst, const Elf_Data *__src, 00228 unsigned __encode)); 00229 extern Elf_Data *elf64_xlatetom __P((Elf_Data *__dst, const Elf_Data *__src, 00230 unsigned __encode)); 00231 00232 /* 00233 * Additional functions found on Solaris 00234 */ 00235 extern long elf64_checksum __P((Elf *__elf)); 00236 00237 #endif /* __LIBELF64 */ 00238 00239 /* 00240 * ELF format extensions 00241 * 00242 * These functions return 0 on failure, 1 on success. 00243 */ 00244 extern int elf_getphnum(Elf *__elf, size_t *__resultp); 00245 extern int elf_getshnum(Elf *__elf, size_t *__resultp); 00246 extern int elf_getshstrndx(Elf *__elf, size_t *__resultp); 00247 00248 /* 00249 * Convenience functions 00250 * 00251 * elfx_update_shstrndx is elf_getshstrndx's counterpart. 00252 * It should be used to set the e_shstrndx member. 00253 * There is no update function for e_shnum or e_phnum 00254 * because libelf handles them internally. 00255 */ 00256 extern int elfx_update_shstrndx(Elf *__elf, size_t __index); 00257 00258 /* 00259 * Experimental extensions: 00260 * 00261 * elfx_movscn() moves section `__scn' directly after section `__after'. 00262 * elfx_remscn() removes section `__scn'. Both functions update 00263 * the section indices; elfx_remscn() also adjusts the ELF header's 00264 * e_shnum member. The application is responsible for updating other 00265 * data (in particular, e_shstrndx and the section headers' sh_link and 00266 * sh_info members). 00267 * 00268 * elfx_movscn() returns the new index of the moved section. 00269 * elfx_remscn() returns the original index of the removed section. 00270 * A return value of zero indicates an error. 00271 */ 00272 extern size_t elfx_movscn __P((Elf *__elf, Elf_Scn *__scn, Elf_Scn *__after)); 00273 extern size_t elfx_remscn __P((Elf *__elf, Elf_Scn *__scn)); 00274 00275 /* 00276 * elf_delscn() is obsolete. Please use elfx_remscn() instead. 00277 */ 00278 extern size_t elf_delscn __P((Elf *__elf, Elf_Scn *__scn)); 00279 00280 #ifdef __cplusplus 00281 } 00282 #endif /* __cplusplus */ 00283 00284 #endif /* _LIBELF_H */