Skip to content

std::dynamic_lib: Fix Windows error handling #20874

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
Jan 19, 2015

Conversation

klutzy
Copy link
Contributor

@klutzy klutzy commented Jan 10, 2015

This is a [breaking-change] since std::dynamic_lib::dl is now
private.

When LoadLibraryW() fails, original code called errno() to get error
code. However, there was local allocation of Vec before
LoadLibraryW(), and it drops before errno(), and the drop
(deallocation) changed errno! Therefore dynamic_lib::open() thought
it always succeeded.
This commit fixes the issue.

This commit also sets Windows error mode during LoadLibrary() to
prevent "dll load failed" dialog.

@rust-highfive
Copy link
Contributor

r? @huonw

(rust_highfive has picked a reviewer for you, use r? to override)

@klutzy klutzy force-pushed the windows-dynamic-lib branch 2 times, most recently from e2ec01b to 4fc7861 Compare January 10, 2015 14:35
// beware: Vec/String may change errno during drop!
// so we get error here.
if result == ptr::null_mut() {
Err(format!("Error code {}", os::errno()))
Copy link
Member

Choose a reason for hiding this comment

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

While you're at it, could this get a beefed up error message with the error description as well as the error code?

@alexcrichton alexcrichton assigned alexcrichton and unassigned huonw Jan 11, 2015
@klutzy klutzy force-pushed the windows-dynamic-lib branch from 4fc7861 to 4f5770e Compare January 17, 2015 04:37
@klutzy
Copy link
Contributor Author

klutzy commented Jan 17, 2015

Now it uses SetThreadErrorMode if available.

@klutzy klutzy force-pushed the windows-dynamic-lib branch from 216b3eb to 65d06c4 Compare January 18, 2015 15:08
This is a [breaking-change] since `std::dynamic_lib::dl` is now
private.

When `LoadLibraryW()` fails, original code called `errno()` to get error
code.  However, there was local allocation of `Vec` before
`LoadLibraryW()`, and it drops before `errno()`, and the drop
(deallocation) changed `errno`! Therefore `dynamic_lib::open()` thought
it always succeeded.
This commit fixes the issue.

This commit also sets Windows error mode during `LoadLibrary()` to
prevent "dll load failed" dialog.
@klutzy klutzy force-pushed the windows-dynamic-lib branch from 65d06c4 to d053ccb Compare January 18, 2015 15:13
@klutzy
Copy link
Contributor Author

klutzy commented Jan 18, 2015

Fixed Rtld dead code issue on unix, and improved error description using os::error_string().

@alexcrichton
Copy link
Member

@bors: r+ d053ccb

@bors
Copy link
Collaborator

bors commented Jan 19, 2015

⌛ Testing commit d053ccb with merge 658e0bd...

@alexcrichton
Copy link
Member

@bors: retry

@bors
Copy link
Collaborator

bors commented Jan 19, 2015

⌛ Testing commit d053ccb with merge 6f161d7...

@bors
Copy link
Collaborator

bors commented Jan 19, 2015

💔 Test failed - auto-bsd-64-opt

@alexcrichton
Copy link
Member

@bors: retry

@bors
Copy link
Collaborator

bors commented Jan 19, 2015

⌛ Testing commit d053ccb with merge bf9b2c3...

bors added a commit that referenced this pull request Jan 19, 2015
This is a [breaking-change] since `std::dynamic_lib::dl` is now
private.

When `LoadLibraryW()` fails, original code called `errno()` to get error
code.  However, there was local allocation of `Vec` before
`LoadLibraryW()`, and it drops before `errno()`, and the drop
(deallocation) changed `errno`! Therefore `dynamic_lib::open()` thought
it always succeeded.
This commit fixes the issue.

This commit also sets Windows error mode during `LoadLibrary()` to
prevent "dll load failed" dialog.
@bors
Copy link
Collaborator

bors commented Jan 19, 2015

💔 Test failed - auto-mac-64-nopt-t

@alexcrichton
Copy link
Member

@bors: retry

cc @sfackler, you may be interested in that failure

@bors
Copy link
Collaborator

bors commented Jan 19, 2015

⌛ Testing commit d053ccb with merge 7b87900...

bors added a commit that referenced this pull request Jan 19, 2015
This is a [breaking-change] since `std::dynamic_lib::dl` is now
private.

When `LoadLibraryW()` fails, original code called `errno()` to get error
code.  However, there was local allocation of `Vec` before
`LoadLibraryW()`, and it drops before `errno()`, and the drop
(deallocation) changed `errno`! Therefore `dynamic_lib::open()` thought
it always succeeded.
This commit fixes the issue.

This commit also sets Windows error mode during `LoadLibrary()` to
prevent "dll load failed" dialog.
@bors
Copy link
Collaborator

bors commented Jan 19, 2015

@bors bors merged commit d053ccb into rust-lang:master Jan 19, 2015
@klutzy klutzy deleted the windows-dynamic-lib branch January 19, 2015 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants