# B09 — Fixed upstream in pharo-12

Bug ref      : always.md B.9 ; pharo.md §5.24
Status       : Partially addressed upstream

## Original concern (pharo-10)

`sqMakeMemoryExecutableFromTo` and `sqMakeMemoryNotExecutableFromTo`
bodies were commented out, and `allocateJITMemory` mapped JIT pages
`PROT_READ|PROT_WRITE|PROT_EXEC` permanently.

## What pharo-12 does

`src/unix/memoryUnix.c:65-89` now implements both hooks via
`mprotect` for real:

  - `sqMakeMemoryExecutableFromTo` → `PROT_READ|PROT_EXEC`
  - `sqMakeMemoryNotExecutableFromTo` → `PROT_READ|PROT_WRITE`

and `allocateJITMemory` (lines 99-113) picks the initial protection
based on a new build option:

```c
#if __APPLE__
    int prot = PROT_READ | PROT_WRITE | PROT_EXEC;   /* MAP_JIT requires RWX on Apple */
#else
    int additionalFlags = desiredPosition ? MAP_FIXED : 0;
#   if READ_ONLY_CODE_ZONE
        int prot = PROT_READ | PROT_EXEC;
#   else
        int prot = PROT_READ | PROT_WRITE | PROT_EXEC;   /* legacy */
#   endif
#endif
```

`cmake/Linux.cmake:1` exposes `READ_ONLY_CODE_ZONE` as an off-by-
default option:

```cmake
option(READ_ONLY_CODE_ZONE "Makes Cogit's code zone never writeable and executable at the same time" OFF)
```

## Residual risk

  - The shipped Linux build still defaults to RWX (READ_ONLY_CODE_ZONE
    is OFF). Operators need to opt in via `-DREAD_ONLY_CODE_ZONE=ON`.
  - The Apple path still maps RWX. MAP_JIT semantics on Apple Silicon
    require `pthread_jit_write_protect_np` rather than mprotect; that
    work is still pending and out of scope for this PR.

The pharo-10 patch from `always/B09` is therefore not needed against
pharo-12 — the infrastructure is already in place.
