mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-29 05:18:00 +00:00
crtools binary is linked with the C library and could rely on all the services this library is providing, including system calls. Thus it doesn't need to be linked with the builtin system calls code made for the parasite/restorer binaries. This patch does: - remove the inclusion of syscall.h - replace all call to sys_<syscall>() by C library <syscall>() - replace unwrapped system calls by syscall(SYS_<syscall>,...) - fix the generated compiler's issues. There should not be any functional changes. The only 'code' changes is appearing in locks.h when futex is called through the C library, the errno value is fetched from errno variable instead of the return value. Signed-off-by: Laurent Dufour <ldufour@linux.vnet.ibm.com> Reviewed-by: Christopher Covington <cov@codeaurora.org> Reviewed-by: Cyrill Gorcunov <gorcunov@openvz.org> Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
114 lines
1.9 KiB
C
114 lines
1.9 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <stdarg.h>
|
|
#include <signal.h>
|
|
#include <limits.h>
|
|
#include <unistd.h>
|
|
#include <errno.h>
|
|
#include <string.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/types.h>
|
|
|
|
#include "asm/types.h"
|
|
#include "file-ids.h"
|
|
#include "rbtree.h"
|
|
#include "kcmp-ids.h"
|
|
#include "compiler.h"
|
|
#include "image.h"
|
|
#include "util.h"
|
|
#include "irmap.h"
|
|
#include "files.h"
|
|
|
|
static DECLARE_KCMP_TREE(fd_tree, KCMP_FILE);
|
|
|
|
#define FDID_BITS 5
|
|
#define FDID_SIZE (1 << FDID_BITS)
|
|
#define FDID_MASK (FDID_SIZE - 1)
|
|
|
|
static inline int fdid_hashfn(unsigned int s_dev, unsigned long i_ino)
|
|
{
|
|
return (s_dev + i_ino) & FDID_MASK;
|
|
}
|
|
|
|
struct fd_id {
|
|
int mnt_id;
|
|
unsigned int dev;
|
|
unsigned long ino;
|
|
u32 id;
|
|
struct fd_id *n;
|
|
};
|
|
|
|
static struct fd_id *fd_id_cache[FDID_SIZE];
|
|
|
|
static void fd_id_cache_one(u32 id, struct fd_parms *p)
|
|
{
|
|
struct fd_id *fi;
|
|
unsigned hv;
|
|
|
|
fi = xmalloc(sizeof(*fi));
|
|
if (fi) {
|
|
fi->dev = p->stat.st_dev;
|
|
fi->ino = p->stat.st_ino;
|
|
fi->mnt_id = p->mnt_id;
|
|
fi->id = id;
|
|
|
|
hv = fdid_hashfn(p->stat.st_dev, p->stat.st_ino);
|
|
fi->n = fd_id_cache[hv];
|
|
fd_id_cache[hv] = fi;
|
|
}
|
|
}
|
|
|
|
static struct fd_id *fd_id_cache_lookup(struct fd_parms *p)
|
|
{
|
|
struct stat *st = &p->stat;
|
|
struct fd_id *fi;
|
|
|
|
for (fi = fd_id_cache[fdid_hashfn(st->st_dev, st->st_ino)];
|
|
fi; fi = fi->n)
|
|
if (fi->dev == st->st_dev &&
|
|
fi->ino == st->st_ino &&
|
|
fi->mnt_id == p->mnt_id)
|
|
return fi;
|
|
|
|
return NULL;
|
|
}
|
|
|
|
int fd_id_generate_special(struct fd_parms *p, u32 *id)
|
|
{
|
|
if (p) {
|
|
struct fd_id *fi;
|
|
|
|
fi = fd_id_cache_lookup(p);
|
|
if (fi) {
|
|
*id = fi->id;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
*id = fd_tree.subid++;
|
|
if (p)
|
|
fd_id_cache_one(*id, p);
|
|
return 1;
|
|
}
|
|
|
|
int fd_id_generate(pid_t pid, FdinfoEntry *fe, struct fd_parms *p)
|
|
{
|
|
u32 id;
|
|
struct kid_elem e;
|
|
int new_id = 0;
|
|
|
|
e.pid = pid;
|
|
e.genid = fe->id;
|
|
e.idx = fe->fd;
|
|
|
|
id = kid_generate_gen(&fd_tree, &e, &new_id);
|
|
if (!id)
|
|
return -ENOMEM;
|
|
|
|
if (new_id)
|
|
fd_id_cache_one(id, p);
|
|
|
|
fe->id = id;
|
|
return new_id;
|
|
}
|