Skip to content

x/sys/windows: wrong Sizeof result on struct windows.JOBOBJECT_EXTENDED_LIMIT_INFORMATION on ARCH 386 #41001

@dbellavista

Description

@dbellavista

Hi! I'm trying to call the windows.SetInformationJobObject function which requires the size of the input structure of type windows.JOBOBJECT_EXTENDED_LIMIT_INFORMATION. To my understanding I can use unsafe.Sizeof to achieve the same result of the C sizeof operator.

When compiling on amd64 arch, the sizeof is correct, but on 386 there is a 4 bytes difference.

What version of Go are you using (go version)?

$ go version
go version go1.14.6 windows/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\danie\AppData\Local\go-build
set GOENV=C:\Users\danie\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\danie\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=c:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=Y:\Agent\windows-service-wrapper\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\danie\AppData\Local\Temp\go-build389674314=/tmp/go-build -gno-record-gcc-switches

What did you do?

package main

// #include <windows.h>
//
// int SizeOfJob() {
//     JOBOBJECT_EXTENDED_LIMIT_INFORMATION test;
//     test.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
//     return sizeof(test);
// }
import "C"

import (
	"fmt"
	"unsafe"

	"golang.org/x/sys/windows"
)

func main() {
	info := windows.JOBOBJECT_EXTENDED_LIMIT_INFORMATION{
		BasicLimitInformation: windows.JOBOBJECT_BASIC_LIMIT_INFORMATION{
			LimitFlags: windows.JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE,
		},
	}

	fmt.Printf("Go Size %d\nC Size %d", unsafe.Sizeof(info), C.SizeOfJob())
}

What did you expect to see?

Compiled on windows with environment GOARCH=386

Go Size 112
C Size 112

Compiled on windows with environment GOARCH="amd64"

Go Size 144
C Size 144

What did you see instead?

Compiled on windows with environment GOARCH=386

Go Size 108
C Size 112

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.OS-Windows

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions