Commit 7ad74ec2 authored by Andrew Vagin's avatar Andrew Vagin Committed by Pavel Emelyanov

rst-malloc: use rst_mem_alloc_cont to allocate arrays

rst_mem_alloc() returns alligned slices. When we want to
allocate an array element, we don't expect to get a hole between
a new element and an old one.
Signed-off-by: 's avatarAndrew Vagin <avagin@virtuozzo.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent 7458b054
...@@ -770,12 +770,12 @@ static int collect_child_pids(int state, int *n) ...@@ -770,12 +770,12 @@ static int collect_child_pids(int state, int *n)
*n = 0; *n = 0;
list_for_each_entry(pi, &current->children, sibling) { list_for_each_entry(pi, &current->children, sibling) {
static pid_t *child; pid_t *child;
if (pi->state != state) if (pi->state != state)
continue; continue;
child = rst_mem_alloc(sizeof(*child), RM_PRIVATE); child = rst_mem_alloc_cont(sizeof(*child), RM_PRIVATE);
if (!child) if (!child)
return -1; return -1;
...@@ -2432,7 +2432,7 @@ static int prepare_posix_timers_from_fd(int pid) ...@@ -2432,7 +2432,7 @@ static int prepare_posix_timers_from_fd(int pid)
if (ret <= 0) if (ret <= 0)
break; break;
t = rst_mem_alloc(sizeof(struct restore_posix_timer), RM_PRIVATE); t = rst_mem_alloc_cont(sizeof(struct restore_posix_timer), RM_PRIVATE);
if (!t) if (!t)
break; break;
...@@ -2464,7 +2464,7 @@ static int prepare_posix_timers(int pid, CoreEntry *core) ...@@ -2464,7 +2464,7 @@ static int prepare_posix_timers(int pid, CoreEntry *core)
posix_timers_nr = tte->n_posix; posix_timers_nr = tte->n_posix;
for (i = 0; i < posix_timers_nr; i++) { for (i = 0; i < posix_timers_nr; i++) {
t = rst_mem_alloc(sizeof(struct restore_posix_timer), RM_PRIVATE); t = rst_mem_alloc_cont(sizeof(struct restore_posix_timer), RM_PRIVATE);
if (!t) if (!t)
goto out; goto out;
...@@ -2623,7 +2623,7 @@ static int prepare_rlimits_from_fd(int pid) ...@@ -2623,7 +2623,7 @@ static int prepare_rlimits_from_fd(int pid)
if (ret <= 0) if (ret <= 0)
break; break;
r = rst_mem_alloc(sizeof(*r), RM_PRIVATE); r = rst_mem_alloc_cont(sizeof(*r), RM_PRIVATE);
if (!r) { if (!r) {
pr_err("Can't allocate memory for resource %d\n", pr_err("Can't allocate memory for resource %d\n",
rlims_nr); rlims_nr);
...@@ -2660,7 +2660,7 @@ static int prepare_rlimits(int pid, CoreEntry *core) ...@@ -2660,7 +2660,7 @@ static int prepare_rlimits(int pid, CoreEntry *core)
return prepare_rlimits_from_fd(pid); return prepare_rlimits_from_fd(pid);
for (i = 0; i < rls->n_rlimits; i++) { for (i = 0; i < rls->n_rlimits; i++) {
r = rst_mem_alloc(sizeof(*r), RM_PRIVATE); r = rst_mem_alloc_cont(sizeof(*r), RM_PRIVATE);
if (!r) { if (!r) {
pr_err("Can't allocate memory for resource %d\n", i); pr_err("Can't allocate memory for resource %d\n", i);
return -1; return -1;
...@@ -2684,7 +2684,7 @@ static int signal_to_mem(SiginfoEntry *sie) ...@@ -2684,7 +2684,7 @@ static int signal_to_mem(SiginfoEntry *sie)
siginfo_t *info, *t; siginfo_t *info, *t;
info = (siginfo_t *) sie->siginfo.data; info = (siginfo_t *) sie->siginfo.data;
t = rst_mem_alloc(sizeof(siginfo_t), RM_PRIVATE); t = rst_mem_alloc_cont(sizeof(siginfo_t), RM_PRIVATE);
if (!t) if (!t)
return -1; return -1;
...@@ -2813,7 +2813,7 @@ rst_prep_creds_args(CredsEntry *ce, unsigned long *prev_pos) ...@@ -2813,7 +2813,7 @@ rst_prep_creds_args(CredsEntry *ce, unsigned long *prev_pos)
} }
args = rst_mem_alloc(sizeof(*args), RM_PRIVATE); args = rst_mem_alloc_cont(sizeof(*args), RM_PRIVATE);
if (!args) if (!args)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
...@@ -3019,7 +3019,7 @@ static int sigreturn_restore(pid_t pid, CoreEntry *core) ...@@ -3019,7 +3019,7 @@ static int sigreturn_restore(pid_t pid, CoreEntry *core)
list_for_each_entry(vma, &vmas->h, list) { list_for_each_entry(vma, &vmas->h, list) {
VmaEntry *vme; VmaEntry *vme;
vme = rst_mem_alloc(sizeof(*vme), RM_PRIVATE); vme = rst_mem_alloc_cont(sizeof(*vme), RM_PRIVATE);
if (!vme) if (!vme)
goto err_nv; goto err_nv;
...@@ -3037,7 +3037,7 @@ static int sigreturn_restore(pid_t pid, CoreEntry *core) ...@@ -3037,7 +3037,7 @@ static int sigreturn_restore(pid_t pid, CoreEntry *core)
for (i = 0; i < mm->n_aios; i++) { for (i = 0; i < mm->n_aios; i++) {
struct rst_aio_ring *raio; struct rst_aio_ring *raio;
raio = rst_mem_alloc(sizeof(*raio), RM_PRIVATE); raio = rst_mem_alloc_cont(sizeof(*raio), RM_PRIVATE);
if (!raio) if (!raio)
goto err_nv; goto err_nv;
......
...@@ -689,7 +689,7 @@ int rst_tcp_socks_prep(void) ...@@ -689,7 +689,7 @@ int rst_tcp_socks_prep(void)
if (ii->sk_fd == -1) if (ii->sk_fd == -1)
continue; continue;
rs = rst_mem_alloc(sizeof(*rs), RM_PRIVATE); rs = rst_mem_alloc_cont(sizeof(*rs), RM_PRIVATE);
if (!rs) if (!rs)
return -1; return -1;
......
...@@ -119,7 +119,7 @@ int rst_timerfd_prep(void) ...@@ -119,7 +119,7 @@ int rst_timerfd_prep(void)
list_for_each_entry(ti, &rst_timerfds, rlist) { list_for_each_entry(ti, &rst_timerfds, rlist) {
TimerfdEntry *tfe = ti->tfe; TimerfdEntry *tfe = ti->tfe;
t = rst_mem_alloc(sizeof(*t), RM_PRIVATE); t = rst_mem_alloc_cont(sizeof(*t), RM_PRIVATE);
if (!t) if (!t)
return -1; return -1;
......
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