guix-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug#75027] [PATCH v2 1/3] syscalls: Add ‘kexec-load-file’.


From: Maxim Cournoyer
Subject: [bug#75027] [PATCH v2 1/3] syscalls: Add ‘kexec-load-file’.
Date: Sat, 28 Dec 2024 15:12:02 +0900
User-agent: Gnus/5.13 (Gnus v5.13)

Hi Ludovic,

Ludovic Courtès <ludo@gnu.org> writes:

> * guix/build/syscalls.scm (string->utf-8/nul-terminated)
> (kexec-load-file): New procedures.

[...]

> +;; Constants from <linux/kexec.h>.
> +(define KEXEC_FILE_UNLOAD    #x00000001)
> +(define KEXEC_FILE_ON_CRASH  #x00000002)
> +(define KEXEC_FILE_NO_INITRAMFS      #x00000004)
> +(define KEXEC_FILE_DEBUG     #x00000008)
> +
> +(define kexec-load-file
> +  (let* ((proc (syscall->procedure int "syscall"
> +                                   (list long             ;sysno
> +                                         int              ;kernel fd
> +                                         int              ;initrd fd
> +                                         unsigned-long    ;cmdline length
> +                                         '*               ;cmdline
> +                                         unsigned-long))) ;flags
> +         ;; TODO: Don't do this.

Why this TODO?  "Don't do this" is not explicit enough; what would be
preferable to do here, but can't be done now for some reason?  Could we
instead detect the error as returned by the syscall when it's not
implemented, and throw/report the error accordingly?  I see that's kind
of done below (a misc-error is raised) -- I think we can remove this
special handling already and let the error be throw if it's not
implemented -- this removes the need to remember to come back here to
edit the list of supported systems the day they gain support.

> +         (syscall-id (match (utsname:machine (uname))
> +                       ("i686"    320)
> +                       ("x86_64"  320)
> +                       ("armv7l"  401)
> +                       ("aarch64" 401)
> +                       ;; XXX: There's apparently no support for ppc64le and
> +                       ;; riscv64.
> +                       (_ #f))))
> +    (lambda* (kernel-fd initrd-fd command-line #:optional (flags 0))
> +      "Load for eventual use of kexec(8) the Linux kernel from
> +@var{kernel-fd}, its initial RAM disk from @var{initrd-fd}, with the given
> +@var{command-line} (a string).  Optionally, @var{flags} can be a bitwise or 
> of
> +the KEXEC_FILE_* constants."
> +      (let*-values (((command-line)
> +                     (string->utf-8/nul-terminated command-line))
> +                    ((ret err)
> +                     (proc syscall-id kernel-fd initrd-fd
> +                           (bytevector-length command-line)
> +                           (bytevector->pointer command-line)
> +                           flags)))
> +        (when (= ret -1)

I checked 'man 2 kexec_file_load*' to make sure:

       On success, these system calls returns 0.  On error, -1 is returned and
       errno is set to indicate the error.

So, looks good.

-- 
Thanks,
Maxim





reply via email to

[Prev in Thread] Current Thread [Next in Thread]