Commit Graph

253 Commits

Author SHA1 Message Date
Giacomo Tesio a3918b108d kern: awake must not interrupt flushes in dev9p
While sending Tflush after a wakeup, we might call sleep.

Since the awake was not yet consumed, the new sleep was interrupted
causing a new Tflush, in an infinite loop that consumes all tags.
2017-12-15 02:58:09 +01:00
Giacomo Tesio 799f99a40f kern: fix pprint on invalid address at syspread 2017-12-15 02:58:09 +01:00
Giacomo Tesio b73c2bce14 kern: awake & dev9p: do not interrupt Tflush to avoid consuming all tags 2017-12-15 02:58:09 +01:00
Giacomo Tesio 3946a06a98 kern: dev9p: Rwrite's count can be greater than Twrite's one 2017-12-15 02:58:09 +01:00
Giacomo Tesio 726217c766 kern: fix proc ref counting in procread 2017-12-15 02:58:09 +01:00
Giacomo Tesio df9c0d8fe4 kern: awake: fix syscall() check for awake_awakened(up) 2017-12-15 02:58:09 +01:00
Giacomo Tesio 2b62ed8010 kern: keep reading /proc/n/syscall after process death, to get all messages 2017-12-15 02:58:09 +01:00
Giacomo Tesio 9aea97a51f kern: fix fmtrwdata on nil buffers 2017-12-15 02:58:09 +01:00
Giacomo Tesio 8ea71b1c66 kern: fix very old bug in syscall tracing 2017-12-15 02:58:09 +01:00
Giacomo Tesio 7ae04d282f kern: devproc: add ppid; enable `rm -e noteid` 2017-12-15 02:56:57 +01:00
Giacomo Tesio 26bd1d8dc4 kern: fix working dir after ns clone
After sending the "clone" request to /proc/$pid/ns, the current process
will be moved to the working directory of $pid.

Otherwise the current process could still access the file and folders
on the service providing its dot, even if such service was not visible to $pid.

Also, keeping the original working directory means that the 'cd' line of the
current process's ns file would be different from that of $pid: the two ns
files must match since the command asked for a "clone".

See also https://marc.info/?l=9fans&m=150893734909969&w=2
2017-10-25 02:06:29 +02:00
Giacomo Tesio 2836ae4d66 kern: improve procfdprint and procfds in devproc 2017-10-25 01:35:34 +02:00
Giacomo Tesio c17d5bdb18 kern: cleanup procread for Qnote 2017-10-25 01:33:51 +02:00
Giacomo Tesio 70d5961022 kern: add missing poperror() to awake_gc_proc 2017-10-25 01:30:07 +02:00
Giacomo Tesio 430df16543 kernel: ignore errors on awake_gc_proc
Calling resrcwait in awake_gc_proc (that is called from pexit and thus
from sys_exits) means that we have to ignore errors that could cause
the syscall to return.

The funny part here was that one single test for newlib showed the
issue by faulting in a note handler AFTER completing with success:

	/arch/amd64/qa/lib/newlib/sigchld/213-sigqueue

The fact was that in the executable, the function notifier() was
located just after the exits() function, whose last line was a call
to _exits().

Thus, when the _exits returned, the notifier() code was executed.
2017-10-25 01:22:01 +02:00
Giacomo Tesio 7c017f5059 kern: fix %r13 management in syscallentry 2017-10-25 01:18:57 +02:00
Giacomo Tesio 90c3415176 kernel: fix _procfdprint to use chan's flags 2017-10-25 01:17:31 +02:00
Giacomo Tesio ba11888753 kern: proc, dup: _procfdprint OCEXEC and ORCLOSE
In _procfdprint print additional informations in the second column:

	E is printed if the file was open with OCEXEC flag
	D is printed if the file was open with ORCLOSE flag

Example output:
  3  rE  9   46 (0000000000000001 0 00)  8192       13 /dev/cons
2017-10-25 01:16:45 +02:00
Giacomo Tesio 9f8050aa4a libc: move exits to its own translation unit (another good idea from 9front) 2017-10-25 01:11:34 +02:00
Giacomo Tesio 2a4b3f26d6 cmds: add ns/clone
usage: ns/clone pid cmd [args...]

It starts cmd with provided arguments in a clone of the namespace
available to pid.
2017-10-25 01:02:32 +02:00
Giacomo Tesio 9d04fba8f2 cmds: rename `ns` to `ns/cat` 2017-10-25 00:22:26 +02:00
Giacomo Tesio 320e6e6f35 kern: clone $pid's namespace writing #p/$pid/ns
Any process X can get a new copy of the namespace of a target
process Y by writing the string "clone" to the ns file of Y.

The same user must own both processes.
The process writing the ns file must be allowed to mount.

