From c2e3552a061cf7ff1941cbd7b2f3595a20f659a8 Mon Sep 17 00:00:00 2001
From: Virgile Prevosto <virgile.prevosto@m4x.org>
Date: Thu, 9 Mar 2023 19:22:07 +0100
Subject: [PATCH] [machdep] various small fixes in manual machdep yaml and
 related places

- remove ill-placed macro in stdio.h
- better error msg for custom yaml parsing
---
 share/libc/stdio.h                      |   2 -
 share/machdeps/machdep_gcc_x86_16.yaml  | 123 +++++++++++++++++++++++-
 share/machdeps/machdep_msvc_x86_64.yaml |  80 +++++++++++++++
 share/machdeps/machdep_x86_16.yaml      | 123 +++++++++++++++++++++++-
 src/kernel_services/ast_queries/file.ml |   7 +-
 tests/value/oracle/gauges.res.oracle    |  12 +--
 6 files changed, 334 insertions(+), 13 deletions(-)

diff --git a/share/libc/stdio.h b/share/libc/stdio.h
index eb9282338d5..736bcfa6f6f 100644
--- a/share/libc/stdio.h
+++ b/share/libc/stdio.h
@@ -621,7 +621,5 @@ int asprintf(char **strp, const char *fmt, ...);
 
 __END_DECLS
 
-#define IOV_MAX 1024
-
 __POP_FC_STDLIB
 #endif
diff --git a/share/machdeps/machdep_gcc_x86_16.yaml b/share/machdeps/machdep_gcc_x86_16.yaml
index 7d36c6f2c24..e93b8af1b5d 100644
--- a/share/machdeps/machdep_gcc_x86_16.yaml
+++ b/share/machdeps/machdep_gcc_x86_16.yaml
@@ -13,10 +13,131 @@ char_is_unsigned: false
 compiler: gcc
 cpp_arch_flags:
 - -m16
+errno:
+    e2big: '7'
+    eacces: '13'
+    eaddrinuse: '98'
+    eaddrnotavail: '99'
+    eafnosupport: '97'
+    eagain: '11'
+    ealready: '114'
+    ebade: '52'
+    ebadf: '9'
+    ebadfd: '77'
+    ebadmsg: '74'
+    ebadr: '53'
+    ebadrqc: '56'
+    ebadslt: '57'
+    ebusy: '16'
+    ecanceled: '125'
+    echild: '10'
+    echrng: '44'
+    ecomm: '70'
+    econnaborted: '103'
+    econnrefused: '111'
+    econnreset: '104'
+    edeadlk: '35'
+    edeadlock: '35'
+    edestaddrreq: '89'
+    edom: '33'
+    edquot: '122'
+    eexist: '17'
+    efault: '14'
+    efbig: '27'
+    ehostdown: '112'
+    ehostunreach: '113'
+    eidrm: '43'
+    eilseq: '84'
+    einprogress: '115'
+    eintr: '4'
+    einval: '22'
+    eio: '5'
+    eisconn: '106'
+    eisdir: '21'
+    eisnam: '120'
+    ekeyexpired: '127'
+    ekeyrejected: '129'
+    ekeyrevoked: '128'
+    el2hlt: '51'
+    el2nsync: '45'
+    el3hlt: '46'
+    el3rst: '47'
+    elibacc: '79'
+    elibbad: '80'
+    elibexec: '83'
+    elibmax: '82'
+    elibscn: '81'
+    eloop: '40'
+    emediumtype: '124'
+    emfile: '24'
+    emlink: '31'
+    emsgsize: '90'
+    emultihop: '72'
+    enametoolong: '36'
+    enetdown: '100'
+    enetreset: '102'
+    enetunreach: '101'
+    enfile: '23'
+    enobufs: '105'
+    enodata: '61'
+    enodev: '19'
+    enoent: '2'
+    enoexec: '8'
+    enokey: '126'
+    enolck: '37'
+    enolink: '67'
+    enomedium: '123'
+    enomem: '12'
+    enomsg: '42'
+    enonet: '64'
+    enopkg: '65'
+    enoprotoopt: '92'
+    enospc: '28'
+    enosr: '63'
+    enostr: '60'
+    enosys: '38'
+    enotblk: '15'
+    enotconn: '107'
+    enotdir: '20'
+    enotempty: '39'
+    enotsock: '88'
+    enotsup: '95'
+    enotty: '25'
+    enotuniq: '76'
+    enxio: '6'
+    eopnotsupp: '95'
+    eoverflow: '75'
+    eperm: '1'
+    epfnosupport: '96'
+    epipe: '32'
+    eproto: '71'
+    eprotonosupport: '93'
+    eprototype: '91'
+    erange: '34'
+    eremchg: '78'
+    eremote: '66'
+    eremoteio: '121'
+    erestart: '85'
+    erofs: '30'
+    eshutdown: '108'
+    esocktnosupport: '94'
+    espipe: '29'
+    esrch: '3'
+    estale: '116'
+    estrpipe: '86'
+    etime: '62'
+    etimedout: '110'
+    etxtbsy: '26'
+    euclean: '117'
+    eunatch: '49'
+    eusers: '87'
+    ewouldblock: '11'
+    exdev: '18'
+    exfull: '54'
 has__builtin_va_list: true
 intptr_t: long
 little_endian: true
