Skip to content

Commit 28c02ae

Browse files
authored
Backport #1629, #1614 and #1581 to 12.9.x (#1646)
* BUG: Fix use-after-free in _HelperInputVoidPtr properties (#1629) * BUG: Fix use-after-free in _HelperInputVoidPtr properties * Revert cptr ref * Apply suggestion from @mdboom * Add fix
1 parent 0e9911a commit 28c02ae

26 files changed

Lines changed: 10530 additions & 7395 deletions

cuda_bindings/cuda/bindings/_bindings/cydriver.pxd.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# SPDX-FileCopyrightText: Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
# SPDX-FileCopyrightText: Copyright (c) 2021-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
33

4-
# This code was automatically generated with version 12.9.0. Do not modify it directly.
4+
# This code was automatically generated with version 12.9.0, generator version 0d24f4f. Do not modify it directly.
55
from cuda.bindings.cydriver cimport *
66

77
{{if 'cuGetErrorString' in found_functions}}

cuda_bindings/cuda/bindings/_bindings/cydriver.pyx.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# SPDX-FileCopyrightText: Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
# SPDX-FileCopyrightText: Copyright (c) 2021-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
33

4-
# This code was automatically generated with version 12.9.0. Do not modify it directly.
4+
# This code was automatically generated with version 12.9.0, generator version 0d24f4f. Do not modify it directly.
55
{{if 'Windows' == platform.system()}}
66
import os
77
cimport cuda.bindings._lib.windll as windll

cuda_bindings/cuda/bindings/_bindings/cynvrtc.pxd.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# SPDX-FileCopyrightText: Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
# SPDX-FileCopyrightText: Copyright (c) 2021-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
33

4-
# This code was automatically generated with version 12.9.0. Do not modify it directly.
4+
# This code was automatically generated with version 12.9.0, generator version 0d24f4f. Do not modify it directly.
55
from cuda.bindings.cynvrtc cimport *
66

77
{{if 'nvrtcGetErrorString' in found_functions}}

cuda_bindings/cuda/bindings/_bindings/cynvrtc.pyx.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# SPDX-FileCopyrightText: Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
# SPDX-FileCopyrightText: Copyright (c) 2021-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
33

4-
# This code was automatically generated with version 12.9.0. Do not modify it directly.
4+
# This code was automatically generated with version 12.9.0, generator version 0d24f4f. Do not modify it directly.
55
{{if 'Windows' == platform.system()}}
66
import os
77
cimport cuda.bindings._lib.windll as windll

cuda_bindings/cuda/bindings/_bindings/cyruntime.pxd.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# SPDX-FileCopyrightText: Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
# SPDX-FileCopyrightText: Copyright (c) 2021-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
33

4-
# This code was automatically generated with version 12.9.0. Do not modify it directly.
4+
# This code was automatically generated with version 12.9.0, generator version 0d24f4f. Do not modify it directly.
55
include "../cyruntime_types.pxi"
66

77
include "../_lib/cyruntime/cyruntime.pxd"

cuda_bindings/cuda/bindings/_bindings/cyruntime.pyx.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# SPDX-FileCopyrightText: Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
# SPDX-FileCopyrightText: Copyright (c) 2021-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
33

4-
# This code was automatically generated with version 12.9.0. Do not modify it directly.
4+
# This code was automatically generated with version 12.9.0, generator version 0d24f4f. Do not modify it directly.
55
include "../cyruntime_functions.pxi"
66

77
import os

cuda_bindings/cuda/bindings/_bindings/cyruntime_ptds.pxd.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# SPDX-FileCopyrightText: Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
# SPDX-FileCopyrightText: Copyright (c) 2021-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
33

4-
# This code was automatically generated with version 12.9.0. Do not modify it directly.
4+
# This code was automatically generated with version 12.9.0, generator version 0d24f4f. Do not modify it directly.
55
cdef extern from "":
66
"""
77
#define CUDA_API_PER_THREAD_DEFAULT_STREAM

cuda_bindings/cuda/bindings/_bindings/cyruntime_ptds.pyx.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# SPDX-FileCopyrightText: Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
# SPDX-FileCopyrightText: Copyright (c) 2021-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
33

4-
# This code was automatically generated with version 12.9.0. Do not modify it directly.
4+
# This code was automatically generated with version 12.9.0, generator version 0d24f4f. Do not modify it directly.
55
cdef extern from "":
66
"""
77
#define CUDA_API_PER_THREAD_DEFAULT_STREAM
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
3+
4+
5+
# This code was automatically generated across versions from 12.9.1 to 13.1.1. Do not modify it directly.
6+
7+
8+
"""
9+
This is a replacement for the stdlib enum.IntEnum.
10+
11+
Notably, it has much better import time performance, since it doesn't generate
12+
and evaluate Python code at startup time.
13+
14+
It supports the most important subset of the IntEnum API. See `test_enum` in
15+
`cuda_bindings/tests/test_basics.py` for details.
16+
"""
17+
18+
from typing import Any, Iterator
19+
20+
21+
class FastEnumMetaclass(type):
22+
def __init__(cls, name, bases, namespace):
23+
super().__init__(name, bases, namespace)
24+
25+
cls.__singletons__ = {}
26+
cls.__members__ = {}
27+
for name, value in cls.__dict__.items():
28+
if name.startswith("__") and name.endswith("__"):
29+
continue
30+
31+
if isinstance(value, tuple):
32+
value, doc = value
33+
elif isinstance(value, int):
34+
doc = None
35+
else:
36+
continue
37+
38+
singleton = int.__new__(cls, value)
39+
singleton.__doc__ = doc
40+
singleton._name = name
41+
cls.__singletons__[value] = singleton
42+
cls.__members__[name] = singleton
43+
44+
for name, member in cls.__members__.items():
45+
setattr(cls, name, member)
46+
47+
def __repr__(cls) -> str:
48+
return f"<enum '{cls.__name__}'>"
49+
50+
def __len__(cls) -> int:
51+
return len(cls.__members__)
52+
53+
def __iter__(cls) -> Iterator["FastEnum"]:
54+
return iter(cls.__members__.values())
55+
56+
def __contains__(cls, item: Any) -> bool:
57+
return item in cls.__singletons__
58+
59+
60+
class FastEnum(int, metaclass=FastEnumMetaclass):
61+
def __new__(cls, value: int) -> "FastEnum":
62+
singleton: FastEnum = cls.__singletons__.get(value)
63+
if singleton is None:
64+
raise ValueError(f"{value} is not a valid {cls.__name__}")
65+
return singleton
66+
67+
def __repr__(self) -> str:
68+
return f"<{self.__class__.__name__}.{self._name}: {int(self)}>"
69+
70+
@property
71+
def name(self) -> str:
72+
return self._name
73+
74+
@property
75+
def value(self) -> int:
76+
return int(self)

cuda_bindings/cuda/bindings/_lib/utils.pxd.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: Copyright (c) 2021-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
# SPDX-FileCopyrightText: Copyright (c) 2021-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
33

44
cimport cuda.bindings.driver as driver
@@ -134,6 +134,7 @@ cdef class _HelperCUmemAllocationHandleType:
134134
{{endif}}
135135

136136
cdef class _InputVoidPtrPtrHelper:
137+
cdef object _references
137138
cdef void** _cptr
138139

139140
{{if 'CUcoredumpSettings_enum' in found_types}}

0 commit comments

Comments
 (0)