The Pgrp of the calling process is then replaced with a new copy of
the Pgrp of the target process.

After the operation, any change done by X to its own namespace does
not affect Y. Also, if mount was forbidden for Y, it will also be
forbidden for X after the clone.
2017-10-24 23:28:14 +02:00
Giacomo Tesio 9202b04504 rc: use some uppercase variables (PATH, USER...) 2017-10-22 13:22:37 +02:00
Giacomo Tesio fab9c1d80f libc: introduce <envvars.h>
The new header envvars.h contains the names of commonly used
environment variables, such as $user, $ifs, $path and so on.

These defines are useful for Jehanne core applications that
use them to comunicate some values.

They are not strictly required, but having such defines we
can easily change the naming convention (from lowercase to uppercase).
2017-10-20 01:22:48 +02:00
Giacomo Tesio 65d37f432f rc: rename $cflag in $rccmd 2017-10-20 00:14:43 +02:00
Giacomo Tesio 9b0b9794c3 rc: write ENV_PATH and ENV_CDPATH as a colon separated string 2017-10-19 00:25:34 +02:00
Giacomo Tesio a5c14e60d7 rc: replace forgotten ENV_RCARGLIST 2017-10-19 00:16:19 +02:00
Giacomo Tesio d33221de34 rc: allow colons as separator in $path and $cdpath 2017-10-18 23:48:42 +02:00
Giacomo Tesio 0ef55939e8 rc: rm plan9.c (fix previous commit) 2017-10-18 22:41:31 +02:00
Giacomo Tesio 4017b73ab2 rc: define constants for rc variable names 2017-10-18 22:38:30 +02:00
Giacomo Tesio b42f8bd4a8 rc: mv plan9.c jehanne.c 2017-10-18 01:20:52 +02:00
Giacomo Tesio 085f5dfa34 rc: import 9front's improvements 2017-10-18 01:10:06 +02:00
Giacomo Tesio 26a2f0a1be libposix: fix typos in get_noteid/set_noteid 2017-09-08 00:24:37 +02:00
Giacomo Tesio e206015f7f libposix: add getpgid 2017-09-07 23:27:33 +02:00
Giacomo Tesio 1f3203e6d3 libposix: add rename 2017-09-07 23:25:34 +02:00
Giacomo Tesio e3ff5b1004 libposix: add getpgrp; draft setsid, getsid and setpgid 2017-09-07 00:10:34 +02:00
Giacomo Tesio e168dcb7fa libposix: add umask 2017-09-06 22:59:05 +02:00
Giacomo Tesio 61f0293e39 libposix: fake get/set functions for uid, gid, euid, egid, pgid, sid, reuid... 2017-09-05 23:53:40 +02:00
Giacomo Tesio 4be2181f89 libposix: add readlink and readlinkat (both failing with EINVAL) 2017-09-03 23:46:18 +02:00
Giacomo Tesio c5aaa72bbb libposix: add dup, dup2, getrusage, fstat and lstat 2017-09-03 17:51:44 +02:00
Giacomo Tesio 4115f92ff6 libc: make times return -1 on io error 2017-09-03 17:43:02 +02:00
Giacomo Tesio 0bc2e60c72 libposix: stub chown family (always returning 0)
I do not expect chown, fchownat and lchown to be much used in
UNIX softwares that we care to port.

We stub the functions in libposix so that we can refer them from
standard C libaries (such as newlib).

We will implement them (parsing /cfg/users to determinate uid and gid)
when it will be actually needed from a software ported to Jehanne.
2017-08-31 00:50:31 +02:00
Giacomo Tesio 3e533d234a cmds: port vt from 9front 2017-08-30 23:07:07 +02:00
Giacomo Tesio 713eb8843f libc: simplify access; libposix: let access lie
There are a few issues with Plan 9's `access`:

- it has side effects: to test the actual access (that the file
  servers can allow or deny according to complex custom rules)
  it opens and then closes the file, allocating (and disposing) the fd
- it does not work on directories, since
  - they cannot be opened for writing, despite the fact that to
    create a file in a directory you must be granted write access on
    that directory
  - they cannot be opened for execution, despite the fact that to
    access a file in a directory you must be granted execution access
    on that directory

Despite the fact that `access` (even on UNIX) is a violation of the
"tell, don't ask" principle (the access could be forbidden just after
its successful return, making subsequent `open` fail anyway), this
fact smells of a little design error in the file interface.

So, right now we choose to let the libposix's `access` lie on directories:
it will always return 0 on AWRITE and AEXEC for them, accepting that
a successive create/mkdir may fail.

