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

Re: [PATCH v1 3/5] tools/ocaml/libs/xc: add hvm_param_get binding


  • To: Christian Lindig <christian.lindig@xxxxxxxxxx>
  • From: Edwin Torok <edvin.torok@xxxxxxxxxx>
  • Date: Thu, 1 Dec 2022 15:07:50 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=tX0z6qO/z3rpnNvYja98p/YzDIk/d0OmtRvMbEJnwjU=; b=hT5zX/MrVpJucx0U4Uy4Je4XpsVP13aLJl8CCqhgYycbj+fxiNL+5mbCT7tMUp5/E9vwCQXZf0FQuY4L+9Zaa6VWYx3Nd0+zvyIYvpq69TUAxC0zxnAQydmPkLgjNGu08d2CzoQhdc5ak4Zy9jF9Vq3Vd5bqUmdBU+yBzRtJR9e5FOlYyECymPMRZcD1nFl3Pl41kjpsZjxl0odHrF7wA0BG4+PjNDzx52M+A9j5GLOjtK3PVjd4+dVPvktePhttsoDlUY/cheARIbXBByNq8eMt7z59B8kJnPaQ2YsrIWVyY20GMxpSh4VYwVn2pKMA6GmYnz3DJGeRXbV2CKtmcQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f/mS9Lfws4NvkVVoC5oBr1Ti7/mx+KLYXsBnIIAZ2jL+YgKQZERuo9e7E8s6ZNZVy/l0qvpccgf2VPsWWxCoGbI2KX1XyTpm7MdZIu6Id68E+1G13ucZ2EEPzIlPLQmnf1uSxt70BwW9T/Ns2sPqFtggA1bwtu+7QvmaX+yl9xQS/t5qG+h9D2rQjAhp9zm+YW3xSShaCdbU+bt2yIDYYdfItMLItsl6nUKW56l0AGum5pHRXWe+zRooTILvcCs9sOr0G2Q5PpIDqgp5NDEk/fDL3RqLeVu90zKBqArDbIHpOT2KeRUsHIUlPTf2q80EQdabODREwoCK/reZ6vP8vA==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Andrew Cooper <Andrew.Cooper3@xxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, David Scott <dave@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Anthony Perard <anthony.perard@xxxxxxxxxx>
  • Delivery-date: Thu, 01 Dec 2022 15:08:11 +0000
  • Ironport-data: A9a23:BpDJlKhur7Awmeh285PCs3ZwX161RxEKZh0ujC45NGQN5FlHY01je htvUTrTOaqNN2f1LdxzOt61/R4OvsDQx9M3Swo5/CE8RHsb9cadCdqndUqhZCn6wu8v7q5Ex 55HNoSfdpBcolv0/ErF3m3J9CEkvU2wbuOgTrWCYmUpH1QMpB4J0XpLg/Q+jpNjne+3CgaMv cKai8DEMRqu1iUc3lg8sspvkzsy+qWs0N8klgZmP6oS5geHzyN94K83fsldEVOpGuG4IcbiL wrz5OnR1n/U+R4rFuSknt7TGqHdauePVeQmoiM+t5mK2nCulARrukoIHKN0hXNsoyeIh7hMJ OBl7vRcf+uL0prkw4zxWzEAe8130DYvFLXveRBTuuTLp6HKnueFL1yDwyjaMKVBktubD12i+ tQWJj4AMw+6pdio7+LgSutCptp6fOrCadZ3VnFIlVk1DN4AaLWaGeDv2oUd2z09wMdTAfzZe swVLyJ1awjNaAFOPVFRD48imOCvhT/0dDgwRFC9/PJrpTSMilIvluS8WDbWUoXiqcF9k0qGp 2SA42PjBRIyP92D0zuVtHmrg4cjmAurBtpNTeXhr5aGhnWx3is2JSwWd2DhirqG1n+vSeh7A kMtr39GQa8asRbDosPGdw21pjuIswARX/JUEvYm80edx6zM+QGbC2MYCDlbZ7QOuMYoSBQw2 1SOntevAiZg2JWKTVqN+7HSqim9URX5NkcHbC4ACA4aud/qpdhpigqVFooyVqmoktfyBDf8h SiQqzQzjKkSishN0Lin+VfAgHSnoZ2hohMJ2zg7l1mNtmtRDLNJraTxtTA3Md4owF6lc2S8
  • Ironport-hdrordr: A9a23:j5CtuaF+IhmpK3hjpLqEPseALOsnbusQ8zAXPiFKOHhom6mj+q yTdZsguyMc5AxxZJhYo6HmBEDYewK7yXcX2/h1AV7BZmbbUQKTRekJ0WKF+V3d8kXFndK1vp 0QEZSWZueAbmSTWa7BkXGF+8lJ+qj4zEi47d2utkuEU2lRGtpdBg1Ce3mm+hAffng9OXIgfK Dsm/auvFKbCAgqUvg=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHZBOHXDfX2gYxBg0iCW8c7bxa9Ka5Y7MWAgAAhD4CAAAIsgIAABU4AgAABv4CAAAx+AA==
  • Thread-topic: [PATCH v1 3/5] tools/ocaml/libs/xc: add hvm_param_get binding


> On 1 Dec 2022, at 14:22, Christian Lindig <christian.lindig@xxxxxxxxxx> wrote:
> 
> 
> 
>> On 1 Dec 2022, at 14:16, Edwin Torok <edvin.torok@xxxxxxxxxx> wrote:
>> 
>> The disadvantage is that we can't pattern match on it anymore.
>> 
>> Although we could have some OCaml code that does the pattern matching on 
>> another type and maps it to these private integer types.
>> However at that point we've manually reinvented what ctypes would already 
>> do, and we have an additional mapping step (which may not matter from a 
>> performance point of view but would be nice if we could avoid it).
> 
> I agree that this is a severe disadvantage. My method is only useful if they 
> are mostly passed around but not when they have an algebra defined over them 
> where you want to combine and match them.


It might be possible to use your method to implement a pure-OCaml ABI checker 
though.

Consider:
```
external constant_A : unit -> int = "caml_constant_A"
external constant_B : unit -> int = "caml_constant_B"
external constant_C : unit -> int = "caml_constant_C"

let check_match = List.iter @@ fun (ocaml_variant, c_constant) ->
   let r = Obj.repr ocaml_variant in
   assert (Obj.is_int r);
   assert ((Obj.magic r : int) = c_constant ())

type t = A | B | C
let () =
   [A, constant_A
   ;B, constant_B
   ;C, constant_C]
   |> check_match
```

(although perhaps with the 2nd assertion replaced by something that includes 
the constant in the exception raised to aid debugging)

This'd only detect the ABI mismatch at runtime (although it would detect it 
right on startup), so it'd need to be accompanied by a small unit test
that would link just this module to make any mismatches a build time failure.

Then there would be no runtime overhead when using these variants in function 
calls, and we'd know they match 1:1.
Although there is still a possibility of mismatching on names (the bug I 
originally had in my patch, which although wouldn't cause any runtime issues,
would be good to catch at build time too).

I'll keep thinking about this to see whether there is another easy approach we 
can use that doesn't require using Cstubs and doesn't rely on manually keeping
code in different files in sync.

Best regards,
--Edwin




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.