00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include <stdlib.h>
00039 #include <stdio.h>
00040 #include <strings.h>
00041 #include <sys/unwindP.h>
00042 #include "unwind_producer.h"
00043
00044
00045
00046
00047 __unw_error_t unwind_info_add_prologue_header(__unw_info_t *info, __uint64_t size) {
00048 __unw_error_t ret = __UNW_OK;
00049
00050
00051 if (NULL == info) {
00052 return __UNW_NULL_ERROR;
00053 } else if (_unwind_info + _unwind_info_size != info) {
00054 return __UNW_INV_ARG_ERROR;
00055 }
00056
00057
00058
00059 if ((__UNW_PROLOGUE == _current_region_id) && (0L != _imask_size)) {
00060 unwind_info_add_imask(info);
00061 }
00062
00063
00064 _current_procedure_size += size;
00065 _current_region_total_size = size;
00066 _current_region_id = __UNW_PROLOGUE;
00067 if (_current_procedure_size > _current_procedure_total_size) {
00068 return __UNW_INV_SIZE_ERROR;
00069 }
00070
00071
00072 if (size < 32) {
00073
00074
00075
00076 __unw_format_r1_t desc;
00077 __uint64_t rsize;
00078
00079 desc._fix[0] = 0x00;
00080 desc._fix[0] |= (char)size;
00081 rsize = 1;
00082
00083
00084 ret = unwind_info_add_desc(rsize, (char *)&desc);
00085 } else {
00086
00087
00088
00089 __unw_format_r3_t *desc;
00090 __uint64_t rsize, esize;
00091 char encoded[1+__UNW_ENCODING_SIZE];
00092
00093 encoded[0] = 0x60;
00094 if ((esize = __leb128_encode((char *)&encoded[1],
00095 (__uint64_t)__UNW_ENCODING_SIZE,
00096 size)) == 0) {
00097 return __UNW_INTERNAL_ERROR;
00098 }
00099
00100 desc = (__unw_format_r3_t *)&encoded;
00101 rsize = 1 + esize;
00102
00103
00104 ret = unwind_info_add_desc(rsize, (char *)desc);
00105 }
00106
00107 return ret;
00108 }
00109
00110
00111
00112
00113 __unw_error_t unwind_info_add_prologue_gr_header(__unw_info_t *info, __uint64_t size,
00114 char mask, __uint32_t gr) {
00115 __unw_error_t ret = __UNW_OK;
00116 __unw_format_r2_t *desc;
00117 __uint64_t rsize, esize;
00118 char encoded[2+__UNW_ENCODING_SIZE];
00119
00120
00121 if (NULL == info) {
00122 return __UNW_NULL_ERROR;
00123 } else if (_unwind_info + _unwind_info_size != info) {
00124 return __UNW_INV_ARG_ERROR;
00125 }
00126
00127
00128
00129 if ((__UNW_PROLOGUE == _current_region_id) && (0L != _imask_size)) {
00130 unwind_info_add_imask(info);
00131 }
00132
00133
00134 _current_procedure_size += size;
00135 _current_region_total_size = size;
00136 _current_region_id = __UNW_PROLOGUE;
00137 if (_current_procedure_size > _current_procedure_total_size) {
00138 return __UNW_INV_SIZE_ERROR;
00139 }
00140
00141
00142
00143
00144
00145
00146
00147 if ((mask >= 16) || (gr >= 128)) {
00148 return __UNW_INV_ARG_ERROR;
00149 }
00150 encoded[0] = 0x40;
00151 encoded[0] |= (mask >> 1);
00152 encoded[1] = (mask << 7);
00153 encoded[1] |= gr;
00154 if ((esize = __leb128_encode((char *)&encoded[2],
00155 (__uint64_t)__UNW_ENCODING_SIZE,
00156 size)) == 0) {
00157 return __UNW_INTERNAL_ERROR;
00158 }
00159
00160 desc = (__unw_format_r2_t *)&encoded;
00161 rsize = 2 + esize;
00162
00163
00164 ret = unwind_info_add_desc(rsize, (char *)desc);
00165
00166 return ret;
00167 }
00168
00169
00170
00171
00172 __unw_error_t unwind_info_add_body_header(__unw_info_t *info, __uint64_t size) {
00173 __unw_error_t ret = __UNW_OK;
00174
00175
00176 if (NULL == info) {
00177 return __UNW_NULL_ERROR;
00178 } else if (_unwind_info + _unwind_info_size != info) {
00179 return __UNW_INV_ARG_ERROR;
00180 }
00181
00182
00183
00184 if ((__UNW_PROLOGUE == _current_region_id) && (0L != _imask_size)) {
00185 unwind_info_add_imask(info);
00186 }
00187
00188
00189 _current_procedure_size += size;
00190 _current_region_total_size = size;
00191 _current_region_id = __UNW_BODY;
00192 if (_current_procedure_size > _current_procedure_total_size) {
00193 return __UNW_INV_SIZE_ERROR;
00194 }
00195
00196
00197 if (size < 32) {
00198
00199
00200
00201 __unw_format_r1_t desc;
00202 __uint64_t rsize;
00203
00204 desc._fix[0] = 0x20;
00205 desc._fix[0] |= (char)size;
00206 rsize = 1;
00207
00208
00209 ret = unwind_info_add_desc(rsize, (char *)&desc);
00210 } else {
00211
00212
00213
00214 __unw_format_r3_t *desc;
00215 __uint64_t rsize, esize;
00216 char encoded[1+__UNW_ENCODING_SIZE];
00217
00218 encoded[0] = 0x61;
00219 if ((esize = __leb128_encode((char *)&encoded[1],
00220 (__uint64_t)__UNW_ENCODING_SIZE,
00221 size)) == 0) {
00222 return __UNW_INTERNAL_ERROR;
00223 }
00224
00225 desc = (__unw_format_r3_t *)&encoded;
00226 rsize = 1 + esize;
00227
00228
00229 ret = unwind_info_add_desc(rsize, (char *)desc);
00230 }
00231
00232 return ret;
00233 }