However, a cleaner file API and protocol should allow a simpler `access`
to be implemented for directories too.
2017-08-29 00:17:51 +02:00
Giacomo Tesio 56287a4337 libc: better access on directories 2017-08-28 23:04:32 +02:00
Giacomo Tesio 59e881c04d libc: improve access(AWRITE) and access(AEXEC) on directories 2017-08-28 23:04:30 +02:00
Giacomo Tesio b78613615d libposix: add access 2017-08-28 23:04:12 +02:00
Giacomo Tesio 386cb370a6 libposix: POSIX_gettimeofday fails without proper initialization 2017-08-25 23:43:14 +02:00
Giacomo Tesio bd149a18f1 libposix: implement gettimeofday 2017-08-25 00:53:10 +02:00
Giacomo Tesio bfb95a3d3e libposix: drafted chdir, fchdir and mkdir 2017-08-23 04:05:31 +02:00
Giacomo Tesio 4de95c9bc0 libposix: make AT_FDCWD value configurable 2017-08-23 02:57:41 +02:00
Giacomo Tesio 4455658796 libposix: drafted chmod/fchmod; TODO: configurable AT_FDCWD 2017-08-23 01:05:54 +02:00
Giacomo Tesio 6a94e587a6 libposix: fix POSIX_open's DMDIR management; fix typo in POSIX_chmod 2017-08-22 22:42:38 +02:00
Giacomo Tesio 965d316ac4 libposix: return PosixENOTDIR according to O_DIRECTORY specification 2017-08-22 02:34:00 +02:00
Giacomo Tesio 9947978c05 libposix: implemented libposix_getdents 2017-08-22 01:42:33 +02:00
Giacomo Tesio 63b227be55 elf64ldseg: do not pprint warnings on wrong header as it could simply be an rc script 2017-08-21 23:59:40 +02:00
Giacomo Tesio f7c3a41b11 libposix: drafted getdents 2017-08-21 01:05:40 +02:00
Giacomo Tesio 3916b222b5 libposix: fix typo 2017-08-21 00:52:57 +02:00
Giacomo Tesio ea6b68588c libposix: implemented getcwd, getlogin, getlogin_r, getpass, pread and pwrite 2017-08-21 00:20:12 +02:00
Giacomo Tesio 6dd00801dc libposix: introduce pause() (still to be integrated in newlib) 2017-08-18 00:50:07 +02:00
Giacomo Tesio 6ce619a2e0 libc: sleep's argument must be unsigned 2017-08-16 00:58:21 +02:00
Giacomo Tesio b9483decb0 libmemdraw: fix typo 2017-08-15 12:10:52 +02:00
Giacomo Tesio e0e45fba5a kernel: removed unreachable code in fault (CID: 155701)
If the user process does not have a segment holding the required addr
the fault function return early.
2017-08-15 01:07:48 +02:00
Giacomo Tesio 55a8a84d8d kernel: fix potential overflow in updatecpu (CID 155825) 2017-08-15 00:54:15 +02:00
Giacomo Tesio 0b8a66f877 kernel: umem: fix img_get macro
The img_get macro used to subtract 1 to the argument provided before
computing the porinter to the image. I can't remember why it did so.

However the expression was wrong.

Coverity found the issue:

	Operands don't affect result (CONSTANT_EXPRESSION_RESULT)
	CID:	155616, 155606, 155598, 155597, 155596, 155587,
		155580, 155578, 155577, 155576, 155568, 155566

