Skip to content

Generate appsec php stub with all exposed function by extension#3858

Merged
estringana merged 5 commits into
masterfrom
estringana/update-stub
May 13, 2026
Merged

Generate appsec php stub with all exposed function by extension#3858
estringana merged 5 commits into
masterfrom
estringana/update-stub

Conversation

@estringana
Copy link
Copy Markdown
Contributor

Description

Migrate appsec extension to stub-based function registration

Replaces the scattered, hand-maintained arginfo blocks and per-file zend_function_entry tables in ddappsec.c and tags.c with the standard PHP stub workflow.

Changes

  • Add ddappsec.stub.php as the single source of truth for the public datadog\appsec PHP API, with proper typed signatures for all 11 exposed functions.
  • Generate ddappsec_arginfo.h from the stub using PHP's gen_stub.php tool; this replaces all hand-written ZEND_BEGIN_ARG_* / ZEND_END_ARG_* blocks and consolidates function registration into a single ext_functions[] table.
  • Wire stub regeneration into CMake so ddappsec_arginfo.h is automatically rebuilt whenever ddappsec.stub.php changes.

Issue where this is reported: #3855

@datadog-datadog-prod-us1-2

This comment has been minimized.

@pr-commenter
Copy link
Copy Markdown

pr-commenter Bot commented May 6, 2026

Benchmarks [ appsec ]

Benchmark execution time: 2026-05-12 16:33:53

Comparing candidate commit a89bb60 in PR branch estringana/update-stub with baseline commit 7d17869 in branch master.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 12 metrics, 0 unstable metrics.

Copy link
Copy Markdown
Contributor

@cataphract cataphract left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not against having a target to regenerate arginfo, but I think we need to do validation on the version of gen_stub.php and call it in the appropriate compatibility mode.

Comment thread appsec/cmake/extension.cmake
Comment thread appsec/cmake/extension.cmake Outdated
Comment thread appsec/cmake/extension.cmake Outdated
Comment thread appsec/cmake/extension.cmake
}

static PHP_FUNCTION(datadog_appsec_is_enabled)
PHP_FUNCTION(datadog_appsec_is_enabled)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these can stay static

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but they will be references from outside

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they are referenced in the generated arginfo header file, which is only included in the same compilation unit. So static should be fine.

Comment thread appsec/src/extension/ddappsec.c Outdated
@estringana estringana force-pushed the estringana/update-stub branch 4 times, most recently from db09385 to 079d514 Compare May 6, 2026 15:26
@pr-commenter
Copy link
Copy Markdown

pr-commenter Bot commented May 6, 2026

Benchmarks [ tracer ]

Benchmark execution time: 2026-05-06 16:45:45

Comparing candidate commit 079d514 in PR branch estringana/update-stub with baseline commit 8ff00ed in branch master.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 194 metrics, 0 unstable metrics.

@estringana estringana marked this pull request as ready for review May 7, 2026 08:36
@estringana estringana requested a review from a team as a code owner May 7, 2026 08:36
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 079d514e06

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

)
list(APPEND STUB_ARGINFO_HEADERS ${_arginfo})
endforeach()
add_custom_target(generate_arginfo DEPENDS ${STUB_ARGINFO_HEADERS})
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Hook stub generation into the extension build

When a stub changes, a normal cmake --build of the extension will keep compiling the checked-in *_arginfo.h because this custom target is not part of ALL and nothing depends on it; CMake's own help for add_custom_target states that, by default, nothing depends on the custom target. In the context of the new stub workflow, this means edits to tags.stub.php or entity_body.stub.php can silently ship stale reflection/function-entry metadata unless a developer remembers to build generate_arginfo manually. Add a dependency from the extension target (or otherwise list the generated headers as generated sources) so the command runs before compiling the files that include these headers.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by design

@cataphract
Copy link
Copy Markdown
Contributor

Needs to be updated in light of #3857

@estringana estringana force-pushed the estringana/update-stub branch from 079d514 to 4c5389a Compare May 8, 2026 15:27
@estringana estringana requested review from a team as code owners May 8, 2026 15:27
@cataphract cataphract force-pushed the estringana/update-stub branch from efca45a to 05b4aff Compare May 8, 2026 17:24
Comment thread appsec/src/extension/ddappsec.c Outdated
Comment thread appsec/src/extension/tags.c Outdated
@estringana estringana force-pushed the estringana/update-stub branch from 168b7a7 to c079283 Compare May 12, 2026 14:15
@estringana estringana enabled auto-merge (squash) May 13, 2026 15:44
@estringana estringana force-pushed the estringana/update-stub branch from a89bb60 to b4ec754 Compare May 13, 2026 15:57
@estringana estringana merged commit 9d1c715 into master May 13, 2026
2 of 3 checks passed
@estringana estringana deleted the estringana/update-stub branch May 13, 2026 15:57
@github-actions github-actions Bot modified the milestone: 1.20.0 May 13, 2026
@github-actions github-actions Bot added profiling Relates to the Continuous Profiler tracing labels May 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:asm profiling Relates to the Continuous Profiler tracing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants