Commit Graph

1598 Commits

Author SHA1 Message Date
kamil 7dea4f94d7 Read TLS base pointer with _lwp_getprivate()
This avoid usage of fast versions that are mostly internal to RTLD.
2019-12-25 02:23:37 +00:00
kamil bd290c46da Define _RTLD_SOURCE in t_ptrace_wait.c
The __lwp_gettcb_fast() and __lwp_getprivate_fast() functions are
namespaced on a selection of ports.
2019-12-24 21:09:38 +00:00
kamil 4f79a48470 Introduce PT_LWPSTATUS + PT_LWPNEXT, obsolete PT_LWPINFO
PT_LWPINFO is a legacy ptrace(2) operation that was originally intended
to retrieve the thread (LWP) information inside a traced process.

It has a number of flaws and is confused with PT_LWPINFO from FreeBSD.

PT_LWPSTATUS and PT_LWPNEXT address the problems (shortly by: rename,
removal of pl_event) and introduces new features: signal context
(pl_sigpend, pl_sigmask), LWP name (pl_name), LWP TLS base address
(pl_private). The private pointer was so far missing information for
a debugger.

PT_LWPSTATUS@nnn is now shipped with core(5) files and contain LWP specific
information, so far missed in the core(5) files.

PT_LWPSTATUS retrieves LWP information for the prompted thread.
PT_LWPNEXT retrieves LWP information for the next thread, borrowing the
semantics from NetBSD specific PT_LWPINFO.

PT_LWPINFO is namespaced with __LEGACY_PT_LWPINFO and still available for
the foreseeable future, without plans of removing it.

Add ATF tests for PT_LWPSTATUS + PT_LWPNEXT.

Keep ATF tests for PT_LWPINFO.

Switch GDB to new API.

Proposed on tech-kern@.
2019-12-24 14:50:59 +00:00
macallan 58c590cd7c disable string op warnings for t_strcat
now this builds on macppc with gcc 8.3
from riastradh@
2019-12-19 19:19:28 +00:00
christos ea19b263f1 Adjust tests for 0 hex values printing 0 instead of 0x0 2019-12-08 17:37:16 +00:00
christos 91fabc4486 Fix broken tests in big endian machines. Internally field values are
stored as uint64_t/uintmax_t so printing them with %d on big endian
ends up being 0.
2019-12-06 19:28:11 +00:00
kamil 1b325ed182 Log PID.LWP in t_ptrace_wait* tests for enabled debug
This is useful for multithreaded test scenarios.
2019-12-06 01:09:50 +00:00
maxv 6f40daa312 Several improvements. In particular, reduce CS.limit, because Intel CPUs
perform strict sanity checks, and the previous (too high) limit caused the
VM entry to fail.
2019-11-22 10:26:32 +00:00
kamil 84cacc6757 Rework thread_concurrent_signals and trace_thread_lwpcreate_and_exit
Change the code to remove the LWP id assumptions that broke after
src/sys/kern/kern_lwp.c r. 1.206.

Original code by <mgorny>, tested and tweaked by myself.
2019-11-12 18:18:04 +00:00
joerg ed08d30824 Avoid warnings about tautological left shifts as conditional. 2019-10-28 18:10:22 +00:00
maxv a6418236ed Add the "nvmm" group, and make nvmm_init() public. Sent to tech-kern@ a few
days ago.
2019-10-27 07:08:15 +00:00
maxv e6f32a5866 Three changes in libnvmm:
- Add 'mach' and 'vcpu' backpointers in the nvmm_io and nvmm_mem
   structures.

 - Rename 'nvmm_callbacks' to 'nvmm_assist_callbacks'.

 - Rename and migrate NVMM_MACH_CONF_CALLBACKS to NVMM_VCPU_CONF_CALLBACKS,
   it now becomes per-VCPU.
2019-10-23 12:02:55 +00:00
maxv f9fb7866ce Miscellaneous changes in NVMM, to address several inconsistencies and
issues in the libnvmm API.

 - Rename NVMM_CAPABILITY_VERSION to NVMM_KERN_VERSION, and check it in
   libnvmm. Introduce NVMM_USER_VERSION, for future use.

 - In libnvmm, open "/dev/nvmm" as read-only and with O_CLOEXEC. This is to
   avoid sharing the VMs with the children if the process forks. In the
   NVMM driver, force O_CLOEXEC on open().

 - Rename the following things for consistency:
       nvmm_exit*              -> nvmm_vcpu_exit*
       nvmm_event*             -> nvmm_vcpu_event*
       NVMM_EXIT_*             -> NVMM_VCPU_EXIT_*
       NVMM_EVENT_INTERRUPT_HW -> NVMM_VCPU_EVENT_INTR
       NVMM_EVENT_EXCEPTION    -> NVMM_VCPU_EVENT_EXCP
   Delete NVMM_EVENT_INTERRUPT_SW, unused already.

 - Slightly reorganize the MI/MD definitions, for internal clarity.

 - Split NVMM_VCPU_EXIT_MSR in two: NVMM_VCPU_EXIT_{RD,WR}MSR. Also provide
   separate u.rdmsr and u.wrmsr fields. This is more consistent with the
   other exit reasons.

 - Change the types of several variables:
       event.type                  enum -> u_int
       event.vector                uint64_t -> uint8_t
       exit.u.*msr.msr:            uint64_t -> uint32_t
       exit.u.io.type:             enum -> bool
       exit.u.io.seg:              int -> int8_t
       cap.arch.mxcsr_mask:        uint64_t -> uint32_t
       cap.arch.conf_cpuid_maxops: uint64_t -> uint32_t

 - Delete NVMM_VCPU_EXIT_MWAIT_COND, it is AMD-only and confusing, and we
   already intercept 'monitor' so it is never armed.

 - Introduce vmx_exit_insn() for NVMM-Intel, similar to svm_exit_insn().
   The 'npc' field wasn't getting filled properly during certain VMEXITs.

 - Introduce nvmm_vcpu_configure(). Similar to nvmm_machine_configure(),
   but as its name indicates, the configuration is per-VCPU and not per-VM.
   Migrate and rename NVMM_MACH_CONF_X86_CPUID to NVMM_VCPU_CONF_CPUID.
   This becomes per-VCPU, which makes more sense than per-VM.

 - Extend the NVMM_VCPU_CONF_CPUID conf to allow triggering VMEXITs on
   specific leaves. Until now we could only mask the leaves. An uint32_t
   is added in the structure:
	uint32_t mask:1;
	uint32_t exit:1;
	uint32_t rsvd:30;
   The two first bits select the desired behavior on the leaf. Specifying
   zero on both resets the leaf to the default behavior. The new
   NVMM_VCPU_EXIT_CPUID exit reason is added.
2019-10-23 07:01:11 +00:00
kamil a73248db21 Remove preprocessor switch TEST_LWP_ENABLED in t_ptrace_wait*
LWP tests are now enabled always and confirmed to be stable.
2019-10-21 18:36:08 +00:00
kamil eb8ea5d12d Remove preprocessor switch TEST_VFORK_ENABLED in t_ptrace_wait*
vfork(2) tests are now enabled always and confirmed to be stable.
2019-10-21 18:31:40 +00:00
mgorny 050caffe42 Fix a race condition when handling concurrent LWP signals and add a test
Fix a race condition that caused PT_GET_SIGINFO to return incorrect
information when multiple signals were delivered concurrently
to different LWPs.  Add a regression test that verifies that when 50
threads concurrently use pthread_kill() on themselves, the debugger
receives all signals with correct information.

The kernel uses separate signal queues for each LWP.  However,
the signal context used to implement PT_GET_SIGINFO is stored in 'struct
proc' and therefore common to all LWPs in the process.  Previously,
this member was filled in kpsignal2(), i.e. when the signal was sent.
This meant that if another LWP managed to send another signal
concurrently, the data was overwritten before the process was stopped.

As a result, PT_GET_SIGINFO did not report the correct LWP and signal
(it could even report a different signal than wait()).  This can be
quite reliably reproduced with the number of 20 LWPs, however it can
also occur with 10.

This patch moves setting of signal context to issignal(), just before
the process is actually stopped.  The data is taken from per-LWP
or per-process signal queue.  The added test confirms that the debugger
correctly receives all signals, and PT_GET_SIGINFO reports both correct
LWP and signal number.

Reviewed by kamil.
2019-10-21 17:07:00 +00:00
maxv c496a7b118 Implement XCHG, add associated tests, and add comments to explain. With
this in place the Windows 95 installer completes successfuly.

Part of PR/54611.
2019-10-14 10:39:24 +00:00
christos 85f5895969 add missing initializer 2019-10-14 01:15:32 +00:00
maxv 416eaf02dc Fix incorrect parsing: the R/M field uses a special GPR map when the
address size is 16 bits, regardless of the actual operating mode. With
this special map there can be two registers referenced at once, and
also disp16-only.

Implement this special behavior, and add associated tests. While here
simplify a few things.

With this in place, the Windows 95 installer initializes correctly.

