Page 1 of 1

Can someone help me with moving a memory address

Posted: Fri Jan 28, 2022 10:46 pm
by kicknbritt
I am trying to smuggle a memory address into a lua thread, but I can't figure out how to.
I thought maybe I could use love.data but things aren't panning out.
I just want to be able to access the same memory I use in the main thread in a seperate thread.

Code: Select all

local ffi = require("ffi")
ffi.cdef(" typedef long map[1000000]; void* malloc(size_t); void free(void*);")


local Memory = love.data.newByteData(ffi.sizeof("map"))

local map = ffi.cast("map(&)", Memory:getFFIPointer())

map[7] = 44

local threadCode = [[
-- Receive values sent via thread:start
local bytedata = ...

local ffi = require("ffi")
ffi.cdef(" typedef long map[10000000]; void* malloc(size_t); void free(void*);")

local map = ffi.cast("map(&)", bytedata)
print("THREAD", map[7]) -- Should equal 44
]]

thread = love.thread.newThread(threadCode)
thread:start(Memory, 0)

Re: Can someone help me with moving a memory address

Posted: Fri Jan 28, 2022 11:16 pm
by EngineerSmith
kicknbritt wrote: Fri Jan 28, 2022 10:46 pm

Code: Select all

local threadCode = [[
-- Receive values sent via thread:start
local bytedata = ...

local ffi = require("ffi")
ffi.cdef(" typedef long map[10000000]; void* malloc(size_t); void free(void*);")

local map = ffi.cast("map(&)", bytedata)
print("THREAD", map[7]) -- Should equal 44
]]
The issue is with your thread code, you don't grab the FFI Pointer of the byteData in order to correctly cast it

Code: Select all

local map = ffi.cast("map(&)", bytedata:getFFIPointer())

Re: Can someone help me with moving a memory address

Posted: Sat Jan 29, 2022 12:09 am
by kicknbritt
Bruh.

How did I miss that

Thanks