Skip to content
This repository was archived by the owner on Sep 19, 2023. It is now read-only.
/ jdk21 Public archive

Commit 45f252b

Browse files
committed
8310405: Linker.Option.firstVariadicArg should specify which index values are valid
Reviewed-by: mcimadamore Backport-of: 7fffdb5e60351026c9ee77f438b8fe505d85de4c
1 parent 687863d commit 45f252b

File tree

1 file changed

+19
-4
lines changed
  • src/java.base/share/classes/java/lang/foreign

1 file changed

+19
-4
lines changed

src/java.base/share/classes/java/lang/foreign/Linker.java

+19-4
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,8 @@
416416
* The native linker only supports linking the specialized form of a variadic function. A variadic function in its specialized
417417
* form can be linked using a function descriptor describing the specialized form. Additionally, the
418418
* {@link Linker.Option#firstVariadicArg(int)} linker option must be provided to indicate the first variadic parameter in
419-
* the parameter list. The corresponding argument layout, and all following argument layouts in the specialized function
420-
* descriptor, are called <em>variadic argument layouts</em>. For a prototype-less function, the index passed to
419+
* the parameter list. The corresponding argument layout (if any), and all following argument layouts in the specialized
420+
* function descriptor, are called <em>variadic argument layouts</em>. For a prototype-less function, the index passed to
421421
* {@link Linker.Option#firstVariadicArg(int)} should always be {@code 0}.
422422
* <p>
423423
* The native linker will reject an attempt to link a specialized function descriptor with any variadic argument layouts
@@ -644,8 +644,23 @@ sealed interface Option
644644
permits LinkerOptions.LinkerOptionImpl {
645645

646646
/**
647-
* {@return a linker option used to denote the index of the first variadic argument layout in the
648-
* function descriptor associated with a downcall linkage request}
647+
* {@return a linker option used to denote the index indicating the start of the variadic arguments passed to the
648+
* function described by the function descriptor associated with a downcall linkage request}
649+
* <p>
650+
* The {@code index} value must conform to {@code 0 <= index <= N}, where {@code N} is the number of argument
651+
* layouts of the function descriptor used in conjunction with this linker option. When the {@code index} is:
652+
* <ul>
653+
* <li>{@code 0}, all arguments passed to the function are passed as variadic arguments</li>
654+
* <li>{@code N}, none of the arguments passed to the function are passed as variadic arguments</li>
655+
* <li>{@code n}, where {@code 0 < m < N}, the arguments {@code m..N} are passed as variadic arguments</li>
656+
* </ul>
657+
* It is important to always use this linker option when linking a <a href=Linker.html#variadic-funcs>variadic
658+
* function</a>, even if no variadic argument is passed (the second case in the list
659+
* above), as this might still affect the calling convention on certain platforms.
660+
*
661+
* @implNote The index value is validated when making a linkage request, which is when the function descriptor
662+
* against which the index is validated is available.
663+
*
649664
* @param index the index of the first variadic argument layout in the function descriptor associated
650665
* with a downcall linkage request.
651666
*/

0 commit comments

Comments
 (0)