@@ -389,10 +389,9 @@ static void parsePatch(Binary *B, const Message &msg)
389389 */
390390static void parseEmit (Binary *B, const Message &msg)
391391{
392- size_t mapping_size = PAGE_SIZE;
393392 const char *filename = nullptr ;
394393 Format format = FORMAT_BINARY;
395- bool have_format = false , have_mapping_size = false , dup = false ;
394+ bool have_format = false , dup = false ;
396395 for (unsigned i = 0 ; i < msg.num_params ; i++)
397396 {
398397 switch (msg.params [i].name )
@@ -406,25 +405,13 @@ static void parseEmit(Binary *B, const Message &msg)
406405 format = (Format)msg.params [i].value .integer ;
407406 have_format = true ;
408407 break ;
409- case PARAM_MAPPING_SIZE:
410- dup = dup || have_mapping_size;
411- mapping_size = (size_t )msg.params [i].value .integer ;
412- have_mapping_size = true ;
413- break ;
414408 default :
415409 break ;
416410 }
417411 }
418412 if (filename == nullptr )
419413 error (" failed to parse \" emit\" message (id=%u); missing "
420414 " \" filename\" parameter" , msg.id );
421- if (mapping_size % PAGE_SIZE != 0 )
422- error (" failed to parse \" emit\" message (id=%u); mapping size "
423- " must be a multiple of the page size (%u), found %zu" , msg.id ,
424- PAGE_SIZE, mapping_size);
425- if ((mapping_size & (mapping_size - 1 )) != 0 )
426- error (" failed to parse \" emit\" message (id=%u); mapping size "
427- " must be a power-of-two, found %zu" , msg.id , mapping_size);
428415 if (dup)
429416 error (" failed to parse \" emit\" message (id=%u); duplicate "
430417 " parameters detected" );
@@ -436,12 +423,12 @@ static void parseEmit(Binary *B, const Message &msg)
436423
437424 // Create and optimize the mappings:
438425 MappingSet mappings;
439- buildMappings (B->allocator , mapping_size , mappings);
426+ buildMappings (B->allocator , option_mem_mapping_size , mappings);
440427 optimizeMappings (mappings);
441428 putchar (' \n ' );
442429
443430 // Create the patched binary:
444- B->patched .size = emitElf (B, mappings, mapping_size );
431+ B->patched .size = emitElf (B, mappings, option_mem_mapping_size );
445432
446433 // Emit the result:
447434 switch (format)
@@ -634,41 +621,15 @@ static void parseTrampoline(Binary *B, const Message &msg)
634621 */
635622static void parseOptions (const Message &msg)
636623{
637- bool disable_B1 = false , disable_B2 = false ,
638- disable_T1 = false , disable_T2 = false ,
639- disable_T3 = false ;
640- bool have_disable_B1 = false , have_disable_B2 = false ,
641- have_disable_T1 = false , have_disable_T2 = false ,
642- have_disable_T3 = false ;
624+ char **argv = nullptr ;
643625 bool dup = false ;
644626 for (unsigned i = 0 ; i < msg.num_params ; i++)
645627 {
646628 switch (msg.params [i].name )
647629 {
648- case PARAM_OPTION_DISABLE_B1:
649- dup = dup || have_disable_B1;
650- disable_B1 = msg.params [i].value .boolean ;
651- have_disable_B1 = true ;
652- break ;
653- case PARAM_OPTION_DISABLE_B2:
654- dup = dup || have_disable_B2;
655- disable_B2 = msg.params [i].value .boolean ;
656- have_disable_B2 = true ;
657- break ;
658- case PARAM_OPTION_DISABLE_T1:
659- dup = dup || have_disable_T1;
660- disable_T1 = msg.params [i].value .boolean ;
661- have_disable_T1 = true ;
662- break ;
663- case PARAM_OPTION_DISABLE_T2:
664- dup = dup || have_disable_T2;
665- disable_T2 = msg.params [i].value .boolean ;
666- have_disable_T2 = true ;
667- break ;
668- case PARAM_OPTION_DISABLE_T3:
669- dup = dup || have_disable_T3;
670- disable_T3 = msg.params [i].value .boolean ;
671- have_disable_T3 = true ;
630+ case PARAM_ARGV:
631+ dup = dup || (argv != nullptr );
632+ argv = msg.params [i].value .strings ;
672633 break ;
673634 default :
674635 break ;
@@ -677,16 +638,11 @@ static void parseOptions(const Message &msg)
677638 if (dup)
678639 error (" failed to parse \" option\" message (id=%u); duplicate "
679640 " parameters detected" , msg.id );
680- if (have_disable_B1)
681- option_tactic_B1 = !disable_B1;
682- if (have_disable_B2)
683- option_tactic_B2 = !disable_B2;
684- if (have_disable_T1)
685- option_tactic_T1 = !disable_T1;
686- if (have_disable_T2)
687- option_tactic_T2 = !disable_T2;
688- if (have_disable_T3)
689- option_tactic_T3 = !disable_T3;
641+ int argc;
642+ for (argc = 0 ; argv[argc] != nullptr ; argc++)
643+ ;
644+ parseOptions (argc, argv, /* api=*/ true );
645+ delete[] argv;
690646}
691647
692648/*
0 commit comments