-nsig: 65
+nsig: '65'
 ptrdiff_t: int
 sig_atomic_t: int
 size_t: unsigned int
diff --git a/share/machdeps/machdep_msvc_x86_64.yaml b/share/machdeps/machdep_msvc_x86_64.yaml
index a71a5365fa0..6f0b88d2cd7 100644
--- a/share/machdeps/machdep_msvc_x86_64.yaml
+++ b/share/machdeps/machdep_msvc_x86_64.yaml
@@ -13,6 +13,86 @@ char_is_unsigned: false
 compiler: msvc
 cpp_arch_flags:
 - -m64
+errno:
+    eperm: '1'
+    enoent: '2'
+    esrch: '3'
+    eintr: '4'
+    eio: '5'
+    enxio: '6'
+    e2big: '7'
+    enoexec: '8'
+    ebadf: '9'
+    echild: '10'
+    eagain: '11'
+    enomem: '12'
+    eacces: '13'
+    efault: '14'
+    ebusy: '16'
+    eexist: '17'
+    exdev: '18'
+    enodev: '19'
+    enotdir: '20'
+    eisdir: '21'
+    einval: '22'
+    enfile: '23'
+    emfile: '24'
+    enotty: '25'
+    etxtbsy: '139'
+    efbig: '27'
+    enospc: '28'
+    espipe: '29'
+    erofs: '30'
+    emlink: '31'
+    epipe: '32'
+    edom: '33'
+    erange: '34'
+    edeadlk: '36'
+    enametoolong: '38'
+    enolck: '39'
+    enosys: '40'
+    enotempty: '41'
+    eloop: '114'
+    ewouldblock: '140'
+    enomsg: '122'
+    eidrm: '111'
+    edeadlock: '36'
+    enostr: '125'
+    enodata: '120'
+    etime: '137'
+    enosr: '124'
+    enolink: '121'
+    eproto: '134'
+    ebadmsg: '104'
+    eoverflow: '132'
+    eilseq: '42'
+    enotsock: '128'
+    edestaddrreq: '109'
+    emsgsize: '115'
+    eprototype: '136'
+    enoprotoopt: '123'
+    eprotonosupport: '135'
+    enotsup: '129'
+    eopnotsupp: '130'
+    eafnosupport: '102'
+    eaddrinuse: '100'
+    eaddrnotavail: '101'
+    enetdown: '116'
+    enetunreach: '118'
+    enetreset: '117'
+    econnaborted: '106'
+    econnreset: '108'
+    enobufs: '119'
+    eisconn: '113'
+    enotconn: '126'
+    etimedout: '138'
+    econnrefused: '107'
+    ehostunreach: '110'
+    ealready: '103'
+    einprogress: '112'
+    ecanceled: '105'
+    eownerdead: '133'
+    enotrecoverable: '127'
 has__builtin_va_list: false
 intptr_t: signed long long
 little_endian: true
