gpu: add device id label (#2186)

This commit is contained in:
Jan-Otto Kröpke
2025-08-28 06:36:10 +02:00
committed by GitHub
parent 71cedbc4d0
commit 0b8a257b31
11 changed files with 490 additions and 193 deletions

View File

@@ -18,6 +18,7 @@
package win32
import (
"strconv"
"unsafe"
"golang.org/x/sys/windows"
@@ -32,8 +33,8 @@ type (
LPWSTR struct {
*uint16
}
ULONG = uint32 // ULONG is a 32-bit unsigned int in Win32
UINT = uint32 // UINT is a 32-bit unsigned int in Win32
ULONG uint32 // ULONG is a 32-bit unsigned int in Win32
UINT uint32 // UINT is a 32-bit unsigned int in Win32
)
// NewLPWSTR creates a new LPWSTR from a string.
@@ -60,3 +61,7 @@ func (s *LPWSTR) Pointer() uintptr {
func (s *LPWSTR) String() string {
return windows.UTF16PtrToString(s.uint16)
}
func (u *UINT) String() string {
return strconv.FormatUint(uint64(*u), 10)
}

View File

@@ -0,0 +1,55 @@
// SPDX-License-Identifier: Apache-2.0
//
// Copyright The Prometheus Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package win32
// ParseMultiSz splits a UTF-16 encoded MULTI_SZ buffer (Windows style) into
// individual UTF-16 string slices.
//
// A MULTI_SZ buffer is a sequence of UTF-16 strings separated by single null
// terminators (0x0000) and terminated by an extra null (i.e., two consecutive
// nulls) to mark the end of the list.
//
// Example layout in memory (UTF-16):
//
// "foo\0bar\0baz\0\0"
//
// Given such a []uint16, this function returns a [][]uint16 where each inner
// slice is one null-terminated string segment without the trailing null.
//
// The returned slices reference the original buffer (no copying).
func ParseMultiSz(buf []uint16) [][]uint16 {
var (
result [][]uint16
start int
)
for i := range buf {
if buf[i] == 0 {
// Found a null terminator.
if i == start {
// Two consecutive nulls → end of list.
break
}
// Append current string slice (excluding null).
result = append(result, buf[start:i])
// Move start to next character after null.
start = i + 1
}
}
return result
}