1 /*
2 * Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
3 * Description: Definition of source file for generating bytecode.
4 * Create: 2020/09/07
5 */
6
7 #ifdef JERRY_FOR_IAR_CONFIG
8
9 #include "generate-bytecode.h"
10
11 #include <string.h>
12
13 #include "config-gt.h"
14 #include "config-jupiter.h"
15
16 #define VERSION_LEN 30
17 #define ONETIME_MAX_OPTBYTES 4096 // max size for reading and writing at onetime
18
19 // jerry version code
20 char version_str[VERSION_LEN];
21
22 // secure functions
23 extern int memset_s(void *dest, size_t destMax, int c, size_t count);
24 extern int strcpy_s(char *strDest, size_t destMax, const char *strSrc);
25 extern int strcat_s(char *strDest, size_t destMax, const char *strSrc);
26 extern int strncat_s(char *strDest, size_t destMax, const char *strSrc, size_t count);
27 extern int sprintf_s(char *strDest, size_t destMax, const char *format, ...);
28 extern int strncpy_s(char *strDest, size_t destMax, const char *strSrc, size_t count);
29
30 #ifdef JERRY_IAR_JUPITER
31 extern uint8_t* input_buffer;
32 extern uint8_t* snapshot_buffer;
33 #endif // JERRY_IAR_JUPITER
34
35 /**
36 * jerry snapshot format version
37 */
get_jerry_version_no()38 char* get_jerry_version_no() {
39 if (sprintf_s(version_str, sizeof(version_str),
40 "JERRY_SNAPSHOT_VERSION_%u", JERRY_SNAPSHOT_VERSION) < 0) {
41 return NULL;
42 }
43 return version_str;
44 } /* get_jerry_version_no */
45
46 /**
47 * splice path and filename
48 */
splice_path(char * str1,char * str2)49 char* splice_path(char* str1, char* str2) {
50 int len1 = strlen(str1);
51 int len2 = strlen(str2);
52 int res_len = len1 + len2 + 1; // str1 + "/" + str2
53
54 char* res = (char*)OhosMalloc(MEM_TYPE_JERRY, (res_len + 1) * sizeof(char));
55 if (res == NULL) {
56 return NULL;
57 }
58 if (memset_s(res, res_len + 1, 0, res_len + 1) != 0) {
59 OhosFree(res);
60 res = NULL;
61 return NULL;
62 }
63 if (strcpy_s(res, len1 + 1, str1) != 0) {
64 OhosFree(res);
65 res = NULL;
66 return NULL;
67 }
68 if ((strcat_s(res, len1 + strlen("/") + 1, "/") != 0)
69 || (strcat_s(res, res_len + 1, str2) != 0)) {
70 OhosFree(res);
71 res = NULL;
72 return NULL;
73 }
74 return res;
75 } /* splice_path */
76
77 /**
78 * judge if is template(js/bc) file
79 */
is_template_file(char * filename,char * template)80 bool is_template_file(char* filename, char* template) {
81 const char* pFile;
82 pFile = strrchr(filename, '.');
83 if ((pFile != NULL) && (strcmp(pFile, template) == 0)) {
84 return true;
85 }
86 return false;
87 } /* is_template_file */
88
89 /**
90 * get output snapshot file absolutely path
91 */
get_output_file_path(char * input_file_path)92 char* get_output_file_path(char* input_file_path) {
93 int len = strlen(input_file_path);
94 char* output_file_path = (char*)OhosMalloc(MEM_TYPE_JERRY, (len + 1) * sizeof(char));
95 if (output_file_path == NULL) {
96 return NULL;
97 }
98 if (memset_s(output_file_path, len + 1, 0, len + 1) != 0) {
99 OhosFree(output_file_path);
100 output_file_path = NULL;
101 return NULL;
102 }
103 if (strncpy_s(output_file_path, len, input_file_path, len - strlen(".js")) != 0) {
104 OhosFree(output_file_path);
105 output_file_path = NULL;
106 return NULL;
107 }
108 output_file_path[len-3] = '.';
109 output_file_path[len-2] = 'b';
110 output_file_path[len-1] = 'c';
111 output_file_path[len] = '\0';
112 return output_file_path;
113 } /* get_output_file_path */
114
115 /**
116 * read js bundle file or snapshot file by Fragement
117 */
read_js_or_snapshot_file(char * filename,uint8_t * target_file,int * file_bytesize,int buffer_capacity)118 EXECRES read_js_or_snapshot_file(char* filename, uint8_t* target_file, int* file_bytesize, int buffer_capacity) {
119 int fd = 0;
120 struct stat file_stat = { 0 };
121 int remain_to_read = 0;
122 int here_to_read = 0;
123 int tmp_read = 0;
124 int read_offset = 0;
125 fd = open(filename, O_RDONLY, S_IREAD);
126 if (fd < 0) {
127 // Error: failed to open file
128 return EXCE_ACE_JERRY_OPEN_FILE_FAILED;
129 }
130 if (fstat(fd, &file_stat) < 0) {
131 close(fd);
132 return EXCE_ACE_JERRY_GET_FILE_STAT_ERROR;
133 }
134 *file_bytesize = file_stat.st_size;
135 if (*file_bytesize > buffer_capacity) {
136 close(fd);
137 return EXCE_ACE_JERRY_FILE_TOO_LARGE;
138 }
139 remain_to_read = *file_bytesize;
140 while (remain_to_read > 0) {
141 here_to_read = (remain_to_read > ONETIME_MAX_OPTBYTES) ?
142 ONETIME_MAX_OPTBYTES : remain_to_read;
143 tmp_read = read(fd, target_file + read_offset, here_to_read);
144 if (tmp_read < 0 || tmp_read != here_to_read) {
145 close(fd);
146 // Error: failed to read file
147 return EXCE_ACE_JERRY_READ_FILE_FAILED;
148 }
149 read_offset = read_offset + here_to_read;
150 remain_to_read = remain_to_read - here_to_read;
151 }
152 if (read_offset != *file_bytesize) {
153 close(fd);
154 // Error: failed to successfully read file
155 return EXCE_ACE_JERRY_READ_FILE_FAILED;
156 }
157 close(fd);
158 return EXCE_ACE_JERRY_EXEC_OK;
159 } /* read_js_or_snapshot_file */
160
161 /**
162 * write snapshot file by Fragment
163 */
write_snapshot(char * output_file_name_path,size_t snapshot_size)164 EXECRES write_snapshot(char* output_file_name_path, size_t snapshot_size) {
165 int fd = 0;
166 int res = 0;
167 int remain_to_write = 0;
168 int here_to_write = 0;
169 int write_offset = 0;
170
171 fd = open(output_file_name_path, O_RDWR | O_CREAT, S_IREAD | S_IWRITE);
172 if (fd < 0) {
173 // Error: Unable to open snapshot file
174 return EXCE_ACE_JERRY_OPEN_FILE_FAILED;
175 }
176 remain_to_write = snapshot_size;
177 while (remain_to_write > 0) {
178 here_to_write = (remain_to_write > ONETIME_MAX_OPTBYTES) ?
179 ONETIME_MAX_OPTBYTES : remain_to_write;
180 res = write(fd, snapshot_buffer + write_offset, here_to_write);
181 if (res <= 0 || res != here_to_write) {
182 close(fd);
183 // Error: Unable to write snapshot file
184 return EXCE_ACE_JERRY_WRITE_SNAPSHOT_FILE_FAILED;
185 }
186 write_offset = write_offset + here_to_write;
187 remain_to_write = remain_to_write - here_to_write;
188 }
189 if (write_offset != snapshot_size) {
190 close(fd);
191 // Error: Unable to successfully write snapshot file
192 return EXCE_ACE_JERRY_WRITE_SNAPSHOT_FILE_FAILED;
193 }
194 close(fd);
195 return EXCE_ACE_JERRY_EXEC_OK;
196 } /* write_snapshot */
197
198 /**
199 * struct for Directory Node
200 */
201 typedef struct Node {
202 char* dir_name;
203 struct Node* next;
204 } dir_node;
205
206 /**
207 * free the memory for linkedlist
208 */
free_link(dir_node * head)209 void free_link(dir_node* head) {
210 dir_node* tmp = NULL;
211 while (head != NULL) {
212 tmp = head;
213 head = head->next;
214 if (tmp->dir_name != NULL) {
215 OhosFree(tmp->dir_name);
216 tmp->dir_name = NULL;
217 }
218 OhosFree(tmp);
219 tmp = NULL;
220 }
221 } /* free_link */
222
223 /**
224 * generate snapshot file
225 */
generate_snapshot_file(char * input_file,char * output_file)226 EXECRES generate_snapshot_file(char* input_file, char* output_file) {
227 uint8_t* target_Js = input_buffer;
228 jerry_value_t generate_result;
229 size_t snapshot_size = 0;
230 EXECRES write_res = EXCE_ACE_JERRY_EXEC_OK;
231 bool convert_state = false;
232 int file_bytesize = 0;
233 EXECRES read_res = EXCE_ACE_JERRY_EXEC_OK;
234
235 if (input_file == NULL || output_file == NULL) {
236 return EXCE_ACE_JERRY_NULL_PATH;
237 }
238 read_res = read_js_or_snapshot_file(input_file, target_Js, &file_bytesize, INPUTJS_BUFFER_SIZE);
239 if (read_res != EXCE_ACE_JERRY_EXEC_OK) {
240 return read_res;
241 }
242
243 generate_result = jerry_generate_snapshot (
244 NULL,
245 0,
246 target_Js,
247 file_bytesize,
248 0,
249 (uint32_t* )snapshot_buffer,
250 SNAPSHOT_BUFFER_SIZE);
251
252 convert_state = jerry_value_is_error(generate_result)
253 || !jerry_value_is_number(generate_result);
254 if (convert_state) {
255 // Error: Generating snapshot failed
256 jerry_release_value(generate_result);
257 return EXCE_ACE_JERRY_GENERATE_SNAPSHOT_FAILED;
258 }
259 snapshot_size = (size_t)jerry_get_number_value(generate_result);
260 jerry_release_value(generate_result);
261
262 write_res = write_snapshot(output_file, snapshot_size);
263 if (write_res != EXCE_ACE_JERRY_EXEC_OK) {
264 // Error: Writing snapshot file failed
265 return write_res;
266 }
267 return EXCE_ACE_JERRY_EXEC_OK;
268 }/* generate_snapshot_file */
269
270 /**
271 * init the linked list for files in filefolder.
272 */
init_directory_list(char * filefolder,char * start_folder,dir_node ** head,dir_node ** end)273 EXECRES init_directory_list(char* filefolder, char* start_folder, dir_node **head, dir_node **end) {
274 struct stat file_stat = { 0 };
275 int filefolder_len = strlen(filefolder) + 1;
276 if ((filefolder == NULL) || (stat(filefolder, &file_stat) < 0)) {
277 return EXCE_ACE_JERRY_INPUT_PATH_ERROR;
278 }
279 if ((start_folder = (char*)OhosMalloc(MEM_TYPE_JERRY, filefolder_len)) == NULL) {
280 return EXCE_ACE_JERRY_MALLOC_ERROR;
281 }
282 if (strcpy_s(start_folder, filefolder_len, filefolder) != 0) {
283 OhosFree(start_folder);
284 start_folder = NULL;
285 return EXCE_ACE_JERRY_INPUT_PATH_ERROR;
286 }
287 if ((*head = (dir_node*)OhosMalloc(MEM_TYPE_JERRY, sizeof(dir_node))) == NULL) {
288 OhosFree(start_folder);
289 start_folder = NULL;
290 return EXCE_ACE_JERRY_LINKLIST_ERROR;
291 }
292 if ((*end = (dir_node*)OhosMalloc(MEM_TYPE_JERRY, sizeof(dir_node))) == NULL) {
293 OhosFree(start_folder);
294 start_folder = NULL;
295 OhosFree(*head);
296 *head = NULL;
297 return EXCE_ACE_JERRY_LINKLIST_ERROR;
298 }
299 (*head)->dir_name = NULL;
300 (*head)->next = *end;
301 (*end)->dir_name = start_folder;
302 (*end)->next = NULL;
303 return EXCE_ACE_JERRY_EXEC_OK;
304 } /* init_directory_list */
305
306 /**
307 * when visited node is a directory, add it to the node list's end.
308 */
add_directory_to_pending_list(dir_node ** end,char * input_file_path)309 EXECRES add_directory_to_pending_list(dir_node **end, char* input_file_path) {
310 dir_node *new_node = NULL;
311 if ((new_node = (dir_node*)OhosMalloc(MEM_TYPE_JERRY, sizeof(dir_node))) == NULL) {
312 OhosFree(input_file_path);
313 input_file_path = NULL;
314 return EXCE_ACE_JERRY_LINKLIST_ERROR;
315 }
316 // input_file_path for dir will be freed when that node is freed
317 new_node->dir_name = input_file_path;
318 new_node->next = NULL;
319 (*end)->next = new_node;
320 *end = new_node;
321 new_node = NULL;
322 return EXCE_ACE_JERRY_EXEC_OK;
323 } /* add_directory_to_pending_list */
324
325 /**
326 * transform this js file into snapshot.
327 */
gen_snapshot(char * input_file_path,char * output_file_path)328 EXECRES gen_snapshot(char* input_file_path, char* output_file_path) {
329 jerry_init_flag_t flags = JERRY_INIT_EMPTY;
330 jerry_init (flags);
331 EXECRES generate_val = EXCE_ACE_JERRY_EXEC_OK;
332 generate_val = generate_snapshot_file(input_file_path, output_file_path);
333 jerry_cleanup();
334 OhosFree(output_file_path);
335 output_file_path = NULL;
336 OhosFree(input_file_path);
337 input_file_path = NULL;
338 if (generate_val != EXCE_ACE_JERRY_EXEC_OK) {
339 return generate_val; // return error_code
340 }
341 return EXCE_ACE_JERRY_EXEC_OK;
342 } /* gen_snapshot */
343
344 /**
345 * validate snapshot's version.
346 */
validate_snapshot(char * input_file_path,char * output_file_path)347 EXECRES validate_snapshot(char* input_file_path, char* output_file_path) {
348 uint8_t* snapshot_data_p = snapshot_buffer;
349 int file_bytesize = 0;
350 OhosFree(input_file_path);
351 input_file_path = NULL;
352
353 EXECRES read_res = read_js_or_snapshot_file(output_file_path, snapshot_data_p, &file_bytesize, SNAPSHOT_BUFFER_SIZE);
354 if ((read_res != EXCE_ACE_JERRY_EXEC_OK) || (snapshot_data_p == NULL) || (file_bytesize == 0)) {
355 OhosFree(output_file_path);
356 output_file_path = NULL;
357 return EXCE_ACE_JERRY_READ_FILE_FAILED;
358 }
359 const jerry_snapshot_header_t* header_p = (const jerry_snapshot_header_t*) snapshot_data_p;
360 if (header_p->version != JERRY_SNAPSHOT_VERSION) {
361 OhosFree(output_file_path);
362 output_file_path = NULL;
363 return EXCE_ACE_JERRY_SNAPSHOT_VERSION_ERROR;
364 }
365 OhosFree(output_file_path);
366 output_file_path = NULL;
367 return EXCE_ACE_JERRY_EXEC_OK;
368 } /* validate_snapshot */
369
370 /**
371 * when visited file is a js file, transform it into snapshot or check its snapshot's version.
372 */
visit_js_file(char * input_file_path,EXECRES (* call_back)(char *,char *))373 EXECRES visit_js_file(char* input_file_path, EXECRES (*call_back)(char*, char*)) {
374 char* output_file_path = NULL;
375 if ((output_file_path = get_output_file_path(input_file_path)) == NULL) {
376 OhosFree(input_file_path);
377 input_file_path = NULL;
378 return EXCE_ACE_JERRY_SPLICE_OUTPUT_PATH_ERROR;
379 }
380 EXECRES res = call_back(input_file_path, output_file_path);
381 return res;
382 } /* visit_js_file */
383
384 /**
385 * visit one single list node.
386 */
visit_directory(dir_node ** end,char * current_path,EXECRES (* call_back)(char *,char *))387 EXECRES visit_directory(dir_node **end, char* current_path, EXECRES (*call_back)(char*, char*)) {
388 struct dirent* direntp = NULL;
389 struct stat file_stat = { 0 };
390 char* filename = NULL;
391 char* input_file_path = NULL;
392 DIR* dir = NULL;
393 if ((dir = (DIR*)opendir(current_path)) == NULL) {
394 return EXCE_ACE_JERRY_OPEN_DIR_FAILED;
395 }
396 while ((direntp = (struct dirent*)readdir(dir)) != NULL) {
397 filename = direntp->d_name;
398 if (strncmp(filename, ".", 1) == 0) {
399 continue;
400 }
401 if ((input_file_path = splice_path(current_path, filename)) == NULL) {
402 closedir(dir);
403 return EXCE_ACE_JERRY_SPLICE_PATH_ERROR;
404 }
405 if (stat(input_file_path, &file_stat) < 0) {
406 OhosFree(input_file_path);
407 input_file_path = NULL;
408 closedir(dir);
409 return EXCE_ACE_JERRY_GET_FILE_STAT_ERROR;
410 }
411 if (file_stat.st_mode & S_IFDIR) {
412 EXECRES add_directory_res = add_directory_to_pending_list(end, input_file_path);
413 if (add_directory_res != EXCE_ACE_JERRY_EXEC_OK) {
414 closedir(dir);
415 return add_directory_res;
416 }
417 } else if (is_template_file(filename, ".js")) {
418 EXECRES visit_js_res = visit_js_file(input_file_path, call_back);
419 if (visit_js_res != EXCE_ACE_JERRY_EXEC_OK) {
420 closedir(dir);
421 return visit_js_res;
422 }
423 } else {
424 OhosFree(input_file_path);
425 input_file_path = NULL;
426 }
427 }
428 closedir(dir);
429 return EXCE_ACE_JERRY_EXEC_OK;
430 } /* visit_directory */
431
432 /**
433 * visit directory from head list node.
434 */
visit_pending_directories(dir_node ** head,dir_node ** end,EXECRES (* call_back)(char *,char *))435 EXECRES visit_pending_directories(dir_node **head, dir_node **end, EXECRES (*call_back)(char*, char*)) {
436 dir_node* curr = NULL;
437 char* current_path = NULL;
438 while ((*head)->next != NULL) {
439 curr = (*head)->next;
440 current_path = curr->dir_name;
441 EXECRES visit_res = visit_directory(end, current_path, call_back);
442 if (visit_res != EXCE_ACE_JERRY_EXEC_OK) {
443 free_link(*head);
444 curr = NULL;
445 *end = NULL;
446 return visit_res;
447 }
448 (*head)->next = curr->next;
449 OhosFree(curr->dir_name);
450 curr->dir_name = NULL;
451 OhosFree(curr);
452 curr = NULL;
453 }
454 OhosFree(*head);
455 head = NULL;
456 end = NULL;
457 return EXCE_ACE_JERRY_EXEC_OK;
458 } /* visit_pending_directories */
459
460 /**
461 * visit directory and do js to snapshot conversion
462 */
generate_snapshots(char * filefolder)463 EXECRES generate_snapshots(char* filefolder) {
464 char* start_folder = NULL;
465 dir_node* head = NULL;
466 dir_node* end = NULL;
467
468 EXECRES init_res = init_directory_list(filefolder, start_folder, &head, &end);
469 if (init_res != EXCE_ACE_JERRY_EXEC_OK) {
470 return init_res;
471 }
472 EXECRES visit_res = visit_pending_directories(&head, &end, gen_snapshot);
473 if (visit_res != EXCE_ACE_JERRY_EXEC_OK) {
474 return visit_res;
475 }
476 return EXCE_ACE_JERRY_EXEC_OK;
477 } /* generate_snapshots */
478
479 /**
480 * visit directory and check snapshot file's version
481 */
validate_snapshots(char * filefolder)482 EXECRES validate_snapshots(char* filefolder) {
483 char* start_folder = NULL;
484 dir_node* head = NULL;
485 dir_node* end = NULL;
486
487 EXECRES init_res = init_directory_list(filefolder, start_folder, &head, &end);
488 if (init_res != EXCE_ACE_JERRY_EXEC_OK) {
489 return init_res;
490 }
491 EXECRES visit_res = visit_pending_directories(&head, &end, validate_snapshot);
492 if (visit_res != EXCE_ACE_JERRY_EXEC_OK) {
493 return visit_res;
494 }
495 return EXCE_ACE_JERRY_EXEC_OK;
496 } /* validate_snapshots */
497
498 /**
499 * visit directory and do js to bytecode conversion ON IAR
500 */
walk_directory(char * filefolder)501 EXECRES walk_directory(char* filefolder) {
502 EXECRES generate_res = generate_snapshots(filefolder);
503 if (generate_res != EXCE_ACE_JERRY_EXEC_OK) {
504 return generate_res;
505 }
506 #if defined (JERRY_ENABLE_SNAPSHOT_VERSION_CHECK) && (JERRY_ENABLE_SNAPSHOT_VERSION_CHECK == 1)
507 return validate_snapshots(filefolder);
508 #else
509 return EXCE_ACE_JERRY_EXEC_OK;
510 #endif
511 } /* walk_directory */
512
513 /**
514 * when convertion failed, traverse directory and delete all created bytecode files
515 */
walk_del_bytecode(char * filefolder)516 EXECRES walk_del_bytecode(char* filefolder) {
517 DIR* dir;
518 struct dirent* direntp;
519 struct stat file_stat = { 0 };
520 char* filename = NULL;
521 char* current_path = NULL;
522 char* input_file_path = NULL;
523 char* start_folder = NULL;
524 dir_node *head, *curr, *end, *new_node;
525 int filefolder_len = strlen(filefolder) + 1;
526
527 if ((filefolder == NULL) || (stat(filefolder, &file_stat) < 0)) {
528 return EXCE_ACE_JERRY_INPUT_PATH_ERROR;
529 }
530 if ((start_folder = (char*)OhosMalloc(MEM_TYPE_JERRY, filefolder_len)) == NULL) {
531 return EXCE_ACE_JERRY_MALLOC_ERROR;
532 }
533 if (strcpy_s(start_folder, filefolder_len, filefolder) != 0) {
534 OhosFree(start_folder);
535 start_folder = NULL;
536 return EXCE_ACE_JERRY_INPUT_PATH_ERROR;
537 }
538 if ((head = (dir_node*)OhosMalloc(MEM_TYPE_JERRY, sizeof(dir_node))) == NULL) {
539 OhosFree(start_folder);
540 start_folder = NULL;
541 return EXCE_ACE_JERRY_LINKLIST_ERROR;
542 }
543 if ((end = (dir_node*)OhosMalloc(MEM_TYPE_JERRY, sizeof(dir_node))) == NULL) {
544 OhosFree(start_folder);
545 start_folder = NULL;
546 OhosFree(head);
547 head = NULL;
548 return EXCE_ACE_JERRY_LINKLIST_ERROR;
549 }
550 head->dir_name = NULL;
551 head->next = end;
552 end->dir_name = start_folder;
553 end->next = NULL;
554
555 while (head->next != NULL) {
556 curr = head->next;
557 current_path = curr->dir_name;
558 if ((dir = (DIR*)opendir(current_path)) == NULL) {
559 free_link(head);
560 curr = NULL;
561 end = NULL;
562 return EXCE_ACE_JERRY_OPEN_DIR_FAILED;
563 }
564 while ((direntp = (struct dirent*)readdir(dir)) != NULL) {
565 filename = direntp->d_name;
566 if (strncmp(filename, ".", 1) == 0) {
567 continue;
568 }
569 if ((input_file_path = splice_path(current_path, filename)) == NULL) {
570 closedir(dir);
571 free_link(head);
572 curr = NULL;
573 end = NULL;
574 return EXCE_ACE_JERRY_SPLICE_PATH_ERROR;
575 }
576 if (stat(input_file_path, &file_stat) < 0) {
577 closedir(dir);
578 OhosFree(input_file_path);
579 input_file_path = NULL;
580 free_link(head);
581 curr = NULL;
582 end = NULL;
583 return EXCE_ACE_JERRY_GET_FILE_STAT_ERROR;
584 }
585 if (file_stat.st_mode & S_IFDIR) {
586 // file now is file folder
587 if ((new_node = (dir_node*)OhosMalloc(MEM_TYPE_JERRY, sizeof(dir_node))) == NULL) {
588 closedir(dir);
589 OhosFree(input_file_path);
590 input_file_path = NULL;
591 free_link(head);
592 curr = NULL;
593 end = NULL;
594 return EXCE_ACE_JERRY_LINKLIST_ERROR;
595 }
596 // input_file_path for dir will be freed when that node is freed
597 new_node->dir_name = input_file_path;
598 new_node->next = NULL;
599 end->next = new_node;
600 end = new_node;
601 new_node = NULL;
602 } else if ((is_template_file(filename, ".bc")) && (unlink(input_file_path) != F_OK)) {
603 //file now is .bc file and unlink file failed
604 closedir(dir);
605 OhosFree(input_file_path);
606 input_file_path = NULL;
607 free_link(head);
608 curr = NULL;
609 end = NULL;
610 return EXCE_ACE_JERRY_UNLINKFILE_ERROR;
611 } else {
612 OhosFree(input_file_path);
613 input_file_path = NULL;
614 }
615 }
616 closedir(dir);
617 head->next = curr->next;
618 OhosFree(curr->dir_name);
619 curr->dir_name = NULL;
620 OhosFree(curr);
621 curr = NULL;
622 }
623 OhosFree(head);
624 head = NULL;
625 end = NULL;
626 return EXCE_ACE_JERRY_EXEC_OK;
627 } /* walk_del_bytecode */
628
629 #endif // end JERRY_FOR_IAR_CONFIG
630