[Xen-devel] [PATCH v2 10/22] golang/xenlight: define CpuidPolicyList builtin type

Nick Rosbrook posted 22 patches 6 years, 2 months ago
There is a newer version of this series
[Xen-devel] [PATCH v2 10/22] golang/xenlight: define CpuidPolicyList builtin type
Posted by Nick Rosbrook 6 years, 2 months ago
From: Nick Rosbrook <rosbrookn@ainfosec.com>

Define CpuidPolicyList as a string so that libxl_cpuid_parse_config can
be used in the toC function.

For now, fromC is a no-op since libxl does not support a way to read a
policy, modify it,and then give it back to libxl.

Signed-off-by: Nick Rosbrook <rosbrookn@ainfosec.com>
---
Changes in v2:
- Re-define CpuidPolicyList as string.
- Make fromC a no-op.
- Use libxl_cpuid_parse_config in toC function.

 tools/golang/xenlight/xenlight.go | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go
index d57f780116..6f0a9278ad 100644
--- a/tools/golang/xenlight/xenlight.go
+++ b/tools/golang/xenlight/xenlight.go
@@ -249,6 +249,31 @@ type EvLink struct{}
 func (el *EvLink) fromC(cel *C.libxl_ev_link) error      { return nil }
 func (el *EvLink) toC() (cel C.libxl_ev_link, err error) { return }
 
+// CpuidPolicyList represents a libxl_cpuid_policy_list.
+//
+// The value of CpuidPolicyList is honored when used as input to libxl. If
+// a struct contains a field of type CpuidPolicyList, that field will be left
+// empty when it is returned from libxl.
+type CpuidPolicyList string
+
+func (cpl CpuidPolicyList) fromC(ccpl *C.libxl_cpuid_policy_list) error { return nil }
+
+func (cpl CpuidPolicyList) toC() (C.libxl_cpuid_policy_list, error) {
+	var ccpl C.libxl_cpuid_policy_list
+
+	s := C.CString(string(cpl))
+	defer C.free(unsafe.Pointer(s))
+
+	ret := C.libxl_cpuid_parse_config(&ccpl, s)
+	if ret != 0 {
+		C.libxl_cpuid_dispose(&ccpl)
+
+		return ccpl, Error(-ret)
+	}
+
+	return ccpl, nil
+}
+
 type Context struct {
 	ctx    *C.libxl_ctx
 	logger *C.xentoollog_logger_stdiostream
-- 
2.19.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v2 10/22] golang/xenlight: define CpuidPolicyList builtin type
Posted by George Dunlap 6 years, 2 months ago
On 11/15/19 7:44 PM, Nick Rosbrook wrote:
> From: Nick Rosbrook <rosbrookn@ainfosec.com>
> 
> Define CpuidPolicyList as a string so that libxl_cpuid_parse_config can
> be used in the toC function.
> 
> For now, fromC is a no-op since libxl does not support a way to read a
> policy, modify it,and then give it back to libxl.
> 
> Signed-off-by: Nick Rosbrook <rosbrookn@ainfosec.com>

Reviewed-by: George Dunlap <george.dunlap@citrix.com>

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel