CC := gcc
CPP := g++
-COMM_FLAGS := -Wall -g -O0
+COMM_FLAGS := -Wall -g -O0 -Werror
DEBUG_FLAGS = \
-DDEBUG \
INCLUDE := \
-Iinclude/generated \
+ -I. \
-I/usr/include \
-I/usr/include/system \
-I/usr/include/capi-system-info \
-I/usr/include/efl-1 \
-I/usr/include/json-c \
-I/usr/include/eo-1
+
+INCLUDE_CPP := \
+ -I. \
+ -Icpp
+
# CALL_MNGR
ifeq ($(CALL_MNGR),y)
INCLUDE += -I/usr/include/call-manager/
# compiler flags
CFLAGS := $(FLAGS)
-CPPFLAGS := $(FLAGS) -std=c++0x -I. -Icpp
+CPPFLAGS := $(FLAGS) $(INCLUDE_CPP) -std=c++0x
# linker flags
LDFLAGS := \
strEnd = strBegin + dataStr->size;
- for (int i = 0; i < relCnt; ++i) {
+ for (size_t i = 0; i < relCnt; ++i) {
if (ELF32_R_TYPE(rel[i].r_info) == jump_slot) {
uint32_t offset = rel[i].r_offset;
uint32_t symId = ELF32_R_SYM(rel[i].r_info);
uint32_t addr, n0, n1, n2, offset, rorN;
- for (int i = 0, step = 0; i < instCnt; ++i) {
+ for (size_t i = 0, step = 0; i < instCnt; ++i) {
uint32_t p = inst[i] & 0xfffff000;
switch (step) {
}
// populate addrs
- for (int i = 0; i < cnt; ++i) {
+ for (size_t i = 0; i < cnt; ++i) {
FuncMap::const_iterator it = funcMap.find(names[i]);
addrs[i] = it == funcMap.end() ? 0 : it->second;
}
{
std::string str;
- for (int i = 0; i < sizeof(uint64_t) * 8; ++i) {
+ for (unsigned int i = 0; i < sizeof(uint64_t) * 8; ++i) {
str += (val & 0x8000000000000000LLU) ? '1' : '0';
val <<= 1;
}
int print_sys_info(struct system_info_t * sys_info)
{
- int i = 0;
/* //FOR DEBUG
+ int i = 0;
sys_info->energy=0x1;
sys_info->wifi_status=0x2;
sys_info->bt_status=0x3;
return lib;
exit_fail_free_lib:
- free_data(lib);
+ free_data((struct data_list_t *)lib);
exit_fail:
return NULL;
}
return NULL;
}
+void free_us_lib_inst(struct us_lib_inst_t *us_lib_inst)
+{
+ free(us_lib_inst->bin_path);
+ free(us_lib_inst);
+}
+
void free_lib(struct lib_list_t *lib)
{
free_us_lib_inst(lib->lib);
free_data((struct data_list_t *)lib);
}
-void free_us_lib_inst(struct us_lib_inst_t *us_lib_inst)
+void free_app_info(struct app_info_t *app_info)
{
- free(us_lib_inst->bin_path);
- free(us_lib_inst);
+ free(app_info->app_id);
+ free(app_info->exe_path);
+ free(app_info);
}
void free_app(struct app_list_t *app)
free_data((struct data_list_t *)app);
}
-void free_app_info(struct app_info_t *app_info)
-{
- free(app_info->app_id);
- free(app_info->exe_path);
- free(app_info);
-}
-
struct probe_list_t *new_probe(void)
{
struct probe_list_t *probe;
while (pr) {
pr = pr->func->func_addr == addr ?
- probe_list_rm_element(app_list, pr) :
+ probe_list_rm_element((struct data_list_t *)app_list, pr) :
pr->next;
}
}
unlock_lib_maps_message();
}
-static inline bool is_always_probing_feature(enum feature_code fv)
+static inline bool is_always_probing_feature(enum feature_code_0 fv)
{
if ((fv & FL_FILE_API_ALWAYS_PROBING) ||
(fv & FL_MEMORY_ALLOC_ALWAYS_PROBING) ||
static void send_maps_inst_msg_to_all_targets()
{
lock_lib_maps_message();
- target_send_msg_to_all(lib_maps_message);
+ target_send_msg_to_all((struct msg_target_t *)lib_maps_message);
unlock_lib_maps_message();
}
LOGI("new_lib_inst_list %p\n", new_lib_inst_list);
if (new_lib_inst_list != NULL) {
LOGI("free new_lib_inst_list start\n");
- free_data_list(&new_lib_inst_list);
+ free_data_list((struct data_list_t **)&new_lib_inst_list);
new_lib_inst_list = NULL;
LOGI("free new_lib_inst_list finish\n");
}
LOGI("us_inst->lib_inst_list %p\n", us_inst->lib_inst_list);
if (us_inst->lib_inst_list != NULL) {
LOGI("free us_inst->lib_inst_list start\n");
- free_data_list(&us_inst->lib_inst_list);
+ free_data_list((struct data_list_t **)&us_inst->lib_inst_list);
us_inst->lib_inst_list = NULL;
LOGI("free us_isnt->lib_inst_list finish\n");
}
LOGI("us_inst->app_inst_list %p\n", us_inst->app_inst_list);
if (us_inst->app_inst_list != NULL) {
LOGI("free us_inst->app_inst_list start\n");
- free_data_list(&us_inst->app_inst_list);
+ free_data_list((struct data_list_t **)&us_inst->app_inst_list);
LOGI("free us_inst->app_isnt_list finish\n");
}
}
for (i = 0; i != feature_to_data_count; i++) {
f = feature_to_data[i];
- LOGI("check feature %016X\n", f.feature_value);
- if ((f.feature_value & to_enable_features_0) ||
- (f.feature_value & to_enable_features_1 << 64)) {
+ LOGI("check feature %016X:%016X\n", f.feature_value_1,
+ f.feature_value_0);
+ if ((f.feature_value_0 & to_enable_features_0) ||
+ (f.feature_value_1 & to_enable_features_1)) {
buf[0] = '\0';
- feature_code_str(f.feature_value, f.feature_value, &buf[0],
+ feature_code_str(f.feature_value_0, f.feature_value_1, &buf[0],
sizeof(buf));
- LOGI("Set LD probes for %016LX <%s>\n", f.feature_value, &buf[0]);
+ LOGI("Set LD probes for %016LX:%016LX <%s>\n",
+ f.feature_value_1, f.feature_value_0, &buf[0]);
feature_add_lib_inst_list(f.feature_ld, &ld_lib_inst_list_new_add);
- } else if (((f.feature_value & to_disable_features_0) &&
- !(f.feature_value & ~to_disable_features_0) ||
- ((f.feature_value & to_disable_features_1 << 64) &&
- !(f.feature_value & ~(to_disable_features_1 << 64))))) {
+ } else if ((((f.feature_value_0 & to_disable_features_0) &&
+ !(f.feature_value_0 & ~to_disable_features_0)) ||
+ (((f.feature_value_1 & to_disable_features_1) &&
+ !(f.feature_value_1 & ~(to_disable_features_1)))))) {
/* If
* (feature_value & to_disable) == (feature_value & ~to_disable)
* then this is NOFEATURE probe, so, do not remove */
buf[0] = '\0';
- feature_code_str(f.feature_value, f.feature_value, &buf[0],
+ feature_code_str(f.feature_value_0, f.feature_value_1, &buf[0],
sizeof(buf));
- LOGI("Remove LD probes for %016LX <%s>\n", f.feature_value, &buf[0]);
+ LOGI("Remove LD probes for %016LX:%016LX <%s>\n",
+ f.feature_value_1, f.feature_value_0, &buf[0]);
feature_add_lib_inst_list(f.feature_ld, &ld_lib_inst_list_new_remove);
}
struct target; // move
void send_maps_inst_msg_to(struct target *t);
+int ld_add_probes_by_feature(uint64_t to_enable_features_0,
+ uint64_t to_enable_features_1,
+ uint64_t to_disable_features_0,
+ uint64_t to_disable_features_1,
+ struct user_space_inst_t *us_inst,
+ struct msg_t **msg_reply_add,
+ struct msg_t **msg_reply_remove);
+
#endif /* __DA_INST_H__*/
#include "md5.h"
#include "da_data.h"
#include "wsi.h"
+#include "cpp/features/feature_manager_c.h"
#include <sys/stat.h>
#include <fcntl.h>
static int process_msg_binary_info(struct msg_buf_t *msg)
{
int err;
- uint32_t i, j, bincount;
+ uint32_t allocated_acks, i, bincount;
enum ErrorCode error_code = ERR_NO;
printBuf(msg->cur_pos, msg->len);
if (!parse_int32(msg, &bincount)) {
LOGE("MSG_BINARY_INFO error: No binaries count\n");
- return -1;
+ goto exit_fail;
}
- struct binary_ack *acks[bincount];
+ struct binary_ack **acks = NULL;
struct binary_ack *new;
size_t total_size = 0;
- for (i = 0; i != bincount; ++i) {
+
+ acks = (struct binary_ack **)malloc(bincount * sizeof(acks[0]));
+ if (acks == NULL) {
+ LOGE("cannon allocate acks\n");
+ goto exit_fail;
+ }
+
+ for (allocated_acks = 0; allocated_acks != bincount; ++allocated_acks) {
const char *str = parse_string_inplace(msg);
if (!str) {
LOGE("MSG_BINARY_INFO error: No enough binaries\n");
- return -1;
+ goto exit_fail_free_ack;
}
new = binary_ack_alloc(str);
/* check for errors */
if (new->local_bin_path[0] == '\0')
LOGW("section '.debug_str' not found in <%s>\n", str);
- acks[i] = new;
+ acks[allocated_acks] = new;
total_size += binary_ack_size(new);
}
typedef uint32_t return_id;
+ total_size);
if (msg_reply == NULL) {
LOGE("Cannot allocates memory for msg_reply\n");
- return 1;
+ goto exit_fail_free_ack;
}
p = msg_reply->payload;
msg_reply->id = NMSG_BINARY_INFO_ACK;
binary_ack_free(acks[i]);
}
- printBuf(msg_reply, msg_reply->len + sizeof(*msg_reply));
+ printBuf((char *)msg_reply, msg_reply->len + sizeof(*msg_reply));
err = send_reply(msg_reply);
free(msg_reply);
return err;
exit_fail_free_ack:
- for (j = 0; j < i; j++)
- binary_ack_free(acks[j]);
+ for (i = 0; i < allocated_acks; i++)
+ binary_ack_free(acks[i]);
+ free(acks);
exit_fail:
return -1;
}
static int process_msg_get_screenshot(struct msg_buf_t *msg_control)
{
- uint32_t log_len;
struct msg_target_t sendlog;
enum ErrorCode err_code = ERR_UNKNOWN;
// send config message to target process
sendlog.type = APP_MSG_CAPTURE_SCREEN;
sendlog.length = 0;
- log_len = sizeof(sendlog.type) + sizeof(sendlog.length) + sendlog.length;
if (target_send_msg_to_all(&sendlog) == 0)
err_code = ERR_NO;
char **cmd_line_arr = NULL;
char *payload = NULL;
char *p;
- struct msg_target_t sendlog;
enum ErrorCode err_code = ERR_UNKNOWN;
/* get pid count */
int process_msg_get_real_path(struct msg_buf_t *msg)
{
- char *file_path = NULL;
+ const char *file_path = NULL;
char *resolved_path= NULL;
enum ErrorCode err_code = ERR_UNKNOWN;
uint32_t response_len = 0;
}
response_len = strnlen(resolved_path, PATH_MAX) + 1;
- if (resolved_path == (PATH_MAX + 1)) {
+ if (response_len == (PATH_MAX + 1)) {
LOGE("NMSG_GET_REAL_PATH error: cannot resolve path <%s>"
"too long path\n", file_path);
err_code = ERR_WRONG_MESSAGE_DATA;
struct conf_t conf;
enum ErrorCode error_code = ERR_NO;
- int target_index;
struct msg_target_t sendlog;
LOGI("MY HANDLE %s (%X)\n", msg_ID_str(msg->id), msg->id);
#include <stdio.h>
#include <stddef.h>
#include <linux/input.h>
+#include <assert.h>
#define PROTOCOL_VERSION "4.0"
#define FL_SYSTEM_ENERGY_OLD (1<<26)
-enum feature_code{
+enum feature_code_0 {
FL_RESERVED1 = 0x0000000000003ULL, // reserved 0011
FL_FUNCTION_PROFILING = 0x0000000000004ULL, // 0x4 * 0x10^00 On/Off the UserSpaceInst
};
+enum feature_code_1 {
+ FL_ALL_FEATURES_1 = 0x0000000000000ULL, /* all */
+};
+
enum probe_type {
SWAP_RETPROBE = 0, //Common retprobe
SWAP_FBI_PROBE = 1, //Function body instrumentation probe
uint32_t code;
uint32_t value;
};
+
+#ifndef static_assert
#define static_assert(cond) \
char __attribute__((unused)) __static_assert[(cond) ? 1 : -1];
+#endif
#define pack_int64(to, n) do { \
static_assert(sizeof(n) == 8); \
#define pack_str(to, n) \
do { \
memcpy(to, n, strlen(n) + 1); \
- to += strlen(n) + 1; \
+ to = (char *)to + strlen(n) + 1; \
} while (0)
static inline void* pack_str_array(void *buffer, const char **strings,
size_t count)
{
- int index;
+ size_t index;
for (index = 0; index != count; ++index)
pack_str(buffer, strings[index]);
return buffer;
int check_app_id(uint32_t app_type, char *app_id)
{
int res = 0;
- char *p;
switch (app_type){
case APP_TYPE_TIZEN:
res = 1;
uint32_t size = 0, tmp_size = 0;
struct us_func_inst_plane_t *func = NULL;
- char type;
+ uint8_t type;
uint64_t addr;
size = sizeof(*func);
free_app(app);
exit_fail_clean_list:
/* TODO free app list */
- free_data_list(app_list);
+ free_data_list((struct data_list_t **)app_list);
exit_fail:
*num = 0;
app_list = NULL;
return 0;
}
/* ld probes */
-#define NOFEATURE 0x123456
#include "ld_preload_types.h"
struct ld_preload_probe_t {
uint64_t orig_addr;
*get_call_type_probe,
*write_msg_probe;
int ret = 0;
- struct us_func_inst_plane_t *func = NULL;
preload_lib = new_lib();
if (preload_lib == NULL) {
goto free_caller_probe;
}
- preload_lib->lib->bin_path = probe_lib;
+ /* probe_lib generates by swap-probe in swap-probe-devel */
+ preload_lib->lib->bin_path = (char *)probe_lib;
preload_lib->func_num = 3;
/* Add get_caller probe */
if (ret != 0)
goto free_caller_probe;
- probe_list_append(preload_lib, get_caller_probe);
+ probe_list_append((struct data_list_t *)preload_lib, get_caller_probe);
/* Add get_call_type probe */
ret = create_preload_probe_func(&get_call_type_probe, get_call_type_addr, 5);
if (ret != 0)
goto free_call_type_probe;
- probe_list_append(preload_lib, get_call_type_probe);
+ probe_list_append((struct data_list_t *)preload_lib, get_call_type_probe);
/* Add write_msg probe */
ret = create_preload_probe_func(&write_msg_probe, write_msg_addr, 6);
if (ret != 0)
goto free_write_msg_probe;
- probe_list_append(preload_lib, write_msg_probe);
+ probe_list_append((struct data_list_t *)preload_lib, write_msg_probe);
preload_lib->func_num = 3;
preload_lib->size += strlen(preload_lib->lib->bin_path) + 1 + sizeof(preload_lib->func_num);
*
*/
#define __STDC_FORMAT_MACROS
+#define _GNU_SOURCE /* for accept4 */
+
#include <stdio.h>
#include <stdlib.h> // for realpath
#include <string.h> // for strtok, strcpy, strncpy
#include "da_inst.h"
#include "da_data.h"
#include "input_events.h"
+#include "threads.h"
#include "smack.h"
#include "swap_debug.h"
#include "wsi.h"
+#include "cpp/features/feature_manager_c.h"
+
#define DA_WORK_DIR "/home/developer/sdk_tools/da/"
#define DA_READELF_PATH "/home/developer/sdk_tools/da/readelf"
#define SCREENSHOT_DIR "/tmp/da"
#define MAX_APP_LAUNCH_TIME 60
#define MAX_CONNECT_TIMEOUT_TIME 5*60
-
// =============================================================================
// start and terminate control functions
// =============================================================================
return res;
}
+/* terminate all profiling applications */
+int terminate_profiling_apps(void)
+{
+ int res = 0;
+ struct app_list_t *app = NULL;
+ const struct app_info_t *app_info = NULL;
+
+ app_info = app_info_get_first(&app);
+ if (app_info == NULL) {
+ LOGE("No app info found\n");
+ return -1;
+ }
+
+ /* all apps */
+ while (app_info != NULL) {
+ if (kill_app_by_info(app_info) != 0) {
+ LOGE("kill app failed\n");
+ res = -1;
+ }
+ app_info = app_info_get_next(&app);
+ }
+
+ return res;
+}
+
// terminate all target and wait for threads
void terminate_all()
{
return res;
}
-/* terminate all profiling applications */
-int terminate_profiling_apps(void)
-{
- int res = 0;
- struct app_list_t *app = NULL;
- const struct app_info_t *app_info = NULL;
-
- app_info = app_info_get_first(&app);
- if (app_info == NULL) {
- LOGE("No app info found\n");
- return -1;
- }
-
- /* all apps */
- while (app_info != NULL) {
- if (kill_app_by_info(app_info) != 0) {
- LOGE("kill app failed\n");
- res = -1;
- }
- app_info = app_info_get_next(&app);
- }
-
- return res;
-}
-
int prepare_profiling(void)
{
/* terminate all profiling applications */
return 0;
}
-int is_feature_enabled(enum feature_code fcode)
+int is_feature_enabled(enum feature_code_0 fcode)
{
/* TODO: add check use_features1 */
return (fcode & prof_session.conf.use_features0) ? 1 : 0;
if (stop_all() != ERR_NO)
LOGE("Stop failed\n");
return -11;
+ default:
+ break;
}
}
ecore_main_loop_begin();
ecore_shutdown();
- END_EFD:
+END_EFD:
LOGI("close efd\n");
close(manager.efd);
- END_EVENT:
+
return return_value;
}
int start_profiling(void);
void stop_profiling(void);
int reconfigure(struct conf_t conf, struct msg_t **msg_reply, struct msg_t **msg_reply_additional);
-int is_feature_enabled(enum feature_code fcode);
-int sendACKCodeToHost(enum HostMessageType resp, int msgcode);
+int is_feature_enabled(enum feature_code_0 fcode);
void terminate_all(void);
#ifdef __cplusplus
FILE *cmd_fp = NULL;
char buffer[BUF_SIZE];
char command[MAX_FILENAME];
- char **name_arr;
+ const char **name_arr;
size_t bytes_count;
if (snprintf(command, sizeof(command), "/sys/class/input/%s/device/name",
rewind(manager.fd.inst_tasks);
fflush(manager.fd.inst_tasks);
- while (fscanf(manager.fd.inst_tasks, "%lu", arr) == 1) {
+ while (fscanf(manager.fd.inst_tasks, "%lu", (long unsigned int *)arr) == 1) {
LOGI_th_samp("PID scaned %d\n", *arr);
arr++;
pid_count++;
#include "buffer.h"
#include "input_events.h"
-static chsmack(const char *filename)
+static int chsmack(const char *filename)
{
int res = 1;
pid_t pid;
*/
-#ifndef _UTILS_H_
-#define _UTILS_H_
+#ifndef _THREADS_H_
+#define _THREADS_H_
#ifdef __cplusplus
extern "C" {
#endif
-struct target;
-
+#include "target.h"
int makeRecvThread(struct target *target);
}
#endif
-#endif
+#endif /* _THREADS_H_ */
{
// alternative path may be /opt/apps/... or /opt/usr/apps/...)
char *add_fname;
- char *p;
if (strncmp(binary_path, APPDIR1, strlen(APPDIR1)) == 0) {
strncpy(alter_bin_path, APPDIR2, buflen);
buflen -= strlen(alter_bin_path);
- add_fname = binary_path + strlen(APPDIR1);
+ add_fname = (char *)binary_path + strlen(APPDIR1);
strncat(alter_bin_path, add_fname, buflen);
} else if (strncmp(binary_path, APPDIR2, strlen(APPDIR2)) == 0) {
strncpy(alter_bin_path, APPDIR1, buflen);
buflen -= strlen(alter_bin_path);
- add_fname = binary_path + strlen(APPDIR2);
+ add_fname = (char *)binary_path + strlen(APPDIR2);
strncat(alter_bin_path, add_fname, buflen);
} else {
return 1;
int exec_app_web(const char *app_id);
void kill_app_web(const char *app_id);
float get_uptime(void);
+
+void swap_usleep(useconds_t usec);
#ifdef __cplusplus
}
#endif