Skip to content

Commit d3e9d92

Browse files
Initial structure
1 parent f472716 commit d3e9d92

File tree

282 files changed

+83780
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

282 files changed

+83780
-1
lines changed

.github/CONTRIBUTING.md

Lines changed: 339 additions & 0 deletions
Large diffs are not rendered by default.

CODE_OF_CONDUCT.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Code of Conduct
2+
3+
This project has adopted the [Microsoft Open Source Code of Conduct][conduct-code].
4+
For more information see the [Code of Conduct FAQ][conduct-FAQ] or contact [opencode@microsoft.com][conduct-email] with any additional questions or comments.
5+
6+
[conduct-code]: http://opensource.microsoft.com/codeofconduct/
7+
[conduct-FAQ]: http://opensource.microsoft.com/codeofconduct/faq/
8+
[conduct-email]: mailto:opencode@microsoft.com

README.md

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,56 @@
1-
# LibPSL-Native
1+
# libpsl-native
2+
3+
This library provides functionality missing from .NET Core via system calls,
4+
that are called from from the `CorePsPlatform.cs` file of PowerShell. The
5+
method to do this is a Platform Invoke, which is C#'s Foreign Function
6+
Interface to C code (and C++ by way of `extern C`).
7+
8+
## Build
9+
10+
[CMake][] is used to build the project, which results in a `libpsl-native.so`
11+
library on Linux, and `libpsl-native.dylib` on OS X.
12+
13+
```sh
14+
cmake -DCMAKE_BUILD_TYPE=Debug .
15+
make -j
16+
```
17+
18+
[CMake]: https://cmake.org/cmake/help/v2.8.12/cmake.html
19+
20+
## Test
21+
22+
The [Google Test][] framework is used for unit tests.
23+
24+
Use either `make test` or `ctest --verbose` for more output.
25+
26+
[Google Test]: https://github.com/google/googletest/tree/release-1.7.0
27+
28+
## Notes
29+
30+
Marshalling data from native to managed code is much easier on Linux than it is
31+
on Windows. For instance, to return a string, you simply return a copy of it on
32+
the heap. Since only one memory allocator is used on Linux, the .NET runtime
33+
has no problem later freeing the buffer. Additionally, .NET presumes that the
34+
codepage "Ansi" on Linux is always UTF-8. So just marshal the string as
35+
`UnmanagedType.LPStr`.
36+
37+
### C# (Managed)
38+
39+
```c#
40+
[DllImport("libpsl-native", CharSet = CharSet.Ansi)]
41+
[return: MarshalAs(UnmanagedType.LPStr)]
42+
internal static extern string GetSomeString();
43+
```
44+
45+
### C (Native)
46+
47+
```c
48+
char *GetSomeString()
49+
{
50+
return strdup("some string");
51+
}
52+
```
53+
54+
The CoreFX team has an excellent guide for [UNIX Interop][].
55+
56+
[UNIX Interop]: https://github.com/dotnet/corefx/blob/master/Documentation/coding-guidelines/interop-guidelines.md#unix-shims

0 commit comments

Comments
 (0)