Exporting functions from user mode module

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Cpasjuste
Posts: 214
Joined: Sun May 29, 2005 8:28 am

Exporting functions from user mode module

Post by Cpasjuste »

Hi, i'm having a little problem exporting some functions from an user mode module to be used by a kernel mode module. First question is it possible ? I think it should be since we can export kernel functions to be used by an user mode module. When i call one of the exported functions, the psp hang.

I want to do this because i want to use pspgu library in my kernel module, but i would have to change a lot of nids to do this on 3.71 kernel. So here is my main code :

Code: Select all

#include <pspkernel.h>
#include <pspdisplay.h>
#include <pspgu.h>
#include <malloc.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pspgum.h>

#include "main.h"

PSP_MODULE_INFO&#40;"Cfe Export Module", 0, 1, 0&#41;;
PSP_NO_CREATE_MAIN_THREAD&#40;&#41;;

typedef struct
&#123;
	Color color;
	float x, y, z;
&#125; CFE2DVERTEX;

... ... ...
... ... ...
... ... ...
... ... ...

void drawingStart&#40;&#41;
&#123;
	sceGuStart&#40;GU_DIRECT, displayList&#41;;
&#125;

void drawingEnd&#40;&#41;
&#123;
	sceGuFinish&#40;&#41;;
	sceGuSync&#40;0, 0&#41;;
	
	sceDisplayWaitVblankStart&#40;&#41;;
&#125;


int module_start &#40;SceSize argc, void* argp&#41;
&#123;
	return 0;
&#125;

int module_stop &#40;SceSize args, void *argp&#41;
&#123;
	return 0;
&#125;
Here is my exports.exp file :

Code: Select all

# Define the exports for the prx
PSP_BEGIN_EXPORTS

# These four lines are mandatory &#40;although you can add other functions like module_stop&#41;
# syslib is a psynonym for the single mandatory export.
PSP_EXPORT_START&#40;syslib, 0, 0x8000&#41;
PSP_EXPORT_FUNC&#40;module_start&#41;
PSP_EXPORT_VAR&#40;module_info&#41;
PSP_EXPORT_END

PSP_EXPORT_START&#40;cfeDraw, 0, 0x4001&#41;
PSP_EXPORT_FUNC&#40;drawingStart&#41;
PSP_EXPORT_FUNC&#40;drawFont&#41;
PSP_EXPORT_FUNC&#40;drawingEnd&#41;
PSP_EXPORT_END

PSP_END_EXPORTS
And finally my makefile :

Code: Select all

# Target Name
TARGET = cfe_exports

# Source Files
OBJS = font_raw.o main.o exports.o

#EXPORTS = 1

# Use LIBC &#40;Not selected by default?&#41;
USE_PSPSDK_LIBC = 1

# Libraries
LIBS = -lpspgum -lpspgu -lm

# Misc.
INCDIR = 
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti
ASFLAGS = $&#40;CFLAGS&#41;
LDFLAGS =

LIBDIR =

PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/lib/build_prx.mak

Then in my kernel module, i add the exports needed with this code :

Code: Select all

	.set noreorder

#include "pspimport.s"

	IMPORT_START "cfeDraw",0x00090000
	IMPORT_FUNC  "cfeDraw",0x291C6394,drawingStart
	IMPORT_FUNC  "cfeDraw",0xC2F24398,drawFont
	IMPORT_FUNC  "cfeDraw",0xF876BFC8,drawingEnd
I'm new in dealing with exports, so any help would be appreciated !
Thanks in advance,
Cpasjuste.
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

Nope it isn't possible at least to do it automatically, you cannot link user mode libraries into kernel mode modules. Best you are going to be able to do is pass the kernel module a big list of functions it can call, but I probably wouldn't recommend that either :)
Cpasjuste
Posts: 214
Joined: Sun May 29, 2005 8:28 am

Post by Cpasjuste »

Ok so i'v identified the first problem, and can't do a syscall by putting the flag "0x4001" in my exports.
Cpasjuste
Posts: 214
Joined: Sun May 29, 2005 8:28 am

Post by Cpasjuste »

Ho ok. Thanks for the fast reply, this save me some time. I go in another direction :)
Post Reply