Skip to content

Commit 35ec5e1

Browse files
add dummy file struct to shmem_file
Needed for i915_gem_dmabuf_mmap
1 parent 706cd59 commit 35ec5e1

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

sys/compat/linuxkpi/common/include/linux/file.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ extern void linux_file_free(struct linux_file *filp);
6464
static inline void
6565
fput(struct linux_file *filp)
6666
{
67-
if (filp->_file == NULL || refcount_release(&filp->_file->f_count))
67+
if ( refcount_release(&filp->_file->f_count))
6868
linux_file_free(filp);
6969
}
7070

sys/compat/linuxkpi/common/src/linux_fs.c

+20-2
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,24 @@ free_anon_mapping(struct address_space *as)
273273
vm_object_deallocate(as);
274274
}
275275

276+
static int shm_file_mmap(struct linux_file *filp, struct vm_area_struct *vma)
277+
{
278+
vma->vm_file = get_file(filp);
279+
return 0;
280+
}
281+
282+
283+
struct file_operations linux_shm_fops = {
284+
.mmap = shm_file_mmap
285+
};
286+
276287
struct linux_file *
277288
shmem_file_setup(char *name, loff_t size, unsigned long flags)
278289
{
279290
struct fileobj {
280291
struct linux_file file __aligned(sizeof(void *));
281292
struct vnode vnode __aligned(sizeof(void *));
293+
__typeof( *((struct file*)0)->_file) pseudo_file __aligned(sizeof(void *));
282294
};
283295
struct fileobj *fileobj;
284296
struct linux_file *filp;
@@ -291,14 +303,20 @@ shmem_file_setup(char *name, loff_t size, unsigned long flags)
291303
goto err_0;
292304
}
293305
filp = &fileobj->file;
306+
filp->_file = &fileobj->pseudo_file;
294307
vp = &fileobj->vnode;
308+
refcount_init(&filp->_file->f_count, 1);
309+
310+
295311

296312
filp->f_dentry = &filp->f_dentry_store;
297313
filp->f_vnode = vp;
298314
filp->f_mapping = file_inode(filp)->i_mapping =
299315
vm_pager_allocate(OBJT_DEFAULT, NULL, size,
300316
VM_PROT_READ | VM_PROT_WRITE, 0, curthread->td_ucred);
301-
317+
318+
filp->f_op = &linux_shm_fops;
319+
302320
if (file_inode(filp)->i_mapping == NULL) {
303321
error = -ENOMEM;
304322
goto err_1;
@@ -442,7 +460,7 @@ void
442460
linux_file_free(struct linux_file *filp)
443461
{
444462

445-
if (filp->_file == NULL) {
463+
if (filp->f_op == &linux_shm_fops) {
446464
struct vnode *vp = filp->f_vnode;
447465
if (vp != NULL && vp->i_mapping != NULL)
448466
vm_object_deallocate(vp->i_mapping);

0 commit comments

Comments
 (0)