Simply removing the subtraction seems the obvious fix.
2017-08-15 00:38:09 +02:00
Giacomo Tesio b056df2da6 kernel: simplify sysnotify; should fix CID 156151 (Wrong sizeof argument) 2017-08-14 19:52:22 +02:00
Giacomo Tesio 17c9087965 kernel: fix typo in sysexec (CID 156141) 2017-08-14 19:34:34 +02:00
Giacomo Tesio 180da90a06 kernel: fix args crossing page boundaries in sysexec
Should also fix CID 155615 (Operands don't affect result)
2017-08-14 19:25:54 +02:00
Giacomo Tesio 21b5682a43 kernel: syspread: avoid negative offsets in dir reads
Should also fix CID 160109: Dereference after null check
2017-08-14 18:40:25 +02:00
Giacomo Tesio da588d69ec kernel: fpprocfork: fix CID 174315 (Missing break in switch) 2017-08-14 15:22:51 +02:00
Giacomo Tesio 8464d1a277 libmemdraw: fix CID 154389 (uninitialized variable) 2017-08-14 13:00:30 +02:00
Giacomo Tesio 93c784fa3f libstdio: fix CID 174305 and CID 174302 (uninitialized variables) 2017-08-14 12:47:03 +02:00
Giacomo Tesio 033744b5be kernel: awake: fix CID 174310: Out-of-bounds read 2017-08-13 21:59:03 +02:00
Giacomo Tesio 5f22403176 libstdio: fix uninitialized variable CID 174334 2017-08-13 21:50:44 +02:00
Giacomo Tesio 34e6b0adc2 kernel: boot: use "bootconsole" instead of "console" env var 2017-08-13 15:24:18 +02:00
Giacomo Tesio c5466152f1 Revert "Revert "kernel: import sdahci from 9front""
This reverts commit ecc2125b28.
2017-08-13 12:47:56 +02:00
Giacomo Tesio 93dfad6b0b kernel: print proc info on addbroken 2017-08-12 23:32:35 +02:00
Giacomo Tesio ecc2125b28 Revert "kernel: import sdahci from 9front"
This reverts commit d9975caeb0.
2017-08-12 15:18:02 +02:00
Giacomo Tesio aef20dca20 kernel: fix.c: fix inverted CHS bit 2017-08-11 06:12:44 +02:00
Giacomo Tesio 330b7cc217 awk: don't get into a infinite loop with eof while in string (thanks BurnZeZ) 2017-08-11 05:51:10 +02:00
Giacomo Tesio d9975caeb0 kernel: import sdahci from 9front 2017-08-11 05:26:53 +02:00
Giacomo Tesio c08d07bcde libc: fix libthread by fixing RENDEZVOUS in qlock.c 2017-08-11 05:26:53 +02:00
Giacomo Tesio 6d242b3aa0 hjfs: import improvements from 9front 2017-08-11 05:09:34 +02:00
Giacomo Tesio fa0a121f17 cmds.json: remove mc.c 2017-08-11 04:19:59 +02:00
Giacomo Tesio 34950f084e cmds: remove old ms tool 2017-08-11 03:18:32 +02:00
Giacomo Tesio a0f7e71d41 rc: do not mess up argv 2017-08-11 03:18:32 +02:00
Giacomo Tesio 93dde48355 kernel: deep refactoring and cleanup
This large commit address several issues
- removed 386 directory: Jehanne is 64bit only
- simplified kernel options management
- rewritten boot process
- ported memory related stuff from 9front's 9/pc64
- removed devacpi
- removed old code
- deep refactor of awake syscall
- removed MCACHE support for mount
- fix libc's setjmp/longjmp
2017-08-11 03:18:32 +02:00
Giacomo Tesio 1bc08b7631 kernel: rendezvous(~0, ...) unconditionally blocks
This commit introduce a special rendezvous point at (void*)~0 that
cannot be reached by any process, since it's not added to the
rendezvous group.

This turns the rendezvous syscall to a cheap way to block until
either a note or a wakeup from awake(2) occurs.

This new feature is used in libc's sleep: the test qa/kern/fork_chain
has shown that using a stack address as rendezvous point is not safe enougth
for sleep, since two different process forked from the same function can
call sleep with the same base pointer. This lead the wakeup variable in
jehanne_sleep to have the same address on both process.

TODO add a test that show this behaviour in the old code.
2017-07-21 01:49:00 +02:00
Giacomo Tesio c13d386ab5 libaml: import 9front's improvements 2017-07-21 01:34:34 +02:00
Giacomo Tesio 83e3161789 kernel: fix ancient bug in GDT initialization 2017-06-08 04:03:32 +02:00
Giacomo Tesio 4f97f4a80b qa: disable broken tests 2017-06-05 22:11:36 +02:00
Giacomo Tesio 87de13f1e0 kernel: mmuptpcheck: use less global memory 2017-05-31 01:10:18 +02:00
Giacomo Tesio 7108477c32 kernel: simplify mmuput 2017-05-30 22:41:44 +02:00
Giacomo Tesio 28c426055d libposix: fix disposition for signals that are ignored by default 2017-05-30 01:15:25 +02:00
Giacomo Tesio 6bd285bdaa libposix: fix SIGCLD disposition; use PosixSIGCHLD to identify the signal when SIGCHLD == SIGCLD 2017-05-30 00:49:28 +02:00
Giacomo Tesio c45cffeaf5 cmd: fix ancient bug on consolefs flush 2017-05-30 00:11:34 +02:00
Giacomo Tesio e525113266 libposix: cleanups 2017-05-29 23:27:30 +02:00
Giacomo Tesio d1e285f721 libposix: honor SIG_IGN by doing nothing (DRAFT) 2017-05-29 02:04:48 +02:00
Giacomo Tesio f6d44667f2 libposix: fix bind #p and POSIX_kill sigrtmin/sigrtmax usage 2017-05-29 01:11:07 +02:00
Giacomo Tesio 40ccb89835 libc: simplify Waitmsg 2017-05-26 01:55:09 +02:00