Hey.
I’m trying to create a mailslot in my driver, i read theres a special system call for it
‘ZwCreateMailslotFile’, which i can’t find ANYwhere. So I guess it was deleted, so i’m trying to create it via ‘ZwCreateFile’, like this:
I have a mailslot that is created by a userspace process with the name X
Now i’m trying to open the mailslot in my driver with:
Status = IoCreateFile(&Handle, GENERIC_READ | GENERIC_WRITE, &ObjectAttr,
&IoStatus, NULL, FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ | FILE_SHARE_WRITE,
FILE_OPEN, FILE_NON_DIRECTORY_FILE, NULL, 0, CreateFileTypeMailslot, &MailSlotParam, 0);
But i fail with 0xc0000035 or STATUS_OBJECT_NAME_COLLISION
Can’t figure out why… i’m opening it, not creating it… any ideas?
and thanks
I will ask the standard question, why do you want to do this? Mailslots are
not a great communication mechanism in general, and not normally used for
communications.
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Thursday, May 18, 2017 10:31 AM
To: Windows System Software Devs Interest List Subject: RE:[ntdev] Creating a Mailslot in a driver
I have a mailslot that is created by a userspace process with the name X
Now i’m trying to open the mailslot in my driver with: Status = IoCreateFile(&Handle, GENERIC_READ | GENERIC_WRITE, &ObjectAttr, &IoStatus, NULL, FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_OPEN, FILE_NON_DIRECTORY_FILE, NULL, 0, CreateFileTypeMailslot, &MailSlotParam, 0);
But i fail with 0xc0000035 or STATUS_OBJECT_NAME_COLLISION
Can’t figure out why… i’m opening it, not creating it… any ideas? and thanks
You can use ZwCreateFile but you have to set the OBJ_OPENIF attributes to avoid STATUS_OBJECT_NAME_COLLISION when the file already exists. You should also set the OBJ_CASE_INSENSITIVE attribute.
Now \ ??\MailSlot is a symlink to \Device\MailSlot. So \ ??\MailSlot\Main is a FILE_OBJECT that belongs to the \Device\MailSlot device object’s namespace.
You could provide your own implementation for instance by creating your own control device \Device\MyDriverMailSlot. Your driver would then provide the Read/Write file dispatch routines.
Also, you should remove references to the TCHAR type which is used in user mode. Use the WCHAR type with UNICODE strings and the CHAR type with ANSI strings.
Not applicable to mailslots, they are a special beast. To create a mailslot you need to issue IRP_MJ_CREATE_MAILSLOT(0x13). To open an existing mailslot you need IRP_MJ_CREATE(0x0).
The object manager substitutes \GLOBAL?? instead of ?? when looking for an object by name. So it is not a problem here as \GLOBAL??\mailslot is a symbolic link to \Device\mailslot
You can do this as RtlInitUnicodeString( &MailslotName, L"\??\mailslot\main" ) without counting by your fingers.</file:>
Pass the handle down in an IOCTL. Depending on when your driver loads, and
how it loads, it is a high probability that \BaseNamedObjects has not been
created yet.
On Thu, May 18, 2017 at 11:14 AM Don Burn wrote:
> I will ask the standard question, why do you want to do this? Mailslots > are > not a great communication mechanism in general, and not normally used for > communications. > > > Don Burn > Windows Driver Consulting > Website: http://www.windrvr.com > > > > -----Original Message----- > From: xxxxx@lists.osr.com > [mailto:xxxxx@lists.osr.com] On Behalf Of > xxxxx@gmail.com > Sent: Thursday, May 18, 2017 10:31 AM > To: Windows System Software Devs Interest List > Subject: RE:[ntdev] Creating a Mailslot in a driver > > I have a mailslot that is created by a userspace process with the name X > > Now i’m trying to open the mailslot in my driver with: > Status = IoCreateFile(&Handle, GENERIC_READ | GENERIC_WRITE, > &ObjectAttr, > &IoStatus, NULL, FILE_ATTRIBUTE_NORMAL, > FILE_SHARE_READ | FILE_SHARE_WRITE, > FILE_OPEN, FILE_NON_DIRECTORY_FILE, NULL, 0, > CreateFileTypeMailslot, &MailSlotParam, 0); > > > But i fail with 0xc0000035 or STATUS_OBJECT_NAME_COLLISION > > Can’t figure out why… i’m opening it, not creating it… any ideas? > and thanks > > — > NTDEV is sponsored by OSR > > Visit the list online at: > http: > > MONTHLY seminars on crash dump analysis, WDF, Windows internals and > software > drivers! > Details at http: > > To unsubscribe, visit the List Server section of OSR Online at > http: > > > — > NTDEV is sponsored by OSR > > Visit the list online at: < > http://www.osronline.com/showlists.cfm?list=ntdev> > > MONTHLY seminars on crash dump analysis, WDF, Windows internals and > software drivers! > Details at http: > > To unsubscribe, visit the List Server section of OSR Online at < > http://www.osronline.com/page.cfm?name=ListServer> ></http:></http:></http:></http:>
Thanks cap.
Nevertheless you still need IRP_MJ_CREATE_MAILSLOT to create a mailsot.
IoCreateFile issues IRP_MJ_CREATE_MAILSLOT when called with the documented CreateFileTypeMailslot.