* This file is part of the MindStudio project.
* Copyright (c) 2025 Huawei Technologies Co.,Ltd.
*
* MindStudio is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
*
* http://license.coscl.org.cn/MulanPSL2
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* ------------------------------------------------------------------------- */
#ifndef CORE_FRAMEWORK_PROCESS_H
#define CORE_FRAMEWORK_PROCESS_H
#include <functional>
#include <memory>
#include "config.h"
#include "communication.h"
namespace Sanitizer {
struct ExecCmd {
explicit ExecCmd(std::vector<std::string> const &args);
std::string const &ExecPath(void) const;
char *const *ExecArgv(void) const;
private:
std::string path_;
int argc_;
std::vector<char*> argv_;
std::vector<std::string> args_;
};
class Process {
public:
using MsgRspFunc = std::function<void(const std::string&)>;
using ANALYSIS_FUNC = std::function<void(const std::string&, MsgRspFunc&)>;
using ClientId = std::size_t;
explicit Process(Config const &config) : config_{config}, mainPid_(getpid()) {}
void Launch(const ExecCmd& cmd);
void RegisterMsgTrap(const ANALYSIS_FUNC& analysisFunc, const std::string &socketPath);
std::string CreateSockPath() const;
private:
void PreProcess(Config const &config);
void PostProcess(pid_t child, ExecCmd const &cmd);
void DoLaunch(const ExecCmd& cmd) const;
private:
Config config_;
pid_t mainPid_;
std::shared_ptr<CommunicationServer> server_;
};
}
#endif