Skip to content
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

Unix.utimes on a missing file results in EUKNOWNERR instead of ENOENT on Win32 #8857

Open
aantron opened this issue Aug 6, 2019 · 1 comment

Comments

@aantron
Copy link
Contributor

commented Aug 6, 2019

I believe this is caused by this code

hFile = CreateFile(wpath,
FILE_WRITE_ATTRIBUTES,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,
NULL);
caml_leave_blocking_section();
caml_stat_free(wpath);
if (hFile == INVALID_HANDLE_VALUE) {
win32_maperr(GetLastError());
uerror("utimes", path);
}

As you can see, caml_leave_blocking_section is called after CreateFile, but before GetLastError.

caml_leave_blocking_section preserves errno, but not the Win32 error code accessed by GetLastError/SetLastError:

ocaml/runtime/signals.c

Lines 177 to 182 in 301e1e6

CAMLexport void caml_leave_blocking_section(void)
{
int saved_errno;
/* Save the value of errno (PR#5982). */
saved_errno = errno;
caml_leave_blocking_section_hook ();

caml_leave_blocking_section_hook calls st_tls_get:

static void caml_thread_leave_blocking_section(void)
{
/* Wait until the runtime is free */
st_masterlock_acquire(&caml_master_lock);
/* Update curr_thread to point to the thread descriptor corresponding
to the thread currently executing */
curr_thread = st_tls_get(thread_descriptor_key);
/* Restore the runtime state from the curr_thread descriptor */
caml_thread_restore_runtime_state();
}

On Windows, this calls TlsGetValue:

static INLINE void * st_tls_get(st_tlskey k)
{
return TlsGetValue(k);
}

TlsGetValue clobbers the error code that would be returned by GetLastError.

cc @dra27

@dra27

This comment has been minimized.

Copy link
Contributor

commented Aug 6, 2019

Ref #8797 (which is stalled waiting for me to go through the review comments)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.