diff --git a/share/machdeps/machdep_x86_16.yaml b/share/machdeps/machdep_x86_16.yaml
index aa873f36dd6..a514e444974 100644
--- a/share/machdeps/machdep_x86_16.yaml
+++ b/share/machdeps/machdep_x86_16.yaml
@@ -13,10 +13,131 @@ char_is_unsigned: false
 compiler: generic
 cpp_arch_flags:
 - -m16
+errno:
+    e2big: '7'
+    eacces: '13'
+    eaddrinuse: '98'
+    eaddrnotavail: '99'
+    eafnosupport: '97'
+    eagain: '11'
+    ealready: '114'
+    ebade: '52'
+    ebadf: '9'
+    ebadfd: '77'
+    ebadmsg: '74'
+    ebadr: '53'
+    ebadrqc: '56'
+    ebadslt: '57'
+    ebusy: '16'
+    ecanceled: '125'
+    echild: '10'
+    echrng: '44'
+    ecomm: '70'
+    econnaborted: '103'
+    econnrefused: '111'
+    econnreset: '104'
+    edeadlk: '35'
+    edeadlock: '35'
+    edestaddrreq: '89'
+    edom: '33'
+    edquot: '122'
+    eexist: '17'
+    efault: '14'
+    efbig: '27'
+    ehostdown: '112'
+    ehostunreach: '113'
+    eidrm: '43'
+    eilseq: '84'
+    einprogress: '115'
+    eintr: '4'
+    einval: '22'
+    eio: '5'
+    eisconn: '106'
+    eisdir: '21'
+    eisnam: '120'
+    ekeyexpired: '127'
+    ekeyrejected: '129'
+    ekeyrevoked: '128'
+    el2hlt: '51'
+    el2nsync: '45'
+    el3hlt: '46'
+    el3rst: '47'
+    elibacc: '79'
+    elibbad: '80'
+    elibexec: '83'
+    elibmax: '82'
+    elibscn: '81'
+    eloop: '40'
+    emediumtype: '124'
+    emfile: '24'
+    emlink: '31'
+    emsgsize: '90'
+    emultihop: '72'
+    enametoolong: '36'
+    enetdown: '100'
+    enetreset: '102'
+    enetunreach: '101'
+    enfile: '23'
+    enobufs: '105'
+    enodata: '61'
+    enodev: '19'
+    enoent: '2'
+    enoexec: '8'
+    enokey: '126'
+    enolck: '37'
+    enolink: '67'
+    enomedium: '123'
+    enomem: '12'
+    enomsg: '42'
+    enonet: '64'
+    enopkg: '65'
+    enoprotoopt: '92'
+    enospc: '28'
+    enosr: '63'
+    enostr: '60'
+    enosys: '38'
+    enotblk: '15'
+    enotconn: '107'
+    enotdir: '20'
+    enotempty: '39'
+    enotsock: '88'
+    enotsup: '95'
+    enotty: '25'
+    enotuniq: '76'
+    enxio: '6'
+    eopnotsupp: '95'
+    eoverflow: '75'
+    eperm: '1'
+    epfnosupport: '96'
+    epipe: '32'
+    eproto: '71'
+    eprotonosupport: '93'
+    eprototype: '91'
+    erange: '34'
+    eremchg: '78'
+    eremote: '66'
+    eremoteio: '121'
+    erestart: '85'
+    erofs: '30'
+    eshutdown: '108'
+    esocktnosupport: '94'
+    espipe: '29'
+    esrch: '3'
+    estale: '116'
+    estrpipe: '86'
+    etime: '62'
+    etimedout: '110'
+    etxtbsy: '26'
+    euclean: '117'
+    eunatch: '49'
+    eusers: '87'
+    ewouldblock: '11'
+    exdev: '18'
+    exfull: '54'
 has__builtin_va_list: true
 intptr_t: long
 little_endian: true
