how to add function in kernel32 ?

All development related issues welcome

Moderator: Moderator Team

Post Reply
win3x
Posts: 8
Joined: Thu Aug 23, 2018 9:48 pm

how to add function in kernel32 ?

Post by win3x »

Hello i want to contribute to reactos and add function to kernel32.

i want to fix this error :
the procedure entry point ReleaseSRWLockExclusive could not be located in the dynnamic link library kernel32.dll


maybe for fix this, i need to add function with naive solution i must add this :

Code: Select all

void ReleaseSRWLockExclusive(()
{
   return 0;
}
first step : i download source code et compile reactos, it's work i can generate bootable iso
second steap i search good practive to add this function to kernel32.

i have some questions :
1) where is located kernel32.dll source code ? i think code is here : RosBE\source\dll\win32
but i have 2 kernel32 :
kernel32 and kernel32_vista, which one should I change?
Will the changes I make to kernel32 be taken into account on a program that runs under windows vista/7/10 ? or i must modify kernel32_vista ?

2) how add this function ?
when i open k32.h
i have this :

Code: Select all

#include <ndk/cmfuncs.h>
#include <ndk/exfuncs.h>
#include <ndk/iofuncs.h>
#include <ndk/kdtypes.h>
...etc
i must create file like this :
#include <ndk/mycustomcode.h>
and create c file with this name ?

or directly modify c file in dll/win32/kernel32/client
maybe file :
dll/win32/kernel32/client/vista.c


thanks for advance for your help
ThFabba
Developer
Posts: 293
Joined: Sun Jul 11, 2010 11:39 am

Re: how to add function in kernel32 ?

Post by ThFabba »

First off, ReleaseSRWLockExclusive is actually implemented in ROS. We intentionally don't export it from kernel32 because Windows 2003 does not have this function. Therefore it lives in a ROS-specific dll called kernel32_vista -- this allows our own code to still use it without breaking when run on 2003, but does not allow applications to use it.
The correct fix is to instruct the shim engine to make this function available when Compatibility Mode is set to Vista or higher -- however this stuff is in an early development state, so there's no "best practice" procedure for doing it yet.

To actually answer your questions:
Yes, <source dir>/dll/win32/kernel32 is where the sources for kernel32.dll are found. The CMakeLists.txt file in that directory determines which sources get built into kernel32.dll -- so to add functionality you need to either modify one of them or add a new file (and add it to CMakeLists.txt). Which of the two is appropriate is somewhat subjective -- in this case vista.c would be correct since it's specifically for vista+ functions, otherwise the right place might be a (new) lock.c or srwlock.c file.
In addition, in order to export a new function you need to add it to the kernel32.spec file.
win3x
Posts: 8
Joined: Thu Aug 23, 2018 9:48 pm

Re: how to add function in kernel32 ?

Post by win3x »

ok thanks for your help
but i don't understand, ReleaseSRWLockExclusive is in kernel_vista.dll
when i run program with vista compatibility i have same error why ?
i have message : entry point ReleaseSRWLockExclusive could not be located in kernel32.dll

how to force program to search in kernel32_vista ? i run with windows vista and windows 7 compatibility but i have same error.
hbelusca
Developer
Posts: 1204
Joined: Sat Dec 26, 2009 10:36 pm
Location: Zagreb, Croatia

Re: how to add function in kernel32 ?

Post by hbelusca »

Do **NOT** rely in your program on kernel32_vista.dll !!!!
This is a **TEMPORARY dll FOR INTERNAL REACTOS USAGE ONLY** before we establish and implement the correct way of forward-compatibility with dll redirection.
User avatar
binarymaster
Posts: 481
Joined: Sun Nov 16, 2014 7:05 pm
Location: Russia, Moscow
Contact:

Re: how to add function in kernel32 ?

Post by binarymaster »

hbelusca wrote: Thu Aug 30, 2018 12:28 pm ...before we establish and implement the correct way of forward-compatibility with dll redirection.
Is it possible to add a shim for this function? Or the API call forwarder does not work fully yet?
hbelusca
Developer
Posts: 1204
Joined: Sat Dec 26, 2009 10:36 pm
Location: Zagreb, Croatia

Re: how to add function in kernel32 ?

Post by hbelusca »

You should see with learn_more or thfabba.
sazearte
Posts: 21
Joined: Fri Mar 07, 2014 9:49 pm

Re: how to add function in kernel32 ?

Post by sazearte »

Hello,
kernel32_vista.dll is not used by reactos even if I use vista+ compatibility ?

is there any way to force this dll ?
User avatar
EmuandCo
Developer
Posts: 4730
Joined: Sun Nov 28, 2004 7:52 pm
Location: Germany, Bavaria, Steinfeld
Contact:

Re: how to add function in kernel32 ?

Post by EmuandCo »

It IS used for building our own code relying on some of these functions in there, like some Wine based dlls, but NO 3rd party application uses it. I "fixed" this in the past by passing over these functions from kernel32 to kernel32_vista by modifying the spec file. This was not more than a little test and was a UGLY HACK causing a chimera OS somewhere between NT 5.x and NT6 and causes more problems than it might fix. The only real way is the shim engine in future.
ReactOS is still in alpha stage, meaning it is not feature-complete and is recommended only for evaluation and testing purposes.

If my post/reply offends or insults you, be sure that you know what sarcasm is...
win3x
Posts: 8
Joined: Thu Aug 23, 2018 9:48 pm

Re: how to add function in kernel32 ?

Post by win3x »

Okay, I understand why that doesn't work.

if i want to use this function, i have to wait for reactos to implement this hack or i add it directly in the kernel32 code
Or, can you tell me what to add to the spec file to integrate the kernel32_vista code?
ThFabba
Developer
Posts: 293
Joined: Sun Jul 11, 2010 11:39 am

Re: how to add function in kernel32 ?

Post by ThFabba »

win3x wrote: Sat Sep 01, 2018 8:13 am Okay, I understand why that doesn't work.

if i want to use this function, i have to wait for reactos to implement this hack or i add it directly in the kernel32 code
Or, can you tell me what to add to the spec file to integrate the kernel32_vista code?
You need to change the current stubs into forwarders, e.g.:

Code: Select all

@ stub -version=0x600+ ReleaseSRWLockExclusive
becomes

Code: Select all

@ stdcall ReleaseSRWLockExclusive(ptr) kernel32_vista.ReleaseSRWLockExclusive
The "(ptr)" is the parameter list, "ptr" for pointers/handles, "long" for most other things -- see other functions in the spec file.
Some functions you'll need to forward to ntdll_vista.dll instead. In those cases you'll see that the current spec is already a forward to ntdll.
win3x
Posts: 8
Joined: Thu Aug 23, 2018 9:48 pm

Re: how to add function in kernel32 ?

Post by win3x »

thanks it's work

i have last question, in spec file some function have this :
@ stdcall -stub -version=0x600+ AcquireSRWLockExclusive(ptr) NTDLL.RtlAcquireSRWLockExclusive

what is ntdll ?
how can i replace this for add this function to kernel32 (if this function exist) ?
Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests