mirror of
https://github.com/Qortal/Brooklyn.git
synced 2025-01-30 14:52:17 +00:00
O shut up T3Q. You'll never be the man your mother was.
This commit is contained in:
parent
604a706f77
commit
2da4b5c5e4
@ -87,6 +87,13 @@ static void ax25_kill_by_device(struct net_device *dev)
|
||||
ax25_for_each(s, &ax25_list) {
|
||||
if (s->ax25_dev == ax25_dev) {
|
||||
sk = s->sk;
|
||||
if (!sk) {
|
||||
spin_unlock_bh(&ax25_list_lock);
|
||||
s->ax25_dev = NULL;
|
||||
ax25_disconnect(s, ENETUNREACH);
|
||||
spin_lock_bh(&ax25_list_lock);
|
||||
goto again;
|
||||
}
|
||||
sock_hold(sk);
|
||||
spin_unlock_bh(&ax25_list_lock);
|
||||
lock_sock(sk);
|
||||
|
@ -4083,6 +4083,7 @@ void hci_release_dev(struct hci_dev *hdev)
|
||||
hci_dev_unlock(hdev);
|
||||
|
||||
ida_simple_remove(&hci_index_ida, hdev->id);
|
||||
kfree_skb(hdev->sent_cmd);
|
||||
kfree(hdev);
|
||||
}
|
||||
EXPORT_SYMBOL(hci_release_dev);
|
||||
|
@ -213,7 +213,7 @@ static ssize_t speed_show(struct device *dev,
|
||||
if (!rtnl_trylock())
|
||||
return restart_syscall();
|
||||
|
||||
if (netif_running(netdev)) {
|
||||
if (netif_running(netdev) && netif_device_present(netdev)) {
|
||||
struct ethtool_link_ksettings cmd;
|
||||
|
||||
if (!__ethtool_get_link_ksettings(netdev, &cmd))
|
||||
|
@ -446,6 +446,7 @@ int esp_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info *
|
||||
struct page *page;
|
||||
struct sk_buff *trailer;
|
||||
int tailen = esp->tailen;
|
||||
unsigned int allocsz;
|
||||
|
||||
/* this is non-NULL only with TCP/UDP Encapsulation */
|
||||
if (x->encap) {
|
||||
@ -455,6 +456,10 @@ int esp_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info *
|
||||
return err;
|
||||
}
|
||||
|
||||
allocsz = ALIGN(skb->data_len + tailen, L1_CACHE_BYTES);
|
||||
if (allocsz > ESP_SKB_FRAG_MAXSIZE)
|
||||
goto cow;
|
||||
|
||||
if (!skb_cloned(skb)) {
|
||||
if (tailen <= skb_tailroom(skb)) {
|
||||
nfrags = 1;
|
||||
|
@ -159,6 +159,9 @@ static struct sk_buff *xfrm4_beet_gso_segment(struct xfrm_state *x,
|
||||
skb_shinfo(skb)->gso_type |= SKB_GSO_TCPV4;
|
||||
}
|
||||
|
||||
if (proto == IPPROTO_IPV6)
|
||||
skb_shinfo(skb)->gso_type |= SKB_GSO_IPXIP4;
|
||||
|
||||
__skb_pull(skb, skb_transport_offset(skb));
|
||||
ops = rcu_dereference(inet_offloads[proto]);
|
||||
if (likely(ops && ops->callbacks.gso_segment))
|
||||
|
@ -1663,11 +1663,13 @@ int tcp_read_sock(struct sock *sk, read_descriptor_t *desc,
|
||||
if (!copied)
|
||||
copied = used;
|
||||
break;
|
||||
} else if (used <= len) {
|
||||
seq += used;
|
||||
copied += used;
|
||||
offset += used;
|
||||
}
|
||||
if (WARN_ON_ONCE(used > len))
|
||||
used = len;
|
||||
seq += used;
|
||||
copied += used;
|
||||
offset += used;
|
||||
|
||||
/* If recv_actor drops the lock (e.g. TCP splice
|
||||
* receive) the skb pointer might be invalid when
|
||||
* getting here: tcp_collapse might have deleted it
|
||||
|
@ -5000,6 +5000,7 @@ static int inet6_fill_ifaddr(struct sk_buff *skb, struct inet6_ifaddr *ifa,
|
||||
nla_put_s32(skb, IFA_TARGET_NETNSID, args->netnsid))
|
||||
goto error;
|
||||
|
||||
spin_lock_bh(&ifa->lock);
|
||||
if (!((ifa->flags&IFA_F_PERMANENT) &&
|
||||
(ifa->prefered_lft == INFINITY_LIFE_TIME))) {
|
||||
preferred = ifa->prefered_lft;
|
||||
@ -5021,6 +5022,7 @@ static int inet6_fill_ifaddr(struct sk_buff *skb, struct inet6_ifaddr *ifa,
|
||||
preferred = INFINITY_LIFE_TIME;
|
||||
valid = INFINITY_LIFE_TIME;
|
||||
}
|
||||
spin_unlock_bh(&ifa->lock);
|
||||
|
||||
if (!ipv6_addr_any(&ifa->peer_addr)) {
|
||||
if (nla_put_in6_addr(skb, IFA_LOCAL, &ifa->addr) < 0 ||
|
||||
|
@ -483,6 +483,7 @@ int esp6_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info
|
||||
struct page *page;
|
||||
struct sk_buff *trailer;
|
||||
int tailen = esp->tailen;
|
||||
unsigned int allocsz;
|
||||
|
||||
if (x->encap) {
|
||||
int err = esp6_output_encap(x, skb, esp);
|
||||
@ -491,6 +492,10 @@ int esp6_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info
|
||||
return err;
|
||||
}
|
||||
|
||||
allocsz = ALIGN(skb->data_len + tailen, L1_CACHE_BYTES);
|
||||
if (allocsz > ESP_SKB_FRAG_MAXSIZE)
|
||||
goto cow;
|
||||
|
||||
if (!skb_cloned(skb)) {
|
||||
if (tailen <= skb_tailroom(skb)) {
|
||||
nfrags = 1;
|
||||
|
@ -198,6 +198,9 @@ static struct sk_buff *xfrm6_beet_gso_segment(struct xfrm_state *x,
|
||||
ipv6_skip_exthdr(skb, 0, &proto, &frag);
|
||||
}
|
||||
|
||||
if (proto == IPPROTO_IPIP)
|
||||
skb_shinfo(skb)->gso_type |= SKB_GSO_IPXIP6;
|
||||
|
||||
__skb_pull(skb, skb_transport_offset(skb));
|
||||
ops = rcu_dereference(inet6_offloads[proto]);
|
||||
if (likely(ops && ops->callbacks.gso_segment))
|
||||
|
@ -2623,7 +2623,7 @@ static int pfkey_migrate(struct sock *sk, struct sk_buff *skb,
|
||||
}
|
||||
|
||||
return xfrm_migrate(&sel, dir, XFRM_POLICY_TYPE_MAIN, m, i,
|
||||
kma ? &k : NULL, net, NULL);
|
||||
kma ? &k : NULL, net, NULL, 0);
|
||||
|
||||
out:
|
||||
return err;
|
||||
|
@ -9,7 +9,7 @@
|
||||
* Copyright 2007, Michael Wu <flamingice@sourmilk.net>
|
||||
* Copyright 2007-2010, Intel Corporation
|
||||
* Copyright(c) 2015-2017 Intel Deutschland GmbH
|
||||
* Copyright (C) 2018 - 2021 Intel Corporation
|
||||
* Copyright (C) 2018 - 2022 Intel Corporation
|
||||
*/
|
||||
|
||||
#include <linux/ieee80211.h>
|
||||
@ -626,6 +626,14 @@ int ieee80211_start_tx_ba_session(struct ieee80211_sta *pubsta, u16 tid,
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (test_sta_flag(sta, WLAN_STA_MFP) &&
|
||||
!test_sta_flag(sta, WLAN_STA_AUTHORIZED)) {
|
||||
ht_dbg(sdata,
|
||||
"MFP STA not authorized - deny BA session request %pM tid %d\n",
|
||||
sta->sta.addr, tid);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/*
|
||||
* 802.11n-2009 11.5.1.1: If the initiating STA is an HT STA, is a
|
||||
* member of an IBSS, and has no other existing Block Ack agreement
|
||||
|
@ -61,10 +61,6 @@ static void inet_diag_msg_sctpasoc_fill(struct inet_diag_msg *r,
|
||||
r->idiag_timer = SCTP_EVENT_TIMEOUT_T3_RTX;
|
||||
r->idiag_retrans = asoc->rtx_data_chunks;
|
||||
r->idiag_expires = jiffies_to_msecs(t3_rtx->expires - jiffies);
|
||||
} else {
|
||||
r->idiag_timer = 0;
|
||||
r->idiag_retrans = 0;
|
||||
r->idiag_expires = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -144,13 +140,14 @@ static int inet_sctp_diag_fill(struct sock *sk, struct sctp_association *asoc,
|
||||
r = nlmsg_data(nlh);
|
||||
BUG_ON(!sk_fullsock(sk));
|
||||
|
||||
r->idiag_timer = 0;
|
||||
r->idiag_retrans = 0;
|
||||
r->idiag_expires = 0;
|
||||
if (asoc) {
|
||||
inet_diag_msg_sctpasoc_fill(r, sk, asoc);
|
||||
} else {
|
||||
inet_diag_msg_common_fill(r, sk);
|
||||
r->idiag_state = sk->sk_state;
|
||||
r->idiag_timer = 0;
|
||||
r->idiag_retrans = 0;
|
||||
}
|
||||
|
||||
if (inet_diag_msg_attrs_fill(sk, skb, r, ext, user_ns, net_admin))
|
||||
|
@ -352,16 +352,18 @@ static int tipc_enable_bearer(struct net *net, const char *name,
|
||||
goto rejected;
|
||||
}
|
||||
|
||||
/* Create monitoring data before accepting activate messages */
|
||||
if (tipc_mon_create(net, bearer_id)) {
|
||||
bearer_disable(net, b);
|
||||
kfree_skb(skb);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
test_and_set_bit_lock(0, &b->up);
|
||||
rcu_assign_pointer(tn->bearer_list[bearer_id], b);
|
||||
if (skb)
|
||||
tipc_bearer_xmit_skb(net, bearer_id, skb, &b->bcast_addr);
|
||||
|
||||
if (tipc_mon_create(net, bearer_id)) {
|
||||
bearer_disable(net, b);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
pr_info("Enabled bearer <%s>, priority %u\n", name, prio);
|
||||
|
||||
return res;
|
||||
|
@ -2285,6 +2285,11 @@ static int tipc_link_proto_rcv(struct tipc_link *l, struct sk_buff *skb,
|
||||
break;
|
||||
|
||||
case STATE_MSG:
|
||||
/* Validate Gap ACK blocks, drop if invalid */
|
||||
glen = tipc_get_gap_ack_blks(&ga, l, hdr, true);
|
||||
if (glen > dlen)
|
||||
break;
|
||||
|
||||
l->rcv_nxt_state = msg_seqno(hdr) + 1;
|
||||
|
||||
/* Update own tolerance if peer indicates a non-zero value */
|
||||
@ -2310,10 +2315,6 @@ static int tipc_link_proto_rcv(struct tipc_link *l, struct sk_buff *skb,
|
||||
break;
|
||||
}
|
||||
|
||||
/* Receive Gap ACK blocks from peer if any */
|
||||
glen = tipc_get_gap_ack_blks(&ga, l, hdr, true);
|
||||
if(glen > dlen)
|
||||
break;
|
||||
tipc_mon_rcv(l->net, data + glen, dlen - glen, l->addr,
|
||||
&l->mon_state, l->bearer_id);
|
||||
|
||||
|
@ -17525,7 +17525,8 @@ void cfg80211_ch_switch_notify(struct net_device *dev,
|
||||
wdev->chandef = *chandef;
|
||||
wdev->preset_chandef = *chandef;
|
||||
|
||||
if (wdev->iftype == NL80211_IFTYPE_STATION &&
|
||||
if ((wdev->iftype == NL80211_IFTYPE_STATION ||
|
||||
wdev->iftype == NL80211_IFTYPE_P2P_CLIENT) &&
|
||||
!WARN_ON(!wdev->current_bss))
|
||||
cfg80211_update_assoc_bss_entry(wdev, chandef->chan);
|
||||
|
||||
|
@ -4259,7 +4259,7 @@ static bool xfrm_migrate_selector_match(const struct xfrm_selector *sel_cmp,
|
||||
}
|
||||
|
||||
static struct xfrm_policy *xfrm_migrate_policy_find(const struct xfrm_selector *sel,
|
||||
u8 dir, u8 type, struct net *net)
|
||||
u8 dir, u8 type, struct net *net, u32 if_id)
|
||||
{
|
||||
struct xfrm_policy *pol, *ret = NULL;
|
||||
struct hlist_head *chain;
|
||||
@ -4268,7 +4268,8 @@ static struct xfrm_policy *xfrm_migrate_policy_find(const struct xfrm_selector *
|
||||
spin_lock_bh(&net->xfrm.xfrm_policy_lock);
|
||||
chain = policy_hash_direct(net, &sel->daddr, &sel->saddr, sel->family, dir);
|
||||
hlist_for_each_entry(pol, chain, bydst) {
|
||||
if (xfrm_migrate_selector_match(sel, &pol->selector) &&
|
||||
if ((if_id == 0 || pol->if_id == if_id) &&
|
||||
xfrm_migrate_selector_match(sel, &pol->selector) &&
|
||||
pol->type == type) {
|
||||
ret = pol;
|
||||
priority = ret->priority;
|
||||
@ -4280,7 +4281,8 @@ static struct xfrm_policy *xfrm_migrate_policy_find(const struct xfrm_selector *
|
||||
if ((pol->priority >= priority) && ret)
|
||||
break;
|
||||
|
||||
if (xfrm_migrate_selector_match(sel, &pol->selector) &&
|
||||
if ((if_id == 0 || pol->if_id == if_id) &&
|
||||
xfrm_migrate_selector_match(sel, &pol->selector) &&
|
||||
pol->type == type) {
|
||||
ret = pol;
|
||||
break;
|
||||
@ -4396,7 +4398,7 @@ static int xfrm_migrate_check(const struct xfrm_migrate *m, int num_migrate)
|
||||
int xfrm_migrate(const struct xfrm_selector *sel, u8 dir, u8 type,
|
||||
struct xfrm_migrate *m, int num_migrate,
|
||||
struct xfrm_kmaddress *k, struct net *net,
|
||||
struct xfrm_encap_tmpl *encap)
|
||||
struct xfrm_encap_tmpl *encap, u32 if_id)
|
||||
{
|
||||
int i, err, nx_cur = 0, nx_new = 0;
|
||||
struct xfrm_policy *pol = NULL;
|
||||
@ -4415,14 +4417,14 @@ int xfrm_migrate(const struct xfrm_selector *sel, u8 dir, u8 type,
|
||||
}
|
||||
|
||||
/* Stage 1 - find policy */
|
||||
if ((pol = xfrm_migrate_policy_find(sel, dir, type, net)) == NULL) {
|
||||
if ((pol = xfrm_migrate_policy_find(sel, dir, type, net, if_id)) == NULL) {
|
||||
err = -ENOENT;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* Stage 2 - find and update state(s) */
|
||||
for (i = 0, mp = m; i < num_migrate; i++, mp++) {
|
||||
if ((x = xfrm_migrate_state_find(mp, net))) {
|
||||
if ((x = xfrm_migrate_state_find(mp, net, if_id))) {
|
||||
x_cur[nx_cur] = x;
|
||||
nx_cur++;
|
||||
xc = xfrm_state_migrate(x, mp, encap);
|
||||
|
@ -1578,9 +1578,6 @@ static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig,
|
||||
memcpy(&x->mark, &orig->mark, sizeof(x->mark));
|
||||
memcpy(&x->props.smark, &orig->props.smark, sizeof(x->props.smark));
|
||||
|
||||
if (xfrm_init_state(x) < 0)
|
||||
goto error;
|
||||
|
||||
x->props.flags = orig->props.flags;
|
||||
x->props.extra_flags = orig->props.extra_flags;
|
||||
|
||||
@ -1605,7 +1602,8 @@ static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct xfrm_state *xfrm_migrate_state_find(struct xfrm_migrate *m, struct net *net)
|
||||
struct xfrm_state *xfrm_migrate_state_find(struct xfrm_migrate *m, struct net *net,
|
||||
u32 if_id)
|
||||
{
|
||||
unsigned int h;
|
||||
struct xfrm_state *x = NULL;
|
||||
@ -1621,6 +1619,8 @@ struct xfrm_state *xfrm_migrate_state_find(struct xfrm_migrate *m, struct net *n
|
||||
continue;
|
||||
if (m->reqid && x->props.reqid != m->reqid)
|
||||
continue;
|
||||
if (if_id != 0 && x->if_id != if_id)
|
||||
continue;
|
||||
if (!xfrm_addr_equal(&x->id.daddr, &m->old_daddr,
|
||||
m->old_family) ||
|
||||
!xfrm_addr_equal(&x->props.saddr, &m->old_saddr,
|
||||
@ -1636,6 +1636,8 @@ struct xfrm_state *xfrm_migrate_state_find(struct xfrm_migrate *m, struct net *n
|
||||
if (x->props.mode != m->mode ||
|
||||
x->id.proto != m->proto)
|
||||
continue;
|
||||
if (if_id != 0 && x->if_id != if_id)
|
||||
continue;
|
||||
if (!xfrm_addr_equal(&x->id.daddr, &m->old_daddr,
|
||||
m->old_family) ||
|
||||
!xfrm_addr_equal(&x->props.saddr, &m->old_saddr,
|
||||
@ -1662,6 +1664,11 @@ struct xfrm_state *xfrm_state_migrate(struct xfrm_state *x,
|
||||
if (!xc)
|
||||
return NULL;
|
||||
|
||||
xc->props.family = m->new_family;
|
||||
|
||||
if (xfrm_init_state(xc) < 0)
|
||||
goto error;
|
||||
|
||||
memcpy(&xc->id.daddr, &m->new_daddr, sizeof(xc->id.daddr));
|
||||
memcpy(&xc->props.saddr, &m->new_saddr, sizeof(xc->props.saddr));
|
||||
|
||||
|
@ -629,13 +629,8 @@ static struct xfrm_state *xfrm_state_construct(struct net *net,
|
||||
|
||||
xfrm_smark_init(attrs, &x->props.smark);
|
||||
|
||||
if (attrs[XFRMA_IF_ID]) {
|
||||
if (attrs[XFRMA_IF_ID])
|
||||
x->if_id = nla_get_u32(attrs[XFRMA_IF_ID]);
|
||||
if (!x->if_id) {
|
||||
err = -EINVAL;
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
err = __xfrm_init_state(x, false, attrs[XFRMA_OFFLOAD_DEV]);
|
||||
if (err)
|
||||
@ -1431,13 +1426,8 @@ static int xfrm_alloc_userspi(struct sk_buff *skb, struct nlmsghdr *nlh,
|
||||
|
||||
mark = xfrm_mark_get(attrs, &m);
|
||||
|
||||
if (attrs[XFRMA_IF_ID]) {
|
||||
if (attrs[XFRMA_IF_ID])
|
||||
if_id = nla_get_u32(attrs[XFRMA_IF_ID]);
|
||||
if (!if_id) {
|
||||
err = -EINVAL;
|
||||
goto out_noput;
|
||||
}
|
||||
}
|
||||
|
||||
if (p->info.seq) {
|
||||
x = xfrm_find_acq_byseq(net, mark, p->info.seq);
|
||||
@ -1750,13 +1740,8 @@ static struct xfrm_policy *xfrm_policy_construct(struct net *net, struct xfrm_us
|
||||
|
||||
xfrm_mark_get(attrs, &xp->mark);
|
||||
|
||||
if (attrs[XFRMA_IF_ID]) {
|
||||
if (attrs[XFRMA_IF_ID])
|
||||
xp->if_id = nla_get_u32(attrs[XFRMA_IF_ID]);
|
||||
if (!xp->if_id) {
|
||||
err = -EINVAL;
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
return xp;
|
||||
error:
|
||||
@ -2607,6 +2592,7 @@ static int xfrm_do_migrate(struct sk_buff *skb, struct nlmsghdr *nlh,
|
||||
int n = 0;
|
||||
struct net *net = sock_net(skb->sk);
|
||||
struct xfrm_encap_tmpl *encap = NULL;
|
||||
u32 if_id = 0;
|
||||
|
||||
if (attrs[XFRMA_MIGRATE] == NULL)
|
||||
return -EINVAL;
|
||||
@ -2631,7 +2617,10 @@ static int xfrm_do_migrate(struct sk_buff *skb, struct nlmsghdr *nlh,
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
err = xfrm_migrate(&pi->sel, pi->dir, type, m, n, kmp, net, encap);
|
||||
if (attrs[XFRMA_IF_ID])
|
||||
if_id = nla_get_u32(attrs[XFRMA_IF_ID]);
|
||||
|
||||
err = xfrm_migrate(&pi->sel, pi->dir, type, m, n, kmp, net, encap, if_id);
|
||||
|
||||
kfree(encap);
|
||||
|
||||
|
@ -374,6 +374,16 @@ run_cmd() {
|
||||
return $rc
|
||||
}
|
||||
|
||||
run_cmd_bg() {
|
||||
cmd="$*"
|
||||
|
||||
if [ "$VERBOSE" = "1" ]; then
|
||||
printf " COMMAND: %s &\n" "${cmd}"
|
||||
fi
|
||||
|
||||
$cmd 2>&1 &
|
||||
}
|
||||
|
||||
# Find the auto-generated name for this namespace
|
||||
nsname() {
|
||||
eval echo \$NS_$1
|
||||
@ -670,10 +680,10 @@ setup_nettest_xfrm() {
|
||||
[ ${1} -eq 6 ] && proto="-6" || proto=""
|
||||
port=${2}
|
||||
|
||||
run_cmd ${ns_a} nettest ${proto} -q -D -s -x -p ${port} -t 5 &
|
||||
run_cmd_bg "${ns_a}" nettest "${proto}" -q -D -s -x -p "${port}" -t 5
|
||||
nettest_pids="${nettest_pids} $!"
|
||||
|
||||
run_cmd ${ns_b} nettest ${proto} -q -D -s -x -p ${port} -t 5 &
|
||||
run_cmd_bg "${ns_b}" nettest "${proto}" -q -D -s -x -p "${port}" -t 5
|
||||
nettest_pids="${nettest_pids} $!"
|
||||
}
|
||||
|
||||
@ -865,7 +875,6 @@ setup_ovs_bridge() {
|
||||
setup() {
|
||||
[ "$(id -u)" -ne 0 ] && echo " need to run as root" && return $ksft_skip
|
||||
|
||||
cleanup
|
||||
for arg do
|
||||
eval setup_${arg} || { echo " ${arg} not supported"; return 1; }
|
||||
done
|
||||
@ -876,7 +885,7 @@ trace() {
|
||||
|
||||
for arg do
|
||||
[ "${ns_cmd}" = "" ] && ns_cmd="${arg}" && continue
|
||||
${ns_cmd} tcpdump -s 0 -i "${arg}" -w "${name}_${arg}.pcap" 2> /dev/null &
|
||||
${ns_cmd} tcpdump --immediate-mode -s 0 -i "${arg}" -w "${name}_${arg}.pcap" 2> /dev/null &
|
||||
tcpdump_pids="${tcpdump_pids} $!"
|
||||
ns_cmd=
|
||||
done
|
||||
@ -1836,6 +1845,10 @@ run_test() {
|
||||
|
||||
unset IFS
|
||||
|
||||
# Since cleanup() relies on variables modified by this subshell, it
|
||||
# has to run in this context.
|
||||
trap cleanup EXIT
|
||||
|
||||
if [ "$VERBOSE" = "1" ]; then
|
||||
printf "\n##########################################################################\n\n"
|
||||
fi
|
||||
|
@ -17,9 +17,6 @@
|
||||
#define MAP_FIXED_NOREPLACE 0x100000
|
||||
#endif
|
||||
|
||||
#define BASE_ADDRESS (256ul * 1024 * 1024)
|
||||
|
||||
|
||||
static void dump_maps(void)
|
||||
{
|
||||
char cmd[32];
|
||||
@ -28,18 +25,46 @@ static void dump_maps(void)
|
||||
system(cmd);
|
||||
}
|
||||
|
||||
static unsigned long find_base_addr(unsigned long size)
|
||||
{
|
||||
void *addr;
|
||||
unsigned long flags;
|
||||
|
||||
flags = MAP_PRIVATE | MAP_ANONYMOUS;
|
||||
addr = mmap(NULL, size, PROT_NONE, flags, -1, 0);
|
||||
if (addr == MAP_FAILED) {
|
||||
printf("Error: couldn't map the space we need for the test\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (munmap(addr, size) != 0) {
|
||||
printf("Error: couldn't map the space we need for the test\n");
|
||||
return 0;
|
||||
}
|
||||
return (unsigned long)addr;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
unsigned long base_addr;
|
||||
unsigned long flags, addr, size, page_size;
|
||||
char *p;
|
||||
|
||||
page_size = sysconf(_SC_PAGE_SIZE);
|
||||
|
||||
//let's find a base addr that is free before we start the tests
|
||||
size = 5 * page_size;
|
||||
base_addr = find_base_addr(size);
|
||||
if (!base_addr) {
|
||||
printf("Error: couldn't map the space we need for the test\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED_NOREPLACE;
|
||||
|
||||
// Check we can map all the areas we need below
|
||||
errno = 0;
|
||||
addr = BASE_ADDRESS;
|
||||
addr = base_addr;
|
||||
size = 5 * page_size;
|
||||
p = mmap((void *)addr, size, PROT_NONE, flags, -1, 0);
|
||||
|
||||
@ -60,7 +85,7 @@ int main(void)
|
||||
printf("unmap() successful\n");
|
||||
|
||||
errno = 0;
|
||||
addr = BASE_ADDRESS + page_size;
|
||||
addr = base_addr + page_size;
|
||||
size = 3 * page_size;
|
||||
p = mmap((void *)addr, size, PROT_NONE, flags, -1, 0);
|
||||
printf("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p);
|
||||
@ -80,7 +105,7 @@ int main(void)
|
||||
* +4 | free | new
|
||||
*/
|
||||
errno = 0;
|
||||
addr = BASE_ADDRESS;
|
||||
addr = base_addr;
|
||||
size = 5 * page_size;
|
||||
p = mmap((void *)addr, size, PROT_NONE, flags, -1, 0);
|
||||
printf("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p);
|
||||
@ -101,7 +126,7 @@ int main(void)
|
||||
* +4 | free |
|
||||
*/
|
||||
errno = 0;
|
||||
addr = BASE_ADDRESS + (2 * page_size);
|
||||
addr = base_addr + (2 * page_size);
|
||||
size = page_size;
|
||||
p = mmap((void *)addr, size, PROT_NONE, flags, -1, 0);
|
||||
printf("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p);
|
||||
@ -121,7 +146,7 @@ int main(void)
|
||||
* +4 | free | new
|
||||
*/
|
||||
errno = 0;
|
||||
addr = BASE_ADDRESS + (3 * page_size);
|
||||
addr = base_addr + (3 * page_size);
|
||||
size = 2 * page_size;
|
||||
p = mmap((void *)addr, size, PROT_NONE, flags, -1, 0);
|
||||
printf("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p);
|
||||
@ -141,7 +166,7 @@ int main(void)
|
||||
* +4 | free |
|
||||
*/
|
||||
errno = 0;
|
||||
addr = BASE_ADDRESS;
|
||||
addr = base_addr;
|
||||
size = 2 * page_size;
|
||||
p = mmap((void *)addr, size, PROT_NONE, flags, -1, 0);
|
||||
printf("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p);
|
||||
@ -161,7 +186,7 @@ int main(void)
|
||||
* +4 | free |
|
||||
*/
|
||||
errno = 0;
|
||||
addr = BASE_ADDRESS;
|
||||
addr = base_addr;
|
||||
size = page_size;
|
||||
p = mmap((void *)addr, size, PROT_NONE, flags, -1, 0);
|
||||
printf("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p);
|
||||
@ -181,7 +206,7 @@ int main(void)
|
||||
* +4 | free | new
|
||||
*/
|
||||
errno = 0;
|
||||
addr = BASE_ADDRESS + (4 * page_size);
|
||||
addr = base_addr + (4 * page_size);
|
||||
size = page_size;
|
||||
p = mmap((void *)addr, size, PROT_NONE, flags, -1, 0);
|
||||
printf("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p);
|
||||
@ -192,7 +217,7 @@ int main(void)
|
||||
return 1;
|
||||
}
|
||||
|
||||
addr = BASE_ADDRESS;
|
||||
addr = base_addr;
|
||||
size = 5 * page_size;
|
||||
if (munmap((void *)addr, size) != 0) {
|
||||
dump_maps();
|
||||
|
@ -46,6 +46,7 @@
|
||||
#include <signal.h>
|
||||
#include <poll.h>
|
||||
#include <string.h>
|
||||
#include <linux/mman.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
Loading…
Reference in New Issue
Block a user