Commit Graph

253 Commits

Author SHA1 Message Date
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
Giacomo Tesio ac9969dadd libposix: fix signals when no realtime signal is supported 2017-05-26 00:27:48 +02:00
Giacomo Tesio abfc6958d6 libposix: build again 2017-05-25 22:42:20 +02:00
Giacomo Tesio a59b992ed4 libposix: more code for signals 2017-05-25 01:04:53 +02:00
Giacomo Tesio 68bc46fe85 libposix: initial changes to POSIX_kill 2017-05-24 00:40:28 +02:00
Giacomo Tesio 3381f75d03 libposix: fix typo 2017-05-24 00:08:00 +02:00
Giacomo Tesio 3307c1e7e2 libposix: drafted Child structure 2017-05-24 00:04:30 +02:00
Giacomo Tesio e0610f6b71 libposix: drafted SIGCHLD management 2017-05-23 00:27:50 +02:00
Giacomo Tesio c27b2aa93b kern: remove unused l64acidt.S 2017-05-22 00:45:03 +02:00
Giacomo Tesio cc595c7c99 kernel: save and restore all registers on syscall 2017-05-21 00:15:51 +02:00
Giacomo Tesio 4b7957a28f kernel: simplify init code 2017-05-20 14:06:26 +02:00
Giacomo Tesio aedc31e925 libstdio: fix uninitialized variables 2017-05-19 01:33:09 +02:00
Giacomo Tesio 3b4af1e4d8 gcc: enable -O2 compilation
To enable -O2 compilation we have to disable some optimizations:

- strict-aliasing (TODO: introduce required unions to enable this)
- aggressive-loop-optimizations
- array-bounds

Affected builds are

- sys/src/cmd/dossrv/build.json
- sys/src/cmd/ip/build.json
- sys/src/lib/authsrv/build.json
- sys/src/lib/memdraw/build.json
2017-05-19 01:15:34 +02:00
Giacomo Tesio 901962f6c9 cmds: avoid duplicated compilation of ip tools 2017-05-19 00:54:23 +02:00
Giacomo Tesio 22d90985a5 kernel: awake() wake up only truly blocking syscalls
If a syscall did not entered sleep(), the pendingWakeup is not consumed.
2017-05-17 02:04:08 +02:00
Giacomo Tesio 1dc8991331 kernel: reset and restore up->cursyscall in trap
This way sleep() knows that it should not interrupt the process
to serve awake().

Also rename Proc.insyscall to Proc.inkernel since that's the meaning
of the flag, which is only read to serve awake()'s mechanics and
to accounttime(). Indeed faultAmd64 was setting insyscall to 1.
2017-05-17 01:16:49 +02:00
Giacomo Tesio 2b1baf8de1 kernel: devpipe: fix error management on writes
The "write on closed pipe" note should be posted only
if the write occurred on a closed pipe.

Before this fix, on any interrupt caused the note to be sent,
despite the pipe being open and fully working.
2017-05-17 00:27:57 +02:00
Giacomo Tesio 031201a1ac kernel: reset process wakeups on exec 2017-05-15 00:35:22 +02:00
Giacomo Tesio f9b2e9aba4 kernel: generalize awake
Awake can now interrupt several blocking syscalls (even
during note handling).

Among others, it can interrupt await, pread and pwrite.

It cannot interrupt several others for different reasons:

- awake cannot be interrupted by awake;
- syscalls like remove and create can be used for kernel comunication
  and it would be hard to know if the effect occurred in the
  receiving fs if they were interrupted;
- other syscalls do not need awake since they just provide access
  to kernel infos (eg seek or fd2path)

