forked from Blendman974/faceclaw
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
75bceb3b92
|
No files matched your search
@@ -29,3 +29,8 @@ add_subdirectory(${LLAMA_CPP_SOURCE_DIR} llama.cpp-build EXCLUDE_FROM_ALL)
|
||||
|
||||
add_library(faceclaw_llama SHARED faceclaw_llama.cpp)
|
||||
target_link_libraries(faceclaw_llama PRIVATE llama android log)
|
||||
# NDK r27 defaults to 4 KiB. Align both LOAD segments and RELRO boundaries
|
||||
# for Android devices using 16 KiB pages, including debug APKs.
|
||||
target_link_options(faceclaw_llama PRIVATE
|
||||
"-Wl,-z,max-page-size=16384"
|
||||
"-Wl,-z,common-page-size=16384")
|
||||
@@ -121,7 +121,6 @@ export type DashboardSnapshot = {
|
||||
* glasses, and this says which harmless thing is actually going on.
|
||||
*/
|
||||
displayPreviewMessage: string;
|
||||
silentModeFeedback: string;
|
||||
activeTextSettingId: string | null;
|
||||
activeTextEditorTitle: string;
|
||||
activeTextSettingTitle: string;
|
||||
@@ -295,9 +294,6 @@ class DashboardController {
|
||||
/** The screen area displayPreview shows (Preview scaling), or null for the whole panel. */
|
||||
private displayPreviewCrop: ScreenRect | null = null;
|
||||
private silentMode = false;
|
||||
private silentModeFeedback = "";
|
||||
private silentModeFeedbackGeneration = 0;
|
||||
private silentModeFeedbackTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
// Brightness value last pushed to the glasses; see pushBrightness.
|
||||
private lastPushedBrightness: string | null = null;
|
||||
// Last battery level the glasses reported, kept across disconnects so a
|
||||
@@ -1146,7 +1142,6 @@ class DashboardController {
|
||||
status: this.status,
|
||||
displayPreview: this.displayPreview,
|
||||
displayPreviewMessage: this.displayPreviewMessage(),
|
||||
silentModeFeedback: this.silentModeFeedback,
|
||||
activeTextSettingId: primaryTextSetting?.id ?? null,
|
||||
activeTextEditorTitle: this.activeTextEditorTitle,
|
||||
activeTextSettingTitle: primaryTextSetting?.editorTitle ?? "",
|
||||
@@ -1186,43 +1181,6 @@ class DashboardController {
|
||||
* charging and silent mode both make the display unavailable while BLE stays
|
||||
* up, and a battery that just ran out simply stops answering.
|
||||
*/
|
||||
private handleSilentMode(silent: boolean): void {
|
||||
if (this.silentMode === silent) return;
|
||||
this.silentMode = silent;
|
||||
const generation = ++this.silentModeFeedbackGeneration;
|
||||
if (this.silentModeFeedbackTimer !== null) clearTimeout(this.silentModeFeedbackTimer);
|
||||
this.silentModeFeedbackTimer = null;
|
||||
this.silentModeFeedback = silent
|
||||
? "Silent mode enabled — hold both touchpads to exit"
|
||||
: "Silent mode disabled";
|
||||
if (!silent) {
|
||||
void this.showSilentModeExit(generation).catch(error => {
|
||||
this.appendLog(`silent-mode exit feedback failed: ${this.formatError(error)}`);
|
||||
});
|
||||
this.silentModeFeedbackTimer = setTimeout(() => {
|
||||
this.silentModeFeedbackTimer = null;
|
||||
this.silentModeFeedback = "";
|
||||
this.emit();
|
||||
}, 5000);
|
||||
}
|
||||
this.emit();
|
||||
}
|
||||
|
||||
private async showSilentModeExit(generation: number): Promise<void> {
|
||||
if (this.phase !== "connected" || this.silentMode || this.glassesLocked) return;
|
||||
// The firmware powered the lenses down, and Faceclaw may have gone to
|
||||
// sleep/suspended EvenHub meanwhile. Reusing the ordinary wake barrier is
|
||||
// essential: rendering an alert into the retained surface alone is invisible.
|
||||
this.cancelEvenHubSuspendTimer();
|
||||
shell.wake("sidebar");
|
||||
const ready = await this.ensureEvenHubSessionActive();
|
||||
if (!ready || generation !== this.silentModeFeedbackGeneration || this.silentMode ||
|
||||
this.phase !== "connected" || this.glassesLocked) return;
|
||||
shell.showAlert("Silent mode disabled");
|
||||
shell.foregroundWindow()?.requestRender();
|
||||
this.requestShellRender();
|
||||
}
|
||||
|
||||
private displayPreviewMessage(): string {
|
||||
if (this.phase === "charging") {
|
||||
return chargingPreviewMessage(this.glassesDisplayState());
|
||||
@@ -1646,7 +1604,9 @@ class DashboardController {
|
||||
});
|
||||
});
|
||||
this.offSilentMode = communicator.onSilentMode((silent) => {
|
||||
this.handleSilentMode(silent);
|
||||
if (this.silentMode === silent) return;
|
||||
this.silentMode = silent;
|
||||
this.emit();
|
||||
});
|
||||
this.offWearState = communicator.onWearState((wearing) => {
|
||||
this.handleWearState(wearing);
|
||||
@@ -3024,10 +2984,6 @@ class DashboardController {
|
||||
// Kept across "connecting": silent mode blocks app launches, so it can
|
||||
// itself cause the reconnect churn, and Java re-reports it either way.
|
||||
this.silentMode = false;
|
||||
this.silentModeFeedbackGeneration++;
|
||||
if (this.silentModeFeedbackTimer !== null) clearTimeout(this.silentModeFeedbackTimer);
|
||||
this.silentModeFeedbackTimer = null;
|
||||
this.silentModeFeedback = "";
|
||||
}
|
||||
this.emit();
|
||||
}
|
||||
|
||||
@@ -74,9 +74,6 @@
|
||||
class="ble-bandwidth-indicator"
|
||||
horizontalAlignment="center"
|
||||
verticalAlignment="bottom" />
|
||||
<Label text="{{ silentModeFeedback }}" visibility="{{ silentModeFeedbackVisibility }}"
|
||||
textWrap="true" horizontalAlignment="center" verticalAlignment="top"
|
||||
margin="12" padding="12" backgroundColor="#333333" color="white" borderRadius="8" />
|
||||
<ScrollView
|
||||
class="warnings-modal"
|
||||
visibility="{{ warningsModalVisibility }}"
|
||||
|
||||
@@ -37,7 +37,6 @@ export class MainViewModel extends RemoteControlsViewModel {
|
||||
private _status = "Disconnected.";
|
||||
private _displayPreview: ImageSource | null = null;
|
||||
private _displayPreviewMessage = "";
|
||||
private _silentModeFeedback = "";
|
||||
private _layoutOrientation: LayoutOrientation = this.readLayoutOrientation();
|
||||
private _landscapePreviewWidth = 0;
|
||||
private _landscapePreviewHeight = 0;
|
||||
@@ -91,7 +90,6 @@ export class MainViewModel extends RemoteControlsViewModel {
|
||||
this.previewMode = snapshot.previewMode;
|
||||
this.displayPreview = snapshot.displayPreview;
|
||||
this.displayPreviewMessage = snapshot.displayPreviewMessage;
|
||||
this.silentModeFeedback = snapshot.silentModeFeedback ?? "";
|
||||
this.phase = snapshot.phase;
|
||||
this.batteryLine = formatBatteryLine(
|
||||
snapshot.batteries,
|
||||
@@ -218,17 +216,6 @@ export class MainViewModel extends RemoteControlsViewModel {
|
||||
}
|
||||
}
|
||||
|
||||
get silentModeFeedback(): string { return this._silentModeFeedback; }
|
||||
set silentModeFeedback(value: string) {
|
||||
if (this._silentModeFeedback === value) return;
|
||||
this._silentModeFeedback = value;
|
||||
this.notifyPropertyChange("silentModeFeedback", value);
|
||||
this.notifyPropertyChange("silentModeFeedbackVisibility", this.silentModeFeedbackVisibility);
|
||||
}
|
||||
get silentModeFeedbackVisibility(): "visible" | "collapse" {
|
||||
return this._silentModeFeedback ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
get hasDisplayPreview(): boolean {
|
||||
return this._displayPreview !== null;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
# Android 16 KiB page compatibility
|
||||
|
||||
The initial debug APK triggered Android's page-size compatibility warning.
|
||||
Its `libfaceclaw_llama.so` LOAD segments were aligned to 4096 bytes. The other
|
||||
six packaged arm64 libraries were aligned to 16384 bytes, and APK ZIP alignment
|
||||
already passed `zipalign -c -P 16 4`.
|
||||
|
||||
The llama JNI shared library now links with both `max-page-size=16384` and
|
||||
`common-page-size=16384`, matching the LC3 JNI library. This changes the native
|
||||
binary layout rather than hiding the compatibility warning or disabling debug.
|
||||
Gradle already tracks CMakeLists.txt as an input, and Ninja reconfigures and
|
||||
relinks existing builds after this change.
|
||||
|
||||
Reproduce the regression and artifact checks inside `devenv shell`:
|
||||
|
||||
```sh
|
||||
python3 -m unittest discover -s tests -p test_apk_pages.py
|
||||
bash build.sh
|
||||
python3 scripts/check-apk-pages.py platforms/android/app/build/outputs/apk/debug/app-debug.apk
|
||||
"$ANDROID_HOME/build-tools/35.0.1/zipalign" -c -P 16 4 platforms/android/app/build/outputs/apk/debug/app-debug.apk
|
||||
```
|
||||
|
||||
The checker rejects the initial APK and reports its misaligned llama library.
|
||||
Five unit tests cover 4 KiB rejection, 16 KiB acceptance, RELRO boundaries and
|
||||
invalid ELF program headers. APK checks inspect all arm64/x86_64 shared libraries.
|
||||
|
||||
Reference: [Android's 16 KiB guidance](https://developer.android.com/guide/practices/page-sizes).
|
||||
Static alignment and successful installation do not prove every native code
|
||||
path works on-device; voice/LLM features still require functional testing.
|
||||
|
||||
The rebuilt APK passes all seven native-library checks, ZIP alignment and APK
|
||||
signature verification. The connected Pixel 10 Pro Fold reports `getconf
|
||||
PAGE_SIZE` = 4096; actual execution with 16 KiB pages remains untested.
|
||||
@@ -1,11 +0,0 @@
|
||||
# Silent-mode feedback
|
||||
|
||||
The firmware blanks the lenses and stops ordinary input while silent mode is active. App code cannot display an activation popup on lenses that the firmware has switched off. The phone now shows a persistent enabled banner with the exit gesture, and a five-second disabled banner on exit. On exit, unlocked glasses wake through the normal screen/EvenHub barrier before the alert popup is rendered. This also handles the shell falling asleep during a long silent period. Locked glasses keep the phone feedback without being woken. A generation check suppresses stale notices after re-entry or disconnect. Duplicate state reports do not repeat feedback, stale timers are cancelled, and disconnect clears the notice.
|
||||
|
||||
Silent-off firmware pushes are not reliable. The existing fallback read used the five-minute battery cadence. While silent mode is known to be on, settings are now polled every two seconds when the session is ready and the message queues are idle. Normal battery cadence and shutdown guards are retained. This bounds ordinary missing-push recovery without assuming a touch gesture always means silent mode ended.
|
||||
|
||||
Independent JavaScript suite: 1065 passed, 2 skipped. TypeScript and changed-source lint passed. Controller tests cover enabled/disabled notices, duplicates, timer cancellation, disconnect and sleeping-display recovery, locked displays, wake-barrier failure and stale async completion. A Kotlin session test checks the two-second silent cadence, normal cadence and shutdown guard. Kotlin compilation and hardware checks are tracked with the combined integration validation.
|
||||
|
||||
Hardware validation remains pending: both transitions via the temple gesture, missing exit push, phone background/foreground, lenses that are awake/asleep/locked, reconnect and charging. No firmware was flashed.
|
||||
|
||||
Follow-up after device-log inspection: both silent transitions arrived, but the exit could occur after the normal idle timeout. Exit now cancels pending suspension, wakes the shell, awaits the existing EvenHub/screen wake barrier and only then shows the notice. It resets idle activity through the ordinary wake path. Re-entry, disconnect, locking or a failed resume suppress stale asynchronous notices. Activation still turns the lenses off in firmware; phone feedback does not claim a lens-side activation popup.
|
||||
-2
@@ -37,8 +37,6 @@ class ConnectionOptions {
|
||||
const val HEARTBEAT_FAILURE_DEADLINE_MS = 10_000
|
||||
const val HEARTBEAT_READY_MS = 4_000
|
||||
const val HEARTBEAT_URGENT_MS = 6_000
|
||||
// Silent-off pushes are not reliable; promptly re-read the state while silent.
|
||||
const val SILENT_MODE_POLL_MS = 2_000
|
||||
const val BATTERY_REFRESH_INTERVAL_MS = 5 * 60_000
|
||||
const val BATTERY_INPUT_QUIET_MS = 5_000
|
||||
// Poll cadence while in charging mode; also bounds how quickly we notice
|
||||
|
||||
+2
-3
@@ -1041,9 +1041,8 @@ internal fun GlassesSessionCore.shouldPollBatteryLocked(now: Long): Boolean {
|
||||
&& sessionReady
|
||||
&& pendingMessages.isEmpty()
|
||||
&& inFlightMessages.isEmpty()
|
||||
&& (silentMode == 1 || now - lastConnectionOrInputAtMs >= ConnectionOptions.BATTERY_INPUT_QUIET_MS)
|
||||
&& (lastBatteryRefreshAtMs == 0L || now - lastBatteryRefreshAtMs >=
|
||||
if (silentMode == 1) ConnectionOptions.SILENT_MODE_POLL_MS else ConnectionOptions.BATTERY_REFRESH_INTERVAL_MS)
|
||||
&& now - lastConnectionOrInputAtMs >= ConnectionOptions.BATTERY_INPUT_QUIET_MS
|
||||
&& (lastBatteryRefreshAtMs == 0L || now - lastBatteryRefreshAtMs >= ConnectionOptions.BATTERY_REFRESH_INTERVAL_MS)
|
||||
}
|
||||
|
||||
internal fun GlassesSessionCore.createBatteryQueryMessageLocked(): OutboundMessage {
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Check ELF64 LOAD/RELRO alignment in an APK; pair with zipalign -c -P 16 4."""
|
||||
import argparse
|
||||
import struct
|
||||
import zipfile
|
||||
|
||||
PAGE = 16384
|
||||
|
||||
|
||||
def alignment_errors(data):
|
||||
if len(data) < 64 or data[:4] != b"\x7fELF" or data[4] != 2 or data[5] not in (1, 2):
|
||||
return ["expected an ELF64 library"]
|
||||
endian = "<" if data[5] == 1 else ">"
|
||||
offset = struct.unpack_from(endian + "Q", data, 32)[0]
|
||||
size, count = struct.unpack_from(endian + "HH", data, 54)
|
||||
if size < 56 or offset + size * count > len(data):
|
||||
return ["invalid program headers"]
|
||||
headers = [struct.unpack_from(endian + "IIQQQQQQ", data, offset + i * size) for i in range(count)]
|
||||
errors = []
|
||||
loads = [h for h in headers if h[0] == 1]
|
||||
if not loads:
|
||||
errors.append("no LOAD segments")
|
||||
for h in loads:
|
||||
if h[7] < PAGE or h[7] % PAGE or (h[3] - h[2]) % PAGE:
|
||||
errors.append(f"LOAD alignment {h[7]} is incompatible with 16 KiB pages")
|
||||
for h in headers:
|
||||
if h[0] != 0x6474E552:
|
||||
continue
|
||||
end = h[3] + h[6]
|
||||
# A RELRO ending within a writable LOAD may protect unrelated writable
|
||||
# data on a 16 KiB device. A separate LOAD after RELRO is also safe.
|
||||
if end % PAGE and any(p[1] & 2 and p[3] <= h[3] and end < p[3] + p[6] for p in loads):
|
||||
errors.append("RELRO ends inside writable LOAD without 16 KiB alignment")
|
||||
return errors
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("apk")
|
||||
args = parser.parse_args()
|
||||
checked = 0
|
||||
failed = False
|
||||
with zipfile.ZipFile(args.apk) as archive:
|
||||
for name in archive.namelist():
|
||||
if not name.startswith(("lib/arm64-v8a/", "lib/x86_64/")) or not name.endswith(".so"):
|
||||
continue
|
||||
checked += 1
|
||||
errors = alignment_errors(archive.read(name))
|
||||
failed |= bool(errors)
|
||||
print(f"{'FAIL' if errors else 'OK'} {name}" + (": " + "; ".join(errors) if errors else ""))
|
||||
if not checked:
|
||||
parser.error("no 64-bit native libraries found")
|
||||
return int(failed)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
@@ -316,24 +316,6 @@ private class Session {
|
||||
}
|
||||
|
||||
class GlassesSessionCoreTest {
|
||||
@Test fun silentModePollsPromptlyWithoutChangingNormalBatteryCadence() {
|
||||
val s = Session()
|
||||
val core = s.core
|
||||
core.monitor.withLock {
|
||||
core.sessionReady = true
|
||||
core.silentMode = 1
|
||||
core.lastBatteryRefreshAtMs = 8_000L
|
||||
core.lastConnectionOrInputAtMs = 10_000L
|
||||
assertFalse(core.shouldPollBatteryLocked(9_999L))
|
||||
assertTrue(core.shouldPollBatteryLocked(10_000L))
|
||||
core.silentMode = 0
|
||||
assertFalse(core.shouldPollBatteryLocked(10_000L))
|
||||
assertTrue(core.shouldPollBatteryLocked(308_000L))
|
||||
core.shutdownRequested = true
|
||||
assertFalse(core.shouldPollBatteryLocked(608_000L))
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun brightnessConfigPrecedesFirstFrameAndSleepWakeFollowsComposites() {
|
||||
val s = Session()
|
||||
s.core.configureBrightness(false, 70, 2, 100, "0:0,1000:100", 280)
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const vm = require('node:vm');
|
||||
const ts = require('typescript');
|
||||
function fixture() {
|
||||
const source = ts.createSourceFile('controller.ts', fs.readFileSync('app/g2/dashboard-controller.ts', 'utf8'), ts.ScriptTarget.Latest, true);
|
||||
const cls = source.statements.find(n => ts.isClassDeclaration(n) && n.name?.text === 'DashboardController');
|
||||
const methods = cls.members.filter(n => ['handleSilentMode', 'showSilentModeExit', 'setPhase'].includes(n.name?.getText(source)));
|
||||
const alerts = [], timers = new Map(); let next = 0, on = true, wakes = 0;
|
||||
const context = { exports: {}, setTimeout: fn => { timers.set(++next, fn); return next; }, clearTimeout: id => timers.delete(id),
|
||||
updateGlassesPresence() {}, shell: { isScreenOn: () => on, wake: () => { on = true; wakes++; }, showAlert: text => alerts.push(text),
|
||||
foregroundWindow: () => ({ requestRender() {} }), setBatteryLevels() {}, getBatteryLevels: () => ({}) } };
|
||||
vm.runInNewContext(ts.transpileModule(`export class Controller { ${methods.map(n => n.getText(source)).join('\n')} }`, {
|
||||
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
|
||||
}).outputText, context);
|
||||
const c = new context.exports.Controller();
|
||||
Object.assign(c, { silentMode: false, silentModeFeedback: '', silentModeFeedbackTimer: null, silentModeFeedbackGeneration: 0, phase: 'connected', emit() {},
|
||||
cancelEvenHubSuspendTimer() {}, ensureEvenHubSessionActive: async () => true, requestShellRender() {},
|
||||
appendLog() {}, formatError: error => String(error) });
|
||||
return { c, alerts, timers, wakes: () => wakes, dark: () => { on = false; }, expire() { const callbacks = [...timers.values()]; timers.clear(); callbacks.forEach(fn => fn()); } };
|
||||
}
|
||||
test('silent activation remains visible on phone; exit waits for the display wake barrier', async () => {
|
||||
const h = fixture(); h.c.handleSilentMode(false);
|
||||
assert.equal(h.c.silentModeFeedback, '');
|
||||
h.c.handleSilentMode(true);
|
||||
assert.match(h.c.silentModeFeedback, /enabled/); assert.equal(h.timers.size, 0); assert.equal(h.alerts.length, 0);
|
||||
h.c.handleSilentMode(false);
|
||||
assert.equal(h.c.silentModeFeedback, 'Silent mode disabled');
|
||||
await new Promise(setImmediate);
|
||||
assert.deepEqual(h.alerts, ['Silent mode disabled']);
|
||||
h.expire(); assert.equal(h.c.silentModeFeedback, '');
|
||||
});
|
||||
test('repeated state reports do not duplicate feedback; an old timer cannot clear a new activation', async () => {
|
||||
const h = fixture(); h.c.handleSilentMode(true); h.c.handleSilentMode(false);
|
||||
h.c.handleSilentMode(false); await new Promise(setImmediate); assert.equal(h.alerts.length, 1);
|
||||
h.c.handleSilentMode(true); h.expire();
|
||||
assert.match(h.c.silentModeFeedback, /enabled/);
|
||||
});
|
||||
test('silent exit wakes a sleeping display before showing feedback but leaves locked glasses alone', async () => {
|
||||
for (const locked of [false, true]) {
|
||||
const h = fixture(); h.c.glassesLocked = locked; h.dark();
|
||||
h.c.handleSilentMode(true); h.c.handleSilentMode(false); await new Promise(setImmediate);
|
||||
assert.equal(h.wakes(), locked ? 0 : 1);
|
||||
assert.equal(h.alerts.length, locked ? 0 : 1);
|
||||
assert.equal(h.c.silentModeFeedback, 'Silent mode disabled');
|
||||
}
|
||||
});
|
||||
test('an unavailable session, re-entry into silence or disconnect suppresses a stale exit popup', async () => {
|
||||
for (const state of ['not-ready', 'silent', 'disconnected']) {
|
||||
const h = fixture(); let finish;
|
||||
h.c.ensureEvenHubSessionActive = () => new Promise(resolve => { finish = resolve; });
|
||||
h.c.handleSilentMode(true); h.c.handleSilentMode(false);
|
||||
assert.equal(h.alerts.length, 0);
|
||||
if (state === 'silent') h.c.handleSilentMode(true);
|
||||
if (state === 'disconnected') h.c.setPhase('disconnected');
|
||||
finish(state !== 'not-ready'); await new Promise(setImmediate);
|
||||
assert.equal(h.alerts.length, 0);
|
||||
}
|
||||
});
|
||||
|
||||
test('disconnect clears feedback and any pending timer without announcing a silent exit', () => {
|
||||
const h = fixture(); h.c.handleSilentMode(true); h.c.handleSilentMode(false);
|
||||
h.c.setPhase('disconnected');
|
||||
assert.equal(h.c.silentModeFeedback, ''); assert.equal(h.timers.size, 0);
|
||||
h.expire(); assert.equal(h.c.silentModeFeedback, '');
|
||||
});
|
||||
@@ -0,0 +1,40 @@
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
import struct
|
||||
import unittest
|
||||
|
||||
spec = importlib.util.spec_from_file_location("apk_pages", Path(__file__).parents[1] / "scripts/check-apk-pages.py")
|
||||
checker = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(checker)
|
||||
|
||||
|
||||
def elf(alignment=16384, relro_end=16384, writable_end=32768):
|
||||
data = bytearray(64 + 2 * 56)
|
||||
data[:6] = b"\x7fELF\x02\x01"
|
||||
struct.pack_into("<Q", data, 32, 64)
|
||||
struct.pack_into("<HH", data, 54, 56, 2)
|
||||
struct.pack_into("<IIQQQQQQ", data, 64, 1, 6, 0, 0, 0, writable_end, writable_end, alignment)
|
||||
struct.pack_into("<IIQQQQQQ", data, 120, 0x6474E552, 4, 0, 0, 0, relro_end, relro_end, 1)
|
||||
return data
|
||||
|
||||
|
||||
class AlignmentTests(unittest.TestCase):
|
||||
def test_rejects_4k_loads(self):
|
||||
self.assertTrue(checker.alignment_errors(elf(alignment=4096)))
|
||||
|
||||
def test_accepts_16k_loads_and_relro(self):
|
||||
self.assertEqual([], checker.alignment_errors(elf()))
|
||||
|
||||
def test_rejects_relro_protecting_writable_data(self):
|
||||
self.assertTrue(checker.alignment_errors(elf(relro_end=4096)))
|
||||
|
||||
def test_accepts_relro_at_end_of_writable_load(self):
|
||||
self.assertEqual([], checker.alignment_errors(elf(relro_end=4096, writable_end=4096)))
|
||||
|
||||
def test_rejects_invalid_headers(self):
|
||||
self.assertTrue(checker.alignment_errors(b"not ELF"))
|
||||
self.assertTrue(checker.alignment_errors(elf()[:70]))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user