Part of PR/54611.
2019-10-13 17:32:15 +00:00
kamil bec2cbec70 Fix race in t_ptrace_wait* LWP tests
Increment the done variable under a mutex. This variable was updated
non-atomically and sometimes not reaching the expected treshold.
2019-10-13 09:42:15 +00:00
mrg de11d87641 introduce some common variables for use in GCC warning disables:
GCC_NO_FORMAT_TRUNCATION    -Wno-format-truncation (GCC 7/8)
GCC_NO_STRINGOP_TRUNCATION  -Wno-stringop-truncation (GCC 8)
GCC_NO_STRINGOP_OVERFLOW    -Wno-stringop-overflow (GCC 8)
GCC_NO_CAST_FUNCTION_TYPE   -Wno-cast-function-type (GCC 8)

use these to turn off warnings for most GCC-8 complaints.  many
of these are false positives, most of the real bugs are already
commited, or are yet to come.


we plan to introduce versions of (some?) of these that use the
"-Wno-error=" form, which still displays the warnings but does
not make it an error, and all of the above will be re-considered
as either being "fix me" (warning still displayed) or "warning
is wrong."
2019-10-13 07:28:04 +00:00
kamil 1f5d3e8c5d Enable TEST_LWP_ENABLED in t_ptrace_wait*
The LWP events (created, exited) are now reliable in my local tests.

PR kern/51420
PR kern/51995
2019-10-13 04:05:39 +00:00
kamil 5a3fb2eb52 Bump the number of threads in LWP t_ptrace_wait*() tests from to 100
This is a torture, but on purpose to catch LWP_CREATED and LWP_EXITED bugs.
The threads do nothing other than calling sched_yield() in a loop.

MAXLWP is now defined to 2048 on all ports.

This change effects the following tests:

 - trace_thread_nolwpevents
 - trace_thread_lwpexit
 - trace_thread_lwpcreate
 - trace_thread_lwpcreate_and_exit
2019-10-13 04:00:12 +00:00
mrg a83f6c1317 msg:
avoid passing the same pointer in multiple arguments for restrict
marked arguments:
- sigaction() wants separate in/out
- use memmove() not memcpy() for overlapping regions (this may fix
  a real bug in nvi -- but it seems unlikely)
- select() wants separate read/write/except
- sigprocmask() wants separate set/oset
2019-10-04 09:01:59 +00:00
kamil 081796c351 Remove ATF t_ptrace_wait test suspend1
The tests verifies that a thread can be suspended by a debugger and later
resumed by a tracee.

This is an unwanted behavior and will be fixed soon.
2019-10-02 23:15:09 +00:00
kamil 1f257ef9aa Merge PT_GET_PROCESS_STATE checks into traceme_raise ATF ptrace tests
Assert that PT_GET_PROCESS_STATE for !child and !lwp events returns
non-error and zeroed struct ptrace_state.

These checks are not really special to traceme_raise, it's just an
opportunity to reuse them in an existing tests without writing a dedicated
one.

This behavior is needed to maintain in 3rd party software (GDB).
2019-10-01 22:26:38 +00:00
kamil b0c977dcb4 Add a few static asserts in t_ptrace_wait.c for conditions that must be kept
Assert that ptrace_state and siginfo_t's _ptrace_state are synchronized.
2019-10-01 21:13:30 +00:00
mrg 21303c93e9 convert HAVE_GCC == 7 to HAVE_GCC >= 7. 2019-09-29 23:44:58 +00:00
blymn e275f7f7db Rototill to add complex character support:
- Add cchar command to director test language to allow a complex character
  to be defined and passed to the slave.
- Removed the distinction between args and returns internally to prevent
  confusing the two which leads to errors and/or crashes.
- Converted mutt_test to use the new cchar definition and fixed the
  check files for the test.
2019-09-19 11:31:57 +00:00
christos 3f24065918 Remove the incomplete define. 2019-09-15 23:39:13 +00:00
kamil 1a5f018b01 Enhance the support of LLVM sanitizers
Define _REENTRANT for MKSANITIZER build. This is needed for at least stdio
code. This caused new build issued with duplicated symbols in few places
and rump kernel code picking different code paths borrowed from libc.
Handle all this in one go.

Add bsd.sanitizer.mk to share common code used by programs and libraries.

Switch from realall to beforeinstall target in .syms files. This is more
reliable in MKSANITIZER.
2019-08-27 22:48:53 +00:00
kamil 1101023c0c Fix build of t_ubsan/t_ubsanxx under MKSANITIZER
Do not link micro-ubsan runtime for disabled tests.

This avoids double symbols linked into a single binary.
2019-08-15 08:17:32 +00:00
martin 7f7ec27799 Re-enable the QEMU specific timing limits, but only an increased upper
limit for now - let's see if that works on the test-bed.
2019-08-11 11:42:23 +00:00
martin 98d251c113 PR lib/54440: adapt the FreeBSD change to this test and calculate time
differences more exact, allowing between 0 and 1 s delay between the
expected wakeup and the actual event happening.
Also convert the QEMU special case code to the same scheme, but for now
disable it (with XXX mark) and see if the proper timing limits fix that
case too.
If not, we will re-enable the QEMU special case.
2019-08-10 07:36:15 +00:00
christos 92bbbea0b3 PR/54414: Valery Ushakov: add a test for wcsrtombs(3) doesn't update the
source argument on conversion error
2019-07-28 13:46:45 +00:00
martin 653f037ebe PR misc/54382: whenever open(2) is called with O_CREAT, make sure to
pass an open mode argument.
2019-07-16 17:29:17 +00:00
gson b9a5a0bbdb In the setitimer_old test case, allow for time passing between the two
setitimer() calls.  Should fix PR kern/54370.
2019-07-13 12:44:02 +00:00
maya 36592171e1 return return atf_no_error() instead of 0 for consistency.
suggested by moritzbuhl in https://github.com/NetBSD/src/pull/11/
2019-07-09 16:24:01 +00:00
gson 7753bf0b70 Update require.memory to match the increased rlimit. 2019-07-09 13:59:25 +00:00
kamil c4f0499ad5 Avoid GCC warning on NetBSD/i386
Cast note_hdr.n_namesz to ssize_t through size_t to avoid potential
signedness bit shifts.
2019-07-01 02:04:37 +00:00
blymn f3430e9b6f Fix test for pad and enable it. 2019-06-30 22:37:11 +00:00
blymn afb56d5385 Enable mvscanw test since libcurses is now correct. 2019-06-30 22:21:33 +00:00
mgorny dba7737605 Add a test for verifying procinfo note inside coredumps.
Add a first test for triggering a core dump in the debugged process
(via PT_DUMPCORE) and verifying it.  The test finds procinfo note
and checks its contents.

The core dump is processed through libelf.  However, it only provides
for finding all note segments (or sections?).  I had to implement
finding and processing individual notes myself.  I've added
a core_find_note() function that will be reused in future tests.

Reviewed by kamil.
2019-06-30 21:20:04 +00:00
blymn edb52aabb2 Enable beep test, return is correct. 2019-06-26 22:18:44 +00:00
mgorny c2ad96ff63 Implement PT_GETXSTATE and PT_SETXSTATE
Introduce two new ptrace() requests: PT_GETXSTATE and PT_SETXSTATE,
that provide access to the extended (and extensible) set of FPU
registers on amd64 and i386.  At the moment, this covers AVX (YMM)
and AVX-512 (ZMM, opmask) registers.  It can be easily extended
to cover further register types without breaking backwards
compatibility.

PT_GETXSTATE issues the XSAVE instruction with all kernel-supported
extended components enabled.  The data is copied into 'struct xstate'
(which -- unlike the XSAVE area itself -- has stable format
and offsets).

PT_SETXSTATE issues the XRSTOR instruction to restore the register
values from user-provided 'struct xstate'.  The function replaces only
the specific XSAVE components that are listed in 'xs_rfbm' field,
making it possible to issue partial updates.

Both syscalls take a 'struct iovec' pointer rather than a direct
argument.  This requires the caller to explicitly specify the buffer
size.  As a result, existing code will continue to work correctly
when the structure is extended (performing partial reads/updates).
2019-06-26 12:30:12 +00:00
blymn 6e08cf3636 Fixed mvscanw test but leave disabled for the moment, the return for
mvscanw is incorrect in libcurses, we need a major lib version bump
to correct it.
2019-06-25 22:19:29 +00:00
kamil 177438b064 Add mkfifo{,at}(2) mode in mknod{,at}(2) as requested by POSIX
mknod with mode & S_IFIFO and dev=0 shall behave like mkfifo.

Update the documentation to reflect this state.

Add ATF tests.

This is an in-kernel implementation as typically user-space programs use
mkfifo(2) directly, however whenever there is need to bypass libc (like in
valgrind) then portable POSIX software calls the mknod syscall.

Noted on tech-kern@ by Greg Troxel.
2019-06-20 03:31:53 +00:00
kamil 6923eb2928 Allow to conditionally enable LWP ATF tests in t_ptrace_wait*
By default the tests are disabled.
2019-06-18 21:14:26 +00:00
kamil 0937aecd4c Enable vfork(2) ATF tests in t_ptrace_wait*
The racing issues are gone in my local setup.
2019-06-13 20:26:06 +00:00
kamil 3d6a33dc1e Add new ATF ptrace(2) tests for posix_spawn, reusing tests for fork/vfork
New tests:
 - posix_spawn_detach_spawner
 - posix_spawn_kill_spawner
 - posix_spawn_singalmasked
 - posix_spawn_singalignored

All test pass.
2019-06-12 17:07:11 +00:00