Skip to content

c_stubs: use 'new' acquire and release runtime functions #6341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions ocaml/auth/xa_auth_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <caml/custom.h>
#include <caml/fail.h>
#include <caml/callback.h>
#include <caml/signals.h>
#include <caml/threads.h>

#include "xa_auth.h"

Expand All @@ -39,11 +39,11 @@ CAMLprim value stub_XA_mh_authorize(value username, value password){
const char *error = NULL;
int rc;

caml_enter_blocking_section();
caml_release_runtime_system();
rc = XA_mh_authorize(c_username, c_password, &error);
free(c_username);
free(c_password);
caml_leave_blocking_section();
caml_acquire_runtime_system();

if (rc != XA_SUCCESS)
caml_failwith(error ? error : "Unknown error");
Expand All @@ -60,11 +60,11 @@ CAMLprim value stub_XA_mh_chpasswd(value username, value new_password){
const char *error = NULL;
int rc;

caml_enter_blocking_section();
caml_release_runtime_system();
rc = XA_mh_chpasswd (c_username, c_new_password, &error);
free(c_username);
free(c_new_password);
caml_leave_blocking_section();
caml_acquire_runtime_system();

if (rc != XA_SUCCESS)
caml_failwith(error ? error : "Unknown error");
Expand Down Expand Up @@ -102,10 +102,10 @@ CAMLprim value stub_XA_crypt_r(value key, value setting) {

struct crypt_data cd = {0};

caml_enter_blocking_section();
caml_release_runtime_system();
const char* const hashed =
crypt_r(String_val(key), String_val(setting), &cd);
Comment on lines 106 to 107
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not the fault of this (totally correct) commit, but these accesses to OCaml values should be brought out of this section.

caml_leave_blocking_section();
caml_acquire_runtime_system();

if (!hashed || *hashed == '*')
CAMLreturn(Val_none);
Expand Down
6 changes: 3 additions & 3 deletions ocaml/libs/log/syslog_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <caml/memory.h>
#include <caml/alloc.h>
#include <caml/custom.h>
#include <caml/signals.h>
#include <caml/threads.h>

static int syslog_level_table[] = {
LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR, LOG_WARNING,
Expand Down Expand Up @@ -57,10 +57,10 @@ value stub_syslog(value facility, value level, value msg)
int c_facility = syslog_facility_table[Int_val(facility)]
| syslog_level_table[Int_val(level)];

caml_enter_blocking_section();
caml_release_runtime_system();
syslog(c_facility, "%s", c_msg);
free(c_msg);
caml_leave_blocking_section();
caml_acquire_runtime_system();

CAMLreturn(Val_unit);
}
Expand Down
6 changes: 3 additions & 3 deletions ocaml/libs/vhd/vhd_format_lwt/blkgetsize64_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#include <caml/alloc.h>
#include <caml/memory.h>
#include <caml/signals.h>
#include <caml/threads.h>
#include <caml/fail.h>
#include <caml/callback.h>
#include <caml/bigarray.h>
Expand Down Expand Up @@ -54,7 +54,7 @@ CAMLprim value stub_blkgetsize64(value filename){
int rc = NOT_IMPLEMENTED;
const char *filename_c = strdup(String_val(filename));

caml_enter_blocking_section();
caml_release_runtime_system();
fd = open(filename_c, O_RDONLY, 0);
if (fd >= 0) {
#if defined(BLKGETSIZE64)
Expand All @@ -71,7 +71,7 @@ CAMLprim value stub_blkgetsize64(value filename){
close(fd);
} else
size_in_bytes = -1;
caml_leave_blocking_section();
caml_acquire_runtime_system();
free((void*)filename_c);

if (fd == -1) uerror("open", filename);
Expand Down
10 changes: 5 additions & 5 deletions ocaml/libs/vhd/vhd_format_lwt/lseek64_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#include <caml/alloc.h>
#include <caml/memory.h>
#include <caml/signals.h>
#include <caml/threads.h>
#include <caml/fail.h>
#include <caml/callback.h>
#include <caml/bigarray.h>
Expand All @@ -43,7 +43,7 @@ CAMLprim value stub_lseek64_data(value fd, value ofs) {
off_t c_ofs = Int64_val(ofs);
off_t c_ret;

caml_enter_blocking_section();
caml_release_runtime_system();
#if defined(SEEK_DATA)
c_ret = lseek(c_fd, c_ofs, SEEK_DATA);
/* retry, if SEEK_DATA not supported on this file system */
Expand All @@ -53,7 +53,7 @@ CAMLprim value stub_lseek64_data(value fd, value ofs) {
/* Set the file pointer to ofs; pretend there is data */
c_ret = lseek(c_fd, c_ofs, SEEK_SET);
#endif
caml_leave_blocking_section();
caml_acquire_runtime_system();
if (c_ret == -1) uerror("lseek", Nothing);

result = caml_copy_int64(c_ret);
Expand All @@ -67,7 +67,7 @@ CAMLprim value stub_lseek64_hole(value fd, value ofs) {
off_t c_ofs = Int64_val(ofs);
off_t c_ret;

caml_enter_blocking_section();
caml_release_runtime_system();
#if defined(SEEK_HOLE)
c_ret = lseek(c_fd, c_ofs, SEEK_HOLE);
/* retry, if SEEK_HOLE not supported on this file system */
Expand All @@ -78,7 +78,7 @@ CAMLprim value stub_lseek64_hole(value fd, value ofs) {
there is no hole */
c_ret = lseek(c_fd, 0, SEEK_END);
#endif
caml_leave_blocking_section();
caml_acquire_runtime_system();
if (c_ret == -1) uerror("lseek", Nothing);
result = caml_copy_int64(c_ret);
CAMLreturn(result);
Expand Down
6 changes: 3 additions & 3 deletions ocaml/libs/vhd/vhd_format_lwt/odirect_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#include <caml/alloc.h>
#include <caml/memory.h>
#include <caml/signals.h>
#include <caml/threads.h>
#include <caml/fail.h>
#include <caml/callback.h>
#include <caml/bigarray.h>
Expand All @@ -36,7 +36,7 @@ CAMLprim value stub_openfile_direct(value filename, value rw, value perm){

const char *filename_c = strdup(String_val(filename));

caml_enter_blocking_section();
caml_release_runtime_system();
int flags = 0;
#if defined(O_DIRECT)
flags |= O_DIRECT;
Expand All @@ -47,7 +47,7 @@ CAMLprim value stub_openfile_direct(value filename, value rw, value perm){
flags |= O_RDONLY;
}
fd = open(filename_c, flags, Int_val(perm));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and above with Bool_val too

caml_leave_blocking_section();
caml_acquire_runtime_system();

free((void*)filename_c);

Expand Down
6 changes: 3 additions & 3 deletions ocaml/vhd-tool/src/direct_copy_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

#include <caml/alloc.h>
#include <caml/memory.h>
#include <caml/signals.h>
#include <caml/threads.h>
#include <caml/fail.h>
#include <caml/callback.h>
#include <caml/bigarray.h>
Expand Down Expand Up @@ -134,7 +134,7 @@ CAMLprim value stub_direct_copy(value handle, value len){
* values may be accessed, until it is reacquired. Also this
* means other OCaml threads may do things while this is going
* on so the caller must be careful. */
caml_enter_blocking_section();
caml_release_runtime_system();

rc = TRIED_AND_FAILED;
bytes = 0;
Expand Down Expand Up @@ -195,7 +195,7 @@ CAMLprim value stub_direct_copy(value handle, value len){
rc = OK;
fail:

caml_leave_blocking_section();
caml_acquire_runtime_system();
/* Now that the OCaml runtime lock is reacquired, it is safe to
* raise OCaml exceptions */

Expand Down
30 changes: 15 additions & 15 deletions ocaml/xenopsd/c_stubs/xenctrlext_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <caml/alloc.h>
#include <caml/custom.h>
#include <caml/fail.h>
#include <caml/signals.h>
#include <caml/threads.h>
#include <caml/callback.h>
#include <caml/unixsupport.h>
#include <caml/bigarray.h>
Expand Down Expand Up @@ -95,9 +95,9 @@ CAMLprim value stub_xenctrlext_interface_open(value unused)
CAMLlocal1(result);
xc_interface *xch;

caml_enter_blocking_section();
caml_release_runtime_system();
xch = xc_interface_open(NULL, NULL, 0);
caml_leave_blocking_section();
caml_acquire_runtime_system();

if ( !xch )
failwith_xc(xch);
Expand Down Expand Up @@ -226,9 +226,9 @@ CAMLprim value stub_xenctrlext_get_max_nr_cpus(value xch_val)
xc_interface *xch = xch_of_val(xch_val);
int r;

caml_enter_blocking_section();
caml_release_runtime_system();
r = xc_physinfo(xch, &c_physinfo);
caml_leave_blocking_section();
caml_acquire_runtime_system();

if (r)
failwith_xc(xch);
Expand Down Expand Up @@ -256,9 +256,9 @@ CAMLprim value stub_xenctrlext_physdev_map_pirq(value xch_val,
CAMLparam3(xch_val, domid, irq);
xc_interface *xch = xch_of_val(xch_val);
int pirq = Int_val(irq);
caml_enter_blocking_section();
caml_release_runtime_system();
int retval = xc_physdev_map_pirq(xch, Int_val(domid), pirq, &pirq);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

caml_leave_blocking_section();
caml_acquire_runtime_system();
if (retval)
failwith_xc(xch);
CAMLreturn(Val_int(pirq));
Expand All @@ -269,9 +269,9 @@ CAMLprim value stub_xenctrlext_assign_device(value xch_val, value domid,
{
CAMLparam4(xch_val, domid, machine_sbdf, flag);
xc_interface *xch = xch_of_val(xch_val);
caml_enter_blocking_section();
caml_release_runtime_system();
int retval = xc_assign_device(xch, Int_val(domid), Int_val(machine_sbdf), Int_val(flag));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

caml_leave_blocking_section();
caml_acquire_runtime_system();
if (retval)
failwith_xc(xch);
CAMLreturn(Val_unit);
Expand All @@ -281,9 +281,9 @@ CAMLprim value stub_xenctrlext_deassign_device(value xch_val, value domid, value
{
CAMLparam3(xch_val, domid, machine_sbdf);
xc_interface *xc = xch_of_val(xch_val);
caml_enter_blocking_section();
caml_release_runtime_system();
int retval = xc_deassign_device(xc, Int_val(domid), Int_val(machine_sbdf));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

caml_leave_blocking_section();
caml_acquire_runtime_system();
if (retval)
failwith_xc(xc);
CAMLreturn(Val_unit);
Expand All @@ -299,9 +299,9 @@ CAMLprim value stub_xenctrlext_domain_soft_reset(value xch_val, value domid)
{
CAMLparam2(xch_val, domid);
xc_interface *xc = xch_of_val(xch_val);
caml_enter_blocking_section();
caml_release_runtime_system();
int retval = xc_domain_soft_reset(xc, Int_val(domid));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same and below

caml_leave_blocking_section();
caml_acquire_runtime_system();
if (retval)
failwith_xc(xc);
CAMLreturn(Val_unit);
Expand All @@ -312,11 +312,11 @@ CAMLprim value stub_xenctrlext_domain_update_channels(value xch_val, value domid
{
CAMLparam4(xch_val, domid, store_port, console_port);
xc_interface *xc = xch_of_val(xch_val);
caml_enter_blocking_section();
caml_release_runtime_system();
int retval = xc_set_hvm_param(xc, Int_val(domid), HVM_PARAM_STORE_EVTCHN, Int_val(store_port));
if (!retval)
retval = xc_set_hvm_param(xc, Int_val(domid), HVM_PARAM_CONSOLE_EVTCHN, Int_val(console_port));
caml_leave_blocking_section();
caml_acquire_runtime_system();
if (retval)
failwith_xc(xc);
CAMLreturn(Val_unit);
Expand Down
Loading