Skip to content

Commit

Permalink
Add flog to CRIU
Browse files Browse the repository at this point in the history
Change made through this commit:
- Include copy of flog as a seperate tree.
- Modify the makefile to add and compile flog code.

Signed-off-by: prakritigoyal19 <prakritigoyal19@gmail.com>
  • Loading branch information
prakritigoyal19 authored and felicitia committed Oct 26, 2023
1 parent 41938f1 commit 7ec1ef9
Show file tree
Hide file tree
Showing 13 changed files with 755 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ HOSTCFLAGS += $(WARNINGS) $(DEFINES) -iquote include/
export AFLAGS CFLAGS USERCLFAGS HOSTCFLAGS

# Default target
all: criu lib
all: flog criu lib crit
.PHONY: all

#
Expand Down Expand Up @@ -250,6 +250,15 @@ soccr/built-in.o: $(CONFIG_HEADER) .FORCE
$(SOCCR_A): |soccr/built-in.o
criu-deps += $(SOCCR_A)

#flog gets used by criu, build it earlier

flogMakefile: ;
flog%:
$(Q) $(MAKE) $(build)=flog $@
flog:
$(Q) $(MAKE) $(build)=flog all
.PHONY: flog

#
# CRIU building done in own directory
# with slightly different rules so we
Expand Down Expand Up @@ -285,6 +294,7 @@ lib: criu

clean mrproper:
$(Q) $(MAKE) $(build)=images $@
$(Q) $(MAKE) $(build)=flog $@
$(Q) $(MAKE) $(build)=criu $@
$(Q) $(MAKE) $(build)=soccr $@
$(Q) $(MAKE) $(build)=lib $@
Expand Down
29 changes: 29 additions & 0 deletions flog/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
OPTS=-ggdb3 -Wall -Werror
export OPTS

CFLAGS += -iquote include
CFLAGS += -iquote flog/include
CFLAGS += -iquote flog/include/uapi

include $(__nmk_dir)msg.mk

$(eval $(call gen-built-in,src))

flog:
$(Q) $(MAKE) $(build)=$(obj)/src all
.PHONY: flog

clean-flog:
$(call msg-gen, $@)
$(Q) $(MAKE) $(build)=$(obj)/src clean
$(Q) $(RM) built-in.o
.PHONY: clean-flog

clean: clean-flog
mrproper: clean

test:
./tests/test00

all-y += flog

4 changes: 4 additions & 0 deletions flog/built-in.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SECTIONS
{
.rodata : { _rodata_start = . ; *(.rodata*) ; _rodata_end = . ;}
}
71 changes: 71 additions & 0 deletions flog/include/compiler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#ifndef __COMPILER_H__
#define __COMPILER_H__

/*
* Various definitions for success build,
* picked from various places, mostly from
* the linux kernel.
*/

#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))

#define __stringify_1(x...) #x
#define __stringify(x...) __stringify_1(x)

#define NORETURN __attribute__((__noreturn__))
#define __packed __attribute__((__packed__))
#define __used __attribute__((__used__))
#define __maybe_unused __attribute__((unused))
#define __always_unused __attribute__((unused))

#define __section(S) __attribute__ ((__section__(#S)))

#ifndef __always_inline
# define __always_inline inline __attribute__((always_inline))
#endif

#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)

#ifndef always_inline
# define always_inline __always_inline
#endif

#ifndef noinline
# define noinline __attribute__((noinline))
#endif

#define __aligned(x) __attribute__((aligned(x)))

#ifndef offsetof
# define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
#endif

#define barrier() asm volatile("" ::: "memory")

#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})

#define __round_mask(x, y) ((__typeof__(x))((y) - 1))
#define round_up(x, y) ((((x) - 1) | __round_mask(x, y)) + 1)
#define round_down(x, y) ((x) & ~__round_mask(x, y))
#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))

#define min(x, y) ({ \
typeof(x) _min1 = (x); \
typeof(y) _min2 = (y); \
(void) (&_min1 == &_min2); \
_min1 < _min2 ? _min1 : _min2; })

#define max(x, y) ({ \
typeof(x) _max1 = (x); \
typeof(y) _max2 = (y); \
(void) (&_max1 == &_max2); \
_max1 > _max2 ? _max1 : _max2; })

#define is_log2(v) (((v) & ((v) - 1)) == 0)

#endif /* __COMPILER_H__ */
9 changes: 9 additions & 0 deletions flog/include/flog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef __FLOG_H__
#define __FLOG_H__

#include <string.h>
#include <errno.h>

#include "uapi/flog.h"

#endif /* __FLOG_H__ */
17 changes: 17 additions & 0 deletions flog/include/log.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef __LOG_H__
#define __LOG_H__

#include <stdio.h>

#define pr_out(fmt, ...) fprintf(stdout, fmt, ##__VA_ARGS__)

#if 1
# define pr_debug(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__)
#else
# define pr_debug(fmt, ...)
#endif

#define pr_err(fmt, ...) fprintf(stderr, "Error (%s:%d): "fmt, __FILE__, __LINE__, ##__VA_ARGS__)
#define pr_perror(fmt, ...) fprintf(stderr, "Error (%s:%d): "fmt "%m\n", __FILE__, __LINE__, ##__VA_ARGS__)

#endif /* __LOG_H__ */
16 changes: 16 additions & 0 deletions flog/include/types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef __FLOG_TYPES_H__
#define __FLOG_TYPES_H__

#include <stdint.h>
#include <stdbool.h>

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef uint16_t u16;
typedef int16_t s16;
typedef uint8_t u8;
typedef int8_t s8;

#endif /* __FLOG_TYPES_H__ */
149 changes: 149 additions & 0 deletions flog/include/uapi/flog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
#ifndef __UAPI_FLOG_H__
#define __UAPI_FLOG_H__

#include <stdbool.h>
#include <string.h>
#include <errno.h>

/*
* We work with up to 32 arguments in macros here.
* If more provided -- behaviour is undefined.
*/

/*
* By Laurent Deniau at https://groups.google.com/forum/#!topic/comp.std.c/d-6Mj5Lko_s
*/
#define FLOG_PP_NARG_(...) FLOG_PP_ARG_N(__VA_ARGS__)
#define FLOG_PP_NARG(...) FLOG_PP_NARG_(1, ##__VA_ARGS__, FLOG_PP_RSEQ_N())

#define FLOG_PP_ARG_N( _0, _1, _2, _3, _4, \
_5, _6, _7, _8, _9, \
_10,_11,_12,_13,_14, \
_15,_16,_17,_18,_19, \
_20,_21,_22,_23,_24, \
_25,_26,_27,_28,_29, \
_30,_31, N, ...) N

#define FLOG_PP_RSEQ_N() \
31, 30, 29, 28, 27, \
26, 25, 24, 23, 22, \
21, 20, 19, 18, 17, \
16, 15, 14, 13, 12, \
11, 10, 9, 8, 7, \
6, 5, 4, 3, 2, \
1, 0

