Serge E. Hallyn wrote: > Quoting Oren Laadan (orenl@xxxxxxxxxxxxxxx): >> From: Dan Smith <danms@xxxxxxxxxx> >> >> As suggested by Dave[1], this provides us a way to make the copy-in and >> copy-out processes symmetric. CR_COPY_ARRAY() provides us a way to do >> the same thing but for arrays. It's not critical, but it helps us unify >> the checkpoint and restart paths for some things. >> >> Changelog: >> Mar 04: >> . Removed semicolons >> . Added build-time check for __must_be_array in CR_COPY_ARRAY >> Feb 27: >> . Changed CR_COPY() to use assignment, eliminating the need >> for the CR_COPY_BIT() macro >> . Add CR_COPY_ARRAY() macro to help copying register arrays, >> etc >> . Move the macro definitions inside the CR #ifdef >> Feb 25: >> . Changed WARN_ON() to BUILD_BUG_ON() >> >> Signed-off-by: Dan Smith <danms@xxxxxxxxxx> >> Signed-off-by: Oren Laadan <orenl@xxxxxxxxxxxxxxx> >> >> 1: https://lists.linux-foundation.org/pipermail/containers/2009-February/015821.html (all the way at the bottom) >> --- >> include/linux/checkpoint.h | 26 ++++++++++++++++++++++++++ >> 1 files changed, 26 insertions(+), 0 deletions(-) >> >> diff --git a/include/linux/checkpoint.h b/include/linux/checkpoint.h >> index 69d14c4..2e99c74 100644 >> --- a/include/linux/checkpoint.h >> +++ b/include/linux/checkpoint.h >> @@ -117,6 +117,32 @@ extern int cr_read_mm(struct cr_ctx *ctx); >> extern int cr_read_fd_table(struct cr_ctx *ctx); >> extern int cr_read_file(struct cr_ctx *ctx, int objref); >> >> +/* useful macros to copy fields and buffers to/from cr_hdr_xxx structures */ >> +#define CR_CPT 1 >> +#define CR_RST 2 >> + >> +#define CR_COPY(op, a, b) \ >> + do { \ >> + if (op == CR_CPT) \ >> + a = b; \ >> + else \ >> + b = a; \ >> + } while (0) >> + > > Speaking from experience with similar sets of macros in capability.h, > I'd like to suggest renaming a and b. Something like: > > #define CR_COPY(op, SAVED, LIVE) \ > do { \ > if (op == CR_CPT) \ > SAVED = LIVE; \ > else \ > LIVE = SAVED; \ > } while (0) > > That way the next time I need to use CR_COPY, I don't have to > agonize over which argument goes where. Good idea, done. > >> +/* >> + * Copy @count items from @b to @a if op is CR_CPT (otherwise, >> + * copy in the reverse direction) >> + */ >> +#define CR_COPY_ARRAY(op, a, b, count) \ >> + do { \ >> + BUILD_BUG_ON(sizeof(*a) != sizeof(*b)); \ >> + if (op == CR_CPT) \ >> + memcpy(a, b, count * sizeof(*a)); \ >> + else \ >> + memcpy(b, a, count * sizeof(*a)); \ >> + } while (__must_be_array(a) && __must_be_array(b) && 0) >> + >> + >> #define cr_debug(fmt, args...) \ >> pr_debug("[%d:c/r:%s] " fmt, task_pid_vnr(current), __func__, ## args) >> >> -- >> 1.5.4.3 > _______________________________________________ Containers mailing list Containers@xxxxxxxxxxxxxxxxxxxxxxxxxx https://lists.linux-foundation.org/mailman/listinfo/containers