2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-22 09:58:09 +00:00
criu/include/image.h

191 lines
5.2 KiB
C
Raw Permalink Normal View History

#ifndef __CR_IMAGE_H__
#define __CR_IMAGE_H__
#include <stdbool.h>
#include "compiler.h"
#include "servicefd.h"
#include "image-desc.h"
#include "fcntl.h"
#include "magic.h"
#include "bfd.h"
#include "bug.h"
arch/ppc64: Add PowerPC 64 LE support This patch initiates the ppc64le architecture support in CRIU. Note that ppc64 (Big Endian) architecture is not yet supported since there are still several issues to address with this architecture. However, in the long term, the two architectures should be addressed using the almost the same code, so sharing the ppc64 directory. Major ppc64 issues: Loader is not involved when the parasite code is loaded. So no relocation is done for the parasite code. As a consequence r2 must be set manually when entering the parasite code, and GOT is not filled. Furthermore, the r2 fixup code at the services's global address which has not been fixed by the loader should not be run. Branching at local address, as the assembly code does is jumping over it. On the long term, relocation should be done when loading the parasite code. We are introducing 2 trampolines for the 2 entry points of the restorer blob. These entry points are dealing with r2. These ppc64 specific entry points are overwritting the standard one in sigreturn_restore() from cr-restore.c. Instead of using #ifdef, we may introduce a per arch wrapper here. CRIU needs 2 kernel patches to be run powerpc which are not yet upstream: - Tracking the vDSO remapping - Enabling the kcmp system call on powerpc Feature not yet supported: - Altivec registers C/R - VSX registers C/R - TM support - all lot of things I missed.. Signed-off-by: Laurent Dufour <ldufour@linux.vnet.ibm.com> Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-04-30 09:57:49 +03:00
#ifdef _ARCH_PPC64
#define PAGE_IMAGE_SIZE 65536
#else
#define PAGE_IMAGE_SIZE 4096
arch/ppc64: Add PowerPC 64 LE support This patch initiates the ppc64le architecture support in CRIU. Note that ppc64 (Big Endian) architecture is not yet supported since there are still several issues to address with this architecture. However, in the long term, the two architectures should be addressed using the almost the same code, so sharing the ppc64 directory. Major ppc64 issues: Loader is not involved when the parasite code is loaded. So no relocation is done for the parasite code. As a consequence r2 must be set manually when entering the parasite code, and GOT is not filled. Furthermore, the r2 fixup code at the services's global address which has not been fixed by the loader should not be run. Branching at local address, as the assembly code does is jumping over it. On the long term, relocation should be done when loading the parasite code. We are introducing 2 trampolines for the 2 entry points of the restorer blob. These entry points are dealing with r2. These ppc64 specific entry points are overwritting the standard one in sigreturn_restore() from cr-restore.c. Instead of using #ifdef, we may introduce a per arch wrapper here. CRIU needs 2 kernel patches to be run powerpc which are not yet upstream: - Tracking the vDSO remapping - Enabling the kcmp system call on powerpc Feature not yet supported: - Altivec registers C/R - VSX registers C/R - TM support - all lot of things I missed.. Signed-off-by: Laurent Dufour <ldufour@linux.vnet.ibm.com> Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-04-30 09:57:49 +03:00
#endif /* _ARCH_PPC64 */
#define PAGE_RSS 1
#define PAGE_ANON 2
/*
* Top bit set in the tgt id means we've remapped
* to a ghost file.
*/
#define REMAP_GHOST (1 << 31)
/*
* By-default, when dumping a unix socket, we should dump its peer
* as well. Which in turn means, we should dump the task(s) that have
* this peer opened.
*
* Sometimes, we can break this rule and dump only one end of the
* unix sockets pair, and on restore time connect() this end back to
* its peer.
*
* So, to resolve this situation we mark the peers we don't dump
* as "external" and require the --ext-unix-sk option.
*/
#define USK_EXTERN (1 << 0)
#define USK_SERVICE (1 << 1)
#define USK_CALLBACK (1 << 2)
#define USK_INHERIT (1 << 3)
/*
* VMA_AREA status:
*
* - none
* VmaEntry is just allocated and has not been used
* for anything yet
* - regular
* VmaEntry represent some memory area which should be
* dumped and restored; this is a general sign that we
* should not skip the area content from processing in
* compare with special areas such as vsyscall
* - stack
* the memory area is used in application stack so we
* should be careful about guard page here
* - vsyscall
* special memory area injected into the task memory
* space by the kernel itself, represent virtual syscall
* implementation and it is specific to every kernel version,
* its contents should not be dumped ever
* - vdso,vvar
* the vDSO area, it might reqire additional memory
* contents modification especially when tasks are
* migrating between different kernel versions
* - heap
* "heap" area in application, currently for inforamtion only
* - file private
* stands for privately memory mapped files
* - file shared
* stands for shared memory mapped files
* - anon shared
* represent shared anonymous memory areas
* - anon private
* represent private anonymous memory areas
* - SysV IPC
* IPC shared memory area
* - socket
* memory map for socket
* - AIO ring
* memory area serves AIO buffers
* - unsupported
* stands for any unknown memory areas, usually means
* we don't know how to work with it and should stop
* processing exiting with error; while the rest of bits
* are part of image ABI, this particular one must never
* be used in image.
*/
#define VMA_AREA_NONE (0 << 0)
#define VMA_AREA_REGULAR (1 << 0)
#define VMA_AREA_STACK (1 << 1)
#define VMA_AREA_VSYSCALL (1 << 2)
#define VMA_AREA_VDSO (1 << 3)
#define VMA_AREA_HEAP (1 << 5)
#define VMA_FILE_PRIVATE (1 << 6)
#define VMA_FILE_SHARED (1 << 7)
#define VMA_ANON_SHARED (1 << 8)
#define VMA_ANON_PRIVATE (1 << 9)
#define VMA_AREA_SYSVIPC (1 << 10)
#define VMA_AREA_SOCKET (1 << 11)
#define VMA_AREA_VVAR (1 << 12)
#define VMA_AREA_AIORING (1 << 13)
#define VMA_UNSUPP (1 << 31)
#define CR_CAP_SIZE 2
#define TASK_COMM_LEN 16
#define TASK_ALIVE 0x1
#define TASK_DEAD 0x2
#define TASK_STOPPED 0x3
#define TASK_HELPER 0x4
#define CR_PARENT_LINK "parent"
extern bool fdinfo_per_id;
extern bool ns_per_id;
extern bool img_common_magic;
#define O_NOBUF (O_DIRECT)
#define O_SERVICE (O_DIRECTORY)
#define O_DUMP (O_WRONLY | O_CREAT | O_TRUNC)
#define O_SHOW (O_RDONLY | O_NOBUF)
#define O_RSTR (O_RDONLY)
struct cr_img {
union {
struct bfd _x;
struct {
int fd; /* should be first to coincide with _x.fd */
int type;
unsigned long oflags;
char *path;
};
};
};
#define EMPTY_IMG_FD (-404)
#define LAZY_IMG_FD (-505)
static inline bool empty_image(struct cr_img *img)
{
return img && img->_x.fd == EMPTY_IMG_FD;
}
static inline bool lazy_image(struct cr_img *img)
{
return img->_x.fd == LAZY_IMG_FD;
}
extern int open_image_lazy(struct cr_img *img);
static inline int img_raw_fd(struct cr_img *img)
{
if (lazy_image(img) && open_image_lazy(img))
return -1;
BUG_ON(bfd_buffered(&img->_x));
return img->_x.fd;
}
extern int open_image_dir(char *dir);
extern void close_image_dir(void);
extern struct cr_img *open_image_at(int dfd, int type, unsigned long flags, ...);
#define open_image(typ, flags, ...) open_image_at(-1, typ, flags, ##__VA_ARGS__)
extern int open_image_lazy(struct cr_img *img);
extern struct cr_img *open_pages_image(unsigned long flags, struct cr_img *pmi);
extern struct cr_img *open_pages_image_at(int dfd, unsigned long flags, struct cr_img *pmi);
extern void up_page_ids_base(void);
extern struct cr_img *img_from_fd(int fd); /* for cr-show mostly */
extern int write_img_buf(struct cr_img *, const void *ptr, int size);
#define write_img(img, ptr) write_img_buf((img), (ptr), sizeof(*(ptr)))
extern int read_img_buf_eof(struct cr_img *, void *ptr, int size);
#define read_img_eof(img, ptr) read_img_buf_eof((img), (ptr), sizeof(*(ptr)))
extern int read_img_buf(struct cr_img *, void *ptr, int size);
#define read_img(img, ptr) read_img_buf((img), (ptr), sizeof(*(ptr)))
extern int read_img_str(struct cr_img *, char **pstr, int size);
extern void close_image(struct cr_img *);
#endif /* __CR_IMAGE_H__ */