]> git.proxmox.com Git - mirror_qemu.git/blame - tcg/tcg-ldst.c.inc
migration: Fix use-after-free of migration state object
[mirror_qemu.git] / tcg / tcg-ldst.c.inc
CommitLineData
9ecefc84
RH
1/*
2 * TCG Backend Data: load-store optimization only.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
9ecefc84
RH
23/*
24 * Generate TB finalization at the end of block
25 */
26
aeee05f5
RH
27static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *l);
28static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *l);
9ecefc84 29
aeee05f5 30static int tcg_out_ldst_finalize(TCGContext *s)
9ecefc84 31{
686461c9 32 TCGLabelQemuLdst *lb;
9ecefc84
RH
33
34 /* qemu_ld/st slow paths */
6001f772 35 QSIMPLEQ_FOREACH(lb, &s->ldst_labels, next) {
aeee05f5
RH
36 if (lb->is_ld
37 ? !tcg_out_qemu_ld_slow_path(s, lb)
38 : !tcg_out_qemu_st_slow_path(s, lb)) {
39 return -2;
9ecefc84 40 }
23dceda6
RH
41
42 /* Test for (pending) buffer overflow. The assumption is that any
43 one operation beginning below the high water mark cannot overrun
44 the buffer completely. Thus we can test for overflow after
45 generating code without having to check during generation. */
46 if (unlikely((void *)s->code_ptr > s->code_gen_highwater)) {
aeee05f5 47 return -1;
23dceda6 48 }
9ecefc84 49 }
aeee05f5 50 return 0;
9ecefc84
RH
51}
52
53/*
54 * Allocate a new TCGLabelQemuLdst entry.
55 */
56
57static inline TCGLabelQemuLdst *new_ldst_label(TCGContext *s)
58{
686461c9 59 TCGLabelQemuLdst *l = tcg_malloc(sizeof(*l));
9ecefc84 60
4745b156 61 memset(l, 0, sizeof(*l));
6001f772
LV
62 QSIMPLEQ_INSERT_TAIL(&s->ldst_labels, l, next);
63
686461c9 64 return l;
9ecefc84 65}