process.cc (13867:9b10bbcf0543) | process.cc (13894:8603648c1679) |
---|---|
1/* 2 * Copyright (c) 2014 Advanced Micro Devices, Inc. 3 * Copyright (c) 2007 The Hewlett-Packard Development Company 4 * All rights reserved. 5 * 6 * The license below extends only to copyright in the software and shall 7 * not be construed as granting a license to any other intellectual 8 * property including but not limited to intellectual property relating --- 748 unchanged lines hidden (view full) --- 757 758template<class IntType> 759void 760X86Process::argsInit(int pageSize, 761 std::vector<AuxVector<IntType> > extraAuxvs) 762{ 763 int intSize = sizeof(IntType); 764 | 1/* 2 * Copyright (c) 2014 Advanced Micro Devices, Inc. 3 * Copyright (c) 2007 The Hewlett-Packard Development Company 4 * All rights reserved. 5 * 6 * The license below extends only to copyright in the software and shall 7 * not be construed as granting a license to any other intellectual 8 * property including but not limited to intellectual property relating --- 748 unchanged lines hidden (view full) --- 757 758template<class IntType> 759void 760X86Process::argsInit(int pageSize, 761 std::vector<AuxVector<IntType> > extraAuxvs) 762{ 763 int intSize = sizeof(IntType); 764 |
765 typedef AuxVector<IntType> auxv_t; 766 std::vector<auxv_t> auxv = extraAuxvs; | 765 std::vector<AuxVector<IntType>> auxv = extraAuxvs; |
767 768 string filename; 769 if (argv.size() < 1) 770 filename = ""; 771 else 772 filename = argv[0]; 773 774 // We want 16 byte alignment --- 79 unchanged lines hidden (view full) --- 854// X86_CPUSelfSnoop | 855// X86_HyperThreading | 856// X86_AutomaticClockControl | 857// X86_IA64Processor | 858 0; 859 860 // Bits which describe the system hardware capabilities 861 // XXX Figure out what these should be | 766 767 string filename; 768 if (argv.size() < 1) 769 filename = ""; 770 else 771 filename = argv[0]; 772 773 // We want 16 byte alignment --- 79 unchanged lines hidden (view full) --- 853// X86_CPUSelfSnoop | 854// X86_HyperThreading | 855// X86_AutomaticClockControl | 856// X86_IA64Processor | 857 0; 858 859 // Bits which describe the system hardware capabilities 860 // XXX Figure out what these should be |
862 auxv.push_back(auxv_t(M5_AT_HWCAP, features)); | 861 auxv.emplace_back(M5_AT_HWCAP, features); |
863 // The system page size | 862 // The system page size |
864 auxv.push_back(auxv_t(M5_AT_PAGESZ, X86ISA::PageBytes)); | 863 auxv.emplace_back(M5_AT_PAGESZ, X86ISA::PageBytes); |
865 // Frequency at which times() increments 866 // Defined to be 100 in the kernel source. | 864 // Frequency at which times() increments 865 // Defined to be 100 in the kernel source. |
867 auxv.push_back(auxv_t(M5_AT_CLKTCK, 100)); | 866 auxv.emplace_back(M5_AT_CLKTCK, 100); |
868 // This is the virtual address of the program header tables if they 869 // appear in the executable image. | 867 // This is the virtual address of the program header tables if they 868 // appear in the executable image. |
870 auxv.push_back(auxv_t(M5_AT_PHDR, elfObject->programHeaderTable())); | 869 auxv.emplace_back(M5_AT_PHDR, elfObject->programHeaderTable()); |
871 // This is the size of a program header entry from the elf file. | 870 // This is the size of a program header entry from the elf file. |
872 auxv.push_back(auxv_t(M5_AT_PHENT, elfObject->programHeaderSize())); | 871 auxv.emplace_back(M5_AT_PHENT, elfObject->programHeaderSize()); |
873 // This is the number of program headers from the original elf file. | 872 // This is the number of program headers from the original elf file. |
874 auxv.push_back(auxv_t(M5_AT_PHNUM, elfObject->programHeaderCount())); | 873 auxv.emplace_back(M5_AT_PHNUM, elfObject->programHeaderCount()); |
875 // This is the base address of the ELF interpreter; it should be 876 // zero for static executables or contain the base address for 877 // dynamic executables. | 874 // This is the base address of the ELF interpreter; it should be 875 // zero for static executables or contain the base address for 876 // dynamic executables. |
878 auxv.push_back(auxv_t(M5_AT_BASE, getBias())); | 877 auxv.emplace_back(M5_AT_BASE, getBias()); |
879 // XXX Figure out what this should be. | 878 // XXX Figure out what this should be. |
880 auxv.push_back(auxv_t(M5_AT_FLAGS, 0)); | 879 auxv.emplace_back(M5_AT_FLAGS, 0); |
881 // The entry point to the program | 880 // The entry point to the program |
882 auxv.push_back(auxv_t(M5_AT_ENTRY, objFile->entryPoint())); | 881 auxv.emplace_back(M5_AT_ENTRY, objFile->entryPoint()); |
883 // Different user and group IDs | 882 // Different user and group IDs |
884 auxv.push_back(auxv_t(M5_AT_UID, uid())); 885 auxv.push_back(auxv_t(M5_AT_EUID, euid())); 886 auxv.push_back(auxv_t(M5_AT_GID, gid())); 887 auxv.push_back(auxv_t(M5_AT_EGID, egid())); | 883 auxv.emplace_back(M5_AT_UID, uid()); 884 auxv.emplace_back(M5_AT_EUID, euid()); 885 auxv.emplace_back(M5_AT_GID, gid()); 886 auxv.emplace_back(M5_AT_EGID, egid()); |
888 // Whether to enable "secure mode" in the executable | 887 // Whether to enable "secure mode" in the executable |
889 auxv.push_back(auxv_t(M5_AT_SECURE, 0)); | 888 auxv.emplace_back(M5_AT_SECURE, 0); |
890 // The address of 16 "random" bytes. | 889 // The address of 16 "random" bytes. |
891 auxv.push_back(auxv_t(M5_AT_RANDOM, 0)); | 890 auxv.emplace_back(M5_AT_RANDOM, 0); |
892 // The name of the program | 891 // The name of the program |
893 auxv.push_back(auxv_t(M5_AT_EXECFN, 0)); | 892 auxv.emplace_back(M5_AT_EXECFN, 0); |
894 // The platform string | 893 // The platform string |
895 auxv.push_back(auxv_t(M5_AT_PLATFORM, 0)); | 894 auxv.emplace_back(M5_AT_PLATFORM, 0); |
896 } 897 898 // Figure out how big the initial stack needs to be 899 900 // A sentry NULL void pointer at the top of the stack. 901 int sentry_size = intSize; 902 903 // This is the name of the file which is present on the initial stack --- 97 unchanged lines hidden (view full) --- 1001 // Write out the sentry void * 1002 IntType sentry_NULL = 0; 1003 initVirtMem.writeBlob(sentry_base, (uint8_t*)&sentry_NULL, sentry_size); 1004 1005 // Write the file name 1006 initVirtMem.writeString(file_name_base, filename.c_str()); 1007 1008 // Fix up the aux vectors which point to data | 895 } 896 897 // Figure out how big the initial stack needs to be 898 899 // A sentry NULL void pointer at the top of the stack. 900 int sentry_size = intSize; 901 902 // This is the name of the file which is present on the initial stack --- 97 unchanged lines hidden (view full) --- 1000 // Write out the sentry void * 1001 IntType sentry_NULL = 0; 1002 initVirtMem.writeBlob(sentry_base, (uint8_t*)&sentry_NULL, sentry_size); 1003 1004 // Write the file name 1005 initVirtMem.writeString(file_name_base, filename.c_str()); 1006 1007 // Fix up the aux vectors which point to data |
1009 assert(auxv[auxv.size() - 3].getHostAuxType() == M5_AT_RANDOM); 1010 auxv[auxv.size() - 3].setAuxVal(aux_data_base); 1011 assert(auxv[auxv.size() - 2].getHostAuxType() == M5_AT_EXECFN); 1012 auxv[auxv.size() - 2].setAuxVal(argv_array_base); 1013 assert(auxv[auxv.size() - 1].getHostAuxType() == M5_AT_PLATFORM); 1014 auxv[auxv.size() - 1].setAuxVal(aux_data_base + numRandomBytes); | 1008 assert(auxv[auxv.size() - 3].type == M5_AT_RANDOM); 1009 auxv[auxv.size() - 3].val = aux_data_base; 1010 assert(auxv[auxv.size() - 2].type == M5_AT_EXECFN); 1011 auxv[auxv.size() - 2].val = argv_array_base; 1012 assert(auxv[auxv.size() - 1].type == M5_AT_PLATFORM); 1013 auxv[auxv.size() - 1].val = aux_data_base + numRandomBytes; |
1015 1016 1017 // Copy the aux stuff | 1014 1015 1016 // Copy the aux stuff |
1018 for (int x = 0; x < auxv.size(); x++) { 1019 initVirtMem.writeBlob(auxv_array_base + x * 2 * intSize, 1020 (uint8_t*)&(auxv[x].getAuxType()), 1021 intSize); 1022 initVirtMem.writeBlob(auxv_array_base + (x * 2 + 1) * intSize, 1023 (uint8_t*)&(auxv[x].getAuxVal()), 1024 intSize); | 1017 Addr auxv_array_end = auxv_array_base; 1018 for (const auto &aux: auxv) { 1019 initVirtMem.write(auxv_array_end, aux, GuestByteOrder); 1020 auxv_array_end += sizeof(aux); |
1025 } 1026 // Write out the terminating zeroed auxiliary vector | 1021 } 1022 // Write out the terminating zeroed auxiliary vector |
1027 const uint64_t zero = 0; 1028 initVirtMem.writeBlob(auxv_array_base + auxv.size() * 2 * intSize, 1029 (uint8_t*)&zero, intSize); 1030 initVirtMem.writeBlob(auxv_array_base + (auxv.size() * 2 + 1) * intSize, 1031 (uint8_t*)&zero, intSize); | 1023 const AuxVector<uint64_t> zero(0, 0); 1024 initVirtMem.write(auxv_array_end, zero); 1025 auxv_array_end += sizeof(zero); |
1032 1033 initVirtMem.writeString(aux_data_base, platform.c_str()); 1034 1035 copyStringArray(envp, envp_array_base, env_data_base, initVirtMem); 1036 copyStringArray(argv, argv_array_base, arg_data_base, initVirtMem); 1037 1038 initVirtMem.writeBlob(argc_base, (uint8_t*)&guestArgc, intSize); 1039 --- 8 unchanged lines hidden (view full) --- 1048 // Align the "stack_min" to a page boundary. 1049 memState->setStackMin(roundDown(stack_min, pageSize)); 1050} 1051 1052void 1053X86_64Process::argsInit(int pageSize) 1054{ 1055 std::vector<AuxVector<uint64_t> > extraAuxvs; | 1026 1027 initVirtMem.writeString(aux_data_base, platform.c_str()); 1028 1029 copyStringArray(envp, envp_array_base, env_data_base, initVirtMem); 1030 copyStringArray(argv, argv_array_base, arg_data_base, initVirtMem); 1031 1032 initVirtMem.writeBlob(argc_base, (uint8_t*)&guestArgc, intSize); 1033 --- 8 unchanged lines hidden (view full) --- 1042 // Align the "stack_min" to a page boundary. 1043 memState->setStackMin(roundDown(stack_min, pageSize)); 1044} 1045 1046void 1047X86_64Process::argsInit(int pageSize) 1048{ 1049 std::vector<AuxVector<uint64_t> > extraAuxvs; |
1056 extraAuxvs.push_back(AuxVector<uint64_t>(M5_AT_SYSINFO_EHDR, 1057 vsyscallPage.base)); | 1050 extraAuxvs.emplace_back(M5_AT_SYSINFO_EHDR, vsyscallPage.base); |
1058 X86Process::argsInit<uint64_t>(pageSize, extraAuxvs); 1059} 1060 1061void 1062I386Process::argsInit(int pageSize) 1063{ 1064 std::vector<AuxVector<uint32_t> > extraAuxvs; 1065 //Tell the binary where the vsyscall part of the vsyscall page is. | 1051 X86Process::argsInit<uint64_t>(pageSize, extraAuxvs); 1052} 1053 1054void 1055I386Process::argsInit(int pageSize) 1056{ 1057 std::vector<AuxVector<uint32_t> > extraAuxvs; 1058 //Tell the binary where the vsyscall part of the vsyscall page is. |
1066 extraAuxvs.push_back(AuxVector<uint32_t>(M5_AT_SYSINFO, 1067 vsyscallPage.base + vsyscallPage.vsyscallOffset)); 1068 extraAuxvs.push_back(AuxVector<uint32_t>(M5_AT_SYSINFO_EHDR, 1069 vsyscallPage.base)); | 1059 extraAuxvs.emplace_back(M5_AT_SYSINFO, 1060 vsyscallPage.base + vsyscallPage.vsyscallOffset); 1061 extraAuxvs.emplace_back(M5_AT_SYSINFO_EHDR, vsyscallPage.base); |
1070 X86Process::argsInit<uint32_t>(pageSize, extraAuxvs); 1071} 1072 1073void 1074X86Process::setSyscallReturn(ThreadContext *tc, SyscallReturn retval) 1075{ 1076 tc->setIntReg(INTREG_RAX, retval.encodedValue()); 1077} --- 55 unchanged lines hidden --- | 1062 X86Process::argsInit<uint32_t>(pageSize, extraAuxvs); 1063} 1064 1065void 1066X86Process::setSyscallReturn(ThreadContext *tc, SyscallReturn retval) 1067{ 1068 tc->setIntReg(INTREG_RAX, retval.encodedValue()); 1069} --- 55 unchanged lines hidden --- |