Marvin, thanks.
What i'm doing is similar to your guessing.
I use syscall.Syscall to call win32 api, and encounter some padding issues.
I have resolve my problems by mannual padding days ago, but I want to know
if there is a more graceful way to finish that.
One of the Apis is:
DWORD WINAPI FwpmFilterAdd0(
_In_ HANDLE engineHandle,
_In_ const FWPM_FILTER0 *filter,
_In_opt_ SECURITY_DESCRIPTOR sd,
_Out_opt_ UINT64 *id
);
I have call with a FWPM_FILTER0 struct as below:
typedef struct FWPM_FILTER0_ {
GUID filterKey;
FWPM_DISPLAY_DATA0 displayData;
UINT32 flags;
GUID *providerKey;
FWP_BYTE_BLOB providerData;
GUID layerKey;
GUID subLayerKey;
FWP_VALUE0 weight;
UINT32 numFilterConditions;
FWPM_FILTER_CONDITION0 *filterCondition;
FWPM_ACTION0 action;
union { UINT64 rawContext; // makes this union aligns to 8
bytes
GUID providerContextKey;
};
GUID *reserved;
UINT64 filterId; // filterId aligns to 8 bytes
FWP_VALUE0 effectiveWeight;
} FWPM_FILTER0;
In win32, I have to define the sturct as below:
type FWPM_FILTER0 struct {
FilterKey GUID
DisplayData FWPM_DISPLAY_DATA0
Flags uint32
ProviderKey *GUID
ProviderData FWP_BYTE_BLOB
LayerKey GUID
SubLayerKey GUID
Weight FWP_VALUE0
NumFilterConditions uint32
FilterCondition *FWPM_FILTER_CONDITION0
Action FWPM_ACTION0
/*
union {
UINT64 rawContext;
GUID providerContextKey;
};
*/
reserved1 uint32 // mannul padding
ProviderContextKey GUID // the max size field of that anonymous union
Reserved *GUID
reserved2 uint32 // mannul padding
FilterId uint64
EffectiveWeight FWP_VALUE0
}
Now I can run my code in 32bit go. But I hope my code can run 64bit go
without any conditional compile.
best regards,
xjdrew
On Monday, May 22, 2017 at 8:57:28 PM UTC+8, Marvin Renich wrote:
>
> * xjdrew <[email protected] <javascript:>> [170522 02:06]:
> > How can i use this kind of Go in windows? my machine is 64bit also. If I
> > download the amd64 Go, the pointer size will be 8 bytes.
> >
> > My real issue is , when I call win32 api, uint64 type in the struct of
> > win32 is aligned to 8 bytes.
> > I have to pad the go struct by manual to make it work with win32 api.
> >
> > > On Friday, May 19, 2017 at 7:28:54 AM UTC-4, xjdrew wrote:
> > >> Code as below, playground url(https://play.golang.org/p/XSx--6uF0E):
> > >>
> > >> package main
> > >>
> > >> import "fmt"
> > >> import "unsafe"
> > >>
> > >> type A struct {
> > >> a uint8
> > >> b uint64
> > >> }
> > >> func main() {
> > >> a := &A{}
> > >> fmt.Println(unsafe.Sizeof(a))
> > >> fmt.Println(unsafe.Sizeof(*a))
> > >> }
>
> As Dan said, you have not given us enough information to provide you
> with useful help (at least not without a lot of good guessing on our
> part as to what you are really trying to do). I am guessing that you
> are importing "golang.org/x/sys/windows" and using syscall to call
> functions in DLLs. If so, what DLL and what entry? What is the C
> structure you are trying to pass to that entry? Must it work in both
> win32 and win64?
>
> When you are mixing Go and C ABIs, there is likely to be some manual
> alignment, especially if you are trying to do this on multiple
> OS/architecture combinations (e.g. win32 and win64).
>
> I believe (but am not 100% positive) that on all platforms supported by
> Go, the following will produce the same alignment:
>
> type A struct {
> a uint8
> _ uint32
> b uint64
> }
>
> ...Marvin
>
>
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.