mirror of
https://github.com/reactos/reactos.git
synced 2025-04-20 20:36:35 +00:00
Changed beep to compile as sys driver.
svn path=/trunk/; revision=350
This commit is contained in:
parent
aa77254872
commit
9e3fe0593a
2 changed files with 181 additions and 157 deletions
|
@ -21,30 +21,32 @@
|
||||||
|
|
||||||
typedef struct _BEEP_DEVICE_EXTENSION
|
typedef struct _BEEP_DEVICE_EXTENSION
|
||||||
{
|
{
|
||||||
KDPC Dpc;
|
KDPC Dpc;
|
||||||
KTIMER Timer;
|
KTIMER Timer;
|
||||||
KEVENT Event;
|
KEVENT Event;
|
||||||
LONG BeepOn;
|
// LONG BeepOn;
|
||||||
|
BOOL BeepOn;
|
||||||
} DEVICE_EXTENSION, *PDEVICE_EXTENSION;
|
} DEVICE_EXTENSION, *PDEVICE_EXTENSION;
|
||||||
|
|
||||||
|
|
||||||
/* FUNCTIONS ***************************************************************/
|
/* FUNCTIONS ***************************************************************/
|
||||||
|
|
||||||
|
|
||||||
VOID BeepDPC(PKDPC Dpc, PVOID DeferredContext, PVOID SystemArgument1, PVOID SystemArgument2)
|
VOID BeepDPC (PKDPC Dpc, PVOID DeferredContext, PVOID SystemArgument1, PVOID SystemArgument2)
|
||||||
{
|
{
|
||||||
PDEVICE_EXTENSION pDeviceExtension = DeferredContext;
|
PDEVICE_EXTENSION DeviceExtension = DeferredContext;
|
||||||
|
|
||||||
DPRINT("BeepDPC() called!\n");
|
DPRINT ("BeepDPC() called!\n");
|
||||||
HalMakeBeep (0);
|
HalMakeBeep (0);
|
||||||
InterlockedExchange (&(pDeviceExtension->BeepOn), 0);
|
// InterlockedExchange (&(DeviceExtension->BeepOn), FALSE);
|
||||||
KeSetEvent (&(pDeviceExtension->Event), 0, TRUE);
|
DeviceExtension->BeepOn = FALSE;
|
||||||
|
KeSetEvent (&(DeviceExtension->Event), 0, TRUE);
|
||||||
|
|
||||||
DPRINT("BeepDPC() finished!\n");
|
DPRINT ("BeepDPC() finished!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NTSTATUS BeepCreate(PDEVICE_OBJECT DeviceObject, PIRP Irp)
|
NTSTATUS BeepCreate (PDEVICE_OBJECT DeviceObject, PIRP Irp)
|
||||||
/*
|
/*
|
||||||
* FUNCTION: Handles user mode requests
|
* FUNCTION: Handles user mode requests
|
||||||
* ARGUMENTS:
|
* ARGUMENTS:
|
||||||
|
@ -53,21 +55,21 @@ NTSTATUS BeepCreate(PDEVICE_OBJECT DeviceObject, PIRP Irp)
|
||||||
* RETURNS: Success or failure
|
* RETURNS: Success or failure
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
|
PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
|
||||||
NTSTATUS status;
|
NTSTATUS status;
|
||||||
|
|
||||||
if (Stack->MajorFunction == IRP_MJ_CREATE)
|
if (Stack->MajorFunction == IRP_MJ_CREATE)
|
||||||
{
|
{
|
||||||
DPRINT ("BeepCreate() called!\n");
|
DPRINT ("BeepCreate() called!\n");
|
||||||
Irp->IoStatus.Information = 0;
|
Irp->IoStatus.Information = 0;
|
||||||
status = STATUS_SUCCESS;
|
status = STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
status = STATUS_NOT_IMPLEMENTED;
|
status = STATUS_NOT_IMPLEMENTED;
|
||||||
|
|
||||||
Irp->IoStatus.Status = status;
|
Irp->IoStatus.Status = status;
|
||||||
IoCompleteRequest(Irp,IO_NO_INCREMENT);
|
IoCompleteRequest (Irp,IO_NO_INCREMENT);
|
||||||
return(status);
|
return (status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -80,24 +82,24 @@ NTSTATUS BeepClose(PDEVICE_OBJECT DeviceObject, PIRP Irp)
|
||||||
* RETURNS: Success or failure
|
* RETURNS: Success or failure
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
|
PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation (Irp);
|
||||||
NTSTATUS status;
|
NTSTATUS status;
|
||||||
|
|
||||||
switch (Stack->MajorFunction)
|
switch (Stack->MajorFunction)
|
||||||
{
|
{
|
||||||
case IRP_MJ_CLOSE:
|
case IRP_MJ_CLOSE:
|
||||||
DPRINT ("BeepClose() called!\n");
|
DPRINT ("BeepClose() called!\n");
|
||||||
Irp->IoStatus.Information = 0;
|
Irp->IoStatus.Information = 0;
|
||||||
status = STATUS_SUCCESS;
|
status = STATUS_SUCCESS;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
status = STATUS_NOT_IMPLEMENTED;
|
status = STATUS_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
Irp->IoStatus.Status = status;
|
Irp->IoStatus.Status = status;
|
||||||
IoCompleteRequest(Irp,IO_NO_INCREMENT);
|
IoCompleteRequest (Irp, IO_NO_INCREMENT);
|
||||||
return(status);
|
return (status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -110,25 +112,25 @@ NTSTATUS BeepCleanup(PDEVICE_OBJECT DeviceObject, PIRP Irp)
|
||||||
* RETURNS: Success or failure
|
* RETURNS: Success or failure
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
|
PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation (Irp);
|
||||||
NTSTATUS status;
|
NTSTATUS status;
|
||||||
|
|
||||||
if (Stack->MajorFunction == IRP_MJ_CLEANUP)
|
if (Stack->MajorFunction == IRP_MJ_CLEANUP)
|
||||||
{
|
{
|
||||||
DPRINT ("BeepCleanup() called!\n");
|
DPRINT ("BeepCleanup() called!\n");
|
||||||
Irp->IoStatus.Information = 0;
|
Irp->IoStatus.Information = 0;
|
||||||
status = STATUS_SUCCESS;
|
status = STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
status = STATUS_NOT_IMPLEMENTED;
|
status = STATUS_NOT_IMPLEMENTED;
|
||||||
|
|
||||||
Irp->IoStatus.Status = status;
|
Irp->IoStatus.Status = status;
|
||||||
IoCompleteRequest(Irp,IO_NO_INCREMENT);
|
IoCompleteRequest (Irp, IO_NO_INCREMENT);
|
||||||
return(status);
|
return (status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NTSTATUS BeepDeviceControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
|
NTSTATUS BeepDeviceControl (PDEVICE_OBJECT DeviceObject, PIRP Irp)
|
||||||
/*
|
/*
|
||||||
* FUNCTION: Handles user mode requests
|
* FUNCTION: Handles user mode requests
|
||||||
* ARGUMENTS:
|
* ARGUMENTS:
|
||||||
|
@ -137,134 +139,134 @@ NTSTATUS BeepDeviceControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
|
||||||
* RETURNS: Success or failure
|
* RETURNS: Success or failure
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
|
PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
|
||||||
PDEVICE_EXTENSION pDeviceExtension;
|
PDEVICE_EXTENSION DeviceExtension;
|
||||||
PBEEP_SET_PARAMETERS pbsp;
|
PBEEP_SET_PARAMETERS pbsp;
|
||||||
NTSTATUS status;
|
NTSTATUS status;
|
||||||
|
|
||||||
pDeviceExtension = DeviceObject->DeviceExtension;
|
DeviceExtension = DeviceObject->DeviceExtension;
|
||||||
|
|
||||||
if (Stack->MajorFunction == IRP_MJ_DEVICE_CONTROL)
|
DPRINT ("BeepDeviceControl() called!\n");
|
||||||
{
|
if (Stack->Parameters.DeviceIoControl.IoControlCode == IOCTL_BEEP_SET)
|
||||||
DPRINT("BeepDeviceControl() called!\n");
|
{
|
||||||
if (Stack->Parameters.DeviceIoControl.IoControlCode == IOCTL_BEEP_SET)
|
Irp->IoStatus.Information = 0;
|
||||||
{
|
if (Stack->Parameters.DeviceIoControl.InputBufferLength == sizeof(BEEP_SET_PARAMETERS))
|
||||||
Irp->IoStatus.Information = 0;
|
{
|
||||||
if (Stack->Parameters.DeviceIoControl.InputBufferLength == sizeof(BEEP_SET_PARAMETERS))
|
pbsp = (PBEEP_SET_PARAMETERS)Irp->AssociatedIrp.SystemBuffer;
|
||||||
{
|
|
||||||
pbsp = (PBEEP_SET_PARAMETERS)Irp->AssociatedIrp.SystemBuffer;
|
|
||||||
|
|
||||||
if (pbsp->Frequency >= BEEP_FREQUENCY_MINIMUM &&
|
if (pbsp->Frequency >= BEEP_FREQUENCY_MINIMUM &&
|
||||||
pbsp->Frequency <= BEEP_FREQUENCY_MAXIMUM)
|
pbsp->Frequency <= BEEP_FREQUENCY_MAXIMUM)
|
||||||
{
|
{
|
||||||
LARGE_INTEGER DueTime = 0;
|
LARGE_INTEGER DueTime = 0;
|
||||||
|
|
||||||
/* do the beep!! */
|
/* do the beep!! */
|
||||||
DPRINT("Beep:\n Freq: %lu Hz\n Dur: %lu ms\n",
|
DPRINT ("Beep:\n Freq: %lu Hz\n Dur: %lu ms\n",
|
||||||
pbsp->Frequency, pbsp->Duration);
|
pbsp->Frequency, pbsp->Duration);
|
||||||
|
|
||||||
if (pbsp->Duration >= 0)
|
if (pbsp->Duration >= 0)
|
||||||
{
|
{
|
||||||
DueTime = (LARGE_INTEGER)pbsp->Duration * 10000;
|
DueTime = (LARGE_INTEGER)pbsp->Duration * 10000;
|
||||||
|
|
||||||
KeSetTimer (&pDeviceExtension->Timer,
|
KeSetTimer (&DeviceExtension->Timer,
|
||||||
-DueTime,
|
-DueTime,
|
||||||
&pDeviceExtension->Dpc);
|
&DeviceExtension->Dpc);
|
||||||
|
|
||||||
HalMakeBeep (pbsp->Frequency);
|
HalMakeBeep (pbsp->Frequency);
|
||||||
InterlockedExchange(&(pDeviceExtension->BeepOn), TRUE);
|
// InterlockedExchange (&(DeviceExtension->BeepOn), TRUE);
|
||||||
KeWaitForSingleObject (&(pDeviceExtension->Event),
|
DeviceExtension->BeepOn = TRUE;
|
||||||
Executive,
|
KeWaitForSingleObject (&(DeviceExtension->Event),
|
||||||
KernelMode,
|
Executive,
|
||||||
FALSE,
|
KernelMode,
|
||||||
NULL);
|
FALSE,
|
||||||
}
|
NULL);
|
||||||
else if (pbsp->Duration == (DWORD)-1)
|
}
|
||||||
{
|
else if (pbsp->Duration == (DWORD)-1)
|
||||||
if (pDeviceExtension->BeepOn)
|
{
|
||||||
{
|
if (DeviceExtension->BeepOn)
|
||||||
HalMakeBeep(0);
|
{
|
||||||
InterlockedExchange(&(pDeviceExtension->BeepOn), FALSE);
|
HalMakeBeep (0);
|
||||||
}
|
// InterlockedExchange (&(DeviceExtension->BeepOn), FALSE);
|
||||||
else
|
DeviceExtension->BeepOn = FALSE;
|
||||||
{
|
}
|
||||||
HalMakeBeep(pbsp->Frequency);
|
else
|
||||||
InterlockedExchange(&(pDeviceExtension->BeepOn), TRUE);
|
{
|
||||||
}
|
HalMakeBeep (pbsp->Frequency);
|
||||||
}
|
// InterlockedExchange (&(DeviceExtension->BeepOn), TRUE);
|
||||||
|
DeviceExtension->BeepOn = TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
DPRINT("Did the beep!\n");
|
DPRINT ("Did the beep!\n");
|
||||||
|
|
||||||
status = STATUS_SUCCESS;
|
status = STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
status = STATUS_INVALID_PARAMETER;
|
status = STATUS_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
status = STATUS_INVALID_PARAMETER;
|
status = STATUS_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
status = STATUS_NOT_IMPLEMENTED;
|
status = STATUS_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
status = STATUS_NOT_IMPLEMENTED;
|
|
||||||
|
|
||||||
Irp->IoStatus.Status = status;
|
Irp->IoStatus.Status = status;
|
||||||
IoCompleteRequest(Irp,IO_NO_INCREMENT);
|
IoCompleteRequest (Irp, IO_NO_INCREMENT);
|
||||||
return(status);
|
return (status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NTSTATUS BeepUnload(PDRIVER_OBJECT DriverObject)
|
NTSTATUS BeepUnload(PDRIVER_OBJECT DriverObject)
|
||||||
{
|
{
|
||||||
DPRINT("BeepUnload() called!\n");
|
DPRINT ("BeepUnload() called!\n");
|
||||||
return(STATUS_SUCCESS);
|
return (STATUS_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NTSTATUS DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
|
|
||||||
/*
|
/*
|
||||||
* FUNCTION: Called by the system to initalize the driver
|
* FUNCTION: Called by the system to initalize the driver
|
||||||
* ARGUMENTS:
|
* ARGUMENTS:
|
||||||
* DriverObject = object describing this driver
|
* DriverObject = object describing this driver
|
||||||
* RegistryPath = path to our configuration entries
|
* RegistryPath = path to our configuration entries
|
||||||
* RETURNS: Success or failure
|
* RETURNS: Success or failure
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
STDCALL NTSTATUS
|
||||||
|
DriverEntry (PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
|
||||||
{
|
{
|
||||||
PDEVICE_OBJECT pDeviceObject;
|
PDEVICE_OBJECT DeviceObject;
|
||||||
PDEVICE_EXTENSION pDeviceExtension;
|
PDEVICE_EXTENSION DeviceExtension;
|
||||||
NTSTATUS ret;
|
NTSTATUS ret;
|
||||||
ANSI_STRING ansi_device_name;
|
ANSI_STRING ansi_device_name;
|
||||||
UNICODE_STRING device_name;
|
UNICODE_STRING device_name;
|
||||||
ANSI_STRING asymlink_name;
|
ANSI_STRING asymlink_name;
|
||||||
UNICODE_STRING symlink_name;
|
UNICODE_STRING symlink_name;
|
||||||
|
|
||||||
DbgPrint("Beep Device Driver 0.0.1\n");
|
DbgPrint ("Beep Device Driver 0.0.1\n");
|
||||||
|
|
||||||
RtlInitAnsiString(&ansi_device_name,"\\Device\\Beep");
|
RtlInitAnsiString (&ansi_device_name, "\\Device\\Beep");
|
||||||
RtlAnsiStringToUnicodeString(&device_name,&ansi_device_name,TRUE);
|
RtlAnsiStringToUnicodeString (&device_name, &ansi_device_name, TRUE);
|
||||||
ret = IoCreateDevice(DriverObject,
|
ret = IoCreateDevice (DriverObject,
|
||||||
sizeof(DEVICE_EXTENSION),
|
sizeof(DEVICE_EXTENSION),
|
||||||
&device_name,
|
&device_name,
|
||||||
FILE_DEVICE_BEEP,
|
FILE_DEVICE_BEEP,
|
||||||
0,
|
0,
|
||||||
FALSE,
|
FALSE,
|
||||||
&pDeviceObject);
|
&DeviceObject);
|
||||||
if (ret!=STATUS_SUCCESS)
|
if (ret!=STATUS_SUCCESS)
|
||||||
{
|
{
|
||||||
return(ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* prelininary */
|
/* prelininary */
|
||||||
RtlInitAnsiString(&asymlink_name,"\\??\\Beep");
|
RtlInitAnsiString (&asymlink_name, "\\??\\Beep");
|
||||||
RtlAnsiStringToUnicodeString(&symlink_name,&asymlink_name,TRUE);
|
RtlAnsiStringToUnicodeString (&symlink_name, &asymlink_name, TRUE);
|
||||||
IoCreateSymbolicLink(&symlink_name,&device_name);
|
IoCreateSymbolicLink (&symlink_name, &device_name);
|
||||||
|
|
||||||
DriverObject->MajorFunction[IRP_MJ_CREATE] = BeepCreate;
|
DriverObject->MajorFunction[IRP_MJ_CREATE] = BeepCreate;
|
||||||
DriverObject->MajorFunction[IRP_MJ_CLOSE] = BeepClose;
|
DriverObject->MajorFunction[IRP_MJ_CLOSE] = BeepClose;
|
||||||
|
@ -273,18 +275,18 @@ NTSTATUS DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
|
||||||
DriverObject->DriverUnload = BeepUnload;
|
DriverObject->DriverUnload = BeepUnload;
|
||||||
|
|
||||||
/* set up device extension */
|
/* set up device extension */
|
||||||
pDeviceObject->Flags |= DO_BUFFERED_IO;
|
// DeviceObject->Flags = DO_BUFFERED_IO;
|
||||||
pDeviceExtension = pDeviceObject->DeviceExtension;
|
DeviceExtension = DeviceObject->DeviceExtension;
|
||||||
pDeviceExtension->BeepOn = 0; /* FALSE */
|
DeviceExtension->BeepOn = FALSE;
|
||||||
|
|
||||||
KeInitializeDpc (&(pDeviceExtension->Dpc),
|
KeInitializeDpc (&(DeviceExtension->Dpc),
|
||||||
BeepDPC,
|
BeepDPC,
|
||||||
pDeviceExtension);
|
DeviceExtension);
|
||||||
KeInitializeTimer (&(pDeviceExtension->Timer));
|
KeInitializeTimer (&(DeviceExtension->Timer));
|
||||||
KeInitializeEvent (&(pDeviceExtension->Event),
|
KeInitializeEvent (&(DeviceExtension->Event),
|
||||||
SynchronizationEvent,
|
SynchronizationEvent,
|
||||||
FALSE);
|
FALSE);
|
||||||
|
|
||||||
return(STATUS_SUCCESS);
|
return (STATUS_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1 +1,23 @@
|
||||||
all: beep.o
|
#
|
||||||
|
#
|
||||||
|
#
|
||||||
|
|
||||||
|
OBJECTS = beep.o ../../../ntoskrnl/ntoskrnl.a
|
||||||
|
|
||||||
|
all: beep.sys
|
||||||
|
|
||||||
|
.PHONY: all
|
||||||
|
|
||||||
|
beep.sys: $(OBJECTS)
|
||||||
|
$(CC) -specs=../../svc_specs -mdll -o junk.tmp -Wl,--defsym,_end=end \
|
||||||
|
-Wl,--defsym,_edata=__data_end__ -Wl,--defsym,_etext=etext \
|
||||||
|
-Wl,--base-file,base.tmp $(OBJECTS)
|
||||||
|
- $(RM) junk.tmp
|
||||||
|
$(DLLTOOL) --dllname beep.sys --base-file base.tmp \
|
||||||
|
--output-exp temp.exp
|
||||||
|
- $(RM) base.tmp
|
||||||
|
$(CC) --verbose -Wl,--image-base,0x10000 -Wl,-e,_DriverEntry@8 \
|
||||||
|
-specs=../../svc_specs -mdll -o beep.sys $(OBJECTS) -Wl,temp.exp
|
||||||
|
- $(RM) temp.exp
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue