Skip to content

Commit e549261

Browse files
committed
Validate PHP extension module exports
1 parent b6fbb05 commit e549261

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

packages/php-wasm/compile-extension/scripts/build-in-docker.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,22 @@ if [ -x /root/emsdk/upstream/bin/wasm-opt ]; then
110110
-o "$module_path"
111111
fi
112112

113+
node --input-type=module - "$module_path" <<'EOF'
114+
import { readFile } from 'node:fs/promises';
115+
116+
const modulePath = process.argv[2];
117+
const module = new WebAssembly.Module(await readFile(modulePath));
118+
const hasGetModule = WebAssembly.Module.exports(module).some(
119+
({ kind, name }) => kind === 'function' && name === 'get_module'
120+
);
121+
122+
if (!hasGetModule) {
123+
throw new Error(
124+
`${modulePath} does not export PHP's get_module() entry point. ` +
125+
'PHP extensions must include config.h and call ZEND_GET_MODULE().'
126+
);
127+
}
128+
EOF
129+
113130
mkdir -p /out
114131
cp "$module_path" "/out/${ARTIFACT_FILENAME}"

packages/php-wasm/compile-extension/tests/fixtures/external-abi/external_abi.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#ifdef HAVE_CONFIG_H
2+
#include "config.h"
3+
#endif
4+
15
#include "php.h"
26
#include "ext/standard/php_password.h"
37
#include <stdio.h>
@@ -43,5 +47,8 @@ zend_module_entry external_abi_module_entry = {
4347
};
4448

4549
#ifdef COMPILE_DL_EXTERNAL_ABI
50+
#ifdef ZTS
51+
ZEND_TSRMLS_CACHE_DEFINE()
52+
#endif
4653
ZEND_GET_MODULE(external_abi)
4754
#endif

0 commit comments

Comments
 (0)