TAFactory();
bool checkIfTARunning(TEEC_UUID TAUUID);
TAInstancePtr createUninitalizedTAInstance(TEEC_UUID TAUUID, ISession* session);
- bool launchTA(TEEC_UUID TAUUID, std::stringstream& str, bool debug, pid_t& pid);
+ bool launchTA(TEEC_UUID TAUUID, std::stringstream& str, pid_t& pid, bool &debug);
+ bool launchTAInDebugMode(uint32_t port, string image_path,
+ string argument, pthread_mutex_t &lock, pid_t &pid);
+
static void* waitForChild(void *pid);
void cleanupTAInstance(pid_t PID);
~TAFactory();
// Initialize PID to -1
pid_t pid = -1;
// Set default values for TA configuration variables
- bool debug = false;
bool alive = false;
+ bool debug;
bool singleInst = false;
TEEC_Result result = TEEC_ERROR_COMMUNICATION;
str << uuidStr << "-";
str << InstID;
- if (launchTA(TAUUID, str, debug, pid)) {
+ if (launchTA(TAUUID, str, pid, debug)) {
// TA is launched successfully, Create a new instance of TAInstance class
/* Check if TA is to be keep alive and accordingly set TAInstance's
* @param debug debug flag
* @param pid PID to be update for launched TA
*/
-bool TAFactory::launchTA(TEEC_UUID TAUUID, std::stringstream& str, bool debug,
- pid_t& pid) {
+bool TAFactory::launchTA(TEEC_UUID TAUUID, std::stringstream& str, pid_t& pid, bool &debug) {
int32_t result = -1;
pthread_t thread;
boost::optional<uint32_t> debugPort;
try {
debugPort = UUIDConf->at(TAUUID)->getDebugPort();
+ debug = true;
} catch (std::out_of_range) {
debugPort = boost::none;
+ debug = false;
}
pthread_mutex_lock(&TABin->taLock);
//Check if the TA is to be launched in debug mode or release mode
if (debugPort != boost::none) { // DEBUG MODE
- debug = true;
- char *argv[5];
- string argvGDB = "/usr/bin/gdbserver";
- string argvHost = "localhost:" + std::to_string(*debugPort);
-
- argv[0] = &argvGDB[0];
- argv[1] = &argvHost[0];
- argv[2] = &argvPath[0];
- argv[3] = &argvName[0];
- argv[4] = NULL;
-
- // fork TA with GDB
- pid = fork();
- if (0 == pid) {
- LOGD(MODULE_SIM_DAEMON, "In Child Process");
- execv(argv[0], argv);
- LOGE(MODULE_SIM_DAEMON, "Launching Trusted Application FAILED");
- pthread_mutex_unlock(&TABin->taLock);
+ bool launched = this->launchTAInDebugMode(
+ *debugPort, argvPath, argvName, TABin->taLock, pid);
+ if (!launched)
return false;
- }
- LOGD(MODULE_SIM_DAEMON, "In Parent Process");
} else { //RELEASE MODE
char *argv[3];
argv[0] = &argvPath[0];
return true;
}
+bool TAFactory::launchTAInDebugMode(uint32_t port, string image_path,
+ string argument, pthread_mutex_t &lock, pid_t &pid)
+{
+ char *argv[5];
+ string gdbserver = "/usr/bin/gdbserver";
+ string port_str = "localhost:" + std::to_string(port);
+
+ argv[0] = &gdbserver[0];
+ argv[1] = &port_str[0];
+ argv[2] = &image_path[0];
+ argv[3] = &argument[0];
+ argv[4] = NULL;
+
+ // fork TA with GDB
+ pid = fork();
+ if (0 == pid) {
+ LOGD(MODULE_SIM_DAEMON, "In Child Process");
+ execv(argv[0], argv);
+ LOGE(MODULE_SIM_DAEMON, "Launching Trusted Application FAILED");
+ pthread_mutex_unlock(&lock);
+ return false;
+ }
+ LOGD(MODULE_SIM_DAEMON, "In Parent Process");
+ return true;
+}
+
TAFactory::~TAFactory() {
/* Destroy the locks created for TAInstance map (mTAInstanceMap), Instance
* Id (InstID) and TA Factory Instance (instance)