#define FLOG_GENMASK_0(N, x) 0
#define FLOG_GENMASK_1(N, op, x, ...) (op(N, 0, x))
#define FLOG_GENMASK_2(N, op, x, ...) ((op(N, 1, x)) | FLOG_GENMASK_1(N, op, __VA_ARGS__))
#define FLOG_GENMASK_3(N, op, x, ...) ((op(N, 2, x)) | FLOG_GENMASK_2(N, op, __VA_ARGS__))
#define FLOG_GENMASK_4(N, op, x, ...) ((op(N, 3, x)) | FLOG_GENMASK_3(N, op, __VA_ARGS__))
#define FLOG_GENMASK_5(N, op, x, ...) ((op(N, 4, x)) | FLOG_GENMASK_4(N, op, __VA_ARGS__))
#define FLOG_GENMASK_6(N, op, x, ...) ((op(N, 5, x)) | FLOG_GENMASK_5(N, op, __VA_ARGS__))
#define FLOG_GENMASK_7(N, op, x, ...) ((op(N, 6, x)) | FLOG_GENMASK_6(N, op, __VA_ARGS__))
#define FLOG_GENMASK_8(N, op, x, ...) ((op(N, 7, x)) | FLOG_GENMASK_7(N, op, __VA_ARGS__))
#define FLOG_GENMASK_9(N, op, x, ...) ((op(N, 8, x)) | FLOG_GENMASK_8(N, op, __VA_ARGS__))
#define FLOG_GENMASK_10(N, op, x, ...) ((op(N, 9, x)) | FLOG_GENMASK_9(N, op, __VA_ARGS__))
#define FLOG_GENMASK_11(N, op, x, ...) ((op(N, 10, x)) | FLOG_GENMASK_10(N, op, __VA_ARGS__))
#define FLOG_GENMASK_12(N, op, x, ...) ((op(N, 11, x)) | FLOG_GENMASK_11(N, op, __VA_ARGS__))
#define FLOG_GENMASK_13(N, op, x, ...) ((op(N, 12, x)) | FLOG_GENMASK_12(N, op, __VA_ARGS__))
#define FLOG_GENMASK_14(N, op, x, ...) ((op(N, 13, x)) | FLOG_GENMASK_13(N, op, __VA_ARGS__))
#define FLOG_GENMASK_15(N, op, x, ...) ((op(N, 14, x)) | FLOG_GENMASK_14(N, op, __VA_ARGS__))
#define FLOG_GENMASK_16(N, op, x, ...) ((op(N, 15, x)) | FLOG_GENMASK_15(N, op, __VA_ARGS__))
#define FLOG_GENMASK_17(N, op, x, ...) ((op(N, 16, x)) | FLOG_GENMASK_16(N, op, __VA_ARGS__))
#define FLOG_GENMASK_18(N, op, x, ...) ((op(N, 17, x)) | FLOG_GENMASK_17(N, op, __VA_ARGS__))
#define FLOG_GENMASK_19(N, op, x, ...) ((op(N, 18, x)) | FLOG_GENMASK_18(N, op, __VA_ARGS__))
#define FLOG_GENMASK_20(N, op, x, ...) ((op(N, 19, x)) | FLOG_GENMASK_19(N, op, __VA_ARGS__))
#define FLOG_GENMASK_21(N, op, x, ...) ((op(N, 20, x)) | FLOG_GENMASK_20(N, op, __VA_ARGS__))
#define FLOG_GENMASK_22(N, op, x, ...) ((op(N, 21, x)) | FLOG_GENMASK_21(N, op, __VA_ARGS__))
#define FLOG_GENMASK_23(N, op, x, ...) ((op(N, 22, x)) | FLOG_GENMASK_22(N, op, __VA_ARGS__))
#define FLOG_GENMASK_24(N, op, x, ...) ((op(N, 23, x)) | FLOG_GENMASK_23(N, op, __VA_ARGS__))
#define FLOG_GENMASK_25(N, op, x, ...) ((op(N, 24, x)) | FLOG_GENMASK_24(N, op, __VA_ARGS__))
#define FLOG_GENMASK_26(N, op, x, ...) ((op(N, 25, x)) | FLOG_GENMASK_25(N, op, __VA_ARGS__))
#define FLOG_GENMASK_27(N, op, x, ...) ((op(N, 26, x)) | FLOG_GENMASK_26(N, op, __VA_ARGS__))
#define FLOG_GENMASK_28(N, op, x, ...) ((op(N, 27, x)) | FLOG_GENMASK_27(N, op, __VA_ARGS__))
#define FLOG_GENMASK_29(N, op, x, ...) ((op(N, 28, x)) | FLOG_GENMASK_28(N, op, __VA_ARGS__))
#define FLOG_GENMASK_30(N, op, x, ...) ((op(N, 29, x)) | FLOG_GENMASK_29(N, op, __VA_ARGS__))
#define FLOG_GENMASK_31(N, op, x, ...) ((op(N, 30, x)) | FLOG_GENMASK_30(N, op, __VA_ARGS__))
#define FLOG_GENMASK_32(N, op, x, ...) ((op(N, 31, x)) | FLOG_GENMASK_31(N, op, __VA_ARGS__))

