MCPcopy Create free account
hub / github.com/GamerHack/GamerHack.github.io / KernelMemory

Class KernelMemory

g2all/900/lapse.js:1376–1467  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1374 // we corrupt that instead for arbitrary read/write. pipe.pipe_map will be
1375 // clobbered with zeros but that's okay
1376 class KernelMemory {
1377 constructor(main_sd, worker_sd, pipes, pipe_addr) {
1378 this.main_sd = main_sd;
1379 this.worker_sd = worker_sd;
1380 this.rpipe = pipes[0];
1381 this.wpipe = pipes[1];
1382 this.pipe_addr = pipe_addr; // &pipe.pipe_buf
1383 this.pipe_addr2 = pipe_addr.add(0x10); // &pipe.pipe_buf.buffer
1384 this.rw_buf = new Buffer(0x14);
1385 this.addr_buf = new Buffer(0x14);
1386 this.data_buf = new Buffer(0x14);
1387 this.data_buf.write32(0xc, 0x40000000);
1388 }
1389
1390 _verify_len(len) {
1391 if (!(Number.isInteger(len) && (0 <= len <= 0xffffffff))) {
1392 throw TypeError('len not a 32-bit unsigned integer');
1393 }
1394 }
1395
1396 copyin(src, dst, len) {
1397 this._verify_len(len);
1398 const main = this.main_sd;
1399 const worker = this.worker_sd;
1400 const addr_buf = this.addr_buf;
1401 const data_buf = this.data_buf;
1402
1403 addr_buf.write64(0, this.pipe_addr);
1404 ssockopt(main, IPPROTO_IPV6, IPV6_PKTINFO, addr_buf);
1405
1406 data_buf.write64(0, 0);
1407 ssockopt(worker, IPPROTO_IPV6, IPV6_PKTINFO, data_buf);
1408
1409 addr_buf.write64(0, this.pipe_addr2);
1410 ssockopt(main, IPPROTO_IPV6, IPV6_PKTINFO, addr_buf);
1411
1412 addr_buf.write64(0, dst);
1413 ssockopt(worker, IPPROTO_IPV6, IPV6_PKTINFO, addr_buf);
1414
1415 sysi('write', this.wpipe, src, len);
1416 }
1417
1418 copyout(src, dst, len) {
1419 this._verify_len(len);
1420 const main = this.main_sd;
1421 const worker = this.worker_sd;
1422 const addr_buf = this.addr_buf;
1423 const data_buf = this.data_buf;
1424
1425 addr_buf.write64(0, this.pipe_addr);
1426 ssockopt(main, IPPROTO_IPV6, IPV6_PKTINFO, addr_buf);
1427
1428 data_buf.write32(0, 0x40000000);
1429 ssockopt(worker, IPPROTO_IPV6, IPV6_PKTINFO, data_buf);
1430
1431 addr_buf.write64(0, this.pipe_addr2);
1432 ssockopt(main, IPPROTO_IPV6, IPV6_PKTINFO, addr_buf);
1433

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected