summaryrefslogtreecommitdiffstats
path: root/sys/compat
Commit message (Collapse)AuthorAgeFilesLines
* - Correct one aspect of the driver_object/device_object/IRP framework:wpaul2005-02-245-6/+237
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | when we create a PDO, the driver_object associated with it is that of the parent driver, not the driver we're trying to attach. For example, if we attach a PCI device, the PDO we pass to the NdisAddDevice() function should contain a pointer to fake_pci_driver, not to the NDIS driver itself. For PCI or PCMCIA devices this doesn't matter because the child never needs to talk to the parent bus driver, but for USB, the child needs to be able to send IRPs to the parent USB bus driver, and for that to work the parent USB bus driver has to be hung off the PDO. This involves modifying windrv_lookup() so that we can search for bus drivers by name, if necessary. Our fake bus drivers attach themselves as "PCI Bus," "PCCARD Bus" and "USB Bus," so we can search for them using those names. The individual attachment stubs now create and attach PDOs to the parent bus drivers instead of hanging them off the NDIS driver's object, and in if_ndis.c, we now search for the correct driver object depending on the bus type, and use that to find the correct PDO. With this fix, I can get my sample USB ethernet driver to deliver an IRP to my fake parent USB bus driver's dispatch routines. - Add stub modules for USB support: subr_usbd.c, usbd_var.h and if_ndis_usb.c. The subr_usbd.c module is hooked up the build but currently doesn't do very much. It provides the stub USB parent driver object and a dispatch routine for IRM_MJ_INTERNAL_DEVICE_CONTROL. The only exported function at the moment is USBD_GetUSBDIVersion(). The if_ndis_usb.c stub compiles, but is not hooked up to the build yet. I'm putting these here so I can keep them under source code control as I flesh them out.
* Regen.jhb2005-02-244-7/+7
|
* Use msync() to implement msync() for freebsd32 emulation. This isn't quitejhb2005-02-241-1/+1
| | | | | | | | right for certain MAP_FIXED mappings on ia64 but it will work fine for all other mappings and works fine on amd64. Requested by: ps, Christian Zander MFC after: 1 week
* Couple of lessons learned during USB driver testing:wpaul2005-02-243-3/+10
| | | | | | | | | | | | | | | | - In kern_ndis.c:ndis_unload_driver(), test that ndis_block->nmb_rlist is not NULL before trying to free() it. - In subr_pe.c:pe_get_import_descriptor(), do a case-insensitive match on the import module name. Most drivers I have encountered link against "ntoskrnl.exe" but the ASIX USB ethernet driver I'm testing with wants "NTOSKRNL.EXE." - In subr_ntoskrnl.c:IoAllocateIrp(), return a pointer to the IRP instead of NULL. (Stub code leftover.) - Also in subr_ntoskrnl.c, add ExAllocatePoolWithTag() and ExFreePool() to the function table list so they'll get exported to drivers properly.
* Implement IoCancelIrp(), IoAcquireCancelSpinLock(), IoReleaseCancelSpinLock()wpaul2005-02-232-5/+260
| | | | | | | | | | | | | | and a machine-independent though inefficient InterlockedExchange(). In Windows, InterlockedExchange() appears to be implemented in header files via inline assembly. I would prefer using an atomic.h macro for this, but there doesn't seem to be one that just does a plain old atomic exchange (as opposed to compare and exchange). Also implement IoSetCancelRoutine(), which is just a macro that uses InterlockedExchange(). Fill in IoBuildSynchronousFsdRequest(), IoBuildAsynchronousFsdRequest() and IoBuildDeviceIoControlRequest() so that they do something useful, and add a bunch of #defines to ntoskrnl_var.h to help make these work. These may require some tweaks later.
* Neuter linux_ustat() until somebody finds time to try to fix it.phk2005-02-221-4/+9
| | | | | | | | | | | | | | | The fundamental problem is that we get only the lower 8 bits of the minor device number so there is no guarantee that we can actually find the disk device in question at all. This was probably a bigger issue pre-GEOM where the upper bits signaled which slice were in use. The secondary problem is how we get from (partial) dev_t to vnode. The correct implementation will involve traversing the mount list looking for a perfect match or a possible match (for truncated minor).
* remove dead codesam2005-02-221-2/+0
| | | | Submitted by: Coverity Prevent analysis tool
* - Add a custom version of exec_copyin_args() to deal with the 32-bitjhb2005-02-181-219/+160
| | | | | | | | | | | | | | pointers in argv and envv in userland and use that together with kern_execve() and exec_free_args() to implement freebsd32_execve() without using the stackgap. - Fix freebsd32_adjtime() to call adjtime() rather than utimes(). Still uses stackgap for now. - Use kern_setitimer(), kern_getitimer(), kern_select(), kern_utimes(), kern_statfs(), kern_fstatfs(), kern_fhstatfs(), kern_stat(), kern_fstat(), and kern_lstat(). Tested by: cokane (amd64) Silence on: amd64, ia64
* Fix a couple of u_int_foos that should have been uint_foos.wpaul2005-02-183-4/+4
|
* Make the Win64 -> ELF64 template a little smaller by using a stringwpaul2005-02-181-34/+21
| | | | | | | | copy op to shift arguments on the stack instead of transfering each argument one by one through a register. Probably doesn't affect overall operation, but makes the code a little less grotty and easier to update later if I choose to make the wrapper handle more args. Also add comments.
* Remove redundant label.wpaul2005-02-161-1/+0
|
* Fix freeing of custom driver extensions. (ExFreePool() was beingwpaul2005-02-161-1/+1
| | | | called with the wrong pointer.)
* KeAcquireSpinLockRaiseToDpc() and KeReleaseSpinLock() are (at leastwpaul2005-02-162-27/+5
| | | | | | | | | | for now) exactly the same as KfAcquireSpinLock() and KfReleaseSpinLock(). I implemented the former as small routines in subr_ntoskrnl.c that just turned around and invoked the latter. But I don't really need the wrapper routines: I can just create an entries in the ntoskrnl func table that map KeAcquireSpinLockRaiseToDpc() and KeReleaseSpinLock() to KfAcquireSpinLock() and KfReleaseSpinLock() directly. This means the stubs can go away.
* Add support for Windows/x86-64 binaries to Project Evil.wpaul2005-02-1612-240/+696
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Ville-Pertti Keinonen (will at exomi dot comohmygodnospampleasekthx) deserves a big thanks for submitting initial patches to make it work. I have mangled his contributions appropriately. The main gotcha with Windows/x86-64 is that Microsoft uses a different calling convention than everyone else. The standard ABI requires using 6 registers for argument passing, with other arguments on the stack. Microsoft uses only 4 registers, and requires the caller to leave room on the stack for the register arguments incase the callee needs to spill them. Unlike x86, where Microsoft uses a mix of _cdecl, _stdcall and _fastcall, all routines on Windows/x86-64 uses the same convention. This unfortunately means that all the functions we export to the driver require an intermediate translation wrapper. Similarly, we have to wrap all calls back into the driver binary itself. The original patches provided macros to wrap every single routine at compile time, providing a secondary jump table with a customized wrapper for each exported routine. I decided to use a different approach: the call wrapper for each function is created from a template at runtime, and the routine to jump to is patched into the wrapper as it is created. The subr_pe module has been modified to patch in the wrapped function instead of the original. (On x86, the wrapping routine is a no-op.) There are some minor API differences that had to be accounted for: - KeAcquireSpinLock() is a real function on amd64, not a macro wrapper around KfAcquireSpinLock() - NdisFreeBuffer() is actually IoFreeMdl(). I had to change the whole NDIS_BUFFER API a bit to accomodate this. Bugs fixed along the way: - IoAllocateMdl() always returned NULL - kern_windrv.c:windrv_unload() wasn't releasing private driver object extensions correctly (found thanks to memguard) This has only been tested with the driver for the Broadcom 802.11g chipset, which was the only Windows/x86-64 driver I could find.
* Unbreak the kernel build. Pointy hat to: sobomax.njl2005-02-131-1/+1
|
* Backout previous change (disabling of security checks for signals deliveredsobomax2005-02-132-3/+3
| | | | | | in emulation layers), since it appears to be too broad. Requested by: rwatson
* Split out kill(2) syscall service routine into user-level and kernel part, thesobomax2005-02-132-2/+2
| | | | | | | | | | | | | | | | | former is callable from user space and the latter from the kernel one. Make kernel version take additional argument which tells if the respective call should check for additional restrictions for sending signals to suid/sugid applications or not. Make all emulation layers using non-checked version, since signal numbers in emulation layers can have different meaning that in native mode and such protection can cause misbehaviour. As a result remove LIBTHR from the signals allowed to be delivered to a suid/sugid application. Requested (sorta) by: rwatson MFC after: 2 weeks
* Semctl with IPC_STAT command should return zero in case of success.sobomax2005-02-111-2/+3
| | | | | | PR: 73778 Submitted by: Andriy Gapon <avg@icyb.net.ua> MFC after: 2 weeks
* Next step on the road to IRPs: create and use an imitation of thewpaul2005-02-087-323/+1364
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Windows DRIVER_OBJECT and DEVICE_OBJECT mechanism so that we can simulate driver stacking. In Windows, each loaded driver image is attached to a DRIVER_OBJECT structure. Windows uses the registry to match up a given vendor/device ID combination with a corresponding DRIVER_OBJECT. When a driver image is first loaded, its DriverEntry() routine is invoked, which sets up the AddDevice() function pointer in the DRIVER_OBJECT and creates a dispatch table (based on IRP major codes). When a Windows bus driver detects a new device, it creates a Physical Device Object (PDO) for it. This is a DEVICE_OBJECT structure, with semantics analagous to that of a device_t in FreeBSD. The Windows PNP manager will invoke the driver's AddDevice() function and pass it pointers to the DRIVER_OBJECT and the PDO. The AddDevice() function then creates a new DRIVER_OBJECT structure of its own. This is known as the Functional Device Object (FDO) and corresponds roughly to a private softc instance. The driver uses IoAttachDeviceToDeviceStack() to add this device object to the driver stack for this PDO. Subsequent drivers (called filter drivers in Windows-speak) can be loaded which add themselves to the stack. When someone issues an IRP to a device, it travel along the stack passing through several possible filter drivers until it reaches the functional driver (which actually knows how to talk to the hardware) at which point it will be completed. This is how Windows achieves driver layering. Project Evil now simulates most of this. if_ndis now has a modevent handler which will use MOD_LOAD and MOD_UNLOAD events to drive the creation and destruction of DRIVER_OBJECTs. (The load event also does the relocation/dynalinking of the image.) We don't have a registry, so the DRIVER_OBJECTS are stored in a linked list for now. Eventually, the list entry will contain the vendor/device ID list extracted from the .INF file. When ndis_probe() is called and detectes a supported device, it will create a PDO for the device instance and attach it to the DRIVER_OBJECT just as in Windows. ndis_attach() will then call our NdisAddDevice() handler to create the FDO. The NDIS miniport block is now a device extension hung off the FDO, just as it is in Windows. The miniport characteristics table is now an extension hung off the DRIVER_OBJECT as well (the characteristics are the same for all devices handled by a given driver, so they don't need to be per-instance.) We also do an IoAttachDeviceToDeviceStack() to put the FDO on the stack for the PDO. There are a couple of fake bus drivers created for the PCI and pccard buses. Eventually, there will be one for USB, which will actually accept USB IRP.s Things should still work just as before, only now we do things in the proper order and maintain the correct framework to support passing IRPs between drivers. Various changes: - corrected the comments about IRQL handling in subr_hal.c to more accurately reflect reality - update ndiscvt to make the drv_data symbol in ndis_driver_data.h a global so that if_ndis_pci.o and/or if_ndis_pccard.o can see it. - Obtain the softc pointer from the miniport block by referencing the PDO rather than a private pointer of our own (nmb_ifp is no longer used) - implement IoAttachDeviceToDeviceStack(), IoDetachDevice(), IoGetAttachedDevice(), IoAllocateDriverObjectExtension(), IoGetDriverObjectExtension(), IoCreateDevice(), IoDeleteDevice(), IoAllocateIrp(), IoReuseIrp(), IoMakeAssociatedIrp(), IoFreeIrp(), IoInitializeIrp() - fix a few mistakes in the driver_object and device_object definitions - add a new module, kern_windrv.c, to handle the driver registration and relocation/dynalinkign duties (which don't really belong in kern_ndis.c). - made ndis_block and ndis_chars in the ndis_softc stucture pointers and modified all references to it - fixed NdisMRegisterMiniport() and NdisInitializeWrapper() so they work correctly with the new driver_object mechanism - changed ndis_attach() to call NdisAddDevice() instead of ndis_load_driver() (which is now deprecated) - used ExAllocatePoolWithTag()/ExFreePool() in lookaside list routines instead of kludged up alloc/free routines - added kern_windrv.c to sys/modules/ndis/Makefile and files.i386.
* - Implement svr4_emul_find() using kern_alternate_path(). This changesjhb2005-02-077-524/+230
| | | | | | | | | | | | | the semantics in that the returned filename to use is now a kernel pointer rather than a user space pointer. This required changing the arguments to the CHECKALT*() macros some and changing the various system calls that used pathnames to use the kern_foo() functions that can accept kernel space filename pointers instead of calling the system call directly. - Use kern_open(), kern_access(), kern_msgctl(), kern_execve(), kern_mkfifo(), kern_mknod(), kern_statfs(), kern_fstatfs(), kern_setitimer(), kern_stat(), kern_lstat(), kern_fstat(), kern_utimes(), kern_pathconf(), and kern_unlink().
* - Use kern_{l,f,}stat() and kern_{f,}statfs() functions rather thanjhb2005-02-071-132/+39
| | | | | | duplicating the contents of the same functions inline. - Consolidate common code to convert a BSD statfs struct to a Linux struct into a static worker function.
* Make linux_emul_convpath() a simple wrapper for kern_alternate_path().jhb2005-02-071-98/+3
|
* - Tweak kern_msgctl() to return a copy of the requested message queue idjhb2005-02-071-3/+2
| | | | | | | | | | | | | | | | | structure in the struct pointed to by the 3rd argument for IPC_STAT and get rid of the 4th argument. The old way returned a pointer into the kernel array that the calling function would then access afterwards without holding the appropriate locks and doing non-lock-safe things like copyout() with the data anyways. This change removes that unsafeness and resulting race conditions as well as simplifying the interface. - Implement kern_foo wrappers for stat(), lstat(), fstat(), statfs(), fstatfs(), and fhstatfs(). Use these wrappers to cut out a lot of code duplication for freebsd4 and netbsd compatability system calls. - Add a new lookup function kern_alternate_path() that looks up a filename under an alternate prefix and determines which filename should be used. This is basically a more general version of linux_emul_convpath() that can be shared by all the ABIs thus allowing for further reduction of code duplication.
* Use kern_setitimer() to implement linux_alarm() instead of fondling thejhb2005-02-071-19/+7
| | | | real interval timer directly.
* Boot away another stackgap (one of the lest ones in linuxlator/i386) bysobomax2005-01-301-14/+13
| | | | | | | | | | providing special version of CDIOCREADSUBCHANNEL ioctl(), which assumes that result has to be placed into kernel space not user space. In the long run more generic solution has to be designed WRT emulating various ioctl()s that operate on userspace buffers, but right now there is only one such ioctl() is emulated, so that it makes little sense. MFC after: 2 weeks
* Extend kern_sendit() to take another enum uio_seg argument, which specifiessobomax2005-01-301-24/+20
| | | | | | | where the buffer to send lies and use it to eliminate yet another stackgap in linuxlator. MFC after: 2 weeks
* o Split out kernel part of execve(2) syscall into two parts: one thatsobomax2005-01-294-20/+11
| | | | | | | | | | | copies arguments into the kernel space and one that operates completely in the kernel space; o use kernel-only version of execve(2) to kill another stackgap in linuxlator/i386. Obtained from: DragonFlyBSD (partially) MFC after: 2 weeks
* Split out kernel side of msgctl(2) into two parts: the first that pops datasobomax2005-01-261-17/+10
| | | | | | | | from the userland and pushes results back and the second which does actual processing. Use the latter to eliminate stackgap in the linux wrapper of that syscall. MFC after: 2 weeks
* Split out kernel side of {get,set}itimer(2) into two parts: the first thatsobomax2005-01-251-64/+33
| | | | | | | | pops data from the userland and pushes results back and the second which does actual processing. Use the latter to eliminate stackgap in the linux wrappers of those syscalls. MFC after: 2 weeks
* Apparently, the Intel icc compiler doesn't like it when you usewpaul2005-01-254-4/+4
| | | | | | attributes in casts (i.e. foo = (__stdcall sometype)bar). This only happens in two places where we need to set up function pointers, so work around the problem with some void pointer magic.
* Begin the first phase of trying to add IRP support (and ultimatelywpaul2005-01-248-818/+1338
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | USB device support): - Convert all of my locally chosen function names to their actual Windows equivalents, where applicable. This is a big no-op change since it doesn't affect functionality, but it helps avoid a bit of confusion (it's now a lot easier to see which functions are emulated Windows API routines and which are just locally defined). - Turn ndis_buffer into an mdl, like it should have been. The structure is the same, but now it belongs to the subr_ntoskrnl module. - Implement a bunch of MDL handling macros from Windows and use them where applicable. - Correct the implementation of IoFreeMdl(). - Properly implement IoAllocateMdl() and MmBuildMdlForNonPagedPool(). - Add the definitions for struct irp and struct driver_object. - Add IMPORT_FUNC() and IMPORT_FUNC_MAP() macros to make formatting the module function tables a little cleaner. (Should also help with AMD64 support later on.) - Fix if_ndis.c to use KeRaiseIrql() and KeLowerIrql() instead of the previous calls to hal_raise_irql() and hal_lower_irql() which have been renamed. The function renaming generated a lot of churn here, but there should be very little operational effect.
* Add a 32bit syscall wrapper for modstatps2005-01-195-8/+13
| | | | Obtained from: Yahoo!
* - rename nanosleep1 to kern_nanosleepps2005-01-196-4/+40
| | | | | | | - Add a 32bit syscall entry for nanosleep Reviewed by: peter Obtained from: Yahoo!
* Fix a problem reported by Pierre Beyssac. Sometinmes when ndis_get_info()wpaul2005-01-144-18/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | calls MiniportQueryInformation(), it will return NDIS_STATUS_PENDING. When this happens, ndis_get_info() will sleep waiting for a completion event. If two threads call ndis_get_info() and both end up having to sleep, they will both end up waiting on the same wait channel, which can cause a panic in sleepq_add() if INVARIANTS are turned on. Fix this by having ndis_get_info() use a common mutex rather than using the process mutex with PROC_LOCK(). Also do the same for ndis_set_info(). Note that Pierre's original patch also made ndis_thsuspend() use the new mutex, but ndis_thsuspend() shouldn't need this since it will make each thread that calls it sleep on a unique wait channel. Also, it occured to me that we probably don't want to enter MiniportQueryInformation() or MiniportSetInformation() from more than one thread at any given time, so now we acquire a Windows spinlock before calling either of them. The Microsoft documentation says that MiniportQueryInformation() and MiniportSetInformation() are called at DISPATCH_LEVEL, and previously we would call KeRaiseIrql() to set the IRQL to DISPATCH_LEVEL before entering either routine, but this only guarantees mutual exclusion on uniprocessor machines. To make it SMP safe, we need to use a real spinlock. For now, I'm abusing the spinlock embedded in the NDIS_MINIPORT_BLOCK structure for this purpose. (This may need to be applied to some of the other routines in kern_ndis.c at a later date.) Export ntoskrnl_init_lock() (KeInitializeSpinlock()) from subr_ntoskrnl.c since we need to use in in kern_ndis.c, and since it's technically part of the Windows kernel DDK API along with the other spinlock routines. Use it in subr_ndis.c too rather than frobbing the spinlock directly.
* Match the LINUX32's style with existing styleobrien2005-01-1412-68/+68
| | | | | | Submitted by: Jung-uk Kim <jkim@niksun.com> Use positive, not negative logic.
* Fix Linux compat 'uname -m' on AMD64.obrien2005-01-141-1/+7
| | | | | Submitted by: Jung-uk Kim <jkim@niksun.com> (patch reworked by me)
* Remove duplicate code.phk2005-01-131-4/+0
|
* Start each of the license/copyright comments with /*-imp2005-01-0567-67/+67
|
* - Move the function prototypes for kern_setrlimit() and kern_wait() tojhb2005-01-052-0/+2
| | | | | sys/syscallsubr.h where all the other kern_foo() prototypes live. - Resort kern_execve() while I'm there.
* Regenerate.jhb2005-01-044-13/+15
|
* Partial sync up to the master syscalls.master file:jhb2005-01-041-8/+9
| | | | | | | | - Mark mount, unmount and nmount MPSAFE. - Add a stub for _umtx_op(). - Mark open(), link(), unlink(), and freebsd32_sigaction() MPSAFE. Pointy hats to: several
* Stop explicitly touching td_base_pri outside of the scheduler and simplyjhb2004-12-301-2/+0
| | | | | set a thread's priority via sched_prio() when that is the desired action. The schedulers will start managing td_base_pri internally shortly.
* Do not blindly pass linux filesystem specific mount data across.phk2004-12-031-1/+1
|
* Fix unvalidated pointer dereference. This is FreeBSD-SA-04:17.procfs.cperciva2004-12-011-1/+13
|
* Don't include sys/user.h merely for its side-effect of recursivelydas2004-11-272-3/+1
| | | | including other headers.
* Axe the semblance of support for PECOFF and Linux a.out core dumps.das2004-11-271-67/+1
|
* Ignore MNT_NODEV option, it is implicit in choice of filesystem.phk2004-11-261-2/+0
|
* Maintain the broken state of backwards compatibilty for a.out (anddas2004-11-201-2/+3
| | | | | | | PECOFF!) core dumps. None of the old versions of gdb I tried were able to read a.out core dumps before or after this change. Reviewed by: arch@
* Rebuild from compat/freebsd32/syscalls.master:1.43marks2004-11-182-2/+2
| | | | | Reviewed by: imp, phk, njl, peter Approved by: njl
* 32-bit FreeBSD ABI compatibility stubs from syscalls.master:1.179marks2004-11-181-1/+1
| | | | | Reviewed by: imp, phk, njl, peter Approved by: njl
OpenPOWER on IntegriCloud