Giter Club home page Giter Club logo

Comments (7)

kennykerr avatar kennykerr commented on August 18, 2024 1

FILETIME and ULARGE_INTEGER are not interchangeable because they have different alignment. FILETIME consists of two 32-bit fields whereas ULARGE_INTEGER consists of a union, one of whose fields is a single 64-bit value. Hence the alignment of ULARGE_INTEGER will be 8 bytes and the alignment of FILETIME will be 4 bytes.

So it is indeed safe to replace ULARGE_INTEGER and LARGE_INTEGER with uint64 and int64 but it is not safe to do so for FILETIME.

from cswin32.

kennykerr avatar kennykerr commented on August 18, 2024 1

Yes, for C# it would be the CsWin32 repo.

from cswin32.

kennykerr avatar kennykerr commented on August 18, 2024 1

@saul - I've just transferred it here for you.

from cswin32.

MauriceKayser avatar MauriceKayser commented on August 18, 2024

There are other types like FILETIME with the same layout as ULARGE_INTEGER, where Microsoft recommends not to replace the structure with a 64 bit integer because of alignment issues. I neither am sure if this also applies for LARGE_INTEGER and ULARGE_INTEGER, nor if this even affects modern CPUs that Windows runs on.

from cswin32.

DefaultRyan avatar DefaultRyan commented on August 18, 2024

I believe that doing this would break ABI, based on my experiences with microsoft/cppwin32#3.

The gist of what I found in that defect is that this:

int64 f1();

and this:

struct S
{
  int 64 value;
}
S f2();

are going to push different amounts of stuff onto the stack, causing memory corruption and crashes if we try to pretend one of them is the other.

We need to keep these structs as-is in the metadata. Projections are free to simplify them and project them idiomatically, but the structs need to exist in metadata so that we preserve ABI compatibility.

from cswin32.

kennykerr avatar kennykerr commented on August 18, 2024

Right, there is a peculiarity in the C++ ABI for the Visual C++ compiler that results in these being different when stdcall is involved. Rust for Windows already maps these to i64 and u64 because it doesn't suffer from this weirdness, but Visual C++ may not be able to handle that reliably.

If your language doesn't yet map this in a natural way, I suggest you open an issue with the language team.

from cswin32.

saul avatar saul commented on August 18, 2024

Okay just so we're on the same page - should I open an issue on CsWin32 to have the struct projected to int64/uint64?

from cswin32.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.