Skip to content
Merged
Changes from 1 commit
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
25 changes: 13 additions & 12 deletions src/core/IronPython.Modules/fcntl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#nullable enable

using System;
using System.Buffers;
using System.Diagnostics;
using System.Numerics;
using System.Reflection;
Expand Down Expand Up @@ -173,9 +172,6 @@ public static object ioctl(int fd, long request, [NotNone] IBufferProtocol arg,
}
bool in_place = bufSize > defaultBufSize; // only large buffers are mutated in place

#if !NETCOREAPP
throw new PlatformNotSupportedException("ioctl is not supported on Mono");
#else
try {
Debug.Assert(!in_place || mutate_flag); // in_place implies mutate_flag

Expand All @@ -192,7 +188,7 @@ public static object ioctl(int fd, long request, [NotNone] IBufferProtocol arg,
unsafe {
fixed (byte* ptr = workSpan) {
do {
if (RuntimeInformation.ProcessArchitecture == Architecture.Arm64) {
if (IsArchitecutreArm64()) {
// workaround for Arm64 vararg calling convention (but not for ARM64EC on Windows)
result = _ioctl_arm64(fd, cmd, 0, 0, 0, 0, 0, 0, ptr);
} else {
Expand All @@ -219,7 +215,6 @@ public static object ioctl(int fd, long request, [NotNone] IBufferProtocol arg,
} finally {
buf.Dispose();
}
#endif
}


Expand All @@ -238,13 +233,10 @@ public static object ioctl(int fd, long request, [Optional] object? arg, bool mu

ulong cmd = unchecked((ulong)request);

#if !NETCOREAPP
throw new PlatformNotSupportedException("ioctl is not supported on Mono");
#else
int result;
Errno errno;
do {
if (RuntimeInformation.ProcessArchitecture == Architecture.Arm64) {
if (IsArchitecutreArm64()) {
// workaround for Arm64 vararg calling convention (but not for ARM64EC on Windows)
result = _ioctl_arm64(fd, cmd, 0, 0, 0, 0, 0, 0, data);
} else {
Expand All @@ -256,7 +248,6 @@ public static object ioctl(int fd, long request, [Optional] object? arg, bool mu
return LightExceptions.Throw(PythonNT.GetOsError(NativeConvert.FromErrno(errno)));
}
return ScriptingRuntimeHelpers.Int32ToObject(result);
#endif
}


Expand Down Expand Up @@ -359,11 +350,21 @@ private static void CheckFileDescriptor(int fd) {
}
}

private static bool IsArchitecutreArm64() {
#if NETCOREAPP
return RuntimeInformation.ProcessArchitecture == Architecture.Arm64;
#else
if (Syscall.uname(out Utsname info) == 0) {
return info.machine is "arm64" or "aarch64";
}
return false;
#endif
}

private static bool TryGetInt64(object? obj, out long value) {
int success = 1;
value = obj switch {
Missing => 0,
Missing => default,
int i => i,
uint ui => ui,
long l => l,
Expand Down