Exporting functions from user mode prx to kernel mode prx
-
- Posts: 409
- Joined: Tue Oct 09, 2007 4:22 am
Exporting functions from user mode prx to kernel mode prx
Is it possible or not? I have tried multiple ways and I can't seem to get it working :/
I really need to export a function from user mode as the kernel LIBC is not the same as the user LIBC and some of the functions I Need are not included in the kernel LIBC.
I have two options, create my own functions or export the function from user mode.
I really need to export a function from user mode as the kernel LIBC is not the same as the user LIBC and some of the functions I Need are not included in the kernel LIBC.
I have two options, create my own functions or export the function from user mode.
I know that 0x0001 attrib is for export a function from kernel to kernel or user to user, and 0x4001 for export kernel to user!
I've never tried to export a function from a user to a kernel prx module...
Have you tried with these flags?
I've never tried to export a function from a user to a kernel prx module...
Have you tried with these flags?
Get Xplora!
-
- Posts: 409
- Joined: Tue Oct 09, 2007 4:22 am
Thats only useful if he wants to use functions exported by a PRX which he made. It looks like he wants to call other sce user mode functions from the firmware PRX, from inside a kernel PRX.phobox wrote:in the exports file.
PSP_EXPORT_START(libName, 0, 0x4001)
the 3rd param is where to put your flags
I think the only way will be to use setddrmemoryprotection function to make the kernel memory as user mode, and then call your user mode function by getting the function address or something. You can't use any kernel function in that time. I'm just guessing, I'm no expert at this.
Generally it only causes various problems. User mode function should be called from user mode prx only, thats it.
-
- Posts: 409
- Joined: Tue Oct 09, 2007 4:22 am
I guess you could do it like this:
Code the original function in a kernel PRX as kernel to kernel export. Then make a wrapper function for it in the same PRX as a kernel to user export.
Then you can call the kernel version from other kernel PRXs, as well as the user wrapper from other user PRXs.
Its impossible to directly call a kernel function from a user prx, so I assume the reverse is true as well. When you have a kernel to user export, it uses syscalls. I don't know if user to kernel export is possible like the way you want..
Code the original function in a kernel PRX as kernel to kernel export. Then make a wrapper function for it in the same PRX as a kernel to user export.
Then you can call the kernel version from other kernel PRXs, as well as the user wrapper from other user PRXs.
Its impossible to directly call a kernel function from a user prx, so I assume the reverse is true as well. When you have a kernel to user export, it uses syscalls. I don't know if user to kernel export is possible like the way you want..
not exactely..Pirata Nervo wrote: so 0x0001 is kernel > kernel and 0x4001 is kernel -> user, then 0x4000 should be user -> user ?
i think everybody should have read http://ps2dev.org/psp/Tutorials/PSP_Mod ... s.download
Ciao! from Italy
-
- Posts: 409
- Joined: Tue Oct 09, 2007 4:22 am
I think you haven't read my first pos torch.
kernel LIBC does not have fopen, fwrite, fclose, fprintf, etc and I need them for my function as the library I am using makes of those functions.
The only way to use that function is exporting from a user prx to a kernel prx (which needs kernel mode to work).
Of course I can the user prx to execute the function when it gets loaded but that's not what I want.
@phobox I already read that file some time ago :) but of course I don't remember everything
kernel LIBC does not have fopen, fwrite, fclose, fprintf, etc and I need them for my function as the library I am using makes of those functions.
The only way to use that function is exporting from a user prx to a kernel prx (which needs kernel mode to work).
Of course I can the user prx to execute the function when it gets loaded but that's not what I want.
@phobox I already read that file some time ago :) but of course I don't remember everything
Does it compiles with USE_KERNEL_LIBC=0 ? That might provide the functions you need.
Are you writing a plugin or an EBOOT?
You only need to worry about user modules if you are writing a plugin.
If you are writing an EBOOT, the correct way IS to have the function executed from a user module. All your main working code should be user mode. You only need to load a kernel prx to do, well, kernel stuff.
If you are writing a plugin however, then you have no choice but to use various tricks to get user mode code working.
Have the user module continuously 'poll' the kernel prx for various commands. I mean export a function get_commands() from your kernel prx. The user prx should keep calling this function to see if the kernel prx needs something done.
Are you writing a plugin or an EBOOT?
You only need to worry about user modules if you are writing a plugin.
If you are writing an EBOOT, the correct way IS to have the function executed from a user module. All your main working code should be user mode. You only need to load a kernel prx to do, well, kernel stuff.
If you are writing a plugin however, then you have no choice but to use various tricks to get user mode code working.
Have the user module continuously 'poll' the kernel prx for various commands. I mean export a function get_commands() from your kernel prx. The user prx should keep calling this function to see if the kernel prx needs something done.
-
- Posts: 409
- Joined: Tue Oct 09, 2007 4:22 am
I am writing a prx of course, otherwise I would not need to export a user function from a user prx and I could do it a from a EBOOT.PBP (as it must be user mode to be executed).
graphics.prx is the user prx.
patchexit_driver.prx is the kernel prx.
patchexit_driver.prx works perfectly since NervOS 2.1 (it's a shell) but now for 2.3 I am working on some new features and I need patchexit_driver.prx to call a user mode function.
patchexit_driver.prx only works with KERNEL_LIBC and KERNEL_LIBS set to 1.
This means I cannot use the stdio.h functions. I have already created the stdio.c and stdio.h and malloc.c and malloc.h with the necessary functions but I still need time() and I couldn't find time.c anywhere so I gave up and deleted my new code.
I am trying graphics.prx in kernel mode with user LIBC but with kernel LIBS and the only error I am getting is:
I've tried adding -lpspsysmem_user/kernel to my LIBS and using the .a and .h that comes with the m33 sdk but didn't work.
Edit:
adding -lc as the first library worked. :) time to test the prx
graphics.prx is the user prx.
patchexit_driver.prx is the kernel prx.
patchexit_driver.prx works perfectly since NervOS 2.1 (it's a shell) but now for 2.3 I am working on some new features and I need patchexit_driver.prx to call a user mode function.
patchexit_driver.prx only works with KERNEL_LIBC and KERNEL_LIBS set to 1.
This means I cannot use the stdio.h functions. I have already created the stdio.c and stdio.h and malloc.c and malloc.h with the necessary functions but I still need time() and I couldn't find time.c anywhere so I gave up and deleted my new code.
I am trying graphics.prx in kernel mode with user LIBC but with kernel LIBS and the only error I am getting is:
Code: Select all
/usr/local/pspdev/lib/gcc/psp/4.3.1/../../../../psp/lib/libc.a(_sbrk.o): In function `_sbrk':
../../../../../../newlib/libc/sys/psp/libcglue.c:549: undefined reference to `sceKernelMaxFreeMemSize'
collect2: ld returned 1 exit status
make: *** [graphics.elf] Error 1
Edit:
adding -lc as the first library worked. :) time to test the prx
-
- Posts: 409
- Joined: Tue Oct 09, 2007 4:22 am
-
- Posts: 409
- Joined: Tue Oct 09, 2007 4:22 am
I am not using user mode anymore. I just managed to get graphics.prx (in kernel mode) using standard I/O functions and exporting functions at the same time.
Here's my makefile:
I am going to do some debug now to see where it is crashing in my code. It may be crashing due to STD I/O functions
Here's my makefile:
Code: Select all
TARGET = graphics
OBJS = main.o exports.o
PSPLIBSDIR = $(PSPSDK)/..
USE_KERNEL_LIBS=1
INCDIR = ../../../sdk/include
CFLAGS = -Os -G0 -Wall -g
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
#LDFLAGS += -mno-crt0 -nostartfiles
BUILD_PRX = 1
PRX_EXPORTS = exports.exp
#USE_KERNEL_LIBC = 1
#USE_USER_LIBC = 1
PSP_FW_VERSION = 500
LIBDIR = ../../../sdk/lib
LIBS = -lc -ljpeg -lpspkernel -lz -lm -lpsploadexec_kernel -lpspsystemctrl_kernel -lpspmodulemgr_kernel -lpspumd -lpspkubridge
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build_prx.mak
I don't know if it works in latest firmwares but I remember long ago it worked using flags 0x0001, which causes functions to resolve as jumps. But that is very propense to cause inestability and finally crash, as the user functions are being executed in kernel mode and they are programmed as user functions.
I remember I did the first version of nethostfs like that, it was a kernel prx that called user functions (net ones), and that's probably the reason why it was so unstable. Later Ahman improved it and I think he used user mode.
Anyways, I don't know if since then Sony has made more checks to make this not possible.
I remember I did the first version of nethostfs like that, it was a kernel prx that called user functions (net ones), and that's probably the reason why it was so unstable. Later Ahman improved it and I think he used user mode.
Anyways, I don't know if since then Sony has made more checks to make this not possible.
-
- Posts: 409
- Joined: Tue Oct 09, 2007 4:22 am
-
- Posts: 328
- Joined: Sun Jun 03, 2007 10:05 pm
-
- Posts: 409
- Joined: Tue Oct 09, 2007 4:22 am
what the fu*k are you talking about?KickinAezz wrote:LOL!
pspiofilemgr_kernel.h.
LIBS = -lpspiofilemgr_kernel (not required since it's already in BUILD.MAK)
I guess you did not read all posts otherwise you would have not said what you said.
THE STANDARD I/O FUNCTIONS ARE CRASHING. (this means it's stdio.c/h)
They use sceIo functions yes but they got a #ifdef before which makes the functions not being able to be used when LIBC or LIBC (i dont know) are set for kernel. So now I removed the necessary #ifdef #endif from the custom stdio.c and stdio.h I have here and it works.
I hope you can read it better now.
-
- Posts: 409
- Joined: Tue Oct 09, 2007 4:22 am
I thought he meant "clean" as makefile without unneeded things lol.
not the clean "section"
"make clean" is a linux command Torch. Sorry for misunderstanding
Edit:
you can also use this:
this will clean all .o files in the specified path everytime you hit make.
rm means remove and the option -f means force. myfile.prx is your prx file.
not the clean "section"
"make clean" is a linux command Torch. Sorry for misunderstanding
Edit:
you can also use this:
Code: Select all
all: myfile.prx
rm -f /home/username/project/*.o
rm means remove and the option -f means force. myfile.prx is your prx file.
-
- Posts: 409
- Joined: Tue Oct 09, 2007 4:22 am