Commit 7b7a08dd authored by Alexander Kartashov's avatar Alexander Kartashov Committed by Pavel Emelyanov

auxv: save and restore AUXV's in a machine-independent way.

The size of an auxv is the machine pointer but a 64-bit integer is reserved
in a MmEntry protobuf message to store an auxv. Moreover the number of auxv's
varies from one architecture to another. So the following is proposed
to alleviate the issue.

* Introduced the type auxv_t representing a machine-pointer sized integer.

* The size of auxv array is extracted from a MmEntry message instead of using
  the value of the macro AT_VECTOR_SIZE.
Signed-off-by: 's avatarAlexander Kartashov <alekskartashov@parallels.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent cbffef75
...@@ -247,4 +247,6 @@ typedef struct { ...@@ -247,4 +247,6 @@ typedef struct {
#define TASK_SIZE ((1UL << 47) - 1) #define TASK_SIZE ((1UL << 47) - 1)
typedef uint64_t auxv_t;
#endif /* __CR_ASM_TYPES_H__ */ #endif /* __CR_ASM_TYPES_H__ */
...@@ -552,10 +552,10 @@ static int get_task_auxv(pid_t pid, MmEntry *mm, size_t *size) ...@@ -552,10 +552,10 @@ static int get_task_auxv(pid_t pid, MmEntry *mm, size_t *size)
for (i = 0; i < AT_VECTOR_SIZE; i++) { for (i = 0; i < AT_VECTOR_SIZE; i++) {
ret = read(fd, &mm->mm_saved_auxv[i], ret = read(fd, &mm->mm_saved_auxv[i],
sizeof(mm->mm_saved_auxv[0])); sizeof(auxv_t));
if (ret == 0) if (ret == 0)
break; break;
else if (ret != sizeof(mm->mm_saved_auxv[0])) { else if (ret != sizeof(auxv_t)) {
ret = -1; ret = -1;
pr_perror("Error readind %d's auxv[%d]", pr_perror("Error readind %d's auxv[%d]",
pid, i); pid, i);
......
...@@ -1453,7 +1453,7 @@ static VmaEntry *vma_list_remap(void *addr, unsigned long len, struct list_head ...@@ -1453,7 +1453,7 @@ static VmaEntry *vma_list_remap(void *addr, unsigned long len, struct list_head
static int prepare_mm(pid_t pid, struct task_restore_core_args *args) static int prepare_mm(pid_t pid, struct task_restore_core_args *args)
{ {
int fd, exe_fd, ret = -1; int fd, exe_fd, i, ret = -1;
MmEntry *mm; MmEntry *mm;
fd = open_image_ro(CR_FD_MM, pid); fd = open_image_ro(CR_FD_MM, pid);
...@@ -1474,9 +1474,10 @@ static int prepare_mm(pid_t pid, struct task_restore_core_args *args) ...@@ -1474,9 +1474,10 @@ static int prepare_mm(pid_t pid, struct task_restore_core_args *args)
goto out; goto out;
} }
args->mm_saved_auxv_size = pb_repeated_size(mm, mm_saved_auxv); args->mm_saved_auxv_size = mm->n_mm_saved_auxv*sizeof(auxv_t);
memcpy(args->mm_saved_auxv, mm->mm_saved_auxv, for (i = 0; i < mm->n_mm_saved_auxv; ++i) {
args->mm_saved_auxv_size); args->mm_saved_auxv[i] = (auxv_t)mm->mm_saved_auxv[i];
}
exe_fd = open_reg_by_id(args->mm.exe_file_id); exe_fd = open_reg_by_id(args->mm.exe_file_id);
if (exe_fd < 0) if (exe_fd < 0)
......
...@@ -123,7 +123,7 @@ struct task_restore_core_args { ...@@ -123,7 +123,7 @@ struct task_restore_core_args {
uint32_t cap_bnd[CR_CAP_SIZE]; uint32_t cap_bnd[CR_CAP_SIZE];
MmEntry mm; MmEntry mm;
u64 mm_saved_auxv[AT_VECTOR_SIZE]; auxv_t mm_saved_auxv[AT_VECTOR_SIZE];
u32 mm_saved_auxv_size; u32 mm_saved_auxv_size;
char comm[TASK_COMM_LEN]; char comm[TASK_COMM_LEN];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment