Skip to content
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C++ Backend Architecture Session Notes This document summarizes the key architectural decisions and implementations for the C++ backend system, focusing on thread safety, file integrity, and cross-platform compatibility.

  1. Thread-Safe Undo Stack Challenge: Pointer misalignment and race conditions when multiple threads attempted to modify or read the document history concurrently. Solution: Implemented a robust undo stack using std::shared_ptr. Mechanism: By wrapping state nodes in std::shared_ptr, we ensure that memory remains valid as long as any thread (or the undo stack itself) holds a reference. This completely eliminates dangling pointers and misalignment during concurrent operations. Result: Thread-safe state traversal and memory management.
  2. Three-Way Merge Logic Challenge: Preventing automated agents (or reverts) from overwriting concurrent human edits. Solution: Integrated Three-Way Merge Logic for state reconciliation. Mechanism: When a revert or agent edit is applied, the system compares the Base (original state), the Local (human edits), and the Remote (agent changes/revert state). Result: Human edits are actively protected and intelligently merged rather than blindly overwritten.
  3. Atomic Persistence Challenge: File corruption occurring if the system crashed or lost power midway through a file write operation. Solution: Atomic file writes using std::filesystem::rename (fs::rename). Mechanism: 1. Write the new state entirely to a temporary hidden file (e.g., .document.tmp). 2. Once the write is completely successful and the file handle is closed, invoke fs::rename to swap the temporary file over the active file. Result: The file system guarantees that rename operations are atomic. The document is either 100% the old version or 100% the new version, with zero risk of a corrupted, half-written state.
  4. Path Standardization Challenge: Path separator conflicts (\ vs /) and root discrepancies between Windows and POSIX (Linux/macOS) environments. Solution: Developed a unified C++ path utility. Mechanism: A custom normalization wrapper around std::filesystem::path that enforces consistent POSIX-style forward slashes internally while resolving absolute/relative paths correctly across different OS kernels. Result: Bridges the gap between Windows and POSIX, ensuring cross-platform stability.
  5. Security Configuration (macOS Hardened Runtime) Challenge: macOS Gatekeeper and Sandbox blocking dynamic library loading for plugin-based architectures. Solution: Signed the binary with specific Hardened Runtime entitlements to allow for unsigned executable memory and third-party library loading. Entitlements Definition The following entitlements are essential for a C++ application that hosts a plugin system: Entitlement Key Purpose com.apple.security.cs.disable-library-validation Allows the app to load plug-ins or frameworks signed by any developer ID, or unsigned ones, bypassing the default requirement that plugins match the host's Team ID. com.apple.security.cs.allow-jit Allows the app to create writable and executable memory regions using mmap with the MAP_JIT flag. com.apple.security.cs.allow-unsigned-executable-memory Allows the app to override the default Hardened Runtime protection against unsigned memory pages, essential for certain dynamic loading scenarios.

Entitlements Generation (entitlements.plist)

com.apple.security.cs.disable-library-validation com.apple.security.cs.allow-jit com.apple.security.cs.allow-unsigned-executable-memory

Signing and Verification Workflow

  1. Apply Entitlements: Use the --options runtime flag to enable the Hardened Runtime.

Apply entitlements and enable Hardened Runtime

codesign --force --options runtime --entitlements entitlements.plist -s "Your Developer ID" ./build/MyCodingPartner

  1. Inspect and Verify: Verify that the entitlements are successfully embedded.

Inspect entitlements in a human-readable format

codesign -d --entitlements :- ./build/MyCodingPartner

Troubleshooting code object is not signed at all: Ensure you are pointing to the correct binary path and have a valid certificate in your Keychain. resource fork, Finder information, or similar detritus not allowed: Run xattr -cr ./build/MyCodingPartner before signing to clear metadata (removes extended attributes that interfere with codesigning). Plugin Load Failure: Even with disable-library-validation, ensure the plugin itself doesn't have broken install_name paths. Use otool -L to check the shared library dependencies. Result: Secure, warning-free plugin loading on macOS environments. This configuration allows the host app to load plugins not signed by the same Team ID and enables JIT compilation for performance-critical modules.

About

No description, website, or topics provided.

Resources

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

Packages

Contributors