[CRIU] [PATCH 1/4] syscall: add memfd_create() (v2)

Pavel Emelyanov xemul at parallels.com
Tue Oct 14 02:05:52 PDT 2014


On 10/14/2014 12:42 PM, Andrey Vagin wrote:
> v2: Follow the kerndat style that "features" are described
> just by global boolean variables.
> 
> Signed-off-by: Andrey Vagin <avagin at openvz.org>
> ---
>  arch/arm/syscall.def        |  1 +
>  arch/x86/syscall-x86-64.def |  1 +
>  include/kerndat.h           |  2 ++
>  kerndat.c                   | 21 +++++++++++++++++++++
>  4 files changed, 25 insertions(+)
> 
> diff --git a/arch/arm/syscall.def b/arch/arm/syscall.def
> index 02eaa65..3b2d1ed 100644
> --- a/arch/arm/syscall.def
> +++ b/arch/arm/syscall.def
> @@ -96,3 +96,4 @@ kcmp				272	378	(pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned
>  openat				56	322	(int dirfd, const char *pathname, int flags, mode_t mode)
>  mkdirat				34	323	(int dirfd, const char *pathname, mode_t mode)
>  unlinkat			35	328	(int dirfd, const char *pathname, int flags)
> +memfd_create			279	385	(const char *name, unsigned int flags)
> diff --git a/arch/x86/syscall-x86-64.def b/arch/x86/syscall-x86-64.def
> index 5d31337..c780c40 100644
> --- a/arch/x86/syscall-x86-64.def
> +++ b/arch/x86/syscall-x86-64.def
> @@ -96,3 +96,4 @@ __NR_prlimit64		302		sys_prlimit64		(pid_t pid, unsigned int resource, const str
>  __NR_open_by_handle_at	304		sys_open_by_handle_at	(int mountdirfd, struct file_handle *handle, int flags)
>  __NR_setns		308		sys_setns		(int fd, int nstype)
>  __NR_kcmp		312		sys_kcmp		(pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx2)
> +__NR_memfd_create	319		sys_memfd_create	(const char *name, unsigned int flags)
> diff --git a/include/kerndat.h b/include/kerndat.h
> index 6b9947f..2b0a653 100644
> --- a/include/kerndat.h
> +++ b/include/kerndat.h
> @@ -24,4 +24,6 @@ extern u64 zero_page_pfn;
>  struct stat;
>  extern struct stat *kerndat_get_devpts_stat(void);
>  
> +extern bool memfd_is_supported;
> +
>  #endif /* __CR_KERNDAT_H__ */
> diff --git a/kerndat.c b/kerndat.c
> index 3c87f6c..0d4fb58 100644
> --- a/kerndat.c
> +++ b/kerndat.c
> @@ -13,6 +13,7 @@
>  #include "mem.h"
>  #include "compiler.h"
>  #include "sysctl.h"
> +#include "syscall.h"
>  #include "asm/types.h"
>  #include "cr_options.h"
>  #include "util.h"
> @@ -220,6 +221,24 @@ int get_last_cap(void)
>  	return sysctl_op(req, CTL_READ);
>  }
>  
> +bool memfd_is_supported;
> +static bool kerndat_has_memfd_create(void)
> +{
> +	int ret;
> +
> +	ret = sys_memfd_create("", 0);
> +
> +	if (ret == -ENOSYS)
> +		memfd_is_supported = false;

return here?

> +	else if (ret < 0) {
> +		pr_err("Unexpected error %d from memfd_create(NULL, 0)\n", ret);
> +		return -1;
> +	}
> +	close(ret);
> +	memfd_is_supported = true;
> +	return 0;
> +}
> +
>  int kerndat_init(void)
>  {
>  	int ret;
> @@ -231,6 +250,8 @@ int kerndat_init(void)
>  		ret = init_zero_page_pfn();
>  	if (!ret)
>  		ret = get_last_cap();
> +	if (!ret)
> +		ret = kerndat_has_memfd_create();
>  
>  	return ret;
>  }
> 



More information about the CRIU mailing list