interplane.Get Omega
Read in your language

hop

Hop: a small native macOS launcher. Clipboard history, find, on-device dictation and your coding agent behind one key.

Brought by drakestapleton

branch main Branches Tags History

hop / Linux / core.om

197 lines · 3223 bytes Raw Blame History
1note Linux adapter for Hop's unchanged Omega matching helper.
2note Requests use the existing Omega/README.md kind1 protocol, not a second matcher.
3note An anonymous local socket carries stdio so send uses MSG_NOSIGNAL if the helper dies.
4text hp_link "/proc/self/exe"
5text hp_tail "/hopcore"
6text hp_fail "Hop could not use its search helper. Rebuild Hop before launching it.\n"
7global hp_fd int 3
8
9fn hp_le a view uchar * p ulong n ulong to ulong
10v = ulong 0
11for i ulong n
12v = or v shl ulong get a add p i mul i 8
13end
14ret v
15end
16
17fn hp_put a edit uchar * p ulong v ulong n ulong to void
18for i ulong n
19put a add p i uchar and shr v mul i 8 255
20end
21end
22
23fn hp_bad to void
24k = write 2 hp_fail 0 len hp_fail
25end
26
27fn hp_start to int
28hp_path = new uchar 4096 0
29hp_exec = new uchar 4104 0
30hp_addr = new uchar 19 0
31put hp_fd 0 -1
32put hp_fd 1 -1
33put hp_fd 2 -1
34n = readlnk hp_link 0 len hp_link hp_path 0 len hp_path
35if le n 0
36hp_bad
37ret 1
38end
39if eq n long len hp_path
40hp_bad
41ret 1
42end
43p = ulong n
44while gt p 0 bound 4096
45if eq get hp_path sub p 1 47
46break
47end
48p = sub p 1
49end
50if or eq p 0 gt add p len hp_tail len hp_path
51hp_bad
52ret 1
53end
54p = sub p 1
55for i ulong len hp_tail
56put hp_path add p i get hp_tail i
57end
58p = add p len hp_tail
59hp_put hp_exec 0 1 2
60hp_put hp_exec 2 p 2
61for i ulong p
62put hp_exec add i 4 get hp_path i
63end
64server = socknew 1 1 0
65if lt server 0
66hp_bad
67ret 1
68end
69put hp_addr 0 1
70k = random hp_addr 3 16 0
71if ne k 16
72k = fclose int server
73hp_bad
74ret 1
75end
76k = bind int server hp_addr 0 len hp_addr
77if ne k 0
78k = fclose int server
79hp_bad
80ret 1
81end
82k = listen int server 1
83if ne k 0
84k = fclose int server
85hp_bad
86ret 1
87end
88pid = fork
89if eq pid 0
90sock = socknew 1 1 0
91if lt sock 0
92exit 126
93end
94k = connect int sock hp_addr 0 len hp_addr
95if ne k 0
96exit 126
97end
98k = dupfd int sock 0 0
99if lt k 0
100exit 126
101end
102k = dupfd int sock 1 0
103if lt k 0
104exit 126
105end
106k = execprog hp_exec 0 add p 4
107exit 127
108end
109if lt pid 0
110k = fclose int server
111hp_bad
112ret 1
113end
114put hp_fd 2 int pid
115ready = waitio int server 1 2000000000
116if le ready 0
117k = fclose int server
118hp_stop
119hp_bad
120ret 1
121end
122sock = accept int server 0
123k = fclose int server
124if lt sock 0
125hp_stop
126hp_bad
127ret 1
128end
129put hp_fd 0 int sock
130put hp_fd 1 int sock
131ret 0
132end
133
134fn hp_fuzz inp view ulong 256 to ulong
135hp_req = new uchar 2056 0
136hp_rep = new uchar 11 0
137if lt get hp_fd 0 0
138ret 0
139end
140hp_put hp_req 0 1 4
141hp_put hp_req 4 2048 4
142for i ulong 256
143hp_put hp_req add 8 mul i 8 get inp i 8
144end
145p = ulong 0
146while lt p len hp_req bound 2056
147k = send get hp_fd 0 hp_req p sub len hp_req p 0
148if le k 0
149hp_bad
150ret 0
151end
152p = add p ulong k
153end
154p = ulong 0
155while lt p 11 bound 11
156ready = waitio get hp_fd 1 1 2000000000
157if le ready 0
158hp_bad
159ret 0
160end
161k = read get hp_fd 1 hp_rep p sub 11 p
162if le k 0
163hp_bad
164ret 0
165end
166p = add p ulong k
167end
168if ne hp_le hp_rep 0 4 0
169hp_bad
170ret 0
171end
172if ne hp_le hp_rep 4 4 3
173hp_bad
174ret 0
175end
176if ne get hp_rep 8 1
177ret 0
178end
179ret hp_le hp_rep 9 2
180end
181
182fn hp_stop to void
183hp_state = new uchar 4 0
184if ge get hp_fd 0 0
185k = fclose get hp_fd 0
186end
187if and ge get hp_fd 1 0 ne get hp_fd 1 get hp_fd 0
188k = fclose get hp_fd 1
189end
190put hp_fd 0 -1
191put hp_fd 1 -1
192if gt get hp_fd 2 0
193k = killpid get hp_fd 2 15
194k = waitpid get hp_fd 2 hp_state 0 4 0
195put hp_fd 2 -1
196end
197end