-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Move dlopen and dlsym to PAL #25134
Move dlopen and dlsym to PAL #25134
Changes from 3 commits
3cbf2ff
434e354
06778ff
306441a
2aafcc4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
internal static partial class Interop | ||
{ | ||
internal static partial class Sys | ||
{ | ||
[Flags] | ||
internal enum DlOpenFlags : int | ||
{ | ||
RTLD_LAZY = 1, | ||
RTLD_NOW = 2 | ||
} | ||
|
||
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_DlOpen")] | ||
internal static extern IntPtr DlOpen(string fileName, DlOpenFlags flag); | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
#include <dlfcn.h> | ||
#include "pal_dl.h" | ||
|
||
// Validate that our definitions match those used by the OS. | ||
static_assert(PAL_RTLD_LAZY == RTLD_LAZY, ""); | ||
static_assert(PAL_RTLD_NOW == RTLD_NOW, ""); | ||
|
||
extern "C" void* SystemNative_DlOpen(const char *file, int mode) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Generally we try to avoid just assuming that these values are the same on all platforms, e.g. that RTLD_GLOBAL is 4 everywhere. Two options:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, I limited the values to |
||
{ | ||
return dlopen(file, mode); | ||
} | ||
|
||
extern "C" void* SystemNative_DlSym(void *handle, const char *name) | ||
{ | ||
return dlsym(handle, name); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
#pragma once | ||
|
||
// Values for the mode flag in dlopen | ||
enum | ||
{ | ||
PAL_RTLD_LAZY = 1, | ||
PAL_RTLD_NOW = 2 | ||
}; | ||
|
||
/** | ||
* Loads a dynamic library file. Implemented as shim to dlopen(3). | ||
* | ||
* An opaque handle for the dynamic library, or null on failure. | ||
*/ | ||
extern "C" void* SystemNative_DlOpen(const char *file, int mode); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: extra line and add comments like in: https://github.com/dotnet/corefx/blob/master/src/Native/Unix/System.Native/pal_io.h#L289-L294? |
||
|
||
/** | ||
* Gets, for a given dynamic library, the address of a symbol in that library. Implemented as shim to dlopen(3). | ||
* | ||
* The address of the symbol, or null on failure. | ||
*/ | ||
extern "C" void* SystemNative_DlSym(void *handle, const char *name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like dlopen is also being used in tests, e.g.
corefx/src/System.Drawing.Common/tests/Helpers.cs
Line 37 in 4bf9019
corefx/src/System.Data.Odbc/tests/Helpers.cs
Line 20 in 118c827
Do those need to be fixed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated both usages of
dlopen
. I couldn't find any other places that usedlopen
so I think we're good now.