Subversion Repositories QNX 8.QNX8 IFS tool

Rev

Rev 42 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 42 Rev 43
Line 889... Line 889...
889
   ((bootargs_entry_t *) bootargs_buffer.bytes)->argc = (uint8_t) exe_cmdline->count;
889
   ((bootargs_entry_t *) bootargs_buffer.bytes)->argc = (uint8_t) exe_cmdline->count;
890
   ((bootargs_entry_t *) bootargs_buffer.bytes)->envc = (uint8_t) exe_env->count;
890
   ((bootargs_entry_t *) bootargs_buffer.bytes)->envc = (uint8_t) exe_env->count;
891
   ((bootargs_entry_t *) bootargs_buffer.bytes)->shdr_addr = WILL_BE_FILLED_LATER; // same value as startup_header.image_paddr (which is not set yet) (TODO: support 64-bit shdr_addr offsets -- see comment in bootargs_entry_t struct)
891
   ((bootargs_entry_t *) bootargs_buffer.bytes)->shdr_addr = WILL_BE_FILLED_LATER; // same value as startup_header.image_paddr (which is not set yet) (TODO: support 64-bit shdr_addr offsets -- see comment in bootargs_entry_t struct)
892
   for (array_index = 0; array_index < exe_cmdline->count; array_index++)
892
   for (array_index = 0; array_index < exe_cmdline->count; array_index++)
893
      ASSERT_WITH_ERRNO (Buffer_Append (&bootargs_buffer, exe_cmdline->args[array_index], strlen (exe_cmdline->args[array_index]) + 1)); // append string including NUL terminator
893
      ASSERT_WITH_ERRNO (Buffer_Append (&bootargs_buffer, exe_cmdline->args[array_index], strlen (exe_cmdline->args[array_index]) + 1)); // append string including NUL terminator
894
   for (array_index = 0; array_index < global_envp.count; array_index++)
-
 
895
      ASSERT_WITH_ERRNO (Buffer_Append (&bootargs_buffer, global_envp.args[array_index], strlen (global_envp.args[array_index]) + 1)); // append string including NUL terminator
-
 
896
   for (array_index = 0; array_index < exe_env->count; array_index++)
894
   for (array_index = 0; array_index < exe_env->count; array_index++)
897
      ASSERT_WITH_ERRNO (Buffer_Append (&bootargs_buffer, exe_env->args[array_index], strlen (exe_env->args[array_index]) + 1)); // append string including NUL terminator
895
      ASSERT_WITH_ERRNO (Buffer_Append (&bootargs_buffer, exe_env->args[array_index], strlen (exe_env->args[array_index]) + 1)); // append string including NUL terminator
898
   ((bootargs_entry_t *) bootargs_buffer.bytes)->size_hi = (uint8_t) ((bootargs_buffer.size >> 8) & 0xff);
896
   ((bootargs_entry_t *) bootargs_buffer.bytes)->size_hi = (uint8_t) ((bootargs_buffer.size >> 8) & 0xff);
899
   ((bootargs_entry_t *) bootargs_buffer.bytes)->size_lo = (uint8_t) ((bootargs_buffer.size >> 0) & 0xff);
897
   ((bootargs_entry_t *) bootargs_buffer.bytes)->size_lo = (uint8_t) ((bootargs_buffer.size >> 0) & 0xff);
900
   *bootargs_offset = (size_t) exeargs_location - (size_t) out_buffer->bytes; // compute the boot args offset
898
   *bootargs_offset = (size_t) exeargs_location - (size_t) out_buffer->bytes; // compute the boot args offset
Line 909... Line 907...
909
{
907
{
910
   static thread_local char *candidate_pathname = NULL;
908
   static thread_local char *candidate_pathname = NULL;
911
   static thread_local parms_t default_parms = { 0 };
909
   static thread_local parms_t default_parms = { 0 };
912
   static thread_local stringarray_t aps_partnames = { NULL, 0 };
910
   static thread_local stringarray_t aps_partnames = { NULL, 0 };
913
   static int inode_count = 0; // will be preincremented each time this function is called
911
   static int inode_count = 0; // will be preincremented each time this function is called
-
 
912
 
-
 
913
   static const char *preserved_kernel_sections[] = { "QNX_info" };
914
 
914
 
915
   typedef struct scriptcmd_s
915
   typedef struct scriptcmd_s
916
   {
916
   {
917
      char *argv0;
917
      char *argv0;
918
      int cpu_number;
918
      int cpu_number;
Line 928... Line 928...
928
   scriptcmd_t default_scriptcmd_params = { NULL, -1, false, -1, -1, -1, false, false, false };
928
   scriptcmd_t default_scriptcmd_params = { NULL, -1, false, -1, -1, -1, false, false, false };
929
   scriptcmd_t current_scriptcmd_params = { 0 };
929
   scriptcmd_t current_scriptcmd_params = { 0 };
930
   stringarray_t global_argv = { NULL, 0 };
930
   stringarray_t global_argv = { NULL, 0 };
931
   stringarray_t line_argv = { NULL, 0 };
931
   stringarray_t line_argv = { NULL, 0 };
932
   stringarray_t line_envp = { NULL, 0 };
932
   stringarray_t line_envp = { NULL, 0 };
933
//   stringarray_t linker_argv = { NULL, 0 };
-
 
934
   const char *stored_pathname_without_leading_slash;
933
   const char *stored_pathname_without_leading_slash;
935
   const char *original_stored_pathname = NULL;
934
   const char *original_stored_pathname = NULL;
936
   const char *filename_bit;
935
   const char *filename_bit;
937
   buffer_t current_line;
936
   buffer_t current_line;
938
   buffer_t compiled_script;
937
   buffer_t compiled_script;
Line 1152... Line 1151...
1152
            {
1151
            {
1153
               if (startup_argv.args == NULL)
1152
               if (startup_argv.args == NULL)
1154
               {
1153
               {
1155
                  startup_argv.args = line_argv.args; // relocate these pointers to the right place
1154
                  startup_argv.args = line_argv.args; // relocate these pointers to the right place
1156
                  startup_argv.count = line_argv.count;
1155
                  startup_argv.count = line_argv.count;
-
 
1156
                  STRINGARRAY_FREE (&startup_envp);
-
 
1157
                  for (array_index = 0; array_index < global_envp.count; array_index++)
1157
                  startup_envp.args = line_envp.args; // relocate these pointers to the right place
1158
                     STRINGARRAY_PUSH (&startup_envp, global_envp.args[array_index]); // concatenate the global environment to the executable environment
1158
                  startup_envp.count = line_envp.count;
1159
                  for (array_index = 0; array_index < line_envp.count; array_index++)
-
 
1160
                     STRINGARRAY_PUSH (&startup_envp, line_envp.args[array_index]); // concatenate the local environment to the executable environment
1159
               }
1161
               }
1160
               else
1162
               else
1161
               {
1163
               {
1162
                  STRINGARRAY_FREE (&procnto_argv); // if procnto's argv was already assigned, free the previous array as we'll be replacing it with a new one
1164
                  STRINGARRAY_FREE (&procnto_argv); // if procnto's argv was already assigned, free the previous array as we'll be replacing it with a new one
1163
                  procnto_argv.args = line_argv.args; // relocate these pointers to the right place
1165
                  procnto_argv.args = line_argv.args; // relocate these pointers to the right place
1164
                  procnto_argv.count = line_argv.count;
1166
                  procnto_argv.count = line_argv.count;
1165
                  STRINGARRAY_FREE (&procnto_envp); // if procnto's envp was already assigned, free the previous array as we'll be replacing it with a new one
1167
                  STRINGARRAY_FREE (&procnto_envp); // if procnto's envp was already assigned, free the previous array as we'll be replacing it with a new one
-
 
1168
                  for (array_index = 0; array_index < global_envp.count; array_index++)
1166
                  procnto_envp.args = line_envp.args; // relocate these pointers to the right place
1169
                     STRINGARRAY_PUSH (&procnto_envp, global_envp.args[array_index]); // concatenate the global environment to the executable environment
1167
                  procnto_envp.count = line_envp.count;
1170
                  for (array_index = 0; array_index < line_envp.count; array_index++)
-
 
1171
                     STRINGARRAY_PUSH (&procnto_envp, line_envp.args[array_index]); // concatenate the local environment to the executable environment
1168
               }
1172
               }
1169
               line_argv.args = NULL; // void the line_argv array so as to not free it as we stole its args pointers
1173
               line_argv.args = NULL; // void the line_argv array so as to not free it as we stole its args pointers
1170
               line_argv.count = 0;
1174
               line_argv.count = 0;
1171
               line_envp.args = NULL; // void the line_envp array so as to not free it as we stole its args pointers
-
 
1172
               line_envp.count = 0;
-
 
1173
            }
1175
            }
1174
            else // this line contained no executable invokation, so stack up its envp assignations into the global envp array
1176
            else // this line contained no executable invokation, so stack up its envp assignations into the global envp array
1175
               for (array_index = 0; array_index < line_envp.count; array_index++)
1177
               for (array_index = 0; array_index < line_envp.count; array_index++)
1176
                  STRINGARRAY_PUSH (&global_envp, line_envp.args[array_index]);
1178
                  STRINGARRAY_PUSH (&global_envp, line_envp.args[array_index]);
1177
 
1179
 
Line 1196... Line 1198...
1196
                  &procnto_argv, &procnto_envp, // executable arguments (including its name) and environment to stamp in it
1198
                  &procnto_argv, &procnto_envp, // executable arguments (including its name) and environment to stamp in it
1197
                  entry_parms->should_keep_ld_output, // whether to keep the linker-produced output file
1199
                  entry_parms->should_keep_ld_output, // whether to keep the linker-produced output file
1198
                  &entry_parms->data, // buffer where to save the output
1200
                  &entry_parms->data, // buffer where to save the output
1199
                  &procnto_bootargs_offset); // where to save the offset of the boot arguments
1201
                  &procnto_bootargs_offset); // where to save the offset of the boot arguments
1200
 
1202
 
1201
         // strip this prelinked ELF file from all the sections we don't need
1203
         // strip this prelinked ELF file from all the sections we don't need: only keep the QNX_info one
1202
         ASSERT_WITH_ERRNO (Buffer_StripELFFile (&entry_parms->data, NULL, 0, true, procnto_argv.args[0])); // strip procnto as per QNX docs (align the segment size in file with the size it occupies in memory)
1204
         ASSERT_WITH_ERRNO (Buffer_StripELFFile (&entry_parms->data, preserved_kernel_sections, sizeof (preserved_kernel_sections) / sizeof (preserved_kernel_sections[0]), true, procnto_argv.args[0])); // strip procnto as per QNX docs (align the segment size in file with the size it occupies in memory)
1203
 
1205
 
1204
         sprintf_s (candidate_pathname, MAXPATHLEN, "%s/%s", (entry_parms->prefix != NULL ? entry_parms->prefix : ""), procnto_argv.args[0]); // fix the entry name
1206
         sprintf_s (candidate_pathname, MAXPATHLEN, "%s/%s", (entry_parms->prefix != NULL ? entry_parms->prefix : ""), procnto_argv.args[0]); // fix the entry name
1205
         stored_pathname = candidate_pathname;
1207
         stored_pathname = candidate_pathname;
1206
 
1208
 
1207
         entry_parms->extra_ino_flags |= IFS_INO_PROCESSED_ELF | IFS_INO_BOOTSTRAP_EXE; // mark this inode as a preprocessed *bootstrap* ELF file
1209
         entry_parms->extra_ino_flags |= IFS_INO_PROCESSED_ELF | IFS_INO_BOOTSTRAP_EXE; // mark this inode as a preprocessed *bootstrap* ELF file