#define FLOG_CONCAT(arg1, arg2) FLOG_CONCAT1(arg1, arg2)
#define FLOG_CONCAT1(arg1, arg2) FLOG_CONCAT2(arg1, arg2)
#define FLOG_CONCAT2(arg1, arg2) arg1##arg2

#define FLOG_GENMASK_(N, op, ...) FLOG_CONCAT(FLOG_GENMASK_, N)(N, op, ##__VA_ARGS__)
#define FLOG_GENMASK(op, ...) FLOG_GENMASK_(FLOG_PP_NARG(__VA_ARGS__), op, ##__VA_ARGS__)

#define flog_genbit(ord, n, v, ...) \
_Generic((v), \
\
/* Basic types */ \
char: 0, \
signed char: 0, \
unsigned char: 0, \
signed short int: 0, \
unsigned short int: 0, \
signed int: 0, \
unsigned int: 0, \
signed long: 0, \
unsigned long: 0, \
signed long long: 0, \
unsigned long long: 0, \
\
/* Not used for a while */ \
/* float: 12, */ \
/* double: 13, */ \
/* long double: 14, */ \
\
/* Basic poniters */ \
char *: (1u << (ord - n - 1)), \
signed char *: (1u << (ord - n - 1)), \
unsigned char *: (1u << (ord - n - 1)), \
signed short int *: 0, \
unsigned short int *: 0, \
signed int *: 0, \
unsigned int *: 0, \
signed long *: 0, \
unsigned long *: 0, \
signed long long *: 0, \
unsigned long long *: 0, \
void *: 0, \
\
/* Const basic pointers */ \
const char *: (1u << (ord - n - 1)), \
const signed char *: (1u << (ord - n - 1)), \
const unsigned char *: (1u << (ord - n - 1)), \
const signed short int *: 0, \
const unsigned short int *: 0, \
const signed int *: 0, \
const unsigned int *: 0, \
const signed long *: 0, \
const unsigned long *: 0, \
const signed long long *: 0, \
const unsigned long long *: 0, \
const void *: 0, \
\
/* Systypes and pointers */ \
default: -1)

typedef struct {
unsigned int magic;
unsigned int size;
unsigned int nargs;
unsigned int mask;
long fmt;
long args[0];
} flog_msg_t;

extern int flog_encode_msg(int fdout, unsigned int nargs, unsigned int mask, const char *format, ...);
void flog_decode_msg(int fdout, const char *format, ...);
extern int flog_decode_all(int fdin, int fdout);

#define flog_encode(fdout, fmt, ...) \
flog_encode_msg(fdout, FLOG_PP_NARG(__VA_ARGS__), \
FLOG_GENMASK(flog_genbit, ##__VA_ARGS__), fmt, ##__VA_ARGS__)

int flog_map_buf(int fdout);
int flog_close(int fdout);

#endif /* __UAPI_FLOG_H__ */
37 changes: 37 additions & 0 deletions flog/include/util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#ifndef __UTIL_H__
#define __UTIL_H__

#include <string.h>
#include <errno.h>

#include "log.h"
#include "types.h"

#define __xalloc(op, size, ...) \
({ \
void *___p = op(__VA_ARGS__); \
___p; \
})

#define xstrdup(str) __xalloc(strdup, strlen(str) + 1, str)
#define xmalloc(size) __xalloc(malloc, size, size)
#define xzalloc(size) __xalloc(calloc, size, 1, size)
#define xrealloc(p, size) __xalloc(realloc, size, p, size)

#define xfree(p) do { if (p) free(p); } while (0)

#define xrealloc_safe(pptr, size) \
({ \
int __ret = -ENOMEM; \
void *new = xrealloc(*pptr, size); \
if (new) { \
*pptr = new; \
__ret = 0; \
} \
__ret; \
})

#define memzero_p(p) memset(p, 0, sizeof(*p))
#define memzero(p, size) memset(p, 0, size)

#endif /* __UTIL_H__ */
5 changes: 5 additions & 0 deletions flog/src/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ccflags-y += -DCONFIG_X86_64 -iquote ./include $(OPTS)
ldflags-y += -r

#obj-y += main.o
obj-y += flog.o
Loading

0 comments on commit 7ec1ef9

Please sign in to comment.