Re: 18/36: services: hurd: Add dummy loopback.

2020-05-06 Thread Ludovic Courtès
Hi!

Jan Nieuwenhuizen  skribis:

> (use-modules (guix build syscalls))
>
> (define LOOPBACK? #t)
> (define IP "127.0.0.1" )
> (define INTERFACE "lo")
> (define NETMASK #f)
> (define GATEWAY #f)
>
> (format #t "ifreq-struct-size: ~a\n" (@@ (guix build syscalls) 
> ifreq-struct-size))
> (format #t "sizeof-ifconf: ~s\n" (@@ (guix build syscalls) sizeof-ifconf))
> (define (test)
>   (let* ((addr (inet-pton AF_INET IP))
>  (sockaddr (make-socket-address AF_INET addr 0))
>  (mask (and NETMASK
> (inet-pton AF_INET NETMASK)))
>  (maskaddr (and mask
> (make-socket-address AF_INET
>  mask 0)))
>  (gateway  (and GATEWAY
> (inet-pton AF_INET GATEWAY)))
>  (gatewayaddr (and gateway
>(make-socket-address AF_INET
> gateway 0
> (configure-network-interface INTERFACE sockaddr
>  (logior IFF_UP
>  (if LOOPBACK?
>  IFF_LOOPBACK
>  0))
>  #:netmask maskaddr)
> (when gateway
>   (let ((sock (socket AF_INET SOCK_DGRAM 0)))
> (add-network-route/gateway sock gatewayaddr)
> (close-port sock)
>
> (test)

Could you change that last line to:

  (catch 'system-error
test
(lambda args
  (let ((errno (system-error-errno args)))
(pk errno (strerror errno)

?

The out-of-range exception presumably is an unrelated error in Guile’s
debugger and it’s shadowing the one we’re interested in.

TIA!

Ludo’.



Re: 18/36: services: hurd: Add dummy loopback.

2020-05-06 Thread Ludovic Courtès
Hi,

Vincent Legoll  skribis:

> On Tue, May 5, 2020 at 11:23 AM Ludovic Courtès  wrote:
>> The patch below appears to fix it:
>
> Is target-word-size checking always equivalent to cross-compiling ?

In this case it’s sufficient: it’s just about ‘sizeof’ and ‘alignof’, so
the word size is all that matters.

Ludo’.



Re: 18/36: services: hurd: Add dummy loopback.

2020-05-05 Thread Jan Nieuwenhuizen
Ludovic Courtès writes:

Hi,

>> Something like that: sizeof-ifconf is set to 16 (like on x86_64), but
>> it's size should be 8.
>
> Oh, that’s because ‘define-c-struct’ does all the work at
> macro-expansion time, with the host types and alignment constraints.  I
> wonder how we didn’t notice it earlier.  Cross-compiling from x86_64 to
> ARMv7 has the same problem, but maybe the networking ioctls work by
> chance.
>
> The patch below appears to fix it:

Yes, it fixes the struct sizes in the cross-compiled .go file.  Thanks!
I have added it as the attached patch to "wip-hurd-vm" for now.  I did

./pre-inst-env guild compile --target=i586-pc-gnu -o syscalls.go 
guix/build/syscalls.scm 

and copied that to the Hurd.

When running this (changed #$... to UPPERCASE)

--8<---cut here---start->8---
(use-modules (guix build syscalls))

(define LOOPBACK? #t)
(define IP "127.0.0.1" )
(define INTERFACE "lo")
(define NETMASK #f)
(define GATEWAY #f)

(format #t "ifreq-struct-size: ~a\n" (@@ (guix build syscalls) 
ifreq-struct-size))
(format #t "sizeof-ifconf: ~s\n" (@@ (guix build syscalls) sizeof-ifconf))
(define (test)
  (let* ((addr (inet-pton AF_INET IP))
 (sockaddr (make-socket-address AF_INET addr 0))
 (mask (and NETMASK
(inet-pton AF_INET NETMASK)))
 (maskaddr (and mask
(make-socket-address AF_INET
 mask 0)))
 (gateway  (and GATEWAY
(inet-pton AF_INET GATEWAY)))
 (gatewayaddr (and gateway
   (make-socket-address AF_INET
gateway 0
(configure-network-interface INTERFACE sockaddr
 (logior IFF_UP
 (if LOOPBACK?
 IFF_LOOPBACK
 0))
 #:netmask maskaddr)
(when gateway
  (let ((sock (socket AF_INET SOCK_DGRAM 0)))
(add-network-route/gateway sock gatewayaddr)
(close-port sock)

(test)
--8<---cut here---end--->8---

Now I see the correct sizes...

root@guixygnu# guile -L . -C . static.scm 
;;; note: source file /root/static.scm
;;;   newer than compiled 
/root/.cache/guile/ccache/3.0-LE-4-4.2/root/static.scm.go
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;;   or pass the --no-auto-compile argument to disable.
;;; compiling /root/static.scm
;;; compiled /root/.cache/guile/ccache/3.0-LE-4-4.2/root/static.scm.go
ifreq-struct-size: 32
sizeof-ifconf: 8
Backtrace:
In ice-9/boot-9.scm:
  1736:10  9 (with-exception-handler _ _ #:unwind? _ # _)
In unknown file:
   8 (apply-smob/0 #)
In ice-9/boot-9.scm:
718:2  7 (call-with-prompt _ _ #)
In ice-9/eval.scm:
619:8  6 (_ #(#(#)))
In ice-9/boot-9.scm:
   2806:4  5 (save-module-excursion _)
  4351:12  4 (_)
In static.scm:
 24:4  3 (test)
In guix/build/syscalls.scm:
   1529:8  2 (configure-network-interface "lo" #(2 2130706433 0) 9 # _)
  1464:18  1 (_ _ "lo" _)
In unknown file:
Exception thrown while printing backtrace:
In procedure primitive-call-ip: Wrong type argument in position 1 (expecting 
PRIMITIVE_P): #

ERROR: Value out of range 0 to 4294967295: -1

...but still/again a similar range error; Ideas?

Greetings,
janneke

>From 33fbfcd7f46cf675cc24db92b1110d38afa51ae5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= 
Date: Tue, 5 May 2020 11:53:39 +0200
Subject: [PATCH] syscalls: Cross-build fix for alignof*, sizeof*.

See .
Reported by Jan (janneke) Nieuwenhuizen .

* guix/build/syscalls.scm (sizeof*, alignof*): When cross-compiling, emit code
to call at runtime.
---
 guix/build/syscalls.scm | 23 +--
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm
index 73b439fb7d..00d8ceb480 100644
--- a/guix/build/syscalls.scm
+++ b/guix/build/syscalls.scm
@@ -23,6 +23,7 @@
 
 (define-module (guix build syscalls)
   #:use-module (system foreign)
+  #:use-module (system base target)
   #:use-module (rnrs bytevectors)
   #:autoload   (ice-9 binary-ports) (get-bytevector-n)
   #:use-module (srfi srfi-1)
@@ -194,9 +195,14 @@
  (* (sizeof* type) n))
 ((_ type)
  (let-syntax ((v (lambda (s)
-   (let ((val (sizeof type)))
- (syntax-case s ()
-   (_ val))
+   ;; When compiling natively, call 'sizeof' at expansion
+   ;; time; otherwise, emit code to call it at run time.
+   (syntax-case s ()
+ (_
+  (if (= (target-word-size)
+ 

Re: 18/36: services: hurd: Add dummy loopback.

2020-05-05 Thread Vincent Legoll
Hello,

On Tue, May 5, 2020 at 11:23 AM Ludovic Courtès  wrote:
> The patch below appears to fix it:

Is target-word-size checking always equivalent to cross-compiling ?

Aren't there cross-compilation host/target combos where this will
be true, but still there will be other differences (endianness maybe) ?

I don't know if the question really makes sense, though, so please
forgive my ignorance...

-- 
Vincent Legoll



Re: 18/36: services: hurd: Add dummy loopback.

2020-05-05 Thread Ludovic Courtès
Hi,

Jan Nieuwenhuizen  skribis:

>> Could it be ‘ifreq-struct-size’ that’s off on GNU/Hurd, or one of its
>> friends?
>
> Something like that: sizeof-ifconf is set to 16 (like on x86_64), but
> it's size should be 8.

Oh, that’s because ‘define-c-struct’ does all the work at
macro-expansion time, with the host types and alignment constraints.  I
wonder how we didn’t notice it earlier.  Cross-compiling from x86_64 to
ARMv7 has the same problem, but maybe the networking ioctls work by
chance.

The patch below appears to fix it:

--8<---cut here---start->8---
$ ./pre-inst-env guild compile --target=i686-pc-linux-gnu 
guix/build/syscalls.scm -o guix/build/syscalls.go
wrote `guix/build/syscalls.go'
$ guix environment -s i686-linux -C --ad-hoc guile-next -- guile -L . -C .
GNU Guile 3.0.2
Copyright (C) 1995-2020 Free Software Foundation, Inc.

Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.

Enter `,help' for help.
scheme@(guile-user)> ,use(guix build syscalls)
scheme@(guile-user)> ,m(guix build syscalls)
scheme@(guix build syscalls)> sizeof-ifconf
$1 = 8
scheme@(guix build syscalls)> %host-type
$2 = "i686-unknown-linux-gnu"
--8<---cut here---end--->8---

Thank you!

Ludo’.

diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm
index 73b439fb7d..00d8ceb480 100644
--- a/guix/build/syscalls.scm
+++ b/guix/build/syscalls.scm
@@ -23,6 +23,7 @@
 
 (define-module (guix build syscalls)
   #:use-module (system foreign)
+  #:use-module (system base target)
   #:use-module (rnrs bytevectors)
   #:autoload   (ice-9 binary-ports) (get-bytevector-n)
   #:use-module (srfi srfi-1)
@@ -194,9 +195,14 @@
  (* (sizeof* type) n))
 ((_ type)
  (let-syntax ((v (lambda (s)
-   (let ((val (sizeof type)))
- (syntax-case s ()
-   (_ val))
+   ;; When compiling natively, call 'sizeof' at expansion
+   ;; time; otherwise, emit code to call it at run time.
+   (syntax-case s ()
+ (_
+  (if (= (target-word-size)
+ (with-target %host-type target-word-size))
+  (sizeof type)
+  #'(sizeof type)))
v
 
 (define-syntax alignof*
@@ -208,9 +214,14 @@
  (alignof* type))
 ((_ type)
  (let-syntax ((v (lambda (s)
-   (let ((val (alignof type)))
- (syntax-case s ()
-   (_ val))
+   ;; When compiling natively, call 'sizeof' at expansion
+   ;; time; otherwise, emit code to call it at run time.
+   (syntax-case s ()
+ (_
+  (if (= (target-word-size)
+ (with-target %host-type target-word-size))
+  (alignof type)
+  #'(alignof type)))
v
 
 (define-syntax align ;as found in (system foreign)


Re: 18/36: services: hurd: Add dummy loopback.

2020-05-03 Thread Jan Nieuwenhuizen
Ludovic Courtès writes:

>> herd: exeception caught while executing 'start' on service 'loopback':
>> Value out of range 0 to 4294967295: -1
>
> Ah see, it’s out of range.
>
> Could you run Guile, load (guix build syscalls), and try to run the code
> of the ‘start’ method that appears in
> ‘static-networking-shepherd-service’ to see which syscall is giving us
> that error?

Yes, that reproduces!

> Could it be ‘ifreq-struct-size’ that’s off on GNU/Hurd, or one of its
> friends?

Something like that: sizeof-ifconf is set to 16 (like on x86_64), but
it's size should be 8.

Not sure how that works!?

Greetings,
janneke

-- 
Jan Nieuwenhuizen  | GNU LilyPond http://lilypond.org
Freelance IT http://JoyofSource.com | Avatar® http://AvatarAcademy.com



Re: 18/36: services: hurd: Add dummy loopback.

2020-05-03 Thread Ludovic Courtès
Hi,

Jan Nieuwenhuizen  skribis:

> Ah, great!  I rewrote this to use ...and it almost
> works already.  I have added
>
> (service static-networking-service-type
>  (list (static-networking (interface "lo")
>   (ip "127.0.0.1")
>   (requirement '())
>   (provision '(loopback)
>
> and the VM builds, only it doesn't start
>
> herd: exeception caught while executing 'start' on service 'loopback':
> Value out of range 0 to 4294967295: -1

Ah see, it’s out of range.

Could you run Guile, load (guix build syscalls), and try to run the code
of the ‘start’ method that appears in
‘static-networking-shepherd-service’ to see which syscall is giving us
that error?

Could it be ‘ifreq-struct-size’ that’s off on GNU/Hurd, or one of its
friends?

Ludo’.



Re: 18/36: services: hurd: Add dummy loopback.

2020-05-01 Thread Jan Nieuwenhuizen
Ludovic Courtès writes:

> guix-comm...@gnu.org skribis:
>
>> +(define (hurd-loopback-shepherd-service _)
>> +  "Return the 'loopback' Shepherd service."
>> +
>> +  (list (shepherd-service
>> + (documentation "Dummy for bootstrapping (gnu services) on the 
>> Hurd.")
>> + (provision '(loopback))
>> + (requirement '())
>> + (start #~(const #t))
>> + (stop #~(const #t))
>> + (respawn? #f
>> +
>> +(define hurd-loopback-service-type
>> +  (service-type
>> +   (name 'loopback)
>> +   (extensions (list (service-extension shepherd-root-service-type
>> +hurd-loopback-shepherd-service)))
>> +   (compose concatenate)
>> +   (extend first-of-two)
>> +   (default-value '(loopback)) ;canary for hurd-service->shepherd-service
>> +   (description "Dummy service to bootstrap (gnu services) on the
>> +Hurd.")))
>
> I believe the code currently used in ‘static-networking-service’ to
> setup the loopback device on GNU/Linux should also work on GNU/Hurd: it
> uses the “traditional” ioctls provided by (guix build syscalls).
>
> So hopefully we don’t need a Hurd-specific variant.

Ah, great!  I rewrote this to use ...and it almost
works already.  I have added

(service static-networking-service-type
 (list (static-networking (interface "lo")
  (ip "127.0.0.1")
  (requirement '())
  (provision '(loopback)

and the VM builds, only it doesn't start

herd: exeception caught while executing 'start' on service 'loopback':
Value out of range 0 to 4294967295: -1

I have added new code for this as a squash! commit, that I then also
revert for now, until it works. :-(

Greetings,
janneke

-- 
Jan Nieuwenhuizen  | GNU LilyPond http://lilypond.org
Freelance IT http://JoyofSource.com | Avatar® http://AvatarAcademy.com



Re: 18/36: services: hurd: Add dummy loopback.

2020-04-30 Thread Ludovic Courtès
guix-comm...@gnu.org skribis:

> +(define (hurd-loopback-shepherd-service _)
> +  "Return the 'loopback' Shepherd service."
> +
> +  (list (shepherd-service
> + (documentation "Dummy for bootstrapping (gnu services) on the 
> Hurd.")
> + (provision '(loopback))
> + (requirement '())
> + (start #~(const #t))
> + (stop #~(const #t))
> + (respawn? #f
> +
> +(define hurd-loopback-service-type
> +  (service-type
> +   (name 'loopback)
> +   (extensions (list (service-extension shepherd-root-service-type
> +hurd-loopback-shepherd-service)))
> +   (compose concatenate)
> +   (extend first-of-two)
> +   (default-value '(loopback)) ;canary for hurd-service->shepherd-service
> +   (description "Dummy service to bootstrap (gnu services) on the
> +Hurd.")))

I believe the code currently used in ‘static-networking-service’ to
setup the loopback device on GNU/Linux should also work on GNU/Hurd: it
uses the “traditional” ioctls provided by (guix build syscalls).

So hopefully we don’t need a Hurd-specific variant.

Ludo’.