NOTE: awakes registered before a note cannot occur during the note
handling and will be deferred till the next call to noted.
2017-05-15 00:05:59 +02:00
Giacomo Tesio 79f8204766 kern: move tsemaquire to userspace (given a generalized awake) 2017-05-12 11:13:19 +02:00
Giacomo Tesio 46664994d4 libposix: fix usleep 2017-05-12 11:13:08 +02:00
Giacomo Tesio aa4172a1de libposix: document timers 2017-05-08 23:46:19 +02:00
Giacomo Tesio a3791c88f7 libposix: add usleep 2017-05-08 23:45:46 +02:00
Giacomo Tesio d62ca1162f Merge branch 'libposix-new-signals' of https://bitbucket.org/tesio/jehanne into libposix-new-signals 2017-05-08 22:54:34 +02:00
Giacomo Tesio edc116ef45 libposix: documented new signal machinery 2017-05-08 00:43:35 +02:00
Giacomo Tesio 333d5dcbcd Merge branch 'master' into libposix-new-signals 2017-05-07 19:44:47 +02:00
Giacomo Tesio b08218529d devproc: can't wait for up to stop 2017-05-06 16:03:16 +02:00
Giacomo Tesio 8d5eb5914f libposix: fix default_signal_disposition 2017-05-06 13:33:08 +02:00
Giacomo Tesio da0381a213 libposix: big refactor of signal handling 2017-05-05 19:01:18 +02:00
Giacomo Tesio d29859684b libposix: complete POSIX_signal_execute 2017-05-03 03:02:56 +02:00
Giacomo Tesio bd5063666f libposix: introduce POSIX_signal_execute and PosixSignalDisposition enum 2017-05-03 01:14:53 +02:00
Giacomo Tesio cf974abe0e libposix: (almost working) waitpid 2017-05-02 00:57:18 +02:00
Giacomo Tesio 8c33c921b4 libposix: draft waitpid (still broken) 2017-05-01 23:57:05 +02:00
Giacomo Tesio 14934ee51f libposix: sleep and pipe 2017-04-30 16:49:50 +02:00
Giacomo Tesio 3707eaece6 libposix: simplify kill 2017-04-30 16:49:01 +02:00
Giacomo Tesio ac33157c37 kern: usbehcipc.c fix CID 155940: Out-of-bounds write 2017-04-25 16:07:47 +02:00
Giacomo Tesio 80a8501c05 kern/ip/gre: fix CID 156224: Uninitialized scalar variable 2017-04-25 15:53:20 +02:00
Giacomo Tesio ea6f34f4f7 kern: mark pexit() as noreturn
Since pexit() calls sched() it wont return to the caller.
Should fix

- CID 155655: Missing break in switch
- CID 155672: Missing break in switch
2017-04-24 09:55:45 +02:00
Giacomo Tesio c2204d83a5 libposix: getppid 2017-04-22 00:40:39 +02:00
Giacomo Tesio a1b4085b7b libc: keep __libc_init weak definition private 2017-04-21 23:58:06 +02:00
Giacomo Tesio 4142b70d32 libposix: allow custom translations of exit status 2017-04-21 23:56:43 +02:00
Giacomo Tesio 188a07782d libposix: initial draft 2017-04-19 23:48:54 +02:00
Giacomo Tesio e70feee4a3 libc: introduce "jehanne_" namespace
With this commit all functions declared in libc.h have been renamed
with the "jehanne_" prefix. This is done for several reason:

- it removes conflicts during symbol resolution when linking
  standard C libraries like newlib or musl
- it allows programs depending on a standard C library to directly
  link to a library depending on our non standard libc (eg libsec).

To ease transiction two files are provided:

- sys/include/lib9.h that can be included instead of <libc.h> to use
  the old names (via a simple set of macros)
- sys/src/lib/c/lib9.c that can be compiled with a program where the
  macro provided by lib9.h are too dumb (see for example rc or grep).

