Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX SHOULD_GATE_ENTROPY condition #2668

Merged
merged 2 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/pyodide/internal/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,8 @@ let TEST_SNAPSHOT: Uint8Array | undefined = undefined;
})();

export function finishSnapshotSetup(pyodide: Pyodide): void {
if (DSO_METADATA?.settings?.baselineSnapshot) {
// Invalidate caches if we have a baseline snapshot because the contents of site-packages may
// have changed.
if (LOADED_SNAPSHOT_VERSION !== undefined) {
// Invalidate caches if we have a snapshot because the contents of site-packages may have changed.
simpleRunPython(
pyodide._module,
'from importlib import invalidate_caches as f; f(); del f'
Expand Down
7 changes: 4 additions & 3 deletions src/pyodide/internal/topLevelEntropy/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
import { default as entropyPatches } from 'pyodide-internal:topLevelEntropy/entropy_patches.py';
import { default as entropyImportContext } from 'pyodide-internal:topLevelEntropy/entropy_import_context.py';
import { default as importPatchManager } from 'pyodide-internal:topLevelEntropy/import_patch_manager.py';
import { IS_TRACING } from 'pyodide-internal:metadata';
import { LOADED_SNAPSHOT_VERSION } from 'pyodide-internal:snapshot';
import { simpleRunPython } from 'pyodide-internal:util';

// Disable entropy gating when we've restored a snapshot of version 1. Version 1 snapshots were
// created without entropy gating and will crash if they are used with it. If we are creating a new
// snapshot or using one of version at least 2 we should gate.
// TODO: When we've updated all the snapshots, remove this.
const SHOULD_GATE_ENTROPY =
!IS_TRACING &&
(LOADED_SNAPSHOT_VERSION === undefined || LOADED_SNAPSHOT_VERSION === 2);
LOADED_SNAPSHOT_VERSION !== 0 && LOADED_SNAPSHOT_VERSION !== 1;

let allowed_entropy_calls_addr: number;

Expand Down