Displaying 20 results from an estimated 64 matches for "caml_enter_blocking_section".
2023 Jun 27
1
[PATCH libguestfs 1/4] ocaml: Replace old enter/leave_blocking_section calls
Since OCaml 4 the old and confusing caml_enter_blocking_section and
caml_leave_blocking_section calls have been replaced with
caml_release_runtime_system and caml_acquire_runtime_system (in that
order). Use the new names.
---
generator/OCaml.ml | 5 +++--
ocaml/guestfs-c.c | 5 +++--
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/generator/OC...
2020 Sep 01
0
[nbdkit PATCH 2/2] ocaml: Implement .list_exports and friends
...+ CAMLlocal2 (rv, v);
+
+ caml_leave_blocking_section ();
+
+ rv = caml_callback2_exn (list_exports_fn, Val_bool (readonly),
+ Val_bool (is_tls));
+ if (Is_exception_result (rv)) {
+ nbdkit_error ("%s", caml_format_exception (Extract_exception (rv)));
+ caml_enter_blocking_section ();
+ CAMLreturnT (int, -1);
+ }
+
+ /* Convert exports list into calls to nbdkit_add_export. */
+ while (rv != Val_int (0)) {
+ const char *name, *desc;
+
+ v = Field (rv, 0); /* export struct */
+ name = String_val (Field (v, 0));
+ desc = String_val (Field (v, 1));
+...
2020 Sep 21
0
[nbdkit PATCH v3 14/14] ocaml: Implement .list_exports and friends
...+ CAMLlocal2 (rv, v);
+
+ caml_leave_blocking_section ();
+
+ rv = caml_callback2_exn (list_exports_fn, Val_bool (readonly),
+ Val_bool (is_tls));
+ if (Is_exception_result (rv)) {
+ nbdkit_error ("%s", caml_format_exception (Extract_exception (rv)));
+ caml_enter_blocking_section ();
+ CAMLreturnT (int, -1);
+ }
+
+ /* Convert exports list into calls to nbdkit_add_export. */
+ while (rv != Val_emptylist) {
+ const char *name, *desc = NULL;
+
+ v = Field (rv, 0); /* export struct */
+ name = String_val (Field (v, 0));
+ if (Is_block (Field (v, 1)))...
2019 May 17
1
Re: [nbdkit PATCH v2 08/24] ocaml: Implement .cache script callback
...t; + CAMLparam0 ();
> + CAMLlocal1 (rv);
> +
> + caml_leave_blocking_section ();
> +
> + rv = caml_callback_exn (can_cache_fn, *(value *) h);
> + if (Is_exception_result (rv)) {
> + nbdkit_error ("%s", caml_format_exception (Extract_exception (rv)));
> + caml_enter_blocking_section ();
> + CAMLreturnT (int, -1);
> + }
> +
> + caml_enter_blocking_section ();
> + CAMLreturnT (int, Int_val (rv));
The not very obvious implicit assumption here is that the order of the
Cache* flags in the OCaml code is the same as the numbering of the
NBDKIT_CACHE_* flags in t...
2017 Jan 27
2
Re: [nbdkit PATCH v3 1/4] plugins: Don't use bogus errno from non-C plugins
...> +static int
> +plugin_ocaml_errno_is_reliable (void *handle)
> +{
> + return 0;
> +}
Actually OCaml is a real compiled language, and the call from C to
OCaml code (via caml_callback_exn) is a short piece of asm which
preserves errno.
However you'll need to save errno around caml_enter_blocking_section
since that unblocks and processes signals.
IOW:
static int
pread_wrapper (void *h, void *buf, uint32_t count, uint64_t offset)
{
CAMLparam0 ();
CAMLlocal3 (rv, strv, offsetv);
+ int saved_errno;
...
rv = caml_callback3_exn (pread_fn, *(value *) h, strv, offsetv);
+ saved_err...
2019 May 16
0
[nbdkit PATCH v2 08/24] ocaml: Implement .cache script callback
...static int
+can_cache_wrapper (void *h)
+{
+ CAMLparam0 ();
+ CAMLlocal1 (rv);
+
+ caml_leave_blocking_section ();
+
+ rv = caml_callback_exn (can_cache_fn, *(value *) h);
+ if (Is_exception_result (rv)) {
+ nbdkit_error ("%s", caml_format_exception (Extract_exception (rv)));
+ caml_enter_blocking_section ();
+ CAMLreturnT (int, -1);
+ }
+
+ caml_enter_blocking_section ();
+ CAMLreturnT (int, Int_val (rv));
+}
+
+static int
+cache_wrapper (void *h, uint32_t count, uint64_t offset, uint32_t flags)
+{
+ CAMLparam0 ();
+ CAMLlocal4 (rv, countv, offsetv, flagsv);
+
+ caml_leave_blocking_section...
2020 Feb 10
1
[nbdkit PATCH] ocaml: Support .preconnect callback
...econnect_wrapper (int readonly)
+{
+ CAMLparam0 ();
+ CAMLlocal1 (rv);
+
+ caml_leave_blocking_section ();
+
+ rv = caml_callback_exn (preconnect_fn, Val_bool (readonly));
+ if (Is_exception_result (rv)) {
+ nbdkit_error ("%s", caml_format_exception (Extract_exception (rv)));
+ caml_enter_blocking_section ();
+ CAMLreturnT (int, -1);
+ }
+
+ caml_enter_blocking_section ();
+ CAMLreturnT (int, 1);
+}
+
/*----------------------------------------------------------------------*/
/* set_* functions called from OCaml code at load time to initialize
* fields in the plugin struct.
@@ -815,6 +836,8...
2020 Sep 01
4
[nbdkit PATCH 0/2] More language bindings for .list_exports
This picks up python and ocaml. Some of our languages are lacking a
number of bindings (for example, lua and perl lack .extents, so I
didn't have anything to copy from), and I felt less comfortable with
golang and rust. But for python and ocaml, I was able to test a
working implementation.
Eric Blake (2):
python: Implement .list_exports and friends
ocaml: Implement .list_exports and
2023 Jun 27
4
[PATCH libguestfs 0/4] Fix ups for OCaml 5
No action required here as I have pushed this already, this is
just for your information.
Rich.
2017 Jan 27
0
Re: [nbdkit PATCH v3 1/4] plugins: Don't use bogus errno from non-C plugins
...ml_callback_exn) is a short piece of asm which
> preserves errno.
Which shows my lack of familiarity with OCaml; but I'm guessing that
also means that OCaml comes with easy ways to directly set errno so that
it will be visible from C.
>
> However you'll need to save errno around caml_enter_blocking_section
> since that unblocks and processes signals.
>
> IOW:
>
> static int
> pread_wrapper (void *h, void *buf, uint32_t count, uint64_t offset)
> {
> CAMLparam0 ();
> CAMLlocal3 (rv, strv, offsetv);
> + int saved_errno;
> ...
> rv = caml_callback...
2023 May 27
2
[PATCH libguestfs 2/2] Only leave/enter blocking_section when OCaml lock is not held
...- caml_leave_blocking_section ();
+ bool in_blocking_section = (caml_state == NULL);
+
+ if (in_blocking_section)
+ caml_leave_blocking_section ();
event_callback_wrapper_locked (g, data, event, event_handle, flags,
buf, buf_len, array, array_len);
- caml_enter_blocking_section ();
+ if (in_blocking_section)
+ caml_enter_blocking_section ();
}
value
--
2.40.1
2019 Apr 23
0
[PATCH nbdkit v2 1/2] ocaml: Change pread method to avoid leaking heap memory.
...455,7 +456,14 @@ pread_wrapper (void *h, void *buf, uint32_t count, uint64_t offset,
CAMLreturnT (int, -1);
}
- memcpy (buf, String_val (strv), count);
+ len = caml_string_length (rv);
+ if (len < count) {
+ nbdkit_error ("buffer returned from pread is too small");
+ caml_enter_blocking_section ();
+ CAMLreturnT (int, -1);
+ }
+
+ memcpy (buf, String_val (rv), count);
caml_enter_blocking_section ();
CAMLreturnT (int, 0);
diff --git a/plugins/ocaml/NBDKit.ml b/plugins/ocaml/NBDKit.ml
index b03ff5a..14b9803 100644
--- a/plugins/ocaml/NBDKit.ml
+++ b/plugins/ocaml/NBDKit.ml
@@ -...
2020 Sep 01
3
Re: [nbdkit PATCH 2/2] ocaml: Implement .list_exports and friends
...desc = NULL;
v = Field (rv, 0); /* export struct */
name = String_val (Field (v, 0));
- desc = String_val (Field (v, 1));
+ if (Is_block (Field (v, 1)))
+ desc = String_val (Field (Field (v, 1), 0));
if (nbdkit_add_export (exports, name, desc) == -1) {
caml_enter_blocking_section ();
CAMLreturnT (int, -1);
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
2019 Aug 15
2
[nbdkit PATCH] ocaml: Add support for dynamic .thread_model
...atic int
+thread_model_wrapper (void)
+{
+ CAMLparam0 ();
+ CAMLlocal1 (rv);
+
+ caml_leave_blocking_section ();
+
+ rv = caml_callback_exn (config_complete_fn, Val_unit);
+ if (Is_exception_result (rv)) {
+ nbdkit_error ("%s", caml_format_exception (Extract_exception (rv)));
+ caml_enter_blocking_section ();
+ CAMLreturnT (int, -1);
+ }
+
+ caml_enter_blocking_section ();
+ CAMLreturnT (int, Int_val (rv));
+}
+
/*----------------------------------------------------------------------*/
/* set_* functions called from OCaml code at load time to initialize
* fields in the plugin struct.
*/...
2019 Aug 12
0
[PATCH libnbd 5/7] ocaml: Use free callback to free closure root, instead of valid_flag == FREE.
...| 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/generator/generator b/generator/generator
index 92ce170..109fad6 100755
--- a/generator/generator
+++ b/generator/generator
@@ -5239,9 +5239,6 @@ let print_ocaml_binding (name, { args; optargs; ret }) =
pr " caml_enter_blocking_section ();\n";
pr " }\n";
pr "\n";
- pr " if (valid_flag & LIBNBD_CALLBACK_FREE)\n";
- pr " free_root (NULL, user_data);\n";
- pr "\n";
pr " return ret;\n";
pr "}\n";...
2020 Sep 01
0
Re: [nbdkit PATCH 2/2] ocaml: Implement .list_exports and friends
...ld (rv, 0); /* export struct */
> name = String_val (Field (v, 0));
> - desc = String_val (Field (v, 1));
> + if (Is_block (Field (v, 1)))
> + desc = String_val (Field (Field (v, 1), 0));
> if (nbdkit_add_export (exports, name, desc) == -1) {
> caml_enter_blocking_section ();
> CAMLreturnT (int, -1);
Seems OK. I'm guessing this crashes?
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-builder quickly builds VMs from scratch
http://libg...
2019 Apr 23
4
[PATCH nbdkit v2 0/2] Be careful not to leak server heap memory to the client.
Version 1 was here:
https://www.redhat.com/archives/libguestfs/2019-April/msg00144.html
Version 2 makes a couple of much larger changes:
The OCaml patch changes the API of the pread method so it matches what
other language bindings are already doing, ie. get the language plugin
to return a newly allocated buffer, check it is long enough, copy out
the data.
The server patch implements a
2020 Sep 01
1
Re: [nbdkit PATCH 2/2] ocaml: Implement .list_exports and friends
...ort struct */
>> name = String_val (Field (v, 0));
>> - desc = String_val (Field (v, 1));
>> + if (Is_block (Field (v, 1)))
>> + desc = String_val (Field (Field (v, 1), 0));
>> if (nbdkit_add_export (exports, name, desc) == -1) {
>> caml_enter_blocking_section ();
>> CAMLreturnT (int, -1);
>
> Seems OK. I'm guessing this crashes?
Nope, it worked. So compared to your explanation above, my test for
Some was Is_block, rather than Int_val(0). And I repeated Field(v,1)
for getting to the 'Some "string"' rather...
2019 Aug 12
0
[PATCH libnbd 3/7] ocaml: Remove NBD.Buffer.free function, use a free callback instead.
...ernal_ocaml_buffer_to_bytes\"
external of_bytes : bytes -> t = \"nbd_internal_ocaml_buffer_of_bytes\"
external size : t -> int = \"nbd_internal_ocaml_buffer_size\"
@@ -5244,10 +5239,8 @@ let print_ocaml_binding (name, { args; optargs; ret }) =
pr " caml_enter_blocking_section ();\n";
pr " }\n";
pr "\n";
- pr " if (valid_flag & LIBNBD_CALLBACK_FREE) {\n";
- pr " caml_remove_generational_global_root ((value *)user_data);\n";
- pr " free (user_data);\n";
- pr "...
2019 Jun 04
0
[PATCH libnbd v2 2/4] generator: Callback returns int instead of void.
...tion ();\n";
let c_argnames = List.flatten (List.map name_of_arg args) in
- pr " %s_%s_wrapper_locked (%s);\n" name cb_name
+ pr " ret = %s_%s_wrapper_locked (%s);\n" name cb_name
(String.concat ", " c_argnames);
pr " caml_enter_blocking_section ();\n";
+ pr " return ret;\n";
pr "}\n"
| _ -> ()
) args;
diff --git a/generator/states-reply-structured.c b/generator/states-reply-structured.c
index e6c1a8a..c835713 100644
--- a/generator/states-reply-structured.c
+++ b/generator/states-reply-st...