summaryrefslogtreecommitdiffstats
path: root/crypto/o_str.c
AgeCommit message (Expand)Author
2017-09-14Revert "GH614: Use memcpy()/strdup() when possible"Pauli
2017-08-30Move e_os.h to be the very first include.Pauli
2017-08-22Use "" not <> on e_os.h includeRich Salz
2017-08-22This has been added to avoid the situation where some host ctype.h functionsPauli
2017-05-01Address some -Wold-style-declaration warningsBenjamin Kaduk
2017-02-24Add -Wundef to --strict-warnings options.Bernd Edlinger
2016-06-21buf2hexstr: properly deal with empty stringKurt Roeckx
2016-05-28Remove internal functions OPENSSL_strcasecmp and OPENSSL_strncasecmpRichard Levitte
2016-05-27crypto/o_str.c: add _GNU_SOURCE strerror_r case.Andy Polyakov
2016-05-27crypto/o_str.c: strerror_s is provided by specific compiler run-time,Andy Polyakov
2016-05-23Use strerror_r()/strerror_s() instead of strerror() where possibleMatt Caswell
2016-05-17Copyright consolidation 04/10Rich Salz
2016-04-18Unsigned chars can't be negativeMatt Caswell
2016-04-18Make string_to_hex/hex_to_string publicRich Salz
2016-02-26Fix master compile errorMatt Caswell
2016-02-26GH680: Reuse strnlen() in strndup()Dmitry-Me
2016-02-03GH614: Use memcpy()/strdup() when possibleDmitry-Me
2016-01-26Remove /* foo.c */ commentsRich Salz
2015-12-18Remove the "eay" c-file-style indicatorsRichard Levitte
2015-12-16Rename some BUF_xxx to OPENSSL_xxxRich Salz
2015-05-14Identify and move OpenSSL internal header filesRichard Levitte
2015-01-23ifdef cleanup part 3: OPENSSL_SYSNAMERich Salz
2015-01-22Run util/openssl-format-source -v -c .Matt Caswell
2013-01-19Improve WINCE support.Andy Polyakov
2009-06-01PR: 1945Dr. Stephen Henson
2008-01-14<strings.h> does not exist under WIN32.Dr. Stephen Henson
2008-01-12Missing headers.Ben Laurie
2005-09-20"Overload" SunOS 4.x memcmp, which ruins ASN1_OBJECT table lookups.Andy Polyakov
2005-01-13Rely on e_os.h to appropriately define str[n]casecmp in non-POSIXAndy Polyakov
2004-12-31Borrow #include <string[s].h> from e_os.h.Andy Polyakov
2004-07-08o_str.c: Windows doesn't have <strings.h>, and since we use _strnicmp() andRichard Levitte
2004-05-13Synchronise o_str.c between 0.9.8-dev and 0.9.7-stable.Richard Levitte
2004-03-24Typo...Richard Levitte
2004-03-24Make sure toupper() is properly declared.Richard Levitte
2003-12-27Include strings.h so strcasecmp() and strncasecmp() get properly declared.Richard Levitte
2003-09-09Typos.Dr. Stephen Henson
2003-09-09Generalise the definition of strcasecmp() and strncasecmp() forRichard Levitte
s now a critical section that must occur while preemption is disabled. Think what would happen if the kernel is executing a floating-point instruction and is then preempted. Remember, the kernel does not save FPU state except for user tasks. Therefore, upon preemption, the FPU registers will be sold to the lowest bidder. Thus, preemption must be disabled around such regions. Note, some FPU functions are already explicitly preempt safe. For example, kernel_fpu_begin and kernel_fpu_end will disable and enable preemption. RULE #3: Lock acquire and release must be performed by same task ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ A lock acquired in one task must be released by the same task. This means you can't do oddball things like acquire a lock and go off to play while another task releases it. If you want to do something like this, acquire and release the task in the same code path and have the caller wait on an event by the other task. Solution ======== Data protection under preemption is achieved by disabling preemption for the duration of the critical region. :: preempt_enable() decrement the preempt counter preempt_disable() increment the preempt counter preempt_enable_no_resched() decrement, but do not immediately preempt preempt_check_resched() if needed, reschedule preempt_count() return the preempt counter The functions are nestable. In other words, you can call preempt_disable n-times in a code path, and preemption will not be reenabled until the n-th call to preempt_enable. The preempt statements define to nothing if preemption is not enabled. Note that you do not need to explicitly prevent preemption if you are holding any locks or interrupts are disabled, since preemption is implicitly disabled in those cases. But keep in mind that 'irqs disabled' is a fundamentally unsafe way of disabling preemption - any cond_resched() or cond_resched_lock() might trigger a reschedule if the preempt count is 0. A simple printk() might trigger a reschedule. So use this implicit preemption-disabling property only if you know that the affected codepath does not do any of this. Best policy is to use this only for small, atomic code that you wrote and which calls no complex functions. Example:: cpucache_t *cc; /* this is per-CPU */ preempt_disable(); cc = cc_data(searchp); if (cc && cc->avail) { __free_block(searchp, cc_entry(cc), cc->avail); cc->avail = 0; } preempt_enable(); return 0; Notice how the preemption statements must encompass every reference of the critical variables. Another example:: int buf[NR_CPUS]; set_cpu_val(buf); if (buf[smp_processor_id()] == -1) printf(KERN_INFO "wee!\n"); spin_lock(&buf_lock); /* ... */ This code is not preempt-safe, but see how easily we can fix it by simply moving the spin_lock up two lines. Preventing preemption using interrupt disabling =============================================== It is possible to prevent a preemption event using local_irq_disable and local_irq_save. Note, when doing so, you must be very careful to not cause an event that would set need_resched and result in a preemption check. When in doubt, rely on locking or explicit preemption disabling. Note in 2.5 interrupt disabling is now only per-CPU (e.g. local). An additional concern is proper usage of local_irq_disable and local_irq_save. These may be used to protect from preemption, however, on exit, if preemption may be enabled, a test to see if preemption is required should be done. If these are called from the spin_lock and read/write lock macros, the right thing is done. They may also be called within a spin-lock protected region, however, if they are ever called outside of this context, a test for preemption should be made. Do note that calls from interrupt context or bottom half/ tasklets are also protected by preemption locks and so may use the versions which do not check preemption.