Can someone help me with moving a memory address

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
kicknbritt
Citizen
Posts: 96
Joined: Sat May 30, 2015 2:15 am
Location: Chicago, IL/Anchorage,AK

Can someone help me with moving a memory address

Post 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)
"I AM THE ARBITER!!!" *Pulls out Energy sword and kills everything*
User avatar
EngineerSmith
Prole
Posts: 38
Joined: Thu Dec 02, 2021 11:38 am
Contact:

Re: Can someone help me with moving a memory address

Post 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())
User avatar
kicknbritt
Citizen
Posts: 96
Joined: Sat May 30, 2015 2:15 am
Location: Chicago, IL/Anchorage,AK

Re: Can someone help me with moving a memory address

Post by kicknbritt »

Bruh.

How did I miss that

Thanks
"I AM THE ARBITER!!!" *Pulls out Energy sword and kills everything*
Post Reply

Who is online

Users browsing this forum: No registered users and 49 guests