In the kernel port/lib.h has been modified accordingly and some of
the functions it directly provides has been renamed too (eg malloc
in qmalloc.c and print in devcons.c).
2017-04-19 23:48:21 +02:00
Giacomo Tesio 7609abaaf3 libauth: fix potential null deref in auth_proxy
Should fix CID 155820
2017-02-08 00:07:01 +01:00
Giacomo Tesio 1f59502bf5 kernel/boot: #ec/console (from kernel args) defines the console to start 2017-02-04 01:04:51 +01:00
Giacomo Tesio 19bf511603 kernel: devdup: fix dup(n, 0)
Completes e1a14b49be
2017-01-24 22:24:55 +01:00
Giacomo Tesio edd84db070 kernel: import 9front's PCI improvements 2017-01-24 22:24:43 +01:00
Giacomo Tesio c2b06ebf80 kernel: fix out of bound read in trap()
Reported by coverity, CID 155927: if vno == 32 it would access index
32 of excname at trap.c:339.
2017-01-24 22:24:20 +01:00
Giacomo Tesio 6dd0f2e130 kernel: use pprint instead of print in elf64ldseg.
Should also fix CID 156242, CID 156240 and CID 156236 avoiding
access to uninitialized pointers (get64, get32 and get16).
2017-01-24 22:23:17 +01:00
Giacomo Tesio db8aab1a04 kernel: boot: fix more dup() leaks reported by coverity 2017-01-24 22:22:58 +01:00
Giacomo Tesio aa25654232 libsec: improve fix #4: check valid length in TLS (msgRecv)
This commit should complete the work done at 90fe80e73b

Should also fix CID 155874.
2017-01-24 22:22:20 +01:00
Giacomo Tesio 65cdad4317 libc: rewrite putenv and getenv.
These new implementations

- do several validity check on input parameters
- allow a bit larger variable names (127 bytes, aka sizeof(Proc.genbuf)-1)
- preserve nulls in the content (the original version used to replace
  '\0' with ' '). I can't see why they did, actually.
  See also http://marc.info/?l=9fans&m=148475801229908&w=2

Should also fix CID 155718
2017-01-19 00:58:43 +01:00
Giacomo Tesio d43be3861b libc: fix potential nil dereference in system() posix wrapper
Should also fix CID 155750.
2017-01-18 23:36:18 +01:00
Giacomo Tesio b05c21397e libc: rewrite brk() and sbrk()
Also fix Coverity 1 scan defects, CID 155773 and CID 155768, removing
less-than-zero comparisons of unsigned values that were never true.
2017-01-18 23:35:41 +01:00
Giacomo Tesio 6e816b293d libmp: fix #6: mptole takes `p` xor `pp`
See commit 0f82a2c3c3 for further info

Also fix build after typo.
2017-01-18 01:59:44 +01:00
Giacomo Tesio 0f82a2c3c3 libmp: fix #5: mptole takes `p` xor `pp`
According to http://man.cat-v.org/9front/2/mp mptole either take p or pp:

> Mptobe and mptole convert an mpint to a byte array.  The
> former creates a big endian representation, the latter a
> little endian one.  If the destination buf is not nil, it
> specifies the buffer of length blen for the result.  If the
> representation is less than blen bytes, the rest of the
> buffer is zero filled.  **If buf is nil**, then a buffer is
> allocated and a pointer to it is deposited in the location
> pointed to by **bufp**. Sign is ignored in these conversions,
> i.e., the byte array version is always positive.

Assert accordingly.
2017-01-18 01:47:31 +01:00
Giacomo Tesio 90fe80e73b libsec: fix #4: Finished.n can only be 0, 12 or 36
As noted ty Cinap Lenrek Finished.n is only set by setVersion and can only
be either 0 before setVersion() as emalloc() zeros the TlsConnection struct
or SSL3FinishedLen/TLSFinishedLen after when we got the client/server hello.

Introducing FinishedLength enum we make the domain of the field explicit.
2017-01-18 00:24:10 +01:00
Giacomo Tesio 49040ffdaa kernel: boot: fix dup() leaks reported by coverity 2017-01-17 22:01:15 +01:00
Giacomo Tesio e1a14b49be kernel: devdup: fix dup(n, 0)
A successful dup(n, 0) must not return -1L
2017-01-17 21:48:33 +01:00
Giacomo Tesio 207967f9e8 libc: _assert do not return. should fix build 2017-01-17 21:28:56 +01:00
Giacomo Tesio 04962f0637 libsec: fix #3: out-of-bound access in aesXCBCmac (CID 155914) 2017-01-17 21:05:59 +01:00
Giacomo Tesio 90f3d2ce31 lib9p2000: cleanup redundant checks in convM2S
CID 49221 (#1 of 1): Identical code for different branches (IDENTICAL_BRANCHES)
identical_branches: The same code is executed when the condition p == NULL is true or false, because the code in the if-then branch and after the if statement is identical. Should the if statement be removed?
2017-01-17 21:05:15 +01:00
Giacomo Tesio 663b002529 libsec: mark DigestState as stack var in ccpoly_*
CID 160099 and CID 160100 (#1 of 1): Free of address-of expression (BAD_FREE)
address_free: ccpolylen frees address of ds
2017-01-17 21:04:15 +01:00
Giacomo Tesio 3cfe366cc0 libsec: fix out of bound write (CID 155904)
In aesXCBCmac fix (potential) out of bound write in padding.

CID 155904 (#1 of 1): Out-of-bounds write (OVERRUN)
7. overrun-local: Overrunning array of 16 bytes at byte offset 16 by dereferencing pointer p2++.
2017-01-17 21:03:32 +01:00
Giacomo Tesio 6daa49324a kernel: umem: fix frees in segments_fill
CID 155453 (#1 of 1): Free of address-of expression (BAD_FREE)
address_free: free frees address of (segments + 0).pages.
2017-01-17 00:26:23 +01:00
Giacomo Tesio 20f15cbe5a kernel: fix not null terminated string in options()
CID 155471 (#1 of 1): Buffer not null terminated (BUFFER_SIZE_WARNING)67.
buffer_size_warning: Calling strncpy with a maximum size argument of 256 bytes on destination array envcopy of size 256 bytes might leave the destination string unterminated.
2017-01-17 00:18:18 +01:00
Giacomo Tesio 41a9489dd4 libsec: fix des56to64 access to key array
CID 155910 (#1 of 1): Out-of-bounds access (OVERRUN)1.

overrun-buffer-val: Overrunning buffer pointed to by key of 7 bytes by passing it to a function which accesses it at byte offset 63.
2017-01-17 00:01:08 +01:00
Giacomo Tesio e2b5953d99 libc: handle positive fd on "always-failing" creates (brk and dup) 2017-01-16 23:53:05 +01:00
Giacomo Tesio 042e206d13 kernel: devrtc: fix use of uninitialized array in rtcextract
CID 156229: Uninitialized scalar variable (UNINIT)9.
uninit_use: Using uninitialized value bcdclock[0].
2017-01-16 02:00:10 +01:00
Giacomo Tesio 237b7709ae kernel: umem: fix use of uninitialized fptr in freelist_pop
CID 156230 (#1 of 1): Uninitialized pointer read (UNINIT)9.
uninit_use: Using uninitialized value fptr.
2017-01-15 01:59:41 +01:00
Giacomo Tesio 1cb4610ed2 kernel: udp: fix read of uninitialized array
CID 156231 (#1 of 1): Uninitialized scalar variable (UNINIT)6.
uninit_use_in_call: Using uninitialized element of array laddr when calling memcmp.
2017-01-15 01:35:28 +01:00
Giacomo Tesio f2f95a935f kernel: fix use of uninitialized value in freelist_pop
CID 156233 (#1 of 1): Uninitialized pointer read (UNINIT)5. uninit_use: Using uninitialized value fimg.
2017-01-15 01:03:35 +01:00
Giacomo Tesio c4fb99ec38 qa: fix a few issues detected by coverity 2017-01-14 17:58:33 +01:00
Giacomo Tesio 0de2dfc95b kernel: fix /dev/swap and `stats -m` 2017-01-12 00:41:14 +01:00
Giacomo Tesio d1cc947cd9 kernel: fix fd mode print in devproc 2017-01-12 00:39:50 +01:00
Giacomo Tesio e93aafc028 qa: build everything with -Werror 2017-01-12 00:38:56 +01:00
Giacomo Tesio 51d12f1f34 kernel: fix #0/brk/ qid (it's a special directory, not a special file) 2017-01-09 00:44:01 +01:00
Giacomo Tesio a8e2247e20 kernel: drop SysNsec references from syscall() 2017-01-06 01:40:04 +01:00
Giacomo Tesio 4676c65a3d kernel: move nsec to libc 2017-01-06 00:56:22 +01:00
Giacomo Tesio 2508de40ea kernel: move sysdup to libc 2017-01-06 00:56:22 +01:00
Giacomo Tesio c342234d74 kernel: print faults to process standard error 2017-01-06 00:54:04 +01:00
Giacomo Tesio e8562ff537 cmd/pict: import 9front's graphical tools 2017-01-03 22:31:09 +01:00
Giacomo Tesio 890f126abc kernel: fix usb after changing OREAD/OWRITE values
OREAD and OWRITE are used as array indexes assuming that OREAD was zero
and OWRITE was one. Thus each related allocation reserved just 2 slot and
even Ep struct in usb.h reserved just 2 int for toggles.

Since OREAD is now 1 and OWRITE is 2 we have to allocate/reserve 3 slot
as long as we use them as array indexes (which we could change in the future).

Unfortunately this means we waste the index zero in those arrays that will
always be unused. This also means that, to loop in such arrays we must begin
with OREAD as index zero is always empty.

PRO-MEMORIA: if/when we introduce the walk() syscall, OSTAT might turn useless.
In that case we might remove it and thus consider to move back OREAD/OWRITE
to 0/1 respectively (which might or might not be a good idea, to be analyzed).
2017-01-03 01:27:08 +01:00
Giacomo Tesio c1eb65b35e kernel: move null and zero from #c to #0 2017-01-03 01:27:08 +01:00
Giacomo Tesio 8e7f47c743 kernel/boot: bind #0 wherever #c is bound 2017-01-03 01:27:08 +01:00
Giacomo Tesio ac15346de7 kernel: make #0/pid, #0/ppid and #0/pgrpid readable 2017-01-03 01:27:07 +01:00
Giacomo Tesio da77086023 mount: update dev9p name (#9 instead of #M) 2016-12-31 17:19:40 +01:00
Giacomo Tesio 37541724d0 kernel: add #0/brk and move brk_() to libc 2016-12-31 00:43:02 +01:00
Giacomo Tesio 0bbd79e0a5 kernel: waitdebugger on lapictimerset if apic->div == 0 2016-12-26 02:18:19 +01:00
Giacomo Tesio 71ea62eb5b rm -e prints the return value of remove syscalls
Some devices return useful info on specific file remove (eg #0/pid, #0/ppid...)
so we need a tool to get such info.

	rm -e '#0/pid' '#0/ppid'
	#0/pid 65
	#0/ppid 59
2016-12-26 02:18:19 +01:00
Giacomo Tesio 31aa85b01a kernel: move pgrpid to devself 2016-12-26 02:18:19 +01:00
Giacomo Tesio 66373243bd libc: rewrite access() 2016-12-26 02:18:06 +01:00
Giacomo Tesio b862596737 kernel&all: create() syscall only sends Tcreate
In Plan9 the create syscall fallback on a open(OTRUNC) if the
path provided already exists. This is actually a common requirement
as most programs (editors, cat...) simply requires that a file is
there and is empty, and doesn't care overwriting existing contents
(note that this is particularily sensible with something like fossil).

In Jehanne the application is responsible of actually handle this
"file exists" error but libc provides ocreate() to mimic the Plan9
behaviour. Note that ocreate introduce a subtle race too: the path
is walked several times if the file exists, thus it could misbehave
on concurrent namespace changes. However I guess this is not going to
happen often enough to care now.

NOTE we will probably address this rare race too, with a more drammatic change
to syscalls: a new walk() syscall that will provide an unopen fd.
2016-12-24 21:25:20 +01:00
Giacomo Tesio c30fb72b82 kernel: allow negative lengths in pwrite 2016-12-24 21:24:49 +01:00
Giacomo Tesio ca05868e4d kernel: use #9 instead of #M in /proc/n/ns 2016-12-24 21:24:28 +01:00
Giacomo Tesio 99855d60d6 kernel: move chdir to libc using devself/devproc
Added wdir to devself and devproc:

- read '#0/wdir' to get the working directory of the calling process
  NOTE that a read(fd, nil, -1) will return the negated length
  of the working directory, just in case you want to
  allocate the memory required

- read '/proc/n/wdir' to know the working directory of process n
  (read(fd, nil, -1) still returns the negated length)

- write '#0/wdir' to change the working directory of the calling process
  NOTE: no offset is allowed and the provided string must
  be null terminated

- write '/proc/n/wdir' to change the working directory of process n
  NOTE: no offset is allowed and the provided string must
  be null terminated; moreover if another process change the working
  directory change during the write, the current process will
  receive an error.

In libc updated getwd() and chdir().
Also modified pwd to get advantage of the new file.

To test, run /arch/amd64/qa/kern/wdir.rc or simply try

	% pwd
	/usr/glenda
	% echo -n /tmp > /proc/$pid/wdir
        % pwd
        /tmp
        % cat '#0/wdir' && echo
        /tmp

The expected use cases for wdir in devproc are rio and acme.

Also, note that we could theoretically remove the cd builtin
from rc and simply implement it as a rc function.
We don't do that to preserve rc portability to other OS.
2016-12-15 22:42:01 +01:00
Giacomo Tesio c6de6b66e9 kernel: introduce devself
Devself provides to each process access to its own structures.

So far it contains four files:

- pid
- ppid
- pipes	used to implement pipe(2)
- segments used to implement segattach, segdetach and segfree
2016-12-11 01:26:08 +01:00
Giacomo Tesio f52a185030 decouple Jehanne from 9P2000 (as much as needed)
Jehanne is going to use a new file protocol, but Plan 9 is really
coupled with 9P2000.

Renamed fcall.h as 9P2000.h and introduced specific constants such
as NP_OREAD, NP_OWRITE and so on, so that we can use different values
in the kernel and new protocol.

Renamed devmnt to devninep, since it's actually a device serving 9P2000
file systems.

Also, fixed 9P2000 support in Jehanne, that was broken with the introduction
of OSTAT.
2016-12-06 23:01:45 +01:00
Giacomo Tesio bbb375a585 kernel: return long from file related syscalls 2016-11-30 20:18:45 +01:00
Giacomo Tesio a9745e02c5 kernel: in Proc defined syscallerr to hold the return value of failing syscalls 2016-11-30 01:07:45 +01:00
Giacomo Tesio 488106eaac cmd/ms: read #P/ps2mouse in a char (not in an int)
After the removal of dumb push in crt0 (commit 929014ebca5c738d3854758326de7abfb77c1ef1)
the first byte of the c integer is not zeroed anymore (which is correct).

But since ms.c reads and bit-match a single byte in c, when it's an int some test success/fail
due to the state of the unused bytes.

This makes the mouse turn crazy.

So we turn it into a char, so that bitmasks and tests work as expected.
2016-11-29 20:42:24 +01:00