-nsig: 65
+nsig: '65'
 ptrdiff_t: int
 sig_atomic_t: int
 size_t: unsigned int
diff --git a/src/kernel_services/ast_queries/file.ml b/src/kernel_services/ast_queries/file.ml
index c2527da3964..bf84049df3f 100644
--- a/src/kernel_services/ast_queries/file.ml
+++ b/src/kernel_services/ast_queries/file.ml
@@ -338,9 +338,10 @@ let yaml_dict_to_list = function
       Result.(
         bind acc
           (fun l ->
-             bind
-               (Yaml.Util.to_string v)
-               (fun s -> Ok ((k,s) :: l))))
+            match Yaml.Util.to_string v with
+              | Ok s -> Ok((k,s) :: l)
+              | Error (`Msg s) ->
+                  Error (`Msg ("Unexpected value for key " ^ k ^ ": " ^ s))))
     in
     List.fold_left make_one (Ok []) l
   | _ -> Error (`Msg "Unexpected YAML value instead of dictionary of strings")
diff --git a/tests/value/oracle/gauges.res.oracle b/tests/value/oracle/gauges.res.oracle
index a66e8eeac60..683d5cd6e3a 100644
--- a/tests/value/oracle/gauges.res.oracle
+++ b/tests/value/oracle/gauges.res.oracle
@@ -343,7 +343,7 @@
   # cvalue:
   __fc_heap_status ∈ [--..--]
   __fc_random_counter ∈ [--..--]
-  __fc_rand_max ∈ {32767}
+  __fc_rand_max ∈ {2147483647}
   __fc_random48_init ∈ {0}
   __fc_random48_counter[0..2] ∈ [--..--]
   __fc_p_random48_counter ∈ {{ &__fc_random48_counter[0] }}
@@ -403,7 +403,7 @@
   # cvalue:
   __fc_heap_status ∈ [--..--]
   __fc_random_counter ∈ [--..--]
-  __fc_rand_max ∈ {32767}
+  __fc_rand_max ∈ {2147483647}
   __fc_random48_init ∈ {0}
   __fc_random48_counter[0..2] ∈ [--..--]
   __fc_p_random48_counter ∈ {{ &__fc_random48_counter[0] }}
@@ -462,7 +462,7 @@
   # cvalue:
   __fc_heap_status ∈ [--..--]
   __fc_random_counter ∈ [--..--]
-  __fc_rand_max ∈ {32767}
+  __fc_rand_max ∈ {2147483647}
   __fc_random48_init ∈ {0}
   __fc_random48_counter[0..2] ∈ [--..--]
   __fc_p_random48_counter ∈ {{ &__fc_random48_counter[0] }}
@@ -521,7 +521,7 @@
   # cvalue:
   __fc_heap_status ∈ [--..--]
   __fc_random_counter ∈ [--..--]
-  __fc_rand_max ∈ {32767}
+  __fc_rand_max ∈ {2147483647}
   __fc_random48_init ∈ {0}
   __fc_random48_counter[0..2] ∈ [--..--]
   __fc_p_random48_counter ∈ {{ &__fc_random48_counter[0] }}
@@ -586,7 +586,7 @@
   # cvalue:
   __fc_heap_status ∈ [--..--]
   __fc_random_counter ∈ [--..--]
-  __fc_rand_max ∈ {32767}
+  __fc_rand_max ∈ {2147483647}
   __fc_random48_init ∈ {0}
   __fc_random48_counter[0..2] ∈ [--..--]
   __fc_p_random48_counter ∈ {{ &__fc_random48_counter[0] }}
@@ -647,7 +647,7 @@
   # cvalue:
   __fc_heap_status ∈ [--..--]
   __fc_random_counter ∈ [--..--]
-  __fc_rand_max ∈ {32767}
+  __fc_rand_max ∈ {2147483647}
   __fc_random48_init ∈ {0}
   __fc_random48_counter[0..2] ∈ [--..--]
   __fc_p_random48_counter ∈ {{ &__fc_random48_counter[0] }}
-- 
GitLab