diff -urN linux-2.4.17/CREDITS linux_umopenmosix/CREDITS --- linux-2.4.17/CREDITS Fri Dec 21 19:41:53 2001 +++ linux_umopenmosix/CREDITS Sun Jun 23 12:40:10 2002 @@ -434,6 +434,7 @@ E: lars@nocrew.org W: http://lars.nocrew.org/ D: dsp56k device driver +D: ptrace proxy in user mode kernel port S: Kopmansg 2 S: 411 13 Goteborg S: Sweden @@ -696,7 +697,7 @@ E: jdike@karaya.com W: http://user-mode-linux.sourceforge.net D: User mode kernel port -S: RR1 Box 67C +S: 375 Tubbs Hill Rd S: Deering NH 03244 S: USA diff -urN linux-2.4.17/Documentation/Configure.help linux_umopenmosix/Documentation/Configure.help --- linux-2.4.17/Documentation/Configure.help Fri Dec 21 19:41:53 2001 +++ linux_umopenmosix/Documentation/Configure.help Sun Jun 23 12:40:10 2002 @@ -75,6 +75,182 @@ # 1995-2000 by Axel Boldt and many others and are governed by the GNU # General Public License. +Mosix extensions +CONFIG_MOSIX + Say Y to support process migration and automatic load-balancing + within a cluster. + +Support clusters with a complex network topology +CONFIG_MOSIX_TOPOLOGY + This option is intended for configurations where the network + "distance" between the nodes is not uniform, so you require + node-dependent fine-tuning (see "man tune"). + + If all the nodes in your MOSIX cluster are connected via a simple + network and use the same networking hardware (which is the more + common case), Say N here (and save kernel-time!). + + Say Y here if not all your MOSIX cluster is connected via a simple + network or if some nodes use significantly different networking + hardware (if you are not sure whether the difference is significant, + compile some MOSIX kernel anyway and compare the results of "tune"). + +Maximum network-topology complexity to support +CONFIG_MOSIX_MAXTOPOLOGY + In a complex network-toplogy, each node can identify a number of + subsets of the other nodes, each set having the same networking + hardware, the same processor type (perhaps slower or faster, but + of the same type) and the same routing path. + The maximum network-complexity is defined as the maximum number of + those sets over all the nodes in your cluster. minimizing this + number helps saving kernel time and inter-node communication, so + please use only the level of complexity that you actually need. + + IMPORTANT NOTE: even if you prepare different kernels for different + nodes, all the nodes in your cluster must have the same value + configured here. + + MOSIX allows this value to be in the range of 2-10 (higher values + will be truncated and lower values imply no complex topology). + +MOSIX kernel debugger +CONFIG_MOSIX_UDB + Say Y to use the MOSIX kernel-debugger: + the MOSIX kernel-debugger is provided AS IS and can be entered from the + console by pressing . It is being used for the + development of MOSIX and no claims to reliability are made. + +MOSIX diagnostics +CONFIG_MOSIX_DIAG + Say Y to include MOSIX consistency checks. + While this adds code to the kernel, it may prevent unexpected + occurences when running new versions of MOSIX. + +MOSIX debug-code +CONFIG_MOSIX_DEBUG + Say Y to include extensive debugging-messages option in MOSIX + (used for MOSIX kernel-development). + +Process arrival messages +CONFIG_MOSIX_WEEEEEEEEE + If you say Y to this option, the console will display messages whenever + a process arrives: Weeeeeeeee..... for remote (guest) processes and + Wooooooooo..... for local processes returning home. + +Loopback process-migration testing +CONFIG_MOSIX_CHEAT_MIGSELF + Say Y to allow loopback process "migration" from a node into itself + (useful only for MOSIX kernel-debugging). + +Level of process-identity disclosure +CONFIG_MOSIX_DISCLOSURE + Determine how much information about processes is disclosed by default + when they run as guests on remote nodes: + 0 = no information + 1 = only PID (and TGID if different) + 2 = PID(/TGID), UID, GID + 3 = PID(/TGID), UID, GID, PGRP, SESSION, COMMAND + Processes may modify this default by writing to /proc/self/disclosure. + +Prevent the "-mosix" extension on kernel name +CONFIG_MOSIX_EXTMOSIX + Say Y if you want the kernel and module directory to have the "-mosix" + extension (to distinguish it from coexistant non-MOSIX kernels of the + same kernel version number). + +Stricter security on MOSIX ports +CONFIG_MOSIX_SECUREPORTS + The internal kernel TCP/UDP ports used by MOSIX may not be accessed + by normal users (and even the Super-User has no real reason to access + them). The question arises whether to allow user-connections to those + ports on other (internet) nodes, outside the cluster. + If routing schemes allow a MOSIX node to also be accessed from within + the MOSIX cluster using an IP address that is not listed in the MOSIX + configuration, you must say Y (or risk that a hacking user will mess + with the MOSIX internals by connecting to that IP address and one of + the MOSIX port numbers). However, these port numbers, though not + listed in "/etc/services", may be in use for other purposes somewhere + else on the internet - and this option would prevent accessing them, + so if your users require such access, say N and make sure that all the + IP addresses by which your nodes can be reached are listed as aliases + in the MOSIX configuration. + +Direct File-System Access for MOSIX +CONFIG_MOSIX_DFSA + Direct File System Access: + DFSA is now ready for Beta-testing. It can currently only be used + by MFS (MOSIX File-System). You may be interested in this option + if you either like experimenting and experiencing the power of DFSA + with MFS, or if you are interested in either developing a new + file-system, or adapting an existing one to DFSA. + + For the lay user, all you need is to also configure MFS, then run + the following commands on each node: + mkdir /mfs + mount -t mfs cluster /mfs -odfsa=1 + + If you are more serious about it, please read "Documentation/DFSA" + or run "man dfsa". + +MOSIX File-System +CONFIG_MOSIX_FS + The MOSIX File-System (MFS) is now ready for Beta-testing. + Along with DFSA, it forms the basis for the next generation + of MOSIX, expanding the power of MOSIX beyond CPU-bound tasks + into I/O tasks as well. + + On its own, MFS allows processes to access most files (more accurately, + all regular files, directories and symbolic-links, but excluding the + "/proc" file-system and MFS itself) on all the nodes in the cluster. + + MFS assumes that all users/group-ID's throughout the cluster are + equivalent: if this is not the case, you cannot use MFS, so you must + say 'N' here, unless you have a sub-cluster where the user/group-ID's + are equivalent, in which case you may still choose to configure MFS + only in that sub-cluster. + + To use MFS, all you need is to type: + mount -t mfs cluster /mfs + (the word "cluster" can be changed to suit your taste and the "/mfs" + mount-point is only a suggestion, to be used in this discussion). + For a permanent solution, enter the following line in "/etc/fstab": + cluster /mfs mfs defaults 0 0 + + You can now access each node via "/mfs/{node_number}", you may also + access the following useful directories: + + /mfs/here - The current node where your process runs + /mfs/home - Your home node + /mfs/magic - The current node when used by the "creat" system call + (or an "open" with the "O_CREAT" option) - otherwise, + the last node on which an MFS magical file was + successfully created (this is very useful for creating + temporary-files, then immediately unlinking them) + /mfs/lastexec - The node on which the process last issued a successful + "execve" system-call. + /mfs/selected - The node you selected by either your process itself or + one of its ancesstors (before forking this process), + writing a number into "/proc/self/selected". + + MFS is currently the only file-system that can be used with DFSA. + Detailed technical information is available in + "Documentation/filesystems/mfs.txt". + +Poll/Select exceptions on pipes +CONFIG_MOSIX_PIPE_EXCEPTIONS + This feature is not required for MOSIX-proper, but some user-mode + programs like it. It allows a program to be notified when someone + is wishing to read from a pipe. If you say Y, you may then use: + ioctl(pipefd, TCSBRK, arg) to set or clear exception conditions. + If (arg & 1), an exception is generated when someone is trying to + read the pipe. If (arg & 2), an exception is generated when the + pipe has no more readers. The default is that pipes never generate + any exceptions. An exception can be returned by the "select" system + call and will also cause POLLPRI to be included in the return-value + of the "poll" system-call. You can also get an under-estimate of the + number of bytes that processes curretly try to read from the pipe using + ioctl(pipefd, TIOCGWINSZ, 0). + Prompt for development and/or incomplete code/drivers CONFIG_EXPERIMENTAL Some of the various things that Linux supports (such as network @@ -13501,7 +13677,7 @@ Synchronous operation (i.e. always writing data to the host's disk immediately) is configurable on a per-UBD basis by using a special kernel command line option. Alternatively, you can say Y here to - turn on synchronous operation by default for all block. + turn on synchronous operation by default for all block devices. If you're running a journalling file system (like reiserfs, for example) in your virtual machine, you will want to say Y here. If @@ -13513,6 +13689,7 @@ CONFIG_PT_PROXY This option enables a debugging interface which allows gdb to debug the kernel without needing to actually attach to kernel threads. + CONFIG_XTERM_CHAN must be enabled in order to enable CONFIG_PT_PROXY. If you want to do kernel debugging, say Y here; otherwise say N. Management console @@ -13707,26 +13884,116 @@ SLIP transport CONFIG_UML_NET_SLIP - The Slip User-Mode Linux network transport allows a running UML to + The slip User-Mode Linux network transport allows a running UML to network with its host over a point-to-point link. Unlike Ethertap, which can carry any Ethernet frame (and hence even non-IP packets), - the Slip transport can only carry IP packets. + the slip transport can only carry IP packets. - To use this, your host must support Slip devices. + To use this, your host must support slip devices. For more information, see . That site - has examples of the UML command line to use to enable Slip + has examples of the UML command line to use to enable slip networking, and details of a few quirks with it. - The Ethertap Transport is preferred over Slip because of its - limitation. If you prefer Slip, however, say Y here. Otherwise + The Ethertap Transport is preferred over slip because of its + limitations. If you prefer slip, however, say Y here. Otherwise choose the Multicast transport (to network multiple UMLs on multiple hosts), Ethertap (to network with the host and the outside world), and/or the Daemon transport (to network multiple UMLs on a single host). You may choose more than one without conflict. If you don't need UML networking, say N. +Default main console channel initialization +CONFIG_CON_ZERO_CHAN + This is the string describing the channel to which the main console + will be attached by default. This value can be overridden from the + command line. The default value is "fd:0,fd:1", which attaches the + main console to stdin and stdout. + It is safe to leave this unchanged. + +Default console channel initialization +CONFIG_CON_CHAN + This is the string describing the channel to which all consoles + except the main console will be attached by default. This value can + be overridden from the command line. The default value is "xterm", + which brings them up in xterms. + It is safe to leave this unchanged, although you may wish to change + this if you expect the UML that you build to be run in environments + which don't have X or xterm available. + +Default serial line channel initialization +CONFIG_SSL_CHAN + This is the string describing the channel to which the serial lines + will be attached by default. This value can be overridden from the + command line. The default value is "pty", which attaches them to + traditional pseudo-terminals. + It is safe to leave this unchanged, although you may wish to change + this if you expect the UML that you build to be run in environments + which don't have a set of /dev/pty* devices. + +UML sound support +CONFIG_UML_SOUND + This option enables UML sound support. If enabled, it will pull in + soundcore and the UML hostaudio relay, which acts as a intermediary + between the host's dsp and mixer devices and the UML sound system. + It is safe to say 'Y' here. + +UML SMP support +CONFIG_UML_SMP + This option enables UML SMP support. UML implements virtual SMP by + allowing as many processes to run simultaneously on the host as + there are virtual processors configured. Obviously, if the host is + a uniprocessor, those processes will timeshare, but, inside UML, + will appear to be running simultaneously. If the host is a + multiprocessor, then UML processes may run simultaneously, depending + on the host scheduler. + CONFIG_SMP will be set to whatever this option is set to. + It is safe to leave this unchanged. + +file descriptor channel support +CONFIG_FD_CHAN + This option enables support for attaching UML consoles and serial + lines to already set up file descriptors. Generally, the main + console is attached to file descriptors 0 and 1 (stdin and stdout), + so it would be wise to leave this enabled unless you intend to + attach it to some other host device. + +port channel support +CONFIG_PORT_CHAN + This option enables support for attaching UML consoles and serial + lines to host portals. They may be accessed with 'telnet + '. Any number of consoles and serial lines may be + attached to a single portal, although what UML device you get when + you telnet to that portal will be unpredictable. + It is safe to say 'Y' here. + +pty channel support +CONFIG_PTY_CHAN + This option enables support for attaching UML consoles and serial + lines to host pseudo-terminals. Access to both traditional + pseudo-terminals (/dev/pty*) and pts pseudo-terminals are controlled + with this option. The assignment of UML devices to host devices + will be announced in the kernel message log. + It is safe to say 'Y' here. + +tty channel support +CONFIG_TTY_CHAN + This option enables support for attaching UML consoles and serial + lines to host terminals. Access to both virtual consoles + (/dev/tty*) and the slave side of pseudo-terminals (/dev/ttyp* and + /dev/pts/*) are controlled by this option. + It is safe to say 'Y' here. + +xterm channel support +CONFIG_XTERM_CHAN + This option enables support for attaching UML consoles and serial + lines to xterms. Each UML device so assigned will be brought up in + its own xterm. + If you disable this option, then CONFIG_PT_PROXY will be disabled as + well, since UML's gdb currently requires an xterm. + It is safe to say 'Y' here. + Microtek USB scanner support CONFIG_USB_MICROTEK Say Y here if you want support for the Microtek X6USB and diff -urN linux-2.4.17/Documentation/DFSA linux_umopenmosix/Documentation/DFSA --- linux-2.4.17/Documentation/DFSA Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/Documentation/DFSA Sun Jun 23 12:40:10 2002 @@ -0,0 +1,215 @@ +DFSA - Direct File-System Access: + +The first generation of MOSIX has brought about great performance +improvements in CPU jobs - "number crunchers", but cannot help in the +case of I/O tasks, which need to communicate with their home-node as +often as every system-call, and are therefore better off remaining there. + +The second generation of MOSIX, includes DFSA, whereby the more common +system-calls can be (under certain conditions) performed directly on the +caller's current node, thus increasing the benefit and probability that +I/O-oriented (or mixed I/O and CPU) tasks will also migrate. + +DFSA operates over suitable, cluster-wide shared file-systems that fulfill +certain requirements. The only file-system to currently fulfill those +requirements is the MOSIX File-System (MFS). + +To use DFSA without violating access permissions, the permission-scheme +(user and group ID's) must be identical, or at least compatible throughout +the MOSIX cluster. + +Each partition that is to operate in DFSA mode must be assigned a unique +DFSA index, currently in the range of 1-8, that must be identical on all +the nodes in the MOSIX cluster. + +To request a particular partition to operate in DFSA mode, mount (or remount) +it with the "-odfsa={n}" argument (1 <= n <= 8). + +You should do the same on all the nodes in the cluster either at about the +same time or before MOSIX is configured: failure to assign all DFSA +mount-points on some of the nodes is not fatal, but may result in serious +performance degradation, while simultaneous use of the same index for +different partitions, is likely to cause various faults. + +To disassociate a partition from DFSA, run: + +mount -o remount {mount-point} -odfsa=0. + +You may also designate symbolic-links to operate in DFSA mode: this is +equivalent to a declaration that the given links are identical on all +nodes and point to the same partition. It saves remote processes who use +those link(s) the need to contact their home node every use in order to +read those links. To declare a symbolic-link as identical, type: + +echo {symbolic-link} > /proc/mosix/admin/dfsalinks, + +where the symbolic-link must be an absolute-pathname, pointing at an existing +file (or directory or another symbolic-link) on an already-mounted partition +that is capable of DFSA (but it is not required to be already associated with +a DFSA index). + +To remove a symbolic-link declaration, type: + +echo -{symbolic-link} > /proc/mosix/admin/dfsalinks: + +If you intend to re-define a declared symbolic link, you must first re- +move its declaration, then re-declare after the change is made. + +To see a list of all currently-declared symbolic links, type: + +cat /proc/mosix/admin/dfsalinks. + +To cancel all symbolic-link declarations, type: + +echo - > /proc/mosix/admin/dfsalinks. + +The number of declared symbolic-links is currently limited to 8 and their +path-name length is limited to 128 characters. + +requirements from a complying file-system: +------------------------------------------ +1) all operations on the file system must be synchronous, in the sense that + there is [at most] only one buffer/inode cache throughout the cluster. + (on client-server file-systems, this usually means that the whole cache + is maintained on the server - however, a sophisticated server may "lend" + the cache of particular inodes to particular clients at any given time. + on shared-hardware file-systems, this probably requires either a hardware + invalidation signal or a new version to be marked on each inode after each + modification). + +2) The time-stamps on files and between files of the same file-system must be + consistent and advancing (unless the clock is deliberately set backwards), + regardless from which node modifications are made. + +3) The file-system must populate the following two new super-block methods: + a) "identify": + Given a "dentry", encapsulate identifying information about it into + a finite, rather-small structure, in a way that is sufficient to be + able to re-establish that open file/directory on another node. + b) "reconstruct": + Given only a mount-structure ("vfsmnt") and information that was + provided by "identify", produce a live new "dentry". + + Also, while not enforced by DFSA itself, in order for the getcwd + system-call to work correctly on a shared file-system, regardless + of where the call is made from, it is also highly recommended to + populate the following new inode-method: + c) "checkpath": + Given a "dentry", ensure that following its path via the "dcache" + will truly reflect its current position on the shared file-system - + and if not, make the necessary fixes by adjusting the "dentry" around + the directory cache: The "dcache" of shared file-systems cannot be + trusted, since processes running on other nodes can move (or remove) + a directory at any time. + +4) The file-system must ensure that files/directories are not cleared when + unlinked, for as long as any process in the cluster still holds them open. + There are several possible techniques to achieve this, but given the + distributed nature of the file-system, some form of garbage-collection + is probably also called upon. + +Which system-calls are supported: +--------------------------------- +The following system-calls are normally supported and usually run directly +by the process, while any other calls, or hard cases still need to go via +the home-node: + + read, readv, write, writev, readahead + lseek, llseek + open, creat, close + dup, dup2, fcntl/fcntl64 (F_DUPFD,F_GETFL,F_SETFL) + getdents, getdents64, old_readdir + fsync, fdatasync + chdir, fchdir, getcwd + stat, stat64, newstat, lstat, lstat64, newlstat, + fstat, fstat64, newfstat + access + truncate, truncate64, ftruncate, ftruncate64 + chmod, chown, chown16, lchown, lchown16, fchmod, fchown, fchown16 + utime, utimes + symlink, readlink + mkdir, rmdir + link, unlink, rename + +Examples of hard cases: +* if not all nodes have the same mounted DFSA partitions, or they do - + but with different mount-flags. +* if the calling process is being traced. +* if the process has a non-standard root-directory. +* If the calling process has an emulating personality that causes it + to use an alternate root (but this is currently not relevant for the + i386 architecture). +* if the calling process shares either its files or current directory + as a result of the "clone" system-call. +* operations occuring during re-configuration of DFSA on either the + home-node or the node where the process runs. +* operations involving special files (eg. other than regular, directories + or symbolic-links) +* operations on files that were commonly opened and still shared with other + related processes. +* dup2, where the second file-descriptor is an already open non-DFSA file + (that requires closing). +* chdir/fchdir when the previous directory is non-DFSA. +* link/rename that fail due to an attempt to cross-device link. +* open/dup/dup2/fcntl(F_DUPFD) that requires an allowable-increase in + the maximal file-descriptor index (initially 1023!). +* When the home-node has pending requests for the process (such as + signals, requests for "ps" information, request to migrate or consider + migration, etc.) +* Use of path-names that leave the DFSA partition, as demonstrated by + the following example: + "/mfs" is a DFSA file-system + /mfstmp is a symbolic link to /mfs/2/tmp, and is declared in + /proc/mosix/admin/dfsalinks. + /mtmp is a symbolic link to /mfstmp, and is declared in + /proc/mosix/admin/dfsalinks. + /mfs2 is a symbolic link to /mfs/2, but is not declared. + on node #2, /fie is a symbolic link to "/tmp/foo". + then the following are accepted as simple cases (and identical): + /mfs/2/tmp/foo + //mfs//2/tmp/foo + /./mfs/2/tmp/foo + /mfstmp/foo + /mtmp/foo + /mfs/2/fie + mfs/2/tmp/foo (when in the root directory) + + but not the following: + /tmp/../mfs/tmp/foo + (the kernel is not allowed to assume that each node has an + accessible "/tmp" directory!) + /mfs/2/../../mfs/2/tmp/foo + (the secon ".." steps out of the "/mfs" DFSA partition) + /mfs2/tmp/foo + (/mfs2 is not declared, hence no assurance was provided + that it is identical on all nodes) + mfstmp/foo (or mfstmp/foo) when in the root directory + (just a difficult case to recognize) + +* when the home-node DEPUTY has pending requests for the process (such as + signals, requests for "ps" information, request to migrate or consider + migration, etc.) + +Deviations from normal Linux/Unix/Posix behavior: +-------------------------------------------------- +It was impossible to maintain 100% compatibility on DFSA file-systems, +but the deviations are kept to the very minimum: + +* A process that received a signal may continue running a few DFSA system-calls + before it actually receives and handles the signal. + (in contrast, any POSIX process that receives a signal may possibly + complete the next system-call, but cannot issue any new ones beyond that). + +* Simultaneous mapping and I/O on the same DFSA file creates unpredictable + results as follows: + 1) execution (and library and all other file-mappings) is not always + protected against other process(es) modifying the file: either the + writing-process or the executing/mapping process may fail to receive the + "ETXTBSY" error. + 2) The "MS_INVALIDATE" flag of "msync" may fail to ensure that previous + "write"(s) to a mapped DFSA file are discarded. + 3) when a process modifies memory that is mapped as "MAP_SHARED" to a DFSA + file, but has not yet written it back (using "msync", "munmap", "exec" + or "exit"), it is possible that another process that reads that file as + it migrates will first see some of the changes but later (as opposed to + normal behavior), see the old values (or some of them) again. diff -urN linux-2.4.17/Documentation/filesystems/00-INDEX linux_umopenmosix/Documentation/filesystems/00-INDEX --- linux-2.4.17/Documentation/filesystems/00-INDEX Wed Jun 20 21:10:27 2001 +++ linux_umopenmosix/Documentation/filesystems/00-INDEX Sun Jun 23 12:40:10 2002 @@ -22,6 +22,8 @@ - info and mount options for the OS/2 HPFS. isofs.txt - info and mount options for the ISO 9660 (CDROM) filesystem. +mfs.txt + - info on the Mosix filesystem. ncpfs.txt - info on Novell Netware(tm) filesystem using NCP protocol. ntfs.txt diff -urN linux-2.4.17/Documentation/filesystems/mfs.txt linux_umopenmosix/Documentation/filesystems/mfs.txt --- linux-2.4.17/Documentation/filesystems/mfs.txt Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/Documentation/filesystems/mfs.txt Sun Jun 23 12:40:10 2002 @@ -0,0 +1,197 @@ +MFS interface, capabilities and limitations: +============================================ +To use MFS, configure the "CONFIG_MOSIX_FS" option into the kernel +then mount it, using: + mount -t mfs {any_name} {mount_point} [-o dfsa={n}] +This gives access to nearly all files throughout the MOSIX cluster, +with the root of each node available via {mount_point}/{node_number}/. +Also available as sub-directories are: + +/{mount_point}/here/ + The current node where your process runs +/{mount_point}/home/ + Your home node +/{mount_point}/magic/ + The current node when used by the "creat" system call (or an "open" + with the "O_CREAT" option) - otherwise, the last node on which an MFS + magical file was successfully created (this is very useful for creating + temporary-files, then immediately unlinking them) +/{mount_point}/lastexec/ + The node on which the process last issued a successful "execve" + system-call. +/{mount_point}/selected/ + The node you selected by either your process itself or as inherited + by one of its ancesstors (before forking this process), writing a + number into "/proc/self/selected". + +You may also wish to have MFS be automatically by entering the following +line into "/etc/fstab": + cluster /{mount_point} mfs defaults 0 0 +or for DFSA use: + cluster /{mount_point} mfs dfsa=1 0 0 + +Once CONFIG_MOSIX_FS is configured in the kernel and MOSIX has been configured +(See "man setpe"), other nodes can access the node's file-system even without +the above mount. To disallow MFS access to this node, write a "1" to +"/proc/mosix/admin/nomfs" (to re-allow, write a "0"). + +MFS was designed to also run under DFSA, allowing direct access by processes, +from wherever they run at each moment, to the node holding the files/directories +that they require, bypassing their "DEPUTY" in most cases. This makes it even +more efficient if the required files are on the same node as the process, in +which case the process can serve itself without resorting to the network. +To use MFS with DFSA, make sure that the mount-point is the same on all nodes, +then mount (or remount) MFS with the "-odfsa={n} flag, where {n} is in the +range of 1-8 and identical on all nodes in the cluster: + +Users and Groups: +----------------- +MFS assumes that all user and group ID's throughout the cluster have +equivalent access rights. You should not use MFS on clusters with +heterogenous user/group scheme. While allowing the Super-User to access +all files throughout the cluster, this is implied anyway by the security +requirements of MOSIX (See "man mosix"). If most of your cluster uses the +same scheme, but some nodes do not, you may either configure MFS only in the +kernel of those nodes that use the same scheme, or write a "1" to +"/proc/mosix/admin/nomfs" during node-startup and before MOSIX is configured +on the other nodes, as well as not mounting MFS there. + +Temporary files: +---------------- +the "here", "magic", "lastexec" and "selected" directories are designed +to provide easier access to temporary files, so that programs are helped +to create their temporary files where they run. With many programs, you +can make use these directories without recompiling, by using the "TMPDIR" +environment variable. + +The most conservative, but safest thing to do, which can be applied to all +programs, is to: + setenv TMPDIR "/{mount-point}/selected/tmp +In this case, your shell (or the calling script) should run + echo `cat /proc/self/where` > /proc/self/selected +before calling the program. +(note that "cp" cannot be used here, since only the shell may modify its +own "selected", but "echo" works because it is built into most shells) + +The next, little less conservative approach, but still safe for programs +that do not rely on passing file-names to their children as arguments of +"exec", is to: + setenv TMPDIR "/{mount-point}/lastexec/tmp + (or "env TMPDIR=/{mount-point}/lastexec/tmp program [args]") + +The next, still less conservative, but more powerful approach, can be used +for programs that create temporary-files, which either create only one MFS file, +or unlink temporary-files as soon as they are created. For such programs: + setenv TMPDIR "/{mount-point}/magic/tmp + (or "env TMPDIR=/{mount-point}/magic/tmp program [args]") + +Finally, programs that are locked on any particular node, may use: + setenv TMPDIR "/{mount-point}/here/tmp + (or "env TMPDIR=/{mount-point}/here/tmp program [args]") +Please note that this approach is not 100% safe, because even while locked, +migration back to the home-node may still occur if/when the node where the +program runs is being shut-down for reboot. + +Of course, when designing a new program to run with MFS, +all the above methods can be freely mixed. + +Interpretation of symbolic-links: +--------------------------------- +The following non-trivial interpretation of symbolic links found within MFS, +was designed to provide uniformity of access between links created locally +and via MFS, especially by scripts and "makefile"s that use `pwd` as part +of symbolic links: + +The rule is that when a symbolic link begins with a '/', it refers to the +root of the file-system's node - not the home-node! +Similarly, a "/.." (or any combination with ".." that calls for the parent of +the file-system's root) refers to the file-system's root again, rather than to +the MFS mount-point. + +One of the implications is that a symbolic link is never allowed to cross nodes. + +Excluded files: +--------------- +The following may not be accessed via the MFS file-system: +* nodes that excluded themselves. +* special files - other than regular-files, directories or symbolic-links. +* the "proc" file-system. +* any subdirectories of the recursive MFS mount-point with the exception + of symblic links starting in '/', pointing to the same node, and doing + so only once. + +Examples: +assuming that there are 3 nodes in the cluster and on node #2: +1) MFS is mounted on "/mfs" +2) "/usr/src/linux_here" is a symbolic link to "/mfs/2/usr/src/linux" +3) "/usr/src/local_linux" is a symbolic link to "../../mfs/2/usr/src/linux" +4) "/usr/src/other_linux" is a symbolic link to "/mfs/3/usr/src/linux" +5) "/usr/src/mfs_linux" is a symbolic link to "/mfs/2/mfs/2/usr/src/linux" + +then the following are accessible: + +/mfs/2/usr/src/linux +/mfs/2/etc/hosts +/mfs/2/mfs +/mfs/2/usr/src/linux_here +/usr/src/local_linux +/usr/src/other_linux + +but the following are not (and will result in "Permission denied" error): + +/mfs/2/dev/tty6 (special character device) +/mfs/2/proc/mosix ("proc" file system) +/mfs/2/mfs/2/tmp (to prevent infinite recursion and confusing the shell) +/mfs/2/usr/src/local_linux (symbolic-link does not start with '/') +/mfs/2/usr/src/other_linux (symbolic-link pointing to another node) +/usr/src/mfs_linux (symbolic-link pointing to local node twice) + +(please note, however, that symbolic-links are still readable +with "lstat" and "readlink" regardless of their contents) + +Garbage Collection: +------------------- +When either a client node or part of the network crashes, a garbage-collection +mechanism will eventually clean up the references to the held-files or +directories on the serving node(s). It may take, however, up to an hour +until the server(s) finally give up the connection, during which the serving +node(s) will not be able to un-mount the particular file-system(s) involved. + +The Super-User may still force an un-mount in 3 ways: +1) disable MFS by writing a "1" to "/proc/mosix/admin/nomfs". +2) un-configure MOSIX by running "setpe -off". +3) write the name of a file or directory to be released to + "/proc/mosix/admin/mfskill". If the given name is of a directory, all + files and sub-directories under it will be released as well (with the + possible exception of files being actively accessed at that very moment), + thus writing '/' releases everything, but is very distruptive to users, + so it is better to write the name of the mount-point of the file-system + that you wish to un-mount. + +Functionality limitations: +-------------------------- +* Mandatory file-locking is not supported. +* the F_NOTIFY fcntl option is not supported. +* Voluntary file-locking only operates among processes of the same home-node + (and since it will not be supported by DFSA, it always requires DEPUTY- + assitance on the home-node). +* file-ioctl is currently only supported for the EXT2 file-system. +* mmap of MFS files only supports private mappings (MAP_PRIVATE). + Open files must have read-permission. + The actual implementation of "mmap" and "execve" does not use demand-paging, + but rather reads in the relevant text/data from the file before proceeding. +* Every effort was attempted to prevent giving the same inode-number to + different files, and in most cases this is the case, but it is not totally + possible with only 32 bits inode-numbers and the large potential number of + files on numerous nodes and devices within each node. Priority is given so + that files on any particular node do not get the same inode-numbers, but even + this cannot be absolutely guaranteed when some of the files are NFS (or other + file-systems that use the full 32-bit space for inode numbers). To identify + an inode most accurately, one should use the raw "stat" ("fstat"/"lstat") + system-call as provided by the kernel before being filtered by the + compatibility library, providing the node-number in the "__unused1" field, + the device-number in the "__unused2" field and the local inode-numer in the + "__unused3" field (these fields are currently always 0 for non-MFS). + In the "stat64"/"lstat64"/"fstat64" system-calls, the node number can be + found in "__pad0[2-3]", the device-number in "__pad0[4-5]" and the local + inode number in "__pad0[6-9]". diff -urN linux-2.4.17/MAINTAINERS linux_umopenmosix/MAINTAINERS --- linux-2.4.17/MAINTAINERS Fri Dec 21 19:41:53 2001 +++ linux_umopenmosix/MAINTAINERS Sun Jun 23 12:40:10 2002 @@ -1694,6 +1694,14 @@ L: linux-usb-devel@lists.sourceforge.net W: http://usb.in.tum.de S: Maintained + +USER-MODE PORT +P: Jeff Dike +M: jdike@karaya.com +L: user-mode-linux-devel@lists.sourceforge.net +L: user-mode-linux-user@lists.sourceforge.net +W: http://user-mode-linux.sourceforge.net +S: Maintained VFAT FILESYSTEM: P: Gordon Chaffee diff -urN linux-2.4.17/Makefile linux_umopenmosix/Makefile --- linux-2.4.17/Makefile Fri Dec 21 19:41:53 2001 +++ linux_umopenmosix/Makefile Sun Jun 23 12:46:26 2002 @@ -5,7 +5,15 @@ KERNELRELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION) -ARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/) +# SUBARCH tells the usermode build what the underlying arch is. That is set +# first, and if a usermode build is happening, the "ARCH=um" on the command +# line overrides the setting of ARCH below. If a native build is happening, +# then ARCH is assigned, getting whatever value it gets normally, and +# SUBARCH is subsequently ignored. + +SUBARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/) +ARCH := $(SUBARCH) + KERNELPATH=kernel-$(shell echo $(KERNELRELEASE) | sed -e "s/-//") CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \ @@ -54,6 +62,11 @@ ifeq (.config,$(wildcard .config)) include .config + +ifdef CONFIG_MOSIX_EXTMOSIX +EXTRAVERSION := $(EXTRAVERSION)-mosix +endif + ifeq (.depend,$(wildcard .depend)) include .depend do-it-all: Version vmlinux @@ -88,8 +101,13 @@ CPPFLAGS := -D__KERNEL__ -I$(HPATH) +ifdef CONFIG_MOSIX_UDB +CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes -Wno-trigraphs -O2 \ + -fno-omit-frame-pointer -fno-strict-aliasing -fno-common +else CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes -Wno-trigraphs -O2 \ -fomit-frame-pointer -fno-strict-aliasing -fno-common +endif AFLAGS := -D__ASSEMBLY__ $(CPPFLAGS) # @@ -122,7 +140,16 @@ NETWORKS =net/network.o LIBS =$(TOPDIR)/lib/lib.a +ifdef CONFIG_MOSIX +CORE_FILES += $(TOPDIR)/mos/mos.o +SUBDIRS =mos kernel drivers mm fs net ipc lib +else SUBDIRS =kernel drivers mm fs net ipc lib +endif +ifdef CONFIG_MOSIX_UDB +CORE_FILES += $(TOPDIR)/udb/debugger.o +SUBDIRS += udb +endif DRIVERS-n := DRIVERS-y := @@ -208,6 +235,11 @@ net/khttpd/make_times_h \ net/khttpd/times.h \ submenu* + +CLEAN_FILES += arch/i386/kernel/mosasm.H arch/i386/kernel/offset \ + mos/auto_syscalls.c mos/mkdefcalls mos/alternate.c \ + udb/symbols.c udb/symtab vmlinux.symtab + # directories removed with 'make clean' CLEAN_DIRS = \ modules @@ -266,6 +298,20 @@ $(LIBS) \ --end-group \ -o vmlinux +ifdef CONFIG_MOSIX_UDB + $(NM) vmlinux | grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | sort > vmlinux.symtab + udb/symtab < vmlinux.symtab > udb/symbols.c + $(CC) -c $(CFLAGS) udb/symbols.c -o udb/symbols.o + $(LD) $(LINKFLAGS) $(HEAD) init/main.o init/version.o \ + --start-group \ + $(CORE_FILES) \ + $(DRIVERS) \ + $(NETWORKS) \ + $(LIBS) \ + --end-group \ + udb/symbols.o \ + -o vmlinux +endif $(NM) vmlinux | grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | sort > System.map symlinks: diff -urN linux-2.4.17/Makefile.ccache linux_umopenmosix/Makefile.ccache --- linux-2.4.17/Makefile.ccache Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/Makefile.ccache Sun Jun 23 12:46:20 2002 @@ -0,0 +1,584 @@ +VERSION = 2 +PATCHLEVEL = 4 +SUBLEVEL = 17 +EXTRAVERSION = + +KERNELRELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION) + +# SUBARCH tells the usermode build what the underlying arch is. That is set +# first, and if a usermode build is happening, the "ARCH=um" on the command +# line overrides the setting of ARCH below. If a native build is happening, +# then ARCH is assigned, getting whatever value it gets normally, and +# SUBARCH is subsequently ignored. + +SUBARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/) +ARCH := $(SUBARCH) + +KERNELPATH=kernel-$(shell echo $(KERNELRELEASE) | sed -e "s/-//") + +CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \ + else if [ -x /bin/bash ]; then echo /bin/bash; \ + else echo sh; fi ; fi) +TOPDIR := $(shell /bin/pwd) + +HPATH = $(TOPDIR)/include +FINDHPATH = $(HPATH)/asm $(HPATH)/linux $(HPATH)/scsi $(HPATH)/net + +HOSTCC = ccache gcc +HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer + +CROSS_COMPILE = + +# +# Include the make variables (CC, etc...) +# + +AS = $(CROSS_COMPILE)as +LD = $(CROSS_COMPILE)ld +CC = ccache $(CROSS_COMPILE)gcc +CPP = $(CC) -E +AR = $(CROSS_COMPILE)ar +NM = $(CROSS_COMPILE)nm +STRIP = $(CROSS_COMPILE)strip +OBJCOPY = $(CROSS_COMPILE)objcopy +OBJDUMP = $(CROSS_COMPILE)objdump +MAKEFILES = $(TOPDIR)/.config +GENKSYMS = /sbin/genksyms +DEPMOD = /sbin/depmod +MODFLAGS = -DMODULE +CFLAGS_KERNEL = +PERL = perl + +export VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION KERNELRELEASE ARCH \ + CONFIG_SHELL TOPDIR HPATH HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC \ + CPP AR NM STRIP OBJCOPY OBJDUMP MAKE MAKEFILES GENKSYMS MODFLAGS PERL + +all: do-it-all + +# +# Make "config" the default target if there is no configuration file or +# "depend" the target if there is no top-level dependency information. +# + +ifeq (.config,$(wildcard .config)) +include .config + +ifdef CONFIG_MOSIX_EXTMOSIX +EXTRAVERSION := $(EXTRAVERSION)-mosix +endif + +ifeq (.depend,$(wildcard .depend)) +include .depend +do-it-all: Version vmlinux +else +CONFIGURATION = depend +do-it-all: depend +endif +else +CONFIGURATION = config +do-it-all: config +endif + +# +# INSTALL_PATH specifies where to place the updated kernel and system map +# images. Uncomment if you want to place them anywhere other than root. +# + +#export INSTALL_PATH=/boot + +# +# INSTALL_MOD_PATH specifies a prefix to MODLIB for module directory +# relocations required by build roots. This is not defined in the +# makefile but the arguement can be passed to make if needed. +# + +MODLIB := $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE) +export MODLIB + +# +# standard CFLAGS +# + +CPPFLAGS := -D__KERNEL__ -I$(HPATH) + +ifdef CONFIG_MOSIX_UDB +CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes -Wno-trigraphs -O2 \ + -fno-omit-frame-pointer -fno-strict-aliasing -fno-common +else +CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes -Wno-trigraphs -O2 \ + -fomit-frame-pointer -fno-strict-aliasing -fno-common +endif +AFLAGS := -D__ASSEMBLY__ $(CPPFLAGS) + +# +# ROOT_DEV specifies the default root-device when making the image. +# This can be either FLOPPY, CURRENT, /dev/xxxx or empty, in which case +# the default of FLOPPY is used by 'build'. +# This is i386 specific. +# + +export ROOT_DEV = CURRENT + +# +# If you want to preset the SVGA mode, uncomment the next line and +# set SVGA_MODE to whatever number you want. +# Set it to -DSVGA_MODE=NORMAL_VGA if you just want the EGA/VGA mode. +# The number is the same as you would ordinarily press at bootup. +# This is i386 specific. +# + +export SVGA_MODE = -DSVGA_MODE=NORMAL_VGA + +# +# If you want the RAM disk device, define this to be the size in blocks. +# This is i386 specific. +# + +#export RAMDISK = -DRAMDISK=512 + +CORE_FILES =kernel/kernel.o mm/mm.o fs/fs.o ipc/ipc.o +NETWORKS =net/network.o + +LIBS =$(TOPDIR)/lib/lib.a +ifdef CONFIG_MOSIX +CORE_FILES += $(TOPDIR)/mos/mos.o +SUBDIRS =mos kernel drivers mm fs net ipc lib +else +SUBDIRS =kernel drivers mm fs net ipc lib +endif +ifdef CONFIG_MOSIX_UDB +CORE_FILES += $(TOPDIR)/udb/debugger.o +SUBDIRS += udb +endif + +DRIVERS-n := +DRIVERS-y := +DRIVERS-m := +DRIVERS- := + +DRIVERS-$(CONFIG_ACPI) += drivers/acpi/acpi.o +DRIVERS-$(CONFIG_PARPORT) += drivers/parport/driver.o +DRIVERS-y += drivers/char/char.o \ + drivers/block/block.o \ + drivers/misc/misc.o \ + drivers/net/net.o \ + drivers/media/media.o +DRIVERS-$(CONFIG_AGP) += drivers/char/agp/agp.o +DRIVERS-$(CONFIG_DRM) += drivers/char/drm/drm.o +DRIVERS-$(CONFIG_NUBUS) += drivers/nubus/nubus.a +DRIVERS-$(CONFIG_ISDN) += drivers/isdn/isdn.a +DRIVERS-$(CONFIG_NET_FC) += drivers/net/fc/fc.o +DRIVERS-$(CONFIG_APPLETALK) += drivers/net/appletalk/appletalk.o +DRIVERS-$(CONFIG_TR) += drivers/net/tokenring/tr.o +DRIVERS-$(CONFIG_WAN) += drivers/net/wan/wan.o +DRIVERS-$(CONFIG_ARCNET) += drivers/net/arcnet/arcnetdrv.o +DRIVERS-$(CONFIG_ATM) += drivers/atm/atm.o +DRIVERS-$(CONFIG_IDE) += drivers/ide/idedriver.o +DRIVERS-$(CONFIG_FC4) += drivers/fc4/fc4.a +DRIVERS-$(CONFIG_SCSI) += drivers/scsi/scsidrv.o +DRIVERS-$(CONFIG_FUSION_BOOT) += drivers/message/fusion/fusion.o +DRIVERS-$(CONFIG_IEEE1394) += drivers/ieee1394/ieee1394drv.o + +ifneq ($(CONFIG_CD_NO_IDESCSI)$(CONFIG_BLK_DEV_IDECD)$(CONFIG_BLK_DEV_SR)$(CONFIG_PARIDE_PCD),) +DRIVERS-y += drivers/cdrom/driver.o +endif + +DRIVERS-$(CONFIG_SOUND) += drivers/sound/sounddrivers.o +DRIVERS-$(CONFIG_PCI) += drivers/pci/driver.o +DRIVERS-$(CONFIG_MTD) += drivers/mtd/mtdlink.o +DRIVERS-$(CONFIG_PCMCIA) += drivers/pcmcia/pcmcia.o +DRIVERS-$(CONFIG_NET_PCMCIA) += drivers/net/pcmcia/pcmcia_net.o +DRIVERS-$(CONFIG_NET_WIRELESS) += drivers/net/wireless/wireless_net.o +DRIVERS-$(CONFIG_PCMCIA_CHRDEV) += drivers/char/pcmcia/pcmcia_char.o +DRIVERS-$(CONFIG_DIO) += drivers/dio/dio.a +DRIVERS-$(CONFIG_SBUS) += drivers/sbus/sbus_all.o +DRIVERS-$(CONFIG_ZORRO) += drivers/zorro/driver.o +DRIVERS-$(CONFIG_FC4) += drivers/fc4/fc4.a +DRIVERS-$(CONFIG_ALL_PPC) += drivers/macintosh/macintosh.o +DRIVERS-$(CONFIG_MAC) += drivers/macintosh/macintosh.o +DRIVERS-$(CONFIG_ISAPNP) += drivers/pnp/pnp.o +DRIVERS-$(CONFIG_SGI_IP22) += drivers/sgi/sgi.a +DRIVERS-$(CONFIG_VT) += drivers/video/video.o +DRIVERS-$(CONFIG_PARIDE) += drivers/block/paride/paride.a +DRIVERS-$(CONFIG_HAMRADIO) += drivers/net/hamradio/hamradio.o +DRIVERS-$(CONFIG_TC) += drivers/tc/tc.a +DRIVERS-$(CONFIG_USB) += drivers/usb/usbdrv.o +DRIVERS-$(CONFIG_INPUT) += drivers/input/inputdrv.o +DRIVERS-$(CONFIG_I2O) += drivers/message/i2o/i2o.o +DRIVERS-$(CONFIG_IRDA) += drivers/net/irda/irda.o +DRIVERS-$(CONFIG_I2C) += drivers/i2c/i2c.o +DRIVERS-$(CONFIG_PHONE) += drivers/telephony/telephony.o +DRIVERS-$(CONFIG_MD) += drivers/md/mddev.o +DRIVERS-$(CONFIG_BLUEZ) += drivers/bluetooth/bluetooth.o +DRIVERS-$(CONFIG_HOTPLUG_PCI) += drivers/hotplug/vmlinux-obj.o + +DRIVERS := $(DRIVERS-y) + + +# files removed with 'make clean' +CLEAN_FILES = \ + kernel/ksyms.lst include/linux/compile.h \ + vmlinux System.map \ + .tmp* \ + drivers/char/consolemap_deftbl.c drivers/video/promcon_tbl.c \ + drivers/char/conmakehash \ + drivers/char/drm/*-mod.c \ + drivers/pci/devlist.h drivers/pci/classlist.h drivers/pci/gen-devlist \ + drivers/zorro/devlist.h drivers/zorro/gen-devlist \ + drivers/sound/bin2hex drivers/sound/hex2hex \ + drivers/atm/fore200e_mkfirm drivers/atm/{pca,sba}*{.bin,.bin1,.bin2} \ + drivers/scsi/aic7xxx/aicasm/aicasm_gram.c \ + drivers/scsi/aic7xxx/aicasm/aicasm_scan.c \ + drivers/scsi/aic7xxx/aicasm/y.tab.h \ + drivers/scsi/aic7xxx/aicasm/aicasm \ + drivers/scsi/53c700-mem.c \ + net/khttpd/make_times_h \ + net/khttpd/times.h \ + submenu* + +CLEAN_FILES += arch/i386/kernel/mosasm.H arch/i386/kernel/offset \ + mos/auto_syscalls.c mos/mkdefcalls mos/alternate.c \ + udb/symbols.c udb/symtab vmlinux.symtab + +# directories removed with 'make clean' +CLEAN_DIRS = \ + modules + +# files removed with 'make mrproper' +MRPROPER_FILES = \ + include/linux/autoconf.h include/linux/version.h \ + drivers/net/hamradio/soundmodem/sm_tbl_{afsk1200,afsk2666,fsk9600}.h \ + drivers/net/hamradio/soundmodem/sm_tbl_{hapn4800,psk4800}.h \ + drivers/net/hamradio/soundmodem/sm_tbl_{afsk2400_7,afsk2400_8}.h \ + drivers/net/hamradio/soundmodem/gentbl \ + drivers/sound/*_boot.h drivers/sound/.*.boot \ + drivers/sound/msndinit.c \ + drivers/sound/msndperm.c \ + drivers/sound/pndsperm.c \ + drivers/sound/pndspini.c \ + drivers/atm/fore200e_*_fw.c drivers/atm/.fore200e_*.fw \ + .version .config* config.in config.old \ + scripts/tkparse scripts/kconfig.tk scripts/kconfig.tmp \ + scripts/lxdialog/*.o scripts/lxdialog/lxdialog \ + .menuconfig.log \ + include/asm \ + .hdepend scripts/mkdep scripts/split-include scripts/docproc \ + $(TOPDIR)/include/linux/modversions.h \ + kernel.spec + +# directories removed with 'make mrproper' +MRPROPER_DIRS = \ + include/config \ + $(TOPDIR)/include/linux/modules + + +include arch/$(ARCH)/Makefile + +export CPPFLAGS CFLAGS AFLAGS + +export NETWORKS DRIVERS LIBS HEAD LDFLAGS LINKFLAGS MAKEBOOT ASFLAGS + +.S.s: + $(CPP) $(AFLAGS) -traditional -o $*.s $< +.S.o: + $(CC) $(AFLAGS) -traditional -c -o $*.o $< + +Version: dummy + @rm -f include/linux/compile.h + +boot: vmlinux + @$(MAKE) CFLAGS="$(CFLAGS) $(CFLAGS_KERNEL)" -C arch/$(ARCH)/boot + +vmlinux: include/linux/version.h $(CONFIGURATION) init/main.o init/version.o linuxsubdirs + $(LD) $(LINKFLAGS) $(HEAD) init/main.o init/version.o \ + --start-group \ + $(CORE_FILES) \ + $(DRIVERS) \ + $(NETWORKS) \ + $(LIBS) \ + --end-group \ + -o vmlinux +ifdef CONFIG_MOSIX_UDB + $(NM) vmlinux | grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | sort > vmlinux.symtab + udb/symtab < vmlinux.symtab > udb/symbols.c + $(CC) -c $(CFLAGS) udb/symbols.c -o udb/symbols.o + $(LD) $(LINKFLAGS) $(HEAD) init/main.o init/version.o \ + --start-group \ + $(CORE_FILES) \ + $(DRIVERS) \ + $(NETWORKS) \ + $(LIBS) \ + --end-group \ + udb/symbols.o \ + -o vmlinux +endif + $(NM) vmlinux | grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | sort > System.map + +symlinks: + rm -f include/asm + ( cd include ; ln -sf asm-$(ARCH) asm) + @if [ ! -d include/linux/modules ]; then \ + mkdir include/linux/modules; \ + fi + +oldconfig: symlinks + $(CONFIG_SHELL) scripts/Configure -d arch/$(ARCH)/config.in + +xconfig: symlinks + $(MAKE) -C scripts kconfig.tk + wish -f scripts/kconfig.tk + +menuconfig: include/linux/version.h symlinks + $(MAKE) -C scripts/lxdialog all + $(CONFIG_SHELL) scripts/Menuconfig arch/$(ARCH)/config.in + +config: symlinks + $(CONFIG_SHELL) scripts/Configure arch/$(ARCH)/config.in + +include/config/MARKER: scripts/split-include include/linux/autoconf.h + scripts/split-include include/linux/autoconf.h include/config + @ touch include/config/MARKER + +linuxsubdirs: $(patsubst %, _dir_%, $(SUBDIRS)) + +$(patsubst %, _dir_%, $(SUBDIRS)) : dummy include/linux/version.h include/config/MARKER + $(MAKE) CFLAGS="$(CFLAGS) $(CFLAGS_KERNEL)" -C $(patsubst _dir_%, %, $@) + +$(TOPDIR)/include/linux/version.h: include/linux/version.h +$(TOPDIR)/include/linux/compile.h: include/linux/compile.h + +newversion: + . scripts/mkversion > .tmpversion + @mv -f .tmpversion .version + +include/linux/compile.h: $(CONFIGURATION) include/linux/version.h newversion + @echo -n \#define UTS_VERSION \"\#`cat .version` > .ver + @if [ -n "$(CONFIG_SMP)" ] ; then echo -n " SMP" >> .ver; fi + @if [ -f .name ]; then echo -n \-`cat .name` >> .ver; fi + @echo ' '`date`'"' >> .ver + @echo \#define LINUX_COMPILE_TIME \"`date +%T`\" >> .ver + @echo \#define LINUX_COMPILE_BY \"`whoami`\" >> .ver + @echo \#define LINUX_COMPILE_HOST \"`hostname`\" >> .ver + @if [ -x /bin/dnsdomainname ]; then \ + echo \#define LINUX_COMPILE_DOMAIN \"`dnsdomainname`\"; \ + elif [ -x /bin/domainname ]; then \ + echo \#define LINUX_COMPILE_DOMAIN \"`domainname`\"; \ + else \ + echo \#define LINUX_COMPILE_DOMAIN ; \ + fi >> .ver + @echo \#define LINUX_COMPILER \"`$(CC) $(CFLAGS) -v 2>&1 | tail -1`\" >> .ver + @mv -f .ver $@ + +include/linux/version.h: ./Makefile + @echo \#define UTS_RELEASE \"$(KERNELRELEASE)\" > .ver + @echo \#define LINUX_VERSION_CODE `expr $(VERSION) \\* 65536 + $(PATCHLEVEL) \\* 256 + $(SUBLEVEL)` >> .ver + @echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))' >>.ver + @mv -f .ver $@ + +init/version.o: init/version.c include/linux/compile.h include/config/MARKER + $(CC) $(CFLAGS) $(CFLAGS_KERNEL) -DUTS_MACHINE='"$(ARCH)"' -c -o init/version.o init/version.c + +init/main.o: init/main.c include/config/MARKER + $(CC) $(CFLAGS) $(CFLAGS_KERNEL) $(PROFILING) -c -o $*.o $< + +fs lib mm ipc kernel drivers net: dummy + $(MAKE) CFLAGS="$(CFLAGS) $(CFLAGS_KERNEL)" $(subst $@, _dir_$@, $@) + +TAGS: dummy + etags `find include/asm-$(ARCH) -name '*.h'` + find include -type d \( -name "asm-*" -o -name config \) -prune -o -name '*.h' -print | xargs etags -a + find $(SUBDIRS) init -name '*.[ch]' | xargs etags -a + +# Exuberant ctags works better with -I +tags: dummy + CTAGSF=`ctags --version | grep -i exuberant >/dev/null && echo "-I __initdata,__exitdata,EXPORT_SYMBOL,EXPORT_SYMBOL_NOVERS"`; \ + ctags $$CTAGSF `find include/asm-$(ARCH) -name '*.h'` && \ + find include -type d \( -name "asm-*" -o -name config \) -prune -o -name '*.h' -print | xargs ctags $$CTAGSF -a && \ + find $(SUBDIRS) init -name '*.[ch]' | xargs ctags $$CTAGSF -a + +ifdef CONFIG_MODULES +ifdef CONFIG_MODVERSIONS +MODFLAGS += -DMODVERSIONS -include $(HPATH)/linux/modversions.h +endif + +.PHONY: modules +modules: $(patsubst %, _mod_%, $(SUBDIRS)) + +.PHONY: $(patsubst %, _mod_%, $(SUBDIRS)) +$(patsubst %, _mod_%, $(SUBDIRS)) : include/linux/version.h include/config/MARKER + $(MAKE) -C $(patsubst _mod_%, %, $@) CFLAGS="$(CFLAGS) $(MODFLAGS)" MAKING_MODULES=1 modules + +.PHONY: modules_install +modules_install: _modinst_ $(patsubst %, _modinst_%, $(SUBDIRS)) _modinst_post + +.PHONY: _modinst_ +_modinst_: + @rm -rf $(MODLIB)/kernel + @rm -f $(MODLIB)/build + @mkdir -p $(MODLIB)/kernel + @ln -s $(TOPDIR) $(MODLIB)/build + +# If System.map exists, run depmod. This deliberately does not have a +# dependency on System.map since that would run the dependency tree on +# vmlinux. This depmod is only for convenience to give the initial +# boot a modules.dep even before / is mounted read-write. However the +# boot script depmod is the master version. +ifeq "$(strip $(INSTALL_MOD_PATH))" "" +depmod_opts := +else +depmod_opts := -b $(INSTALL_MOD_PATH) -r +endif +.PHONY: _modinst_post +_modinst_post: _modinst_post_pcmcia + if [ -r System.map ]; then $(DEPMOD) -ae -F System.map $(depmod_opts) $(KERNELRELEASE); fi + +# Backwards compatibilty symlinks for people still using old versions +# of pcmcia-cs with hard coded pathnames on insmod. Remove +# _modinst_post_pcmcia for kernel 2.4.1. +.PHONY: _modinst_post_pcmcia +_modinst_post_pcmcia: + cd $(MODLIB); \ + mkdir -p pcmcia; \ + find kernel -path '*/pcmcia/*' -name '*.o' | xargs -i -r ln -sf ../{} pcmcia + +.PHONY: $(patsubst %, _modinst_%, $(SUBDIRS)) +$(patsubst %, _modinst_%, $(SUBDIRS)) : + $(MAKE) -C $(patsubst _modinst_%, %, $@) modules_install + +# modules disabled.... + +else +modules modules_install: dummy + @echo + @echo "The present kernel configuration has modules disabled." + @echo "Type 'make config' and enable loadable module support." + @echo "Then build a kernel with module support enabled." + @echo + @exit 1 +endif + +clean: archclean + find . \( -name '*.[oas]' -o -name core -o -name '.*.flags' \) -type f -print \ + | grep -v lxdialog/ | xargs rm -f + rm -f $(CLEAN_FILES) + rm -rf $(CLEAN_DIRS) + $(MAKE) -C Documentation/DocBook clean + +mrproper: clean archmrproper + find . \( -size 0 -o -name .depend \) -type f -print | xargs rm -f + rm -f $(MRPROPER_FILES) + rm -rf $(MRPROPER_DIRS) + $(MAKE) -C Documentation/DocBook mrproper + +distclean: mrproper + rm -f core `find . \( -not -type d \) -and \ + \( -name '*.orig' -o -name '*.rej' -o -name '*~' \ + -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \ + -o -name '.*.rej' -o -name '.SUMS' -o -size 0 \) -type f -print` TAGS tags + +backup: mrproper + cd .. && tar cf - linux/ | gzip -9 > backup.gz + sync + +sgmldocs: + chmod 755 $(TOPDIR)/scripts/docgen + chmod 755 $(TOPDIR)/scripts/gen-all-syms + chmod 755 $(TOPDIR)/scripts/kernel-doc + $(MAKE) -C $(TOPDIR)/Documentation/DocBook books + +psdocs: sgmldocs + $(MAKE) -C Documentation/DocBook ps + +pdfdocs: sgmldocs + $(MAKE) -C Documentation/DocBook pdf + +htmldocs: sgmldocs + $(MAKE) -C Documentation/DocBook html + +sums: + find . -type f -print | sort | xargs sum > .SUMS + +dep-files: scripts/mkdep archdep include/linux/version.h + scripts/mkdep -- init/*.c > .depend + scripts/mkdep -- `find $(FINDHPATH) -name SCCS -prune -o -follow -name \*.h ! -name modversions.h -print` > .hdepend + $(MAKE) $(patsubst %,_sfdep_%,$(SUBDIRS)) _FASTDEP_ALL_SUB_DIRS="$(SUBDIRS)" +ifdef CONFIG_MODVERSIONS + $(MAKE) update-modverfile +endif + +ifdef CONFIG_MODVERSIONS +MODVERFILE := $(TOPDIR)/include/linux/modversions.h +else +MODVERFILE := +endif +export MODVERFILE + +depend dep: dep-files + +checkconfig: + find * -name '*.[hcS]' -type f -print | sort | xargs $(PERL) -w scripts/checkconfig.pl + +checkhelp: + find * -name [cC]onfig.in -print | sort | xargs $(PERL) -w scripts/checkhelp.pl + +checkincludes: + find * -name '*.[hcS]' -type f -print | sort | xargs $(PERL) -w scripts/checkincludes.pl + +ifdef CONFIGURATION +..$(CONFIGURATION): + @echo + @echo "You have a bad or nonexistent" .$(CONFIGURATION) ": running 'make" $(CONFIGURATION)"'" + @echo + $(MAKE) $(CONFIGURATION) + @echo + @echo "Successful. Try re-making (ignore the error that follows)" + @echo + exit 1 + +#dummy: ..$(CONFIGURATION) +dummy: + +else + +dummy: + +endif + +include Rules.make + +# +# This generates dependencies for the .h files. +# + +scripts/mkdep: scripts/mkdep.c + $(HOSTCC) $(HOSTCFLAGS) -o scripts/mkdep scripts/mkdep.c + +scripts/split-include: scripts/split-include.c + $(HOSTCC) $(HOSTCFLAGS) -o scripts/split-include scripts/split-include.c + +# +# RPM target +# +# If you do a make spec before packing the tarball you can rpm -ta it +# +spec: + . scripts/mkspec >kernel.spec + +# +# Build a tar ball, generate an rpm from it and pack the result +# There arw two bits of magic here +# 1) The use of /. to avoid tar packing just the symlink +# 2) Removing the .dep files as they have source paths in them that +# will become invalid +# +rpm: clean spec + find . \( -size 0 -o -name .depend -o -name .hdepend \) -type f -print | xargs rm -f + set -e; \ + cd $(TOPDIR)/.. ; \ + ln -sf $(TOPDIR) $(KERNELPATH) ; \ + tar -cvz --exclude CVS -f $(KERNELPATH).tar.gz $(KERNELPATH)/. ; \ + rm $(KERNELPATH) ; \ + cd $(TOPDIR) ; \ + . scripts/mkversion > .version ; \ + rpm -ta $(TOPDIR)/../$(KERNELPATH).tar.gz ; \ + rm $(TOPDIR)/../$(KERNELPATH).tar.gz diff -urN linux-2.4.17/Makefile.org linux_umopenmosix/Makefile.org --- linux-2.4.17/Makefile.org Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/Makefile.org Sun Jun 23 12:40:10 2002 @@ -0,0 +1,584 @@ +VERSION = 2 +PATCHLEVEL = 4 +SUBLEVEL = 17 +EXTRAVERSION = + +KERNELRELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION) + +# SUBARCH tells the usermode build what the underlying arch is. That is set +# first, and if a usermode build is happening, the "ARCH=um" on the command +# line overrides the setting of ARCH below. If a native build is happening, +# then ARCH is assigned, getting whatever value it gets normally, and +# SUBARCH is subsequently ignored. + +SUBARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/) +ARCH := $(SUBARCH) + +KERNELPATH=kernel-$(shell echo $(KERNELRELEASE) | sed -e "s/-//") + +CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \ + else if [ -x /bin/bash ]; then echo /bin/bash; \ + else echo sh; fi ; fi) +TOPDIR := $(shell /bin/pwd) + +HPATH = $(TOPDIR)/include +FINDHPATH = $(HPATH)/asm $(HPATH)/linux $(HPATH)/scsi $(HPATH)/net + +HOSTCC = gcc +HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer + +CROSS_COMPILE = + +# +# Include the make variables (CC, etc...) +# + +AS = $(CROSS_COMPILE)as +LD = $(CROSS_COMPILE)ld +CC = $(CROSS_COMPILE)gcc +CPP = $(CC) -E +AR = $(CROSS_COMPILE)ar +NM = $(CROSS_COMPILE)nm +STRIP = $(CROSS_COMPILE)strip +OBJCOPY = $(CROSS_COMPILE)objcopy +OBJDUMP = $(CROSS_COMPILE)objdump +MAKEFILES = $(TOPDIR)/.config +GENKSYMS = /sbin/genksyms +DEPMOD = /sbin/depmod +MODFLAGS = -DMODULE +CFLAGS_KERNEL = +PERL = perl + +export VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION KERNELRELEASE ARCH \ + CONFIG_SHELL TOPDIR HPATH HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC \ + CPP AR NM STRIP OBJCOPY OBJDUMP MAKE MAKEFILES GENKSYMS MODFLAGS PERL + +all: do-it-all + +# +# Make "config" the default target if there is no configuration file or +# "depend" the target if there is no top-level dependency information. +# + +ifeq (.config,$(wildcard .config)) +include .config + +ifdef CONFIG_MOSIX_EXTMOSIX +EXTRAVERSION := $(EXTRAVERSION)-mosix +endif + +ifeq (.depend,$(wildcard .depend)) +include .depend +do-it-all: Version vmlinux +else +CONFIGURATION = depend +do-it-all: depend +endif +else +CONFIGURATION = config +do-it-all: config +endif + +# +# INSTALL_PATH specifies where to place the updated kernel and system map +# images. Uncomment if you want to place them anywhere other than root. +# + +#export INSTALL_PATH=/boot + +# +# INSTALL_MOD_PATH specifies a prefix to MODLIB for module directory +# relocations required by build roots. This is not defined in the +# makefile but the arguement can be passed to make if needed. +# + +MODLIB := $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE) +export MODLIB + +# +# standard CFLAGS +# + +CPPFLAGS := -D__KERNEL__ -I$(HPATH) + +ifdef CONFIG_MOSIX_UDB +CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes -Wno-trigraphs -O2 \ + -fno-omit-frame-pointer -fno-strict-aliasing -fno-common +else +CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes -Wno-trigraphs -O2 \ + -fomit-frame-pointer -fno-strict-aliasing -fno-common +endif +AFLAGS := -D__ASSEMBLY__ $(CPPFLAGS) + +# +# ROOT_DEV specifies the default root-device when making the image. +# This can be either FLOPPY, CURRENT, /dev/xxxx or empty, in which case +# the default of FLOPPY is used by 'build'. +# This is i386 specific. +# + +export ROOT_DEV = CURRENT + +# +# If you want to preset the SVGA mode, uncomment the next line and +# set SVGA_MODE to whatever number you want. +# Set it to -DSVGA_MODE=NORMAL_VGA if you just want the EGA/VGA mode. +# The number is the same as you would ordinarily press at bootup. +# This is i386 specific. +# + +export SVGA_MODE = -DSVGA_MODE=NORMAL_VGA + +# +# If you want the RAM disk device, define this to be the size in blocks. +# This is i386 specific. +# + +#export RAMDISK = -DRAMDISK=512 + +CORE_FILES =kernel/kernel.o mm/mm.o fs/fs.o ipc/ipc.o +NETWORKS =net/network.o + +LIBS =$(TOPDIR)/lib/lib.a +ifdef CONFIG_MOSIX +CORE_FILES += $(TOPDIR)/mos/mos.o +SUBDIRS =mos kernel drivers mm fs net ipc lib +else +SUBDIRS =kernel drivers mm fs net ipc lib +endif +ifdef CONFIG_MOSIX_UDB +CORE_FILES += $(TOPDIR)/udb/debugger.o +SUBDIRS += udb +endif + +DRIVERS-n := +DRIVERS-y := +DRIVERS-m := +DRIVERS- := + +DRIVERS-$(CONFIG_ACPI) += drivers/acpi/acpi.o +DRIVERS-$(CONFIG_PARPORT) += drivers/parport/driver.o +DRIVERS-y += drivers/char/char.o \ + drivers/block/block.o \ + drivers/misc/misc.o \ + drivers/net/net.o \ + drivers/media/media.o +DRIVERS-$(CONFIG_AGP) += drivers/char/agp/agp.o +DRIVERS-$(CONFIG_DRM) += drivers/char/drm/drm.o +DRIVERS-$(CONFIG_NUBUS) += drivers/nubus/nubus.a +DRIVERS-$(CONFIG_ISDN) += drivers/isdn/isdn.a +DRIVERS-$(CONFIG_NET_FC) += drivers/net/fc/fc.o +DRIVERS-$(CONFIG_APPLETALK) += drivers/net/appletalk/appletalk.o +DRIVERS-$(CONFIG_TR) += drivers/net/tokenring/tr.o +DRIVERS-$(CONFIG_WAN) += drivers/net/wan/wan.o +DRIVERS-$(CONFIG_ARCNET) += drivers/net/arcnet/arcnetdrv.o +DRIVERS-$(CONFIG_ATM) += drivers/atm/atm.o +DRIVERS-$(CONFIG_IDE) += drivers/ide/idedriver.o +DRIVERS-$(CONFIG_FC4) += drivers/fc4/fc4.a +DRIVERS-$(CONFIG_SCSI) += drivers/scsi/scsidrv.o +DRIVERS-$(CONFIG_FUSION_BOOT) += drivers/message/fusion/fusion.o +DRIVERS-$(CONFIG_IEEE1394) += drivers/ieee1394/ieee1394drv.o + +ifneq ($(CONFIG_CD_NO_IDESCSI)$(CONFIG_BLK_DEV_IDECD)$(CONFIG_BLK_DEV_SR)$(CONFIG_PARIDE_PCD),) +DRIVERS-y += drivers/cdrom/driver.o +endif + +DRIVERS-$(CONFIG_SOUND) += drivers/sound/sounddrivers.o +DRIVERS-$(CONFIG_PCI) += drivers/pci/driver.o +DRIVERS-$(CONFIG_MTD) += drivers/mtd/mtdlink.o +DRIVERS-$(CONFIG_PCMCIA) += drivers/pcmcia/pcmcia.o +DRIVERS-$(CONFIG_NET_PCMCIA) += drivers/net/pcmcia/pcmcia_net.o +DRIVERS-$(CONFIG_NET_WIRELESS) += drivers/net/wireless/wireless_net.o +DRIVERS-$(CONFIG_PCMCIA_CHRDEV) += drivers/char/pcmcia/pcmcia_char.o +DRIVERS-$(CONFIG_DIO) += drivers/dio/dio.a +DRIVERS-$(CONFIG_SBUS) += drivers/sbus/sbus_all.o +DRIVERS-$(CONFIG_ZORRO) += drivers/zorro/driver.o +DRIVERS-$(CONFIG_FC4) += drivers/fc4/fc4.a +DRIVERS-$(CONFIG_ALL_PPC) += drivers/macintosh/macintosh.o +DRIVERS-$(CONFIG_MAC) += drivers/macintosh/macintosh.o +DRIVERS-$(CONFIG_ISAPNP) += drivers/pnp/pnp.o +DRIVERS-$(CONFIG_SGI_IP22) += drivers/sgi/sgi.a +DRIVERS-$(CONFIG_VT) += drivers/video/video.o +DRIVERS-$(CONFIG_PARIDE) += drivers/block/paride/paride.a +DRIVERS-$(CONFIG_HAMRADIO) += drivers/net/hamradio/hamradio.o +DRIVERS-$(CONFIG_TC) += drivers/tc/tc.a +DRIVERS-$(CONFIG_USB) += drivers/usb/usbdrv.o +DRIVERS-$(CONFIG_INPUT) += drivers/input/inputdrv.o +DRIVERS-$(CONFIG_I2O) += drivers/message/i2o/i2o.o +DRIVERS-$(CONFIG_IRDA) += drivers/net/irda/irda.o +DRIVERS-$(CONFIG_I2C) += drivers/i2c/i2c.o +DRIVERS-$(CONFIG_PHONE) += drivers/telephony/telephony.o +DRIVERS-$(CONFIG_MD) += drivers/md/mddev.o +DRIVERS-$(CONFIG_BLUEZ) += drivers/bluetooth/bluetooth.o +DRIVERS-$(CONFIG_HOTPLUG_PCI) += drivers/hotplug/vmlinux-obj.o + +DRIVERS := $(DRIVERS-y) + + +# files removed with 'make clean' +CLEAN_FILES = \ + kernel/ksyms.lst include/linux/compile.h \ + vmlinux System.map \ + .tmp* \ + drivers/char/consolemap_deftbl.c drivers/video/promcon_tbl.c \ + drivers/char/conmakehash \ + drivers/char/drm/*-mod.c \ + drivers/pci/devlist.h drivers/pci/classlist.h drivers/pci/gen-devlist \ + drivers/zorro/devlist.h drivers/zorro/gen-devlist \ + drivers/sound/bin2hex drivers/sound/hex2hex \ + drivers/atm/fore200e_mkfirm drivers/atm/{pca,sba}*{.bin,.bin1,.bin2} \ + drivers/scsi/aic7xxx/aicasm/aicasm_gram.c \ + drivers/scsi/aic7xxx/aicasm/aicasm_scan.c \ + drivers/scsi/aic7xxx/aicasm/y.tab.h \ + drivers/scsi/aic7xxx/aicasm/aicasm \ + drivers/scsi/53c700-mem.c \ + net/khttpd/make_times_h \ + net/khttpd/times.h \ + submenu* + +CLEAN_FILES += arch/i386/kernel/mosasm.H arch/i386/kernel/offset \ + mos/auto_syscalls.c mos/mkdefcalls mos/alternate.c \ + udb/symbols.c udb/symtab vmlinux.symtab + +# directories removed with 'make clean' +CLEAN_DIRS = \ + modules + +# files removed with 'make mrproper' +MRPROPER_FILES = \ + include/linux/autoconf.h include/linux/version.h \ + drivers/net/hamradio/soundmodem/sm_tbl_{afsk1200,afsk2666,fsk9600}.h \ + drivers/net/hamradio/soundmodem/sm_tbl_{hapn4800,psk4800}.h \ + drivers/net/hamradio/soundmodem/sm_tbl_{afsk2400_7,afsk2400_8}.h \ + drivers/net/hamradio/soundmodem/gentbl \ + drivers/sound/*_boot.h drivers/sound/.*.boot \ + drivers/sound/msndinit.c \ + drivers/sound/msndperm.c \ + drivers/sound/pndsperm.c \ + drivers/sound/pndspini.c \ + drivers/atm/fore200e_*_fw.c drivers/atm/.fore200e_*.fw \ + .version .config* config.in config.old \ + scripts/tkparse scripts/kconfig.tk scripts/kconfig.tmp \ + scripts/lxdialog/*.o scripts/lxdialog/lxdialog \ + .menuconfig.log \ + include/asm \ + .hdepend scripts/mkdep scripts/split-include scripts/docproc \ + $(TOPDIR)/include/linux/modversions.h \ + kernel.spec + +# directories removed with 'make mrproper' +MRPROPER_DIRS = \ + include/config \ + $(TOPDIR)/include/linux/modules + + +include arch/$(ARCH)/Makefile + +export CPPFLAGS CFLAGS AFLAGS + +export NETWORKS DRIVERS LIBS HEAD LDFLAGS LINKFLAGS MAKEBOOT ASFLAGS + +.S.s: + $(CPP) $(AFLAGS) -traditional -o $*.s $< +.S.o: + $(CC) $(AFLAGS) -traditional -c -o $*.o $< + +Version: dummy + @rm -f include/linux/compile.h + +boot: vmlinux + @$(MAKE) CFLAGS="$(CFLAGS) $(CFLAGS_KERNEL)" -C arch/$(ARCH)/boot + +vmlinux: include/linux/version.h $(CONFIGURATION) init/main.o init/version.o linuxsubdirs + $(LD) $(LINKFLAGS) $(HEAD) init/main.o init/version.o \ + --start-group \ + $(CORE_FILES) \ + $(DRIVERS) \ + $(NETWORKS) \ + $(LIBS) \ + --end-group \ + -o vmlinux +ifdef CONFIG_MOSIX_UDB + $(NM) vmlinux | grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | sort > vmlinux.symtab + udb/symtab < vmlinux.symtab > udb/symbols.c + $(CC) -c $(CFLAGS) udb/symbols.c -o udb/symbols.o + $(LD) $(LINKFLAGS) $(HEAD) init/main.o init/version.o \ + --start-group \ + $(CORE_FILES) \ + $(DRIVERS) \ + $(NETWORKS) \ + $(LIBS) \ + --end-group \ + udb/symbols.o \ + -o vmlinux +endif + $(NM) vmlinux | grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | sort > System.map + +symlinks: + rm -f include/asm + ( cd include ; ln -sf asm-$(ARCH) asm) + @if [ ! -d include/linux/modules ]; then \ + mkdir include/linux/modules; \ + fi + +oldconfig: symlinks + $(CONFIG_SHELL) scripts/Configure -d arch/$(ARCH)/config.in + +xconfig: symlinks + $(MAKE) -C scripts kconfig.tk + wish -f scripts/kconfig.tk + +menuconfig: include/linux/version.h symlinks + $(MAKE) -C scripts/lxdialog all + $(CONFIG_SHELL) scripts/Menuconfig arch/$(ARCH)/config.in + +config: symlinks + $(CONFIG_SHELL) scripts/Configure arch/$(ARCH)/config.in + +include/config/MARKER: scripts/split-include include/linux/autoconf.h + scripts/split-include include/linux/autoconf.h include/config + @ touch include/config/MARKER + +linuxsubdirs: $(patsubst %, _dir_%, $(SUBDIRS)) + +$(patsubst %, _dir_%, $(SUBDIRS)) : dummy include/linux/version.h include/config/MARKER + $(MAKE) CFLAGS="$(CFLAGS) $(CFLAGS_KERNEL)" -C $(patsubst _dir_%, %, $@) + +$(TOPDIR)/include/linux/version.h: include/linux/version.h +$(TOPDIR)/include/linux/compile.h: include/linux/compile.h + +newversion: + . scripts/mkversion > .tmpversion + @mv -f .tmpversion .version + +include/linux/compile.h: $(CONFIGURATION) include/linux/version.h newversion + @echo -n \#define UTS_VERSION \"\#`cat .version` > .ver + @if [ -n "$(CONFIG_SMP)" ] ; then echo -n " SMP" >> .ver; fi + @if [ -f .name ]; then echo -n \-`cat .name` >> .ver; fi + @echo ' '`date`'"' >> .ver + @echo \#define LINUX_COMPILE_TIME \"`date +%T`\" >> .ver + @echo \#define LINUX_COMPILE_BY \"`whoami`\" >> .ver + @echo \#define LINUX_COMPILE_HOST \"`hostname`\" >> .ver + @if [ -x /bin/dnsdomainname ]; then \ + echo \#define LINUX_COMPILE_DOMAIN \"`dnsdomainname`\"; \ + elif [ -x /bin/domainname ]; then \ + echo \#define LINUX_COMPILE_DOMAIN \"`domainname`\"; \ + else \ + echo \#define LINUX_COMPILE_DOMAIN ; \ + fi >> .ver + @echo \#define LINUX_COMPILER \"`$(CC) $(CFLAGS) -v 2>&1 | tail -1`\" >> .ver + @mv -f .ver $@ + +include/linux/version.h: ./Makefile + @echo \#define UTS_RELEASE \"$(KERNELRELEASE)\" > .ver + @echo \#define LINUX_VERSION_CODE `expr $(VERSION) \\* 65536 + $(PATCHLEVEL) \\* 256 + $(SUBLEVEL)` >> .ver + @echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))' >>.ver + @mv -f .ver $@ + +init/version.o: init/version.c include/linux/compile.h include/config/MARKER + $(CC) $(CFLAGS) $(CFLAGS_KERNEL) -DUTS_MACHINE='"$(ARCH)"' -c -o init/version.o init/version.c + +init/main.o: init/main.c include/config/MARKER + $(CC) $(CFLAGS) $(CFLAGS_KERNEL) $(PROFILING) -c -o $*.o $< + +fs lib mm ipc kernel drivers net: dummy + $(MAKE) CFLAGS="$(CFLAGS) $(CFLAGS_KERNEL)" $(subst $@, _dir_$@, $@) + +TAGS: dummy + etags `find include/asm-$(ARCH) -name '*.h'` + find include -type d \( -name "asm-*" -o -name config \) -prune -o -name '*.h' -print | xargs etags -a + find $(SUBDIRS) init -name '*.[ch]' | xargs etags -a + +# Exuberant ctags works better with -I +tags: dummy + CTAGSF=`ctags --version | grep -i exuberant >/dev/null && echo "-I __initdata,__exitdata,EXPORT_SYMBOL,EXPORT_SYMBOL_NOVERS"`; \ + ctags $$CTAGSF `find include/asm-$(ARCH) -name '*.h'` && \ + find include -type d \( -name "asm-*" -o -name config \) -prune -o -name '*.h' -print | xargs ctags $$CTAGSF -a && \ + find $(SUBDIRS) init -name '*.[ch]' | xargs ctags $$CTAGSF -a + +ifdef CONFIG_MODULES +ifdef CONFIG_MODVERSIONS +MODFLAGS += -DMODVERSIONS -include $(HPATH)/linux/modversions.h +endif + +.PHONY: modules +modules: $(patsubst %, _mod_%, $(SUBDIRS)) + +.PHONY: $(patsubst %, _mod_%, $(SUBDIRS)) +$(patsubst %, _mod_%, $(SUBDIRS)) : include/linux/version.h include/config/MARKER + $(MAKE) -C $(patsubst _mod_%, %, $@) CFLAGS="$(CFLAGS) $(MODFLAGS)" MAKING_MODULES=1 modules + +.PHONY: modules_install +modules_install: _modinst_ $(patsubst %, _modinst_%, $(SUBDIRS)) _modinst_post + +.PHONY: _modinst_ +_modinst_: + @rm -rf $(MODLIB)/kernel + @rm -f $(MODLIB)/build + @mkdir -p $(MODLIB)/kernel + @ln -s $(TOPDIR) $(MODLIB)/build + +# If System.map exists, run depmod. This deliberately does not have a +# dependency on System.map since that would run the dependency tree on +# vmlinux. This depmod is only for convenience to give the initial +# boot a modules.dep even before / is mounted read-write. However the +# boot script depmod is the master version. +ifeq "$(strip $(INSTALL_MOD_PATH))" "" +depmod_opts := +else +depmod_opts := -b $(INSTALL_MOD_PATH) -r +endif +.PHONY: _modinst_post +_modinst_post: _modinst_post_pcmcia + if [ -r System.map ]; then $(DEPMOD) -ae -F System.map $(depmod_opts) $(KERNELRELEASE); fi + +# Backwards compatibilty symlinks for people still using old versions +# of pcmcia-cs with hard coded pathnames on insmod. Remove +# _modinst_post_pcmcia for kernel 2.4.1. +.PHONY: _modinst_post_pcmcia +_modinst_post_pcmcia: + cd $(MODLIB); \ + mkdir -p pcmcia; \ + find kernel -path '*/pcmcia/*' -name '*.o' | xargs -i -r ln -sf ../{} pcmcia + +.PHONY: $(patsubst %, _modinst_%, $(SUBDIRS)) +$(patsubst %, _modinst_%, $(SUBDIRS)) : + $(MAKE) -C $(patsubst _modinst_%, %, $@) modules_install + +# modules disabled.... + +else +modules modules_install: dummy + @echo + @echo "The present kernel configuration has modules disabled." + @echo "Type 'make config' and enable loadable module support." + @echo "Then build a kernel with module support enabled." + @echo + @exit 1 +endif + +clean: archclean + find . \( -name '*.[oas]' -o -name core -o -name '.*.flags' \) -type f -print \ + | grep -v lxdialog/ | xargs rm -f + rm -f $(CLEAN_FILES) + rm -rf $(CLEAN_DIRS) + $(MAKE) -C Documentation/DocBook clean + +mrproper: clean archmrproper + find . \( -size 0 -o -name .depend \) -type f -print | xargs rm -f + rm -f $(MRPROPER_FILES) + rm -rf $(MRPROPER_DIRS) + $(MAKE) -C Documentation/DocBook mrproper + +distclean: mrproper + rm -f core `find . \( -not -type d \) -and \ + \( -name '*.orig' -o -name '*.rej' -o -name '*~' \ + -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \ + -o -name '.*.rej' -o -name '.SUMS' -o -size 0 \) -type f -print` TAGS tags + +backup: mrproper + cd .. && tar cf - linux/ | gzip -9 > backup.gz + sync + +sgmldocs: + chmod 755 $(TOPDIR)/scripts/docgen + chmod 755 $(TOPDIR)/scripts/gen-all-syms + chmod 755 $(TOPDIR)/scripts/kernel-doc + $(MAKE) -C $(TOPDIR)/Documentation/DocBook books + +psdocs: sgmldocs + $(MAKE) -C Documentation/DocBook ps + +pdfdocs: sgmldocs + $(MAKE) -C Documentation/DocBook pdf + +htmldocs: sgmldocs + $(MAKE) -C Documentation/DocBook html + +sums: + find . -type f -print | sort | xargs sum > .SUMS + +dep-files: scripts/mkdep archdep include/linux/version.h + scripts/mkdep -- init/*.c > .depend + scripts/mkdep -- `find $(FINDHPATH) -name SCCS -prune -o -follow -name \*.h ! -name modversions.h -print` > .hdepend + $(MAKE) $(patsubst %,_sfdep_%,$(SUBDIRS)) _FASTDEP_ALL_SUB_DIRS="$(SUBDIRS)" +ifdef CONFIG_MODVERSIONS + $(MAKE) update-modverfile +endif + +ifdef CONFIG_MODVERSIONS +MODVERFILE := $(TOPDIR)/include/linux/modversions.h +else +MODVERFILE := +endif +export MODVERFILE + +depend dep: dep-files + +checkconfig: + find * -name '*.[hcS]' -type f -print | sort | xargs $(PERL) -w scripts/checkconfig.pl + +checkhelp: + find * -name [cC]onfig.in -print | sort | xargs $(PERL) -w scripts/checkhelp.pl + +checkincludes: + find * -name '*.[hcS]' -type f -print | sort | xargs $(PERL) -w scripts/checkincludes.pl + +ifdef CONFIGURATION +..$(CONFIGURATION): + @echo + @echo "You have a bad or nonexistent" .$(CONFIGURATION) ": running 'make" $(CONFIGURATION)"'" + @echo + $(MAKE) $(CONFIGURATION) + @echo + @echo "Successful. Try re-making (ignore the error that follows)" + @echo + exit 1 + +#dummy: ..$(CONFIGURATION) +dummy: + +else + +dummy: + +endif + +include Rules.make + +# +# This generates dependencies for the .h files. +# + +scripts/mkdep: scripts/mkdep.c + $(HOSTCC) $(HOSTCFLAGS) -o scripts/mkdep scripts/mkdep.c + +scripts/split-include: scripts/split-include.c + $(HOSTCC) $(HOSTCFLAGS) -o scripts/split-include scripts/split-include.c + +# +# RPM target +# +# If you do a make spec before packing the tarball you can rpm -ta it +# +spec: + . scripts/mkspec >kernel.spec + +# +# Build a tar ball, generate an rpm from it and pack the result +# There arw two bits of magic here +# 1) The use of /. to avoid tar packing just the symlink +# 2) Removing the .dep files as they have source paths in them that +# will become invalid +# +rpm: clean spec + find . \( -size 0 -o -name .depend -o -name .hdepend \) -type f -print | xargs rm -f + set -e; \ + cd $(TOPDIR)/.. ; \ + ln -sf $(TOPDIR) $(KERNELPATH) ; \ + tar -cvz --exclude CVS -f $(KERNELPATH).tar.gz $(KERNELPATH)/. ; \ + rm $(KERNELPATH) ; \ + cd $(TOPDIR) ; \ + . scripts/mkversion > .version ; \ + rpm -ta $(TOPDIR)/../$(KERNELPATH).tar.gz ; \ + rm $(TOPDIR)/../$(KERNELPATH).tar.gz diff -urN linux-2.4.17/Makefile.orig linux_umopenmosix/Makefile.orig --- linux-2.4.17/Makefile.orig Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/Makefile.orig Sun Jun 23 12:40:10 2002 @@ -0,0 +1,546 @@ +VERSION = 2 +PATCHLEVEL = 4 +SUBLEVEL = 17 +EXTRAVERSION = + +KERNELRELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION) + +# SUBARCH tells the usermode build what the underlying arch is. That is set +# first, and if a usermode build is happening, the "ARCH=um" on the command +# line overrides the setting of ARCH below. If a native build is happening, +# then ARCH is assigned, getting whatever value it gets normally, and +# SUBARCH is subsequently ignored. + +SUBARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/) +ARCH := $(SUBARCH) + +KERNELPATH=kernel-$(shell echo $(KERNELRELEASE) | sed -e "s/-//") + +CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \ + else if [ -x /bin/bash ]; then echo /bin/bash; \ + else echo sh; fi ; fi) +TOPDIR := $(shell /bin/pwd) + +HPATH = $(TOPDIR)/include +FINDHPATH = $(HPATH)/asm $(HPATH)/linux $(HPATH)/scsi $(HPATH)/net + +HOSTCC = ccache gcc +HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer + +CROSS_COMPILE = + +# +# Include the make variables (CC, etc...) +# + +AS = $(CROSS_COMPILE)as +LD = $(CROSS_COMPILE)ld +CC = ccache $(CROSS_COMPILE)gcc +CPP = $(CC) -E +AR = $(CROSS_COMPILE)ar +NM = $(CROSS_COMPILE)nm +STRIP = $(CROSS_COMPILE)strip +OBJCOPY = $(CROSS_COMPILE)objcopy +OBJDUMP = $(CROSS_COMPILE)objdump +MAKEFILES = $(TOPDIR)/.config +GENKSYMS = /sbin/genksyms +DEPMOD = /sbin/depmod +MODFLAGS = -DMODULE +CFLAGS_KERNEL = +PERL = perl + +export VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION KERNELRELEASE ARCH \ + CONFIG_SHELL TOPDIR HPATH HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC \ + CPP AR NM STRIP OBJCOPY OBJDUMP MAKE MAKEFILES GENKSYMS MODFLAGS PERL + +all: do-it-all + +# +# Make "config" the default target if there is no configuration file or +# "depend" the target if there is no top-level dependency information. +# + +ifeq (.config,$(wildcard .config)) +include .config +ifeq (.depend,$(wildcard .depend)) +include .depend +do-it-all: Version vmlinux +else +CONFIGURATION = depend +do-it-all: depend +endif +else +CONFIGURATION = config +do-it-all: config +endif + +# +# INSTALL_PATH specifies where to place the updated kernel and system map +# images. Uncomment if you want to place them anywhere other than root. +# + +#export INSTALL_PATH=/boot + +# +# INSTALL_MOD_PATH specifies a prefix to MODLIB for module directory +# relocations required by build roots. This is not defined in the +# makefile but the arguement can be passed to make if needed. +# + +MODLIB := $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE) +export MODLIB + +# +# standard CFLAGS +# + +CPPFLAGS := -D__KERNEL__ -I$(HPATH) + +CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes -Wno-trigraphs -O2 \ + -fomit-frame-pointer -fno-strict-aliasing -fno-common +AFLAGS := -D__ASSEMBLY__ $(CPPFLAGS) + +# +# ROOT_DEV specifies the default root-device when making the image. +# This can be either FLOPPY, CURRENT, /dev/xxxx or empty, in which case +# the default of FLOPPY is used by 'build'. +# This is i386 specific. +# + +export ROOT_DEV = CURRENT + +# +# If you want to preset the SVGA mode, uncomment the next line and +# set SVGA_MODE to whatever number you want. +# Set it to -DSVGA_MODE=NORMAL_VGA if you just want the EGA/VGA mode. +# The number is the same as you would ordinarily press at bootup. +# This is i386 specific. +# + +export SVGA_MODE = -DSVGA_MODE=NORMAL_VGA + +# +# If you want the RAM disk device, define this to be the size in blocks. +# This is i386 specific. +# + +#export RAMDISK = -DRAMDISK=512 + +CORE_FILES =kernel/kernel.o mm/mm.o fs/fs.o ipc/ipc.o +NETWORKS =net/network.o + +LIBS =$(TOPDIR)/lib/lib.a +SUBDIRS =kernel drivers mm fs net ipc lib + +DRIVERS-n := +DRIVERS-y := +DRIVERS-m := +DRIVERS- := + +DRIVERS-$(CONFIG_ACPI) += drivers/acpi/acpi.o +DRIVERS-$(CONFIG_PARPORT) += drivers/parport/driver.o +DRIVERS-y += drivers/char/char.o \ + drivers/block/block.o \ + drivers/misc/misc.o \ + drivers/net/net.o \ + drivers/media/media.o +DRIVERS-$(CONFIG_AGP) += drivers/char/agp/agp.o +DRIVERS-$(CONFIG_DRM) += drivers/char/drm/drm.o +DRIVERS-$(CONFIG_NUBUS) += drivers/nubus/nubus.a +DRIVERS-$(CONFIG_ISDN) += drivers/isdn/isdn.a +DRIVERS-$(CONFIG_NET_FC) += drivers/net/fc/fc.o +DRIVERS-$(CONFIG_APPLETALK) += drivers/net/appletalk/appletalk.o +DRIVERS-$(CONFIG_TR) += drivers/net/tokenring/tr.o +DRIVERS-$(CONFIG_WAN) += drivers/net/wan/wan.o +DRIVERS-$(CONFIG_ARCNET) += drivers/net/arcnet/arcnetdrv.o +DRIVERS-$(CONFIG_ATM) += drivers/atm/atm.o +DRIVERS-$(CONFIG_IDE) += drivers/ide/idedriver.o +DRIVERS-$(CONFIG_FC4) += drivers/fc4/fc4.a +DRIVERS-$(CONFIG_SCSI) += drivers/scsi/scsidrv.o +DRIVERS-$(CONFIG_FUSION_BOOT) += drivers/message/fusion/fusion.o +DRIVERS-$(CONFIG_IEEE1394) += drivers/ieee1394/ieee1394drv.o + +ifneq ($(CONFIG_CD_NO_IDESCSI)$(CONFIG_BLK_DEV_IDECD)$(CONFIG_BLK_DEV_SR)$(CONFIG_PARIDE_PCD),) +DRIVERS-y += drivers/cdrom/driver.o +endif + +DRIVERS-$(CONFIG_SOUND) += drivers/sound/sounddrivers.o +DRIVERS-$(CONFIG_PCI) += drivers/pci/driver.o +DRIVERS-$(CONFIG_MTD) += drivers/mtd/mtdlink.o +DRIVERS-$(CONFIG_PCMCIA) += drivers/pcmcia/pcmcia.o +DRIVERS-$(CONFIG_NET_PCMCIA) += drivers/net/pcmcia/pcmcia_net.o +DRIVERS-$(CONFIG_NET_WIRELESS) += drivers/net/wireless/wireless_net.o +DRIVERS-$(CONFIG_PCMCIA_CHRDEV) += drivers/char/pcmcia/pcmcia_char.o +DRIVERS-$(CONFIG_DIO) += drivers/dio/dio.a +DRIVERS-$(CONFIG_SBUS) += drivers/sbus/sbus_all.o +DRIVERS-$(CONFIG_ZORRO) += drivers/zorro/driver.o +DRIVERS-$(CONFIG_FC4) += drivers/fc4/fc4.a +DRIVERS-$(CONFIG_ALL_PPC) += drivers/macintosh/macintosh.o +DRIVERS-$(CONFIG_MAC) += drivers/macintosh/macintosh.o +DRIVERS-$(CONFIG_ISAPNP) += drivers/pnp/pnp.o +DRIVERS-$(CONFIG_SGI_IP22) += drivers/sgi/sgi.a +DRIVERS-$(CONFIG_VT) += drivers/video/video.o +DRIVERS-$(CONFIG_PARIDE) += drivers/block/paride/paride.a +DRIVERS-$(CONFIG_HAMRADIO) += drivers/net/hamradio/hamradio.o +DRIVERS-$(CONFIG_TC) += drivers/tc/tc.a +DRIVERS-$(CONFIG_USB) += drivers/usb/usbdrv.o +DRIVERS-$(CONFIG_INPUT) += drivers/input/inputdrv.o +DRIVERS-$(CONFIG_I2O) += drivers/message/i2o/i2o.o +DRIVERS-$(CONFIG_IRDA) += drivers/net/irda/irda.o +DRIVERS-$(CONFIG_I2C) += drivers/i2c/i2c.o +DRIVERS-$(CONFIG_PHONE) += drivers/telephony/telephony.o +DRIVERS-$(CONFIG_MD) += drivers/md/mddev.o +DRIVERS-$(CONFIG_BLUEZ) += drivers/bluetooth/bluetooth.o +DRIVERS-$(CONFIG_HOTPLUG_PCI) += drivers/hotplug/vmlinux-obj.o + +DRIVERS := $(DRIVERS-y) + + +# files removed with 'make clean' +CLEAN_FILES = \ + kernel/ksyms.lst include/linux/compile.h \ + vmlinux System.map \ + .tmp* \ + drivers/char/consolemap_deftbl.c drivers/video/promcon_tbl.c \ + drivers/char/conmakehash \ + drivers/char/drm/*-mod.c \ + drivers/pci/devlist.h drivers/pci/classlist.h drivers/pci/gen-devlist \ + drivers/zorro/devlist.h drivers/zorro/gen-devlist \ + drivers/sound/bin2hex drivers/sound/hex2hex \ + drivers/atm/fore200e_mkfirm drivers/atm/{pca,sba}*{.bin,.bin1,.bin2} \ + drivers/scsi/aic7xxx/aicasm/aicasm_gram.c \ + drivers/scsi/aic7xxx/aicasm/aicasm_scan.c \ + drivers/scsi/aic7xxx/aicasm/y.tab.h \ + drivers/scsi/aic7xxx/aicasm/aicasm \ + drivers/scsi/53c700-mem.c \ + net/khttpd/make_times_h \ + net/khttpd/times.h \ + submenu* +# directories removed with 'make clean' +CLEAN_DIRS = \ + modules + +# files removed with 'make mrproper' +MRPROPER_FILES = \ + include/linux/autoconf.h include/linux/version.h \ + drivers/net/hamradio/soundmodem/sm_tbl_{afsk1200,afsk2666,fsk9600}.h \ + drivers/net/hamradio/soundmodem/sm_tbl_{hapn4800,psk4800}.h \ + drivers/net/hamradio/soundmodem/sm_tbl_{afsk2400_7,afsk2400_8}.h \ + drivers/net/hamradio/soundmodem/gentbl \ + drivers/sound/*_boot.h drivers/sound/.*.boot \ + drivers/sound/msndinit.c \ + drivers/sound/msndperm.c \ + drivers/sound/pndsperm.c \ + drivers/sound/pndspini.c \ + drivers/atm/fore200e_*_fw.c drivers/atm/.fore200e_*.fw \ + .version .config* config.in config.old \ + scripts/tkparse scripts/kconfig.tk scripts/kconfig.tmp \ + scripts/lxdialog/*.o scripts/lxdialog/lxdialog \ + .menuconfig.log \ + include/asm \ + .hdepend scripts/mkdep scripts/split-include scripts/docproc \ + $(TOPDIR)/include/linux/modversions.h \ + kernel.spec + +# directories removed with 'make mrproper' +MRPROPER_DIRS = \ + include/config \ + $(TOPDIR)/include/linux/modules + + +include arch/$(ARCH)/Makefile + +export CPPFLAGS CFLAGS AFLAGS + +export NETWORKS DRIVERS LIBS HEAD LDFLAGS LINKFLAGS MAKEBOOT ASFLAGS + +.S.s: + $(CPP) $(AFLAGS) -traditional -o $*.s $< +.S.o: + $(CC) $(AFLAGS) -traditional -c -o $*.o $< + +Version: dummy + @rm -f include/linux/compile.h + +boot: vmlinux + @$(MAKE) CFLAGS="$(CFLAGS) $(CFLAGS_KERNEL)" -C arch/$(ARCH)/boot + +vmlinux: include/linux/version.h $(CONFIGURATION) init/main.o init/version.o linuxsubdirs + $(LD) $(LINKFLAGS) $(HEAD) init/main.o init/version.o \ + --start-group \ + $(CORE_FILES) \ + $(DRIVERS) \ + $(NETWORKS) \ + $(LIBS) \ + --end-group \ + -o vmlinux + $(NM) vmlinux | grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | sort > System.map + +symlinks: + rm -f include/asm + ( cd include ; ln -sf asm-$(ARCH) asm) + @if [ ! -d include/linux/modules ]; then \ + mkdir include/linux/modules; \ + fi + +oldconfig: symlinks + $(CONFIG_SHELL) scripts/Configure -d arch/$(ARCH)/config.in + +xconfig: symlinks + $(MAKE) -C scripts kconfig.tk + wish -f scripts/kconfig.tk + +menuconfig: include/linux/version.h symlinks + $(MAKE) -C scripts/lxdialog all + $(CONFIG_SHELL) scripts/Menuconfig arch/$(ARCH)/config.in + +config: symlinks + $(CONFIG_SHELL) scripts/Configure arch/$(ARCH)/config.in + +include/config/MARKER: scripts/split-include include/linux/autoconf.h + scripts/split-include include/linux/autoconf.h include/config + @ touch include/config/MARKER + +linuxsubdirs: $(patsubst %, _dir_%, $(SUBDIRS)) + +$(patsubst %, _dir_%, $(SUBDIRS)) : dummy include/linux/version.h include/config/MARKER + $(MAKE) CFLAGS="$(CFLAGS) $(CFLAGS_KERNEL)" -C $(patsubst _dir_%, %, $@) + +$(TOPDIR)/include/linux/version.h: include/linux/version.h +$(TOPDIR)/include/linux/compile.h: include/linux/compile.h + +newversion: + . scripts/mkversion > .tmpversion + @mv -f .tmpversion .version + +include/linux/compile.h: $(CONFIGURATION) include/linux/version.h newversion + @echo -n \#define UTS_VERSION \"\#`cat .version` > .ver + @if [ -n "$(CONFIG_SMP)" ] ; then echo -n " SMP" >> .ver; fi + @if [ -f .name ]; then echo -n \-`cat .name` >> .ver; fi + @echo ' '`date`'"' >> .ver + @echo \#define LINUX_COMPILE_TIME \"`date +%T`\" >> .ver + @echo \#define LINUX_COMPILE_BY \"`whoami`\" >> .ver + @echo \#define LINUX_COMPILE_HOST \"`hostname`\" >> .ver + @if [ -x /bin/dnsdomainname ]; then \ + echo \#define LINUX_COMPILE_DOMAIN \"`dnsdomainname`\"; \ + elif [ -x /bin/domainname ]; then \ + echo \#define LINUX_COMPILE_DOMAIN \"`domainname`\"; \ + else \ + echo \#define LINUX_COMPILE_DOMAIN ; \ + fi >> .ver + @echo \#define LINUX_COMPILER \"`$(CC) $(CFLAGS) -v 2>&1 | tail -1`\" >> .ver + @mv -f .ver $@ + +include/linux/version.h: ./Makefile + @echo \#define UTS_RELEASE \"$(KERNELRELEASE)\" > .ver + @echo \#define LINUX_VERSION_CODE `expr $(VERSION) \\* 65536 + $(PATCHLEVEL) \\* 256 + $(SUBLEVEL)` >> .ver + @echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))' >>.ver + @mv -f .ver $@ + +init/version.o: init/version.c include/linux/compile.h include/config/MARKER + $(CC) $(CFLAGS) $(CFLAGS_KERNEL) -DUTS_MACHINE='"$(ARCH)"' -c -o init/version.o init/version.c + +init/main.o: init/main.c include/config/MARKER + $(CC) $(CFLAGS) $(CFLAGS_KERNEL) $(PROFILING) -c -o $*.o $< + +fs lib mm ipc kernel drivers net: dummy + $(MAKE) CFLAGS="$(CFLAGS) $(CFLAGS_KERNEL)" $(subst $@, _dir_$@, $@) + +TAGS: dummy + etags `find include/asm-$(ARCH) -name '*.h'` + find include -type d \( -name "asm-*" -o -name config \) -prune -o -name '*.h' -print | xargs etags -a + find $(SUBDIRS) init -name '*.[ch]' | xargs etags -a + +# Exuberant ctags works better with -I +tags: dummy + CTAGSF=`ctags --version | grep -i exuberant >/dev/null && echo "-I __initdata,__exitdata,EXPORT_SYMBOL,EXPORT_SYMBOL_NOVERS"`; \ + ctags $$CTAGSF `find include/asm-$(ARCH) -name '*.h'` && \ + find include -type d \( -name "asm-*" -o -name config \) -prune -o -name '*.h' -print | xargs ctags $$CTAGSF -a && \ + find $(SUBDIRS) init -name '*.[ch]' | xargs ctags $$CTAGSF -a + +ifdef CONFIG_MODULES +ifdef CONFIG_MODVERSIONS +MODFLAGS += -DMODVERSIONS -include $(HPATH)/linux/modversions.h +endif + +.PHONY: modules +modules: $(patsubst %, _mod_%, $(SUBDIRS)) + +.PHONY: $(patsubst %, _mod_%, $(SUBDIRS)) +$(patsubst %, _mod_%, $(SUBDIRS)) : include/linux/version.h include/config/MARKER + $(MAKE) -C $(patsubst _mod_%, %, $@) CFLAGS="$(CFLAGS) $(MODFLAGS)" MAKING_MODULES=1 modules + +.PHONY: modules_install +modules_install: _modinst_ $(patsubst %, _modinst_%, $(SUBDIRS)) _modinst_post + +.PHONY: _modinst_ +_modinst_: + @rm -rf $(MODLIB)/kernel + @rm -f $(MODLIB)/build + @mkdir -p $(MODLIB)/kernel + @ln -s $(TOPDIR) $(MODLIB)/build + +# If System.map exists, run depmod. This deliberately does not have a +# dependency on System.map since that would run the dependency tree on +# vmlinux. This depmod is only for convenience to give the initial +# boot a modules.dep even before / is mounted read-write. However the +# boot script depmod is the master version. +ifeq "$(strip $(INSTALL_MOD_PATH))" "" +depmod_opts := +else +depmod_opts := -b $(INSTALL_MOD_PATH) -r +endif +.PHONY: _modinst_post +_modinst_post: _modinst_post_pcmcia + if [ -r System.map ]; then $(DEPMOD) -ae -F System.map $(depmod_opts) $(KERNELRELEASE); fi + +# Backwards compatibilty symlinks for people still using old versions +# of pcmcia-cs with hard coded pathnames on insmod. Remove +# _modinst_post_pcmcia for kernel 2.4.1. +.PHONY: _modinst_post_pcmcia +_modinst_post_pcmcia: + cd $(MODLIB); \ + mkdir -p pcmcia; \ + find kernel -path '*/pcmcia/*' -name '*.o' | xargs -i -r ln -sf ../{} pcmcia + +.PHONY: $(patsubst %, _modinst_%, $(SUBDIRS)) +$(patsubst %, _modinst_%, $(SUBDIRS)) : + $(MAKE) -C $(patsubst _modinst_%, %, $@) modules_install + +# modules disabled.... + +else +modules modules_install: dummy + @echo + @echo "The present kernel configuration has modules disabled." + @echo "Type 'make config' and enable loadable module support." + @echo "Then build a kernel with module support enabled." + @echo + @exit 1 +endif + +clean: archclean + find . \( -name '*.[oas]' -o -name core -o -name '.*.flags' \) -type f -print \ + | grep -v lxdialog/ | xargs rm -f + rm -f $(CLEAN_FILES) + rm -rf $(CLEAN_DIRS) + $(MAKE) -C Documentation/DocBook clean + +mrproper: clean archmrproper + find . \( -size 0 -o -name .depend \) -type f -print | xargs rm -f + rm -f $(MRPROPER_FILES) + rm -rf $(MRPROPER_DIRS) + $(MAKE) -C Documentation/DocBook mrproper + +distclean: mrproper + rm -f core `find . \( -not -type d \) -and \ + \( -name '*.orig' -o -name '*.rej' -o -name '*~' \ + -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \ + -o -name '.*.rej' -o -name '.SUMS' -o -size 0 \) -type f -print` TAGS tags + +backup: mrproper + cd .. && tar cf - linux/ | gzip -9 > backup.gz + sync + +sgmldocs: + chmod 755 $(TOPDIR)/scripts/docgen + chmod 755 $(TOPDIR)/scripts/gen-all-syms + chmod 755 $(TOPDIR)/scripts/kernel-doc + $(MAKE) -C $(TOPDIR)/Documentation/DocBook books + +psdocs: sgmldocs + $(MAKE) -C Documentation/DocBook ps + +pdfdocs: sgmldocs + $(MAKE) -C Documentation/DocBook pdf + +htmldocs: sgmldocs + $(MAKE) -C Documentation/DocBook html + +sums: + find . -type f -print | sort | xargs sum > .SUMS + +dep-files: scripts/mkdep archdep include/linux/version.h + scripts/mkdep -- init/*.c > .depend + scripts/mkdep -- `find $(FINDHPATH) -name SCCS -prune -o -follow -name \*.h ! -name modversions.h -print` > .hdepend + $(MAKE) $(patsubst %,_sfdep_%,$(SUBDIRS)) _FASTDEP_ALL_SUB_DIRS="$(SUBDIRS)" +ifdef CONFIG_MODVERSIONS + $(MAKE) update-modverfile +endif + +ifdef CONFIG_MODVERSIONS +MODVERFILE := $(TOPDIR)/include/linux/modversions.h +else +MODVERFILE := +endif +export MODVERFILE + +depend dep: dep-files + +checkconfig: + find * -name '*.[hcS]' -type f -print | sort | xargs $(PERL) -w scripts/checkconfig.pl + +checkhelp: + find * -name [cC]onfig.in -print | sort | xargs $(PERL) -w scripts/checkhelp.pl + +checkincludes: + find * -name '*.[hcS]' -type f -print | sort | xargs $(PERL) -w scripts/checkincludes.pl + +ifdef CONFIGURATION +..$(CONFIGURATION): + @echo + @echo "You have a bad or nonexistent" .$(CONFIGURATION) ": running 'make" $(CONFIGURATION)"'" + @echo + $(MAKE) $(CONFIGURATION) + @echo + @echo "Successful. Try re-making (ignore the error that follows)" + @echo + exit 1 + +#dummy: ..$(CONFIGURATION) +dummy: + +else + +dummy: + +endif + +include Rules.make + +# +# This generates dependencies for the .h files. +# + +scripts/mkdep: scripts/mkdep.c + $(HOSTCC) $(HOSTCFLAGS) -o scripts/mkdep scripts/mkdep.c + +scripts/split-include: scripts/split-include.c + $(HOSTCC) $(HOSTCFLAGS) -o scripts/split-include scripts/split-include.c + +# +# RPM target +# +# If you do a make spec before packing the tarball you can rpm -ta it +# +spec: + . scripts/mkspec >kernel.spec + +# +# Build a tar ball, generate an rpm from it and pack the result +# There arw two bits of magic here +# 1) The use of /. to avoid tar packing just the symlink +# 2) Removing the .dep files as they have source paths in them that +# will become invalid +# +rpm: clean spec + find . \( -size 0 -o -name .depend -o -name .hdepend \) -type f -print | xargs rm -f + set -e; \ + cd $(TOPDIR)/.. ; \ + ln -sf $(TOPDIR) $(KERNELPATH) ; \ + tar -cvz --exclude CVS -f $(KERNELPATH).tar.gz $(KERNELPATH)/. ; \ + rm $(KERNELPATH) ; \ + cd $(TOPDIR) ; \ + . scripts/mkversion > .version ; \ + rpm -ta $(TOPDIR)/../$(KERNELPATH).tar.gz ; \ + rm $(TOPDIR)/../$(KERNELPATH).tar.gz diff -urN linux-2.4.17/arch/i386/Makefile linux_umopenmosix/arch/i386/Makefile --- linux-2.4.17/arch/i386/Makefile Thu Apr 12 22:20:31 2001 +++ linux_umopenmosix/arch/i386/Makefile Sun Jun 23 12:40:10 2002 @@ -138,6 +138,9 @@ install: vmlinux @$(MAKEBOOT) BOOTIMAGE=bzImage install +install1: + @$(MAKEBOOT) BOOTIMAGE=bzImage install + archclean: @$(MAKEBOOT) clean diff -urN linux-2.4.17/arch/i386/config.in linux_umopenmosix/arch/i386/config.in --- linux-2.4.17/arch/i386/config.in Fri Dec 21 19:41:53 2001 +++ linux_umopenmosix/arch/i386/config.in Sun Jun 23 12:40:10 2002 @@ -11,6 +11,31 @@ define_bool CONFIG_UID16 y mainmenu_option next_comment +comment 'MOSIX' +bool 'MOSIX process migration support' CONFIG_MOSIX +if [ "$CONFIG_MOSIX" = "y" ]; then + bool 'Support clusters with a complex network topology' CONFIG_MOSIX_TOPOLOGY + if [ "$CONFIG_MOSIX_TOPOLOGY" = "y" ]; then + int 'Maximum network-topology complexity to support (2-10)' CONFIG_MOSIX_MAXTOPOLOGY 4 + fi + + bool 'MOSIX Kernel Debugger' CONFIG_MOSIX_UDB + if [ "$CONFIG_MOSIX_UDB" = "y" ]; then + bool 'MOSIX Kernel Debugging Code' CONFIG_MOSIX_DEBUG + bool 'Allow migration to self (for easyier testing)' CONFIG_MOSIX_CHEAT_MIGSELF + bool 'Process-arrival messages' CONFIG_MOSIX_WEEEEEEEEE + fi + bool 'MOSIX Kernel Diagnostics' CONFIG_MOSIX_DIAG + bool 'Stricter security on MOSIX ports' CONFIG_MOSIX_SECUREPORTS + int 'Level of process-identity disclosure (0-3)' CONFIG_MOSIX_DISCLOSURE 1 + bool 'Create the kernel with a "-mosix" extension' CONFIG_MOSIX_EXTMOSIX + bool 'Direct File-System Access' CONFIG_MOSIX_DFSA + bool 'MOSIX File-System' CONFIG_MOSIX_FS + bool 'Poll/Select exceptions on pipes' CONFIG_MOSIX_PIPE_EXCEPTIONS +fi +endmenu + +mainmenu_option next_comment comment 'Code maturity level options' bool 'Prompt for development and/or incomplete code/drivers' CONFIG_EXPERIMENTAL endmenu diff -urN linux-2.4.17/arch/i386/config.in.org linux_umopenmosix/arch/i386/config.in.org --- linux-2.4.17/arch/i386/config.in.org Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/i386/config.in.org Sun Jun 23 12:40:10 2002 @@ -0,0 +1,443 @@ +# +# For a description of the syntax of this configuration file, +# see Documentation/kbuild/config-language.txt. +# +mainmenu_name "Linux Kernel Configuration" + +define_bool CONFIG_X86 y +define_bool CONFIG_ISA y +define_bool CONFIG_SBUS n + +define_bool CONFIG_UID16 y + +mainmenu_option next_comment +comment 'MOSIX' +bool 'MOSIX process migration support' CONFIG_MOSIX +if [ "$CONFIG_MOSIX" = "y" ]; then + bool 'Support clusters with a complex network topology' CONFIG_MOSIX_TOPOLOGY + if [ "$CONFIG_MOSIX_TOPOLOGY" = "y" ]; then + int 'Maximum network-topology complexity to support (2-10)' CONFIG_MOSIX_MAXTOPOLOGY 4 + fi + + bool 'MOSIX Kernel Debugger' CONFIG_MOSIX_UDB + if [ "$CONFIG_MOSIX_UDB" = "y" ]; then + bool 'MOSIX Kernel Debugging Code' CONFIG_MOSIX_DEBUG + bool 'Allow migration to self (for easyier testing)' CONFIG_MOSIX_CHEAT_MIGSELF + bool 'Process-arrival messages' CONFIG_MOSIX_WEEEEEEEEE + fi + bool 'MOSIX Kernel Diagnostics' CONFIG_MOSIX_DIAG + bool 'Stricter security on MOSIX ports' CONFIG_MOSIX_SECUREPORTS + int 'Level of process-identity disclosure (0-3)' CONFIG_MOSIX_DISCLOSURE 1 + bool 'Create the kernel with a "-mosix" extension' CONFIG_MOSIX_EXTMOSIX + bool 'Direct File-System Access' CONFIG_MOSIX_DFSA + bool 'MOSIX File-System' CONFIG_MOSIX_FS + bool 'Poll/Select exceptions on pipes' CONFIG_MOSIX_PIPE_EXCEPTIONS +fi +endmenu + +mainmenu_option next_comment +comment 'Code maturity level options' +bool 'Prompt for development and/or incomplete code/drivers' CONFIG_EXPERIMENTAL +endmenu + +mainmenu_option next_comment +comment 'Loadable module support' +bool 'Enable loadable module support' CONFIG_MODULES +if [ "$CONFIG_MODULES" = "y" ]; then + bool ' Set version information on all module symbols' CONFIG_MODVERSIONS + bool ' Kernel module loader' CONFIG_KMOD +fi +endmenu + +mainmenu_option next_comment +comment 'Processor type and features' +choice 'Processor family' \ + "386 CONFIG_M386 \ + 486 CONFIG_M486 \ + 586/K5/5x86/6x86/6x86MX CONFIG_M586 \ + Pentium-Classic CONFIG_M586TSC \ + Pentium-MMX CONFIG_M586MMX \ + Pentium-Pro/Celeron/Pentium-II CONFIG_M686 \ + Pentium-III/Celeron(Coppermine) CONFIG_MPENTIUMIII \ + Pentium-4 CONFIG_MPENTIUM4 \ + K6/K6-II/K6-III CONFIG_MK6 \ + Athlon/Duron/K7 CONFIG_MK7 \ + Crusoe CONFIG_MCRUSOE \ + Winchip-C6 CONFIG_MWINCHIPC6 \ + Winchip-2 CONFIG_MWINCHIP2 \ + Winchip-2A/Winchip-3 CONFIG_MWINCHIP3D \ + CyrixIII/C3 CONFIG_MCYRIXIII" Pentium-Pro +# +# Define implied options from the CPU selection here +# + +if [ "$CONFIG_M386" = "y" ]; then + define_bool CONFIG_X86_CMPXCHG n + define_bool CONFIG_X86_XADD n + define_int CONFIG_X86_L1_CACHE_SHIFT 4 + define_bool CONFIG_RWSEM_GENERIC_SPINLOCK y + define_bool CONFIG_RWSEM_XCHGADD_ALGORITHM n + define_bool CONFIG_X86_PPRO_FENCE y +else + define_bool CONFIG_X86_WP_WORKS_OK y + define_bool CONFIG_X86_INVLPG y + define_bool CONFIG_X86_CMPXCHG y + define_bool CONFIG_X86_XADD y + define_bool CONFIG_X86_BSWAP y + define_bool CONFIG_X86_POPAD_OK y + define_bool CONFIG_RWSEM_GENERIC_SPINLOCK n + define_bool CONFIG_RWSEM_XCHGADD_ALGORITHM y +fi +if [ "$CONFIG_M486" = "y" ]; then + define_int CONFIG_X86_L1_CACHE_SHIFT 4 + define_bool CONFIG_X86_USE_STRING_486 y + define_bool CONFIG_X86_ALIGNMENT_16 y + define_bool CONFIG_X86_PPRO_FENCE y +fi +if [ "$CONFIG_M586" = "y" ]; then + define_int CONFIG_X86_L1_CACHE_SHIFT 5 + define_bool CONFIG_X86_USE_STRING_486 y + define_bool CONFIG_X86_ALIGNMENT_16 y + define_bool CONFIG_X86_PPRO_FENCE y +fi +if [ "$CONFIG_M586TSC" = "y" ]; then + define_int CONFIG_X86_L1_CACHE_SHIFT 5 + define_bool CONFIG_X86_USE_STRING_486 y + define_bool CONFIG_X86_ALIGNMENT_16 y + define_bool CONFIG_X86_TSC y + define_bool CONFIG_X86_PPRO_FENCE y +fi +if [ "$CONFIG_M586MMX" = "y" ]; then + define_int CONFIG_X86_L1_CACHE_SHIFT 5 + define_bool CONFIG_X86_USE_STRING_486 y + define_bool CONFIG_X86_ALIGNMENT_16 y + define_bool CONFIG_X86_TSC y + define_bool CONFIG_X86_GOOD_APIC y + define_bool CONFIG_X86_PPRO_FENCE y +fi +if [ "$CONFIG_M686" = "y" ]; then + define_int CONFIG_X86_L1_CACHE_SHIFT 5 + define_bool CONFIG_X86_TSC y + define_bool CONFIG_X86_GOOD_APIC y + define_bool CONFIG_X86_PGE y + define_bool CONFIG_X86_USE_PPRO_CHECKSUM y + define_bool CONFIG_X86_PPRO_FENCE y +fi +if [ "$CONFIG_MPENTIUMIII" = "y" ]; then + define_int CONFIG_X86_L1_CACHE_SHIFT 5 + define_bool CONFIG_X86_TSC y + define_bool CONFIG_X86_GOOD_APIC y + define_bool CONFIG_X86_PGE y + define_bool CONFIG_X86_USE_PPRO_CHECKSUM y +fi +if [ "$CONFIG_MPENTIUM4" = "y" ]; then + define_int CONFIG_X86_L1_CACHE_SHIFT 7 + define_bool CONFIG_X86_TSC y + define_bool CONFIG_X86_GOOD_APIC y + define_bool CONFIG_X86_PGE y + define_bool CONFIG_X86_USE_PPRO_CHECKSUM y +fi +if [ "$CONFIG_MK6" = "y" ]; then + define_int CONFIG_X86_L1_CACHE_SHIFT 5 + define_bool CONFIG_X86_ALIGNMENT_16 y + define_bool CONFIG_X86_TSC y + define_bool CONFIG_X86_USE_PPRO_CHECKSUM y +fi +if [ "$CONFIG_MK7" = "y" ]; then + define_int CONFIG_X86_L1_CACHE_SHIFT 6 + define_bool CONFIG_X86_TSC y + define_bool CONFIG_X86_GOOD_APIC y + define_bool CONFIG_X86_USE_3DNOW y + define_bool CONFIG_X86_PGE y + define_bool CONFIG_X86_USE_PPRO_CHECKSUM y +fi +if [ "$CONFIG_MCYRIXIII" = "y" ]; then + define_int CONFIG_X86_L1_CACHE_SHIFT 5 + define_bool CONFIG_X86_TSC y + define_bool CONFIG_X86_ALIGNMENT_16 y + define_bool CONFIG_X86_USE_3DNOW y + define_bool CONFIG_X86_USE_PPRO_CHECKSUM y +fi +if [ "$CONFIG_MCRUSOE" = "y" ]; then + define_int CONFIG_X86_L1_CACHE_SHIFT 5 + define_bool CONFIG_X86_TSC y +fi +if [ "$CONFIG_MWINCHIPC6" = "y" ]; then + define_int CONFIG_X86_L1_CACHE_SHIFT 5 + define_bool CONFIG_X86_ALIGNMENT_16 y + define_bool CONFIG_X86_USE_PPRO_CHECKSUM y +fi +if [ "$CONFIG_MWINCHIP2" = "y" ]; then + define_int CONFIG_X86_L1_CACHE_SHIFT 5 + define_bool CONFIG_X86_ALIGNMENT_16 y + define_bool CONFIG_X86_TSC y + define_bool CONFIG_X86_USE_PPRO_CHECKSUM y +fi +if [ "$CONFIG_MWINCHIP3D" = "y" ]; then + define_int CONFIG_X86_L1_CACHE_SHIFT 5 + define_bool CONFIG_X86_ALIGNMENT_16 y + define_bool CONFIG_X86_TSC y + define_bool CONFIG_X86_USE_PPRO_CHECKSUM y +fi +tristate 'Toshiba Laptop support' CONFIG_TOSHIBA +tristate 'Dell laptop support' CONFIG_I8K + +tristate '/dev/cpu/microcode - Intel IA32 CPU microcode support' CONFIG_MICROCODE +tristate '/dev/cpu/*/msr - Model-specific register support' CONFIG_X86_MSR +tristate '/dev/cpu/*/cpuid - CPU information support' CONFIG_X86_CPUID + +choice 'High Memory Support' \ + "off CONFIG_NOHIGHMEM \ + 4GB CONFIG_HIGHMEM4G \ + 64GB CONFIG_HIGHMEM64G" off +if [ "$CONFIG_HIGHMEM4G" = "y" ]; then + define_bool CONFIG_HIGHMEM y +fi +if [ "$CONFIG_HIGHMEM64G" = "y" ]; then + define_bool CONFIG_HIGHMEM y + define_bool CONFIG_X86_PAE y +fi + +bool 'Math emulation' CONFIG_MATH_EMULATION +bool 'MTRR (Memory Type Range Register) support' CONFIG_MTRR +bool 'Symmetric multi-processing support' CONFIG_SMP +if [ "$CONFIG_SMP" != "y" ]; then + bool 'Local APIC support on uniprocessors' CONFIG_X86_UP_APIC + dep_bool 'IO-APIC support on uniprocessors' CONFIG_X86_UP_IOAPIC $CONFIG_X86_UP_APIC + if [ "$CONFIG_X86_UP_APIC" = "y" ]; then + define_bool CONFIG_X86_LOCAL_APIC y + fi + if [ "$CONFIG_X86_UP_IOAPIC" = "y" ]; then + define_bool CONFIG_X86_IO_APIC y + fi +else + bool 'Multiquad NUMA system' CONFIG_MULTIQUAD +fi + +if [ "$CONFIG_SMP" = "y" -a "$CONFIG_X86_CMPXCHG" = "y" ]; then + define_bool CONFIG_HAVE_DEC_LOCK y +fi +endmenu + +mainmenu_option next_comment +comment 'General setup' + +bool 'Networking support' CONFIG_NET + +# Visual Workstation support is utterly broken. +# If you want to see it working mail an VW540 to hch@infradead.org 8) +#bool 'SGI Visual Workstation support' CONFIG_VISWS +if [ "$CONFIG_VISWS" = "y" ]; then + define_bool CONFIG_X86_VISWS_APIC y + define_bool CONFIG_X86_LOCAL_APIC y + define_bool CONFIG_PCI y +else + if [ "$CONFIG_SMP" = "y" ]; then + define_bool CONFIG_X86_IO_APIC y + define_bool CONFIG_X86_LOCAL_APIC y + fi + bool 'PCI support' CONFIG_PCI + if [ "$CONFIG_PCI" = "y" ]; then + choice ' PCI access mode' \ + "BIOS CONFIG_PCI_GOBIOS \ + Direct CONFIG_PCI_GODIRECT \ + Any CONFIG_PCI_GOANY" Any + if [ "$CONFIG_PCI_GOBIOS" = "y" -o "$CONFIG_PCI_GOANY" = "y" ]; then + define_bool CONFIG_PCI_BIOS y + fi + if [ "$CONFIG_PCI_GODIRECT" = "y" -o "$CONFIG_PCI_GOANY" = "y" ]; then + define_bool CONFIG_PCI_DIRECT y + fi + fi +fi + +source drivers/pci/Config.in + +bool 'EISA support' CONFIG_EISA + +if [ "$CONFIG_VISWS" != "y" ]; then + bool 'MCA support' CONFIG_MCA +else + define_bool CONFIG_MCA n +fi + +bool 'Support for hot-pluggable devices' CONFIG_HOTPLUG + +if [ "$CONFIG_HOTPLUG" = "y" ] ; then + source drivers/pcmcia/Config.in + source drivers/hotplug/Config.in +else + define_bool CONFIG_PCMCIA n + define_bool CONFIG_HOTPLUG_PCI n +fi + +bool 'System V IPC' CONFIG_SYSVIPC +bool 'BSD Process Accounting' CONFIG_BSD_PROCESS_ACCT +bool 'Sysctl support' CONFIG_SYSCTL +if [ "$CONFIG_PROC_FS" = "y" ]; then + choice 'Kernel core (/proc/kcore) format' \ + "ELF CONFIG_KCORE_ELF \ + A.OUT CONFIG_KCORE_AOUT" ELF +fi +tristate 'Kernel support for a.out binaries' CONFIG_BINFMT_AOUT +tristate 'Kernel support for ELF binaries' CONFIG_BINFMT_ELF +tristate 'Kernel support for MISC binaries' CONFIG_BINFMT_MISC + +bool 'Power Management support' CONFIG_PM + +if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then + dep_bool ' ACPI support' CONFIG_ACPI $CONFIG_PM + + if [ "$CONFIG_ACPI" != "n" ]; then + source drivers/acpi/Config.in + fi +fi + +dep_tristate ' Advanced Power Management BIOS support' CONFIG_APM $CONFIG_PM +if [ "$CONFIG_APM" != "n" ]; then + bool ' Ignore USER SUSPEND' CONFIG_APM_IGNORE_USER_SUSPEND + bool ' Enable PM at boot time' CONFIG_APM_DO_ENABLE + bool ' Make CPU Idle calls when idle' CONFIG_APM_CPU_IDLE + bool ' Enable console blanking using APM' CONFIG_APM_DISPLAY_BLANK + bool ' RTC stores time in GMT' CONFIG_APM_RTC_IS_GMT + bool ' Allow interrupts during APM BIOS calls' CONFIG_APM_ALLOW_INTS + bool ' Use real mode APM BIOS call to power off' CONFIG_APM_REAL_MODE_POWER_OFF +fi + +endmenu + +source drivers/mtd/Config.in + +source drivers/parport/Config.in + +source drivers/pnp/Config.in + +source drivers/block/Config.in + +source drivers/md/Config.in + +if [ "$CONFIG_NET" = "y" ]; then + source net/Config.in +fi + +source drivers/telephony/Config.in + +mainmenu_option next_comment +comment 'ATA/IDE/MFM/RLL support' + +tristate 'ATA/IDE/MFM/RLL support' CONFIG_IDE + +if [ "$CONFIG_IDE" != "n" ]; then + source drivers/ide/Config.in +else + define_bool CONFIG_BLK_DEV_IDE_MODES n + define_bool CONFIG_BLK_DEV_HD n +fi +endmenu + +mainmenu_option next_comment +comment 'SCSI support' + +tristate 'SCSI support' CONFIG_SCSI + +if [ "$CONFIG_SCSI" != "n" ]; then + source drivers/scsi/Config.in +fi +endmenu + +source drivers/message/fusion/Config.in + +source drivers/ieee1394/Config.in + +source drivers/message/i2o/Config.in + +if [ "$CONFIG_NET" = "y" ]; then + mainmenu_option next_comment + comment 'Network device support' + + bool 'Network device support' CONFIG_NETDEVICES + if [ "$CONFIG_NETDEVICES" = "y" ]; then + source drivers/net/Config.in + if [ "$CONFIG_ATM" = "y" ]; then + source drivers/atm/Config.in + fi + fi + endmenu +fi + +source net/ax25/Config.in + +source net/irda/Config.in + +mainmenu_option next_comment +comment 'ISDN subsystem' +if [ "$CONFIG_NET" != "n" ]; then + tristate 'ISDN support' CONFIG_ISDN + if [ "$CONFIG_ISDN" != "n" ]; then + source drivers/isdn/Config.in + fi +fi +endmenu + +mainmenu_option next_comment +comment 'Old CD-ROM drivers (not SCSI, not IDE)' + +bool 'Support non-SCSI/IDE/ATAPI CDROM drives' CONFIG_CD_NO_IDESCSI +if [ "$CONFIG_CD_NO_IDESCSI" != "n" ]; then + source drivers/cdrom/Config.in +fi +endmenu + +# +# input before char - char/joystick depends on it. As does USB. +# +source drivers/input/Config.in +source drivers/char/Config.in + +#source drivers/misc/Config.in + +source drivers/media/Config.in + +source fs/Config.in + +if [ "$CONFIG_VT" = "y" ]; then + mainmenu_option next_comment + comment 'Console drivers' + bool 'VGA text console' CONFIG_VGA_CONSOLE + bool 'Video mode selection support' CONFIG_VIDEO_SELECT + if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then + tristate 'MDA text console (dual-headed) (EXPERIMENTAL)' CONFIG_MDA_CONSOLE + source drivers/video/Config.in + fi + endmenu +fi + +mainmenu_option next_comment +comment 'Sound' + +tristate 'Sound card support' CONFIG_SOUND +if [ "$CONFIG_SOUND" != "n" ]; then + source drivers/sound/Config.in +fi +endmenu + +source drivers/usb/Config.in + +if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then + source net/bluetooth/Config.in +fi + +mainmenu_option next_comment +comment 'Kernel hacking' + +bool 'Kernel debugging' CONFIG_DEBUG_KERNEL +if [ "$CONFIG_DEBUG_KERNEL" != "n" ]; then + bool ' Debug high memory support' CONFIG_DEBUG_HIGHMEM + bool ' Debug memory allocations' CONFIG_DEBUG_SLAB + bool ' Memory mapped I/O debugging' CONFIG_DEBUG_IOVIRT + bool ' Magic SysRq key' CONFIG_MAGIC_SYSRQ + bool ' Spinlock debugging' CONFIG_DEBUG_SPINLOCK + bool ' Verbose BUG() reporting (adds 70K)' CONFIG_DEBUG_BUGVERBOSE +fi + +endmenu diff -urN linux-2.4.17/arch/i386/defconfig linux_umopenmosix/arch/i386/defconfig --- linux-2.4.17/arch/i386/defconfig Mon Nov 12 21:59:03 2001 +++ linux_umopenmosix/arch/i386/defconfig Sun Jun 23 12:40:10 2002 @@ -1,6 +1,26 @@ # # Automatically generated make config: don't edit # + +# +# MOSIX options +# + +CONFIG_MOSIX=y +# CONFIG_MOSIX_TOPOLOGY is not set +CONFIG_MOSIX_MAXTOPOLOGY=4 +# CONFIG_MOSIX_UDB is not set +# CONFIG_MOSIX_CHEAT_MIGSELF is not set +# CONFIG_MOSIX_DEBUG is not set +# CONFIG_MOSIX_WEEEEEEEEE is not set +CONFIG_MOSIX_DISCLOSURE=1 +# CONFIG_MOSIX_EXTMOSIX is not set +CONFIG_MOSIX_DIAG=y +CONFIG_MOSIX_SECUREPORTS=y +# CONFIG_MOSIX_DFSA is not set +# CONFIG_MOSIX_FS is not set +# CONFIG_MOSIX_PIPE_EXCEPTIONS is not set + CONFIG_X86=y CONFIG_ISA=y # CONFIG_SBUS is not set diff -urN linux-2.4.17/arch/i386/kernel/Makefile linux_umopenmosix/arch/i386/kernel/Makefile --- linux-2.4.17/arch/i386/kernel/Makefile Sat Nov 10 00:21:21 2001 +++ linux_umopenmosix/arch/i386/kernel/Makefile Sun Jun 23 12:40:10 2002 @@ -42,3 +42,14 @@ obj-$(CONFIG_X86_VISWS_APIC) += visws_apic.o include $(TOPDIR)/Rules.make + +ifdef CONFIG_MOSIX +entry.o: ./mosasm.H + +offset: offset.c $(TOPDIR)/include/linux/config.h $(TOPDIR)/include/linux/types.h $(TOPDIR)/include/linux/sched.h $(TOPDIR)/include/linux/signal.h $(TOPDIR)/include/linux/sys.h $(TOPDIR)/include/linux/kernel.h + $(HOSTCC) $(HOSTCFLAGS) -D__KERNEL__ -I$(TOPDIR)/include -o offset offset.c + +./mosasm.H: offset entry.S + ./offset < entry.S > mosasm.H + +endif diff -urN linux-2.4.17/arch/i386/kernel/entry.S linux_umopenmosix/arch/i386/kernel/entry.S --- linux-2.4.17/arch/i386/kernel/entry.S Sat Nov 3 03:18:49 2001 +++ linux_umopenmosix/arch/i386/kernel/entry.S Sun Jun 23 12:40:10 2002 @@ -46,6 +46,10 @@ #include #include +#ifdef CONFIG_MOSIX +#include "mosasm.H" +#endif /* CONFIG_MOSIX */ + EBX = 0x00 ECX = 0x04 EDX = 0x08 @@ -179,10 +183,16 @@ pushl %ebx call SYMBOL_NAME(schedule_tail) addl $4, %esp +#ifdef CONFIG_MOSIX +ENTRY(ret_from_kickstart) + GET_CURRENT(%ebx) + jmp ret_from_sys_call +#else GET_CURRENT(%ebx) testb $0x02,tsk_ptrace(%ebx) # PT_TRACESYS jne tracesys_exit jmp ret_from_sys_call +#endif /* CONFIG_MOSIX */ /* * Return to user mode is not as complex as all this looks, @@ -197,16 +207,50 @@ GET_CURRENT(%ebx) testb $0x02,tsk_ptrace(%ebx) # PT_TRACESYS jne tracesys +/* conflict resolution - Qlusters */ +#ifdef CONFIG_MOSIX_UDB + pushl %eax + call SYMBOL_NAME(sys_call_trace) # display syscalls for debugging + popl %eax +#endif /* CONFIG_MOSIX_UDB */ cmpl $(NR_syscalls),%eax jae badsys +#ifdef CONFIG_MOSIX + testl $(DTRACESYS1|DTRACESYS2),DFLAGS(%ebx) + jne adjust_trace_before_syscall +adjusted_trace: + testb $DREMOTE,DFLAGS(%ebx) + je local_syscall +on_remote: + pushl %eax + call *SYMBOL_NAME(remote_sys_call_table)(,%eax,4) + addl $4,%esp + movl %eax,EAX(%esp) + jmp ret_from_sys_call +local_syscall: +#endif /* CONFIG_MOSIX */ call *SYMBOL_NAME(sys_call_table)(,%eax,4) movl %eax,EAX(%esp) # save the return value +#ifdef CONFIG_MOSIX + call SYMBOL_NAME(mosix_local_syscall) +#endif /* CONFIG_MOSIX */ ENTRY(ret_from_sys_call) +#ifdef CONFIG_MOSIX + testl $(DTRACESYS1|DTRACESYS2),DFLAGS(%ebx) + jne adjust_trace_before_syscall +ret_check_reschedule: +#endif /* CONFIG_MOSIX */ cli # need_resched and signals atomic test cmpl $0,need_resched(%ebx) jne reschedule cmpl $0,sigpending(%ebx) jne signal_return +#ifdef CONFIG_MOSIX +straight_to_mosix: + call SYMBOL_NAME(mosix_pre_usermode_actions) + testl %eax,%eax + jne ret_from_sys_call +#endif /* CONFIG_MOSIX */ restore_all: RESTORE_ALL @@ -218,7 +262,11 @@ jne v86_signal_return xorl %edx,%edx call SYMBOL_NAME(do_signal) +#ifdef CONFIG_MOSIX + jmp straight_to_mosix +#else jmp restore_all +#endif /* CONFIG_MOSIX */ ALIGN v86_signal_return: @@ -226,18 +274,41 @@ movl %eax,%esp xorl %edx,%edx call SYMBOL_NAME(do_signal) +#ifdef CONFIG_MOSIX + jmp straight_to_mosix +#else jmp restore_all +#endif /* CONFIG_MOSIX */ ALIGN tracesys: movl $-ENOSYS,EAX(%esp) call SYMBOL_NAME(syscall_trace) +#ifdef CONFIG_MOSIX +adjust_trace_before_syscall: # only arrive here with DTRACESYS(1|2) + testl $DDEPUTY,DFLAGS(%ebx) + jne straight_to_mosix # no mess with signals/syscalls/tracesys + testl $DREMOTE,DFLAGS(%ebx) + je no_need_to_unsync + call wait_for_permission_to_continue +no_need_to_unsync: + testl $DTRACESYS2,DFLAGS(%ebx) + jne second_tracesys # skipping system-call + orl $DTRACESYS2,DFLAGS(%ebx) # next time we skip the system-call + movl $-ENOSYS,EAX(%esp) + movl ORIG_EAX(%esp),%eax + cmpl $(NR_syscalls),%eax + jae second_tracesys # prevent system-call out of range trick + jmp adjusted_trace # now do the system-call +second_tracesys: # note: "syscall_trace" clears the flags +#else movl ORIG_EAX(%esp),%eax cmpl $(NR_syscalls),%eax jae tracesys_exit call *SYMBOL_NAME(sys_call_table)(,%eax,4) movl %eax,EAX(%esp) # save the return value tracesys_exit: +#endif /* CONFIG_MOSIX */ call SYMBOL_NAME(syscall_trace) jmp ret_from_sys_call badsys: @@ -251,7 +322,11 @@ movl EFLAGS(%esp),%eax # mix EFLAGS and CS movb CS(%esp),%al testl $(VM_MASK | 3),%eax # return to VM86 mode or non-supervisor? +#ifdef CONFIG_MOSIX + jne ret_check_reschedule +#else jne ret_from_sys_call +#endif /* CONFIG_MOSIX */ jmp restore_all ALIGN @@ -259,6 +334,73 @@ call SYMBOL_NAME(schedule) # test jmp ret_from_sys_call +#ifdef CONFIG_MOSIX +/* + * call_with_regs(caddr_t routine, pt_regs *before, pt_regs *after) + * pushes the "before" regs on the stack and calls routine, + * then places the possibly-modified registers in "after" + * (which may possibly equal "before"). + * Also, set "current->altregs" to the pushed registers, then restores it. + */ +ENTRY(call_with_regs) + pushl %ebx + GET_CURRENT(%ebx) + pushl ALTREGS(%ebx) + movl 16(%esp),%eax + pushl 56(%eax) + pushl 52(%eax) + pushl 48(%eax) + pushl 44(%eax) + pushl 40(%eax) + pushl 36(%eax) + pushl 32(%eax) + pushl 28(%eax) + pushl 24(%eax) + pushl 20(%eax) + pushl 16(%eax) + pushl 12(%eax) + pushl 8(%eax) + pushl 4(%eax) + pushl 0(%eax) + movl %esp,ALTREGS(%ebx) + movl 72(%esp),%eax + call *%eax + movl 80(%esp),%edx + popl %ecx + movl %ecx,0(%edx) + popl %ecx + movl %ecx,4(%edx) + popl %ecx + movl %ecx,8(%edx) + popl %ecx + movl %ecx,12(%edx) + popl %ecx + movl %ecx,16(%edx) + popl %ecx + movl %ecx,20(%edx) + popl %ecx + movl %ecx,24(%edx) + popl %ecx + movl %ecx,28(%edx) + popl %ecx + movl %ecx,32(%edx) + popl %ecx + movl %ecx,36(%edx) + popl %ecx + movl %ecx,40(%edx) + popl %ecx + movl %ecx,44(%edx) + popl %ecx + movl %ecx,48(%edx) + popl %ecx + movl %ecx,52(%edx) + popl %ecx + movl %ecx,56(%edx) + popl ALTREGS(%ebx) + popl %ebx + ret +#endif /* CONFIG_MOSIX */ + ENTRY(divide_error) pushl $0 # no error code pushl $ SYMBOL_NAME(do_divide_error) @@ -402,7 +544,11 @@ .long SYMBOL_NAME(sys_read) .long SYMBOL_NAME(sys_write) .long SYMBOL_NAME(sys_open) /* 5 */ +#ifdef CONFIG_MOSIX_DFSA + .long SYMBOL_NAME(sys_close_syscall) +#else .long SYMBOL_NAME(sys_close) +#endif /* CONFIG_MOSIX_DFSA */ .long SYMBOL_NAME(sys_waitpid) .long SYMBOL_NAME(sys_creat) .long SYMBOL_NAME(sys_link) diff -urN linux-2.4.17/arch/i386/kernel/i387.c linux_umopenmosix/arch/i386/kernel/i387.c --- linux-2.4.17/arch/i386/kernel/i387.c Fri Feb 23 20:09:08 2001 +++ linux_umopenmosix/arch/i386/kernel/i387.c Sun Jun 23 12:40:10 2002 @@ -520,3 +520,66 @@ return fpvalid; } + +#ifdef CONFIG_MOSIX + +int +has_fxsr(void) +{ + return(cpu_has_fxsr); +} + +void +fsave_to_fxsave(union i387_union *from, union i387_union *to) +{ + int i; + long *fcp, *tcp; + + to->fxsave.cwd = from->fsave.cwd; + to->fxsave.swd = from->fsave.swd; + to->fxsave.twd = twd_i387_to_fxsr(from->fsave.twd); + to->fxsave.fop = from->fxsave.padding[0]; + to->fxsave.fip = from->fsave.fip; + to->fxsave.fcs = from->fsave.fcs; + to->fxsave.foo = from->fsave.foo; + to->fxsave.mxcsr = from->fxsave.padding[1]; + to->fxsave.fos = from->fsave.fos; + for(fcp = from->fsave.st_space , tcp = to->fxsave.st_space , + i = 0 ; i < 8 ; i++) + { + *tcp++ = *fcp++; + *tcp++ = *fcp++; + *tcp = *((unsigned short *)fcp)++; + tcp += 2; + } + memcpy(to->fxsave.xmm_space, from->fxsave.xmm_space, + sizeof(from->fxsave.xmm_space)); +} + +void +fxsave_to_fsave(union i387_union *from, union i387_union *to) +{ + int i; + long *fcp, *tcp; + + to->fsave.cwd = from->fxsave.cwd; + to->fsave.swd = from->fxsave.swd; + to->fsave.twd = twd_fxsr_to_i387(&from->fxsave); + to->fsave.fip = from->fxsave.fip; + to->fsave.fcs = from->fxsave.fcs; + to->fsave.foo = from->fxsave.foo; + to->fsave.fos = from->fxsave.fos; + to->fxsave.padding[0] = from->fxsave.fop; + to->fxsave.padding[1] = from->fxsave.mxcsr; + for(fcp = from->fxsave.st_space , tcp = to->fsave.st_space , + i = 0 ; i < 8 ; i++) + { + *tcp++ = *fcp++; + *tcp++ = *fcp++; + *((unsigned short *)tcp)++ = *fcp; + fcp += 2; + } + memcpy(to->fxsave.xmm_space, from->fxsave.xmm_space, + sizeof(to->fxsave.xmm_space)); +} +#endif /* CONFIG_MOSIX */ diff -urN linux-2.4.17/arch/i386/kernel/ioport.c linux_umopenmosix/arch/i386/kernel/ioport.c --- linux-2.4.17/arch/i386/kernel/ioport.c Tue Jul 20 01:22:48 1999 +++ linux_umopenmosix/arch/i386/kernel/ioport.c Sun Jun 23 12:40:10 2002 @@ -15,6 +15,10 @@ #include #include +#ifdef CONFIG_MOSIX +#include +#endif /* CONFIG_MOSIX */ + /* Set EXTENT bits starting at BASE in BITMAP to value TURN_ON. */ static void set_bitmap(unsigned long *bitmap, short base, short extent, int new_value) { @@ -61,6 +65,10 @@ return -EINVAL; if (turn_on && !capable(CAP_SYS_RAWIO)) return -EPERM; +#ifdef CONFIG_MOSIX + if(turn_on && !mosix_go_home_for_reason(1, DSTAY_FOR_IOPL)) + return(-ENOMEM); +#endif /* CONFIG_MOSIX */ /* * If it's the first ioperm() call in this thread's lifetime, set the * IO bitmap up. ioperm() is much less timing critical than clone(), @@ -111,6 +119,11 @@ if (!capable(CAP_SYS_RAWIO)) return -EPERM; } +#ifdef CONFIG_MOSIX + if(!mosix_go_home_for_reason(1, DSTAY_FOR_IOPL)) + return(-ENOMEM); + regs = mos_to_regs(¤t->mosix); +#endif /* CONFIG_MOSIX */ regs->eflags = (regs->eflags & 0xffffcfff) | (level << 12); return 0; } diff -urN linux-2.4.17/arch/i386/kernel/irq.c linux_umopenmosix/arch/i386/kernel/irq.c --- linux-2.4.17/arch/i386/kernel/irq.c Thu Oct 25 22:53:46 2001 +++ linux_umopenmosix/arch/i386/kernel/irq.c Sun Jun 23 12:40:10 2002 @@ -279,6 +279,10 @@ clear_bit(0,&global_irq_lock); for (;;) { +#ifdef CONFIG_MOSIX_UDB + extern int nmi_debugger; + if(!nmi_debugger) +#endif /* CONFIG_MOSIX_UDB */ if (!--count) { show("wait_on_irq"); count = ~0; diff -urN linux-2.4.17/arch/i386/kernel/nmi.c linux_umopenmosix/arch/i386/kernel/nmi.c --- linux-2.4.17/arch/i386/kernel/nmi.c Fri Sep 21 06:55:24 2001 +++ linux_umopenmosix/arch/i386/kernel/nmi.c Sun Jun 23 12:40:10 2002 @@ -25,6 +25,9 @@ #include unsigned int nmi_watchdog = NMI_NONE; +#ifdef CONFIG_MOSIX_UDB +#include +#endif /* CONFIG_MOSIX_UDB */ static unsigned int nmi_hz = HZ; unsigned int nmi_perfctr_msr; /* the MSR to reset in NMI handler */ extern void show_registers(struct pt_regs *regs); @@ -268,6 +271,10 @@ */ int sum, cpu = smp_processor_id(); +#ifdef CONFIG_MOSIX_UDB + if(nmi_debugger) + return; +#endif /* CONFIG_MOSIX_UDB */ sum = apic_timer_irqs[cpu]; if (last_irq_sums[cpu] == sum) { @@ -285,6 +292,10 @@ bust_spinlocks(1); printk("NMI Watchdog detected LOCKUP on CPU%d, registers:\n", cpu); show_registers(regs); +#ifdef CONFIG_MOSIX_UDB + mosix_debugger("Watchdog"); + return; +#endif /* CONFIG_MOSIX_UDB */ printk("console shuts up ...\n"); console_silent(); spin_unlock(&nmi_print_lock); diff -urN linux-2.4.17/arch/i386/kernel/offset.c linux_umopenmosix/arch/i386/kernel/offset.c --- linux-2.4.17/arch/i386/kernel/offset.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/i386/kernel/offset.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il) + * Some sections copyright 2002 by Moshe Bar + * Permission to use this software is hereby granted under the terms of the + * GNU General Public License, as published by the Free Software Foundation. + * + * THIS SOFTWARE IS PROVIDED IN ITS "AS IS" CONDITION, WITH NO WARRANTY + * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING + * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED. + */ +/* + * Author(s): Amnon Shiloh, Moshe Bar + */ + +/* + * Produce an include-file for "entry.S", with: + * 1. constant-offsets of some required MOSIX-members of "task_struct" + * 2. some bits to test "current->dflags" + * 3. a duplicate system-call table (remote_sys_call_table), with all + * system-calls names preceded by a "remote_". + */ + +#include +#include +#include +#include +#include +#include + +struct file; +#define FILE struct file + +extern int printf(char *, ...); +extern int fgets(char *, int, FILE *); +extern int perror(char *); +extern FILE *stdin; + +char line[2048]; + +int +main(void) +{ + register char *c; + register int i; + long t, time(long *); + char *ctime(long *); + + time(&t); + printf("/* Please do not edit -- this file is created automatically */\n"); + printf("/* %.24s */\n\n", ctime(&t)); + printf("ALTREGS\t\t= 0x%X\n", + (int)&(((struct task_struct *)0)->mosix.altregs)); + printf("DFLAGS\t\t= 0x%X\n", + (int)&(((struct task_struct *)0)->mosix.dflags)); + printf("DDEPUTY\t\t= 0x%X\n", DDEPUTY); + printf("DREMOTE\t\t= 0x%X\n", DREMOTE); + printf("DTRACESYS1\t\t= 0x%X\n", DTRACESYS1); + printf("DTRACESYS2\t\t= 0x%X\n", DTRACESYS2); + printf(".data\n"); + printf("\nENTRY(remote_sys_call_table)\n"); + while(fgets(line, 2048, stdin) && + strcmp(line, "ENTRY(sys_call_table)\n")) + ; + for(i = 0 ; i < NR_syscalls && fgets(line, 2048, stdin) ; i++) + if(!strncmp(line, "\t.long SYMBOL_NAME(", 19)) + { + for(c = &line[19] ; *c && *c != ')' ; c++); + *c = '\0'; + if(!strcmp(&line[19], "sys_ni_syscall")) + { + printf("\t.long SYMBOL_NAME(sys_ni_syscall)\n"); + continue; + } + printf("\t.long SYMBOL_NAME(remote_%s)\n", &line[19]); + } + else if(!strcmp(line, "\t.rept NR_syscalls-(.-sys_call_table)/4\n")) + printf("\t.rept NR_syscalls-(.-remote_sys_call_table)/4\n"); + else + { + printf("%s", line); + if(!strncmp(line, "\t.endr", 5)) + break; + } + printf(".text\n"); + return(0); +} diff -urN linux-2.4.17/arch/i386/kernel/process.c linux_umopenmosix/arch/i386/kernel/process.c --- linux-2.4.17/arch/i386/kernel/process.c Fri Oct 5 03:42:54 2001 +++ linux_umopenmosix/arch/i386/kernel/process.c Sun Jun 23 12:40:10 2002 @@ -49,6 +49,10 @@ #include +#ifdef CONFIG_MOSIX +#include +#endif /* CONFIG_MOSIX */ + asmlinkage void ret_from_fork(void) __asm__("ret_from_fork"); int hlt_counter; @@ -160,6 +164,14 @@ /* shamelessly grabbed from lib/vsprintf.c for readability */ #define is_digit(c) ((c) >= '0' && (c) <= '9') #endif + +#ifdef CONFIG_MOSIX_UDB +void set_fastest_reboot(void) +{ + reboot_mode = 0x1234; +} +#endif /* CONFIG_MOSIX_UDB */ + static int __init reboot_setup(char *str) { while(1) { @@ -510,6 +522,43 @@ return retval; } +#ifdef CONFIG_MOSIX +/* + * Create a thread that starts as kernel, but will eventually run in user-mode: + * The slight differences from "kernel_thread" are: + * 1) not using CLONE_VM. + * 2) adding SIGCHLD to the flags. + * 3) leaving space on the stack for the user-registers. + */ +int user_thread(int (*fn)(void *), void * arg, unsigned long flags) +{ + long retval, d0; + + __asm__ __volatile__( + "movl %%esp,%%esi\n\t" + "int $0x80\n\t" /* Linux/i386 system call */ + "cmpl %%esp,%%esi\n\t" /* child or parent? */ + "je 1f\n\t" /* parent - jump */ + "subl %7,%%esp\n\t" /* space for user-registers */ + /* Load the argument into eax, and push it. That way, it does + * not matter whether the called function is compiled with + * -mregparm or not. */ + "movl %4,%%eax\n\t" + "pushl %%eax\n\t" + "call *%5\n\t" /* call fn */ + "movl %3,%0\n\t" /* exit */ + "int $0x80\n" + "1:\t" + :"=&a" (retval), "=&S" (d0) + :"0" (__NR_clone), "i" (__NR_exit), + "r" (arg), "r" (fn), + "b" (flags | SIGCHLD), + "i" (sizeof(struct pt_regs)) + : "memory"); + return retval; +} +#endif /* CONFIG_MOSIX */ + /* * Free current thread data structures etc.. */ @@ -583,6 +632,10 @@ childregs = ((struct pt_regs *) (THREAD_SIZE + (unsigned long) p)) - 1; struct_cpy(childregs, regs); +#ifdef CONFIG_MOSIX + p->mosix.altregs = (uint32_t *)childregs; + p->mosix.deputy_regs = current->mosix.deputy_regs; +#endif /* CONFIG_MOSIX */ childregs->eax = 0; childregs->esp = esp; @@ -734,10 +787,32 @@ */ tss->bitmap = INVALID_IO_BITMAP_OFFSET; } +#ifdef CONFIG_MOSIX + if(test_bit(X86_FEATURE_TSC, &boot_cpu_data.x86_capability)) + { + /* REMOTE emulates the RDTSC instruction */ + if(next_p->mosix.dflags & DREMOTE) + { + if(!(prev_p->mosix.dflags & DREMOTE)) + __asm__ __volatile__("movl %%cr4,%%eax\n\t" \ + "orl $4,%%eax\n\t" \ + "movl %%eax,%%cr4\n" \ + : : :"ax"); + } + else if(prev_p->mosix.dflags & DREMOTE) + __asm__ __volatile__("movl %%cr4,%%eax\n\t" \ + "andl $0xfffffffb,%%eax\n\t" \ + "movl %%eax,%%cr4\n" \ + : : :"ax"); + } +#endif /* CONFIG_MOSIX */ } asmlinkage int sys_fork(struct pt_regs regs) { +#ifdef CONFIG_MOSIX + mosix_obtain_registers(BIT_OF_REGISTER(esp)); +#endif /* CONFIG_MOSIX */ return do_fork(SIGCHLD, regs.esp, ®s, 0); } @@ -745,12 +820,27 @@ { unsigned long clone_flags; unsigned long newsp; +#ifdef CONFIG_MOSIX + int retval; +#endif /* CONFIG_MOSIX */ clone_flags = regs.ebx; newsp = regs.ecx; if (!newsp) +#ifdef CONFIG_MOSIX + mosix_obtain_registers(BIT_OF_REGISTER(esp)) , +#endif /* CONFIG_MOSIX */ newsp = regs.esp; +#ifdef CONFIG_MOSIX + if((clone_flags & CLONE_VM) && (retval = mosix_pre_clone())) + return(retval); + retval = do_fork(clone_flags, newsp, ®s, 0); + if(clone_flags & CLONE_VM) + mosix_post_clone(); + return(retval); +#else return do_fork(clone_flags, newsp, ®s, 0); +#endif /* CONFIG_MOSIX */ } /* @@ -765,7 +855,18 @@ */ asmlinkage int sys_vfork(struct pt_regs regs) { +#ifdef CONFIG_MOSIX + int retval; + + mosix_obtain_registers(BIT_OF_REGISTER(esp)); + if((retval = mosix_pre_clone())) + return(retval); + retval = do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs.esp, ®s, 0); + mosix_post_clone(); + return(retval); +#else return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs.esp, ®s, 0); +#endif /* CONFIG_MOSIX */ } /* @@ -801,23 +902,50 @@ unsigned long ebp, esp, eip; unsigned long stack_page; int count = 0; +#ifdef CONFIG_MOSIX + unsigned long result = 0; + if (!p || p == current || LOGICAL_STATE(p) == TASK_RUNNING) +#else if (!p || p == current || p->state == TASK_RUNNING) +#endif /* CONFIG_MOSIX */ return 0; stack_page = (unsigned long)p; esp = p->thread.esp; if (!stack_page || esp < stack_page || esp > 8188+stack_page) +#ifdef CONFIG_MOSIX + return(result); +#else return 0; +#endif /* CONFIG_MOSIX */ /* include/asm-i386/system.h:switch_to() pushes ebp last. */ ebp = *(unsigned long *) esp; do { if (ebp < stack_page || ebp > 8184+stack_page) +#ifdef CONFIG_MOSIX + return(result); +#else return 0; +#endif /* CONFIG_MOSIX */ eip = *(unsigned long *) (ebp+4); if (eip < first_sched || eip >= last_sched) +#ifdef CONFIG_MOSIX + { + if(!result) + return eip; + } + else + result = 0; +#else return eip; +#endif /* CONFIG_MOSIX */ ebp = *(unsigned long *) ebp; +#ifdef CONFIG_MOSIX + } while (count++ < 64); + return(result); +#else } while (count++ < 16); return 0; +#endif /* CONFIG_MOSIX */ } #undef last_sched #undef first_sched diff -urN linux-2.4.17/arch/i386/kernel/ptrace.c linux_umopenmosix/arch/i386/kernel/ptrace.c --- linux-2.4.17/arch/i386/kernel/ptrace.c Wed Nov 21 20:42:41 2001 +++ linux_umopenmosix/arch/i386/kernel/ptrace.c Sun Jun 23 12:40:10 2002 @@ -21,6 +21,10 @@ #include #include +#ifdef CONFIG_MOSIX +#include +#endif /* CONFIG_MOSIX */ + /* * does not yet catch signals sent when the child dies. * in exit.c or in signal.c. @@ -44,13 +48,47 @@ * this routine assumes that all the privileged stacks are in our * data space. */ +#ifdef CONFIG_MOSIX +inline int get_stack_long(struct task_struct *task, int offset) +#else static inline int get_stack_long(struct task_struct *task, int offset) +#endif /* CONFIG_MOSIX */ { unsigned char *stack; +#ifdef CONFIG_MOSIX + if(task != current) + lock_mosix(); + if(task->mosix.dflags & DDEPUTY) + { + if(task != current) + unlock_mosix(); + return(request_process(task, NULL, PR_PTRACE_GET_STACK_LONG, + offset)); + } + if(task == current) + mosix_obtain_registers(ALL_REGISTERS); + else + task_lock(task); + if(!task->thread.saved_esp0) /* unless in VM86 mode */ + stack = (char *)(mos_to_regs(&task->mosix) + 1); + else +#endif /* CONFIG_MOSIX */ stack = (unsigned char *)task->thread.esp0; stack += offset; +#ifdef CONFIG_MOSIX + { + int res = *((int *)stack); + if(task != current) + { + task_unlock(task); + unlock_mosix(); + } + return(res); + } +#else return (*((int *)stack)); +#endif /* CONFIG_MOSIX */ } /* @@ -59,14 +97,43 @@ * this routine assumes that all the privileged stacks are in our * data space. */ +#ifdef CONFIG_MOSIX +inline int put_stack_long(struct task_struct *task, int offset, +#else static inline int put_stack_long(struct task_struct *task, int offset, +#endif /* CONFIG_MOSIX */ unsigned long data) { unsigned char * stack; +#ifdef CONFIG_MOSIX + if(task != current) + lock_mosix(); + if(task->mosix.dflags & DDEPUTY) + { + if(task != current) + unlock_mosix(); + return(request_process_arg2(task, NULL, + PR_PTRACE_PUT_STACK_LONG, offset, data)); + } + if(task == current) + mosix_obtain_registers(ALL_REGISTERS); + else + task_lock(task); + if(!task->thread.saved_esp0) /* unless in VM86 mode */ + stack = (char *)(mos_to_regs(&task->mosix) + 1); + else +#endif /* CONFIG_MOSIX */ stack = (unsigned char *) task->thread.esp0; stack += offset; *(unsigned long *) stack = data; +#ifdef CONFIG_MOSIX + if(task != current) + { + task_unlock(task); + unlock_mosix(); + } +#endif /* CONFIG_MOSIX */ return 0; } @@ -107,6 +174,17 @@ return 0; } +#ifdef CONFIG_MOSIX +void +ptrace_putregs(unsigned long *data) +{ + register int i; + + for (i = 0; i < FRAME_SIZE ; i++) + putreg(current, i << 2, data[i]); +} +#endif /* CONFIG_MOSIX */ + static unsigned long getreg(struct task_struct *child, unsigned long regno) { @@ -147,6 +225,17 @@ put_stack_long(child, EFL_OFFSET, tmp); } +#ifdef CONFIG_MOSIX +void +ptrace_getregs(unsigned long *data) +{ + register int i; + + for (i = 0; i < FRAME_SIZE ; i++) + data[i] = getreg(current, i << 2); +} +#endif /* CONFIG_MOSIX */ + asmlinkage int sys_ptrace(long request, long pid, long addr, long data) { struct task_struct *child; @@ -161,6 +250,9 @@ goto out; /* set the ptrace bit in the process flags. */ current->ptrace |= PT_PTRACED; +#ifdef CONFIG_MOSIX_DFSA + tell_process(current, DREQ_NOTUPTODATE); +#endif /* CONFIG_MOSIX_DFSA */ ret = 0; goto out; } @@ -210,6 +302,17 @@ addr > sizeof(struct user) - 3) break; +#ifdef CONFIG_MOSIX + lock_mosix(); + if(child->mosix.dflags & DDEPUTY) + { + unlock_mosix(); + if(request_process(child, &tmp, PR_PTRACE_PEEKUSER, addr)) + goto out; + } + else + { +#endif /* CONFIG_MOSIX */ tmp = 0; /* Default return condition */ if(addr < FRAME_SIZE*sizeof(long)) tmp = getreg(child, addr); @@ -219,6 +322,10 @@ addr = addr >> 2; tmp = child->thread.debugreg[addr]; } +#ifdef CONFIG_MOSIX + unlock_mosix(); + } +#endif /* CONFIG_MOSIX */ ret = put_user(tmp,(unsigned long *) data); break; } @@ -265,7 +372,23 @@ addr -= (long) &dummy->u_debugreg; addr = addr >> 2; +#ifdef CONFIG_MOSIX + lock_mosix(); + if(child->mosix.dflags & DDEPUTY) + { + unlock_mosix(); + if(request_process_arg2(child, NULL, + PR_PTRACE_POKEUSER, addr, data)) + goto out; + } + else + { +#endif /* CONFIG_MOSIX */ child->thread.debugreg[addr] = data; +#ifdef CONFIG_MOSIX + unlock_mosix(); + } +#endif /* CONFIG_MOSIX */ ret = 0; } break; @@ -282,9 +405,22 @@ else child->ptrace &= ~PT_TRACESYS; child->exit_code = data; +#ifdef CONFIG_MOSIX + if(child->mosix.dflags & DDEPUTY) + { + if(request_process(child, NULL, PR_PTRACE_CONT, + request)) + goto out; + } + else + { +#endif /* CONFIG_MOSIX */ /* make sure the single step bit is not set. */ tmp = get_stack_long(child, EFL_OFFSET) & ~TRAP_FLAG; put_stack_long(child, EFL_OFFSET,tmp); +#ifdef CONFIG_MOSIX + } +#endif /* CONFIG_MOSIX */ wake_up_process(child); ret = 0; break; @@ -299,7 +435,11 @@ long tmp; ret = 0; +#ifdef CONFIG_MOSIX + if (LOGICAL_STATE(child) == TASK_ZOMBIE) /* already dead */ +#else if (child->state == TASK_ZOMBIE) /* already dead */ +#endif /* CONFIG_MOSIX */ break; child->exit_code = SIGKILL; /* make sure the single step bit is not set. */ @@ -320,8 +460,21 @@ /* Spurious delayed TF traps may occur */ child->ptrace |= PT_DTRACE; } +#ifdef CONFIG_MOSIX + if(child->mosix.dflags & DDEPUTY) + { + if(request_process(child, NULL, PR_PTRACE_SINGLE_STEP, + 0)) + goto out; + } + else + { +#endif /* CONFIG_MOSIX */ tmp = get_stack_long(child, EFL_OFFSET) | TRAP_FLAG; put_stack_long(child, EFL_OFFSET, tmp); +#ifdef CONFIG_MOSIX + } +#endif /* CONFIG_MOSIX */ child->exit_code = data; /* give it a chance to run. */ wake_up_process(child); @@ -339,26 +492,57 @@ ret = -EIO; break; } +#ifdef CONFIG_MOSIX + /* NOTE: even when child does not look like a DEPUTY, + * it could easily become one while we wait for a page + * on __put_user ... therefore, we do this ALWAYS: + */ + { + unsigned long t[FRAME_SIZE]; + + if(request_process(child, &t, PR_PTRACE_GETREGS, 0)) + ret = -EIO; + else + copy_to_user((void *)data, t, sizeof(t)); + } +#else for ( i = 0; i < FRAME_SIZE*sizeof(long); i += sizeof(long) ) { __put_user(getreg(child, i),(unsigned long *) data); data += sizeof(long); } +#endif /* CONFIG_MOSIX */ ret = 0; break; } case PTRACE_SETREGS: { /* Set all gp regs in the child. */ +#ifndef CONFIG_MOSIX unsigned long tmp; +#endif /* CONFIG_MOSIX */ if (!access_ok(VERIFY_READ, (unsigned *)data, FRAME_SIZE*sizeof(long))) { ret = -EIO; break; } +#ifdef CONFIG_MOSIX + /* NOTE: even when child does not look like a DEPUTY, + * it could easily become one while we wait for a page + * on __get_user ... therefore, we do this ALWAYS: + */ + { + unsigned long t[FRAME_SIZE]; + + copy_from_user(t, (void *)data, sizeof(t)); + ret = request_process(child, &t, PR_PTRACE_SETREGS, 0) + ? -EIO : 0; + } +#else for ( i = 0; i < FRAME_SIZE*sizeof(long); i += sizeof(long) ) { __get_user(tmp, (unsigned long *) data); putreg(child, i, tmp); data += sizeof(long); } ret = 0; +#endif /* CONFIG_MOSIX */ break; } @@ -369,6 +553,23 @@ break; } ret = 0; +#ifdef CONFIG_MOSIX + /* DEPUTY or NOT - the child-process may become DEPUTY + * while we page-fault on "__copy_to_user", + * so we always do it the long way: + */ + { + struct user_i387_struct f; + + if(request_process(child, &f, PR_PTRACE_GETFPREGS, 0)) + { + ret = -EIO; + goto out; + } + __copy_to_user((void *)data, &f, + sizeof(struct user_i387_struct)); + } +#else if ( !child->used_math ) { /* Simulate an empty FPU. */ set_fpu_cwd(child, 0x037f); @@ -376,6 +577,7 @@ set_fpu_twd(child, 0xffff); } get_fpregs((struct user_i387_struct *)data, child); +#endif /* CONFIG_MOSIX */ break; } @@ -385,9 +587,23 @@ ret = -EIO; break; } +#ifdef CONFIG_MOSIX + /* DEPUTY or NOT - the child-process may become DEPUTY + * while we page-fault on "__copy_from_user", + * so we always do it the long way: + */ + { + struct user_i387_struct f; + + __copy_from_user(&f, (void *)data, sizeof(f)); + ret = request_process(child, &f, PR_PTRACE_SETFPREGS, 0) + ? -EIO : 0; + } +#else child->used_math = 1; set_fpregs(child, (struct user_i387_struct *)data); ret = 0; +#endif /* CONFIG_MOSIX */ break; } @@ -397,6 +613,24 @@ ret = -EIO; break; } +#ifdef CONFIG_MOSIX + ret = 0; + /* DEPUTY or NOT - the child-process may become DEPUTY + * while we page-fault on "__copy_to_user", + * so we always do it the long way: + */ + { + struct user_fxsr_struct f; + + if(request_process(child, &f, PR_PTRACE_GETFPXREGS, 0)) + { + ret = -EIO; + goto out; + } + __copy_to_user((void *)data, &f, + sizeof(struct user_fxsr_struct)); + } +#else if ( !child->used_math ) { /* Simulate an empty FPU. */ set_fpu_cwd(child, 0x037f); @@ -405,6 +639,7 @@ set_fpu_mxcsr(child, 0x1f80); } ret = get_fpxregs((struct user_fxsr_struct *)data, child); +#endif /* CONFIG_MOSIX */ break; } @@ -414,8 +649,22 @@ ret = -EIO; break; } +#ifdef CONFIG_MOSIX + /* DEPUTY or NOT - the child-process may become DEPUTY + * while we page-fault on "__copy_from_user", + * so we always do it the long way: + */ + { + struct user_fxsr_struct f; + + __copy_from_user(&f, (void *)data, sizeof(f)); + ret = request_process(child, &f, PR_PTRACE_SETFPXREGS, + 0) ? -EIO : 0; + } +#else child->used_math = 1; ret = set_fpxregs(child, (struct user_fxsr_struct *)data); +#endif /* CONFIG_MOSIX */ break; } @@ -439,7 +688,174 @@ return ret; } +#ifdef CONFIG_MOSIX +/* + * The following routines are parts of sys_ptrace performed by the + * child process on itself. + * Should the relevant code in "sys_ptrace" change, the following routines + * must also be modified accordingly. + */ +unsigned long +ptrace_peekuser(long addr) +{ + struct user * dummy = NULL; + unsigned long tmp; + + tmp = 0; /* Default return condition */ + if(addr < FRAME_SIZE*sizeof(long)) + tmp = getreg(current, addr); + if(addr >= (long) &dummy->u_debugreg[0] && + addr <= (long) &dummy->u_debugreg[7]){ + addr -= (long) &dummy->u_debugreg[0]; + addr = addr >> 2; + tmp = current->thread.debugreg[addr]; + }; + return(tmp); +} + +void +ptrace_pokeuser(long addr, long data) +{ + current->thread.debugreg[addr] = data; +#define loaddebug(tsk,register) \ + __asm__("movl %0,%%db" #register \ + : /* no output */ \ + :"r" (tsk->thread.debugreg[register])) + /* unlike the original ptrace code, we are doing this for ourselves, + * and there may be no "switch_to" before we go to user-mode again, + * so here we go: + */ + if(current->thread.debugreg[7]) + { + loaddebug(current, 0); + loaddebug(current, 1); + loaddebug(current, 2); + loaddebug(current, 3); + loaddebug(current, 6); + loaddebug(current, 7); + } +} + +void +ptrace_cont(int request) +{ + unsigned long tmp; + struct task_struct *tsk = current; + + tmp = get_stack_long(tsk, EFL_OFFSET) & ~TRAP_FLAG; + put_stack_long(tsk, EFL_OFFSET, tmp); + if (request == PTRACE_SYSCALL) + tsk->ptrace |= PT_TRACESYS; + else + tsk->ptrace &= ~PT_TRACESYS; + if (request == PTRACE_DETACH) + tsk->ptrace &= ~PT_PTRACED; +} + +void +ptrace_single_step(void) +{ + unsigned long tmp; + + tmp = get_stack_long(current, EFL_OFFSET) | TRAP_FLAG; + put_stack_long(current, EFL_OFFSET, tmp); + current->ptrace |= PT_PTRACED | PT_DTRACE; +#ifdef CONFIG_MOSIX_DFSA + tell_process(current, DREQ_NOTUPTODATE); +#endif /* CONFIG_MOSIX_DFSA */ +} + +void +ptrace_getfpregs(struct user_i387_struct *to) +{ + struct task_struct *p = current; + + unlazy_fpu(p); + if (!p->used_math) + { + /* Simulate an empty FPU. */ + set_fpu_cwd(p, 0x037f); + set_fpu_swd(p, 0x0000); + set_fpu_twd(p, 0xffff); + } + get_fpregs(to, p); +} + +void +ptrace_getfpxregs(struct user_fxsr_struct *to) +{ + struct task_struct *p = current; + + unlazy_fpu(p); + if (!p->used_math) + { + /* Simulate an empty FPU. */ + set_fpu_cwd(p, 0x037f); + set_fpu_swd(p, 0x0000); + set_fpu_twd(p, 0xffff); + set_fpu_mxcsr(p, 0x1f80); + } + get_fpxregs(to, p); +} + +void +ptrace_setfpregs(struct user_i387_struct *from) +{ + struct task_struct *p = current; + + clear_fpu(p); + p->used_math = 1; + set_fpregs(p, from); +} + +void +ptrace_setfpxregs(struct user_fxsr_struct *from) +{ + struct task_struct *p = current; + + clear_fpu(p); + p->used_math = 1; + set_fpxregs(p, from); +} +#endif /* CONFIG_MOSIX */ + +#ifdef CONFIG_MOSIX +/* + * When a process starts a system call in PT_TRACESYS mode, it must run + * the full sequence: A=syscall_trace, B=the_system_call, C=syscall_trace. + * Since our process can migrate at any of those stages, we maintain 2 flags + * that tell us where to resume in the sequence. + * In the particular case of DTRACESYS1, the trace was already complete + * before the migration. In the case of DTRACESYS2, the system-call was already + * complete before the migration and the code in "entry.S" prevents it from + * re-running. + */ +asmlinkage void +syscall_trace(void) +{ + extern asmlinkage void do_syscall_trace(void); + + switch(current->mosix.dflags & (DTRACESYS1|DTRACESYS2)) + { + case 0: + current->mosix.dflags |= DTRACESYS1; + break; + case DTRACESYS1: + return; + case DTRACESYS2: + case DTRACESYS1|DTRACESYS2: + current->mosix.dflags &= ~(DTRACESYS1|DTRACESYS2); + } + if(current->mosix.dflags & DREMOTE) + mosix_remote_syscall_trace(); + else + do_syscall_trace(); +} + +asmlinkage void do_syscall_trace(void) +#else asmlinkage void syscall_trace(void) +#endif /* CONFIG_MOSIX */ { if ((current->ptrace & (PT_PTRACED|PT_TRACESYS)) != (PT_PTRACED|PT_TRACESYS)) diff -urN linux-2.4.17/arch/i386/kernel/signal.c linux_umopenmosix/arch/i386/kernel/signal.c --- linux-2.4.17/arch/i386/kernel/signal.c Sat Sep 15 00:15:40 2001 +++ linux_umopenmosix/arch/i386/kernel/signal.c Sun Jun 23 12:40:10 2002 @@ -24,6 +24,10 @@ #include #include +#ifdef CONFIG_MOSIX +#include +#endif /* CONFIG_MOSIX */ + #define DEBUG_SIG 0 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP))) @@ -37,6 +41,29 @@ if (from->si_code < 0) return __copy_to_user(to, from, sizeof(siginfo_t)); else { +#ifdef CONFIG_MOSIX + /* it is unreasonable to send a separate request per word, + * so find the limit and send them all together. + */ + int sz = offsetof(struct siginfo, _sifields); + + switch(from->si_code >> 16) + { + case __SI_FAULT >> 16: + sz += sizeof(to->_sifields._sigfault); + break; + case __SI_CHLD >> 16: + sz += sizeof(to->_sifields._sigchld); + break; + case __SI_MIGRATION >> 16: + sz += sizeof(to->_sifields._sigmig); + break; + default: + sz += sizeof(to->_sifields._kill); + break; + } + return(__copy_to_user(to, from, sz)); +#else int err; /* If you change siginfo_t structure, please be sure @@ -62,6 +89,7 @@ /* case __SI_RT: This is not generated by the kernel as of now. */ } return err; +#endif /* CONFIG_MOSIX */ } } @@ -81,6 +109,10 @@ recalc_sigpending(current); spin_unlock_irq(¤t->sigmask_lock); +#ifdef CONFIG_MOSIX + mosix_obtain_registers( + BIT_OF_REGISTER(orig_eax)|BIT_OF_REGISTER(eax)|BIT_OF_REGISTER(eip)); +#endif /* CONFIG_MOSIX */ regs->eax = -EINTR; while (1) { current->state = TASK_INTERRUPTIBLE; @@ -110,6 +142,10 @@ recalc_sigpending(current); spin_unlock_irq(¤t->sigmask_lock); +#ifdef CONFIG_MOSIX + mosix_obtain_registers( + BIT_OF_REGISTER(orig_eax)|BIT_OF_REGISTER(eax)|BIT_OF_REGISTER(eip)); +#endif /* CONFIG_MOSIX */ regs->eax = -EINTR; while (1) { current->state = TASK_INTERRUPTIBLE; @@ -155,6 +191,10 @@ sys_sigaltstack(const stack_t *uss, stack_t *uoss) { struct pt_regs *regs = (struct pt_regs *) &uss; + +#ifdef CONFIG_MOSIX + mosix_obtain_registers(BIT_OF_REGISTER(esp)); +#endif /* CONFIG_MOSIX */ return do_sigaltstack(uss, uoss, regs->esp); } @@ -185,11 +225,19 @@ char retcode[8]; }; +#ifdef CONFIG_MOSIX +int +#else static int +#endif /* CONFIG_MOSIX */ restore_sigcontext(struct pt_regs *regs, struct sigcontext *sc, int *peax) { unsigned int err = 0; +#ifdef CONFIG_MOSIX + mosix_obtain_registers(ALL_REGISTERS); +#endif /* CONFIG_MOSIX */ + #define COPY(x) err |= __get_user(regs->x, &sc->x) #define COPY_SEG(seg) \ @@ -249,10 +297,18 @@ asmlinkage int sys_sigreturn(unsigned long __unused) { struct pt_regs *regs = (struct pt_regs *) &__unused; +#ifdef CONFIG_MOSIX + struct sigframe *frame; +#else struct sigframe *frame = (struct sigframe *)(regs->esp - 8); +#endif /* CONFIG_MOSIX */ sigset_t set; int eax; +#ifdef CONFIG_MOSIX + mosix_obtain_registers(BIT_OF_REGISTER(esp)); + frame = (struct sigframe *)(regs->esp - 8); +#endif /* CONFIG_MOSIX */ if (verify_area(VERIFY_READ, frame, sizeof(*frame))) goto badframe; if (__get_user(set.sig[0], &frame->sc.oldmask) @@ -267,6 +323,14 @@ recalc_sigpending(current); spin_unlock_irq(¤t->sigmask_lock); +#ifdef CONFIG_MOSIX + if(current->mosix.dflags & DDEPUTY) + { + if (mosix_deputy_restore_sigcontext(&frame->sc, &eax)) + goto badframe; + } + else +#endif /* CONFIG_MOSIX */ if (restore_sigcontext(regs, &frame->sc, &eax)) goto badframe; return eax; @@ -279,11 +343,19 @@ asmlinkage int sys_rt_sigreturn(unsigned long __unused) { struct pt_regs *regs = (struct pt_regs *) &__unused; +#ifdef CONFIG_MOSIX + struct rt_sigframe *frame; +#else struct rt_sigframe *frame = (struct rt_sigframe *)(regs->esp - 4); +#endif /* CONFIG_MOSIX */ sigset_t set; stack_t st; int eax; +#ifdef CONFIG_MOSIX + mosix_obtain_registers(BIT_OF_REGISTER(esp)); + frame = (struct rt_sigframe *)(regs->esp - 4); +#endif /* CONFIG_MOSIX */ if (verify_area(VERIFY_READ, frame, sizeof(*frame))) goto badframe; if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) @@ -295,6 +367,14 @@ recalc_sigpending(current); spin_unlock_irq(¤t->sigmask_lock); +#ifdef CONFIG_MOSIX + if(current->mosix.dflags & DDEPUTY) + { + if(mosix_deputy_restore_sigcontext(&frame->uc.uc_mcontext,&eax)) + goto badframe; + } + else +#endif /* CONFIG_MOSIX */ if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &eax)) goto badframe; @@ -302,6 +382,9 @@ goto badframe; /* It is more difficult to avoid calling this function than to call it and ignore errors. */ +#ifdef CONFIG_MOSIX + mosix_obtain_registers(BIT_OF_REGISTER(esp)); +#endif /* CONFIG_MOSIX */ do_sigaltstack(&st, NULL, regs->esp); return eax; @@ -321,6 +404,9 @@ { int tmp, err = 0; +#ifdef CONFIG_MOSIX_NO_NEED__ALL_CALLERS_ALREADY_DID + mosix_obtain_registers(ALL_REGISTERS); +#endif /* CONFIG_MOSIX_NO_NEED__ALL_CALLERS_ALREADY_DID */ tmp = 0; __asm__("movl %%gs,%0" : "=r"(tmp): "0"(tmp)); err |= __put_user(tmp, (unsigned int *)&sc->gs); @@ -385,12 +471,19 @@ return (void *)((esp - frame_size) & -8ul); } +#ifdef CONFIG_MOSIX +void setup_frame(int sig, struct k_sigaction *ka, +#else static void setup_frame(int sig, struct k_sigaction *ka, +#endif /* CONFIG_MOSIX */ sigset_t *set, struct pt_regs * regs) { struct sigframe *frame; int err = 0; +#ifdef CONFIG_MOSIX + mosix_obtain_registers(ALL_REGISTERS); +#endif /* CONFIG_MOSIX */ frame = get_sigframe(ka, regs, sizeof(*frame)); if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) @@ -455,12 +548,19 @@ force_sig(SIGSEGV, current); } +#ifdef CONFIG_MOSIX +void setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, +#else static void setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, +#endif /* CONFIG_MOSIX */ sigset_t *set, struct pt_regs * regs) { struct rt_sigframe *frame; int err = 0; +#ifdef CONFIG_MOSIX + mosix_obtain_registers(ALL_REGISTERS); +#endif /* CONFIG_MOSIX */ frame = get_sigframe(ka, regs, sizeof(*frame)); if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) @@ -538,6 +638,10 @@ handle_signal(unsigned long sig, struct k_sigaction *ka, siginfo_t *info, sigset_t *oldset, struct pt_regs * regs) { +#ifdef CONFIG_MOSIX + mosix_obtain_registers( + BIT_OF_REGISTER(orig_eax)|BIT_OF_REGISTER(eax)|BIT_OF_REGISTER(eip)); +#endif /* CONFIG_MOSIX */ /* Are we from a system call? */ if (regs->orig_eax >= 0) { /* If so, check system call restarting.. */ @@ -559,6 +663,11 @@ } /* Set up the stack frame */ +#ifdef CONFIG_MOSIX + if(current->mosix.dflags & DDEPUTY) + mosix_deputy_setup_frame(sig, ka, *info, oldset); + else +#endif /* CONFIG_MOSIX */ if (ka->sa.sa_flags & SA_SIGINFO) setup_rt_frame(sig, ka, info, oldset, regs); else @@ -586,6 +695,11 @@ siginfo_t info; struct k_sigaction *ka; +#ifdef CONFIG_MOSIX + if(current->mosix.dflags & DREMOTE) + return(0); +#endif /* CONFIG_MOSIX */ + /* * We want the common case to go fast, which * is why we may in certain cases get here from @@ -611,6 +725,10 @@ if ((current->ptrace & PT_PTRACED) && signr != SIGKILL) { /* Let the debugger run. */ current->exit_code = signr; +#ifdef CONFIG_MOSIX + if(current->mosix.dflags & DDEPUTY) + mosix_deputy_rusage(0); +#endif /* CONFIG_MOSIX */ current->state = TASK_STOPPED; notify_parent(current, SIGCHLD); schedule(); @@ -668,6 +786,10 @@ case SIGSTOP: { struct signal_struct *sig; +#ifdef CONFIG_MOSIX + if(current->mosix.dflags & DDEPUTY) + mosix_deputy_rusage(0); +#endif /* CONFIG_MOSIX */ current->state = TASK_STOPPED; current->exit_code = signr; sig = current->p_pptr->sig; @@ -706,6 +828,10 @@ } /* Did we come from a system call? */ +#ifdef CONFIG_MOSIX + mosix_obtain_registers( + BIT_OF_REGISTER(orig_eax)|BIT_OF_REGISTER(eax)|BIT_OF_REGISTER(eip)); +#endif /* CONFIG_MOSIX */ if (regs->orig_eax >= 0) { /* Restart the system call - no handlers present */ if (regs->eax == -ERESTARTNOHAND || diff -urN linux-2.4.17/arch/i386/kernel/sys_i386.c linux_umopenmosix/arch/i386/kernel/sys_i386.c --- linux-2.4.17/arch/i386/kernel/sys_i386.c Mon Mar 19 22:35:09 2001 +++ linux_umopenmosix/arch/i386/kernel/sys_i386.c Sun Jun 23 12:40:10 2002 @@ -22,6 +22,10 @@ #include #include +#ifdef CONFIG_MOSIX_DFSA +#include +#endif /* CONFIG_MOSIX_DFSA */ + /* * sys_pipe() is the normal C calling standard for creating * a pipe. It's not the way Unix traditionally does this, though. @@ -55,12 +59,20 @@ goto out; } +#ifdef CONFIG_MOSIX + error = do_mmap_pgoff_down(file, addr, len, prot, flags, pgoff); +#else down_write(¤t->mm->mmap_sem); error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); up_write(¤t->mm->mmap_sem); +#endif /* CONFIG_MOSIX */ if (file) fput(file); +#ifdef CONFIG_MOSIX_DFSA + if(file && file_count(file) > 1) + dfsa_touch_file(fd); +#endif /* CONFIG_MOSIX_DFSA */ out: return error; } diff -urN linux-2.4.17/arch/i386/kernel/traps.c linux_umopenmosix/arch/i386/kernel/traps.c --- linux-2.4.17/arch/i386/kernel/traps.c Sun Sep 30 21:26:08 2001 +++ linux_umopenmosix/arch/i386/kernel/traps.c Sun Jun 23 12:40:10 2002 @@ -50,6 +50,11 @@ #include #include +#ifdef CONFIG_MOSIX +#include +#include +#endif /* CONFIG_MOSIX */ + asmlinkage int system_call(void); asmlinkage void lcall7(void); asmlinkage void lcall27(void); @@ -248,6 +253,12 @@ show_registers(regs); bust_spinlocks(0); spin_unlock_irq(&die_lock); +#ifdef CONFIG_MOSIX_UDB + { + extern void mosix_debugger(char *); + mosix_debugger("die"); + } +#endif /* CONFIG_MOSIX_UDB */ do_exit(SIGSEGV); } @@ -336,10 +347,16 @@ } DO_VM86_ERROR_INFO( 0, SIGFPE, "divide error", divide_error, FPE_INTDIV, regs->eip) +#ifndef CONFIG_MOSIX_UDB DO_VM86_ERROR( 3, SIGTRAP, "int3", int3) +#endif /* CONFIG_MOSIX_UDB */ DO_VM86_ERROR( 4, SIGSEGV, "overflow", overflow) DO_VM86_ERROR( 5, SIGSEGV, "bounds", bounds) +#ifdef CONFIG_MOSIX +DO_ERROR_INFO( 6, SIGILL, "invalid operand", real_invalid_op, ILL_ILLOPN, regs->eip) +#else DO_ERROR_INFO( 6, SIGILL, "invalid operand", invalid_op, ILL_ILLOPN, regs->eip) +#endif /* CONFIG_MOSIX */ DO_VM86_ERROR( 7, SIGSEGV, "device not available", device_not_available) DO_ERROR( 8, SIGSEGV, "double fault", double_fault) DO_ERROR( 9, SIGFPE, "coprocessor segment overrun", coprocessor_segment_overrun) @@ -356,6 +373,24 @@ if (!(regs->xcs & 3)) goto gp_in_kernel; +#ifdef CONFIG_MOSIX + if(error_code == 0 && (current->mosix.dflags & DREMOTE)) + { + short code; + u64 clk; + + if(!get_user(code, (short *)regs->eip) && + code == 0x310F) /* RDTSC */ + { + clk = mosix_remote_tsc(); + regs->eax = clk & 0xffffffff; + regs->edx = clk >> 32; + regs->eip += 2; + return; + } + mosix_go_home(0); + } +#endif /* CONFIG_MOSIX */ current->thread.error_code = error_code; current->thread.trap_no = 13; force_sig(SIGSEGV, current); @@ -452,6 +487,41 @@ inb(0x71); /* dummy */ } +#ifdef CONFIG_MOSIX_UDB +asmlinkage void do_int3(struct pt_regs * regs, long error_code) +{ + extern int udb_breakpoint(struct pt_regs *regs); + + if (!(regs->eflags & VM_MASK) && (regs->xcs & 3) != 3 && + udb_breakpoint(regs)) + return; + do_trap(3, SIGTRAP, "int3", 1, regs, error_code, NULL); +} +#endif /* CONFIG_MOSIX_UDB */ + +#ifdef CONFIG_MOSIX +static __u32 user_features[NCAPINTS] = USER_MODE_FEATURES; + +asmlinkage void +do_invalid_op(struct pt_regs * regs, long error_code) +{ + if((current->mosix.dflags & DREMOTE) && !(regs->eflags & VM_MASK) && + (regs->xcs & 3) == 3) + { + int i; + + for(i = 0 ; i < NCAPINTS ; i++) + if(current->mosix.features[i] & user_features[i] & + ~boot_cpu_data.x86_capability[i]) + { + mosix_go_home(0); /* no return if successful */ + break; + } + } + do_real_invalid_op(regs, error_code); +} +#endif /* CONFIG_MOSIX */ + /* * Our handling of the processor debug registers is non-trivial. * We do not clear them on entry and exit from the kernel. Therefore diff -urN linux-2.4.17/arch/i386/kernel/vm86.c linux_umopenmosix/arch/i386/kernel/vm86.c --- linux-2.4.17/arch/i386/kernel/vm86.c Sat Jul 7 03:05:07 2001 +++ linux_umopenmosix/arch/i386/kernel/vm86.c Sun Jun 23 12:40:10 2002 @@ -17,6 +17,10 @@ #include #include +#ifdef CONFIG_MOSIX +#include +#endif /* CONFIG_MOSIX */ + /* * Known problems: * @@ -69,6 +73,10 @@ struct pt_regs *ret; unsigned long tmp; +#ifdef CONFIG_MOSIX + if(current->mosix.dflags & DREMOTE) + panic("remote save_v86"); +#endif /* CONFIG_MOSIX */ if (!current->thread.vm86_info) { printk("no vm86_info: BAD\n"); do_exit(SIGSEGV); @@ -83,9 +91,18 @@ do_exit(SIGSEGV); } tss = init_tss + smp_processor_id(); +#ifdef CONFIG_MOSIX + lock_mosix(); /* ptrace checks saved_esp0 under the mosix-lock */ +#endif /* CONFIG_MOSIX */ tss->esp0 = current->thread.esp0 = current->thread.saved_esp0; current->thread.saved_esp0 = 0; ret = KVM86->regs32; +#ifdef CONFIG_MOSIX + unlock_mosix(); + task_lock(current); + current->mosix.stay &= ~DSTAY_FOR_86; + task_unlock(current); +#endif /* CONFIG_MOSIX */ return ret; } @@ -136,6 +153,13 @@ struct task_struct *tsk; int tmp, ret = -EPERM; +#ifdef CONFIG_MOSIX + if(!mosix_go_home_for_reason(1, DSTAY_FOR_86)) + { + ret = -ENOMEM; + goto out; + } +#endif /* CONFIG_MOSIX */ tsk = current; if (tsk->thread.saved_esp0) goto out; @@ -193,6 +217,13 @@ ret = -EFAULT; if (tmp) goto out; +#ifdef CONFIG_MOSIX + if(!mosix_go_home_for_reason(1, DSTAY_FOR_86)) + { + ret = -ENOMEM; + goto out; + } +#endif /* CONFIG_MOSIX */ info.regs32 = (struct pt_regs *) &subfunction; info.vm86plus.is_vm86pus = 1; tsk->thread.vm86_info = (struct vm86_struct *)v86; @@ -245,9 +276,15 @@ * Save old state, set default return value (%eax) to 0 */ info->regs32->eax = 0; +#ifdef CONFIG_MOSIX + lock_mosix(); +#endif /* CONFIG_MOSIX */ tsk->thread.saved_esp0 = tsk->thread.esp0; tss = init_tss + smp_processor_id(); tss->esp0 = tsk->thread.esp0 = (unsigned long) &info->VM86_TSS_ESP0; +#ifdef CONFIG_MOSIX + unlock_mosix(); +#endif /* CONFIG_MOSIX */ tsk->thread.screen_bitmap = info->screen_bitmap; if (info->flags & VM86_SCREEN_BITMAP) @@ -267,6 +304,11 @@ regs32 = save_v86_state(regs16); regs32->eax = retval; +#ifdef CONFIG_MOSIX + task_lock(current); + current->mosix.stay &= ~DSTAY_FOR_86; + task_unlock(current); +#endif /* CONFIG_MOSIX */ __asm__ __volatile__("movl %0,%%esp\n\t" "jmp ret_from_sys_call" : : "r" (regs32), "b" (current)); @@ -602,7 +644,11 @@ int ret = 0; read_lock(&tasklist_lock); +#ifdef CONFIG_MOSIX + for_each_local_task(p) { +#else for_each_task(p) { +#endif /* CONFIG_MOSIX */ if ((p == tsk) && (p->sig)) { ret = 1; break; diff -urN linux-2.4.17/arch/i386/lib/usercopy.c linux_umopenmosix/arch/i386/lib/usercopy.c --- linux-2.4.17/arch/i386/lib/usercopy.c Fri Nov 9 23:58:02 2001 +++ linux_umopenmosix/arch/i386/lib/usercopy.c Sun Jun 23 12:40:10 2002 @@ -99,6 +99,11 @@ __strncpy_from_user(char *dst, const char *src, long count) { long res; + +#ifdef CONFIG_MOSIX + if(USER_IS_REMOTE) + return(deputy_strncpy_from_user(dst, (char *)src, count, 0)); +#endif /* CONFIG_MOSIX */ __do_strncpy_from_user(dst, src, count, res); return res; } @@ -107,6 +112,11 @@ strncpy_from_user(char *dst, const char *src, long count) { long res = -EFAULT; + +#ifdef CONFIG_MOSIX + if(USER_IS_REMOTE) + return(deputy_strncpy_from_user(dst, (char *)src, count, 1)); +#endif /* CONFIG_MOSIX */ if (access_ok(VERIFY_READ, src, 1)) __do_strncpy_from_user(dst, src, count, res); return res; @@ -141,6 +151,10 @@ unsigned long clear_user(void *to, unsigned long n) { +#ifdef CONFIG_MOSIX + if (USER_IS_REMOTE) + return(deputy_clear_user(to, n, 1)); +#endif /* CONFIG_MOSIX */ if (access_ok(VERIFY_WRITE, to, n)) __do_clear_user(to, n); return n; @@ -149,6 +163,10 @@ unsigned long __clear_user(void *to, unsigned long n) { +#ifdef CONFIG_MOSIX + if (USER_IS_REMOTE) + return(deputy_clear_user(to, n, 0)); +#endif /* CONFIG_MOSIX */ __do_clear_user(to, n); return n; } @@ -164,6 +182,10 @@ unsigned long mask = -__addr_ok(s); unsigned long res, tmp; +#ifdef CONFIG_MOSIX + if(USER_IS_REMOTE) + return(deputy_strnlen_user((char *)s, n)); +#endif /* CONFIG_MOSIX */ __asm__ __volatile__( " testl %0, %0\n" " jz 3f\n" diff -urN linux-2.4.17/arch/i386/mm/fault.c linux_umopenmosix/arch/i386/mm/fault.c --- linux-2.4.17/arch/i386/mm/fault.c Wed Oct 10 00:13:03 2001 +++ linux_umopenmosix/arch/i386/mm/fault.c Sun Jun 23 12:40:10 2002 @@ -25,6 +25,10 @@ #include #include +#ifdef CONFIG_MOSIX +#include +#endif /* CONFIG_MOSIX */ + extern void die(const char *,struct pt_regs *,long); extern int console_loglevel; @@ -40,6 +44,10 @@ if (!size) return 1; +#ifdef CONFIG_MOSIX + if(USER_IS_REMOTE) + return(deputy_verify_write((void *)addr, size)); +#endif /* CONFIG_MOSIX */ vma = find_vma(current->mm, start); if (!vma) goto bad_area; @@ -136,6 +144,10 @@ asmlinkage void do_invalid_op(struct pt_regs *, unsigned long); extern unsigned long idt; +#ifdef CONFIG_MOSIX_UDB +int debug_fixup = 0; +#endif /* CONFIG_MOSIX_UDB */ + /* * This routine handles page faults. It determines the address, * and the problem, and then passes it off to one of the appropriate @@ -263,6 +275,10 @@ */ if (regs->eflags & VM_MASK) { unsigned long bit = (address - 0xA0000) >> PAGE_SHIFT; +#ifdef CONFIG_MOSIX_DIAG + if(!(current->mosix.stay & DSTAY_FOR_86)) + panic("VM_MASK without STAY"); +#endif /* CONFIG_MOSIX_DIAG */ if (bit < 32) tsk->thread.screen_bitmap |= 1 << bit; } @@ -307,6 +323,10 @@ /* Are we prepared to handle this kernel fault? */ if ((fixup = search_exception_table(regs->eip)) != 0) { regs->eip = fixup; +#ifdef CONFIG_MOSIX_UDB + if(debug_fixup) + mosix_debugger("fixup"); +#endif /* CONFIG_MOSIX_UDB */ return; } diff -urN linux-2.4.17/arch/um/Makefile linux_umopenmosix/arch/um/Makefile --- linux-2.4.17/arch/um/Makefile Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/Makefile Sun Jun 23 12:40:10 2002 @@ -0,0 +1,110 @@ +include arch/$(ARCH)/Makefile-$(SUBARCH) + +EXTRAVERSION := $(EXTRAVERSION)-14um +include/linux/version.h: arch/$(ARCH)/Makefile + +# Recalculate MODLIB to reflect the EXTRAVERSION changes (via KERNELRELEASE) +# The way the toplevel Makefile is written EXTRAVERSION is not supposed +# to be changed outside the toplevel Makefile, but recalculating MODLIB is +# a sufficient workaround until we no longer need architecture dependent +# EXTRAVERSION... +MODLIB := $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE) + +ARCH_DIR = arch/um + +MAKEBOOT = $(MAKE) -C $(ARCH_DIR)/boot + +ifeq ($(CONFIG_DEBUGSYM),y) +DEBUG = -g +CFLAGS := $(subst -fomit-frame-pointer,,$(CFLAGS)) +endif + +ifeq ($(CONFIG_GCOV),y) +CFLAGS += -fprofile-arcs -ftest-coverage +endif + +ifeq ($(CONFIG_GPROF), y) +PROFILE += -pg -DPROFILING +LINK_PROFILE = $(PROFILE) -Wl,--wrap,__monstartup +endif + +SUBDIRS += $(ARCH_DIR)/fs $(ARCH_DIR)/drivers $(ARCH_DIR)/kernel \ + $(ARCH_DIR)/sys-$(SUBARCH) + +LIBS += $(shell [ -e $(ARCH_DIR)/fs/fs.o ] && echo $(ARCH_DIR)/fs/fs.o) \ + $(ARCH_DIR)/kernel/um.o $(ARCH_DIR)/drivers/um_drivers.o \ + $(ARCH_DIR)/sys-$(SUBARCH)/sys.o + +ifeq ($(CONFIG_PT_PROXY), y) +SUBDIRS += $(ARCH_DIR)/ptproxy +LIBS += $(ARCH_DIR)/ptproxy/ptproxy.a +endif + +NESTING = 0 + +ARCH_INCLUDE = $(TOPDIR)/$(ARCH_DIR)/include + +# -Derrno=kernel_errno - This turns all kernel references to errno into +# kernel_errno to separate them from the libc errno. This allows -fno-common +# in CFLAGS. Otherwise, it would cause ld to complain about the two different +# errnos. + +CFLAGS += $(DEBUG) $(PROFILE) $(ARCH_CFLAGS) -D__arch_um__ \ + -DSUBARCH=\"$(SUBARCH)\" -DNESTING=$(NESTING) -D_LARGEFILE64_SOURCE \ + -I$(ARCH_INCLUDE) -Derrno=kernel_errno + +LINKFLAGS += -r + +LINK_WRAPS = -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc + +$(ARCH_DIR)/link.ld: $(ARCH_DIR)/link.ld.in + m4 -DSTART=$(START_ADDR) -DSUBARCH=$(SUBARCH) \ + -DELF_SUBARCH=$(ELF_SUBARCH) $< > $@ + +SYMLINK_HEADERS = include/asm-um/archparam.h include/asm-um/system.h \ + include/asm-um/sigcontext.h include/asm-um/processor.h + +ARCH_SYMLINKS = include/asm-um/arch arch/um/include/sysdep $(SYMLINK_HEADERS) + +linux: $(ARCH_SYMLINKS) $(ARCH_DIR)/main.o vmlinux $(ARCH_DIR)/link.ld + mv vmlinux vmlinux.o + $(CC) -Wl,-T,$(ARCH_DIR)/link.ld $(LINK_PROFILE) $(LINK_WRAPS) \ + -o linux -static $(ARCH_DIR)/main.o vmlinux.o -L/usr/lib + +USER_CFLAGS := $(patsubst -I%,,$(CFLAGS)) +USER_CFLAGS := $(patsubst -Derrno=kernel_errno,,$(USER_CFLAGS)) +USER_CFLAGS := $(patsubst -D__KERNEL__,,$(USER_CFLAGS)) -I$(ARCH_INCLUDE) + +# To get a definition of F_SETSIG +USER_CFLAGS += -D_GNU_SOURCE + +$(ARCH_DIR)/main.o: $(ARCH_DIR)/main.c + $(CC) $(USER_CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $< + +archmrproper: + $(MAKE) -C $(ARCH_DIR)/sys-$(SUBARCH) archmrproper + rm -f $(SYMLINK_HEADERS) $(ARCH_SYMLINKS) include/asm \ + $(ARCH_DIR)/link.ld \ + $(addprefix $(ARCH_DIR)/kernel/,$(KERN_SYMLINKS)) + +archclean: + find . \( -name '*.bb' -o -name '*.bbg' -o -name '*.da' \ + -o -name '*.gcov' \) -type f -print | xargs rm -f + rm -f linux x.i gmon.out $(ARCH_DIR)/link.ld + @$(MAKEBOOT) clean + +archdep: $(ARCH_SYMLINKS) + @$(MAKEBOOT) dep + +$(SYMLINK_HEADERS): + echo $@ + cd $(TOPDIR)/$(dir $@) ; \ + ln -sf $(basename $(notdir $@))-$(SUBARCH)$(suffix $@) $(notdir $@) + +include/asm-um/arch: + cd $(TOPDIR)/include/asm-um && ln -sf ../asm-$(SUBARCH) arch + +arch/um/include/sysdep: + cd $(TOPDIR)/arch/um/include && ln -sf sysdep-$(SUBARCH) sysdep + +export SUBARCH USER_CFLAGS diff -urN linux-2.4.17/arch/um/Makefile-i386 linux_umopenmosix/arch/um/Makefile-i386 --- linux-2.4.17/arch/um/Makefile-i386 Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/Makefile-i386 Sun Jun 23 12:40:10 2002 @@ -0,0 +1,8 @@ +ifeq ($(CONFIG_HOST_2G_2G), y) +START_ADDR = 0x60000000 +else +START_ADDR = 0xa0000000 +endif + +ARCH_CFLAGS = -U__$(SUBARCH)__ -U$(SUBARCH) -DUM_FASTCALL +ELF_SUBARCH = $(SUBARCH) diff -urN linux-2.4.17/arch/um/Makefile-ia64 linux_umopenmosix/arch/um/Makefile-ia64 --- linux-2.4.17/arch/um/Makefile-ia64 Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/Makefile-ia64 Sun Jun 23 12:40:10 2002 @@ -0,0 +1 @@ +START_ADDR = 0x1000000000000000 diff -urN linux-2.4.17/arch/um/Makefile-ppc linux_umopenmosix/arch/um/Makefile-ppc --- linux-2.4.17/arch/um/Makefile-ppc Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/Makefile-ppc Sun Jun 23 12:40:10 2002 @@ -0,0 +1,9 @@ +ifeq ($(CONFIG_HOST_2G_2G), y) +START_ADDR = 0x60000000 +else +START_ADDR = 0xa0000000 +endif +ARCH_CFLAGS = -U__powerpc__ -D__UM_PPC__ + +# The arch is ppc, but the elf32 name is powerpc +ELF_SUBARCH = powerpc diff -urN linux-2.4.17/arch/um/boot/Makefile linux_umopenmosix/arch/um/boot/Makefile --- linux-2.4.17/arch/um/boot/Makefile Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/boot/Makefile Sun Jun 23 12:40:10 2002 @@ -0,0 +1,3 @@ +dep: + +clean: diff -urN linux-2.4.17/arch/um/config.in linux_umopenmosix/arch/um/config.in --- linux-2.4.17/arch/um/config.in Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/config.in Sun Jun 23 12:40:10 2002 @@ -0,0 +1,142 @@ +define_bool CONFIG_USERMODE y + +mainmenu_name "Linux/Usermode Kernel Configuration" + +define_bool CONFIG_ISA n +define_bool CONFIG_SBUS n +define_bool CONFIG_PCI n + +define_bool CONFIG_UID16 y + +define_bool CONFIG_RWSEM_XCHGADD_ALGORITHM y + +mainmenu_option next_comment +comment 'Code maturity level options' +bool 'Prompt for development and/or incomplete code/drivers' CONFIG_EXPERIMENTAL +endmenu + +mainmenu_option next_comment +comment 'openMosix' +bool 'openMosix process migration support' CONFIG_MOSIX +if [ "$CONFIG_MOSIX" = "y" ]; then + bool 'Support clusters with a complex network topology' CONFIG_MOSIX_TOPOLOGY + if [ "$CONFIG_MOSIX_TOPOLOGY" = "y" ]; then + int 'Maximum network-topology complexity to support (2-10)' CONFIG_MOSIX_MAXTOPOLOGY 4 + fi + + bool 'Stricter security on openMosix ports' CONFIG_MOSIX_SECUREPORTS + int 'Level of process-identity disclosure (0-3)' CONFIG_MOSIX_DISCLOSURE 1 + bool 'Create the kernel with a "-openmosix" extension' CONFIG_MOSIX_EXTMOSIX +# bool 'Direct File-System Access' CONFIG_MOSIX_DFSA + bool 'openMosix File-System' CONFIG_MOSIX_FS + if [ "$CONFIG_MOSIX_FS" = "y" ]; then CONFIG_MOSIX_DFSA = "y" + fi + bool 'Poll/Select exceptions on pipes' CONFIG_MOSIX_PIPE_EXCEPTIONS +fi +endmenu + +mainmenu_option next_comment +comment 'General Setup' +define_bool CONFIG_STDIO_CONSOLE y +bool 'Networking support' CONFIG_NET +bool 'System V IPC' CONFIG_SYSVIPC +bool 'BSD Process Accounting' CONFIG_BSD_PROCESS_ACCT +bool 'Sysctl support' CONFIG_SYSCTL +tristate 'Kernel support for a.out binaries' CONFIG_BINFMT_AOUT +tristate 'Kernel support for ELF binaries' CONFIG_BINFMT_ELF +tristate 'Kernel support for MISC binaries' CONFIG_BINFMT_MISC +bool 'Unix98 PTY support' CONFIG_UNIX98_PTYS +if [ "$CONFIG_UNIX98_PTYS" = "y" ]; then + int 'Maximum number of Unix98 PTYs in use (0-2048)' CONFIG_UNIX98_PTY_COUNT 256 +fi +bool 'Virtual serial line' CONFIG_SSL +tristate 'Host filesystem' CONFIG_HOSTFS +bool 'Management console' CONFIG_MCONSOLE +dep_bool 'Magic SysRq key' CONFIG_MAGIC_SYSRQ $CONFIG_MCONSOLE +bool '2G/2G host address space split' CONFIG_HOST_2G_2G +bool 'Symmetric multi-processing support' CONFIG_UML_SMP +define_bool CONFIG_SMP $CONFIG_UML_SMP +string 'Default main console channel initialization' CONFIG_CON_ZERO_CHAN \ + "fd:0,fd:1" +string 'Default console channel initialization' CONFIG_CON_CHAN "xterm" +string 'Default serial line channel initialization' CONFIG_SSL_CHAN "pty" +endmenu + +mainmenu_option next_comment +comment 'Loadable module support' +bool 'Enable loadable module support' CONFIG_MODULES +if [ "$CONFIG_MODULES" = "y" ]; then +# MODVERSIONS does not yet work in this architecture +# bool ' Set version information on all module symbols' CONFIG_MODVERSIONS + bool ' Kernel module loader' CONFIG_KMOD +fi +endmenu + +mainmenu_option next_comment +comment 'Devices' +define_bool CONFIG_BLK_DEV_UBD y +bool 'Always do synchronous disk IO for UBD' CONFIG_BLK_DEV_UBD_SYNC +tristate 'Loopback device support' CONFIG_BLK_DEV_LOOP +dep_tristate 'Network block device support' CONFIG_BLK_DEV_NBD $CONFIG_NET +tristate 'RAM disk support' CONFIG_BLK_DEV_RAM +if [ "$CONFIG_BLK_DEV_RAM" = "y" -o "$CONFIG_BLK_DEV_RAM" = "m" ]; then + int ' Default RAM disk size' CONFIG_BLK_DEV_RAM_SIZE 4096 +fi +dep_bool ' Initial RAM disk (initrd) support' CONFIG_BLK_DEV_INITRD $CONFIG_BLK_DEV_RAM +tristate 'Example IO memory driver' CONFIG_MMAPPER + +tristate 'Sound support' CONFIG_UML_SOUND +define_tristate CONFIG_SOUND $CONFIG_UML_SOUND +define_tristate CONFIG_HOSTAUDIO $CONFIG_UML_SOUND + +bool 'file descriptor channel support' CONFIG_FD_CHAN +bool 'port channel support' CONFIG_PORT_CHAN +bool 'pty channel support' CONFIG_PTY_CHAN +bool 'tty channel support' CONFIG_TTY_CHAN +bool 'xterm channel support' CONFIG_XTERM_CHAN + +endmenu + +if [ "$CONFIG_NET" = "y" ]; then + source net/Config.in +fi + +if [ "$CONFIG_NET" = "y" ]; then + mainmenu_option next_comment + comment 'Network device support' + + bool 'Virtual network device support' CONFIG_UML_NET + if [ "$CONFIG_UML_NET" != "n" ]; then + bool ' Ethertap transport' CONFIG_UML_NET_ETHERTAP + bool ' TUN/TAP transport' CONFIG_UML_NET_TUNTAP + bool ' SLIP transport' CONFIG_UML_NET_SLIP + bool ' Daemon transport' CONFIG_UML_NET_DAEMON + bool ' Multicast transport' CONFIG_UML_NET_MCAST + fi + + bool 'Software network device support' CONFIG_NETDEVICES + if [ "$CONFIG_NETDEVICES" = "y" ]; then + source drivers/net/Config.in + fi + + endmenu +fi + +source fs/Config.in + +source drivers/md/Config.in + +source drivers/mtd/Config.in + +mainmenu_option next_comment +comment 'Kernel hacking' +bool 'Debug memory allocations' CONFIG_DEBUG_SLAB +bool 'Enable kernel debugging symbols' CONFIG_DEBUGSYM +if [ "$CONFIG_XTERM_CHAN" = "y" ]; then + dep_bool 'Enable ptrace proxy' CONFIG_PT_PROXY $CONFIG_DEBUGSYM +else + define_bool CONFIG_PT_PROXY n +fi +dep_bool 'Enable gprof support' CONFIG_GPROF $CONFIG_DEBUGSYM +dep_bool 'Enable gcov support' CONFIG_GCOV $CONFIG_DEBUGSYM +endmenu diff -urN linux-2.4.17/arch/um/config.in.org linux_umopenmosix/arch/um/config.in.org --- linux-2.4.17/arch/um/config.in.org Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/config.in.org Sun Jun 23 12:40:10 2002 @@ -0,0 +1,122 @@ +define_bool CONFIG_USERMODE y + +mainmenu_name "Linux/Usermode Kernel Configuration" + +define_bool CONFIG_ISA n +define_bool CONFIG_SBUS n +define_bool CONFIG_PCI n + +define_bool CONFIG_UID16 y + +define_bool CONFIG_RWSEM_XCHGADD_ALGORITHM y + +mainmenu_option next_comment +comment 'Code maturity level options' +bool 'Prompt for development and/or incomplete code/drivers' CONFIG_EXPERIMENTAL +endmenu + +mainmenu_option next_comment +comment 'General Setup' +define_bool CONFIG_STDIO_CONSOLE y +bool 'Networking support' CONFIG_NET +bool 'System V IPC' CONFIG_SYSVIPC +bool 'BSD Process Accounting' CONFIG_BSD_PROCESS_ACCT +bool 'Sysctl support' CONFIG_SYSCTL +tristate 'Kernel support for a.out binaries' CONFIG_BINFMT_AOUT +tristate 'Kernel support for ELF binaries' CONFIG_BINFMT_ELF +tristate 'Kernel support for MISC binaries' CONFIG_BINFMT_MISC +bool 'Unix98 PTY support' CONFIG_UNIX98_PTYS +if [ "$CONFIG_UNIX98_PTYS" = "y" ]; then + int 'Maximum number of Unix98 PTYs in use (0-2048)' CONFIG_UNIX98_PTY_COUNT 256 +fi +bool 'Virtual serial line' CONFIG_SSL +tristate 'Host filesystem' CONFIG_HOSTFS +bool 'Management console' CONFIG_MCONSOLE +dep_bool 'Magic SysRq key' CONFIG_MAGIC_SYSRQ $CONFIG_MCONSOLE +bool '2G/2G host address space split' CONFIG_HOST_2G_2G +bool 'Symmetric multi-processing support' CONFIG_UML_SMP +define_bool CONFIG_SMP $CONFIG_UML_SMP +string 'Default main console channel initialization' CONFIG_CON_ZERO_CHAN \ + "fd:0,fd:1" +string 'Default console channel initialization' CONFIG_CON_CHAN "xterm" +string 'Default serial line channel initialization' CONFIG_SSL_CHAN "pty" +endmenu + +mainmenu_option next_comment +comment 'Loadable module support' +bool 'Enable loadable module support' CONFIG_MODULES +if [ "$CONFIG_MODULES" = "y" ]; then +# MODVERSIONS does not yet work in this architecture +# bool ' Set version information on all module symbols' CONFIG_MODVERSIONS + bool ' Kernel module loader' CONFIG_KMOD +fi +endmenu + +mainmenu_option next_comment +comment 'Devices' +define_bool CONFIG_BLK_DEV_UBD y +bool 'Always do synchronous disk IO for UBD' CONFIG_BLK_DEV_UBD_SYNC +tristate 'Loopback device support' CONFIG_BLK_DEV_LOOP +dep_tristate 'Network block device support' CONFIG_BLK_DEV_NBD $CONFIG_NET +tristate 'RAM disk support' CONFIG_BLK_DEV_RAM +if [ "$CONFIG_BLK_DEV_RAM" = "y" -o "$CONFIG_BLK_DEV_RAM" = "m" ]; then + int ' Default RAM disk size' CONFIG_BLK_DEV_RAM_SIZE 4096 +fi +dep_bool ' Initial RAM disk (initrd) support' CONFIG_BLK_DEV_INITRD $CONFIG_BLK_DEV_RAM +tristate 'Example IO memory driver' CONFIG_MMAPPER + +tristate 'Sound support' CONFIG_UML_SOUND +define_tristate CONFIG_SOUND $CONFIG_UML_SOUND +define_tristate CONFIG_HOSTAUDIO $CONFIG_UML_SOUND + +bool 'file descriptor channel support' CONFIG_FD_CHAN +bool 'port channel support' CONFIG_PORT_CHAN +bool 'pty channel support' CONFIG_PTY_CHAN +bool 'tty channel support' CONFIG_TTY_CHAN +bool 'xterm channel support' CONFIG_XTERM_CHAN + +endmenu + +if [ "$CONFIG_NET" = "y" ]; then + source net/Config.in +fi + +if [ "$CONFIG_NET" = "y" ]; then + mainmenu_option next_comment + comment 'Network device support' + + bool 'Virtual network device support' CONFIG_UML_NET + if [ "$CONFIG_UML_NET" != "n" ]; then + bool ' Ethertap transport' CONFIG_UML_NET_ETHERTAP + bool ' TUN/TAP transport' CONFIG_UML_NET_TUNTAP + bool ' SLIP transport' CONFIG_UML_NET_SLIP + bool ' Daemon transport' CONFIG_UML_NET_DAEMON + bool ' Multicast transport' CONFIG_UML_NET_MCAST + fi + + bool 'Software network device support' CONFIG_NETDEVICES + if [ "$CONFIG_NETDEVICES" = "y" ]; then + source drivers/net/Config.in + fi + + endmenu +fi + +source fs/Config.in + +source drivers/md/Config.in + +source drivers/mtd/Config.in + +mainmenu_option next_comment +comment 'Kernel hacking' +bool 'Debug memory allocations' CONFIG_DEBUG_SLAB +bool 'Enable kernel debugging symbols' CONFIG_DEBUGSYM +if [ "$CONFIG_XTERM_CHAN" = "y" ]; then + dep_bool 'Enable ptrace proxy' CONFIG_PT_PROXY $CONFIG_DEBUGSYM +else + define_bool CONFIG_PT_PROXY n +fi +dep_bool 'Enable gprof support' CONFIG_GPROF $CONFIG_DEBUGSYM +dep_bool 'Enable gcov support' CONFIG_GCOV $CONFIG_DEBUGSYM +endmenu diff -urN linux-2.4.17/arch/um/config.release linux_umopenmosix/arch/um/config.release --- linux-2.4.17/arch/um/config.release Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/config.release Sun Jun 23 12:40:10 2002 @@ -0,0 +1,300 @@ +# +# Automatically generated make config: don't edit +# +CONFIG_USERMODE=y +# CONFIG_ISA is not set +# CONFIG_SBUS is not set +# CONFIG_PCI is not set +CONFIG_UID16=y +CONFIG_RWSEM_XCHGADD_ALGORITHM=y + +# +# Code maturity level options +# +CONFIG_EXPERIMENTAL=y + +# +# General Setup +# +CONFIG_STDIO_CONSOLE=y +CONFIG_NET=y +CONFIG_SYSVIPC=y +CONFIG_BSD_PROCESS_ACCT=y +CONFIG_SYSCTL=y +CONFIG_BINFMT_AOUT=y +CONFIG_BINFMT_ELF=y +CONFIG_BINFMT_MISC=y +CONFIG_UNIX98_PTYS=y +CONFIG_UNIX98_PTY_COUNT=256 +CONFIG_SSL=y +CONFIG_HOSTFS=y +CONFIG_MCONSOLE=y +CONFIG_MAGIC_SYSRQ=y +# CONFIG_HOST_2G_2G is not set + +# +# Loadable module support +# +CONFIG_MODULES=y +CONFIG_KMOD=y + +# +# Devices +# +CONFIG_BLK_DEV_UBD=y +# CONFIG_BLK_DEV_UBD_SYNC is not set +CONFIG_BLK_DEV_LOOP=y +CONFIG_BLK_DEV_NBD=y +CONFIG_BLK_DEV_RAM=y +CONFIG_BLK_DEV_RAM_SIZE=4096 +# CONFIG_BLK_DEV_INITRD is not set +# CONFIG_MMAPPER is not set + +# +# Networking options +# +CONFIG_PACKET=y +CONFIG_PACKET_MMAP=y +# CONFIG_NETLINK_DEV is not set +# CONFIG_NETFILTER is not set +# CONFIG_FILTER is not set +CONFIG_UNIX=y +CONFIG_INET=y +# CONFIG_IP_MULTICAST is not set +# CONFIG_IP_ADVANCED_ROUTER is not set +# CONFIG_IP_PNP is not set +# CONFIG_NET_IPIP is not set +# CONFIG_NET_IPGRE is not set +# CONFIG_ARPD is not set +# CONFIG_INET_ECN is not set +# CONFIG_SYN_COOKIES is not set +# CONFIG_IPV6 is not set +# CONFIG_KHTTPD is not set +# CONFIG_ATM is not set +# CONFIG_VLAN_8021Q is not set + +# +# +# +# CONFIG_IPX is not set +# CONFIG_ATALK is not set +# CONFIG_DECNET is not set +# CONFIG_BRIDGE is not set +# CONFIG_X25 is not set +# CONFIG_LAPB is not set +# CONFIG_LLC is not set +# CONFIG_NET_DIVERT is not set +# CONFIG_ECONET is not set +# CONFIG_WAN_ROUTER is not set +# CONFIG_NET_FASTROUTE is not set +# CONFIG_NET_HW_FLOWCONTROL is not set + +# +# QoS and/or fair queueing +# +# CONFIG_NET_SCHED is not set + +# +# Network device support +# +CONFIG_UML_NET=y +CONFIG_UML_NET_ETHERTAP=y +CONFIG_UML_NET_TUNTAP=y +CONFIG_UML_NET_SLIP=y +CONFIG_UML_NET_DAEMON=y +CONFIG_UML_NET_MCAST=y +CONFIG_NETDEVICES=y + +# +# ARCnet devices +# +# CONFIG_ARCNET is not set +CONFIG_DUMMY=y +CONFIG_BONDING=m +CONFIG_EQUALIZER=m +CONFIG_TUN=y +# CONFIG_ETHERTAP is not set + +# +# Ethernet (10 or 100Mbit) +# +# CONFIG_NET_ETHERNET is not set + +# +# Ethernet (1000 Mbit) +# +# CONFIG_ACENIC is not set +# CONFIG_DL2K is not set +# CONFIG_MYRI_SBUS is not set +# CONFIG_NS83820 is not set +# CONFIG_HAMACHI is not set +# CONFIG_YELLOWFIN is not set +# CONFIG_SK98LIN is not set +# CONFIG_FDDI is not set +# CONFIG_HIPPI is not set +CONFIG_PLIP=m +CONFIG_PPP=m +CONFIG_PPP_MULTILINK=y +# CONFIG_PPP_FILTER is not set +# CONFIG_PPP_ASYNC is not set +CONFIG_PPP_SYNC_TTY=m +CONFIG_PPP_DEFLATE=m +CONFIG_PPP_BSDCOMP=m +CONFIG_PPPOE=m +CONFIG_SLIP=m +CONFIG_SLIP_COMPRESSED=y +CONFIG_SLIP_SMART=y +# CONFIG_SLIP_MODE_SLIP6 is not set + +# +# Wireless LAN (non-hamradio) +# +# CONFIG_NET_RADIO is not set + +# +# Token Ring devices +# +# CONFIG_TR is not set +# CONFIG_NET_FC is not set +# CONFIG_RCPCI is not set +CONFIG_SHAPER=m + +# +# Wan interfaces +# +# CONFIG_WAN is not set + +# +# File systems +# +CONFIG_QUOTA=y +CONFIG_AUTOFS_FS=m +CONFIG_AUTOFS4_FS=m +CONFIG_REISERFS_FS=m +# CONFIG_REISERFS_CHECK is not set +# CONFIG_REISERFS_PROC_INFO is not set +CONFIG_ADFS_FS=m +# CONFIG_ADFS_FS_RW is not set +CONFIG_AFFS_FS=m +CONFIG_HFS_FS=m +CONFIG_BFS_FS=m +# CONFIG_EXT3_FS is not set +# CONFIG_JBD is not set +# CONFIG_JBD_DEBUG is not set +CONFIG_FAT_FS=y +CONFIG_MSDOS_FS=y +CONFIG_UMSDOS_FS=y +CONFIG_VFAT_FS=y +CONFIG_EFS_FS=m +CONFIG_JFFS_FS=m +CONFIG_JFFS_FS_VERBOSE=0 +# CONFIG_JFFS_PROC_FS is not set +# CONFIG_JFFS2_FS is not set +CONFIG_CRAMFS=m +CONFIG_TMPFS=y +CONFIG_RAMFS=m +CONFIG_ISO9660_FS=y +# CONFIG_JOLIET is not set +# CONFIG_ZISOFS is not set +CONFIG_MINIX_FS=m +CONFIG_VXFS_FS=m +# CONFIG_NTFS_FS is not set +# CONFIG_NTFS_RW is not set +CONFIG_HPFS_FS=m +CONFIG_PROC_FS=y +CONFIG_DEVFS_FS=y +CONFIG_DEVFS_MOUNT=y +# CONFIG_DEVFS_DEBUG is not set +CONFIG_DEVPTS_FS=y +CONFIG_QNX4FS_FS=m +# CONFIG_QNX4FS_RW is not set +CONFIG_ROMFS_FS=m +CONFIG_EXT2_FS=y +CONFIG_SYSV_FS=m +CONFIG_UDF_FS=m +# CONFIG_UDF_RW is not set +CONFIG_UFS_FS=m +# CONFIG_UFS_FS_WRITE is not set + +# +# Network File Systems +# +# CONFIG_CODA_FS is not set +# CONFIG_INTERMEZZO_FS is not set +# CONFIG_NFS_FS is not set +# CONFIG_NFS_V3 is not set +# CONFIG_ROOT_NFS is not set +# CONFIG_NFSD is not set +# CONFIG_NFSD_V3 is not set +# CONFIG_SUNRPC is not set +# CONFIG_LOCKD is not set +# CONFIG_SMB_FS is not set +# CONFIG_NCP_FS is not set +# CONFIG_NCPFS_PACKET_SIGNING is not set +# CONFIG_NCPFS_IOCTL_LOCKING is not set +# CONFIG_NCPFS_STRONG is not set +# CONFIG_NCPFS_NFS_NS is not set +# CONFIG_NCPFS_OS2_NS is not set +# CONFIG_NCPFS_SMALLDOS is not set +# CONFIG_NCPFS_NLS is not set +# CONFIG_NCPFS_EXTRAS is not set +# CONFIG_ZISOFS_FS is not set +CONFIG_ZLIB_FS_INFLATE=m + +# +# Partition Types +# +# CONFIG_PARTITION_ADVANCED is not set +CONFIG_MSDOS_PARTITION=y +# CONFIG_SMB_NLS is not set +CONFIG_NLS=y + +# +# Native Language Support +# +CONFIG_NLS_DEFAULT="iso8859-1" +# CONFIG_NLS_CODEPAGE_437 is not set +# CONFIG_NLS_CODEPAGE_737 is not set +# CONFIG_NLS_CODEPAGE_775 is not set +# CONFIG_NLS_CODEPAGE_850 is not set +# CONFIG_NLS_CODEPAGE_852 is not set +# CONFIG_NLS_CODEPAGE_855 is not set +# CONFIG_NLS_CODEPAGE_857 is not set +# CONFIG_NLS_CODEPAGE_860 is not set +# CONFIG_NLS_CODEPAGE_861 is not set +# CONFIG_NLS_CODEPAGE_862 is not set +# CONFIG_NLS_CODEPAGE_863 is not set +# CONFIG_NLS_CODEPAGE_864 is not set +# CONFIG_NLS_CODEPAGE_865 is not set +# CONFIG_NLS_CODEPAGE_866 is not set +# CONFIG_NLS_CODEPAGE_869 is not set +# CONFIG_NLS_CODEPAGE_936 is not set +# CONFIG_NLS_CODEPAGE_950 is not set +# CONFIG_NLS_CODEPAGE_932 is not set +# CONFIG_NLS_CODEPAGE_949 is not set +# CONFIG_NLS_CODEPAGE_874 is not set +# CONFIG_NLS_ISO8859_8 is not set +# CONFIG_NLS_CODEPAGE_1251 is not set +# CONFIG_NLS_ISO8859_1 is not set +# CONFIG_NLS_ISO8859_2 is not set +# CONFIG_NLS_ISO8859_3 is not set +# CONFIG_NLS_ISO8859_4 is not set +# CONFIG_NLS_ISO8859_5 is not set +# CONFIG_NLS_ISO8859_6 is not set +# CONFIG_NLS_ISO8859_7 is not set +# CONFIG_NLS_ISO8859_9 is not set +# CONFIG_NLS_ISO8859_13 is not set +# CONFIG_NLS_ISO8859_14 is not set +# CONFIG_NLS_ISO8859_15 is not set +# CONFIG_NLS_KOI8_R is not set +# CONFIG_NLS_KOI8_U is not set +# CONFIG_NLS_UTF8 is not set + +# +# Kernel hacking +# +# CONFIG_DEBUG_SLAB is not set +# CONFIG_DEBUGSYM is not set +# CONFIG_PT_PROXY is not set +# CONFIG_GPROF is not set +# CONFIG_GCOV is not set diff -urN linux-2.4.17/arch/um/defconfig linux_umopenmosix/arch/um/defconfig --- linux-2.4.17/arch/um/defconfig Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/defconfig Sun Jun 23 12:40:10 2002 @@ -0,0 +1,344 @@ +# +# Automatically generated make config: don't edit +# +CONFIG_USERMODE=y +# CONFIG_ISA is not set +# CONFIG_SBUS is not set +# CONFIG_PCI is not set +CONFIG_UID16=y +CONFIG_RWSEM_XCHGADD_ALGORITHM=y + +# +# Code maturity level options +# +CONFIG_EXPERIMENTAL=y + +# +# General Setup +# +CONFIG_STDIO_CONSOLE=y +CONFIG_NET=y +CONFIG_SYSVIPC=y +CONFIG_BSD_PROCESS_ACCT=y +CONFIG_SYSCTL=y +CONFIG_BINFMT_AOUT=y +CONFIG_BINFMT_ELF=y +CONFIG_BINFMT_MISC=y +CONFIG_UNIX98_PTYS=y +CONFIG_UNIX98_PTY_COUNT=256 +CONFIG_SSL=y +CONFIG_HOSTFS=m +CONFIG_MCONSOLE=y +CONFIG_MAGIC_SYSRQ=y +# CONFIG_HOST_2G_2G is not set +# CONFIG_UML_SMP is not set +# CONFIG_SMP is not set +CONFIG_CON_ZERO_CHAN="fd:0,fd:1" +CONFIG_CON_CHAN="xterm" +CONFIG_SSL_CHAN="pty" + +# +# Loadable module support +# +CONFIG_MODULES=y +# CONFIG_KMOD is not set + +# +# Devices +# +CONFIG_BLK_DEV_UBD=y +# CONFIG_BLK_DEV_UBD_SYNC is not set +CONFIG_BLK_DEV_LOOP=y +CONFIG_BLK_DEV_NBD=y +CONFIG_BLK_DEV_RAM=y +CONFIG_BLK_DEV_RAM_SIZE=4096 +CONFIG_BLK_DEV_INITRD=y +# CONFIG_MMAPPER is not set +CONFIG_UML_SOUND=y +CONFIG_SOUND=y +CONFIG_HOSTAUDIO=y +CONFIG_FD_CHAN=y +CONFIG_PORT_CHAN=y +CONFIG_PTY_CHAN=y +CONFIG_TTY_CHAN=y +CONFIG_XTERM_CHAN=y + +# +# Networking options +# +CONFIG_PACKET=y +CONFIG_PACKET_MMAP=y +# CONFIG_NETLINK_DEV is not set +# CONFIG_NETFILTER is not set +# CONFIG_FILTER is not set +CONFIG_UNIX=y +CONFIG_INET=y +# CONFIG_IP_MULTICAST is not set +# CONFIG_IP_ADVANCED_ROUTER is not set +# CONFIG_IP_PNP is not set +# CONFIG_NET_IPIP is not set +# CONFIG_NET_IPGRE is not set +# CONFIG_ARPD is not set +# CONFIG_INET_ECN is not set +# CONFIG_SYN_COOKIES is not set +# CONFIG_IPV6 is not set +# CONFIG_KHTTPD is not set +# CONFIG_ATM is not set +# CONFIG_VLAN_8021Q is not set + +# +# +# +# CONFIG_IPX is not set +# CONFIG_ATALK is not set +# CONFIG_DECNET is not set +# CONFIG_BRIDGE is not set +# CONFIG_X25 is not set +# CONFIG_LAPB is not set +# CONFIG_LLC is not set +# CONFIG_NET_DIVERT is not set +# CONFIG_ECONET is not set +# CONFIG_WAN_ROUTER is not set +# CONFIG_NET_FASTROUTE is not set +# CONFIG_NET_HW_FLOWCONTROL is not set + +# +# QoS and/or fair queueing +# +# CONFIG_NET_SCHED is not set + +# +# Network device support +# +CONFIG_UML_NET=y +CONFIG_UML_NET_ETHERTAP=y +CONFIG_UML_NET_TUNTAP=y +CONFIG_UML_NET_SLIP=y +CONFIG_UML_NET_DAEMON=y +CONFIG_UML_NET_MCAST=y +CONFIG_NETDEVICES=y + +# +# ARCnet devices +# +# CONFIG_ARCNET is not set +CONFIG_DUMMY=y +# CONFIG_BONDING is not set +# CONFIG_EQUALIZER is not set +CONFIG_TUN=y +CONFIG_ETHERTAP=y + +# +# Ethernet (10 or 100Mbit) +# +# CONFIG_NET_ETHERNET is not set + +# +# Ethernet (1000 Mbit) +# +# CONFIG_ACENIC_OMIT_TIGON_I is not set +# CONFIG_FDDI is not set +# CONFIG_HIPPI is not set +# CONFIG_PLIP is not set +CONFIG_PPP=y +# CONFIG_PPP_MULTILINK is not set +# CONFIG_PPP_ASYNC is not set +# CONFIG_PPP_SYNC_TTY is not set +# CONFIG_PPP_DEFLATE is not set +# CONFIG_PPP_BSDCOMP is not set +# CONFIG_PPPOE is not set +CONFIG_SLIP=y +# CONFIG_SLIP_COMPRESSED is not set +# CONFIG_SLIP_SMART is not set +# CONFIG_SLIP_MODE_SLIP6 is not set + +# +# Wireless LAN (non-hamradio) +# +# CONFIG_NET_RADIO is not set + +# +# Token Ring devices +# +# CONFIG_TR is not set +# CONFIG_NET_FC is not set +# CONFIG_SHAPER is not set + +# +# Wan interfaces +# +# CONFIG_WAN is not set + +# +# File systems +# +CONFIG_QUOTA=y +CONFIG_AUTOFS_FS=m +CONFIG_AUTOFS4_FS=m +CONFIG_REISERFS_FS=m +# CONFIG_REISERFS_CHECK is not set +# CONFIG_REISERFS_PROC_INFO is not set +# CONFIG_ADFS_FS is not set +# CONFIG_AFFS_FS is not set +# CONFIG_HFS_FS is not set +# CONFIG_BFS_FS is not set +# CONFIG_EXT3_FS is not set +# CONFIG_JBD is not set +CONFIG_FAT_FS=m +CONFIG_MSDOS_FS=m +CONFIG_UMSDOS_FS=m +CONFIG_VFAT_FS=m +# CONFIG_EFS_FS is not set +CONFIG_JFFS_FS=y +CONFIG_JFFS_FS_VERBOSE=0 +CONFIG_JFFS_PROC_FS=y +CONFIG_JFFS2_FS=y +CONFIG_JFFS2_FS_DEBUG=0 +# CONFIG_CRAMFS is not set +# CONFIG_TMPFS is not set +# CONFIG_RAMFS is not set +CONFIG_ISO9660_FS=m +# CONFIG_JOLIET is not set +# CONFIG_ZISOFS is not set +CONFIG_MINIX_FS=m +# CONFIG_VXFS_FS is not set +# CONFIG_NTFS_FS is not set +# CONFIG_HPFS_FS is not set +CONFIG_PROC_FS=y +CONFIG_DEVFS_FS=y +CONFIG_DEVFS_MOUNT=y +# CONFIG_DEVFS_DEBUG is not set +CONFIG_DEVPTS_FS=y +# CONFIG_QNX4FS_FS is not set +# CONFIG_ROMFS_FS is not set +CONFIG_EXT2_FS=y +# CONFIG_SYSV_FS is not set +# CONFIG_UDF_FS is not set +# CONFIG_UFS_FS is not set + +# +# Network File Systems +# +# CONFIG_CODA_FS is not set +# CONFIG_INTERMEZZO_FS is not set +# CONFIG_NFS_FS is not set +# CONFIG_NFSD is not set +# CONFIG_SUNRPC is not set +# CONFIG_LOCKD is not set +# CONFIG_SMB_FS is not set +# CONFIG_NCP_FS is not set +# CONFIG_ZISOFS_FS is not set +# CONFIG_ZLIB_FS_INFLATE is not set + +# +# Partition Types +# +# CONFIG_PARTITION_ADVANCED is not set +CONFIG_MSDOS_PARTITION=y +# CONFIG_SMB_NLS is not set +CONFIG_NLS=y + +# +# Native Language Support +# +CONFIG_NLS_DEFAULT="iso8859-1" +# CONFIG_NLS_CODEPAGE_437 is not set +# CONFIG_NLS_CODEPAGE_737 is not set +# CONFIG_NLS_CODEPAGE_775 is not set +# CONFIG_NLS_CODEPAGE_850 is not set +# CONFIG_NLS_CODEPAGE_852 is not set +# CONFIG_NLS_CODEPAGE_855 is not set +# CONFIG_NLS_CODEPAGE_857 is not set +# CONFIG_NLS_CODEPAGE_860 is not set +# CONFIG_NLS_CODEPAGE_861 is not set +# CONFIG_NLS_CODEPAGE_862 is not set +# CONFIG_NLS_CODEPAGE_863 is not set +# CONFIG_NLS_CODEPAGE_864 is not set +# CONFIG_NLS_CODEPAGE_865 is not set +# CONFIG_NLS_CODEPAGE_866 is not set +# CONFIG_NLS_CODEPAGE_869 is not set +# CONFIG_NLS_CODEPAGE_936 is not set +# CONFIG_NLS_CODEPAGE_950 is not set +# CONFIG_NLS_CODEPAGE_932 is not set +# CONFIG_NLS_CODEPAGE_949 is not set +# CONFIG_NLS_CODEPAGE_874 is not set +# CONFIG_NLS_ISO8859_8 is not set +# CONFIG_NLS_CODEPAGE_1251 is not set +# CONFIG_NLS_ISO8859_1 is not set +# CONFIG_NLS_ISO8859_2 is not set +# CONFIG_NLS_ISO8859_3 is not set +# CONFIG_NLS_ISO8859_4 is not set +# CONFIG_NLS_ISO8859_5 is not set +# CONFIG_NLS_ISO8859_6 is not set +# CONFIG_NLS_ISO8859_7 is not set +# CONFIG_NLS_ISO8859_9 is not set +# CONFIG_NLS_ISO8859_13 is not set +# CONFIG_NLS_ISO8859_14 is not set +# CONFIG_NLS_ISO8859_15 is not set +# CONFIG_NLS_KOI8_R is not set +# CONFIG_NLS_KOI8_U is not set +# CONFIG_NLS_UTF8 is not set + +# +# Multi-device support (RAID and LVM) +# +# CONFIG_MD is not set + +# +# Memory Technology Devices (MTD) +# +CONFIG_MTD=y +# CONFIG_MTD_DEBUG is not set +# CONFIG_MTD_PARTITIONS is not set + +# +# User Modules And Translation Layers +# +CONFIG_MTD_CHAR=y +CONFIG_MTD_BLOCK=y +# CONFIG_FTL is not set +# CONFIG_NFTL is not set + +# +# RAM/ROM/Flash chip drivers +# +# CONFIG_MTD_CFI is not set +# CONFIG_MTD_JEDECPROBE is not set +# CONFIG_MTD_GEN_PROBE is not set +# CONFIG_MTD_RAM is not set +# CONFIG_MTD_ROM is not set +# CONFIG_MTD_ABSENT is not set +# CONFIG_MTD_OBSOLETE_CHIPS is not set + +# +# Mapping drivers for chip access +# + +# +# Self-contained MTD device drivers +# +# CONFIG_MTD_SLRAM is not set +# CONFIG_MTD_MTDRAM is not set +CONFIG_MTD_BLKMTD=m + +# +# Disk-On-Chip Device Drivers +# +# CONFIG_MTD_DOC1000 is not set +# CONFIG_MTD_DOC2000 is not set +# CONFIG_MTD_DOC2001 is not set +# CONFIG_MTD_DOCPROBE is not set + +# +# NAND Flash Device Drivers +# +# CONFIG_MTD_NAND is not set + +# +# Kernel hacking +# +# CONFIG_DEBUG_SLAB is not set +CONFIG_DEBUGSYM=y +CONFIG_PT_PROXY=y +# CONFIG_GPROF is not set +# CONFIG_GCOV is not set diff -urN linux-2.4.17/arch/um/drivers/Makefile linux_umopenmosix/arch/um/drivers/Makefile --- linux-2.4.17/arch/um/drivers/Makefile Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/drivers/Makefile Sun Jun 23 12:40:10 2002 @@ -0,0 +1,48 @@ +# +# Copyright (C) 2000 Jeff Dike (jdike@karaya.com) +# Licensed under the GPL +# + +OBJ := um_drivers.o + +CHAN_OBJS = chan_kern.o chan_user.o line.o + +OBJS-y = +OBJS-$(CONFIG_SSL) += ssl.o +OBJS-$(CONFIG_UML_NET_SLIP) += slip_kern.o slip_user.o +OBJS-$(CONFIG_UML_NET_ETHERTAP) += ethertap_kern.o ethertap_user.o +OBJS-$(CONFIG_UML_NET_TUNTAP) += tuntap_kern.o tuntap_user.o +OBJS-$(CONFIG_UML_NET_DAEMON) += daemon_kern.o daemon_user.o +OBJS-$(CONFIG_UML_NET_MCAST) += mcast_user.o mcast_kern.o +OBJS-$(CONFIG_UML_NET) += net_kern.o net_user.o +OBJS-$(CONFIG_MCONSOLE) += mconsole_kern.o mconsole_user.o +OBJS-$(CONFIG_MMAPPER) += mmapper_kern.o +OBJS-$(CONFIG_BLK_DEV_UBD) += ubd.o ubd_user.o +OBJS-$(CONFIG_HOSTAUDIO) += hostaudio_kern.o hostaudio_user.o +OBJS-$(CONFIG_FD_CHAN) += fd.o +OBJS-$(CONFIG_PORT_CHAN) += port.o port_kern.o +OBJS-$(CONFIG_PTY_CHAN) += pty.o +OBJS-$(CONFIG_TTY_CHAN) += tty.o +OBJS-$(CONFIG_XTERM_CHAN) += xterm.o + +OBJS = stdio_console.o $(OBJS-y) $(CHAN_OBJS) + +USER_OBJS = $(filter %_user.o,$(OBJS)) fd.o pty.o socket.o tty.o xterm.o + +all : $(OBJ) + +$(USER_OBJS) : %.o: %.c + $(CC) $(CFLAGS_$@) $(USER_CFLAGS) -c -o $@ $< + +$(OBJ): $(OBJS) $(export-objs) + rm -f $@ + $(LD) $(LINKFLAGS) --start-group $^ --end-group -o $@ + +clean: + rm -f $(OBJS) $(export-objs) + +modules: + +fastdep: + +include $(TOPDIR)/Rules.make diff -urN linux-2.4.17/arch/um/drivers/chan_kern.c linux_umopenmosix/arch/um/drivers/chan_kern.c --- linux-2.4.17/arch/um/drivers/chan_kern.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/drivers/chan_kern.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,326 @@ +/* + * Copyright (C) 2000 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include +#include +#include +#include +#include +#include +#include +#include "chan_kern.h" +#include "user_util.h" +#include "kern.h" +#include "irq_user.h" + +static void tty_receive_char(struct tty_struct *tty, char ch) +{ + if(tty == NULL) return; + + if(I_IXON(tty) && !I_IXOFF(tty) && !tty->raw) { + if(ch == STOP_CHAR(tty)){ + stop_tty(tty); + return; + } + else if(ch == START_CHAR(tty)){ + start_tty(tty); + return; + } + } + + if((tty->flip.flag_buf_ptr == NULL) || + (tty->flip.char_buf_ptr == NULL)) + return; + tty_insert_flip_char(tty, ch, TTY_NORMAL); +} + +static int open_one_chan(struct chan *chan, int input, int output) +{ + int fd; + + if(chan->opened) return(0); + fd = (*chan->ops->open)(input, output, chan->data); + if(fd < 0) return(-fd); + chan->fd = fd; + + chan->opened = 1; + return(0); +} + +int open_chan(struct list_head *chans) +{ + struct list_head *ele; + struct chan *chan; + int ret, err = 0; + + list_for_each(ele, chans){ + chan = list_entry(ele, struct chan, list); + ret = open_one_chan(chan, chan->input, chan->output); + if(chan->primary) err = ret; + } + return(err); +} + +void enable_chan(struct list_head *chans, + int (*irq_setup)(int fd, int input, int output, void *data), + void *data) +{ + struct list_head *ele; + struct chan *chan; + + list_for_each(ele, chans){ + chan = list_entry(ele, struct chan, list); + if(!chan->opened) continue; + + (*irq_setup)(chan->fd, chan->input, chan->output, data); + } +} + +void disable_chan(struct list_head *chans) +{ + struct list_head *ele; + struct chan *chan; + + list_for_each(ele, chans){ + chan = list_entry(ele, struct chan, list); + if(!chan->opened) continue; + + free_irq_by_fd(chan->fd); + } +} + +void close_chan(struct list_head *chans) +{ + struct list_head *ele; + struct chan *chan; + + /* Close in reverse order as open in case more than one of them + * refers to the same device and they save and restore that device's + * state. Then, the first one opened will have the original state, + * so it must be the last closed. + */ + for(ele = chans->prev; ele != chans; ele = ele->prev){ + chan = list_entry(ele, struct chan, list); + if(chan->ops->close != NULL) + (*chan->ops->close)(chan->fd, chan->data); + free_irq_by_fd(chan->fd); + } +} + +int write_chan(struct list_head *chans, const char *buf, int len) +{ + struct list_head *ele; + struct chan *chan; + int n, ret = 0; + + list_for_each(ele, chans){ + chan = list_entry(ele, struct chan, list); + if(!chan->output) continue; + n = chan->ops->write(chan->fd, buf, len, chan->data); + if(chan->primary) ret = n; + } + return(ret); +} + +int console_write_chan(struct list_head *chans, const char *buf, int len) +{ + struct list_head *ele; + struct chan *chan; + int n, ret = 0; + + list_for_each(ele, chans){ + chan = list_entry(ele, struct chan, list); + if(!chan->output) continue; + n = chan->ops->console_write(chan->fd, buf, len, chan->data); + if(chan->primary) ret = n; + } + return(ret); +} + +int chan_window_size(struct list_head *chans, unsigned short *rows_out, + unsigned short *cols_out) +{ + struct list_head *ele; + struct chan *chan; + + list_for_each(ele, chans){ + chan = list_entry(ele, struct chan, list); + if(chan->primary) + return(chan->ops->window_size(chan->fd, chan->data, + rows_out, cols_out)); + } + return(0); +} + +void free_one_chan(struct chan *chan) +{ + list_del(&chan->list); + (*chan->ops->free)(chan->data); + free_irq_by_fd(chan->fd); + kfree(chan); +} + +void free_chan(struct list_head *chans) +{ + struct list_head *ele, *next; + struct chan *chan; + + list_for_each_safe(ele, next, chans){ + chan = list_entry(ele, struct chan, list); + free_one_chan(chan); + } +} + +struct chan_type { + char *key; + struct chan_ops *ops; +}; + +struct chan_type chan_table[] = { +#ifdef CONFIG_PTY_CHAN + { "pty", &pty_ops }, + { "pts", &pts_ops }, +#endif +#ifdef CONFIG_TTY_CHAN + { "tty", &tty_ops }, +#endif +#ifdef CONFIG_XTERM_CHAN + { "xterm", &xterm_ops }, +#endif +#ifdef CONFIG_FD_CHAN + { "fd", &fd_ops }, +#endif +#ifdef CONFIG_PORT_CHAN + { "port", &port_ops }, +#endif +}; + +static struct chan *parse_chan(char *str, int pri, int device, + struct chan_opts *opts) +{ + struct chan_type *entry; + struct chan_ops *ops; + struct chan *chan; + void *data; + int i; + + ops = NULL; + for(i = 0; i < sizeof(chan_table)/sizeof(chan_table[0]); i++){ + entry = &chan_table[i]; + if(!strncmp(str, entry->key, strlen(entry->key))){ + ops = entry->ops; + str += strlen(entry->key); + break; + } + } + if(ops == NULL){ + printk(KERN_ERR "parse_chan couldn't parse \"%s\"\n", str); + return(NULL); + } + + data = (*ops->init)(str, device, opts); + if(data == NULL) return(NULL); + chan = kmalloc(sizeof(*chan), GFP_KERNEL); + if(chan == NULL) return(NULL); + *chan = ((struct chan) { list : LIST_HEAD_INIT(chan->list), + primary : 1, + input : 0, + output : 0, + opened : 0, + fd : -1, + pri : pri, + ops : ops, + data : data }); + return(chan); +} + +int parse_chan_pair(char *str, struct list_head *chans, int pri, int device, + struct chan_opts *opts) +{ + struct chan *new, *chan; + char *in, *out; + + if(!list_empty(chans)){ + chan = list_entry(chans->next, struct chan, list); + if(chan->pri >= pri) return(0); + free_chan(chans); + INIT_LIST_HEAD(chans); + } + + if((out = strchr(str, ',')) != NULL){ + in = str; + *out = '\0'; + out++; + new = parse_chan(in, pri, device, opts); + if(new == NULL) return(-1); + new->input = 1; + list_add(&new->list, chans); + + new = parse_chan(out, pri, device, opts); + if(new == NULL) return(-1); + list_add(&new->list, chans); + new->output = 1; + } + else { + new = parse_chan(str, pri, device, opts); + if(new == NULL) return(-1); + list_add(&new->list, chans); + new->input = 1; + new->output = 1; + } + return(0); +} + +int chan_out_fd(struct list_head *chans) +{ + struct list_head *ele; + struct chan *chan; + + list_for_each(ele, chans){ + chan = list_entry(ele, struct chan, list); + if(chan->primary && chan->output) + return(chan->fd); + } + return(-1); +} + +void chan_interrupt(struct list_head *chans, struct tty_struct *tty) +{ + struct list_head *ele; + struct chan *chan; + char c; + + list_for_each(ele, chans){ + chan = list_entry(ele, struct chan, list); + if(!chan->input) continue; + do { + c = chan->ops->read(chan->fd, chan->data); + if(c > 0) tty_receive_char(tty, c); + } while(c > 0); + if(c == 0) reactivate_fd(chan->fd); + if(c == -EIO){ + chan->ops->close(chan->fd, chan->data); + chan->opened = 0; + if(chan->primary){ + if(tty != NULL) tty_hangup(tty); + free_chan(chans); + return; + } + else free_one_chan(chan); + } + } + if(tty) tty_flip_buffer_push(tty); +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/drivers/chan_user.c linux_umopenmosix/arch/um/drivers/chan_user.c --- linux-2.4.17/arch/um/drivers/chan_user.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/drivers/chan_user.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2000, 2001 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include +#include +#include +#include +#include +#include +#include +#include "user_util.h" +#include "user.h" + +void generic_close(int fd, void *unused) +{ + close(fd); +} + +int generic_read(int fd, void *unused) +{ + int n; + char c; + + n = read(fd, &c, sizeof(c)); + if(n < 0){ + if(errno == EAGAIN) return(0); + return(-errno); + } + else if(n == 0) return(-EIO); + return(c); +} + +int generic_write(int fd, const char *buf, int n, void *unused) +{ + return(write(fd, buf, n)); +} + +int generic_console_write(int fd, const char *buf, int n, void *state) +{ + struct termios save, *orig = state; + int err; + + if(isatty(fd)){ + tcgetattr(fd, &save); + tcsetattr(fd, TCSADRAIN, orig); + } + err = generic_write(fd, buf, n, NULL); + if(isatty(fd)) tcsetattr(fd, TCSADRAIN, &save); + return(err); +} + +int generic_window_size(int fd, void *unused, unsigned short *rows_out, + unsigned short *cols_out) +{ + struct winsize size; + int ret = 0; + + if(ioctl(fd, TIOCGWINSZ, &size) == 0){ + ret = ((*rows_out != size.ws_row) || + (*cols_out != size.ws_col)); + *rows_out = size.ws_row; + *cols_out = size.ws_col; + } + return(ret); +} + +void generic_free(void *data) +{ + kfree(data); +} + +int getmaster(char *line) +{ + struct stat stb; + char *pty, *bank, *cp; + int master; + + pty = &line[strlen("/dev/ptyp")]; + for (bank = "pqrs"; *bank; bank++) { + line[strlen("/dev/pty")] = *bank; + *pty = '0'; + if (stat(line, &stb) < 0) + break; + for (cp = "0123456789abcdef"; *cp; cp++) { + *pty = *cp; + master = open(line, O_RDWR); + if (master >= 0) { + char *tp = &line[strlen("/dev/")]; + int ok; + + /* verify slave side is usable */ + *tp = 't'; + ok = access(line, R_OK|W_OK) == 0; + *tp = 'p'; + if (ok) return(master); + (void) close(master); + } + } + } + return(-1); +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/drivers/daemon.h linux_umopenmosix/arch/um/drivers/daemon.h --- linux-2.4.17/arch/um/drivers/daemon.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/drivers/daemon.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2001 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include "net_user.h" + +struct daemon_data { + char *sock_type; + char *ctl_sock; + char *data_sock; + void *ctl_addr; + void *data_addr; + void *local_addr; + unsigned char hwaddr[ETH_ADDR_LEN]; + int hw_setup; + int control; + void *dev; +}; + +extern struct net_user_info daemon_user_info; + +extern int daemon_user_set_mac(struct daemon_data *pri, unsigned char *hwaddr, + int len); +extern int daemon_user_write(int fd, void *buf, int len, + struct daemon_data *pri); + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/drivers/daemon_kern.c linux_umopenmosix/arch/um/drivers/daemon_kern.c --- linux-2.4.17/arch/um/drivers/daemon_kern.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/drivers/daemon_kern.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,127 @@ +/* + * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and + * James Leu (jleu@mindspring.net). + * Copyright (C) 2001 by various other people who didn't put their name here. + * Licensed under the GPL. + */ + +#include "linux/init.h" +#include "linux/netdevice.h" +#include "linux/etherdevice.h" +#include "net_kern.h" +#include "net_user.h" +#include "daemon.h" +#include "daemon_kern.h" + +struct daemon_data daemon_priv[MAX_UML_NETDEV] = { + [ 0 ... MAX_UML_NETDEV - 1 ] = + { + sock_type: "unix", + ctl_sock: "/tmp/uml.ctl", + data_sock: "/tmp/uml.data", + hwaddr: { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }, + hw_setup: 0, + control: -1, + } +}; + +struct net_device *daemon_init(int private_size, int index) +{ + struct net_device *dev; + struct uml_net_private *pri; + struct daemon_data *dpri; + + dev = init_etherdev(NULL, private_size); + if(dev == NULL) return(NULL); + pri = dev->priv; + dpri = (struct daemon_data *) pri->user; + *dpri = daemon_priv[index]; + memcpy(dev->dev_addr, dpri->hwaddr, ETH_ALEN); + printk("daemon backend"); + if(dpri->hw_setup) + printk("- ethernet address = %x:%x:%x:%x:%x:%x\n", + dpri->hwaddr[0], dpri->hwaddr[1], dpri->hwaddr[2], + dpri->hwaddr[3], dpri->hwaddr[4], dpri->hwaddr[5]); + printk("\n"); + return(dev); +} + +static unsigned short daemon_protocol(struct sk_buff *skb) +{ + return(eth_type_trans(skb, skb->dev)); +} + +static int daemon_set_mac(struct sockaddr *addr, void *data) +{ + struct daemon_data *pri = data; + struct net_device *dev = pri->dev; + struct sockaddr *hwaddr = addr; + + memcpy(dev->dev_addr, hwaddr->sa_data, ETH_ALEN); + return(daemon_user_set_mac(pri, hwaddr->sa_data, ETH_ALEN)); +} + +static int daemon_read(int fd, struct sk_buff **skb, + struct uml_net_private *lp) +{ + *skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER); + if(*skb == NULL) return(-ENOMEM); + return(net_recvfrom(fd, (*skb)->mac.raw, + (*skb)->dev->mtu + ETH_HEADER_OTHER)); +} + +static int daemon_write(int fd, struct sk_buff **skb, + struct uml_net_private *lp) +{ + return(daemon_user_write(fd, (*skb)->data, (*skb)->len, + (struct daemon_data *) &lp->user)); +} + +static struct net_kern_info daemon_kern_info = { + init: daemon_init, + protocol: daemon_protocol, + set_mac: daemon_set_mac, + read: daemon_read, + write: daemon_write, +}; + +static int daemon_count = 0; + +void daemon_setup(char *str, struct uml_net *dev) +{ + int err, n = daemon_count; + + dev->user = &daemon_user_info; + dev->kern = &daemon_kern_info; + dev->private_size = sizeof(struct daemon_data); + dev->transport_index = daemon_count++; + if(*str != ',') return; + str++; + if(*str != ','){ + err = setup_etheraddr(str, daemon_priv[n].hwaddr); + if(!err) daemon_priv[n].hw_setup = 1; + } + str = strchr(str, ','); + if(str == NULL) return; + *str++ = '\0'; + if(*str != ',') daemon_priv[n].sock_type = str; + str = strchr(str, ','); + if(str == NULL) return; + *str++ = '\0'; + if(*str != ',') daemon_priv[n].ctl_sock = str; + str = strchr(str, ','); + if(str == NULL) return; + *str++ = '\0'; + if(*str != '\0') daemon_priv[n].data_sock = str; +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/drivers/daemon_kern.h linux_umopenmosix/arch/um/drivers/daemon_kern.h --- linux-2.4.17/arch/um/drivers/daemon_kern.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/drivers/daemon_kern.h Sun Jun 23 13:07:41 2002 @@ -0,0 +1,8 @@ +#ifndef __UM_DAEMON_KERN_H +#define __UM_DAEMON_KERN_H + +#include "net_kern.h" + +extern void daemon_setup(char *arg, struct uml_net *dev); + +#endif diff -urN linux-2.4.17/arch/um/drivers/daemon_user.c linux_umopenmosix/arch/um/drivers/daemon_user.c --- linux-2.4.17/arch/um/drivers/daemon_user.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/drivers/daemon_user.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,189 @@ +/* + * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and + * James Leu (jleu@mindspring.net). + * Copyright (C) 2001 by various other people who didn't put their name here. + * Licensed under the GPL. + */ + +#include +#include +#include +#include +#include +#include "net_user.h" +#include "daemon.h" +#include "kern_util.h" +#include "user_util.h" +#include "user.h" + +#define MAX_PACKET (ETH_MAX_PACKET + ETH_HEADER_OTHER) + +enum request_type { REQ_NEW_CONTROL }; + +struct request { + enum request_type type; + union { + struct { + unsigned char addr[ETH_ADDR_LEN]; + struct sockaddr_un name; + } new_control; + struct { + unsigned long cookie; + } new_data; + } u; +}; + +static struct sockaddr_un *new_addr(void *name, int len) +{ + struct sockaddr_un *sun; + + sun = um_kmalloc(sizeof(struct sockaddr_un)); + if(sun == NULL){ + printk("new_addr: allocation of sockaddr_un failed\n"); + return(NULL); + } + sun->sun_family = AF_UNIX; + memcpy(sun->sun_path, name, len); + return(sun); +} + +static void daemon_user_init(void *data, void *dev) +{ + struct daemon_data *pri = data; + struct timeval tv; + struct { + char zero; + int pid; + int usecs; + } name; + + if(!strcmp(pri->sock_type, "unix")){ + pri->ctl_addr = new_addr(pri->ctl_sock, + strlen(pri->ctl_sock) + 1); + pri->data_addr = new_addr(pri->data_sock, + strlen(pri->data_sock) + 1); + } + name.zero = 0; + name.pid = getpid(); + gettimeofday(&tv, NULL); + name.usecs = tv.tv_usec; + pri->local_addr = new_addr(&name, sizeof(name)); + pri->dev = dev; +} + +static int daemon_open(void *data) +{ + struct daemon_data *pri = data; + struct sockaddr_un *ctl_addr = pri->ctl_addr; + struct sockaddr_un *local_addr = pri->local_addr; + struct request req; + char addr[sizeof("255.255.255.255\0")]; + int fd, n, err; + + if(!pri->hw_setup){ + pri->hwaddr[0] = 0xfe; + pri->hwaddr[1] = 0xfd; + pri->hwaddr[2] = 0x0; + pri->hwaddr[3] = 0x0; + pri->hwaddr[4] = 0x0; + pri->hwaddr[5] = 0x0; + dev_ip_addr(pri->dev, addr, &pri->hwaddr[2]); + set_ether_mac(pri->dev, pri->hwaddr); + } + if((ctl_addr == NULL) || (pri->data_addr == NULL) || + (pri->local_addr == NULL)) + return(-EINVAL); + + if((pri->control = socket(AF_UNIX, SOCK_STREAM, 0)) < 0){ + printk("daemon_open : control socket failed, errno = %d\n", + errno); + return(-ENOMEM); + } + + if(connect(pri->control, (struct sockaddr *) ctl_addr, + sizeof(*ctl_addr)) < 0){ + printk("daemon_open : control connect failed, errno = %d\n", + errno); + err = -ENOTCONN; + goto out; + } + + req.type = REQ_NEW_CONTROL; + memcpy(req.u.new_control.addr, pri->hwaddr, + sizeof(req.u.new_control.addr)); + req.u.new_control.name = *local_addr; + n = write(pri->control, &req, sizeof(req)); + if(n != sizeof(req)){ + printk("daemon_open : control setup request returned %d, " + "errno = %d\n", n, errno); + err = -ENOTCONN; + goto out; + } + + if((fd = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0){ + printk("daemon_open : data socket failed, errno = %d\n", + errno); + err = -ENOMEM; + goto out; + } + if(bind(fd, (struct sockaddr *) local_addr, sizeof(*local_addr)) < 0){ + printk("daemon_open : data bind failed, errno = %d\n", + errno); + close(fd); + err = -EINVAL; + goto out; + } + + return(fd); + out: + close(pri->control); + return(err); +} + +static void daemon_close(int fd, void *data) +{ + struct daemon_data *pri = data; + + close(fd); + close(pri->control); +} + +int daemon_user_write(int fd, void *buf, int len, struct daemon_data *pri) +{ + struct sockaddr_un *data_addr = pri->data_addr; + + return(net_sendto(fd, buf, len, data_addr, sizeof(*data_addr))); +} + +static int daemon_set_mtu(int mtu, void *data) +{ + return(mtu); +} + +int daemon_user_set_mac(struct daemon_data *pri, unsigned char *hwaddr, + int len) +{ + memcpy(pri->hwaddr, hwaddr, len); + return(0); +} + +struct net_user_info daemon_user_info = { + init: daemon_user_init, + open: daemon_open, + close: daemon_close, + set_mtu: daemon_set_mtu, + add_address: NULL, + delete_address: NULL, + max_packet: MAX_PACKET - ETH_HEADER_OTHER +}; + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/drivers/etap.h linux_umopenmosix/arch/um/drivers/etap.h --- linux-2.4.17/arch/um/drivers/etap.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/drivers/etap.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2001 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include "net_user.h" + +struct ethertap_data { + char *dev_name; + char *gate_addr; + int data_fd; + int control_fd; + void *dev; + unsigned char hw_addr[ETH_ADDR_LEN]; + int hw_setup; +}; + +extern struct net_user_info ethertap_user_info; + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/drivers/etap_kern.h linux_umopenmosix/arch/um/drivers/etap_kern.h --- linux-2.4.17/arch/um/drivers/etap_kern.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/drivers/etap_kern.h Sun Jun 23 13:07:37 2002 @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2001 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#ifndef __UM_ETHERTAP_KERN_H +#define __UM_ETHERTAP_KERN_H + +#include "net_kern.h" + +extern void ethertap_setup(char *arg, struct uml_net *dev); + +#endif + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/drivers/ethertap_kern.c linux_umopenmosix/arch/um/drivers/ethertap_kern.c --- linux-2.4.17/arch/um/drivers/ethertap_kern.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/drivers/ethertap_kern.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,137 @@ +/* + * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and + * James Leu (jleu@mindspring.net). + * Copyright (C) 2001 by various other people who didn't put their name here. + * Licensed under the GPL. + */ + +#include "linux/init.h" +#include "linux/netdevice.h" +#include "linux/etherdevice.h" +#include "net_kern.h" +#include "net_user.h" +#include "etap.h" +#include "etap_kern.h" + +struct ethertap_setup { + char *dev_name; + unsigned char hw_addr[ETH_ALEN]; + int hw_setup; + char *gate_addr; +}; + +struct ethertap_setup ethertap_priv[MAX_UML_NETDEV] = { + [ 0 ... MAX_UML_NETDEV - 1 ] = + { + dev_name: NULL, + hw_addr: { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }, + hw_setup: 0, + gate_addr: NULL, + } +}; + +struct net_device *etap_init(int private_size, int index) +{ + struct net_device *dev; + struct uml_net_private *pri; + struct ethertap_data *epri; + + dev = init_etherdev(NULL, private_size); + if(dev == NULL) return(NULL); + pri = dev->priv; + epri = (struct ethertap_data *) pri->user; + epri->dev_name = ethertap_priv[index].dev_name; + epri->gate_addr = ethertap_priv[index].gate_addr; + memcpy(dev->dev_addr, ethertap_priv[index].hw_addr, ETH_ALEN); + memcpy(epri->hw_addr, ethertap_priv[index].hw_addr, + sizeof(epri->hw_addr)); + printk("ethertap backend - %s", epri->dev_name); + if(epri->gate_addr != NULL) + printk(", IP = %s", epri->gate_addr); + epri->hw_setup = ethertap_priv[index].hw_setup; + if(epri->hw_setup) + printk(", ether = %x:%x:%x:%x:%x:%x", + epri->hw_addr[0], epri->hw_addr[1], epri->hw_addr[2], + epri->hw_addr[3], epri->hw_addr[4], epri->hw_addr[5]); + printk("\n"); + epri->data_fd = -1; + epri->control_fd = -1; + return(dev); +} + +static unsigned short etap_protocol(struct sk_buff *skb) +{ + return(eth_type_trans(skb, skb->dev)); +} + +static int etap_set_mac(struct sockaddr *addr, void *data) +{ + struct ethertap_data *pri = data; + struct sockaddr *hwaddr = addr; + + memcpy(pri->hw_addr, hwaddr->sa_data, ETH_ALEN); + + return 0; +} + +static int etap_read(int fd, struct sk_buff **skb, struct uml_net_private *lp) +{ + int len; + + *skb = ether_adjust_skb(*skb, ETH_HEADER_ETHERTAP); + if(*skb == NULL) return(-ENOMEM); + len = net_recvfrom(fd, (*skb)->mac.raw, + (*skb)->dev->mtu + 2 * ETH_HEADER_ETHERTAP); + if(len <= 0) return(len); + skb_pull(*skb, 2); + len -= 2; + return(len); +} + +static int etap_write(int fd, struct sk_buff **skb, struct uml_net_private *lp) +{ + if(skb_headroom(*skb) < 2){ + struct sk_buff *skb2; + + skb2 = skb_realloc_headroom(*skb, 2); + dev_kfree_skb(*skb); + if (skb2 == NULL) return(-ENOMEM); + *skb = skb2; + } + skb_push(*skb, 2); + return(net_send(fd, (*skb)->data, (*skb)->len)); +} + +struct net_kern_info ethertap_kern_info = { + init: etap_init, + protocol: etap_protocol, + set_mac: etap_set_mac, + read: etap_read, + write: etap_write, +}; + +static int ethertap_count = 0; + +void ethertap_setup(char *str, struct uml_net *dev) +{ + struct ethertap_setup *pri; + + dev->user = ðertap_user_info; + dev->kern = ðertap_kern_info; + dev->private_size = sizeof(struct ethertap_data); + pri = ðertap_priv[ethertap_count]; + dev->transport_index = ethertap_count++; + tap_setup_common(str, "ethertap", &pri->dev_name, pri->hw_addr, + &pri->hw_setup, &pri->gate_addr); +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/drivers/ethertap_user.c linux_umopenmosix/arch/um/drivers/ethertap_user.c --- linux-2.4.17/arch/um/drivers/ethertap_user.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/drivers/ethertap_user.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,224 @@ +/* + * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and + * James Leu (jleu@mindspring.net). + * Copyright (C) 2001 by various other people who didn't put their name here. + * Licensed under the GPL. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "user.h" +#include "kern_util.h" +#include "net_user.h" +#include "etap.h" + +#define MAX_PACKET ETH_MAX_PACKET + +void etap_user_init(void *data, void *dev) +{ + struct ethertap_data *pri = data; + + pri->dev = dev; +} + +struct etap_open_data { + char *name; + char *gate; + int data_remote; + int data_me; + int control_remote; + int control_me; + int err; + char *output; +}; + +struct addr_change { + enum { ADD_ADDR, DEL_ADDR } what; + unsigned char addr[4]; + unsigned char netmask[4]; +}; + +static void etap_change(int op, unsigned char *addr, unsigned char *netmask, + int fd) +{ + struct addr_change change; + char *output; + + change.what = op; + memcpy(change.addr, addr, sizeof(change.addr)); + memcpy(change.netmask, netmask, sizeof(change.netmask)); + if(write(fd, &change, sizeof(change)) != sizeof(change)) + printk("etap_change - request failed, errno = %d\n", + errno); + if(!read_output(fd, &output)) printk("%s", output); +} + +static void etap_open_addr(unsigned char *addr, unsigned char *netmask, + void *arg) +{ + etap_change(ADD_ADDR, addr, netmask, *((int *) arg)); +} + +static void etap_close_addr(unsigned char *addr, unsigned char *netmask, + void *arg) +{ + etap_change(DEL_ADDR, addr, netmask, *((int *) arg)); +} + +static void etap_tramp(void *arg) +{ + struct etap_open_data *data = arg; + int pid, status; + char version_buf[sizeof("nnnnn\0")]; + char data_fd_buf[sizeof("nnnnnn\0")]; + char gate_buf[sizeof("nnn.nnn.nnn.nnn\0")]; + char *setup_args[] = { "uml_net", version_buf, "ethertap", data->name, + data_fd_buf, gate_buf, NULL }; + char *nosetup_args[] = { "uml_net", version_buf, "ethertap", + data->name, data_fd_buf, NULL }; + char **args, c; + + sprintf(data_fd_buf, "%d", data->data_remote); + sprintf(version_buf, "%d", UML_NET_VERSION); + if(data->gate != NULL){ + strcpy(gate_buf, data->gate); + args = setup_args; + } + else args = nosetup_args; + data->err = 0; + if((pid = fork()) == 0){ + dup2(data->control_remote, 1); + close(data->data_me); + close(data->control_me); + execvp(args[0], args); + printk("Exec of '%s' failed - errno = %d\n", args[0], errno); + exit(1); + } + else if(pid < 0) data->err = errno; + close(data->data_remote); + close(data->control_remote); + data->output = NULL; + if(read(data->control_me, &c, sizeof(c)) != sizeof(c)){ + printk("etap_tramp : read of status failed, errno = %d\n", + errno); + data->err = EINVAL; + return; + } + if(c != 1){ + printk("etap_tramp : uml_net failed\n"); + data->err = EINVAL; + if(waitpid(pid, &status, 0) < 0) data->err = errno; + else if(!WIFEXITED(status) || (WEXITSTATUS(status) != 1)){ + printk("uml_net didn't exit with status 1\n"); + } + return; + } + if(read_output(data->control_me, &data->output)) + data->err = EINVAL; +} + +static int etap_open(void *data) +{ + struct ethertap_data *pri = data; + struct etap_open_data tap_data; + int data_fds[2], control_fds[2], err; + + err = tap_open_common(pri->dev, pri->hw_setup, pri->gate_addr); + if(err) return(err); + + tap_data.name = pri->dev_name; + + if(socketpair(PF_UNIX, SOCK_DGRAM, 0, data_fds) < 0){ + printk("data socketpair failed - errno = %d\n", errno); + return(-errno); + } + tap_data.data_remote = data_fds[1]; + tap_data.data_me = data_fds[0]; + + if(socketpair(PF_UNIX, SOCK_STREAM, 0, control_fds) < 0){ + printk("data socketpair failed - errno = %d\n", errno); + return(-errno); + } + tap_data.control_remote = control_fds[1]; + tap_data.control_me = control_fds[0]; + + tap_data.gate = pri->gate_addr; + tracing_cb(etap_tramp, &tap_data); + if(tap_data.output){ + printk("%s", tap_data.output); + kfree(tap_data.output); + } + if(tap_data.err != 0){ + printk("etap_tramp failed - errno = %d\n", tap_data.err); + return(-tap_data.err); + } + pri->data_fd = data_fds[0]; + pri->control_fd = control_fds[0]; + iter_addresses(pri->dev, etap_open_addr, &pri->control_fd); + return(data_fds[0]); +} + +static void etap_close(int fd, void *data) +{ + struct ethertap_data *pri = data; + + iter_addresses(pri->dev, etap_close_addr, &pri->control_fd); + close(fd); + shutdown(pri->data_fd, SHUT_RDWR); + close(pri->data_fd); + pri->data_fd = -1; + close(pri->control_fd); + pri->control_fd = -1; +} + +static int etap_set_mtu(int mtu, void *data) +{ + return(mtu); +} + +static void etap_add_addr(unsigned char *addr, unsigned char *netmask, + void *data) +{ + struct ethertap_data *pri = data; + + if(pri->control_fd == -1) return; + etap_open_addr(addr, netmask, &pri->control_fd); +} + +static void etap_del_addr(unsigned char *addr, unsigned char *netmask, + void *data) +{ + struct ethertap_data *pri = data; + + if(pri->control_fd == -1) return; + etap_close_addr(addr, netmask, &pri->control_fd); +} + +struct net_user_info ethertap_user_info = { + init: etap_user_init, + open: etap_open, + close: etap_close, + set_mtu: etap_set_mtu, + add_address: etap_add_addr, + delete_address: etap_del_addr, + max_packet: MAX_PACKET - ETH_HEADER_ETHERTAP +}; + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/drivers/fd.c linux_umopenmosix/arch/um/drivers/fd.c --- linux-2.4.17/arch/um/drivers/fd.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/drivers/fd.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2001 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include +#include +#include +#include +#include "user.h" +#include "user_util.h" +#include "chan_user.h" + +struct fd_chan { + int fd; + int raw; + struct termios tt; +}; + +void *fd_init(char *str, int device, struct chan_opts *opts) +{ + struct fd_chan *data; + char *end; + int n; + + if(*str != ':'){ + printk("fd_init : channel type 'fd' must specify a file " + "descriptor\n"); + return(NULL); + } + str++; + n = strtoul(str, &end, 0); + if(*end != '\0'){ + printk("fd_init : couldn't parse file descriptor '%s'\n", str); + return(NULL); + } + if((data = um_kmalloc(sizeof(*data))) == NULL) return(NULL); + *data = ((struct fd_chan) { fd : n, + raw : opts->raw }); + return(data); +} + +int fd_open(int input, int output, void *d) +{ + struct fd_chan *data = d; + + if(data->raw && isatty(data->fd)){ + tcgetattr(data->fd, &data->tt); + raw(data->fd, 0); + } + return(data->fd); +} + +void fd_close(int fd, void *d) +{ + struct fd_chan *data = d; + + if(data->raw && isatty(fd)){ + tcsetattr(fd, TCSADRAIN, &data->tt); + data->raw = 0; + } +} + +int fd_console_write(int fd, const char *buf, int n, void *d) +{ + struct fd_chan *data = d; + + return(generic_console_write(fd, buf, n, &data->tt)); +} + +struct chan_ops fd_ops = { + init: fd_init, + open: fd_open, + close: fd_close, + read: generic_read, + write: generic_write, + console_write: fd_console_write, + window_size: generic_window_size, + free: generic_free, +}; + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/drivers/hostaudio_kern.c linux_umopenmosix/arch/um/drivers/hostaudio_kern.c --- linux-2.4.17/arch/um/drivers/hostaudio_kern.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/drivers/hostaudio_kern.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,262 @@ +/* + * Copyright (C) 2002 Steve Schmidtke + * Licensed under the GPL + */ + +#include "linux/config.h" +#include "linux/module.h" +#include "linux/version.h" +#include "linux/init.h" +#include "linux/slab.h" +#include "linux/fs.h" +#include "linux/sound.h" +#include "linux/soundcard.h" +#include "kern_util.h" +#include "init.h" +#include "hostaudio.h" + +char *dsp = HOSTAUDIO_DEV_DSP; +char *mixer = HOSTAUDIO_DEV_MIXER; + +static int set_dsp(char *name, int *add) +{ + dsp = uml_strdup(name); + return(0); +} + +__uml_setup("dsp=", set_dsp, +"dsp=\n" +" This is used to specify the host dsp device to the hostaudio driver.\n" +" The default is \"" HOSTAUDIO_DEV_DSP "\".\n\n" +); + +static int set_mixer(char *name, int *add) +{ + mixer = uml_strdup(name); + return(0); +} + +__uml_setup("mixer=", set_mixer, +"mixer=\n" +" This is used to specify the host mixer device to the hostaudio driver.\n" +" The default is \"" HOSTAUDIO_DEV_MIXER "\".\n\n" +); + +/* /dev/dsp file operations */ + +static ssize_t hostaudio_read(struct file *file, char *buffer, size_t count, + loff_t *ppos) +{ + struct hostaudio_state *state = file->private_data; + +#ifdef DEBUG + printk("hostaudio: read called, count = %d\n", count); +#endif + + return(hostaudio_read_user(state, buffer, count, ppos)); +} + +static ssize_t hostaudio_write(struct file *file, const char *buffer, + size_t count, loff_t *ppos) +{ + struct hostaudio_state *state = file->private_data; + +#ifdef DEBUG + printk("hostaudio: write called, count = %d\n", count); +#endif + return(hostaudio_write_user(state, buffer, count, ppos)); +} + +static unsigned int hostaudio_poll(struct file *file, + struct poll_table_struct *wait) +{ + unsigned int mask = 0; + +#ifdef DEBUG + printk("hostaudio: poll called (unimplemented)\n"); +#endif + + return(mask); +} + +static int hostaudio_ioctl(struct inode *inode, struct file *file, + unsigned int cmd, unsigned long arg) +{ + struct hostaudio_state *state = file->private_data; + +#ifdef DEBUG + printk("hostaudio: ioctl called, cmd = %u\n", cmd); +#endif + + return(hostaudio_ioctl_user(state, cmd, arg)); +} + +static int hostaudio_open(struct inode *inode, struct file *file) +{ + struct hostaudio_state *state; + int r = 0, w = 0; + int ret; + +#ifdef DEBUG + printk("hostaudio: open called (host: %s)\n", dsp); +#endif + + state = kmalloc(sizeof(struct hostaudio_state), GFP_KERNEL); + if(state == NULL) return(-ENOMEM); + + if(file->f_mode & FMODE_READ) r = 1; + if(file->f_mode & FMODE_WRITE) w = 1; + + ret = hostaudio_open_user(state, r, w, dsp); + if(ret < 0){ + kfree(state); + return(ret); + } + + file->private_data = state; + return(0); +} + +static int hostaudio_release(struct inode *inode, struct file *file) +{ + struct hostaudio_state *state = file->private_data; + int ret; + +#ifdef DEBUG + printk("hostaudio: release called\n"); +#endif + + ret = hostaudio_release_user(state); + kfree(state); + + return(ret); +} + +/* /dev/mixer file operations */ + +static int hostmixer_ioctl_mixdev(struct inode *inode, struct file *file, + unsigned int cmd, unsigned long arg) +{ + struct hostmixer_state *state = file->private_data; + +#ifdef DEBUG + printk("hostmixer: ioctl called\n"); +#endif + + return(hostmixer_ioctl_mixdev_user(state, cmd, arg)); +} + +static int hostmixer_open_mixdev(struct inode *inode, struct file *file) +{ + struct hostmixer_state *state; + int r = 0, w = 0; + int ret; + +#ifdef DEBUG + printk("hostmixer: open called (host: %s)\n", mixer); +#endif + + state = kmalloc(sizeof(struct hostmixer_state), GFP_KERNEL); + if(state == NULL) return(-ENOMEM); + + if(file->f_mode & FMODE_READ) r = 1; + if(file->f_mode & FMODE_WRITE) w = 1; + + ret = hostmixer_open_mixdev_user(state, r, w, mixer); + + if(ret < 0){ + kfree(state); + return(ret); + } + + file->private_data = state; + return(0); +} + +static int hostmixer_release(struct inode *inode, struct file *file) +{ + struct hostmixer_state *state = file->private_data; + int ret; + +#ifdef DEBUG + printk("hostmixer: release called\n"); +#endif + + ret = hostmixer_release_mixdev_user(state); + kfree(state); + + return(ret); +} + + +/* kernel module operations */ + +static struct file_operations hostaudio_fops = { + owner: THIS_MODULE, + llseek: no_llseek, + read: hostaudio_read, + write: hostaudio_write, + poll: hostaudio_poll, + ioctl: hostaudio_ioctl, + mmap: NULL, + open: hostaudio_open, + release: hostaudio_release, +}; + +static struct file_operations hostmixer_fops = { + owner: THIS_MODULE, + llseek: no_llseek, + ioctl: hostmixer_ioctl_mixdev, + open: hostmixer_open_mixdev, + release: hostmixer_release, +}; + +struct { + int dev_audio; + int dev_mixer; +} module_data; + +MODULE_AUTHOR("Steve Schmidtke"); +MODULE_DESCRIPTION("UML Audio Relay"); +MODULE_LICENSE("GPL"); + +static int __init hostaudio_init_module(void) +{ + printk(KERN_INFO "UML Audio Relay: " __DATE__ " " __TIME__ "\n"); + + module_data.dev_audio = register_sound_dsp(&hostaudio_fops, -1); + if(module_data.dev_audio < 0){ + printk(KERN_ERR "hostaudio: couldn't register DSP device!\n"); + return -ENODEV; + } + + module_data.dev_mixer = register_sound_mixer(&hostmixer_fops, -1); + if(module_data.dev_mixer < 0){ + printk(KERN_ERR "hostmixer: couldn't register mixer " + "device!\n"); + unregister_sound_dsp(module_data.dev_audio); + return -ENODEV; + } + + return 0; +} + +static void __exit hostaudio_cleanup_module (void) +{ + unregister_sound_mixer(module_data.dev_mixer); + unregister_sound_dsp(module_data.dev_audio); +} + +module_init(hostaudio_init_module); +module_exit(hostaudio_cleanup_module); + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/drivers/hostaudio_user.c linux_umopenmosix/arch/um/drivers/hostaudio_user.c --- linux-2.4.17/arch/um/drivers/hostaudio_user.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/drivers/hostaudio_user.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,160 @@ +/* + * Copyright (C) 2002 Steve Schmidtke + * Licensed under the GPL + */ + +#include +#include +#include +#include +#include +#include +#include "hostaudio.h" +#include "user_util.h" +#include "kern_util.h" +#include "user.h" + +/* /dev/dsp file operations */ + +ssize_t hostaudio_read_user(struct hostaudio_state *state, char *buffer, + size_t count, loff_t *ppos) +{ + ssize_t ret; + +#ifdef DEBUG + printk("hostaudio: read_user called, count = %d\n", count); +#endif + + ret = read(state->fd, buffer, count); + + if(ret < 0) return(-errno); + return(ret); +} + +ssize_t hostaudio_write_user(struct hostaudio_state *state, const char *buffer, + size_t count, loff_t *ppos) +{ + ssize_t ret; + +#ifdef DEBUG + printk("hostaudio: write_user called, count = %d\n", count); +#endif + + ret = write(state->fd, buffer, count); + + if(ret < 0) return(-errno); + return(ret); +} + +int hostaudio_ioctl_user(struct hostaudio_state *state, unsigned int cmd, + unsigned long arg) +{ + int ret; +#ifdef DEBUG + printk("hostaudio: ioctl_user called, cmd = %u\n", cmd); +#endif + + ret = ioctl(state->fd, cmd, arg); + + if(ret < 0) return(-errno); + return(ret); +} + +int hostaudio_open_user(struct hostaudio_state *state, int r, int w, char *dsp) +{ + int flags = 0; + +#ifdef DEBUG + printk("hostaudio: open_user called\n"); +#endif + + if(r && !w) flags = O_RDONLY; + else if(!r && w) flags = O_WRONLY; + else if(r && w) flags = O_RDWR; + + state->fd = open(dsp, flags); + + if(state->fd >= 0) return(0); + + printk("hostaudio_open_user failed to open '%s', errno = %d\n", + dsp, errno); + + return(-errno); +} + +int hostaudio_release_user(struct hostaudio_state *state) +{ +#ifdef DEBUG + printk("hostaudio: release called\n"); +#endif + if(state->fd >= 0){ + close(state->fd); + state->fd=-1; + } + + return(0); +} + +/* /dev/mixer file operations */ + +int hostmixer_ioctl_mixdev_user(struct hostmixer_state *state, + unsigned int cmd, unsigned long arg) +{ + int ret; +#ifdef DEBUG + printk("hostmixer: ioctl_user called cmd = %u\n",cmd); +#endif + + ret = ioctl(state->fd, cmd, arg); + if(ret < 0) + return(-errno); + return(ret); +} + +int hostmixer_open_mixdev_user(struct hostmixer_state *state, int r, int w, + char *mixer) +{ + int flags = 0; + +#ifdef DEBUG + printk("hostmixer: open_user called\n"); +#endif + + if(r && !w) flags = O_RDONLY; + else if(!r && w) flags = O_WRONLY; + else if(r && w) flags = O_RDWR; + + state->fd = open(mixer, flags); + + if(state->fd >= 0) return(0); + + printk("hostaudio_open_mixdev_user failed to open '%s', errno = %d\n", + mixer, errno); + + return(-errno); +} + +int hostmixer_release_mixdev_user(struct hostmixer_state *state) +{ +#ifdef DEBUG + printk("hostmixer: release_user called\n"); +#endif + + if(state->fd >= 0){ + close(state->fd); + state->fd = -1; + } + + return 0; +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/drivers/line.c linux_umopenmosix/arch/um/drivers/line.c --- linux-2.4.17/arch/um/drivers/line.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/drivers/line.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,124 @@ +/* + * Copyright (C) 2001 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include "linux/sched.h" +#include "chan_kern.h" +#include "line.h" + +void line_interrupt(int irq, void *data, struct pt_regs *unused) +{ + struct line *dev = data; + + if(dev->count > 0) chan_interrupt(&dev->chan_list, dev->tty); +} + +int line_open(struct line *lines, int n, struct tty_struct *tty, + int (*setup_irq)(int fd, int input, int output, void *data), + struct chan_opts *opts) +{ + struct line *line = &lines[n]; + int err = 0; + + down(&line->sem); + if(line->count == 0){ + if(list_empty(&line->chan_list)){ + err = parse_chan_pair(line->init_str, &line->chan_list, + line->init_pri, n, opts); + if(err) goto out; + err = open_chan(&line->chan_list); + if(err) goto out; + } + enable_chan(&line->chan_list, setup_irq, line); + } + /* This is outside the if because the initial console is opened + * with tty == NULL + */ + line->tty = tty; + if(tty != NULL) tty->driver_data = line; + + line->count++; + out: + up(&line->sem); + return(err); +} + +void line_close(struct line *lines, int n) +{ + struct line *line = &lines[n]; + + line->count--; + if(line->count == 0){ + disable_chan(&line->chan_list); + line->tty = NULL; + } +} + +void line_setup(struct line *lines, int num, char *init) +{ + int i, n; + char *end; + + if(*init == '=') n = -1; + else { + n = simple_strtoul(init, &end, 0); + if(*end != '='){ + printk(KERN_ERR "line_setup failed to parse \"%s\"\n", + init); + return; + } + init = end; + } + init++; + if(n == -1){ + for(i = 0; i < num; i++){ + if(lines[i].init_pri <= INIT_ALL){ + lines[i].init_str = init; + lines[i].init_pri = INIT_ALL; + } + } + } + else if(lines[n].init_pri <= INIT_ONE){ + lines[n].init_str = init; + lines[n].init_pri = INIT_ONE; + } +} + +struct list_head winch_regs = LIST_HEAD_INIT(winch_regs); + +void register_winch(struct winch_lines *lines) +{ + list_add(&lines->list, &winch_regs); +} + +void run_winch_handlers(void) +{ + struct list_head *ele; + struct winch_lines *lines; + struct line *line; + int i; + + list_for_each(ele, &winch_regs){ + lines = list_entry(ele, struct winch_lines, list); + for(i = 0; i < lines->nlines; i++){ + line = &lines->lines[i]; + if((line->count > 0) && (line->tty != NULL) && + chan_window_size(&line->chan_list, + &line->tty->winsize.ws_row, + &line->tty->winsize.ws_col)) + kill_pg(line->tty->pgrp, SIGWINCH, 1); + } + } +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/drivers/mcast.h linux_umopenmosix/arch/um/drivers/mcast.h --- linux-2.4.17/arch/um/drivers/mcast.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/drivers/mcast.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2001 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include "net_user.h" + +struct mcast_data { + char *addr; + unsigned short port; + void *mcast_addr; + int ttl; + unsigned char hwaddr[ETH_ADDR_LEN]; + int hw_setup; + void *dev; +}; + +extern struct net_user_info mcast_user_info; + +extern int mcast_user_set_mac(struct mcast_data *pri, unsigned char *hwaddr, + int len); +extern int mcast_user_write(int fd, void *buf, int len, + struct mcast_data *pri); + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/drivers/mcast_kern.c linux_umopenmosix/arch/um/drivers/mcast_kern.c --- linux-2.4.17/arch/um/drivers/mcast_kern.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/drivers/mcast_kern.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,167 @@ +/* + * user-mode-linux networking multicast transport + * Copyright (C) 2001 by Harald Welte + * + * based on the existing uml-networking code, which is + * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and + * James Leu (jleu@mindspring.net). + * Copyright (C) 2001 by various other people who didn't put their name here. + * + * Licensed under the GPL. + */ + +#include "linux/kernel.h" +#include "linux/init.h" +#include "linux/netdevice.h" +#include "linux/etherdevice.h" +#include "linux/in.h" +#include "linux/inet.h" +#include "net_kern.h" +#include "net_user.h" +#include "mcast.h" +#include "mcast_kern.h" + +struct mcast_data mcast_priv[MAX_UML_NETDEV] = { + [ 0 ... MAX_UML_NETDEV - 1 ] = + { + addr: "239.192.168.1", + port: 1102, + ttl: 1, + hwaddr: { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }, + hw_setup: 0, + } +}; + +struct net_device *mcast_init(int private_size, int index) +{ + struct net_device *dev; + struct uml_net_private *pri; + struct mcast_data *dpri; + + dev = init_etherdev(NULL, private_size); + if (!dev) + return NULL; + + pri = dev->priv; + dpri = (struct mcast_data *) pri->user; + *dpri = mcast_priv[index]; + memcpy(dev->dev_addr, dpri->hwaddr, ETH_ALEN); + printk("mcast backend "); + if(dpri->hw_setup) + printk("ethernet address=%x:%x:%x:%x:%x:%x ", + dpri->hwaddr[0], dpri->hwaddr[1], dpri->hwaddr[2], + dpri->hwaddr[3], dpri->hwaddr[4], dpri->hwaddr[5]); + + printk("multicast adddress: %s:%u, TTL:%u ", + dpri->addr, dpri->port, dpri->ttl); + + printk("\n"); + return(dev); +} + +static unsigned short mcast_protocol(struct sk_buff *skb) +{ + return eth_type_trans(skb, skb->dev); +} + +static int mcast_set_mac(struct sockaddr *addr, void *data) +{ + struct mcast_data *pri = data; + struct net_device *dev = pri->dev; + struct sockaddr *hwaddr = addr; + + memcpy(dev->dev_addr, hwaddr->sa_data, ETH_ALEN); + return mcast_user_set_mac(pri, hwaddr->sa_data, ETH_ALEN); +} + +static int mcast_read(int fd, struct sk_buff **skb, struct uml_net_private *lp) +{ + *skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER); + if(*skb == NULL) return(-ENOMEM); + return(net_recvfrom(fd, (*skb)->mac.raw, + (*skb)->dev->mtu + ETH_HEADER_OTHER)); +} + +static int mcast_write(int fd, struct sk_buff **skb, + struct uml_net_private *lp) +{ + return mcast_user_write(fd, (*skb)->data, (*skb)->len, + (struct mcast_data *) &lp->user); +} + +static struct net_kern_info mcast_kern_info = { + init: mcast_init, + protocol: mcast_protocol, + set_mac: mcast_set_mac, + read: mcast_read, + write: mcast_write, +}; + +static int mcast_count = 0; + +void mcast_setup(char *str, struct uml_net *dev) +{ + int err, n = mcast_count; + int num = 0; + char *p1, *p2; + + dev->user = &mcast_user_info; + dev->kern = &mcast_kern_info; + dev->private_size = sizeof(struct mcast_data); + dev->transport_index = mcast_count++; + + + /* somewhat more sophisticated parser, needed for in_aton */ + + p1 = str; + if (*str == ',') + p1++; + while (p1 && *p1) { + if ((p2 = strchr(p1, ','))) + *p2++ = '\0'; + if (strlen(p1) > 0) { + switch (num) { + case 0: + /* First argument: Ethernet address */ + err = setup_etheraddr(p1, + mcast_priv[n].hwaddr); + if (!err) + mcast_priv[n].hw_setup = 1; + break; + case 1: + /* Second argument: Multicast group */ + mcast_priv[n].addr = p1; + break; + case 2: + /* Third argument: Port number */ + mcast_priv[n].port = + htons(simple_strtoul(p1, NULL, 10)); + break; + case 3: + /* Fourth argument: TTL */ + mcast_priv[n].ttl = + simple_strtoul(p1, NULL, 10); + break; + } + } + p1 = p2; + num++; + } + + printk(KERN_INFO "Configured mcast device: %s:%u-%u\n", + mcast_priv[n].addr, mcast_priv[n].port, + mcast_priv[n].ttl); + + return; +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/drivers/mcast_kern.h linux_umopenmosix/arch/um/drivers/mcast_kern.h --- linux-2.4.17/arch/um/drivers/mcast_kern.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/drivers/mcast_kern.h Sun Jun 23 13:07:43 2002 @@ -0,0 +1,8 @@ +#ifndef __UM_MCAST_KERN_H +#define __UM_MCAST_KERN_H + +#include "net_kern.h" + +extern void mcast_setup(char *arg, struct uml_net *dev); + +#endif diff -urN linux-2.4.17/arch/um/drivers/mcast_user.c linux_umopenmosix/arch/um/drivers/mcast_user.c --- linux-2.4.17/arch/um/drivers/mcast_user.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/drivers/mcast_user.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,194 @@ +/* + * user-mode-linux networking multicast transport + * Copyright (C) 2001 by Harald Welte + * + * based on the existing uml-networking code, which is + * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and + * James Leu (jleu@mindspring.net). + * Copyright (C) 2001 by various other people who didn't put their name here. + * + * Licensed under the GPL. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include "net_user.h" +#include "mcast.h" +#include "kern_util.h" +#include "user_util.h" +#include "user.h" + +#define MAX_PACKET (ETH_MAX_PACKET + ETH_HEADER_OTHER) + +static struct sockaddr_in *new_addr(char *addr, unsigned short port) +{ + struct sockaddr_in *sin; + + sin = um_kmalloc(sizeof(struct sockaddr_in)); + if(sin == NULL){ + printk("new_addr: allocation of sockaddr_in failed\n"); + return(NULL); + } + sin->sin_addr.s_addr = in_aton(addr); + sin->sin_port = port; + return(sin); +} + +static void mcast_user_init(void *data, void *dev) +{ + struct mcast_data *pri = data; + + pri->mcast_addr = new_addr(pri->addr, pri->port); + pri->dev = dev; +} + +static int mcast_open(void *data) +{ + struct mcast_data *pri = data; + struct sockaddr_in *sin = pri->mcast_addr; + struct ip_mreq mreq; + char addr[sizeof("255.255.255.255\0")]; + int fd, err, yes = 1; + + + if(!pri->hw_setup){ + pri->hwaddr[0] = 0xfe; + pri->hwaddr[1] = 0xfd; + pri->hwaddr[2] = 0x0; + pri->hwaddr[3] = 0x0; + pri->hwaddr[4] = 0x0; + pri->hwaddr[5] = 0x0; + dev_ip_addr(pri->dev, addr, &pri->hwaddr[2]); + set_ether_mac(pri->dev, pri->hwaddr); + } + + if ((sin->sin_addr.s_addr == 0) || (sin->sin_port == 0)) { + err = -EINVAL; + goto out; + } + + if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0){ + printk("mcast_open : data socket failed, errno = %d\n", + errno); + err = -ENOMEM; + goto out; + } + + if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0) { + printk("mcast_open: SO_REUSEADDR failed, errno = %d\n", + errno); + close(fd); + err = -EINVAL; + goto out; + } + + /* set ttl according to config */ + if (setsockopt(fd, SOL_IP, IP_MULTICAST_TTL, &pri->ttl, + sizeof(pri->ttl)) < 0) { + printk("mcast_open: IP_MULTICAST_TTL failed, error = %d\n", + errno); + close(fd); + err = -EINVAL; + goto out; + } + + /* set LOOP, so data does get fed back to local sockets */ + if (setsockopt(fd, SOL_IP, IP_MULTICAST_LOOP, &yes, sizeof(yes)) < 0) { + printk("mcast_open: IP_MULTICAST_LOOP failed, error = %d\n", + errno); + close(fd); + err = -EINVAL; + goto out; + } + + /* bind socket to mcast address */ + if (bind(fd, (struct sockaddr *) sin, sizeof(*sin)) < 0) { + printk("mcast_open : data bind failed, errno = %d\n", errno); + close(fd); + err = -EINVAL; + goto out; + } + + /* subscribe to the multicast group */ + mreq.imr_multiaddr.s_addr = sin->sin_addr.s_addr; + mreq.imr_interface.s_addr = 0; + if (setsockopt(fd, SOL_IP, IP_ADD_MEMBERSHIP, + &mreq, sizeof(mreq)) < 0) { + printk("mcast_open: IP_ADD_MEMBERSHIP failed, error = %d\n", + errno); + printk("There appears not to be a multicast-capable network " + "interface on the host.\n"); + printk("eth0 should be configured in order to use the " + "multicast transport.\n"); + close(fd); + err = -EINVAL; + goto out; + } + + return(fd); + out: + return(err); +} + +static void mcast_close(int fd, void *data) +{ + struct ip_mreq mreq; + struct mcast_data *pri = data; + struct sockaddr_in *sin = pri->mcast_addr; + + mreq.imr_multiaddr.s_addr = sin->sin_addr.s_addr; + mreq.imr_interface.s_addr = 0; + if (setsockopt(fd, SOL_IP, IP_DROP_MEMBERSHIP, + &mreq, sizeof(mreq)) < 0) { + printk("mcast_open: IP_DROP_MEMBERSHIP failed, error = %d\n", + errno); + } + + close(fd); +} + +int mcast_user_write(int fd, void *buf, int len, struct mcast_data *pri) +{ + struct sockaddr_in *data_addr = pri->mcast_addr; + + return(net_sendto(fd, buf, len, data_addr, sizeof(*data_addr))); +} + +static int mcast_set_mtu(int mtu, void *data) +{ + return(mtu); +} + +int mcast_user_set_mac(struct mcast_data *pri, unsigned char *hwaddr, + int len) +{ + memcpy(pri->hwaddr, hwaddr, len); + return 0; +} + +struct net_user_info mcast_user_info = { + init: mcast_user_init, + open: mcast_open, + close: mcast_close, + set_mtu: mcast_set_mtu, + add_address: NULL, + delete_address: NULL, + max_packet: MAX_PACKET - ETH_HEADER_OTHER +}; + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/drivers/mconsole_kern.c linux_umopenmosix/arch/um/drivers/mconsole_kern.c --- linux-2.4.17/arch/um/drivers/mconsole_kern.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/drivers/mconsole_kern.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,238 @@ +/* + * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) + * Licensed under the GPL + */ + +#include "linux/kernel.h" +#include "linux/slab.h" +#include "linux/init.h" +#include "linux/notifier.h" +#include "linux/reboot.h" +#include "linux/utsname.h" +#include "linux/ctype.h" +#include "linux/interrupt.h" +#include "linux/sysrq.h" +#include "asm/irq.h" +#include "user_util.h" +#include "kern_util.h" +#include "kern.h" +#include "mconsole.h" +#include "mconsole_kern.h" +#include "irq_user.h" + +static int do_unlink_socket(struct notifier_block *notifier, + unsigned long what, void *data) +{ + return(mconsole_unlink_socket()); +} + + +static struct notifier_block reboot_notifier = { + notifier_call: do_unlink_socket, + priority: 0, +}; + +LIST_HEAD(mc_requests); + +void mc_task_proc(void *unused) +{ + struct mconsole_entry *req; + unsigned long flags; + int done; + + do { + save_flags(flags); + req = list_entry(mc_requests.next, struct mconsole_entry, + list); + list_del(&req->list); + done = list_empty(&mc_requests); + restore_flags(flags); + req->request.cmd->handler(&req->request); + kfree(req); + } while(!done); +} + +struct tq_struct mconsole_task = { + routine: mc_task_proc, + data: NULL +}; + +void mconsole_interrupt(int irq, void *dev_id, struct pt_regs *regs) +{ + int fd; + struct mconsole_entry *new; + struct mc_request req; + + fd = (int) dev_id; + while (mconsole_get_request(fd, &req)){ + if(req.cmd->as_interrupt) (*req.cmd->handler)(&req); + else { + new = kmalloc(sizeof(req), GFP_ATOMIC); + if(new == NULL) + mconsole_reply(&req, "Out of memory", 1, 0); + else { + new->request = req; + list_add(&new->list, &mc_requests); + } + } + } + if(!list_empty(&mc_requests)) schedule_task(&mconsole_task); + reactivate_fd(fd); +} + +void mconsole_version(struct mc_request *req) +{ + char version[256]; + + sprintf(version, "%s %s %s %s %s", system_utsname.sysname, + system_utsname.nodename, system_utsname.release, + system_utsname.version, system_utsname.machine); + mconsole_reply(req, version, 0, 0); +} + +#define UML_MCONSOLE_HELPTEXT \ +"Commands: + version - Get kernel version + help - Print this message + halt - Halt UML + reboot - Reboot UML + config = - Add a new device to UML; + same syntax as command line + remove - Remove a device from the client +" + +void mconsole_help(struct mc_request *req) +{ + mconsole_reply(req, UML_MCONSOLE_HELPTEXT, 0, 0); +} + +void mconsole_halt(struct mc_request *req) +{ + mconsole_reply(req, "", 0, 0); + machine_halt(); +} + +void mconsole_reboot(struct mc_request *req) +{ + mconsole_reply(req, "", 0, 0); + machine_restart(NULL); +} + +extern void ctrl_alt_del(void); + +void mconsole_cad(struct mc_request *req) +{ + mconsole_reply(req, "", 0, 0); + ctrl_alt_del(); +} + +LIST_HEAD(mconsole_devices); + +void mconsole_register_dev(struct mc_device *new) +{ + list_add(&new->list, &mconsole_devices); +} + +static struct mc_device *mconsole_find_dev(char *name) +{ + struct list_head *ele; + struct mc_device *dev; + + list_for_each(ele, &mconsole_devices){ + dev = list_entry(ele, struct mc_device, list); + if(!strncmp(name, dev->name, strlen(dev->name))) + return(dev); + } + return(NULL); +} + +void mconsole_config(struct mc_request *req) +{ + struct mc_device *dev; + char *ptr = req->request.data; + int err; + + ptr += strlen("config"); + while(isspace(*ptr)) ptr++; + dev = mconsole_find_dev(ptr); + if(dev == NULL){ + mconsole_reply(req, "Bad configuration option", 1, 0); + return; + } + err = (*dev->config)(&ptr[strlen(dev->name)]); + mconsole_reply(req, "", err, 0); +} + +void mconsole_remove(struct mc_request *req) +{ + struct mc_device *dev; + char *ptr = req->request.data; + int err; + + ptr += strlen("remove"); + while(isspace(*ptr)) ptr++; + dev = mconsole_find_dev(ptr); + if(dev == NULL){ + mconsole_reply(req, "Bad remove option", 1, 0); + return; + } + err = (*dev->remove)(&ptr[strlen(dev->name)]); + mconsole_reply(req, "", err, 0); +} + +#ifdef CONFIG_MAGIC_SYSRQ +void mconsole_sysrq(struct mc_request *req) +{ + char *ptr = req->request.data; + + ptr += strlen("sysrq"); + while(isspace(*ptr)) ptr++; + + handle_sysrq(*ptr, (struct pt_regs *) ¤t->thread.process_regs, + NULL, NULL); + mconsole_reply(req, "", 0, 0); +} +#else +void mconsole_sysrq(struct mc_request *req) +{ + mconsole_reply(req, "Sysrq not compiled in", 1, 0); +} +#endif + +int mconsole_init(void) +{ + int err; + int sock; + + sock = mconsole_create_listening_socket(); + if (sock < 0) { + printk("Failed to initialize management console\n"); + return 1; + } + + register_reboot_notifier(&reboot_notifier); + + err = um_request_irq(MCONSOLE_IRQ, sock, mconsole_interrupt, + SA_INTERRUPT | SA_SHIRQ, "mconsole", + (void *)sock); + if (err) { + printk("Failed to get IRQ for management console\n"); + return 1; + } + + printk("mconsole initialized on %s\n", mconsole_socket_name); + return 0; +} + +__initcall(mconsole_init); + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/drivers/mconsole_user.c linux_umopenmosix/arch/um/drivers/mconsole_user.c --- linux-2.4.17/arch/um/drivers/mconsole_user.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/drivers/mconsole_user.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,232 @@ +/* + * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) + * Licensed under the GPL + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "user.h" +#include "mconsole.h" +#include "umid.h" + +static struct mconsole_command commands[] = { + { "version", mconsole_version, 1 }, + { "halt", mconsole_halt, 0 }, + { "reboot", mconsole_reboot, 0 }, + { "config", mconsole_config, 0 }, + { "remove", mconsole_remove, 0 }, + { "sysrq", mconsole_sysrq, 1 }, + { "help", mconsole_help, 1 }, + { "cad", mconsole_cad, 1 }, +}; + +char mconsole_socket_name[256]; + +static int has_correct_credentials(struct msghdr *msg) +{ + struct cmsghdr *cmsg; + + cmsg = CMSG_FIRSTHDR(msg); + while (cmsg != NULL) { + if (cmsg->cmsg_level == SOL_SOCKET && + cmsg->cmsg_type == SCM_CREDENTIALS) { + struct ucred *cred; + + cred = (struct ucred *)CMSG_DATA(cmsg); + if (cred->uid == getuid()) + return 1; + } + cmsg = CMSG_NXTHDR(msg, cmsg); + } + + return 0; +} + +int mconsole_reply_v0(struct mc_request *req, char *reply) +{ + struct iovec iov; + struct msghdr msg; + + iov.iov_base = reply; + iov.iov_len = strlen(reply); + + msg.msg_name = &(req->origin); + msg.msg_namelen = req->originlen; + msg.msg_iov = &iov; + msg.msg_iovlen = 1; + msg.msg_control = NULL; + msg.msg_controllen = 0; + msg.msg_flags = 0; + + return sendmsg(req->originating_fd, &msg, 0); +} + +static struct mconsole_command *mconsole_parse(struct mc_request *req) +{ + struct mconsole_command *cmd; + int i; + + for(i=0;irequest.data, cmd->command, + strlen(cmd->command))){ + return(cmd); + } + } + return(NULL); +} + +#define MIN(a,b) ((a)<(b) ? (a):(b)) + +int mconsole_get_request(int fd, struct mc_request *req) +{ + char anc[64]; + struct iovec iov; + struct msghdr msg; + int len; + + iov.iov_base = &req->request; + iov.iov_len = sizeof(req->request); + + msg.msg_name = &(req->origin); + msg.msg_namelen = sizeof(req->origin); + msg.msg_iov = &iov; + msg.msg_iovlen = 1; + msg.msg_control = anc; + msg.msg_controllen = sizeof(anc); + msg.msg_flags = 0; + + req->len = recvmsg(fd, &msg, 0); + if (req->len < 0) + return 0; + + if(!has_correct_credentials(&msg)){ + mconsole_reply(req, "Permission denied", 1, 0); + return(0); + } + + req->originlen = msg.msg_namelen; + req->originating_fd = fd; + + if(req->request.magic != MCONSOLE_MAGIC){ + /* Unversioned request */ + len = MIN(sizeof(req->request.data) - 1, + strlen((char *) &req->request)); + memmove(req->request.data, &req->request, len); + req->request.data[len] = '\0'; + + req->request.magic = MCONSOLE_MAGIC; + req->request.version = 0; + req->request.len = len; + + mconsole_reply_v0(req, "ERR Version 0 mconsole clients are " + "not supported by this driver"); + return(0); + } + + req->cmd = mconsole_parse(req); + if(req->cmd == NULL){ + mconsole_reply(req, "Unknown command", 1, 0); + return(0); + } + + return(1); +} + +int mconsole_reply(struct mc_request *req, char *str, int err, int more) +{ + struct iovec iov; + struct msghdr msg; + struct mconsole_reply reply; + int total, len, n; + + msg.msg_name = &(req->origin); + msg.msg_namelen = req->originlen; + msg.msg_iov = &iov; + msg.msg_iovlen = 1; + msg.msg_control = NULL; + msg.msg_controllen = 0; + msg.msg_flags = 0; + + total = strlen(str); + do { + reply.err = err; + + /* err can only be true on the first packet */ + err = 0; + + len = MIN(total, MCONSOLE_MAX_DATA - 1); + + if(len == total) reply.more = more; + else reply.more = 1; + + memcpy(reply.data, str, len); + reply.data[len] = '\0'; + total -= len; + reply.len = len + 1; + + iov.iov_base = &reply; + iov.iov_len = sizeof(reply) + reply.len - sizeof(reply.data); + n = sendmsg(req->originating_fd, &msg, 0); + if(n < 0) return(-errno); + } while(total > 0); + return(0); +} + +int mconsole_unlink_socket(void) +{ + unlink(mconsole_socket_name); + return 0; +} + +int mconsole_create_listening_socket(void) +{ + struct sockaddr_un addr; + char file[256]; + int sock, err, yes = 1; + + sock = socket(PF_UNIX, SOCK_DGRAM, 0); + if (sock < 0) { + printk("create_listening_socket - socket failed, errno = %d\n", + errno); + return(-1); + } + + addr.sun_family = AF_UNIX; + + if(umid_file_name("mconsole", file, sizeof(file))) return(-1); + + strcpy(mconsole_socket_name, file); + strcpy(addr.sun_path, file); + + err = bind(sock, (struct sockaddr *) &addr, sizeof(addr)); + if (err < 0) { + if (errno != EADDRINUSE) { + printk("create_listening_socket - bind failed, " + "errno = %d\n", errno); + return(-1); + } + } + + setsockopt(sock, SOL_SOCKET, SO_PASSCRED, &yes, sizeof(yes)); + + return sock; +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/drivers/mmapper_kern.c linux_umopenmosix/arch/um/drivers/mmapper_kern.c --- linux-2.4.17/arch/um/drivers/mmapper_kern.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/drivers/mmapper_kern.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,146 @@ +/* + * arch/um/drivers/mmapper_kern.c + * + * BRIEF MODULE DESCRIPTION + * + * Copyright (C) 2000 RidgeRun, Inc. + * Author: RidgeRun, Inc. + * Greg Lonnon glonnon@ridgerun.com or info@ridgerun.com + * + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "mem_user.h" +#include "user_util.h" + +static unsigned long mmapper_size; +static char *p_buf = NULL; +static char *v_buf = NULL; + +static ssize_t +mmapper_read(struct file *file, char *buf, size_t count, loff_t *ppos) +{ + if(*ppos > mmapper_size) + return -EINVAL; + + if(count + *ppos > mmapper_size) + count = count + *ppos - mmapper_size; + + if(count < 0) + return -EINVAL; + + copy_to_user(buf,&v_buf[*ppos],count); + + return count; +} + +static ssize_t +mmapper_write(struct file *file, const char *buf, size_t count, loff_t *ppos) +{ + if(*ppos > mmapper_size) + return -EINVAL; + + if(count + *ppos > mmapper_size) + count = count + *ppos - mmapper_size; + + if(count < 0) + return -EINVAL; + + copy_from_user(&v_buf[*ppos],buf,count); + + return count; +} + +static int +mmapper_ioctl(struct inode *inode, struct file *file, unsigned int cmd, + unsigned long arg) +{ + return(-ENOIOCTLCMD); +} + +static int +mmapper_mmap(struct file *file, struct vm_area_struct * vma) +{ + int ret = -EINVAL; + int size; + + lock_kernel(); + if (vma->vm_pgoff != 0) + goto out; + + size = vma->vm_end - vma->vm_start; + + /* XXX A comment above remap_page_range says it should only be + * called when the mm semaphore is held + */ + if (remap_page_range(vma->vm_start, (unsigned long) p_buf, + size, vma->vm_page_prot)) + goto out; + ret = 0; +out: + unlock_kernel(); + return ret; +} + +static int +mmapper_open(struct inode *inode, struct file *file) +{ + return 0; +} + +static int +mmapper_release(struct inode *inode, struct file *file) +{ + return 0; +} + +static struct file_operations mmapper_fops = { + owner: THIS_MODULE, + read: mmapper_read, + write: mmapper_write, + ioctl: mmapper_ioctl, + mmap: mmapper_mmap, + open: mmapper_open, + release: mmapper_release, +}; + +static int __init mmapper_init(void) +{ + printk(KERN_INFO "Mapper v0.1\n"); + + p_buf = (char *) find_iomem("mmapper", &mmapper_size); + + v_buf = p_buf; + + devfs_register (NULL, "mmapper", DEVFS_FL_DEFAULT, + 30, 0, S_IFCHR | S_IRUGO | S_IWUGO, + &mmapper_fops, NULL); + devfs_mk_symlink(NULL, "mmapper", DEVFS_FL_DEFAULT, "mmapper0", + NULL, NULL); + return(0); +} + +static void mmapper_exit(void) +{ +} + +module_init(mmapper_init); +module_exit(mmapper_exit); + +MODULE_AUTHOR("Greg Lonnon "); +MODULE_DESCRIPTION("DSPLinux simulator mmapper driver"); +/* + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/drivers/net_kern.c linux_umopenmosix/arch/um/drivers/net_kern.c --- linux-2.4.17/arch/um/drivers/net_kern.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/drivers/net_kern.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,691 @@ +/* + * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and + * James Leu (jleu@mindspring.net). + * Copyright (C) 2001 by various other people who didn't put their name here. + * Licensed under the GPL. + */ + +#include "linux/config.h" +#include "linux/kernel.h" +#include "linux/netdevice.h" +#include "linux/skbuff.h" +#include "linux/socket.h" +#include "linux/spinlock.h" +#include "linux/module.h" +#include "linux/init.h" +#include "linux/etherdevice.h" +#include "linux/list.h" +#include "linux/inetdevice.h" +#include "linux/ctype.h" +#include "user_util.h" +#include "kern_util.h" +#include "net_kern.h" +#include "net_user.h" +#include "slip.h" +#include "slip_kern.h" +#include "etap.h" +#include "etap_kern.h" +#include "tuntap.h" +#include "tuntap_kern.h" +#include "daemon.h" +#include "daemon_kern.h" +#include "mcast.h" +#include "mcast_kern.h" +#include "mconsole_kern.h" +#include "init.h" +#include "irq_user.h" + +LIST_HEAD(opened); + +struct uml_net devices[MAX_UML_NETDEV] = { + [ 0 ... MAX_UML_NETDEV - 1 ] = + { + dev: NULL, + user: NULL, + kern: NULL, + private_size: 0, + } +}; + +static int eth_setup_common(char *str, int *index_out) +{ + char *end; + int n; + + n = simple_strtoul(str, &end, 0); + if(end == str){ + printk(KERN_ERR "eth_setup: Failed to parse '%s'\n", str); + return(1); + } + if((n < 0) || (n > sizeof(devices)/sizeof(devices[0]))){ + printk(KERN_ERR "eth_setup: device %d out of range\n", n); + return(1); + } + str = end; + if(*str != '='){ + printk(KERN_ERR + "eth_setup: expected '=' after device number\n"); + return(1); + } + str++; + if(devices[n].dev != NULL){ + printk(KERN_ERR "eth_setup: Device %d already configured\n", + n); + return(1); + } + if(index_out) *index_out = n; +#ifdef CONFIG_UML_NET_ETHERTAP + if(!strncmp(str, "ethertap", strlen("ethertap"))){ + ethertap_setup(&str[strlen("ethertap")], &devices[n]); + return(0); + } +#endif +#ifdef CONFIG_UML_NET_TUNTAP + if(!strncmp(str, "tuntap", strlen("tuntap"))){ + tuntap_setup(&str[strlen("tuntap")], &devices[n]); + return(0); + } +#endif +#ifdef CONFIG_UML_NET_DAEMON + if(!strncmp(str, "daemon", strlen("daemon"))){ + daemon_setup(&str[strlen("daemon")], &devices[n]); + return(0); + } +#endif +#ifdef CONFIG_UML_NET_SLIP + if(!strncmp(str, "slip", strlen("slip"))){ + slip_setup(&str[strlen("slip")], &devices[n]); + return(0); + } +#endif +#ifdef CONFIG_UML_NET_MCAST + if(!strncmp(str, "mcast", strlen("mcast"))){ + mcast_setup(&str[strlen("mcast")], &devices[n]); + return(0); + } +#endif + printk(KERN_ERR "Unknown transport in eth_setup : %s\n", str); + return(1); +} + +static int eth_setup(char *str) +{ + eth_setup_common(str, NULL); + return(1); +} + +#ifdef CONFIG_UML_NET_ETHERTAP +#define UML_NET_ETHERTAP_HELP \ +" eth[0-9]+=ethertap,,,\n" \ +" eth0=ethertap,tap0,,192.168.0.1\n\n" +#else +#define UML_NET_ETHERTAP_HELP +#endif +#ifdef CONFIG_UML_NET_TUNTAP +#define UML_NET_TUNTAP_HELP \ +" eth[0-9]+=tuntap,,,\n" \ +" eth0=tuntap,,fe:fd:0:0:0:1,192.168.0.1\n\n" +#else +#define UML_NET_TUNTAP_HELP +#endif +#ifdef CONFIG_UML_NET_DAEMON +#define UML_NET_DAEMON_HELP \ +" eth[0-9]+=daemon,,,,\n" \ +" eth0=daemon,unix,/tmp/uml.ctl,/tmp/uml.data\n\n" +#else +#define UML_NET_DAEMON_HELP +#endif +#ifdef CONFIG_UML_NET_SLIP +#define UML_NET_SLIP_HELP \ +" eth[0-9]+=slip,\n" \ +" eth0=slip,192.168.0.1\n\n" +#else +#define UML_NET_SLIP_HELP +#endif +#ifdef CONFIG_UML_NET_MCAST +#define UML_NET_MCAST_HELP \ +" eth[0-9]+=mcast,,
,,\n" \ +" eth0=mcast,,224.2.3.4:5555,3\n\n" +#else +#define UML_NET_MCAST_HELP +#endif + +__setup("eth", eth_setup); +__uml_help(eth_setup, +"eth[0-9]+=,\n" +" Configure a network device. Formats and examples follow (one \n" +" for each configured transport).\n\n" +UML_NET_ETHERTAP_HELP +UML_NET_TUNTAP_HELP +UML_NET_DAEMON_HELP +UML_NET_SLIP_HELP +UML_NET_MCAST_HELP +); +int ndev = 0; + +static int uml_net_rx(struct net_device *dev) +{ + struct uml_net_private *lp = dev->priv; + int pkt_len; + struct sk_buff *skb; + + /* If we can't allocate memory, try again next round. */ + if ((skb = dev_alloc_skb(dev->mtu)) == NULL) { + lp->stats.rx_dropped++; + reactivate_fd(lp->fd); + return 0; + } + + skb->dev = dev; + skb_put(skb, dev->mtu); + skb->mac.raw = skb->data; + pkt_len = (*lp->read)(lp->fd, &skb, lp); + + reactivate_fd(lp->fd); + if (pkt_len > 0) { + skb_trim(skb, pkt_len); + skb->protocol = (*lp->protocol)(skb); + netif_rx(skb); + + lp->stats.rx_bytes += skb->len; + lp->stats.rx_packets++; + return pkt_len; + } + + kfree_skb(skb); + return pkt_len; +} + +void uml_net_interrupt(int irq, void *dev_id, struct pt_regs *regs) +{ + struct net_device *dev = dev_id; + struct uml_net_private *lp = dev->priv; + int err; + + if (netif_running(dev)) { + spin_lock(&lp->lock); + while((err = uml_net_rx(dev)) > 0) ; + if(err < 0) { + printk(KERN_ERR + "Device '%s' read returned %d, shutting it " + "down\n", dev->name, err); + dev->flags &= ~IFF_UP; + dev_close(dev); + } + spin_unlock(&lp->lock); + } +} + +static int uml_net_open(struct net_device *dev) +{ + struct uml_net_private *lp = dev->priv; + int err; + + spin_lock(&lp->lock); + + if(lp->fd >= 0){ + err = -ENXIO; + goto out; + } + + lp->fd = (*lp->open)(&lp->user); + if(lp->fd < 0){ + err = lp->fd; + goto out; + } + + err = um_request_irq(dev->irq, lp->fd, uml_net_interrupt, + SA_INTERRUPT | SA_SHIRQ, dev->name, dev); + if(err != 0){ + printk(KERN_ERR "uml_net_open: failed to get irq(%d)\n", err); + (*lp->close)(lp->fd, &lp->user); + lp->fd = -1; + err = -ENETUNREACH; + } + + lp->tl.data = (unsigned long) &lp->user; + netif_start_queue(dev); + + list_add(&lp->list, &opened); + MOD_INC_USE_COUNT; + out: + spin_unlock(&lp->lock); + return(err); +} + +static int uml_net_close(struct net_device *dev) +{ + struct uml_net_private *lp = dev->priv; + + netif_stop_queue(dev); + spin_lock(&lp->lock); + + free_irq(dev->irq, dev); + (*lp->close)(lp->fd, &lp->user); + lp->fd = -1; + list_del(&lp->list); + + MOD_DEC_USE_COUNT; + spin_unlock(&lp->lock); + return 0; +} + +static int uml_net_start_xmit(struct sk_buff *skb, struct net_device *dev) +{ + struct uml_net_private *lp = dev->priv; + unsigned long flags; + int len; + + netif_stop_queue(dev); + + spin_lock_irqsave(&lp->lock, flags); + + len = (*lp->write)(lp->fd, &skb, lp); + + if(len == skb->len) { + lp->stats.tx_packets++; + lp->stats.tx_bytes += skb->len; + dev->trans_start = jiffies; + netif_start_queue(dev); + + /* this is normally done in the interrupt when tx finishes */ + netif_wake_queue(dev); + } + else if(len == 0){ + netif_start_queue(dev); + lp->stats.tx_dropped++; + } + else { + netif_start_queue(dev); + printk(KERN_ERR "uml_net_start_xmit: failed(%d)\n", len); + } + + spin_unlock_irqrestore(&lp->lock, flags); + + dev_kfree_skb(skb); + + return 0; +} + +static struct net_device_stats *uml_net_get_stats(struct net_device *dev) +{ + struct uml_net_private *lp = dev->priv; + return &lp->stats; +} + +static void uml_net_set_multicast_list(struct net_device *dev) +{ + if (dev->flags & IFF_PROMISC) return; + else if (dev->mc_count) dev->flags |= IFF_ALLMULTI; + else dev->flags &= ~IFF_ALLMULTI; +} + +static void uml_net_tx_timeout(struct net_device *dev) +{ + dev->trans_start = jiffies; + netif_wake_queue(dev); +} + +static int uml_net_set_mac(struct net_device *dev, void *addr) +{ + struct uml_net_private *lp = dev->priv; + struct sockaddr *hwaddr = addr; + int err; + + spin_lock(&lp->lock); + + err = (*lp->set_mac)(hwaddr, &lp->user); + + spin_unlock(&lp->lock); + + return err; +} + +static int uml_net_change_mtu(struct net_device *dev, int new_mtu) +{ + struct uml_net_private *lp = dev->priv; + int err = 0; + + spin_lock(&lp->lock); + + new_mtu = (*lp->set_mtu)(new_mtu, &lp->user); + if(new_mtu < 0){ + err = new_mtu; + goto out; + } + + dev->mtu = new_mtu; + + out: + spin_unlock(&lp->lock); + return err; +} + +static int uml_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) +{ + return(-EINVAL); +} + +void uml_net_user_timer_expire(unsigned long _conn) +{ +#ifdef undef + struct connection *conn = (struct connection *)_conn; + + dprintk(KERN_INFO "uml_net_user_timer_expire [%p]\n", conn); + do_connect(conn); +#endif +} + +static int eth_configure(struct uml_net *device, int n) +{ + struct net_device *dev; + struct uml_net_private *lp; + + device->private_size += sizeof(struct uml_net_private) + + sizeof(((struct uml_net_private *) 0)->user); + printk(KERN_INFO "Netdevice %d : ", n); + dev = (*device->kern->init)(device->private_size, + device->transport_index); + device->dev = dev; + + if (dev == NULL){ + printk(KERN_ERR "eth_configure: Out of memory on device %d\n", + n); + return(1); + } + + dev->mtu = device->user->max_packet; + dev->open = uml_net_open; + dev->hard_start_xmit = uml_net_start_xmit; + dev->stop = uml_net_close; + dev->get_stats = uml_net_get_stats; + dev->set_multicast_list = uml_net_set_multicast_list; + dev->tx_timeout = uml_net_tx_timeout; + dev->set_mac_address = uml_net_set_mac; + dev->change_mtu = uml_net_change_mtu; + dev->do_ioctl = uml_net_ioctl; + dev->watchdog_timeo = (HZ >> 1); + dev->irq = UM_ETH_IRQ; + + lp = dev->priv; + spin_lock_init(&lp->lock); + init_timer(&lp->tl); + lp->tl.function = uml_net_user_timer_expire; + lp->list = ((struct list_head) LIST_HEAD_INIT(lp->list)); + memset(&lp->stats, 0, sizeof(lp->stats)); + lp->fd = -1; + lp->protocol = device->kern->protocol; + lp->set_mac = device->kern->set_mac; + lp->open = device->user->open; + lp->close = device->user->close; + lp->read = device->kern->read; + lp->write = device->kern->write; + lp->add_address = device->user->add_address; + lp->delete_address = device->user->delete_address; + lp->set_mtu = device->user->set_mtu; + + if(device->user->init) + (*device->user->init)(&lp->user, dev); + return(0); +} + +int __init uml_net_probe(void) +{ + int i; + + for(i = 0; i < sizeof(devices)/sizeof(devices[0]); i++){ + if(devices[i].user == NULL) continue; + eth_configure(&devices[i], i); + } + return(0); +} + +static int net_config(char *str) +{ + int err, n; + + str = uml_strdup(str); + if(str == NULL){ + printk(KERN_ERR "net_config failed to strdup string\n"); + return(1); + } + err = eth_setup_common(str, &n); + if(err){ + kfree(str); + return(err); + } + err = eth_configure(&devices[n], n); + return(err); +} + +static int net_remove(char *str) +{ + struct net_device *dev; + struct uml_net_private *lp; + int n; + + if(!isdigit(*str)) return(-1); + n = *str - '0'; + if(devices[n].dev == NULL) return(0); + dev = devices[n].dev; + lp = dev->priv; + if(lp->fd > 0) return(-1); + unregister_netdev(dev); + devices[n].dev = NULL; + return(0); +} + +static struct mc_device net_mc = { + name: "eth", + config: net_config, + remove: net_remove, +}; + +static int uml_inetaddr_event(struct notifier_block *this, unsigned long event, + void *ptr) +{ + struct in_ifaddr *ifa = ptr; + u32 addr = ifa->ifa_address; + u32 netmask = ifa->ifa_mask; + struct net_device *dev = ifa->ifa_dev->dev; + struct uml_net_private *lp; + void (*proc)(unsigned char *, unsigned char *, void *); + unsigned char addr_buf[4], netmask_buf[4]; + + if(dev->open != uml_net_open) return(NOTIFY_DONE); + + lp = dev->priv; + if(lp->fd == -1) return(NOTIFY_DONE); + + proc = NULL; + switch (event){ + case NETDEV_UP: + proc = lp->add_address; + break; + case NETDEV_DOWN: + proc = lp->delete_address; + break; + } + if(proc != NULL){ + addr_buf[0] = addr & 0xff; + addr_buf[1] = (addr >> 8) & 0xff; + addr_buf[2] = (addr >> 16) & 0xff; + addr_buf[3] = addr >> 24; + netmask_buf[0] = netmask & 0xff; + netmask_buf[1] = (netmask >> 8) & 0xff; + netmask_buf[2] = (netmask >> 16) & 0xff; + netmask_buf[3] = netmask >> 24; + (*proc)(addr_buf, netmask_buf, &lp->user); + } + return(NOTIFY_DONE); +} + +struct notifier_block uml_inetaddr_notifier = { + notifier_call: uml_inetaddr_event, +}; + +static int uml_net_init(void) +{ + mconsole_register_dev(&net_mc); + register_inetaddr_notifier(¨_inetaddr_notifier); + return(0); +} + +__initcall(uml_net_init); + +static void close_devices(void) +{ + struct list_head *ele; + struct uml_net_private *lp; + + list_for_each(ele, &opened){ + lp = list_entry(ele, struct uml_net_private, list); + (*lp->close)(lp->fd, &lp->user); + } +} + +__uml_exitcall(close_devices); + +int setup_etheraddr(char *str, unsigned char *addr) +{ + char *end; + int i; + + for(i=0;i<6;i++){ + addr[i] = simple_strtoul(str, &end, 16); + if((end == str) || + ((*end != ':') && (*end != ',') && (*end != '\0'))){ + printk(KERN_ERR + "setup_etheraddr: failed to parse '%s' " + "as an ethernet address\n", str); + return(-1); + } + str = end + 1; + } + if(addr[0] & 1){ + printk(KERN_ERR + "Attempt to assign a broadcast ethernet address to a " + "device disallowed\n"); + return(-1); + } + return(0); +} + +void dev_ip_addr(void *d, char *buf, char *bin_buf) +{ + struct net_device *dev = d; + struct in_device *ip = dev->ip_ptr; + struct in_ifaddr *in; + u32 addr; + + if((ip == NULL) || ((in = ip->ifa_list) == NULL)){ + printk(KERN_WARNING "dev_ip_addr - device not assigned an " + "IP address\n"); + return; + } + addr = in->ifa_address; + sprintf(buf, "%d.%d.%d.%d", addr & 0xff, (addr >> 8) & 0xff, + (addr >> 16) & 0xff, addr >> 24); + if(bin_buf){ + bin_buf[0] = addr & 0xff; + bin_buf[1] = (addr >> 8) & 0xff; + bin_buf[2] = (addr >> 16) & 0xff; + bin_buf[3] = addr >> 24; + } +} + +void set_ether_mac(void *d, unsigned char *addr) +{ + struct net_device *dev = d; + + memcpy(dev->dev_addr, addr, ETH_ALEN); +} + +struct sk_buff *ether_adjust_skb(struct sk_buff *skb, int extra) +{ + if((skb != NULL) && (skb_tailroom(skb) < extra)){ + struct sk_buff *skb2; + + skb2 = skb_copy_expand(skb, 0, extra, GFP_ATOMIC); + dev_kfree_skb(skb); + skb = skb2; + } + if(skb != NULL) skb_put(skb, extra); + return(skb); +} + +void iter_addresses(void *d, void (*cb)(unsigned char *, unsigned char *, + void *), + void *arg) +{ + struct net_device *dev = d; + struct in_device *ip = dev->ip_ptr; + struct in_ifaddr *in; + unsigned char address[4], netmask[4]; + + if(ip == NULL) return; + in = ip->ifa_list; + while(in != NULL){ + address[0] = in->ifa_address & 0xff; + address[1] = (in->ifa_address >> 8) & 0xff; + address[2] = (in->ifa_address >> 16) & 0xff; + address[3] = in->ifa_address >> 24; + netmask[0] = in->ifa_mask & 0xff; + netmask[1] = (in->ifa_mask >> 8) & 0xff; + netmask[2] = (in->ifa_mask >> 16) & 0xff; + netmask[3] = in->ifa_mask >> 24; + (*cb)(address, netmask, arg); + in = in->ifa_next; + } +} + +void *get_output_buffer(int *len_out) +{ + void *ret; + + ret = (void *) __get_free_pages(GFP_KERNEL, 0); + if(ret) *len_out = PAGE_SIZE; + else *len_out = 0; + return(ret); +} + +void free_output_buffer(void *buffer) +{ + free_pages((unsigned long) buffer, 0); +} + +void tap_setup_common(char *str, char *type, char **dev_name, char *hw_addr, + int *hw_setup, char **gate_addr) +{ + int err; + + if(*str != ','){ + printk(KERN_ERR + "ethertap_setup: expected ',' after '%s'\n", type); + return; + } + str++; + if(*str != ',') *dev_name = str; + str = strchr(str, ','); + if(str == NULL) return; + *str++ = '\0'; + if(*str != ','){ + err = setup_etheraddr(str, hw_addr); + if(!err) *hw_setup = 1; + } + str = strchr(str, ','); + if(str == NULL) return; + *str++ = '\0'; + if(*str != '\0') *gate_addr = str; +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/drivers/net_kern.h linux_umopenmosix/arch/um/drivers/net_kern.h --- linux-2.4.17/arch/um/drivers/net_kern.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/drivers/net_kern.h Sun Jun 23 13:07:34 2002 @@ -0,0 +1,66 @@ +#ifndef __UM_NET_KERN_H +#define __UM_NET_KERN_H + +#include "linux/netdevice.h" +#include "linux/skbuff.h" +#include "linux/socket.h" +#include "linux/list.h" + +#define MAX_UML_NETDEV (16) + +struct uml_net { + struct net_device *dev; + struct net_user_info *user; + struct net_kern_info *kern; + int private_size; + int transport_index; +}; + +struct uml_net_private { + spinlock_t lock; + + struct timer_list tl; + struct list_head list; + struct net_device_stats stats; + int fd; + unsigned short (*protocol)(struct sk_buff *); + int (*set_mac)(struct sockaddr *hwaddr, void *); + int (*open)(void *); + void (*close)(int, void *); + int (*read)(int, struct sk_buff **skb, struct uml_net_private *); + int (*write)(int, struct sk_buff **skb, struct uml_net_private *); + + void (*add_address)(unsigned char *, unsigned char *, void *); + void (*delete_address)(unsigned char *, unsigned char *, void *); + int (*set_mtu)(int mtu, void *); + int user[1]; +}; + +struct net_kern_info { + struct net_device *(*init)(int, int); + unsigned short (*protocol)(struct sk_buff *); + int (*set_mac)(struct sockaddr *hwaddr, void *); + int (*read)(int, struct sk_buff **skb, struct uml_net_private *); + int (*write)(int, struct sk_buff **skb, struct uml_net_private *); +}; + +extern struct net_device *ether_init(int); +extern unsigned short ether_protocol(struct sk_buff *); +extern int ether_set_mac(struct sockaddr *hwaddr, void *); +extern int setup_etheraddr(char *str, unsigned char *addr); +extern struct sk_buff *ether_adjust_skb(struct sk_buff *skb, int extra); +extern void tap_setup_common(char *str, char *type, char **dev_name, + char *hw_addr, int *hw_setup, char **gate_addr); + +#endif + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/drivers/net_user.c linux_umopenmosix/arch/um/drivers/net_user.c --- linux-2.4.17/arch/um/drivers/net_user.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/drivers/net_user.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,227 @@ +/* + * Copyright (C) 2001 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include +#include +#include +#include +#include +#include +#include +#include "user.h" +#include "user_util.h" +#include "kern_util.h" +#include "net_user.h" + +int tap_open_common(void *dev, int hw_setup, char *gate_addr) +{ + char addr[sizeof("255.255.255.255\0")]; + char ether[ETH_ADDR_LEN]; + + if((gate_addr != NULL) || !hw_setup){ + ether[0] = 0xfe; + ether[1] = 0xfd; + ether[2] = 0x0; + ether[3] = 0x0; + ether[4] = 0x0; + ether[5] = 0x0; + dev_ip_addr(dev, addr, ðer[2]); + } + if(gate_addr != NULL){ + int uml_addr[4], tap_addr[4]; + if(sscanf(addr, "%d.%d.%d.%d", ¨_addr[0], ¨_addr[1], + ¨_addr[2], ¨_addr[3]) != 4){ + printk("Invalid UML IP address - '%s'\n", addr); + return(-EINVAL); + } + if(sscanf(gate_addr, "%d.%d.%d.%d", &tap_addr[0], + &tap_addr[1], &tap_addr[2], &tap_addr[3]) != 4){ + printk("Invalid tap IP address - '%s'\n", + gate_addr); + return(-EINVAL); + } + if((uml_addr[0] == tap_addr[0]) && + (uml_addr[1] == tap_addr[1]) && + (uml_addr[2] == tap_addr[2]) && + (uml_addr[3] == tap_addr[3])){ + printk("The tap IP address and the UML eth IP address" + " must be different\n"); + return(-EINVAL); + } + } + if(!hw_setup){ + ether[0] = 0xfe; + ether[1] = 0xfd; + set_ether_mac(dev, ether); + } + return(0); +} + +int read_output(int fd, char **output_out) +{ + int n; + + if(read(fd, &n, sizeof(n)) != sizeof(n)){ + printk("read_output - read of length failed, errno = %d\n", + errno); + return(-1); + } + if((*output_out = um_kmalloc(n)) == NULL){ + printk("read_output - kmalloc failed\n"); + return(-1); + } + if(read(fd, *output_out, n) != n){ + printk("read_output - read of data failed, errno = %d\n", + errno); + kfree(*output_out); + return(-1); + } + return(0); +} + +int net_read(int fd, void *buf, int len) +{ + int n; + + while(((n = read(fd, buf, len)) < 0) && (errno == EINTR)) ; + + if(n < 0){ + if(errno == EAGAIN) return(0); + return(-errno); + } + else if(n == 0) return(-ENOTCONN); + return(n); +} + +int net_recvfrom(int fd, void *buf, int len) +{ + int n; + + while(((n = recvfrom(fd, buf, len, 0, NULL, NULL)) < 0) && + (errno == EINTR)) ; + + if(n < 0){ + if(errno == EAGAIN) return(0); + return(-errno); + } + else if(n == 0) return(-ENOTCONN); + return(n); +} + +int net_write(int fd, void *buf, int len) +{ + int n; + + while(((n = write(fd, buf, len)) < 0) && (errno == EINTR)) ; + if(n < 0){ + if(errno == EAGAIN) return(0); + return(-errno); + } + else if(n == 0) return(-ENOTCONN); + return(n); +} + +int net_send(int fd, void *buf, int len) +{ + int n; + + while(((n = send(fd, buf, len, 0)) < 0) && (errno == EINTR)) ; + if(n < 0){ + if(errno == EAGAIN) return(0); + return(-errno); + } + else if(n == 0) return(-ENOTCONN); + return(n); +} + +int net_sendto(int fd, void *buf, int len, void *to, int sock_len) +{ + int n; + + while(((n = sendto(fd, buf, len, 0, (struct sockaddr *) to, + sock_len)) < 0) && (errno == EINTR)) ; + if(n < 0){ + if(errno == EAGAIN) return(0); + return(-errno); + } + else if(n == 0) return(-ENOTCONN); + return(n); +} + +struct change_data { + char *dev; + char *what; + char *address; + char *netmask; + char *output; +}; + +static void change_tramp(void *arg) +{ + int pid, fds[2]; + struct change_data *data = arg; + char version[sizeof("nnnnn\0")]; + char *argv[] = { "uml_net", version, data->what, data->dev, + data->address, data->netmask, NULL }; + + sprintf(version, "%d", UML_NET_VERSION); + if(pipe(fds) < 0){ + printk("change_tramp - pipe failed, errno = %d\n", + errno); + return; + } + if((pid = fork()) == 0){ + dup2(fds[1], 1); + close(fds[0]); + execvp(argv[0], argv); + printk("Exec of '%s' failed - errno = %d\n", argv[0], errno); + exit(1); + } + close(fds[1]); + if(read_output(fds[0], &data->output)) data->output = NULL; + waitpid(pid, NULL, 0); +} + +static void change(char *dev, char *what, unsigned char *addr, + unsigned char *netmask) +{ + char addr_buf[sizeof("255.255.255.255\0")]; + char netmask_buf[sizeof("255.255.255.255\0")]; + struct change_data data; + + data.dev = dev; + data.what = what; + sprintf(addr_buf, "%d.%d.%d.%d", addr[0], addr[1], addr[2], addr[3]); + sprintf(netmask_buf, "%d.%d.%d.%d", netmask[0], netmask[1], + netmask[2], netmask[3]); + data.address = addr_buf; + data.netmask = netmask_buf; + tracing_cb(change_tramp, &data); + if(data.output != NULL){ + printk("%s", data.output); + kfree(data.output); + } +} + +void open_addr(unsigned char *addr, unsigned char *netmask, void *arg) +{ + change(arg, "add", addr, netmask); +} + +void close_addr(unsigned char *addr, unsigned char *netmask, void *arg) +{ + change(arg, "del", addr, netmask); +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/drivers/net_user.h linux_umopenmosix/arch/um/drivers/net_user.h --- linux-2.4.17/arch/um/drivers/net_user.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/drivers/net_user.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,55 @@ +#ifndef __UM_NET_USER_H__ +#define __UM_NET_USER_H__ + +#define ETH_ADDR_LEN (6) +#define ETH_HEADER_ETHERTAP (16) +#define ETH_HEADER_OTHER (14) +#define ETH_MAX_PACKET (1500) + +#define UML_NET_VERSION (4) + +struct net_user_info { + void (*init)(void *, void *); + int (*open)(void *); + void (*close)(int, void *); + int (*set_mtu)(int mtu, void *); + void (*add_address)(unsigned char *, unsigned char *, void *); + void (*delete_address)(unsigned char *, unsigned char *, void *); + int max_packet; +}; + +extern void ether_user_init(void *data, void *dev); +extern void dev_ip_addr(void *d, char *buf, char *bin_buf); +extern void set_ether_mac(void *d, unsigned char *addr); +extern void iter_addresses(void *d, void (*cb)(unsigned char *, + unsigned char *, void *), + void *arg); + +extern void *get_output_buffer(int *len_out); +extern void free_output_buffer(void *buffer); + +extern int tap_open_common(void *dev, int hw_setup, char *gate_addr); + +extern int read_output(int fd, char **output_out); + +extern int net_read(int fd, void *buf, int len); +extern int net_recvfrom(int fd, void *buf, int len); +extern int net_write(int fd, void *buf, int len); +extern int net_send(int fd, void *buf, int len); +extern int net_sendto(int fd, void *buf, int len, void *to, int sock_len); + +extern void open_addr(unsigned char *addr, unsigned char *netmask, void *arg); +extern void close_addr(unsigned char *addr, unsigned char *netmask, void *arg); + +#endif + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/drivers/port.c linux_umopenmosix/arch/um/drivers/port.c --- linux-2.4.17/arch/um/drivers/port.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/drivers/port.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,213 @@ +/* + * Copyright (C) 2001 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "user_util.h" +#include "kern_util.h" +#include "user.h" +#include "chan_user.h" +#include "port.h" + +struct port_chan { + int fd; + int raw; + struct termios tt; + void *kernel_data; +}; + +void *port_init(char *str, int device, struct chan_opts *opts) +{ + struct port_chan *data; + void *kern_data; + char *end; + int port; + + if(*str != ':'){ + printk("port_init : channel type 'port' must specify a " + "port number\n"); + return(NULL); + } + str++; + port = strtoul(str, &end, 0); + if(*end != '\0'){ + printk("port_init : couldn't parse port '%s'\n", str); + return(NULL); + } + + if((kern_data = port_data(port)) == NULL) return(NULL); + + if((data = um_kmalloc(sizeof(*data))) == NULL) return(NULL); + *data = ((struct port_chan) { fd : -1, + raw : opts->raw, + kernel_data : kern_data }); + + return(data); +} + +int port_open(int input, int output, void *d) +{ + struct port_chan *data = d; + int fd; + + fd = port_wait(data->kernel_data); + if((fd >= 0) && data->raw){ + tcgetattr(fd, &data->tt); + raw(fd, 0); + } + data->fd = fd; + return(fd); +} + +void port_close(int fd, void *d) +{ + struct port_chan *data = d; + + close(data->fd); +} + +int port_console_write(int fd, const char *buf, int n, void *d) +{ + struct port_chan *data = d; + + return(generic_console_write(fd, buf, n, &data->tt)); +} + +void port_free(void *d) +{ + struct port_chan *data = d; + + port_kern_free(data->kernel_data); + kfree(data); +} + +struct chan_ops port_ops = { + init: port_init, + open: port_open, + close: port_close, + read: generic_read, + write: generic_write, + console_write: port_console_write, + window_size: generic_window_size, + free: port_free, +}; + +int port_listen_fd(int port) +{ + struct sockaddr_in addr; + int fd; + + fd = socket(PF_INET, SOCK_STREAM, 0); + if(fd == -1) return(-errno); + + addr.sin_family = AF_INET; + addr.sin_port = htons(port); + addr.sin_addr.s_addr = htonl(INADDR_ANY); + if(bind(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) + return(-errno); + + if(listen(fd, 1) < 0) return(-errno); + + return(fd); +} + +struct port_connect_data { + int sock_fd; + int pipe_fds[2]; + int err; +}; + +void port_connect_tramp(void *d) +{ + struct port_connect_data *data = d; + + data->err = 0; + if(fork() == 0){ + dup2(data->sock_fd, 0); + dup2(data->sock_fd, 1); + dup2(data->sock_fd, 2); + close(data->sock_fd); + dup2(data->pipe_fds[1], 3); + close(data->pipe_fds[1]); + execlp("/usr/sbin/in.telnetd", "in.telnetd", "-L", + "/usr/lib/uml/port-helper", NULL); + shutdown(3, SHUT_RDWR); + shutdown(data->pipe_fds[0], SHUT_RDWR); + data->err = errno; + exit(1); + } +} + +static int rcv_fd(int fd, struct port_connect_data *data) +{ + int new, n; + char buf[CMSG_SPACE(sizeof(new))]; + struct msghdr msg; + struct cmsghdr *cmsg; + + msg.msg_name = NULL; + msg.msg_namelen = 0; + msg.msg_iov = NULL; + msg.msg_iovlen = 0; + msg.msg_control = buf; + msg.msg_controllen = sizeof(buf); + msg.msg_flags = 0; + + n = recvmsg(fd, &msg, 0); + if(n < 0){ + printk("rcv_fd : recvmsg failed - errno = %d\n", errno); + return(-1); + } + + cmsg = CMSG_FIRSTHDR(&msg); + if(cmsg == NULL){ + printk("rcv_fd didn't receive anything, error = %d\n", + data->err); + return(-1); + } + if((cmsg->cmsg_level != SOL_SOCKET) || + (cmsg->cmsg_type != SCM_RIGHTS)){ + printk("rcv_fd didn't receive a descriptor\n"); + return(-1); + } + + new = ((int *) CMSG_DATA(cmsg))[0]; + return(new); +} + +int port_connection(int fd) +{ + int new, fds[2]; + struct port_connect_data data; + + if((new = accept(fd, NULL, 0)) < 0) return(-errno); + + if(socketpair(PF_UNIX, SOCK_DGRAM, 0, fds) < 0) return(-errno); + + data = ((struct port_connect_data) + { sock_fd : new, + pipe_fds : { fds[0], fds[1] } }); + + tracing_cb(port_connect_tramp, &data); + return(rcv_fd(fds[0], &data)); +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/drivers/port.h linux_umopenmosix/arch/um/drivers/port.h --- linux-2.4.17/arch/um/drivers/port.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/drivers/port.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2001 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#ifndef __PORT_H__ +#define __PORT_H__ + +extern void *port_data(int port); +extern int port_wait(void *data); +extern void port_kern_close(void *d); +extern int port_connection(int fd); +extern int port_listen_fd(int port); +extern void port_read(int fd, void *data); +extern void port_kern_free(void *d); + +#endif + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/drivers/port_kern.c linux_umopenmosix/arch/um/drivers/port_kern.c --- linux-2.4.17/arch/um/drivers/port_kern.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/drivers/port_kern.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,149 @@ +/* + * Copyright (C) 2001 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include "linux/list.h" +#include "linux/slab.h" +#include "linux/irq.h" +#include "linux/spinlock.h" +#include "linux/errno.h" +#include "asm/semaphore.h" +#include "asm/errno.h" +#include "kern_util.h" +#include "kern.h" +#include "irq_user.h" +#include "port.h" + +struct port_list { + struct list_head list; + struct semaphore sem; + int port; + int fd; + spinlock_t lock; + struct list_head connections; +}; + +struct port_dev { + struct port_list *port; + int fd; +}; + +struct connection { + struct list_head list; + int fd; +}; + +struct list_head ports = LIST_HEAD_INIT(ports); + +static void port_interrupt(int irq, void *data, struct pt_regs *regs) +{ + struct port_list *port = data; + struct connection *conn; + int fd; + + reactivate_fd(port->fd); + fd = port_connection(port->fd); + if(fd < 0){ + printk("port_connection returned %d\n", -fd); + return; + } + conn = kmalloc(sizeof(*conn), GFP_ATOMIC); + if(conn == NULL){ + printk("port_interrupt : failed to allocate connection\n"); + close(fd); + return; + } + *conn = ((struct connection) + { list : LIST_HEAD_INIT(conn->list), + fd : fd }); + list_add(&conn->list, &port->connections); + up(&port->sem); +} + +void *port_data(int port_num) +{ + struct list_head *ele; + struct port_list *port; + struct port_dev *dev; + int fd; + + list_for_each(ele, &ports){ + port = list_entry(ele, struct port_list, list); + if(port->port == port_num) goto found; + } + port = kmalloc(sizeof(struct port_list), GFP_KERNEL); + if(port == NULL){ + printk(KERN_ERR "Allocation of port list failed\n"); + return(NULL); + } + + fd = port_listen_fd(port_num); + if(fd < 0){ + printk(KERN_ERR "binding to port %d failed, errno = %d\n", + port_num, -fd); + return(NULL); + } + if(um_request_irq(ACCEPT_IRQ, fd, port_interrupt, + SA_INTERRUPT | SA_SHIRQ, "port", port)){ + printk(KERN_ERR "Failed to get IRQ for port %d\n", port_num); + return(NULL); + } + + *port = ((struct port_list) + { list : LIST_HEAD_INIT(port->list), + sem : __SEMAPHORE_INITIALIZER(port->sem, 0), + lock : SPIN_LOCK_UNLOCKED, + port : port_num, + fd : fd, + connections : LIST_HEAD_INIT(port->connections) }); + list_add(&port->list, &ports); + + found: + dev = kmalloc(sizeof(struct port_dev), GFP_KERNEL); + if(dev == NULL){ + printk(KERN_ERR "Allocation of port device entry failed\n"); + return(NULL); + } + + *dev = ((struct port_dev) + { port : port, + fd : -1 }); + return(dev); +} + +int port_wait(void *data) +{ + struct port_dev *dev = data; + struct connection *conn; + + if(down_interruptible(&dev->port->sem)) return(-ERESTARTSYS); + spin_lock(&dev->port->lock); + conn = list_entry(dev->port->connections.next, struct connection, + list); + list_del(&conn->list); + spin_unlock(&dev->port->lock); + + dev->fd = conn->fd; + kfree(conn); + + return(dev->fd); +} + +void port_kern_free(void *d) +{ + struct port_dev *dev = d; + + kfree(dev); +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/drivers/pty.c linux_umopenmosix/arch/um/drivers/pty.c --- linux-2.4.17/arch/um/drivers/pty.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/drivers/pty.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2001 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include +#include +#include +#include "chan_user.h" +#include "user.h" +#include "user_util.h" + +struct pty_chan { + void (*announce)(char *dev_name, int dev); + int dev; + int raw; + struct termios tt; +}; + +void *pty_chan_init(char *str, int device, struct chan_opts *opts) +{ + struct pty_chan *data; + + if((data = um_kmalloc(sizeof(*data))) == NULL) return(NULL); + *data = ((struct pty_chan) { announce : opts->announce, + dev : device, + raw : opts->raw }); + return(data); +} + +int pts_open(int input, int output, void *d) +{ + struct pty_chan *data = d; + int fd; + + if((fd = get_pty()) < 0){ + printk("open_pts : Failed to open pts\n"); + return(-errno); + } + if(data->raw){ + tcgetattr(fd, &data->tt); + raw(fd, 0); + } + if(data->announce) (*data->announce)(ptsname(fd), data->dev); + return(fd); +} + +int pty_open(int input, int output, void *d) +{ + struct pty_chan *data = d; + int fd; + char dev[sizeof("/dev/ptyxx\0")] = "/dev/ptyxx"; + + fd = getmaster(dev); + if(fd < 0) return(-errno); + if(data->raw) raw(fd, 0); + if(data->announce) (*data->announce)(dev, data->dev); + return(fd); +} + +int pty_console_write(int fd, const char *buf, int n, void *d) +{ + struct pty_chan *data = d; + + return(generic_console_write(fd, buf, n, &data->tt)); +} + +struct chan_ops pty_ops = { + init: pty_chan_init, + open: pty_open, + close: generic_close, + read: generic_read, + write: generic_write, + console_write: pty_console_write, + window_size: generic_window_size, + free: generic_free, +}; + +struct chan_ops pts_ops = { + init: pty_chan_init, + open: pts_open, + close: generic_close, + read: generic_read, + write: generic_write, + console_write: pty_console_write, + window_size: generic_window_size, + free: generic_free, +}; + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/drivers/slip.h linux_umopenmosix/arch/um/drivers/slip.h --- linux-2.4.17/arch/um/drivers/slip.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/drivers/slip.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,34 @@ +#ifndef __UM_SLIP_H +#define __UM_SLIP_H + +#define BUF_SIZE 1500 + +struct slip_data { + void *dev; + char name[sizeof("slnnnnn\0")]; + char *addr; + char *gate_addr; + int slave; + char buf[2 * BUF_SIZE]; + int pos; + int esc; +}; + +extern struct net_user_info slip_user_info; + +extern int set_umn_addr(int fd, char *addr, char *ptp_addr); +extern int slip_user_read(int fd, void *buf, int len, struct slip_data *pri); +extern int slip_user_write(int fd, void *buf, int len, struct slip_data *pri); + +#endif + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/drivers/slip_kern.c linux_umopenmosix/arch/um/drivers/slip_kern.c --- linux-2.4.17/arch/um/drivers/slip_kern.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/drivers/slip_kern.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,106 @@ +#include "linux/kernel.h" +#include "linux/stddef.h" +#include "linux/init.h" +#include "linux/netdevice.h" +#include "linux/if_arp.h" +#include "net_kern.h" +#include "net_user.h" +#include "kern.h" +#include "slip.h" +#include "slip_kern.h" + +struct slip_data slip_priv[MAX_UML_NETDEV] = { + [ 0 ... MAX_UML_NETDEV - 1 ] = + { + addr: NULL, + gate_addr: NULL, + slave: -1, + buf: { 0 }, + pos: 0, + esc: 0, + } +}; + +struct net_device umn_dev; + +struct net_device *slip_init(int private_size, int index) +{ + struct uml_net_private *private; + struct slip_data *spri; + + private = kmalloc(private_size, GFP_KERNEL); + if(private == NULL) return(NULL); + umn_dev.priv = private; + spri = (struct slip_data *) private->user; + *spri = slip_priv[index]; + strncpy(umn_dev.name, "umn", IFNAMSIZ); + umn_dev.init = NULL; + umn_dev.hard_header_len = 0; + umn_dev.addr_len = 4; + umn_dev.type = ARPHRD_ETHER; + umn_dev.tx_queue_len = 256; + umn_dev.flags = IFF_NOARP; + if(register_netdev(&umn_dev)) + printk(KERN_ERR "Couldn't initialize umn\n"); + printk("SLIP backend - SLIP IP = %s\n", spri->gate_addr); + + return(&umn_dev); +} + +static int slip_set_mac(struct sockaddr *hwaddr, void *data) +{ + return(0); +} + +static unsigned short slip_protocol(struct sk_buff *skbuff) +{ + return(htons(ETH_P_IP)); +} + +static int slip_read(int fd, struct sk_buff **skb, + struct uml_net_private *lp) +{ + return(slip_user_read(fd, (*skb)->mac.raw, (*skb)->dev->mtu, + (struct slip_data *) &lp->user)); +} + +static int slip_write(int fd, struct sk_buff **skb, + struct uml_net_private *lp) +{ + return(slip_user_write(fd, (*skb)->data, (*skb)->len, + (struct slip_data *) &lp->user)); +} + +struct net_kern_info slip_kern_info = { + init: slip_init, + protocol: slip_protocol, + set_mac: slip_set_mac, + read: slip_read, + write: slip_write, +}; + +static int slip_count = 0; + +void slip_setup(char *str, struct uml_net *dev) +{ + int n = slip_count; + + dev->user = &slip_user_info; + dev->kern = &slip_kern_info; + dev->private_size = sizeof(struct slip_data); + dev->transport_index = slip_count++; + if(*str != ',') return; + str++; + if(str[0] != '\0') slip_priv[n].gate_addr = str; +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/drivers/slip_kern.h linux_umopenmosix/arch/um/drivers/slip_kern.h --- linux-2.4.17/arch/um/drivers/slip_kern.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/drivers/slip_kern.h Sun Jun 23 13:07:34 2002 @@ -0,0 +1,8 @@ +#ifndef __UM_SLIP_KERN_H +#define __UM_SLIP_KERN_H + +#include "net_kern.h" + +extern void slip_setup(char *arg, struct uml_net *dev); + +#endif diff -urN linux-2.4.17/arch/um/drivers/slip_user.c linux_umopenmosix/arch/um/drivers/slip_user.c --- linux-2.4.17/arch/um/drivers/slip_user.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/drivers/slip_user.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,323 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "user_util.h" +#include "kern_util.h" +#include "user.h" +#include "net_user.h" +#include "slip.h" + +void slip_user_init(void *data, void *dev) +{ + struct slip_data *pri = data; + + pri->dev = dev; +} + +static int set_up_tty(int fd) +{ + int i; + struct termios tios; + + if (tcgetattr(fd, &tios) < 0) { + printk("could not get initial terminal attributes\n"); + return(-1); + } + + tios.c_cflag = CS8 | CREAD | HUPCL | CLOCAL; + tios.c_iflag = IGNBRK | IGNPAR; + tios.c_oflag = 0; + tios.c_lflag = 0; + for (i = 0; i < NCCS; i++) + tios.c_cc[i] = 0; + tios.c_cc[VMIN] = 1; + tios.c_cc[VTIME] = 0; + + cfsetospeed(&tios, B38400); + cfsetispeed(&tios, B38400); + + if (tcsetattr(fd, TCSAFLUSH, &tios) < 0) { + printk("failed to set terminal attributes\n"); + return(-1); + } + return(0); +} + +struct slip_tramp_data { + int fd; + char **args; + int err; + char *output; +}; + +void slip_tramp(void *arg) +{ + struct slip_tramp_data *data = arg; + char **argv = data->args; + int status, pid, fds[2]; + + data->err = 0; + data->output = NULL; + if(pipe(fds) != 0){ + perror("slip_tramp : pipe failed"); + data->err = EINVAL; + return; + } + if((pid = fork()) == 0){ + if(data->fd != -1) dup2(data->fd, 0); + dup2(fds[1], 1); + close(fds[0]); + execvp(argv[0], argv); + exit(errno); + } + else if(pid < 0) data->err = errno; + else { + close(fds[1]); + read_output(fds[0], &data->output); + if(waitpid(pid, &status, 0) < 0) data->err = errno; + else if(!WIFEXITED(status) || (WEXITSTATUS(status) != 0)){ + printk("'%s' didn't exit with status 0\n", argv[0]); + data->err = EINVAL; + } + } +} + +static int slip_open(void *data) +{ + struct slip_data *pri = data; + struct slip_tramp_data slip_data; + char version_buf[sizeof("nnnnn\0")]; + char gate_buf[sizeof("nnn.nnn.nnn.nnn\0")]; + char *argv[] = { "uml_net", version_buf, "slip", "up", gate_buf, + NULL }; + int sfd, mfd, disc, sencap; + + if((mfd = get_pty()) < 0){ + printk("umn : Failed to open pty\n"); + return(-1); + } + if((sfd = open(ptsname(mfd), O_RDWR)) < 0){ + printk("Couldn't open tty for slip line\n"); + return(-1); + } + if(set_up_tty(sfd)) return(-1); + pri->slave = sfd; + pri->pos = 0; + pri->esc = 0; + if(pri->gate_addr != NULL){ + sprintf(version_buf, "%d", UML_NET_VERSION); + slip_data.fd = sfd; + strcpy(gate_buf, pri->gate_addr); + slip_data.args = argv; + tracing_cb(slip_tramp, &slip_data); + if(slip_data.output != NULL){ + printk("%s", slip_data.output); + kfree(slip_data.output); + } + if(slip_data.err != 0){ + printk("slip_tramp failed - errno = %d\n", + slip_data.err); + return(-slip_data.err); + } + if(ioctl(pri->slave, SIOCGIFNAME, pri->name) < 0){ + printk("SIOCGIFNAME failed, errno = %d\n", errno); + return(-errno); + } + iter_addresses(pri->dev, open_addr, pri->name); + } + else { + disc = N_SLIP; + if(ioctl(sfd, TIOCSETD, &disc) < 0){ + printk("Failed to set slip line discipline - " + "errno = %d\n", errno); + return(-errno); + } + sencap = 0; + if(ioctl(sfd, SIOCSIFENCAP, &sencap) < 0){ + printk("Failed to sett slip encapsulation - " + "errno = %d\n", errno); + return(-errno); + } + } + return(mfd); +} + +static void slip_close(int fd, void *data) +{ + struct slip_data *pri = data; + struct slip_tramp_data slip_data; + char version_buf[sizeof("nnnnn\0")]; + char *argv[] = { "uml_net", version_buf, "slip", "down", pri->name, + NULL }; + + if(pri->gate_addr != NULL) + iter_addresses(pri->dev, close_addr, pri->name); + + sprintf(version_buf, "%d", UML_NET_VERSION); + slip_data.fd = -1; + slip_data.args = argv; + tracing_cb(slip_tramp, &slip_data); + if(slip_data.output != NULL){ + printk("%s", slip_data.output); + kfree(slip_data.output); + } + if(slip_data.err != 0) + printk("slip_tramp failed - errno = %d\n", slip_data.err); + close(fd); + close(pri->slave); + pri->slave = -1; +} + +/* SLIP protocol characters. */ +#define END 0300 /* indicates end of frame */ +#define ESC 0333 /* indicates byte stuffing */ +#define ESC_END 0334 /* ESC ESC_END means END 'data' */ +#define ESC_ESC 0335 /* ESC ESC_ESC means ESC 'data' */ + +static int slip_unesc(struct slip_data *sl, unsigned char c) +{ + int ret; + + switch(c){ + case END: + sl->esc = 0; + ret = sl->pos; + sl->pos = 0; + return(ret); + case ESC: + sl->esc = 1; + return(0); + case ESC_ESC: + if(sl->esc){ + sl->esc = 0; + c = ESC; + } + break; + case ESC_END: + if(sl->esc){ + sl->esc = 0; + c = END; + } + break; + } + sl->buf[sl->pos++] = c; + return(0); +} + +int slip_user_read(int fd, void *buf, int len, struct slip_data *pri) +{ + int i, n, size, start; + + n = net_read(fd, &pri->buf[pri->pos], sizeof(pri->buf) - pri->pos); + if(n <= 0) return(n); + + start = pri->pos; + for(i = 0; i < n; i++){ + size = slip_unesc(pri, pri->buf[start + i]); + if(size){ + memcpy(buf, pri->buf, size); + return(size); + } + } + return(0); +} + +static int slip_esc(unsigned char *s, unsigned char *d, int len) +{ + unsigned char *ptr = d; + unsigned char c; + + /* + * Send an initial END character to flush out any + * data that may have accumulated in the receiver + * due to line noise. + */ + + *ptr++ = END; + + /* + * For each byte in the packet, send the appropriate + * character sequence, according to the SLIP protocol. + */ + + while (len-- > 0) { + switch(c = *s++) { + case END: + *ptr++ = ESC; + *ptr++ = ESC_END; + break; + case ESC: + *ptr++ = ESC; + *ptr++ = ESC_ESC; + break; + default: + *ptr++ = c; + break; + } + } + *ptr++ = END; + return (ptr - d); +} + +int slip_user_write(int fd, void *buf, int len, struct slip_data *pri) +{ + int actual, n; + + actual = slip_esc(buf, pri->buf, len); + n = net_write(fd, pri->buf, actual); + if(n < 0) return(n); + else return(len); +} + +static int slip_set_mtu(int mtu, void *data) +{ + return(mtu); +} + +static void slip_add_addr(unsigned char *addr, unsigned char *netmask, + void *data) +{ + struct slip_data *pri = data; + + if(pri->slave == -1) return; + open_addr(addr, netmask, pri->name); +} + +static void slip_del_addr(unsigned char *addr, unsigned char *netmask, + void *data) +{ + struct slip_data *pri = data; + + if(pri->slave == -1) return; + close_addr(addr, netmask, pri->name); +} + +struct net_user_info slip_user_info = { + init: slip_user_init, + open: slip_open, + close: slip_close, + set_mtu: slip_set_mtu, + add_address: slip_add_addr, + delete_address: slip_del_addr, + max_packet: BUF_SIZE +}; + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/drivers/ssl.c linux_umopenmosix/arch/um/drivers/ssl.c --- linux-2.4.17/arch/um/drivers/ssl.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/drivers/ssl.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,261 @@ +/* + * Copyright (C) 2000 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include "linux/config.h" +#include "linux/fs.h" +#include "linux/tty.h" +#include "linux/tty_driver.h" +#include "linux/major.h" +#include "linux/mm.h" +#include "linux/init.h" +#include "linux/devfs_fs_kernel.h" +#include "asm/termbits.h" +#include "asm/irq.h" +#include "line.h" +#include "ssl.h" +#include "chan_kern.h" +#include "user_util.h" +#include "kern_util.h" +#include "kern.h" +#include "init.h" +#include "2_5compat.h" + +static int ssl_version = 1; + +static struct tty_driver ssl_driver; + +static int ssl_refcount = 0; + +#define NR_PORTS 64 + +static struct tty_struct *ssl_table[NR_PORTS]; +static struct termios *ssl_termios[NR_PORTS]; +static struct termios *ssl_termios_locked[NR_PORTS]; + +void ssl_announce(char *dev_name, int dev) +{ + printk(KERN_INFO "Serial line %d assigned device '%s'\n", dev, + dev_name); +} + +static struct chan_opts opts = { + announce: ssl_announce, + xterm_title: "Serial Line #%d", + raw: 1, +}; + +static struct line serial_lines[NR_PORTS] = + { [0 ... NR_PORTS - 1] = LINE_INIT(CONFIG_SSL_CHAN) }; + +static int setup_ssl_irq(int fd, int input, int output, void *data) +{ + return(um_request_irq(SSL_IRQ, fd, line_interrupt, + SA_INTERRUPT | SA_SHIRQ, "ssl", data)); +} + +int ssl_open(struct tty_struct *tty, struct file *filp) +{ + int line; + + line = minor(tty->device) - tty->driver.minor_start; + if ((line < 0) || (line >= NR_PORTS)) + return -ENODEV; + return(line_open(serial_lines, line, tty, setup_ssl_irq, &opts)); +} + +static void ssl_close(struct tty_struct *tty, struct file * filp) +{ + line_close(serial_lines, minor(tty->device) - tty->driver.minor_start); +} + +static int ssl_write(struct tty_struct * tty, int from_user, + const unsigned char *buf, int count) +{ + int line; + + line = minor(tty->device) - tty->driver.minor_start; + if ((line < 0) || (line >= NR_PORTS)) + panic("Bad tty in ssl_put_char"); + return(write_chan(&serial_lines[line].chan_list, buf, count)); +} + +static void ssl_put_char(struct tty_struct *tty, unsigned char ch) +{ + int line; + + line = minor(tty->device) - tty->driver.minor_start; + if ((line < 0) || (line >= NR_PORTS)) + panic("Bad tty in ssl_put_char"); + write_chan(&serial_lines[line].chan_list, &ch, sizeof(ch)); +} + +static void ssl_flush_chars(struct tty_struct *tty) +{ + return; +} + +static int ssl_write_room(struct tty_struct *tty) +{ + return(16384); +} + +static int ssl_chars_in_buffer(struct tty_struct *tty) +{ + return(0); +} + +static void ssl_flush_buffer(struct tty_struct *tty) +{ + return; +} + +static int ssl_ioctl(struct tty_struct *tty, struct file * file, + unsigned int cmd, unsigned long arg) +{ + int ret; + + ret = 0; + switch(cmd){ + case TCGETS: + case TCSETS: + case TCFLSH: + case TCSETSF: + case TCSETSW: + case TCGETA: + ret = -ENOIOCTLCMD; + break; + default: + printk(KERN_ERR + "Unimplemented ioctl in ssl_ioctl : 0x%x\n", cmd); + ret = -ENOIOCTLCMD; + break; + } + return(ret); +} + +static void ssl_throttle(struct tty_struct * tty) +{ + printk(KERN_ERR "Someone should implement ssl_throttle\n"); +} + +static void ssl_unthrottle(struct tty_struct * tty) +{ + printk(KERN_ERR "Someone should implement ssl_unthrottle\n"); +} + +static void ssl_set_termios(struct tty_struct *tty, + struct termios *old_termios) +{ +} + +static void ssl_stop(struct tty_struct *tty) +{ + printk(KERN_ERR "Someone should implement ssl_stop\n"); +} + +static void ssl_start(struct tty_struct *tty) +{ + printk(KERN_ERR "Someone should implement ssl_start\n"); +} + +void ssl_hangup(struct tty_struct *tty) +{ +} + +static struct winch_lines winch = { + list : LIST_HEAD_INIT(winch.list), + lines : serial_lines, + nlines : sizeof(serial_lines)/sizeof(serial_lines[0]) +}; + +int ssl_init(void) +{ + int i, err; + + printk(KERN_INFO "Initializing software serial port version %d\n", + ssl_version); + + /* Initialize the tty_driver structure */ + + memset(&ssl_driver, 0, sizeof(struct tty_driver)); + ssl_driver.magic = TTY_DRIVER_MAGIC; + ssl_driver.name = "tts/%d"; + ssl_driver.major = TTYAUX_MAJOR; + ssl_driver.minor_start = 64; + ssl_driver.num = NR_PORTS; + ssl_driver.type = TTY_DRIVER_TYPE_SERIAL; + ssl_driver.subtype = 0; + ssl_driver.init_termios = tty_std_termios; + ssl_driver.init_termios.c_cflag = + B9600 | CS8 | CREAD | HUPCL | CLOCAL; + ssl_driver.flags = TTY_DRIVER_REAL_RAW; + ssl_driver.refcount = &ssl_refcount; + ssl_driver.table = ssl_table; + ssl_driver.termios = ssl_termios; + ssl_driver.termios_locked = ssl_termios_locked; + + ssl_driver.open = ssl_open; + ssl_driver.close = ssl_close; + ssl_driver.write = ssl_write; + ssl_driver.put_char = ssl_put_char; + ssl_driver.flush_chars = ssl_flush_chars; + ssl_driver.write_room = ssl_write_room; + ssl_driver.chars_in_buffer = ssl_chars_in_buffer; + ssl_driver.flush_buffer = ssl_flush_buffer; + ssl_driver.ioctl = ssl_ioctl; + ssl_driver.throttle = ssl_throttle; + ssl_driver.unthrottle = ssl_unthrottle; + ssl_driver.set_termios = ssl_set_termios; + ssl_driver.stop = ssl_stop; + ssl_driver.start = ssl_start; + ssl_driver.hangup = ssl_hangup; + if (tty_register_driver(&ssl_driver)) + panic("Couldn't register ssl driver\n"); + + err = devfs_mk_symlink(NULL, "serial", 0, "tts", NULL, NULL); + if(err) printk("Symlink creation from /dev/serial to /dev/tts " + "returned %d\n", err); + for(i = 0; i < sizeof(serial_lines)/sizeof(serial_lines[0]); i++){ + INIT_LIST_HEAD(&serial_lines[i].chan_list); + sema_init(&serial_lines[i].sem, 1); + } + + register_winch(&winch); + return(0); +} + +__initcall(ssl_init); + +static int ssl_chan_setup(char *str) +{ + line_setup(serial_lines, sizeof(serial_lines)/sizeof(serial_lines[0]), + str); + return(1); +} + +__setup("ssl", ssl_chan_setup); +__channel_help(ssl_chan_setup, "ssl"); + +static void ssl_exit(void) +{ + int i; + + for(i=0;idevice) - tty->driver.minor_start; + ret = open_console(line, tty); + chan_window_size(&vts[line].chan_list, &tty->winsize.ws_row, + &tty->winsize.ws_col); + return(ret); +} + +static void con_close(struct tty_struct * tty, struct file * filp) +{ + line_close(vts, minor(tty->device) - tty->driver.minor_start); +} + +static int con_write(struct tty_struct * tty, int from_user, + const unsigned char *buf, int count) +{ + int line; + + if(in_interrupt() && tty->stopped) return 0; + while(tty->stopped) schedule(); + + line = minor(tty->device) - tty->driver.minor_start; + return(write_chan(&vts[line].chan_list, buf, count)); +} + +static int write_room(struct tty_struct *tty) +{ + return(1024); +} + +static void set_termios(struct tty_struct *tty, struct termios * old) +{ +} + +static int chars_in_buffer(struct tty_struct *tty) +{ + return(0); +} + +static struct winch_lines winch = { + list : LIST_HEAD_INIT(winch.list), + lines : vts, + nlines : sizeof(vts)/sizeof(vts[0]) +}; + +int stdio_init(void) +{ + int i, err; + + printk(KERN_INFO "Initializing stdio console driver\n"); + memset(&console_driver, 0, sizeof(struct tty_driver)); + console_driver.magic = TTY_DRIVER_MAGIC; + console_driver.driver_name = "stdio console"; + console_driver.name = "vc/%d"; + console_driver.major = TTY_MAJOR; + console_driver.minor_start = 0; + console_driver.num = 8; + console_driver.type = TTY_DRIVER_TYPE_CONSOLE; + console_driver.subtype = SYSTEM_TYPE_CONSOLE; + console_driver.init_termios = tty_std_termios; + console_driver.flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_NO_DEVFS; + console_driver.refcount = &console_refcount; + console_driver.table = console_table; + console_driver.termios = console_termios; + console_driver.termios_locked = console_termios_locked; + + console_driver.open = con_open; + console_driver.close = con_close; + console_driver.write = con_write; + console_driver.put_char = NULL; + console_driver.flush_chars = NULL; + console_driver.write_room = write_room; + console_driver.chars_in_buffer = chars_in_buffer; + console_driver.flush_buffer = NULL; + console_driver.ioctl = NULL; + console_driver.throttle = NULL; + console_driver.unthrottle = NULL; + console_driver.send_xchar = NULL; + console_driver.set_termios = set_termios; + console_driver.stop = NULL; + console_driver.start = NULL; + console_driver.hangup = NULL; + console_driver.break_ctl = NULL; + console_driver.wait_until_sent = NULL; + console_driver.read_proc = NULL; + if (tty_register_driver(&console_driver)) + panic("Couldn't register console driver\n"); + + err = devfs_mk_symlink(NULL, "ttys", 0, "vc", NULL, NULL); + if(err) printk("Symlink creation from /dev/ttys to /dev/vc " + "returned %d\n", err); + for(i=0;iindex].chan_list, string, len); +} + +static kdev_t console_device(struct console *c) +{ + return mk_kdev(TTY_MAJOR, c->index); +} + +static int console_setup(struct console *co, char *options) +{ + return(0); +} + +static struct console stdiocons = INIT_CONSOLE("tty", console_write, + console_device, console_setup, + CON_PRINTBUFFER); + +void stdio_console_init(void) +{ + INIT_LIST_HEAD(&vts[0].chan_list); + list_add(&init_console_chan.list, &vts[0].chan_list); + register_console(&stdiocons); +} + +static int console_chan_setup(char *str) +{ + line_setup(vts, sizeof(vts)/sizeof(vts[0]), str); + return(1); +} + +__setup("con", console_chan_setup); +__channel_help(console_chan_setup, "con"); + +static void console_exit(void) +{ + int i; + + line_close(vts, 0); + for(i=0;i +#include +#include +#include +#include +#include "chan_user.h" +#include "user_util.h" +#include "user.h" + +struct tty_chan { + char *dev; + int raw; + struct termios tt; +}; + +void *tty_chan_init(char *str, int device, struct chan_opts *opts) +{ + struct tty_chan *data; + + if(*str != ':'){ + printk("tty_init : channel type 'tty' must specify " + "a device\n"); + return(NULL); + } + str++; + + if((data = um_kmalloc(sizeof(*data))) == NULL) return(NULL); + *data = ((struct tty_chan) { dev : str, + raw : opts->raw }); + + return(data); +} + +int tty_open(int input, int output, void *d) +{ + struct tty_chan *data = d; + int fd, mode; + + if(input && output) mode = O_RDWR; + else if(input) mode = O_RDONLY; + else mode = O_WRONLY; + + fd = open(data->dev, mode); + if(fd < 0) return(-errno); + if(data->raw){ + tcgetattr(fd, &data->tt); + raw(fd, 0); + } + return(fd); +} + +int tty_console_write(int fd, const char *buf, int n, void *d) +{ + struct tty_chan *data = d; + + return(generic_console_write(fd, buf, n, &data->tt)); +} + +struct chan_ops tty_ops = { + init: tty_chan_init, + open: tty_open, + close: generic_close, + read: generic_read, + write: generic_write, + console_write: tty_console_write, + window_size: generic_window_size, + free: generic_free, +}; + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/drivers/tuntap.h linux_umopenmosix/arch/um/drivers/tuntap.h --- linux-2.4.17/arch/um/drivers/tuntap.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/drivers/tuntap.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#ifndef __UM_TUNTAP_H +#define __UM_TUNTAP_H + +#include "net_user.h" + +struct tuntap_data { + char *dev_name; + int fixed_config; + char *gate_addr; + int fd; + void *dev; + unsigned char hw_addr[ETH_ADDR_LEN]; + int hw_setup; +}; + +extern struct net_user_info tuntap_user_info; + +#endif + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/drivers/tuntap_kern.c linux_umopenmosix/arch/um/drivers/tuntap_kern.c --- linux-2.4.17/arch/um/drivers/tuntap_kern.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/drivers/tuntap_kern.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,123 @@ +/* + * Copyright (C) 2001 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include "linux/stddef.h" +#include "linux/netdevice.h" +#include "linux/etherdevice.h" +#include "linux/skbuff.h" +#include "asm/errno.h" +#include "net_kern.h" +#include "net_user.h" +#include "tuntap.h" + +struct tuntap_setup { + char *dev_name; + unsigned char hw_addr[ETH_ALEN]; + int hw_setup; + char *gate_addr; +}; + +struct tuntap_setup tuntap_priv[MAX_UML_NETDEV] = { + [ 0 ... MAX_UML_NETDEV - 1 ] = + { + dev_name: NULL, + hw_addr: { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }, + hw_setup: 0, + gate_addr: NULL, + } +}; + +struct net_device *tuntap_init(int private_size, int index) +{ + struct net_device *dev; + struct uml_net_private *pri; + struct tuntap_data *tpri; + + dev = init_etherdev(NULL, private_size); + if(dev == NULL) return(NULL); + pri = dev->priv; + tpri = (struct tuntap_data *) pri->user; + tpri->dev_name = tuntap_priv[index].dev_name; + tpri->fixed_config = (tpri->dev_name != NULL); + tpri->gate_addr = tuntap_priv[index].gate_addr; + memcpy(dev->dev_addr, tuntap_priv[index].hw_addr, ETH_ALEN); + memcpy(tpri->hw_addr, tuntap_priv[index].hw_addr, + sizeof(tpri->hw_addr)); + printk("TUN/TAP backend - "); + if(tpri->gate_addr != NULL) + printk("IP = %s", tpri->gate_addr); + tpri->hw_setup = tuntap_priv[index].hw_setup; + if(tpri->hw_setup) + printk(" ether = %x:%x:%x:%x:%x:%x", + tpri->hw_addr[0], tpri->hw_addr[1], tpri->hw_addr[2], + tpri->hw_addr[3], tpri->hw_addr[4], tpri->hw_addr[5]); + printk("\n"); + tpri->fd = -1; + return(dev); +} + +static unsigned short tuntap_protocol(struct sk_buff *skb) +{ + return(eth_type_trans(skb, skb->dev)); +} + +static int tuntap_set_mac(struct sockaddr *addr, void *data) +{ + struct tuntap_data *pri = data; + struct sockaddr *hwaddr = addr; + + memcpy(pri->hw_addr, hwaddr->sa_data, ETH_ALEN); + + return 0; +} + +static int tuntap_read(int fd, struct sk_buff **skb, + struct uml_net_private *lp) +{ + *skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER); + if(*skb == NULL) return(-ENOMEM); + return(net_read(fd, (*skb)->mac.raw, + (*skb)->dev->mtu + ETH_HEADER_OTHER)); +} + +static int tuntap_write(int fd, struct sk_buff **skb, + struct uml_net_private *lp) +{ + return(net_write(fd, (*skb)->data, (*skb)->len)); +} + +struct net_kern_info tuntap_kern_info = { + init: tuntap_init, + protocol: tuntap_protocol, + set_mac: tuntap_set_mac, + read: tuntap_read, + write: tuntap_write, +}; + +static int tuntap_count = 0; + +void tuntap_setup(char *str, struct uml_net *dev) +{ + struct tuntap_setup *pri; + + dev->user = &tuntap_user_info; + dev->kern = &tuntap_kern_info; + dev->private_size = sizeof(struct tuntap_data); + pri = &tuntap_priv[tuntap_count]; + dev->transport_index = tuntap_count++; + tap_setup_common(str, "tuntap", &pri->dev_name, pri->hw_addr, + &pri->hw_setup, &pri->gate_addr); +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/drivers/tuntap_kern.h linux_umopenmosix/arch/um/drivers/tuntap_kern.h --- linux-2.4.17/arch/um/drivers/tuntap_kern.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/drivers/tuntap_kern.h Sun Jun 23 13:07:44 2002 @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2001 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#ifndef __UM_TUNTAP_KERN_H +#define __UM_TUNTAP_KERN_H + +#include "net_kern.h" + +extern void tuntap_setup(char *arg, struct uml_net *dev); + +#endif + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/drivers/tuntap_user.c linux_umopenmosix/arch/um/drivers/tuntap_user.c --- linux-2.4.17/arch/um/drivers/tuntap_user.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/drivers/tuntap_user.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,222 @@ +/* + * Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "net_user.h" +#include "tuntap.h" +#include "kern_util.h" +#include "user.h" + +#define MAX_PACKET ETH_MAX_PACKET + +void tuntap_user_init(void *data, void *dev) +{ + struct tuntap_data *pri = data; + + pri->dev = dev; +} + +struct tuntap_open_data { + char *name; + char *gate; + int data_fd; + int remote; + int me; + int err; + char *buffer; + int len; + int used; +}; + +static void tuntap_open_tramp(void *arg) +{ + struct tuntap_open_data *data = arg; + char version_buf[sizeof("nnnnn\0")]; + char *args[] = { "uml_net", version_buf, "tuntap", "up", data->gate, + NULL }; + char buf[CMSG_SPACE(sizeof(data->data_fd))]; + struct msghdr msg; + struct cmsghdr *cmsg; + struct iovec iov; + int pid, n; + + sprintf(version_buf, "%d", UML_NET_VERSION); + data->err = 0; + if((pid = fork()) == 0){ + dup2(data->remote, 1); + close(data->me); + execvp(args[0], args); + printk("Exec of '%s' failed - errno = %d\n", args[0], errno); + exit(1); + } + else if(pid < 0) data->err = errno; + close(data->remote); + + msg.msg_name = NULL; + msg.msg_namelen = 0; + if(data->buffer != NULL){ + iov = ((struct iovec) { data->buffer, data->len }); + msg.msg_iov = &iov; + msg.msg_iovlen = 1; + } + else { + msg.msg_iov = NULL; + msg.msg_iovlen = 0; + } + msg.msg_control = buf; + msg.msg_controllen = sizeof(buf); + msg.msg_flags = 0; + n = recvmsg(data->me, &msg, 0); + data->used = n; + if(n < 0){ + printk("tuntap_open_tramp : recvmsg failed - errno = %d\n", + errno); + data->err = errno; + return; + } + waitpid(pid, NULL, 0); + + cmsg = CMSG_FIRSTHDR(&msg); + if(cmsg == NULL){ + printk("tuntap_open_tramp : didn't receive a message\n"); + data->err = EINVAL; + return; + } + if((cmsg->cmsg_level != SOL_SOCKET) || + (cmsg->cmsg_type != SCM_RIGHTS)){ + printk("tuntap_open_tramp : didn't receive a descriptor\n"); + data->err = EINVAL; + return; + } + data->data_fd = ((int *) CMSG_DATA(cmsg))[0]; +} + +static void tuntap_add_addr(unsigned char *addr, unsigned char *netmask, + void *data) +{ + struct tuntap_data *pri = data; + + if((pri->fd == -1) || pri->fixed_config) return; + open_addr(addr, netmask, pri->dev_name); +} + +static void tuntap_del_addr(unsigned char *addr, unsigned char *netmask, + void *data) +{ + struct tuntap_data *pri = data; + + if((pri->fd == -1) || pri->fixed_config) return; + close_addr(addr, netmask, pri->dev_name); +} + +static int tuntap_open(void *data) +{ + struct ifreq ifr; + struct tuntap_data *pri = data; + struct tuntap_open_data tap_data; + char *output; + int err, fds[2]; + + err = tap_open_common(pri->dev, pri->hw_setup, pri->gate_addr); + if(err) return(err); + + if(pri->fixed_config){ + if((pri->fd = open("/dev/net/tun", O_RDWR)) < 0){ + printk("Failed to open /dev/net/tun, errno = %d\n", + errno); + return(-errno); + } + memset(&ifr, 0, sizeof(ifr)); + ifr.ifr_flags = IFF_TAP; + strncpy(ifr.ifr_name, pri->dev_name, sizeof(ifr.ifr_name) - 1); + if(ioctl(pri->fd, TUNSETIFF, (void *) &ifr) < 0){ + printk("TUNSETIFF failed, errno = %d", errno); + close(pri->fd); + return(-errno); + } + } + else { + if(socketpair(PF_UNIX, SOCK_DGRAM, 0, fds) < 0){ + printk("data socketpair failed - errno = %d\n", errno); + return(-errno); + } + + tap_data.me = fds[0]; + tap_data.remote = fds[1]; + tap_data.data_fd = -1; + tap_data.gate = pri->gate_addr; + tap_data.buffer = get_output_buffer(&tap_data.len); + if(tap_data.buffer != NULL) tap_data.len--; + tap_data.used = 0; + + tracing_cb(tuntap_open_tramp, &tap_data); + output = tap_data.buffer; + if(tap_data.err == 0){ + pri->dev_name = uml_strdup(tap_data.buffer); + output += IFNAMSIZ; + printk(output); + free_output_buffer(tap_data.buffer); + } + else { + printk(output); + free_output_buffer(tap_data.buffer); + printk("tuntap_open_tramp failed - errno = %d\n", + tap_data.err); + return(-tap_data.err); + } + close(fds[0]); + pri->fd = tap_data.data_fd; + iter_addresses(pri->dev, open_addr, pri->dev_name); + } + + return(pri->fd); +} + +static void tuntap_close(int fd, void *data) +{ + struct tuntap_data *pri = data; + + if(!pri->fixed_config) + iter_addresses(pri->dev, close_addr, pri->dev_name); + close(fd); +} + +static int tuntap_set_mtu(int mtu, void *data) +{ + return(mtu); +} + +struct net_user_info tuntap_user_info = { + init: tuntap_user_init, + open: tuntap_open, + close: tuntap_close, + set_mtu: tuntap_set_mtu, + add_address: tuntap_add_addr, + delete_address: tuntap_del_addr, + max_packet: MAX_PACKET +}; + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/drivers/ubd.c linux_umopenmosix/arch/um/drivers/ubd.c --- linux-2.4.17/arch/um/drivers/ubd.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/drivers/ubd.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,824 @@ +/* + * Copyright (C) 2000 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include "ubd_user.h" +#define MAJOR_NR UBD_MAJOR +#include "linux/config.h" +#include "linux/blk.h" +#include "linux/blkdev.h" +#include "linux/hdreg.h" +#include "linux/init.h" +#include "linux/devfs_fs_kernel.h" +#include "linux/cdrom.h" +#include "linux/proc_fs.h" +#include "linux/ctype.h" +#include "linux/capability.h" +#include "linux/mm.h" +#include "linux/vmalloc.h" +#include "linux/blkpg.h" +#include "asm/segment.h" +#include "asm/uaccess.h" +#include "asm/irq.h" +#include "asm/types.h" +#include "user_util.h" +#include "mem_user.h" +#include "kern_util.h" +#include "kern.h" +#include "mconsole_kern.h" +#include "init.h" +#include "irq_user.h" +#include "2_5compat.h" + +extern __u64 file_size(char *file); + +static int ubd_open(struct inode * inode, struct file * filp); +static int ubd_release(struct inode * inode, struct file * file); +static int ubd_ioctl(struct inode * inode, struct file * file, + unsigned int cmd, unsigned long arg); + +#define MAX_DEV (8) + +static int blk_sizes[MAX_DEV] = { [ 0 ... MAX_DEV - 1 ] = BLOCK_SIZE }; + +static int hardsect_sizes[MAX_DEV] = { [ 0 ... MAX_DEV - 1 ] = BLOCK_SIZE }; + +static int sizes[MAX_DEV] = { [ 0 ... MAX_DEV - 1 ] = 0 }; + +static struct block_device_operations ubd_blops = { + open: ubd_open, + release: ubd_release, + ioctl: ubd_ioctl, +}; + +static struct hd_struct ubd_part[MAX_DEV] = +{ [ 0 ... MAX_DEV - 1 ] = { 0, 0, 0 } }; + +static request_queue_t *ubd_queue; + +static int fake_major = 0; + +static struct gendisk ubd_gendisk = INIT_GENDISK(MAJOR_NR, "ubd", ubd_part, + sizes, MAX_DEV, &ubd_blops); + +static struct gendisk fake_gendisk = INIT_GENDISK(0, "ubd", ubd_part, + sizes, MAX_DEV, &ubd_blops); + +#ifdef CONFIG_BLK_DEV_UBD_SYNC +#define OPEN_FLAGS O_RDWR | O_SYNC +#else +#define OPEN_FLAGS O_RDWR +#endif + +struct cow { + char *file; + int fd; + unsigned long *bitmap; + unsigned long bitmap_len; + int bitmap_offset; + int data_offset; +}; + +struct ubd { + char *file; + int is_dir; + int count; + int fd; + __u64 size; + int boot_openflags; + int openflags; + devfs_handle_t real; + devfs_handle_t fake; + struct cow cow; +}; + +#define DEFAULT_COW { \ + file: NULL, \ + fd: -1, \ + bitmap: NULL, \ + bitmap_offset: 0, \ + data_offset: 0, \ +} + +#define DEFAULT_UBD { \ + file: NULL, \ + is_dir: 0, \ + count: 0, \ + fd: -1, \ + size: -1, \ + boot_openflags: OPEN_FLAGS, \ + openflags: OPEN_FLAGS, \ + real: NULL, \ + fake: NULL, \ + cow: DEFAULT_COW, \ +} + +struct ubd ubd_dev[MAX_DEV] = { +{ + file: "root_fs", + is_dir: 0, + count: 0, + fd: -1, + size: 0, + boot_openflags: OPEN_FLAGS, + openflags: OPEN_FLAGS, + real: NULL, + fake: NULL, + cow: DEFAULT_COW, +}, +[ 1 ... MAX_DEV - 1 ] = DEFAULT_UBD +}; + +static struct hd_driveid ubd_id = { + cyls: 0, + heads: 128, + sectors: 32, +}; + +static int fake_ide = 0; +static struct proc_dir_entry *proc_ide_root = NULL; +static struct proc_dir_entry *proc_ide = NULL; + +static void make_proc_ide(void) +{ + proc_ide_root = proc_mkdir("ide", 0); + proc_ide = proc_mkdir("ide0", proc_ide_root); +} + +static int proc_ide_read_media(char *page, char **start, off_t off, int count, + int *eof, void *data) +{ + int len; + + strcpy(page, "disk\n"); + len = strlen("disk\n"); + len -= off; + if (len < count){ + *eof = 1; + if (len <= 0) return 0; + } + else len = count; + *start = page + off; + return len; + +} + +static void make_ide_entries(char *dev_name) +{ + struct proc_dir_entry *dir, *ent; + char name[64]; + + if(!fake_ide) return; + if(proc_ide_root == NULL) make_proc_ide(); + dir = proc_mkdir(dev_name, proc_ide); + ent = create_proc_entry("media", S_IFREG|S_IRUGO, dir); + if(!ent) return; + ent->nlink = 1; + ent->data = NULL; + ent->read_proc = proc_ide_read_media; + ent->write_proc = NULL; + sprintf(name,"ide0/%s", dev_name); + proc_symlink(dev_name, proc_ide_root, name); +} + +static int fake_ide_setup(char *str) +{ + fake_ide = 1; + return(1); +} + +__setup("fake_ide", fake_ide_setup); +__uml_help(fake_ide_setup, +"fake_ide\n" +" Create ide0 entries that map onto ubd devices.\n\n" +); + +static int ubd_setup_common(char *str, int *index_out) +{ + char *backing_file; + int n, sync, perm = O_RDWR; + + if(index_out) *index_out = -1; + n = *str++; + if(n == '='){ + char *end; + int major; + + if(!strcmp(str, "sync")){ + sync = 1; + return(0); + } + major = simple_strtoul(str, &end, 0); + if(*end != '\0'){ + printk(KERN_ERR + "ubd_setup : didn't parse major number\n"); + return(1); + } + fake_gendisk.major = major; + fake_major = major; + printk(KERN_INFO "Setting extra ubd major number to %d\n", + major); + return(0); + } + if(n < '0'){ + printk(KERN_ERR "ubd_setup : index out of range\n"); + return(1); + } + n -= '0'; + if(n >= MAX_DEV){ + printk(KERN_ERR "ubd_setup : index out of range\n"); + return(1); + } + if(index_out) *index_out = n; + sync = ubd_dev[n].boot_openflags & O_SYNC; + if (*str == 'r') { + perm = O_RDONLY; + str++; + } + if (*str == 's') { + sync = O_SYNC; + str++; + } + if(*str++ != '='){ + printk(KERN_ERR "ubd_setup : Expected '='\n"); + return(1); + } + backing_file = strchr(str, ','); + if(backing_file){ + *backing_file = '\0'; + backing_file++; + } + ubd_dev[n].file = str; + ubd_dev[n].cow.file = backing_file; + ubd_dev[n].boot_openflags = perm | sync; + return(0); +} + +static int ubd_setup(char *str) +{ + ubd_setup_common(str, NULL); + return(1); +} + +__setup("ubd", ubd_setup); +__uml_help(ubd_setup, +"ubd=\n" +" This is used to associate a device with a file in the underlying\n" +" filesystem. Usually, there is a filesystem in the file, but \n" +" that's not required. Swap devices containing swap files can be\n" +" specified like this. Also, a file which doesn't contain a\n" +" filesystem can have its contents read in the virtual \n" +" machine by running dd on the device. n must be in the range\n" +" 0 to 7. Appending an 'r' to the number will cause that device\n" +" to be mounted read-only. For example ubd1r=./ext_fs. Appending\n" +" an 's' (has to be _after_ 'r', if there is one) will cause data\n" +" to be written to disk on the host immediately.\n\n" +); + +static int fakehd(char *str) +{ + printk(KERN_INFO + "fakehd : Changing ubd_gendisk.major_name to \"hd\".\n"); + ubd_gendisk.major_name = "hd"; + return(1); +} + +__setup("fakehd", fakehd); +__uml_help(fakehd, +"fakehd\n" +" Change the ubd device name to \"hd\".\n\n" +); + +static void do_ubd_request(request_queue_t * q); + +int thread_fd = -1; + +int intr_count = 0; + +extern int errno; + +static spinlock_t ubd_lock = SPIN_LOCK_UNLOCKED; + +static void ubd_finish(int error) +{ + int nsect; + + if(error){ + end_request(0); + return; + } + nsect = CURRENT->current_nr_sectors; + CURRENT->sector += nsect; + CURRENT->buffer += nsect << 9; + CURRENT->errors = 0; + CURRENT->nr_sectors -= nsect; + CURRENT->current_nr_sectors = 0; + end_request(1); +} + +static void ubd_handler(void) +{ + struct io_thread_req req; + + DEVICE_INTR = NULL; + intr_count++; + if(read_ubd_fs(thread_fd, &req, sizeof(req)) != sizeof(req)){ + printk(KERN_ERR "Pid %d - spurious interrupt in ubd_handler, " + "errno = %d\n", getpid(), errno); + spin_lock(&REQUEST_LOCK); + end_request(0); + spin_unlock(&REQUEST_LOCK); + return; + } + + if((req.offset != ((__u64) (CURRENT->sector)) << 9) || + (req.length != (CURRENT->current_nr_sectors) << 9)) + panic("I/O op mismatch"); + + spin_lock(&REQUEST_LOCK); + ubd_finish(req.error); + reactivate_fd(thread_fd); + do_ubd_request(ubd_queue); + spin_unlock(&REQUEST_LOCK); +} + +static void ubd_intr(int irq, void *dev, struct pt_regs *unused) +{ + ubd_handler(); +} + +static int io_pid = -1; + +void kill_io_thread(void) +{ + if(io_pid != -1) kill(io_pid, SIGKILL); +} + +__uml_exitcall(kill_io_thread); + +int sync = 0; + +devfs_handle_t ubd_dir_handle; +devfs_handle_t ubd_fake_dir_handle; + +static int ubd_add(int n) +{ + char name[sizeof("nnnnnn\0")], dev_name[sizeof("ubd0x")]; + + if(ubd_dev[n].file == NULL) return(-1); + sprintf(name, "%d", n); + ubd_dev[n].real = devfs_register(ubd_dir_handle, name, + DEVFS_FL_DEFAULT, MAJOR_NR, n, + S_IFBLK | S_IRUSR | S_IWUSR | + S_IRGRP |S_IWGRP, + &ubd_blops, NULL); + if(fake_major != 0){ + ubd_dev[n].fake = devfs_register(ubd_fake_dir_handle, name, + DEVFS_FL_DEFAULT, fake_major, + n, S_IFBLK | S_IRUSR | + S_IWUSR | S_IRGRP | S_IWGRP, + &ubd_blops, NULL); + } + if(!strcmp(ubd_gendisk.major_name, "ubd")){ + sprintf(dev_name, "%s%d", ubd_gendisk.major_name, n); + } + else sprintf(dev_name, "%s%c", ubd_gendisk.major_name, + n + 'a'); + make_ide_entries(dev_name); + return(0); +} + +static int ubd_config(char *str) +{ + int n, err; + + str = uml_strdup(str); + if(str == NULL){ + printk(KERN_ERR "ubd_config failed to strdup string\n"); + return(1); + } + err = ubd_setup_common(str, &n); + if(err){ + kfree(str); + return(-1); + } + if(n != -1) ubd_add(n); + return(0); +} + +static int ubd_remove(char *str) +{ + int n; + + if(!isdigit(*str)) return(-1); + n = *str - '0'; + if(ubd_dev[n].file == NULL) return(0); + if(ubd_dev[n].count > 0) return(-1); + if(ubd_dev[n].real != NULL) devfs_unregister(ubd_dev[n].real); + if(ubd_dev[n].fake != NULL) devfs_unregister(ubd_dev[n].fake); + ubd_dev[n] = ((struct ubd) DEFAULT_UBD); + return(0); +} + +static struct mc_device ubd_mc = { + name: "ubd", + config: ubd_config, + remove: ubd_remove, +}; + +int ubd_mc_init(void) +{ + mconsole_register_dev(&ubd_mc); + return(0); +} + +__initcall(ubd_mc_init); + +static request_queue_t *ubd_get_queue(kdev_t device) +{ + return(ubd_queue); +} + +int ubd_init(void) +{ + unsigned long stack; + int i, err; + + ubd_dir_handle = devfs_mk_dir (NULL, "ubd", NULL); + if (devfs_register_blkdev(MAJOR_NR, "ubd", &ubd_blops)) { + printk(KERN_ERR "ubd: unable to get major %d\n", MAJOR_NR); + return -1; + } + ubd_queue = BLK_DEFAULT_QUEUE(MAJOR_NR); + INIT_QUEUE(ubd_queue, DEVICE_REQUEST, &ubd_lock); + INIT_ELV(ubd_queue, &ubd_queue->elevator); + read_ahead[MAJOR_NR] = 8; /* 8 sector (4kB) read-ahead */ + blksize_size[MAJOR_NR] = blk_sizes; + blk_size[MAJOR_NR] = sizes; + INIT_HARDSECT(hardsect_size, MAJOR_NR, hardsect_sizes); + add_gendisk(&ubd_gendisk); + if (fake_major != 0){ + char name[sizeof("ubd_nnn\0")]; + + snprintf(name, sizeof(name), "ubd_%d", fake_major); + ubd_fake_dir_handle = devfs_mk_dir(NULL, name, NULL); + if(devfs_register_blkdev(fake_major, "ubd", &ubd_blops)) { + printk(KERN_ERR "ubd: unable to get major %d\n", + fake_major); + return -1; + } + blk_dev[fake_major].queue = ubd_get_queue; + read_ahead[fake_major] = 8; /* 8 sector (4kB) read-ahead */ + blksize_size[fake_major] = blk_sizes; + INIT_HARDSECT(hardsect_size, fake_major, hardsect_sizes); + add_gendisk(&fake_gendisk); + } + for(i=0;ifd); + if(dev->cow.file != NULL) { + close_fd(dev->cow.fd); + vfree(dev->cow.bitmap); + dev->cow.bitmap = NULL; + } +} + +static int ubd_open_dev(struct ubd *dev) +{ + int err, flags, n, create_cow, *create_ptr; + + create_cow = 0; + create_ptr = (dev->cow.file != NULL) ? &create_cow : NULL; + dev->fd = open_ubd_file(dev->file, &dev->openflags, &dev->cow.file, + &dev->cow.bitmap_offset, &dev->cow.bitmap_len, + &dev->cow.data_offset, create_ptr); + + if((dev->fd == -ENOENT) && create_cow){ + printk(KERN_INFO "Creating \"%s\" as COW file for \"%s\"\n", + dev->file, dev->cow.file); + n = dev - ubd_dev; + dev->fd = create_cow_file(dev->file, dev->cow.file, 1 << 9, + &dev->cow.bitmap_offset, + &dev->cow.bitmap_len, + &dev->cow.data_offset); + if(dev->fd < 0){ + printk(KERN_ERR "Creation of COW file \"%s\" failed, " + "errno = %d\n", dev->file, -dev->fd); + } + } + + if(dev->fd < 0) return(dev->fd); + + if(dev->cow.file != NULL){ + err = -ENOMEM; + dev->cow.bitmap = (void *) vmalloc(dev->cow.bitmap_len); + if(dev->cow.bitmap == NULL) goto error; + flush_tlb_kernel_vm(); + + err = read_cow_bitmap(dev->fd, dev->cow.bitmap, + dev->cow.bitmap_offset, + dev->cow.bitmap_len); + if(err) goto error; + + flags = O_RDONLY; + err = open_ubd_file(dev->cow.file, &flags, NULL, NULL, NULL, + NULL, NULL); + if(err < 0) goto error; + dev->cow.fd = err; + } + return(0); + error: + close_fd(dev->fd); + return(err); +} + +static int ubd_open(struct inode * inode, struct file * filp) +{ + char *file; + int n; + + n = minor(inode->i_rdev); + if(n > MAX_DEV) + return -ENODEV; + if(ubd_is_dir(ubd_dev[n].file)){ + ubd_dev[n].is_dir = 1; + return(0); + } + if(ubd_dev[n].count == 0){ + ubd_dev[n].openflags = ubd_dev[n].boot_openflags; + /* XXX This error is wrong when errno isn't stored in + * ubd_dev[n].fd + */ + if(ubd_open_dev(&ubd_dev[n]) < 0){ + printk(KERN_ERR "ubd%d: Can't open \"%s\": " + "errno = %d\n", n, ubd_dev[n].file, + -ubd_dev[n].fd); + } + if(ubd_dev[n].fd < 0) + return -ENODEV; + file = ubd_dev[n].cow.file ? ubd_dev[n].cow.file : + ubd_dev[n].file; + ubd_dev[n].size = file_size(file); + if(ubd_dev[n].size < 0) return(ubd_dev[n].size); + ubd_part[n].start_sect = 0; + ubd_part[n].nr_sects = ubd_dev[n].size / blk_sizes[n]; + sizes[n] = ubd_dev[n].size / BLOCK_SIZE; + } + ubd_dev[n].count++; + if ((filp->f_mode & FMODE_WRITE) && + ((ubd_dev[n].openflags & ~O_SYNC) == O_RDONLY)){ + if(--ubd_dev[n].count == 0) ubd_close(&ubd_dev[n]); + return -EROFS; + } + return(0); +} + +static int ubd_release(struct inode * inode, struct file * file) +{ + int n; + + n = minor(inode->i_rdev); + if(n > MAX_DEV) + return -ENODEV; + if(--ubd_dev[n].count == 0) ubd_close(&ubd_dev[n]); + return(0); +} + +int cow_read = 0; +int cow_write = 0; + +void cowify_req(struct io_thread_req *req, struct ubd *dev) +{ + int i, update_bitmap, sector = req->offset >> 9; + + if(req->length > (sizeof(req->sector_mask) * 8) << 9) + panic("Operation too long"); + if(req->op == UBD_READ) { + for(i = 0; i < req->length >> 9; i++){ + if(ubd_test_bit(sector + i, dev->cow.bitmap)){ + ubd_set_bit(i, &req->sector_mask); + cow_read++; + } + } + } + else { + update_bitmap = 0; + for(i = 0; i < req->length >> 9; i++){ + cow_write++; + ubd_set_bit(i, &req->sector_mask); + if(!ubd_test_bit(sector + i, dev->cow.bitmap)) + update_bitmap = 1; + ubd_set_bit(sector + i, dev->cow.bitmap); + } + if(update_bitmap){ + req->cow_offset = sector / (sizeof(unsigned long) * 8); + req->bitmap_words[0] = + dev->cow.bitmap[req->cow_offset]; + req->bitmap_words[1] = + dev->cow.bitmap[req->cow_offset + 1]; + req->cow_offset *= sizeof(unsigned long); + req->cow_offset += dev->cow.bitmap_offset; + } + } +} + +static int prepare_request(struct request *req, struct io_thread_req *io_req) +{ + struct ubd *dev; + __u64 block; + int nsect; + + if(req->rq_status == RQ_INACTIVE) return(1); + + dev = &ubd_dev[minor(req->rq_dev)]; + if(dev->is_dir){ + strcpy(req->buffer, "HOSTFS:"); + strcat(req->buffer, dev->file); + end_request(1); + return(1); + } + if(IS_WRITE(req) && ((dev->openflags & O_ACCMODE) == O_RDONLY)){ + printk("Write attempted on readonly ubd device %d\n", + minor(req->rq_dev)); + end_request(0); + return(1); + } + + block = req->sector; + nsect = req->current_nr_sectors; + + io_req->op = (req->cmd == READ) ? UBD_READ : UBD_WRITE; + io_req->fds[0] = (dev->cow.file != NULL) ? dev->cow.fd : dev->fd; + io_req->fds[1] = dev->fd; + io_req->offsets[0] = 0; + io_req->offsets[1] = dev->cow.data_offset; + io_req->offset = ((__u64) block) << 9; + io_req->length = nsect << 9; + io_req->buffer = req->buffer; + io_req->sectorsize = 1 << 9; + io_req->sector_mask = 0; + io_req->cow_offset = -1; + io_req->error = 0; + + if(dev->cow.file != NULL) cowify_req(io_req, dev); + return(0); +} + +static void do_ubd_request(request_queue_t *q) +{ + struct io_thread_req io_req; + struct request *req; + int err, n; + + if(thread_fd == -1){ + while(!list_empty(&q->queue_head)){ + req = blkdev_entry_next_request(&q->queue_head); + err = prepare_request(req, &io_req); + if(!err){ + do_io(&io_req); + ubd_finish(io_req.error); + } + } + } + else { + if(DEVICE_INTR || list_empty(&q->queue_head)) return; + req = blkdev_entry_next_request(&q->queue_head); + err = prepare_request(req, &io_req); + if(!err){ + SET_INTR(ubd_handler); + n = write_ubd_fs(thread_fd, (char *) &io_req, + sizeof(io_req)); + if(n != sizeof(io_req)) + printk("write to io thread failed - returned " + "%d, errno %d\n", n, errno); + } + } +} + +static int ubd_ioctl(struct inode * inode, struct file * file, + unsigned int cmd, unsigned long arg) +{ + struct hd_geometry *loc = (struct hd_geometry *) arg; + int dev, err; + + if(!inode) return -EINVAL; + dev = minor(inode->i_rdev); + if (dev > MAX_DEV) + return -EINVAL; + switch (cmd) { + struct hd_geometry g; + struct cdrom_volctrl volume; + case HDIO_GETGEO: + if (!loc) return -EINVAL; + g.heads = 128; + g.sectors = 32; + g.cylinders = ubd_dev[dev].size / (128 * 32); + g.start = 2; + return copy_to_user(loc, &g, sizeof g) ? -EFAULT : 0; + case BLKRASET: + if(!capable(CAP_SYS_ADMIN)) return -EACCES; + if(arg > 0xff) return -EINVAL; + read_ahead[major(inode->i_rdev)] = arg; + return 0; + case BLKRAGET: + if (!arg) return -EINVAL; + err = verify_area(VERIFY_WRITE, (long *) arg, sizeof(long)); + if (err) + return err; + return 0; + case BLKGETSIZE: /* Return device size */ + if (!arg) return -EINVAL; + err = verify_area(VERIFY_WRITE, (long *) arg, sizeof(long)); + if (err) + return err; + put_user(ubd_dev[dev].size >> 9, (long *) arg); + return 0; + case BLKFLSBUF: + if(!capable(CAP_SYS_ADMIN)) return -EACCES; + return 0; + + case BLKRRPART: /* Re-read partition tables */ + return 0; /* revalidate_hddisk(inode->i_rdev, 1); */ + + case HDIO_SET_UNMASKINTR: + if (!capable(CAP_SYS_ADMIN)) return -EACCES; + if ((arg > 1) || (minor(inode->i_rdev) & 0x3F)) + return -EINVAL; + return 0; + + case HDIO_GET_UNMASKINTR: + if (!arg) return -EINVAL; + err = verify_area(VERIFY_WRITE, (long *) arg, sizeof(long)); + if (err) + return err; + return 0; + + case HDIO_GET_MULTCOUNT: + if (!arg) return -EINVAL; + err = verify_area(VERIFY_WRITE, (long *) arg, sizeof(long)); + if (err) + return err; + return 0; + + case HDIO_SET_MULTCOUNT: + if (!capable(CAP_SYS_ADMIN)) return -EACCES; + if (minor(inode->i_rdev) & 0x3F) return -EINVAL; + return 0; + + case HDIO_GET_IDENTITY: + ubd_id.cyls = ubd_dev[dev].size / (128 * 32); + if (copy_to_user((char *) arg, (char *) &ubd_id, + sizeof(ubd_id))) + return -EFAULT; + return 0; + + case CDROMVOLREAD: + if(copy_from_user(&volume, (char *) arg, sizeof(volume))) + return -EFAULT; + volume.channel0 = 255; + volume.channel1 = 255; + volume.channel2 = 255; + volume.channel3 = 255; + if(copy_to_user((char *) arg, &volume, sizeof(volume))) + return -EFAULT; + return 0; + + default: + return blk_ioctl(inode->i_rdev, cmd, arg); + } +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/drivers/ubd_user.c linux_umopenmosix/arch/um/drivers/ubd_user.c --- linux-2.4.17/arch/um/drivers/ubd_user.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/drivers/ubd_user.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,526 @@ +/* + * Copyright (C) 2000 Jeff Dike (jdike@karaya.com) + * Copyright (C) 2001 Ridgerun,Inc (glonnon@ridgerun.com) + * Licensed under the GPL + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "asm/types.h" +#include "user_util.h" +#include "kern_util.h" +#include "user.h" +#include "ubd_user.h" + +#include +#include +#if __BYTE_ORDER == __BIG_ENDIAN +# define ntohll(x) (x) +# define htonll(x) (x) +#elif __BYTE_ORDER == __LITTLE_ENDIAN +# define ntohll(x) bswap_64(x) +# define htonll(x) bswap_64(x) +#else +#error "__BYTE_ORDER not defined" +#endif + +extern void panic(char *fmt, ...); + +#define PATH_LEN_V1 256 + +struct cow_header_v1 { + int magic; + int version; + char backing_file[PATH_LEN_V1]; + time_t mtime; + __u64 size; + int sectorsize; +}; + +#define PATH_LEN_V2 MAXPATHLEN + +struct cow_header_v2 { + unsigned long magic; + unsigned long version; + char backing_file[PATH_LEN_V2]; + time_t mtime; + __u64 size; + int sectorsize; +}; + +union cow_header { + struct cow_header_v1 v1; + struct cow_header_v2 v2; +}; + +#define COW_MAGIC 0x4f4f4f4d /* MOOO */ +#define COW_VERSION 2 + +static void sizes(__u64 size, int sectorsize, int bitmap_offset, + unsigned long *bitmap_len_out, int *data_offset_out) +{ + *bitmap_len_out = (size + sectorsize - 1) / (8 * sectorsize); + + *data_offset_out = bitmap_offset + *bitmap_len_out; + *data_offset_out = (*data_offset_out + sectorsize - 1) / sectorsize; + *data_offset_out *= sectorsize; +} + +static int read_cow_header(int fd, int *magic_out, char **backing_file_out, + time_t *mtime_out, __u64 *size_out, + int *sectorsize_out, int *bitmap_offset_out) +{ + union cow_header *header; + char *file; + int err, n; + unsigned long version, magic; + + header = um_kmalloc(sizeof(*header)); + if(header == NULL){ + printk("read_cow_header - Failed to allocate header\n"); + return(-ENOMEM); + } + err = -EINVAL; + n = read(fd, header, sizeof(*header)); + if(n < offsetof(typeof(header->v1), backing_file)){ + printk("read_cow_header - short header\n"); + goto out; + } + + magic = header->v1.magic; + if(magic == COW_MAGIC) { + version = header->v1.version; + } + else if(magic == ntohl(COW_MAGIC)){ + version = ntohl(header->v1.version); + } + else goto out; + + *magic_out = COW_MAGIC; + + if(version == 1){ + if(n < sizeof(header->v1)){ + printk("read_cow_header - failed to read V1 header\n"); + goto out; + } + *mtime_out = header->v1.mtime; + *size_out = header->v1.size; + *sectorsize_out = header->v1.sectorsize; + *bitmap_offset_out = sizeof(header->v1); + file = header->v1.backing_file; + } + else if(version == 2){ + if(n < sizeof(header->v2)){ + printk("read_cow_header - failed to read V2 header\n"); + goto out; + } + *mtime_out = ntohl(header->v2.mtime); + *size_out = ntohll(header->v2.size); + *sectorsize_out = ntohl(header->v2.sectorsize); + *bitmap_offset_out = sizeof(header->v2); + file = header->v2.backing_file; + } + else { + printk("read_cow_header - invalid COW version\n"); + goto out; + } + err = -ENOMEM; + *backing_file_out = uml_strdup(file); + if(*backing_file_out == NULL){ + printk("read_cow_header - failed to allocate backing file\n"); + goto out; + } + err = 0; + out: + kfree(header); + return(err); +} + +int open_ubd_file(char *file, int *openflags, char **backing_file_out, + int *bitmap_offset_out, unsigned long *bitmap_len_out, + int *data_offset_out, int *create_cow_out) +{ + struct stat64 buf; + time_t mtime; + __u64 size; + char *backing_file; + int fd, err, sectorsize, magic, mode = 0644; + + if((fd = open64(file, *openflags, mode)) < 0){ + if((errno == ENOENT) && (create_cow_out != NULL)) + *create_cow_out = 1; + if(((*openflags & O_ACCMODE) != O_RDWR) || + ((errno != EROFS) && (errno != EACCES))) return(-errno); + *openflags &= ~O_ACCMODE; + *openflags |= O_RDONLY; + if((fd = open64(file, *openflags, mode)) < 0) return(-errno); + } + if(backing_file_out == NULL) return(fd); + + err = read_cow_header(fd, &magic, &backing_file, &mtime, &size, + §orsize, bitmap_offset_out); + if(err && (*backing_file_out != NULL)){ + printk("Failed to read COW header from COW file \"%s\", " + "errno = %d\n", file, err); + goto error; + } + if(err) return(fd); + + if((*backing_file_out != NULL) && + strcmp(*backing_file_out, backing_file)){ + printk("Backing file mismatch - \"%s\" requested,\n" + "\"%s\" specified in COW header of \"%s\"\n", + *backing_file_out, backing_file, file); + printk("Using \"%s\"\n", backing_file); + } + + if(backing_file_out == NULL) return(fd); + + *backing_file_out = backing_file; + + err = stat64(*backing_file_out, &buf); + if(err){ + printk("Failed to stat backing file \"%s\", errno = %d\n", + *backing_file_out, errno); + err = -errno; + goto error; + } + + err = -EINVAL; + if(buf.st_size != size){ + printk("Size mismatch (%ld vs %ld) of COW header vs backing " + "file\n", buf.st_size, size); + goto error; + } + if(buf.st_mtime != mtime){ + printk("mtime mismatch (%ld vs %ld) of COW header vs backing " + "file\n", buf.st_mtime, mtime); + goto error; + } + + sizes(size, sectorsize, *bitmap_offset_out, bitmap_len_out, + data_offset_out); + + return(fd); + error: + close(fd); + return(err); +} + +int read_cow_bitmap(int fd, void *buf, int offset, int len) +{ + int err; + + err = lseek64(fd, offset, SEEK_SET); + if(err != offset) return(-errno); + err = read(fd, buf, len); + if(err < 0) return(-errno); + return(0); +} + +static int absolutize(char *to, int size, char *from) +{ + char save_cwd[256], *slash; + int remaining; + + if(getcwd(save_cwd, sizeof(save_cwd)) == NULL) { + printk("absolutize : unable to get cwd - errno = %d\n", errno); + return(-1); + } + slash = strrchr(from, '/'); + if(slash != NULL){ + *slash = '\0'; + if(chdir(from)){ + *slash = '/'; + printk("absolutize : Can't cd to '%s' - errno = %d\n", + from, errno); + return(-1); + } + *slash = '/'; + if(getcwd(to, size) == NULL){ + printk("absolutize : unable to get cwd of '%s' - " + "errno = %d\n", from, errno); + return(-1); + } + remaining = size - strlen(to); + if(strlen(slash) + 1 > remaining){ + printk("absolutize : unable to fit '%s' into %d " + "chars\n", from, size); + return(-1); + } + strcat(to, slash); + } + else { + if(strlen(save_cwd) + 1 + strlen(from) + 1 > size){ + printk("absolutize : unable to fit '%s' into %d " + "chars\n", from, size); + return(-1); + } + strcpy(to, save_cwd); + strcat(to, "/"); + strcat(to, from); + } + chdir(save_cwd); + return(0); +} + +int create_cow_file(char *cow_file, char *backing_file, int sectorsize, + int *bitmap_offset_out, unsigned long *bitmap_len_out, + int *data_offset_out) +{ + struct cow_header_v2 *header; + struct stat64 buf; + __u64 blocks; + long zero; + int err, fd, i, flags; + __u64 size; + + flags = O_RDWR | O_CREAT; + fd = open_ubd_file(cow_file, &flags, NULL, NULL, NULL, NULL, NULL); + if(fd < 0) return(fd); + + err = -ENOMEM; + header = um_kmalloc(sizeof(*header)); + if(header == NULL){ + printk("Failed to allocate COW V2 header\n"); + goto out_close; + } + header->magic = htonl(COW_MAGIC); + header->version = htonl(COW_VERSION); + + err = -EINVAL; + if(strlen(backing_file) > sizeof(header->backing_file) - 1){ + printk("Backing file name \"%s\" is too long - names are " + "limited to %d characters\n", backing_file, + sizeof(header->backing_file) - 1); + goto out_free; + } + + if(absolutize(header->backing_file, sizeof(header->backing_file), + backing_file)) + goto out_free; + + err = stat64(header->backing_file, &buf); + if(err < 0){ + err = -errno; + goto out_free; + } + + header->mtime = htonl(buf.st_mtime); + header->size = htonll(buf.st_size); + header->sectorsize = htonl(sectorsize); + size = buf.st_size; + + err = write(fd, header, sizeof(*header)); + if(err != sizeof(*header)) goto out_free; + + blocks = (size + sectorsize - 1) / sectorsize; + blocks = (blocks + sizeof(long) * 8 - 1) / (sizeof(long) * 8); + zero = 0; + for(i = 0; i < blocks; i++){ + err = write(fd, &zero, sizeof(zero)); + if(err != sizeof(zero)) goto out_free; + } + + sizes(size, sectorsize, sizeof(struct cow_header_v2), + bitmap_len_out, data_offset_out); + *bitmap_offset_out = sizeof(struct cow_header_v2); + + kfree(header); + return(fd); + + out_free: + kfree(header); + out_close: + close(fd); + return(err); +} + +int read_ubd_fs(int fd, void *buffer, int len) +{ + return(read(fd, buffer, len)); +} + +int write_ubd_fs(int fd, char *buffer, int len) +{ + return(write(fd, buffer, len)); +} + +int ubd_is_dir(char *file) +{ + struct stat64 buf; + + if(stat64(file, &buf) < 0) return(0); + return(S_ISDIR(buf.st_mode)); +} + +void do_io(struct io_thread_req *req) +{ + char *buf; + unsigned long len; + int n, nsectors, start, end, bit; + __u64 off; + + nsectors = req->length / req->sectorsize; + start = 0; + do { + bit = ubd_test_bit(start, &req->sector_mask); + end = start; + while((end < nsectors) && + (ubd_test_bit(end, &req->sector_mask) == bit)) + end++; + + if(end != nsectors) + printk("end != nsectors\n"); + off = req->offset + req->offsets[bit]; + len = (end - start) * req->sectorsize; + buf = &req->buffer[start * req->sectorsize]; + + if(lseek64(req->fds[bit], off, SEEK_SET) != off){ + printk("do_io - lseek failed : errno = %d\n", errno); + req->error = 1; + return; + } + if(req->op == UBD_READ){ + n = 0; + do { + buf = &buf[n]; + len -= n; + n = read(req->fds[bit], buf, len); + if (n < 0) { + printk("do_io - read returned %d : " + "errno = %d fd = %d\n", n, + errno, req->fds[bit]); + req->error = 1; + return; + } + } while((n < len) && (n != 0)); + if (n < len) memset(&buf[n], 0, len - n); + } + else { + n = write(req->fds[bit], buf, len); + if(n != len){ + printk("do_io - write returned %d : " + "errno = %d fd = %d\n", n, + errno, req->fds[bit]); + req->error = 1; + return; + } + } + + start = end; + } while(start < nsectors); + + if(req->cow_offset != -1){ + if(lseek64(req->fds[1], req->cow_offset, SEEK_SET) != + req->cow_offset){ + printk("do_io - bitmap lseek failed : errno = %d\n", + errno); + req->error = 1; + return; + } + n = write(req->fds[1], &req->bitmap_words, + sizeof(req->bitmap_words)); + if(n != sizeof(req->bitmap_words)){ + printk("do_io - bitmap update returned %d : " + "errno = %d fd = %d\n", n, errno, req->fds[1]); + req->error = 1; + return; + } + } + req->error = 0; + return; +} + +int kernel_fd = -1; + +int io_count = 0; + +int io_thread(void *arg) +{ + struct io_thread_req req; + int n; + + signal(SIGWINCH, SIG_IGN); + while(1){ + n = read(kernel_fd, &req, sizeof(req)); + if(n < 0) printk("io_thread - read returned %d, errno = %d\n", + n, errno); + else if(n < sizeof(req)){ + printk("io_thread - short read : length = %d\n", n); + continue; + } + io_count++; + do_io(&req); + n = write(kernel_fd, &req, sizeof(req)); + if(n != sizeof(req)) + printk("io_thread - write failed, errno = %d\n", + errno); + } +} + +int start_io_thread(unsigned long sp, int *fd_out) +{ + int pid, fds[2]; + + if(socketpair(AF_UNIX, SOCK_STREAM, 0, fds) < 0){ + printk("start_io_thread - socketpair failed, errno = %d\n", + errno); + return(-1); + } + kernel_fd = fds[0]; + *fd_out = fds[1]; + + pid = clone(io_thread, (void *) sp, CLONE_FILES | CLONE_VM | SIGCHLD, + NULL); + if(pid < 0){ + printk("start_io_thread - clone failed : errno = %d\n", errno); + return(-errno); + } + return(pid); +} + +#ifdef notdef +int start_io_thread(unsigned long sp, int *fd_out) +{ + int pid; + + if((kernel_fd = get_pty()) < 0) return(-1); + raw(kernel_fd, 0); + if((*fd_out = open(ptsname(kernel_fd), O_RDWR)) < 0){ + printk("Couldn't open tty for IO\n"); + return(-1); + } + + pid = clone(io_thread, (void *) sp, CLONE_FILES | CLONE_VM | SIGCHLD, + NULL); + if(pid < 0){ + printk("start_io_thread - clone failed : errno = %d\n", errno); + return(-errno); + } + return(pid); +} +#endif + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/drivers/xterm.c linux_umopenmosix/arch/um/drivers/xterm.c --- linux-2.4.17/arch/um/drivers/xterm.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/drivers/xterm.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,140 @@ +/* + * Copyright (C) 2001 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "kern_util.h" +#include "user_util.h" +#include "chan_user.h" +#include "user.h" + +struct xterm_chan { + int pid; + int fd; + char *title; + int device; + int raw; + struct termios tt; +}; + +void *xterm_init(char *str, int device, struct chan_opts *opts) +{ + struct xterm_chan *data; + + if((data = malloc(sizeof(*data))) == NULL) return(NULL); + *data = ((struct xterm_chan) { pid : -1, + device : device, + title : opts->xterm_title, + raw : opts->raw }); + return(data); +} + +struct xterm_info { + char tty[2]; + int fd; + int slave; + int console_num; + int *pid_out; + char *title; +}; + +static void xterm_tramp(void *arg) +{ + struct xterm_info *info; + int pid; + char title[256], flag[sizeof("Sxxnn\0")], c; + + info = arg; + sprintf(flag, "-S%c%c%d", info->tty[0], info->tty[1], info->fd); + sprintf(title, info->title, info->console_num); + if((pid = fork()) != 0) *info->pid_out = pid; + else { + execlp("xterm", "xterm", flag, "-T", title, NULL); + printk("execlp of xterm failed - errno = %d\n", errno); + close(info->fd); + exit(1); + } + close(info->fd); + while((read(info->slave, &c, sizeof(c)) == sizeof(c)) && (c != '\n')) ; +} + +int xterm_open(int input, int output, void *d) +{ + struct xterm_chan *data = d; + struct xterm_info info; + int master, slave; + char dev[] = "/dev/ptyXX"; + + master = getmaster(dev); + if(master == -1){ + printk("No unused host ptys found\n"); + return(-ENODEV); + } + dev[strlen("/dev/")] = 't'; + slave = open(dev, O_RDWR); + if(slave == -1) return(-errno); + tcgetattr(slave, &data->tt); + raw(slave, 0); + info.tty[0] = dev[strlen("/dev/pty")]; + info.tty[1] = dev[strlen("/dev/ptyX")]; + info.fd = master; + info.slave = slave; + info.console_num = data->device; + info.pid_out = &data->pid; + info.title = data->title; + tracing_cb(xterm_tramp, &info); + tcsetattr(slave, TCSADRAIN, &data->tt); + if(data->raw) raw(slave, 0); + data->fd = slave; + return(slave); +} + +void xterm_close(int fd, void *d) +{ + struct xterm_chan *data = d; + + if(data->pid != -1) kill(data->pid, SIGKILL); + close(fd); +} + +void xterm_free(void *d) +{ + free(d); +} + +int xterm_console_write(int fd, const char *buf, int n, void *d) +{ + struct xterm_chan *data = d; + + return(generic_console_write(fd, buf, n, &data->tt)); +} + +struct chan_ops xterm_ops = { + init: xterm_init, + open: xterm_open, + close: xterm_close, + read: generic_read, + write: generic_write, + console_write: xterm_console_write, + window_size: generic_window_size, + free: xterm_free, +}; + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/fs/Makefile linux_umopenmosix/arch/um/fs/Makefile --- linux-2.4.17/arch/um/fs/Makefile Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/fs/Makefile Sun Jun 23 12:40:10 2002 @@ -0,0 +1,16 @@ +# +# Copyright (C) 2000 Jeff Dike (jdike@karaya.com) +# Licensed under the GPL +# + +O_TARGET := fs.o + +subdir-$(CONFIG_HOSTFS) = hostfs + +MOD_SUB_DIRS := $(subdir-m) +SUB_DIRS := $(subdir-y) + +obj-y += $(join $(subdir-y),$(subdir-y:%=/%.o)) +obj-m += $(join $(subdir-m),$(subdir-m:%=/%.o)) + +include $(TOPDIR)/Rules.make diff -urN linux-2.4.17/arch/um/fs/hostfs/Makefile linux_umopenmosix/arch/um/fs/hostfs/Makefile --- linux-2.4.17/arch/um/fs/hostfs/Makefile Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/fs/hostfs/Makefile Sun Jun 23 12:40:10 2002 @@ -0,0 +1,31 @@ +# +# Copyright (C) 2000 Jeff Dike (jdike@karaya.com) +# Licensed under the GPL +# + +# struct stat64 changed the inode field name between 2.2 and 2.4 from st_ino +# to __st_ino. It stayed in the same place, so as long as the correct name +# is used, hostfs compiled on 2.2 should work on 2.4 and vice versa. + +STAT64_INO_FIELD := $(shell grep -q __st_ino /usr/include/bits/stat.h && \ + echo __)st_ino + +USER_CFLAGS := $(USER_CFLAGS) -DSTAT64_INO_FIELD=$(STAT64_INO_FIELD) + +O_TARGET := +obj-y = +obj-m = + +CFLAGS_hostfs_kern.o := $(CFLAGS) +CFLAGS_hostfs_user.o := $(USER_CFLAGS) + +ifneq ($(CONFIG_HOSTFS), n) + O_TARGET := hostfs.o +endif + +obj-y += hostfs_kern.o hostfs_user.o +obj-m += $(O_TARGET) + +override CFLAGS = + +include $(TOPDIR)/Rules.make diff -urN linux-2.4.17/arch/um/fs/hostfs/hostfs.h linux_umopenmosix/arch/um/fs/hostfs/hostfs.h --- linux-2.4.17/arch/um/fs/hostfs/hostfs.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/fs/hostfs/hostfs.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,74 @@ +#ifndef __UM_FS_HOSTFS +#define __UM_FS_HOSTFS + +#define HOSTFS_FILE 1 +#define HOSTFS_DIR 2 +#define HOSTFS_SYMLINK 3 +#define HOSTFS_CHARDEV 4 +#define HOSTFS_BLOCDEV 5 +#define HOSTFS_FIFO 6 +#define HOSTFS_SOCK 7 + +/* These are exactly the same definitions as in fs.h, but the names are + * changed so that this file can be included in both kernel and user files. + */ + +#define HOSTFS_ATTR_MODE 1 +#define HOSTFS_ATTR_UID 2 +#define HOSTFS_ATTR_GID 4 +#define HOSTFS_ATTR_SIZE 8 +#define HOSTFS_ATTR_ATIME 16 +#define HOSTFS_ATTR_MTIME 32 +#define HOSTFS_ATTR_CTIME 64 +#define HOSTFS_ATTR_ATIME_SET 128 +#define HOSTFS_ATTR_MTIME_SET 256 +#define HOSTFS_ATTR_FORCE 512 /* Not a change, but a change it */ +#define HOSTFS_ATTR_ATTR_FLAG 1024 + +struct hostfs_iattr { + unsigned int ia_valid; + mode_t ia_mode; + uid_t ia_uid; + gid_t ia_gid; + loff_t ia_size; + time_t ia_atime; + time_t ia_mtime; + time_t ia_ctime; + unsigned int ia_attr_flags; +}; + +extern int stat_file(const char *path, int *dev_out, unsigned long long *inode_out, + int *mode_out, int *nlink_out, int *uid_out, + int *gid_out, unsigned long long *size_out, + unsigned long *atime_out, unsigned long *mtime_out, + unsigned long *ctime_out, int *blksize_out, + unsigned long long *blocks_out); +extern int access_file(char *path, int r, int w, int x); +extern int open_file(char *path, int r, int w); +extern int file_type(const char *path, int *rdev); +extern void *open_dir(char *path, int *err_out); +extern char *read_dir(void *stream, unsigned long long *pos, + unsigned long long *ino_out, int *len_out); +extern void close_file(void *stream); +extern void close_dir(void *stream); +extern int read_file(int fd, unsigned long long *offset, char *buf, int len); +extern int write_file(int fd, unsigned long long *offset, const char *buf, + int len); +extern int lseek_file(int fd, long long offset, int whence); +extern int file_create(char *name, int ur, int uw, int ux, int gr, + int gw, int gx, int or, int ow, int ox); +extern int set_attr(const char *file, struct hostfs_iattr *attrs); +extern int make_symlink(const char *from, const char *to); +extern int unlink_file(const char *file); +extern int do_mkdir(const char *file, int mode); +extern int do_rmdir(const char *file); +extern int do_mknod(const char *file, int mode, int dev); +extern int link_file(const char *from, const char *to); +extern int do_readlink(char *file, char *buf, int size); +extern int rename_file(char *from, char *to); +extern int do_statfs(char *root, long *bsize_out, long long *blocks_out, + long long *bfree_out, long long *bavail_out, long long *files_out, + long long *ffree_out, void *fsid_out, int fsid_size, + long *namelen_out, long *spare_out); + +#endif diff -urN linux-2.4.17/arch/um/fs/hostfs/hostfs_kern.c linux_umopenmosix/arch/um/fs/hostfs/hostfs_kern.c --- linux-2.4.17/arch/um/fs/hostfs/hostfs_kern.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/fs/hostfs/hostfs_kern.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,784 @@ +/* + * Copyright (C) 2000, 2001 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "hostfs.h" +#include "kern_util.h" +#include "kern.h" +#include "user_util.h" +#include "2_5compat.h" + +#define file_hostfs_i(file) (&(file)->f_dentry->d_inode->u.hostfs_i) + +int hostfs_d_delete(struct dentry *dentry) +{ + return(1); +} + +struct dentry_operations hostfs_dentry_ops = { + d_delete: hostfs_d_delete, +}; + +static char *root_ino = "/"; + +#define HOSTFS_SUPER_MAGIC 0x00c0ffee + +static struct inode_operations hostfs_iops; +static struct address_space_operations hostfs_link_aops; + +static char *dentry_name(struct dentry *dentry, int extra) +{ + struct dentry *parent; + char *root, *name; + int len; + + len = 0; + parent = dentry; + while(parent->d_parent != parent){ + len += parent->d_name.len + 1; + parent = parent->d_parent; + } + + root = parent->d_inode->u.hostfs_i.host_filename; + len += strlen(root); + name = kmalloc(len + extra + 1, GFP_KERNEL); + if(name == NULL) return(NULL); + + name[len] = '\0'; + parent = dentry; + while(parent->d_parent != parent){ + len -= parent->d_name.len + 1; + name[len] = '/'; + strncpy(&name[len + 1], parent->d_name.name, + parent->d_name.len); + parent = parent->d_parent; + } + strncpy(name, root, strlen(root)); + return(name); +} + +static char *inode_name(struct inode *ino, int extra) +{ + struct dentry *dentry; + + dentry = list_entry(ino->i_dentry.next, struct dentry, d_alias); + return(dentry_name(dentry, extra)); +} + +static int read_name(struct inode *ino, char *name) +{ + /* The non-int inode fields are copied into ints by stat_file and + * then copied into the inode because passing the actual pointers + * in and having them treated as int * breaks on big-endian machines + */ + int err; + int i_dev, i_mode, i_nlink, i_blksize; + unsigned long long i_size; + unsigned long long i_ino; + unsigned long long i_blocks; + err = stat_file(name, &i_dev, &i_ino, &i_mode, &i_nlink, + &ino->i_uid, &ino->i_gid, &i_size, &ino->i_atime, + &ino->i_mtime, &ino->i_ctime, &i_blksize, &i_blocks); + if(err) return(err); + ino->i_ino = i_ino; + ino->i_dev = i_dev; + ino->i_mode = i_mode; + ino->i_nlink = i_nlink; + ino->i_size = i_size; + ino->i_blksize = i_blksize; + ino->i_blocks = i_blocks; + if(kdev_same(ino->i_sb->s_dev, ROOT_DEV) && (ino->i_uid == getuid())) + ino->i_uid = 0; + return(0); +} + +static int read_inode(struct inode *ino) +{ + char *name; + int err; + + name = inode_name(ino, 0); + if(name == NULL) return(-ENOMEM); + err = read_name(ino, name); + kfree(name); + return(err); +} + +void hostfs_delete_inode(struct inode *ino) +{ + if(ino->u.hostfs_i.host_filename) kfree(ino->u.hostfs_i.host_filename); + ino->u.hostfs_i.host_filename = NULL; + if(ino->u.hostfs_i.fd != -1) close_file(&ino->u.hostfs_i.fd); + ino->u.hostfs_i.mode = 0; + clear_inode(ino); +} + +int hostfs_statfs(struct super_block *sb, struct statfs *sf) +{ + /* do_statfs uses struct statfs64 internally, but the linux kernel + * struct statfs still has 32-bit versions for most of these fields, + * so we convert them here + */ + int err; + long long f_blocks; + long long f_bfree; + long long f_bavail; + long long f_files; + long long f_ffree; + + err = do_statfs(sb->s_root->d_inode->u.hostfs_i.host_filename, + &sf->f_bsize, &f_blocks, &f_bfree, &f_bavail, &f_files, + &f_ffree, &sf->f_fsid, sizeof(sf->f_fsid), + &sf->f_namelen, sf->f_spare); + if(err) return(err); + sf->f_blocks = f_blocks; + sf->f_bfree = f_bfree; + sf->f_bavail = f_bavail; + sf->f_files = f_files; + sf->f_ffree = f_ffree; + sf->f_type = HOSTFS_SUPER_MAGIC; + return(0); +} + +static struct super_operations hostfs_sbops = { + put_inode: force_delete, + delete_inode: hostfs_delete_inode, + statfs: hostfs_statfs, +}; + +int hostfs_readdir(struct file *file, void *ent, filldir_t filldir) +{ + void *dir; + char *name; + unsigned long long next, ino; + int error, len; + + name = dentry_name(file->f_dentry, 0); + if(name == NULL) return(-ENOMEM); + dir = open_dir(name, &error); + kfree(name); + if(dir == NULL) return(-error); + next = file->f_pos; + while((name = read_dir(dir, &next, &ino, &len)) != NULL){ + error = (*filldir)(ent, name, len, file->f_pos, + ino, DT_UNKNOWN); + if(error) break; + file->f_pos = next; + } + close_dir(dir); + return(0); +} + +unsigned int hostfs_poll(struct file *file, struct poll_table_struct *table) +{ + not_implemented(); + return(-EINVAL); +} + +int hostfs_ioctl(struct inode *ino, struct file *file, unsigned int code, + unsigned long data) +{ + not_implemented(); + return(-EINVAL); +} + +int hostfs_file_open(struct inode *ino, struct file *file) +{ + char *name; + int mode = 0, r = 0, w = 0, fd; + + mode = file->f_mode & (FMODE_READ | FMODE_WRITE); + if((mode & ino->u.hostfs_i.mode) == mode) return(0); + + if(ino->u.hostfs_i.fd != -1){ + close_file(&ino->u.hostfs_i.fd); + ino->u.hostfs_i.fd = -1; + } + ino->u.hostfs_i.mode |= mode; + if(ino->u.hostfs_i.mode & FMODE_READ) r = 1; + if(ino->u.hostfs_i.mode & FMODE_WRITE) w = 1; + if(w) r = 1; + name = dentry_name(file->f_dentry, 0); + if(name == NULL) return(-ENOMEM); + fd = open_file(name, r, w); + kfree(name); + if(fd < 0) return(fd); + file_hostfs_i(file)->fd = fd; + return(0); +} + +int hostfs_dir_open(struct inode *ino, struct file *file) +{ + return(0); +} + +int hostfs_dir_release(struct inode *ino, struct file *file) +{ + return(0); +} + +int hostfs_fsync(struct file *file, struct dentry *dentry, int datasync) +{ + return(0); +} + +int hostfs_fasync(int fd, struct file *file, int on) +{ + not_implemented(); + return(-EINVAL); +} + +static struct file_operations hostfs_file_fops = { + owner: NULL, + read: generic_file_read, + write: generic_file_write, + poll: hostfs_poll, + mmap: generic_file_mmap, + open: hostfs_file_open, + release: NULL, + fsync: hostfs_fsync, + fasync: hostfs_fasync +}; + +static struct file_operations hostfs_dir_fops = { + owner: NULL, + readdir: hostfs_readdir, + poll: hostfs_poll, + ioctl: hostfs_ioctl, + open: hostfs_dir_open, + release: hostfs_dir_release, + fsync: hostfs_fsync, + fasync: hostfs_fasync +}; + +int hostfs_writepage(struct page *page) +{ + struct address_space *mapping = page->mapping; + struct inode *inode = mapping->host; + char *buffer; + unsigned long long base; + int count = PAGE_CACHE_SIZE; + int end_index = inode->i_size >> PAGE_CACHE_SHIFT; + int err; + + if (page->index >= end_index) + count = inode->i_size & (PAGE_CACHE_SIZE-1); + + buffer = kmap(page); + base = ((unsigned long long) page->index) << PAGE_CACHE_SHIFT; + + err = write_file(inode->u.hostfs_i.fd, &base, buffer, count); + if(err != count){ + ClearPageUptodate(page); + goto out; + } + + if (base > inode->i_size) + inode->i_size = base; + + if (PageError(page)) + ClearPageError(page); + + out: + kunmap(page); + + UnlockPage(page); + return err; +} + +int hostfs_readpage(struct file *file, struct page *page) +{ + char *buffer; + long long start; + int err = 0; + + start = (long long) page->index << PAGE_CACHE_SHIFT; + buffer = kmap(page); + err = read_file(file_hostfs_i(file)->fd, &start, buffer, + PAGE_CACHE_SIZE); + if(err < 0) goto out; + + flush_dcache_page(page); + SetPageUptodate(page); + if (PageError(page)) ClearPageError(page); + err = 0; + out: + kunmap(page); + UnlockPage(page); + return(err); +} + +int hostfs_prepare_write(struct file *file, struct page *page, + unsigned int from, unsigned int to) +{ + char *buffer; + long long start, tmp; + int err; + + start = (long long) page->index << PAGE_CACHE_SHIFT; + buffer = kmap(page); + if(from != 0){ + tmp = start; + err = read_file(file_hostfs_i(file)->fd, &tmp, buffer, + from); + if(err < 0) goto out; + } + if(to != PAGE_CACHE_SIZE){ + start += to; + err = read_file(file_hostfs_i(file)->fd, &start, buffer + to, + PAGE_CACHE_SIZE - to); + if(err < 0) goto out; + } + err = 0; + out: + kunmap(page); + return(err); +} + +int hostfs_commit_write(struct file *file, struct page *page, unsigned from, + unsigned to) +{ + struct address_space *mapping = page->mapping; + struct inode *inode = mapping->host; + char *buffer; + long long start; + int err = 0; + + start = (long long) (page->index << PAGE_CACHE_SHIFT) + from; + buffer = kmap(page); + err = write_file(file_hostfs_i(file)->fd, &start, buffer + from, + to - from); + if(err > 0) err = 0; + if(!err && (start > inode->i_size)) + inode->i_size = start; + + kunmap(page); + return(err); +} + +static struct address_space_operations hostfs_aops = { + writepage: hostfs_writepage, + readpage: hostfs_readpage, + prepare_write: hostfs_prepare_write, + commit_write: hostfs_commit_write +}; + +static struct inode *get_inode(struct super_block *sb, struct dentry *dentry, + int *error) +{ + struct inode *inode; + char *name; + int type, err = 0, rdev; + + inode = get_empty_inode(); + if(inode == NULL) return(NULL); + inode->u.hostfs_i.host_filename = NULL; + inode->u.hostfs_i.fd = -1; + inode->u.hostfs_i.mode = 0; + if(error) *error = 0; + insert_inode_hash(inode); + if(dentry){ + name = dentry_name(dentry, 0); + if(name == NULL){ + err = -ENOMEM; + goto out; + } + type = file_type(name, &rdev); + kfree(name); + } + else type = HOSTFS_DIR; + inode->i_sb = sb; + + if(type == HOSTFS_SYMLINK) + inode->i_op = &page_symlink_inode_operations; + else inode->i_op = &hostfs_iops; + + if(type == HOSTFS_DIR) inode->i_fop = &hostfs_dir_fops; + else inode->i_fop = &hostfs_file_fops; + + if(type == HOSTFS_SYMLINK) inode->i_mapping->a_ops = &hostfs_link_aops; + else inode->i_mapping->a_ops = &hostfs_aops; + + switch (type) { + case HOSTFS_CHARDEV: + init_special_inode(inode, S_IFCHR, rdev); + break; + case HOSTFS_BLOCDEV: + init_special_inode(inode, S_IFBLK, rdev); + break; + case HOSTFS_FIFO: + init_special_inode(inode, S_IFIFO, 0); + break; + case HOSTFS_SOCK: + init_special_inode(inode, S_IFSOCK, 0); + break; + } + + return(inode); + out: + iput(inode); + if(error) *error = err; + return(NULL); +} + +int hostfs_create(struct inode *dir, struct dentry *dentry, int mode) +{ + struct inode *inode; + char *name; + int error; + + inode = get_inode(dir->i_sb, dentry, &error); + if(error) return(error); + name = dentry_name(dentry, 0); + if(name == NULL){ + iput(inode); + return(-ENOMEM); + } + error = file_create(name, + mode | S_IRUSR, mode | S_IWUSR, mode | S_IXUSR, + mode | S_IRGRP, mode | S_IWGRP, mode | S_IXGRP, + mode | S_IROTH, mode | S_IWOTH, mode | S_IXOTH); + if(!error) error = read_name(inode, name); + kfree(name); + if(error){ + iput(inode); + return(error); + } + d_instantiate(dentry, inode); + return(0); +} + +struct dentry *hostfs_lookup(struct inode *ino, struct dentry *dentry) +{ + struct inode *inode; + char *name; + int error; + + inode = get_inode(ino->i_sb, dentry, &error); + if(error != 0) return(ERR_PTR(error)); + name = dentry_name(dentry, 0); + if(name == NULL) return(ERR_PTR(-ENOMEM)); + error = read_name(inode, name); + kfree(name); + if(error){ + iput(inode); + if(error == -ENOENT) inode = NULL; + else return(ERR_PTR(error)); + } + d_add(dentry, inode); + dentry->d_op = &hostfs_dentry_ops; + return(NULL); +} + +static char *inode_dentry_name(struct inode *ino, struct dentry *dentry) +{ + char *file; + int len; + + file = inode_name(ino, dentry->d_name.len + 1); + if(file == NULL) return(NULL); + strcat(file, "/"); + len = strlen(file); + strncat(file, dentry->d_name.name, dentry->d_name.len); + file[len + dentry->d_name.len] = '\0'; + return(file); +} + +int hostfs_link(struct dentry *to, struct inode *ino, struct dentry *from) +{ + char *from_name, *to_name; + int err; + + if((from_name = inode_dentry_name(ino, from)) == NULL) + return(-ENOMEM); + to_name = dentry_name(to, 0); + if(to_name == NULL){ + kfree(from_name); + return(-ENOMEM); + } + err = link_file(to_name, from_name); + kfree(from_name); + kfree(to_name); + return(err); +} + +int hostfs_unlink(struct inode *ino, struct dentry *dentry) +{ + char *file; + int err; + + if((file = inode_dentry_name(ino, dentry)) == NULL) return(-ENOMEM); + err = unlink_file(file); + kfree(file); + return(err); +} + +int hostfs_symlink(struct inode *ino, struct dentry *dentry, const char *to) +{ + char *file; + int err; + + if((file = inode_dentry_name(ino, dentry)) == NULL) return(-ENOMEM); + err = make_symlink(file, to); + kfree(file); + return(err); +} + +int hostfs_mkdir(struct inode *ino, struct dentry *dentry, int mode) +{ + char *file; + int err; + + if((file = inode_dentry_name(ino, dentry)) == NULL) return(-ENOMEM); + err = do_mkdir(file, mode); + kfree(file); + return(err); +} + +int hostfs_rmdir(struct inode *ino, struct dentry *dentry) +{ + char *file; + int err; + + if((file = inode_dentry_name(ino, dentry)) == NULL) return(-ENOMEM); + err = do_rmdir(file); + kfree(file); + return(err); +} + +int hostfs_mknod(struct inode *ino, struct dentry *dentry, int mode, int dev) +{ + char *file; + int err; + + if((file = inode_dentry_name(ino, dentry)) == NULL) return(-ENOMEM); + err = do_mknod(file, mode, dev); + kfree(file); + return(err); +} + +int hostfs_rename(struct inode *from_ino, struct dentry *from, + struct inode *to_ino, struct dentry *to) +{ + char *from_name, *to_name; + int err; + + if((from_name = inode_dentry_name(from_ino, from)) == NULL) + return(-ENOMEM); + if((to_name = inode_dentry_name(to_ino, to)) == NULL){ + kfree(from_name); + return(-ENOMEM); + } + err = rename_file(from_name, to_name); + kfree(from_name); + kfree(to_name); + return(err); +} + +void hostfs_truncate(struct inode *ino) +{ + not_implemented(); +} + +int hostfs_permission(struct inode *ino, int desired) +{ + char *name; + int r = 0, w = 0, x = 0, err; + + if(desired & MAY_READ) r = 1; + if(desired & MAY_WRITE) w = 1; + if(desired & MAY_EXEC) x = 1; + name = inode_name(ino, 0); + if(name == NULL) return(-ENOMEM); + err = access_file(name, r, w, x); + kfree(name); + if(!err) err = vfs_permission(ino, desired); + return(err); +} + +int hostfs_setattr(struct dentry *dentry, struct iattr *attr) +{ + struct hostfs_iattr attrs; + char *name; + int err; + + attrs.ia_valid = 0; + if(attr->ia_valid & ATTR_MODE){ + attrs.ia_valid |= HOSTFS_ATTR_MODE; + attrs.ia_mode = attr->ia_mode; + } + if(attr->ia_valid & ATTR_UID){ + attrs.ia_valid |= HOSTFS_ATTR_UID; + attrs.ia_uid = attr->ia_uid; + } + if(attr->ia_valid & ATTR_GID){ + attrs.ia_valid |= HOSTFS_ATTR_GID; + attrs.ia_gid = attr->ia_gid; + } + if(attr->ia_valid & ATTR_SIZE){ + attrs.ia_valid |= HOSTFS_ATTR_SIZE; + attrs.ia_size = attr->ia_size; + } + if(attr->ia_valid & ATTR_ATIME){ + attrs.ia_valid |= HOSTFS_ATTR_ATIME; + attrs.ia_atime = attr->ia_atime; + } + if(attr->ia_valid & ATTR_MTIME){ + attrs.ia_valid |= HOSTFS_ATTR_MTIME; + attrs.ia_mtime = attr->ia_mtime; + } + if(attr->ia_valid & ATTR_CTIME){ + attrs.ia_valid |= HOSTFS_ATTR_CTIME; + attrs.ia_ctime = attr->ia_ctime; + } + if(attr->ia_valid & ATTR_ATIME_SET){ + attrs.ia_valid |= HOSTFS_ATTR_ATIME_SET; + } + if(attr->ia_valid & ATTR_MTIME_SET){ + attrs.ia_valid |= HOSTFS_ATTR_MTIME_SET; + } + name = dentry_name(dentry, 0); + if(name == NULL) return(-ENOMEM); + err = set_attr(name, &attrs); + kfree(name); + return(err); +} + +int hostfs_getattr(struct dentry *dentry, struct iattr *attr) +{ + not_implemented(); + return(-EINVAL); +} + +static struct inode_operations hostfs_iops = { + create: hostfs_create, + lookup: hostfs_lookup, + link: hostfs_link, + unlink: hostfs_unlink, + symlink: hostfs_symlink, + mkdir: hostfs_mkdir, + rmdir: hostfs_rmdir, + mknod: hostfs_mknod, + rename: hostfs_rename, + truncate: hostfs_truncate, + permission: hostfs_permission, + setattr: hostfs_setattr, + getattr: hostfs_getattr, +}; + +int hostfs_link_readpage(struct file *file, struct page *page) +{ + char *buffer, *name; + long long start; + int err; + + start = page->index << PAGE_CACHE_SHIFT; + buffer = kmap(page); + name = inode_name(page->mapping->host, 0); + if(name == NULL) return(-ENOMEM); + err = do_readlink(name, buffer, PAGE_CACHE_SIZE); + kfree(name); + if(err == 0){ + flush_dcache_page(page); + SetPageUptodate(page); + if (PageError(page)) ClearPageError(page); + } + kunmap(page); + UnlockPage(page); + return(err); +} + +static struct address_space_operations hostfs_link_aops = { + readpage: hostfs_link_readpage, +}; + +static struct super_block *hostfs_read_super_common(struct super_block *sb, + char *data) +{ + struct inode * root_inode; + char *name; + + sb->s_blocksize = 1024; + sb->s_blocksize_bits = 10; + sb->s_magic = HOSTFS_SUPER_MAGIC; + sb->s_op = &hostfs_sbops; + if((data == NULL) || (*((char *) data) == '\0')) data = root_ino; + name = kmalloc(strlen(data) + 1, GFP_KERNEL); + if(name == NULL) return(NULL); + strcpy(name, data); + root_inode = get_inode(sb, NULL, NULL); + if(root_inode == NULL){ + kfree(name); + return(NULL); + } + root_inode->u.hostfs_i.host_filename = name; + sb->s_root = d_alloc_root(root_inode); + if(read_inode(root_inode)){ + iput(root_inode); + return(NULL); + } + return(sb); +} + +struct super_block *hostfs_read_super(struct super_block *sb, void *data, + int silent) +{ + return(hostfs_read_super_common(sb, data)); +} + +struct super_block *hostfs_root_read_super(struct super_block *sb, void *data, + int silent) +{ + struct buffer_head * bh; + struct super_block *ret = NULL; + kdev_t dev = sb->s_dev; + int blocksize = get_hardsect_size(dev); + + if(blocksize == 0) blocksize = BLOCK_SIZE; + set_blocksize (dev, blocksize); + if(!(bh = bread (dev, 0, blocksize))) return NULL; + if(strncmp(bh->b_data, "HOSTFS:", strlen("HOSTFS:"))) goto out; + ret = hostfs_read_super_common(sb, bh->b_data + strlen("HOSTFS:")); + out: + brelse (bh); + return(ret); +} + +DECLARE_FSTYPE(hostfs_type, "hostfs", hostfs_read_super, 0); +DECLARE_FSTYPE_DEV(hostfs_root_type, "root-hostfs", hostfs_root_read_super); + +static int __init init_hostfs(void) +{ + return(register_filesystem(&hostfs_type) || + register_filesystem(&hostfs_root_type)); +} + +static void __exit exit_hostfs(void) +{ + unregister_filesystem(&hostfs_type); + unregister_filesystem(&hostfs_root_type); +} + +module_init(init_hostfs) +module_exit(exit_hostfs) + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/fs/hostfs/hostfs_user.c linux_umopenmosix/arch/um/fs/hostfs/hostfs_user.c --- linux-2.4.17/arch/um/fs/hostfs/hostfs_user.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/fs/hostfs/hostfs_user.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,337 @@ +/* + * Copyright (C) 2000 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "hostfs.h" +#include "kern_util.h" +#include "user.h" + +int stat_file(const char *path, int *dev_out, unsigned long long *inode_out, + int *mode_out, int *nlink_out, int *uid_out, int *gid_out, + unsigned long long *size_out, unsigned long *atime_out, + unsigned long *mtime_out, unsigned long *ctime_out, + int *blksize_out, unsigned long long *blocks_out) +{ + struct stat64 buf; + + if(lstat64(path, &buf) < 0) + return(-errno); + if(dev_out != NULL) *dev_out = buf.st_dev; + + /* See the Makefile for why STAT64_INO_FIELD is passed in + * by the build + */ + if(inode_out != NULL) *inode_out = buf.STAT64_INO_FIELD; + if(mode_out != NULL) *mode_out = buf.st_mode; + if(nlink_out != NULL) *nlink_out = buf.st_nlink; + if(uid_out != NULL) *uid_out = buf.st_uid; + if(gid_out != NULL) *gid_out = buf.st_gid; + if(size_out != NULL) *size_out = buf.st_size; + if(atime_out != NULL) *atime_out = buf.st_atime; + if(mtime_out != NULL) *mtime_out = buf.st_mtime; + if(ctime_out != NULL) *ctime_out = buf.st_ctime; + if(blksize_out != NULL) *blksize_out = buf.st_blksize; + if(blocks_out != NULL) *blocks_out = buf.st_blocks; + return(0); +} + +int file_type(const char *path, int *rdev) +{ + struct stat64 buf; + + if(lstat64(path, &buf) < 0) return(-errno); + *rdev = buf.st_rdev; + if(S_ISDIR(buf.st_mode)) return(HOSTFS_DIR); + else if(S_ISLNK(buf.st_mode)) return(HOSTFS_SYMLINK); + else if(S_ISCHR(buf.st_mode)) return(HOSTFS_CHARDEV); + else if(S_ISBLK(buf.st_mode)) return(HOSTFS_BLOCDEV); + else if(S_ISFIFO(buf.st_mode))return(HOSTFS_FIFO); + else if(S_ISSOCK(buf.st_mode))return(HOSTFS_SOCK); + + else return(HOSTFS_FILE); +} + +int access_file(char *path, int r, int w, int x) +{ + int mode = 0; + + if(r) mode = R_OK; + if(w) mode |= W_OK; + if(x) mode |= X_OK; + if(access(path, mode) != 0) return(-errno); + else return(0); +} + +int open_file(char *path, int r, int w) +{ + int mode = 0, fd; + + if(r && !w) mode = O_RDONLY; + else if(!r && w) mode = O_WRONLY; + else if(r && w) mode = O_RDWR; + else panic("Impossible mode in open_file"); + fd = open64(path, mode); + if(fd < 0) return(-errno); + else return(fd); +} + +void *open_dir(char *path, int *err_out) +{ + DIR *dir; + + dir = opendir(path); + *err_out = errno; + if(dir == NULL) return(NULL); + return(dir); +} + +char *read_dir(void *stream, unsigned long long *pos, + unsigned long long *ino_out, int *len_out) +{ + DIR *dir = stream; + struct dirent *ent; + + seekdir(dir, *pos); + ent = readdir(dir); + if(ent == NULL) return(NULL); + *len_out = strlen(ent->d_name); + *ino_out = ent->d_ino; + *pos = telldir(dir); + return(ent->d_name); +} + +int read_file(int fd, unsigned long long *offset, char *buf, int len) +{ + int n; + + n = pread64(fd, buf, len, *offset); + if(n < 0) return(-errno); + *offset += n; + return(n); +} + +int write_file(int fd, unsigned long long *offset, const char *buf, int len) +{ + int n; + + n = pwrite64(fd, buf, len, *offset); + if(n < 0) return(-errno); + *offset += n; + return(n); +} + +int lseek_file(int fd, long long offset, int whence) +{ + int ret; + + ret = lseek64(fd, offset, whence); + if(ret < 0) return(-errno); + return(0); +} + +void close_file(void *stream) +{ + close(*((int *) stream)); +} + +void close_dir(void *stream) +{ + closedir(stream); +} + +int file_create(char *name, int ur, int uw, int ux, int gr, + int gw, int gx, int or, int ow, int ox) +{ + int mode, fd; + + mode = 0; + mode |= ur ? S_IRUSR : 0; + mode |= uw ? S_IWUSR : 0; + mode |= ux ? S_IXUSR : 0; + mode |= gr ? S_IRGRP : 0; + mode |= gw ? S_IWGRP : 0; + mode |= gx ? S_IXGRP : 0; + mode |= or ? S_IROTH : 0; + mode |= ow ? S_IWOTH : 0; + mode |= ox ? S_IXOTH : 0; + fd = open64(name, O_CREAT, mode); + if(fd < 0) return(-errno); + close(fd); + return(0); +} + +int set_attr(const char *file, struct hostfs_iattr *attrs) +{ + struct utimbuf buf; + int err, ma; + + if(attrs->ia_valid & HOSTFS_ATTR_MODE){ + if(chmod(file, attrs->ia_mode) != 0) return(-errno); + } + if(attrs->ia_valid & HOSTFS_ATTR_UID){ + if(chown(file, attrs->ia_uid, -1)) return(-errno); + } + if(attrs->ia_valid & HOSTFS_ATTR_GID){ + if(chown(file, -1, attrs->ia_gid)) return(-errno); + } + if(attrs->ia_valid & HOSTFS_ATTR_SIZE){ + if(truncate(file, attrs->ia_size)) return(-errno); + } + ma = HOSTFS_ATTR_ATIME_SET | HOSTFS_ATTR_MTIME_SET; + if((attrs->ia_valid & ma) == ma){ + buf.actime = attrs->ia_atime; + buf.modtime = attrs->ia_mtime; + if(utime(file, &buf) != 0) return(-errno); + } + else { + if(attrs->ia_valid & HOSTFS_ATTR_ATIME_SET){ + err = stat_file(file, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, &buf.modtime, NULL, + NULL, NULL); + if(err != 0) return(err); + buf.actime = attrs->ia_atime; + if(utime(file, &buf) != 0) return(-errno); + } + if(attrs->ia_valid & HOSTFS_ATTR_MTIME_SET){ + err = stat_file(file, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, &buf.actime, NULL, NULL, + NULL, NULL); + if(err != 0) return(err); + buf.modtime = attrs->ia_mtime; + if(utime(file, &buf) != 0) return(-errno); + } + } + if(attrs->ia_valid & HOSTFS_ATTR_CTIME) ; + if(attrs->ia_valid & (HOSTFS_ATTR_ATIME | HOSTFS_ATTR_MTIME)){ + err = stat_file(file, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, &attrs->ia_atime, &attrs->ia_mtime, + NULL, NULL, NULL); + if(err != 0) return(err); + } + return(0); +} + +int make_symlink(const char *from, const char *to) +{ + int err; + + err = symlink(to, from); + if(err) return(-errno); + return(0); +} + +int unlink_file(const char *file) +{ + int err; + + err = unlink(file); + if(err) return(-errno); + return(0); +} + +int do_mkdir(const char *file, int mode) +{ + int err; + + err = mkdir(file, mode); + if(err) return(-errno); + return(0); +} + +int do_rmdir(const char *file) +{ + int err; + + err = rmdir(file); + if(err) return(-errno); + return(0); +} + +int do_mknod(const char *file, int mode, int dev) +{ + int err; + + err = mknod(file, mode, dev); + if(err) return(-errno); + return(0); +} + +int link_file(const char *to, const char *from) +{ + int err; + + err = link(to, from); + if(err) return(-errno); + return(0); +} + +int do_readlink(char *file, char *buf, int size) +{ + int err; + + err = readlink(file, buf, size); + if(err < 0) return(-errno); + if(err < size) buf[err] = '\0'; + return(0); +} + +int rename_file(char *from, char *to) +{ + int err; + + err = rename(from, to); + if(err < 0) return(-errno); + return(0); +} + +int do_statfs(char *root, long *bsize_out, long long *blocks_out, + long long *bfree_out, long long *bavail_out, + long long *files_out, long long *ffree_out, + void *fsid_out, int fsid_size, long *namelen_out, + long *spare_out) +{ + struct statfs64 buf; + int err; + + err = statfs64(root, &buf); + if(err < 0) return(-errno); + *bsize_out = buf.f_bsize; + *blocks_out = buf.f_blocks; + *bfree_out = buf.f_bfree; + *bavail_out = buf.f_bavail; + *files_out = buf.f_files; + *ffree_out = buf.f_ffree; + memcpy(fsid_out, &buf.f_fsid, + sizeof(buf.f_fsid) > fsid_size ? fsid_size : + sizeof(buf.f_fsid)); + *namelen_out = buf.f_namelen; + spare_out[0] = buf.f_spare[0]; + spare_out[1] = buf.f_spare[1]; + spare_out[2] = buf.f_spare[2]; + spare_out[3] = buf.f_spare[3]; + spare_out[4] = buf.f_spare[4]; + spare_out[5] = buf.f_spare[5]; + return(0); +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/include/2_5compat.h linux_umopenmosix/arch/um/include/2_5compat.h --- linux-2.4.17/arch/um/include/2_5compat.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/include/2_5compat.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2001 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#ifndef __2_5_COMPAT_H__ +#define __2_5_COMPAT_H__ + +#include "linux/version.h" + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0) + +#define major(dev) MAJOR(dev) +#define minor(dev) MINOR(dev) +#define kdev_same(dev1, dev2) ((dev1) == (dev2)) +#define mk_kdev(maj, min) MKDEV(maj, min) +#define INIT_CONSOLE(dev_name, write_proc, device_proc, setup_proc, f) { \ + name : dev_name, \ + write : write_proc, \ + read : NULL, \ + device : device_proc, \ + wait_key : NULL, \ + unblank : NULL, \ + setup : setup_proc, \ + flags : f, \ + index : -1, \ + cflag : 0, \ + next : NULL \ +} + +#define INIT_GENDISK(maj, name, parts, bsizes, max, blops) { \ + major : maj, \ + major_name : name, \ + minor_shift : 0, \ + max_p : 1, \ + part : parts, \ + sizes : bsizes, \ + nr_real : max, \ + real_devices : NULL, \ + next : NULL, \ + fops : blops, \ + de_arr : NULL, \ + flags : 0 \ +} + +#define INIT_QUEUE(queue, request, lock) blk_init_queue(queue, request) + +#define ELV_NOOP ELEVATOR_NOOP +#define INIT_ELV(queue, elv) elevator_init(elv, ELV_NOOP) + +#define REQUEST_LOCK io_request_lock + +#define INIT_HARDSECT(arr, maj, sizes) arr[maj] = sizes + +#define IS_WRITE(req) ((req)->cmd == WRITE) +#define IS_READ(req) ((req)->cmd == READ) + +#define CPU(task) ((task)->processor) + +#define yield() do { current->policy |= SCHED_YIELD; schedule(); } while(0) + +#define SET_PRI(task) \ + do { (task)->nice = 20; (task)->counter = -100; } while(0); + +#else + +#define INIT_CONSOLE(dev_name, write_proc, device_proc, setup_proc, f) { \ + name : dev_name, \ + write : write_proc, \ + read : NULL, \ + device : device_proc, \ + setup : setup_proc, \ + flags : f, \ + index : -1, \ + cflag : 0, \ + next : NULL \ +} + +#define INIT_GENDISK(maj, name, parts, bsizes, max, blops) { \ + major : maj, \ + major_name : name, \ + minor_shift : 0, \ + part : parts, \ + sizes : bsizes, \ + nr_real : max, \ + next : NULL, \ + fops : blops, \ + de_arr : NULL, \ + flags : 0 \ +} + +#define INIT_QUEUE(queue, request, lock) blk_init_queue(queue, request, lock) + +#define ELV_NOOP elevator_noop +#define INIT_ELV(queue, elv) elevator_init(queue, elv, ELV_NOOP) + +#define REQUEST_LOCK ubd_lock + +#define INIT_HARDSECT(arr, maj, sizes) + +#define IS_WRITE(req) (rq_data_dir(req) == WRITE) +#define IS_READ(req) (rq_data_dir(req) == READ) + +#define CPU(task) ((task)->cpu) + +#define SET_PRI(task) do ; while(0) + +#endif + +#endif + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/include/chan_kern.h linux_umopenmosix/arch/um/include/chan_kern.h --- linux-2.4.17/arch/um/include/chan_kern.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/include/chan_kern.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2000, 2001 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#ifndef __CHAN_KERN_H__ +#define __CHAN_KERN_H__ + +#include "linux/tty.h" +#include "linux/list.h" +#include "chan_user.h" + +struct chan { + struct list_head list; + unsigned int primary:1; + unsigned int input:1; + unsigned int output:1; + int opened; + int fd; + enum chan_init_pri pri; + struct chan_ops *ops; + void *data; +}; + +extern void chan_interrupt(struct list_head *chans, struct tty_struct *tty); +extern int parse_chan_pair(char *str, struct list_head *chans, int pri, + int device, struct chan_opts *opts); +extern int open_chan(struct list_head *chans); +extern int write_chan(struct list_head *chans, const char *buf, int len); +extern int console_write_chan(struct list_head *chans, const char *buf, + int len); +extern void close_chan(struct list_head *chans); +extern void enable_chan(struct list_head *chans, + int (*irq_setup)(int fd, int input, int output, + void *data), + void *data); +extern void disable_chan(struct list_head *chans); +extern int chan_window_size(struct list_head *chans, + unsigned short *rows_out, + unsigned short *cols_out); +extern int chan_out_fd(struct list_head *chans); + +#endif + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/include/chan_user.h linux_umopenmosix/arch/um/include/chan_user.h --- linux-2.4.17/arch/um/include/chan_user.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/include/chan_user.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2000, 2001 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#ifndef __CHAN_USER_H__ +#define __CHAN_USER_H__ + +#include "init.h" + +struct chan_opts { + void (*announce)(char *dev_name, int dev); + char *xterm_title; + int raw; +}; + +enum chan_init_pri { INIT_STATIC, INIT_ALL, INIT_ONE }; + +struct chan_ops { + void *(*init)(char *, int, struct chan_opts *); + int (*open)(int, int, void *); + void (*close)(int, void *); + int (*read)(int, void *); + int (*write)(int, const char *, int, void *); + int (*console_write)(int, const char *, int, void *); + int (*window_size)(int, void *, unsigned short *, unsigned short *); + void (*free)(void *); +}; + +extern struct chan_ops pty_ops, pts_ops, tty_ops, xterm_ops, fd_ops, + port_ops; + +extern void generic_close(int fd, void *unused); +extern int generic_read(int fd, void *unused); +extern int generic_write(int fd, const char *buf, int n, void *unused); +extern int generic_console_write(int fd, const char *buf, int n, void *state); +extern int generic_window_size(int fd, void *unused, unsigned short *rows_out, + unsigned short *cols_out); +extern void generic_free(void *data); +extern int getmaster(char *line); +extern void run_winch_handlers(void); + +#define __channel_help(fn, prefix) \ +__uml_help(fn, prefix "[0-9]*=\n" \ +" Attach a console or serial line to a host channel. See\n" \ +" http://user-mode-linux.sourceforge.net/input.html for a complete\n" \ +" description of this switch.\n\n" \ +); + +#endif + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/include/debug.h linux_umopenmosix/arch/um/include/debug.h --- linux-2.4.17/arch/um/include/debug.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/include/debug.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com) and + * Lars Brinkhoff. + * Licensed under the GPL + */ +#ifndef __DEBUG_H +#define __DEBUG_H + +extern int debugger_proxy(int status, pid_t pid); +extern void child_proxy(pid_t pid, int status); +extern void init_proxy (pid_t pid, int waiting, int status); +extern int start_debugger(char *prog, int startup, int stop, int *debugger_fd); +extern void fake_child_exit(void); + +#endif + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/include/frame.h linux_umopenmosix/arch/um/include/frame.h --- linux-2.4.17/arch/um/include/frame.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/include/frame.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2002 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#ifndef __FRAME_H_ +#define __FRAME_H_ + +#include "sysdep/frame.h" + +struct sc_frame { + void *data; + int len; + int sig_index; + int sc_index; + int sr_index; + int sr_relative; + int sp_index; + struct arch_frame_data arch; +}; + +extern struct sc_frame signal_frame_sc; + +struct si_frame { + void *data; + int len; + int sig_index; + int sip_index; + int si_index; + int sr_index; + int sr_relative; + int sp_index; +}; + +extern struct si_frame signal_frame_si; + +extern void capture_signal_stack(void); +extern void set_sc_ip_sp(void *sc_ptr, unsigned long ip, unsigned long sp); + +#endif + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/include/frame_kern.h linux_umopenmosix/arch/um/include/frame_kern.h --- linux-2.4.17/arch/um/include/frame_kern.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/include/frame_kern.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2002 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#ifndef __FRAME_KERN_H_ +#define __FRAME_KERN_H_ + +extern int setup_signal_stack_sc(unsigned long stack_top, int sig, + unsigned long handler, + void (*restorer)(void), + struct sys_pt_regs *regs, void *sc, + void *context_sc); +extern int setup_signal_stack_si(unsigned long stack_top, int sig, + unsigned long handler, + void (*restorer)(void), + struct sys_pt_regs *regs, siginfo_t *info); + +#endif + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/include/hostaudio.h linux_umopenmosix/arch/um/include/hostaudio.h --- linux-2.4.17/arch/um/include/hostaudio.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/include/hostaudio.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2002 Steve Schmidtke + * Licensed under the GPL + */ + +#ifndef HOSTAUDIO_H +#define HOSTAUDIO_H + +#define HOSTAUDIO_DEV_DSP "/dev/sound/dsp" +#define HOSTAUDIO_DEV_MIXER "/dev/sound/mixer" + +struct hostaudio_state { + int fd; +}; + +struct hostmixer_state { + int fd; +}; + +/* UML user-side protoypes */ +extern ssize_t hostaudio_read_user(struct hostaudio_state *state, char *buffer, + size_t count, loff_t *ppos); +extern ssize_t hostaudio_write_user(struct hostaudio_state *state, + const char *buffer, size_t count, + loff_t *ppos); +extern int hostaudio_ioctl_user(struct hostaudio_state *state, + unsigned int cmd, unsigned long arg); +extern int hostaudio_open_user(struct hostaudio_state *state, int r, int w, + char *dsp); +extern int hostaudio_release_user(struct hostaudio_state *state); +extern int hostmixer_ioctl_mixdev_user(struct hostmixer_state *state, + unsigned int cmd, unsigned long arg); +extern int hostmixer_open_mixdev_user(struct hostmixer_state *state, int r, + int w, char *mixer); +extern int hostmixer_release_mixdev_user(struct hostmixer_state *state); + +#endif /* HOSTAUDIO_H */ + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/include/init.h linux_umopenmosix/arch/um/include/init.h --- linux-2.4.17/arch/um/include/init.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/include/init.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,106 @@ +#ifndef _LINUX_UML_INIT_H +#define _LINUX_UML_INIT_H + +/* These macros are used to mark some functions or + * initialized data (doesn't apply to uninitialized data) + * as `initialization' functions. The kernel can take this + * as hint that the function is used only during the initialization + * phase and free up used memory resources after + * + * Usage: + * For functions: + * + * You should add __init immediately before the function name, like: + * + * static void __init initme(int x, int y) + * { + * extern int z; z = x * y; + * } + * + * If the function has a prototype somewhere, you can also add + * __init between closing brace of the prototype and semicolon: + * + * extern int initialize_foobar_device(int, int, int) __init; + * + * For initialized data: + * You should insert __initdata between the variable name and equal + * sign followed by value, e.g.: + * + * static int init_variable __initdata = 0; + * static char linux_logo[] __initdata = { 0x32, 0x36, ... }; + * + * Don't forget to initialize data not at file scope, i.e. within a function, + * as gcc otherwise puts the data into the bss section and not into the init + * section. + * + * Also note, that this data cannot be "const". + */ + +#ifndef _LINUX_INIT_H +typedef int (*initcall_t)(void); +typedef void (*exitcall_t)(void); + +#define __init __attribute__ ((__section__ (".text.init"))) +#define __exit __attribute__ ((unused, __section__(".text.exit"))) +#define __initdata __attribute__ ((__section__ (".data.init"))) + +#endif +struct uml_param { + const char *str; + int (*setup_func)(char *, int *); +}; + +extern initcall_t __uml_initcall_start, __uml_initcall_end; +extern initcall_t __uml_postsetup_start, __uml_postsetup_end; +extern const char *__uml_help_start, *__uml_help_end; + +#define __uml_initcall(fn) \ + static initcall_t __uml_initcall_##fn __uml_init_call = fn + +#define __uml_exitcall(fn) \ + static exitcall_t __uml_exitcall_##fn __uml_exit_call = fn + +extern struct uml_param __uml_setup_start, __uml_setup_end; + +#define __uml_postsetup(fn) \ + static initcall_t __uml_postsetup_##fn __uml_postsetup_call = fn + +#define __non_empty_string(dummyname,string) \ + struct __uml_non_empty_string_struct_##dummyname \ + { \ + char _string[sizeof(string)-2]; \ + } + +#define __uml_setup(str, fn, help...) \ + __non_empty_string(fn ##_setup, str); \ + __uml_help(fn, help); \ + static char __uml_setup_str_##fn[] __initdata = str; \ + static struct uml_param __uml_setup_##fn __uml_init_setup = { __uml_setup_str_##fn, fn } + +#define __uml_help(fn, help...) \ + __non_empty_string(fn ##__help, help); \ + static char __uml_help_str_##fn[] __initdata = help; \ + static const char *__uml_help_##fn __uml_setup_help = __uml_help_str_##fn + +/* + * Mark functions and data as being only used at initialization + * or exit time. + */ +#define __uml_init_setup __attribute__ ((unused,__section__ (".uml.setup.init"))) +#define __uml_setup_help __attribute__ ((unused,__section__ (".uml.help.init"))) +#define __uml_init_call __attribute__ ((unused,__section__ (".uml.initcall.init"))) +#define __uml_postsetup_call __attribute__ ((unused,__section__ (".uml.postsetup.init"))) +#define __uml_exit_call __attribute__ ((unused,__section__ (".uml.exitcall.exit"))) + +#endif /* _LINUX_UML_INIT_H */ + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/include/initrd.h linux_umopenmosix/arch/um/include/initrd.h --- linux-2.4.17/arch/um/include/initrd.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/include/initrd.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2000 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#ifndef __INITRD_USER_H__ +#define __INITRD_USER_H__ + +extern int load_initrd(char *filename, void *buf, int size); + +#endif + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/include/irq_user.h linux_umopenmosix/arch/um/include/irq_user.h --- linux-2.4.17/arch/um/include/irq_user.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/include/irq_user.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2001 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#ifndef __IRQ_USER_H__ +#define __IRQ_USER_H__ + +extern void sigio_handler(int sig, void *sc, int usermode); +extern int activate_fd(int irq, int fd, void *dev_id); +extern void free_irq_by_dev(void *dev_id); +extern void free_irq_by_fd(int fd); +extern void reactivate_fd(int fd); +extern void forward_interrupts(int pid); +extern void init_irq_signals(int on_sigstack); +extern void forward_ipi(int fd, int pid); + +#endif + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/include/kern.h linux_umopenmosix/arch/um/include/kern.h --- linux-2.4.17/arch/um/include/kern.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/include/kern.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2000 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#ifndef __KERN_H__ +#define __KERN_H__ + +/* These are all user-mode things which are convenient to call directly + * from kernel code and for which writing a wrapper is too much of a pain. + * The regular include files can't be included because this file is included + * only into kernel code, and user-space includes conflict with kernel + * includes. + */ + +extern int errno; + +extern int getpid(void); +extern int clone(int (*proc)(void *), void *sp, int flags, void *data); +extern int sleep(int); +extern int printf(char *fmt, ...); +extern char *strerror(int errnum); +extern char *ptsname(int __fd); +extern int munmap(void *, int); +extern void *sbrk(int increment); +extern void *malloc(int size); +extern void perror(char *err); +extern int kill(int pid, int sig); +extern int getuid(void); +extern int pause(void); +extern int write(int, const void *, int); +extern int exit(int); +extern int close(int); +extern int read(unsigned int, char *, int); +extern int pipe(int *); + +#endif + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/include/kern_util.h linux_umopenmosix/arch/um/include/kern_util.h --- linux-2.4.17/arch/um/include/kern_util.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/include/kern_util.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,126 @@ +/* + * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#ifndef __KERN_UTIL_H__ +#define __KERN_UTIL_H__ + +#include "sysdep/ptrace.h" + +extern int ncpus; +extern char *linux_prog; +extern char *gdb_init; +extern int kmalloc_ok; + +#define ROUND_DOWN(addr) ((void *)(((unsigned long) addr) & PAGE_MASK)) +#define ROUND_UP(addr) ROUND_DOWN(((unsigned long) addr) + PAGE_SIZE - 1) + +extern int kernel_fork(unsigned long flags, int (*fn)(void *), void * arg); +extern unsigned long stack_sp(unsigned long page); +extern int kernel_thread_proc(void *data); +extern long execute_syscall(struct sys_pt_regs regs); +extern void syscall_segv(int sig); +extern int current_pid(void); +extern void set_init_pid(int pid); +extern unsigned long alloc_stack(void); +extern int do_signal(int error); +extern int is_stack_fault(unsigned long sp); +extern unsigned long segv(unsigned long address, unsigned long ip, + int is_write, int is_user); +extern int set_user_mode(void *task, int restore_state, int protect_mem); +extern void syscall_ready(void); +extern void set_tracing(void *t, int tracing); +extern int is_tracing(void *task); +extern int segv_syscall(void); +extern void ret_from_sys_call(void); +extern void kern_finish_exec(void *task, int new_pid, unsigned long stack); +extern int page_size(void); +extern int page_mask(void); +extern int need_finish_fork(void); +extern int do_proc_op(void *t, int proc_id); +extern void free_stack(unsigned long stack); +extern void add_input_request(int op, void (*proc)(int), void *arg); +extern int sys_execve(char *file, char **argv, char **env); +extern char *current_cmd(void); +extern void timer_handler(int sig, void *sc, int usermode); +extern int set_signals(int enable); +extern void force_sigbus(void); +extern int pid_to_processor_id(int pid); +extern void block_signals(void); +extern void unblock_signals(void); +extern void deliver_signals(void *t); +extern void lock_syscall(void); +extern void unlock_syscall(void); +extern void lock_trap(void); +extern void unlock_trap(void); +extern void lock_pid(void); +extern void unlock_pid(void); +extern void cpu_idle(void); +extern void finish_fork(void); +extern void paging_init(void); +extern unsigned long um_virt_to_phys(void *t, unsigned long addr); +extern void init_flush_vm(void); +extern void *process_state(void *t); +extern void *syscall_sp(void *t); +extern void syscall_trace(void); +extern int hz(void); +extern void idle_timer(void); +extern unsigned int do_IRQ(int irq, int user_mode); +extern int external_pid(void *t); +extern int pid_to_processor_id(int pid); +extern void boot_timer_handler(int sig); +extern void interrupt_end(void); +extern void tracing_reboot(void); +extern void tracing_halt(void); +extern void tracing_cb(void (*proc)(void *), void *arg); +extern int debugger_signal(int status, int pid); +extern void child_signal(int pid, int status); +extern int init_ptrace_proxy(int idle_pid, int startup, int stop); +extern void check_stack_overflow(void *ptr); +extern void relay_signal(int sig, void *sc, int usermode); +extern int singlestepping(void *t); +extern void not_implemented(void); +extern void finish_fork_handler(int sig); +extern int user_context(unsigned long sp); +extern void timer_irq(int user_mode); +extern void unprotect_stack(unsigned long stack); +extern void kern_start_exec(int new_pid); +extern void do_exitcalls(void); +extern void do_uml_exitcalls(void); +extern int attach_debugger(int idle_pid, int pid, int stop); +extern void *round_up(unsigned long addr); +extern void *round_down(unsigned long addr); +extern void bad_segv(unsigned long address, unsigned long ip, int is_write); +extern int config_gdb(char *str); +extern int remove_gdb(void); +extern char *uml_strdup(char *string); +extern void unprotect_kernel_mem(int delay_signals); +extern void protect_kernel_mem(int delay_signals); +extern unsigned long get_kmem_end(void); +extern void set_kmem_end(unsigned long); +extern void set_task_sizes(int arg); +extern void uml_cleanup(void); +extern int pid_to_processor_id(int pid); +extern void set_current(void *t); +extern void lock_signalled_task(void *t); +extern void IPI_handler(int cpu); +extern int jail_setup(char *line, int *add); +extern void *get_init_task(void); +extern int copy_to_user_proc(void *to, void *from, int size); +extern int copy_from_user_proc(void *to, void *from, int size); +extern void set_thread_sc(void *sc); +extern int get_restore_state(void *t); + +#endif + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/include/line.h linux_umopenmosix/arch/um/include/line.h --- linux-2.4.17/arch/um/include/line.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/include/line.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2001 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#ifndef __LINE_H__ +#define __LINE_H__ + +#include "linux/list.h" +#include "asm/semaphore.h" +#include "chan_user.h" + +struct line { + char *init_str; + int init_pri; + struct list_head chan_list; + int count; + struct tty_struct *tty; + struct semaphore sem; + int initialized; +}; + +#define LINE_INIT(str) \ + { init_str : str, \ + init_pri : INIT_STATIC, \ + chan_list : { }, \ + count : 0, \ + tty : NULL, \ + sem : { } } + +struct winch_lines { + struct list_head list; + struct line *lines; + int nlines; +}; + +extern void line_interrupt(int irq, void *data, struct pt_regs *unused); +extern void line_close(struct line *lines, int n); +extern int line_open(struct line *lines, int n, struct tty_struct *tty, + int (*setup_irq)(int fd, int input, int output, + void *data), + struct chan_opts *opts); +extern void line_setup(struct line *lines, int num, char *init); +extern void run_winch_handlers(void); +extern void register_winch(struct winch_lines *lines); + +#endif + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/include/mconsole.h linux_umopenmosix/arch/um/include/mconsole.h --- linux-2.4.17/arch/um/include/mconsole.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/include/mconsole.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) + * Licensed under the GPL + */ + +#ifndef __MCONSOLE_H__ +#define __MCONSOLE_H__ + +#define MCONSOLE_MAGIC (0xcafebabe) +#define MCONSOLE_MAX_DATA (512) +#define MCONSOLE_VERSION (1) + +struct mconsole_request { + unsigned long magic; + int version; + int len; + char data[MCONSOLE_MAX_DATA]; +}; + +struct mconsole_reply { + int err; + int more; + int len; + char data[MCONSOLE_MAX_DATA]; +}; + +struct mc_request; + +struct mconsole_command +{ + char *command; + void (*handler)(struct mc_request *req); + int as_interrupt; +}; + +struct mc_request +{ + int len; + int as_interrupt; + + int originating_fd; + int originlen; + unsigned char origin[128]; /* sockaddr_un */ + + struct mconsole_request request; + struct mconsole_command *cmd; +}; + +extern char mconsole_socket_name[]; + +extern int mconsole_unlink_socket(void); +extern int mconsole_reply(struct mc_request *req, char *reply, int err, + int more); +extern void mconsole_version(struct mc_request *req); +extern void mconsole_help(struct mc_request *req); +extern void mconsole_halt(struct mc_request *req); +extern void mconsole_reboot(struct mc_request *req); +extern void mconsole_config(struct mc_request *req); +extern void mconsole_remove(struct mc_request *req); +extern void mconsole_sysrq(struct mc_request *req); +extern void mconsole_cad(struct mc_request *req); +extern int mconsole_create_listening_socket(void); +extern int mconsole_get_request(int fd, struct mc_request *req); + +#endif + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/include/mconsole_kern.h linux_umopenmosix/arch/um/include/mconsole_kern.h --- linux-2.4.17/arch/um/include/mconsole_kern.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/include/mconsole_kern.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2001 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#ifndef __MCONSOLE_KERN_H__ +#define __MCONSOLE_KERN_H__ + +#include "linux/config.h" +#include "linux/list.h" +#include "mconsole.h" + +struct mconsole_entry { + struct list_head list; + struct mc_request request; +}; + +struct mc_device { + struct list_head list; + char *name; + int (*config)(char *); + int (*remove)(char *); +}; + +#ifdef CONFIG_MCONSOLE + +extern void mconsole_register_dev(struct mc_device *new); + +#else + +static inline void mconsole_register_dev(struct mc_device *new) +{ +} + +#endif + +#endif + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/include/mem_user.h linux_umopenmosix/arch/um/include/mem_user.h --- linux-2.4.17/arch/um/include/mem_user.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/include/mem_user.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,61 @@ +/* + * arch/um/include/mem_user.h + * + * BRIEF MODULE DESCRIPTION + * user side memory interface for support IO memory inside user mode linux + * + * Copyright (C) 2001 RidgeRun, Inc. + * Author: RidgeRun, Inc. + * Greg Lonnon glonnon@ridgerun.com or info@ridgerun.com + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN + * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#ifndef _MEM_USER_H +#define _MEM_USER_H + +#define ROUND_4M(n) ((((unsigned long) (n)) + (1 << 22)) & ~((1 << 22) - 1)) + +extern unsigned long host_task_size; +extern unsigned long task_size; + +extern int init_mem_user(void); +extern int create_mem_file(unsigned long len); +extern void setup_range(int fd, char *driver, unsigned long start, + unsigned long usable, unsigned long total); +extern void map(unsigned long virt, void *p, unsigned long len, + int r, int w, int x); +extern int parse_iomem(char *str, int *add); +extern void setup_memory(void); +extern unsigned long find_iomem(char *driver, unsigned long *len_out); + +#endif + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/include/process.h linux_umopenmosix/arch/um/include/process.h --- linux-2.4.17/arch/um/include/process.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/include/process.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2000, 2001 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#ifndef __PROCESS_H__ +#define __PROCESS_H__ + +#include + +extern void sig_handler(int sig, struct sigcontext sc); +extern void irq_handler(int sig, struct sigcontext sc); +extern void alarm_handler(int sig, struct sigcontext sc); + +#endif + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/include/sigcontext.h linux_umopenmosix/arch/um/include/sigcontext.h --- linux-2.4.17/arch/um/include/sigcontext.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/include/sigcontext.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2001 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#ifndef __UML_SIGCONTEXT_H__ +#define __UML_SIGCONTEXT_H__ + +extern int copy_sigcontext_to_user(void *sc, struct sys_pt_regs *regs, + unsigned long cr2, int err); +extern void fill_in_regs(struct sys_pt_regs *regs, void *sc_ptr); +extern int copy_sc_to_user(void *to_ptr, void *from_ptr, void *data); +extern int copy_sc_from_user(void *to_ptr, void *from_ptr); + +#endif + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/include/signal_kern.h linux_umopenmosix/arch/um/include/signal_kern.h --- linux-2.4.17/arch/um/include/signal_kern.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/include/signal_kern.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2001 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#ifndef __SIGNAL_KERN_H__ +#define __SIGNAL_KERN_H__ + +#include "sysdep/ptrace.h" + +extern void signal_deliverer(int sig); +extern int probe_stack(unsigned long sp, int delta); +extern int have_signals(void *t); + +#endif + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/include/signal_user.h linux_umopenmosix/arch/um/include/signal_user.h --- linux-2.4.17/arch/um/include/signal_user.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/include/signal_user.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2001 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#ifndef __SIGNAL_USER_H__ +#define __SIGNAL_USER_H__ + +extern int signal_stack_size; + +extern int change_sig(int signal, int on); +extern void set_sigstack(void *stack, int size); +extern void set_handler(int sig, void (*handler)(int), int flags, ...); +extern void setup_stack(unsigned long stack_top, struct sys_pt_regs *regs_out); + +#endif + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/include/somename.h linux_umopenmosix/arch/um/include/somename.h --- linux-2.4.17/arch/um/include/somename.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/include/somename.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,5 @@ +#ifndef _UML_SOMENAME_H +#define _UML_SOMENAME_H +extern void sys_somename(); +#endif + diff -urN linux-2.4.17/arch/um/include/syscall_user.h linux_umopenmosix/arch/um/include/syscall_user.h --- linux-2.4.17/arch/um/include/syscall_user.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/include/syscall_user.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2000, 2001 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#ifndef __SYSCALL_USER_H__ +#define __SYSCALL_USER_H__ + +#include + +extern void syscall_handler(int sig, struct sigcontext sc); +extern int exit_kernel(int pid, void *task); +extern int do_syscall(void *task, int pid); + +#endif + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/include/sysdep-i386/frame.h linux_umopenmosix/arch/um/include/sysdep-i386/frame.h --- linux-2.4.17/arch/um/include/sysdep-i386/frame.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/include/sysdep-i386/frame.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2002 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#ifndef __FRAME_I386_H +#define __FRAME_I386_H + +#include + +/* This stuff is to calculate the size of the fp state struct at runtime + * because it has changed between 2.2 and 2.4 and it would be good for a + * UML compiled on one to work on the other. + * So, setup_arch_frame_raw fills in the arch struct of the raw data, which + * just contains the address of the end of the sigcontext. This is invoked + * from the signal handler. + * setup_arch_frame uses that data to figure out what + * arch_frame_data.fpstate_size should be. It really has no idea, since it's + * not allowed to do sizeof(struct fpstate) but it's safe to consider that it's + * everything from the end of the sgcontext up to the top of the stack. So, + * it masks off the page number to get the offset within the page and subtracts + * that from the page size, and that's how big the fpstate struct will be + * considered to be. + */ + +struct arch_frame_data_raw { + unsigned long sc_end; +}; + +static inline void setup_arch_frame_raw(struct arch_frame_data_raw *data, + struct sigcontext *sc) +{ + data->sc_end = (unsigned long) sc; + data->sc_end += sizeof(*sc); +} + +struct arch_frame_data { + int fpstate_size; +}; + +static inline void setup_arch_frame(struct arch_frame_data_raw *in, + struct arch_frame_data *out) +{ + unsigned long fpstate_start = in->sc_end; + + fpstate_start &= ~PAGE_MASK; + out->fpstate_size = PAGE_SIZE - fpstate_start; +} + +/* This figures out where on the stack the SA_RESTORER function address + * is stored. For i386, it's the signal handler return address, so it's + * located next to the frame pointer. + * This is inlined, so __builtin_frame_address(0) is correct. Otherwise, + * it would have to be __builtin_frame_address(1). + */ + +static inline unsigned long frame_restorer(void) +{ + unsigned long *fp; + + fp = __builtin_frame_address(0); + return((unsigned long) (fp + 1)); +} + +/* Similarly, this returns the value of sp when the handler was first + * entered. This is used to calculate the proper sp when delivering + * signals. + */ + +static inline unsigned long frame_sp(void) +{ + unsigned long *fp; + + fp = __builtin_frame_address(0); + return((unsigned long) (fp + 1)); +} + +#endif + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/include/sysdep-i386/ptrace.h linux_umopenmosix/arch/um/include/sysdep-i386/ptrace.h --- linux-2.4.17/arch/um/include/sysdep-i386/ptrace.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/include/sysdep-i386/ptrace.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2000 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#ifndef __SYSDEP_I386_PTRACE_H +#define __SYSDEP_I386_PTRACE_H + +#define UM_MAX_REG (17) +#define UM_MAX_FP_REG (27) + +#define UM_MAX_REG_OFFSET (UM_MAX_REG * sizeof(long)) + +struct sys_pt_regs { + unsigned long regs[UM_MAX_REG]; +}; + +#define EMPTY_REGS { { [ 0 ... UM_MAX_REG - 1 ] = 0 } } + +#define UM_REG(r, n) ((r)->regs[n]) + +#define UM_IP(r) UM_REG(r, EIP) +#define UM_SP(r) UM_REG(r, UESP) +#define UM_ELF_ZERO(r) UM_REG(r, EDX) + +#define UM_SYSCALL_RET(r) UM_REG(r, EAX) +#define UM_SYSCALL_NR(r) UM_REG(r, ORIG_EAX) +#define UM_ORIG_SYSCALL(r) UM_REG(r, EAX) + +#define UM_SYSCALL_ARG1(r) UM_REG(r, EBX) +#define UM_SYSCALL_ARG2(r) UM_REG(r, ECX) +#define UM_SYSCALL_ARG3(r) UM_REG(r, EDX) +#define UM_SYSCALL_ARG4(r) UM_REG(r, ESI) +#define UM_SYSCALL_ARG5(r) UM_REG(r, EDI) +#define UM_SYSCALL_ARG6(r) UM_REG(r, EBP) + +#define UM_IP_OFFSET (EIP * sizeof(long)) +#define UM_SP_OFFSET (UESP * sizeof(long)) +#define UM_ELF_ZERO_OFFSET (EDX * sizeof(long)) + +#define UM_SYSCALL_RET_OFFSET (EAX * sizeof(long)) +#define UM_SYSCALL_NR_OFFSET (ORIG_EAX * sizeof(long)) + +#define UM_SYSCALL_ARG1_OFFSET (EBX * sizeof(long)) +#define UM_SYSCALL_ARG2_OFFSET (ECX * sizeof(long)) +#define UM_SYSCALL_ARG3_OFFSET (EDX * sizeof(long)) +#define UM_SYSCALL_ARG4_OFFSET (ESI * sizeof(long)) +#define UM_SYSCALL_ARG5_OFFSET (EDI * sizeof(long)) +#define UM_SYSCALL_ARG6_OFFSET (EBP * sizeof(long)) + +#define UM_SET_SYSCALL_RETURN(r, result) UM_REG(r, EAX) = (result) + +#define UM_FIX_EXEC_STACK(sp) do ; while(0) + +#define UM_RESTART_SYSCALL(regs) (UM_IP(regs) -= 2) + +#define UM_HAVE_GETREGS +#define UM_HAVE_GETFPREGS +#define UM_HAVE_SETREGS +#define UM_HAVE_SETFPREGS + + + +#define EBX 0 +#define ECX 1 +#define EDX 2 +#define ESI 3 +#define EDI 4 +#define EBP 5 +#define EAX 6 +#define DS 7 +#define ES 8 +#define FS 9 +#define GS 10 +#define ORIG_EAX 11 +#define EIP 12 +#define CS 13 +#define EFL 14 +#define UESP 15 +#define SS 16 +#define FRAME_SIZE 17 + + + + + + + + + + + +#endif + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/include/sysdep-i386/sigcontext.h linux_umopenmosix/arch/um/include/sysdep-i386/sigcontext.h --- linux-2.4.17/arch/um/include/sysdep-i386/sigcontext.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/include/sysdep-i386/sigcontext.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#ifndef __SYS_SIGCONTEXT_I386_H +#define __SYS_SIGCONTEXT_I386_H + +#define SC_FAULT_ADDR(sc) ((sc)->cr2) +#define SC_FAULT_WRITE(sc) (((sc)->err) & 2) +#define SC_IP(sc) ((sc)->eip) +#define SC_SP(sc) ((sc)->esp) + +#define SC_STACK_SIZE (sizeof(struct sigcontext) + sizeof(struct _fpstate)) + +/* These are General Protection and Page Fault */ +#define SEGV_IS_FIXABLE(sc) (((sc)->trapno == 13) || ((sc)->trapno == 14)) +#endif + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/include/sysdep-i386/syscalls.h linux_umopenmosix/arch/um/include/sysdep-i386/syscalls.h --- linux-2.4.17/arch/um/include/sysdep-i386/syscalls.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/include/sysdep-i386/syscalls.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2000 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include "asm/unistd.h" + +typedef long syscall_handler_t(struct sys_pt_regs regs); + +#define EXECUTE_SYSCALL(syscall, regs) (*sys_call_table[syscall])(regs) + +extern syscall_handler_t sys_modify_ldt; +extern syscall_handler_t old_mmap_i386; +extern syscall_handler_t old_select; +extern syscall_handler_t sys_ni_syscall; + +#define ARCH_SYSCALLS \ + [ __NR_mmap ] = old_mmap_i386, \ + [ __NR_select ] = old_select, \ + [ __NR_vm86old ] = sys_ni_syscall, \ + [ __NR_modify_ldt ] = sys_modify_ldt, \ + [ __NR_lchown32 ] = sys_lchown, \ + [ __NR_getuid32 ] = sys_getuid, \ + [ __NR_getgid32 ] = sys_getgid, \ + [ __NR_geteuid32 ] = sys_geteuid, \ + [ __NR_getegid32 ] = sys_getegid, \ + [ __NR_setreuid32 ] = sys_setreuid, \ + [ __NR_setregid32 ] = sys_setregid, \ + [ __NR_getgroups32 ] = sys_getgroups, \ + [ __NR_setgroups32 ] = sys_setgroups, \ + [ __NR_fchown32 ] = sys_fchown, \ + [ __NR_setresuid32 ] = sys_setresuid, \ + [ __NR_getresuid32 ] = sys_getresuid, \ + [ __NR_setresgid32 ] = sys_setresgid, \ + [ __NR_getresgid32 ] = sys_getresgid, \ + [ __NR_chown32 ] = sys_chown, \ + [ __NR_setuid32 ] = sys_setuid, \ + [ __NR_setgid32 ] = sys_setgid, \ + [ __NR_setfsuid32 ] = sys_setfsuid, \ + [ __NR_setfsgid32 ] = sys_setfsgid, \ + [ __NR_pivot_root ] = sys_pivot_root, \ + [ __NR_mincore ] = sys_mincore, \ + [ __NR_madvise ] = sys_madvise, \ + [ 222 ] = sys_ni_syscall, + +/* 222 doesn't yet have a name in include/asm-i386/unistd.h */ + +#define LAST_ARCH_SYSCALL 222 + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/include/sysdep-ia64/ptrace.h linux_umopenmosix/arch/um/include/sysdep-ia64/ptrace.h --- linux-2.4.17/arch/um/include/sysdep-ia64/ptrace.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/include/sysdep-ia64/ptrace.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2000 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#ifndef __SYSDEP_IA64_PTRACE_H +#define __SYSDEP_IA64_PTRACE_H + +struct sys_pt_regs { + int foo; +}; + +#define EMPTY_REGS { 0 } + +#endif + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/include/sysdep-ia64/sigcontext.h linux_umopenmosix/arch/um/include/sysdep-ia64/sigcontext.h --- linux-2.4.17/arch/um/include/sysdep-ia64/sigcontext.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/include/sysdep-ia64/sigcontext.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2000 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#ifndef __SYSDEP_IA64_SIGCONTEXT_H +#define __SYSDEP_IA64_SIGCONTEXT_H + +#endif + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/include/sysdep-ia64/syscalls.h linux_umopenmosix/arch/um/include/sysdep-ia64/syscalls.h --- linux-2.4.17/arch/um/include/sysdep-ia64/syscalls.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/include/sysdep-ia64/syscalls.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2000 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#ifndef __SYSDEP_IA64_SYSCALLS_H +#define __SYSDEP_IA64_SYSCALLS_H + +#endif + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/include/sysdep-ppc/ptrace.h linux_umopenmosix/arch/um/include/sysdep-ppc/ptrace.h --- linux-2.4.17/arch/um/include/sysdep-ppc/ptrace.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/include/sysdep-ppc/ptrace.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,104 @@ +/* + * Licensed under the GPL + */ + +#ifndef __SYS_PTRACE_PPC_H +#define __SYS_PTRACE_PPC_H + +#include "linux/config.h" +#include "linux/types.h" + +/* the following taken from */ + +#ifdef CONFIG_PPC64 +#define PPC_REG unsigned long /*long*/ +#else +#define PPC_REG unsigned long +#endif +struct sys_pt_regs_s { + PPC_REG gpr[32]; + PPC_REG nip; + PPC_REG msr; + PPC_REG orig_gpr3; /* Used for restarting system calls */ + PPC_REG ctr; + PPC_REG link; + PPC_REG xer; + PPC_REG ccr; + PPC_REG mq; /* 601 only (not used at present) */ + /* Used on APUS to hold IPL value. */ + PPC_REG trap; /* Reason for being here */ + PPC_REG dar; /* Fault registers */ + PPC_REG dsisr; + PPC_REG result; /* Result of a system call */ +}; + +#define NUM_REGS (sizeof(struct sys_pt_regs_s) / sizeof(PPC_REG)) + +struct sys_pt_regs { + PPC_REG regs[sizeof(struct sys_pt_regs_s) / sizeof(PPC_REG)]; +}; + +#define UM_MAX_REG (PT_FPR0) +#define UM_MAX_REG_OFFSET (UM_MAX_REG * sizeof(PPC_REG)) + +#define EMPTY_REGS { { [ 0 ... NUM_REGS - 1] = 0 } } + +#define UM_REG(r, n) ((r)->regs[n]) + +#define UM_SYSCALL_RET(r) UM_REG(r, PT_R3) +#define UM_SP(r) UM_REG(r, PT_R1) +#define UM_IP(r) UM_REG(r, PT_NIP) +#define UM_ELF_ZERO(r) UM_REG(r, PT_FPSCR) +#define UM_SYSCALL_NR(r) UM_REG(r, PT_R0) +#define UM_SYSCALL_ARG1(r) UM_REG(r, PT_ORIG_R3) +#define UM_SYSCALL_ARG2(r) UM_REG(r, PT_R4) +#define UM_SYSCALL_ARG3(r) UM_REG(r, PT_R5) +#define UM_SYSCALL_ARG4(r) UM_REG(r, PT_R6) +#define UM_SYSCALL_ARG5(r) UM_REG(r, PT_R7) +#define UM_SYSCALL_ARG6(r) UM_REG(r, PT_R8) + +#define UM_SYSCALL_NR_OFFSET (PT_R0 * sizeof(PPC_REG)) +#define UM_SYSCALL_RET_OFFSET (PT_R3 * sizeof(PPC_REG)) +#define UM_SYSCALL_ARG1_OFFSET (PT_R3 * sizeof(PPC_REG)) +#define UM_SYSCALL_ARG2_OFFSET (PT_R4 * sizeof(PPC_REG)) +#define UM_SYSCALL_ARG3_OFFSET (PT_R5 * sizeof(PPC_REG)) +#define UM_SYSCALL_ARG4_OFFSET (PT_R6 * sizeof(PPC_REG)) +#define UM_SYSCALL_ARG5_OFFSET (PT_R7 * sizeof(PPC_REG)) +#define UM_SYSCALL_ARG6_OFFSET (PT_R8 * sizeof(PPC_REG)) +#define UM_SP_OFFSET (PT_R1 * sizeof(PPC_REG)) +#define UM_IP_OFFSET (PT_NIP * sizeof(PPC_REG)) +#define UM_ELF_ZERO_OFFSET (PT_R3 * sizeof(PPC_REG)) + +#define UM_SET_SYSCALL_RETURN(_regs, result) \ +do { \ + if (result < 0) { \ + (_regs)->regs[PT_CCR] |= 0x10000000; \ + UM_SYSCALL_RET((_regs)) = -result; \ + } else { \ + UM_SYSCALL_RET((_regs)) = result; \ + } \ +} while(0) + +extern void shove_aux_table(unsigned long sp); +#define UM_FIX_EXEC_STACK(sp) shove_aux_table(sp); + +/* These aren't actually defined. The undefs are just to make sure + * everyone's clear on the concept. + */ +#undef UML_HAVE_GETREGS +#undef UML_HAVE_GETFPREGS +#undef UML_HAVE_SETREGS +#undef UML_HAVE_SETFPREGS + +#endif + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/include/sysdep-ppc/sigcontext.h linux_umopenmosix/arch/um/include/sysdep-ppc/sigcontext.h --- linux-2.4.17/arch/um/include/sysdep-ppc/sigcontext.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/include/sysdep-ppc/sigcontext.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2000 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#ifndef __SYS_SIGCONTEXT_PPC_H +#define __SYS_SIGCONTEXT_PPC_H + +#define DSISR_WRITE 0x02000000 + +#define SC_FAULT_ADDR(sc) ({ \ + struct sigcontext_struct *_sc = (sc); \ + long retval = -1; \ + switch (_sc->regs->trap) { \ + case 0x300: \ + /* data exception */ \ + retval = _sc->regs->dar; \ + break; \ + case 0x400: \ + /* instruction exception */ \ + retval = _sc->regs->nip; \ + break; \ + default: \ + panic("SC_FAULT_ADDR: unhandled trap type\n"); \ + } \ + retval; \ + }) + +#define SC_FAULT_WRITE(sc) ({ \ + struct sigcontext_struct *_sc = (sc); \ + long retval = -1; \ + switch (_sc->regs->trap) { \ + case 0x300: \ + /* data exception */ \ + retval = !!(_sc->regs->dsisr & DSISR_WRITE); \ + break; \ + case 0x400: \ + /* instruction exception: not a write */ \ + retval = 0; \ + break; \ + default: \ + panic("SC_FAULT_ADDR: unhandled trap type\n"); \ + } \ + retval; \ + }) + +#define SC_IP(sc) ((sc)->regs->nip) +#define SC_SP(sc) ((sc)->regs->gpr[1]) +#define SEGV_IS_FIXABLE(sc) (1) + +#endif + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/include/sysdep-ppc/syscalls.h linux_umopenmosix/arch/um/include/sysdep-ppc/syscalls.h --- linux-2.4.17/arch/um/include/sysdep-ppc/syscalls.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/include/sysdep-ppc/syscalls.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2000 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +typedef long syscall_handler_t(unsigned long arg1, unsigned long arg2, + unsigned long arg3, unsigned long arg4, + unsigned long arg5, unsigned long arg6); + +#define EXECUTE_SYSCALL(syscall, regs) \ + (*sys_call_table[syscall])(UM_SYSCALL_ARG1(®s), \ + UM_SYSCALL_ARG2(®s), \ + UM_SYSCALL_ARG3(®s), \ + UM_SYSCALL_ARG4(®s), \ + UM_SYSCALL_ARG5(®s), \ + UM_SYSCALL_ARG6(®s)) + +extern syscall_handler_t sys_mincore; +extern syscall_handler_t sys_madvise; + +/* old_mmap needs the correct prototype since syscall_kern.c includes + * this file. + */ +int old_mmap(unsigned long addr, unsigned long len, + unsigned long prot, unsigned long flags, + unsigned long fd, unsigned long offset); + +#define ARCH_SYSCALLS \ + [ __NR_modify_ldt ] = sys_ni_syscall, \ + [ __NR_pciconfig_read ] = sys_ni_syscall, \ + [ __NR_pciconfig_write ] = sys_ni_syscall, \ + [ __NR_pciconfig_iobase ] = sys_ni_syscall, \ + [ __NR_pivot_root ] = sys_ni_syscall, \ + [ __NR_multiplexer ] = sys_ni_syscall, \ + [ __NR_mmap ] = old_mmap, \ + [ __NR_madvise ] = sys_madvise, \ + [ __NR_mincore ] = sys_mincore, + +#define LAST_ARCH_SYSCALL __NR_mincore + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/include/sysrq.h linux_umopenmosix/arch/um/include/sysrq.h --- linux-2.4.17/arch/um/include/sysrq.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/include/sysrq.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,6 @@ +#ifndef __UM_SYSRQ_H +#define __UM_SYSRQ_H + +extern void show_trace(unsigned long *stack); + +#endif diff -urN linux-2.4.17/arch/um/include/tlb.h linux_umopenmosix/arch/um/include/tlb.h --- linux-2.4.17/arch/um/include/tlb.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/include/tlb.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2002 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#ifndef __TLB_H__ +#define __TLB_H__ + +extern void mprotect_kernel_vm(int w); +extern void force_flush_all(void); + +#endif + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/include/ubd_user.h linux_umopenmosix/arch/um/include/ubd_user.h --- linux-2.4.17/arch/um/include/ubd_user.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/include/ubd_user.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2000 Jeff Dike (jdike@karaya.com) + * Copyright (C) 2001 RidgeRun, Inc (glonnon@ridgerun.com) + * Licensed under the GPL + */ + +#ifndef __UM_UBD_USER_H +#define __UM_UBD_USER_H + +enum ubd_req { UBD_READ, UBD_WRITE }; + +struct io_thread_req { + enum ubd_req op; + int fds[2]; + unsigned long offsets[2]; + unsigned long long offset; + unsigned long length; + char *buffer; + int sectorsize; + unsigned long sector_mask; + unsigned long cow_offset; + unsigned long bitmap_words[2]; + int error; +}; + +extern int open_ubd_file(char *file, int *openflags, char **backing_file_out, + int *bitmap_offset_out, unsigned long *bitmap_len_out, + int *data_offset_out, int *create_cow_out); +extern int create_cow_file(char *cow_file, char *backing_file, int sectorsize, + int *bitmap_offset_out, + unsigned long *bitmap_len_out, + int *data_offset_out); +extern int read_cow_bitmap(int fd, void *buf, int offset, int len); +extern int read_ubd_fs(int fd, void *buffer, int len); +extern int write_ubd_fs(int fd, char *buffer, int len); +extern int start_io_thread(unsigned long sp, int *fds_out); +extern void do_io(struct io_thread_req *req); +extern int ubd_is_dir(char *file); + +static inline int ubd_test_bit(int bit, unsigned long *data) +{ + int bits, n, off; + + bits = sizeof(data[0]) * 8; + n = bit / bits; + off = bit % bits; + return((data[n] & (1 << off)) != 0); +} + +static inline void ubd_set_bit(int bit, unsigned long *data) +{ + int bits, n, off; + + bits = sizeof(data[0]) * 8; + n = bit / bits; + off = bit % bits; + data[n] |= (1 << off); +} + + +#endif + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/include/umid.h linux_umopenmosix/arch/um/include/umid.h --- linux-2.4.17/arch/um/include/umid.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/include/umid.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,17 @@ +/* + * Copyright (C) 2001 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +extern int umid_file_name(char *name, char *buf, int len); + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/include/umn.h linux_umopenmosix/arch/um/include/umn.h --- linux-2.4.17/arch/um/include/umn.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/include/umn.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2000 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#ifndef __UMN_H +#define __UMN_H + +extern int open_umn_tty(int *slave_out, int *slipno_out); +extern void close_umn_tty(int master, int slave); +extern int umn_send_packet(int fd, void *data, int len); +extern int set_umn_addr(int fd, char *addr, char *ptp_addr); +extern void slip_unesc(unsigned char s); +extern void umn_read(int fd); + +#endif + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/include/user.h linux_umopenmosix/arch/um/include/user.h --- linux-2.4.17/arch/um/include/user.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/include/user.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2000 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#ifndef __USER_H__ +#define __USER_H__ + +extern void panic(char *fmt, ...); +extern int printk(char *fmt, ...); +extern void schedule(void); +extern void *um_kmalloc(int size); +extern void kfree(void *ptr); +extern int in_aton(char *str); +extern int open_gdb_chan(void); + +#endif + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/include/user_util.h linux_umopenmosix/arch/um/include/user_util.h --- linux-2.4.17/arch/um/include/user_util.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/include/user_util.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,124 @@ +/* + * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#ifndef __USER_UTIL_H__ +#define __USER_UTIL_H__ + +#include "sysdep/ptrace.h" + +extern int grantpt(int __fd); +extern int unlockpt(int __fd); +extern char *ptsname(int __fd); + +enum { OP_NONE, OP_EXEC, OP_THREAD, OP_FORK, OP_TRACE_ON, OP_REBOOT, + OP_HALT, OP_CB }; + +struct cpu_task { + int pid; + void *task; +}; + +extern struct cpu_task cpu_tasks[]; + +extern unsigned long low_physmem; +extern unsigned long high_physmem; +extern unsigned long uml_physmem; +extern unsigned long end_vm; +extern unsigned long start_vm; + +extern int tracing_pid; +extern int honeypot; + +extern char host_info[]; + +extern char saved_command_line[]; +extern char command_line[]; + +extern int gdb_pid; + +extern char *tempdir; + +extern unsigned long _stext, _etext, _sdata, _edata, __bss_start, _end; +extern unsigned long _unprotected_end; +extern void *brk_start; + +extern void *open_maps(void); +extern void close_maps(void *fd); +extern unsigned long get_brk(void); +extern void stop(void); +extern int proc_start_thread(unsigned long ip, unsigned long sp); +extern void stack_protections(unsigned long address); +extern void task_protections(unsigned long address); +extern void abandon_proc_space(int (*proc)(void *), unsigned long sp); +extern int signals(int (*init_proc)(void *), void *sp); +extern int unmap(unsigned long address, unsigned long len); +extern int protect(unsigned long addr, unsigned long len, int r, int w, + int x, int must_succeed); +extern void stop_pid(int pid); +extern void kill_pid(int pid); +extern void usr1_pid(int pid); +extern int __personality(int); +extern int wait_for_stop(int pid, int sig, int cont_type); +extern void *add_signal_handler(int sig, void (*handler)(int)); +extern void signal_init(void); +extern void finish_exec(int old_pid, int new_pid, struct sys_pt_regs *regs); +extern int start_fork_tramp(void *arg, unsigned long temp_stack, int clone_vm, + int (*tramp)(void *)); +extern void trace_myself(void); +extern void timer(void); +extern void get_profile_timer(void); +extern void disable_profile_timer(void); +extern void set_timers(int set_signal); +extern int clone_and_wait(int (*fn)(void *), void *arg, void *sp, int flags); +extern int input_loop(void); +extern void continue_execing_proc(int pid); +extern int linux_main(int argc, char **argv); +extern void remap_data(void *segment_start, void *segment_end, int w); +extern void set_cmdline(char *cmd); +extern void input_cb(void (*proc)(void *), void *arg, int arg_len); +extern void setup_input(void); +extern int get_pty(void); +extern void save_signal_state(int *sig_ptr); +extern void *um_kmalloc(int size); +extern int raw(int fd, int complain); +extern int switcheroo(int fd, int prot, void *from, void *to, int size); +extern void idle_sleep(int secs); +extern void setup_machinename(char *machine_out); +extern void setup_hostinfo(void); +extern void add_arg(char *cmd_line, char *arg); +extern void init_new_thread(void *sig_stack, void (*usr1_handler)(int)); +extern void start_exec(int old_pid, int new_pid, int *error, + struct sys_pt_regs *regs); +extern void attach_process(int pid); +extern void calc_sigframe_size(void); +extern int fork_tramp(void *sig_stack); +extern void do_exec(int old_pid, int new_pid); +extern void tracer_panic(char *msg, ...); +extern void close_fd(int); +extern int make_tempfile(const char *template, char **tempname, int do_unlink); +extern char *get_umid(void); +extern int ptrace_getregs(long pid, struct sys_pt_regs *regs_out); +extern int ptrace_setregs(long pid, struct sys_pt_regs *regs_in); +extern void do_longjmp(void *p); +extern void term_handler(int sig); +extern void suspend_new_thread(int fd); +extern int detach(int pid, int sig); +extern int attach(int pid); +extern void kill_child_dead(int pid); +extern int cont(int pid); +extern void check_ptrace(void); + +#endif + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/kernel/Makefile linux_umopenmosix/arch/um/kernel/Makefile --- linux-2.4.17/arch/um/kernel/Makefile Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/kernel/Makefile Sun Jun 23 12:40:10 2002 @@ -0,0 +1,66 @@ +OBJ = um.o + +OBJS = exec_kern.o exec_user.o frame_kern.o frame_user.o init_task.o irq.o \ + irq_user.o mem.o mem_user.o process.o ptrace.o reboot.o resource.o \ + setup.o signal_user.o smp.o syscall_kern.o syscall_user.o sysrq.o \ + sys_call_table.o time.o time_kern.o tlb.o trap_kern.o trap_user.o \ + uaccess_user.o um_arch.o umid.o user_util.o somename.o i387.o + +ifeq ($(CONFIG_BLK_DEV_INITRD), y) + OBJS += initrd_kern.o initrd_user.o +endif + +# user_syms.o not included here because Rules.make has its own ideas about +# building anything in export-objs + +USER_OBJS = $(filter %_user.o,$(OBJS)) process.o time.o umid.o user_util.o + +export-objs = ksyms.o process_kern.o signal_kern.o user_syms.o + +UNMAP_CFLAGS := $(patsubst -pg -DPROFILING,,$(USER_CFLAGS)) +UNMAP_CFLAGS := $(patsubst -fprofile-arcs -ftest-coverage,,$(UNMAP_CFLAGS)) + +ifeq ($(CONFIG_MODULES), y) + DMODULES = -D__CONFIG_MODULES__ +endif + +ifeq ($(CONFIG_MODVERSIONS), y) + DMODVERSIONS = -D__CONFIG_MODVERSIONS__ +endif + +ifeq ($(CONFIG_GPROF), y) + OBJS += gprof_syms.o + export-objs += gprof_syms.o +endif + +ifeq ($(CONFIG_GCOV), y) + OBJS += gmon_syms.o + export-objs += gmon_syms.o +endif + +CFLAGS_user_syms.o = -D__AUTOCONF_INCLUDED__ $(DMODULES) $(DMODVERSIONS) -I- \ + -I../include + +all: $(OBJ) unmap_fin.o + +$(USER_OBJS) : %.o: %.c + $(CC) $(CFLAGS_$@) $(USER_CFLAGS) -c -o $@ $< + +unmap.o: unmap.c + $(CC) $(UNMAP_CFLAGS) -c -o $@ $< + +unmap_fin.o : unmap.o + ld -r -o $@ $< -lc -L/usr/lib + +$(OBJ): $(OBJS) $(export-objs) + rm -f $@ + $(LD) $(LINKFLAGS) --start-group $^ --end-group -o $@ + +clean: + rm -f $(OBJS) $(export-objs) + +modules: + +fastdep: + +include $(TOPDIR)/Rules.make diff -urN linux-2.4.17/arch/um/kernel/exec_kern.c linux_umopenmosix/arch/um/kernel/exec_kern.c --- linux-2.4.17/arch/um/kernel/exec_kern.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/kernel/exec_kern.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,118 @@ +/* + * Copyright (C) 2000, 2001 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include "linux/slab.h" +#include "linux/smp_lock.h" +#include "asm/ptrace.h" +#include "asm/pgtable.h" +#include "asm/pgalloc.h" +#include "asm/uaccess.h" +#include "user_util.h" +#include "kern_util.h" +#include "kern.h" +#include "irq_user.h" +#include "tlb.h" +#include "2_5compat.h" + +/* See comment above fork_tramp for why sigstop is defined and used like + * this + */ + +static int sigstop = SIGSTOP; + +static int exec_tramp(void *sig_stack) +{ + int sig = sigstop; + + block_signals(); + init_new_thread(sig_stack, NULL); + kill(getpid(), sig); + return(0); +} + +void flush_thread(void) +{ + unsigned long stack; + int new_pid; + + stack = alloc_stack(); + new_pid = start_fork_tramp((void *) current->thread.kernel_stack, + stack, 0, exec_tramp); + if(new_pid < 0){ + printk(KERN_ERR + "flush_thread : new thread failed, errno = %d\n", + errno); + do_exit(SIGKILL); + } + + if(CPU(current) == 0) + forward_interrupts(new_pid); + current->thread.request.op = OP_EXEC; + current->thread.request.u.exec.pid = new_pid; + unprotect_stack((unsigned long) current); + usr1_pid(getpid()); + + free_page(stack); + protect(uml_physmem, high_physmem - uml_physmem, 1, 1, 0, 1); + task_protections((unsigned long) current); + force_flush_all(); + unblock_signals(); +} + +void start_thread(struct pt_regs * regs, unsigned long eip, unsigned long esp) +{ + set_fs(USER_DS); + flush_tlb_mm(current->mm); + UM_IP(¤t->thread.process_regs) = eip; + UM_SP(¤t->thread.process_regs) = esp; + UM_ELF_ZERO(¤t->thread.process_regs) = 0; + UM_FIX_EXEC_STACK(esp); +} + +static int execve1(char *file, char **argv, char **env) +{ + int error; + + error = do_execve(file, argv, env, + (struct pt_regs *) ¤t->thread.process_regs); + if (error == 0){ + current->ptrace &= ~PT_DTRACE; + set_cmdline(current_cmd()); + } + return(error); +} + +int um_execve(char *file, char **argv, char **env) +{ + if(execve1(file, argv, env) == 0) set_user_mode(current, 1, 1); + return(-1); +} + +int sys_execve(char *file, char **argv, char **env) +{ + int error; + char *filename; + + lock_kernel(); + filename = getname((char *) file); + error = PTR_ERR(filename); + if (IS_ERR(filename)) goto out; + error = execve1(filename, argv, env); + putname(filename); + out: + unlock_kernel(); + return(error); +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/kernel/exec_user.c linux_umopenmosix/arch/um/kernel/exec_user.c --- linux-2.4.17/arch/um/kernel/exec_user.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/kernel/exec_user.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2000 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "user_util.h" +#include "kern_util.h" +#include "user.h" + +void do_exec(int old_pid, int new_pid) +{ + struct sys_pt_regs regs; + + if((ptrace(PTRACE_ATTACH, new_pid, 0, 0) < 0) || + (ptrace(PTRACE_CONT, new_pid, 0, 0) < 0) || + (waitpid(new_pid, 0, WUNTRACED) < 0)) + tracer_panic("do_exec failed to attach proc"); + + if(ptrace_getregs(old_pid, ®s) < 0) + tracer_panic("do_exec failed to get registers"); + + kill(old_pid, SIGKILL); + + if(ptrace_setregs(new_pid, ®s) < 0) + tracer_panic("do_exec failed to start new proc"); +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/kernel/frame_kern.c linux_umopenmosix/arch/um/kernel/frame_kern.c --- linux-2.4.17/arch/um/kernel/frame_kern.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/kernel/frame_kern.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,118 @@ +/* + * Copyright (C) 2002 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include "asm/ptrace.h" +#include "asm/uaccess.h" +#include "frame.h" +#include "frame_kern.h" +#include "sigcontext.h" +#include "sysdep/ptrace.h" + +int copy_siginfo_to_user(siginfo_t *to, siginfo_t *from) +{ + if (!access_ok (VERIFY_WRITE, to, sizeof(siginfo_t))) + return -EFAULT; + if (from->si_code < 0) + return __copy_to_user(to, from, sizeof(siginfo_t)); + else { + int err; + + /* If you change siginfo_t structure, please be sure + this code is fixed accordingly. + It should never copy any pad contained in the structure + to avoid security leaks, but must copy the generic + 3 ints plus the relevant union member. */ + err = __put_user(from->si_signo, &to->si_signo); + err |= __put_user(from->si_errno, &to->si_errno); + err |= __put_user((short)from->si_code, &to->si_code); + /* First 32bits of unions are always present. */ + err |= __put_user(from->si_pid, &to->si_pid); + switch (from->si_code >> 16) { + case __SI_FAULT >> 16: + break; + case __SI_CHLD >> 16: + err |= __put_user(from->si_utime, &to->si_utime); + err |= __put_user(from->si_stime, &to->si_stime); + err |= __put_user(from->si_status, &to->si_status); + default: + err |= __put_user(from->si_uid, &to->si_uid); + break; + } + return err; + } +} + +static int copy_restorer(void (*restorer)(void), unsigned long start, + unsigned long sr_index, int sr_relative) +{ + if(restorer != 0){ + if(copy_to_user((void *) (start + sr_index), &restorer, + sizeof(restorer))) + return(1); + } + else if(sr_relative){ + unsigned long *sr = (unsigned long *) (start + sr_index); + *sr += (unsigned long) sr; + } + return(0); +} + +int setup_signal_stack_si(unsigned long stack_top, int sig, + unsigned long handler, void (*restorer)(void), + struct sys_pt_regs *regs, siginfo_t *info) +{ + unsigned long start = stack_top - signal_frame_si.len; + void *sip = (void *) (start + signal_frame_si.si_index); + + if(copy_to_user((void *) start, signal_frame_si.data, + signal_frame_si.len) || + copy_to_user((void *) (start + signal_frame_si.sig_index), &sig, + sizeof(sig)) || + copy_siginfo_to_user(sip, info) || + copy_to_user((void *) (start + signal_frame_si.sip_index), &sip, + sizeof(sip)) || + copy_restorer(restorer, start, signal_frame_si.sr_index, + signal_frame_si.sr_relative)) + return(1); + + UM_IP(regs) = handler; + UM_SP(regs) = start + signal_frame_sc.sp_index; + return(0); +} + +int setup_signal_stack_sc(unsigned long stack_top, int sig, + unsigned long handler, void (*restorer)(void), + struct sys_pt_regs *regs, void *sc, void *context_sc) +{ + unsigned long start = stack_top - signal_frame_sc.len; + void *user_sc = (void *) (start + signal_frame_sc.sc_index); + + if(copy_to_user((void *) start, signal_frame_sc.data, + signal_frame_sc.len) || + copy_to_user((void *) (start + signal_frame_sc.sig_index), &sig, + sizeof(sig)) || + copy_sc_to_user(user_sc, sc, &signal_frame_sc.arch) || + copy_to_user(context_sc, &user_sc, sizeof(user_sc)) || + copy_restorer(restorer, start, signal_frame_sc.sr_index, + signal_frame_sc.sr_relative)) + return(1); + + UM_IP(regs) = handler; + UM_SP(regs) = start + signal_frame_sc.sp_index; + + set_sc_ip_sp(sc, handler, start + signal_frame_sc.sp_index); + return(0); +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/kernel/frame_user.c linux_umopenmosix/arch/um/kernel/frame_user.c --- linux-2.4.17/arch/um/kernel/frame_user.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/kernel/frame_user.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,286 @@ +/* + * Copyright (C) 2002 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "sysdep/ptrace.h" +#include "sysdep/frame.h" +#include "sysdep/sigcontext.h" +#include "frame.h" +#include "kern_util.h" + +static int capture_stack(int (*child)(void *arg), void *arg, void *sp, + unsigned long top, void **data_out) +{ + struct sys_pt_regs regs; + int pid, status, n, len; + + /* Start the child as a thread */ + pid = clone(child, sp, CLONE_VM | SIGCHLD, arg); + if(pid < 0){ + printf("setup_stack : clone failed - errno = %d\n", errno); + exit(1); + } + + /* Wait for it to stop itself and continue it with a SIGUSR1 to force + * it into the signal handler. + */ + n = waitpid(-1, &status, WUNTRACED); + if(n < 0){ + printf("setup_stack : waitpid failed - errno = %d\n", errno); + exit(1); + } + if(!WIFSTOPPED(status) || (WSTOPSIG(status) != SIGSTOP)){ + fprintf(stderr, "Expected SIGSTOP, got status = 0x%x\n", + status); + exit(1); + } + if(ptrace(PTRACE_CONT, pid, 0, SIGUSR1) < 0){ + printf("setup_stack : PTRACE_CONT failed - errno = %d\n", + errno); + exit(1); + } + + /* Wait for it to stop itself again and grab its registers again. + * At this point, the handler has stuffed the addresses of + * sig, sc, and SA_RESTORER in raw. + */ + n = waitpid(pid, &status, WUNTRACED); + if(n < 0){ + printf("setup_stack : waitpid failed - errno = %d\n", errno); + exit(1); + } + if(!WIFSTOPPED(status) || (WSTOPSIG(status) != SIGSTOP)){ + fprintf(stderr, "Expected SIGSTOP, got status = 0x%x\n", + status); + exit(1); + } + if(ptrace(PTRACE_GETREGS, pid, 0, ®s) < 0){ + printf("setup_stack : PTRACE_GETREGS failed - errno = %d\n", + errno); + exit(1); + } + + /* It has outlived its usefulness, so continue it so it can exit */ + if(ptrace(PTRACE_CONT, pid, 0, 0) < 0){ + printf("setup_stack : mmap failed - errno = %d\n", errno); + exit(1); + } + if(waitpid(pid, &status, 0) < 0){ + printf("setup_stack : waitpid failed - errno = %d\n", errno); + exit(1); + } + if(!WIFEXITED(status) || (WEXITSTATUS(status) != 0)){ + printf("setup_stack : Expected exit status 0, " + "got status = 0x%x\n", status); + exit(1); + } + + /* The frame that we want is the top of the signal stack */ + len = top - UM_SP(®s); + *data_out = malloc(len); + if(*data_out == NULL){ + printf("setup_stack : malloc failed - errno = %d\n", errno); + exit(1); + } + memcpy(*data_out, (void *) UM_SP(®s), len); + + return(len); +} + +static void child_common(void *sp, int size, sighandler_t handler, int flags) +{ + stack_t ss; + struct sigaction sa; + + ptrace(PTRACE_TRACEME, 0, 0, 0); + ss.ss_sp = sp; + ss.ss_flags = 0; + ss.ss_size = size; + if(sigaltstack(&ss, NULL) < 0){ + printf("sigaltstack failed - errno = %d\n", errno); + exit(1); + } + + sa.sa_handler = handler; + sigemptyset(&sa.sa_mask); + sa.sa_flags = SA_ONSTACK | flags; + if(sigaction(SIGUSR1, &sa, NULL) < 0){ + printf("sigaction failed - errno = %d\n", errno); + exit(1); + } + + kill(getpid(), SIGSTOP); +} + +struct sc_frame signal_frame_sc; + +struct sc_frame_raw { + void *stack; + int size; + unsigned long sig; + unsigned long sc; + unsigned long sr; + unsigned long sp; + struct arch_frame_data_raw arch; +}; + +static struct sc_frame_raw *raw_sc = NULL; + +static void sc_handler(int sig, struct sigcontext sc) +{ + raw_sc->sig = (unsigned long) &sig; + raw_sc->sc = (unsigned long) ≻ + raw_sc->sr = frame_restorer(); + raw_sc->sp = frame_sp(); + setup_arch_frame_raw(&raw_sc->arch, &sc); + kill(getpid(), SIGSTOP); + exit(0); +} + +static int sc_child(void *arg) +{ + raw_sc = arg; + child_common(raw_sc->stack, raw_sc->size, (sighandler_t) sc_handler, + 0); + return(0); +} + +struct si_frame signal_frame_si; + +struct si_frame_raw { + void *stack; + int size; + unsigned long sig; + unsigned long sip; + unsigned long si; + unsigned long sr; + unsigned long sp; +}; + +static struct si_frame_raw *raw_si = NULL; + +static void si_handler(int sig, siginfo_t *si) +{ + raw_si->sig = (unsigned long) &sig; + raw_si->sip = (unsigned long) &si; + raw_si->si = (unsigned long) si; + raw_si->sr = frame_restorer(); + raw_si->sp = frame_sp(); + kill(getpid(), SIGSTOP); + exit(0); +} + +static int si_child(void *arg) +{ + raw_si = arg; + child_common(raw_si->stack, raw_si->size, (sighandler_t) si_handler, + SA_SIGINFO); + return(0); +} + +void capture_signal_stack(void) +{ + struct sc_frame_raw raw_sc; + struct si_frame_raw raw_si; + void *stack, *sigstack; + unsigned long top, sig_top, base; + + stack = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + sigstack = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if((stack == MAP_FAILED) || (sigstack == MAP_FAILED)){ + printf("setup_stack : mmap failed - errno = %d\n", errno); + exit(1); + } + + top = (unsigned long) stack + PAGE_SIZE - sizeof(void *); + sig_top = (unsigned long) sigstack + PAGE_SIZE; + + raw_sc.stack = sigstack; + raw_sc.size = PAGE_SIZE; + signal_frame_sc.len = capture_stack(sc_child, &raw_sc, (void *) top, + sig_top, &signal_frame_sc.data); + + /* These are the offsets within signal_frame_sc.data (counting from + * the bottom) of sig, sc, SA_RESTORER, and the initial sp. + */ + base = sig_top - signal_frame_sc.len; + signal_frame_sc.sig_index = raw_sc.sig - base; + signal_frame_sc.sc_index = raw_sc.sc - base; + signal_frame_sc.sr_index = raw_sc.sr - base; + if((*((unsigned long *) raw_sc.sr) & PAGE_MASK) == + (unsigned long) sigstack){ + unsigned long *sr = (unsigned long *) raw_sc.sr; + unsigned long frame = (unsigned long) signal_frame_sc.data; + + signal_frame_sc.sr_relative = 1; + *sr -= raw_sc.sr; + *((unsigned long *) (frame + signal_frame_sc.sr_index)) = *sr; + } + else signal_frame_sc.sr_relative = 0; + signal_frame_sc.sp_index = raw_sc.sp - base; + setup_arch_frame(&raw_sc.arch, &signal_frame_sc.arch); + + /* Repeat for the siginfo variant */ + + raw_si.stack = sigstack; + raw_si.size = PAGE_SIZE; + signal_frame_si.len = capture_stack(si_child, &raw_si, (void *) top, + sig_top, &signal_frame_si.data); + base = sig_top - signal_frame_si.len; + signal_frame_si.sig_index = raw_si.sig - base; + signal_frame_si.sip_index = raw_si.sip - base; + signal_frame_si.si_index = raw_si.si - base; + signal_frame_si.sr_index = raw_si.sr - base; + if((*((unsigned long *) raw_si.sr) & PAGE_MASK) == + (unsigned long) sigstack){ + unsigned long *sr = (unsigned long *) raw_si.sr; + unsigned long frame = (unsigned long) signal_frame_si.data; + + signal_frame_sc.sr_relative = 1; + *sr -= raw_si.sr; + *((unsigned long *) (frame + signal_frame_si.sr_index)) = *sr; + } + else signal_frame_si.sr_relative = 0; + signal_frame_si.sp_index = raw_si.sp - base; + + if((munmap(stack, PAGE_SIZE) < 0) || + (munmap(sigstack, PAGE_SIZE) < 0)){ + printf("setup_stack : munmap failed - errno = %d\n", errno); + exit(1); + } +} + +void set_sc_ip_sp(void *sc_ptr, unsigned long ip, unsigned long sp) +{ + struct sigcontext *sc = sc_ptr; + + SC_IP(sc) = ip; + SC_SP(sc) = sp; +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/kernel/gmon_syms.c linux_umopenmosix/arch/um/kernel/gmon_syms.c --- linux-2.4.17/arch/um/kernel/gmon_syms.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/kernel/gmon_syms.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include "linux/module.h" + +extern void __bb_init_func(void *); +EXPORT_SYMBOL(__bb_init_func); + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/kernel/gprof_syms.c linux_umopenmosix/arch/um/kernel/gprof_syms.c --- linux-2.4.17/arch/um/kernel/gprof_syms.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/kernel/gprof_syms.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include "linux/module.h" + +extern void mcount(void); +EXPORT_SYMBOL(mcount); + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/kernel/i387.c linux_umopenmosix/arch/um/kernel/i387.c --- linux-2.4.17/arch/um/kernel/i387.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/kernel/i387.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,596 @@ +/* + * linux/arch/i386/kernel/i387.c + * + * Copyright (C) 1994 Linus Torvalds + * + * Pentium III FXSR, SSE support + * General FPU state handling cleanups + * Gareth Hughes , May 2000 + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef CONFIG_MATH_EMULATION +#define HAVE_HWFP (boot_cpu_data.hard_math) +#else +#define HAVE_HWFP 1 +#endif + +/* + * The _current_ task is using the FPU for the first time + * so initialize it and set the mxcsr to its default + * value at reset if we support XMM instructions and then + * remeber the current task has used the FPU. + */ +void init_fpu(void) +{ + __asm__("fninit"); + if ( cpu_has_xmm ) + load_mxcsr(0x1f80); + + current->used_math = 1; +} + +/* + * FPU lazy state save handling. + */ + +static inline void __save_init_fpu( struct task_struct *tsk ) +{ + if ( cpu_has_fxsr ) { + asm volatile( "fxsave %0 ; fnclex" + : "=m" (tsk->thread.i387.fxsave) ); + } else { + asm volatile( "fnsave %0 ; fwait" + : "=m" (tsk->thread.i387.fsave) ); + } + tsk->flags &= ~PF_USEDFPU; +} + +void save_init_fpu( struct task_struct *tsk ) +{ + __save_init_fpu(tsk); + stts(); +} + +void kernel_fpu_begin(void) +{ + struct task_struct *tsk = current; + + if (tsk->flags & PF_USEDFPU) { + __save_init_fpu(tsk); + return; + } + clts(); +} + +void restore_fpu( struct task_struct *tsk ) +{ + if ( cpu_has_fxsr ) { + asm volatile( "fxrstor %0" + : : "m" (tsk->thread.i387.fxsave) ); + } else { + asm volatile( "frstor %0" + : : "m" (tsk->thread.i387.fsave) ); + } +} + +/* + * FPU tag word conversions. + */ + +static inline unsigned short twd_i387_to_fxsr( unsigned short twd ) +{ + unsigned int tmp; /* to avoid 16 bit prefixes in the code */ + + /* Transform each pair of bits into 01 (valid) or 00 (empty) */ + tmp = ~twd; + tmp = (tmp | (tmp>>1)) & 0x5555; /* 0V0V0V0V0V0V0V0V */ + /* and move the valid bits to the lower byte. */ + tmp = (tmp | (tmp >> 1)) & 0x3333; /* 00VV00VV00VV00VV */ + tmp = (tmp | (tmp >> 2)) & 0x0f0f; /* 0000VVVV0000VVVV */ + tmp = (tmp | (tmp >> 4)) & 0x00ff; /* 00000000VVVVVVVV */ + return tmp; +} + +static inline unsigned long twd_fxsr_to_i387( struct i387_fxsave_struct *fxsave ) +{ + struct _fpxreg *st = NULL; + unsigned long twd = (unsigned long) fxsave->twd; + unsigned long tag; + unsigned long ret = 0xffff0000; + int i; + +#define FPREG_ADDR(f, n) ((char *)&(f)->st_space + (n) * 16); + + for ( i = 0 ; i < 8 ; i++ ) { + if ( twd & 0x1 ) { + st = (struct _fpxreg *) FPREG_ADDR( fxsave, i ); + + switch ( st->exponent & 0x7fff ) { + case 0x7fff: + tag = 2; /* Special */ + break; + case 0x0000: + if ( !st->significand[0] && + !st->significand[1] && + !st->significand[2] && + !st->significand[3] ) { + tag = 1; /* Zero */ + } else { + tag = 2; /* Special */ + } + break; + default: + if ( st->significand[3] & 0x8000 ) { + tag = 0; /* Valid */ + } else { + tag = 2; /* Special */ + } + break; + } + } else { + tag = 3; /* Empty */ + } + ret |= (tag << (2 * i)); + twd = twd >> 1; + } + return ret; +} + +/* + * FPU state interaction. + */ + +unsigned short get_fpu_cwd( struct task_struct *tsk ) +{ + if ( cpu_has_fxsr ) { + return tsk->thread.i387.fxsave.cwd; + } else { + return (unsigned short)tsk->thread.i387.fsave.cwd; + } +} + +unsigned short get_fpu_swd( struct task_struct *tsk ) +{ + if ( cpu_has_fxsr ) { + return tsk->thread.i387.fxsave.swd; + } else { + return (unsigned short)tsk->thread.i387.fsave.swd; + } +} + +unsigned short get_fpu_twd( struct task_struct *tsk ) +{ + if ( cpu_has_fxsr ) { + return tsk->thread.i387.fxsave.twd; + } else { + return (unsigned short)tsk->thread.i387.fsave.twd; + } +} + +unsigned short get_fpu_mxcsr( struct task_struct *tsk ) +{ + if ( cpu_has_xmm ) { + return tsk->thread.i387.fxsave.mxcsr; + } else { + return 0x1f80; + } +} + +void set_fpu_cwd( struct task_struct *tsk, unsigned short cwd ) +{ + if ( cpu_has_fxsr ) { + tsk->thread.i387.fxsave.cwd = cwd; + } else { + tsk->thread.i387.fsave.cwd = ((long)cwd | 0xffff0000); + } +} + +void set_fpu_swd( struct task_struct *tsk, unsigned short swd ) +{ + if ( cpu_has_fxsr ) { + tsk->thread.i387.fxsave.swd = swd; + } else { + tsk->thread.i387.fsave.swd = ((long)swd | 0xffff0000); + } +} + +void set_fpu_twd( struct task_struct *tsk, unsigned short twd ) +{ + if ( cpu_has_fxsr ) { + tsk->thread.i387.fxsave.twd = twd_i387_to_fxsr(twd); + } else { + tsk->thread.i387.fsave.twd = ((long)twd | 0xffff0000); + } +} + +void set_fpu_mxcsr( struct task_struct *tsk, unsigned short mxcsr ) +{ + if ( cpu_has_xmm ) { + tsk->thread.i387.fxsave.mxcsr = (mxcsr & 0xffbf); + } +} + +/* + * FXSR floating point environment conversions. + */ + +static inline int convert_fxsr_to_user( struct _fpstate *buf, + struct i387_fxsave_struct *fxsave ) +{ + unsigned long env[7]; + struct _fpreg *to; + struct _fpxreg *from; + int i; + + env[0] = (unsigned long)fxsave->cwd | 0xffff0000; + env[1] = (unsigned long)fxsave->swd | 0xffff0000; + env[2] = twd_fxsr_to_i387(fxsave); + env[3] = fxsave->fip; + env[4] = fxsave->fcs | ((unsigned long)fxsave->fop << 16); + env[5] = fxsave->foo; + env[6] = fxsave->fos; + + if ( __copy_to_user( buf, env, 7 * sizeof(unsigned long) ) ) + return 1; + + to = &buf->_st[0]; + from = (struct _fpxreg *) &fxsave->st_space[0]; + for ( i = 0 ; i < 8 ; i++, to++, from++ ) { + if ( __copy_to_user( to, from, sizeof(*to) ) ) + return 1; + } + return 0; +} + +static inline int convert_fxsr_from_user( struct i387_fxsave_struct *fxsave, + struct _fpstate *buf ) +{ + unsigned long env[7]; + struct _fpxreg *to; + struct _fpreg *from; + int i; + + if ( __copy_from_user( env, buf, 7 * sizeof(long) ) ) + return 1; + + fxsave->cwd = (unsigned short)(env[0] & 0xffff); + fxsave->swd = (unsigned short)(env[1] & 0xffff); + fxsave->twd = twd_i387_to_fxsr((unsigned short)(env[2] & 0xffff)); + fxsave->fip = env[3]; + fxsave->fop = (unsigned short)((env[4] & 0xffff0000) >> 16); + fxsave->fcs = (env[4] & 0xffff); + fxsave->foo = env[5]; + fxsave->fos = env[6]; + + to = (struct _fpxreg *) &fxsave->st_space[0]; + from = &buf->_st[0]; + for ( i = 0 ; i < 8 ; i++, to++, from++ ) { + if ( __copy_from_user( to, from, sizeof(*from) ) ) + return 1; + } + return 0; +} + +/* + * Signal frame handlers. + */ + +static inline int save_i387_fsave( struct _fpstate *buf ) +{ + struct task_struct *tsk = current; + + unlazy_fpu( tsk ); + tsk->thread.i387.fsave.status = tsk->thread.i387.fsave.swd; + if ( __copy_to_user( buf, &tsk->thread.i387.fsave, + sizeof(struct i387_fsave_struct) ) ) + return -1; + return 1; +} + +static inline int save_i387_fxsave( struct _fpstate *buf ) +{ + struct task_struct *tsk = current; + int err = 0; + + unlazy_fpu( tsk ); + + if ( convert_fxsr_to_user( buf, &tsk->thread.i387.fxsave ) ) + return -1; + + err |= __put_user( tsk->thread.i387.fxsave.swd, &buf->status ); + err |= __put_user( X86_FXSR_MAGIC, &buf->magic ); + if ( err ) + return -1; + + if ( __copy_to_user( &buf->_fxsr_env[0], &tsk->thread.i387.fxsave, + sizeof(struct i387_fxsave_struct) ) ) + return -1; + return 1; +} + +int save_i387( struct _fpstate *buf ) +{ + if ( !current->used_math ) + return 0; + + /* This will cause a "finit" to be triggered by the next + * attempted FPU operation by the 'current' process. + */ + current->used_math = 0; + + if ( HAVE_HWFP ) { + if ( cpu_has_fxsr ) { + return save_i387_fxsave( buf ); + } else { + return save_i387_fsave( buf ); + } + } else { + return save_i387_soft( ¤t->thread.i387.soft, buf ); + } +} + +static inline int restore_i387_fsave( struct _fpstate *buf ) +{ + struct task_struct *tsk = current; + clear_fpu( tsk ); + return __copy_from_user( &tsk->thread.i387.fsave, buf, + sizeof(struct i387_fsave_struct) ); +} + +static inline int restore_i387_fxsave( struct _fpstate *buf ) +{ + struct task_struct *tsk = current; + clear_fpu( tsk ); + if ( __copy_from_user( &tsk->thread.i387.fxsave, &buf->_fxsr_env[0], + sizeof(struct i387_fxsave_struct) ) ) + return 1; + /* mxcsr bit 6 and 31-16 must be zero for security reasons */ + tsk->thread.i387.fxsave.mxcsr &= 0xffbf; + return convert_fxsr_from_user( &tsk->thread.i387.fxsave, buf ); +} + +int restore_i387( struct _fpstate *buf ) +{ + int err; + + if ( HAVE_HWFP ) { + if ( cpu_has_fxsr ) { + err = restore_i387_fxsave( buf ); + } else { + err = restore_i387_fsave( buf ); + } + } else { + err = restore_i387_soft( ¤t->thread.i387.soft, buf ); + } + current->used_math = 1; + return err; +} + +/* + * ptrace request handlers. + */ + +static inline int get_fpregs_fsave( struct user_i387_struct *buf, + struct task_struct *tsk ) +{ + return __copy_to_user( buf, &tsk->thread.i387.fsave, + sizeof(struct user_i387_struct) ); +} + +static inline int get_fpregs_fxsave( struct user_i387_struct *buf, + struct task_struct *tsk ) +{ + return convert_fxsr_to_user( (struct _fpstate *)buf, + &tsk->thread.i387.fxsave ); +} + +int get_fpregs( struct user_i387_struct *buf, struct task_struct *tsk ) +{ + if ( HAVE_HWFP ) { + if ( cpu_has_fxsr ) { + return get_fpregs_fxsave( buf, tsk ); + } else { + return get_fpregs_fsave( buf, tsk ); + } + } else { + return save_i387_soft( &tsk->thread.i387.soft, + (struct _fpstate *)buf ); + } +} + +static inline int set_fpregs_fsave( struct task_struct *tsk, + struct user_i387_struct *buf ) +{ + return __copy_from_user( &tsk->thread.i387.fsave, buf, + sizeof(struct user_i387_struct) ); +} + +static inline int set_fpregs_fxsave( struct task_struct *tsk, + struct user_i387_struct *buf ) +{ + return convert_fxsr_from_user( &tsk->thread.i387.fxsave, + (struct _fpstate *)buf ); +} + +int set_fpregs( struct task_struct *tsk, struct user_i387_struct *buf ) +{ + if ( HAVE_HWFP ) { + if ( cpu_has_fxsr ) { + return set_fpregs_fxsave( tsk, buf ); + } else { + return set_fpregs_fsave( tsk, buf ); + } + } else { + return restore_i387_soft( &tsk->thread.i387.soft, + (struct _fpstate *)buf ); + } +} + +int get_fpxregs( struct user_fxsr_struct *buf, struct task_struct *tsk ) +{ + if ( cpu_has_fxsr ) { + if (__copy_to_user( (void *)buf, &tsk->thread.i387.fxsave, + sizeof(struct user_fxsr_struct) )) + return -EFAULT; + return 0; + } else { + return -EIO; + } +} + +int set_fpxregs( struct task_struct *tsk, struct user_fxsr_struct *buf ) +{ + if ( cpu_has_fxsr ) { + __copy_from_user( &tsk->thread.i387.fxsave, (void *)buf, + sizeof(struct user_fxsr_struct) ); + /* mxcsr bit 6 and 31-16 must be zero for security reasons */ + tsk->thread.i387.fxsave.mxcsr &= 0xffbf; + return 0; + } else { + return -EIO; + } +} + +/* + * FPU state for core dumps. + */ + +static inline void copy_fpu_fsave( struct task_struct *tsk, + struct user_i387_struct *fpu ) +{ + memcpy( fpu, &tsk->thread.i387.fsave, + sizeof(struct user_i387_struct) ); +} + +static inline void copy_fpu_fxsave( struct task_struct *tsk, + struct user_i387_struct *fpu ) +{ + unsigned short *to; + unsigned short *from; + int i; + + memcpy( fpu, &tsk->thread.i387.fxsave, 7 * sizeof(long) ); + + to = (unsigned short *)&fpu->st_space[0]; + from = (unsigned short *)&tsk->thread.i387.fxsave.st_space[0]; + for ( i = 0 ; i < 8 ; i++, to += 5, from += 8 ) { + memcpy( to, from, 5 * sizeof(unsigned short) ); + } +} + + + + +/* +int dump_fpu( struct pt_regs *regs, struct user_i387_struct *fpu ) +{ + int fpvalid; + struct task_struct *tsk = current; + + fpvalid = tsk->used_math; + if ( fpvalid ) { + unlazy_fpu( tsk ); + if ( cpu_has_fxsr ) { + copy_fpu_fxsave( tsk, fpu ); + } else { + copy_fpu_fsave( tsk, fpu ); + } + } + + return fpvalid; +} +*/ + + + + + + + +int dump_extended_fpu( struct pt_regs *regs, struct user_fxsr_struct *fpu ) +{ + int fpvalid; + struct task_struct *tsk = current; + + fpvalid = tsk->used_math && cpu_has_fxsr; + if ( fpvalid ) { + unlazy_fpu( tsk ); + memcpy( fpu, &tsk->thread.i387.fxsave, + sizeof(struct user_fxsr_struct) ); + } + + return fpvalid; +} + +#ifdef CONFIG_MOSIX + +int +has_fxsr(void) +{ + return(cpu_has_fxsr); +} + +void +fsave_to_fxsave(union i387_union *from, union i387_union *to) +{ + int i; + long *fcp, *tcp; + + to->fxsave.cwd = from->fsave.cwd; + to->fxsave.swd = from->fsave.swd; + to->fxsave.twd = twd_i387_to_fxsr(from->fsave.twd); + to->fxsave.fop = from->fxsave.padding[0]; + to->fxsave.fip = from->fsave.fip; + to->fxsave.fcs = from->fsave.fcs; + to->fxsave.foo = from->fsave.foo; + to->fxsave.mxcsr = from->fxsave.padding[1]; + to->fxsave.fos = from->fsave.fos; + for(fcp = from->fsave.st_space , tcp = to->fxsave.st_space , + i = 0 ; i < 8 ; i++) + { + *tcp++ = *fcp++; + *tcp++ = *fcp++; + *tcp = *((unsigned short *)fcp)++; + tcp += 2; + } + memcpy(to->fxsave.xmm_space, from->fxsave.xmm_space, + sizeof(from->fxsave.xmm_space)); +} + +void +fxsave_to_fsave(union i387_union *from, union i387_union *to) +{ + int i; + long *fcp, *tcp; + + to->fsave.cwd = from->fxsave.cwd; + to->fsave.swd = from->fxsave.swd; + to->fsave.twd = twd_fxsr_to_i387(&from->fxsave); + to->fsave.fip = from->fxsave.fip; + to->fsave.fcs = from->fxsave.fcs; + to->fsave.foo = from->fxsave.foo; + to->fsave.fos = from->fxsave.fos; + to->fxsave.padding[0] = from->fxsave.fop; + to->fxsave.padding[1] = from->fxsave.mxcsr; + for(fcp = from->fxsave.st_space , tcp = to->fsave.st_space , + i = 0 ; i < 8 ; i++) + { + *tcp++ = *fcp++; + *tcp++ = *fcp++; + *((unsigned short *)tcp)++ = *fcp; + fcp += 2; + } + memcpy(to->fxsave.xmm_space, from->fxsave.xmm_space, + sizeof(to->fxsave.xmm_space)); +} +#endif /* CONFIG_MOSIX */ diff -urN linux-2.4.17/arch/um/kernel/init_task.c linux_umopenmosix/arch/um/kernel/init_task.c --- linux-2.4.17/arch/um/kernel/init_task.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/kernel/init_task.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2000 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include "linux/mm.h" +#include "linux/sched.h" +#include "linux/version.h" +#include "asm/uaccess.h" +#include "asm/pgtable.h" +#include "user_util.h" + +static struct fs_struct init_fs = INIT_FS; +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0) +static struct files_struct init_files = INIT_FILES; +static struct signal_struct init_signals = INIT_SIGNALS; +#endif +struct mm_struct init_mm = INIT_MM(init_mm); + +/* + * Initial task structure. + * + * We need to make sure that this is 16384-byte aligned due to the + * way process stacks are handled. This is done by having a special + * "init_task" linker map entry.. + */ + +union task_union init_task_union +__attribute__((__section__(".data.init_task"))) = +{ INIT_TASK(init_task_union.task) }; + +struct task_struct *alloc_task_struct(void){ + struct task_struct *task; + + task = (struct task_struct *) __get_free_pages(GFP_KERNEL, 2); + if(task == NULL) return(NULL); + return(task); +} + +void unprotect_stack(unsigned long stack) +{ + protect(stack, 4 * PAGE_SIZE, 1, 1, 0, 1); +} + +void free_task_struct(struct task_struct *task) +{ + /* free_pages decrements the page counter and only actually frees + * the pages if they are now not accessed by anything. + */ + free_pages((unsigned long) task, 2); +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/kernel/initrd_kern.c linux_umopenmosix/arch/um/kernel/initrd_kern.c --- linux-2.4.17/arch/um/kernel/initrd_kern.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/kernel/initrd_kern.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include "linux/init.h" +#include "linux/bootmem.h" +#include "linux/blk.h" +#include "asm/types.h" +#include "user_util.h" +#include "kern_util.h" +#include "initrd.h" +#include "init.h" + +extern __u64 file_size(char *file); + +static char *initrd __initdata = NULL; + +static int __init read_initrd(void) +{ + void *area; + int size; + + if(initrd == NULL) return 0; + size = file_size(initrd); + if(size < 0) return 0; + area = alloc_bootmem(size); + if(area == NULL) return 0; + if(load_initrd(initrd, area, size) == -1) return 0; + initrd_start = (unsigned long) area; + initrd_end = initrd_start + size; + return 0; +} + +__uml_postsetup(read_initrd); + +static int __init uml_initrd_setup(char *line, int *add) +{ + initrd = line; + return 0; +} + +__uml_setup("initrd=", uml_initrd_setup, +"initrd=\n" +" This is used to boot UML from an initrd image. The argument is the\n" +" name of the file containing the image\n" +); + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/kernel/initrd_user.c linux_umopenmosix/arch/um/kernel/initrd_user.c --- linux-2.4.17/arch/um/kernel/initrd_user.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/kernel/initrd_user.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2000, 2001 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include +#include +#include +#include +#include + +#include "user_util.h" +#include "kern_util.h" +#include "user.h" +#include "initrd.h" + +int load_initrd(char *filename, void *buf, int size) +{ + int fd, n; + + if((fd = open(filename, O_RDONLY)) == -1){ + printk("Opening '%s' failed - errno = %d\n", filename, errno); + return(-1); + } + if((n = read(fd, buf, size)) != size){ + printk("Read of %d bytes from '%s' returned %d, errno = %d\n", + size, filename, n, errno); + return(-1); + } + return(0); +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/kernel/irq.c linux_umopenmosix/arch/um/kernel/irq.c --- linux-2.4.17/arch/um/kernel/irq.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/kernel/irq.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,814 @@ +/* + * Copyright (C) 2000 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + * Derived (i.e. mostly copied) from arch/i386/kernel/irq.c: + * Copyright (C) 1992, 1998 Linus Torvalds, Ingo Molnar + */ + +#include "linux/config.h" +#include "linux/kernel.h" +#include "linux/smp.h" +#include "linux/irq.h" +#include "linux/kernel_stat.h" +#include "linux/interrupt.h" +#include "linux/random.h" +#include "linux/slab.h" +#include "linux/file.h" +#include "linux/proc_fs.h" +#include "linux/init.h" +#include "linux/seq_file.h" +#include "asm/irq.h" +#include "asm/hw_irq.h" +#include "asm/hardirq.h" +#include "asm/atomic.h" +#include "asm/signal.h" +#include "asm/system.h" +#include "asm/errno.h" +#include "asm/uaccess.h" +#include "user_util.h" +#include "irq_user.h" + +static void register_irq_proc (unsigned int irq); + +irq_desc_t irq_desc[NR_IRQS] __cacheline_aligned = + { [0 ... NR_IRQS-1] = { 0, &no_irq_type, NULL, 0, SPIN_LOCK_UNLOCKED}}; + +/* + * Generic no controller code + */ + +static void enable_none(unsigned int irq) { } +static unsigned int startup_none(unsigned int irq) { return 0; } +static void disable_none(unsigned int irq) { } +static void ack_none(unsigned int irq) +{ +/* + * 'what should we do if we get a hw irq event on an illegal vector'. + * each architecture has to answer this themselves, it doesnt deserve + * a generic callback i think. + */ +#if CONFIG_X86 + printk(KERN_ERR "unexpected IRQ trap at vector %02x\n", irq); +#ifdef CONFIG_X86_LOCAL_APIC + /* + * Currently unexpected vectors happen only on SMP and APIC. + * We _must_ ack these because every local APIC has only N + * irq slots per priority level, and a 'hanging, unacked' IRQ + * holds up an irq slot - in excessive cases (when multiple + * unexpected vectors occur) that might lock up the APIC + * completely. + */ + ack_APIC_irq(); +#endif +#endif +} + +/* startup is the same as "enable", shutdown is same as "disable" */ +#define shutdown_none disable_none +#define end_none enable_none + +struct hw_interrupt_type no_irq_type = { + "none", + startup_none, + shutdown_none, + enable_none, + disable_none, + ack_none, + end_none +}; + +volatile unsigned long irq_err_count; + +/* + * Generic, controller-independent functions: + */ + +int get_irq_list(char *buf) +{ + int i, j; + struct irqaction * action; + char *p = buf; + + p += sprintf(p, " "); + for (j=0; jtypename); + p += sprintf(p, " %s", action->name); + + for (action=action->next; action; action = action->next) + p += sprintf(p, ", %s", action->name); + *p++ = '\n'; + } + p += sprintf(p, "\n"); +#ifdef notdef +#if CONFIG_SMP + p += sprintf(p, "LOC: "); + for (j = 0; j < smp_num_cpus; j++) + p += sprintf(p, "%10u ", + apic_timer_irqs[cpu_logical_map(j)]); + p += sprintf(p, "\n"); +#endif +#endif + p += sprintf(p, "ERR: %10lu\n", irq_err_count); + return p - buf; +} + + +/* + * This should really return information about whether + * we should do bottom half handling etc. Right now we + * end up _always_ checking the bottom half, which is a + * waste of time and is not what some drivers would + * prefer. + */ +int handle_IRQ_event(unsigned int irq, struct pt_regs * regs, + struct irqaction * action) +{ + int status; + int cpu = smp_processor_id(); + + irq_enter(cpu, irq); + + status = 1; /* Force the "do bottom halves" bit */ + + if (!(action->flags & SA_INTERRUPT)) + __sti(); + + do { + status |= action->flags; + action->handler(irq, action->dev_id, regs); + action = action->next; + } while (action); + if (status & SA_SAMPLE_RANDOM) + add_interrupt_randomness(irq); + __cli(); + + irq_exit(cpu, irq); + + return status; +} + +/* + * Generic enable/disable code: this just calls + * down into the PIC-specific version for the actual + * hardware disable after having gotten the irq + * controller lock. + */ + +/** + * disable_irq_nosync - disable an irq without waiting + * @irq: Interrupt to disable + * + * Disable the selected interrupt line. Disables of an interrupt + * stack. Unlike disable_irq(), this function does not ensure existing + * instances of the IRQ handler have completed before returning. + * + * This function may be called from IRQ context. + */ + +void inline disable_irq_nosync(unsigned int irq) +{ + irq_desc_t *desc = irq_desc + irq; + unsigned long flags; + + spin_lock_irqsave(&desc->lock, flags); + if (!desc->depth++) { + desc->status |= IRQ_DISABLED; + desc->handler->disable(irq); + } + spin_unlock_irqrestore(&desc->lock, flags); +} + +/** + * disable_irq - disable an irq and wait for completion + * @irq: Interrupt to disable + * + * Disable the selected interrupt line. Disables of an interrupt + * stack. That is for two disables you need two enables. This + * function waits for any pending IRQ handlers for this interrupt + * to complete before returning. If you use this function while + * holding a resource the IRQ handler may need you will deadlock. + * + * This function may be called - with care - from IRQ context. + */ + +void disable_irq(unsigned int irq) +{ + disable_irq_nosync(irq); + + if (!local_irq_count(smp_processor_id())) { + do { + barrier(); + } while (irq_desc[irq].status & IRQ_INPROGRESS); + } +} + +/** + * enable_irq - enable interrupt handling on an irq + * @irq: Interrupt to enable + * + * Re-enables the processing of interrupts on this IRQ line + * providing no disable_irq calls are now in effect. + * + * This function may be called from IRQ context. + */ + +void enable_irq(unsigned int irq) +{ + irq_desc_t *desc = irq_desc + irq; + unsigned long flags; + + spin_lock_irqsave(&desc->lock, flags); + switch (desc->depth) { + case 1: { + unsigned int status = desc->status & ~IRQ_DISABLED; + desc->status = status; + if ((status & (IRQ_PENDING | IRQ_REPLAY)) == IRQ_PENDING) { + desc->status = status | IRQ_REPLAY; + hw_resend_irq(desc->handler,irq); + } + desc->handler->enable(irq); + /* fall-through */ + } + default: + desc->depth--; + break; + case 0: + printk(KERN_ERR "enable_irq() unbalanced from %p\n", + __builtin_return_address(0)); + } + spin_unlock_irqrestore(&desc->lock, flags); +} + +/* + * do_IRQ handles all normal device IRQ's (the special + * SMP cross-CPU interrupts have their own specific + * handlers). + */ +unsigned int do_IRQ(int irq, int user_mode) +{ + /* + * 0 return value means that this irq is already being + * handled by some other CPU. (or is disabled) + */ + int cpu = smp_processor_id(); + irq_desc_t *desc = irq_desc + irq; + struct irqaction * action; + struct pt_regs regs; + unsigned int status; + + regs.user_mode = user_mode; + kstat.irqs[cpu][irq]++; + spin_lock(&desc->lock); + desc->handler->ack(irq); + /* + REPLAY is when Linux resends an IRQ that was dropped earlier + WAITING is used by probe to mark irqs that are being tested + */ + status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING); + status |= IRQ_PENDING; /* we _want_ to handle it */ + + /* + * If the IRQ is disabled for whatever reason, we cannot + * use the action we have. + */ + action = NULL; + if (!(status & (IRQ_DISABLED | IRQ_INPROGRESS))) { + action = desc->action; + status &= ~IRQ_PENDING; /* we commit to handling */ + status |= IRQ_INPROGRESS; /* we are handling it */ + } + desc->status = status; + + /* + * If there is no IRQ handler or it was disabled, exit early. + Since we set PENDING, if another processor is handling + a different instance of this same irq, the other processor + will take care of it. + */ + if (!action) + goto out; + + /* + * Edge triggered interrupts need to remember + * pending events. + * This applies to any hw interrupts that allow a second + * instance of the same irq to arrive while we are in do_IRQ + * or in the handler. But the code here only handles the _second_ + * instance of the irq, not the third or fourth. So it is mostly + * useful for irq hardware that does not mask cleanly in an + * SMP environment. + */ + for (;;) { + spin_unlock(&desc->lock); + handle_IRQ_event(irq, ®s, action); + spin_lock(&desc->lock); + + if (!(desc->status & IRQ_PENDING)) + break; + desc->status &= ~IRQ_PENDING; + } + desc->status &= ~IRQ_INPROGRESS; +out: + /* + * The ->end() handler has to deal with interrupts which got + * disabled while the handler was running. + */ + desc->handler->end(irq); + spin_unlock(&desc->lock); + + if (softirq_pending(cpu)) + do_softirq(); + return 1; +} + +/** + * request_irq - allocate an interrupt line + * @irq: Interrupt line to allocate + * @handler: Function to be called when the IRQ occurs + * @irqflags: Interrupt type flags + * @devname: An ascii name for the claiming device + * @dev_id: A cookie passed back to the handler function + * + * This call allocates interrupt resources and enables the + * interrupt line and IRQ handling. From the point this + * call is made your handler function may be invoked. Since + * your handler function must clear any interrupt the board + * raises, you must take care both to initialise your hardware + * and to set up the interrupt handler in the right order. + * + * Dev_id must be globally unique. Normally the address of the + * device data structure is used as the cookie. Since the handler + * receives this value it makes sense to use it. + * + * If your interrupt is shared you must pass a non NULL dev_id + * as this is required when freeing the interrupt. + * + * Flags: + * + * SA_SHIRQ Interrupt is shared + * + * SA_INTERRUPT Disable local interrupts while processing + * + * SA_SAMPLE_RANDOM The interrupt can be used for entropy + * + */ + +int request_irq(unsigned int irq, + void (*handler)(int, void *, struct pt_regs *), + unsigned long irqflags, + const char * devname, + void *dev_id) +{ + int retval; + struct irqaction * action; + +#if 1 + /* + * Sanity-check: shared interrupts should REALLY pass in + * a real dev-ID, otherwise we'll have trouble later trying + * to figure out which interrupt is which (messes up the + * interrupt freeing logic etc). + */ + if (irqflags & SA_SHIRQ) { + if (!dev_id) + printk(KERN_ERR "Bad boy: %s (at 0x%x) called us " + "without a dev_id!\n", devname, (&irq)[-1]); + } +#endif + + if (irq >= NR_IRQS) + return -EINVAL; + if (!handler) + return -EINVAL; + + action = (struct irqaction *) + kmalloc(sizeof(struct irqaction), GFP_KERNEL); + if (!action) + return -ENOMEM; + + action->handler = handler; + action->flags = irqflags; + action->mask = 0; + action->name = devname; + action->next = NULL; + action->dev_id = dev_id; + + retval = setup_irq(irq, action); + if (retval) + kfree(action); + return retval; +} + +int um_request_irq(unsigned int irq, int fd, + void (*handler)(int, void *, struct pt_regs *), + unsigned long irqflags, const char * devname, + void *dev_id) +{ + int retval; + + retval = request_irq(irq, handler, irqflags, devname, dev_id); + if(retval) return(retval); + return(activate_fd(irq, fd, dev_id)); +} + +/* this was setup_x86_irq but it seems pretty generic */ +int setup_irq(unsigned int irq, struct irqaction * new) +{ + int shared = 0; + unsigned long flags; + struct irqaction *old, **p; + irq_desc_t *desc = irq_desc + irq; + + /* + * Some drivers like serial.c use request_irq() heavily, + * so we have to be careful not to interfere with a + * running system. + */ + if (new->flags & SA_SAMPLE_RANDOM) { + /* + * This function might sleep, we want to call it first, + * outside of the atomic block. + * Yes, this might clear the entropy pool if the wrong + * driver is attempted to be loaded, without actually + * installing a new handler, but is this really a problem, + * only the sysadmin is able to do this. + */ + rand_initialize_irq(irq); + } + + /* + * The following block of code has to be executed atomically + */ + spin_lock_irqsave(&desc->lock,flags); + p = &desc->action; + if ((old = *p) != NULL) { + /* Can't share interrupts unless both agree to */ + if (!(old->flags & new->flags & SA_SHIRQ)) { + spin_unlock_irqrestore(&desc->lock,flags); + return -EBUSY; + } + + /* add new interrupt at end of irq queue */ + do { + p = &old->next; + old = *p; + } while (old); + shared = 1; + } + + *p = new; + + if (!shared) { + desc->depth = 0; + desc->status &= ~IRQ_DISABLED; + desc->handler->startup(irq); + } + spin_unlock_irqrestore(&desc->lock,flags); + + register_irq_proc(irq); + return 0; +} + +/** + * free_irq - free an interrupt + * @irq: Interrupt line to free + * @dev_id: Device identity to free + * + * Remove an interrupt handler. The handler is removed and if the + * interrupt line is no longer in use by any driver it is disabled. + * On a shared IRQ the caller must ensure the interrupt is disabled + * on the card it drives before calling this function. The function + * does not return until any executing interrupts for this IRQ + * have completed. + * + * This function may be called from interrupt context. + * + * Bugs: Attempting to free an irq in a handler for the same irq hangs + * the machine. + */ + +void free_irq(unsigned int irq, void *dev_id) +{ + irq_desc_t *desc; + struct irqaction **p; + unsigned long flags; + + if (irq >= NR_IRQS) + return; + + desc = irq_desc + irq; + spin_lock_irqsave(&desc->lock,flags); + p = &desc->action; + for (;;) { + struct irqaction * action = *p; + if (action) { + struct irqaction **pp = p; + p = &action->next; + if (action->dev_id != dev_id) + continue; + + /* Found it - now remove it from the list of entries */ + *pp = action->next; + if (!desc->action) { + desc->status |= IRQ_DISABLED; + desc->handler->shutdown(irq); + } + free_irq_by_dev(dev_id); + spin_unlock_irqrestore(&desc->lock,flags); + +#ifdef CONFIG_SMP + /* Wait to make sure it's not being used on another CPU */ + while (desc->status & IRQ_INPROGRESS) + barrier(); +#endif + kfree(action); + return; + } + printk(KERN_ERR "Trying to free free IRQ%d\n",irq); + spin_unlock_irqrestore(&desc->lock,flags); + return; + } +} + +static struct proc_dir_entry * root_irq_dir; +static struct proc_dir_entry * irq_dir [NR_IRQS]; +static struct proc_dir_entry * smp_affinity_entry [NR_IRQS]; + +static unsigned long irq_affinity [NR_IRQS] = { [0 ... NR_IRQS-1] = ~0UL }; + +#define HEX_DIGITS 8 + +static int irq_affinity_read_proc (char *page, char **start, off_t off, + int count, int *eof, void *data) +{ + if (count < HEX_DIGITS+1) + return -EINVAL; + return sprintf (page, "%08lx\n", irq_affinity[(long)data]); +} + +static unsigned int parse_hex_value (const char *buffer, + unsigned long count, unsigned long *ret) +{ + unsigned char hexnum [HEX_DIGITS]; + unsigned long value; + int i; + + if (!count) + return -EINVAL; + if (count > HEX_DIGITS) + count = HEX_DIGITS; + if (copy_from_user(hexnum, buffer, count)) + return -EFAULT; + + /* + * Parse the first 8 characters as a hex string, any non-hex char + * is end-of-string. '00e1', 'e1', '00E1', 'E1' are all the same. + */ + value = 0; + + for (i = 0; i < count; i++) { + unsigned int c = hexnum[i]; + + switch (c) { + case '0' ... '9': c -= '0'; break; + case 'a' ... 'f': c -= 'a'-10; break; + case 'A' ... 'F': c -= 'A'-10; break; + default: + goto out; + } + value = (value << 4) | c; + } +out: + *ret = value; + return 0; +} + +static int irq_affinity_write_proc (struct file *file, const char *buffer, + unsigned long count, void *data) +{ + int irq = (long) data, full_count = count, err; + unsigned long new_value; + + if (!irq_desc[irq].handler->set_affinity) + return -EIO; + + err = parse_hex_value(buffer, count, &new_value); + +#if CONFIG_SMP + /* + * Do not allow disabling IRQs completely - it's a too easy + * way to make the system unusable accidentally :-) At least + * one online CPU still has to be targeted. + */ + if (!(new_value & cpu_online_map)) + return -EINVAL; +#endif + + irq_affinity[irq] = new_value; + irq_desc[irq].handler->set_affinity(irq, new_value); + + return full_count; +} + +static int prof_cpu_mask_read_proc (char *page, char **start, off_t off, + int count, int *eof, void *data) +{ + unsigned long *mask = (unsigned long *) data; + if (count < HEX_DIGITS+1) + return -EINVAL; + return sprintf (page, "%08lx\n", *mask); +} + +static int prof_cpu_mask_write_proc (struct file *file, const char *buffer, + unsigned long count, void *data) +{ + unsigned long *mask = (unsigned long *) data, full_count = count, err; + unsigned long new_value; + + err = parse_hex_value(buffer, count, &new_value); + if (err) + return err; + + *mask = new_value; + return full_count; +} + +#define MAX_NAMELEN 10 + +static void register_irq_proc (unsigned int irq) +{ + struct proc_dir_entry *entry; + char name [MAX_NAMELEN]; + + if (!root_irq_dir || (irq_desc[irq].handler == &no_irq_type) || + irq_dir[irq]) + return; + + memset(name, 0, MAX_NAMELEN); + sprintf(name, "%d", irq); + + /* create /proc/irq/1234 */ + irq_dir[irq] = proc_mkdir(name, root_irq_dir); + + /* create /proc/irq/1234/smp_affinity */ + entry = create_proc_entry("smp_affinity", 0600, irq_dir[irq]); + + entry->nlink = 1; + entry->data = (void *)(long)irq; + entry->read_proc = irq_affinity_read_proc; + entry->write_proc = irq_affinity_write_proc; + + smp_affinity_entry[irq] = entry; +} + +unsigned long prof_cpu_mask = -1; + +void init_irq_proc (void) +{ + struct proc_dir_entry *entry; + int i; + + /* create /proc/irq */ + root_irq_dir = proc_mkdir("irq", 0); + + /* create /proc/irq/prof_cpu_mask */ + entry = create_proc_entry("prof_cpu_mask", 0600, root_irq_dir); + + entry->nlink = 1; + entry->data = (void *)&prof_cpu_mask; + entry->read_proc = prof_cpu_mask_read_proc; + entry->write_proc = prof_cpu_mask_write_proc; + + /* + * Create entries for all existing IRQs. + */ + for (i = 0; i < NR_IRQS; i++) + register_irq_proc(i); +} + +unsigned long probe_irq_on(void) +{ + return(0); +} + +int probe_irq_off(unsigned long val) +{ + return(0); +} + +static unsigned int startup_SIGIO_irq(unsigned int irq) +{ + return(0); +} + +static void shutdown_SIGIO_irq(unsigned int irq) +{ +} + +static void enable_SIGIO_irq(unsigned int irq) +{ +} + +static void disable_SIGIO_irq(unsigned int irq) +{ +} + +static void mask_and_ack_SIGIO(unsigned int irq) +{ +} + +static void end_SIGIO_irq(unsigned int irq) +{ +} + +static unsigned int startup_SIGVTALRM_irq(unsigned int irq) +{ + return(0); +} + +static void shutdown_SIGVTALRM_irq(unsigned int irq) +{ +} + +static void enable_SIGVTALRM_irq(unsigned int irq) +{ +} + +static void disable_SIGVTALRM_irq(unsigned int irq) +{ +} + +static void mask_and_ack_SIGVTALRM(unsigned int irq) +{ +} + +static void end_SIGVTALRM_irq(unsigned int irq) +{ +} + +static struct hw_interrupt_type SIGIO_irq_type = { + "SIGIO", + startup_SIGIO_irq, + shutdown_SIGIO_irq, + enable_SIGIO_irq, + disable_SIGIO_irq, + mask_and_ack_SIGIO, + end_SIGIO_irq, + NULL +}; + +static struct hw_interrupt_type SIGVTALRM_irq_type = { + "SIGVTALRM", + startup_SIGVTALRM_irq, + shutdown_SIGVTALRM_irq, + enable_SIGVTALRM_irq, + disable_SIGVTALRM_irq, + mask_and_ack_SIGVTALRM, + end_SIGVTALRM_irq, + NULL +}; + +void __init init_IRQ(void) +{ + int i; + + irq_desc[TIMER_IRQ].status = IRQ_DISABLED; + irq_desc[TIMER_IRQ].action = 0; + irq_desc[TIMER_IRQ].depth = 1; + irq_desc[TIMER_IRQ].handler = &SIGVTALRM_irq_type; + enable_irq(TIMER_IRQ); + for(i=1;i +#include +#include +#include +#include +#include +#include +#include +#include +#include "user_util.h" +#include "kern_util.h" +#include "user.h" +#include "process.h" +#include "signal_user.h" + +struct irq_fd { + struct irq_fd *next; + void *id; + int fd; + int irq; + int pid; + int events; + int current_events; +}; + +static struct irq_fd *active_fds = NULL; +static struct irq_fd **last_irq_ptr = &active_fds; + +static struct pollfd *pollfds = NULL; +static int pollfds_num = 0; +static int pollfds_size = 0; + +extern int io_count, intr_count; + +void sigio_handler(int sig, void *sc, int usermode) +{ + struct irq_fd *irq_fd, *next; + int i, n; + +#ifdef CONFIG_SMP + IPI_handler(hard_smp_processor_id()); + if (hard_smp_processor_id() != 0) return; +#endif + while(1){ + if((n = poll(pollfds, pollfds_num, 0)) < 0){ + if(errno == EINTR) continue; + printk("sigio_handler : poll returned %d, " + "errno = %d\n", n, errno); + break; + } + if(n == 0) break; + + irq_fd = active_fds; + for(i = 0; i < pollfds_num; i++){ + if(pollfds[i].revents != 0){ + irq_fd->current_events = pollfds[i].revents; + pollfds[i].events = 0; + } + irq_fd = irq_fd->next; + } + + for(irq_fd = active_fds; irq_fd != NULL; irq_fd = next){ + /* This mysterious assignment protects us against + * the irq handler freeing the irq from under us. + */ + next = irq_fd->next; + if(irq_fd->current_events != 0){ + irq_fd->current_events = 0; + do_IRQ(irq_fd->irq, usermode); + } + } + } +} + +static int prepare_fd_async(int fd, int pid) +{ + int retval; + + if((retval = fcntl(fd, F_SETFL, O_ASYNC | O_NONBLOCK)) < 0){ + printk("Failed to set O_ASYNC and O_NONBLOCK on fd # %d, " + "errno = %d\n", fd, errno); + return(-retval); + } + + if(((retval = fcntl(fd, F_SETSIG, SIGIO)) < 0) || + ((retval = fcntl(fd, F_SETOWN, pid)) < 0)){ + printk("Failed to fcntl F_SETOWN (or F_SETSIG) " + "fd %d to pid %d, errno = %d\n", fd, pid, errno); + return(-retval); + } + + return(0); +} + +int activate_ipi(int fd, int pid) +{ + return prepare_fd_async(fd, pid); +} + +int activate_fd(int irq, int fd, void *dev_id) +{ + struct irq_fd *new_fd; + int pid, retval, events = POLLIN | POLLPRI; + + for(new_fd = active_fds;new_fd;new_fd = new_fd->next){ + if(new_fd->fd == fd){ + printk("Registering fd %d twice\n", fd); + printk("Irqs : %d, %d\n", new_fd->irq, irq); + printk("Ids : 0x%x, 0x%x\n", new_fd->id, dev_id); + return(-EIO); + } + } + pid = cpu_tasks[0].pid; + if ((retval = prepare_fd_async(fd, pid)) != 0) + return(retval); + new_fd = um_kmalloc(sizeof(*new_fd)); + if(new_fd == NULL) return(-ENOMEM); + pollfds_num++; + if(pollfds_num > pollfds_size){ + struct pollfd *tmp_pfd; + + tmp_pfd = um_kmalloc(pollfds_num * sizeof(pollfds[0])); + if(tmp_pfd == NULL){ + pollfds_num--; + return(-ENOMEM); + } + if(pollfds != NULL){ + memcpy(tmp_pfd, pollfds, + sizeof(pollfds[0]) * pollfds_size); + kfree(pollfds); + } + pollfds = tmp_pfd; + pollfds_size = pollfds_num; + } + *new_fd = ((struct irq_fd) { next : NULL, + id : dev_id, + fd : fd, + irq : irq, + pid : pid, + events : events, + current_events: 0 } ); + + *last_irq_ptr = new_fd; + last_irq_ptr = &new_fd->next; + + pollfds[pollfds_num - 1].fd = fd; + pollfds[pollfds_num - 1].events = events; + pollfds[pollfds_num - 1].revents = 0; + return(0); +} + +static void free_irq_by_cb(int (*test)(struct irq_fd *, void *), void *arg) +{ + struct irq_fd **prev; + int i = 0; + + prev = &active_fds; + while(*prev != NULL){ + if((*test)(*prev, arg)){ + struct irq_fd *old_fd = *prev; + if(pollfds[i].fd != (*prev)->fd){ + printk("free_irq_fd - mismatch between " + "active_fds and pollfds, fd %d vs %d\n", + (*prev)->fd, pollfds[i].fd); + return; + } + memcpy(&pollfds[i], &pollfds[i + 1], + (pollfds_num - i - 1) * sizeof(pollfds[0])); + pollfds_num--; + if(last_irq_ptr == &old_fd->next) + last_irq_ptr = prev; + *prev = (*prev)->next; + kfree(old_fd); + continue; + } + prev = &(*prev)->next; + i++; + } +} + +static int same_dev(struct irq_fd *irq, void *dev) +{ + return(irq->id == dev); +} + +void free_irq_by_dev(void *dev) +{ + free_irq_by_cb(same_dev, dev); +} + +static int same_fd(struct irq_fd *irq, void *fd) +{ + return(irq->fd == *((int *) fd)); +} + +void free_irq_by_fd(int fd) +{ + free_irq_by_cb(same_fd, &fd); +} + +static struct irq_fd *find_irq_by_fd(int fd, int *index_out) +{ + struct irq_fd *irq; + int i = 0; + + for(irq=active_fds; irq != NULL; irq = irq->next){ + if(irq->fd == fd) break; + i++; + } + if(irq == NULL){ + printk("find_irq_by_fd doesn't have descriptor %d\n", fd); + return(NULL); + } + if(pollfds[i].fd != fd){ + printk("find_irq_by_fd - mismatch between active_fds and " + "pollfds, fd %d vs %d, need %d\n", irq->fd, + pollfds[i].fd, fd); + return(NULL); + } + *index_out = i; + return(irq); +} + +void reactivate_fd(int fd) +{ + struct irq_fd *irq; + int i; + + irq = find_irq_by_fd(fd, &i); + if(irq == NULL) return; + pollfds[i].events = irq->events; +} + +void forward_ipi(int fd, int pid) +{ + if(fcntl(fd, F_SETOWN, pid) < 0) + printk("forward_ipi: F_SETOWN failed, errno = %d\n", errno); +} + +void forward_interrupts(int pid) +{ + struct irq_fd *irq; + + for(irq=active_fds;irq != NULL;irq = irq->next){ + if(fcntl(irq->fd, F_SETOWN, pid) < 0){ + int save_errno = errno; + if(fcntl(irq->fd, F_GETOWN, 0) != pid){ + /* XXX Just remove the irq rather than + * print out an infinite stream of these + */ + printk("Failed to forward %d to pid %d, " + "errno = %d\n", irq->fd, pid, + save_errno); + } + } + irq->pid = pid; + } +} + +void init_irq_signals(int on_sigstack) +{ + int flags; + + flags = on_sigstack ? SA_ONSTACK : 0; + set_handler(SIGVTALRM, (__sighandler_t) alarm_handler, + flags | SA_NODEFER | SA_RESTART, SIGUSR1, SIGIO, + SIGWINCH, -1); + set_handler(SIGIO, (__sighandler_t) irq_handler, flags | SA_RESTART, + SIGUSR1, SIGIO, SIGWINCH, -1); +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/kernel/ksyms.c linux_umopenmosix/arch/um/kernel/ksyms.c --- linux-2.4.17/arch/um/kernel/ksyms.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/kernel/ksyms.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,29 @@ +#include "linux/module.h" +#include "linux/string.h" +#include "asm/current.h" +#include "asm/delay.h" +#include "asm/processor.h" +#include "asm/unistd.h" +#include "asm/pgalloc.h" +#include "kern_util.h" +#include "user_util.h" + +EXPORT_SYMBOL(stop); +EXPORT_SYMBOL(strtok); +EXPORT_SYMBOL(uml_physmem); +EXPORT_SYMBOL(set_signals); +EXPORT_SYMBOL(kernel_thread); +EXPORT_SYMBOL(__const_udelay); +EXPORT_SYMBOL(sys_waitpid); +EXPORT_SYMBOL(task_size); +EXPORT_SYMBOL(__do_copy_from_user); +EXPORT_SYMBOL(__do_strncpy_from_user); +EXPORT_SYMBOL(flush_tlb_range); +EXPORT_SYMBOL(__do_clear_user); +EXPORT_SYMBOL(honeypot); +EXPORT_SYMBOL(host_task_size); + +/* This is here because UML expands open to sys_open, not to a system + * call instruction. + */ +EXPORT_SYMBOL(sys_open); diff -urN linux-2.4.17/arch/um/kernel/mem.c linux_umopenmosix/arch/um/kernel/mem.c --- linux-2.4.17/arch/um/kernel/mem.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/kernel/mem.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,224 @@ +/* + * Copyright (C) 2000 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include "linux/config.h" +#include "linux/types.h" +#include "linux/mm.h" +#include "linux/fs.h" +#include "linux/init.h" +#include "linux/bootmem.h" +#include "linux/swap.h" +#include "asm/page.h" +#include "asm/pgtable.h" +#include "asm/pgalloc.h" +#include "asm/bitops.h" +#include "asm/uaccess.h" +#include "user_util.h" +#include "kern_util.h" +#include "mem_user.h" +#include "kern.h" +#include "init.h" + +unsigned long high_physmem; + +unsigned long low_physmem; + +unsigned long vm_start; + +unsigned long vm_end; + +pgd_t swapper_pg_dir[1024]; + +unsigned long *empty_zero_page = NULL; + +unsigned long *empty_bad_page = NULL; + +const char bad_pmd_string[] = "Bad pmd in pte_alloc: %08lx\n"; + +static unsigned long totalram_pages = 0; + +extern char __init_begin, __init_end; +extern long physmem_size; + +int kmalloc_ok = 0; + +void mem_init(void) +{ + max_mapnr = num_physpages = max_low_pfn; + + /* clear the zero-page */ + memset((void *) empty_zero_page, 0, PAGE_SIZE); + + /* this will put all low memory onto the freelists */ + totalram_pages += free_all_bootmem(); + printk(KERN_INFO "Memory: %luk available\n", + (unsigned long) nr_free_pages() << (PAGE_SHIFT-10)); + kmalloc_ok = 1; +} + +void paging_init(void) +{ + unsigned long zones_size[MAX_NR_ZONES]; + int i; + + empty_zero_page = (unsigned long *) alloc_bootmem_low_pages(PAGE_SIZE); + empty_bad_page = (unsigned long *) alloc_bootmem_low_pages(PAGE_SIZE); + for(i=0;i> PAGE_SHIFT) - + (uml_physmem >> PAGE_SHIFT) - zones_size[0]; + free_area_init(zones_size); +} + +static int meminfo_22 = 0; + +static int meminfo_compat(char *str) +{ + meminfo_22 = 1; + return(1); +} + +__setup("22_meminfo", meminfo_compat); + +void si_meminfo(struct sysinfo *val) +{ + val->totalram = totalram_pages; + val->sharedram = 0; + val->freeram = nr_free_pages(); + val->bufferram = atomic_read(&buffermem_pages); + val->totalhigh = 0; + val->freehigh = 0; + val->mem_unit = PAGE_SIZE; + if(meminfo_22){ + val->freeram <<= PAGE_SHIFT; + val->bufferram <<= PAGE_SHIFT; + val->totalram <<= PAGE_SHIFT; + val->sharedram <<= PAGE_SHIFT; + } +} + +pte_t __bad_page(void) +{ + clear_page(empty_bad_page); + return pte_mkdirty(mk_pte((struct page *) empty_bad_page, + PAGE_SHARED)); +} + +/* This can't do anything because nothing in the kernel image can be freed + * since it's not in kernel physical memory. + */ + +void free_initmem(void) +{ +} + +#ifdef CONFIG_BLK_DEV_INITRD + +void free_initrd_mem(unsigned long start, unsigned long end) +{ + if (start < end) + printk ("Freeing initrd memory: %ldk freed\n", + (end - start) >> 10); + for (; start < end; start += PAGE_SIZE) { + ClearPageReserved(virt_to_page(start)); + set_page_count(virt_to_page(start), 1); + free_page(start); + totalram_pages++; + } +} + +#endif + +int do_check_pgt_cache(int low, int high) +{ + int freed = 0; + if(pgtable_cache_size > high) { + do { + if (pgd_quicklist) { + free_pgd_slow(get_pgd_fast()); + freed++; + } + if (pmd_quicklist) { + pmd_free_slow(pmd_alloc_one_fast(NULL, 0)); + freed++; + } + if (pte_quicklist) { + pte_free_slow(pte_alloc_one_fast(NULL, 0)); + freed++; + } + } while(pgtable_cache_size > low); + } + return freed; +} + +void show_mem(void) +{ + int i, total = 0, reserved = 0; + int shared = 0, cached = 0; + int highmem = 0; + + printk("Mem-info:\n"); + show_free_areas(); + printk("Free swap: %6dkB\n",nr_swap_pages<<(PAGE_SHIFT-10)); + i = max_mapnr; + while (i-- > 0) { + total++; + if (PageHighMem(mem_map+i)) + highmem++; + if (PageReserved(mem_map+i)) + reserved++; + else if (PageSwapCache(mem_map+i)) + cached++; + else if (page_count(mem_map+i)) + shared += page_count(mem_map+i) - 1; + } + printk("%d pages of RAM\n", total); + printk("%d pages of HIGHMEM\n",highmem); + printk("%d reserved pages\n",reserved); + printk("%d pages shared\n",shared); + printk("%d pages swap cached\n",cached); + printk("%ld pages in page table cache\n",pgtable_cache_size); + show_buffers(); +} + +unsigned long kmem_top = 0; + +unsigned long get_kmem_end(void) +{ + if(kmem_top == 0) kmem_top = host_task_size - ABOVE_KMEM; + return(kmem_top); +} + +void set_kmem_end(unsigned long new) +{ + kmem_top = new; +} + +static int __init uml_mem_setup(char *line, int *add) +{ + char *retptr; + physmem_size = memparse(line,&retptr); + return 0; +} +__uml_setup("mem=",uml_mem_setup, +"mem=\n" +" This controls how much \"physical\" memory the kernel allocates\n" +" for the system. The size is specified as a number followed by\n" +" one of 'k', 'K', 'm', 'M', which have the obvious meanings.\n" +" This is not related to the amount of memory in the physical\n" +" machine. It can be more, and the excess, if it's ever used, will\n" +" just be swapped out.\n Example: mem=64M\n\n" +); + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/kernel/mem_user.c linux_umopenmosix/arch/um/kernel/mem_user.c --- linux-2.4.17/arch/um/kernel/mem_user.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/kernel/mem_user.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,240 @@ +/* + * arch/um/kernel/mem_user.c + * + * BRIEF MODULE DESCRIPTION + * user side memory routines for supporting IO memory inside user mode linux + * + * Copyright (C) 2001 RidgeRun, Inc. + * Author: RidgeRun, Inc. + * Greg Lonnon glonnon@ridgerun.com or info@ridgerun.com + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN + * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "kern_util.h" +#include "user.h" +#include "user_util.h" +#include "init.h" + +struct mem_region { + struct mem_region *next; + char *driver; + unsigned long start; + unsigned long usable; + unsigned long total; + int fd; +}; + +struct mem_region physmem_region; + +struct mem_region *mem_list = &physmem_region; + +#define TEMPNAME_TEMPLATE "vm_file-XXXXXX" + +int create_mem_file(unsigned long len) +{ + int fd; + char zero; + + fd = make_tempfile(TEMPNAME_TEMPLATE, NULL, 1); + if (fchmod(fd, 0777) < 0){ + perror("fchmod"); + exit(1); + } + if(lseek(fd, len, SEEK_SET) < 0){ + perror("lseek"); + exit(1); + } + zero = 0; + if(write(fd, &zero, 1) != 1){ + perror("write"); + exit(1); + } + if(fcntl(fd, F_SETFD, 1) != 0) + perror("Setting FD_CLOEXEC failed"); + return(fd); +} + +void setup_range(int fd, char *driver, unsigned long start, + unsigned long usable, unsigned long total) +{ + struct mem_region *region, *next; + + if(fd == -1){ + fd = create_mem_file(usable); + region = &physmem_region; + next = physmem_region.next; + } + else { + region = malloc(sizeof(*region)); + if(region == NULL){ + perror("Allocating iomem struct"); + exit(1); + } + next = physmem_region.next; + } + *region = ((struct mem_region) { next, driver, start, usable, + total, fd } ); + if(region != &physmem_region) physmem_region.next = region; +} + +void setup_memory(void) +{ + struct mem_region *region; + void *loc; + unsigned long start; + int page; + + start = -1; + region = mem_list; + page = page_size(); + while(region){ + if(region->start != -1) start = region->start; + else region->start = start; + loc = mmap((void *) region->start, region->usable, + PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, + region->fd, 0); + if(loc != (void *) region->start){ + perror("Mapping memory"); + exit(1); + } + start += region->total; + start = (start + page - 1) & ~(page - 1); + region = region->next; + } +} + +static int __init parse_iomem(char *str, int *add) +{ + struct stat buf; + char *file, *driver; + int fd; + + driver = str; + file = strchr(str,','); + if(file == NULL){ + printk(__FUNCTION__ " failed to parse iomem\n"); + return 1; + } + *file = '\0'; + file++; + fd = open(file, O_RDWR); + if(fd < 0){ + perror("Couldn't open io file"); + return 1; + } + if(fstat(fd, &buf) < 0) { + perror(__FUNCTION__ "fstat - cannot fstat file"); + exit(1); + } + setup_range(fd, driver, -1, buf.st_size, buf.st_size); + return 0; +} +__uml_setup("iomem=",parse_iomem, +"iomem=,\n" +" Configure as a named IO memory region named .\n\n" +); + +#ifdef notdef +int logging = 0; +int logging_fd = -1; + +int logging_line = 0; +char logging_buf[256]; + +void log(char *fmt, ...) +{ + va_list ap; + struct timeval tv; + + if(logging == 0) return; + if(logging_fd == -1) + logging_fd = open("log", O_RDWR | O_CREAT | O_TRUNC, 0644); + gettimeofday(&tv, NULL); + sprintf(logging_buf, "%d\t %u.%u ", logging_line++, tv.tv_sec, + tv.tv_usec); + va_start(ap, fmt); + vsprintf(&logging_buf[strlen(logging_buf)], fmt, ap); + va_end(ap); + write(logging_fd, logging_buf, strlen(logging_buf)); +} +#endif + +void map(unsigned long virt, void *p, unsigned long len, + int r, int w, int x) +{ + struct mem_region *region; + unsigned long phys = (unsigned long) p; + void *loc; + int prot; + + prot = (r ? PROT_READ : 0) | (w ? PROT_WRITE : 0) | + (x ? PROT_EXEC : 0); + for(region = mem_list; region ; region = region->next) { + if((phys < region->start) || + (phys >= region->start + region->usable)) + continue; + phys -= region->start; + loc = mmap((void *) virt, len, prot, MAP_SHARED | MAP_FIXED, + region->fd, phys); + if(loc != (void *) virt){ + panic("Error mapping a page - errno = %d", errno); + } + return; + } + panic("No physical or IO memory region for address 0x%x\n", phys); +} + +unsigned long find_iomem(char *driver, unsigned long *len_out) +{ + struct mem_region *region; + + for(region = mem_list; region ; region = region->next) { + if((region->driver != NULL) && + !strcmp(region->driver, driver)){ + *len_out = region->usable; + return(region->start); + } + } + *len_out = 0; + return 0; +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/kernel/mprot.h linux_umopenmosix/arch/um/kernel/mprot.h --- linux-2.4.17/arch/um/kernel/mprot.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/kernel/mprot.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,6 @@ +#ifndef __MPROT_H__ +#define __MPROT_H__ + +extern void no_access(unsigned long addr, unsigned int len); + +#endif diff -urN linux-2.4.17/arch/um/kernel/process.c linux_umopenmosix/arch/um/kernel/process.c --- linux-2.4.17/arch/um/kernel/process.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/kernel/process.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,284 @@ +/* + * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef PROFILING +#include +#endif +#include "user_util.h" +#include "kern_util.h" +#include "user.h" +#include "process.h" +#include "signal_kern.h" +#include "signal_user.h" +#include "sysdep/ptrace.h" +#include "sysdep/sigcontext.h" +#include "irq_user.h" +#include "syscall_user.h" + +void stop_pid(int pid) +{ + kill(pid, SIGSTOP); +} + +void kill_pid(int pid) +{ + kill(pid, SIGKILL); +} + +void usr1_pid(int pid) +{ + kill(pid, SIGUSR1); +} + +void init_new_thread(void *sig_stack, void (*usr1_handler)(int)) +{ + int flags = 0; + + if(sig_stack != NULL){ + set_sigstack(sig_stack, 2 * page_size()); + flags = SA_ONSTACK; + } + set_handler(SIGSEGV, (__sighandler_t) sig_handler, flags, + SIGUSR1, SIGIO, SIGWINCH, -1); + set_handler(SIGTRAP, (__sighandler_t) sig_handler, flags, + SIGUSR1, SIGIO, SIGWINCH, -1); + set_handler(SIGFPE, (__sighandler_t) sig_handler, flags, + SIGUSR1, SIGIO, SIGWINCH, -1); + set_handler(SIGILL, (__sighandler_t) sig_handler, flags, + SIGUSR1, SIGIO, SIGWINCH, -1); + set_handler(SIGBUS, (__sighandler_t) sig_handler, flags, + SIGUSR1, SIGIO, SIGWINCH, -1); + set_handler(SIGWINCH, (__sighandler_t) sig_handler, flags, + SIGUSR1, SIGIO, SIGWINCH, -1); + set_handler(SIGUSR2, (__sighandler_t) syscall_handler, + SA_NOMASK | flags, -1); + if(usr1_handler) set_handler(SIGUSR1, usr1_handler, flags, -1); + signal(SIGCHLD, SIG_IGN); + signal(SIGHUP, SIG_IGN); + set_timers(1); /* XXX A bit of a race here */ + init_irq_signals(sig_stack != NULL); +} + +struct tramp { + int (*tramp)(void *); + void *tramp_data; + unsigned long temp_stack; + int flags; + int pid; +}; + +/* See above for why sigkill is here */ + +int sigkill = SIGKILL; + +int outer_tramp(void *arg) +{ + struct tramp *t; + int sig = sigkill; + + t = arg; + t->pid = clone(t->tramp, (void *) t->temp_stack + page_size()/2, + t->flags, t->tramp_data); + if(t->pid > 0) wait_for_stop(t->pid, SIGSTOP, PTRACE_CONT); + kill(getpid(), sig); + exit(0); +} + +int start_fork_tramp(void *thread_arg, unsigned long temp_stack, int clone_vm, + int (*tramp)(void *)) +{ + struct tramp arg; + unsigned long sp; + int new_pid, flags, status, err; + + /* The trampoline will run on the temporary stack */ + sp = stack_sp(temp_stack); + + flags = CLONE_FILES | SIGCHLD; + if(clone_vm) flags |= CLONE_VM; + + arg.tramp = tramp; + arg.tramp_data = thread_arg; + arg.temp_stack = temp_stack; + arg.flags = flags; + + /* Start the process and wait for it to stop itself */ + new_pid = clone(outer_tramp, (void *) sp, flags, &arg); + if(new_pid < 0) return(-errno); + while((err = waitpid(new_pid, &status, 0) < 0) && (errno == EINTR)) ; + if(err < 0) panic("Waiting for outer trampoline failed - errno = %d", + errno); + if(!WIFSIGNALED(status) || (WTERMSIG(status) != SIGKILL)) + panic("outer trampoline didn't exit with SIGKILL"); + + return(arg.pid); +} + +void trace_myself(void) +{ + if(ptrace(PTRACE_TRACEME, 0, 0, 0) < 0) + panic("ptrace failed in trace_myself"); +} + +void attach_process(int pid) +{ + if((ptrace(PTRACE_ATTACH, pid, 0, 0) < 0) || + (ptrace(PTRACE_CONT, pid, 0, 0) < 0)) + tracer_panic("OP_FORK failed to attach pid"); + wait_for_stop(pid, SIGSTOP, PTRACE_CONT); + if(ptrace(PTRACE_CONT, pid, 0, 0) < 0) + tracer_panic("OP_FORK failed to continue process"); +} + +void tracer_panic(char *format, ...) +{ + va_list ap; + + va_start(ap, format); + vprintf(format, ap); + printf("\n"); + while(1) sleep(10); +} + +void suspend_new_thread(int fd) +{ + char c; + + kill(getpid(), SIGSTOP); + + if(read(fd, &c, sizeof(c)) != sizeof(c)) + panic("read failed in suspend_new_thread"); +} + +static int ptrace_child(void *arg) +{ + int pid = getpid(); + + if(ptrace(PTRACE_TRACEME, 0, 0, 0) < 0){ + perror("ptrace"); + exit(1); + } + kill(pid, SIGSTOP); + exit(getpid() == pid); +} + +void check_ptrace(void) +{ + void *stack; + unsigned long sp; + int status, pid, n, syscall; + + printk("Checking that the host ptrace works..."); + stack = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if(stack == MAP_FAILED) + panic("check_ptrace : mmap failed, errno = %d", errno); + sp = (unsigned long) stack + PAGE_SIZE - sizeof(void *); + pid = clone(ptrace_child, (void *) sp, SIGCHLD, NULL); + if(pid < 0) + panic("check_ptrace : clone failed, errno = %d", errno); + n = waitpid(pid, &status, WUNTRACED); + if(n < 0) + panic("check_ptrace : wait failed, errno = %d", errno); + if(!WIFSTOPPED(status) || (WSTOPSIG(status) != SIGSTOP)) + panic("check_ptrace : expected SIGSTOP, got status = %d", + status); + while(1){ + if(ptrace(PTRACE_SYSCALL, pid, 0, 0) < 0) + panic("check_ptrace : ptrace failed, errno = %d", + errno); + n = waitpid(pid, &status, WUNTRACED); + if(n < 0) + panic("check_ptrace : wait failed, errno = %d", errno); + if(!WIFSTOPPED(status) || (WSTOPSIG(status) != SIGTRAP)) + panic("check_ptrace : expected SIGTRAP, " + "got status = %d", status); + + syscall = ptrace(PTRACE_PEEKUSER, pid, UM_SYSCALL_NR_OFFSET, + 0); + if(syscall == __NR_getpid){ + n = ptrace(PTRACE_POKEUSER, pid, UM_SYSCALL_NR_OFFSET, + __NR_getppid); + if(n < 0) + panic("check_ptrace : failed to modify system " + "call, errno = %d", errno); + break; + } + } + if(ptrace(PTRACE_CONT, pid, 0, 0) < 0) + panic("check_ptrace : ptrace failed, errno = %d", errno); + n = waitpid(pid, &status, 0); + if(!WIFEXITED(status) || (WEXITSTATUS(status) != 0)) + panic("check_ptrace : child exited with status %d", status); + + if(munmap(stack, PAGE_SIZE) < 0) + panic("check_ptrace : munmap failed, errno = %d", errno); + printk("OK\n"); +} + + + + +int user_thread(int (*fn)(void *), void * arg, unsigned long flags) +{ + long retval, d0; + + __asm__ __volatile__( + "movl %%esp,%%esi\n\t" + "int $0x80\n\t" /* Linux/i386 system call */ + "cmpl %%esp,%%esi\n\t" /* child or parent? */ + "je 1f\n\t" /* parent - jump */ + "subl %7,%%esp\n\t" /* space for user-registers */ + /* Load the argument into eax, and push it. That way, it does + * not matter whether the called function is compiled with + * -mregparm or not. */ + "movl %4,%%eax\n\t" + "pushl %%eax\n\t" + "call *%5\n\t" /* call fn */ + "movl %3,%0\n\t" /* exit */ + "int $0x80\n" + "1:\t" + :"=&a" (retval), "=&S" (d0) + :"0" (__NR_clone), "i" (__NR_exit), + "r" (arg), "r" (fn), + "b" (flags | SIGCHLD), + "i" (sizeof(struct pt_regs)) + : "memory"); + return retval; +} + + + + + + + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/kernel/process_kern.c linux_umopenmosix/arch/um/kernel/process_kern.c --- linux-2.4.17/arch/um/kernel/process_kern.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/kernel/process_kern.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,750 @@ +/* + * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include "linux/config.h" +#include "linux/kernel.h" +#include "linux/sched.h" +#include "linux/interrupt.h" +#include "linux/mm.h" +#include "linux/slab.h" +#include "linux/utsname.h" +#include "linux/fs.h" +#include "linux/utime.h" +#include "linux/smp_lock.h" +#include "linux/module.h" +#include "linux/init.h" +#include "linux/capability.h" +#include "asm/unistd.h" +#include "asm/mman.h" +#include "asm/segment.h" +#include "asm/stat.h" +#include "asm/pgtable.h" +#include "asm/processor.h" +#include "asm/pgalloc.h" +#include "asm/spinlock.h" +#include "asm/uaccess.h" +#include "asm/user.h" +#include "user_util.h" +#include "kern_util.h" +#include "kern.h" +#include "signal_kern.h" +#include "signal_user.h" +#include "init.h" +#include "irq_user.h" +#include "tlb.h" +#include "frame.h" +#include "2_5compat.h" + +struct cpu_task cpu_tasks[NR_CPUS] = { [0 ... NR_CPUS - 1] = { -1, NULL } }; + +static struct task_struct *get_task(int pid, int require) +{ + struct task_struct *task, *ret; + + ret = NULL; + read_lock(&tasklist_lock); + for_each_task(task){ + if(task->pid == pid){ + ret = task; + break; + } + } + read_unlock(&tasklist_lock); + if(require && (ret == NULL)) panic("get_task couldn't find a task\n"); + return(ret); +} + +int external_pid(void *t) +{ + struct task_struct *task = t ? t : current; + + return(task->thread.extern_pid); +} + +int pid_to_processor_id(int pid) +{ + int i; + + for(i = 0; i < smp_num_cpus; i++){ + if(cpu_tasks[i].pid == pid) return(i); + } + return(-1); +} + +void free_stack(unsigned long stack) +{ + free_page(stack); +} + +void set_init_pid(int pid) +{ + init_task.thread.extern_pid = pid; + if(pipe(init_task.thread.switch_pipe) < 0) + panic("Can't create switch pipe for init_task"); +} + +int set_user_mode(void *t, int restore_state, int protect_mem) +{ + struct task_struct *task; + + task = t ? t : current; + if(task->thread.tracing) return(1); + task->thread.request.op = OP_TRACE_ON; + task->thread.request.u.trace_on.restore_state = restore_state; + if(protect_mem) protect_kernel_mem(1); + usr1_pid(getpid()); + return(0); +} + +void set_tracing(void *task, int tracing) +{ + ((struct task_struct *) task)->thread.tracing = tracing; +} + +int is_tracing(void *t) +{ + return (((struct task_struct *) t)->thread.tracing); +} + +extern void schedule_tail(struct task_struct *prev); + +static int new_thread_proc(void *t) +{ + struct task_struct *task; + int (*fn)(void *), pid; + void *arg; + + task = t; + trace_myself(); + init_new_thread(NULL, NULL); + pid = getpid(); + fn = task->thread.request.u.thread.proc; + arg = task->thread.request.u.thread.arg; + task->thread.extern_pid = pid; + + suspend_new_thread(task->thread.switch_pipe[0]); + + set_cmdline("(kernel thread)"); + force_flush_all(); + if(current->thread.prev_sched != NULL) + schedule_tail(current->thread.prev_sched); + current->thread.prev_sched = NULL; + (*fn)(arg); + do_exit(0); + return(0); +} + +unsigned long alloc_stack(void) +{ + unsigned long page; + + if((page = __get_free_page(GFP_KERNEL)) == 0) + panic("Couldn't allocate new stack"); + stack_protections(page); + return(page); +} + +extern int inited_cpus; + +static int start_kernel_thread(struct task_struct *task, int (*fn)(void *), + void *arg, int cpu) +{ + int extern_pid; + unsigned long sp; + + sp = ((unsigned long) task) + 4 * PAGE_SIZE - sizeof(void *); + task->thread.request.u.thread.proc = fn; + task->thread.request.u.thread.arg = arg; + task->thread.extern_pid = -1; + extern_pid = clone_and_wait(new_thread_proc, task, (void *) sp, + CLONE_FILES | SIGCHLD); + if(task->thread.extern_pid == -1) + tracer_panic("task didn't set its pid"); + task->mm = NULL; + task->active_mm = NULL; +#ifdef CONFIG_SMP + if(cpu != NO_PROC_ID){ + unsigned char c; + + cpu_tasks[cpu].pid = extern_pid; + cpu_tasks[cpu].task = task; + inited_cpus++; + init_tasks[cpu] = task; + task->processor = cpu; + write(task->thread.switch_pipe[1], &c, sizeof(c)); + } +#endif + return(extern_pid); +} + +int kernel_thread1(int (*fn)(void *), void * arg, unsigned long flags, + int cpu, int *extern_pid_out) +{ + struct task_struct *new_task; + int pid, extern_pid; + + pid = do_fork(CLONE_VM | flags, 0, NULL, 0); + if(pid < 0) panic("do_fork failed in kernel_thread"); + new_task = get_task(pid, 1); + current->thread.request.op = OP_THREAD; + current->thread.request.u.thread.proc = fn; + current->thread.request.u.thread.arg = arg; + current->thread.request.u.thread.flags = flags; + current->thread.request.u.thread.new_task = new_task; + current->thread.request.u.thread.cpu = cpu; + usr1_pid(getpid()); + extern_pid = current->thread.request.u.thread.new_pid; + if(extern_pid < 0){ + printk(KERN_ERR "Kernel thread failed : errno = %d\n", + -extern_pid); + return(extern_pid); + } + if(extern_pid_out != NULL) *extern_pid_out = extern_pid; + current->thread.prev_sched = NULL; + return(pid); +} + +int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags) +{ + return(kernel_thread1(fn, arg, flags, -1, NULL)); +} + +void switch_mm(struct mm_struct *prev, struct mm_struct *next, + struct task_struct *tsk, unsigned cpu) +{ + if (prev != next) + clear_bit(cpu, &prev->cpu_vm_mask); + set_bit(cpu, &next->cpu_vm_mask); +} + +void set_current(void *t) +{ + struct task_struct *task = t; + + cpu_tasks[CPU(task)] = ((struct cpu_task) + { task->thread.extern_pid, task }); +} + +void *_switch_to(void *prev, void *next) +{ + struct task_struct *from, *to; + int vtalrm, alrm; + char c; + + from = prev; + to = next; + + to->thread.prev_sched = from; + + if(CPU(from) == 0) forward_interrupts(to->thread.extern_pid); + forward_ipi(cpu_data[CPU(from)].ipi_pipe[0], to->thread.extern_pid); + block_signals(); + + vtalrm = change_sig(SIGVTALRM, 0); + alrm = change_sig(SIGALRM, 0); + + c = 0; + set_current(to); + if(write(to->thread.switch_pipe[1], &c, sizeof(c)) != sizeof(c)) + panic("write of switch_pipe failed, errno = %d", errno); + + if(from->state == TASK_ZOMBIE) kill_pid(getpid()); + if(read(from->thread.switch_pipe[0], &c, sizeof(c)) != sizeof(c)) + panic("read of switch_pipe failed, errno = %d", errno); + + change_sig(SIGVTALRM, vtalrm); + change_sig(SIGALRM, alrm); + + flush_tlb_all(); + unblock_signals(); + + return(current->thread.prev_sched); +} + +void ret_from_sys_call(void) +{ + if(current->need_resched) schedule(); + if(current->sigpending != 0) do_signal(0); +} + +void release_thread(struct task_struct *task) +{ + close(task->thread.switch_pipe[0]); + close(task->thread.switch_pipe[1]); + kill_pid(task->thread.extern_pid); +} + +void exit_thread(void) +{ + unprotect_stack((unsigned long) current); +} + +/* This sigusr1 business works around a bug in gcc's -pg support. + * Normally a procedure's mcount call comes after esp has been copied to + * ebp and the new frame is constructed. With procedures with no locals, + * the mcount comes before, as the first thing that the procedure does. + * When that procedure is main for a thread, ebp comes in as NULL. So, + * when mcount dereferences it, it segfaults. So, UML works around this + * by adding a non-optimizable local to the various trampolines, fork_tramp + * and outer_tramp below, and exec_tramp. + */ + +static int sigusr1 = SIGUSR1; + +int fork_tramp(void *stack) +{ + int sig = sigusr1; + + block_signals(); + init_new_thread(stack, finish_fork_handler); + + kill(getpid(), sig); + return(0); +} + +int copy_thread(int nr, unsigned long clone_flags, unsigned long sp, + unsigned long stack_top, struct task_struct * p, + struct pt_regs *regs) +{ + int new_pid, clone_vm; + unsigned long stack; + + p->thread = (struct thread_struct) INIT_THREAD; + p->thread.kernel_stack = (unsigned long) p + 2 * PAGE_SIZE; + p->thread.process_regs = current->thread.process_regs; + if(pipe(p->thread.switch_pipe) < 0) + panic("copy_thread : pipe failed"); + if(current->thread.forking){ + stack = alloc_stack(); + clone_vm = (p->mm == current->mm); + p->thread.temp_stack = stack; + new_pid = start_fork_tramp((void *) p->thread.kernel_stack, + stack, clone_vm, fork_tramp); + if(new_pid < 0){ + printk(KERN_ERR "copy_thread : clone failed - " + "errno = %d\n", -new_pid); + return(new_pid); + } + + UM_SET_SYSCALL_RETURN(&p->thread.process_regs, 0); + if(sp != 0) UM_SP(&p->thread.process_regs) = sp; + p->thread.extern_pid = new_pid; + + current->thread.request.op = OP_FORK; + current->thread.request.u.fork.pid = new_pid; + usr1_pid(getpid()); + } + current->need_resched = 1; + return(0); +} + +void tracing_reboot(void) +{ + current->thread.request.op = OP_REBOOT; + usr1_pid(getpid()); +} + +void tracing_halt(void) +{ + current->thread.request.op = OP_HALT; + usr1_pid(getpid()); +} + +void tracing_cb(void (*proc)(void *), void *arg) +{ + if(getpid() == tracing_pid){ + (*proc)(arg); + } + else { + current->thread.request.op = OP_CB; + current->thread.request.u.cb.proc = proc; + current->thread.request.u.cb.arg = arg; + usr1_pid(getpid()); + } +} + +int do_proc_op(void *t, int proc_id) +{ + struct task_struct *task; + struct thread_struct *thread; + int op, pid; + + task = t; + thread = &task->thread; + op = thread->request.op; + switch(op){ + case OP_NONE: + case OP_TRACE_ON: + break; + case OP_EXEC: + { + int new_pid = thread->request.u.exec.pid; + do_exec(thread->extern_pid, new_pid); + thread->extern_pid = new_pid; + cpu_tasks[CPU(task)].pid = new_pid; + break; + } + case OP_THREAD: + pid = start_kernel_thread(thread->request.u.thread.new_task, + thread->request.u.thread.proc, + thread->request.u.thread.arg, + thread->request.u.thread.cpu); + thread->request.u.thread.new_pid = pid; + break; + case OP_FORK: + attach_process(thread->request.u.fork.pid); + break; + case OP_CB: + (*thread->request.u.cb.proc)(thread->request.u.cb.arg); + break; + case OP_REBOOT: + case OP_HALT: + break; + default: + tracer_panic("Bad op in do_proc_op"); + break; + } + thread->request.op = OP_NONE; + return(op); +} + +unsigned long stack_sp(unsigned long page) +{ + return(page + PAGE_SIZE - sizeof(void *)); +} + +int current_pid(void) +{ + return(current->pid); +} + +void cpu_idle(void) +{ + if(CPU(current) == 0) idle_timer(); + + atomic_inc(&init_mm.mm_count); + current->mm = &init_mm; + current->active_mm = &init_mm; + + while(1){ + /* endless idle loop with no priority at all */ + SET_PRI(current); + + /* + * although we are an idle CPU, we do not want to + * get into the scheduler unnecessarily. + */ + if (current->need_resched) { + schedule(); + check_pgt_cache(); + } + idle_sleep(10); + } +} + +int page_size(void) +{ + return(PAGE_SIZE); +} + +int page_mask(void) +{ + return(PAGE_MASK); +} + +unsigned long um_virt_to_phys(void *t, unsigned long addr) +{ + struct task_struct *task; + pgd_t *pgd; + pmd_t *pmd; + pte_t *pte; + + task = t; + if(task->mm == NULL) return(0xffffffff); + pgd = pgd_offset(task->mm, addr); + pmd = pmd_offset(pgd, addr); + if(!pmd_present(*pmd)) return(0xffffffff); + pte = pte_offset(pmd, addr); + if(!pte_present(*pte)) return(0xffffffff); + return((pte_val(*pte) & PAGE_MASK) + (addr & ~PAGE_MASK)); +} + +char *current_cmd(void) +{ +#ifdef CONFIG_SMP + return("(Unknown)"); +#else + unsigned long addr; + + if((addr = um_virt_to_phys(current, + current->mm->arg_start)) == 0xffffffff) + return("(Unknown)"); + else return((char *) addr); +#endif +} + +void force_sigbus(void) +{ + printk(KERN_ERR "Killing pid %d because of a lack of memory\n", + current->pid); + lock_kernel(); + sigaddset(¤t->pending.signal, SIGBUS); + recalc_sigpending(current); + current->flags |= PF_SIGNALED; + do_exit(SIGBUS | 0x80); +} + +void finish_fork_handler(int sig) +{ + suspend_new_thread(current->thread.switch_pipe[0]); + + force_flush_all(); + if(current->mm != current->p_pptr->mm) + protect(uml_physmem, high_physmem - uml_physmem, 1, 1, 0, 1); + task_protections((unsigned long) current); + if(current->thread.prev_sched != NULL) + schedule_tail(current->thread.prev_sched); + current->thread.prev_sched = NULL; + + free_page(current->thread.temp_stack); + change_sig(SIGUSR1, 1); + unblock_signals(); + set_user_mode(current, 1, 1); +} + +void *process_state(void *t) +{ + struct task_struct *task = t ? t : current; + + return(&task->thread.process_regs); +} + +void dump_thread(struct pt_regs *regs, struct user *u) +{ +} + +void enable_hlt(void) +{ + panic("enable_hlt"); +} + +void disable_hlt(void) +{ + panic("disable_hlt"); +} + +extern int signal_frame_size; + +void interrupt_end(void) +{ + if(current->need_resched) schedule(); + do_signal(0); +} + +void *um_kmalloc(int size) +{ + return(kmalloc(size, GFP_KERNEL)); +} + +unsigned long get_fault_addr(void) +{ + return((unsigned long) current->thread.fault_addr); +} + +EXPORT_SYMBOL(get_fault_addr); + +int singlestepping(void *t) +{ + struct task_struct *task; + int ret; + + task = (struct task_struct *) t; + ret = (task->ptrace & PT_DTRACE); + task->ptrace &= ~PT_DTRACE; + return(ret); +} + +void not_implemented(void) +{ + printk(KERN_DEBUG "Something isn't implemented in here\n"); +} + +EXPORT_SYMBOL(not_implemented); + +int user_context(unsigned long sp) +{ + return((sp & (PAGE_MASK << 1)) != current->thread.kernel_stack); +} + +extern void remove_umid_dir(void); +__uml_exitcall(remove_umid_dir); + +extern exitcall_t __uml_exitcall_begin, __uml_exitcall_end; + +void do_uml_exitcalls(void) +{ + exitcall_t *call; + + call = &__uml_exitcall_end; + while (--call >= &__uml_exitcall_begin) + (*call)(); +} + +extern exitcall_t __exitcall_begin, __exitcall_end; + +void do_exitcalls(void) +{ + exitcall_t *call; + + call = &__exitcall_end; + while (--call >= &__exitcall_begin) + (*call)(); + do_uml_exitcalls(); +} + +void *round_up(unsigned long addr) +{ + return(ROUND_UP(addr)); +} + +void *round_down(unsigned long addr) +{ + return(ROUND_DOWN(addr)); +} + +char *uml_strdup(char *string) +{ + char *new; + + new = kmalloc(strlen(string) + 1, GFP_KERNEL); + if(new == NULL) return(NULL); + strcpy(new, string); + return(new); +} + +int jail = 0; + +int __init jail_setup(char *line, int *add) +{ + int ok = 1; + + if(jail) return(0); +#ifdef CONFIG_SMP + printf("'jail' may not used used in a kernel with CONFIG_SMP " + "enabled\n"); + ok = 0; +#endif +#ifdef CONFIG_HOSTFS + printf("'jail' may not used used in a kernel with CONFIG_HOSTFS " + "enabled\n"); + ok = 0; +#endif +#ifdef CONFIG_MODULES + printf("'jail' may not used used in a kernel with CONFIG_MODULES " + "enabled\n"); + ok = 0; +#endif + if(!ok) exit(1); + + /* CAP_SYS_RAWIO controls the ability to open /dev/mem and /dev/kmem. + * Removing it from the bounding set eliminates the ability of anything + * to acquire it, and thus read or write kernel memory. + */ + cap_lower(cap_bset, CAP_SYS_RAWIO); + jail = 1; + return(0); +} + +__uml_setup("jail", jail_setup, +"jail\n" +" Enables the protection of kernel memory from processes\n\n" +); + +static void mprotect_kernel_mem(int w, int delay_signals) +{ + unsigned long start, end, flags = 0; + int alrm = 0, vtalrm = 0; + + if(!jail || (current == &init_task)) return; + + if(delay_signals){ + local_irq_save(flags); + alrm = change_sig(SIGALRM, 0); + vtalrm = change_sig(SIGVTALRM, 0); + } + + start = (unsigned long) current + PAGE_SIZE; + end = (unsigned long) current + PAGE_SIZE * 4; + protect(uml_physmem, start - uml_physmem, 1, w, 1, 1); + protect(end, high_physmem - end, 1, w, 1, 1); + + start = (unsigned long) ROUND_DOWN(&_stext); + end = (unsigned long) ROUND_UP(&_etext); + protect(start, end - start, 1, w, 1, 1); + + start = (unsigned long) ROUND_DOWN(&_unprotected_end); + end = (unsigned long) ROUND_UP(&_edata); + protect(start, end - start, 1, w, 1, 1); + + start = (unsigned long) ROUND_DOWN(&__bss_start); + end = (unsigned long) ROUND_UP(brk_start); + protect(start, end - start, 1, w, 1, 1); + + mprotect_kernel_vm(w); + + if(delay_signals){ + local_irq_restore(flags); + change_sig(SIGALRM, alrm); + change_sig(SIGVTALRM, vtalrm); + } +} + +void unprotect_kernel_mem(int delay_signals) +{ + mprotect_kernel_mem(1, delay_signals); +} + +void protect_kernel_mem(int delay_signals) +{ + mprotect_kernel_mem(0, delay_signals); +} + +void *get_init_task(void) +{ + return(&init_task_union.task); +} + +int copy_to_user_proc(void *to, void *from, int size) +{ + return(copy_to_user(to, from, size)); +} + +int copy_from_user_proc(void *to, void *from, int size) +{ + return(copy_from_user(to, from, size)); +} + +void set_thread_sc(void *sc) +{ + current->thread.sc = sc; +} + +int get_restore_state(void *t) +{ + struct task_struct *task = t; + + return(task->thread.request.u.trace_on.restore_state); +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/kernel/ptrace.c linux_umopenmosix/arch/um/kernel/ptrace.c --- linux-2.4.17/arch/um/kernel/ptrace.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/kernel/ptrace.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,521 @@ +/* + * Copyright (C) 2000 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include "linux/sched.h" +#include "linux/mm.h" +#include "linux/errno.h" +#include "linux/smp_lock.h" +#include "asm/ptrace.h" +#include "asm/uaccess.h" +#include "kern_util.h" +#include "asm/i387.h" + + +#ifdef CONFIG_MOSIX +#include +#endif /* CONFIG_MOSIX */ + +#define EFL_OFFSET ((EFL-2)*4-sizeof(struct pt_regs)) +#define TRAP_FLAG 0x100 + + +/* + * Called by kernel/ptrace.c when detaching.. + */ +void ptrace_disable(struct task_struct *child) +{ +} + + +asmlinkage void do_syscall_trace(void) +{ + if ((current->ptrace & (PT_PTRACED|PT_TRACESYS)) != + (PT_PTRACED|PT_TRACESYS)) + return; + /* the 0x80 provides a way for the tracing parent to distinguish + between a syscall stop and SIGTRAP delivery */ + current->exit_code = SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD) + ? 0x80 : 0); + current->state = TASK_STOPPED; + notify_parent(current, SIGCHLD); + schedule(); + /* + * this isn't the same as continuing with a signal, but it will do + * for normal use. strace only continues with a signal if the + * stopping signal is not SIGTRAP. -brl + */ + if (current->exit_code) { + send_sig(current->exit_code, current, 1); + current->exit_code = 0; + } +} + + +int sys_ptrace(long request, long pid, long addr, long data) +{ + struct task_struct *child; + int i, ret; + + lock_kernel(); + ret = -EPERM; + if (request == PTRACE_TRACEME) { + /* are we already being traced? */ + if (current->ptrace & PT_PTRACED) + goto out; + /* set the ptrace bit in the process flags. */ + current->ptrace |= PT_PTRACED; + ret = 0; + goto out; + } + ret = -ESRCH; + read_lock(&tasklist_lock); + child = find_task_by_pid(pid); + if (child) + get_task_struct(child); + read_unlock(&tasklist_lock); + if (!child) + goto out; + + ret = -EPERM; + if (pid == 1) /* you may not mess with init */ + goto out_tsk; + + if (request == PTRACE_ATTACH) { + ret = ptrace_attach(child); + goto out_tsk; + } + + ret = ptrace_check_attach(child, request == PTRACE_KILL); + if (ret < 0) + goto out_tsk; + + switch (request) { + /* when I and D space are separate, these will need to be fixed. */ + case PTRACE_PEEKTEXT: /* read word at location addr. */ + case PTRACE_PEEKDATA: { + unsigned long tmp; + int copied; + + ret = -EIO; + copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0); + if (copied != sizeof(tmp)) + break; + ret = put_user(tmp,(unsigned long *) data); + break; + } + + /* read the word at location addr in the USER area. */ + case PTRACE_PEEKUSR: { + unsigned long tmp; + + ret = -EIO; + if ((addr & 3) || addr < 0) + break; + + tmp = 0; /* Default return condition */ + if(addr < UM_MAX_REG_OFFSET){ + tmp = getreg(child, addr); + ret = put_user(tmp,(unsigned long *) data); + } + break; + } + + /* when I and D space are separate, this will have to be fixed. */ + case PTRACE_POKETEXT: /* write the word at location addr. */ + case PTRACE_POKEDATA: + ret = -EIO; + if (access_process_vm(child, addr, &data, sizeof(data), + 1) != sizeof(data)) + break; + ret = 0; + break; + + case PTRACE_POKEUSR: /* write the word at location addr in the USER area */ + ret = -EIO; + if ((addr & 3) || addr < 0) + break; + + if (addr < UM_MAX_REG_OFFSET) { + ret = putreg(child, addr, data); + break; + } + + break; + + case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */ + case PTRACE_CONT: { /* restart after signal. */ + ret = -EIO; + if ((unsigned long) data > _NSIG) + break; + if (request == PTRACE_SYSCALL) + child->ptrace |= PT_TRACESYS; + else + child->ptrace &= ~PT_TRACESYS; + child->exit_code = data; + wake_up_process(child); + ret = 0; + break; + } + +/* + * make the child exit. Best I can do is send it a sigkill. + * perhaps it should be put in the status that it wants to + * exit. + */ + case PTRACE_KILL: { + ret = 0; + if (child->state == TASK_ZOMBIE) /* already dead */ + break; + child->exit_code = SIGKILL; + wake_up_process(child); + break; + } + + case PTRACE_SINGLESTEP: { /* set the trap flag. */ + ret = -EIO; + if ((unsigned long) data > _NSIG) + break; + child->ptrace &= ~PT_TRACESYS; + child->ptrace |= PT_DTRACE; + child->exit_code = data; + /* give it a chance to run. */ + wake_up_process(child); + ret = 0; + break; + } + + case PTRACE_DETACH: + /* detach a process that was attached. */ + ret = ptrace_detach(child, data); + break; + +#ifdef PTRACE_GETREGS + case PTRACE_GETREGS: { /* Get all gp regs from the child. */ + if (!access_ok(VERIFY_WRITE, (unsigned *)data, + UM_MAX_REG_OFFSET)) { + ret = -EIO; + break; + } + for ( i = 0; i < UM_MAX_REG_OFFSET; i += sizeof(long) ) { + __put_user(getreg(child, i),(unsigned long *) data); + data += sizeof(long); + } + ret = 0; + break; + } +#endif +#ifdef PTRACE_SETREGS + case PTRACE_SETREGS: { /* Set all gp regs in the child. */ + unsigned long tmp = 0; + if (!access_ok(VERIFY_READ, (unsigned *)data, + UM_MAX_REG_OFFSET)) { + ret = -EIO; + break; + } + for ( i = 0; i < UM_MAX_REG_OFFSET; i += sizeof(long) ) { + __get_user(tmp, (unsigned long *) data); + putreg(child, i, tmp); + data += sizeof(long); + } + ret = 0; + break; + } +#endif +#ifdef PTRACE_GETFPREGS + case PTRACE_GETFPREGS: { /* Get the child FPU state. */ + ret = -EIO; + break; + } +#endif +#ifdef PTRACE_SETFPREGS + case PTRACE_SETFPREGS: { /* Set the child FPU state. */ + ret = -EIO; + break; + } +#endif + default: + ret = -EIO; + break; + } + out_tsk: + free_task_struct(child); + out: + unlock_kernel(); + return ret; +} + +void syscall_trace(void) +{ + if ((current->ptrace & (PT_PTRACED|PT_TRACESYS)) + != (PT_PTRACED|PT_TRACESYS)) + return; + current->exit_code = SIGTRAP; + current->state = TASK_STOPPED; + notify_parent(current, SIGCHLD); + schedule(); + /* + * this isn't the same as continuing with a signal, but it will do + * for normal use. strace only continues with a signal if the + * stopping signal is not SIGTRAP. -brl + */ + if (current->exit_code) { + send_sig(current->exit_code, current, 1); + current->exit_code = 0; + } +} + + +#ifdef CONFIG_MOSIX +inline int get_stack_long(struct task_struct *task, int offset) +#else +static inline int get_stack_long(struct task_struct *task, int offset) +#endif /* CONFIG_MOSIX */ +{ + unsigned char *stack; + +#ifdef CONFIG_MOSIX + if(task != current) + lock_mosix(); + if(task->mosix.dflags & DDEPUTY) + { + if(task != current) + unlock_mosix(); + return(request_process(task, NULL, PR_PTRACE_GET_STACK_LONG, + offset)); + } + if(task == current) + mosix_obtain_registers(ALL_REGISTERS); + else + task_lock(task); + if(!task->thread.saved_esp0) /* unless in VM86 mode */ + stack = (char *)(mos_to_regs(&task->mosix) + 1); + else +#endif /* CONFIG_MOSIX */ + stack = (unsigned char *)task->thread.esp0; + stack += offset; +#ifdef CONFIG_MOSIX + { + int res = *((int *)stack); + if(task != current) + { + task_unlock(task); + unlock_mosix(); + } + return(res); + } +#else + return (*((int *)stack)); +#endif /* CONFIG_MOSIX */ +} + + + + + + +#ifdef CONFIG_MOSIX +inline int put_stack_long(struct task_struct *task, int offset, +#else +static inline int put_stack_long(struct task_struct *task, int offset, +#endif /* CONFIG_MOSIX */ + unsigned long data) +{ + unsigned char * stack; + +#ifdef CONFIG_MOSIX + if(task != current) + lock_mosix(); + if(task->mosix.dflags & DDEPUTY) + { + if(task != current) + unlock_mosix(); + return(request_process_arg2(task, NULL, + PR_PTRACE_PUT_STACK_LONG, offset, data)); + } + if(task == current) + mosix_obtain_registers(ALL_REGISTERS); + else + task_lock(task); + if(!task->thread.saved_esp0) /* unless in VM86 mode */ + stack = (char *)(mos_to_regs(&task->mosix) + 1); + else +#endif /* CONFIG_MOSIX */ + stack = (unsigned char *) task->thread.esp0; + stack += offset; + *(unsigned long *) stack = data; +#ifdef CONFIG_MOSIX + if(task != current) + { + task_unlock(task); + unlock_mosix(); + } +#endif /* CONFIG_MOSIX */ + return 0; +} + + + + + +#ifdef CONFIG_MOSIX +void +ptrace_putregs(unsigned long *data) +{ + register int i; + + for (i = 0; i < FRAME_SIZE ; i++) + putreg(current, i << 2, data[i]); +} + + + +unsigned long +ptrace_peekuser(long addr) +{ + struct user * dummy = NULL; + unsigned long tmp; + + tmp = 0; /* Default return condition */ + if(addr < FRAME_SIZE*sizeof(long)) + tmp = getreg(current, addr); + if(addr >= (long) &dummy->u_debugreg[0] && + addr <= (long) &dummy->u_debugreg[7]){ + addr -= (long) &dummy->u_debugreg[0]; + addr = addr >> 2; + tmp = current->thread.debugreg[addr]; + }; + return(tmp); +} + +void +ptrace_pokeuser(long addr, long data) +{ + current->thread.debugreg[addr] = data; +#define loaddebug(tsk,register) \ + __asm__("movl %0,%%db" #register \ + : /* no output */ \ + :"r" (tsk->thread.debugreg[register])) + /* unlike the original ptrace code, we are doing this for ourselves, + * and there may be no "switch_to" before we go to user-mode again, + * so here we go: + */ + if(current->thread.debugreg[7]) + { + loaddebug(current, 0); + loaddebug(current, 1); + loaddebug(current, 2); + loaddebug(current, 3); + loaddebug(current, 6); + loaddebug(current, 7); + } +} + +void +ptrace_cont(int request) +{ + unsigned long tmp; + struct task_struct *tsk = current; + + tmp = get_stack_long(tsk, EFL_OFFSET) & ~TRAP_FLAG; + put_stack_long(tsk, EFL_OFFSET, tmp); + if (request == PTRACE_SYSCALL) + tsk->ptrace |= PT_TRACESYS; + else + tsk->ptrace &= ~PT_TRACESYS; + if (request == PTRACE_DETACH) + tsk->ptrace &= ~PT_PTRACED; +} + + + +void +ptrace_single_step(void) +{ + unsigned long tmp; + + tmp = get_stack_long(current, EFL_OFFSET) | TRAP_FLAG; + put_stack_long(current, EFL_OFFSET, tmp); + current->ptrace |= PT_PTRACED | PT_DTRACE; +#ifdef CONFIG_MOSIX_DFSA + tell_process(current, DREQ_NOTUPTODATE); +#endif /* CONFIG_MOSIX_DFSA */ +} + + + + + +void +ptrace_getfpregs(struct user_i387_struct *to) +{ + struct task_struct *p = current; + + unlazy_fpu(p); + if (!p->used_math) + { + /* Simulate an empty FPU. */ + set_fpu_cwd(p, 0x037f); + set_fpu_swd(p, 0x0000); + set_fpu_twd(p, 0xffff); + } + get_fpregs(to, p); +} + +void +ptrace_getfpxregs(struct user_fxsr_struct *to) +{ + struct task_struct *p = current; + + unlazy_fpu(p); + if (!p->used_math) + { + /* Simulate an empty FPU. */ + set_fpu_cwd(p, 0x037f); + set_fpu_swd(p, 0x0000); + set_fpu_twd(p, 0xffff); + set_fpu_mxcsr(p, 0x1f80); + } + get_fpxregs(to, p); +} + +void +ptrace_setfpregs(struct user_i387_struct *from) +{ + struct task_struct *p = current; + + clear_fpu(p); + p->used_math = 1; + set_fpregs(p, from); +} + +void +ptrace_setfpxregs(struct user_fxsr_struct *from) +{ + struct task_struct *p = current; + + clear_fpu(p); + p->used_math = 1; + set_fpxregs(p, from); +} +#endif /* CONFIG_MOSIX */ + + + + + + + + + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/kernel/reboot.c linux_umopenmosix/arch/um/kernel/reboot.c --- linux-2.4.17/arch/um/kernel/reboot.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/kernel/reboot.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2000 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include "linux/sched.h" +#include "user_util.h" +#include "kern_util.h" +#include "kern.h" + +static void kill_off_processes(void) +{ + struct task_struct *p; + int me; + + me = getpid(); + for_each_task(p){ + if(p->thread.extern_pid != me) kill_pid(p->thread.extern_pid); + } + if(init_task.thread.extern_pid != me) + kill_pid(init_task.thread.extern_pid); +} + +void uml_cleanup(void) +{ + kill_off_processes(); + do_uml_exitcalls(); +} + +void machine_restart(char * __unused) +{ + do_exitcalls(); + kill_off_processes(); + tracing_reboot(); + kill_pid(getpid()); +} + +void machine_power_off(void) +{ + do_exitcalls(); + kill_off_processes(); + tracing_halt(); + kill_pid(getpid()); +} + +void machine_halt(void) +{ + machine_power_off(); +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/kernel/resource.c linux_umopenmosix/arch/um/kernel/resource.c --- linux-2.4.17/arch/um/kernel/resource.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/kernel/resource.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2000 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include "linux/pci.h" + +unsigned long resource_fixup(struct pci_dev * dev, struct resource * res, + unsigned long start, unsigned long size) +{ + return start; +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/kernel/setup.c linux_umopenmosix/arch/um/kernel/setup.c --- linux-2.4.17/arch/um/kernel/setup.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/kernel/setup.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2000 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include "asm/processor.h" + +struct cpuinfo_um boot_cpu_data = { 0, 0, 0, 0 }; + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/kernel/signal_kern.c linux_umopenmosix/arch/um/kernel/signal_kern.c --- linux-2.4.17/arch/um/kernel/signal_kern.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/kernel/signal_kern.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,363 @@ +/* + * Copyright (C) 2000, 2001 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include "linux/config.h" +#include "linux/stddef.h" +#include "linux/sys.h" +#include "linux/sched.h" +#include "linux/wait.h" +#include "linux/kernel.h" +#include "linux/smp_lock.h" +#include "linux/module.h" +#include "linux/slab.h" +#include "asm/signal.h" +#include "asm/uaccess.h" +#include "user_util.h" +#include "kern_util.h" +#include "signal_kern.h" +#include "signal_user.h" +#include "kern.h" +#include "frame_kern.h" +#include "frame.h" +#include "sigcontext.h" +#include "sysdep/sigcontext.h" + + +EXPORT_SYMBOL(block_signals); +EXPORT_SYMBOL(unblock_signals); + +int probe_stack(unsigned long sp, int delta) +{ + int n; + + if((get_user(n, (int *) sp) != 0) || + (put_user(n, (int *) sp) != 0) || + (get_user(n, (int *) (sp - delta)) != 0) || + (put_user(n, (int *) (sp - delta)) != 0)) + return(-EFAULT); + return(0); +} + +static void force_segv(int sig) +{ + if(sig == SIGSEGV){ + struct k_sigaction *ka; + + ka = ¤t->sig->action[SIGSEGV - 1]; + ka->sa.sa_handler = SIG_DFL; + } + force_sig(SIGSEGV, current); +} + +#define _S(nr) (1<<((nr)-1)) + +#define _BLOCKABLE (~(_S(SIGKILL) | _S(SIGSTOP))) + +/* + * OK, we're invoking a handler + */ +static int handle_signal(unsigned long signr, struct k_sigaction *ka, + siginfo_t *info, sigset_t *oldset, int error) +{ + struct signal_context *context; + __sighandler_t handler; + void (*restorer)(void); + unsigned long sp; + sigset_t save; + int err, ret; + + ret = 0; + switch(error){ + case -ERESTARTNOHAND: + ret = -EINTR; + break; + + case -ERESTARTSYS: + if (!(ka->sa.sa_flags & SA_RESTART)) { + ret = -EINTR; + break; + } + /* fallthrough */ + case -ERESTARTNOINTR: + UM_RESTART_SYSCALL(¤t->thread.process_regs); + UM_ORIG_SYSCALL(¤t->thread.process_regs) = + UM_SYSCALL_NR(¤t->thread.process_regs); + + /* This is because of the UM_SET_SYSCALL_RETURN and the fact + * that on i386 the system call number and return value are + * in the same register. When the system call restarts, %eax + * had better have the system call number in it. Since the + * return value doesn't matter (except that it shouldn't be + * -ERESTART*), we'll stick the system call number there. + */ + ret = UM_SYSCALL_NR(¤t->thread.process_regs); + break; + } + + handler = ka->sa.sa_handler; + save = *oldset; + + if (ka->sa.sa_flags & SA_ONESHOT) + ka->sa.sa_handler = SIG_DFL; + + if (!(ka->sa.sa_flags & SA_NODEFER)) { + spin_lock_irq(¤t->sigmask_lock); + sigorsets(¤t->blocked, ¤t->blocked, + &ka->sa.sa_mask); + sigaddset(¤t->blocked, signr); + recalc_sigpending(current); + spin_unlock_irq(¤t->sigmask_lock); + } + + sp = UM_SP(¤t->thread.process_regs); + + if((ka->sa.sa_flags & SA_ONSTACK) && (sas_ss_flags(sp) == 0)) + sp = current->sas_ss_sp + current->sas_ss_size; + + sp -= 4 * sizeof(void *) + sizeof(*context); + context = (struct signal_context *) sp; + + if(error != 0) + UM_SET_SYSCALL_RETURN(¤t->thread.process_regs, ret); + + if(copy_to_user(&context->regs, ¤t->thread.process_regs, + sizeof(current->thread.process_regs)) || + copy_to_user(&context->sigs, &save, sizeof(save)) || + copy_to_user(&context->prev, ¤t->thread.signal_context, + sizeof(current->thread.signal_context))){ + force_segv(signr); + return(1); + } + + if(ka->sa.sa_flags & SA_SIGINFO){ + sp -= SC_STACK_SIZE; + if(copy_sc_to_user((void *) sp, current->thread.sc, + &signal_frame_sc.arch)) + goto segv; + context->sc = (struct sigcontext *) sp; + } + + current->thread.signal_context = context; + sp -= 4 * sizeof(void *); + + if (ka->sa.sa_flags & SA_RESTORER) restorer = ka->sa.sa_restorer; + else restorer = NULL; + + if(ka->sa.sa_flags & SA_SIGINFO) + err = setup_signal_stack_si(sp, signr, (unsigned long) handler, + restorer, + ¤t->thread.process_regs, + info); + else + err = setup_signal_stack_sc(sp, signr, (unsigned long) handler, + restorer, + ¤t->thread.process_regs, + current->thread.sc, &context->sc); + if(err) goto segv; + + return(0); + segv: + force_segv(signr); + return(1); +} + +/* + * Note that 'init' is a special process: it doesn't get signals it doesn't + * want to handle. Thus you cannot kill init even with a SIGKILL even by + * mistake. + */ + +static int kern_do_signal(sigset_t *oldset, int error) +{ + siginfo_t info; + struct k_sigaction *ka; + int err; + + if (!oldset) + oldset = ¤t->blocked; + + for (;;) { + unsigned long signr; + + spin_lock_irq(¤t->sigmask_lock); + signr = dequeue_signal(¤t->blocked, &info); + spin_unlock_irq(¤t->sigmask_lock); + + if (!signr) + break; + + if ((current->ptrace & PT_PTRACED) && signr != SIGKILL) { + /* Let the debugger run. */ + current->exit_code = signr; + current->state = TASK_STOPPED; + notify_parent(current, SIGCHLD); + schedule(); + + /* We're back. Did the debugger cancel the sig? */ + if (!(signr = current->exit_code)) + continue; + current->exit_code = 0; + + /* The debugger continued. Ignore SIGSTOP. */ + if (signr == SIGSTOP) + continue; + + /* Update the siginfo structure. Is this good? */ + if (signr != info.si_signo) { + info.si_signo = signr; + info.si_errno = 0; + info.si_code = SI_USER; + info.si_pid = current->p_pptr->pid; + info.si_uid = current->p_pptr->uid; + } + + /* If the (new) signal is now blocked, requeue it. */ + if (sigismember(¤t->blocked, signr)) { + send_sig_info(signr, &info, current); + continue; + } + } + + ka = ¤t->sig->action[signr-1]; + if (ka->sa.sa_handler == SIG_IGN) { + if (signr != SIGCHLD) + continue; + /* Check for SIGCHLD: it's special. */ + while (sys_wait4(-1, NULL, WNOHANG, NULL) > 0) + /* nothing */; + continue; + } + + if (ka->sa.sa_handler == SIG_DFL) { + int exit_code = signr; + + /* Init gets no signals it doesn't want. */ + if (current->pid == 1) + continue; + + switch (signr) { + case SIGCONT: case SIGCHLD: case SIGWINCH: + continue; + + case SIGTSTP: case SIGTTIN: case SIGTTOU: + if (is_orphaned_pgrp(current->pgrp)) + continue; + /* FALLTHRU */ + + case SIGSTOP: { + struct signal_struct *sig; + current->state = TASK_STOPPED; + current->exit_code = signr; + sig = current->p_pptr->sig; + if (sig && !(sig->action[SIGCHLD-1].sa.sa_flags & SA_NOCLDSTOP)) + notify_parent(current, SIGCHLD); + schedule(); + continue; + } + case SIGQUIT: case SIGILL: case SIGTRAP: + case SIGABRT: case SIGFPE: case SIGSEGV: + case SIGBUS: case SIGSYS: case SIGXCPU: case SIGXFSZ: + if (do_coredump(signr, + (struct pt_regs *) + ¤t->thread.process_regs)) + exit_code |= 0x80; + /* FALLTHRU */ + + default: + sigaddset(¤t->pending.signal, signr); + recalc_sigpending(current); + current->flags |= PF_SIGNALED; + do_exit(exit_code); + /* NOTREACHED */ + } + } + + /* Whee! Actually deliver the signal. */ + err = handle_signal(signr, ka, &info, oldset, error); + if(!err) return(1); + } + return(0); +} + +int do_signal(int error) +{ + return(kern_do_signal(NULL, error)); +} + +/* + * Atomically swap in the new signal mask, and wait for a signal. + */ +int sys_sigsuspend(int history0, int history1, old_sigset_t mask) +{ + sigset_t saveset; + + mask &= _BLOCKABLE; + spin_lock_irq(¤t->sigmask_lock); + saveset = current->blocked; + siginitset(¤t->blocked, mask); + recalc_sigpending(current); + spin_unlock_irq(¤t->sigmask_lock); + + while (1) { + current->state = TASK_INTERRUPTIBLE; + schedule(); + if(kern_do_signal(&saveset, -EINTR)) + return(-EINTR); + } +} + +int sys_rt_sigsuspend(sigset_t *unewset, size_t sigsetsize) +{ + sigset_t saveset, newset; + + /* XXX: Don't preclude handling different sized sigset_t's. */ + if (sigsetsize != sizeof(sigset_t)) + return -EINVAL; + + if (copy_from_user(&newset, unewset, sizeof(newset))) + return -EFAULT; + sigdelsetmask(&newset, ~_BLOCKABLE); + + spin_lock_irq(¤t->sigmask_lock); + saveset = current->blocked; + current->blocked = newset; + recalc_sigpending(current); + spin_unlock_irq(¤t->sigmask_lock); + + while (1) { + current->state = TASK_INTERRUPTIBLE; + schedule(); + if (kern_do_signal(&saveset, -EINTR)) + return(-EINTR); + } +} + +int sys_sigreturn(struct sys_pt_regs regs) +{ + struct signal_context *context = current->thread.signal_context; + + sigdelsetmask(&context->sigs, ~_BLOCKABLE); + spin_lock_irq(¤t->sigmask_lock); + current->blocked = context->sigs; + recalc_sigpending(current); + spin_unlock_irq(¤t->sigmask_lock); + current->thread.process_regs = context->regs; + current->thread.signal_context = context->prev; + if(context->sc != NULL) + copy_sc_from_user(current->thread.sc, context->sc); + return(UM_SYSCALL_RET(¤t->thread.process_regs)); +} + + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/kernel/signal_user.c linux_umopenmosix/arch/um/kernel/signal_user.c --- linux-2.4.17/arch/um/kernel/signal_user.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/kernel/signal_user.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,139 @@ +/* + * Copyright (C) 2000 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "user_util.h" +#include "kern_util.h" +#include "user.h" +#include "signal_user.h" +#include "signal_kern.h" +#include "sysdep/sigcontext.h" +#include "sigcontext.h" + +extern int timer_on; + +void set_sigstack(void *sig_stack, int size) +{ + stack_t stack; + + stack.ss_sp = (__ptr_t) sig_stack; + stack.ss_flags = 0; + stack.ss_size = size - sizeof(void *); + if(sigaltstack(&stack, NULL) != 0) + panic("sigaltstack failed"); +} + +void set_handler(int sig, void (*handler)(int), int flags, ...) +{ + struct sigaction action; + va_list ap; + int mask; + + va_start(ap, flags); + action.sa_handler = handler; + sigemptyset(&action.sa_mask); + while((mask = va_arg(ap, int)) != -1){ + sigaddset(&action.sa_mask, mask); + } + action.sa_flags = flags; + action.sa_restorer = NULL; + if(sigaction(sig, &action, NULL) < 0) + panic("sigaction failed"); +} + +int change_sig(int signal, int on) +{ + sigset_t sigset, old; + + sigemptyset(&sigset); + sigaddset(&sigset, signal); + sigprocmask(on ? SIG_UNBLOCK : SIG_BLOCK, &sigset, &old); + return(sigismember(&old, signal)); +} + +static void change_signals(int type) +{ + sigset_t mask; + + sigemptyset(&mask); + if(type == SIG_BLOCK) timer_on = 0; + else { + timer_on = 1; + sigaddset(&mask, SIGVTALRM); + sigaddset(&mask, SIGALRM); + } + sigaddset(&mask, SIGIO); + sigaddset(&mask, SIGWINCH); + sigaddset(&mask, SIGPROF); + if(sigprocmask(type, &mask, NULL) < 0) + panic("Failed to change signal mask - errno = %d", errno); +} + +void block_signals(void) +{ + change_signals(SIG_BLOCK); +} + +void unblock_signals(void) +{ + change_signals(SIG_UNBLOCK); +} + +#define SIGIO_BIT 0 +#define SIGVTALRM_BIT 1 + +static int enable_mask(sigset_t *mask) +{ + int sigs; + + sigs = sigismember(mask, SIGIO) ? 0 : 1 << SIGIO_BIT; + sigs |= sigismember(mask, SIGVTALRM) ? 0 : 1 << SIGVTALRM_BIT; + sigs |= sigismember(mask, SIGALRM) ? 0 : 1 << SIGVTALRM_BIT; + if(timer_on) sigs |= 1 << SIGVTALRM_BIT; + return(sigs); +} + +int set_signals(int enable) +{ + sigset_t mask; + int ret; + + sigemptyset(&mask); + if(enable & (1 << SIGIO_BIT)) sigaddset(&mask, SIGIO); + if(enable & (1 << SIGVTALRM_BIT)){ + timer_on = 1; + sigaddset(&mask, SIGVTALRM); + sigaddset(&mask, SIGALRM); + } + if(sigprocmask(SIG_UNBLOCK, &mask, &mask) < 0) + panic("Failed to enable signals"); + ret = enable_mask(&mask); + sigemptyset(&mask); + if((enable & (1 << SIGIO_BIT)) == 0) sigaddset(&mask, SIGIO); + if((enable & (1 << SIGVTALRM_BIT)) == 0){ + timer_on = 0; + } + if(sigprocmask(SIG_BLOCK, &mask, NULL) < 0) + panic("Failed to block signals"); + return(ret); +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/kernel/smp.c linux_umopenmosix/arch/um/kernel/smp.c --- linux-2.4.17/arch/um/kernel/smp.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/kernel/smp.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,299 @@ +/* + * Copyright (C) 2000 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include "linux/config.h" + + +#ifdef CONFIG_SMP + +#include "linux/sched.h" +#include "linux/threads.h" +#include "linux/interrupt.h" +#include "asm/smp.h" +#include "asm/processor.h" +#include "asm/spinlock.h" +#include "asm/softirq.h" +#include "asm/hardirq.h" +#include "user_util.h" +#include "kern_util.h" +#include "kern.h" + +/* Total count of live CPUs */ +int smp_num_cpus = 1; + +/* The 'big kernel lock' */ +spinlock_t kernel_flag = SPIN_LOCK_UNLOCKED; + +/* Per CPU bogomips and other parameters */ +struct cpuinfo_um cpu_data[NR_CPUS]; + +/* CPU online map */ +unsigned long cpu_online_map; + +spinlock_t um_bh_lock = SPIN_LOCK_UNLOCKED; + +atomic_t global_bh_count; + +unsigned char global_irq_holder = NO_PROC_ID; +unsigned volatile long global_irq_lock; + +/* Set when the idlers are all forked */ +int smp_threads_ready = 0; +int num_reschedules_sent = 0; + +void smp_send_reschedule(int cpu) +{ + write(cpu_data[cpu].ipi_pipe[1], "R", 1); + num_reschedules_sent++; +} + +static void show(char * str) +{ + int cpu = smp_processor_id(); + + printk(KERN_INFO "\n%s, CPU %d:\n", str, cpu); +} + +#define MAXCOUNT 100000000 + +static inline void wait_on_bh(void) +{ + int count = MAXCOUNT; + do { + if (!--count) { + show("wait_on_bh"); + count = ~0; + } + /* nothing .. wait for the other bh's to go away */ + } while (atomic_read(&global_bh_count) != 0); +} + +/* + * This is called when we want to synchronize with + * bottom half handlers. We need to wait until + * no other CPU is executing any bottom half handler. + * + * Don't wait if we're already running in an interrupt + * context or are inside a bh handler. + */ +void synchronize_bh(void) +{ + if (atomic_read(&global_bh_count) && !in_interrupt()) + wait_on_bh(); +} + +void smp_send_stop(void) +{ + printk(KERN_INFO "Stopping all CPUs\n"); +} + + +static atomic_t smp_commenced = ATOMIC_INIT(0); +static volatile unsigned long smp_callin_map = 0; + +void smp_commence(void) +{ + printk("All CPUs are go!\n"); + + wmb(); + atomic_set(&smp_commenced, 1); +} + +static int idle_proc(void *unused) +{ + int cpu; + + set_current(current); + del_from_runqueue(current); + unhash_process(current); + + cpu = current->processor; + if (socketpair(AF_UNIX, SOCK_STREAM, 0, cpu_data[cpu].ipi_pipe) < 0) + panic("CPU#%d failed to create IPI pipe", cpu); + + activate_ipi(cpu_data[cpu].ipi_pipe[0], current->thread.extern_pid); + + wmb(); + if (test_and_set_bit(current->processor, &smp_callin_map)) { + printk("huh, CPU#%d already present??\n", current->processor); + BUG(); + } + + while (!atomic_read(&smp_commenced)) + cpu_relax(); + + init_idle(); + cpu_idle(); + return(0); +} + +void smp_boot_cpus(void) +{ + set_bit(0, &cpu_online_map); + set_bit(0, &smp_callin_map); + + if (socketpair(AF_UNIX, SOCK_STREAM, 0, cpu_data[0].ipi_pipe) < 0) + panic("CPU#0 failed to create IPI pipe"); + activate_ipi(cpu_data[0].ipi_pipe[0], current->thread.extern_pid); + + if(ncpus < 1){ + printk(KERN_INFO "ncpus set to 1\n"); + ncpus = 1; + } + else if(ncpus > NR_CPUS){ + printk(KERN_INFO + "ncpus can't be greater than NR_CPUS, set to %d\n", + NR_CPUS); + ncpus = NR_CPUS; + } + + if(ncpus > 1){ + int i, pid; + + printk(KERN_INFO "Starting up other processors:\n"); + for(i=1;ineed_resched = 1; + break; + + default: + printk("CPU#%d received unknown IPI [%c]!\n", cpu, c); + break; + } + } +} + +int inited_cpus = 1; + +int hard_smp_processor_id(void) +{ + return(pid_to_processor_id(getpid())); +} + +static spinlock_t call_lock = SPIN_LOCK_UNLOCKED; +static atomic_t scf_started; +static atomic_t scf_finished; +static void (*func)(void *info); +static void *info; + +void smp_call_function_slave(int cpu) +{ + atomic_inc(&scf_started); + (*func)(info); + atomic_inc(&scf_finished); +} + +int smp_call_function(void (*_func)(void *info), void *_info, int nonatomic, + int wait) +{ + int cpus = smp_num_cpus - 1; + int i; + + if (!cpus) + return 0; + + spin_lock_bh(&call_lock); + atomic_set(&scf_started, 0); + atomic_set(&scf_finished, 0); + func = _func; + info = _info; + + for (i=0;iprocessor && test_bit(i, &cpu_online_map)) + write(cpu_data[i].ipi_pipe[1], "C", 1); + + while (atomic_read(&scf_started) != cpus) + barrier(); + + if (wait) + while (atomic_read(&scf_finished) != cpus) + barrier(); + + spin_unlock_bh(&call_lock); + return 0; +} + + + + +void flush_tlb_current_task(void) +{ + struct mm_struct *mm = current->mm; + unsigned long cpu_mask = mm->cpu_vm_mask & ~(1 << smp_processor_id()); + + local_flush_tlb(); + if (cpu_mask) + flush_tlb_others(cpu_mask, mm, FLUSH_ALL); +} + + + + + + + + + + + + + +#endif + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/kernel/somename.c linux_umopenmosix/arch/um/kernel/somename.c --- linux-2.4.17/arch/um/kernel/somename.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/kernel/somename.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,12 @@ +#include "linux/kernel.h" +#include "linux/unistd.h" +#include "somename.h" + +void sys_somename() { + printk("hello, from syscall 226, ;)\n"); + return; +} + + + + diff -urN linux-2.4.17/arch/um/kernel/sys_call_table.c linux_umopenmosix/arch/um/kernel/sys_call_table.c --- linux-2.4.17/arch/um/kernel/sys_call_table.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/kernel/sys_call_table.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,464 @@ +/* + * Copyright (C) 2000 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include "linux/unistd.h" +#include "linux/version.h" +#include "linux/sys.h" +#include "asm/signal.h" +#include "sysdep/syscalls.h" +#include "kern_util.h" + +extern syscall_handler_t sys_ni_syscall; +extern syscall_handler_t sys_exit; +extern syscall_handler_t sys_fork; +extern syscall_handler_t sys_read; +extern syscall_handler_t sys_write; +extern syscall_handler_t sys_creat; +extern syscall_handler_t sys_link; +extern syscall_handler_t sys_unlink; +extern syscall_handler_t sys_chdir; +extern syscall_handler_t sys_mknod; +extern syscall_handler_t sys_chmod; +extern syscall_handler_t sys_lchown16; +extern syscall_handler_t sys_ni_syscall; +extern syscall_handler_t sys_stat; +extern syscall_handler_t sys_lseek; +extern syscall_handler_t sys_getpid; +extern syscall_handler_t sys_oldumount; +extern syscall_handler_t sys_setuid16; +extern syscall_handler_t sys_getuid16; +extern syscall_handler_t sys_ptrace; +extern syscall_handler_t sys_alarm; +extern syscall_handler_t sys_fstat; +extern syscall_handler_t sys_pause; +extern syscall_handler_t sys_utime; +extern syscall_handler_t sys_ni_syscall; +extern syscall_handler_t sys_ni_syscall; +extern syscall_handler_t sys_access; +extern syscall_handler_t sys_nice; +extern syscall_handler_t sys_ni_syscall; +extern syscall_handler_t sys_sync; +extern syscall_handler_t sys_kill; +extern syscall_handler_t sys_rename; +extern syscall_handler_t sys_mkdir; +extern syscall_handler_t sys_rmdir; +extern syscall_handler_t sys_pipe; +extern syscall_handler_t sys_times; +extern syscall_handler_t sys_ni_syscall; +extern syscall_handler_t sys_brk; +extern syscall_handler_t sys_setgid16; +extern syscall_handler_t sys_getgid16; +extern syscall_handler_t sys_signal; +extern syscall_handler_t sys_geteuid16; +extern syscall_handler_t sys_getegid16; +extern syscall_handler_t sys_acct; +extern syscall_handler_t sys_umount; +extern syscall_handler_t sys_ni_syscall; +extern syscall_handler_t sys_ioctl; +extern syscall_handler_t sys_fcntl; +extern syscall_handler_t sys_ni_syscall; +extern syscall_handler_t sys_setpgid; +extern syscall_handler_t sys_ni_syscall; +extern syscall_handler_t sys_olduname; +extern syscall_handler_t sys_umask; +extern syscall_handler_t sys_chroot; +extern syscall_handler_t sys_ustat; +extern syscall_handler_t sys_dup2; +extern syscall_handler_t sys_getppid; +extern syscall_handler_t sys_getpgrp; +extern syscall_handler_t sys_sigaction; +extern syscall_handler_t sys_sgetmask; +extern syscall_handler_t sys_ssetmask; +extern syscall_handler_t sys_setreuid16; +extern syscall_handler_t sys_setregid16; +extern syscall_handler_t sys_sigsuspend; +extern syscall_handler_t sys_sigpending; +extern syscall_handler_t sys_sethostname; +extern syscall_handler_t sys_setrlimit; +extern syscall_handler_t sys_old_getrlimit; +extern syscall_handler_t sys_getrusage; +extern syscall_handler_t sys_gettimeofday; +extern syscall_handler_t sys_settimeofday; +extern syscall_handler_t sys_getgroups16; +extern syscall_handler_t sys_setgroups16; +extern syscall_handler_t sys_symlink; +extern syscall_handler_t sys_lstat; +extern syscall_handler_t sys_readlink; +extern syscall_handler_t sys_uselib; +extern syscall_handler_t sys_swapon; +extern syscall_handler_t sys_reboot; +extern syscall_handler_t old_readdir; +extern syscall_handler_t sys_munmap; +extern syscall_handler_t sys_truncate; +extern syscall_handler_t sys_ftruncate; +extern syscall_handler_t sys_fchmod; +extern syscall_handler_t sys_fchown16; +extern syscall_handler_t sys_getpriority; +extern syscall_handler_t sys_setpriority; +extern syscall_handler_t sys_ni_syscall; +extern syscall_handler_t sys_statfs; +extern syscall_handler_t sys_fstatfs; +extern syscall_handler_t sys_ni_syscall; +extern syscall_handler_t sys_socketcall; +extern syscall_handler_t sys_syslog; +extern syscall_handler_t sys_setitimer; +extern syscall_handler_t sys_getitimer; +extern syscall_handler_t sys_newstat; +extern syscall_handler_t sys_newlstat; +extern syscall_handler_t sys_newfstat; +extern syscall_handler_t sys_uname; +extern syscall_handler_t sys_ni_syscall; +extern syscall_handler_t sys_vhangup; +extern syscall_handler_t sys_ni_syscall; +extern syscall_handler_t sys_ni_syscall; +extern syscall_handler_t sys_swapoff; +extern syscall_handler_t sys_sysinfo; +extern syscall_handler_t sys_ipc; +extern syscall_handler_t sys_fsync; +extern syscall_handler_t sys_sigreturn; +extern syscall_handler_t sys_clone; +extern syscall_handler_t sys_setdomainname; +extern syscall_handler_t sys_newuname; +extern syscall_handler_t sys_ni_syscall; +extern syscall_handler_t sys_adjtimex; +extern syscall_handler_t sys_mprotect; +extern syscall_handler_t sys_sigprocmask; +extern syscall_handler_t sys_create_module; +extern syscall_handler_t sys_init_module; +extern syscall_handler_t sys_delete_module; +extern syscall_handler_t sys_get_kernel_syms; +extern syscall_handler_t sys_quotactl; +extern syscall_handler_t sys_getpgid; +extern syscall_handler_t sys_fchdir; +extern syscall_handler_t sys_bdflush; +extern syscall_handler_t sys_sysfs; +extern syscall_handler_t sys_personality; +extern syscall_handler_t sys_ni_syscall; +extern syscall_handler_t sys_setfsuid16; +extern syscall_handler_t sys_setfsgid16; +extern syscall_handler_t sys_llseek; +extern syscall_handler_t sys_getdents; +extern syscall_handler_t sys_flock; +extern syscall_handler_t sys_msync; +extern syscall_handler_t sys_readv; +extern syscall_handler_t sys_writev; +extern syscall_handler_t sys_getsid; +extern syscall_handler_t sys_fdatasync; +extern syscall_handler_t sys_sysctl; +extern syscall_handler_t sys_mlock; +extern syscall_handler_t sys_munlock; +extern syscall_handler_t sys_mlockall; +extern syscall_handler_t sys_munlockall; +extern syscall_handler_t sys_sched_setparam; +extern syscall_handler_t sys_sched_getparam; +extern syscall_handler_t sys_sched_setscheduler; +extern syscall_handler_t sys_sched_getscheduler; +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0) +extern syscall_handler_t sys_sched_yield; +#endif +extern syscall_handler_t sys_sched_get_priority_max; +extern syscall_handler_t sys_sched_get_priority_min; +extern syscall_handler_t sys_sched_rr_get_interval; +extern syscall_handler_t sys_nanosleep; +extern syscall_handler_t sys_mremap; +extern syscall_handler_t sys_setresuid16; +extern syscall_handler_t sys_getresuid16; +extern syscall_handler_t sys_ni_syscall; +extern syscall_handler_t sys_query_module; +extern syscall_handler_t sys_poll; +extern syscall_handler_t sys_nfsservctl; +extern syscall_handler_t sys_setresgid16; +extern syscall_handler_t sys_getresgid16; +extern syscall_handler_t sys_prctl; +extern syscall_handler_t sys_ni_syscall; +extern syscall_handler_t sys_rt_sigaction; +extern syscall_handler_t sys_rt_sigprocmask; +extern syscall_handler_t sys_rt_sigpending; +extern syscall_handler_t sys_rt_sigtimedwait; +extern syscall_handler_t sys_rt_sigqueueinfo; +extern syscall_handler_t sys_rt_sigsuspend; +extern syscall_handler_t sys_pread; +extern syscall_handler_t sys_pwrite; +extern syscall_handler_t sys_chown16; +extern syscall_handler_t sys_getcwd; +extern syscall_handler_t sys_capget; +extern syscall_handler_t sys_capset; +extern syscall_handler_t sys_sigaltstack; +extern syscall_handler_t sys_sendfile; +extern syscall_handler_t sys_ni_syscall; +extern syscall_handler_t sys_ni_syscall; +extern syscall_handler_t sys_vfork; +extern syscall_handler_t sys_getrlimit; +extern syscall_handler_t sys_mmap2; +extern syscall_handler_t sys_truncate64; +extern syscall_handler_t sys_ftruncate64; +extern syscall_handler_t sys_stat64; +extern syscall_handler_t sys_lstat64; +extern syscall_handler_t sys_fstat64; +extern syscall_handler_t sys_lchown; +extern syscall_handler_t sys_getuid; +extern syscall_handler_t sys_getgid; +extern syscall_handler_t sys_geteuid; +extern syscall_handler_t sys_getegid; +extern syscall_handler_t sys_setreuid; +extern syscall_handler_t sys_setregid; +extern syscall_handler_t sys_getgroups; +extern syscall_handler_t sys_setgroups; +extern syscall_handler_t sys_fchown; +extern syscall_handler_t sys_setresuid; +extern syscall_handler_t sys_getresuid; +extern syscall_handler_t sys_setresgid; +extern syscall_handler_t sys_getresgid; +extern syscall_handler_t sys_chown; +extern syscall_handler_t sys_setuid; +extern syscall_handler_t sys_setgid; +extern syscall_handler_t sys_setfsuid; +extern syscall_handler_t sys_setfsgid; +extern syscall_handler_t sys_pivot_root; +extern syscall_handler_t sys_mincore; +extern syscall_handler_t sys_madvise; +extern syscall_handler_t sys_fcntl64; +extern syscall_handler_t sys_getdents64; +extern syscall_handler_t sys_gettid; +extern syscall_handler_t sys_readahead; + +extern syscall_handler_t sys_somename; + +extern syscall_handler_t um_mount; +extern syscall_handler_t um_time; +extern syscall_handler_t um_stime; + +#define LAST_GENERIC_SYSCALL __NR_somename + +#if LAST_GENERIC_SYSCALL > LAST_ARCH_SYSCALL +#define LAST_SYSCALL LAST_GENERIC_SYSCALL +#else +#define LAST_SYSCALL LAST_ARCH_SYSCALL +#endif + +syscall_handler_t *sys_call_table[] = { + [ 0 ] = sys_ni_syscall, + [ __NR_exit ] = sys_exit, + [ __NR_fork ] = sys_fork, + [ __NR_read ] = sys_read, + [ __NR_write ] = sys_write, + + /* These three are declared differently in asm/unistd.h */ + [ __NR_open ] = (syscall_handler_t *) sys_open, + [ __NR_close ] = (syscall_handler_t *) sys_close, + [ __NR_waitpid ] = (syscall_handler_t *) sys_waitpid, + [ __NR_creat ] = sys_creat, + [ __NR_link ] = sys_link, + [ __NR_unlink ] = sys_unlink, + + /* declared differently in kern_util.h */ + [ __NR_execve ] = (syscall_handler_t *) sys_execve, + [ __NR_chdir ] = sys_chdir, + [ __NR_time ] = um_time, + [ __NR_mknod ] = sys_mknod, + [ __NR_chmod ] = sys_chmod, + [ __NR_lchown ] = sys_lchown16, + [ __NR_break ] = sys_ni_syscall, + [ __NR_oldstat ] = sys_stat, + [ __NR_lseek ] = sys_lseek, + [ __NR_getpid ] = sys_getpid, + [ __NR_mount ] = um_mount, + [ __NR_umount ] = sys_oldumount, + [ __NR_setuid ] = sys_setuid16, + [ __NR_getuid ] = sys_getuid16, + [ __NR_stime ] = um_stime, + [ __NR_ptrace ] = sys_ptrace, + [ __NR_alarm ] = sys_alarm, + [ __NR_oldfstat ] = sys_fstat, + [ __NR_pause ] = sys_pause, + [ __NR_utime ] = sys_utime, + [ __NR_stty ] = sys_ni_syscall, + [ __NR_gtty ] = sys_ni_syscall, + [ __NR_access ] = sys_access, + [ __NR_nice ] = sys_nice, + [ __NR_ftime ] = sys_ni_syscall, + [ __NR_sync ] = sys_sync, + [ __NR_kill ] = sys_kill, + [ __NR_rename ] = sys_rename, + [ __NR_mkdir ] = sys_mkdir, + [ __NR_rmdir ] = sys_rmdir, + + /* Declared differently in asm/unistd.h */ + [ __NR_dup ] = (syscall_handler_t *) sys_dup, + [ __NR_pipe ] = sys_pipe, + [ __NR_times ] = sys_times, + [ __NR_prof ] = sys_ni_syscall, + [ __NR_brk ] = sys_brk, + [ __NR_setgid ] = sys_setgid16, + [ __NR_getgid ] = sys_getgid16, + [ __NR_signal ] = sys_signal, + [ __NR_geteuid ] = sys_geteuid16, + [ __NR_getegid ] = sys_getegid16, + [ __NR_acct ] = sys_acct, + [ __NR_umount2 ] = sys_umount, + [ __NR_lock ] = sys_ni_syscall, + [ __NR_ioctl ] = sys_ioctl, + [ __NR_fcntl ] = sys_fcntl, + [ __NR_mpx ] = sys_ni_syscall, + [ __NR_setpgid ] = sys_setpgid, + [ __NR_ulimit ] = sys_ni_syscall, + [ __NR_oldolduname ] = sys_olduname, + [ __NR_umask ] = sys_umask, + [ __NR_chroot ] = sys_chroot, + [ __NR_ustat ] = sys_ustat, + [ __NR_dup2 ] = sys_dup2, + [ __NR_getppid ] = sys_getppid, + [ __NR_getpgrp ] = sys_getpgrp, + [ __NR_setsid ] = (syscall_handler_t *) sys_setsid, + [ __NR_sigaction ] = sys_sigaction, + [ __NR_sgetmask ] = sys_sgetmask, + [ __NR_ssetmask ] = sys_ssetmask, + [ __NR_setreuid ] = sys_setreuid16, + [ __NR_setregid ] = sys_setregid16, + [ __NR_sigsuspend ] = sys_sigsuspend, + [ __NR_sigpending ] = sys_sigpending, + [ __NR_sethostname ] = sys_sethostname, + [ __NR_setrlimit ] = sys_setrlimit, + [ __NR_getrlimit ] = sys_old_getrlimit, + [ __NR_getrusage ] = sys_getrusage, + [ __NR_gettimeofday ] = sys_gettimeofday, + [ __NR_settimeofday ] = sys_settimeofday, + [ __NR_getgroups ] = sys_getgroups16, + [ __NR_setgroups ] = sys_setgroups16, + [ __NR_symlink ] = sys_symlink, + [ __NR_oldlstat ] = sys_lstat, + [ __NR_readlink ] = sys_readlink, + [ __NR_uselib ] = sys_uselib, + [ __NR_swapon ] = sys_swapon, + [ __NR_reboot ] = sys_reboot, + [ __NR_readdir ] = old_readdir, + [ __NR_munmap ] = sys_munmap, + [ __NR_truncate ] = sys_truncate, + [ __NR_ftruncate ] = sys_ftruncate, + [ __NR_fchmod ] = sys_fchmod, + [ __NR_fchown ] = sys_fchown16, + [ __NR_getpriority ] = sys_getpriority, + [ __NR_setpriority ] = sys_setpriority, + [ __NR_profil ] = sys_ni_syscall, + [ __NR_statfs ] = sys_statfs, + [ __NR_fstatfs ] = sys_fstatfs, + [ __NR_ioperm ] = sys_ni_syscall, + [ __NR_socketcall ] = sys_socketcall, + [ __NR_syslog ] = sys_syslog, + [ __NR_setitimer ] = sys_setitimer, + [ __NR_getitimer ] = sys_getitimer, + [ __NR_stat ] = sys_newstat, + [ __NR_lstat ] = sys_newlstat, + [ __NR_fstat ] = sys_newfstat, + [ __NR_olduname ] = sys_uname, + [ __NR_iopl ] = sys_ni_syscall, + [ __NR_vhangup ] = sys_vhangup, + [ __NR_idle ] = sys_ni_syscall, + [ __NR_wait4 ] = (syscall_handler_t *) sys_wait4, + [ __NR_swapoff ] = sys_swapoff, + [ __NR_sysinfo ] = sys_sysinfo, + [ __NR_ipc ] = sys_ipc, + [ __NR_fsync ] = sys_fsync, + [ __NR_sigreturn ] = sys_sigreturn, + [ __NR_clone ] = sys_clone, + [ __NR_setdomainname ] = sys_setdomainname, + [ __NR_uname ] = sys_newuname, + [ __NR_adjtimex ] = sys_adjtimex, + [ __NR_mprotect ] = sys_mprotect, + [ __NR_sigprocmask ] = sys_sigprocmask, + [ __NR_create_module ] = sys_create_module, + [ __NR_init_module ] = sys_init_module, + [ __NR_delete_module ] = sys_delete_module, + [ __NR_get_kernel_syms ] = sys_get_kernel_syms, + [ __NR_quotactl ] = sys_quotactl, + [ __NR_getpgid ] = sys_getpgid, + [ __NR_fchdir ] = sys_fchdir, + [ __NR_bdflush ] = sys_bdflush, + [ __NR_sysfs ] = sys_sysfs, + [ __NR_personality ] = sys_personality, + [ __NR_afs_syscall ] = sys_ni_syscall, + [ __NR_setfsuid ] = sys_setfsuid16, + [ __NR_setfsgid ] = sys_setfsgid16, + [ __NR__llseek ] = sys_llseek, + [ __NR_getdents ] = sys_getdents, + [ __NR__newselect ] = (syscall_handler_t *) sys_select, + [ __NR_flock ] = sys_flock, + [ __NR_msync ] = sys_msync, + [ __NR_readv ] = sys_readv, + [ __NR_writev ] = sys_writev, + [ __NR_getsid ] = sys_getsid, + [ __NR_fdatasync ] = sys_fdatasync, + [ __NR__sysctl ] = sys_sysctl, + [ __NR_mlock ] = sys_mlock, + [ __NR_munlock ] = sys_munlock, + [ __NR_mlockall ] = sys_mlockall, + [ __NR_munlockall ] = sys_munlockall, + [ __NR_sched_setparam ] = sys_sched_setparam, + [ __NR_sched_getparam ] = sys_sched_getparam, + [ __NR_sched_setscheduler ] = sys_sched_setscheduler, + [ __NR_sched_getscheduler ] = sys_sched_getscheduler, + [ __NR_sched_yield ] = sys_sched_yield, + [ __NR_sched_get_priority_max ] = sys_sched_get_priority_max, + [ __NR_sched_get_priority_min ] = sys_sched_get_priority_min, + [ __NR_sched_rr_get_interval ] = sys_sched_rr_get_interval, + [ __NR_nanosleep ] = sys_nanosleep, + [ __NR_mremap ] = sys_mremap, + [ __NR_setresuid ] = sys_setresuid16, + [ __NR_getresuid ] = sys_getresuid16, + [ __NR_vm86 ] = sys_ni_syscall, + [ __NR_query_module ] = sys_query_module, + [ __NR_poll ] = sys_poll, + [ __NR_nfsservctl ] = sys_nfsservctl, + [ __NR_setresgid ] = sys_setresgid16, + [ __NR_getresgid ] = sys_getresgid16, + [ __NR_prctl ] = sys_prctl, + [ __NR_rt_sigreturn ] = sys_ni_syscall, + [ __NR_rt_sigaction ] = sys_rt_sigaction, + [ __NR_rt_sigprocmask ] = sys_rt_sigprocmask, + [ __NR_rt_sigpending ] = sys_rt_sigpending, + [ __NR_rt_sigtimedwait ] = sys_rt_sigtimedwait, + [ __NR_rt_sigqueueinfo ] = sys_rt_sigqueueinfo, + [ __NR_rt_sigsuspend ] = sys_rt_sigsuspend, + [ __NR_pread ] = sys_pread, + [ __NR_pwrite ] = sys_pwrite, + [ __NR_chown ] = sys_chown16, + [ __NR_getcwd ] = sys_getcwd, + [ __NR_capget ] = sys_capget, + [ __NR_capset ] = sys_capset, + [ __NR_sigaltstack ] = sys_sigaltstack, + [ __NR_sendfile ] = sys_sendfile, + [ __NR_getpmsg ] = sys_ni_syscall, + [ __NR_putpmsg ] = sys_ni_syscall, + [ __NR_vfork ] = sys_vfork, + [ __NR_ugetrlimit ] = sys_getrlimit, + [ __NR_mmap2 ] = sys_mmap2, + [ __NR_truncate64 ] = sys_truncate64, + [ __NR_ftruncate64 ] = sys_ftruncate64, + [ __NR_stat64 ] = sys_stat64, + [ __NR_lstat64 ] = sys_lstat64, + [ __NR_fstat64 ] = sys_fstat64, + [ __NR_fcntl64 ] = sys_fcntl64, + [ __NR_getdents64 ] = sys_getdents64, + [ __NR_security ] = sys_ni_syscall, + [ __NR_gettid ] = sys_gettid, + [ __NR_readahead ] = sys_readahead, +/* added by matt new syscall test from uml linux */ + [ __NR_somename ] = sys_somename, +/* added by matt new syscall test from uml linux */ + ARCH_SYSCALLS + [ LAST_SYSCALL + 1 ... NR_syscalls ] = + (syscall_handler_t *) sys_ni_syscall +}; + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/kernel/syscall_kern.c linux_umopenmosix/arch/um/kernel/syscall_kern.c --- linux-2.4.17/arch/um/kernel/syscall_kern.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/kernel/syscall_kern.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,438 @@ +/* + * Copyright (C) 2000 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include "linux/sched.h" +#include "linux/file.h" +#include "linux/smp_lock.h" +#include "linux/mm.h" +#include "linux/utsname.h" +#include "linux/msg.h" +#include "linux/shm.h" +#include "linux/sys.h" +#include "linux/unistd.h" +#include "linux/slab.h" +#include "linux/utime.h" +#include "asm/mman.h" +#include "asm/uaccess.h" +#include "asm/ipc.h" +#include "kern_util.h" +#include "user_util.h" +#include "sysdep/syscalls.h" + +long um_mount(char * dev_name, char * dir_name, char * type, + unsigned long new_flags, void * data) +{ + if(type == NULL) type = ""; + return(sys_mount(dev_name, dir_name, type, new_flags, data)); +} + +long sys_fork(void) +{ + long ret; + + current->thread.forking = 1; + ret = do_fork(SIGCHLD, 0, NULL, 0); + current->thread.forking = 0; + return(ret); +} + +long sys_clone(unsigned long clone_flags, unsigned long newsp) +{ + long ret; + + current->thread.forking = 1; + ret = do_fork(clone_flags, newsp, NULL, 0); + current->thread.forking = 0; + return(ret); +} + +long sys_vfork(void) +{ + long ret; + + current->thread.forking = 1; + ret = do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, 0, NULL, 0); + current->thread.forking = 0; + return(ret); +} + +/* common code for old and new mmaps */ +static inline long do_mmap2( + unsigned long addr, unsigned long len, + unsigned long prot, unsigned long flags, + unsigned long fd, unsigned long pgoff) +{ + int error = -EBADF; + struct file * file = NULL; + + flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); + if (!(flags & MAP_ANONYMOUS)) { + file = fget(fd); + if (!file) + goto out; + } + + down_write(¤t->mm->mmap_sem); + error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); + up_write(¤t->mm->mmap_sem); + + if (file) + fput(file); + out: + return error; +} + +long sys_mmap2(unsigned long addr, unsigned long len, + unsigned long prot, unsigned long flags, + unsigned long fd, unsigned long pgoff) +{ + return do_mmap2(addr, len, prot, flags, fd, pgoff); +} + +/* + * Perform the select(nd, in, out, ex, tv) and mmap() system + * calls. Linux/i386 didn't use to be able to handle more than + * 4 system call parameters, so these system calls used a memory + * block for parameter passing.. + */ + +struct mmap_arg_struct { + unsigned long addr; + unsigned long len; + unsigned long prot; + unsigned long flags; + unsigned long fd; + unsigned long offset; +}; + +int old_mmap(unsigned long addr, unsigned long len, + unsigned long prot, unsigned long flags, + unsigned long fd, unsigned long offset) +{ + int err = -EINVAL; + if (offset & ~PAGE_MASK) + goto out; + + err = do_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT); + out: + return err; +} +/* + * sys_pipe() is the normal C calling standard for creating + * a pipe. It's not the way unix traditionally does this, though. + */ +int sys_pipe(unsigned long * fildes) +{ + int fd[2]; + int error; + + error = do_pipe(fd); + if (!error) { + if (copy_to_user(fildes, fd, 2*sizeof(int))) + error = -EFAULT; + } + return error; +} + +int sys_pause(void) +{ + current->state = TASK_INTERRUPTIBLE; + schedule(); + return -ERESTARTNOHAND; +} + +int sys_sigaction(int sig, const struct old_sigaction *act, + struct old_sigaction *oact) +{ + struct k_sigaction new_ka, old_ka; + int ret; + + if (act) { + old_sigset_t mask; + if (verify_area(VERIFY_READ, act, sizeof(*act)) || + __get_user(new_ka.sa.sa_handler, &act->sa_handler) || + __get_user(new_ka.sa.sa_restorer, &act->sa_restorer)) + return -EFAULT; + __get_user(new_ka.sa.sa_flags, &act->sa_flags); + __get_user(mask, &act->sa_mask); + siginitset(&new_ka.sa.sa_mask, mask); + } + + ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL); + + if (!ret && oact) { + if (verify_area(VERIFY_WRITE, oact, sizeof(*oact)) || + __put_user(old_ka.sa.sa_handler, &oact->sa_handler) || + __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer)) + return -EFAULT; + __put_user(old_ka.sa.sa_flags, &oact->sa_flags); + __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask); + } + + return ret; +} + +/* + * sys_ipc() is the de-multiplexer for the SysV IPC calls.. + * + * This is really horribly ugly. + */ +int sys_ipc (uint call, int first, int second, + int third, void *ptr, long fifth) +{ + int version, ret; + + version = call >> 16; /* hack for backward compatibility */ + call &= 0xffff; + + switch (call) { + case SEMOP: + return sys_semop (first, (struct sembuf *)ptr, second); + case SEMGET: + return sys_semget (first, second, third); + case SEMCTL: { + union semun fourth; + if (!ptr) + return -EINVAL; + if (get_user(fourth.__pad, (void **) ptr)) + return -EFAULT; + return sys_semctl (first, second, third, fourth); + } + + case MSGSND: + return sys_msgsnd (first, (struct msgbuf *) ptr, + second, third); + case MSGRCV: + switch (version) { + case 0: { + struct ipc_kludge tmp; + if (!ptr) + return -EINVAL; + + if (copy_from_user(&tmp, + (struct ipc_kludge *) ptr, + sizeof (tmp))) + return -EFAULT; + return sys_msgrcv (first, tmp.msgp, second, + tmp.msgtyp, third); + } + default: + panic("msgrcv with version != 0"); + return sys_msgrcv (first, + (struct msgbuf *) ptr, + second, fifth, third); + } + case MSGGET: + return sys_msgget ((key_t) first, second); + case MSGCTL: + return sys_msgctl (first, second, (struct msqid_ds *) ptr); + + case SHMAT: + switch (version) { + default: { + ulong raddr; + ret = sys_shmat (first, (char *) ptr, second, &raddr); + if (ret) + return ret; + return put_user (raddr, (ulong *) third); + } + case 1: /* iBCS2 emulator entry point */ + if (!segment_eq(get_fs(), get_ds())) + return -EINVAL; + return sys_shmat (first, (char *) ptr, second, (ulong *) third); + } + case SHMDT: + return sys_shmdt ((char *)ptr); + case SHMGET: + return sys_shmget (first, second, third); + case SHMCTL: + return sys_shmctl (first, second, + (struct shmid_ds *) ptr); + default: + return -EINVAL; + } +} + +int sys_uname(struct old_utsname * name) +{ + int err; + if (!name) + return -EFAULT; + down_read(&uts_sem); + err=copy_to_user(name, &system_utsname, sizeof (*name)); + up_read(&uts_sem); + return err?-EFAULT:0; +} + +int sys_olduname(struct oldold_utsname * name) +{ + int error; + + if (!name) + return -EFAULT; + if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname))) + return -EFAULT; + + down_read(&uts_sem); + + error = __copy_to_user(&name->sysname,&system_utsname.sysname, + __OLD_UTS_LEN); + error |= __put_user(0,name->sysname+__OLD_UTS_LEN); + error |= __copy_to_user(&name->nodename,&system_utsname.nodename, + __OLD_UTS_LEN); + error |= __put_user(0,name->nodename+__OLD_UTS_LEN); + error |= __copy_to_user(&name->release,&system_utsname.release, + __OLD_UTS_LEN); + error |= __put_user(0,name->release+__OLD_UTS_LEN); + error |= __copy_to_user(&name->version,&system_utsname.version, + __OLD_UTS_LEN); + error |= __put_user(0,name->version+__OLD_UTS_LEN); + error |= __copy_to_user(&name->machine,&system_utsname.machine, + __OLD_UTS_LEN); + error |= __put_user(0,name->machine+__OLD_UTS_LEN); + + up_read(&uts_sem); + + error = error ? -EFAULT : 0; + + return error; +} + +int sys_sigaltstack(const stack_t *uss, stack_t *uoss) +{ + return(do_sigaltstack(uss, uoss, + UM_SP(¤t->thread.process_regs))); +} + +static int check_readlink(struct sys_pt_regs *regs) +{ + return(verify_area(VERIFY_WRITE, (void *) UM_SYSCALL_ARG2(regs), + UM_SYSCALL_ARG3(regs))); +} + +static int check_utime(struct sys_pt_regs *regs) +{ + return(verify_area(VERIFY_WRITE, (void *) UM_SYSCALL_ARG2(regs), + sizeof(struct utimbuf))); +} + +static int check_oldstat(struct sys_pt_regs *regs) +{ + return(verify_area(VERIFY_WRITE, (void *) UM_SYSCALL_ARG2(regs), + sizeof(struct __old_kernel_stat))); +} + +static int check_stat(struct sys_pt_regs *regs) +{ + return(verify_area(VERIFY_WRITE, (void *) UM_SYSCALL_ARG2(regs), + sizeof(struct stat))); +} + +static int check_stat64(struct sys_pt_regs *regs) +{ + return(verify_area(VERIFY_WRITE, (void *) UM_SYSCALL_ARG2(regs), + sizeof(struct stat64))); +} + +struct bogus { + int kernel_ds; + int (*check_params)(struct sys_pt_regs *); +}; + +struct bogus this_is_bogus[] = { + [ __NR_mknod ] = { 1, NULL }, + [ __NR_mkdir ] = { 1, NULL }, + [ __NR_rmdir ] = { 1, NULL }, + [ __NR_unlink ] = { 1, NULL }, + [ __NR_symlink ] = { 1, NULL }, + [ __NR_link ] = { 1, NULL }, + [ __NR_rename ] = { 1, NULL }, + [ __NR_umount ] = { 1, NULL }, + [ __NR_mount ] = { 1, NULL }, + [ __NR_pivot_root ] = { 1, NULL }, + [ __NR_chdir ] = { 1, NULL }, + [ __NR_chroot ] = { 1, NULL }, + [ __NR_open ] = { 1, NULL }, + [ __NR_quotactl ] = { 1, NULL }, + [ __NR_sysfs ] = { 1, NULL }, + [ __NR_readlink ] = { 1, check_readlink }, + [ __NR_acct ] = { 1, NULL }, + [ __NR_execve ] = { 1, NULL }, + [ __NR_uselib ] = { 1, NULL }, + [ __NR_statfs ] = { 1, NULL }, + [ __NR_truncate ] = { 1, NULL }, + [ __NR_access ] = { 1, NULL }, + [ __NR_chmod ] = { 1, NULL }, + [ __NR_chown ] = { 1, NULL }, + [ __NR_lchown ] = { 1, NULL }, + [ __NR_utime ] = { 1, check_utime }, + [ __NR_oldlstat ] = { 1, check_oldstat }, + [ __NR_oldstat ] = { 1, check_oldstat }, + [ __NR_stat ] = { 1, check_stat }, + [ __NR_lstat ] = { 1, check_stat }, + [ __NR_stat64 ] = { 1, check_stat64 }, + [ __NR_lstat64 ] = { 1, check_stat64 }, +}; + +/* sys_utimes */ + +static int check_bogosity(struct sys_pt_regs *regs) +{ + struct bogus *bogon = &this_is_bogus[UM_SYSCALL_NR(regs)]; + + if(!bogon->kernel_ds) return(0); + if(bogon->check_params && (*bogon->check_params)(regs)) + return(-EFAULT); + set_fs(KERNEL_DS); + return(0); +} + +int nsyscalls = 0; + +extern syscall_handler_t *sys_call_table[]; + +long execute_syscall(struct sys_pt_regs regs) +{ + long res; + int syscall; + + current->thread.nsyscalls++; + nsyscalls++; + syscall = UM_SYSCALL_NR(®s); + + if((syscall >= NR_syscalls) || (syscall < 0)) + res = -ENOSYS; + else if(honeypot && check_bogosity(®s)) + res = -EFAULT; + else res = EXECUTE_SYSCALL(syscall, regs); + UM_SET_SYSCALL_RETURN(¤t->thread.process_regs, res); + + set_fs(USER_DS); + + return(res); +} + +spinlock_t syscall_lock = SPIN_LOCK_UNLOCKED; + +void lock_syscall(void) +{ + spin_lock(&syscall_lock); +} + +void unlock_syscall(void) +{ + spin_unlock(&syscall_lock); +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/kernel/syscall_user.c linux_umopenmosix/arch/um/kernel/syscall_user.c --- linux-2.4.17/arch/um/kernel/syscall_user.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/kernel/syscall_user.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,137 @@ +/* + * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +/* XXX FIXME : Ensure that SIGIO and SIGVTALRM can't happen immediately + * after setting up syscall stack + * block SIGVTALRM in any code that's under wait_for_stop + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "user_util.h" +#include "kern_util.h" +#include "user.h" +#include "signal_kern.h" +#include "signal_user.h" +#include "frame.h" +#include "sigcontext.h" +#include "sysdep/ptrace.h" + +/* XXX Bogus */ +#define ERESTARTSYS 512 +#define ERESTARTNOINTR 513 +#define ERESTARTNOHAND 514 + +struct { + int syscall; + int pid; + int result; + struct timeval start; + struct timeval end; +} syscall_record[1024]; + +int syscall_index = 0; + +extern int timer_ready, timer_on; + +void syscall_handler(int sig, struct sigcontext sc) +{ + struct sys_pt_regs *regs; + long result; + int index, syscall; + + unprotect_kernel_mem(1); + timer_ready = 1; + lock_syscall(); + if(syscall_index == 1024) syscall_index = 0; + index = syscall_index; + syscall_index++; + unlock_syscall(); + regs = process_state(NULL); + syscall = UM_SYSCALL_NR(regs); + set_thread_sc(&sc); + fill_in_regs(regs, &sc); + UM_ORIG_SYSCALL(regs) = -ENOSYS; + syscall_record[index].syscall = syscall; + syscall_record[index].pid = current_pid(); + syscall_record[index].result = 0xdeadbeef; + gettimeofday(&syscall_record[index].start, NULL); + syscall_trace(); + result = execute_syscall(*regs); + if((result == -ERESTARTNOHAND) || (result == -ERESTARTSYS) || + (result == -ERESTARTNOINTR)) + do_signal(result); + syscall_trace(); + syscall_record[index].result = result; + gettimeofday(&syscall_record[index].end, NULL); + ret_from_sys_call(); + + block_signals(); + change_sig(SIGUSR1, 0); + + timer_ready = 0; + set_user_mode(NULL, 1, 1); + timer_on = 1; +} + +int exit_kernel(int pid, void *task) +{ + struct sys_pt_regs *regs; + + if(!get_restore_state(task)) return(1); + regs = process_state(task); + if(ptrace_setregs(pid, regs) < 0) + tracer_panic("Couldn't restore registers"); + return(1); +} + +int do_syscall(void *task, int pid) +{ + struct sys_pt_regs *regs, proc_regs; + int syscall; + + if(ptrace_getregs(pid, &proc_regs) < 0) + tracer_panic("Couldn't read registers"); + + syscall = UM_SYSCALL_NR(&proc_regs); + if(syscall < 1) return(0); + + regs = process_state(task); + UM_SYSCALL_NR(regs) = syscall; + + if((syscall != __NR_sigreturn) && + ((unsigned long *) UM_IP(&proc_regs) >= &_stext) && + ((unsigned long *) UM_IP(&proc_regs) <= &_etext)) + tracer_panic("I'm tracing myself and I can't get out"); + + if(ptrace(PTRACE_POKEUSER, pid, UM_SYSCALL_NR_OFFSET, + __NR_getpid) < 0) + tracer_panic("do_syscall : Nullifying syscall failed, " + "errno = %d", errno); + return(1); +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/kernel/sysrq.c linux_umopenmosix/arch/um/kernel/sysrq.c --- linux-2.4.17/arch/um/kernel/sysrq.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/kernel/sysrq.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2001 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include "linux/sched.h" +#include "linux/kernel.h" +#include "linux/module.h" +#include "asm/page.h" +#include "asm/processor.h" +#include "sysrq.h" +#include "user_util.h" + + /* + * If the address is either in the .text section of the + * kernel, or in the vmalloc'ed module regions, it *may* + * be the address of a calling routine + */ + +#ifdef CONFIG_MODULES + +extern struct module *module_list; +extern struct module kernel_module; + +static inline int kernel_text_address(unsigned long addr) +{ + int retval = 0; + struct module *mod; + + if (addr >= (unsigned long) &_stext && + addr <= (unsigned long) &_etext) + return 1; + + for (mod = module_list; mod != &kernel_module; mod = mod->next) { + /* mod_bound tests for addr being inside the vmalloc'ed + * module area. Of course it'd be better to test only + * for the .text subset... */ + if (mod_bound(addr, 0, mod)) { + retval = 1; + break; + } + } + + return retval; +} + +#else + +static inline int kernel_text_address(unsigned long addr) +{ + return (addr >= (unsigned long) &_stext && + addr <= (unsigned long) &_etext); +} + +#endif + +void show_trace(unsigned long * stack) +{ + int i; + unsigned long addr; + + if (!stack) + stack = (unsigned long*) &stack; + + printk("Call Trace: "); + i = 1; + while (((long) stack & (THREAD_SIZE-1)) != 0) { + addr = *stack++; + if (kernel_text_address(addr)) { + if (i && ((i % 6) == 0)) + printk("\n "); + printk("[<%08lx>] ", addr); + i++; + } + } + printk("\n"); +} + +void show_trace_task(struct task_struct *tsk) +{ + unsigned long esp = UM_SP(&tsk->thread.process_regs); + + /* User space on another CPU? */ + if ((esp ^ (unsigned long)tsk) & (PAGE_MASK<<1)) + return; + show_trace((unsigned long *)esp); +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/kernel/time.c linux_umopenmosix/arch/um/kernel/time.c --- linux-2.4.17/arch/um/kernel/time.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/kernel/time.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,120 @@ +/* + * Copyright (C) 2000, 2001 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#define _GNU_SOURCE /* to get timeradd and timersub */ + +#include +#include +#include +#include +#include +#include +#include "user_util.h" +#include "kern_util.h" +#include "user.h" +#include "process.h" +#include "signal_user.h" + +extern struct timeval xtime; + +void timer_handler(int sig, void *sc, int usermode) +{ + timer_irq(usermode); +} + +void timer(void) +{ + gettimeofday(&xtime, NULL); +} + +static struct itimerval profile_interval; + +void get_profile_timer(void) +{ + getitimer(ITIMER_PROF, &profile_interval); + profile_interval.it_value = profile_interval.it_interval; +} + +void disable_profile_timer(void) +{ + struct itimerval interval = ((struct itimerval) { { 0, 0 }, { 0, 0 }}); + setitimer(ITIMER_PROF, &interval, NULL); +} + +static void set_interval(int timer_type) +{ + struct itimerval interval; + + interval.it_interval.tv_sec = 0; + interval.it_interval.tv_usec = 1000000/hz(); + interval.it_value.tv_sec = 0; + interval.it_value.tv_usec = 1000000/hz(); + if(setitimer(timer_type, &interval, NULL) == -1) + panic("setitimer failed - errno = %d\n", errno); +} + +void idle_timer(void) +{ + if(signal(SIGVTALRM, SIG_IGN) == SIG_ERR) + panic("Couldn't unset SIGVTALRM handler"); + set_handler(SIGALRM, (__sighandler_t) alarm_handler, + SA_NODEFER | SA_RESTART, SIGUSR1, SIGIO, SIGWINCH, -1); + set_interval(ITIMER_REAL); +} + +void time_init(void) +{ + if(signal(SIGVTALRM, boot_timer_handler) == SIG_ERR) + panic("Couldn't set SIGVTALRM handler"); + set_interval(ITIMER_VIRTUAL); +} + +void set_timers(int set_signal) +{ + if(set_signal){ + if(signal(SIGVTALRM, + (__sighandler_t) alarm_handler) == SIG_ERR) + panic("Couldn't set SIGVTALRM handler"); + set_interval(ITIMER_VIRTUAL); + } + if(setitimer(ITIMER_PROF, &profile_interval, NULL) == -1) + panic("setitimer ITIMER_PROF failed - errno = %d\n", errno); +} + +struct timeval local_offset = { 0, 0 }; + +void do_gettimeofday(struct timeval *tv) +{ + gettimeofday(tv, NULL); + timeradd(tv, &local_offset, tv); +} + +void do_settimeofday(struct timeval *tv) +{ + struct timeval now; + + gettimeofday(&now, NULL); + timersub(tv, &now, &local_offset); +} + +void idle_sleep(int secs) +{ + struct timespec ts; + + ts.tv_sec = secs; + ts.tv_nsec = 0; + nanosleep(&ts, &ts); +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/kernel/time_kern.c linux_umopenmosix/arch/um/kernel/time_kern.c --- linux-2.4.17/arch/um/kernel/time_kern.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/kernel/time_kern.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,141 @@ +/* + * Copyright (C) 2000 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include "linux/kernel.h" +#include "linux/unistd.h" +#include "linux/stddef.h" +#include "linux/spinlock.h" +#include "linux/sched.h" +#include "linux/interrupt.h" +#include "linux/init.h" +#include "linux/delay.h" +#include "asm/param.h" +#include "asm/current.h" +#include "kern_util.h" +#include "user_util.h" + +extern rwlock_t xtime_lock; + +int hz(void) +{ + return(HZ); +} + +int timer_irq_inited = 0; + +/* timer_on and missed_ticks are modified after kernel memory has been + * write-protected, so this puts it in a section which will be left + * write-enabled. + */ +int __attribute__ ((__section__ (".unprotected"))) timer_on = 0; +int __attribute__ ((__section__ (".unprotected"))) missed_ticks = 0; + +int timer_ready = 0; + +void timer_irq(int user_mode) +{ + int ticks = missed_ticks; + + if(!timer_irq_inited) return; + missed_ticks = 0; + while(ticks--) do_IRQ(TIMER_IRQ, user_mode); +} + +void boot_timer_handler(int sig) +{ + struct pt_regs regs; + + regs.user_mode = 0; + do_timer(®s); +} + +void um_timer(int irq, void *dev, struct pt_regs *regs) +{ + do_timer(regs); + write_lock(&xtime_lock); + timer(); + write_unlock(&xtime_lock); +} + +long um_time(int * tloc) +{ + struct timeval now; + + do_gettimeofday(&now); + if (tloc) { + if (put_user(now.tv_sec,tloc)) + now.tv_sec = -EFAULT; + } + return now.tv_sec; +} + +long um_stime(int * tptr) +{ + int value; + struct timeval new; + + if (get_user(value, tptr)) + return -EFAULT; + new.tv_sec = value; + new.tv_usec = 0; + do_settimeofday(&new); + return 0; +} + +void __delay(um_udelay_t time) +{ + /* Stolen from the i386 __loop_delay */ + int d0; + __asm__ __volatile__( + "\tjmp 1f\n" + ".align 16\n" + "1:\tjmp 2f\n" + ".align 16\n" + "2:\tdecl %0\n\tjns 2b" + :"=&a" (d0) + :"0" (time)); +} + +void __udelay(um_udelay_t usecs) +{ + int i, n; + + n = (loops_per_jiffy * HZ * usecs) / 1000000; + for(i=0;ithread.extern_pid != -1) && + (current->thread.extern_pid != getpid())) + panic("fix_range fixing wrong address space, current = 0x%p", + current); + if(mm == NULL) return; + for(addr=start_addr;addr TASK_SIZE, which is + * only true in the honeypot case. + */ + addr = STACK_TOP - ABOVE_KMEM; + continue; + } + npgd = pgd_offset(mm, addr); + npmd = pmd_offset(npgd, addr); + if(pmd_present(*npmd)){ + npte = pte_offset(npmd, addr); + r = pte_read(*npte); + w = pte_write(*npte); + x = pte_exec(*npte); + if(!pte_dirty(*npte)) w = 0; + if(!pte_young(*npte)){ + r = 0; + w = 0; + } + if(force || pte_newpage(*npte)){ + if(munmap((void *) addr, PAGE_SIZE) < 0) + panic("munmap failed, errno = %d\n", + errno); + if(pte_present(*npte)) + map(addr, pte_address(*npte), + PAGE_SIZE, r, w, x); + } + else if(pte_newprot(*npte)) + protect(addr, PAGE_SIZE, r, w, x, 1); + *npte = pte_mkuptodate(*npte); + addr += PAGE_SIZE; + } + else { + if(force || pmd_newpage(*npmd)){ + if(munmap((void *) addr, PMD_SIZE) < 0) + panic("munmap failed, errno = %d\n", + errno); + } + addr += PMD_SIZE; + } + } +} + +atomic_t vmchange_seq = ATOMIC_INIT(1); + +static void flush_kernel_vm_range(unsigned long start, unsigned long end, + int update_seq) +{ + struct mm_struct *mm; + pgd_t *pgd; + pmd_t *pmd; + pte_t *pte; + unsigned long addr; + int updated = 0; + + mm = &init_mm; + for(addr = start_vm; addr < end_vm;){ + pgd = pgd_offset(mm, addr); + pmd = pmd_offset(pgd, addr); + if(pmd_present(*pmd)){ + pte = pte_offset(pmd, addr); + if(!pte_present(*pte) || pte_newpage(*pte)){ + updated = 1; + if(munmap((void *) addr, PAGE_SIZE) < 0) + panic("munmap failed, errno = %d\n", + errno); + if(pte_present(*pte)) + map(addr, pte_address(*pte), + PAGE_SIZE, 1, 1, 1); + } + else if(pte_newprot(*pte)){ + updated = 1; + protect(addr, PAGE_SIZE, 1, 1, 1, 1); + } + addr += PAGE_SIZE; + + } + else { + if(pmd_newpage(*pmd)){ + updated = 1; + if(munmap((void *) addr, PMD_SIZE) < 0) + panic("munmap failed, errno = %d\n", + errno); + } + addr += PMD_SIZE; + } + } + if(updated && update_seq) atomic_inc(&vmchange_seq); +} + +static void protect_vm_page(unsigned long addr, int w, int must_succeed) +{ + int err; + + err = protect(addr, PAGE_SIZE, 1, w, 1, must_succeed); + if(err == 0) return; + else if(err == -EFAULT){ + flush_kernel_vm_range(addr, addr + PAGE_SIZE, 1); + protect_vm_page(addr, w, 1); + } + else panic("protect_vm_page : protect failed, errno = %d\n", err); +} + +void mprotect_kernel_vm(int w) +{ + struct mm_struct *mm; + pgd_t *pgd; + pmd_t *pmd; + pte_t *pte; + unsigned long addr; + + mm = &init_mm; + for(addr = start_vm; addr < end_vm;){ + pgd = pgd_offset(mm, addr); + pmd = pmd_offset(pgd, addr); + if(pmd_present(*pmd)){ + pte = pte_offset(pmd, addr); + if(pte_present(*pte)) protect_vm_page(addr, w, 0); + addr += PAGE_SIZE; + } + else addr += PMD_SIZE; + } +} + +void flush_tlb_kernel_vm(void) +{ + flush_kernel_vm_range(start_vm, end_vm, 1); +} + +void flush_tlb_range(struct mm_struct *mm, unsigned long start, + unsigned long end) +{ + if(mm != current->mm) return; + + /* Assumes that the range start ... end is entirely within + * either process memory or kernel vm + */ + if((start >= start_vm) && (start < end_vm)) + flush_kernel_vm_range(start, end, 1); + else fix_range(mm, start, end, 0); +} + +void flush_tlb_mm(struct mm_struct *mm) +{ + unsigned long seq; + + if(mm != current->mm) return; + + fix_range(mm, 0, STACK_TOP, 0); + + seq = atomic_read(&vmchange_seq); + if(current->thread.vm_seq == seq) return; + current->thread.vm_seq = seq; + flush_kernel_vm_range(start_vm, end_vm, 0); +} + +void flush_tlb_page(struct vm_area_struct *vma, unsigned long address) +{ + address &= PAGE_MASK; + flush_tlb_range(vma->vm_mm, address, address + PAGE_SIZE); +} + +void flush_tlb_all(void) +{ + flush_tlb_mm(current->mm); +} + +void force_flush_all(void) +{ + fix_range(current->mm, 0, STACK_TOP, 1); + flush_kernel_vm_range(start_vm, end_vm, 0); +} + +pgd_t *pgd_offset_proc(struct mm_struct *mm, unsigned long address) +{ + return(pgd_offset(mm, address)); +} + +pmd_t *pmd_offset_proc(pgd_t *pgd, unsigned long address) +{ + return(pmd_offset(pgd, address)); +} + +pte_t *pte_offset_proc(pmd_t *pmd, unsigned long address) +{ + return(pte_offset(pmd, address)); +} + +pte_t *addr_pte(struct task_struct *task, unsigned long addr) +{ + return(pte_offset(pmd_offset(pgd_offset(task->mm, addr), addr), addr)); +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/kernel/trap_kern.c linux_umopenmosix/arch/um/kernel/trap_kern.c --- linux-2.4.17/arch/um/kernel/trap_kern.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/kernel/trap_kern.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,376 @@ +/* + * Copyright (C) 2000, 2001 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include "linux/kernel.h" +#include "linux/sched.h" +#include "linux/mm.h" +#include "linux/spinlock.h" +#include "linux/config.h" +#include "linux/init.h" +#include "asm/semaphore.h" +#include "asm/pgtable.h" +#include "asm/pgalloc.h" +#include "asm/a.out.h" +#include "asm/current.h" +#include "user_util.h" +#include "kern_util.h" +#include "kern.h" +#include "chan_kern.h" +#include "debug.h" +#include "mconsole_kern.h" +#include "2_5compat.h" + +extern int nsyscalls; + +unsigned long segv(unsigned long address, unsigned long ip, int is_write, + int is_user) +{ + struct mm_struct *mm = current->mm; + struct vm_area_struct *vma; + struct siginfo si; + pgd_t *pgd; + pmd_t *pmd; + pte_t *pte; + unsigned long page; + + if((address >= start_vm) && (address < end_vm)){ + flush_tlb_kernel_vm(); + return(0); + } + if(mm == NULL) panic("Segfault with no mm"); + si.si_code = SEGV_MAPERR; + down_read(&mm->mmap_sem); + vma = find_vma(mm, address); + if(!vma) goto bad; + else if(vma->vm_start <= address) goto good_area; + else if(!(vma->vm_flags & VM_GROWSDOWN)) goto bad; + else if(expand_stack(vma, address)) goto bad; + + good_area: + si.si_code = SEGV_ACCERR; + if(is_write && !(vma->vm_flags & VM_WRITE)) goto bad; + page = address & PAGE_MASK; + if(page == (unsigned long) current + PAGE_SIZE) + panic("Kernel stack overflow"); + pgd = pgd_offset(mm, page); + pmd = pmd_offset(pgd, page); + do { + survive: + switch (handle_mm_fault(mm, vma, address, is_write)) { + case 1: + current->min_flt++; + break; + case 2: + current->maj_flt++; + break; + default: + if (current->pid == 1) { + up_read(&mm->mmap_sem); + yield(); + down_read(&mm->mmap_sem); + goto survive; + } + /* Fall through to bad area case */ + case 0: + goto bad; + } + pte = pte_offset(pmd, page); + } while(!pte_present(*pte)); + *pte = pte_mkyoung(*pte); + if(pte_write(*pte)) *pte = pte_mkdirty(*pte); + flush_tlb_page(vma, page); + up_read(&mm->mmap_sem); + return(0); + bad: + if (current->thread.fault_catcher != NULL) { + current->thread.fault_addr = (void *) address; + up_read(&mm->mmap_sem); + do_longjmp(current->thread.fault_catcher); + } + else if(current->thread.fault_addr != NULL){ + panic("fault_addr set but no fault catcher"); + } + if(!is_user) + panic("Kernel mode fault at addr 0x%lx, ip 0x%lx", + address, ip); + si.si_signo = SIGSEGV; + si.si_addr = (void *) address; + current->thread.cr2 = address; + current->thread.err = is_write; + force_sig_info(SIGSEGV, &si, current); + up_read(&mm->mmap_sem); + return(0); +} + +void bad_segv(unsigned long address, unsigned long ip, int is_write) +{ + struct siginfo si; + + printk(KERN_ERR "Unfixable SEGV in '%s' (pid %d) at 0x%lx " + "(ip 0x%lx)\n", current->comm, current->pid, address, ip); + si.si_signo = SIGSEGV; + si.si_code = SEGV_ACCERR; + si.si_addr = (void *) address; + current->thread.cr2 = address; + current->thread.err = is_write; + force_sig_info(SIGSEGV, &si, current); +} + +void relay_signal(int sig, void *sc, int usermode) +{ + force_sig(sig, current); +} + +void trap_init(void) +{ +} + +spinlock_t trap_lock = SPIN_LOCK_UNLOCKED; + +void lock_trap(void) +{ + spin_lock(&trap_lock); +} + +void unlock_trap(void) +{ + spin_unlock(&trap_lock); +} + +extern int debugger_pid; +extern int debugger_fd; + +#ifdef CONFIG_PT_PROXY + +int debugger_signal(int status, pid_t pid) +{ + return(debugger_proxy(status, pid)); +} + +void child_signal(pid_t pid, int status) +{ + child_proxy(pid, status); +} + +static void gdb_announce(char *dev_name, int dev) +{ + printf("gdb assigned device '%s'\n", dev_name); +} + +static struct chan_opts opts = { + announce : gdb_announce, + xterm_title : "UML kernel debugger", + raw : 0 +}; + +static void *xterm_data; +static int xterm_fd; + +extern void *xterm_init(char *, int, struct chan_opts *); +extern int xterm_open(int, int, void *); +extern void xterm_close(int, void *); + +int open_gdb_chan(void) +{ + xterm_data = xterm_init("", 0, &opts); + xterm_fd = xterm_open(1, 1, xterm_data); + return(xterm_fd); +} + +static void exit_debugger_cb(void *unused) +{ + if(debugger_pid != -1){ + if(gdb_pid != -1){ + fake_child_exit(); + gdb_pid = -1; + } + else kill_child_dead(debugger_pid); + debugger_pid = -1; + } + if(xterm_data != NULL) xterm_close(xterm_fd, xterm_data); +} + +static void exit_debugger(void) +{ + tracing_cb(exit_debugger_cb, NULL); +} + +__uml_exitcall(exit_debugger); + +struct gdb_data { + char *str; + int err; +}; + +static void config_gdb_cb(void *arg) +{ + struct gdb_data *data = arg; + struct task_struct *task; + int pid; + + data->err = -1; + if(debugger_pid != -1) exit_debugger_cb(NULL); + if(!strncmp(data->str, "pid,", strlen("pid,"))){ + data->str += strlen("pid,"); + pid = simple_strtoul(data->str, NULL, 0); + task = cpu_tasks[0].task; + debugger_pid = attach_debugger(task->thread.extern_pid, + pid, 0); + if(debugger_pid != -1){ + data->err = 0; + gdb_pid = pid; + } + return; + } + data->err = 0; + debugger_pid = start_debugger(linux_prog, 0, 0, &debugger_fd); + init_proxy(debugger_pid, 0, 0); +} + +int gdb_config(char *str) +{ + struct gdb_data data; + + if(*str++ != '=') return(-1); + data.str = str; + tracing_cb(config_gdb_cb, &data); + return(data.err); +} + +void remove_gdb_cb(void *unused) +{ + exit_debugger_cb(NULL); +} + +int gdb_remove(char *unused) +{ + tracing_cb(remove_gdb_cb, NULL); + return(0); +} + +#ifdef CONFIG_MCONSOLE + +static struct mc_device gdb_mc = { + name: "gdb", + config: gdb_config, + remove: gdb_remove, +}; + +int gdb_mc_init(void) +{ + mconsole_register_dev(&gdb_mc); + return(0); +} + +__initcall(gdb_mc_init); + +#endif + +void signal_usr1(int sig) +{ + if(debugger_pid != -1){ + printk(KERN_ERR "The debugger is already running\n"); + return; + } + debugger_pid = start_debugger(linux_prog, 0, 0, &debugger_fd); + init_proxy(debugger_pid, 0, 0); +} + +int init_ptrace_proxy(int idle_pid, int startup, int stop) +{ + int pid, status; + + pid = start_debugger(linux_prog, startup, stop, &debugger_fd); + status = wait_for_stop(idle_pid, SIGSTOP, PTRACE_CONT); + if(pid < 0){ + cont(idle_pid); + return(-1); + } + init_proxy(pid, 1, status); + return(pid); +} + +int attach_debugger(int idle_pid, int pid, int stop) +{ + int status = 0; + + if(attach(pid) < 0){ + printf("Failed to attach pid %d, errno = %d\n", pid, errno); + return(-1); + } + if(stop) status = wait_for_stop(idle_pid, SIGSTOP, PTRACE_CONT); + init_proxy(pid, 1, status); + return(pid); +} + +#ifdef notdef /* Put this back in when it does something useful */ +static int __init uml_gdb_init_setup(char *line, int *add) +{ + gdb_init = uml_strdup(line); + return 0; +} + +__uml_setup("gdb=", uml_gdb_init_setup, +"gdb=\n\n" +); +#endif + +static int __init uml_gdb_pid_setup(char *line, int *add) +{ + gdb_pid = simple_strtoul(line, NULL, 0); + return 0; +} + +__uml_setup("gdb-pid=", uml_gdb_pid_setup, +"gdb-pid=\n" +" gdb-pid is used to attach an external debugger to UML. This may be\n" +" an already-running gdb or a debugger-like process like strace.\n\n" +); + +#else + +int debugger_signal(int status, pid_t pid){ return(0); } +void child_signal(pid_t pid, int status){ } +int init_ptrace_proxy(int idle_pid, int startup, int stop) +{ + printk(KERN_ERR "debug requested when CONFIG_PT_PROXY is off\n"); + wait_for_stop(idle_pid, SIGSTOP, PTRACE_CONT); + cont(idle_pid); + return(-1); +} + +void signal_usr1(int sig) +{ + printk(KERN_ERR "debug requested when CONFIG_PT_PROXY is off\n"); +} + +int attach_debugger(int idle_pid, int pid, int stop) +{ + printk(KERN_ERR "attach_debugger called when CONFIG_PT_PROXY " + "is off\n"); + return(-1); +} + +int config_gdb(char *str) +{ + return(-1); +} + +int remove_gdb(void) +{ + return(-1); +} + +#endif +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/kernel/trap_user.c linux_umopenmosix/arch/um/kernel/trap_user.c --- linux-2.4.17/arch/um/kernel/trap_user.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/kernel/trap_user.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,537 @@ +/* + * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "user_util.h" +#include "kern_util.h" +#include "signal_user.h" +#include "mem_user.h" +#include "user.h" +#include "process.h" +#include "sigcontext.h" +#include "sysdep/sigcontext.h" +#include "init.h" +#include "chan_user.h" +#include "irq_user.h" +#include "frame.h" +#include "syscall_user.h" + +static void signal_segv(int sig) +{ + write(2, "Seg fault in signals\n", strlen("Seg fault in signals\n")); + for(;;) ; +} + +int detach(int pid, int sig) +{ + return(ptrace(PTRACE_DETACH, pid, 0, sig)); +} + +int attach(int pid) +{ + return(ptrace(PTRACE_ATTACH, pid, 0, 0)); +} + +int cont(int pid) +{ + return(ptrace(PTRACE_CONT, pid, 0, 0)); +} + +void kill_child_dead(int pid) +{ + kill(pid, SIGKILL); + kill(pid, SIGCONT); + while(waitpid(pid, NULL, 0) > 0) kill(pid, SIGCONT); +} + +int debug = 0; +int debug_stop = 1; + +int honeypot = 0; + +static int signal_tramp(void *arg) +{ + int (*proc)(void *); + + if(honeypot && munmap((void *) (host_task_size - 0x10000000), + 0x10000000)) + panic("Unmapping stack failed"); + if(ptrace(PTRACE_TRACEME, 0, 0, 0) < 0) + panic("ptrace PTRACE_TRACEME failed"); + kill(getpid(), SIGSTOP); + signal(SIGUSR1, SIG_IGN); + signal(SIGSEGV, (__sighandler_t) sig_handler); + set_timers(0); + set_cmdline("(idle thread)"); + set_init_pid(getpid()); + proc = arg; + return((*proc)(NULL)); +} + +static void last_ditch_exit(int sig) +{ + signal(SIGINT, SIG_DFL); + signal(SIGTERM, SIG_DFL); + signal(SIGHUP, SIG_DFL); + uml_cleanup(); + exit(1); +} + +static void sleeping_process_signal(int pid, int sig) +{ + switch(sig){ + /* These two result from UML being ^Z-ed and bg-ed. PTRACE_CONT is + * right because the process must be in the kernel already. + */ + case SIGCONT: + case SIGTSTP: + if(ptrace(PTRACE_CONT, pid, 0, sig) < 0) + tracer_panic("sleeping_process_signal : Failed to " + "continue pid %d, errno = %d\n", pid, + sig); + break; + + /* If an xterm changes size and the process handling SIGWINCH is + * asleep, its signal needs to be annulled and the SIGWINCH needs + * to be passed to the current running process. + * XXX if the current process is switching out, then the SIGWINCH + * might hit the wrong process. + */ + case SIGWINCH: + if(ptrace(PTRACE_CONT, pid, 0, 0) < 0) + tracer_panic("sleeping_process_signal : Failed to " + "annull SIGWINCH pid %d, errno = %d\n", + pid, sig); + kill(external_pid(cpu_tasks[0].task), SIGWINCH); + break; + + /* This happens when the debugger (e.g. strace) is doing system call + * tracing on the kernel. During a context switch, the current task + * will be set to the incoming process and the outgoing process will + * hop into write and then read. Since it's not the current process + * any more, the trace of those will land here. So, we need to just + * PTRACE_SYSCALL it. + */ + case SIGTRAP: + if(ptrace(PTRACE_SYSCALL, pid, 0, 0) < 0) + tracer_panic("sleeping_process_signal : Failed to " + "PTRACE_SYSCALL pid %d, errno = %d\n", + pid, sig); + break; + default: + tracer_panic("sleeping process %d got unexpected " + "signal : %d\n", sig); + break; + } +} + + +#ifdef CONFIG_SMP +#error need to make these arrays +#endif + +int debugger_pid = -1; +int debugger_fd = -1; +int gdb_pid = -1; + +struct { + unsigned long address; + int is_write; + int pid; + unsigned long sp; + int is_user; +} segfault_record[1024]; + +int segfault_index = 0; + +struct { + int pid; + int signal; + unsigned long addr; + struct timeval time; +} signal_record[1024]; + +int signal_index = 0; +int nsignals = 0; +int debug_trace = 0; +extern int io_nsignals, io_count, intr_count; + +extern void signal_usr1(int sig); + +int tracing_pid = -1; + +int signals(int (*init_proc)(void *), void *sp) +{ + void *task = NULL; + unsigned long eip = 0; + int status, pid = 0, sig, cont_type, tracing = 0, op = 0; + int last_index, proc_id, n, strace = 0; + + capture_signal_stack(); + signal(SIGPIPE, SIG_IGN); + tracing_pid = getpid(); + printk("tracing thread pid = %d\n", tracing_pid); + + pid = clone(signal_tramp, sp, CLONE_FILES | SIGCHLD, init_proc); + n = waitpid(pid, &status, WUNTRACED); + if(n < 0){ + printf("waitpid on idle thread failed, errno = %d\n", errno); + exit(1); + } + if((ptrace_getregs(pid, process_state(get_init_task())) < 0) || + (ptrace(PTRACE_CONT, pid, 0, 0) < 0)){ + printf("Failed to get idle thread registers or continue it, " + "errno = %d\n", errno); + exit(1); + } + if(ptrace(PTRACE_CONT, pid, 0, 0) < 0) + + signal(SIGSEGV, signal_segv); + signal(SIGUSR1, signal_usr1); + set_handler(SIGINT, last_ditch_exit, SA_ONESHOT | SA_NODEFER, -1); + set_handler(SIGTERM, last_ditch_exit, SA_ONESHOT | SA_NODEFER, -1); + set_handler(SIGHUP, last_ditch_exit, SA_ONESHOT | SA_NODEFER, -1); + if(debug){ + if(gdb_pid != -1) + debugger_pid = attach_debugger(pid, gdb_pid, 1); + else debugger_pid = init_ptrace_proxy(pid, 1, debug_stop); + } + set_cmdline("(tracing thread)"); + if(debug_trace){ + printk("Tracing thread pausing to be attached\n"); + stop(); + } + while(1){ + if((pid = waitpid(-1, &status, WUNTRACED)) <= 0){ + if(errno != ECHILD){ + printk("wait failed - errno = %d\n", errno); + } + continue; + } + if(pid == debugger_pid){ + int cont = 0; + + if(WIFEXITED(status) || WIFSIGNALED(status)) + debugger_pid = -1; + /* XXX Figure out how to deal with gdb and SMP */ + else cont = debugger_signal(status, cpu_tasks[0].pid); + if(cont == PTRACE_SYSCALL) strace = 1; + continue; + } + nsignals++; + if(WIFEXITED(status)) ; +#ifdef notdef + { + printk("Child %d exited with status %d\n", pid, + WEXITSTATUS(status)); + } +#endif + else if(WIFSIGNALED(status)){ + sig = WTERMSIG(status); + if(sig != 9){ + printk("Child %d exited with signal %d\n", pid, + sig); + } + } + else if(WIFSTOPPED(status)){ + sig = WSTOPSIG(status); + if(signal_index == 1024){ + signal_index = 0; + last_index = 1023; + } + else last_index = signal_index - 1; + if(((sig == SIGPROF) || (sig == SIGVTALRM) || + (sig == SIGALRM)) && + (signal_record[last_index].signal == sig) && + (signal_record[last_index].pid == pid)) + signal_index = last_index; + signal_record[signal_index].pid = pid; + gettimeofday(&signal_record[signal_index].time, NULL); + eip = ptrace(PTRACE_PEEKUSER, pid, UM_IP_OFFSET, 0); + signal_record[signal_index].addr = eip; + signal_record[signal_index++].signal = sig; + + proc_id = pid_to_processor_id(pid); + if(proc_id == -1){ + sleeping_process_signal(pid, sig); + continue; + } + + task = cpu_tasks[proc_id].task; + tracing = is_tracing(task); + + switch(sig){ + case SIGUSR1: + sig = 0; + op = do_proc_op(task, proc_id); + switch(op){ + case OP_TRACE_ON: + tracing = exit_kernel(pid, task); + break; + case OP_REBOOT: + case OP_HALT: + kmalloc_ok = 0; + ptrace(PTRACE_KILL, pid, 0, 0); + return(op == OP_REBOOT); + case OP_NONE: + printk("Detaching pid %d\n", pid); + detach(pid, SIGSTOP); + continue; + default: + break; + } + /* OP_EXEC switches host processes on us, + * we want to continue the new one. + */ + pid = cpu_tasks[proc_id].pid; + break; + case SIGTRAP: + if(!tracing && (debugger_pid != -1)){ + child_signal(pid, status); + continue; + } + tracing = 0; + if(do_syscall(task, pid)) sig = SIGUSR2; + break; + case SIGPROF: + if(tracing) sig = 0; + break; + case SIGCHLD: + case SIGHUP: + sig = 0; + break; + case SIGSEGV: + case SIGIO: + case SIGALRM: + case SIGVTALRM: + case SIGFPE: + case SIGBUS: + case SIGILL: + case SIGWINCH: + default: + tracing = 0; + break; + } + set_tracing(task, tracing); + + if(!tracing && (debugger_pid != -1) && (sig != 0) && + (sig != SIGALRM) && (sig != SIGVTALRM) && + (sig != SIGSEGV) && (sig != SIGTRAP) && + (sig != SIGUSR2)){ + child_signal(pid, status); + continue; + } + + if(tracing){ + if(singlestepping(task)) + cont_type = PTRACE_SINGLESTEP; + else cont_type = PTRACE_SYSCALL; + } + else cont_type = PTRACE_CONT; + + if((cont_type == PTRACE_CONT) && + (debugger_pid != -1) && strace) + cont_type = PTRACE_SYSCALL; + + if(ptrace(cont_type, pid, 0, sig) != 0){ + tracer_panic("ptrace failed to continue " + "process - errno = %d\n", + errno); + } + } + } + return(0); +} + +static int __init uml_debugtrace_setup(char *line, int *add) +{ + debug_trace = 1; + return 0; +} +__uml_setup("debugtrace=", uml_debugtrace_setup, +"debugtrace\n" +" Causes the tracing thread to pause until it is attached by a\n" +" debugger and continued. This is mostly for debugging crashes\n" +" early during boot, and should be pretty much obsoleted by\n" +" the debug switch.\n\n" +); + +static int __init uml_honeypot_setup(char *line, int *add) +{ + jail_setup("", add); + honeypot = 1; + return 0; +} +__uml_setup("honeypot", uml_honeypot_setup, +"honeypot\n" +" This makes UML put process stacks in the same location as they are\n" +" on the host, allowing expoits such as stack smashes to work against\n" +" UML. This implies 'jail'.\n\n" +); + +int nsegfaults = 0; + +void segv_handler(int sig, void *sc, int usermode) +{ + struct sigcontext_struct *context = sc; + int index; + + if(usermode && !SEGV_IS_FIXABLE(context)){ + bad_segv(SC_FAULT_ADDR(context), SC_IP(context), + SC_FAULT_WRITE(context)); + return; + } + lock_trap(); + index = segfault_index++; + if(segfault_index == 1024) segfault_index = 0; + unlock_trap(); + nsegfaults++; + segfault_record[index].address = SC_FAULT_ADDR(context); + segfault_record[index].pid = getpid(); + segfault_record[index].is_write = SC_FAULT_WRITE(context); + segfault_record[index].sp = SC_SP(context); + segfault_record[index].is_user = usermode; + segv(SC_FAULT_ADDR(context), SC_IP(context), SC_FAULT_WRITE(context), + usermode); +} + +static void winch_handler(int sig, void *sc, int usermode) +{ + run_winch_handlers(); +} + +extern int timer_ready, timer_on; + +static void (*handlers[])(int, void *, int) = { + [ SIGTRAP ] relay_signal, + [ SIGFPE ] relay_signal, + [ SIGILL ] relay_signal, + [ SIGBUS ] relay_signal, + [ SIGSEGV] segv_handler, + [ SIGIO ] sigio_handler, + [ SIGVTALRM ] timer_handler, + [ SIGALRM ] timer_handler, + [ SIGWINCH ] winch_handler, +}; + +void irq_handler_common(int sig, struct sigcontext *sc) +{ + int user, save_errno = errno, save_timer = timer_on; + + user = user_context(SC_SP(sc)); + unprotect_kernel_mem(0); + timer_on = 0; + if(user){ + set_thread_sc(sc); + fill_in_regs(process_state(NULL), sc); + timer_ready = 1; + } + change_sig(SIGUSR1, 1); + (*handlers[sig])(sig, sc, user); + if(user) interrupt_end(); + block_signals(); + change_sig(SIGUSR1, 0); + if(user) set_user_mode(NULL, 1, 0); + errno = save_errno; + if(user) timer_ready = 0; + timer_on = save_timer; + if(user) protect_kernel_mem(0); +} + +void irq_handler(int sig, struct sigcontext sc) +{ + irq_handler_common(sig, &sc); +} + +void sig_handler(int sig, struct sigcontext sc) +{ + int user, save_errno = errno, save_timer = timer_on; + + user = user_context(SC_SP(&sc)); + unprotect_kernel_mem(0); + timer_on = 0; + if(user){ + set_thread_sc(&sc); + fill_in_regs(process_state(NULL), &sc); + timer_ready = 1; + } + change_sig(SIGUSR1, 1); + unblock_signals(); + (*handlers[sig])(sig, &sc, user); + if(user) interrupt_end(); + block_signals(); + change_sig(SIGUSR1, 0); + if(user) set_user_mode(NULL, 1, 0); + errno = save_errno; + if(user) timer_ready = 0; + timer_on = save_timer; + if(user) protect_kernel_mem(0); +} + +extern int timer_irq_inited, missed_ticks; + +void alarm_handler(int sig, struct sigcontext sc) +{ + int user; + + if(!timer_irq_inited) return; + missed_ticks++; + user = user_context(SC_SP(&sc)); + if(!user && !timer_ready) return; + if(!timer_on) return; + irq_handler_common(sig, &sc); + timer_ready = 1; +} + +void do_longjmp(void *p) +{ + jmp_buf *jbuf = (jmp_buf *) p; + + longjmp(*jbuf, 1); +} + +static int __init uml_debug_setup(char *line, int *add) +{ + debug = 1; + if(!strcmp(line, "=go")){ + debug_stop = 0; + *add = 0; + } + return 0; +} + +__uml_setup("debug", uml_debug_setup, +"debug\n" +" Starts up the kernel under the control of gdb. See the \n" +" kernel debugging tutorial and the debugging session pages\n" +" at http://user-mode-linux.sourceforge.net/ for more information.\n\n" +); + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/kernel/uaccess_user.c linux_umopenmosix/arch/um/kernel/uaccess_user.c --- linux-2.4.17/arch/um/kernel/uaccess_user.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/kernel/uaccess_user.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,125 @@ +/* + * Copyright (C) 2001 Chris Emerson (cemerson@chiark.greenend.org.uk) + * Licensed under the GPL + */ + +#include +#include +#include "user_util.h" + +static unsigned long __do_user_copy(void *to, const void *from, int n, + void **fault_addr, void **fault_catcher, + void (*op)(void *to, const void *from, + int n), int *faulted_out) +{ + unsigned long *faddrp = (unsigned long *) fault_addr, ret; + + jmp_buf jbuf; + *fault_catcher = &jbuf; + if(setjmp(jbuf) == 0){ + (*op)(to, from, n); + ret = 0; + *faulted_out = 0; + } + else { + ret = *faddrp; + *faulted_out = 1; + } + *fault_addr = NULL; + *fault_catcher = NULL; + return ret; +} + +static void __do_copy(void *to, const void *from, int n) +{ + memcpy(to, from, n); +} + +int __do_copy_from_user(void *to, const void *from, int n, + void **fault_addr, void **fault_catcher) +{ + unsigned long fault; + int faulted; + + fault = __do_user_copy(to, from, n, fault_addr, fault_catcher, + __do_copy, &faulted); + if(!faulted) return(0); + else return(n - (fault - (unsigned long) from)); +} + + +int __do_copy_to_user(void *to, const void *from, int n, + void **fault_addr, void **fault_catcher) +{ + unsigned long fault; + int faulted; + + fault = __do_user_copy(to, from, n, fault_addr, fault_catcher, + __do_copy, &faulted); + if(!faulted) return(0); + else return(n - (fault - (unsigned long) to)); +} + +static void __do_strncpy(void *dst, const void *src, int count) +{ + strncpy(dst, src, count); +} + +int __do_strncpy_from_user(char *dst, const char *src, unsigned long count, + void **fault_addr, void **fault_catcher) +{ + unsigned long fault; + int faulted; + + fault = __do_user_copy(dst, src, count, fault_addr, fault_catcher, + __do_strncpy, &faulted); + if(!faulted) return(strlen(dst)); + else return(-1); +} + +static void __do_clear(void *to, const void *from, int n) +{ + memset(to, 0, n); +} + +int __do_clear_user(void *mem, unsigned long len, + void **fault_addr, void **fault_catcher) +{ + unsigned long fault; + int faulted; + + fault = __do_user_copy(mem, NULL, len, fault_addr, fault_catcher, + __do_clear, &faulted); + if(!faulted) return(0); + else return(len - (fault - (unsigned long) mem)); +} + +int __do_strnlen_user(const char *str, unsigned long n, + void **fault_addr, void **fault_catcher) +{ + int ret; + unsigned long *faddrp = (unsigned long *)fault_addr; + jmp_buf jbuf; + + *fault_catcher = &jbuf; + if(setjmp(jbuf) == 0){ + ret = strlen(str) + 1; + } + else { + ret = *faddrp - (unsigned long) str; + } + *fault_addr = NULL; + *fault_catcher = NULL; + return ret; +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/kernel/um_arch.c linux_umopenmosix/arch/um/kernel/um_arch.c --- linux-2.4.17/arch/um/kernel/um_arch.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/kernel/um_arch.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,375 @@ +/* + * Copyright (C) 2000 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include "linux/config.h" +#include "linux/sched.h" +#include "linux/mm.h" +#include "linux/types.h" +#include "linux/tty.h" +#include "linux/init.h" +#include "linux/bootmem.h" +#include "linux/spinlock.h" +#include "linux/utsname.h" +#include +#include "asm/page.h" +#include "asm/pgtable.h" +#include "asm/ptrace.h" +#include "asm/elf.h" +#include "asm/user.h" +#include "asm/delay.h" +#include "ubd_user.h" +#include "asm/current.h" +#include "user_util.h" +#include "kern_util.h" +#include "kern.h" +#include "mprot.h" +#include "mem_user.h" +#include "umid.h" +#include "initrd.h" +#include "init.h" + +#define DEFAULT_COMMAND_LINE "root=/dev/ubd0" + +int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu) +{ + return(0); +} + +unsigned long thread_saved_pc(struct thread_struct *thread) +{ + panic("Someone should implement thread_saved_pc"); + return(0); +} + +/* + * get_cpuinfo - Get information on one CPU for use by procfs. + * + * Prints info on the next CPU into buffer. Beware, doesn't check for + * buffer overflow. Current implementation of procfs assumes that the + * resulting data is <= 1K. + * + * Args: + * buffer -- you guessed it, the data buffer + * cpu_np -- Input: next cpu to get (start at 0). Output: Updated. + * + * Returns number of bytes written to buffer. + */ + +static int show_cpuinfo(struct seq_file *m, void *v) +{ + int index; + + index = (struct cpuinfo_um *)v - cpu_data; +#ifdef CONFIG_SMP + if (!(cpu_online_map & (1 << index))) + return 0; +#endif + + seq_printf(m, "processor\t: user-mode\n"); + seq_printf(m, "bogomips\t: %lu.%02lu\n", + loops_per_jiffy/(500000/HZ), + (loops_per_jiffy/(5000/HZ)) % 100); + seq_printf(m, "host\t\t: %s\n", host_info); + + return(0); +} + +static void *c_start(struct seq_file *m, loff_t *pos) +{ + return *pos < NR_CPUS ? cpu_data + *pos : NULL; +} + +static void *c_next(struct seq_file *m, void *v, loff_t *pos) +{ + ++*pos; + return c_start(m, pos); +} + +static void c_stop(struct seq_file *m, void *v) +{ +} + +struct seq_operations cpuinfo_op = { + start: c_start, + next: c_next, + stop: c_stop, + show: show_cpuinfo, +}; + +pte_t * __bad_pagetable(void) +{ + panic("Someone should implement __bad_pagetable"); + return(NULL); +} + +extern void start_kernel(void); + +extern int debug; +extern int debug_stop; + +static int start_kernel_proc(void *unused) +{ + int pid; + + block_signals(); + pid = getpid(); + + cpu_tasks[0].pid = pid; + cpu_tasks[0].task = current; +#ifdef CONFIG_SMP + cpu_online_map = 1; +#endif + if(debug) stop_pid(pid); + start_kernel(); + return(0); +} + +extern unsigned long high_physmem; + +#ifdef CONFIG_HOST_2G_2G +#define START 0x60000000 +#else +#define START 0xa0000000 +#endif + +unsigned long host_task_size; +unsigned long task_size; + +void set_task_sizes(int arg) +{ + /* Round up to the nearest 4M */ + host_task_size = ROUND_4M((unsigned long) &arg); + task_size = START; +} + +unsigned long uml_physmem; + +unsigned long start_vm; +unsigned long end_vm; + +int ncpus = 1; + +#define PFN_UP(x) (((x) + PAGE_SIZE-1) >> PAGE_SHIFT) +#define PFN_DOWN(x) ((x) >> PAGE_SHIFT) +#define PFN_PHYS(x) ((x) << PAGE_SHIFT) + +static char *argv1_begin = NULL; +static char *argv1_end = NULL; + +static int have_root __initdata = 0; +long physmem_size = 32 * 1024 * 1024; + +void set_cmdline(char *cmd) +{ + if(honeypot) return; + strcpy(argv1_begin, "["); + strncat(argv1_begin, cmd, argv1_end - argv1_begin - strlen("[]")); + strcat(argv1_begin, "]"); + memset(argv1_begin + strlen(argv1_begin), '\0', + argv1_end - argv1_begin - strlen(argv1_begin)); +} + +static char *usage_string = +"User Mode Linux v%s\n" +" available at http://user-mode-linux.sourceforge.net/\n\n"; + +static int __init uml_version_setup(char *line, int *add) +{ + printf("%s\n", system_utsname.release); + exit(0); +} + +__uml_setup("--version", uml_version_setup, +"--version\n" +" Prints the version number of the kernel\n\n" +); + +static int __init uml_root_setup(char *line, int *add) +{ + have_root = 1; + return 0; +} + +__uml_setup("root=", uml_root_setup, +"root=\n" +" This is actually used by the generic kernel in exactly the same\n" +" way as in any other kernel. If you configure a number of block\n" +" devices and want to boot off something other than ubd0, you \n" +" would use something like:\n" +" root=/dev/ubd5\n\n" +); + +#ifdef CONFIG_SMP +static int __init uml_ncpus_setup(char *line, int *add) +{ + if (!sscanf(line, "%d", &ncpus)) { + printk("Couldn't parse [%s]\n", line); + return -1; + } + + return 0; +} + +__uml_setup("ncpus=", uml_ncpus_setup, +"ncpus=<# of desired CPUs>\n" +" This tells an SMP kernel how many virtual processors to start.\n" +" Currently, this has no effect because SMP isn't enabled.\n\n" +); +#endif + +static int __init Usage(char *line, int *add) +{ + const char **p; + + printf(usage_string, system_utsname.release); + p = &__uml_help_start; + while (p < &__uml_help_end) { + printf("%s", *p); + p++; + } + exit(0); +} + +__uml_setup("--help", Usage, +"--help\n" +" Prints this message\n\n" +); + +static int __init uml_checksetup(char *line, int *add) +{ + struct uml_param *p; + + p = &__uml_setup_start; + while(p < &__uml_setup_end) { + int n; + + n = strlen(p->str); + if(!strncmp(line, p->str, n)){ + if (p->setup_func(line + n, add)) return 1; + } + p++; + } + return 0; +} + +static void __init uml_postsetup(void) +{ + initcall_t *p; + + p = &__uml_postsetup_start; + while(p < &__uml_postsetup_end){ + (*p)(); + p++; + } + return; +} + +extern int debug_trace; +extern int jail; +void *brk_start; + +int linux_main(int argc, char **argv) +{ + unsigned long start_pfn, end_pfn, bootmap_size; + unsigned long virtmem_size; + unsigned int i, add; + void *sp; + + for (i = 1; i < argc; i++){ + if((i == 1) && (argv[i][0] == ' ')) continue; + add = 1; + uml_checksetup(argv[i], &add); + if(add) add_arg(saved_command_line, argv[i]); + } + if(have_root == 0) add_arg(saved_command_line, DEFAULT_COMMAND_LINE); + + if(!jail) + remap_data(ROUND_DOWN(&_stext), ROUND_UP(&_etext), 1); + remap_data(ROUND_DOWN(&_sdata), ROUND_UP(&_edata), 1); + brk_start = sbrk(0); + remap_data(ROUND_DOWN(&__bss_start), ROUND_UP(brk_start), 1); + + /* Start physical memory at least 4M after the current brk */ + uml_physmem = ROUND_4M(brk_start) + (1 << 22); + + setup_machinename(system_utsname.machine); + + argv1_begin = argv[1]; + argv1_end = &argv[1][strlen(argv[1])]; + + /* Kernel vm starts after physical memory and is either the size + * of physical memory or the remaining space left in the kernel + * area of the address space, whichever is smaller. + */ + start_vm = uml_physmem + physmem_size + VMALLOC_OFFSET; + if(start_vm >= get_kmem_end()) + panic("Physical memory too large to allow any kernel " + "virtual memory"); + + virtmem_size = physmem_size; + if(physmem_size > get_kmem_end() - start_vm) + virtmem_size = get_kmem_end() - start_vm; + end_vm = start_vm + virtmem_size; + + if(virtmem_size < physmem_size) + printk(KERN_INFO "Kernel virtual memory size shrunk to %ld " + "bytes\n", virtmem_size); + + setup_range(-1, NULL, uml_physmem, physmem_size, + physmem_size + VMALLOC_OFFSET + virtmem_size); + setup_memory(); + high_physmem = uml_physmem + physmem_size; + + start_pfn = PFN_UP(__pa(uml_physmem)); + end_pfn = PFN_DOWN(__pa(high_physmem)); + bootmap_size = init_bootmem(start_pfn, end_pfn - start_pfn); + free_bootmem(__pa(uml_physmem) + bootmap_size, + high_physmem - uml_physmem - bootmap_size); + uml_postsetup(); + + init_task.thread.kernel_stack = (unsigned long) &init_task + + 2 * PAGE_SIZE; + + task_protections((unsigned long) &init_task); + sp = (void *) init_task.thread.kernel_stack + 2 * PAGE_SIZE - + sizeof(unsigned long); + return(signals(start_kernel_proc, sp)); +} + +void setup_arch(char **cmdline_p) +{ + paging_init(); + strcpy(command_line, saved_command_line); + *cmdline_p = command_line; + setup_hostinfo(); +} + +void check_bugs(void) +{ + check_ptrace(); +} + +spinlock_t pid_lock = SPIN_LOCK_UNLOCKED; + +void lock_pid(void) +{ + spin_lock(&pid_lock); +} + +void unlock_pid(void) +{ + spin_unlock(&pid_lock); +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/kernel/umid.c linux_umopenmosix/arch/um/kernel/umid.c --- linux-2.4.17/arch/um/kernel/umid.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/kernel/umid.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,291 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "user.h" +#include "umid.h" +#include "init.h" + +#define UMID_LEN 64 +#define UML_DIR "~/.uml/" + +static char umid[UMID_LEN] = { 0 }; +static char *uml_dir = UML_DIR; + +static int umid_inited = 0; + +static int make_umid(void); + +static int __init set_umid(char *name, int *add) +{ + if(umid_inited){ + printk("Unique machine name can't be set twice\n"); + return(-1); + } + + if(strlen(name) > UMID_LEN - 1) + printk("Unique machine name is being truncated to %s " + "characters\n", UMID_LEN); + strncpy(umid, name, UMID_LEN - 1); + umid[UMID_LEN - 1] = '\0'; + + umid_inited = 1; + return 0; +} + +__uml_setup("umid=", set_umid, +"umid=\n" +" This is used to assign a unique identity to this UML machine\n" +" This is used for naming the pid file and management console socket\n\n" +); + +int __init umid_file_name(char *name, char *buf, int len) +{ + int n; + + if(!umid_inited && make_umid()) return(-1); + + n = strlen(uml_dir) + strlen(umid) + strlen(name) + 1; + if(n > len){ + printk("umid_file_name : buffer too short\n"); + return(-1); + } + + sprintf(buf, "%s%s/%s", uml_dir, umid, name); + return(0); +} + +extern int tracing_pid; + +static int __init create_pid_file(void) +{ + char file[strlen(uml_dir) + UMID_LEN + sizeof("/pid\0")]; + char pid[sizeof("nnnnn\0")]; + int fd; + + if(umid_file_name("pid", file, sizeof(file))) return 0; + + if((fd = open(file, O_RDWR | O_CREAT | O_EXCL, 0644)) < 0){ + printk("Open of machine pid file \"%s\" failed - " + "errno = %d\n", file, errno); + return 0; + } + + sprintf(pid, "%d\n", (tracing_pid == -1) ? getpid() : tracing_pid); + if(write(fd, pid, strlen(pid)) != strlen(pid)) + printk("Write of pid file failed - errno = %d\n", errno); + close(fd); + return 0; +} + +static int actually_do_remove(char *dir) +{ + DIR *directory; + struct dirent *ent; + int len; + char file[256]; + + if((directory = opendir(dir)) == NULL){ + printk("actually_do_remove : couldn't open directory '%s', " + "errno = %d\n", dir, errno); + return(1); + } + while((ent = readdir(directory)) != NULL){ + if(!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, "..")) + continue; + len = strlen(dir) + sizeof("/") + strlen(ent->d_name) + 1; + if(len > sizeof(file)){ + printk("Not deleting '%s' from '%s' - name too long\n", + ent->d_name, dir); + continue; + } + sprintf(file, "%s/%s", dir, ent->d_name); + if(unlink(file) < 0){ + printk("actually_do_remove : couldn't remove '%s' " + "from '%s', errno = %d\n", ent->d_name, dir, + errno); + return(1); + } + } + if(rmdir(dir) < 0){ + printk("actually_do_remove : couldn't rmdir '%s', " + "errno = %d\n", dir, errno); + return(1); + } + return(0); +} + +void remove_umid_dir(void) +{ + char dir[strlen(uml_dir) + UMID_LEN + 1]; + if(!umid_inited) return; + + sprintf(dir, "%s%s", uml_dir, umid); + actually_do_remove(dir); +} + +char *get_umid(void) +{ + return(umid); +} + +int not_dead_yet(char *dir) +{ + char file[strlen(uml_dir) + UMID_LEN + sizeof("/pid\0")]; + char pid[sizeof("nnnnn\0")], *end; + int dead, fd, p; + + sprintf(file, "%s/pid", dir); + dead = 0; + if((fd = open(file, O_RDONLY)) < 0){ + if(errno != ENOENT){ + printk("not_dead_yet : couldn't open pid file '%s', " + "errno = %d\n", file, errno); + return(1); + } + dead = 1; + } + if(fd > 0){ + if(read(fd, pid, sizeof(pid)) < 0){ + printk("not_dead_yet : couldn't read pid file '%s', " + "errno = %d\n", file, errno); + return(1); + } + p = strtoul(pid, &end, 0); + if(end == pid){ + printk("not_dead_yet : couldn't parse pid file '%s', " + "errno = %d\n", file, errno); + dead = 1; + } + if(((kill(p, 0) < 0) && (errno == ESRCH)) || + (p == tracing_pid)) + dead = 1; + } + if(!dead) return(1); + return(actually_do_remove(dir)); + return(0); +} + +static int __init set_uml_dir(char *name, int *add) +{ + if((strlen(name) > 0) && (name[strlen(name) - 1] != '/')){ + uml_dir = malloc(strlen(name) + 1); + if(uml_dir == NULL){ + printk("Failed to malloc uml_dir - error = %d\n", + errno); + uml_dir = name; + return(0); + } + sprintf(uml_dir, "%s/", name); + } + else uml_dir = name; + return 0; +} + +static int __init make_uml_dir(void) +{ + char dir[MAXPATHLEN + 1] = { '\0' }; + int len; + + if(*uml_dir == '~'){ + char *home = getenv("HOME"); + + if(home == NULL){ + printk("make_uml_dir : no value in environment for " + "$HOME\n"); + exit(1); + } + strncpy(dir, home, sizeof(dir)); + uml_dir++; + } + len = strlen(dir); + strncat(dir, uml_dir, sizeof(dir) - len); + len = strlen(dir); + if((len > 0) && (len < sizeof(dir) - 1) && (dir[len - 1] != '/')){ + dir[len] = '/'; + dir[len + 1] = '\0'; + } + + if((uml_dir = malloc(strlen(dir) + 1)) == NULL){ + printf("make_uml_dir : malloc failed, errno = %d\n", errno); + exit(1); + } + strcpy(uml_dir, dir); + + if((mkdir(uml_dir, 0777) < 0) && (errno != EEXIST)){ + printk("Failed to mkdir %s - errno = %i\n", uml_dir, errno); + return(-1); + } + return 0; +} + +static int __init make_umid(void) +{ + int fd, err; + char tmp[strlen(uml_dir) + UMID_LEN + 1]; + + strncpy(tmp, uml_dir, sizeof(tmp) - 1); + tmp[sizeof(tmp) - 1] = '\0'; + + if(*umid == 0){ + strcat(tmp, "XXXXXX"); + fd = mkstemp(tmp); + if(fd < 0){ + printk("set_umid - mkstemp failed, errno = %d\n", + errno); + return(1); + } + + close(fd); + /* There's a nice tiny little race between this unlink and + * the mkdir below. It'd be nice if there were a mkstemp + * for directories. + */ + unlink(tmp); + strcpy(umid, &tmp[strlen(uml_dir)]); + } + + sprintf(tmp, "%s%s", uml_dir, umid); + + if((err = mkdir(tmp, 0777)) < 0){ + if(errno == EEXIST){ + if(not_dead_yet(tmp)){ + printk("umid '%s' is in use\n", umid); + return(-1); + } + err = mkdir(tmp, 0777); + } + } + if(err < 0){ + printk("Failed to create %s - errno = %d\n", umid, errno); + return(-1); + } + + return(0); +} + +__uml_setup("uml_dir=", set_uml_dir, +"uml_dir=\n" +" The location to place the pid and umid files.\n\n" +); + +__uml_postsetup(make_uml_dir); +__uml_postsetup(make_umid); +__uml_postsetup(create_pid_file); + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/kernel/unmap.c linux_umopenmosix/arch/um/kernel/unmap.c --- linux-2.4.17/arch/um/kernel/unmap.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/kernel/unmap.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2000 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include +#include +#include +#include "user.h" + +int switcheroo(int fd, int prot, void *from, void *to, int size) +{ + if(munmap(to, size) < 0){ + return(-1); + } + if(mmap(to, size, prot, MAP_SHARED | MAP_FIXED, fd, 0) != to){ + return(-1); + } + if(munmap(from, size) < 0){ + return(-1); + } + return(0); +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/kernel/user_syms.c linux_umopenmosix/arch/um/kernel/user_syms.c --- linux-2.4.17/arch/um/kernel/user_syms.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/kernel/user_syms.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,120 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "user_util.h" +#include "mem_user.h" + +/* XXX All the __CONFIG_* stuff is broken because this file can't include + * config.h + */ + +/* Had to steal this from linux/module.h because that file can't be included + * since this includes various user-level headers. + */ + +struct module_symbol +{ + unsigned long value; + const char *name; +}; + +/* Indirect stringification. */ + +#define __MODULE_STRING_1(x) #x +#define __MODULE_STRING(x) __MODULE_STRING_1(x) + +#if !defined(__AUTOCONF_INCLUDED__) + +#define __EXPORT_SYMBOL(sym,str) error config_must_be_included_before_module +#define EXPORT_SYMBOL(var) error config_must_be_included_before_module +#define EXPORT_SYMBOL_NOVERS(var) error config_must_be_included_before_module + +#elif !defined(__CONFIG_MODULES__) + +#define __EXPORT_SYMBOL(sym,str) +#define EXPORT_SYMBOL(var) +#define EXPORT_SYMBOL_NOVERS(var) + +#else + +#define __EXPORT_SYMBOL(sym, str) \ +const char __kstrtab_##sym[] \ +__attribute__((section(".kstrtab"))) = str; \ +const struct module_symbol __ksymtab_##sym \ +__attribute__((section("__ksymtab"))) = \ +{ (unsigned long)&sym, __kstrtab_##sym } + +#if defined(__MODVERSIONS__) || !defined(__CONFIG_MODVERSIONS__) +#define EXPORT_SYMBOL(var) __EXPORT_SYMBOL(var, __MODULE_STRING(var)) +#else +#define EXPORT_SYMBOL(var) __EXPORT_SYMBOL(var, __MODULE_STRING(__VERSIONED_SYMBOL(var))) +#endif + +#define EXPORT_SYMBOL_NOVERS(var) __EXPORT_SYMBOL(var, __MODULE_STRING(var)) + +#endif + +EXPORT_SYMBOL(__errno_location); + +EXPORT_SYMBOL(access); +EXPORT_SYMBOL(open); +EXPORT_SYMBOL(open64); +EXPORT_SYMBOL(close); +EXPORT_SYMBOL(read); +EXPORT_SYMBOL(write); +EXPORT_SYMBOL(__xstat); +EXPORT_SYMBOL(__lxstat); +EXPORT_SYMBOL(__lxstat64); +EXPORT_SYMBOL(lseek); +EXPORT_SYMBOL(lseek64); +EXPORT_SYMBOL(chown); +EXPORT_SYMBOL(truncate); +EXPORT_SYMBOL(utime); +EXPORT_SYMBOL(chmod); +EXPORT_SYMBOL(rename); +EXPORT_SYMBOL(__xmknod); + +EXPORT_SYMBOL(symlink); +EXPORT_SYMBOL(link); +EXPORT_SYMBOL(unlink); +EXPORT_SYMBOL(readlink); + +EXPORT_SYMBOL(mkdir); +EXPORT_SYMBOL(rmdir); +EXPORT_SYMBOL(opendir); +EXPORT_SYMBOL(readdir); +EXPORT_SYMBOL(closedir); +EXPORT_SYMBOL(seekdir); +EXPORT_SYMBOL(telldir); + +EXPORT_SYMBOL(ioctl); + +extern ssize_t pread64 (int __fd, void *__buf, size_t __nbytes, + __off64_t __offset); +extern ssize_t pwrite64 (int __fd, __const void *__buf, size_t __n, + __off64_t __offset); +EXPORT_SYMBOL(pread64); +EXPORT_SYMBOL(pwrite64); + +EXPORT_SYMBOL(statfs); +EXPORT_SYMBOL(statfs64); + +EXPORT_SYMBOL(memcpy); +EXPORT_SYMBOL(getuid); + +EXPORT_SYMBOL(memset); +EXPORT_SYMBOL(strstr); + +EXPORT_SYMBOL(find_iomem); + + + + + diff -urN linux-2.4.17/arch/um/kernel/user_util.c linux_umopenmosix/arch/um/kernel/user_util.c --- linux-2.4.17/arch/um/kernel/user_util.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/kernel/user_util.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,346 @@ +/* + * Copyright (C) 2000, 2001 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "asm/types.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include "user_util.h" +#include "kern_util.h" +#include "user.h" +#include "mem_user.h" +#include "init.h" + +#define VERIFY_READ 0 +#define VERIFY_WRITE 1 + + + +#define access_ok(type,addr,size) (__range_ok(addr,size) == 0) + + +#define COMMAND_LINE_SIZE _POSIX_ARG_MAX + +char saved_command_line[COMMAND_LINE_SIZE] = { 0 }; +char command_line[COMMAND_LINE_SIZE] = { 0 }; + +void add_arg(char *cmd_line, char *arg) +{ + if (strlen(cmd_line) + strlen(arg) + 1 > COMMAND_LINE_SIZE) { + printf("add_arg: Too much command line!\n"); + exit(1); + } + if(strlen(cmd_line) > 0) strcat(cmd_line, " "); + strcat(cmd_line, arg); +} + +void remap_data(void *segment_start, void *segment_end, int w) +{ + void *addr; + unsigned long size; + int data, prot; + + if(w) prot = PROT_WRITE; + else prot = 0; + prot |= PROT_READ | PROT_EXEC; + size = (unsigned long) segment_end - + (unsigned long) segment_start; + data = create_mem_file(size); + if((addr = mmap(NULL, size, PROT_WRITE | PROT_READ, + MAP_SHARED, data, 0)) < 0){ + perror("mapping new data segment"); + exit(1); + } + memcpy(addr, segment_start, size); + if(switcheroo(data, prot, addr, segment_start, + size) < 0){ + printf("switcheroo failed\n"); + exit(1); + } +} + +__u64 file_size(char *file) +{ + struct stat64 buf; + + if(stat64(file, &buf) == -1){ + printk("Couldn't stat \"%s\" : errno = %d\n", file, errno); + return(-errno); + } + if(S_ISBLK(buf.st_mode)){ + long long size; + int fd; + + if((fd = open64(file, O_RDONLY)) < 0){ + printk("Couldn't open \"%s\", errno = %d\n", file, + errno); + return(-errno); + } + if(ioctl(fd, BLKGETSIZE, &size) < 0){ + printk("Couldn't get the block size of \"%s\", " + "errno = %d\n", file, errno); + close(fd); + return(-errno); + } + size *= 512; + close(fd); + return(size); + } + return(buf.st_size); +} + +void stop(void) +{ + while(1) sleep(1000000); +} + +void stack_protections(unsigned long address) +{ + int prot = PROT_READ | PROT_WRITE | PROT_EXEC; + + if(mprotect((void *) address, page_size(), prot) < 0) + panic("protecting stack failed, errno = %d", errno); +} + +void task_protections(unsigned long address) +{ + unsigned long guard = address + page_size(); + unsigned long stack = guard + page_size(); + int prot = 0; + + if(mprotect((void *) stack, page_size(), prot) < 0) + panic("protecting guard page failed, errno = %d", errno); + prot = PROT_READ | PROT_WRITE | PROT_EXEC; + if(mprotect((void *) stack, 2 * page_size(), prot) < 0) + panic("protecting stack failed, errno = %d", errno); +} + +int protect(unsigned long addr, unsigned long len, int r, int w, int x, + int must_succeed) +{ + int prot; + + prot = (r ? PROT_READ : 0) | (w ? PROT_WRITE : 0) | + (x ? PROT_EXEC : 0); + if(mprotect((void *) addr, len, prot) == -1){ + if(must_succeed) + panic("protect failed, errno = %d", errno); + else return(-errno); + } + return(0); +} + +int wait_for_stop(int pid, int sig, int cont_type) +{ + int status, ret; + + while(1){ + if(((ret = waitpid(pid, &status, WUNTRACED)) < 0) || + !WIFSTOPPED(status) || (WSTOPSIG(status) != sig)){ + if(ret < 0){ + if(errno == EINTR) continue; + printk("wait failed, errno = %d\n", + errno); + } + else if(WIFEXITED(status)) + printk("process exited with status %d\n", + WEXITSTATUS(status)); + else if(WIFSIGNALED(status)) + printk("process exited with signal %d\n", + WTERMSIG(status)); + else if((WSTOPSIG(status) == SIGVTALRM) || + (WSTOPSIG(status) == SIGALRM) || + (WSTOPSIG(status) == SIGIO) || + (WSTOPSIG(status) == SIGPROF) || + (WSTOPSIG(status) == SIGCHLD) || + (WSTOPSIG(status) == SIGWINCH) || + (WSTOPSIG(status) == SIGINT)){ + ptrace(cont_type, pid, 0, WSTOPSIG(status)); + continue; + } + else printk("process stopped with signal %d\n", + WSTOPSIG(status)); + panic("wait_for_stop failed to wait for %d to stop " + "with %d\n", pid, sig); + } + return(status); + } +} + +int clone_and_wait(int (*fn)(void *), void *arg, void *sp, int flags) +{ + int pid; + + pid = clone(fn, sp, flags, arg); + if(pid < 0) return(-1); + wait_for_stop(pid, SIGSTOP, PTRACE_CONT); + ptrace(PTRACE_CONT, pid, 0, 0); + return(pid); +} + +struct grantpt_info { + int fd; + int res; + int err; +}; + +static void grantpt_cb(void *arg) +{ + struct grantpt_info *info = arg; + + info->res = grantpt(info->fd); + info->err = errno; +} + +int get_pty(void) +{ + struct grantpt_info info; + int fd; + + if((fd = open("/dev/ptmx", O_RDWR)) < 0){ + printk("get_pty : Couldn't open /dev/ptmx - errno = %d\n", + errno); + return(-1); + } + info.fd = fd; + tracing_cb(grantpt_cb, &info); + if(info.res < 0){ + printk("get_pty : Couldn't grant pty - errno = %d\n", + info.err); + return(-1); + } + if(unlockpt(fd) < 0){ + printk("get_pty : Couldn't unlock pty - errno = %d\n", errno); + return(-1); + } + return(fd); +} + +int raw(int fd, int complain) +{ + struct termios tt; + int err; + + tcgetattr(fd, &tt); + cfmakeraw(&tt); + err = tcsetattr(fd, TCSANOW, &tt); + if((err < 0) && complain){ + printk("tcsetattr failed, errno = %d\n", errno); + return(-errno); + } + return(0); +} + +void setup_machinename(char *machine_out) +{ + struct utsname host; + + uname(&host); + strcpy(machine_out, host.machine); +} + +char host_info[(_UTSNAME_LENGTH + 1) * 4 + _UTSNAME_NODENAME_LENGTH + 1]; + +void setup_hostinfo(void) +{ + struct utsname host; + + uname(&host); + sprintf(host_info, "%s %s %s %s %s", host.sysname, host.nodename, + host.release, host.version, host.machine); +} + +void close_fd(int fd) +{ + close(fd); +} + +char *tempdir = NULL; + +static void __init find_tempdir(void) +{ + char *dirs[] = { "TMP", "TEMP", "TMPDIR", NULL }; + int i; + char *dir = NULL; + + if(tempdir != NULL) return; /* We've already been called */ + for(i = 0; dirs[i]; i++){ + dir = getenv(dirs[i]); + if(dir != NULL) break; + } + if(dir == NULL) dir = "/tmp"; + else if(*dir == '\0') dir = NULL; + if(dir != NULL) { + tempdir = malloc(strlen(dir) + 2); + if(tempdir == NULL){ + fprintf(stderr, "Failed to malloc tempdir, " + "errno = %d\n", errno); + return; + } + strcpy(tempdir, dir); + strcat(tempdir, "/"); + } +} + +int make_tempfile(const char *template, char **out_tempname, int do_unlink) +{ + char tempname[MAXPATHLEN]; + int fd; + + find_tempdir(); + if (*template != '/') + strcpy(tempname, tempdir); + else + *tempname = 0; + strcat(tempname, template); + if((fd = mkstemp(tempname)) < 0){ + fprintf(stderr, "open - cannot create %s: %s\n", tempname, + strerror(errno)); + return -1; + } + if(do_unlink && (unlink(tempname) < 0)){ + perror("unlink"); + return -1; + } + if(out_tempname){ + if((*out_tempname = strdup(tempname)) == NULL){ + perror("strdup"); + return -1; + } + } + return(fd); +} + + + + + + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/link.ld.in linux_umopenmosix/arch/um/link.ld.in --- linux-2.4.17/arch/um/link.ld.in Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/link.ld.in Sun Jun 23 12:40:10 2002 @@ -0,0 +1,133 @@ +OUTPUT_FORMAT("elf32-ELF_SUBARCH") +OUTPUT_ARCH(ELF_SUBARCH) +ENTRY(_start) + +SECTIONS +{ + . = START() + SIZEOF_HEADERS; + + . = ALIGN(4096); + .thread_private : { + __start_thread_private = .; + errno = .; + . += 4; + arch/um/kernel/unmap_fin.o (.data) + __end_thread_private = .; + } + . = ALIGN(4096); + .remap : { arch/um/kernel/unmap_fin.o (.text) } + + . = ALIGN(4096); /* Init code and data */ + _stext = .; + __init_begin = .; + .text.init : { *(.text.init) } + . = ALIGN(4096); + .text : + { + *(.text) + /* .gnu.warning sections are handled specially by elf32.em. */ + *(.gnu.warning) + *(.gnu.linkonce.t*) + } + .kstrtab : { *(.kstrtab) } + + . = ALIGN(16); /* Exception table */ + __start___ex_table = .; + __ex_table : { *(__ex_table) } + __stop___ex_table = .; + + __start___ksymtab = .; /* Kernel symbol table */ + __ksymtab : { *(__ksymtab) } + __stop___ksymtab = .; + .fini : { *(.fini) } =0x9090 + .rodata : { *(.rodata) *(.gnu.linkonce.r*) } + .rodata1 : { *(.rodata1) } + _etext = .; + PROVIDE (etext = .); + + . = ALIGN(4096); + PROVIDE (_sdata = .); + + .unprotected : { *(.unprotected) } + . = ALIGN(4096); + PROVIDE (_unprotected_end = .); + + . = ALIGN(4096); + __uml_setup_start = .; + .uml.setup.init : { *(.uml.setup.init) } + __uml_setup_end = .; + __uml_help_start = .; + .uml.help.init : { *(.uml.help.init) } + __uml_help_end = .; + __uml_postsetup_start = .; + .uml.postsetup.init : { *(.uml.postsetup.init) } + __uml_postsetup_end = .; + __setup_start = .; + .setup.init : { *(.setup.init) } + __setup_end = .; + __initcall_start = .; + .initcall.init : { *(.initcall.init) } + __initcall_end = .; + __uml_initcall_start = .; + .uml.initcall.init : { *(.uml.initcall.init) } + __uml_initcall_end = .; + __init_end = .; + __exitcall_begin = .; + .exitcall : { *(.exitcall.exit) } + __exitcall_end = .; + __uml_exitcall_begin = .; + .uml.exitcall : { *(.uml.exitcall.exit) } + __uml_exitcall_end = .; + + .data.init : { *(.data.init) } + .data : + { + . = ALIGN(16384); /* init_task */ + *(.data.init_task) + *(.data) + *(.gnu.linkonce.d*) + CONSTRUCTORS + } + .data1 : { *(.data1) } + .ctors : + { + *(.ctors) + } + .dtors : + { + *(.dtors) + } + + .got : { *(.got.plt) *(.got) } + .dynamic : { *(.dynamic) } + /* We want the small data sections together, so single-instruction offsets + can access them all, and initialized data all before uninitialized, so + we can shorten the on-disk segment size. */ + .sdata : { *(.sdata) } + _edata = .; + PROVIDE (edata = .); + . = ALIGN(0x1000); + .sbss : + { + __bss_start = .; + PROVIDE(_bss_start = .); + *(.sbss) + *(.scommon) + } + .bss : + { + *(.dynbss) + *(.bss) + *(COMMON) + } + _end = . ; + PROVIDE (end = .); + /* Stabs debugging sections. */ + .stab 0 : { *(.stab) } + .stabstr 0 : { *(.stabstr) } + .stab.excl 0 : { *(.stab.excl) } + .stab.exclstr 0 : { *(.stab.exclstr) } + .stab.index 0 : { *(.stab.index) } + .stab.indexstr 0 : { *(.stab.indexstr) } + .comment 0 : { *(.comment) } +} diff -urN linux-2.4.17/arch/um/main.c linux_umopenmosix/arch/um/main.c --- linux-2.4.17/arch/um/main.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/main.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,203 @@ +/* + * Copyright (C) 2000, 2001 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "user_util.h" +#include "kern_util.h" +#include "mem_user.h" +#include "user.h" +#include "init.h" + +unsigned long stacksizelim; + +char *linux_prog; + +#define PGD_BOUND (4 * 1024 * 1024) +#define STACKSIZE (8 * 1024 * 1024) +#define THREAD_NAME_LEN (256) + +char padding[THREAD_NAME_LEN] = { [ 0 ... THREAD_NAME_LEN - 2] = ' ', '\0' }; + +static void set_stklim(void) +{ + struct rlimit lim; + + if(getrlimit(RLIMIT_STACK, &lim) < 0){ + perror("getrlimit"); + exit(1); + } + if((lim.rlim_cur == RLIM_INFINITY) || (lim.rlim_cur > STACKSIZE)){ + lim.rlim_cur = STACKSIZE; + if(setrlimit(RLIMIT_STACK, &lim) < 0){ + perror("setrlimit"); + exit(1); + } + } + stacksizelim = (lim.rlim_cur + PGD_BOUND - 1) & ~(PGD_BOUND - 1); +} + +static __init void do_uml_initcalls(void) +{ + initcall_t *call; + + call = &__uml_initcall_start; + while (call < &__uml_initcall_end){; + (*call)(); + call++; + } +} +int main(int argc, char **argv, char **envp) +{ + int ret, i; + char **new_argv; + + /* Allocate memory for thread command lines */ + if(argc < 2 || strlen(argv[1]) < THREAD_NAME_LEN - 1){ + new_argv = malloc((argc + 2) * sizeof(char*)); + if(!new_argv) { + perror("Allocating extended argv"); + exit(1); + } + + new_argv[0] = argv[0]; + new_argv[1] = padding; + + for(i = 2; i <= argc; i++) + new_argv[i] = argv[i - 1]; + new_argv[argc + 1] = NULL; + +#ifdef PROFILING + disable_profile_timer(); +#endif + execvp(new_argv[0], new_argv); + perror("execing with extended args"); + exit(1); + } + + linux_prog = argv[0]; + + set_stklim(); + set_task_sizes(0); + + if((new_argv = malloc((argc + 1) * sizeof(char *))) == NULL){ + perror("Mallocing argv"); + exit(1); + } + for(i=0;i +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ptproxy.h" +#include "sysdep.h" +#include "wait.h" + +#include "user_util.h" +#include "user.h" + +/* + * Handle debugger trap, i.e. syscall. + */ + +int debugger_syscall (debugger_state *debugger, pid_t child) +{ + long arg1, arg2, arg3, arg4, arg5, result; + int syscall, ret = 0; + + syscall = get_syscall(debugger->pid, &arg1, &arg2, &arg3, &arg4, + &arg5); + + switch(syscall){ + case __NR_execve: + /* execve never returns */ + debugger->handle_trace = debugger_syscall; + break; + + case __NR_ptrace: + if(debugger->debugee->pid != 0) arg2 = debugger->debugee->pid; + result = proxy_ptrace(debugger, arg1, arg2, arg3, arg4, child, + &ret); + syscall_cancel(debugger->pid, result); + debugger->handle_trace = debugger_syscall; + return(ret); + + case __NR_waitpid: + case __NR_wait4: + debugger->wait_status_ptr = (int *) arg2; + debugger->wait_options = arg3; + if(debugger->debugee->event){ + syscall_continue(debugger->pid); + wait_for_stop(debugger->pid, SIGTRAP, PTRACE_SYSCALL); + proxy_wait_return(debugger, -1); + return(0); + } + else if(debugger->wait_options & WNOHANG){ + syscall_cancel(debugger->pid, 0); + debugger->handle_trace = debugger_syscall; + return(0); + } + else { + syscall_pause(debugger->pid); + debugger->handle_trace = proxy_wait_return; + debugger->waiting = 1; + } + break; + + case __NR_kill: + if(arg1 == debugger->debugee->pid){ + result = kill(child, arg2); + syscall_cancel(debugger->pid, result); + debugger->handle_trace = debugger_syscall; + return(0); + } + else debugger->handle_trace = debugger_normal_return; + break; + + default: + debugger->handle_trace = debugger_normal_return; + } + + syscall_continue (debugger->pid); + return(ret); +} + +int debugger_normal_return(debugger_state *debugger, pid_t unused) +{ + debugger->handle_trace = debugger_syscall; + syscall_continue(debugger->pid); + return(0); +} + +void debugger_cancelled_return(debugger_state *debugger, int result) +{ + debugger->handle_trace = debugger_syscall; + syscall_set_result(debugger->pid, result); + syscall_continue(debugger->pid); +} + +#ifdef CONFIG_SMP +#error need to make these arrays +#endif + +static debugger_state debugger; +static debugee_state debugee; + +void init_proxy (pid_t debugger_pid, int stopped, int status) +{ + debugger.pid = debugger_pid; + debugger.handle_trace = debugger_syscall; + debugger.debugee = &debugee; + debugger.waiting = 0; + + debugee.pid = 0; + debugee.traced = 0; + debugee.stopped = stopped; + debugee.event = 0; + debugee.zombie = 0; + debugee.died = 0; + debugee.wait_status = status; +} + +int debugger_proxy(int status, int pid) +{ + int ret = 0; + + if(WIFSTOPPED(status)){ + if (WSTOPSIG (status) == SIGTRAP) + ret = (*debugger.handle_trace)(&debugger, pid); + else ptrace(PTRACE_SYSCALL, debugger.pid, 0, WSTOPSIG(status)); + } + else if(WIFEXITED(status)){ + tracer_panic("debugger (pid %d) exited with status %d", + debugger.pid, WEXITSTATUS(status)); + } + else if(WIFSIGNALED(status)){ + tracer_panic("debugger (pid %d) exited with signal %d", + debugger.pid, WTERMSIG(status)); + } + else { + tracer_panic("proxy got unknown status (0x%x) on debugger " + "(pid %d)", status, debugger.pid); + } + return(ret); +} + +void child_proxy(pid_t pid, int status) +{ + debugee.event = 1; + debugee.wait_status = status; + + if(WIFSTOPPED(status)){ + debugee.stopped = 1; + kill(debugger.pid, SIGCHLD); + } + else if(WIFEXITED(status) || WIFSIGNALED(status)){ + debugee.zombie = 1; + kill(debugger.pid, SIGCHLD); + } + else panic("proxy got unknown status (0x%x) on child (pid %d)", + status, pid); +} + +void fake_child_exit(void) +{ + int status, pid; + + child_proxy(1, W_EXITCODE(0, 0)); + while(debugger.waiting == 1){ + pid = waitpid(debugger.pid, &status, WUNTRACED); + if(pid != debugger.pid){ + printk("fake_child_exit - waitpid failed, " + "errno = %d\n", errno); + return; + } + debugger_proxy(status, debugger.pid); + } + pid = waitpid(debugger.pid, &status, WUNTRACED); + if(pid != debugger.pid){ + printk("fake_child_exit - waitpid failed, " + "errno = %d\n", errno); + return; + } + if(ptrace(PTRACE_DETACH, debugger.pid, 0, SIGCONT) < 0) + printk("fake_child_exit - PTRACE_DETACH failed, errno = %d\n", + errno); +} + +char gdb_init_string[] = +"att 1 +b panic +b stop +handle SIGWINCH nostop noprint pass +"; + +int start_debugger(char *prog, int startup, int stop, int *fd_out) +{ + int slave, child; + + slave = open_gdb_chan(); + if((child = fork()) == 0){ + char *tempname = NULL; + int fd; + + if(setsid() < 0) perror("setsid"); + if((dup2(slave, 0) < 0) || (dup2(slave, 1) < 0) || + (dup2(slave, 2) < 0)){ + printk("start_debugger : dup2 failed, errno = %d\n", + errno); + exit(1); + } + if(ioctl(0, TIOCSCTTY, 0) < 0){ + printk("start_debugger : TIOCSCTTY failed, " + "errno = %d\n", errno); + exit(1); + } + if(tcsetpgrp (1, getpid()) < 0){ + printk("start_debugger : tcsetpgrp failed, " + "errno = %d\n", errno); +#ifdef notdef + exit(1); +#endif + } + if((fd = make_tempfile("/tmp/gdb_init-XXXXXX", &tempname, 0)) < 0){ + printk("start_debugger : make_tempfile failed, errno = %d\n", + errno); + exit(1); + } + write(fd, gdb_init_string, sizeof(gdb_init_string) - 1); + if(startup){ + if(stop){ + write(fd, "b start_kernel\n", + strlen("b start_kernel\n")); + } + write(fd, "c\n", strlen("c\n")); + } + if(ptrace(PTRACE_TRACEME, 0, 0, 0) < 0){ + printk("start_debugger : PTRACE_TRACEME failed, " + "errno = %d\n", errno); + exit(1); + } + execlp("gdb", "gdb", "--command", tempname, prog, NULL); + printk("start_debugger : exec of gdb failed, errno = %d\n", + errno); + } + if(child < 0){ + printk("start_debugger : fork for gdb failed, errno = %d\n", + errno); + return(-1); + } + *fd_out = slave; + return(child); +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/ptproxy/ptproxy.h linux_umopenmosix/arch/um/ptproxy/ptproxy.h --- linux-2.4.17/arch/um/ptproxy/ptproxy.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/ptproxy/ptproxy.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,58 @@ +/********************************************************************** +ptproxy.h + +Copyright (C) 1999 Lars Brinkhoff. See the file COPYING for licensing +terms and conditions. +**********************************************************************/ + +#ifndef __PTPROXY_H +#define __PTPROXY_H + +#include + +typedef struct debugger debugger_state; +typedef struct debugee debugee_state; + +struct debugger +{ + pid_t pid; + int wait_options; + int *wait_status_ptr; + unsigned int waiting : 1; + int (*handle_trace) (debugger_state *, pid_t); + + debugee_state *debugee; +}; + +struct debugee +{ + pid_t pid; + int wait_status; + unsigned died : 1; + unsigned event : 1; + unsigned stopped : 1; + unsigned trace_singlestep : 1; + unsigned trace_syscall : 1; + unsigned traced : 1; + unsigned zombie : 1; +}; + +extern int debugger_syscall(debugger_state *debugger, pid_t pid); +extern int debugger_normal_return (debugger_state *debugger, pid_t unused); + +extern long proxy_ptrace (struct debugger *, int, pid_t, long, long, pid_t, + int *strace_out); +extern void debugger_cancelled_return(debugger_state *debugger, int result); + +#endif + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/ptproxy/ptrace.c linux_umopenmosix/arch/um/ptproxy/ptrace.c --- linux-2.4.17/arch/um/ptproxy/ptrace.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/ptproxy/ptrace.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,179 @@ +/********************************************************************** +ptrace.c + +Copyright (C) 1999 Lars Brinkhoff. See the file COPYING for licensing +terms and conditions. + +Jeff Dike (jdike@karaya.com) : Modified for integration into uml +**********************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +#include "ptproxy.h" +#include "debug.h" +#include "user_util.h" + +long proxy_ptrace(struct debugger *debugger, int arg1, pid_t arg2, + long arg3, long arg4, pid_t child, int *ret) +{ + long result; + int status; + + *ret = 0; + if(debugger->debugee->died) return(-ESRCH); + + switch(arg1){ + case PTRACE_ATTACH: + if(debugger->debugee->traced) return(-EPERM); + + debugger->debugee->pid = arg2; + debugger->debugee->traced = 1; + if(debugger->debugee->stopped) + child_proxy(child, W_STOPCODE(SIGSTOP)); + else kill(child, SIGSTOP); + return(0); + + case PTRACE_CONT: + *ret = PTRACE_CONT; + return(ptrace(PTRACE_CONT, child, arg3, arg4)); + + case PTRACE_DETACH: + if(!debugger->debugee->traced) return(-EPERM); + + debugger->debugee->traced = 0; + kill(child, SIGCONT); + return(0); + +#ifdef UM_HAVE_GETFPREGS + case PTRACE_GETFPREGS: + { + long regs[UM_MAX_FP_REG]; + int i, result; + + result = ptrace(PTRACE_GETFPREGS, child, 0, regs); + if(result == -1) return(-errno); + + for (i = 0; i < sizeof(regs)/sizeof(regs[0]); i++) + ptrace(PTRACE_POKEDATA, debugger->pid, arg4 + 4 * i, + regs[i]); + return(result); + } +#endif + +#ifdef UM_HAVE_GETREGS + case PTRACE_GETREGS: + { + long regs[UM_MAX_REG]; + int i, result; + + result = ptrace(PTRACE_GETREGS, child, 0, regs); + if(result == -1) return(-errno); + + for (i = 0; i < sizeof(regs)/sizeof(regs[0]); i++) + ptrace (PTRACE_POKEDATA, debugger->pid, + arg4 + 4 * i, regs[i]); + return(result); + } + break; +#endif + + case PTRACE_KILL: + result = ptrace(PTRACE_KILL, child, arg3, arg4); + if(result == -1) return(-errno); + + return(result); + + case PTRACE_PEEKDATA: + case PTRACE_PEEKTEXT: + case PTRACE_PEEKUSER: + /* The value being read out could be -1, so we have to + * check errno to see if there's an error, and zero it + * beforehand so we're not faked out by an old error + */ + + errno = 0; + result = ptrace(arg1, child, arg3, 0); + if((result == -1) && (errno != 0)) return(-errno); + + result = ptrace(PTRACE_POKEDATA, debugger->pid, arg4, result); + if(result == -1) return(-errno); + + return(result); + + case PTRACE_POKEDATA: + case PTRACE_POKETEXT: + case PTRACE_POKEUSER: + result = ptrace(arg1, child, arg3, arg4); + if(result == -1) return(-errno); + + return(result); + +#ifdef UM_HAVE_SETFPREGS + case PTRACE_SETFPREGS: + { + long regs[UM_MAX_FP_REG]; + int i; + + for (i = 0; i < sizeof(regs)/sizeof(regs[0]); i++) + regs[i] = ptrace (PTRACE_PEEKDATA, debugger->pid, + arg4 + 4 * i, 0); + result = ptrace(PTRACE_SETFPREGS, child, 0, regs); + if(result == -1) return(-errno); + + return(result); + } +#endif + +#ifdef UM_HAVE_SETREGS + case PTRACE_SETREGS: + { + long regs[UM_MAX_REG]; + int i; + + for (i = 0; i < sizeof(regs)/sizeof(regs[0]); i++) + regs[i] = ptrace(PTRACE_PEEKDATA, debugger->pid, + arg4 + 4 * i, 0); + result = ptrace(PTRACE_SETREGS, child, 0, regs); + if(result == -1) return(-errno); + + return(result); + } +#endif + + case PTRACE_SINGLESTEP: + result = ptrace(PTRACE_SINGLESTEP, child, arg3, arg4); + if(result == -1) return(-errno); + + status = wait_for_stop(child, SIGTRAP, PTRACE_SINGLESTEP); + child_proxy(child, status); + return(result); + + case PTRACE_SYSCALL: + result = ptrace(PTRACE_SYSCALL, child, arg3, arg4); + if(result == -1) return(-errno); + + *ret = PTRACE_SYSCALL; + return(result); + + case PTRACE_TRACEME: + default: + return(-EINVAL); + } +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/ptproxy/sysdep.c linux_umopenmosix/arch/um/ptproxy/sysdep.c --- linux-2.4.17/arch/um/ptproxy/sysdep.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/ptproxy/sysdep.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,71 @@ +/********************************************************************** +sysdep.c + +Copyright (C) 1999 Lars Brinkhoff. See the file COPYING for licensing +terms and conditions. +**********************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "sysdep/ptrace.h" +#include "user_util.h" +#include "user.h" + +int get_syscall(pid_t pid, long *arg1, long *arg2, long *arg3, long *arg4, + long *arg5) +{ + *arg1 = ptrace(PTRACE_PEEKUSER, pid, UM_SYSCALL_ARG1_OFFSET, 0); + *arg2 = ptrace(PTRACE_PEEKUSER, pid, UM_SYSCALL_ARG2_OFFSET, 0); + *arg3 = ptrace(PTRACE_PEEKUSER, pid, UM_SYSCALL_ARG3_OFFSET, 0); + *arg4 = ptrace(PTRACE_PEEKUSER, pid, UM_SYSCALL_ARG4_OFFSET, 0); + *arg5 = ptrace(PTRACE_PEEKUSER, pid, UM_SYSCALL_ARG5_OFFSET, 0); + return(ptrace(PTRACE_PEEKUSER, pid, UM_SYSCALL_NR_OFFSET, 0)); +} + +void syscall_cancel(pid_t pid, int result) +{ + if((ptrace(PTRACE_POKEUSER, pid, UM_SYSCALL_NR_OFFSET, + __NR_getpid) < 0) || + (ptrace(PTRACE_SYSCALL, pid, 0, 0) < 0) || + (wait_for_stop(pid, SIGTRAP, PTRACE_SYSCALL) < 0) || + (ptrace(PTRACE_POKEUSER, pid, UM_SYSCALL_RET_OFFSET, result) < 0) || + (ptrace(PTRACE_SYSCALL, pid, 0, 0) < 0)) + printk("ptproxy: couldn't cancel syscall: errno = %d\n", + errno); +} + +void syscall_set_result(pid_t pid, long result) +{ + ptrace(PTRACE_POKEUSER, pid, UM_SYSCALL_RET_OFFSET, result); +} + +void syscall_continue(pid_t pid) +{ + ptrace(PTRACE_SYSCALL, pid, 0, 0); +} + +int syscall_pause(pid_t pid) +{ + if(ptrace(PTRACE_POKEUSER, pid, UM_SYSCALL_NR_OFFSET, __NR_pause) < 0){ + printk("syscall_change - ptrace failed, errno = %d\n", errno); + return(-1); + } + return(0); +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/ptproxy/sysdep.h linux_umopenmosix/arch/um/ptproxy/sysdep.h --- linux-2.4.17/arch/um/ptproxy/sysdep.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/ptproxy/sysdep.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,25 @@ +/********************************************************************** +sysdep.h + +Copyright (C) 1999 Lars Brinkhoff. +Copyright (C) 2001 Jeff Dike (jdike@karaya.com) +See the file COPYING for licensing terms and conditions. +**********************************************************************/ + +extern int get_syscall(pid_t pid, long *arg1, long *arg2, long *arg3, + long *arg4, long *arg5); +extern void syscall_cancel (pid_t pid, long result); +extern void syscall_set_result (pid_t pid, long result); +extern void syscall_continue (pid_t pid); +extern int syscall_pause(pid_t pid); + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/ptproxy/wait.c linux_umopenmosix/arch/um/ptproxy/wait.c --- linux-2.4.17/arch/um/ptproxy/wait.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/ptproxy/wait.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,57 @@ +/********************************************************************** +wait.c + +Copyright (C) 1999 Lars Brinkhoff. See the file COPYING for licensing +terms and conditions. + +**********************************************************************/ + +#include +#include +#include + +#include "ptproxy.h" +#include "sysdep.h" +#include "wait.h" + +#include +#include "sysdep/ptrace.h" + +int proxy_wait_return (struct debugger *debugger, pid_t unused) +{ + debugger->waiting = 0; + + if(debugger->debugee->died || (debugger->wait_options & __WCLONE)){ + debugger_cancelled_return(debugger, -ECHILD); + return(0); + } + + if(debugger->debugee->zombie && debugger->debugee->event) + debugger->debugee->died = 1; + + if(debugger->debugee->event){ + debugger->debugee->event = 0; + ptrace(PTRACE_POKEDATA, debugger->pid, + debugger->wait_status_ptr, + debugger->debugee->wait_status); + /* if (wait4) + ptrace (PTRACE_POKEDATA, pid, rusage_ptr, ...); */ + debugger_cancelled_return(debugger, debugger->debugee->pid); + return(0); + } + + /* pause will return -EINTR, which happens to be right for wait */ + debugger_normal_return(debugger, -1); + return(0); +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/ptproxy/wait.h linux_umopenmosix/arch/um/ptproxy/wait.h --- linux-2.4.17/arch/um/ptproxy/wait.h Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/ptproxy/wait.h Sun Jun 23 12:40:10 2002 @@ -0,0 +1,8 @@ +/********************************************************************** +wait.h + +Copyright (C) 1999 Lars Brinkhoff. See the file COPYING for licensing +terms and conditions. +**********************************************************************/ + +extern int proxy_wait_return (struct debugger *debugger, pid_t unused); diff -urN linux-2.4.17/arch/um/sys-i386/Makefile linux_umopenmosix/arch/um/sys-i386/Makefile --- linux-2.4.17/arch/um/sys-i386/Makefile Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/sys-i386/Makefile Sun Jun 23 12:40:10 2002 @@ -0,0 +1,49 @@ +OBJ = sys.o + +OBJS = checksum.o ldt.o old-checksum.o ptrace.o ptrace_user.o semaphore.o \ + sigcontext.o syscalls.o sysrq.o +export-objs = ksyms.o + +SYMLINKS = semaphore.c old-checksum.c checksum.S + +all: $(OBJ) + +$(OBJ): $(OBJS) $(export-objs) + rm -f $@ + $(LD) $(LINKFLAGS) --start-group $^ --end-group -o $@ + +sigcontext.o: sigcontext.c + $(CC) $(USER_CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $< + +ldt.o: ldt.c + $(CC) $(USER_CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $< + +ptrace_user.o: ptrace_user.c + $(CC) $(USER_CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $< + +checksum.S old-checksum.c: + -rm -f $@ + -ln -s $(TOPDIR)/arch/i386/lib/$@ $@ + +semaphore.c: + -rm -f $@ + -ln -s $(TOPDIR)/arch/i386/kernel/$@ $@ + +clean: + rm -f $(OBJS) $(export-objs) + +fastdep: + +archmrproper: + rm -f $(SYMLINKS) + +archclean: + rm -f link.ld + @$(MAKEBOOT) clean + +archdep: + @$(MAKEBOOT) dep + +modules: + +include $(TOPDIR)/Rules.make diff -urN linux-2.4.17/arch/um/sys-i386/ksyms.c linux_umopenmosix/arch/um/sys-i386/ksyms.c --- linux-2.4.17/arch/um/sys-i386/ksyms.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/sys-i386/ksyms.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,35 @@ +#include "linux/module.h" +#include "linux/in6.h" +#include "linux/rwsem.h" +#include "asm/byteorder.h" +#include "asm/semaphore.h" +#include "asm/uaccess.h" +#include "asm/checksum.h" +#include "asm/errno.h" +#include "linux/mosix.h" + + + + + +EXPORT_SYMBOL(__down_failed); +EXPORT_SYMBOL(__down_failed_interruptible); +EXPORT_SYMBOL(__down_failed_trylock); +EXPORT_SYMBOL(__up_wakeup); + +/* Networking helper routines. */ +EXPORT_SYMBOL(csum_partial_copy_generic); + + + + + + + + + + + + + + diff -urN linux-2.4.17/arch/um/sys-i386/ldt.c linux_umopenmosix/arch/um/sys-i386/ldt.c --- linux-2.4.17/arch/um/sys-i386/ldt.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/sys-i386/ldt.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2001 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +extern int modify_ldt(int func, void *ptr, unsigned long bytecount); + +int sys_modify_ldt(int func, void *ptr, unsigned long bytecount) +{ + return modify_ldt(func, ptr, bytecount); +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/sys-i386/ptrace.c linux_umopenmosix/arch/um/sys-i386/ptrace.c --- linux-2.4.17/arch/um/sys-i386/ptrace.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/sys-i386/ptrace.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2000 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include "linux/sched.h" +#include "asm/ptrace.h" + +/* determines which flags the user has access to. */ +/* 1 = access 0 = no access */ +#define FLAG_MASK 0x00044dd5 + +int putreg(struct task_struct *child, unsigned long regno, + unsigned long value) +{ + switch (regno >> 2) { + case FS: + if (value && (value & 3) != 3) + return -EIO; + child->thread.process_regs.regs[FS] = value; + return 0; + case GS: + if (value && (value & 3) != 3) + return -EIO; + child->thread.process_regs.regs[GS] = value; + return 0; + case DS: + case ES: + if (value && (value & 3) != 3) + return -EIO; + value &= 0xffff; + break; + case SS: + case CS: + if ((value & 3) != 3) + return -EIO; + value &= 0xffff; + break; + case EFL: + value &= FLAG_MASK; + value |= child->thread.process_regs.regs[EFL]; + break; + } + child->thread.process_regs.regs[regno >> 2] = value; + return 0; +} + +unsigned long getreg(struct task_struct *child, unsigned long regno) +{ + unsigned long retval = ~0UL; + + switch (regno >> 2) { + case FS: + case GS: + case DS: + case ES: + case SS: + case CS: + retval = 0xffff; + /* fall through */ + default: + retval &= child->thread.process_regs.regs[regno >> 2]; + } + return retval; +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/sys-i386/ptrace_user.c linux_umopenmosix/arch/um/sys-i386/ptrace_user.c --- linux-2.4.17/arch/um/sys-i386/ptrace_user.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/sys-i386/ptrace_user.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,25 @@ +#include +#include +#include +#include "sysdep/ptrace.h" + +int ptrace_getregs(long pid, struct sys_pt_regs *regs_out) +{ + return(ptrace(PTRACE_GETREGS, pid, 0, regs_out)); +} + +int ptrace_setregs(long pid, struct sys_pt_regs *regs) +{ + return(ptrace(PTRACE_SETREGS, pid, 0, regs)); +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/sys-i386/sigcontext.c linux_umopenmosix/arch/um/sys-i386/sigcontext.c --- linux-2.4.17/arch/um/sys-i386/sigcontext.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/sys-i386/sigcontext.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include +#include +#include +#include "sysdep/ptrace.h" +#include "kern_util.h" +#include "frame.h" + +int copy_sigcontext_to_user(void *sc_ptr, struct sys_pt_regs *regs, + unsigned long cr2, int error) +{ + struct sigcontext *sc; + int err; + + sc = sc_ptr; + err = 0; + err |= copy_to_user_proc(&sc->ebx, ®s->regs[EBX], sizeof(sc->ebx)); + err |= copy_to_user_proc(&sc->ecx, ®s->regs[ECX], sizeof(sc->ecx)); + err |= copy_to_user_proc(&sc->edx, ®s->regs[EDX], sizeof(sc->edx)); + err |= copy_to_user_proc(&sc->esi, ®s->regs[ESI], sizeof(sc->esi)); + err |= copy_to_user_proc(&sc->edi, ®s->regs[EDI], sizeof(sc->edi)); + err |= copy_to_user_proc(&sc->ebp, ®s->regs[EBP], sizeof(sc->ebp)); + err |= copy_to_user_proc(&sc->eax, ®s->regs[EAX], sizeof(sc->eax)); + err |= copy_to_user_proc(&sc->ds, ®s->regs[DS], sizeof(sc->ds)); + err |= copy_to_user_proc(&sc->es, ®s->regs[ES], sizeof(sc->es)); + err |= copy_to_user_proc(&sc->fs, ®s->regs[FS], sizeof(sc->fs)); + err |= copy_to_user_proc(&sc->gs, ®s->regs[GS], sizeof(sc->gs)); + err |= copy_to_user_proc(&sc->eip, ®s->regs[EIP], sizeof(sc->eip)); + err |= copy_to_user_proc(&sc->cs, ®s->regs[CS], sizeof(sc->cs)); + err |= copy_to_user_proc(&sc->eflags, ®s->regs[EFL], + sizeof(sc->eflags)); + err |= copy_to_user_proc(&sc->esp_at_signal, ®s->regs[UESP], + sizeof(sc->esp_at_signal)); + err |= copy_to_user_proc(&sc->ss, ®s->regs[SS], sizeof(sc->ss)); + err |= copy_to_user_proc(&sc->err, &error, sizeof(sc->err)); + err |= copy_to_user_proc(&sc->cr2, &cr2, sizeof(sc->cr2)); + return(err); +} + +void fill_in_regs(struct sys_pt_regs *regs, void *sc_ptr) +{ + struct sigcontext *sc; + + sc = sc_ptr; + regs->regs[EBX] = sc->ebx; + regs->regs[ECX] = sc->ecx; + regs->regs[EDX] = sc->edx; + regs->regs[ESI] = sc->esi; + regs->regs[EDI] = sc->edi; + regs->regs[EBP] = sc->ebp; + regs->regs[EAX] = sc->eax; + regs->regs[DS] = sc->ds; + regs->regs[ES] = sc->es; + regs->regs[FS] = sc->fs; + regs->regs[GS] = sc->gs; + regs->regs[EIP] = sc->eip; + regs->regs[CS] = sc->cs; + regs->regs[EFL] = sc->eflags; + regs->regs[UESP] = sc->esp_at_signal; + regs->regs[SS] = sc->ss; +} + +int copy_sc_to_user(void *to_ptr, void *from_ptr, void *data) +{ + struct arch_frame_data *arch = data; + struct sigcontext *to = to_ptr, *from = from_ptr; + struct _fpstate *to_fp, *from_fp; + int err; + + to_fp = (struct _fpstate *)((unsigned long) to + sizeof(*to)); + from_fp = from->fpstate; + err = copy_to_user_proc(to, from, sizeof(*to)); + if(from_fp != NULL){ + err |= copy_to_user_proc(&to->fpstate, &to_fp, + sizeof(to->fpstate)); + err |= copy_to_user_proc(to_fp, from_fp, arch->fpstate_size); + } + return(err); +} + +int copy_sc_from_user(void *to_ptr, void *from_ptr) +{ + struct sigcontext *to = to_ptr, *from = from_ptr; + struct _fpstate *to_fp, *from_fp; + int err; + + to_fp = to->fpstate; + from_fp = from->fpstate; + err = copy_from_user_proc(to, from, sizeof(*to)); + if(to_fp != NULL) + err |= copy_from_user_proc(to_fp, from_fp, sizeof(*to_fp)); + return(err); +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/sys-i386/syscalls.c linux_umopenmosix/arch/um/sys-i386/syscalls.c --- linux-2.4.17/arch/um/sys-i386/syscalls.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/sys-i386/syscalls.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2000 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include "asm/mman.h" +#include "asm/uaccess.h" +#include "asm/unistd.h" + +/* + * Perform the select(nd, in, out, ex, tv) and mmap() system + * calls. Linux/i386 didn't use to be able to handle more than + * 4 system call parameters, so these system calls used a memory + * block for parameter passing.. + */ + +struct mmap_arg_struct { + unsigned long addr; + unsigned long len; + unsigned long prot; + unsigned long flags; + unsigned long fd; + unsigned long offset; +}; + +extern int old_mmap(unsigned long addr, unsigned long len, + unsigned long prot, unsigned long flags, + unsigned long fd, unsigned long offset); + +int old_mmap_i386(struct mmap_arg_struct *arg) +{ + struct mmap_arg_struct a; + int err = -EFAULT; + + if (copy_from_user(&a, arg, sizeof(a))) + goto out; + + err = old_mmap(a.addr, a.len, a.prot, a.flags, a.fd, a.offset); + out: + return err; +} + +struct sel_arg_struct { + unsigned long n; + fd_set *inp, *outp, *exp; + struct timeval *tvp; +}; + +int old_select(struct sel_arg_struct *arg) +{ + struct sel_arg_struct a; + + if (copy_from_user(&a, arg, sizeof(a))) + return -EFAULT; + /* sys_select() does the appropriate kernel locking */ + return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp); +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/sys-i386/sysrq.c linux_umopenmosix/arch/um/sys-i386/sysrq.c --- linux-2.4.17/arch/um/sys-i386/sysrq.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/sys-i386/sysrq.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,23 @@ +#include "linux/kernel.h" +#include "linux/smp.h" +#include "linux/sched.h" +#include "asm/ptrace.h" +#include "sysrq.h" + +void show_regs(struct pt_regs_subarch *regs) +{ + printk("\n"); + printk("EIP: %04x:[<%08lx>] CPU: %d %s",0xffff & regs->xcs, regs->eip, + smp_processor_id(), print_tainted()); + if (regs->xcs & 3) + printk(" ESP: %04x:%08lx",0xffff & regs->xss, regs->esp); + printk(" EFLAGS: %08lx\n %s\n", regs->eflags, print_tainted()); + printk("EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n", + regs->eax, regs->ebx, regs->ecx, regs->edx); + printk("ESI: %08lx EDI: %08lx EBP: %08lx", + regs->esi, regs->edi, regs->ebp); + printk(" DS: %04x ES: %04x\n", + 0xffff & regs->xds, 0xffff & regs->xes); + + show_trace(®s->esp); +} diff -urN linux-2.4.17/arch/um/sys-ia64/Makefile linux_umopenmosix/arch/um/sys-ia64/Makefile --- linux-2.4.17/arch/um/sys-ia64/Makefile Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/sys-ia64/Makefile Sun Jun 23 12:40:10 2002 @@ -0,0 +1,26 @@ +OBJ = sys.o + +OBJS = + +all: $(OBJ) + +$(OBJ): $(OBJS) + rm -f $@ + $(LD) $(LINKFLAGS) --start-group $^ --end-group -o $@ +clean: + rm -f $(OBJS) + +fastdep: + +archmrproper: + +archclean: + rm -f link.ld + @$(MAKEBOOT) clean + +archdep: + @$(MAKEBOOT) dep + +modules: + +include $(TOPDIR)/Rules.make diff -urN linux-2.4.17/arch/um/sys-ppc/Makefile linux_umopenmosix/arch/um/sys-ppc/Makefile --- linux-2.4.17/arch/um/sys-ppc/Makefile Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/sys-ppc/Makefile Sun Jun 23 12:40:10 2002 @@ -0,0 +1,78 @@ +OBJ = sys.o + +.S.o: + $(CC) $(AFLAGS) -D__ASSEMBLY__ -D__UM_PPC__ -c $< -o $*.o + +OBJS = ptrace.o sigcontext.o semaphore.o checksum.o miscthings.o misc.o \ + ptrace_user.o sysrq.o + +EXTRA_AFLAGS := -DCONFIG_ALL_PPC -I. -I$(TOPDIR)/arch/ppc/kernel + +all: $(OBJ) + +$(OBJ): $(OBJS) + rm -f $@ + $(LD) $(LINKFLAGS) --start-group $^ --end-group -o $@ + +ptrace_user.o: ptrace_user.c + $(CC) -D__KERNEL__ $(USER_CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $< + +sigcontext.o: sigcontext.c + $(CC) $(USER_CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $< + +semaphore.c: + rm -f $@ + ln -s $(TOPDIR)/arch/ppc/kernel/$@ $@ + +checksum.S: + rm -f $@ + ln -s $(TOPDIR)/arch/ppc/lib/$@ $@ + +mk_defs.c: + rm -f $@ + ln -s $(TOPDIR)/arch/ppc/kernel/$@ $@ + +ppc_defs.head: + rm -f $@ + ln -s $(TOPDIR)/arch/ppc/kernel/$@ $@ + +ppc_defs.h: mk_defs.c ppc_defs.head \ + $(TOPDIR)/include/asm-ppc/mmu.h \ + $(TOPDIR)/include/asm-ppc/processor.h \ + $(TOPDIR)/include/asm-ppc/pgtable.h \ + $(TOPDIR)/include/asm-ppc/ptrace.h +# $(CC) $(CFLAGS) -S mk_defs.c + cp ppc_defs.head ppc_defs.h +# for bk, this way we can write to the file even if it's not checked out + echo '#define THREAD 608' >> ppc_defs.h + echo '#define PT_REGS 8' >> ppc_defs.h + echo '#define CLONE_VM 256' >> ppc_defs.h +# chmod u+w ppc_defs.h +# grep '^#define' mk_defs.s >> ppc_defs.h +# rm mk_defs.s + +# the asm link is horrible, and breaks the other targets. This is also +# not going to work with parallel makes. + +checksum.o: checksum.S + rm -f asm + ln -s $(TOPDIR)/include/asm-ppc asm + $(CC) $(EXTRA_AFLAGS) $(AFLAGS) -D__ASSEMBLY__ -D__UM_PPC__ -c $< -o $*.o + rm -f asm + +misc.o: misc.S ppc_defs.h + rm -f asm + ln -s $(TOPDIR)/include/asm-ppc asm + $(CC) $(EXTRA_AFLAGS) $(AFLAGS) -D__ASSEMBLY__ -D__UM_PPC__ -c $< -o $*.o + rm -f asm + +clean: + rm -f $(OBJS) + rm -f ppc_defs.h + rm -f checksum.S semaphore.c mk_defs.c + +fastdep: + +modules: + +include $(TOPDIR)/Rules.make diff -urN linux-2.4.17/arch/um/sys-ppc/misc.S linux_umopenmosix/arch/um/sys-ppc/misc.S --- linux-2.4.17/arch/um/sys-ppc/misc.S Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/sys-ppc/misc.S Sun Jun 23 12:40:10 2002 @@ -0,0 +1,116 @@ +/* + * This file contains miscellaneous low-level functions. + * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) + * + * Largely rewritten by Cort Dougan (cort@cs.nmt.edu) + * and Paul Mackerras. + * + * A couple of functions stolen from arch/ppc/kernel/misc.S for UML + * by Chris Emerson. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + * + */ + +#include +#include +#include "ppc_asm.h" + +#if defined(CONFIG_4xx) || defined(CONFIG_8xx) +#define CACHE_LINE_SIZE 16 +#define LG_CACHE_LINE_SIZE 4 +#define MAX_COPY_PREFETCH 1 +#elif !defined(CONFIG_PPC64BRIDGE) +#define CACHE_LINE_SIZE 32 +#define LG_CACHE_LINE_SIZE 5 +#define MAX_COPY_PREFETCH 4 +#else +#define CACHE_LINE_SIZE 128 +#define LG_CACHE_LINE_SIZE 7 +#define MAX_COPY_PREFETCH 1 +#endif /* CONFIG_4xx || CONFIG_8xx */ + + .text + +/* + * Clear a page using the dcbz instruction, which doesn't cause any + * memory traffic (except to write out any cache lines which get + * displaced). This only works on cacheable memory. + */ +_GLOBAL(clear_page) + li r0,4096/CACHE_LINE_SIZE + mtctr r0 +#ifdef CONFIG_8xx + li r4, 0 +1: stw r4, 0(r3) + stw r4, 4(r3) + stw r4, 8(r3) + stw r4, 12(r3) +#else +1: dcbz 0,r3 +#endif + addi r3,r3,CACHE_LINE_SIZE + bdnz 1b + blr + +/* + * Copy a whole page. We use the dcbz instruction on the destination + * to reduce memory traffic (it eliminates the unnecessary reads of + * the destination into cache). This requires that the destination + * is cacheable. + */ +#define COPY_16_BYTES \ + lwz r6,4(r4); \ + lwz r7,8(r4); \ + lwz r8,12(r4); \ + lwzu r9,16(r4); \ + stw r6,4(r3); \ + stw r7,8(r3); \ + stw r8,12(r3); \ + stwu r9,16(r3) + +_GLOBAL(copy_page) + addi r3,r3,-4 + addi r4,r4,-4 + li r5,4 + +#ifndef CONFIG_8xx +#if MAX_COPY_PREFETCH > 1 + li r0,MAX_COPY_PREFETCH + li r11,4 + mtctr r0 +11: dcbt r11,r4 + addi r11,r11,CACHE_LINE_SIZE + bdnz 11b +#else /* MAX_COPY_PREFETCH == 1 */ + dcbt r5,r4 + li r11,CACHE_LINE_SIZE+4 +#endif /* MAX_COPY_PREFETCH */ +#endif /* CONFIG_8xx */ + + li r0,4096/CACHE_LINE_SIZE + mtctr r0 +1: +#ifndef CONFIG_8xx + dcbt r11,r4 + dcbz r5,r3 +#endif + COPY_16_BYTES +#if CACHE_LINE_SIZE >= 32 + COPY_16_BYTES +#if CACHE_LINE_SIZE >= 64 + COPY_16_BYTES + COPY_16_BYTES +#if CACHE_LINE_SIZE >= 128 + COPY_16_BYTES + COPY_16_BYTES + COPY_16_BYTES + COPY_16_BYTES +#endif +#endif +#endif + bdnz 1b + blr diff -urN linux-2.4.17/arch/um/sys-ppc/miscthings.c linux_umopenmosix/arch/um/sys-ppc/miscthings.c --- linux-2.4.17/arch/um/sys-ppc/miscthings.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/sys-ppc/miscthings.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,56 @@ +#include "linux/threads.h" +#include "linux/stddef.h" // for NULL +#include "linux/elf.h" // for AT_NULL + +/* unsigned int local_bh_count[NR_CPUS]; */ +unsigned long isa_io_base = 0; + +/* The following function nicked from arch/ppc/kernel/process.c and + * adapted slightly */ +/* + * XXX ld.so expects the auxiliary table to start on + * a 16-byte boundary, so we have to find it and + * move it up. :-( + */ +void shove_aux_table(unsigned long sp) +{ + int argc; + char *p; + unsigned long e; + unsigned long aux_start, offset; + + argc = *(int *)sp; + sp += sizeof(int) + (argc + 1) * sizeof(char *); + /* skip over the environment pointers */ + do { + p = *(char **)sp; + sp += sizeof(char *); + } while (p != NULL); + aux_start = sp; + /* skip to the end of the auxiliary table */ + do { + e = *(unsigned long *)sp; + sp += 2 * sizeof(unsigned long); + } while (e != AT_NULL); + offset = ((aux_start + 15) & ~15) - aux_start; + if (offset != 0) { + do { + sp -= sizeof(unsigned long); + e = *(unsigned long *)sp; + *(unsigned long *)(sp + offset) = e; + } while (sp > aux_start); + } +} +/* END stuff taken from arch/ppc/kernel/process.c */ + + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/sys-ppc/ptrace.c linux_umopenmosix/arch/um/sys-ppc/ptrace.c --- linux-2.4.17/arch/um/sys-ppc/ptrace.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/sys-ppc/ptrace.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,28 @@ +#include "linux/sched.h" +#include "asm/ptrace.h" + +int putreg(struct task_struct *child, unsigned long regno, + unsigned long value) +{ + child->thread.process_regs.regs[regno >> 2] = value; + return 0; +} + +unsigned long getreg(struct task_struct *child, unsigned long regno) +{ + unsigned long retval = ~0UL; + + retval &= child->thread.process_regs.regs[regno >> 2]; + return retval; +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/sys-ppc/ptrace_user.c linux_umopenmosix/arch/um/sys-ppc/ptrace_user.c --- linux-2.4.17/arch/um/sys-ppc/ptrace_user.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/sys-ppc/ptrace_user.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,40 @@ +#include +#include +#include +#include "sysdep/ptrace.h" + +int ptrace_getregs(long pid, struct sys_pt_regs *regs_out) +{ + int i; + for (i=0; i < sizeof(struct sys_pt_regs)/sizeof(PPC_REG); ++i) { + errno = 0; + regs_out->regs[i] = ptrace(PTRACE_PEEKUSER, pid, i*4, 0); + if (errno) { + return -errno; + } + } + return 0; +} + +int ptrace_setregs(long pid, struct sys_pt_regs *regs_in) +{ + int i; + for (i=0; i < sizeof(struct sys_pt_regs)/sizeof(PPC_REG); ++i) { + if (i != 34 /* FIXME: PT_ORIG_R3 */ && i <= PT_MQ) { + if (ptrace(PTRACE_POKEUSER, pid, i*4, regs_in->regs[i]) < 0) { + return -errno; + } + } + } + return 0; +} +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/sys-ppc/sigcontext.c linux_umopenmosix/arch/um/sys-ppc/sigcontext.c --- linux-2.4.17/arch/um/sys-ppc/sigcontext.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/sys-ppc/sigcontext.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,54 @@ +#include "asm/ptrace.h" +#include "asm/sigcontext.h" +#include "sysdep/ptrace.h" +#include "user_util.h" + +void copy_sigcontext_to_user(void *scontext, struct sys_pt_regs *regs, + unsigned long cr2, int err) +{ + struct sigcontext_struct *sc = scontext; +#if 0 + int i; + // general purpose regs + for (i=0; i<32; ++i) { + sc->regs->gpr[i] = regs->regs[PT_R0 + i]; + } + sc->regs->nip = regs->regs[PT_NIP]; + sc->regs->msr = regs->regs[PT_MSR]; + sc->regs->orig_gpr3 = regs->regs[PT_ORIG_R3]; + sc->regs->ctr = regs->regs[PT_CTR]; + sc->regs->link = regs->regs[PT_LNK]; + sc->regs->xer = regs->regs[PT_XER]; + sc->regs->ccr = regs->regs[PT_CCR]; + sc->regs->mq = regs->regs[PT_MQ]; + sc->regs->trap = err; + sc->regs->dar = cr2; +#endif + /* This is a bit of a hack; there's some confusion with the + * various definitions of [sys_]pt_regs, and everything isn't + * quite coming together quite right. */ + memcpy(sc->regs, regs, sizeof(struct sys_pt_regs)); + /*(sc->regs) = *regs; */ + return(0); +} + +void fill_in_regs(struct sys_pt_regs *regs, void *sc_ptr) +{ + struct sigcontext_struct *sc; + + sc = sc_ptr; + + // FIXME: need to investigate what's going on with struct pt_regs etc. + *regs = *(sc->regs); +} + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/arch/um/sys-ppc/sysrq.c linux_umopenmosix/arch/um/sys-ppc/sysrq.c --- linux-2.4.17/arch/um/sys-ppc/sysrq.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/arch/um/sys-ppc/sysrq.c Sun Jun 23 12:40:10 2002 @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2001 Chris Emerson (cemerson@chiark.greenend.org.uk) + * Licensed under the GPL + */ + +#include "linux/kernel.h" +#include "linux/smp.h" +#include "asm/ptrace.h" +#include "sysrq.h" + +void show_regs(struct pt_regs_subarch *regs) +{ + printk("\n"); + printk("show_regs(): insert regs here.\n"); +#if 0 + printk("\n"); + printk("EIP: %04x:[<%08lx>] CPU: %d",0xffff & regs->xcs, regs->eip, + smp_processor_id()); + if (regs->xcs & 3) + printk(" ESP: %04x:%08lx",0xffff & regs->xss, regs->esp); + printk(" EFLAGS: %08lx\n", regs->eflags); + printk("EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n", + regs->eax, regs->ebx, regs->ecx, regs->edx); + printk("ESI: %08lx EDI: %08lx EBP: %08lx", + regs->esi, regs->edi, regs->ebp); + printk(" DS: %04x ES: %04x\n", + 0xffff & regs->xds, 0xffff & regs->xes); +#endif + + show_trace(®s->gpr[1]); +} + + +/* + * Overrides for Emacs so that we follow Linus's tabbing style. + * Emacs will notice this stuff at the end of the file and automatically + * adjust the settings for this buffer only. This must remain at the end + * of the file. + * --------------------------------------------------------------------------- + * Local variables: + * c-file-style: "linux" + * End: + */ diff -urN linux-2.4.17/drivers/char/Makefile linux_umopenmosix/drivers/char/Makefile --- linux-2.4.17/drivers/char/Makefile Sun Nov 11 20:09:32 2001 +++ linux_umopenmosix/drivers/char/Makefile Sun Jun 23 12:40:10 2002 @@ -72,6 +72,12 @@ endif endif +ifeq ($(ARCH),um) + KEYMAP = + KEYBD = + CONSOLE = +endif + ifeq ($(ARCH),sh) KEYMAP = KEYBD = @@ -137,7 +143,12 @@ obj-$(CONFIG_PCI) += keyboard.o $(KEYMAP) endif +ifdef CONFIG_MOSIX_UDB +obj-y += sysrq.o +else obj-$(CONFIG_MAGIC_SYSRQ) += sysrq.o +endif + obj-$(CONFIG_ATARI_DSP56K) += dsp56k.o obj-$(CONFIG_ROCKETPORT) += rocket.o obj-$(CONFIG_MOXA_SMARTIO) += mxser.o diff -urN linux-2.4.17/drivers/char/Makefile.orig linux_umopenmosix/drivers/char/Makefile.orig --- linux-2.4.17/drivers/char/Makefile.orig Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/drivers/char/Makefile.orig Sun Jun 23 12:40:10 2002 @@ -0,0 +1,267 @@ +# +# Makefile for the kernel character device drivers. +# +# Note! Dependencies are done automagically by 'make dep', which also +# removes any old dependencies. DON'T put your own dependencies here +# unless it's something special (ie not a .c file). +# +# Note 2! The CFLAGS definitions are now inherited from the +# parent makes.. +# + +# +# This file contains the font map for the default (hardware) font +# +FONTMAPFILE = cp437.uni + +O_TARGET := char.o + +obj-y += mem.o tty_io.o n_tty.o tty_ioctl.o raw.o pty.o misc.o random.o + +# All of the (potential) objects that export symbols. +# This list comes from 'grep -l EXPORT_SYMBOL *.[hc]'. + +export-objs := busmouse.o console.o keyboard.o sysrq.o \ + misc.o pty.o random.o selection.o serial.o \ + sonypi.o tty_io.o tty_ioctl.o generic_serial.o + +mod-subdirs := joystick ftape drm pcmcia + +list-multi := + +KEYMAP =defkeymap.o +KEYBD =pc_keyb.o +CONSOLE =console.o +SERIAL =serial.o + +ifeq ($(ARCH),s390) + KEYMAP = + KEYBD = + CONSOLE = + SERIAL = +endif + +ifeq ($(ARCH),mips) + ifneq ($(CONFIG_PC_KEYB),y) + KEYBD = + endif +endif + +ifeq ($(ARCH),s390x) + KEYMAP = + KEYBD = + CONSOLE = + SERIAL = +endif + +ifeq ($(ARCH),m68k) + ifdef CONFIG_AMIGA + KEYBD = amikeyb.o + else + KEYBD = + endif + SERIAL = +endif + +ifeq ($(ARCH),arm) + ifneq ($(CONFIG_PC_KEYMAP),y) + KEYMAP = + endif + ifneq ($(CONFIG_PC_KEYB),y) + KEYBD = + endif +endif + +ifeq ($(ARCH),um) + KEYMAP = + KEYBD = + CONSOLE = +endif + +ifeq ($(ARCH),sh) + KEYMAP = + KEYBD = + CONSOLE = + ifeq ($(CONFIG_SH_HP600),y) + KEYMAP = defkeymap.o + KEYBD = scan_keyb.o hp600_keyb.o + CONSOLE = console.o + endif + ifeq ($(CONFIG_SH_DMIDA),y) + # DMIDA does not connect the HD64465 PS/2 keyboard port + # but we allow for USB keyboards to be plugged in. + KEYMAP = defkeymap.o + KEYBD = # hd64465_keyb.o pc_keyb.o + CONSOLE = console.o + endif + ifeq ($(CONFIG_SH_EC3104),y) + KEYMAP = defkeymap.o + KEYBD = ec3104_keyb.o + CONSOLE = console.o + endif + ifeq ($(CONFIG_SH_DREAMCAST),y) + KEYMAP = defkeymap.o + KEYBD = + CONSOLE = console.o + endif +endif + +ifeq ($(CONFIG_DECSTATION),y) + KEYMAP = + KEYBD = + SERIAL = decserial.o +endif + +ifeq ($(CONFIG_BAGET_MIPS),y) + KEYBD = + SERIAL = +endif + +ifeq ($(CONFIG_NINO),y) + SERIAL = +endif + +ifneq ($(CONFIG_SUN_SERIAL),) + SERIAL = +endif + +ifeq ($(CONFIG_QTRONIX_KEYBOARD),y) + KEYBD = qtronix.o + KEYMAP = qtronixmap.o +endif + +obj-$(CONFIG_VT) += vt.o vc_screen.o consolemap.o consolemap_deftbl.o $(CONSOLE) selection.o +obj-$(CONFIG_SERIAL) += $(SERIAL) +obj-$(CONFIG_SERIAL_ACPI) += acpi_serial.o +obj-$(CONFIG_SERIAL_21285) += serial_21285.o +obj-$(CONFIG_SERIAL_SA1100) += serial_sa1100.o +obj-$(CONFIG_SERIAL_AMBA) += serial_amba.o + +ifndef CONFIG_SUN_KEYBOARD + obj-$(CONFIG_VT) += keyboard.o $(KEYMAP) $(KEYBD) +else + obj-$(CONFIG_PCI) += keyboard.o $(KEYMAP) +endif + +obj-$(CONFIG_MAGIC_SYSRQ) += sysrq.o +obj-$(CONFIG_ATARI_DSP56K) += dsp56k.o +obj-$(CONFIG_ROCKETPORT) += rocket.o +obj-$(CONFIG_MOXA_SMARTIO) += mxser.o +obj-$(CONFIG_MOXA_INTELLIO) += moxa.o +obj-$(CONFIG_DIGI) += pcxx.o +obj-$(CONFIG_DIGIEPCA) += epca.o +obj-$(CONFIG_CYCLADES) += cyclades.o +obj-$(CONFIG_STALLION) += stallion.o +obj-$(CONFIG_ISTALLION) += istallion.o +obj-$(CONFIG_COMPUTONE) += ip2.o ip2main.o +obj-$(CONFIG_RISCOM8) += riscom8.o +obj-$(CONFIG_ISI) += isicom.o +obj-$(CONFIG_ESPSERIAL) += esp.o +obj-$(CONFIG_SYNCLINK) += synclink.o +obj-$(CONFIG_N_HDLC) += n_hdlc.o +obj-$(CONFIG_SPECIALIX) += specialix.o +obj-$(CONFIG_AMIGA_BUILTIN_SERIAL) += amiserial.o +obj-$(CONFIG_A2232) += ser_a2232.o generic_serial.o +obj-$(CONFIG_SX) += sx.o generic_serial.o +obj-$(CONFIG_RIO) += rio/rio.o generic_serial.o +obj-$(CONFIG_SH_SCI) += sh-sci.o generic_serial.o +obj-$(CONFIG_SERIAL167) += serial167.o +obj-$(CONFIG_MVME147_SCC) += generic_serial.o vme_scc.o +obj-$(CONFIG_MVME162_SCC) += generic_serial.o vme_scc.o +obj-$(CONFIG_BVME6000_SCC) += generic_serial.o vme_scc.o +obj-$(CONFIG_SERIAL_TX3912) += generic_serial.o serial_tx3912.o + +subdir-$(CONFIG_RIO) += rio +subdir-$(CONFIG_INPUT) += joystick + +obj-$(CONFIG_ATIXL_BUSMOUSE) += atixlmouse.o +obj-$(CONFIG_LOGIBUSMOUSE) += logibusmouse.o +obj-$(CONFIG_PRINTER) += lp.o + +ifeq ($(CONFIG_INPUT),y) +obj-y += joystick/js.o +endif + +obj-$(CONFIG_BUSMOUSE) += busmouse.o +obj-$(CONFIG_DTLK) += dtlk.o +obj-$(CONFIG_R3964) += n_r3964.o +obj-$(CONFIG_APPLICOM) += applicom.o +obj-$(CONFIG_SONYPI) += sonypi.o +obj-$(CONFIG_MS_BUSMOUSE) += msbusmouse.o +obj-$(CONFIG_82C710_MOUSE) += qpmouse.o +obj-$(CONFIG_AMIGAMOUSE) += amigamouse.o +obj-$(CONFIG_ATARIMOUSE) += atarimouse.o +obj-$(CONFIG_ADBMOUSE) += adbmouse.o +obj-$(CONFIG_PC110_PAD) += pc110pad.o +obj-$(CONFIG_RTC) += rtc.o +obj-$(CONFIG_EFI_RTC) += efirtc.o +ifeq ($(CONFIG_PPC),) + obj-$(CONFIG_NVRAM) += nvram.o +endif +obj-$(CONFIG_TOSHIBA) += toshiba.o +obj-$(CONFIG_I8K) += i8k.o +obj-$(CONFIG_DS1620) += ds1620.o +obj-$(CONFIG_INTEL_RNG) += i810_rng.o + +obj-$(CONFIG_QIC02_TAPE) += tpqic02.o + +subdir-$(CONFIG_FTAPE) += ftape +subdir-$(CONFIG_DRM) += drm +subdir-$(CONFIG_PCMCIA) += pcmcia +subdir-$(CONFIG_AGP) += agp + +ifeq ($(CONFIG_FTAPE),y) +obj-y += ftape/ftape.o +endif + +obj-$(CONFIG_H8) += h8.o +obj-$(CONFIG_PPDEV) += ppdev.o +obj-$(CONFIG_DZ) += dz.o +obj-$(CONFIG_NWBUTTON) += nwbutton.o +obj-$(CONFIG_NWFLASH) += nwflash.o + +# Only one watchdog can succeed. We probe the hardware watchdog +# drivers first, then the softdog driver. This means if your hardware +# watchdog dies or is 'borrowed' for some reason the software watchdog +# still gives you some cover. + +obj-$(CONFIG_PCWATCHDOG) += pcwd.o +obj-$(CONFIG_ACQUIRE_WDT) += acquirewdt.o +obj-$(CONFIG_ADVANTECH_WDT) += advantechwdt.o +obj-$(CONFIG_IB700_WDT) += ib700wdt.o +obj-$(CONFIG_MIXCOMWD) += mixcomwd.o +obj-$(CONFIG_60XX_WDT) += sbc60xxwdt.o +obj-$(CONFIG_WDT) += wdt.o +obj-$(CONFIG_WDTPCI) += wdt_pci.o +obj-$(CONFIG_21285_WATCHDOG) += wdt285.o +obj-$(CONFIG_977_WATCHDOG) += wdt977.o +obj-$(CONFIG_I810_TCO) += i810-tco.o +obj-$(CONFIG_MACHZ_WDT) += machzwd.o +obj-$(CONFIG_SH_WDT) += shwdt.o +obj-$(CONFIG_EUROTECH_WDT) += eurotechwdt.o +obj-$(CONFIG_SOFT_WATCHDOG) += softdog.o + +subdir-$(CONFIG_MWAVE) += mwave +ifeq ($(CONFIG_MWAVE),y) + obj-y += mwave/mwave.o +endif + +include $(TOPDIR)/Rules.make + +fastdep: + +conmakehash: conmakehash.c + $(HOSTCC) $(HOSTCFLAGS) -o conmakehash conmakehash.c + +consolemap_deftbl.c: $(FONTMAPFILE) conmakehash + ./conmakehash $(FONTMAPFILE) > consolemap_deftbl.c + +consolemap_deftbl.o: consolemap_deftbl.c $(TOPDIR)/include/linux/types.h + +.DELETE_ON_ERROR: + +defkeymap.c: defkeymap.map + set -e ; loadkeys --mktable $< | sed -e 's/^static *//' > $@ + +qtronixmap.c: qtronixmap.map + set -e ; loadkeys --mktable $< | sed -e 's/^static *//' > $@ diff -urN linux-2.4.17/drivers/char/console.c linux_umopenmosix/drivers/char/console.c --- linux-2.4.17/drivers/char/console.c Fri Dec 21 19:41:53 2001 +++ linux_umopenmosix/drivers/char/console.c Sun Jun 23 12:40:10 2002 @@ -2170,6 +2170,32 @@ clear_bit(0, &printing); } +#ifdef CONFIG_MOSIX_UDB +int +vt_console_read(struct console *co, const char *into, unsigned cnt) +{ + extern int keyboard_has_any(void); + extern void keyboard_manual_mode(int); + extern char keyboard_readch(void); + int n = 0; + + keyboard_manual_mode(1); + while(!keyboard_has_any()); + while(cnt--) + { + ((char *)into)[n++] = keyboard_readch(); + unblank_screen(); + if(!keyboard_has_any()) + { + keyboard_manual_mode(0); + return(n); + } + } + keyboard_manual_mode(0); + return(n); +} +#endif /* CONFIG_MOSIX_UDB */ + static kdev_t vt_console_device(struct console *c) { return MKDEV(TTY_MAJOR, c->index ? c->index : fg_console + 1); @@ -2178,6 +2204,9 @@ struct console vt_console_driver = { name: "tty", write: vt_console_print, +#ifdef CONFIG_MOSIX_UDB + read: vt_console_read, +#endif /* CONFIG_MOSIX_UDB */ device: vt_console_device, wait_key: keyboard_wait_for_keypress, unblank: unblank_screen, diff -urN linux-2.4.17/drivers/char/drm/i810_dma.c linux_umopenmosix/drivers/char/drm/i810_dma.c --- linux-2.4.17/drivers/char/drm/i810_dma.c Wed Aug 8 19:42:15 2001 +++ linux_umopenmosix/drivers/char/drm/i810_dma.c Sun Jun 23 12:40:10 2002 @@ -36,6 +36,10 @@ #include "i810_drv.h" #include /* For task queue support */ +#ifdef CONFIG_MOSIX +#include +#endif /* CONFIG_MOSIX */ + /* in case we don't have a 2.3.99-pre6 kernel or later: */ #ifndef VM_DONTCOPY #define VM_DONTCOPY 0 @@ -181,6 +185,13 @@ if(buf_priv->currently_mapped == I810_BUF_MAPPED) return -EINVAL; +#ifdef CONFIG_MOSIX + if(!mosix_go_home(1)) + { + printk("i810_map_buffer: Cannot map while away!\n"); + return(-ENOMEM); + } +#endif /* CONFIG_MOSIX */ if(VM_DONTCOPY != 0) { #if LINUX_VERSION_CODE <= 0x020402 down( ¤t->mm->mmap_sem ); @@ -222,6 +233,13 @@ if(VM_DONTCOPY != 0) { if(buf_priv->currently_mapped != I810_BUF_MAPPED) return -EINVAL; +#ifdef CONFIG_MOSIX + { + extern asmlinkage long sys_munmap(unsigned long,size_t); + retcode = sys_munmap((unsigned long)buf_priv->virtual, + (size_t) buf->total); + } +#else #if LINUX_VERSION_CODE <= 0x020402 down( ¤t->mm->mmap_sem ); #else @@ -240,6 +258,7 @@ #else up_write( ¤t->mm->mmap_sem ); #endif +#endif /* CONFIG_MOSIX */ } buf_priv->currently_mapped = I810_BUF_UNMAPPED; buf_priv->virtual = 0; diff -urN linux-2.4.17/drivers/char/keyboard.c linux_umopenmosix/drivers/char/keyboard.c --- linux-2.4.17/drivers/char/keyboard.c Tue Sep 18 23:39:51 2001 +++ linux_umopenmosix/drivers/char/keyboard.c Sun Jun 23 12:40:10 2002 @@ -65,6 +65,61 @@ EXPORT_SYMBOL(handle_scancode); EXPORT_SYMBOL(kbd_ledfunc); +#ifdef CONFIG_MOSIX_UDB +#define MANQ 8 +char manq[MANQ]; +static int man_in, man_out; +static int manual_mode; + +void +keyboard_manual_mode(int x) +{ + if(x) + manual_mode++; + else + { + if(manual_mode) + manual_mode--; + man_in = man_out = 0; + } +} + +int +in_manual_mode(void) +{ + return(manual_mode); +} + +int +keyboard_has_any(void) +{ + extern void keyboard_like_interrupt(void); + + keyboard_like_interrupt(); + return(man_in != man_out); +} + +char +keyboard_readch(void) +{ + char c; + + if(man_in == man_out) + return('\0'); + c = manq[man_out]; + man_out = (man_out + 1) % MANQ; + return(c); +} + +void +keyboard_putch(char ch) +{ + manq[man_in++] = ch; + man_in %= MANQ; +} + +#endif /* CONFIG_MOSIX_UDB */ + extern void ctrl_alt_del(void); DECLARE_WAIT_QUEUE_HEAD(keypress_wait); @@ -129,12 +184,19 @@ num, hold, scroll_forw, scroll_back, boot_it, caps_on, compose, SAK, decr_console, incr_console, spawn_console, bare_num; +#ifdef CONFIG_MOSIX_UDB +static void_fn call_udb; +#endif /* CONFIG_MOSIX_UDB */ + static void_fnp spec_fn_table[] = { do_null, enter, show_ptregs, show_mem, show_state, send_intr, lastcons, caps_toggle, num, hold, scroll_forw, scroll_back, boot_it, caps_on, compose, SAK, decr_console, incr_console, spawn_console, bare_num +#ifdef CONFIG_MOSIX_UDB + , call_udb +#endif /* CONFIG_MOSIX_UDB */ }; #define SPECIALS_ALLOWED_IN_RAW_MODE (1 << KVAL(K_SAK)) @@ -279,6 +341,9 @@ */ if (!rep || (vc_kbd_mode(kbd,VC_REPEAT) && tty && +#ifdef CONFIG_MOSIX_UDB + !manual_mode && +#endif /* CONFIG_MOSIX_UDB */ (L_ECHO(tty) || (tty->driver.chars_in_buffer(tty) == 0)))) { u_short keysym; u_char type; @@ -334,6 +399,13 @@ void put_queue(int ch) { +#ifdef CONFIG_MOSIX_UDB + if(manual_mode) + { + keyboard_putch((char)ch); + return; + } +#endif /* CONFIG_MOSIX_UDB */ wake_up(&keypress_wait); if (tty) { tty_insert_flip_char(tty, ch, 0); @@ -814,6 +886,14 @@ } } +#ifdef CONFIG_MOSIX_UDB +static void call_udb(void) +{ + extern void mosix_debugger(char *); + mosix_debugger("Keyboard"); +} +#endif /* CONFIG_MOSIX_UDB */ + /* * The leds display either (i) the status of NumLock, CapsLock, ScrollLock, * or (ii) whatever pattern of lights people want to show using KDSETLED, @@ -940,5 +1020,8 @@ pm_kbd = pm_register(PM_SYS_DEV, PM_SYS_KBC, pm_kbd_request_override); +#ifdef CONFIG_MOSIX_UDB + key_maps[2][69] = key_maps[8][69] = K_DEBUGGER|0xf000; +#endif /* CONFIG_MOSIX_UDB */ return 0; } diff -urN linux-2.4.17/drivers/char/mem.c linux_umopenmosix/drivers/char/mem.c --- linux-2.4.17/drivers/char/mem.c Fri Dec 21 19:41:54 2001 +++ linux_umopenmosix/drivers/char/mem.c Sun Jun 23 12:40:10 2002 @@ -443,6 +443,9 @@ left = count; /* do we want to be clever? Arbitrary cut-off */ +#ifdef CONFIG_MOSIX + if(!(current->mosix.dflags & DDEPUTY)) +#endif /* CONFIG_MOSIX */ if (count >= PAGE_SIZE*4) { unsigned long partial; @@ -520,6 +523,62 @@ return capable(CAP_SYS_RAWIO) ? 0 : -EPERM; } +#ifdef CONFIG_MOSIX +static ssize_t read_fun(struct file * file, char * buf, + size_t count, loff_t *ppos) +{ + unsigned long i, n = 0; + + if (!count) + return 0; + + if (!access_ok(VERIFY_WRITE, buf, count)) + return -EFAULT; + + while(count) + { + i = (count > 2*PAGE_SIZE ? 2*PAGE_SIZE : count); + if(copy_to_user(buf, current, i) < 0) + return(EFAULT); + buf += i; + count -= i; + n += i; + } + return(n); +} + +static ssize_t write_fun(struct file * file, const char * buf, + size_t count, loff_t *ppos) +{ + unsigned long i, n = 0; + char *page; + + if (!count) + return 0; + + if (!access_ok(VERIFY_READ, buf, count)) + return -EFAULT; + + if (!(page = (char *)__get_free_page(GFP_KERNEL))) + return(-ENOMEM); + + while(count) + { + i = (count > PAGE_SIZE ? PAGE_SIZE : count); + if(copy_from_user(page, (char *)buf, i) < 0) + { + free_page((long)page); + return(EFAULT); + } + buf += i; + count -= i; + n += i; + } + free_page((long)page); + return(n); +} +#endif /* CONFIG_MOSIX */ + #define mmap_kmem mmap_mem #define zero_lseek null_lseek #define full_lseek null_lseek @@ -572,6 +631,13 @@ write: write_full, }; +#ifdef CONFIG_MOSIX +static struct file_operations fun_fops = { + read: read_fun, + write: write_fun, +}; +#endif /* CONFIG_MOSIX */ + static int memory_open(struct inode * inode, struct file * filp) { switch (MINOR(inode->i_rdev)) { @@ -601,6 +667,11 @@ case 9: filp->f_op = &urandom_fops; break; +#ifdef CONFIG_MOSIX + case 10: + filp->f_op = &fun_fops; + break; +#endif /* CONFIG_MOSIX */ default: return -ENXIO; } diff -urN linux-2.4.17/drivers/char/pc_keyb.c linux_umopenmosix/drivers/char/pc_keyb.c --- linux-2.4.17/drivers/char/pc_keyb.c Sat Nov 10 00:01:21 2001 +++ linux_umopenmosix/drivers/char/pc_keyb.c Sun Jun 23 12:40:10 2002 @@ -525,6 +525,27 @@ spin_unlock_irq(&kbd_controller_lock); } + +#ifdef CONFIG_MOSIX_UDB +void keyboard_like_interrupt(void) +{ + unsigned char status; + unsigned char scancode; + + status = kbd_read_status(); + if(!(status & KBD_STAT_OBF)) + return; + status = kbd_read_status(); + scancode = kbd_read_input(); + + if (do_acknowledge(scancode)) + handle_scancode(scancode, !(scancode & 0x80)); + if ((status & KBD_STAT_OBF) && do_acknowledge(scancode)) + handle_scancode(scancode, !(scancode & 0x80)); + tasklet_schedule(&keyboard_tasklet); +} +#endif /* CONFIG_MOSIX_UDB */ + /* * send_data sends a character to the keyboard and waits * for an acknowledge, possibly retrying if asked to. Returns diff -urN linux-2.4.17/drivers/char/serial.c linux_umopenmosix/drivers/char/serial.c --- linux-2.4.17/drivers/char/serial.c Fri Dec 21 19:41:54 2001 +++ linux_umopenmosix/drivers/char/serial.c Sun Jun 23 12:40:10 2002 @@ -231,6 +231,10 @@ #include #include +#ifdef CONFIG_MOSIX_UDB +#include +#endif /* CONFIG_MOSIX_UDB */ + #ifdef CONFIG_MAC_SERIAL #define SERIAL_DEV_OFFSET 2 #else @@ -818,6 +822,10 @@ if (!info) return; +#if defined(CONFIG_MOSIX_UDB) && defined(CONFIG_SERIAL_CONSOLE) + if (serial_inp(info, UART_LSR) & (UART_LSR_BI | UART_LSR_FE)) + mosix_debugger("user request 1"); +#endif /* CONFIG_MOSIX_UDB && CONFIG_SERIAL_CONSOLE */ #ifdef CONFIG_SERIAL_MULTIPORT multi = &rs_multiport[irq]; if (multi->port_monitor) @@ -892,7 +900,15 @@ #endif info = IRQ_ports[irq]; +#if defined(CONFIG_MOSIX_UDB) && defined(CONFIG_SERIAL_CONSOLE) + if (!info) + return; + if (serial_inp(info, UART_LSR) & (UART_LSR_BI | UART_LSR_FE)) + mosix_debugger("user request 2"); + else if (!info->tty) +#else if (!info || !info->tty) +#endif /* CONFIG_MOSIX_UDB */ return; #ifdef CONFIG_SERIAL_MULTIPORT @@ -952,6 +968,10 @@ info = IRQ_ports[irq]; if (!info) return; +#if defined(CONFIG_MOSIX_UDB) && defined(CONFIG_SERIAL_CONSOLE) + if (serial_inp(info, UART_LSR) & (UART_LSR_BI | UART_LSR_FE)) + mosix_debugger("user request 3"); +#endif /* CONFIG_MOSIX_UDB && CONFIG_SERIAL_CONSOLE */ multi = &rs_multiport[irq]; if (!multi->port1) { /* Should never happen */ @@ -5850,6 +5870,44 @@ return c; } +#ifdef CONFIG_MOSIX_UDB +#ifdef CONFIG_SERIAL_CONSOLE +static int serial_console_read(struct console *co, const char *into, unsigned cnt) +{ + int n = 0; + struct serial_state *ser = rs_table + co->index; + int lsr; + int c; + int ier = inb(ser->port + UART_IER); + + outb(0x00, ser->port + UART_IER); + while(cnt) + { + do { + lsr = inb(ser->port + UART_LSR); + } while (!n && !(lsr & UART_LSR_DR)); + if(!(lsr & UART_LSR_DR)) + break; + c = inb(ser->port + UART_RX); + if(lsr & (UART_LSR_BI | UART_LSR_FE)) + { + mosix_debugger("recursive break"); + continue; + } + if (lsr & (UART_LSR_PE | UART_LSR_FE | UART_LSR_OE)) + { + printk("Bad input-char, status=0x%x\n", lsr); + continue; + } + ((char *)into)[n++] = c; + cnt--; + } + outb(ier, ser->port + UART_IER); + return(n); +} +#endif /* CONFIG_SERIAL_CONSOLE */ +#endif /* CONFIG_MOSIX_UDB */ + static kdev_t serial_console_device(struct console *c) { return MKDEV(TTY_MAJOR, 64 + c->index); @@ -5989,6 +6047,9 @@ static struct console sercons = { name: "ttyS", write: serial_console_write, +#ifdef CONFIG_MOSIX_UDB + read: serial_console_read, +#endif /* CONFIG_MOSIX_UDB */ device: serial_console_device, wait_key: serial_console_wait_key, setup: serial_console_setup, diff -urN linux-2.4.17/drivers/char/sysrq.c linux_umopenmosix/drivers/char/sysrq.c --- linux-2.4.17/drivers/char/sysrq.c Fri Dec 21 19:41:54 2001 +++ linux_umopenmosix/drivers/char/sysrq.c Sun Jun 23 12:40:10 2002 @@ -162,6 +162,13 @@ file_list_unlock(); DQUOT_OFF(sb); fsync_dev(sb->s_dev); +#ifdef CONFIG_MOSIX_UDB + if (sb->s_op->write_super && sb->s_dirt) + sb->s_op->write_super(sb); + if (sb->s_op->put_super) + sb->s_op->put_super(sb); + fsync_dev(sb->s_dev); +#endif /* CONFIG_MOSIX_UDB */ flags = MS_RDONLY; if (sb->s_op && sb->s_op->remount_fs) { ret = sb->s_op->remount_fs(sb, &flags, NULL); @@ -288,7 +295,11 @@ { struct task_struct *p; +#ifdef CONFIG_MOSIX + for_each_local_task(p) { +#else for_each_task(p) { +#endif /* CONFIG_MOSIX */ if (p->mm) { /* Not swapper nor kernel thread */ if (p->pid == 1 && even_init) /* Ugly hack to kill init */ diff -urN linux-2.4.17/drivers/char/tty_io.c linux_umopenmosix/drivers/char/tty_io.c --- linux-2.4.17/drivers/char/tty_io.c Fri Dec 21 19:41:54 2001 +++ linux_umopenmosix/drivers/char/tty_io.c Sun Jun 23 12:40:10 2002 @@ -497,7 +497,11 @@ } read_lock(&tasklist_lock); +#ifdef CONFIG_MOSIX + for_each_local_task(p) { +#else for_each_task(p) { +#endif /* CONFIG_MOSIX */ if ((tty->session > 0) && (p->session == tty->session) && p->leader) { send_sig(SIGHUP,p,1); @@ -595,7 +599,11 @@ tty->pgrp = -1; read_lock(&tasklist_lock); +#ifdef CONFIG_MOSIX + for_each_local_task(p) +#else for_each_task(p) +#endif /* CONFIG_MOSIX */ if (p->session == current->session) p->tty = NULL; read_unlock(&tasklist_lock); @@ -1226,7 +1234,11 @@ struct task_struct *p; read_lock(&tasklist_lock); +#ifdef CONFIG_MOSIX + for_each_local_task(p) { +#else for_each_task(p) { +#endif /* CONFIG_MOSIX */ if (p->tty == tty || (o_tty && p->tty == o_tty)) p->tty = NULL; } @@ -1566,7 +1578,11 @@ struct task_struct *p; read_lock(&tasklist_lock); +#ifdef CONFIG_MOSIX + for_each_local_task(p) +#else for_each_task(p) +#endif /* CONFIG_MOSIX */ if (p->tty == tty) p->tty = NULL; read_unlock(&tasklist_lock); @@ -1839,7 +1855,11 @@ if (tty->driver.flush_buffer) tty->driver.flush_buffer(tty); read_lock(&tasklist_lock); +#ifdef CONFIG_MOSIX + for_each_local_task(p) { +#else for_each_task(p) { +#endif /* CONFIG_MOSIX */ if ((p->tty == tty) || ((session > 0) && (p->session == session))) { send_sig(SIGKILL, p, 1); diff -urN linux-2.4.17/drivers/char/vt.c linux_umopenmosix/drivers/char/vt.c --- linux-2.4.17/drivers/char/vt.c Fri Nov 16 20:08:28 2001 +++ linux_umopenmosix/drivers/char/vt.c Sun Jun 23 12:40:10 2002 @@ -221,6 +221,10 @@ key_map[0] = U(K_ALLOCATED); for (j = 1; j < NR_KEYS; j++) key_map[j] = U(K_HOLE); +#ifdef CONFIG_MOSIX_UDB + if(s == 2 || s == 8) + key_map[69] = K_DEBUGGER|0xf000; +#endif /* CONFIG_MOSIX_UDB */ keymap_count++; } ov = U(key_map[i]); @@ -232,6 +236,10 @@ if (((ov == K_SAK) || (v == K_SAK)) && !capable(CAP_SYS_ADMIN)) return -EPERM; key_map[i] = U(v); +#ifdef CONFIG_MOSIX_UDB + if(i == 69 && (s == 2 || s == 8)) + key_map[i] = K_DEBUGGER|0xf000; +#endif /* CONFIG_MOSIX_UDB */ if (!s && (KTYP(ov) == KT_SHIFT || KTYP(v) == KT_SHIFT)) compute_shiftstate(); break; diff -urN linux-2.4.17/drivers/scsi/cpqfcTSworker.c linux_umopenmosix/drivers/scsi/cpqfcTSworker.c --- linux-2.4.17/drivers/scsi/cpqfcTSworker.c Thu Oct 25 22:53:50 2001 +++ linux_umopenmosix/drivers/scsi/cpqfcTSworker.c Sun Jun 23 12:40:10 2002 @@ -193,6 +193,9 @@ { current->fs = fs; atomic_inc(&fs->count); +#ifdef CONFIG_MOSIX + atomic_inc(&fs->users); +#endif /* CONFIG_MOSIX */ } siginitsetinv(¤t->blocked, SHUTDOWN_SIGS); diff -urN linux-2.4.17/drivers/sgi/char/graphics.c linux_umopenmosix/drivers/sgi/char/graphics.c --- linux-2.4.17/drivers/sgi/char/graphics.c Thu Oct 11 18:43:30 2001 +++ linux_umopenmosix/drivers/sgi/char/graphics.c Sun Jun 23 12:40:10 2002 @@ -152,11 +152,17 @@ * sgi_graphics_mmap */ disable_gconsole (); +#ifdef CONFIG_MOSIX + r = do_mmap_down (file, (unsigned long)vaddr, + cards[board].g_regs_size, PROT_READ|PROT_WRITE, + MAP_FIXED|MAP_PRIVATE, 0); +#else down_write(¤t->mm->mmap_sem); r = do_mmap (file, (unsigned long)vaddr, cards[board].g_regs_size, PROT_READ|PROT_WRITE, MAP_FIXED|MAP_PRIVATE, 0); up_write(¤t->mm->mmap_sem); +#endif /* CONFIG_MOSIX */ if (r) return r; } diff -urN linux-2.4.17/drivers/sgi/char/shmiq.c linux_umopenmosix/drivers/sgi/char/shmiq.c --- linux-2.4.17/drivers/sgi/char/shmiq.c Mon Aug 27 18:56:31 2001 +++ linux_umopenmosix/drivers/sgi/char/shmiq.c Sun Jun 23 12:40:11 2002 @@ -285,11 +285,16 @@ s = req.arg * sizeof (struct shmqevent) + sizeof (struct sharedMemoryInputQueue); v = sys_munmap (vaddr, s); +#ifdef CONFIG_MOSIX + do_mmap_down(filp, vaddr, s, PROT_READ | PROT_WRITE, + MAP_PRIVATE|MAP_FIXED, 0); +#else down_write(¤t->mm->mmap_sem); do_munmap(current->mm, vaddr, s); do_mmap(filp, vaddr, s, PROT_READ | PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 0); up_write(¤t->mm->mmap_sem); +#endif /* CONFIG_MOSIX */ shmiqs[minor].events = req.arg; shmiqs[minor].mapped = 1; diff -urN linux-2.4.17/drivers/usb/storage/usb.c linux_umopenmosix/drivers/usb/storage/usb.c --- linux-2.4.17/drivers/usb/storage/usb.c Sun Nov 11 20:01:32 2001 +++ linux_umopenmosix/drivers/usb/storage/usb.c Sun Jun 23 12:40:11 2002 @@ -317,6 +317,9 @@ exit_files(current); current->files = init_task.files; atomic_inc(¤t->files->count); +#ifdef CONFIG_MOSIX_DFSA + atomic_inc(¤t->files->users); +#endif /* CONFIG_MOSIX_DFSA */ daemonize(); /* set our name for identification purposes */ diff -urN linux-2.4.17/fs/Makefile linux_umopenmosix/fs/Makefile --- linux-2.4.17/fs/Makefile Mon Nov 12 19:34:16 2001 +++ linux_umopenmosix/fs/Makefile Sun Jun 23 12:40:11 2002 @@ -67,6 +67,9 @@ subdir-$(CONFIG_REISERFS_FS) += reiserfs subdir-$(CONFIG_DEVPTS_FS) += devpts subdir-$(CONFIG_SUN_OPENPROMFS) += openpromfs +ifdef CONFIG_MOSIX +subdir-$(CONFIG_MOSIX_FS) += mfs +endif obj-$(CONFIG_BINFMT_AOUT) += binfmt_aout.o diff -urN linux-2.4.17/fs/binfmt_aout.c linux_umopenmosix/fs/binfmt_aout.c --- linux-2.4.17/fs/binfmt_aout.c Sat Nov 3 03:39:20 2001 +++ linux_umopenmosix/fs/binfmt_aout.c Sun Jun 23 12:40:11 2002 @@ -29,6 +29,10 @@ #include #include +#ifdef CONFIG_MOSIX +#include +#endif /* CONFIG_MOSIX */ + static int load_aout_binary(struct linux_binprm *, struct pt_regs * regs); static int load_aout_library(struct file*); static int aout_core_dump(long signr, struct pt_regs * regs, struct file *file); @@ -108,6 +112,14 @@ dump.u_ar0 = (void *)(((unsigned long)(&dump.regs)) - ((unsigned long)(&dump))); #endif dump.signal = signr; +#ifdef CONFIG_MOSIX + if(current->mosix.dflags & DDEPUTY) + { + if(mosix_deputy_dump_thread(&dump)) + goto end_coredump; + } + else +#endif /* CONFIG_MOSIX */ dump_thread(regs, &dump); /* If the size of the dump file exceeds the rlimit, then see what would happen @@ -189,7 +201,11 @@ * memory and creates the pointer tables from them, and puts their * addresses on the "stack", returning the new stack pointer value. */ +#ifdef CONFIG_MOSIX +unsigned long * create_aout_tables(char * p, struct linux_binprm * bprm) +#else static unsigned long * create_aout_tables(char * p, struct linux_binprm * bprm) +#endif /* CONFIG_MOSIX */ { char **argv, **envp; unsigned long * sp; @@ -258,6 +274,9 @@ unsigned long fd_offset; unsigned long rlim; int retval; +#ifdef CONFIG_MOSIX + unsigned long start_stack; +#endif /* CONFIG_MOSIX */ ex = *((struct exec *) bprm->buf); /* exec-header */ if ((N_MAGIC(ex) != ZMAGIC && N_MAGIC(ex) != OMAGIC && @@ -296,6 +315,12 @@ set_personality(PER_LINUX); #endif +#ifdef CONFIG_MOSIX + if(current->mosix.dflags & DDEPUTY) + mosix_deputy_init_aout_mm(&ex); + else + { +#endif /* CONFIG_MOSIX */ current->mm->end_code = ex.a_text + (current->mm->start_code = N_TXTADDR(ex)); current->mm->end_data = ex.a_data + @@ -305,6 +330,9 @@ current->mm->rss = 0; current->mm->mmap = NULL; +#ifdef CONFIG_MOSIX + } +#endif /* CONFIG_MOSIX */ compute_creds(bprm); current->flags &= ~PF_FORKNOEXEC; #ifdef __sparc__ @@ -349,6 +377,9 @@ return error; } +// #if defined(CONFIG_MOSIX) && !defined(__i386__) +// #error On platforms where "flush_icache_range" is non-empty, code must be adjusted +// #endif /* CONFIG_MOSIX */ flush_icache_range(text_addr, text_addr+ex.a_text+ex.a_data); } else { static unsigned long error_time, error_time2; @@ -379,24 +410,38 @@ goto beyond_if; } +#ifdef CONFIG_MOSIX + error = do_mmap_down(bprm->file, N_TXTADDR(ex), ex.a_text, + PROT_READ | PROT_EXEC, + MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE, + fd_offset); +#else down_write(¤t->mm->mmap_sem); error = do_mmap(bprm->file, N_TXTADDR(ex), ex.a_text, PROT_READ | PROT_EXEC, MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE, fd_offset); up_write(¤t->mm->mmap_sem); +#endif /* CONFIG_MOSIX */ if (error != N_TXTADDR(ex)) { send_sig(SIGKILL, current, 0); return error; } +#ifdef CONFIG_MOSIX + error = do_mmap_down(bprm->file, N_DATADDR(ex), ex.a_data, + PROT_READ | PROT_WRITE | PROT_EXEC, + MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE, + fd_offset + ex.a_text); +#else down_write(¤t->mm->mmap_sem); error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE, fd_offset + ex.a_text); up_write(¤t->mm->mmap_sem); +#endif /* CONFIG_MOSIX */ if (error != N_DATADDR(ex)) { send_sig(SIGKILL, current, 0); return error; @@ -405,8 +450,27 @@ beyond_if: set_binfmt(&aout_format); +#ifdef CONFIG_MOSIX + /* if DEPUTY, the REMOTE already did "set_brk" in aout_remote_init_mm */ + if(!(current->mosix.dflags & DDEPUTY)) +#endif /* CONFIG_MOSIX */ set_brk(current->mm->start_brk, current->mm->brk); +#ifdef CONFIG_MOSIX + if(current->mosix.dflags & DDEPUTY) + { + retval = mosix_deputy_setup_args(SETUP_ARGS_AS_AOUT, + &start_stack); + if(retval < 0) + { + send_sig(SIGKILL, current, 0); + return(retval); + } + mosix_obtain_registers(START_THREAD_REGS); + } + else + { +#endif /* CONFIG_MOSIX */ retval = setup_arg_pages(bprm); if (retval < 0) { /* Someone check-me: is this error path enough? */ @@ -414,17 +478,46 @@ return retval; } +#ifdef CONFIG_MOSIX + start_stack = +#endif /* CONFIG_MOSIX */ current->mm->start_stack = (unsigned long) create_aout_tables((char *) bprm->p, bprm); +#ifdef CONFIG_MOSIX + } +#endif /* CONFIG_MOSIX */ #ifdef __alpha__ regs->gp = ex.a_gpvalue; #endif +#ifdef CONFIG_MOSIX + start_thread(regs, ex.a_entry, start_stack); +#else start_thread(regs, ex.a_entry, current->mm->start_stack); +#endif /* CONFIG_MOSIX */ if (current->ptrace & PT_PTRACED) send_sig(SIGTRAP, current, 0); return 0; } +#ifdef CONFIG_MOSIX +void +aout_remote_init_mm(struct exec *ex) +{ + register struct task_struct *p = current; + + /* in principle we should first check for the "PER_LINUX" personality */ + /* but then which LINUX does not have it??? */ + + p->mm->end_code = ex->a_text + (p->mm->start_code = N_TXTADDR(*ex)); + p->mm->end_data = ex->a_data + (p->mm->start_data = N_DATADDR(*ex)); + p->mm->brk = ex->a_bss + (p->mm->start_brk = N_BSSADDR(*ex)); + + p->mm->rss = 0; + p->mm->mmap = NULL; + set_brk(p->mm->start_brk, current->mm->brk); +} +#endif /* CONFIG_MOSIX */ + static int load_aout_library(struct file *file) { struct inode * inode; @@ -478,12 +571,19 @@ goto out; } /* Now use mmap to map the library into memory. */ +#ifdef CONFIG_MOSIX + error = do_mmap_down(file, start_addr, ex.a_text + ex.a_data, + PROT_READ | PROT_WRITE | PROT_EXEC, + MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE, + N_TXTOFF(ex)); +#else down_write(¤t->mm->mmap_sem); error = do_mmap(file, start_addr, ex.a_text + ex.a_data, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE, N_TXTOFF(ex)); up_write(¤t->mm->mmap_sem); +#endif /* CONFIG_MOSIX */ retval = error; if (error != start_addr) goto out; diff -urN linux-2.4.17/fs/binfmt_elf.c linux_umopenmosix/fs/binfmt_elf.c --- linux-2.4.17/fs/binfmt_elf.c Fri Dec 21 19:41:55 2001 +++ linux_umopenmosix/fs/binfmt_elf.c Sun Jun 23 12:40:11 2002 @@ -42,6 +42,10 @@ #include +#ifdef CONFIG_MOSIX +#include +#endif /* CONFIG_MOSIX */ + static int load_elf_binary(struct linux_binprm * bprm, struct pt_regs * regs); static int load_elf_library(struct file*); static unsigned long elf_map (struct file *, unsigned long, struct elf_phdr *, int, int); @@ -106,12 +110,17 @@ } } -static elf_addr_t * +static elf_addr_t * create_elf_tables(char *p, int argc, int envc, struct elfhdr * exec, unsigned long load_addr, unsigned long load_bias, +#ifdef CONFIG_MOSIX + unsigned long interp_load_addr, int ibcs, + struct elf_tables_extras *extras) +#else unsigned long interp_load_addr, int ibcs) +#endif /* CONFIG_MOSIX */ { elf_caddr_t *argv; elf_caddr_t *envp; @@ -123,13 +132,18 @@ /* * Get hold of platform and hardware capabilities masks for - * the machine we are running on. In some cases (Sparc), + * the machine we are running on. In some cases (Sparc), * this info is impossible to get, in others (i386) it is * merely difficult. */ +#ifdef CONFIG_MOSIX + hwcap = extras->hwcap; + k_platform = extras->platform; +#else hwcap = ELF_HWCAP; k_platform = ELF_PLATFORM; +#endif /* CONFIG_MOSIX */ if (k_platform) { platform_len = strlen(k_platform) + 1; @@ -176,12 +190,19 @@ NEW_AUX_ENT( 6, AT_BASE, interp_load_addr); NEW_AUX_ENT( 7, AT_FLAGS, 0); NEW_AUX_ENT( 8, AT_ENTRY, load_bias + exec->e_entry); +#ifdef CONFIG_MOSIX + NEW_AUX_ENT(9, AT_UID, (elf_addr_t) extras->uid); + NEW_AUX_ENT(10, AT_EUID, (elf_addr_t) extras->euid); + NEW_AUX_ENT(11, AT_GID, (elf_addr_t) extras->gid); + NEW_AUX_ENT(12, AT_EGID, (elf_addr_t) extras->egid); +#else NEW_AUX_ENT( 9, AT_UID, (elf_addr_t) current->uid); NEW_AUX_ENT(10, AT_EUID, (elf_addr_t) current->euid); NEW_AUX_ENT(11, AT_GID, (elf_addr_t) current->gid); NEW_AUX_ENT(12, AT_EGID, (elf_addr_t) current->egid); +#endif /* CONFIG_MOSIX */ #ifdef ARCH_DLINFO - /* + /* * ARCH_DLINFO must come last so platform specific code can enforce * special alignment requirements on the AUXV if necessary (eg. PPC). */ @@ -228,11 +249,17 @@ { unsigned long map_addr; +#ifdef CONFIG_MOSIX + map_addr = do_mmap_down(filep, ELF_PAGESTART(addr), + eppnt->p_filesz + ELF_PAGEOFFSET(eppnt->p_vaddr), prot, + type, eppnt->p_offset - ELF_PAGEOFFSET(eppnt->p_vaddr)); +#else down_write(¤t->mm->mmap_sem); map_addr = do_mmap(filep, ELF_PAGESTART(addr), eppnt->p_filesz + ELF_PAGEOFFSET(eppnt->p_vaddr), prot, type, eppnt->p_offset - ELF_PAGEOFFSET(eppnt->p_vaddr)); up_write(¤t->mm->mmap_sem); +#endif /* CONFIG_MOSIX */ return(map_addr); } @@ -334,7 +361,7 @@ /* * Now fill out the bss section. First pad the last page up * to the page boundary, and then perform a mmap to make sure - * that there are zero-mapped pages up to and including the + * that there are zero-mapped pages up to and including the * last bss page. */ padzero(elf_bss); @@ -361,10 +388,23 @@ loff_t offset; int retval; +#ifdef CONFIG_MOSIX + if(current->mosix.dflags & DDEPUTY) + mosix_deputy_fix_elf_aout_interp(interp_ex->a_bss, + interp_ex->a_data, interp_ex->a_text); + else +#endif /* CONFIG_MOSIX */ current->mm->end_code = interp_ex->a_text; text_data = interp_ex->a_text + interp_ex->a_data; +#ifdef CONFIG_MOSIX + if(!current->mosix.dflags & DDEPUTY) + { +#endif /* CONFIG_MOSIX */ current->mm->end_data = text_data; current->mm->brk = interp_ex->a_bss + text_data; +#ifdef CONFIG_MOSIX + } +#endif /* CONFIG_MOSIX */ switch (N_MAGIC(*interp_ex)) { case OMAGIC: @@ -387,6 +427,12 @@ retval = interpreter->f_op->read(interpreter, addr, text_data, &offset); if (retval < 0) goto out; +#ifdef CONFIG_MOSIX +// #ifndef __i386__ +// #On platforms where "flush_icache_range" is non-empty, +// #it has to distributed and run REMOTELY. +// #endif /* __i386__ */ +#endif /* CONFIG_MOSIX */ flush_icache_range((unsigned long)addr, (unsigned long)addr + text_data); @@ -428,7 +474,10 @@ struct elfhdr interp_elf_ex; struct exec interp_ex; char passed_fileno[6]; - +#ifdef CONFIG_MOSIX + struct elf_tables_extras extras; +#endif /* CONFIG_MOSIX */ + /* Get the exec-header */ elf_ex = *((struct elfhdr *) bprm->buf); @@ -513,6 +562,9 @@ struct fs_struct *old_fs = current->fs, *new_fs; get_exec_domain(old_domain); atomic_inc(&old_fs->count); +#ifdef CONFIG_MOSIX_DFSA + atomic_inc(&old_fs->users); +#endif /* CONFIG_MOSIX_DFSA */ set_personality(PER_SVR4); interpreter = open_exec(elf_interpreter); @@ -523,7 +575,11 @@ current->exec_domain = old_domain; current->fs = old_fs; put_exec_domain(new_domain); +#ifdef CONFIG_MOSIX_DFSA + put_used_fs_struct(new_fs); +#else put_fs_struct(new_fs); +#endif /* CONFIG_MOSIX_DFSA */ } else #endif { @@ -583,7 +639,7 @@ if (elf_interpreter) { retval = copy_strings_kernel(1,&passed_p,bprm); if (retval) - goto out_free_dentry; + goto out_free_dentry; bprm->argc++; } } @@ -595,6 +651,22 @@ goto out_free_dentry; /* OK, This is the point of no return */ +#ifdef CONFIG_MOSIX + if(current->mosix.dflags & DDEPUTY) + { + current->flags &= ~PF_FORKNOEXEC; + elf_entry = (unsigned long) elf_ex.e_entry; + SET_PERSONALITY(elf_ex, ibcs2_interpreter); + mosix_deputy_setup_args(SETUP_ARGS_AS_ELF, NULL); + if(IS_ERR((const unsigned *)bprm->p)) + { + send_sig(SIGKILL, current, 0); + return(0); /* too late for error */ + } + } + else + { +#endif /* CONFIG_MOSIX */ current->mm->start_data = 0; current->mm->end_data = 0; current->mm->end_code = 0; @@ -611,6 +683,9 @@ current->mm->rss = 0; setup_arg_pages(bprm); /* XXX: check error */ current->mm->start_stack = bprm->p; +#ifdef CONFIG_MOSIX + } +#endif /* CONFIG_MOSIX */ /* Now we do a little grungy work by mmaping the ELF image into the correct location in memory. At this point, we assume that @@ -626,7 +701,7 @@ if (unlikely (elf_brk > elf_bss)) { unsigned long nbyte; - + /* There was a PT_LOAD segment with p_memsz > p_filesz before this one. Map anonymous pages, if needed, and clear the area. */ @@ -724,6 +799,26 @@ compute_creds(bprm); current->flags &= ~PF_FORKNOEXEC; +#ifdef CONFIG_MOSIX + extras.uid = current->uid; + extras.euid = current->euid; + extras.gid = current->gid; + extras.egid = current->egid; + extras.hwcap = ELF_HWCAP; + memcpy(extras.platform, ELF_PLATFORM, sizeof(extras.platform)); + extras.platform[sizeof(extras.platform)-1] = '\0'; + if(current->mosix.dflags & DDEPUTY) + bprm->p = mosix_deputy_elf_setup((char *)bprm->p, + bprm->argc, bprm->envc, &elf_ex, + load_addr, load_bias, interp_load_addr, + (interpreter_type == INTERPRETER_AOUT ? 0 : 1), + interpreter_type == INTERPRETER_AOUT ? + strlen(passed_fileno) + 1 : 0, + elf_brk, end_code, start_code, start_data, end_data, elf_bss, + current->personality, &extras); + if(!(current->mosix.dflags & DDEPUTY)) /* must check again! */ + { +#endif /* CONFIG_MOSIX */ bprm->p = (unsigned long) create_elf_tables((char *)bprm->p, bprm->argc, @@ -731,7 +826,12 @@ &elf_ex, load_addr, load_bias, interp_load_addr, +#ifdef CONFIG_MOSIX + (interpreter_type == INTERPRETER_AOUT ? 0 : 1), + &extras); +#else (interpreter_type == INTERPRETER_AOUT ? 0 : 1)); +#endif /* CONFIG_MOSIX */ /* N.B. passed_fileno might not be initialized? */ if (interpreter_type == INTERPRETER_AOUT) current->mm->arg_start += strlen(passed_fileno) + 1; @@ -765,11 +865,21 @@ Since we do not have the power to recompile these, we emulate the SVr4 behavior. Sigh. */ /* N.B. Shouldn't the size here be PAGE_SIZE?? */ +#ifdef CONFIG_MOSIX + error = do_mmap_down(NULL, 0, 4096, PROT_READ | PROT_EXEC, + MAP_FIXED | MAP_PRIVATE, 0); +#else down_write(¤t->mm->mmap_sem); error = do_mmap(NULL, 0, 4096, PROT_READ | PROT_EXEC, MAP_FIXED | MAP_PRIVATE, 0); up_write(¤t->mm->mmap_sem); +#endif /* CONFIG_MOSIX */ + } + +#ifdef CONFIG_MOSIX } + mosix_obtain_registers(START_THREAD_REGS|ELF_PLAT_INIT_REGS); +#endif /* CONFIG_MOSIX */ #ifdef ELF_PLAT_INIT /* @@ -802,6 +912,69 @@ goto out; } +#ifdef CONFIG_MOSIX +/* + * the following routine is the remote portion of part of "do_load_elf_binary" + * and must be updated with changes to the former. + */ +unsigned long +elf_remote_setup(char *p, int argc, int envc, struct elfhdr *exec, + unsigned long load_addr, unsigned long load_bias, + unsigned long interp_load_addr, int ibcs, int add_arg_start, + unsigned long elf_brk, unsigned long end_code, unsigned long start_code, + unsigned long start_data, unsigned long end_data, unsigned long elf_bss, + unsigned long personality, struct elf_tables_extras *extras) +{ + unsigned long ret; + struct exec_domain *new_domain = lookup_exec_domain(personality); + + if(!new_domain) + mosix_go_home(2); /* never returns */ + + if (current->exec_domain && current->exec_domain->module) + __MOD_DEC_USE_COUNT(current->exec_domain->module); + current->exec_domain = new_domain; + if (new_domain->module) + __MOD_INC_USE_COUNT(new_domain->module); + ret = (unsigned long)create_elf_tables(p, argc, envc, exec, load_addr, + load_bias, interp_load_addr, ibcs, extras); + current->mm->arg_start += add_arg_start; + current->mm->start_brk = current->mm->brk = elf_brk; + current->mm->end_code = end_code; + current->mm->start_code = start_code; + current->mm->start_data = start_data; + current->mm->end_data = end_data; + current->mm->start_stack = (unsigned long)p; + + /* Calling set_brk effectively mmaps the pages that we need for the bss and break + sections */ + set_brk(elf_bss, elf_brk); + + padzero(elf_bss); + +#if 0 + printk("(start_brk) %x\n" , current->mm->start_brk); + printk("(end_code) %x\n" , current->mm->end_code); + printk("(start_code) %x\n" , current->mm->start_code); + printk("(end_data) %x\n" , current->mm->end_data); + printk("(start_stack) %x\n" , current->mm->start_stack); + printk("(brk) %x\n" , current->mm->brk); +#endif + + if ( personality == PER_SVR4 ) + { + /* Why this, you ask??? Well SVr4 maps page 0 as read-only, + and some applications "depend" upon this behavior. + Since we do not have the power to recompile these, we + emulate the SVr4 behavior. Sigh. */ + /* N.B. Shouldn't the size here be PAGE_SIZE?? */ + do_mmap(NULL, 0, 4096, PROT_READ | PROT_EXEC, + MAP_FIXED | MAP_PRIVATE, 0); + } + return(ret); +} +#endif /* CONFIG_MOSIX */ + /* This is really simpleminded and specialized - we are loading an a.out library that is given an ELF header. */ @@ -848,6 +1021,16 @@ while (elf_phdata->p_type != PT_LOAD) elf_phdata++; /* Now use mmap to map the library into memory. */ +#ifdef CONFIG_MOSIX + error = do_mmap_down(file, + ELF_PAGESTART(elf_phdata->p_vaddr), + (elf_phdata->p_filesz + + ELF_PAGEOFFSET(elf_phdata->p_vaddr)), + PROT_READ | PROT_WRITE | PROT_EXEC, + MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE, + (elf_phdata->p_offset - + ELF_PAGEOFFSET(elf_phdata->p_vaddr))); +#else down_write(¤t->mm->mmap_sem); error = do_mmap(file, ELF_PAGESTART(elf_phdata->p_vaddr), @@ -858,6 +1041,7 @@ (elf_phdata->p_offset - ELF_PAGEOFFSET(elf_phdata->p_vaddr))); up_write(¤t->mm->mmap_sem); +#endif /* CONFIG_MOSIX */ if (error != ELF_PAGESTART(elf_phdata->p_vaddr)) goto out_free_ph; @@ -937,6 +1121,14 @@ #define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) +#ifdef CONFIG_MOSIX +int +elf_maydump(struct vm_area_struct *vma) +{ + return(maydump(vma)); +} +#endif /* CONFIG_MOSIX */ + /* An ELF note in memory */ struct memelfnote { @@ -1031,17 +1223,60 @@ struct elf_prstatus prstatus; /* NT_PRSTATUS */ elf_fpregset_t fpu; /* NT_PRFPREG */ struct elf_prpsinfo psinfo; /* NT_PRPSINFO */ +#ifdef CONFIG_MOSIX + struct vmalist *vmas = NULL, *rvma; + unsigned long arg_start, arg_end; +#endif /* CONFIG_MOSIX */ + +#ifdef CONFIG_MOSIX + if(current->mosix.dflags & DDEPUTY) + { + segs = 0; + mosix_deputy_rusage(0); + if((i=mosix_deputy_list_vmas(&vmas, &arg_start, &arg_end)) < 0) + { + MOD_DEC_USE_COUNT; + return(0); + } + for(rvma = vmas ; i-- > 0 ; rvma++) + { + if(rvma->maydump) + { + int sz = rvma->vmend - rvma->vmstart; + if (size+sz >= limit) + break; + else + size += sz; + } + segs++; + } + vma = NULL; /* to satisfy the silly compiler */ + } + else +#endif /* CONFIG_MOSIX */ /* first copy the parameters from user space */ memset(&psinfo, 0, sizeof(psinfo)); { int i, len; +#ifdef CONFIG_MOSIX + if(current->mosix.dflags & DDEPUTY) + len = arg_end - arg_start; + else +#endif /* CONFIG_MOSIX */ len = current->mm->arg_end - current->mm->arg_start; if (len >= ELF_PRARGSZ) len = ELF_PRARGSZ-1; +#ifdef CONFIG_MOSIX + copy_from_user(&psinfo.pr_psargs, + (current->mosix.dflags & DDEPUTY) ? + (const char *)arg_start : + (const char *)current->mm->arg_start, len); +#else copy_from_user(&psinfo.pr_psargs, (const char *)current->mm->arg_start, len); +#endif /* CONFIG_MOSIX */ for(i = 0; i < len; i++) if (psinfo.pr_psargs[i] == 0) psinfo.pr_psargs[i] = ' '; @@ -1118,6 +1353,9 @@ * This transfers the registers from regs into the standard * coredump arrangement, whatever that is. */ +#ifdef CONFIG_MOSIX + mosix_obtain_registers(ALL_REGISTERS); +#endif /* CONFIG_MOSIX */ #ifdef ELF_CORE_COPY_REGS ELF_CORE_COPY_REGS(prstatus.pr_reg, regs) #else @@ -1139,7 +1377,12 @@ notes[1].type = NT_PRPSINFO; notes[1].datasz = sizeof(psinfo); notes[1].data = &psinfo; +#ifdef CONFIG_MOSIX + i = LOGICAL_STATE(current); + i = i ? ffz(~i) + 1 : 0; +#else i = current->state ? ffz(~current->state) + 1 : 0; +#endif /* CONFIG_MOSIX */ psinfo.pr_state = i; psinfo.pr_sname = (i < 0 || i > 5) ? '.' : "RSDZTD"[i]; psinfo.pr_zomb = psinfo.pr_sname == 'Z'; @@ -1155,6 +1398,11 @@ notes[2].data = current; /* Try to dump the FPU. */ +#ifdef CONFIG_MOSIX + if(current->mosix.dflags & DDEPUTY) + prstatus.pr_fpvalid = mosix_deputy_dump_fpu(&fpu); + else +#endif /* CONFIG_MOSIX */ prstatus.pr_fpvalid = dump_fpu (regs, &fpu); if (!prstatus.pr_fpvalid) { @@ -1167,7 +1415,7 @@ notes[3].datasz = sizeof(fpu); notes[3].data = &fpu; } - + /* Write notes phdr entry */ { struct elf_phdr phdr; @@ -1193,6 +1441,30 @@ dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE); /* Write program headers for segments dump */ +#ifdef CONFIG_MOSIX + if(current->mosix.dflags & DDEPUTY) + for(rvma = vmas , i = 0 ; i < segs ; rvma++ , i++) { + struct elf_phdr phdr; + size_t sz; + + sz = rvma->vmend - rvma->vmstart; + + phdr.p_type = PT_LOAD; + phdr.p_offset = offset; + phdr.p_vaddr = rvma->vmstart; + phdr.p_paddr = 0; + phdr.p_filesz = rvma->maydump ? sz : 0; + phdr.p_memsz = sz; + offset += phdr.p_filesz; + phdr.p_flags = (rvma->vmflags & VM_READ) ? PF_R : 0; + if (rvma->vmflags & VM_WRITE) phdr.p_flags |= PF_W; + if (rvma->vmflags & VM_EXEC) phdr.p_flags |= PF_X; + phdr.p_align = ELF_EXEC_PAGESIZE; + + DUMP_WRITE(&phdr, sizeof(phdr)); + } + else +#endif /* CONFIG_MOSIX */ for(vma = current->mm->mmap; vma != NULL; vma = vma->vm_next) { struct elf_phdr phdr; size_t sz; @@ -1220,6 +1492,23 @@ DUMP_SEEK(dataoff); +#ifdef CONFIG_MOSIX + if(current->mosix.dflags & DDEPUTY) + { + for(i = 0 , rvma = vmas ; i < segs ; rvma++ , i++) + if(rvma->maydump) + { + unsigned long addr = rvma->vmstart; + unsigned long len = rvma->vmend - rvma->vmstart; + +#ifdef DEBUG + printk("elf_core_dump: writing %08lx %lx\n", addr, len); +#endif + DUMP_WRITE((void *)addr, len); + } + } + else +#endif /* CONFIG_MOSIX */ for(vma = current->mm->mmap; vma != NULL; vma = vma->vm_next) { unsigned long addr; @@ -1260,6 +1549,10 @@ } end_coredump: +#ifdef CONFIG_MOSIX + if(vmas) + kfree(vmas); +#endif /* CONFIG_MOSIX */ set_fs(fs); up_write(¤t->mm->mmap_sem); return has_dumped; diff -urN linux-2.4.17/fs/buffer.c linux_umopenmosix/fs/buffer.c --- linux-2.4.17/fs/buffer.c Fri Dec 21 19:41:55 2001 +++ linux_umopenmosix/fs/buffer.c Sun Jun 23 12:40:11 2002 @@ -53,6 +53,10 @@ #include #include +#ifdef CONFIG_MOSIX_DFSA +#include +#endif /* CONFIG_MOSIX_DFSA */ + #define MAX_BUF_PER_PAGE (PAGE_CACHE_SIZE / 512) #define NR_RESERVED (10*MAX_BUF_PER_PAGE) #define MAX_UNUSED_BUFFERS NR_RESERVED+20 /* don't ever have more than this @@ -403,6 +407,9 @@ struct inode * inode; int err; +#ifdef CONFIG_MOSIX_DFSA + dfsa_syscall_on_file(fd, 0); +#endif /* CONFIG_MOSIX_DFSA */ err = -EBADF; file = fget(fd); if (!file) @@ -435,6 +442,9 @@ struct inode * inode; int err; +#ifdef CONFIG_MOSIX_DFSA + dfsa_syscall_on_file(fd, 0); +#endif /* CONFIG_MOSIX_DFSA */ err = -EBADF; file = fget(fd); if (!file) diff -urN linux-2.4.17/fs/dcache.c linux_umopenmosix/fs/dcache.c --- linux-2.4.17/fs/dcache.c Fri Dec 21 19:41:55 2001 +++ linux_umopenmosix/fs/dcache.c Sun Jun 23 12:40:11 2002 @@ -26,6 +26,10 @@ #include +#ifdef CONFIG_MOSIX +#include +#endif /* CONFIG_MOSIX */ + #define DCACHE_PARANOIA 1 /* #define DCACHE_DEBUG 1 */ @@ -834,6 +838,11 @@ void d_rehash(struct dentry * entry) { struct list_head *list = d_hash(entry->d_parent, entry->d_name.hash); + +#ifdef CONFIG_MOSIX_FS + if(entry->d_flags & DCACHE_NO_CACHE) + return; +#endif /* CONFIG_MOSIX_FS */ if (!list_empty(&entry->d_hash)) BUG(); spin_lock(&dcache_lock); list_add(&entry->d_hash, list); @@ -906,6 +915,9 @@ spin_lock(&dcache_lock); /* Move the dentry to the target hash queue */ list_del(&dentry->d_hash); +#ifdef CONFIG_MOSIX_FS + if(!(dentry->d_flags & DCACHE_NO_CACHE)) +#endif /* CONFIG_MOSIX_FS */ list_add(&dentry->d_hash, &target->d_hash); /* Unhash the target: dput() will then get rid of it */ @@ -951,6 +963,9 @@ *--end = '\0'; buflen--; +#ifdef CONFIG_MOSIX_FS + if (!(dentry->d_flags & DCACHE_NO_CACHE)) +#endif /* CONFIG_MOSIX_FS */ if (!IS_ROOT(dentry) && list_empty(&dentry->d_hash)) { buflen -= 10; end -= 10; @@ -1022,19 +1037,40 @@ char *page = (char *) __get_free_page(GFP_USER); if (!page) +#ifdef CONFIG_MOSIX_DFSA + return ((current->mosix.dflags & DREMOTE) ? + -EDOITATHOME : -ENOMEM); +#else return -ENOMEM; +#endif /* CONFIG_MOSIX_DFSA */ read_lock(¤t->fs->lock); +#ifdef CONFIG_MOSIX_DFSA + if(!current->fs->pwd) /* we are REMOTE and not on a DFSA FS! */ + { + read_unlock(¤t->fs->lock); + return(-EDOITATHOME); + } +#endif /* CONFIG_MOSIX_DFSA */ pwdmnt = mntget(current->fs->pwdmnt); pwd = dget(current->fs->pwd); rootmnt = mntget(current->fs->rootmnt); root = dget(current->fs->root); read_unlock(¤t->fs->lock); +#if defined(CONFIG_MOSIX_DFSA) || defined(CONFIG_MOSIX_FS) + if(pwd->d_inode->i_op && pwd->d_inode->i_op->check_path) + pwd->d_inode->i_op->check_path(pwd); +#endif /* CONFIG_MOSIX_DFSA || CONFIG_MOSIX_FS */ error = -ENOENT; /* Has the current directory has been unlinked? */ spin_lock(&dcache_lock); +#ifdef CONFIG_MOSIX_FS + if (pwd->d_parent == pwd || !list_empty(&pwd->d_hash) || + (pwd->d_flags & DCACHE_NO_CACHE)) { +#else if (pwd->d_parent == pwd || !list_empty(&pwd->d_hash)) { +#endif /* CONFIG_MOSIX_FS */ unsigned long len; char * cwd; diff -urN linux-2.4.17/fs/dnotify.c linux_umopenmosix/fs/dnotify.c --- linux-2.4.17/fs/dnotify.c Wed Nov 8 09:27:57 2000 +++ linux_umopenmosix/fs/dnotify.c Sun Jun 23 12:40:11 2002 @@ -20,6 +20,10 @@ #include #include +#ifdef CONFIG_MOSIX_FS +#include +#endif /* CONFIG_MOSIX_FS */ + extern void send_sigio(struct fown_struct *fown, int fd, int band); int dir_notify_enable = 1; @@ -51,6 +55,10 @@ inode = filp->f_dentry->d_inode; if (!S_ISDIR(inode->i_mode)) return -ENOTDIR; +#ifdef CONFIG_MOSIX_FS + if(inode->i_sb->s_magic == MFS_SUPER_MAGIC) + return(-EPERM); +#endif /* CONFIG_MOSIX_FS */ if (!turning_off) { dn = kmem_cache_alloc(dn_cache, SLAB_KERNEL); if (dn == NULL) diff -urN linux-2.4.17/fs/exec.c linux_umopenmosix/fs/exec.c --- linux-2.4.17/fs/exec.c Fri Dec 21 19:41:55 2001 +++ linux_umopenmosix/fs/exec.c Sun Jun 23 12:40:11 2002 @@ -19,7 +19,7 @@ * current->executable is only used by the procfs. This allows a dispatch * table to check for several different types of binary formats. We keep * trying until we recognize the file or we run out of supported binary - * formats. + * formats. */ #include @@ -47,6 +47,12 @@ #endif int core_uses_pid; +#ifdef CONFIG_MOSIX +#include +#endif /* CONFIG_MOSIX */ +#ifdef CONFIG_MOSIX_DFSA +#include +#endif /* CONFIG_MOSIX_DFSA */ static struct linux_binfmt *formats; static rwlock_t binfmt_lock = RW_LOCK_UNLOCKED; @@ -70,7 +76,7 @@ fmt->next = formats; formats = fmt; write_unlock(&binfmt_lock); - return 0; + return 0; } int unregister_binfmt(struct linux_binfmt * fmt) @@ -125,6 +131,9 @@ if (IS_ERR(file)) goto out; +#ifdef CONFIG_MOSIX_DFSA + current->mosix.dflags &= ~DSTATSDOWN; /* NOT a DFSA system-call */ +#endif /* CONFIG_MOSIX_DFSA */ error = -ENOEXEC; if(file->f_op && file->f_op->read) { struct linux_binfmt * fmt; @@ -180,7 +189,7 @@ * memory to free pages in kernel mem. These are in a format ready * to be put directly into the top of new user memory. */ -int copy_strings(int argc,char ** argv, struct linux_binprm *bprm) +int copy_strings(int argc,char ** argv, struct linux_binprm *bprm) { while (argc-- > 0) { char *str; @@ -189,11 +198,11 @@ if (get_user(str, argv+argc) || !(len = strnlen_user(str, bprm->p))) return -EFAULT; - if (bprm->p < len) - return -E2BIG; + if (bprm->p < len) + return -E2BIG; bprm->p -= len; - /* XXX: add architecture specific overflow check here. */ + /* XXX: add architecture specific overflow check here. */ pos = bprm->p; while (len > 0) { @@ -227,7 +236,7 @@ kunmap(page); if (err) - return -EFAULT; + return -EFAULT; pos += bytes_to_copy; str += bytes_to_copy; @@ -244,10 +253,10 @@ { int r; mm_segment_t oldfs = get_fs(); - set_fs(KERNEL_DS); + set_fs(KERNEL_DS); r = copy_strings(argc, argv, bprm); set_fs(oldfs); - return r; + return r; } /* @@ -305,9 +314,9 @@ bprm->exec += stack_base; mpnt = kmem_cache_alloc(vm_area_cachep, SLAB_KERNEL); - if (!mpnt) - return -ENOMEM; - + if (!mpnt) + return -ENOMEM; + down_write(¤t->mm->mmap_sem); { mpnt->vm_mm = current->mm; @@ -321,7 +330,7 @@ mpnt->vm_private_data = (void *) 0; insert_vm_struct(current->mm, mpnt); current->mm->total_vm = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT; - } + } for (i = 0 ; i < MAX_ARG_PAGES ; i++) { struct page *page = bprm->page[i]; @@ -332,7 +341,7 @@ stack_base += PAGE_SIZE; } up_write(¤t->mm->mmap_sem); - + return 0; } @@ -343,7 +352,16 @@ struct file *file; int err = 0; +#ifdef CONFIG_MOSIX_FS + /* if file is MFS, we need to complete in order to perform the "open" + * method of dentry_open (which is NULL on MFS itself) */ + nd.express_function = EF_OPEN; + nd.complete_args.ints.i1 = O_RDONLY+1; + nd.complete_args.ints.i2 = 0; + if (path_init(name, LOOKUP_FOLLOW|LOOKUP_POSITIVE|LOOKUP_COMPLETE, &nd)) +#else if (path_init(name, LOOKUP_FOLLOW|LOOKUP_POSITIVE, &nd)) +#endif /* CONFIG_MOSIX_FS */ err = path_walk(name, &nd); file = ERR_PTR(err); if (!err) { @@ -390,7 +408,11 @@ return result; } +#ifdef CONFIG_MOSIX +int exec_mmap(void) +#else static int exec_mmap(void) +#endif /* CONFIG_MOSIX */ { struct mm_struct * mm, * old_mm; @@ -398,6 +420,9 @@ if (old_mm && atomic_read(&old_mm->mm_users) == 1) { mm_release(); exit_mmap(old_mm); +#ifdef CONFIG_MOSIX + mosix_exec_mmap(NULL); +#endif /* CONFIG_MOSIX */ return 0; } @@ -423,6 +448,9 @@ task_unlock(current); activate_mm(active_mm, mm); mm_release(); +#ifdef CONFIG_MOSIX + mosix_exec_mmap(old_mm); +#endif /* CONFIG_MOSIX */ if (old_mm) { if (active_mm != old_mm) BUG(); mmput(old_mm); @@ -440,7 +468,7 @@ * disturbing other processes. (Other processes might share the signal * table via the CLONE_SIGNAL option to clone().) */ - + static inline int make_private_signals(void) { struct signal_struct * newsig; @@ -458,7 +486,7 @@ spin_unlock_irq(¤t->sigmask_lock); return 0; } - + /* * If make_private_signals() made a copy of the signal table, decrement the * refcount of the original table, and free it if necessary. @@ -541,9 +569,16 @@ retval = make_private_signals(); if (retval) goto flush_failed; - /* + /* * Release all of the old mmap stuff */ +#ifdef CONFIG_MOSIX + if(!(current->mosix.dflags & DDEPUTY)) + mosix_clear_statistics(); + if(current->mosix.dflags & DDEPUTY) + retval = mosix_deputy_exec_mmap(bprm->filename); + else +#endif /* CONFIG_MOSIX */ retval = exec_mmap(); if (retval) goto mmap_failed; @@ -553,7 +588,11 @@ current->sas_ss_sp = current->sas_ss_size = 0; if (current->euid == current->uid && current->egid == current->gid) +#ifdef CONFIG_MOSIX + set_me_dumpable(1); +#else current->mm->dumpable = 1; +#endif /* CONFIG_MOSIX */ name = bprm->filename; for (i=0; (ch = *(name++)) != '\0';) { if (ch == '/') @@ -563,20 +602,27 @@ current->comm[i++] = ch; } current->comm[i] = '\0'; +#ifdef CONFIG_MOSIX + tell_process(current, DREQ_INFOCNG); +#endif /* CONFIG_MOSIX */ flush_thread(); de_thread(current); - if (bprm->e_uid != current->euid || bprm->e_gid != current->egid || + if (bprm->e_uid != current->euid || bprm->e_gid != current->egid || permission(bprm->file->f_dentry->d_inode,MAY_READ)) +#ifdef CONFIG_MOSIX + set_me_dumpable(0); +#else current->mm->dumpable = 0; +#endif /* CONFIG_MOSIX */ /* An exec changes our domain. We are no longer part of the thread group */ - + current->self_exec_id++; - + flush_signal_handlers(current); flush_old_files(current->files); @@ -602,8 +648,8 @@ return (p->ptrace & PT_PTRACED) && !(p->ptrace & PT_PTRACE_CAP); } -/* - * Fill the binprm structure from the inode. +/* + * Fill the binprm structure from the inode. * Check permissions, then read the first 128 (BINPRM_BUF_SIZE) bytes */ int prepare_binprm(struct linux_binprm *bprm) @@ -657,7 +703,7 @@ cap_set_full(bprm->cap_inheritable); cap_set_full(bprm->cap_permitted); } - if (bprm->e_uid == 0) + if (bprm->e_uid == 0) cap_set_full(bprm->cap_effective); } @@ -680,7 +726,7 @@ * */ -void compute_creds(struct linux_binprm *bprm) +void compute_creds(struct linux_binprm *bprm) { kernel_cap_t new_permitted, working; int do_unlock = 0; @@ -692,12 +738,21 @@ if (bprm->e_uid != current->uid || bprm->e_gid != current->gid || !cap_issubset(new_permitted, current->cap_permitted)) { +#ifdef CONFIG_MOSIX + set_me_dumpable(0); +#else current->mm->dumpable = 0; - +#endif /* CONFIG_MOSIX */ + lock_kernel(); if (must_not_trace_exec(current) +#ifdef CONFIG_MOSIX_DFSA + || atomic_read(¤t->fs->users) > 1 + || atomic_read(¤t->files->users) > 1 +#else || atomic_read(¤t->fs->count) > 1 || atomic_read(¤t->files->count) > 1 +#endif /* CONFIG_MOSIX_DFSA */ || atomic_read(¤t->sig->count) > 1) { if(!capable(CAP_SETUID)) { bprm->e_uid = current->uid; @@ -720,9 +775,15 @@ current->cap_effective = cap_intersect(new_permitted, bprm->cap_effective); } - + /* AUD: Audit candidate if current->cap_effective is set */ +#ifdef CONFIG_MOSIX + tell_process(current, DREQ_CAPCNG|DREQ_INFOCNG); +#endif /* CONFIG_MOSIX */ +#ifdef CONFIG_MOSIX_DFSA + current->mosix.dupdates |= DFSA_UPDCRED; +#endif /* CONFIG_MOSIX_DFSA */ current->suid = current->euid = current->fsuid = bprm->e_uid; current->sgid = current->egid = current->fsgid = bprm->e_gid; @@ -867,13 +928,26 @@ return retval; bprm.p = PAGE_SIZE*MAX_ARG_PAGES-sizeof(void *); - memset(bprm.page, 0, MAX_ARG_PAGES*sizeof(bprm.page[0])); + memset(bprm.page, 0, MAX_ARG_PAGES*sizeof(bprm.page[0])); bprm.file = file; bprm.filename = filename; bprm.sh_bang = 0; bprm.loader = 0; bprm.exec = 0; +#ifdef CONFIG_MOSIX + if(current->mosix.dflags & DDEPUTY) + { + mosix_deputy_count_args(argv, envp, &bprm.argc, &bprm.envc); + if(bprm.argc < 0 || bprm.envc < 0) + { + allow_write_access(file); + fput(file); + return(bprm.argc < 0 ? bprm.argc : bprm.envc); + } + goto counted; + } +#endif /* CONFIG_MOSIX */ if ((bprm.argc = count(argv, bprm.p / sizeof(void *))) < 0) { allow_write_access(file); fput(file); @@ -885,30 +959,61 @@ fput(file); return bprm.envc; } +#ifdef CONFIG_MOSIX + counted: +#endif /* CONFIG_MOSIX */ retval = prepare_binprm(&bprm); - if (retval < 0) - goto out; +#ifdef CONFIG_MOSIX + current->mosix.inexec = &bprm; + if((current->mosix.dflags & DDEPUTY) && retval >= 0) + retval = mosix_deputy_bring_strings(&bprm, (char *)regs->ebx, + envp, argv); + else + { +#endif /* CONFIG_MOSIX */ + if (retval < 0) + goto out; retval = copy_strings_kernel(1, &bprm.filename, &bprm); - if (retval < 0) - goto out; + if (retval < 0) + goto out; bprm.exec = bprm.p; retval = copy_strings(bprm.envc, envp, &bprm); - if (retval < 0) - goto out; + if (retval < 0) + goto out; retval = copy_strings(bprm.argc, argv, &bprm); - if (retval < 0) - goto out; +#ifdef CONFIG_MOSIX + } +#endif /* CONFIG_MOSIX */ + if (retval < 0) + goto out; retval = search_binary_handler(&bprm,regs); +#ifdef CONFIG_MOSIX + current->mosix.inexec = NULL; + if(retval >= 0) + { + mosix_decay_exec(); + current->mosix.sigmig = 0; +#ifdef CONFIG_MOSIX_FS + current->mosix.lastexec = current->mosix.whereami ? : PE; +#ifdef CONFIG_MOSIX_DFSA + current->mosix.dupdates |= DFSA_UPDSEL; +#endif /* CONFIG_MOSIX_DFSA */ +#endif /* CONFIG_MOSIX_FS */ + } +#endif /* CONFIG_MOSIX */ if (retval >= 0) /* execve success */ return retval; out: +#ifdef CONFIG_MOSIX + current->mosix.inexec = NULL; +#endif /* CONFIG_MOSIX */ /* Something went wrong, return the inode and free the argument pages*/ allow_write_access(bprm.file); if (bprm.file) @@ -945,15 +1050,28 @@ binfmt = current->binfmt; if (!binfmt || !binfmt->core_dump) goto fail; +#ifdef CONFIG_MOSIX + if(!i_am_dumpable()) +#else if (!current->mm->dumpable) +#endif /* CONFIG_MOSIX */ goto fail; +#ifdef CONFIG_MOSIX + set_me_dumpable(0); +#else current->mm->dumpable = 0; +#endif /* CONFIG_MOSIX */ if (current->rlim[RLIMIT_CORE].rlim_cur < binfmt->min_coredump) goto fail; memcpy(corename,"core.", 5); corename[4] = '\0'; +#ifdef CONFIG_MOSIX + if (core_uses_pid || + (current->mm && atomic_read(¤t->mm->mm_realusers) != 1)) +#else if (core_uses_pid || atomic_read(¤t->mm->mm_users) != 1) +#endif /* CONFIG_MOSIX */ sprintf(&corename[4], ".%d", current->pid); file = filp_open(corename, O_CREAT | 2 | O_NOFOLLOW, 0600); if (IS_ERR(file)) @@ -972,6 +1090,10 @@ goto close_fail; if (do_truncate(file->f_dentry, 0) != 0) goto close_fail; +#ifdef CONFIG_MOSIX + if(current->mosix.dflags & DDEPUTY) + mosix_deputy_rusage(0); +#endif /* CONFIG_MOSIX */ retval = binfmt->core_dump(signr, regs, file); @@ -981,3 +1103,43 @@ unlock_kernel(); return retval; } + +#ifdef CONFIG_MOSIX +/* + * The following routines are performed on the REMOTE side + * and must be updated whenever the corresponding original-code + * is modified: + */ + +void +execve_remote_counts(char **argv, char **envp, int *argc, int *envc) +{ +/* the following definition must match the value + * of bprm.p at the beginning of do_execve(): + * (otherwise, this constant needs to be passed as argument) + */ +#define BPRM_P_AS_SIZE (PAGE_SIZE*MAX_ARG_PAGES-sizeof(void *)) + if ((*argc = count(argv, BPRM_P_AS_SIZE / sizeof(void *))) < 0) + return; + if ((*envc = count(envp, BPRM_P_AS_SIZE / sizeof(void *))) < 0) + return; +} + +int +execve_remote_bring_strings(struct linux_binprm *bprm, char **envp, char **argv) +{ + int retval; + char *filename = getname(bprm->filename); + + if(IS_ERR(filename)) + return((int)filename); + retval = copy_strings_kernel(1, &filename, bprm); + putname(filename); + if(retval < 0) + return(retval); + bprm->exec = bprm->p; + if((retval = copy_strings(bprm->envc, envp, bprm)) < 0) + return(retval); + return(copy_strings(bprm->argc, argv, bprm)); +} +#endif /* CONFIG_MOSIX */ diff -urN linux-2.4.17/fs/fcntl.c linux_umopenmosix/fs/fcntl.c --- linux-2.4.17/fs/fcntl.c Mon Sep 17 23:16:30 2001 +++ linux_umopenmosix/fs/fcntl.c Sun Jun 23 12:40:11 2002 @@ -16,6 +16,10 @@ #include #include +#ifdef CONFIG_MOSIX_DFSA +#include +#endif /* CONFIG_MOSIX_DFSA */ + extern int sock_fcntl (struct file *, unsigned int cmd, unsigned long arg); extern int fcntl_setlease(unsigned int fd, struct file *filp, long arg); extern int fcntl_getlease(struct file *filp); @@ -81,6 +85,13 @@ files->max_fdset, start); } +#ifdef CONFIG_MOSIX_DFSA + if((current->mosix.dflags & DREMOTE) && newfd >= files->max_fds) + { + error = -EDOITATHOME; + goto out; + } +#endif /* CONFIG_MOSIX_DFSA */ error = -EMFILE; if (newfd >= current->rlim[RLIMIT_NOFILE].rlim_cur) goto out; @@ -137,12 +148,24 @@ struct file * file, *tofree; struct files_struct * files = current->files; +#ifdef CONFIG_MOSIX_DFSA + dfsa_syscall_on_file(oldfd, 1); +#endif /* CONFIG_MOSIX_DFSA */ write_lock(&files->file_lock); if (!(file = fcheck(oldfd))) goto out_unlock; err = newfd; if (newfd == oldfd) goto out_unlock; +#ifdef CONFIG_MOSIX_DFSA + if((current->mosix.dflags & DREMOTE) && + (newfd >= files->max_fdset || newfd >= files->max_fds || + (!files->fd[newfd] && FD_ISSET(newfd, files->open_fds)))) + { + err = -EDOITATHOME; + goto out_unlock; + } +#endif /* CONFIG_MOSIX_DFSA */ err = -EBADF; if (newfd >= current->rlim[RLIMIT_NOFILE].rlim_cur) goto out_unlock; @@ -169,6 +192,11 @@ FD_SET(newfd, files->open_fds); FD_CLR(newfd, files->close_on_exec); write_unlock(&files->file_lock); +#ifdef CONFIG_MOSIX_DFSA + if(tofree) + dfsa_close_file(newfd); + dfsa_open_file(newfd); +#endif /* CONFIG_MOSIX_DFSA */ if (tofree) filp_close(tofree, files); @@ -190,6 +218,9 @@ int ret = -EBADF; struct file * file = fget(fildes); +#ifdef CONFIG_MOSIX_DFSA + dfsa_syscall_on_file(fildes, 1); +#endif /* CONFIG_MOSIX_DFSA */ if (file) ret = dupfd(file, 0); return ret; @@ -206,6 +237,16 @@ * In the case of an append-only file, O_APPEND * cannot be cleared */ +#ifdef CONFIG_MOSIX_FS + if(!(arg & O_APPEND)) + /* no way to guess the IS_APPEND status on MFS - need to look */ + { + struct inode_operations *iops = filp->f_dentry->d_inode->i_op; + + if (iops && iops->revalidate) + iops->revalidate(filp->f_dentry); + } +#endif /* CONFIG_MOSIX_FS */ if (!(arg & O_APPEND) && IS_APPEND(inode)) return -EPERM; @@ -251,6 +292,18 @@ { long err = -EINVAL; +#ifdef CONFIG_MOSIX_DFSA + switch(cmd) + { + case F_GETFL: + dfsa_syscall_on_file(fd, 0); + break; + case F_DUPFD: + case F_SETFL: + dfsa_syscall_on_file(fd, 1); + break; + } +#endif /* CONFIG_MOSIX_DFSA */ switch (cmd) { case F_DUPFD: if (arg < NR_OPEN) { @@ -438,7 +491,11 @@ send_sigio_to_task(p, fown, fd, band); goto out; } +#ifdef CONFIG_MOSIX + for_each_local_task(p) { +#else for_each_task(p) { +#endif /* CONFIG_MOSIX */ int match = p->pid; if (pid < 0) match = -p->pgrp; diff -urN linux-2.4.17/fs/file.c linux_umopenmosix/fs/file.c --- linux-2.4.17/fs/file.c Fri Feb 9 21:29:44 2001 +++ linux_umopenmosix/fs/file.c Sun Jun 23 12:40:11 2002 @@ -14,6 +14,9 @@ #include +#ifdef CONFIG_MOSIX_DFSA +#include +#endif /* CONFIG_MOSIX_DFSA */ /* * Allocate an fd array, using kmalloc or vmalloc. @@ -98,6 +101,10 @@ struct file **old_fds; int i; +#ifdef CONFIG_MOSIX_DFSA + if(files == current->files) + current->mosix.dupdates |= DFSA_UPDMAX; +#endif /* CONFIG_MOSIX_DFSA */ old_fds = xchg(&files->fd, new_fds); i = xchg(&files->max_fds, nfds); @@ -164,6 +171,9 @@ int expand_fdset(struct files_struct *files, int nr) { fd_set *new_openset = 0, *new_execset = 0; +#ifdef CONFIG_MOSIX_DFSA + fd_set *new_closed = 0, *new_opened = 0, *new_modified = 0; +#endif /* CONFIG_MOSIX_DFSA */ int error, nfds = 0; error = -EMFILE; @@ -187,8 +197,18 @@ error = -ENOMEM; new_openset = alloc_fdset(nfds); new_execset = alloc_fdset(nfds); +#ifdef CONFIG_MOSIX_DFSA + new_closed = alloc_fdset(nfds); + new_opened = alloc_fdset(nfds); + new_modified = alloc_fdset(nfds); +#endif /* CONFIG_MOSIX_DFSA */ write_lock(&files->file_lock); +#ifdef CONFIG_MOSIX_DFSA + if (!new_openset || !new_execset || + !new_closed || !new_opened || !new_modified) +#else if (!new_openset || !new_execset) +#endif /* CONFIG_MOSIX_DFSA */ goto out; error = 0; @@ -198,6 +218,10 @@ int i = files->max_fdset / (sizeof(unsigned long) * 8); int count = (nfds - files->max_fdset) / 8; +#ifdef CONFIG_MOSIX_DFSA + if(files == current->files) + current->mosix.dupdates |= DFSA_UPDMAX; +#endif /* CONFIG_MOSIX_DFSA */ /* * Don't copy the entire array if the current fdset is * not yet initialised. @@ -207,14 +231,32 @@ memcpy (new_execset, files->close_on_exec, files->max_fdset/8); memset (&new_openset->fds_bits[i], 0, count); memset (&new_execset->fds_bits[i], 0, count); +#ifdef CONFIG_MOSIX_DFSA + memcpy (new_closed, files->closed, files->max_fdset/8); + memcpy (new_opened, files->opened, files->max_fdset/8); + memcpy (new_modified, files->modified, files->max_fdset/8); + memset (&new_closed->fds_bits[i], 0, count); + memset (&new_opened->fds_bits[i], 0, count); + memset (&new_modified->fds_bits[i], 0, count); +#endif /* CONFIG_MOSIX_DFSA */ } nfds = xchg(&files->max_fdset, nfds); new_openset = xchg(&files->open_fds, new_openset); new_execset = xchg(&files->close_on_exec, new_execset); +#ifdef CONFIG_MOSIX_DFSA + new_closed = xchg(&files->closed, new_closed); + new_opened = xchg(&files->opened, new_opened); + new_modified = xchg(&files->modified, new_modified); +#endif /* CONFIG_MOSIX_DFSA */ write_unlock(&files->file_lock); free_fdset (new_openset, nfds); free_fdset (new_execset, nfds); +#ifdef CONFIG_MOSIX_DFSA + free_fdset (files->closed, nfds); + free_fdset (files->opened, nfds); + free_fdset (files->modified, nfds); +#endif /* CONFIG_MOSIX_DFSA */ write_lock(&files->file_lock); return 0; } @@ -226,6 +268,14 @@ free_fdset(new_openset, nfds); if (new_execset) free_fdset(new_execset, nfds); +#ifdef CONFIG_MOSIX_DFSA + if (new_closed) + free_fdset(new_closed, nfds); + if (new_opened) + free_fdset(new_opened, nfds); + if (new_modified) + free_fdset(new_modified, nfds); +#endif /* CONFIG_MOSIX_DFSA */ write_lock(&files->file_lock); return error; } diff -urN linux-2.4.17/fs/file_table.c linux_umopenmosix/fs/file_table.c --- linux-2.4.17/fs/file_table.c Mon Sep 17 23:16:30 2001 +++ linux_umopenmosix/fs/file_table.c Sun Jun 23 12:40:11 2002 @@ -58,7 +58,12 @@ /* * Allocate a new one if we're below the limit. */ +#ifdef CONFIG_MOSIX_FS + if (files_stat.nr_files < files_stat.max_files || + (current->mosix.dirty_bits & MFSARG_EMPTYF_PRI)) { +#else if (files_stat.nr_files < files_stat.max_files) { +#endif /* CONFIG_MOSIX_FS */ file_list_unlock(); f = kmem_cache_alloc(filp_cachep, SLAB_KERNEL); file_list_lock(); @@ -113,6 +118,9 @@ file->f_op->release(inode, file); fops_put(file->f_op); if (file->f_mode & FMODE_WRITE) +#ifdef CONFIG_MOSIX + if (!(file->f_flags & O_NOWRITEACCESS)) +#endif /* CONFIG_MOSIX */ put_write_access(inode); file_list_lock(); file->f_dentry = NULL; diff -urN linux-2.4.17/fs/inode.c linux_umopenmosix/fs/inode.c --- linux-2.4.17/fs/inode.c Fri Dec 21 19:41:55 2001 +++ linux_umopenmosix/fs/inode.c Sun Jun 23 12:40:11 2002 @@ -18,6 +18,11 @@ #include #include +#ifdef CONFIG_MOSIX +spinlock_t unique_gen_lock = SPIN_LOCK_UNLOCKED; +unsigned long long unique_generator; +#endif /* CONFIG_MOSIX */ + /* * New inode.c implementation. * @@ -787,6 +792,9 @@ inode->i_data.host = inode; inode->i_data.gfp_mask = GFP_HIGHUSER; inode->i_mapping = &inode->i_data; +#ifdef CONFIG_MOSIX + VMODIFIED(inode); +#endif /* CONFIG_MOSIX */ } /** @@ -822,6 +830,9 @@ inode->i_flags = 0; atomic_set(&inode->i_count, 1); inode->i_state = 0; +#ifdef CONFIG_MOSIX + VMODIFIED(inode); +#endif /* CONFIG_MOSIX */ spin_unlock(&inode_lock); clean_inode(inode); } @@ -856,6 +867,9 @@ inode->i_flags = 0; atomic_set(&inode->i_count, 1); inode->i_state = I_LOCK; +#ifdef CONFIG_MOSIX + VMODIFIED(inode); +#endif /* CONFIG_MOSIX */ spin_unlock(&inode_lock); clean_inode(inode); diff -urN linux-2.4.17/fs/ioctl.c linux_umopenmosix/fs/ioctl.c --- linux-2.4.17/fs/ioctl.c Fri Feb 9 21:29:44 2001 +++ linux_umopenmosix/fs/ioctl.c Sun Jun 23 12:40:11 2002 @@ -11,6 +11,10 @@ #include #include +#ifdef CONFIG_MOSIX_DFSA +#include +#endif /* CONFIG_MOSIX_DFSA */ + static int file_ioctl(struct file *filp,unsigned int cmd,unsigned long arg) { int error; @@ -51,6 +55,9 @@ struct file * filp; unsigned int flag; int on, error = -EBADF; +#ifdef CONFIG_MOSIX_DFSA + int flags_changed = 0; +#endif /* CONFIG_MOSIX_DFSA */ filp = fget(fd); if (!filp) @@ -79,6 +86,9 @@ filp->f_flags |= flag; else filp->f_flags &= ~flag; +#ifdef CONFIG_MOSIX_DFSA + flags_changed = 1; +#endif /* CONFIG_MOSIX_DFSA */ break; case FIOASYNC: @@ -99,6 +109,9 @@ filp->f_flags |= FASYNC; else filp->f_flags &= ~FASYNC; +#ifdef CONFIG_MOSIX_DFSA + flags_changed = 1; +#endif /* CONFIG_MOSIX_DFSA */ break; default: @@ -110,6 +123,10 @@ } unlock_kernel(); fput(filp); +#ifdef CONFIG_MOSIX_DFSA + if(flags_changed) + dfsa_touch_file(fd); +#endif /* CONFIG_MOSIX_DFSA */ out: return error; diff -urN linux-2.4.17/fs/lockd/svc.c linux_umopenmosix/fs/lockd/svc.c --- linux-2.4.17/fs/lockd/svc.c Sun Oct 21 19:32:33 2001 +++ linux_umopenmosix/fs/lockd/svc.c Sun Jun 23 12:40:11 2002 @@ -304,6 +304,9 @@ * Wait for the lockd process to exit, but since we're holding * the lockd semaphore, we can't wait around forever ... */ +#ifdef CONFIG_MOSIX + current->mosix.ignoreoldsigs = 1; +#endif /* CONFIG_MOSIX */ current->sigpending = 0; interruptible_sleep_on_timeout(&lockd_exit, HZ); if (nlmsvc_pid) { diff -urN linux-2.4.17/fs/mfs/Makefile linux_umopenmosix/fs/mfs/Makefile --- linux-2.4.17/fs/mfs/Makefile Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/fs/mfs/Makefile Sun Jun 23 12:40:11 2002 @@ -0,0 +1,8 @@ +# +# Makefile for the Linux MOSIX mfs filesystem routines. +# + +O_TARGET := mfs.o +obj-y := file.o convert.o complete.o server.o client.o scontact.o ccontact.o socket.o count.o + +include $(TOPDIR)/Rules.make diff -urN linux-2.4.17/fs/mfs/ccontact.c linux_umopenmosix/fs/mfs/ccontact.c --- linux-2.4.17/fs/mfs/ccontact.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/fs/mfs/ccontact.c Sun Jun 23 12:40:11 2002 @@ -0,0 +1,325 @@ +/* + * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il) + * Some sections copyright 2002 by Moshe Bar + * Permission to use this software is hereby granted under the terms of the + * GNU General Public License, as published by the Free Software Foundation. + * + * THIS SOFTWARE IS PROVIDED IN ITS "AS IS" CONDITION, WITH NO WARRANTY + * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING + * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED. + */ +/* + * Author(s): Amnon Shiloh, Moshe Bar + */ + +#include +#ifdef CONFIG_MOSIX_FS +#include +#include +#include + +spinlock_t mfs_client_lock = SPIN_LOCK_UNLOCKED; + +#define MFS_CLIENT_OPTCONS 50 +#define MFS_MAX_HOGGING_A_NODE 8 + +struct mfs_client_contact +{ + struct mfs_client_contact *next; + int to; + struct socket *sock; + int serial; + int has_mh; + struct mfs_message_header mh; +} *mfs_busy_clients, *mfs_connected_clients, *mfs_closing_clients; + +int mfs_client_serial; + +DECLARE_WAIT_QUEUE_HEAD(wait_for_busy_contact); +int waiting_for_busy_contact; + +int +mfs_client_send(struct mfs_client_contact *s, int type, void *header, int hdln, + void *dat1, int len1, void *dat2, int len2) +{ + return(mfs_send(s->sock, 0, s->serial, + type, header, hdln, dat1, len1, dat2, len2)); +} + +int +mfs_client_receive(struct mfs_client_contact *s, + void **header, void **dat1, void **dat2) +{ + if(s->has_mh) + { + s->has_mh = 0; +if(mfs_debug > 1) +printk("mfs_client_receive: continuing with serial %d, type %d (%d/%d/%d)\n", +s->mh.serial, s->mh.type, s->mh.hdsz, s->mh.dat1sz, s->mh.dat2sz); + return(mfs_receive(s->sock, MFS_MUST_MATCH, &s->serial, &s->mh, + header, dat1, dat2)); + } + else + return(mfs_receive(s->sock, MFS_SKIP_OTHERS, &s->serial, NULL, + header, dat1, dat2)); +} + +int +mfs_client_contact_has_data(struct mfs_client_contact *con) +{ + return(mfs_socket_has_data(con->sock)); +} + +void +delayed_close_client(struct mfs_client_contact *con) +{ + mfs_send(con->sock, 1, 0, MFS_CLOSE, NULL, 0, NULL, 0, NULL,0); + spin_lock(&mfs_client_lock); + con->next = mfs_closing_clients; + mfs_closing_clients = con; + spin_unlock(&mfs_client_lock); +} + +void +mfs_client_check_closed(struct mfs_client_contact **head) +{ + struct mfs_client_contact *c, *prev, *next; + struct mfs_client_contact *dispose = NULL; + + spin_lock(&mfs_client_lock); + for(prev = NULL, c = *head ; c ; c = next) + { + next = c->next; + if(mfs_socket_is_closed(c->sock)) + { + if(prev) + prev->next = next; + else + *head = next; + c->next = dispose; + dispose = c; + } + else + prev = c; + } + spin_unlock(&mfs_client_lock); + for(; dispose ; dispose = next) + { + next = dispose->next; + mfs_close_socket(dispose->sock); + kfree(dispose); + } +} + +void +mfs_release_contact(struct mfs_client_contact *con) +{ + struct mfs_client_contact *s, *prev; + int bcnt = 0, pcnt = 0, tcnt = 0; + int pe = con->to; + int found = 0; + + spin_lock(&mfs_client_lock); + for(prev = NULL , s = mfs_busy_clients ; s ; ) + { + tcnt++; + if(s == con) + { + s = s->next; + if(prev) + prev->next = s; + else + mfs_busy_clients = s; + found = 1; + } + else + { + if(s->to == pe && ++bcnt >= MFS_MAX_HOGGING_A_NODE && + found) + break; + prev = s; + s = s->next; + } + } + if(!found) + printk("mfs_release_contact: not listed!\n"); + if((pcnt = bcnt) < MFS_MAX_HOGGING_A_NODE) + for(s = mfs_connected_clients ; s ; s = s->next) + { + tcnt++; + if(s->to == pe && ++pcnt == MFS_MAX_HOGGING_A_NODE) + break; + } + if((tcnt >= MFS_CLIENT_OPTCONS && pcnt) || + pcnt >= MFS_MAX_HOGGING_A_NODE) + { + spin_unlock(&mfs_client_lock); + delayed_close_client(con); + if(bcnt >= MFS_MAX_HOGGING_A_NODE) + return; + spin_lock(&mfs_client_lock); + } + else + { + con->next = mfs_connected_clients; + mfs_connected_clients = con; + } + if(waiting_for_busy_contact == pe || + waiting_for_busy_contact == MFS_UNKNOWN_PE) + { + waiting_for_busy_contact = 0; + wake_up(&wait_for_busy_contact); + } + spin_unlock(&mfs_client_lock); +} + +static inline int +node_is_hogged(int pe) +{ + int n = 0; + struct mfs_client_contact *s; + + for(s = mfs_busy_clients ; s ; s = s->next) + if(s->to == pe && ++n == MFS_MAX_HOGGING_A_NODE) + return(1); + return(0); +} + +struct mfs_client_contact * +mfs_new_request(int pe, int type, void *header, int hdln, void *dat1, int len1, + void *dat2, int len2) +{ + struct mfs_client_contact *s, *prev, *prevprev, *con; + int tried_a_new = 0; + int cnt; + DECLARE_WAITQUEUE(wait, current); + + if(pe == MFS_BAD_PE) + return(ERR_PTR(-ESTALE)); + spin_lock(&mfs_client_lock); + for(prev = prevprev = NULL , cnt = 0 , s = mfs_connected_clients ; s ; + prevprev = prev, prev = s , s = s->next) + if(s->to == pe) + break; + else + cnt++; + if(s) + { + found_a_connected: + if(prev) + prev->next = s->next; + else + mfs_connected_clients = s->next; + try_it: + con = s; + con->to = pe; + con->next = mfs_busy_clients; + mfs_busy_clients = con; + con->serial = ++mfs_client_serial; + spin_unlock(&mfs_client_lock); + if(!mfs_send(con->sock, 1, con->serial, type, header, hdln, + dat1, len1, dat2, len2) && + mfs_receive(con->sock, MFS_JUST_HEADER, &con->serial, + &con->mh, NULL, NULL, NULL) >= 0) + { + con->has_mh = 1; +if(mfs_debug > 1) +printk("mfs_new_request: first reply will be serial %d, type %d (%d/%d/%d)\n", +con->mh.serial, con->mh.type, con->mh.hdsz, con->mh.dat1sz, con->mh.dat2sz); + return(con); + } + spin_lock(&mfs_client_lock); + for(prev = NULL , s = mfs_busy_clients ; s && s != con ; + prev = s , s = s->next) + ; + if(s) + { + if(prev) + prev->next = s->next; + else + mfs_busy_clients = s->next; + if(waiting_for_busy_contact == pe || + waiting_for_busy_contact == MFS_UNKNOWN_PE) + { + waiting_for_busy_contact = 0; + wake_up(&wait_for_busy_contact); + } + spin_unlock(&mfs_client_lock); + mfs_close_socket(s->sock); + kfree(s); + spin_lock(&mfs_client_lock); + } + else + printk("mfs_new_request: contact disappeared!\n"); + } + else if(cnt >= MFS_CLIENT_OPTCONS) + { + /* trim out the last one (also last used) */ + prevprev->next = NULL; + spin_unlock(&mfs_client_lock); + delayed_close_client(prev); + mfs_client_check_closed(&mfs_closing_clients); + spin_lock(&mfs_client_lock); + } + if(tried_a_new || !PE) + { + spin_unlock(&mfs_client_lock); + return(ERR_PTR(-EREMOTE)); + } + if(node_is_hogged(pe)) + { + add_wait_queue(&wait_for_busy_contact, &wait); + while(1) + { + set_current_state(TASK_UNINTERRUPTIBLE); + if(waiting_for_busy_contact && + waiting_for_busy_contact != pe) + waiting_for_busy_contact = MFS_UNKNOWN_PE; + else + waiting_for_busy_contact = pe; + if(!node_is_hogged(pe)) + break; + spin_unlock(&mfs_client_lock); + if(!PE) + { + remove_wait_queue(&wait_for_busy_contact, &wait); + set_current_state(TASK_RUNNING); + return(NULL); + } + schedule_timeout(HZ); + spin_lock(&mfs_client_lock); + for(prev = NULL , s = mfs_connected_clients ; s ; + prev = s , s = s->next) + if(s->to == pe) + { + remove_wait_queue(&wait_for_busy_contact,&wait); + set_current_state(TASK_RUNNING); + goto found_a_connected; + } + } + remove_wait_queue(&wait_for_busy_contact, &wait); + set_current_state(TASK_RUNNING); + } + spin_unlock(&mfs_client_lock); + tried_a_new++; + if(!(s = (struct mfs_client_contact *)kmalloc(sizeof(*s), GFP_KERNEL))) + return(ERR_PTR(-ENOMEM)); + s->sock = mfs_connect_to(pe); + s->has_mh = 0; + if(!IS_ERR(s->sock)) + { + spin_lock(&mfs_client_lock); + goto try_it; + } + con = (struct mfs_client_contact *)s->sock; + kfree(s); + return(con); +} + +void +mfs_monitor_client_contacts(void) +{ + mfs_client_check_closed(&mfs_connected_clients); + mfs_client_check_closed(&mfs_closing_clients); +} +#endif /* CONFIG_MOSIX_FS */ diff -urN linux-2.4.17/fs/mfs/client.c linux_umopenmosix/fs/mfs/client.c --- linux-2.4.17/fs/mfs/client.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/fs/mfs/client.c Sun Jun 23 12:40:11 2002 @@ -0,0 +1,665 @@ +/* + * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il) + * Some sections copyright 2002 by Moshe Bar + * Permission to use this software is hereby granted under the terms of the + * GNU General Public License, as published by the Free Software Foundation. + * + * THIS SOFTWARE IS PROVIDED IN ITS "AS IS" CONDITION, WITH NO WARRANTY + * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING + * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED. + */ +/* + * Author(s): Amnon Shiloh, Moshe Bar + */ + +#include +#ifdef CONFIG_MOSIX_FS +#include +#include +#include + +void +pack_credits(struct mfs_cred *cred) +{ + register struct task_struct *p = current; + register int i; + + cred->uid = p->uid; + cred->euid = p->euid; + cred->sgid = p->sgid; + cred->fsuid = p->fsuid; + cred->gid = p->gid; + cred->egid = p->egid; + cred->sgid = p->sgid; + cred->fsgid = p->fsgid; + cred->ngroups = p->ngroups; + for(i = cred->ngroups-1 ; i >= 0 ; i--) + cred->groups[i] = p->groups[i]; + cred->caps = p->cap_effective; + cred->whereami = current->mosix.whereami ? : PE; + cred->deppe = current->mosix.deppe ? : PE; +} + +inline void +mfs_file_up_to_date(struct file *filp) +{ + struct dentry *dp; + struct mfs_dinfo *i; + + if((dp = filp->f_dentry) && (i = (struct mfs_dinfo *)dp->d_fsdata)) + i->latest = jiffies; +} + +int +mfs_client_attach_handle(int pe, mfs_handle_t handle) +{ + struct mfs_request_attach_handle s; + struct mfs_reply_attach_handle *r; + struct mfs_client_contact *con; + int err; + + s.handle = handle; + con = mfs_new_request(pe, MFS_REQUEST_ATTACH_HANDLE, &s, sizeof(s), + NULL, 0, NULL, 0); + if(IS_ERR(con)) + return((int)con); + err = mfs_client_receive(con, (void **)&r, NULL, NULL); + if(err == MFS_REPLY_ATTACH_HANDLE) + err = r->result; + else if(err >= 0) + { + printk("mfs_client_attach_handle: unexpected reply %d\n", err); + err = -EINVAL; + } + if(r) + kfree(r); + mfs_release_contact(con); + return(err); +} + +int +mfs_client_touch_handle(int pe, mfs_handle_t handle) +{ + struct mfs_request_touch_handle s; + struct mfs_reply_touch_handle *r; + struct mfs_client_contact *con; + int err; + + s.handle = handle; + con = mfs_new_request(pe, MFS_REQUEST_TOUCH_HANDLE, &s, sizeof(s), + NULL, 0, NULL, 0); + if(IS_ERR(con)) + return((int)con); + err = mfs_client_receive(con, (void **)&r, NULL, NULL); + if(err == MFS_REPLY_TOUCH_HANDLE) + err = r->result; + else if(err >= 0) + { + printk("mfs_client_touch_handle: unexpected reply %d\n", err); + err = -EINVAL; + } + if(r) + kfree(r); + mfs_release_contact(con); + return(err); +} + +void +mfs_client_dispose_handle(int pe, mfs_handle_t handle) +{ + struct mfs_request_dispose_handle s; + struct mfs_client_contact *con; + void *r; + + s.handle = handle; + con = mfs_new_request(pe, MFS_REQUEST_DISPOSE_HANDLE, &s, sizeof(s), + NULL, 0, NULL, 0); + if(IS_ERR(con)) + return; + mfs_client_receive(con, &r, NULL, NULL); + if(r) + kfree(r); + mfs_release_contact(con); +} + +int +mfs_client_llseek(int pe, mfs_handle_t handle, struct file *filp, loff_t offset, + int origin) +{ + struct mfs_request_llseek s; + struct mfs_reply_llseek *r; + struct mfs_client_contact *con; + int err; + + pack_credits(&s.cred); + s.handle = handle; + s.file = *filp; + s.offset = offset; + s.origin = origin; + con = mfs_new_request(pe, MFS_REQUEST_LLSEEK, &s, sizeof(s), NULL, 0, + NULL, 0); + if(IS_ERR(con)) + return((int)con); + err = mfs_client_receive(con, (void **)&r, NULL, NULL); + if(err == MFS_REPLY_LLSEEK) + { + cp_file_fields(filp, &r->file); + err = r->result; + if(err >= 0) + mfs_file_up_to_date(filp); + } + else if(err >= 0) + { + printk("mfs_client_llseek: unexpected reply %d\n", err); + err = -EINVAL; + } + if(r) + kfree(r); + mfs_release_contact(con); + return(err); +} + +ssize_t +mfs_client_read(int pe, mfs_handle_t handle, struct file *filp, char *buf, + size_t count, loff_t *ppos) +{ + struct mfs_request_read s; + struct mfs_reply_read *r; + struct mfs_client_contact *con; + void *data; + int err; + ssize_t i, result = 0; + int user_err = 0; + int done = 0; + + if((int)count < 0) + return(-EINVAL); + pack_credits(&s.cred); + s.handle = handle; + s.file = *filp; + s.count = count; + s.pos = *ppos; + con = mfs_new_request(pe, MFS_REQUEST_READ, &s, sizeof(s), NULL, 0, + NULL, 0); + if(IS_ERR(con)) + return((int)con); + while(!done) + { + err = mfs_client_receive(con, (void **)&r, &data, NULL); + if(err < 0) + { + result = err; + break; + } + switch(err) + { + case MFS_INTERIM_DATA: + i = ((struct mfs_interim_data *)r)->count; + if(!user_err && copy_to_user(buf, data, i)) + user_err = -EFAULT; + else + buf += i; + /* do not exit: it is always the server + * that should close the connection + */ + break; + case MFS_REPLY_READ: + done = 1; + if(!user_err && r->datalen && + copy_to_user(buf, data, r->datalen)) + user_err = -EFAULT; + cp_file_fields(filp, &r->file); + *ppos = r->ppos; + result = r->result; + if(result >= 0) + mfs_file_up_to_date(filp); + break; + default: + printk("mfs_client_read: unexpected reply %d\n", + err); + result = -EINVAL; + done = 1; + break; + + } + if(r) + kfree(r); + } + mfs_release_contact(con); + return(user_err ? : result); +} + +ssize_t +mfs_client_write(int pe, mfs_handle_t handle, struct file *filp, char *buf, + size_t count, loff_t *ppos, long flim) +{ + struct mfs_request_write s; + struct mfs_interim_data i; + struct mfs_reply_write *r; + struct mfs_client_contact *con; + void *data; + int err; + ssize_t result = 0; + int user_err = 0; + size_t max, sent, cnt; + char smallbuf[4]; + char *tbuf = NULL; /* NULL just because bad compiler complains */ + + if(count == 0) + return(0); + if((int)count < 0) + return(-EINVAL); + pack_credits(&s.cred); + s.handle = handle; + s.file = *filp; + s.count = count; + s.pos = *ppos; + s.flim = flim; + for(max = count > 16384 ? 16384 : count ; max > sizeof(smallbuf) ; + max >>= 1) + if((tbuf = (char *)kmalloc(max, GFP_KERNEL))) + break; + if(max <= sizeof(smallbuf)) + { + tbuf = smallbuf; + max = sizeof(smallbuf); + } + s.datalen = sent = count < max ? count : max; + if(copy_from_user(tbuf, buf, sent)) + { + user_err = -EFAULT; + goto free_buf; + } + buf += sent; + con = mfs_new_request(pe, MFS_REQUEST_WRITE, &s, sizeof(s), tbuf, sent, + NULL, 0); + if(IS_ERR(con)) + { + result = (int)con; + goto free_buf; + } + while(sent < count) + { + if(mfs_client_contact_has_data(con)) + break; + cnt = count - sent; + if(cnt > max) + cnt = max; + if(user_err || copy_from_user(tbuf, buf, cnt)) + { + user_err = -EFAULT; + mfs_client_send(con, MFS_STOP, NULL, 0, + NULL, 0, NULL, 0); + break; /* let the server quit first */ + } + i.count = cnt; + if((err = mfs_client_send(con, MFS_INTERIM_DATA, + &i, sizeof(i), (void *)tbuf, cnt, + NULL, 0))) + { + result = err; + break; + } + buf += cnt; + sent += cnt; + } + err = mfs_client_receive(con, (void **)&r, &data, NULL); + if(err == MFS_CONTINUE) + err = mfs_client_receive(con, (void **)&r, &data, NULL); + if(err == MFS_REPLY_WRITE) + { + cp_file_fields(filp, &r->file); + *ppos = r->ppos; + result = r->result; + if(result >= 0) + mfs_file_up_to_date(filp); + if(r->hadsigxfsz) + send_sig(SIGXFSZ, current, 0); + } + else if(err < 0) + result = err; + else + { + printk("mfs_client_write: unexpected reply %d\n", err); + result = -EINVAL; + } + if(r) + kfree(r); + mfs_release_contact(con); + free_buf: + if(max != sizeof(smallbuf)) + kfree(tbuf); + return(user_err ? : result); +} + +int +mfs_client_readdir_transfer(void *d, int len, void *dirent, filldir_t filldir) +{ + ino_t ino; + loff_t off; + unsigned int type; + short namelen; + int err; + + while(len) + { + len -= sizeof(ino)+sizeof(off)+sizeof(type)+sizeof(namelen); + if(len < 0) + return(-EINVAL); + ino = *((ino_t *)d)++; + off = *((loff_t *)d)++; + type = *((unsigned int *)d)++; + namelen = *((short *)d)++; + if(len < namelen) + return(-EINVAL); + len -= namelen; + if((err = filldir(dirent, (const char *)d, namelen, off, ino, + type))) + return(err); + d += namelen; + } + return(0); +} + +int +mfs_client_readdir(int pe, mfs_handle_t handle, struct file *filp, void *dirent, + filldir_t filldir, int policy, int maxbytes, int *packets, int *bytes) +{ + struct mfs_request_readdir s; + struct mfs_reply_readdir *r; + struct mfs_interim_readdir ri; + struct mfs_client_contact *con; + void *data; + ssize_t i; + int result = 0; + int done = 0; + + pack_credits(&s.cred); + s.handle = handle; + s.file = *filp; + s.policy = policy; + s.maxbytes = maxbytes; + *packets = *bytes = 0; + con = mfs_new_request(pe, MFS_REQUEST_READDIR, &s, sizeof(s), NULL, 0, + NULL, 0); + if(IS_ERR(con)) + return((int)con); + while(!done && (result = + mfs_client_receive(con, (void **)&r, &data, NULL)) >= 0) + { + switch(result) + { + case MFS_INTERIM_DATA: + i = ((struct mfs_interim_data *)r)->count; + (*packets)++; + (*bytes) += i; + ri.error = mfs_client_readdir_transfer(data, i, + dirent, filldir); + if((result = mfs_client_send(con, + MFS_INTERIM_READDIR, &ri, sizeof(ri), + NULL, 0, NULL, 0))) + done = 1; + break; + case MFS_REPLY_READDIR: + done = 1; + (*bytes) += r->datalen; + if(!r->datalen || + !(result = mfs_client_readdir_transfer( + data, r->datalen, dirent, filldir))) + result = r->result; + cp_file_fields(filp, &r->file); + if(result >= 0) + mfs_file_up_to_date(filp); + break; + default: + printk("mfs_client_readdir: unexpected reply %d\n", result); + result = -EINVAL; + done = 1; + break; + } + if(r) + kfree(r); + } + mfs_release_contact(con); + return(result); +} + +int +mfs_client_ioctl(int pe, mfs_handle_t handle, struct file *filp, + unsigned int cmd, unsigned long arg, int size, int *data) +{ + struct mfs_request_ioctl s; + struct mfs_reply_ioctl *r; + struct mfs_client_contact *con; + int err; + + pack_credits(&s.cred); + s.handle = handle; + s.file = *filp; + s.cmd = cmd; + s.arg = arg; + s.data = *data; + s.size = size; + con = mfs_new_request(pe, MFS_REQUEST_IOCTL, &s, sizeof(s), NULL, 0, + NULL, 0); + if(IS_ERR(con)) + return((int)con); + err = mfs_client_receive(con, (void **)&r, NULL, NULL); + if(err == MFS_REPLY_IOCTL) + { + cp_file_fields(filp, &r->file); + if(size < 0) + *data = r->data; + err = r->result; + if(err >= 0) + mfs_file_up_to_date(filp); + } + else if(err >= 0) + { + printk("mfs_client_ioctl: unexpected reply %d\n", err); + err = -EINVAL; + } + if(r) + kfree(r); + mfs_release_contact(con); + return(err); +} + +int +mfs_client_fsync(int pe, mfs_handle_t handle, struct file *filp, int datasync) +{ + struct mfs_request_fsync s; + struct mfs_reply_fsync *r; + struct mfs_client_contact *con; + int err; + + pack_credits(&s.cred); + s.handle = handle; + s.file = *filp; + s.datasync = datasync; + con = mfs_new_request(pe, MFS_REQUEST_FSYNC, &s, sizeof(s), NULL, 0, + NULL, 0); + if(IS_ERR(con)) + return((int)con); + err = mfs_client_receive(con, (void **)&r, NULL, NULL); + if(err == MFS_REPLY_FSYNC) + { + cp_file_fields(filp, &r->file); + err = r->result; + if(err >= 0) + mfs_file_up_to_date(filp); + } + else if(err >= 0) + { + printk("mfs_client_fsync: unexpected reply %d\n", err); + err = -EINVAL; + } + if(r) + kfree(r); + mfs_release_contact(con); + return(err); +} + +int +mfs_client_revalidate(int pe, mfs_handle_t handle, struct subinode *iinfo) +{ + struct mfs_request_revalidate s; + struct mfs_reply_revalidate *r; + struct mfs_client_contact *con; + int err; + + pack_credits(&s.cred); + s.handle = handle; + con = mfs_new_request(pe, MFS_REQUEST_REVALIDATE, &s, sizeof(s), + NULL, 0, NULL, 0); + if(IS_ERR(con)) + return((int)con); + err = mfs_client_receive(con, (void **)&r, NULL, NULL); + if(err == MFS_REPLY_REVALIDATE) + { + *iinfo = r->iinfo; + err = r->result; + } + else if(err >= 0) + { + printk("mfs_client_revalidate: unexpected reply %d\n", err); + err = -EINVAL; + } + if(r) + kfree(r); + mfs_release_contact(con); + return(err); +} + +int +mfs_client_express_lookup(int pe, mfs_handle_t *handle, char *name, + unsigned int follow, struct subinode *iinfo, char **newname, + struct mfs_completion *complete) +{ + struct mfs_request_express s; + struct mfs_reply_express *r; + struct mfs_client_contact *con; + int err; + void *name_back, *more_data; + + *newname = NULL; + pack_credits(&s.cred); + s.handle = *handle; + s.namelen = strlen(name) + 1; + s.follow = follow; + s.link_count = current->link_count; + s.total_link_count = current->total_link_count; + s.complete = *complete; + con = mfs_new_request(pe, MFS_REQUEST_EXPRESS, &s, sizeof(s), + (void *)name, s.namelen, + s.complete.more_data, s.complete.more_data_len); + if(IS_ERR(con)) + return((int)con); + err = mfs_client_receive(con, (void **)&r, &name_back, &more_data); + if(err == MFS_REPLY_EXPRESS) + { + *handle = r->handle; + *iinfo = r->iinfo; + *complete = r->complete; + err = r->result; + if(!err) + { + if(!r->namelen) + *newname = NULL; + else if((*newname = kmalloc(r->namelen, GFP_KERNEL))) + memcpy(*newname, name_back, r->namelen); + else + err = -ENOMEM; + } + if(complete->more_data) + { + if((complete->more_data = + kmalloc(complete->more_data_len, GFP_KERNEL))) + memcpy(complete->more_data, more_data, + complete->more_data_len); + else + { + if(!err) + err = -ENOMEM; + if(*newname) + { + kfree(*newname); + *newname = NULL; + } + } + } + } + else if(err >= 0) + { + printk("mfs_client_express_lookup: unexpected reply %d\n", err); + err = -EINVAL; + } + if(r) + kfree(r); + mfs_release_contact(con); + return(err); +} + +char * +mfs_client_check_path(int pe, mfs_handle_t handle) +{ + struct mfs_request_checkpath s; + struct mfs_reply_checkpath *r; + char *path; + char *copy = NULL; + struct mfs_client_contact *con; + int err; + + pack_credits(&s.cred); + s.handle = handle; + con = mfs_new_request(pe, MFS_REQUEST_CHECKPATH, &s, sizeof(s), NULL, 0, + NULL, 0); + if(IS_ERR(con)) + return(NULL); + err = mfs_client_receive(con, (void **)&r, (void *)&path, NULL); + if(err == MFS_REPLY_CHECKPATH) + { + if(r->namelen && (copy = kmalloc(r->namelen, GFP_KERNEL))) + memcpy(copy, path, r->namelen); + } + else if(err >= 0) + { + printk("mfs_client_check_path: unexpected reply %d\n", err); + err = -EINVAL; + } + if(r) + kfree(r); + mfs_release_contact(con); + return(copy); +} + +int +mfs_client_setattr(int pe, mfs_handle_t handle, struct iattr *iattr) +{ + struct mfs_request_setattr s; + struct mfs_reply_setattr *r; + struct mfs_client_contact *con; + int err; + + pack_credits(&s.cred); + s.handle = handle; + s.attr = *iattr; + con = mfs_new_request(pe, MFS_REQUEST_SETATTR, &s, sizeof(s), + NULL, 0, NULL, 0); + if(IS_ERR(con)) + return((int)con); + err = mfs_client_receive(con, (void **)&r, NULL, NULL); + if(err == MFS_REPLY_SETATTR) + err = r->result; + else if(err >= 0) + { + printk("mfs_client_setattr: unexpected reply %d\n", err); + err = -EINVAL; + } + if(r) + kfree(r); + mfs_release_contact(con); + return(err); +} + +#endif /* CONFIG_MOSIX_FS */ diff -urN linux-2.4.17/fs/mfs/complete.c linux_umopenmosix/fs/mfs/complete.c --- linux-2.4.17/fs/mfs/complete.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/fs/mfs/complete.c Sun Jun 23 12:40:11 2002 @@ -0,0 +1,731 @@ +/* + * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il) + * Some sections copyright 2002 by Moshe Bar + * Permission to use this software is hereby granted under the terms of the + * GNU General Public License, as published by the Free Software Foundation. + * + * THIS SOFTWARE IS PROVIDED IN ITS "AS IS" CONDITION, WITH NO WARRANTY + * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING + * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED. + */ +/* + * Author(s): Amnon Shiloh, Moshe Bar + */ + +#include +#ifdef CONFIG_MOSIX_FS +#include +#include +#include +#include +#include +#include + +extern struct dentry *lookup_create(struct nameidata *, int); +extern int chown_common(struct dentry *, uid_t, gid_t); + +#define MAX_READLINK 10240 + +void +mfs_prepare_other(struct mfs_completion *c, struct nameidata *ond) +{ + struct dentry *other = ond->dentry; + struct mfs_dinfo *info; + + if(other->d_sb != mfs_super || + !(info = (struct mfs_dinfo *)other->d_fsdata)) + c->other_pe = 0; + else + { + c->other_pe = info->pe; + c->other = info->handle; + if(atomic_read(&other->d_count) > 1) + c->dispose_other = 0; + else + { + kfree(info); + other->d_fsdata = NULL; + c->dispose_other = 1; + } + } +} + +void +mfs_prepare_utime(struct mfs_completion *c, time_t *pa, time_t *pm) +{ + if(get_user(c->args.times.a, pa) || get_user(c->args.times.m, pm)) + { + c->needed = 0; + c->error = -EFAULT; + } +} + +void +mfs_prepare_completion(struct mfs_completion *c, struct nameidata *nd) +{ + struct dentry *base = nd->dentry; + struct utimbuf *ut; + struct timeval *uts; + struct mfs_dinfo *info; + + c->done = 0; + c->other_pe = 0; + c->dispose_other = 0; + c->more_data = NULL; + c->more_data_len = 0; + c->error = 0; + c->ro = mfs_is_ro; +#ifdef CONFIG_MOSIX_DIAG + if(nd->mnt->mnt_sb != mfs_super) + panic("mfs_prepare_completion: bad base\n"); +#endif /* CONFIG_MOSIX_DIAG */ + c->dispose_base = 0; + if((info = (struct mfs_dinfo *)base->d_fsdata)) + { + c->base_pe = info->pe; + c->base = info->handle; + if(atomic_read(&base->d_count) == 1) + { + kfree(info); + base->d_fsdata = NULL; + c->dispose_base = 1; + } + } + else + { + c->base_pe = 0; + c->base = MFS_ROOT_INO; + } + if(!(c->needed = ((nd->flags & LOOKUP_COMPLETE) != 0))) + return; + c->args = nd->complete_args; + switch(c->func = nd->express_function) + { + case EF_OPEN: + case EF_ACCESS: + case EF_UNLINK: + case EF_MKDIR: + case EF_RMDIR: + case EF_TRUNCATE: + case EF_CHOWN: + case EF_CHMOD: + case EF_MKNOD: + return; + case EF_RENAME: + if(nd->complete_args.oldnd->last_type == LAST_NORM) + { + c->more_data = (char *) + nd->complete_args.oldnd->last.name; + c->more_data_len = strlen(c->more_data)+1; + } + /* fall through */ + case EF_LINK: + mfs_prepare_other(c, nd->complete_args.oldnd); + return; + case EF_SYMLINK: + c->more_data = nd->complete_parg; + c->more_data_len = strlen(c->more_data)+1; + return; + case EF_READLINK: + if(c->args.buffer.bufsiz > MAX_READLINK) + c->args.buffer.bufsiz = MAX_READLINK; + return; + case EF_UTIME: + ut = (struct utimbuf *)nd->complete_parg; + if(ut) + mfs_prepare_utime(c, &ut->actime, &ut->modtime); + else + c->other_pe = 1; + return; + case EF_UTIMES: + uts = (struct timeval *)nd->complete_parg; + if(uts) + mfs_prepare_utime(c, &uts[0].tv_sec, + &uts[1].tv_sec); + else + c->other_pe = 1; + return; + case EF_STAT: + nd->complete_parg = NULL; + return; + default: + c->needed = 0; + return; + } +} + +int +mfs_low_complete_link(struct mfs_completion *c, struct nameidata *nd) +{ + struct nameidata ond; + int err; + struct dentry *new_dentry; + + if(c->other_pe != MFS_PE) + return(-EXDEV); + if((err = mfs_to_local(c->other, &ond))) + return(err); + err = -EXDEV; + if(ond.mnt != nd->mnt) + goto out; + new_dentry = lookup_create(nd, 0); + if(IS_ERR(new_dentry)) + err = PTR_ERR(new_dentry); + else + { + err = vfs_link(ond.dentry, nd->dentry->d_inode, new_dentry); + dput(new_dentry); + } + up(&nd->dentry->d_inode->i_sem); + out: + mfs_lput(ond.dentry, ond.mnt); + return(err); +} + +int +mfs_low_complete_unlink(struct mfs_completion *c, struct nameidata *nd) +{ + int err; + struct dentry *dentry; + + if(nd->last_type != LAST_NORM) + return(-EISDIR); + down(&nd->dentry->d_inode->i_sem); + dentry = lookup_hash(&nd->last, nd->dentry); + if(IS_ERR(dentry)) + err = PTR_ERR(dentry); + else + { + if(!dentry->d_inode) + err = -ENOENT; + else if(nd->last.name[nd->last.len]) + err = S_ISDIR(dentry->d_inode->i_mode) ? + -EISDIR : -ENOTDIR; + else + err = vfs_unlink(nd->dentry->d_inode, dentry); + dput(dentry); + } + up(&nd->dentry->d_inode->i_sem); + return(err); +} + +int +mfs_low_complete_symlink(struct mfs_completion *c, struct nameidata *nd) +{ + int err; + struct dentry *dentry; + + dentry = lookup_create(nd, 0); + if(IS_ERR(dentry)) + err = PTR_ERR(dentry); + else + { + err = vfs_symlink(nd->dentry->d_inode, dentry, c->more_data); + dput(dentry); + } + up(&nd->dentry->d_inode->i_sem); + return(err); +} + +int +mfs_low_complete_mkdir(struct mfs_completion *c, struct nameidata *nd) +{ + int err; + struct dentry *dentry; + + dentry = lookup_create(nd, 1); + if(IS_ERR(dentry)) + err = PTR_ERR(dentry); + else + { + err = vfs_mkdir(nd->dentry->d_inode, dentry, c->args.ints.i1); + dput(dentry); + } + up(&nd->dentry->d_inode->i_sem); + return(err); +} + +int +mfs_low_complete_mknod(struct mfs_completion *c, struct nameidata *nd) +{ + int err; + struct dentry *dentry; + int mode = c->args.ints.i1; + + dentry = lookup_create(nd, 1); + if(IS_ERR(dentry)) + err = PTR_ERR(dentry); + else + { + switch(mode & S_IFMT) + { + case 0: + case S_IFREG: + err = vfs_create(nd->dentry->d_inode, dentry, + mode); + break; + case S_IFCHR: + case S_IFBLK: + case S_IFIFO: + case S_IFSOCK: + case S_IFDIR: + err = -EPERM; + break; + default: + err = -EINVAL; + break; + } + dput(dentry); + } + up(&nd->dentry->d_inode->i_sem); + return(err); +} + +int +mfs_low_complete_rmdir(struct mfs_completion *c, struct nameidata *nd) +{ + int err; + struct dentry *dentry; + + switch(nd->last_type) + { + case LAST_NORM: + break; + case LAST_DOTDOT: + return(-ENOTEMPTY); + default: + return(-EBUSY); + } + down(&nd->dentry->d_inode->i_sem); + dentry = lookup_hash(&nd->last, nd->dentry); + if(IS_ERR(dentry)) + err = PTR_ERR(dentry); + else + { + err = vfs_rmdir(nd->dentry->d_inode, dentry); + dput(dentry); + } + up(&nd->dentry->d_inode->i_sem); + return(err); +} + +int +mfs_low_complete_rename(struct mfs_completion *c, struct nameidata *newnd) +{ + struct nameidata ond; + int err; + struct dentry *old_dir, *new_dir; + struct dentry *old_dentry, *new_dentry; + + if(c->other_pe != MFS_PE) + return(-EXDEV); + if((err = mfs_to_local(c->other, &ond))) + return(err); + if(c->more_data_len) + { + unsigned int hash = init_name_hash(); + const unsigned char *n; + + ond.last_type = LAST_NORM; + ond.last.name = c->more_data; + ond.last.len = strlen(c->more_data); + for(n = ond.last.name ; *n && *n != '/' ; n++) + hash = partial_name_hash(*n, hash); + ond.last.hash = end_name_hash(hash); + } + err = -EXDEV; + if(ond.mnt != newnd->mnt) + goto out; + err = -EBUSY; + if (ond.last_type != LAST_NORM || newnd->last_type != LAST_NORM) + goto out; + old_dir = ond.dentry; + new_dir = newnd->dentry; + double_lock(new_dir, old_dir); + + old_dentry = lookup_hash(&ond.last, old_dir); + err = PTR_ERR(old_dentry); + if (IS_ERR(old_dentry)) + goto out1; + /* source must exist */ + err = -ENOENT; + if (!old_dentry->d_inode) + goto out2; + /* unless the source is a directory trailing slashes give -ENOTDIR */ + if (!S_ISDIR(old_dentry->d_inode->i_mode)) { + err = -ENOTDIR; + if (ond.last.name[ond.last.len]) + goto out2; + if (newnd->last.name[newnd->last.len]) + goto out2; + } + new_dentry = lookup_hash(&newnd->last, new_dir); + err = PTR_ERR(new_dentry); + if (IS_ERR(new_dentry)) + goto out2; + + lock_kernel(); + err = vfs_rename(old_dir->d_inode, old_dentry, new_dir->d_inode, + new_dentry); + unlock_kernel(); + + dput(new_dentry); + out2: + dput(old_dentry); + out1: + double_up(&new_dir->d_inode->i_sem, &old_dir->d_inode->i_sem); + out: + mfs_lput(ond.dentry, ond.mnt); + return(err); +} + +int +mfs_low_complete_readlink(struct mfs_completion *c, struct nameidata *nd) +{ + char *buf; + mm_segment_t old_fs = get_fs(); + int err; + struct inode *ip = nd->dentry->d_inode; + int sz = c->args.buffer.bufsiz; + + if(!ip) + return(-ENOENT); + if(!ip->i_op || !ip->i_op->readlink) + return(-EINVAL); + if(ip->i_op && ip->i_op->revalidate && + (err = ip->i_op->revalidate(nd->dentry))) + return(err); + if(!(buf = kmalloc(sz, GFP_KERNEL))) + return(-ENOMEM); + UPDATE_ATIME(ip); + set_fs(KERNEL_DS); + if(!ip->i_op || !ip->i_op->readlink) + err = -EINVAL; + else + err = ip->i_op->readlink(nd->dentry, buf, sz); + set_fs(old_fs); + if(err > 0) + { + c->more_data = buf; + c->more_data_len = err; + } + else + kfree(buf); + return(err); +} + +int +mfs_low_complete_truncate(struct mfs_completion *c, struct nameidata *nd) +{ + int err; + struct inode *ip = nd->dentry->d_inode; + + if(!S_ISREG(ip->i_mode)) + return(-EACCES); + if((err = permission(ip, MAY_WRITE))) + return(err); + if(IS_RDONLY(ip)) + return(-EROFS); + if(IS_IMMUTABLE(ip) || IS_APPEND(ip)) + return(-EPERM); + if((err = get_write_access(ip))) + return(err); + if(!(err = locks_verify_truncate(ip, NULL, c->args.len))) + { + DQUOT_INIT(ip); + err = do_truncate(nd->dentry, c->args.len); + } + put_write_access(ip); + return(err); +} + +int +mfs_low_complete_utime(struct mfs_completion *c, struct nameidata *nd) +{ + int err; + struct iattr newattrs; + struct inode *ip = nd->dentry->d_inode; + + if(IS_RDONLY(ip)) + return(-EROFS); + newattrs.ia_valid = ATTR_CTIME | ATTR_MTIME | ATTR_ATIME; + if(c->other_pe) + { + if((err = permission(ip, MAY_WRITE))) + return(err); + } + else + { + newattrs.ia_atime = c->args.times.a; + newattrs.ia_mtime = c->args.times.m; + newattrs.ia_valid |= ATTR_ATIME_SET | ATTR_MTIME_SET; + } + return(notify_change(nd->dentry, &newattrs)); +} + +int +mfs_low_complete_chmod(struct mfs_completion *c, struct nameidata *nd) +{ + struct iattr newattrs; + mode_t mode = c->args.mode; + struct inode *ip = nd->dentry->d_inode; + + if(IS_RDONLY(ip)) + return(-EROFS); + if(IS_IMMUTABLE(ip) || IS_APPEND(ip)) + return(-EPERM); + if (mode == (mode_t) -1) + mode = ip->i_mode; + newattrs.ia_mode = (mode & S_IALLUGO) | (ip->i_mode & ~S_IALLUGO); + newattrs.ia_valid = ATTR_MODE | ATTR_CTIME; + return(notify_change(nd->dentry, &newattrs)); +} + +int +mfs_low_complete_stat(struct mfs_completion *c, struct nameidata *nd) +{ + int err; + struct inode *ip = nd->dentry->d_inode; + + if (ip->i_op && ip->i_op->revalidate && + (err = ip->i_op->revalidate(nd->dentry))) + return(err); + if(!(c->more_data = kmalloc(sizeof(struct subinode), GFP_KERNEL))) + return(-ENOMEM); + c->more_data_len = sizeof(struct subinode); + ip = nd->dentry->d_inode; + mfs_ip_to_subip((struct subinode *)c->more_data, ip); + ((struct subinode *)c->more_data)->si_ino = global_inum(ip); + return(0); +} + +mfs_handle_t +mfs_low_complete(struct mfs_completion *c, struct nameidata *nd) +{ + mfs_handle_t result; + + if(!c->needed) + goto export; + c->error = 0; + c->done = 1; + if(c->ro) + current->mosix.dirty_bits |= MFSARG_RONLY; + switch(c->func) + { + case EF_OPEN: + c->error = open_namei(NULL, c->args.ints.i1, + c->args.ints.i2, nd); + break; + case EF_ACCESS: + c->error = permission(nd->dentry->d_inode, + c->args.ints.i1); + break; + case EF_LINK: + c->error = mfs_low_complete_link(c, nd); + break; + case EF_UNLINK: + c->error = mfs_low_complete_unlink(c, nd); + break; + case EF_SYMLINK: + c->error = mfs_low_complete_symlink(c, nd); + c->more_data = NULL; + c->more_data_len = 0; + break; + case EF_MKDIR: + c->error = mfs_low_complete_mkdir(c, nd); + break; + case EF_MKNOD: + c->error = mfs_low_complete_mknod(c, nd); + break; + case EF_RMDIR: + c->error = mfs_low_complete_rmdir(c, nd); + break; + case EF_RENAME: + c->error = mfs_low_complete_rename(c, nd); + c->more_data = NULL; + c->more_data_len = 0; + break; + case EF_READLINK: + c->error = mfs_low_complete_readlink(c, nd); + break; + case EF_TRUNCATE: + c->error = mfs_low_complete_truncate(c, nd); + break; + case EF_UTIME: + case EF_UTIMES: + c->error = mfs_low_complete_utime(c, nd); + break; + case EF_CHMOD: + c->error = mfs_low_complete_chmod(c, nd); + break; + case EF_CHOWN: + c->error = chown_common(nd->dentry, c->args.ids.uid, + c->args.ids.gid); + break; + case EF_STAT: + c->error = mfs_low_complete_stat(c, nd); + break; + default: + c->done = 0; + break; + } + current->mosix.dirty_bits &= ~MFSARG_RONLY; + if(c->dispose_other && c->other_pe == MFS_PE) + { + c->dispose_other = 0; + mfs_low_dispose_handle(c->other); + } + if(c->dispose_base && c->base_pe == MFS_PE) + { + c->dispose_base = 0; + mfs_low_dispose_handle(c->base); + } + if(c->done && (c->func != EF_OPEN || c->error)) + return(0); + export: + if(!(result = local_to_mfs(nd))) + { + if(c->more_data) + { + kfree(c->more_data); + c->more_data = NULL; + c->more_data_len = 0; + } + c->error = -ENOMEM; + path_release(nd); + if(c->needed) + c->done = 1; + } + return(result); +} + +void +mfs_low_complete_error(struct mfs_completion *c, int err) +{ + if(c->dispose_base && c->base_pe == MFS_PE) + { + c->dispose_base = 0; + mfs_low_dispose_handle(c->base); + } + if(c->dispose_other && c->other_pe == MFS_PE) + { + c->dispose_other = 0; + mfs_low_dispose_handle(c->other); + } + c->error = err; + c->more_data = NULL; /* in case of EF_SYMLINK */ + c->more_data_len = 0; + if(c->needed) + c->done = 1; +} + +int +mfs_check_completion(struct mfs_completion *c, struct nameidata *nd) +{ + struct inode *inode; + struct subinode *subip; + + if(c->dispose_other) + mfs_dispose_handle(c->other_pe, c->other); + if(c->dispose_base) + mfs_dispose_handle(c->base_pe, c->base); + if(!c->done) + return(0); + nd->complete_flags |= COMPLETE_DONE; + if(c->error && (c->func != EF_READLINK || c->error < 0)) + return(1); + switch(c->func) + { + case EF_OPEN: + return(0); + case EF_STAT: + nd->complete_parg = NULL; + if(!(subip = (struct subinode *)c->more_data)) + { + if(!c->error) + c->error = -ENOMEM; + return(1); + } + if((inode = (struct inode *) + kmalloc(sizeof(struct inode), GFP_KERNEL))) + { + path_release(nd); + mfs_subip_to_ip(inode, subip); + inode->i_ino = + ((struct subinode *)c->more_data)->si_ino; + inode->i_dev = mfs_super->s_dev; + inode->u.mfs_i.pe = c->other_pe; + nd->complete_parg = inode; + /* the caller must later kfree this! */ + } + else if(!c->error) + c->error = -ENOMEM; + kfree(subip); + return(1); + case EF_READLINK: + if(c->more_data) + { + if(c->error >= 0 && + copy_to_user((void *)c->args.buffer.buf, + c->more_data, c->more_data_len)) + c->error = -EFAULT; + kfree(c->more_data); + path_release(nd); + } + else if(c->error >= 0) + c->error = -ENOMEM; + return(1); + default: + path_release(nd); + case 0: + return(1); + } +} + +int +mfs_link_complete(struct mfs_completion *c, int pe, struct nameidata *nd) +{ + int result; + char node[6]; + int len, copy; + struct inode *ip; + + if(c->dispose_other) + mfs_dispose_handle(c->other_pe, c->other); + if(c->dispose_base) + mfs_dispose_handle(c->base_pe, c->base); + if(!c->needed) + return(-EPERM); + nd->complete_flags |= COMPLETE_DONE; + switch(c->func) + { + case EF_READLINK: + sprintf(node, "%d", pe); + len = strlen(node); + result = copy = min(len, c->args.buffer.bufsiz); + if(copy_to_user((void *)c->args.buffer.buf, node, copy)) + return(-EFAULT); + break; + case EF_STAT: + if(!(ip = (struct inode *) + kmalloc(sizeof(*ip), GFP_KERNEL))) + return(-ENOMEM); + nd->complete_parg = ip; + memset(ip, 0, sizeof(*ip)); + ip->i_dev = mfs_super->s_dev; + ip->i_ino = pe; + ip->u.mfs_i.pe = pe; + ip->i_mode = S_IFLNK | 0555; + ip->i_nlink = 1; + for(len = pe ; len ; len /= 10) + ip->i_size++; + ip->i_version = pe; + result = 0; + break; + default: + return(-EPERM); + } + path_release(nd); + return(result); +} +#endif /* CONFIG_MOSIX_FS */ diff -urN linux-2.4.17/fs/mfs/convert.c linux_umopenmosix/fs/mfs/convert.c --- linux-2.4.17/fs/mfs/convert.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/fs/mfs/convert.c Sun Jun 23 12:40:11 2002 @@ -0,0 +1,629 @@ +/* + * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il) + * Some sections copyright 2002 by Moshe Bar + * Permission to use this software is hereby granted under the terms of the + * GNU General Public License, as published by the Free Software Foundation. + * + * THIS SOFTWARE IS PROVIDED IN ITS "AS IS" CONDITION, WITH NO WARRANTY + * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING + * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED. + */ +/* + * Author(s): Amnon Shiloh, Moshe Bar + */ + +#include +#ifdef CONFIG_MOSIX_FS +#include +#include +#include +#include + +static struct semaphore mfsc_sem = __MUTEX_INITIALIZER(mfsc_sem); + +mfs_handle_t mfs_unique; +struct dentry *mfs_root; +struct vfsmount *mfs_mnt; +ino_t mfs_root_ino; +dev_t mfs_root_dev; +int mfs_root_usage; + +#define MFS_HASHES 64 +struct mfs_map +{ + struct list_head llist; + struct list_head glist; + mfs_handle_t handle; + struct dentry *l; + struct vfsmount *mnt; + int dcount; /* inc: local_to_mfs ; dec: mfs_put_handle */ + int usecount; /* inc: mfs_to_local ; dec: mfs_lput */ + unsigned long latest; +}; + +static struct list_head lhash[MFS_HASHES], ghash[MFS_HASHES]; + +static inline int +hash_dentry(struct dentry *d) +{ + return(((((unsigned int)d) >> 8) + (((unsigned int)d) >> 14) + + (((unsigned int)d) >> 20)) % MFS_HASHES); +} + +static inline int +hash_handle(mfs_handle_t l) +{ + unsigned int h = l; + + return((h+(h>>6)+(h>>12)+(h>>18)+(h>>24)) % MFS_HASHES); +} + +int +mfs_conversion_init(void) +{ + int i; + + if(!mfs_unique) + { + mfs_root = dget(current->fs->root); + mfs_mnt = mntget(current->fs->rootmnt); + mfs_root_ino = mfs_root->d_inode->i_ino; + mfs_root_dev = mfs_root->d_inode->i_dev; + mfs_unique = ((mfs_handle_t) CURRENT_TIME) << 31; + if(mfs_unique <= MFS_ROOT_INO) /* 0 time? */ + mfs_unique = MFS_ROOT_INO + 1; + for(i = 0 ; i < MFS_HASHES ; i++) + { + INIT_LIST_HEAD(&lhash[i]); + INIT_LIST_HEAD(&ghash[i]); + } + } + return(0); +} + +void +mfs_put(struct mfs_map *m, int putuse) +{ + struct list_head *x, *nex, *prv; + + if(putuse) + m->usecount--; + else + m->dcount--; + if(m->usecount > 0 || m->dcount > 0) + return; + x = &m->llist; + nex = x->next; + prv = x->prev; + nex->prev = prv; + prv->next = nex; + x = &m->glist; + nex = x->next; + prv = x->prev; + nex->prev = prv; + prv->next = nex; + dput(m->l); + mntput(m->mnt); + kfree(m); +} + +void +mfs_change_root(struct dentry *from, struct vfsmount *frommnt, + struct dentry *to, struct vfsmount *tomnt) +{ + int h; + struct list_head *head, *x; + struct mfs_map *m, *new = NULL; + int new_root_usage = 0; + + down(&mfsc_sem); + if(from != mfs_root || frommnt != mfs_mnt || + (to == from && tomnt == frommnt)) + goto out; + if(mfs_root_usage && !(new = (struct mfs_map *) + kmalloc(sizeof (struct mfs_map), GFP_KERNEL))) + { + printk("MFS root failed to change (ENOMEM)!\n"); + goto out; + } + + /* is the new root listed? (if so, and no external refs, remove it) */ + head = &lhash[hash_dentry(to)]; + for(x = head->next ; x != head ; x = x->next) + { + m = (struct mfs_map *)((char *)x - + offsetof(struct mfs_map, llist)); + if(m->l == to && m->mnt == tomnt) + { + new_root_usage = m->dcount; + m->dcount = 1; + mfs_put(m, 0); + break; + } + } + + if(mfs_root_usage) + { + /* someone is actively using the old root, + * so we must set it up as a normal hashed entry */ + new->l = dget(from); + new->mnt = mntget(frommnt); + new->dcount = 0; + new->usecount = mfs_root_usage; + new->handle = mfs_unique++; + new->latest = jiffies; + h = hash_dentry(from); + new->llist.next = lhash[h].next; + lhash[h].next->prev = &new->llist; + new->llist.prev = &lhash[h]; + lhash[h].next = &new->llist; + h = hash_handle(new->handle); + new->glist.next = ghash[h].next; + ghash[h].next->prev = &new->glist; + new->glist.prev = &ghash[h]; + ghash[h].next = &new->glist; + new = NULL; + } + dget(to); + mntget(tomnt); + mfs_root = to; + mfs_mnt = tomnt; + mfs_root_ino = to->d_inode->i_ino; + mfs_root_dev = to->d_inode->i_dev; + mfs_root_usage = new_root_usage; + dput(from); + mntput(frommnt); + if(new) + kfree(new); + out: + up(&mfsc_sem); +} + +mfs_handle_t +local_to_mfs(struct nameidata *local) +{ + struct dentry *dp = local->dentry; + struct vfsmount *mnt = local->mnt; + int h = hash_dentry(dp); + struct list_head *head = &lhash[h], *x; + struct mfs_map *m; + + down(&mfsc_sem); + if(dp == mfs_root && mnt == mfs_mnt) + { + up(&mfsc_sem); + return(MFS_PE); + } + for(x = head->next ; x != head ; x = x->next) + { + m = (struct mfs_map *)((char *)x - + offsetof(struct mfs_map, llist)); + if(m->l == dp && mnt == mnt) + { + m->dcount++; + up(&mfsc_sem); + return(m->handle); + } + } + if(!(m = (struct mfs_map *)kmalloc(sizeof (struct mfs_map),GFP_KERNEL))) + { + up(&mfsc_sem); + return(0); + } + m->l = dget(dp); + m->mnt = mntget(mnt); + m->dcount = 1; + m->usecount = 0; + m->handle = mfs_unique++; + m->llist.next = lhash[h].next; + lhash[h].next->prev = &m->llist; + m->llist.prev = &lhash[h]; + lhash[h].next = &m->llist; + h = hash_handle(m->handle); + m->glist.next = ghash[h].next; + ghash[h].next->prev = &m->glist; + m->glist.prev = &ghash[h]; + ghash[h].next = &m->glist; + m->latest = jiffies; + up(&mfsc_sem); + return(m->handle); +} + +int +mfs_to_local(mfs_handle_t handle, struct nameidata *local) +{ + struct list_head *head, *x, *nex, *prv; + struct mfs_map *m; + + down(&mfsc_sem); + if(handle == MFS_PE) + { + its_the_root: + mfs_root_usage++; + local->dentry = mfs_root; + local->mnt = mfs_mnt; + up(&mfsc_sem); + return(0); + } + if(handle < MFS_ROOT_INO) + { + up(&mfsc_sem); + return(-EINVAL); + } + head = &ghash[hash_handle(handle)]; + for(x = head->next ; x != head ; x = x->next) + { + m = (struct mfs_map *)((char *)x - + offsetof(struct mfs_map, glist)); + if(m->handle == handle) + { + local->dentry = m->l; + local->mnt = m->mnt; + if(m->l == mfs_root && m->mnt == mfs_mnt) + /* very rare, but possible after root change */ + goto its_the_root; + m->usecount++; + /* move to head of queues: */ + if(x != head->next) + { + nex = x->next; + prv = x->prev; + nex->prev = prv; + prv->next = nex; + x->next = head->next; + x->prev = head; + x->next->prev = x; + head->next = x; + } + head = &lhash[hash_dentry(local->dentry)]; + x = &m->llist; + if(x != head->next) + { + nex = x->next; + prv = x->prev; + nex->prev = prv; + prv->next = nex; + x->next = head->next; + x->prev = head; + x->next->prev = x; + head->next = x; + } + m->latest = jiffies; + up(&mfsc_sem); + return(0); + } + } + up(&mfsc_sem); + printk("MFS: Handle %016LX not found (obsolete)\n", handle); + return(-ESTALE); +} + +void +mfs_lput(struct dentry *dp, struct vfsmount *mnt) +{ + struct list_head *head, *x; + struct mfs_map *m; + + down(&mfsc_sem); + if(dp == mfs_root && mnt == mfs_mnt) + { + mfs_root_usage--; + up(&mfsc_sem); + return; + } + head = &lhash[hash_dentry(dp)]; + for(x = head->next ; x != head ; x = x->next) + { + m = (struct mfs_map *)((char *)x - + offsetof(struct mfs_map, llist)); + if(m->l == dp && m->mnt == mnt) + { + mfs_put(m, 1); + up(&mfsc_sem); + return; + } + } + up(&mfsc_sem); + printk("mfs_lput: no handle!\n"); +} + +int +mfs_get_handle(mfs_handle_t handle) +{ + int h = hash_handle(handle); + struct list_head *head = &ghash[h], *x; + struct mfs_map *m; + + if(handle < MFS_ROOT_INO) + return(0); + down(&mfsc_sem); + for(x = head->next ; x != head ; x = x->next) + { + m = (struct mfs_map *)((char *)x - + offsetof(struct mfs_map, glist)); + if(m->handle == handle) + { + m->dcount++; + m->latest = jiffies; + up(&mfsc_sem); + return(0); + } + } + up(&mfsc_sem); + printk("MFS: Handle %016LX not found (obsolete) when duplicated\n", + handle); + return(-ESTALE); +} + +int +mfs_access_handle(mfs_handle_t handle) +{ + int h = hash_handle(handle); + struct list_head *head = &ghash[h], *x; + struct mfs_map *m; + + if(handle < MFS_ROOT_INO) + return(0); + down(&mfsc_sem); + for(x = head->next ; x != head ; x = x->next) + { + m = (struct mfs_map *)((char *)x - + offsetof(struct mfs_map, glist)); + if(m->handle == handle) + { + m->latest = jiffies; + up(&mfsc_sem); + return(0); + } + } + up(&mfsc_sem); + printk("MFS: Handle %016LX not found (obsolete) when claimed\n", + handle); + return(-ESTALE); +} + +void +mfs_put_handle(mfs_handle_t handle) +{ + int h = hash_handle(handle); + struct list_head *head = &ghash[h], *x; + struct mfs_map *m; + + if(handle < MFS_ROOT_INO) + return; + down(&mfsc_sem); + for(x = head->next ; x != head ; x = x->next) + { + m = (struct mfs_map *)((char *)x - + offsetof(struct mfs_map, glist)); + if(m->handle == handle) + { + mfs_put(m, 0); + up(&mfsc_sem); + return; + } + } + up(&mfsc_sem); + printk("MFS: Handle %016LX not found (obsolete) when released\n", + handle); +} + +int +mfs_try_to_cleanup(int force) +{ + int h; + struct mfs_map *m; + struct list_head *next; + + if(!mfs_unique) + return(0); + down(&mfsc_sem); + if(force != 2) + for(h = 0 ; h < MFS_HASHES ; h++) + while(lhash[h].next != &lhash[h]) + { + m = (struct mfs_map *)((char *)lhash[h].next - + offsetof(struct mfs_map, llist)); + if(!force || m->usecount) + { + busy: + up(&mfsc_sem); + return(-EBUSY); + } + } + for(h = 0 ; h < MFS_HASHES ; h++) + for(next = lhash[h].next ; next != &lhash[h] ; ) + { + m = (struct mfs_map *)((char *)next - + offsetof(struct mfs_map, llist)); + next = next->next; + if(m->usecount) + { + if(force == 2) + m->dcount = 0; + else + goto busy; + } + else + { + m->dcount = 1; + mfs_put(m, 0); + } + } + up(&mfsc_sem); + return(0); +} + +void +mfs_throw_garbage(void) +{ + int h; + struct mfs_map *m; + struct list_head *next; + int n = 0; + + down(&mfsc_sem); + for(h = 0 ; h < MFS_HASHES ; h++) + for(next = lhash[h].next ; next != &lhash[h] ; ) + { + m = (struct mfs_map *)((char *)lhash[h].next - + offsetof(struct mfs_map, llist)); + next = next->next; + if(!m->usecount && + time_after(jiffies, m->latest + MFS_GARBAGE_TIME)) + { + m->dcount = 1; + mfs_put(m, 0); + n++; + } + } + up(&mfsc_sem); + if(n) + printk("MFS: Disposed of %d unclaimed entr%s\n", n, + n > 1 ? "ies" : "y"); +} + +/* why is this not in dcache.c? */ +int +is_descendant(struct dentry *dp, struct vfsmount *mnt, struct dentry *pdp, + struct vfsmount *pmnt) +{ + spin_lock(&dcache_lock); + while(1) + { + if(dp == pdp && mnt == pmnt) + { + spin_unlock(&dcache_lock); + return(1); + } + if(dp == mnt->mnt_root) + { + struct vfsmount *xmnt = mnt->mnt_parent; + + if(xmnt == mnt) + break; + dp = mnt->mnt_mountpoint; + mnt = xmnt; + } + else + dp = dp->d_parent; + } + spin_unlock(&dcache_lock); + return(0); +} + +int +mfs_kill(char *filename) +{ + int h; + struct mfs_map *m; + struct list_head *next; + int n = 0; + int error; + mm_segment_t old_fs; + struct nameidata nd; + + old_fs = set_fs(KERNEL_DS); + error = 0; + if(path_init(filename, LOOKUP_POSITIVE, &nd)) + error = path_walk(filename, &nd); + set_fs(old_fs); + if(error) + return(error); + down(&mfsc_sem); + for(h = 0 ; h < MFS_HASHES ; h++) + for(next = lhash[h].next ; next != &lhash[h] ; ) + { + m = (struct mfs_map *)((char *)lhash[h].next - + offsetof(struct mfs_map, llist)); + next = next->next; + if(is_descendant(m->l, m->mnt, nd.dentry, nd.mnt)) + { + m->dcount = 1; + mfs_put(m, 0); + n++; + } + } + up(&mfsc_sem); + if(n) + printk("MFS_KILL: Killed %d entr%s\n", n, n > 1 ? "ies" : "y"); + path_release(&nd); + return(0); +} + +/* JUST FOR DEBUGGING: */ +void +mfs_print_latest(unsigned long when) +{ + int diff = (when - jiffies) / HZ; + + printk(", age="); + if(diff < 0 || diff > 24*3600) + printk("%ld", when); + else if(diff == 0) + printk("in %ld ticks", when - jiffies); + else if(diff < 6000) + printk("%d seconds", diff); + else if(diff < 3600) + printk("%d:%02d minutes", diff/60, diff % 60); + else + printk("%d:%02d:%02d hours", diff/3600, (diff % 3600) / 60, + diff % 60); +} + +int +dump_mfsc(void) +{ + register int h; + struct list_head *head, *x; + struct mfs_map *m; + int cnt = 0; + + for(h = 0 ; h < MFS_HASHES ; h++) + for(head = &lhash[h] , x = head->next ; x != head ; x = x->next) + { + cnt++; + m = (struct mfs_map *)((char *)x - + offsetof(struct mfs_map, llist)); + printk("%d: handle=%016LX, l=%x, ip=%x, count=%d, use=%d", + h, m->handle, + (int)m->l, (int)m->l->d_inode, m->dcount, m->usecount); + if(m->l->d_inode) + printk("\n dev=%d/%d, ino=%ld, mode=0%o", + MAJOR(m->l->d_inode->i_dev), + MINOR(m->l->d_inode->i_dev), + m->l->d_inode->i_ino, m->l->d_inode->i_mode); + mfs_print_latest(m->latest); + printk("\n"); + } + return(cnt); +} + +int +dump_mfsc2(void) +{ + register int h; + struct list_head *head, *x; + struct mfs_map *m; + int cnt = 0; + + for(h = 0 ; h < MFS_HASHES ; h++) + for(head = &ghash[h] , x = head->next ; x != head ; x = x->next) + { + cnt++; + m = (struct mfs_map *)((char *)x - + offsetof(struct mfs_map, glist)); + printk("%d: handle=%016LX, l=%x, ip=%x, count=%d, use=%d", + h, m->handle, + (int)m->l, (int)m->l->d_inode, m->dcount, m->usecount); + if(m->l->d_inode) + printk("\n dev=%d/%d, ino=%ld, mode=0%o", + MAJOR(m->l->d_inode->i_dev), + MINOR(m->l->d_inode->i_dev), + m->l->d_inode->i_ino, m->l->d_inode->i_mode); + mfs_print_latest(m->latest); + printk("\n"); + } + return(cnt); +} +#endif /* CONFIG_MOSIX_FS */ diff -urN linux-2.4.17/fs/mfs/count.c linux_umopenmosix/fs/mfs/count.c --- linux-2.4.17/fs/mfs/count.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/fs/mfs/count.c Sun Jun 23 12:40:11 2002 @@ -0,0 +1,282 @@ +/* + * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il) + * + * Permission to use this software is hereby granted under the terms of the + * GNU General Public License, as published by the Free Software Foundation. + * + * THIS SOFTWARE IS PROVIDED IN ITS "AS IS" CONDITION, WITH NO WARRANTY + * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING + * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED. + */ +/* + * Author(s): Amnon Shiloh. + */ + + +#include +#if defined(CONFIG_MOSIX_FS) && defined(CONFIG_MOSIX_DFSA) +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define weight(_c,_i,_o) ((_c)*2048+(_i)+(_o)) +#define threshold 0xffe00000 + +#define DEBUG_MFSCOUNT +#ifdef DEBUG_MFSCOUNT +int debug_mfscount; + +void do_dump_mfscount(struct task_struct *p) +{ + int i; + struct mfs_stats *s = p->mosix.mfs_stats; + + if(!s || !s->nnodes) + { + printk("%s MFS Statistics for %d(%s)\n", s ? "Empty" : "No", + p->pid, p->comm); + return; + } + for(i = 0 ; i < s->nnodes ; i++) + printk("%d: node #%d, conns=%d, inbytes=%d, outbytes=%d\n", i, + s->nodes[i], (int)s->conns[i], (int)s->inbytes[i], + (int)s->outbytes[i]); +} +#endif /* DEBUG_MFSCOUNT */ + +void +mfs_count(int w, int inbytes, int outbytes) +{ + struct task_struct *p = current; + struct mfs_stats *s = p->mosix.mfs_stats; + register int i; + int64_t prev, worst = 0, best = 0; + int victim = -1; + long new_weight; + + if(!mfs_is_dfsa || !(p->mosix.dflags & (DREMOTE|DSTATSDOWN))) + return; +#ifdef DEBUG_MFSCOUNT + if(debug_mfscount > 1) + printk("mfs_count(%d,%d,%d): ", w, inbytes, outbytes); +#endif /* DEBUG_MFSCOUNT */ + if(w == 0 || w > MOSIX_MAX) + return; + if(!s) + { + if(!(s = kmalloc(sizeof(struct mfs_stats), GFP_KERNEL))) + return; + p->mosix.mfs_stats = s; + s->nnodes = 0; + } + new_weight = weight(1, inbytes, outbytes); + for(i = (s->hint < s->nnodes && s->nodes[s->hint] == w) ? s->hint : + s->nnodes - 1 ; i >= 0 ; i--) + { + prev = weight(s->conns[i], s->inbytes[i], s->outbytes[i]); + if(s->nodes[i] == w) + { + s->conns[i]++; + s->inbytes[i] += inbytes; + s->outbytes[i] += outbytes; + s->hint = i; + if(w != PE && + (((((long)prev)+new_weight)^prev) & threshold)) + mosix_add_to_whereto(p, MFSBALANCE); +#ifdef DEBUG_MFSCOUNT + if(debug_mfscount) + { + printk("Successfully added <%d,%d> to %d\n", + inbytes, outbytes, w); + if(debug_mfscount > 2) + do_dump_mfscount(p); + } +#endif /* DEBUG_MFSCOUNT */ + return; + } + if(victim == -1) + { + best = worst = prev; + victim = i; + } + else + { + if(prev > best) + best = prev; + if(prev < worst) + { + worst = prev; + victim = i; + } + } + } + if((i = s->nnodes) < MAX_MFS_STATNODES) + { + s->nnodes++; + s->nodes[i] = w; + s->conns[i] = 1; + s->inbytes[i] = inbytes; + s->outbytes[i] = outbytes; + s->hint = i; +#ifdef DEBUG_MFSCOUNT + if(debug_mfscount) + { + printk("New MFS stats (%d,%d) for %d\n", + inbytes, outbytes, w); + if(debug_mfscount > 2) + do_dump_mfscount(p); + } +#endif /* DEBUG_MFSCOUNT */ + return; + } + i = victim; + if(--s->conns[i] <= 0 || (s->inbytes[i] -= inbytes) <= 0 || + (s->outbytes[i] -= outbytes) <= 0) + { + if(victim == --s->nnodes) + { +#ifdef DEBUG_MFSCOUNT + if(debug_mfscount) + { + printk("Anulled victim=%d\n", s->nodes[i]); + if(debug_mfscount > 2) + do_dump_mfscount(p); + } +#endif /* DEBUG_MFSCOUNT */ + return; + } + victim = s->nnodes; + s->nodes[i] = s->nodes[victim]; + s->conns[i] = s->conns[victim]; + s->inbytes[i] = s->inbytes[victim]; + s->outbytes[i] = s->outbytes[victim]; + if(s->hint == victim) + s->hint = i; +#ifdef DEBUG_MFSCOUNT + if(debug_mfscount) + { + printk("Anulled/replaced a victim\n"); + if(debug_mfscount > 2) + do_dump_mfscount(p); + } +#endif /* DEBUG_MFSCOUNT */ + } +#ifdef DEBUG_MFSCOUNT + else if(debug_mfscount) + { + printk("Reduced victim=%d by <%d,%d>\n", s->nodes[i], + inbytes, outbytes); + if(debug_mfscount > 2) + do_dump_mfscount(p); + } +#endif /* DEBUG_MFSCOUNT */ + return; +} + +int +mfs_add_stats(struct mfs_stats *add, struct mfs_stats *to, struct mosix_task *m) +{ + register int i, j; + int64_t prev, worst = 0; + int victim = -1; +#if MAX_MFS_STATNODES > BITS_PER_LONG +#error unsigned long is not enough +#else + unsigned long bit, done = 0; +#endif /* MAX_MFS_STATNODES > BITS_PER_LONG */ + int node; + int ret = 0; + + if(!add || !add->nnodes) + return(0); + if(!to) + { + if(!to && (!m || !(to = m->mfs_stats = + kmalloc(sizeof(struct mfs_stats), GFP_KERNEL)))) + return(0); + *to = *add; + for(i = to->nnodes-1 ; i >= 0 ; i--) + if(weight(to->conns[i], to->inbytes[i], to->outbytes[i]) & + threshold) + return(1); + return(0); + } + for(i = 0 ; i < to->nnodes ; i++) + { + node = to->nodes[i]; + for(j = 0 ; j < add->nnodes ; j++) + if(add->nodes[j] == node) + { + prev = weight(to->conns[i], to->inbytes[i], + to->outbytes[i]); + to->conns[i] += add->conns[i]; + to->inbytes[i] += add->inbytes[i]; + to->outbytes[i] += add->outbytes[i]; + if(!ret && node != PE && + (weight(to->conns[i], to->inbytes[i], + to->outbytes[i]) ^ prev) & threshold) + ret = 1; + done |= (1 << (j-1)); + break; + } + } + for(bit = 1 , j = 0 ; j < add->nnodes ; j++ , bit <<= 1) + if(!(done & bit)) + { + if(to->nnodes < MAX_MFS_STATNODES) + { + i = to->nnodes++; + to->nodes[i] = add->nodes[j]; + to->conns[i] = add->conns[j]; + to->inbytes[i] = add->inbytes[j]; + to->outbytes[i] = add->outbytes[j]; + if(!ret && (weight(to->conns[i], to->inbytes[i], + to->outbytes[i]) & threshold)) + ret = 1; + continue; + } + for(i = 0 ; i < MAX_MFS_STATNODES ; i++) + { + prev = weight(add->conns[i], add->inbytes[i], + add->outbytes[i]); + if(i == 0 || prev < worst) + { + victim = i; + worst = prev; + } + } + if(!ret && (weight(add->conns[i], add->inbytes[i], + add->outbytes[i]) & threshold)) + ret = 1; + to->nodes[victim] = add->nodes[i]; + to->conns[victim] = add->conns[i]; + to->inbytes[victim] = add->inbytes[i]; + to->outbytes[victim] = add->outbytes[i]; + } + return(ret); +} + +#ifdef DEBUG_MFSCOUNT +void +dump_mfscount(int pid) +{ + struct task_struct *p; + + if(!pid) + p = current; + else + p = find_any_task_by_pid(pid); + if(p) + do_dump_mfscount(p); + else + printk("No Such Task (%d)\n", pid); +} +#endif /* DEBUG_MFSCOUNT */ + +#endif /* CONFIG_MOSIX_FS && CONFIG_MOSIX_DFSA */ diff -urN linux-2.4.17/fs/mfs/file.c linux_umopenmosix/fs/mfs/file.c --- linux-2.4.17/fs/mfs/file.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/fs/mfs/file.c Sun Jun 23 12:40:11 2002 @@ -0,0 +1,1868 @@ +/* + * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il) + * + * Permission to use this software is hereby granted under the terms of the + * GNU General Public License, as published by the Free Software Foundation. + * + * THIS SOFTWARE IS PROVIDED IN ITS "AS IS" CONDITION, WITH NO WARRANTY + * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING + * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED. + */ +/* + * Author(s): Amnon Shiloh. + */ + + +#include +#ifdef CONFIG_MOSIX_FS +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int MFS_PE; +int mfs_is_mounted; +char mfs_is_ro; +#ifdef CONFIG_MOSIX_DFSA +char mfs_is_dfsa; +#include +#endif /* CONFIG_MOSIX_DFSA */ +#ifdef CONFIG_MOSIX_DEBUG +int mfs_loopback_test = 0; +#else +#define mfs_loopback_test 0 +#endif /* CONFIG_MOSIX_DEBUG */ +int mfs_debug; +struct super_block *mfs_super; +extern int may_create(struct inode *, struct dentry *); + +#define AN_IMPOSSIBLE_ERROR (-ECHILD) /* cannot occur in FS context */ + +ino_t +global_inum(struct inode *ip) +{ + dev_t dev = ip->i_dev; + ino_t mask = (MFS_PE << 16) ^ (MAJOR(dev) << 16) ^ (MINOR(dev) << 24); + ino_t result = ip->i_ino ^ mask; + + if(ip->i_ino == mfs_root_ino && dev == mfs_root_dev) + return(MFS_PE); + if(((unsigned long)result) <= MFS_ROOT_INO) + result ^= 0x80800000; + return(result); +} + +inline void +mfs_get_handling(struct dentry *dp, int *where, mfs_handle_t *handle) +{ + struct mfs_dinfo *p = (struct mfs_dinfo *)dp->d_fsdata; + +#ifdef CONFIG_MOSIX_DIAG + if(!p) + panic("mfs_get_handling: no handle\n"); +#endif /* CONFIG_MOSIX_DIAG */ + *where = p->pe; + *handle = p->handle; +} + +inline int +mfs_is_last_use(struct dentry *dp, int *where, mfs_handle_t *handle) +{ + if(dp->d_fsdata) + { + *where = ((struct mfs_dinfo *)dp->d_fsdata)->pe; + *handle = ((struct mfs_dinfo *)dp->d_fsdata)->handle; + if(atomic_read(&dp->d_count) > 1) + return(0); + kfree(dp->d_fsdata); + dp->d_fsdata = NULL; + return(1); + } + else + { + *where = 0; + *handle = MFS_ROOT_INO; + return(0); + } +} + +inline int +mfs_low_attach_handle(mfs_handle_t handle) +{ + if(handle > MFS_ROOT_INO) /* do not waste time on root */ + return(mfs_get_handle(handle)); + return(0); +} + +inline int +mfs_attach_handle(int pe, mfs_handle_t handle) +{ + if(handle <= MFS_ROOT_INO) + return(0); + mfs_count_attach_handle(pe); + if(pe == MFS_PE && !mfs_loopback_test) + return(mfs_low_attach_handle(handle)); + else if(pe) + return(mfs_client_attach_handle(pe, handle)); + return(0); +} + +inline int +mfs_low_touch_handle(mfs_handle_t handle) +{ + if(handle > MFS_ROOT_INO) /* do not waste time on root */ + return(mfs_access_handle(handle)); + return(0); +} + +inline int +mfs_touch_handle(int pe, mfs_handle_t handle) +{ + if(handle <= MFS_ROOT_INO) + return(0); + mfs_count_touch_handle(pe); + if(pe == MFS_PE && !mfs_loopback_test) + return(mfs_low_touch_handle(handle)); + else if(pe) + return(mfs_client_touch_handle(pe, handle)); + return(0); +} + +inline void +mfs_low_dispose_handle(mfs_handle_t handle) +{ + if(handle > MFS_ROOT_INO) /* do not waste time on root */ + mfs_put_handle(handle); +} + +inline void +mfs_dispose_handle(int pe, mfs_handle_t handle) +{ + if(handle <= MFS_ROOT_INO) + return; + mfs_count_dispose_handle(pe); + if(pe == MFS_PE && !mfs_loopback_test) + mfs_low_dispose_handle(handle); + else if(pe) + mfs_client_dispose_handle(pe, handle); +} + +extern struct file_operations mfs_file_file_operations; +extern struct file_operations mfs_symlink_file_operations; +extern struct file_operations mfs_dir_file_operations; +extern struct inode_operations mfs_file_inode_operations; +extern struct inode_operations mfs_symlink_inode_operations; +extern struct inode_operations mfs_dir_inode_operations; +extern struct dentry_operations mfs_dentry_operations; + +void +mfs_ip_to_subip(struct subinode *subip, struct inode *ip) +{ + subip->si_mode = ip->i_mode; + subip->si_nlink = ip->i_nlink; + subip->si_iuid = ip->i_uid; + subip->si_gid = ip->i_gid; + subip->si_rdev = ip->i_rdev; + subip->si_size = ip->i_size; + subip->si_atime = ip->i_atime; + subip->si_ctime = ip->i_ctime; + subip->si_mtime = ip->i_mtime; + subip->si_blksize = ip->i_blksize; + subip->si_blocks = ip->i_blocks; + subip->si_origino = ip->i_ino; + subip->si_origdev = ip->i_dev; +} + +void +mfs_subip_to_ip(struct inode *ip, struct subinode *subip) +{ + ip->i_mode = subip->si_mode; + ip->i_nlink = subip->si_nlink; + ip->i_uid = subip->si_iuid; + ip->i_gid = subip->si_gid; + ip->i_rdev = subip->si_rdev; + ip->i_size = subip->si_size; + ip->i_atime = subip->si_atime; + ip->i_ctime = subip->si_ctime; + ip->i_mtime = subip->si_mtime; + ip->i_blksize = subip->si_blksize; + ip->i_blocks = subip->si_blocks; + ip->i_version = subip->si_origino; + ip->i_generation = subip->si_origdev; + ip->i_sb = mfs_super; + switch(ip->i_mode & S_IFMT) + { + case S_IFREG: + ip->i_op = &mfs_file_inode_operations; + ip->i_fop = &mfs_file_file_operations; + break; + case S_IFLNK: + ip->i_op = &mfs_symlink_inode_operations; + ip->i_fop = &mfs_symlink_file_operations; + break; + case S_IFDIR: + ip->i_op = &mfs_dir_inode_operations; + ip->i_fop = &mfs_dir_file_operations; + break; + default: + printk("MFS: inum %d of bad mode (0%o)\n", + (int)ip->i_ino, ip->i_mode); + make_bad_inode(ip); + break; + } +} + +void +cp_file_fields(struct file *filto, struct file *filfrom) +{ + filto->f_mode = filfrom->f_mode; + filto->f_pos = filfrom->f_pos; + filto->f_owner = filfrom->f_owner; + filto->f_reada = filfrom->f_reada; + filto->f_ramax = filfrom->f_ramax; + filto->f_raend = filfrom->f_raend; + filto->f_ralen = filfrom->f_ralen; + filto->f_rawin = filfrom->f_rawin; +/* the following two fields are not actually currently in use! + filto->f_uid = filfrom->f_uid; + filto->f_gid = filfrom->f_gid; +*/ + filto->f_error = filfrom->f_error; + filto->f_version = filfrom->f_version; + filto->private_data = filfrom->private_data; +} + +int +prepare_dummy_file(mfs_handle_t handle, struct file *dummy, struct file *filp) +{ + struct nameidata nd; + int err; + + if((err = mfs_to_local(handle, &nd))) + return(err); + if(nd.dentry->d_inode && nd.dentry->d_inode->i_op) + dummy->f_op = nd.dentry->d_inode->i_fop; + else + dummy->f_op = NULL; + dummy->f_dentry = nd.dentry; + dummy->f_vfsmnt = nd.mnt; + dummy->f_flags = filp->f_flags & (O_LARGEFILE|O_SYNC); + dummy->f_iobuf = NULL; + dummy->f_iobuf_lock = 0; + atomic_set(&dummy->f_count, 1); + cp_file_fields(dummy, filp); + return(0); +} + +void +collect_dummy_file(struct file *dummy, struct file *filp) +{ + mfs_lput(dummy->f_dentry, dummy->f_vfsmnt); + cp_file_fields(filp, dummy); +} + +loff_t +mfs_dir_llseek(struct file *filp, loff_t offset, int origin) +{ + int where; + mfs_handle_t handle; + + mfs_get_handling(filp->f_dentry, &where, &handle); + mfs_count_llseek(where); + if(where != MFS_PE || mfs_loopback_test) + return(mfs_client_llseek(where, handle, filp, offset, origin)); + return(mfs_low_llseek(handle, filp, offset, origin)); +} + +loff_t +mfs_file_llseek(struct file *filp, loff_t offset, int origin) +{ + uint64_t newoff; + + switch(origin) + { + case 0: + newoff = offset; + break; + case 1: + newoff = offset + filp->f_pos; + break; + default: + goto must_call; + } + if(!(newoff >> 32)) + { + if(newoff != filp->f_pos) + { + lock_kernel(); + filp->f_pos = newoff; + filp->f_reada = 0; + filp->f_version = ++event; + unlock_kernel(); + } + return(newoff); + } + + must_call: + return(mfs_dir_llseek(filp, offset, origin)); +} + +loff_t +mfs_low_llseek(mfs_handle_t handle, struct file *filp, loff_t offset, + int origin) +{ + loff_t ret; + struct file dummy; + extern loff_t llseek(struct file *, loff_t, int); + + if((ret = prepare_dummy_file(handle, &dummy, filp))) + return(ret); + lock_kernel(); + ret = llseek(&dummy, offset, origin); + unlock_kernel(); + collect_dummy_file(&dummy, filp); + return(ret); +} + +ssize_t +mfs_read(struct file *filp, char *buf, size_t count, loff_t *ppos) +{ + int where; + mfs_handle_t handle; + + if(!(filp->f_mode & FMODE_READ)) + return(-EBADF); + mfs_get_handling(filp->f_dentry, &where, &handle); + mfs_count_read(where, count); + if(where != MFS_PE || mfs_loopback_test) + return(mfs_client_read(where, handle, filp, buf, count, ppos)); + return(mfs_low_read(handle, filp, buf, count, ppos)); +} + +ssize_t +mfs_low_read(mfs_handle_t handle, struct file *filp, char *buf, size_t count, + loff_t *ppos) +{ + loff_t ret; + struct file *dummy; + struct file_operations *fops; + loff_t mppos; + + current->mosix.dirty_bits |= MFSARG_EMPTYF_PRI; + dummy = get_empty_filp(); + current->mosix.dirty_bits &= ~MFSARG_EMPTYF_PRI; + if(!dummy) + return(-ENFILE); + + if((ret = prepare_dummy_file(handle, dummy, filp))) + { + put_filp(dummy); + return(ret); + } + dget(dummy->f_dentry); + mntget(dummy->f_vfsmnt); + fops = dummy->f_dentry->d_inode->i_fop; + mppos = *ppos; +#ifdef ONE_DAY_S_FILES_WILL_BE_USED_FOR_RDONLY_FILES + if(ip->i_sb) + file_move(dummy, &ip->i_sb->s_files); +#endif /* ONE_DAY_S_FILES_WILL_BE_USED_FOR_RDONLY_FILES */ + if(!fops || !fops->read) + ret = -EINVAL; + else + ret = fops->read(dummy, buf, count, &mppos); + collect_dummy_file(dummy, filp); + *ppos = mppos; + dummy->f_mode &= ~FMODE_WRITE; + fput(dummy); + return(ret); +} + +ssize_t +mfs_write(struct file *filp, const char *buf, size_t count, loff_t *ppos) +{ + int where; + mfs_handle_t handle; + int flim = current->rlim[RLIMIT_FSIZE].rlim_cur; + + if(!(filp->f_mode & FMODE_WRITE)) + return(-EBADF); + mfs_get_handling(filp->f_dentry, &where, &handle); + mfs_count_write(where, count); + if(where != MFS_PE || mfs_loopback_test) + return(mfs_client_write(where, handle, filp, (char *)buf, count, + ppos, flim)); + return(mfs_low_write(handle, filp, (char *)buf, count, ppos, flim)); +} + +ssize_t +mfs_low_write(mfs_handle_t handle, struct file *filp, char *buf, size_t count, + loff_t *ppos, long flim) +{ + loff_t ret; + struct file *dummy; + struct file_operations *fops; + struct super_block *sb; + struct inode *ip; + loff_t mppos; + + /* unlike other functions, we need to allocate a dummy "file" + * in the proper way, because NFS files could live even after + * we exit */ + current->mosix.dirty_bits |= MFSARG_EMPTYF_PRI; + dummy = get_empty_filp(); + current->mosix.dirty_bits &= ~MFSARG_EMPTYF_PRI; + if(!dummy) + return(-ENFILE); + + if((ret = prepare_dummy_file(handle, dummy, filp))) + { + put_filp(dummy); + return(ret); + } + dget(dummy->f_dentry); + mntget(dummy->f_vfsmnt); + current->rlim[RLIMIT_FSIZE].rlim_cur = flim; + ip = dummy->f_dentry->d_inode; + sb = ip->i_sb; + fops = ip->i_fop; + mppos = *ppos; + if(filp->f_flags & O_APPEND) + mppos = ip->i_size; + if(sb) + file_move(dummy, &sb->s_files); + if(get_write_access(ip)) + dummy->f_flags |= O_NOWRITEACCESS; + if((ret = locks_verify_area(FLOCK_VERIFY_WRITE, ip, NULL, mppos,count))) + ; + else if(sb && (sb->s_flags & MS_RDONLY)) + ret = -EROFS; + else if(!fops || !fops->write) + ret = -EINVAL; + else + ret = fops->write(dummy, buf, count, &mppos); + collect_dummy_file(dummy, filp); + *ppos = mppos; + fput(dummy); + return(ret); +} + +int +mfs_readdir(struct file *filp, void *dirent, filldir_t filldir) +{ + int where; + mfs_handle_t handle; + struct task_struct *p = current; + int policy; + int packets, bytes; + int result; + + switch(p->mosix.dirty_bits & + (MFSARG_GETDENTS|MFSARG_GETDENTS64|MFSARG_OLDREADDIR)) + { + case MFSARG_GETDENTS: + policy = MFS_READDIR_GETDENTS; + break; + case MFSARG_GETDENTS64: + policy = MFS_READDIR_GETDENTS64; + break; + case MFSARG_OLDREADDIR: + policy = MFS_READDIR_JUSTONE; + break; + default: + policy = MFS_READDIR_UNKNOWN; + break; + } + mfs_get_handling(filp->f_dentry, &where, &handle); + if(where != MFS_PE || mfs_loopback_test) + result = mfs_client_readdir(where, handle, filp, dirent, + filldir, policy, p->mosix.dirty_arg, &packets, &bytes); + else + result = mfs_low_readdir(handle, filp, dirent, filldir, + &packets, &bytes); + mfs_count_readdir(where, packets, bytes); + return(result); +} + +struct mfs_local_readdir_callback +{ + filldir_t realfilldir; + void *realdirent; + struct dentry *parent; + struct vfsmount *pmnt; + int packets, bytes, inbytes; +}; + +int +mfs_local_filldir(void *__cb, const char *name, int namelen, loff_t offset, + ino_t ino, unsigned int type) +{ + struct mfs_local_readdir_callback *cb = __cb; + struct inode ji; + struct inode *ri; + int b = sizeof(ino_t) + sizeof(loff_t) + sizeof(namelen) + + strnlen(name, namelen) + 1; + + cb->bytes += b; + if((cb->inbytes += b) > MFS_MAXBLOCK) + { + cb->packets++; + cb->inbytes = b; + } + ji.i_ino = ino; + ji.i_dev = cb->parent->d_inode->i_dev; + /* to present a single, flat filesystem, we must adjust in case the + * son falls outside the parent's file-system. */ + if(namelen == 1 && name[0] == '.') + ; /* nothing */ + else if(namelen == 2 && name[0] == '.' && name[1] == '.') + { + if(cb->parent == cb->pmnt->mnt_root) + { + ri = cb->pmnt->mnt_mountpoint->d_inode; + ji.i_ino = ri->i_ino; + ji.i_dev = ri->i_dev; + } + } + else + { + struct list_head *p; + struct vfsmount *m; + + spin_lock(&dcache_lock); + for(p = cb->pmnt->mnt_mounts.next ; p != &cb->pmnt->mnt_mounts ; + p = p->next) + { + m = list_entry(p, struct vfsmount, mnt_child); + if(m->mnt_mountpoint->d_inode->i_ino == ji.i_ino) + { + struct inode *mroot = m->mnt_root->d_inode; + + ji.i_dev = mroot->i_dev; + ji.i_ino = mroot->i_ino; + break; + } + } + spin_unlock(&dcache_lock); + } + return(cb->realfilldir(cb->realdirent, name, namelen, offset, + global_inum(&ji), type)); +} + +int +mfs_low_readdir(mfs_handle_t handle, struct file *filp, void *dirent, + filldir_t filldir, int *packets, int *bytes) +{ + int ret; + struct file_operations *fops; + struct file dummy; + struct mfs_local_readdir_callback lrb; + + if((ret = prepare_dummy_file(handle, &dummy, filp))) + return(ret); + fops = dummy.f_dentry->d_inode->i_fop; + lrb.realfilldir = filldir; + lrb.realdirent = dirent; + lrb.parent = dummy.f_dentry; + lrb.pmnt = dummy.f_vfsmnt; + lrb.packets = lrb.bytes = lrb.inbytes = 0; + ret = vfs_readdir(&dummy, mfs_local_filldir, (void *)&lrb); + collect_dummy_file(&dummy, filp); + *packets = lrb.packets; + *bytes = lrb.bytes; + return(ret); +} + +int +mfs_ioctl(struct inode *ip, struct file *filp, unsigned int cmd, unsigned long arg) +{ + int where; + mfs_handle_t handle; + int size; + int data; + int ret; + +#ifdef CONFIG_MOSIX_DIAG + if(ip != filp->f_dentry->d_inode) + { + mosix_panic("mfs_ioctl: not same"); + return(-EINVAL); + } +#endif /* CONFIG_MOSIX_DIAG */ + /* currently supporting only EXT2 ioctls: the following others + * are possible candidates (later): ncpfs, smbfs, umsdos */ + switch(cmd) + { + case EXT2_IOC_GETFLAGS: + case EXT2_IOC_GETVERSION: + size = -(int)sizeof(int); + break; + case EXT2_IOC_SETFLAGS: + case EXT2_IOC_SETVERSION: + size = sizeof(int); + break; + default: + return(-EPERM); + } + if(size > 0 && copy_from_user((void *)&data, (void *)arg, size)) + return(-EFAULT); + mfs_get_handling(filp->f_dentry, &where, &handle); + mfs_count_ioctl(where); + if(where != MFS_PE || mfs_loopback_test) + ret = mfs_client_ioctl(where, handle, filp, cmd, arg, size, + &data); + else + ret = mfs_low_ioctl(handle, filp, cmd, arg, size, &data); + if(!ret && size < 0 && copy_to_user((void *)arg, (void *)&data, -size)) + ret = -EFAULT; + return(ret); +} + +int +mfs_low_ioctl(mfs_handle_t handle, struct file *filp, unsigned int cmd, + unsigned long arg, int size, int *data) +{ + int ret; + struct file_operations *fops; + struct file dummy; + mm_segment_t old_fs; + + if((ret = prepare_dummy_file(handle, &dummy, filp))) + return(ret); + fops = dummy.f_dentry->d_inode->i_fop; + if(!fops || !fops->ioctl) + ret = -ENOTTY; + else + { + if(size) + old_fs = set_fs(KERNEL_DS); + lock_kernel(); + ret = fops->ioctl(dummy.f_dentry->d_inode, &dummy, cmd, + size ? (unsigned long)data : arg); + unlock_kernel(); + if(size) + set_fs(old_fs); + } + collect_dummy_file(&dummy, filp); + return(ret); +} + +int +mfs_mmap(struct file *f, struct vm_area_struct *x) +{ + /* cannot be reached: just a place-holder */ + /* some code (including "binfmt_elf.c") check for the existance of this + * routine, but "do_mmap" will detect that there are no a_ops + * and convert it to a file-read + */ + panic("mfs_mmap"); + return(-ENOSYS); +} + +int +mfs_fsync(struct file *filp, struct dentry *dp, int datasync) +{ + int where; + mfs_handle_t handle; + +#ifdef CONFIG_MOSIX_DIAG + if(dp != filp->f_dentry) + mosix_panic("mfs_fsync: not same"); +#endif /* CONFIG_MOSIX_DIAG */ + mfs_get_handling(dp, &where, &handle); + mfs_count_fsync(where); + if(where != MFS_PE || mfs_loopback_test) + return(mfs_client_fsync(where, handle, filp, datasync)); + return(mfs_low_fsync(handle, filp, datasync)); +} + +int +mfs_low_fsync(mfs_handle_t handle, struct file *filp, int datasync) +{ + int ret; + struct file_operations *fops; + struct file dummy; + + if((ret = prepare_dummy_file(handle, &dummy, filp))) + return(ret); + fops = dummy.f_dentry->d_inode->i_fop; + down(&dummy.f_dentry->d_inode->i_sem); + if(!fops || !fops->fsync) + ret = -EINVAL; + else + ret = fops->fsync(&dummy, dummy.f_dentry, datasync); + up(&dummy.f_dentry->d_inode->i_sem); + collect_dummy_file(&dummy, filp); + return(ret); +} + +static struct file_operations mfs_file_file_operations = +{ + llseek: mfs_file_llseek, + read: mfs_read, + write: mfs_write, + ioctl: mfs_ioctl, + mmap: mfs_mmap, + fsync: mfs_fsync, +}; + +static struct file_operations mfs_symlink_file_operations = +{ + ioctl: mfs_ioctl, +}; + +static struct file_operations mfs_dir_file_operations = +{ + llseek: mfs_dir_llseek, + read: mfs_read, + readdir: mfs_readdir, + ioctl: mfs_ioctl, + fsync: mfs_fsync, +}; + +struct mfs_iphand +{ + int pe; + mfs_handle_t handle; +}; + +int +compare_mfs_ip(struct inode *ip, unsigned long ig1, void *arg) +{ + int pe = ((struct mfs_iphand *)arg)->pe; + + return(!pe || (ip->u.mfs_i.pe == pe && + ip->u.mfs_i.handle == ((struct mfs_iphand *)arg)->handle)); +} + +struct inode *mfs_iget(unsigned long ino, int pe, mfs_handle_t handle) +{ + struct mfs_iphand h; + + h.pe = pe; + h.handle = handle; + current->mosix.iget_mfs_pe = pe; + current->mosix.iget_mfs_handle = handle; + return(iget4(mfs_super, ino, compare_mfs_ip, &h)); +} + +int +mfs_revalidate(struct dentry *dentry) +{ + int where; + mfs_handle_t handle; + int ret; + struct subinode iinfo; + struct inode *ip = dentry->d_inode; + + mfs_get_handling(dentry, &where, &handle); + mfs_ip_to_subip(&iinfo, ip); + mfs_count_revalidate(where); + if(where != MFS_PE || mfs_loopback_test) + ret = mfs_client_revalidate(where, handle, &iinfo); + else + ret = mfs_low_revalidate(handle, &iinfo); + if(!ret) + mfs_subip_to_ip(ip, &iinfo); + return(ret); +} + +int +mfs_low_revalidate(mfs_handle_t handle, struct subinode *iinfo) +{ + struct inode *lip; + int ret; + struct nameidata nd; + + if((ret = mfs_to_local(handle, &nd))) + return(ret); + lip = nd.dentry->d_inode; + if(!lip || !lip->i_op || !lip->i_op->revalidate) + ret = 0; + else + ret = lip->i_op->revalidate(nd.dentry); + if(!ret) + mfs_ip_to_subip(iinfo, lip); + mfs_lput(nd.dentry, nd.mnt); + return(ret); +} + +int +mfs_setattr(struct dentry *dentry, struct iattr *attr) +{ + int where; + mfs_handle_t handle; + + if(mfs_is_ro) + return(-EROFS); + if(!dentry->d_fsdata) /* someone trying to fiddle with the MFS root */ + return(-EPERM); + mfs_get_handling(dentry, &where, &handle); + mfs_count_setattr(where); + if(where != MFS_PE || mfs_loopback_test) + return(mfs_client_setattr(where, handle, attr)); + return(mfs_low_setattr(handle, attr)); +} + +int +mfs_low_setattr(mfs_handle_t handle, struct iattr *attr) +{ + struct nameidata nd; + struct inode *ip; + int ret; + int wa = 0; + + if((ret = mfs_to_local(handle, &nd))) + return(ret); + ret = -EINVAL; + if(!(ip = nd.dentry->d_inode)) + goto out; + if(attr->ia_valid & ATTR_SIZE) + { + /* this must be ftruncate: */ + + if((ret = get_write_access(ip))) + goto out; + wa = 1; + ret = -EISDIR; + if(S_ISDIR(ip->i_mode)) + goto out; + ret = -EINVAL; + if(!S_ISREG(ip->i_mode)) + goto out; + ret = -EPERM; + if(IS_APPEND(ip)) + goto out; + if((ret = locks_verify_truncate(ip, NULL, attr->ia_size))) + goto out; + down(&ip->i_sem); + } + ret = notify_change(nd.dentry, attr); + if(attr->ia_valid & ATTR_SIZE) + up(&ip->i_sem); + out: + if(wa) + put_write_access(ip); + mfs_lput(nd.dentry, nd.mnt); + return(ret); +} + +int +mfs_root_name_to_ino(char *name, int len) +{ + int node = 0; + + if(*name >= '0' && *name <= '9') + while(len && node <= MOSIX_MAX && *name >= '0' && *name <= '9') + { + node = node * 10 + (*name - '0'); + name++; + len--; + } + else if(len) + switch(*name) + { + case 'h': + if(len != 4 || name[3] != 'e') + return(0); + if(name[1] == 'e' && name[2] == 'r') + return(current->mosix.whereami ? : PE); + if(name[1] == 'o' && name[2] == 'm') + return(current->mosix.deppe ? : PE); + break; + case 'l': + if(len == 8 && !memcmp(&name[1], "astexec", 7)) + return(current->mosix.lastexec ? : + (current->mosix.deppe ? : PE)); + break; + case 'm': + if(len == 5 && !memcmp(&name[1], "agic", 4)) + return(current->mosix.lastmagic ? : + (current->mosix.deppe ? : PE)); + case 's': + if(len == 8 && !memcmp(&name[1], "elected", 7)) + return(current->mosix.selected ? : + (current->mosix.deppe ? : PE)); + } + if(len || !mos_to_net(node, NULL)) + node = 0; + return(node); +} + +static void +fill_last_component(char *nam, struct nameidata *nd) +{ + char *start = nam, *end; + + while(*nam) + nam++; + end = nam; + for(nam-- ; *nam == '/' && nam > start ; nam--) + ; + while(nam > start && *(nam-1) != '/') + nam--; + nd->last.name = nam; + nd->last.len = end - nam + 1; + nd->last_type = LAST_NORM; + switch(*nam) + { + case '/': + case '\0': + nd->last_type = LAST_ROOT; + break; + case '.': + switch(*(nam+1)) + { + case '.': + if(*(nam+2) == '/' || *(nam+2) == '\0') + nd->last_type = LAST_DOTDOT; + break; + case '/': + case '\0': + nd->last_type = LAST_DOT; + return; + } + break; + } +} + +int +mfs_express_lookup(struct nameidata *nd, char **name) +{ + char *nam = *name; + struct vfsmount *mnt; + int pe; + mfs_handle_t handle; + struct subinode iinfo; + struct inode *ip; + struct qstr qnam; + char *newname = NULL; + struct mfs_completion complete; + struct dentry *result; + int err; + int magic = 0; + int link = 0; +#ifdef CONFIG_MOSIX_DFSA + unsigned int flags = nd->flags & ~(LOOKUP_COMPLETE|LOOKUP_STAYFS); +#else + unsigned int flags = nd->flags & ~LOOKUP_COMPLETE; +#endif /* CONFIG_MOSIX_DFSA */ + + mfs_prepare_completion(&complete, nd); + if(complete.error < 0) + { + mfs_check_completion(&complete, nd); + return(complete.error); + } + pe = complete.base_pe; + handle = complete.base; + *name = NULL; + while(*nam) + { + if(pe == 0) + { + char *c; + + if(*nam == '.') + switch(*(nam+1)) + { + case '\0': + nam++; + continue; + case '/': + nam += 2; + while(*nam == '/') + nam++; + continue; + case '.': + if(*(nam+2) == '\0' || *(nam+2) == '/') + goto name_leads_back; + break; + } + for(c = nam ; *c && *c != '/' ; c++) + ; + pe = mfs_root_name_to_ino(nam, c - nam); + handle = pe; + if(!pe) + { + mfs_check_completion(&complete, nd); +#ifdef CONFIG_MOSIX_DFSA + if(current->mosix.dflags & DREMOTE) + return(-EDOITATHOME); +#endif /* CONFIG_MOSIX_DFSA */ + return(-ENOENT); + } + if(nam[0] == 'm') + magic = 1; + link = (nam[0] >= 'a'); + while(*c == '/') + c++; + nam = c; + } + if(flags & LOOKUP_MFS) + { + /* server may only access the MFS root itself or reach + * back to the node's root via the correct link */ + mfs_check_completion(&complete, nd); + if(pe != MFS_PE || !(flags & LOOKUP_MFS_MFS)) + return(-EACCES); + nd->flags &= ~LOOKUP_MFS_MFS; + dput(nd->dentry); + mntput(nd->mnt); + nd->dentry = dget(mfs_root); + nd->mnt = mntget(mfs_mnt); + if(*nam) + *name = nam; + return(0); + } + if(!*nam && (nd->flags & LOOKUP_PARENT)) + { + mfs_check_completion(&complete, nd); + return(-EPERM); + } + if(pe && !*nam && link && !(nd->flags & LOOKUP_FOLLOW)) + return(mfs_link_complete(&complete, pe, nd)); + mfs_count_express(pe, complete.more_data_len); + if(pe != MFS_PE || mfs_loopback_test) + err = mfs_client_express_lookup(pe, &handle, nam, + flags, &iinfo, &newname, &complete); + else + err = mfs_low_express_lookup(&handle, nam, flags, + current->link_count, + current->total_link_count, &iinfo, + &newname, &complete); +#if 0 +printk("mfs_express_lookup: nam=<%s>, newname=%x", nam, newname); +if(newname)printk("<%s>\n", newname);else printk("\n"); +#endif + + if(err == AN_IMPOSSIBLE_ERROR && iinfo.si_count) + { + pe = magic = 0; +#if 0 +printk("mfs_express_lookup: skipping from <%s> to ", nam); +#endif + nam += iinfo.si_count - 1; +#if 0 +printk("<%s>\n", nam); +#endif + if(!*nam && (nd->flags & LOOKUP_PARENT)) + { + mfs_check_completion(&complete, nd); + return(-EPERM); + } + dput(nd->dentry); + nd->dentry = dget(mfs_super->s_root); + } + else if(IS_ERR((const void *)err)) + { + mfs_check_completion(&complete, nd); + return(err); + } + else + { + if(nd->flags & LOOKUP_PARENT) + fill_last_component(nam, nd); + break; + } + } + if(pe == 0) + { + mfs_check_completion(&complete, nd); + return(0); + } + if(mfs_check_completion(&complete, nd)) + { + if(newname) + kfree(newname); + return(complete.error); + } + if(newname) + { + qnam.name = newname; + qnam.len = strlen(newname); + } + else /* can still function - except 'getcwd' */ + { + qnam.name = "__removed__"; + qnam.len = 11; + } + result = d_alloc(mfs_super->s_root, &qnam); + if(newname) + kfree(newname); + if(!result) + { + mfs_dispose_handle(pe, handle); + return(-ENOMEM); + } + if(!(result->d_fsdata = kmalloc(sizeof(struct mfs_dinfo), GFP_KERNEL))) + { + dput(result); + mfs_dispose_handle(pe, handle); + return(-ENOMEM); + } + result->d_flags |= DCACHE_NO_CACHE; + result->d_op = &mfs_dentry_operations; + ((struct mfs_dinfo *)result->d_fsdata)->pe = pe; + ((struct mfs_dinfo *)result->d_fsdata)->handle = handle; + ((struct mfs_dinfo *)result->d_fsdata)->latest = jiffies; + if(iinfo.si_ino) + { + ip = mfs_iget(iinfo.si_ino, pe, handle); + if(!ip) + { + dput(result); + return(-EACCES); + } + mfs_subip_to_ip(ip, &iinfo); + d_add(result, ip); + } + else + d_add(result, NULL); + if(magic && (nd->complete_flags & COMPLETE_DONE)) + nd->complete_flags |= COMPLETE_MAGICAL; + dput(nd->dentry); + nd->dentry = result; + return(0); + + name_leads_back: +#ifdef CONFIG_MOSIX_DIAG + if(complete.done) + printk("OOPS: compete->done in name_leads_back!\n"); +#endif /* CONFIG_MOSIX_DIAG */ + mfs_check_completion(&complete, nd); +#ifdef CONFIG_MOSIX_DFSA + if(nd->flags & LOOKUP_STAYFS) + { + if(current->mosix.dflags & DREMOTE) + return(-EDOITATHOME); + nd->flags &= ~LOOKUP_STAYFS; + current->mosix.dflags &= ~DSTATSDOWN; + } +#endif /* CONFIG_MOSIX_DFSA */ + for(nam += 2 ; *nam == '/' ; nam++) + ; +#if 0 +printk("name leads back, left=../<%s>\n", nam); +#endif + if(*nam) + *name = nam; + else if(nd->flags & LOOKUP_PARENT) + return(-EPERM); + dput(nd->dentry); + mnt = nd->mnt; + nd->mnt = mntget(mnt->mnt_parent); + nd->dentry = dget(mnt->mnt_mountpoint->d_parent); + mntput(mnt); + return(0); +} + +char * +mfs_full_name(struct dentry *of, struct vfsmount *on) +{ + char *a, *b; + char *page = (char *)kmalloc(PAGE_SIZE, GFP_KERNEL); + int x; + + if(!page) + return(NULL); + if(of == mfs_root && on == mfs_mnt) + { + a = &page[PAGE_SIZE-1]; + *a = '\0'; + } + else + { + spin_lock(&dcache_lock); + a = __d_path(of, on, mfs_root, mfs_mnt, page, PAGE_SIZE); + spin_unlock(&dcache_lock); + } + for(x = MFS_PE ; x ; x /= 10) + { + if(a == page) + { + kfree(page); + return(NULL); + } + *(--a) = x % 10 + '0'; + } + if(a != page) + { + for(b = page ; *a ; ) + *b++ = *a++; + *b = '\0'; + a = page; + } + return(a); +} + +int +mfs_low_express_lookup(mfs_handle_t *handlep, char *name, unsigned int flags, + int link_count, int total_link_count, struct subinode *iinfo, + char **newname, struct mfs_completion *complete) +{ + struct inode *ip; + struct nameidata nd; + int error; + + iinfo->si_count = 0; + *newname = NULL; + if((error = mfs_to_local(*handlep, &nd))) + { + mfs_low_complete_error(complete, error); + return(error); + } +#if 0 +ip = nd.dentry->d_inode; +printk("mfs_low_express_lookup, original ino=%x/%d, d_count=%d\n", ip->i_dev, ip->i_ino, atomic_read(&nd.dentry->d_count)); +#endif + nd.flags = (flags | LOOKUP_MFS) & ~LOOKUP_MFS_MFS; + nd.last_type = LAST_ROOT; + nd.name_left = NULL; + nd.complete_flags = 0; + dget(nd.dentry); + mntget(nd.mnt); + mfs_lput(nd.dentry, nd.mnt); + current->link_count = link_count; + current->total_link_count = total_link_count; + error = path_walk(name, &nd); + if(nd.name_left) /* "/.." */ + { + iinfo->si_count = (nd.name_left - name) + 1; +#if 0 +printk("mfs_low_express_lookup: name_left %x<%s>, orig_name=%x<%s>, skip_factor=%d\n", nd.name_left, nd.name_left, name, name, iinfo->si_count); +#endif + return(AN_IMPOSSIBLE_ERROR); + } + if(error) + { + mfs_low_complete_error(complete, error); + return(error); + } + if((*handlep = mfs_low_complete(complete, &nd))) + { + /* need information back */ + if((ip = nd.dentry->d_inode)) + { + iinfo->si_ino = global_inum(ip); + mfs_ip_to_subip(iinfo, ip); + } + else + iinfo->si_ino = 0; + *newname = mfs_full_name(nd.dentry, nd.mnt); +#if 0 +printk("mfs_low_express_lookup: dev=%x, ip=%d, name=<%s>, newname=%x", ip ? ip->i_dev : 0, ip ? ip->i_ino : 0, name, *newname); +if(*newname)printk("<%s>", *newname);printk("\n"); +#endif + } + else + { +#if 0 +printk("mfs_low_express_lookup(%s): all resolved, err=%d", name, complete->error); +if(nd.dentry->d_inode)printk(", dev=%x, ino=%d\n", nd.dentry->d_inode->i_dev, nd.dentry->d_inode->i_ino); +printk("\n"); +#endif + *handlep = 0; + } +#if 0 +ip = nd.dentry->d_inode; printk("before path release, "); +if(ip)printk("ino=%x/%d, ", ip->i_dev, ip->i_ino); +printk("d_count=%d\n", atomic_read(&nd.dentry->d_count)); +#endif + if(!IS_ERR((const void *)complete->error)) + path_release(&nd); + return(complete->error); +} + +void +mfs_check_path(struct dentry *dp) +{ + int where; + mfs_handle_t handle; + char *name; + int len; + + if(dp == mfs_super->s_root) + return; + if(dp->d_parent != mfs_super->s_root) + { +#ifdef CONFIG_MOSIX_DIAG + printk("mfs_check_path: not son of root\n"); +#endif /* CONFIG_MOSIX_DIAG */ + return; + } + mfs_get_handling(dp, &where, &handle); + if(where != MFS_PE || mfs_loopback_test) + name = mfs_client_check_path(where, handle); + else + name = mfs_low_check_path(handle); + mfs_count_check_path(where, name ? strlen(name)+1 : 0); + if(!name || !strcmp(name, dp->d_name.name)) + return; + + len = strlen(name); + if(len <= dp->d_name.len) + { + dp->d_name.len = len; + strcpy((char *)dp->d_name.name, name); + kfree(name); + } + else + { + if(dname_external(dp)) + kfree(dp->d_name.name); + dp->d_name.name = name; + dp->d_name.len = len; + } +} + +char * +mfs_low_check_path(mfs_handle_t handle) +{ + struct nameidata nd; + char *ret; + + if(mfs_to_local(handle, &nd)) + return(NULL); + ret = mfs_full_name(nd.dentry, nd.mnt); + mfs_lput(nd.dentry, nd.mnt); + return(ret); +} + +struct inode_operations mfs_file_inode_operations = { + revalidate: mfs_revalidate, + setattr: mfs_setattr, + check_path: mfs_check_path, +}; + +struct inode_operations mfs_symlink_inode_operations = { + revalidate: mfs_revalidate, + setattr: mfs_setattr, + check_path: mfs_check_path, +}; + +struct inode_operations mfs_dir_inode_operations = { + revalidate: mfs_revalidate, + setattr: mfs_setattr, + express_lookup: mfs_express_lookup, + check_path: mfs_check_path, +}; + +int +mfs_root_readdir(struct file *filp, void *dirent, filldir_t filldir) +{ + int first, last; + + if(filp->f_pos == 0) + { + if(filldir(dirent, ".", 1, 0, + filp->f_dentry->d_inode->i_ino, DT_DIR) < 0) + return(0); + filp->f_pos = 1; + } + if(filp->f_pos == 1) + { + if(filldir(dirent, "..", 2, 1, + filp->f_dentry->d_inode->i_ino, DT_DIR) < 0) + return(0); + filp->f_pos = 2; + } + if(filp->f_pos == 2) + { + if(filldir(dirent, "here", 4, 2, + mfs_root_name_to_ino("here", 4), DT_DIR)) + return(0); + filp->f_pos = 3; + } + if(filp->f_pos == 3) + { + if(filldir(dirent, "home", 4, 3, + mfs_root_name_to_ino("home", 4), DT_DIR)) + return(0); + filp->f_pos = 4; + } + if(filp->f_pos == 4) + { + if(filldir(dirent, "lastexec", 8, 4, + mfs_root_name_to_ino("lastexec", 8), DT_DIR)) + return(0); + filp->f_pos = 5; + } + if(filp->f_pos == 5) + { + if(filldir(dirent, "magic", 5, 5, + mfs_root_name_to_ino("magic", 5), DT_DIR)) + return(0); + filp->f_pos = 6; + } + if(filp->f_pos == 6) + { + if(filldir(dirent, "selected", 8, 6, + mfs_root_name_to_ino("selected", 8), DT_DIR)) + return(0); + filp->f_pos = 7; + } + if(filp->f_pos < 7 || filp->f_pos >= 7 + MOSIX_MAX) + return(0); + while(scan_mosix_nodes(filp->f_pos - 6, &first, &last)) + while(first <= last) + { + char node[6]; + int n = first; + char *c; + + c = &node[5]; + *c = '\0'; + while(n) + { + c--; + *c = n % 10 + '0'; + n /= 10; + } + if(filldir(dirent, c, sizeof(node) - 1 - (c - node), + first + 6, first, DT_DIR)) + return(0); + filp->f_pos = ++first + 6; + } + return(0); +} + +static struct file_operations mfs_root_file_operations = +{ + readdir: mfs_root_readdir, +}; + +int +mfs_root_revalidate(struct dentry *dp) +{ + struct inode *ip = dp->d_inode; + + ip->i_mode = S_IFDIR | S_IRUGO | S_IXUGO; + ip->i_nlink = 1; + ip->i_uid = 0; + ip->i_gid = 0; + ip->i_rdev = 0; + ip->i_size = 0; + ip->i_atime = 0; + ip->i_ctime = 0; + ip->i_mtime = 0; + ip->i_blksize = 1024; + ip->i_blocks = 0; + return(0); +} + +struct dentry * +mfs_root_lookup(struct inode *dir, struct dentry *dentry) +{ + struct mfs_dinfo *info; + struct inode *inode = NULL; + int node; + + if(!(node = mfs_root_name_to_ino((char *)dentry->d_name.name, + dentry->d_name.len))) + { +#ifdef CONFIG_MOSIX_DFSA + if(current->mosix.dflags & DREMOTE) + return(ERR_PTR(-EDOITATHOME)); +#endif /* CONFIG_MOSIX_DFSA */ + return(ERR_PTR(-EACCES)); + } + if(!(info = (struct mfs_dinfo *)kmalloc(sizeof(struct mfs_dinfo), + GFP_KERNEL))) + return(ERR_PTR(-ENOMEM)); + info->pe = node; + info->handle = node; + info->latest = jiffies; + dentry->d_flags |= DCACHE_NO_CACHE; + dentry->d_op = &mfs_dentry_operations; + dentry->d_fsdata = info; + inode = mfs_iget(node, node, node); + if(!inode) + return(ERR_PTR(-ENOMEM)); + d_add(dentry, inode); + return(NULL); +} + +/* note: most of the following functions are actually required, even though + * not really permitted on the MFS root itself, because the MFS root is + * technically the parent of all MFS nodes. + */ +struct inode_operations mfs_root_inode_operations = { + revalidate: mfs_root_revalidate, + setattr: mfs_setattr, + express_lookup: mfs_express_lookup, +}; + +void +mfs_read_inode(struct inode * inode) +{ + unsigned long ino = inode->i_ino; + struct subinode iinfo; + int err; + + if(ino == MFS_ROOT_INO) + { + inode->i_mode = S_IFDIR | S_IXUGO | S_IRUGO | S_IWUGO; + inode->i_op = &mfs_root_inode_operations; + inode->i_fop = &mfs_root_file_operations; + inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; + inode->i_blocks = 0; + inode->i_blksize = 1024; + inode->i_uid = 0; + inode->i_gid = 0; + inode->i_nlink = 1; + inode->i_size = 0; + inode->i_generation = 0; + inode->i_version = 0; + return; + } + inode->u.mfs_i.pe = current->mosix.iget_mfs_pe; + inode->u.mfs_i.handle = current->mosix.iget_mfs_handle; + if(ino < MFS_ROOT_INO) + { + mfs_count_revalidate(ino); + if(ino != MFS_PE || mfs_loopback_test) + err = mfs_client_revalidate(ino, ino, &iinfo); + else + err = mfs_low_revalidate(MFS_PE, &iinfo); + if(err) /* just guess */ + { + inode->i_mode = S_IFDIR | S_IXUGO | S_IRUGO; + inode->i_op = &mfs_dir_inode_operations; + inode->i_mtime = inode->i_atime = inode->i_ctime = + CURRENT_TIME; + inode->i_blocks = 0; + inode->i_blksize = 1024; + inode->i_uid = 0; + inode->i_gid = 0; + inode->i_nlink = 1; + inode->i_size = 0; + } + else + mfs_subip_to_ip(inode, &iinfo); + } +} + +int +mfs_statfs(struct super_block *sb, struct statfs *buf) +{ + buf->f_type = MFS_SUPER_MAGIC; + buf->f_bsize = PAGE_SIZE/sizeof(long); + buf->f_namelen = NAME_MAX; + /* all the rest are 0 */ + return(0); +} + +void +mfs_put_super(struct super_block *sb) +{ + mfs_is_mounted = 0; + mfs_super = NULL; +} + +#ifdef CONFIG_MOSIX_DFSA +struct mfs_ident /* used in mfs_identify/mfs_reconstruct */ +{ + int pe; + mfs_handle_t handle; + ino_t ino; + mode_t mode; +}; + +int +mfs_identify(struct dentry *dentry, void *into) +{ + struct mfs_ident *i = into; + struct mfs_dinfo *p = (struct mfs_dinfo *)dentry->d_fsdata; + + if(sizeof(struct mfs_ident) > MAX_IDENT_RECORD_LEN) + panic("mfs_identify: insufficient\n"); + if(p) + { + i->pe = p->pe; + i->handle = p->handle; + } + else + { + i->pe = 0; + i->handle = 0; + } + i->ino = dentry->d_inode->i_ino; + i->mode = dentry->d_inode->i_mode; + return(sizeof(struct mfs_ident)); +} + +struct dentry * +mfs_reconstruct(struct vfsmount *mnt, void *info, int infolen) +{ + struct mfs_ident *i = (struct mfs_ident *)info; + struct dentry *dp; + struct inode *ip; + struct qstr qname; + + if(mnt->mnt_sb != mfs_super || infolen != sizeof(struct mfs_ident)) + { + printk("mfs_reconstruct: improper data\n"); + return(NULL); + } + if(!i->pe) + return(i->handle ? NULL : dget(mfs_super->s_root)); + qname.name = "yet_unknown"; + qname.len = 11; + if(!(dp = d_alloc(mfs_super->s_root, &qname))) + return(NULL); + if(!(dp->d_fsdata = kmalloc(sizeof(struct mfs_dinfo), GFP_KERNEL))) + { + dput(dp); + return(NULL); + } + dp->d_flags |= DCACHE_NO_CACHE; + dp->d_op = &mfs_dentry_operations; + ((struct mfs_dinfo *)dp->d_fsdata)->pe = i->pe; + ((struct mfs_dinfo *)dp->d_fsdata)->handle = i->handle; + ((struct mfs_dinfo *)dp->d_fsdata)->latest = jiffies; + ip = mfs_iget(i->ino, i->pe, i->handle); + if(!ip) + { + kfree(dp->d_fsdata); + dp->d_fsdata = NULL; + dput(dp); + return(NULL); + } + ip->i_mode = i->mode; + switch(i->mode & S_IFMT) + { + case S_IFREG: + ip->i_op = &mfs_file_inode_operations; + ip->i_fop = &mfs_file_file_operations; + break; + case S_IFLNK: + ip->i_op = &mfs_symlink_inode_operations; + ip->i_fop = &mfs_symlink_file_operations; + break; + case S_IFDIR: + ip->i_op = &mfs_dir_inode_operations; + ip->i_fop = &mfs_dir_file_operations; + break; + default: + printk("mfs_reconstruct: inum %d of bad mode (0%o)\n", + (int)ip->i_ino, ip->i_mode); + make_bad_inode(ip); + break; + } + d_add(dp, ip); + if(mfs_attach_handle(i->pe, i->handle)) + { + kfree(dp->d_fsdata); + dp->d_fsdata = NULL; + dput(dp); + return(NULL); + } + return(dp); +} + +void +mfs_dfsa_changed(struct vfsmount *mnt, int new) +{ + mfs_is_dfsa = (new != 0); +} +#endif /* CONFIG_MOSIX_DFSA */ + +struct super_operations mfs_sops = +{ + read_inode: mfs_read_inode, + put_inode: force_delete, + put_super: mfs_put_super, + statfs: mfs_statfs, +#ifdef CONFIG_MOSIX_DFSA + identify: mfs_identify, + reconstruct: mfs_reconstruct, + dfsa_changed: mfs_dfsa_changed, +#endif /* CONFIG_MOSIX_DFSA */ +}; + +int +mfs_dentry_compare(struct dentry *d, struct qstr *a, struct qstr *b) +{ + /* since MFS uses no hashing/caching, we should never reach here! */ + printk("mfs_dentry_compare! (<%s>, <%s>)\n", a->name, b->name); + return(1); +} + +void +mfs_dentry_release(struct dentry *dp) +{ + int where; + mfs_handle_t handle; + + if(dp->d_fsdata) + { + where = ((struct mfs_dinfo *)dp->d_fsdata)->pe; + handle = ((struct mfs_dinfo *)dp->d_fsdata)->handle; + kfree(dp->d_fsdata); + dp->d_fsdata = NULL; + mfs_dispose_handle(where, handle); + } +} + +struct dentry_operations mfs_dentry_operations = +{ + d_compare: mfs_dentry_compare, + d_release: mfs_dentry_release, +}; + +struct super_block * +mfs_read_super(struct super_block *s, void *data, int silent) +{ + struct inode * root_inode; + struct super_block *ret = s; + + if(mfs_is_mounted) + { + printk("MFS already mounted!\n"); + return(NULL); + } + if(!PE) + printk("WARNING: MFS mounting is ineffective until MOSIX is configured.\n"); + mfs_is_mounted = 1; + mfs_is_ro = (s->s_flags & MS_RDONLY); + mfs_super = s; + s->s_blocksize = 1024; + s->s_blocksize_bits = 10; + s->s_magic = MFS_SUPER_MAGIC; + s->s_op = &mfs_sops; + root_inode = iget(s, MFS_ROOT_INO); + if (!root_inode || !(s->s_root = d_alloc_root(root_inode))) + { + printk("Failed initializing MOSIX file-system.\n"); + iput(root_inode); + mfs_is_mounted = 0; + ret = NULL; + } + else + s->s_root->d_op = &mfs_dentry_operations; + s->s_maxbytes = ~0LL; + return(ret); +} + +void +mfs_change_pe(void) +{ + lock_mosix(); + if(MFS_PE == ((PE && !mosadmin_mode_nomfs) ? PE : MFS_UNKNOWN_PE)) + { + unlock_mosix(); + return; + } + unlock_mosix(); + if(mfs_try_to_cleanup(0)) + { + printk("WARNING: Due to the MOSIX configuration-change, all MFS files and\n"); + printk("directories previously opened on this node will become inaccessible!\n"); + mfs_try_to_cleanup(2); + } + lock_mosix(); + MFS_PE = (PE && !mosadmin_mode_nomfs) ? PE : MFS_UNKNOWN_PE; + unlock_mosix(); +} + +DECLARE_FSTYPE(mfs_fs_type, "mfs", mfs_read_super, 0); + +int +init_mfs(void) +{ + int err; + + MFS_PE = (PE && !mosadmin_mode_nomfs) ? PE : MFS_UNKNOWN_PE; + if((err = register_filesystem(&mfs_fs_type))) + return(err); + mfs_conversion_init(); + mfs_make_servers(); + return(0); +} + +int +mfs_walk_init_root(struct nameidata *nd) +{ + int ret; + + lock_kernel(); + if(mfs_root) + { + nd->dentry = dget(mfs_root); + nd->mnt = mntget(mfs_mnt); + ret = 1; + } + else + ret = 0; + unlock_kernel(); + return(ret); +} + +int +is_mfs_root(struct nameidata *nd) +{ + return(nd->dentry == mfs_root && nd->mnt == mfs_mnt); +} + +void +mfs_report_used(void) +{ + struct dentry *root; + struct dentry *dp; + struct list_head *next; + unsigned long timo = jiffies + 10 * HZ; + struct mfs_dinfo *i; + + loop: + if(!mfs_super) + return; + root = mfs_super->s_root; + dget(root); + for(next = root->d_subdirs.next ; next != &root->d_subdirs && + time_before(jiffies, timo) ; next = next->next) + { + dp = list_entry(next, struct dentry, d_child); + if((i = dp->d_fsdata) && + time_before(i->latest + MFS_REPORT_TIME, jiffies)) + { + dget(dp); + i->latest = jiffies; + if(mfs_touch_handle(i->pe, i->handle)) + i->pe = MFS_BAD_PE; + dput(dp); + goto loop; + } + } + dput(root); +} + +int +mfs_client_daemon(void *nothing) +{ + struct task_struct *p = current; + + lock_kernel(); + common_daemon_setup("mfs_gc", 0); + while(1) + { + mfs_report_used(); + mfs_monitor_client_contacts(); + p->state = TASK_INTERRUPTIBLE; + schedule_timeout(20 * HZ); + flush_signals(p); + } +} +#endif /* CONFIG_MOSIX_FS */ diff -urN linux-2.4.17/fs/mfs/scontact.c linux_umopenmosix/fs/mfs/scontact.c --- linux-2.4.17/fs/mfs/scontact.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/fs/mfs/scontact.c Sun Jun 23 12:40:11 2002 @@ -0,0 +1,517 @@ +/* + * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il) + * + * Permission to use this software is hereby granted under the terms of the + * GNU General Public License, as published by the Free Software Foundation. + * + * THIS SOFTWARE IS PROVIDED IN ITS "AS IS" CONDITION, WITH NO WARRANTY + * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING + * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED. + */ +/* + * Author(s): Amnon Shiloh. + */ + +#include +#ifdef CONFIG_MOSIX_FS +#include +#include +#include +#include +#include +#include + +#define MFS_MINSERVERS 2 +#define MFS_MAXDEDICATED 6 +#define MFS_MAXSERVERS 14 +#define MFS_CONTACT_KEEPALIVE (60*HZ) +#define MFS_MAXQ 100 /* do not increase - leave space under 128 */ + +spinlock_t mfs_servq_lock = SPIN_LOCK_UNLOCKED; + +struct task_struct *mfs_main_server_task; +int n_mfs_servers; +int mfs_total_services; + +struct mfs_server_contact +{ + struct mfs_server_contact *next; + struct socket *sock; + int caller; + int serial; + unsigned long last_use; +}; + +/* service queue: */ +struct mfs_server_contact *queued_services; +struct mfs_server_contact *last_queued_service; +int mfs_qlen; + +/* past connections that are still kept open: */ +struct mfs_server_contact *mfs_idle_connections; + +/* servers waiting: */ +DECLARE_WAIT_QUEUE_HEAD(wait_to_serve_mfs); +atomic_t waiting_to_serve_mfs = ATOMIC_INIT(0); +int mfs_idle_servers; + +/* main server waiting: */ +DECLARE_WAIT_QUEUE_HEAD(wait_for_mfs_calls); +volatile int waiting_for_mfs_calls; +volatile int mfs_has_new_calls; + +int +mfs_server_send(struct mfs_server_contact *s, int type, void *header, int hdln, + void *dat1, int len1, void *dat2, int len2) +{ + return(mfs_send(s->sock, 0, s->serial, type, + header, hdln, dat1, len1, dat2, len2)); +} + +int +mfs_server_receive(struct mfs_server_contact *s, + void **header, void **dat1, void **dat2) +{ + return(mfs_receive(s->sock, MFS_MUST_MATCH, &s->serial, NULL, + header, dat1, dat2)); +} + +void +mfs_serve1(struct mfs_server_contact *s) +{ + int type, more, changed; + void *header; + void *dat1; + void *dat2; + static int n_dedicated; + + mfs_set_main_ownership(s->sock, 0); + again: + type = mfs_receive(s->sock, MFS_FIRST_RECEIVE, &s->serial, NULL, + &header, &dat1, &dat2); + if(type == MFS_CLOSE || type < MFS_NONE) + { + mfs_close_socket(s->sock); +if(mfs_debug > 1) +printk("mfs_serve1: closing socket %x by client request!\n", (int)s->sock); + s->sock = NULL; + } + else + mfs_serve(s, type, header, dat1, dat2); + if(header) + kfree(header); + if(!s->sock) + return; + spin_lock(&mfs_servq_lock); + more = 1 + (n_dedicated < MFS_MAXDEDICATED); + if(more == 2) + n_dedicated++; + spin_unlock(&mfs_servq_lock); + changed = mfs_set_main_ownership(s->sock, more); + if(more == 2) + { + spin_lock(&mfs_servq_lock); + n_dedicated--; + spin_unlock(&mfs_servq_lock); + } + if(!changed) + { + if(mfs_debug) + printk("mfs_serv1: serving in chain!\n"); + goto again; + } +} + +/* trim_idle_connections must be called with mfs_servq_lock! */ +void +trim_idle_connections(void) +{ +#define HOGS_CONSIDERED 10 + struct mfs_server_contact *s, *prev, *next, *dispose = NULL; + int nhogs = 0; + int hogpe[HOGS_CONSIDERED]; + int hogs[HOGS_CONSIDERED]; + int i, caller, least, leastval, penalty, bar; + int disposed = 0; + + /* compile the hog-table */ + for(prev = NULL, s = mfs_idle_connections ; s ; prev = s , s = s->next) + { + caller = s->caller; + for(i = 0 ; i < nhogs ; i++) + if(hogpe[i] == caller) + { + hogs[i]++; + goto next_connection; + } + if(i < HOGS_CONSIDERED) + { + hogpe[i] = caller; + hogs[i] = 1; + nhogs++; + goto next_connection; + } + leastval = 10000000; + least = 0; + for(i = 0 ; i < HOGS_CONSIDERED ; i++) + if(hogs[i] < leastval) + { + least = i; + leastval = hogs[i]; + } + hogpe[least] = caller; + hogs[least] = 1; + next_connection:; + } + /* calculate penalties, store in the "serial" field (unused for idle) */ + /* penalty increases for old sockets and for hogs */ + for(s = mfs_idle_connections ; s ; s = s->next) + { + penalty = abs((long)jiffies - (long)(s->last_use)); + if(penalty > 2*MFS_CONTACT_KEEPALIVE) /* avoid overflow */ + penalty = 2*MFS_CONTACT_KEEPALIVE; + penalty = mfs_total_services * penalty / MFS_CONTACT_KEEPALIVE; + caller = s->caller; + for(i = 0 ; i < nhogs ; i++) + if(hogpe[i] == caller) + { + penalty *= hogs[i]; + break; + } + s->serial = penalty; + } + /* collect old sockets, more aggressively as services are exhausted */ + for(bar = MFS_MAXQ/2 ; + mfs_idle_connections && mfs_total_services - disposed > MFS_MAXQ + ; bar = bar * 2 / 3) + for(prev = NULL, s = mfs_idle_connections ; s ; ) + if(s->serial >= bar) + { + next = s->next; + if(prev) + prev->next = next; + else + mfs_idle_connections = next; +if(mfs_debug) +printk("trim_idle_connections: penalty=%d, closing socket %x\n", s->serial, +(int)s->sock); + s->next = dispose; + dispose = s; + disposed++; + s = next; + } + else + { + prev = s; + s = s->next; + } + /* dispose of those sockets */ + mfs_total_services -= disposed; + spin_unlock(&mfs_servq_lock); + for(; dispose ; dispose = next) + { + next = dispose->next; + mfs_close_socket(dispose->sock); + kfree(dispose); + } + spin_lock(&mfs_servq_lock); +} + +void +mfs_recycle_service(struct mfs_server_contact *s) +{ + spin_lock(&mfs_servq_lock); + if(!s->sock) + { + mfs_total_services--; + spin_unlock(&mfs_servq_lock); + kfree(s); + return; + } + if(mfs_total_services >= MFS_MAXQ) + trim_idle_connections(); + if(mfs_total_services < MFS_MAXQ) + { + s->last_use = jiffies; + s->next = mfs_idle_connections; + mfs_idle_connections = s; + spin_unlock(&mfs_servq_lock); + return; + } +if(mfs_debug) +printk("mfs_recycle_service: closing socket %x (too many connections already)\n", (int)s->sock); + mfs_total_services--; + spin_unlock(&mfs_servq_lock); + mfs_close_socket(s->sock); + kfree(s); +} + +int +mfs_server(void *nothing) +{ + struct mfs_server_contact *s; + struct task_struct *p = current; + extern struct task_struct *child_reaper; + + strcpy(p->comm, "mfs_server"); + p->exit_signal = SIGCHLD; + p->p_opptr = child_reaper; + write_lock_irq(&tasklist_lock); + REMOVE_LINKS(p); + p->p_pptr = p->p_opptr; + SET_LINKS(p); + p->fs->umask = 0; + write_unlock_irq(&tasklist_lock); + set_fs(KERNEL_DS); /* all server I/O always to kernel */ + spin_lock(&mfs_servq_lock); + mfs_idle_servers--; + while(1) + { + while((s = queued_services)) + { + mfs_qlen--; + if(!(queued_services = s->next)) + last_queued_service = NULL; + spin_unlock(&mfs_servq_lock); + mfs_serve1(s); + mfs_recycle_service(s); + spin_lock(&mfs_servq_lock); + } + if(n_mfs_servers > MFS_MINSERVERS || MFS_PE == MFS_UNKNOWN_PE) + { + n_mfs_servers--; + spin_unlock(&mfs_servq_lock); + return(0); /* and exit */ + } + mfs_idle_servers++; + atomic_inc(&waiting_to_serve_mfs); + spin_unlock(&mfs_servq_lock); + interruptible_sleep_on(&wait_to_serve_mfs); + if(p->sigpending) + { + spin_lock_irq(&p->sigmask_lock); + flush_signals(p); + spin_unlock_irq(&p->sigmask_lock); + } + spin_lock(&mfs_servq_lock); + atomic_dec(&waiting_to_serve_mfs); + mfs_idle_servers--; + } +} + +void +mfs_new_request_arrived(void) +{ +if(mfs_debug > 1) +printk("mfs_new_request_arrived!\n"); + mfs_has_new_calls = 1; + if(waiting_for_mfs_calls) + wake_up_interruptible(&wait_for_mfs_calls); +} + +/* mfs_add_to_queue must be called with mfs_servq_lock! */ +static inline void +mfs_add_to_queue(struct mfs_server_contact *s) +{ + s->next = NULL; + mfs_qlen++; + if(last_queued_service) + last_queued_service->next = s; + else + queued_services = s; + last_queued_service = s; + if(atomic_read(&waiting_to_serve_mfs)) + wake_up_interruptible(&wait_to_serve_mfs); +} + +int +mfs_main_server(void *nothing) +{ + register struct task_struct *p = current; + struct socket *mainsock = NULL, *sock; + struct mfs_server_contact *s, *prev, *next, *dispose = NULL; + int caller; + unsigned long last_trim = 0; + int client_pid = 0; + int success; + DECLARE_WAITQUEUE(wait, p); + + mfs_main_server_task = p; + common_daemon_setup("mfs_main_server", 1); + while(client_pid <= 0 || !mainsock) + { + if(client_pid <= 0) + client_pid = kernel_thread(mfs_client_daemon, NULL, 0); + if(!mainsock) + mainsock = mfs_open_main_socket(); + if(client_pid > 0 && mainsock) + break; + set_current_state(TASK_INTERRUPTIBLE); + schedule_timeout(MFS_CONTACT_KEEPALIVE / 3); + spin_lock_irq(&p->sigmask_lock); + flush_signals(p); + spin_unlock_irq(&p->sigmask_lock); + } + mainloop: + spin_lock(&mfs_servq_lock); + if(MFS_PE != MFS_UNKNOWN_PE) + while(n_mfs_servers < MFS_MINSERVERS) + { + n_mfs_servers++; + mfs_idle_servers++; + spin_unlock(&mfs_servq_lock); + success = (kernel_thread(mfs_server, NULL, 0) >= 0); + spin_lock(&mfs_servq_lock); + if(!success) + { + n_mfs_servers--; + mfs_idle_servers--; + break; + } + } + if(mfs_has_new_calls) + { + spin_unlock(&mfs_servq_lock); + mfs_has_new_calls = 0; + while((sock = mfs_new_connection(mainsock, &caller))) + if(MFS_PE == MFS_UNKNOWN_PE) + mfs_close_socket(sock); + else + { +if(mfs_debug) +printk("mfs_main_server: new connection=%x (mainsock=%x)\n", (int)sock, (int)mainsock); + if((s = (struct mfs_server_contact *)kmalloc( + sizeof(struct mfs_server_contact), GFP_KERNEL))) + { + spin_lock(&mfs_servq_lock); + mfs_total_services++; + s->sock = sock; + s->caller = caller; + mfs_add_to_queue(s); + spin_unlock(&mfs_servq_lock); + } + else + mfs_close_socket(sock); + } + spin_lock(&mfs_servq_lock); + for(prev = NULL, s = mfs_idle_connections ; s ; ) + if(MFS_PE == MFS_UNKNOWN_PE || mfs_socket_has_data(s->sock)) + { + next = s->next; + if(prev) + prev->next = next; + else + mfs_idle_connections = next; + if(MFS_PE == MFS_UNKNOWN_PE) + { + s->next = dispose; + dispose = s; + mfs_total_services--; + } + else + { +if(mfs_debug) +printk("mfs_main_server: new request on old sock (%x)\n", (int)s->sock); + mfs_add_to_queue(s); + } + s = next; + } + else + { + prev = s; + s = s->next; + } + while(mfs_qlen > mfs_idle_servers && + n_mfs_servers < MFS_MAXSERVERS && + MFS_PE != MFS_UNKNOWN_PE) + { +if(mfs_debug > 1)printk("mfs_main_server adding a server\n"); + n_mfs_servers++; + mfs_idle_servers++; + spin_unlock(&mfs_servq_lock); + success = (kernel_thread(mfs_server, NULL, 0) >= 0); + spin_lock(&mfs_servq_lock); + if(!success) + { + n_mfs_servers--; + mfs_idle_servers--; + if(!n_mfs_servers) + { + /* too bad - just shut all down */ + while((s = queued_services)) + { + queued_services = s->next; + mfs_qlen--; + mfs_total_services--; + spin_unlock(&mfs_servq_lock); + mfs_close_socket(s->sock); + kfree(s); + spin_lock(&mfs_servq_lock); + } + } + break; + } + } + } + if(abs((long)jiffies - (long)last_trim) > HZ) + { + for(prev = NULL, s = mfs_idle_connections ; s ; ) + if(abs((long)jiffies - (long)(s->last_use)) >= + MFS_CONTACT_KEEPALIVE) + { + next = s->next; + if(prev) + prev->next = next; + else + mfs_idle_connections = next; + if(mfs_socket_has_data(s->sock)) + mfs_add_to_queue(s); + else + { +if(mfs_debug > 1) +printk("mfs_main_server: closing old socket %x\n", (int)s->sock); + s->next = dispose; + dispose = s; + mfs_total_services--; + } + s = next; + } + else + { + prev = s; + s = s->next; + } + } + spin_unlock(&mfs_servq_lock); + last_trim = jiffies; + for(; dispose ; dispose = next) + { + next = dispose->next; + mfs_close_socket(dispose->sock); + kfree(dispose); + } + if(!mfs_has_new_calls) + { + add_wait_queue(&wait_for_mfs_calls, &wait); + set_current_state(TASK_INTERRUPTIBLE); + waiting_for_mfs_calls = 1; + if(!mfs_has_new_calls) + schedule_timeout(MFS_CONTACT_KEEPALIVE / 3); + waiting_for_mfs_calls = 0; + remove_wait_queue(&wait_for_mfs_calls, &wait); + set_current_state(TASK_RUNNING); + } + spin_lock_irq(&p->sigmask_lock); + flush_signals(p); + spin_unlock_irq(&p->sigmask_lock); + mfs_throw_garbage(); + goto mainloop; +} + +void +mfs_make_servers(void) +{ + kernel_thread(mfs_main_server, NULL, 0); +} + +#endif /* CONFIG_MOSIX_FS */ diff -urN linux-2.4.17/fs/mfs/server.c linux_umopenmosix/fs/mfs/server.c --- linux-2.4.17/fs/mfs/server.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/fs/mfs/server.c Sun Jun 23 12:40:11 2002 @@ -0,0 +1,471 @@ +/* + * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il) + * + * Permission to use this software is hereby granted under the terms of the + * GNU General Public License, as published by the Free Software Foundation. + * + * THIS SOFTWARE IS PROVIDED IN ITS "AS IS" CONDITION, WITH NO WARRANTY + * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING + * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED. + */ +/* + * Author(s): Amnon Shiloh. + */ + +#include +#ifdef CONFIG_MOSIX_FS +#include +#include +#include + +void +unpack_credits(struct mfs_cred *cred) +{ + register struct task_struct *p = current; + register int i; + + p->uid = cred->uid; + p->euid = cred->euid; + p->sgid = cred->sgid; + p->fsuid = cred->fsuid; + p->gid = cred->gid; + p->egid = cred->egid; + p->sgid = cred->sgid; + p->fsgid = cred->fsgid; + p->ngroups = cred->ngroups; + for(i = cred->ngroups-1 ; i >= 0 ; i--) + p->groups[i] = cred->groups[i]; + p->cap_effective = (p->cap_effective & ~REMOTE_CAPS) | + (cred->caps & REMOTE_CAPS); + p->mosix.whereami = cred->whereami; + p->mosix.deppe = cred->deppe; +} + +void +mfs_serve_attach(struct mfs_server_contact *con, + struct mfs_request_attach_handle *s) +{ + struct mfs_reply_attach_handle r; + + r.result = mfs_low_attach_handle(s->handle); + mfs_server_send(con, MFS_REPLY_ATTACH_HANDLE, &r, sizeof(r), NULL, 0, + NULL, 0); +} + +void +mfs_serve_touch(struct mfs_server_contact *con, + struct mfs_request_touch_handle *s) +{ + struct mfs_reply_touch_handle r; + + r.result = mfs_low_touch_handle(s->handle); + mfs_server_send(con, MFS_REPLY_TOUCH_HANDLE, &r, sizeof(r), NULL, 0, + NULL, 0); +} + +void +mfs_serve_llseek(struct mfs_server_contact *con, struct mfs_request_llseek *s) +{ + struct mfs_reply_llseek r; + + unpack_credits(&s->cred); + r.result = mfs_low_llseek(s->handle, &s->file, s->offset, s->origin); + r.file = s->file; + mfs_server_send(con, MFS_REPLY_LLSEEK, &r, sizeof(r), NULL, 0, NULL, 0); +} + +void +mfs_serve_read(struct mfs_server_contact *con, struct mfs_request_read *s) +{ + struct mfs_reply_read r; + int n; + size_t count = s->count; + size_t cnt, sent = 0; + char *buf = NULL; + int ret = 0; + size_t max; + char smallbuf[4]; + struct mfs_interim_data d; + + for(max = s->count > 16384 ? 16384 : s->count ; max > sizeof(smallbuf) ; + max >>= 1) + if((buf = (char *)kmalloc(max, GFP_KERNEL))) + break; + if(max <= sizeof(smallbuf)) + { + buf = smallbuf; + max = sizeof(smallbuf); + } + unpack_credits(&s->cred); + while(count > 0) + { + cnt = count; + if(cnt > max) + cnt = max; + n = mfs_low_read(s->handle, &s->file, buf, cnt, &s->pos); + if(n < cnt || cnt == count) + { + if(n < 0) + ret = n; + else + ret += n; + break; + } + ret += cnt; + d.count = cnt; + if(mfs_server_send(con, MFS_INTERIM_DATA, (void *)&d, sizeof(d), + (void *)buf, cnt, NULL, 0)) + goto free_buf; + sent += cnt; + count -= cnt; + } + r.file = s->file; + r.ppos = s->pos; + r.result = ret; + r.datalen = (ret > 0 && ret > sent) ? ret - sent : 0; + mfs_server_send(con, MFS_REPLY_READ, &r, sizeof(r), + r.datalen ? buf : NULL, r.datalen, NULL, 0); + free_buf: + if(max != sizeof(smallbuf)) + kfree(buf); +} + +void +mfs_serve_write(struct mfs_server_contact *con, struct mfs_request_write *s, + void *buf) +{ + struct mfs_reply_write r; + struct mfs_interim_data *i = NULL; + ssize_t n; + size_t count = s->count; + size_t cnt; + struct task_struct *p = current; + + unpack_credits(&s->cred); + if(signal_pending(p)) + { + spin_lock_irq(&p->sigmask_lock); + flush_signals(p); + spin_unlock_irq(&p->sigmask_lock); + } + cnt = s->datalen; + if(cnt < count) + mfs_server_send(con, MFS_CONTINUE, NULL, 0, NULL, 0, NULL, 0); + r.result = mfs_low_write(s->handle, &s->file, buf, cnt,&s->pos,s->flim); + /* in Linux, an append-"write", once started is not broken even if + * another process interfered */ + s->file.f_flags &= ~O_APPEND; + if(r.result == cnt) + while(r.result < count) + { + if(i) + kfree(i); + if((n = mfs_server_receive(con, (void **)&i, &buf, NULL)) < 0) + return; + if(n == MFS_STOP) + { + r.result = -EFAULT; + break; + } + if(n != MFS_INTERIM_DATA) + { + printk("mfs_serve_write: unexpected type: %d\n", n); + if(i) + kfree(i); + return; + } + n = mfs_low_write(s->handle, &s->file, buf, i->count, &s->pos, + s->flim); + r.result += n; + if(n < i->count) + { + if(n < 0) + r.result = n; + break; + } + } + if(i) + kfree(i); + r.file = s->file; + r.ppos = s->pos; + if(sigismember(&p->pending.signal, SIGXFSZ)) + { + spin_lock_irq(&p->sigmask_lock); + flush_signals(p); + spin_unlock_irq(&p->sigmask_lock); + r.hadsigxfsz = 1; + } + else + r.hadsigxfsz = 0; + current->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY; + mfs_server_send(con, MFS_REPLY_WRITE, &r, sizeof(r), NULL, 0, NULL, 0); +} + +struct mfs_serve_readdir_callback +{ + struct mfs_server_contact *con; + void *buf, *bufp; + int buflen; + int policy; + int maxbytes; +}; + +int +mfs_serve_flush_dirs(struct mfs_serve_readdir_callback *cb) +{ + struct mfs_interim_data i; + struct mfs_interim_readdir *ri; + int t, err; + + i.count = cb->bufp - cb->buf; + if(i.count == 0) + return(0); + if(mfs_server_send(cb->con, MFS_INTERIM_DATA, (void *)&i, sizeof(i), + cb->buf, i.count, NULL, 0)) + return(-EINVAL); + t = mfs_server_receive(cb->con, (void **)&ri, NULL, NULL); + if(t == MFS_INTERIM_READDIR) + err = ri->error; + else + err = -EINVAL; + if(ri) + kfree(ri); + if(err) + return(err); + cb->bufp = cb->buf; + return(0); +} + +int +mfs_serve_filldir(void *__cb, const char *name, int namelen, loff_t offset, + ino_t ino, unsigned int type) +{ + struct mfs_serve_readdir_callback *cb = __cb; + int reclen; + int err; + + switch(cb->policy) + { + case MFS_READDIR_JUSTONE: + if(!cb->maxbytes) + return(-EINVAL); + cb->maxbytes = 0; + break; + case MFS_READDIR_GETDENTS: + reclen = (offsetof(struct dirent, d_name[0]) + namelen + + 1 + sizeof(long)-1) & ~(sizeof(long)-1); + if(reclen > cb->maxbytes) + return(-EINVAL); + cb->maxbytes -= reclen; + break; + case MFS_READDIR_GETDENTS64: + reclen = (offsetof(struct dirent64, d_name[0]) + + namelen + 1 + sizeof(u64)-1) & ~(sizeof(u64)-1); + if(reclen > cb->maxbytes) + return(-EINVAL); + cb->maxbytes -= reclen; + break; + } + reclen = sizeof(ino_t) + sizeof(loff_t) + sizeof(unsigned int) + + sizeof(short) + namelen; + if(reclen > cb->buflen - (cb->bufp - cb->buf)) + { + if(cb->bufp == cb->buf || (cb->policy != MFS_READDIR_GETDENTS + && cb->policy != MFS_READDIR_GETDENTS64)) + { + /* should not happen - we allocated at least dirent64 */ + printk("mfs_serve_filldir: buffer not sufficient\n"); + return(-EINVAL); + } + if((err = mfs_serve_flush_dirs(cb))) + return(err); + } + *((ino_t *)cb->bufp)++ = ino; + *((loff_t *)cb->bufp)++ = offset; + *((unsigned int *)cb->bufp)++ = type; + *((short *)cb->bufp)++ = namelen; + memcpy(cb->bufp, (void *)name, namelen); + cb->bufp += namelen; + if(cb->policy == MFS_READDIR_UNKNOWN) + return(mfs_serve_flush_dirs(cb)); + else + return(0); +} + +void +mfs_serve_readdir(struct mfs_server_contact *con, struct mfs_request_readdir *s) +{ + struct mfs_reply_readdir r; + int ret = 0; + struct mfs_serve_readdir_callback cb; + int multi = (s->policy == MFS_READDIR_GETDENTS || + s->policy == MFS_READDIR_GETDENTS64); + int duma, dumb; + + for(cb.buflen = multi ? 16384 : sizeof(struct dirent64) ; + cb.buflen >= sizeof(struct dirent64) ; cb.buflen >>= 1) + if((cb.buf = (char *)kmalloc(cb.buflen, GFP_KERNEL))) + break; + cb.bufp = cb.buf; + cb.policy = s->policy; + cb.maxbytes = multi ? s->maxbytes : 1; + cb.con = con; + unpack_credits(&s->cred); + if(cb.buflen < sizeof(struct dirent64)) + ret = -ENOMEM; + else + ret = mfs_low_readdir(s->handle, &s->file, (void *)&cb, + mfs_serve_filldir, &duma, &dumb); + r.file = s->file; + r.result = ret; + r.datalen = cb.bufp - cb.buf; + mfs_server_send(con, MFS_REPLY_READDIR, &r, sizeof(r), + r.datalen ? cb.buf : NULL, r.datalen, NULL, 0); + if(cb.buflen >= sizeof(struct dirent64)) + kfree(cb.buf); +} + +void +mfs_serve_ioctl(struct mfs_server_contact *con, struct mfs_request_ioctl *s) +{ + struct mfs_reply_ioctl r; + + unpack_credits(&s->cred); + r.result = mfs_low_ioctl(s->handle, &s->file, s->cmd, s->arg, s->size, + &s->data); + r.file = s->file; + r.data = s->data; + mfs_server_send(con, MFS_REPLY_IOCTL, &r, sizeof(r), NULL, 0, NULL, 0); +} + +void +mfs_serve_fsync(struct mfs_server_contact *con, struct mfs_request_fsync *s) +{ + struct mfs_reply_fsync r; + + unpack_credits(&s->cred); + r.result = mfs_low_fsync(s->handle, &s->file, s->datasync); + r.file = s->file; + mfs_server_send(con, MFS_REPLY_FSYNC, &r, sizeof(r), NULL, 0, NULL, 0); +} + +void +mfs_serve_revalidate(struct mfs_server_contact *con, + struct mfs_request_revalidate *s) +{ + struct mfs_reply_revalidate r; + + unpack_credits(&s->cred); + r.result = mfs_low_revalidate(s->handle, &r.iinfo); + mfs_server_send(con, MFS_REPLY_REVALIDATE, &r, sizeof(r), NULL, 0, NULL, 0); +} + +void +mfs_serve_express(struct mfs_server_contact *con, struct mfs_request_express *s, + char *name, void *more_data) +{ + struct mfs_reply_express r; + char *newname; + + unpack_credits(&s->cred); + r.handle = s->handle; + r.complete = s->complete; + if(r.complete.more_data) + r.complete.more_data = more_data; + r.result = mfs_low_express_lookup(&r.handle, name, s->follow, + s->link_count, s->total_link_count, &r.iinfo, + &newname, &r.complete); + r.namelen = (r.result || !newname) ? 0 : strlen(newname) + 1; + mfs_server_send(con, MFS_REPLY_EXPRESS, &r, sizeof(r), + r.namelen ? (void *)newname : NULL, r.namelen, + r.complete.more_data, r.complete.more_data_len); + if(r.namelen) + kfree(newname); + if(r.complete.more_data) + kfree(r.complete.more_data); +} + +void +mfs_serve_checkpath(struct mfs_server_contact *con, + struct mfs_request_checkpath *s) +{ + struct mfs_reply_checkpath r; + char *path; + + unpack_credits(&s->cred); + path = mfs_low_check_path(s->handle); + r.namelen = path ? strlen(path)+1 : 0; + mfs_server_send(con, MFS_REPLY_CHECKPATH, &r, sizeof(r), + r.namelen ? (void *)path : NULL, r.namelen, NULL, 0); + if(path) + kfree(path); +} + +void +mfs_serve_setattr(struct mfs_server_contact *con, struct mfs_request_setattr *s) +{ + struct mfs_reply_setattr r; + + unpack_credits(&s->cred); + r.result = mfs_low_setattr(s->handle, &s->attr); + mfs_server_send(con, MFS_REPLY_SETATTR, &r, sizeof(r), NULL, 0, + NULL, 0); +} + +void +mfs_serve(struct mfs_server_contact *con, int type, void *header, void *dat1, + void *dat2) +{ + switch(type) + { + case MFS_REQUEST_ATTACH_HANDLE: + mfs_serve_attach(con, + (struct mfs_request_attach_handle *)header); + break; + case MFS_REQUEST_TOUCH_HANDLE: + mfs_serve_touch(con,(struct mfs_request_touch_handle *)header); + break; + case MFS_REQUEST_DISPOSE_HANDLE: + mfs_low_dispose_handle( + ((struct mfs_request_dispose_handle *)header)->handle); + mfs_server_send(con, MFS_CONTINUE, NULL, 0, NULL, 0, NULL,0); + break; + case MFS_REQUEST_LLSEEK: + mfs_serve_llseek(con, (struct mfs_request_llseek *)header); + break; + case MFS_REQUEST_READ: + mfs_serve_read(con, (struct mfs_request_read *)header); + break; + case MFS_REQUEST_WRITE: + mfs_serve_write(con, (struct mfs_request_write *)header, dat1); + break; + case MFS_REQUEST_READDIR: + mfs_serve_readdir(con, (struct mfs_request_readdir *)header); + break; + case MFS_REQUEST_IOCTL: + mfs_serve_ioctl(con, (struct mfs_request_ioctl *)header); + break; + case MFS_REQUEST_FSYNC: + mfs_serve_fsync(con, (struct mfs_request_fsync *)header); + break; + case MFS_REQUEST_REVALIDATE: + mfs_serve_revalidate(con, + (struct mfs_request_revalidate *)header); + break; + case MFS_REQUEST_EXPRESS: + mfs_serve_express(con, (struct mfs_request_express *)header, + (char *)dat1, dat2); + break; + case MFS_REQUEST_CHECKPATH: + mfs_serve_checkpath(con, + (struct mfs_request_checkpath *)header); + break; + case MFS_REQUEST_SETATTR: + mfs_serve_setattr(con, (struct mfs_request_setattr *)header); + break; + default: + printk("mfs_serve: type %d unimplemented\n", type); + } +} + +#endif /* CONFIG_MOSIX_FS */ diff -urN linux-2.4.17/fs/mfs/socket.c linux_umopenmosix/fs/mfs/socket.c --- linux-2.4.17/fs/mfs/socket.c Thu Jan 1 02:00:00 1970 +++ linux_umopenmosix/fs/mfs/socket.c Sun Jun 23 12:40:11 2002 @@ -0,0 +1,534 @@ +/* + * Copyright (C) 2000, 2001, Amnon Barak (amnon@cs.huji.ac.il) + * + * Permission to use this software is hereby granted under the terms of the + * GNU General Public License, as published by the Free Software Foundation. + * + * THIS SOFTWARE IS PROVIDED IN ITS "AS IS" CONDITION, WITH NO WARRANTY + * WHATSOEVER. NO LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING + * FROM THE USE OF THIS SOFTWARE WILL BE ACCEPTED. + */ +/* + * Author(s): Amnon Shiloh. + * used code by Oren Laadan. + */ + +#include +#ifdef CONFIG_MOSIX_FS +#include +#include +#include +#include +#include +#include +#include +#include + +/* meanwhile, we assume MOSIX uses only IPv4 addresses */ +/* when MOSIX can use IPv6, this file must also be upgraded */ + +#ifdef CONFIG_MOSIX_UDB +#define MFS_CONNECT_TIMO (100*HZ) +#define MFS_RECEIVE_TIMO (100*HZ) +#else +#define MFS_CONNECT_TIMO (10*HZ) +#define MFS_RECEIVE_TIMO (10*HZ) +#endif /* CONFIG_MOSIX_UDB */ + +int +mfs_common_socket_setup(struct socket *sock) +{ + mm_segment_t oldfs = get_fs(); + int error = 0; + int val; + + set_fs(KERNEL_DS); + val = 32768+1024; + sock_setsockopt(sock, SOL_SOCKET, SO_SNDBUF, (char *)&val, sizeof(val)); + sock_setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (char *)&val, sizeof(val)); + val = MOSIX_CONNECTION_KEEPALIVE_INTERVAL; + sock->ops->setsockopt(sock, IPPROTO_TCP, TCP_KEEPINTVL, + (char *) &val, sizeof(val)); + val = MOSIX_CONNECTION_KEEPALIVE_MAXTRIES; + sock->ops->setsockopt(sock, IPPROTO_TCP, TCP_KEEPCNT, + (char *) &val, sizeof(val)); + val = MOSIX_CONNECTION_KEEPALIVE_TOTAL; + sock->ops->setsockopt(sock, IPPROTO_TCP, TCP_KEEPIDLE, + (char *) &val, sizeof(val)); + val = 1; + sock->ops->setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, + (char *)&val, sizeof(val)); + error = sock_setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, + (char *)&val, sizeof(val)); + set_fs(oldfs); + set_bit(SOCK_INTER_MOSIX, &sock->flags); + return(error); +} + +struct socket * +mfs_open_main_socket(void) +{ + struct socket *sock; + struct sockaddr_in addr; + + deeper_sleep(); + + memset(&addr, 0, sizeof(struct sockaddr_in)); + addr.sin_family = AF_INET; + addr.sin_addr.s_addr = INADDR_ANY; + addr.sin_port = MFS_MAIN_PORT; + if(sock_create(AF_INET, SOCK_STREAM, IPPROTO_TCP, &sock)) + goto failed; + + if(mfs_common_socket_setup(sock)) + { +#ifdef CONFIG_MOSIX_DEBUG + printk("setup failed on MFS main socket\n"); +#endif /* CONFIG_MOSIX_DEBUG */ + goto failed; + } + + if(sock->ops->bind(sock, (struct sockaddr *)&addr, sizeof(addr))) + { +#ifdef CONFIG_MOSIX_DEBUG + printk("bind failed on MFS main socket\n"); +#endif /* CONFIG_MOSIX_DEBUG */ + goto failed; + } + if(sock->ops->listen(sock, SOMAXCONN)) + { +#ifdef CONFIG_MOSIX_DEBUG + printk("listen failed on MFS main socket\n"); +#endif /* CONFIG_MOSIX_DEBUG */ + goto failed; + } + + lighter_sleep(); + spin_lock_irq(&skown_lock); + sock->sk->owner = mfs_main_server_task; + spin_unlock_irq(&skown_lock); + return(sock); + +failed: + lighter_sleep(); + if (sock) + sock_release(sock); + return(NULL); +} + +struct socket * +mfs_new_connection(struct socket *parent, int *caller) +{ + struct socket *sock; + struct mosix_addr mosaddr; + int val = sizeof(mosaddr.saddr); + + if(!(parent->ops->poll(NULL, parent, NULL) & POLLIN)) + return(NULL); + if (!(sock = sock_alloc())) + return(NULL); + sock->type = parent->type; + sock->ops = parent->ops; + if(sock->ops->accept(parent, sock, O_NONBLOCK)) + goto failed; + if (sock->ops->getname(sock, &mosaddr.saddr, &val, 1)) + goto failed; + if(!(*caller = net_to_mos(&mosaddr))) + { + comm_report_violation("MFS", &mosaddr.saddr); + goto failed; + } + if(mfs_common_socket_setup(sock)) + goto failed; + spin_lock_irq(&skown_lock); + sock->sk->owner = mfs_main_server_task; + spin_unlock_irq(&skown_lock); + return(sock); + failed: + sock_release(sock); + return(NULL); +} + +struct socket * +mfs_connect_to(int to) +{ + struct task_struct *p = current; + int error; + struct socket *sock = NULL; + struct sockaddr addr; + unsigned long timo = MFS_CONNECT_TIMO; + DECLARE_WAITQUEUE(wait, p); + + deeper_sleep(); + if(!mos_to_net(to, &addr)) + { + error = -EREMOTE; + goto failed; + } + ((struct sockaddr_in *)&addr)->sin_port = MFS_MAIN_PORT; + if((error = sock_create(AF_INET, SOCK_STREAM, IPPROTO_TCP, &sock))) + goto failed; + if((error = mfs_common_socket_setup(sock))) + goto failed; + sock->ops->connect(sock, &addr, sizeof(addr), O_NONBLOCK); + add_wait_queue(sock->sk->sleep, &wait); + while (sock->state != SS_CONNECTED) + { + set_current_state(TASK_INTERRUPTIBLE); + error = sock->ops->connect(sock, &addr, sizeof(addr), + O_NONBLOCK); + if (error != -EALREADY || (error = sock_error(sock->sk))) + break; + timo = schedule_timeout(timo); + if (timo <= 0) + { + error = -EAGAIN; + break; + } + } + remove_wait_queue(sock->sk->sleep, &wait); + set_current_state(TASK_RUNNING); + + if (error) + goto failed; + if (sock->sk->err) + { + error = sock_error(sock->sk); /* cleans error.. */ + goto failed; + } + lighter_sleep(); +if(mfs_debug) +printk("%s-mfs_connect_to %d: success\n", desc_mostask(NULL), to); + return (sock); + +failed: + lighter_sleep(); + if (sock) + sock_release(sock); + return (ERR_PTR(error)); +} + +inline int +mfs_socket_has_data(struct socket *sock) +{ + return((sock->ops->poll(NULL, sock, 0) & + (POLLRDNORM|POLLIN|POLLHUP|POLLERR)) != 0); +} + +/* + * "mfs_socket_is_closed" is only called by the client on inactive sockets: + * we never expect server-initiated data, so POLLIN implies a closed socket. + */ +int +mfs_socket_is_closed(struct socket *sock) +{ +if(mfs_debug > 1)printk("socket_is_closed(%x): poll=0x%x\n", (int)sock, sock->ops->poll(NULL, sock, NULL)); + return((sock->ops->poll(NULL, sock, NULL) & + (POLLHUP|POLLERR|POLLIN)) != 0); +} + +int +mfs_send(struct socket *sock, int first, int serial, int type, + void *header, int hdsz, void *dat1, int dat1sz, void *dat2, int dat2sz) +{ + struct mfs_message_header hd; + struct iovec iov[5]; + struct msghdr msg = { NULL, 0, iov, 0, NULL, 0, MSG_NOSIGNAL }; + mm_segment_t oldfs; + int niov = 1; + int size = 0; + int error = -ENOMEM; + + hd.serial = serial; + hd.first = first; + hd.version = MFS_VERSION; + hd.caller = PE; + hd.type = type; + hd.hdsz = hdsz; + hd.dat1sz = dat1sz; + hd.dat2sz = dat2sz; + iov[0].iov_base = &hd; + iov[0].iov_len = sizeof(hd); + if(hdsz) + { + iov[1].iov_base = header; + iov[1].iov_len = hdsz; + niov++; + } + if(dat1sz) + { + iov[niov].iov_base = dat1; + iov[niov++].iov_len = dat1sz; + } + if(dat2sz) + { + iov[niov].iov_base = dat2; + iov[niov++].iov_len = dat2sz; + } + size = sizeof(hd) + hdsz + dat1sz + dat2sz; + msg.msg_iovlen = niov; + + deeper_sleep(); + oldfs = get_fs(); + set_fs(KERNEL_DS); + error = sock->ops->sendmsg(sock, &msg, size, 0); +if(mfs_debug) +printk("%s-mfs_send, type=%d, serial=%d, size=%d/%d/%d, err=%d\n", desc_mostask(NULL), type, serial, hdsz, dat1sz, dat2sz, error); + set_fs(oldfs); + lighter_sleep(); + + return (error < 0 ? error : 0); +} + +int +mfs_do_receive(struct socket *sock, void *base, int len) +{ + struct task_struct *p = current; + int n = 0; + struct iovec iov; + struct msghdr msg = { NULL, 0, &iov, 1, NULL, 0, + MSG_NOSIGNAL | MSG_DONTWAIT}; + int done = 0; + unsigned long timo = MFS_RECEIVE_TIMO; + DECLARE_WAITQUEUE(wait, p); + + add_wait_queue(sock->sk->sleep, &wait); + while(done < len) + { + set_current_state(TASK_INTERRUPTIBLE); + p->mosix.ignoreoldsigs = 1; + p->sigpending = 0; + if(!mfs_socket_has_data(sock)) + { + if(timo <= 0) + { + len = -EPIPE; + break; + } +if(mfs_debug)printk("mfs_do_receive: timo before=%ld\n", timo); + timo = schedule_timeout(timo); +if(mfs_debug)printk("mfs_do_receive: timo after=%ld\n", timo); + continue; + } + iov.iov_base = (void *)((char *)base + done); + iov.iov_len = len - done; + msg.msg_iov = &iov; + msg.msg_iovlen = 1; +if(mfs_debug > 2)printk("%s-mfs_do_receive: looking for %d-%d\n", desc_mostask(NULL), len, done); + n = sock->ops->recvmsg(sock, &msg, len-done, msg.msg_flags, 0); +if(mfs_debug > 2)printk("%s-mfs_do_receive: got %d of %d-%d\n", desc_mostask(NULL), n, len, done); + if (n == -EAGAIN || n == -ERESTARTSYS || n == -EINTR) + continue; + if(n <= 0) + { + len = n < 0 ? n : ECONNRESET; + break; + } + done += n; + } + remove_wait_queue(sock->sk->sleep, &wait); + set_current_state(TASK_RUNNING); + recalc_sigpending(p); + return (len); +} + +int +mfs_receive(struct socket *sock, int policy, int *serial, + struct mfs_message_header *preread_header, + void **header, void **dat1, void **dat2) +{ + struct mfs_message_header hd; + void *contents = NULL; + int tlen; + mm_segment_t oldfs; + int error; + int need_another; + +if(mfs_debug > 1) +printk("%s-mfs_receive, policy=%d\n", desc_mostask(NULL), policy); + deeper_sleep(); + oldfs = get_fs(); + set_fs(KERNEL_DS); + + next_message: + need_another = 0; + + if(preread_header && policy != MFS_JUST_HEADER) + { + hd = *preread_header; + preread_header = NULL; + error = 0; + } + else if ((error = mfs_do_receive(sock, &hd, sizeof(hd))) != sizeof(hd)) + { +if(mfs_debug) +printk("%s-mfs_receive: asked for header(%d), got %d\n", desc_mostask(NULL), sizeof(hd), error); + if (error >= 0) + error = -EPIPE; + goto failed; + } +if(mfs_debug) +printk("%s-mfs_do_receive: asked and got header: ", desc_mostask(NULL)); +if(mfs_debug) +printk("version=%d, first=%d, caller=%d, serial=%d, type=%d, size=%d/%d/%d\n", hd.version,hd.first, hd.caller, hd.serial, hd.type, hd.hdsz, hd.dat1sz, hd.dat2sz); + if(hd.version != MFS_VERSION) + { + static int limit; + + if(limit++ < 5) + { + printk("MFS received request from wrong version:\n"); + printk("Mine is %d, theirs (%d) is %d\n", MFS_VERSION, + hd.caller, hd.version); + error = -EINVAL; + goto failed; + } + } + error = 0; + switch(policy) + { + case MFS_JUST_HEADER: + if(hd.serial != *serial) + { + need_another = 1; + break; + } + *preread_header = hd; + goto done; + case MFS_SKIP_OTHERS: + if(hd.serial != *serial) + need_another = 1; + break; + case MFS_MUST_MATCH: + if(hd.first || hd.serial != *serial) + { + error = -EPIPE; + goto failed; + } + break; + case MFS_FIRST_RECEIVE: + if(hd.first) + *serial = hd.serial; + else + { + error = -EPIPE; + goto failed; + } + break; + } + tlen = hd.hdsz + hd.dat1sz + hd.dat2sz; + + if (tlen) + { + if(!(contents = kmalloc(tlen, GFP_KERNEL))) + { + error = -ENOMEM; + goto failed; + } + if ((error = mfs_do_receive(sock, contents, tlen)) != tlen) { +if(mfs_debug) +printk("%s-mfs_receive: asked for body(%d), got %d\n", desc_mostask(NULL), tlen, error); + if (error >= 0) + error = -EFAULT; + goto failed; + } +if(mfs_debug>1) +printk("%s-mfs_receive: asked and got body(%d)\n", desc_mostask(NULL), tlen); + } + error = 0; + +done: +failed: + lighter_sleep(); + set_fs(oldfs); + if(error) + { + if(contents) + kfree(contents); + if(header) + *header = NULL; + if(dat1) + *dat1 = NULL; + if(dat2) + *dat2 = NULL; +if(mfs_debug) +printk("%s-mfs_receive: error=%d\n", desc_mostask(NULL), error); + return(error); + } + else if(need_another) + { + need_another = 0; +if(mfs_debug) +printk("%s-mfs_receive: need another!\n", desc_mostask(NULL)); + if(contents) + { + kfree(contents); + contents = NULL; + } + goto next_message; + } + if(header) + *header = contents; + if(dat1) + *dat1 = (void *)(((char *)contents) + hd.hdsz); + if(dat2) + *dat2 = (void *)(((char *)contents) + hd.hdsz + hd.dat1sz); + return(hd.type); +} + +int +mfs_set_main_ownership(struct socket *sock, int main) +{ + int timo = HZ; + + spin_lock_irq(&skown_lock); + if(!main) + { + sock->sk->owner = NULL; + spin_unlock_irq(&skown_lock); + return(1); + } + sock->sk->owner = current; + set_bit(SOCK_WAIT_MFSDATA, &sock->flags); + spin_unlock_irq(&skown_lock); + while(1) + { + current->state = TASK_INTERRUPTIBLE; + if(sock->ops->poll(NULL, sock, 0) & POLLIN) + { + spin_lock_irq(&skown_lock); + clear_bit(SOCK_WAIT_MFSDATA, &sock->flags); + sock->sk->owner = NULL; + spin_unlock_irq(&skown_lock); + current->state = TASK_RUNNING; + return(0); + } + if(main == 1 || timo <= 0) + { + spin_lock_irq(&skown_lock); + clear_bit(SOCK_WAIT_MFSDATA, &sock->flags); + sock->sk->owner = NULL; + current->state = TASK_RUNNING; + spin_unlock_irq(&skown_lock); + sock->sk->owner = mfs_main_server_task; + mfs_new_request_arrived(); + return(1); + } + timo = schedule_timeout(timo); + } +} + +void +mfs_close_socket(struct socket *sock) +{ + spin_lock_irq(&skown_lock); + if(sock->sk) + sock->sk->owner = NULL; + clear_bit(SOCK_INTER_MOSIX, &sock->flags); + spin_unlock_irq(&skown_lock); + if(sock->ops) + sock->ops->shutdown(sock, 2); + sock_release(sock); +} + +#endif /* CONFIG_MOSIX_FS */ diff -urN linux-2.4.17/fs/namei.c linux_umopenmosix/fs/namei.c --- linux-2.4.17/fs/namei.c Wed Oct 17 23:46:29 2001 +++ linux_umopenmosix/fs/namei.c Sun Jun 23 12:40:11 2002 @@ -26,6 +26,15 @@ #include #include +#ifdef CONFIG_MOSIX_FS +#include +#include +#endif /* CONFIG_MOSIX_FS */ +#ifdef CONFIG_MOSIX_DFSA +#include +#define replaced_name name_left +#endif /* CONFIG_MOSIX_DFSA */ + #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE]) /* [Feb-1997 T. Schoebel-Theuer] @@ -237,6 +246,7 @@ spin_unlock(&arbitration_lock); return 0; } + int deny_write_access(struct file * file) { spin_lock(&arbitration_lock); @@ -324,6 +334,25 @@ return result; } +#ifdef CONFIG_MOSIX_DFSA +static inline int +dfsa_crossed(struct nameidata *nd, struct vfsmount *prevmnt) +{ + if(nd->flags & LOOKUP_STAYFS) + { + mntput(prevmnt); + if(nd->mnt != prevmnt) + { + if(current->mosix.dflags & DREMOTE) + return(-EDOITATHOME); + nd->flags &= ~LOOKUP_STAYFS; + current->mosix.dflags &= ~DSTATSDOWN; + } + } + return(0); +} +#endif /* CONFIG_MOSIX_DFSA */ + /* * This limits recursive symlink follows to 8, while * limiting consecutive symlinks to 40. @@ -436,6 +465,15 @@ } } +#ifdef CONFIG_MOSIX_FS +static inline int +unacceptable_mfs_fs(unsigned long magic) +{ + return(magic == PROC_SUPER_MAGIC || magic == 0x42494e4d); + /* (BINMisc) */ +} +#endif /* CONFIG_MOSIX_FS */ + /* * Name resolution. * @@ -450,7 +488,29 @@ struct inode *inode; int err; unsigned int lookup_flags = nd->flags; - +#ifdef CONFIG_MOSIX_DFSA + struct vfsmount *prevmnt = NULL; +#endif /* CONFIG_MOSIX_DFSA */ +#ifdef CONFIG_MOSIX_FS + char *orig_part = NULL, *orig_ref = NULL, *tmpname; + int flattings = 0; + char *free_me = NULL; +#endif /* CONFIG_MOSIX_FS */ + +#ifdef CONFIG_MOSIX_DFSA + /* an early error in path_init? (callers did not error-check there!) */ + if(nd->flags & LOOKUP_DOITATHOME) + { + path_release(nd); + return(-EDOITATHOME); + } + if(nd->flags & LOOKUP_REPLACENAME) + { + nd->flags &= ~LOOKUP_REPLACENAME; + name = nd->replaced_name; + nd->replaced_name = NULL; + } +#endif /* CONFIG_MOSIX_DFSA */ while (*name=='/') name++; if (!*name) @@ -458,7 +518,12 @@ inode = nd->dentry->d_inode; if (current->link_count) +#ifdef CONFIG_MOSIX_FS + lookup_flags = LOOKUP_FOLLOW | + (nd->flags & (LOOKUP_MFS|LOOKUP_MFS_MFS)); +#else lookup_flags = LOOKUP_FOLLOW; +#endif /* CONFIG_MOSIX_FS */ /* At this point we know we have a real path component. */ for(;;) { @@ -466,6 +531,47 @@ struct qstr this; unsigned int c; +#ifdef CONFIG_MOSIX_FS + /* have we consumed the whole link and can continue + * with the original name? + */ + if(orig_part && name >= orig_part) + { + name = orig_ref + (name - orig_part); + orig_part = orig_ref = NULL; + if(free_me) + { + kfree(free_me); + free_me = NULL; + } + flattings = 0; /* real progress made */ + nd->flags &= ~LOOKUP_MFS_MFS; + } + if(inode->i_op->express_lookup) + { + if(current->link_count) + /* flatten the path by passing it back to top-level, + * so all is included in the same express_lookup */ + { + if(!(nd->name_left = + kmalloc(strlen(name)+1, GFP_KERNEL))) + { + err = -ENOMEM; + break; + } + strcpy(nd->name_left, name); + return(0); + } + err = inode->i_op->express_lookup(nd, (char **)&name); + if(IS_ERR((const void *)err)) + break; + if(!name) + goto return_err; /*trick: err can be positive*/ + inode = nd->dentry->d_inode; + continue; + } +#endif /* CONFIG_MOSIX_FS */ + err = permission(inode, MAY_EXEC); dentry = ERR_PTR(err); if (err) @@ -501,7 +607,25 @@ case 2: if (this.name[1] != '.') break; +#ifdef CONFIG_MOSIX_FS + if((nd->flags & LOOKUP_MFS) && + !current->link_count && !orig_ref && + is_mfs_root(nd)) + { + nd->name_left = (char *)name; + path_release(nd); + goto return_base; + } +#endif /* CONFIG_MOSIX_FS */ +#ifdef CONFIG_MOSIX_DFSA + if(nd->flags & LOOKUP_STAYFS) + prevmnt = mntget(nd->mnt); +#endif /* CONFIG_MOSIX_DFSA */ follow_dotdot(nd); +#ifdef CONFIG_MOSIX_DFSA + if((err = dfsa_crossed(nd, prevmnt))) + break; +#endif /* CONFIG_MOSIX_DFSA */ inode = nd->dentry->d_inode; /* fallthrough */ case 1: @@ -525,8 +649,16 @@ break; } /* Check mountpoints.. */ +#ifdef CONFIG_MOSIX_DFSA + if(nd->flags & LOOKUP_STAYFS) + prevmnt = mntget(nd->mnt); +#endif /* CONFIG_MOSIX_DFSA */ while (d_mountpoint(dentry) && __follow_down(&nd->mnt, &dentry)) ; +#ifdef CONFIG_MOSIX_DFSA + if((err = dfsa_crossed(nd, prevmnt))) + break; +#endif /* CONFIG_MOSIX_DFSA */ err = -ENOENT; inode = dentry->d_inode; @@ -543,6 +675,43 @@ goto return_err; err = -ENOENT; inode = nd->dentry->d_inode; +#ifdef CONFIG_MOSIX_FS + if(nd->name_left) + { + int l = strlen(nd->name_left); + + err = -ELOOP; + if(flattings++ > 8) + { + kfree(nd->name_left); + nd->name_left = NULL; + break; + } + err = -ENOMEM; + if(!(tmpname = kmalloc(l + strlen(name) + 2, + GFP_KERNEL))) + { + kfree(nd->name_left); + nd->name_left = NULL; + break; + } + sprintf(tmpname, "%s/%s", nd->name_left, name); + kfree(nd->name_left); + if(current->link_count) + { + nd->name_left = tmpname; + return(0); + } + if(free_me) + kfree(free_me); + free_me = tmpname; + nd->name_left = NULL; + orig_part = tmpname + l + 1; + orig_ref = (char *)name; + name = tmpname; + continue; + } +#endif /* CONFIG_MOSIX_FS */ if (!inode) break; err = -ENOTDIR; @@ -553,8 +722,19 @@ nd->dentry = dentry; } err = -ENOTDIR; +#ifdef CONFIG_MOSIX_FS + if (!inode->i_op->express_lookup) +#endif /* CONFIG_MOSIX_FS */ if (!inode->i_op->lookup) break; +#ifdef CONFIG_MOSIX_FS + if(lookup_flags & LOOKUP_MFS) + { + err = -EACCES; + if(unacceptable_mfs_fs(nd->mnt->mnt_sb->s_magic)) + break; + } +#endif /* CONFIG_MOSIX_FS */ continue; /* here ends the main loop */ @@ -569,7 +749,25 @@ case 2: if (this.name[1] != '.') break; +#ifdef CONFIG_MOSIX_FS + if((nd->flags & LOOKUP_MFS) && + !current->link_count && !orig_ref && + is_mfs_root(nd)) + { + nd->name_left = (char *)name; + path_release(nd); + goto return_base; + } +#endif /* CONFIG_MOSIX_FS */ +#ifdef CONFIG_MOSIX_DFSA + if(nd->flags & LOOKUP_STAYFS) + prevmnt = mntget(nd->mnt); +#endif /* CONFIG_MOSIX_DFSA */ follow_dotdot(nd); +#ifdef CONFIG_MOSIX_DFSA + if((err = dfsa_crossed(nd, prevmnt))) + break; +#endif /* CONFIG_MOSIX_DFSA */ inode = nd->dentry->d_inode; /* fallthrough */ case 1: @@ -587,8 +785,16 @@ if (IS_ERR(dentry)) break; } +#ifdef CONFIG_MOSIX_DFSA + if(nd->flags & LOOKUP_STAYFS) + prevmnt = mntget(nd->mnt); +#endif /* CONFIG_MOSIX_DFSA */ while (d_mountpoint(dentry) && __follow_down(&nd->mnt, &dentry)) ; +#ifdef CONFIG_MOSIX_DFSA + if((err = dfsa_crossed(nd, prevmnt))) + break; +#endif /* CONFIG_MOSIX_DFSA */ inode = dentry->d_inode; if ((lookup_flags & LOOKUP_FOLLOW) && inode && inode->i_op && inode->i_op->follow_link) { @@ -597,6 +803,29 @@ if (err) goto return_err; inode = nd->dentry->d_inode; +#ifdef CONFIG_MOSIX_FS + if(nd->name_left) + { + err = -ELOOP; + if(flattings++ > 8) + { + kfree(nd->name_left); + nd->name_left = NULL; + break; + } + err = -ENOMEM; + if(free_me) + kfree(free_me); + if(current->link_count) + return(0); + orig_ref = (char *)name; + name = free_me = nd->name_left; + nd->name_left = NULL; + lookup_flags = nd->flags; + orig_part = NULL; + continue; + } +#endif /* CONFIG_MOSIX_FS */ } else { dput(nd->dentry); nd->dentry = dentry; @@ -606,9 +835,26 @@ goto no_inode; if (lookup_flags & LOOKUP_DIRECTORY) { err = -ENOTDIR; +#ifdef CONFIG_MOSIX_FS + if (!inode->i_op || (!inode->i_op->lookup && + !inode->i_op->express_lookup)) +#else if (!inode->i_op || !inode->i_op->lookup) +#endif /* CONFIG_MOSIX_FS */ break; } +#ifdef CONFIG_MOSIX_FS + if(lookup_flags & LOOKUP_MFS) + { + umode_t mod = inode->i_mode & S_IFMT; + + err = -EACCES; + if(mod != S_IFREG && mod != S_IFDIR && mod != S_IFLNK) + break; + if(unacceptable_mfs_fs(nd->mnt->mnt_sb->s_magic)) + break; + } +#endif /* CONFIG_MOSIX_FS */ goto return_base; no_inode: err = -ENOENT; @@ -625,6 +871,10 @@ else if (this.len == 2 && this.name[1] == '.') nd->last_type = LAST_DOTDOT; return_base: +#ifdef CONFIG_MOSIX_FS + if(free_me) + kfree(free_me); +#endif /* CONFIG_MOSIX_FS */ return 0; out_dput: dput(dentry); @@ -632,6 +882,10 @@ } path_release(nd); return_err: +#ifdef CONFIG_MOSIX_FS + if(free_me) + kfree(free_me); +#endif /* CONFIG_MOSIX_FS */ return err; } @@ -701,12 +955,53 @@ dput(olddentry); mntput(oldmnt); } +#ifdef CONFIG_MOSIX_DFSA + tell_process(current, DREQ_NOTUPTODATE); +#endif /* CONFIG_MOSIX_DFSA */ } /* SMP-safe */ static inline int walk_init_root(const char *name, struct nameidata *nd) { +#ifdef CONFIG_MOSIX_DFSA + if(nd->flags & LOOKUP_STAYFS) + { + struct task_struct *p = current; + + if(current->fs->altroot) + { + p->mosix.dflags &= ~DSTATSDOWN; + nd->flags &= ~LOOKUP_STAYFS; + } + else if(p->mosix.dflags & DDEPUTY) + nd->flags &= ~LOOKUP_STAYFS; + else if(((p->mosix.dflags & DREMOTE) || CAN_DFSA(p)) && + name_starts_in_dfsa((char **)&name, nd)) + { + if(!(p->mosix.dflags & DREMOTE) && !p->link_count) + p->mosix.dflags |= DSTATSDOWN; + if(!*name) + return(0); + nd->flags |= LOOKUP_REPLACENAME; + nd->replaced_name = (char *)name; + return(1); + } + else if(p->mosix.dflags & DREMOTE) + { + nd->flags |= LOOKUP_DOITATHOME; + nd->mnt = NULL; + nd->dentry = NULL; + return(1); + } + else + p->mosix.dflags &= ~DSTATSDOWN; + } +#endif /* CONFIG_MOSIX_DFSA */ +#ifdef CONFIG_MOSIX_FS + if(nd->flags & LOOKUP_MFS) + return(mfs_walk_init_root(nd)); +#endif /* CONFIG_MOSIX_FS */ read_lock(¤t->fs->lock); if (current->fs->altroot && !(nd->flags & LOOKUP_NOALT)) { nd->mnt = mntget(current->fs->altrootmnt); @@ -727,12 +1022,48 @@ { nd->last_type = LAST_ROOT; /* if there are only slashes... */ nd->flags = flags; +#ifdef CONFIG_MOSIX_FS + nd->name_left = NULL; + nd->complete_flags = 0; +#ifdef CONFIG_MOSIX_DIAG + if(flags & LOOKUP_MFS) + panic("MFS should have own path_init!"); +#endif /* CONFIG_MOSIX_DIAG */ +#endif /* CONFIG_MOSIX_FS */ if (*name=='/') return walk_init_root(name,nd); read_lock(¤t->fs->lock); nd->mnt = mntget(current->fs->pwdmnt); nd->dentry = dget(current->fs->pwd); read_unlock(¤t->fs->lock); +#ifdef CONFIG_MOSIX_DFSA + if(!nd->dentry) /* possible on REMOTE! */ + { + nd->flags |= LOOKUP_DOITATHOME; + return(1); + } + + if(nd->flags & LOOKUP_STAYFS) + { + struct task_struct *p = current; + + if(p->mosix.dflags & DDEPUTY) + nd->flags &= ~LOOKUP_STAYFS; + else if(((p->mosix.dflags & DREMOTE) || CAN_DFSA(p)) && + within_dfsa(nd)) + { + if(!(p->mosix.dflags & DREMOTE)) + p->mosix.dflags |= DSTATSDOWN; + } + else + { + if(p->mosix.dflags & DREMOTE) + nd->flags |= LOOKUP_DOITATHOME; + else + p->mosix.dflags &= ~DSTATSDOWN; + } + } +#endif /* CONFIG_MOSIX_DFSA */ return 1; } @@ -832,6 +1163,10 @@ err = path_walk(tmp, nd); putname(tmp); } +#ifdef CONFIG_MOSIX_FS + else + nd->complete_flags = 0; +#endif /* CONFIG_MOSIX_FS */ return err; } @@ -898,7 +1233,11 @@ * 3. We should have write and exec permissions on dir * 4. We can't do it if dir is immutable (done in permission()) */ +#ifdef CONFIG_MOSIX_FS +inline int may_create(struct inode *dir, struct dentry *child) { +#else static inline int may_create(struct inode *dir, struct dentry *child) { +#endif /* CONFIG_MOSIX_FS */ if (child->d_inode) return -EEXIST; if (IS_DEADDIR(dir)) @@ -976,17 +1315,46 @@ struct dentry *dentry; struct dentry *dir; int count = 0; +#if defined(CONFIG_MOSIX_DFSA) || defined(CONFIG_MOSIX_FS) + unsigned int more_flags = 0; +#endif /* CONFIG_MOSIX_DFSA || CONFIG_MOSIX_FS */ acc_mode = ACC_MODE(flag); +#ifdef CONFIG_MOSIX_FS + if(!pathname) /* special argument to skip path-search */ + { + if(flag & O_CREAT) + goto low_create; + else + goto low_nocreate; + } + nd->express_function = EF_OPEN; + nd->complete_args.ints.i1 = flag; + nd->complete_args.ints.i2 = mode & ~current->fs->umask; + more_flags |= LOOKUP_COMPLETE; +#endif /* CONFIG_MOSIX_FS */ +#ifdef CONFIG_MOSIX_DFSA + if(current->mosix.dirty_bits & FILP_OPEN_SYSCALL) + more_flags |= LOOKUP_STAYFS; +#endif /* CONFIG_MOSIX_DFSA */ /* * The simplest case - just a plain lookup. */ if (!(flag & O_CREAT)) { +#if defined(CONFIG_MOSIX_DFSA) || defined(CONFIG_MOSIX_FS) + if (path_init(pathname, lookup_flags(flag)|more_flags, nd)) +#else if (path_init(pathname, lookup_flags(flag), nd)) +#endif /* CONFIG_MOSIX_DFSA || CONFIG_MOSIX_FS */ error = path_walk(pathname, nd); if (error) return error; +#ifdef CONFIG_MOSIX_FS + if(nd->complete_flags & COMPLETE_DONE) + return(0); + low_nocreate: +#endif /* CONFIG_MOSIX_FS */ dentry = nd->dentry; goto ok; } @@ -994,10 +1362,19 @@ /* * Create - we need to know the parent. */ +#if defined(CONFIG_MOSIX_DFSA) || defined(CONFIG_MOSIX_FS) + if (path_init(pathname, LOOKUP_PARENT|more_flags, nd)) +#else if (path_init(pathname, LOOKUP_PARENT, nd)) +#endif /* CONFIG_MOSIX_FS */ error = path_walk(pathname, nd); if (error) return error; +#ifdef CONFIG_MOSIX_FS + if(nd->complete_flags & COMPLETE_DONE) + return(0); + low_create: +#endif /* CONFIG_MOSIX_FS */ /* * We have the parent and last component. First of all, check @@ -1186,7 +1563,11 @@ } /* SMP-safe */ +#ifdef CONFIG_MOSIX_FS +struct dentry *lookup_create(struct nameidata *nd, int is_dir) +#else static struct dentry *lookup_create(struct nameidata *nd, int is_dir) +#endif /* CONFIG_MOSIX_FS */ { struct dentry *dentry; @@ -1247,8 +1628,18 @@ if (IS_ERR(tmp)) return PTR_ERR(tmp); +#ifdef CONFIG_MOSIX_FS + nd.express_function = EF_MKNOD; + nd.complete_args.ints.i1 = mode & ~current->fs->umask; + if (path_init(tmp, LOOKUP_COMPLETE|LOOKUP_PARENT, &nd)) +#else if (path_init(tmp, LOOKUP_PARENT, &nd)) +#endif /* CONFIG_MOSIX_FS */ error = path_walk(tmp, &nd); +#ifdef CONFIG_MOSIX_FS + if(nd.complete_flags & COMPLETE_DONE) + goto out; +#endif /* CONFIG_MOSIX_FS */ if (error) goto out; dentry = lookup_create(&nd, 0); @@ -1316,10 +1707,25 @@ struct dentry *dentry; struct nameidata nd; +#ifdef CONFIG_MOSIX_FS + nd.express_function = EF_MKDIR; + nd.complete_args.ints.i1 = mode & ~current->fs->umask; + if (path_init(tmp, LOOKUP_COMPLETE|LOOKUP_PARENT|LOOKUP_STAYFS, + &nd)) +#else +#ifdef CONFIG_MOSIX_DFSA + if (path_init(tmp, LOOKUP_PARENT|LOOKUP_STAYFS, &nd)) +#else if (path_init(tmp, LOOKUP_PARENT, &nd)) +#endif /* CONFIG_MOSIX_DFSA */ +#endif /* CONFIG_MOSIX_FS */ error = path_walk(tmp, &nd); if (error) goto out; +#ifdef CONFIG_MOSIX_FS + if(nd.complete_flags & COMPLETE_DONE) + goto out; +#endif /* CONFIG_MOSIX_FS */ dentry = lookup_create(&nd, 1); error = PTR_ERR(dentry); if (!IS_ERR(dentry)) { @@ -1411,10 +1817,23 @@ if(IS_ERR(name)) return PTR_ERR(name); +#ifdef CONFIG_MOSIX_FS + nd.express_function = EF_RMDIR; + if (path_init(name, LOOKUP_COMPLETE|LOOKUP_PARENT|LOOKUP_STAYFS, &nd)) +#else +#ifdef CONFIG_MOSIX_DFSA + if (path_init(name, LOOKUP_PARENT|LOOKUP_STAYFS, &nd)) +#else if (path_init(name, LOOKUP_PARENT, &nd)) +#endif /* CONFIG_MOSIX_DFSA */ +#endif /* CONFIG_MOSIX_FS */ error = path_walk(name, &nd); if (error) goto exit; +#ifdef CONFIG_MOSIX_FS + if(nd.complete_flags & COMPLETE_DONE) + goto exit; +#endif /* CONFIG_MOSIX_FS */ switch(nd.last_type) { case LAST_DOTDOT: @@ -1480,10 +1899,23 @@ if(IS_ERR(name)) return PTR_ERR(name); +#ifdef CONFIG_MOSIX_FS + nd.express_function = EF_UNLINK; + if (path_init(name, LOOKUP_COMPLETE|LOOKUP_PARENT|LOOKUP_STAYFS, &nd)) +#else +#ifdef CONFIG_MOSIX_DFSA + if (path_init(name, LOOKUP_PARENT|LOOKUP_STAYFS, &nd)) +#else if (path_init(name, LOOKUP_PARENT, &nd)) +#endif /* CONFIG_MOSIX_DFSA */ +#endif /* CONFIG_MOSIX_FS */ error = path_walk(name, &nd); if (error) goto exit; +#ifdef CONFIG_MOSIX_FS + if(nd.complete_flags & COMPLETE_DONE) + goto exit; +#endif /* CONFIG_MOSIX_FS */ error = -EISDIR; if (nd.last_type != LAST_NORM) goto exit1; @@ -1552,10 +1984,25 @@ struct dentry *dentry; struct nameidata nd; +#ifdef CONFIG_MOSIX_FS + nd.express_function = EF_SYMLINK; + nd.complete_parg = from; + if (path_init(to, LOOKUP_COMPLETE|LOOKUP_PARENT|LOOKUP_STAYFS, + &nd)) +#else +#ifdef CONFIG_MOSIX_DFSA + if (path_init(to, LOOKUP_PARENT|LOOKUP_STAYFS, &nd)) +#else if (path_init(to, LOOKUP_PARENT, &nd)) +#endif /* CONFIG_MOSIX_DFSA */ +#endif /* CONFIG_MOSIX_FS */ error = path_walk(to, &nd); if (error) goto out; +#ifdef CONFIG_MOSIX_FS + if(nd.complete_flags & COMPLETE_DONE) + goto out; +#endif /* CONFIG_MOSIX_FS */ dentry = lookup_create(&nd, 0); error = PTR_ERR(dentry); if (!IS_ERR(dentry)) { @@ -1634,16 +2081,40 @@ if (!IS_ERR(to)) { struct dentry *new_dentry; struct nameidata nd, old_nd; +#if defined(CONFIG_MOSIX_DFSA) || defined(CONFIG_MOSIX_FS) + unsigned int more_flags = 0; +#endif /* CONFIG_MOSIX_DFSA || CONFIG_MOSIX_FS */ error = 0; +#ifdef CONFIG_MOSIX_DFSA + if (path_init(from, LOOKUP_POSITIVE|LOOKUP_STAYFS, &old_nd)) +#else if (path_init(from, LOOKUP_POSITIVE, &old_nd)) +#endif /* CONFIG_MOSIX_DFSA */ error = path_walk(from, &old_nd); if (error) goto exit; +#ifdef CONFIG_MOSIX_DFSA + if(current->mosix.dflags & (DREMOTE|DSTATSDOWN)) + more_flags |= LOOKUP_STAYFS; +#endif /* CONFIG_MOSIX_DFSA */ +#ifdef CONFIG_MOSIX_FS + nd.express_function = EF_LINK; + nd.complete_args.oldnd = &old_nd; + more_flags |= LOOKUP_COMPLETE; +#endif /* CONFIG_MOSIX_FS */ +#if defined(CONFIG_MOSIX_DFSA) || defined(CONFIG_MOSIX_FS) + if (path_init(to, LOOKUP_PARENT|more_flags, &nd)) +#else if (path_init(to, LOOKUP_PARENT, &nd)) +#endif /* CONFIG_MOSIX_DFSA || CONFIG_MOSIX_FS */ error = path_walk(to, &nd); if (error) goto out; +#ifdef CONFIG_MOSIX_FS + if(nd.complete_flags & COMPLETE_DONE) + goto out; +#endif /* CONFIG_MOSIX_FS */ error = -EXDEV; if (old_nd.mnt != nd.mnt) goto out_release; @@ -1840,15 +2311,39 @@ struct dentry * old_dir, * new_dir; struct dentry * old_dentry, *new_dentry; struct nameidata oldnd, newnd; - +#if defined(CONFIG_MOSIX_DFSA) || defined(CONFIG_MOSIX_FS) + unsigned int more_flags = 0; +#endif /* CONFIG_MOSIX_DFSA || CONFIG_MOSIX_FS */ + +#ifdef CONFIG_MOSIX_DFSA + if (path_init(oldname, LOOKUP_PARENT|LOOKUP_STAYFS, &oldnd)) +#else if (path_init(oldname, LOOKUP_PARENT, &oldnd)) +#endif /* CONFIG_MOSIX_DFSA */ error = path_walk(oldname, &oldnd); if (error) goto exit; +#ifdef CONFIG_MOSIX_DFSA + if(current->mosix.dflags & (DREMOTE|DSTATSDOWN)) + more_flags |= LOOKUP_STAYFS; +#endif /* CONFIG_MOSIX_DFSA */ +#ifdef CONFIG_MOSIX_FS + newnd.express_function = EF_RENAME; + newnd.complete_args.oldnd = &oldnd; + more_flags |= LOOKUP_COMPLETE; +#endif /* CONFIG_MOSIX_FS */ +#if defined(CONFIG_MOSIX_DFSA) || defined(CONFIG_MOSIX_FS) + if (path_init(newname, LOOKUP_PARENT|more_flags, &newnd)) +#else if (path_init(newname, LOOKUP_PARENT, &newnd)) +#endif /* CONFIG_MOSIX_DFSA || CONFIG_MOSIX_FS */ error = path_walk(newname, &newnd); +#ifdef CONFIG_MOSIX_FS + if(newnd.complete_flags & COMPLETE_DONE) + goto exit1; +#endif /* CONFIG_MOSIX_FS */ if (error) goto exit1; @@ -1955,8 +2450,16 @@ if (!walk_init_root(link, nd)) /* weird __emul_prefix() stuff did it */ goto out; +#ifdef CONFIG_MOSIX_FS + if(nd->flags & LOOKUP_MFS) + nd->flags |= LOOKUP_MFS_MFS; +#endif /* CONFIG_MOSIX_FS */ } res = link_path_walk(link, nd); +#ifdef CONFIG_MOSIX_FS + if(!nd->name_left) + nd->flags &= ~LOOKUP_MFS_MFS; +#endif /* CONFIG_MOSIX_FS */ out: if (current->link_count || res || nd->last_type!=LAST_NORM) return res; diff -urN linux-2.4.17/fs/namespace.c linux_umopenmosix/fs/namespace.c --- linux-2.4.17/fs/namespace.c Fri Dec 21 19:41:55 2001 +++ linux_umopenmosix/fs/namespace.c Sun Jun 23 12:40:11 2002 @@ -21,13 +21,24 @@ #include +#ifdef CONFIG_MOSIX +#include +#endif /* CONFIG_MOSIX */ +#ifdef CONFIG_MOSIX_DFSA +#include +#include +#endif /* CONFIG_MOSIX_DFSA */ +#ifdef CONFIG_MOSIX_FS +#include +#endif /* CONFIG_MOSIX_FS */ + struct vfsmount *do_kern_mount(char *type, int flags, char *name, void *data); int do_remount_sb(struct super_block *sb, int flags, void * data); void kill_super(struct super_block *sb); static struct list_head *mount_hashtable; static int hash_mask, hash_bits; -static kmem_cache_t *mnt_cache; +static kmem_cache_t *mnt_cache; static LIST_HEAD(vfsmntlist); static DECLARE_MUTEX(mount_sem); @@ -45,7 +56,7 @@ struct vfsmount *alloc_vfsmnt(void) { - struct vfsmount *mnt = kmem_cache_alloc(mnt_cache, GFP_KERNEL); + struct vfsmount *mnt = kmem_cache_alloc(mnt_cache, GFP_KERNEL); if (mnt) { memset(mnt, 0, sizeof(struct vfsmount)); atomic_set(&mnt->mnt_count,1); @@ -240,7 +251,12 @@ } if (mnt->mnt_sb->s_op->show_options) err = mnt->mnt_sb->s_op->show_options(m, mnt); - seq_puts(m, " 0 0\n"); + seq_puts(m, " 0 0"); +#ifdef CONFIG_MOSIX_DFSA + if (mnt->mnt_dfsa) + seq_printf(m, ",dfsa=%d", mnt->mnt_dfsa); +#endif /* CONFIG_MOSIX_DFSA */ + seq_puts(m, "\n"); return err; } @@ -333,7 +349,16 @@ return retval; } +#ifdef CONFIG_MOSIX_DFSA + down_half_interruptible(&mount_sem); + if((retval = dfsa_setmnt(mnt, 0, 0))) + { + up(&mount_sem); + return(retval); + } +#else down(&mount_sem); +#endif /* CONFIG_MOSIX_DFSA */ spin_lock(&dcache_lock); if (atomic_read(&sb->s_active) == 1) { @@ -398,9 +423,9 @@ } /* - * The 2.0 compatible umount. No flags. + * The 2.0 compatible umount. No flags. */ - + asmlinkage long sys_oldumount(char * name) { return sys_umount(name,0); @@ -510,7 +535,11 @@ if (err) return err; +#ifdef CONFIG_MOSIX + down_half_interruptible(&mount_sem); +#else down(&mount_sem); +#endif /* CONFIG_MOSIX */ err = -EINVAL; if (check_mnt(nd->mnt) && (!recurse || check_mnt(old_nd.mnt))) { err = -ENOMEM; @@ -545,6 +574,9 @@ { int err; struct super_block * sb = nd->mnt->mnt_sb; +#ifdef CONFIG_MOSIX_DFSA + int odfsa = 0, new_dfsa, cng_dfsa; +#endif /* CONFIG_MOSIX_DFSA */ if (!capable(CAP_SYS_ADMIN)) return -EPERM; @@ -555,11 +587,33 @@ if (nd->dentry != nd->mnt->mnt_root) return -EINVAL; +#ifdef CONFIG_MOSIX_DFSA + if((cng_dfsa = dfsa_option(data, &new_dfsa))) + { + down_half_interruptible(&mount_sem); + odfsa = nd->mnt->mnt_dfsa; + nd->mnt->mnt_dfsa = new_dfsa; + err = dfsa_setmnt(nd->mnt, new_dfsa, flags); + up(&mount_sem); + if(err) + return(err); + } +#endif /* CONFIG_MOSIX_DFSA */ down_write(&sb->s_umount); err = do_remount_sb(sb, flags, data); if (!err) nd->mnt->mnt_flags=mnt_flags; up_write(&sb->s_umount); +#ifdef CONFIG_MOSIX_DFSA + if(err && cng_dfsa) + { + /* undo - unless someone else played with mount meanwhile */ + down_half_interruptible(&mount_sem); + if(nd->mnt->mnt_dfsa == new_dfsa) + dfsa_setmnt(nd->mnt, odfsa, nd->mnt->mnt_sb->s_flags); + up(&mount_sem); + } +#endif /* CONFIG_MOSIX_DFSA */ return err; } @@ -572,7 +626,11 @@ if (IS_ERR(mnt)) goto out; +#ifdef CONFIG_MOSIX_DFSA + down_half_interruptible(&mount_sem); +#else down(&mount_sem); +#endif /* CONFIG_MOSIX_DFSA */ /* Something was mounted here while we slept */ while(d_mountpoint(nd->dentry) && follow_down(&nd->mnt, &nd->dentry)) ; @@ -599,7 +657,7 @@ int i; unsigned long page; unsigned long size; - + *where = 0; if (!data) return 0; @@ -618,7 +676,7 @@ i = size - copy_from_user((void *)page, data, size); if (!i) { - free_page(page); + free_page(page); return -EFAULT; } if (i != PAGE_SIZE) @@ -647,6 +705,9 @@ struct nameidata nd; int retval = 0; int mnt_flags = 0; +#ifdef CONFIG_MOSIX_DFSA + int dfsa_opt; +#endif /* CONFIG_MOSIX_DFSA */ /* Discard magic */ if ((flags & MS_MGC_MSK) == MS_MGC_VAL) @@ -682,6 +743,22 @@ else retval = do_add_mount(&nd, type_page, flags, mnt_flags, dev_name, data_page); +#ifdef CONFIG_MOSIX_DFSA + down_half_interruptible(&mount_sem); + if(!retval && dfsa_option((char *)data_page, &dfsa_opt) && + d_mountpoint(nd.dentry) && follow_down(&nd.mnt, &nd.dentry) + && (nd.mnt->mnt_dfsa = dfsa_opt) && + dfsa_setmnt(nd.mnt, dfsa_opt, flags)) + { + /* too late to undo the mount - all we can do is complain: */ + nd.mnt->mnt_dfsa = 0; + printk("Mount succeeded, but DFSA option failed: " + "if you can fix the problem, run:\n"); + printk("'mount -o remount,dfsa=%d %s %s'\n", dfsa_opt, + dev_name, dir_name); + } + up(&mount_sem); +#endif /* CONFIG_MOSIX_DFSA */ path_release(&nd); return retval; } @@ -733,7 +810,12 @@ struct fs_struct *fs; read_lock(&tasklist_lock); +#ifdef CONFIG_MOSIX + /* DFSA is disabled, so no REMOTE roots (and no cwd's away) */ + for_each_local_task(p) { +#else for_each_task(p) { +#endif /* CONFIG_MOSIX */ task_lock(p); fs = p->fs; if (fs) { @@ -750,6 +832,32 @@ read_unlock(&tasklist_lock); } +#ifdef CONFIG_MOSIX_DFSA +void +restore_dfsa_mounts(void) +{ + struct list_head *p; + int told = 0; + + for (p = vfsmntlist.next; p != &vfsmntlist; p = p->next) + { + struct vfsmount *tmp = list_entry(p, struct vfsmount, mnt_list); + + if(tmp->mnt_dfsa && + dfsa_setmnt(tmp, tmp->mnt_dfsa, tmp->mnt_sb->s_flags)) + { + if(!told++) + printk("One or more partitions failed to restore DFSA" + " status after pivot_root.\n" + "If you can fix the problem, please remount " + "the affected partition(s) with the appropriate" + " dfsa= option\n"); + tmp->mnt_dfsa = 0; + } + } +} +#endif /* CONFIG_MOSIX_DFSA */ + /* * Moves the current root to put_root, and sets root/cwd of all processes * which had them on the old root to new_root. @@ -773,6 +881,10 @@ if (!capable(CAP_SYS_ADMIN)) return -EPERM; +#ifdef CONFIG_MOSIX_DFSA + if((error = disable_dfsa())) + return(error); +#endif /* CONFIG_MOSIX_DFSA */ lock_kernel(); name = getname(new_root); @@ -804,7 +916,11 @@ user_nd.mnt = mntget(current->fs->rootmnt); user_nd.dentry = dget(current->fs->root); read_unlock(¤t->fs->lock); +#ifdef CONFIG_MOSIX_DFSA + down_half_interruptible(&mount_sem); +#else down(&mount_sem); +#endif /* CONFIG_MOSIX_DFSA */ down(&old_nd.dentry->d_inode->i_zombie); error = -EINVAL; if (!check_mnt(user_nd.mnt)) @@ -816,6 +932,15 @@ goto out2; if (d_unhashed(old_nd.dentry) && !IS_ROOT(old_nd.dentry)) goto out2; +#ifdef CONFIG_MOSIX_FS + if(new_nd.dentry->d_inode->i_sb->s_magic == MFS_SUPER_MAGIC || + old_nd.dentry->d_inode->i_sb->s_magic == MFS_SUPER_MAGIC) + { + /* MFS does not support mounts (which are otherwise ignored) */ + error = -EINVAL; + goto out2; + } +#endif /* CONFIG_MOSIX_FS */ error = -EBUSY; if (new_nd.mnt == user_nd.mnt || old_nd.mnt == user_nd.mnt) goto out2; /* loop */ @@ -843,6 +968,9 @@ attach_mnt(user_nd.mnt, &old_nd); attach_mnt(new_nd.mnt, &root_parent); spin_unlock(&dcache_lock); +#ifdef CONFIG_MOSIX_FS + mfs_change_root(user_nd.dentry, user_nd.mnt, new_nd.dentry, new_nd.mnt); +#endif /* CONFIG_MOSIX_FS */ chroot_fs_refs(&user_nd, &new_nd); error = 0; path_release(&root_parent); @@ -856,6 +984,10 @@ path_release(&new_nd); out0: unlock_kernel(); +#ifdef CONFIG_MOSIX_DFSA + enable_dfsa(); + restore_dfsa_mounts(); +#endif /* CONFIG_MOSIX_DFSA */ return error; out3: spin_unlock(&dcache_lock); @@ -1001,7 +1133,7 @@ mount_root(); #if 1 shrink_dcache(); - printk("change_root: old root has d_count=%d\n", + printk("change_root: old root has d_count=%d\n", atomic_read(&old_rootmnt->mnt_root->d_count)); #endif mount_devfs_fs (); @@ -1033,7 +1165,7 @@ } else { printk("okay\n"); error = 0; - } + } kfree(new_devname); return error; } diff -urN linux-2.4.17/fs/nfsd/auth.c linux_umopenmosix/fs/nfsd/auth.c --- linux-2.4.17/fs/nfsd/auth.c Mon Jul 24 09:04:10 2000 +++ linux_umopenmosix/fs/nfsd/auth.c Sun Jun 23 12:40:11 2002 @@ -9,6 +9,9 @@ #include #include #include +#ifdef CONFIG_MOSIX_DFSA +#include +#endif /* CONFIG_MOSIX_DFSA */ #define CAP_NFSD_MASK (CAP_FS_MASK|CAP_TO_MASK(CAP_SYS_RESOURCE)) void @@ -20,6 +23,9 @@ if (rqstp->rq_userset) return; +#ifdef CONFIG_MOSIX_DFSA + current->mosix.dupdates |= DFSA_UPDCRED; +#endif /* CONFIG_MOSIX_DFSA */ if (exp->ex_flags & NFSEXP_ALLSQUASH) { cred->cr_uid = exp->ex_anon_uid; cred->cr_gid = exp->ex_anon_gid; diff -urN linux-2.4.17/fs/nfsd/export.c linux_umopenmosix/fs/nfsd/export.c --- linux-2.4.17/fs/nfsd/export.c Thu Oct 4 07:57:36 2001 +++ linux_umopenmosix/fs/nfsd/export.c Sun Jun 23 12:40:11 2002 @@ -463,6 +463,9 @@ return 0; } +#ifdef CONFIG_MOSIX + current->mosix.ignoreoldsigs = 1; +#endif /* CONFIG_MOSIX */ current->sigpending = 0; want_lock++; while (hash_count || hash_lock) { diff -urN linux-2.4.17/fs/nfsd/vfs.c linux_umopenmosix/fs/nfsd/vfs.c --- linux-2.4.17/fs/nfsd/vfs.c Fri Dec 21 19:41:55 2001 +++ linux_umopenmosix/fs/nfsd/vfs.c Sun Jun 23 12:40:11 2002 @@ -45,6 +45,10 @@ #include +#ifdef CONFIG_MOSIX_FS +#include +#endif /* CONFIG_MOSIX_FS */ + #define NFSDDBG_FACILITY NFSDDBG_FILEOP #define NFSD_PARANOIA @@ -108,6 +112,13 @@ dparent = fhp->fh_dentry; exp = fhp->fh_export; +#ifdef CONFIG_MOSIX_FS + if(dparent->d_sb->s_magic == MFS_SUPER_MAGIC) + { + err = -EPERM; + goto out; + } +#endif /* CONFIG_MOSIX_FS */ err = nfserr_acces; /* Lookup the name, but don't follow links */ @@ -510,6 +521,9 @@ filp->f_op->release(inode, filp); fops_put(filp->f_op); if (filp->f_mode & FMODE_WRITE) +#ifdef CONFIG_MOSIX + if (!(filp->f_flags & O_NOWRITEACCESS)) +#endif /* CONFIG_MOSIX */ put_write_access(inode); } diff -urN linux-2.4.17/fs/open.c linux_umopenmosix/fs/open.c --- linux-2.4.17/fs/open.c Fri Oct 12 22:48:42 2001 +++ linux_umopenmosix/fs/open.c Sun Jun 23 12:40:11 2002 @@ -20,6 +20,12 @@ #define special_file(m) (S_ISCHR(m)||S_ISBLK(m)||S_ISFIFO(m)||S_ISSOCK(m)) +#ifdef CONFIG_MOSIX_DFSA +#include +#include +#include +#endif /* CONFIG_MOSIX_DFSA */ + int vfs_statfs(struct super_block *sb, struct statfs *buf) { int retval = -ENODEV; @@ -99,7 +105,21 @@ if (length < 0) /* sorry, but loff_t says... */ goto out; +#ifdef CONFIG_MOSIX_FS + nd.express_function = EF_TRUNCATE; + nd.complete_args.len = length; + error = __user_walk(path, LOOKUP_POSITIVE|LOOKUP_FOLLOW|LOOKUP_STAYFS| + LOOKUP_COMPLETE, &nd); + if(nd.complete_flags & COMPLETE_DONE) + return(error); +#else +#ifdef CONFIG_MOSIX_DFSA + error = __user_walk(path, + LOOKUP_POSITIVE|LOOKUP_FOLLOW|LOOKUP_STAYFS, &nd); +#else error = user_path_walk(path, &nd); +#endif /* CONFIG_MOSIX_DFSA */ +#endif /* CONFIG_MOSIX_FS */ if (error) goto out; inode = nd.dentry->d_inode; @@ -165,6 +185,9 @@ error = -EINVAL; if (length < 0) goto out; +#ifdef CONFIG_MOSIX_DFSA + dfsa_syscall_on_file(fd, 0); +#endif /* CONFIG_MOSIX_DFSA */ error = -EBADF; file = fget(fd); if (!file) @@ -236,7 +259,21 @@ struct inode * inode; struct iattr newattrs; +#ifdef CONFIG_MOSIX_FS + nd.express_function = EF_UTIME; + nd.complete_parg = times; + error = __user_walk(filename, LOOKUP_POSITIVE|LOOKUP_FOLLOW| + LOOKUP_STAYFS|LOOKUP_COMPLETE, &nd); + if(nd.complete_flags & COMPLETE_DONE) + return(error); +#else +#ifdef CONFIG_MOSIX_DFSA + error = __user_walk(filename, + LOOKUP_POSITIVE|LOOKUP_FOLLOW|LOOKUP_STAYFS, &nd); +#else error = user_path_walk(filename, &nd); +#endif /* CONFIG_MOSIX_DFSA */ +#endif /* CONFIG_MOSIX_FS */ if (error) goto out; inode = nd.dentry->d_inode; @@ -280,7 +317,21 @@ struct inode * inode; struct iattr newattrs; +#ifdef CONFIG_MOSIX_FS + nd.express_function = EF_UTIMES; + nd.complete_parg = utimes; + error = __user_walk(filename, LOOKUP_POSITIVE|LOOKUP_FOLLOW| + LOOKUP_STAYFS| LOOKUP_COMPLETE, &nd); + if(nd.complete_flags & COMPLETE_DONE) + return(error); +#else +#ifdef CONFIG_MOSIX_DFSA + error = __user_walk(filename, + LOOKUP_POSITIVE|LOOKUP_FOLLOW|LOOKUP_STAYFS , &nd); +#else error = user_path_walk(filename, &nd); +#endif /* CONFIG_MOSIX_DFSA */ +#endif /* CONFIG_MOSIX_FS */ if (error) goto out; @@ -339,7 +390,22 @@ else current->cap_effective = current->cap_permitted; +#ifdef CONFIG_MOSIX_FS + nd.express_function = EF_ACCESS; + nd.complete_args.ints.i1 = mode; + res = __user_walk(filename, + LOOKUP_POSITIVE|LOOKUP_FOLLOW|LOOKUP_COMPLETE|LOOKUP_STAYFS, + &nd); + if(nd.complete_flags & COMPLETE_DONE) + return(res); +#else +#ifdef CONFIG_MOSIX_DFSA + res = __user_walk(filename, + LOOKUP_POSITIVE|LOOKUP_FOLLOW|LOOKUP_STAYFS, &nd); +#else res = user_path_walk(filename, &nd); +#endif /* CONFIG_MOSIX_DFSA */ +#endif /* CONFIG_MOSIX_FS */ if (!res) { res = permission(nd.dentry->d_inode, mode); /* SuS v2 requires we report a read only fs too */ @@ -352,6 +418,11 @@ current->fsuid = old_fsuid; current->fsgid = old_fsgid; current->cap_effective = old_cap; +#ifdef CONFIG_MOSIX_DFSA + /* a bit paranoid, for the rare case when we slept interruptibly + * during "permission" and the temporary fs[ug]id passed across: */ + current->mosix.dupdates |= DFSA_UPDCRED; +#endif /* CONFIG_MOSIX_DFSA */ return res; } @@ -368,7 +439,12 @@ goto out; error = 0; +#ifdef CONFIG_MOSIX_DFSA + if (path_init(name, LOOKUP_POSITIVE|LOOKUP_FOLLOW|LOOKUP_DIRECTORY| + LOOKUP_STAYFS, &nd)) +#else if (path_init(name,LOOKUP_POSITIVE|LOOKUP_FOLLOW|LOOKUP_DIRECTORY,&nd)) +#endif /* CONFIG_MOSIX_DFSA */ error = path_walk(name, &nd); putname(name); if (error) @@ -394,6 +470,9 @@ struct vfsmount *mnt; int error; +#ifdef CONFIG_MOSIX_DFSA + dfsa_syscall_on_file(fd, 0); +#endif /* CONFIG_MOSIX_DFSA */ error = -EBADF; file = fget(fd); if (!file) @@ -459,6 +538,9 @@ int err = -EBADF; struct iattr newattrs; +#ifdef CONFIG_MOSIX_DFSA + dfsa_syscall_on_file(fd, 0); +#endif /* CONFIG_MOSIX_DFSA */ file = fget(fd); if (!file) goto out; @@ -491,7 +573,21 @@ int error; struct iattr newattrs; +#ifdef CONFIG_MOSIX_FS + nd.express_function = EF_CHMOD; + nd.complete_args.mode = mode; + error = __user_walk(filename, LOOKUP_POSITIVE|LOOKUP_FOLLOW| + LOOKUP_STAYFS|LOOKUP_COMPLETE, &nd); + if(nd.complete_flags & COMPLETE_DONE) + return(error); +#else +#ifdef CONFIG_MOSIX_DFSA + error = __user_walk(filename, + LOOKUP_POSITIVE|LOOKUP_FOLLOW|LOOKUP_STAYFS, &nd); +#else error = user_path_walk(filename, &nd); +#endif /* CONFIG_MOSIX_DFSA */ +#endif /* CONFIG_MOSIX_FS */ if (error) goto out; inode = nd.dentry->d_inode; @@ -516,7 +612,11 @@ return error; } +#ifdef CONFIG_MOSIX_FS +int chown_common(struct dentry * dentry, uid_t user, gid_t group) +#else static int chown_common(struct dentry * dentry, uid_t user, gid_t group) +#endif /* CONFIG_MOSIX_FS */ { struct inode * inode; int error; @@ -581,7 +681,22 @@ struct nameidata nd; int error; +#ifdef CONFIG_MOSIX_FS + nd.express_function = EF_CHOWN; + nd.complete_args.ids.uid = user; + nd.complete_args.ids.gid = group; + error = __user_walk(filename, LOOKUP_POSITIVE|LOOKUP_FOLLOW| + LOOKUP_STAYFS|LOOKUP_COMPLETE, &nd); + if(nd.complete_flags & COMPLETE_DONE) + return(error); +#else +#ifdef CONFIG_MOSIX_DFSA + error = __user_walk(filename, + LOOKUP_POSITIVE|LOOKUP_FOLLOW|LOOKUP_STAYFS, &nd); +#else error = user_path_walk(filename, &nd); +#endif /* CONFIG_MOSIX_DFSA */ +#endif /* CONFIG_MOSIX_FS */ if (!error) { error = chown_common(nd.dentry, user, group); path_release(&nd); @@ -594,7 +709,21 @@ struct nameidata nd; int error; +#ifdef CONFIG_MOSIX_FS + nd.express_function = EF_CHOWN; + nd.complete_args.ids.uid = user; + nd.complete_args.ids.gid = group; + error = __user_walk(filename, + LOOKUP_POSITIVE|LOOKUP_STAYFS|LOOKUP_COMPLETE, &nd); + if(nd.complete_flags & COMPLETE_DONE) + return(error); +#else +#ifdef CONFIG_MOSIX_DFSA + error = __user_walk(filename, LOOKUP_POSITIVE|LOOKUP_STAYFS, &nd); +#else error = user_path_walk_link(filename, &nd); +#endif /* CONFIG_MOSIX_DFSA */ +#endif /* CONFIG_MOSIX_FS */ if (!error) { error = chown_common(nd.dentry, user, group); path_release(&nd); @@ -608,6 +737,9 @@ struct file * file; int error = -EBADF; +#ifdef CONFIG_MOSIX_DFSA + dfsa_syscall_on_file(fd, 0); +#endif /* CONFIG_MOSIX_DFSA */ file = fget(fd); if (file) { error = chown_common(file->f_dentry, user, group); @@ -634,6 +766,9 @@ { int namei_flags, error; struct nameidata nd; +#ifdef CONFIG_MOSIX_FS + int old_magic = current->mosix.lastmagic; +#endif /* CONFIG_MOSIX_FS */ namei_flags = flags; if ((namei_flags+1) & O_ACCMODE) @@ -641,9 +776,31 @@ if (namei_flags & O_TRUNC) namei_flags |= 2; +#ifdef CONFIG_MOSIX_FS + if(flags & O_CREAT) + current->mosix.lastmagic = current->mosix.whereami ? : PE; +#endif /* CONFIG_MOSIX_FS */ error = open_namei(filename, namei_flags, mode, &nd); +#ifdef CONFIG_MOSIX_FS + if(!(nd.complete_flags & COMPLETE_MAGICAL)) + current->mosix.lastmagic = old_magic; +#endif /* CONFIG_MOSIX_FS */ if (!error) +#ifdef CONFIG_MOSIX_FS + { + struct file *newf = dentry_open(nd.dentry, nd.mnt, flags); + + if(IS_ERR(newf)) + current->mosix.lastmagic = old_magic; +#ifdef CONFIG_MOSIX_DFSA + else if(current->mosix.lastmagic != old_magic) + current->mosix.dupdates |= DFSA_UPDSEL; +#endif /* CONFIG_MOSIX_DFSA */ + return(newf); + } +#else return dentry_open(nd.dentry, nd.mnt, flags); +#endif /* CONFIG_MOSIX_FS */ return ERR_PTR(error); } @@ -735,6 +892,11 @@ /* Do we need to expand the fdset array? */ if (fd >= files->max_fdset) { +#ifdef CONFIG_MOSIX_DFSA + if(current->mosix.dflags & DREMOTE) + error = -EDOITATHOME; + else +#endif /* CONFIG_MOSIX_DFSA */ error = expand_fdset(files, fd); if (!error) { error = -EMFILE; @@ -747,6 +909,11 @@ * Check whether we need to expand the fd array. */ if (fd >= files->max_fds) { +#ifdef CONFIG_MOSIX_DFSA + if(current->mosix.dflags & DREMOTE) + error = -EDOITATHOME; + else +#endif /* CONFIG_MOSIX_DFSA */ error = expand_fd_array(files, fd); if (!error) { error = -EMFILE; @@ -785,10 +952,46 @@ if (!IS_ERR(tmp)) { fd = get_unused_fd(); if (fd >= 0) { +#ifdef CONFIG_MOSIX_DFSA + struct file * f; + mode_t imode; + + current->mosix.dirty_bits |= FILP_OPEN_SYSCALL; + f = filp_open(tmp, flags, mode); + current->mosix.dirty_bits &= ~FILP_OPEN_SYSCALL; +#else struct file *f = filp_open(tmp, flags, mode); +#endif /* CONFIG_MOSIX_DFSA */ error = PTR_ERR(f); if (IS_ERR(f)) goto out_error; +#ifdef CONFIG_MOSIX_DF